2 * QuickThreads -- Threads-building toolkit.
3 * Copyright (c) 1993 by David Keppel
5 * Permission to use, copy, modify and distribute this software and
6 * its documentation for any purpose and without fee is hereby
7 * granted, provided that the above copyright notice and this notice
8 * appear in all copies. This software is provided as a
9 * proof-of-concept and for demonstration purposes; there is no
10 * representation about the suitability of this software for any
17 typedef unsigned long qt_word_t;
19 /* Thread's initial stack layout on the i386:
24 | arg[2] === `userf' on startup
25 | arg[1] === `pt' on startup
26 | arg[0] === `pu' on startup
30 | ret pc === `only' on startup
38 When a non-varargs thread is started, it ``returns'' directly to
39 the client's `only' function.
48 | ret pc === `qt_vstart'
53 | %ebx === `vuserf' <--- qt_t.sp
56 When a varargs thread is started, it ``returns'' to the `qt_vstart'
57 startup code. The startup code calls the appropriate functions. */
60 /* What to do to start a varargs thread running. */
61 QT_API void qt_vstart (void);
64 /* Hold 4 saved regs plus two return pcs (qt_error, qt_start) plus
66 #define QT_STKBASE (9 * 4)
68 /* Hold 4 saved regs plus one return pc (qt_vstart). */
69 #define QT_VSTKBASE (5 * 4)
72 /* Stack must be 4-byte aligned. */
73 #define QT_STKALIGN (4)
76 /* Where to place various arguments. */
77 #define QT_ONLY_INDEX (QT_PC)
78 #define QT_USER_INDEX (QT_ARG2)
79 #define QT_ARGT_INDEX (QT_ARG1)
80 #define QT_ARGU_INDEX (QT_ARG0)
82 #define QT_VSTARTUP_INDEX (QT_EBP)
83 #define QT_VUSERF_INDEX (QT_EBX)
84 #define QT_VCLEANUP_INDEX (QT_ESI)
85 #define QT_VARGT_INDEX (QT_EDI)
93 /* The following are defined only for non-varargs. */
100 /* Stack grows down. The top of the stack is the first thing to
101 pop off (preincrement, postdecrement). */
104 QT_API void qt_error (void);
106 /* Push on the error return address. */
107 #define QT_ARGS_MD(sto) \
108 (QT_SPUT (sto, QT_RPC, qt_error))
111 /* When varargs are pushed, allocate space for all the args. */
112 #define QT_VARGS_MD0(sto, nbytes) \
113 ((qt_t *)(((char *)(sto)) - QT_STKROUNDUP(nbytes)))
115 #define QT_VARGS_MD1(sto) \
116 (QT_SPUT (sto, QT_PC, qt_vstart))
118 #define QT_VARGS_DEFAULT
120 #endif /* QT_386_H */