i386.h revision 12027
1360SN/A/*
21458SN/A * QuickThreads -- Threads-building toolkit.
3360SN/A * Copyright (c) 1993 by David Keppel
4360SN/A *
5360SN/A * Permission to use, copy, modify and distribute this software and
6360SN/A * its documentation for any purpose and without fee is hereby
7360SN/A * granted, provided that the above copyright notice and this notice
8360SN/A * appear in all copies.  This software is provided as a
9360SN/A * proof-of-concept and for demonstration purposes; there is no
10360SN/A * representation about the suitability of this software for any
11360SN/A * purpose.
12360SN/A */
13360SN/A
14360SN/A#ifndef QUICKTHREADS_386_H
15360SN/A#define QUICKTHREADS_386_H
16360SN/A
17360SN/Atypedef unsigned long qt_word_t;
18360SN/A
19360SN/A/* Thread's initial stack layout on the i386:
20360SN/A
21360SN/A   non-varargs:
22360SN/A
23360SN/A   +---
24360SN/A   | arg[2]	=== `userf' on startup
25360SN/A   | arg[1]	=== `pt' on startup
26360SN/A   | arg[0]	=== `pu' on startup
272665Ssaidi@eecs.umich.edu   +---
282665Ssaidi@eecs.umich.edu   | ret pc === qt_error
292665Ssaidi@eecs.umich.edu   +---
30360SN/A   | ret pc	=== `only' on startup
31360SN/A   +---
321354SN/A   | %ebp
331354SN/A   | %esi
34360SN/A   | %edi
352764Sstever@eecs.umich.edu   | %ebx				<--- qt_t.sp
362764Sstever@eecs.umich.edu   +---
372064SN/A
38360SN/A   When a non-varargs thread is started, it ``returns'' directly to
39360SN/A   the client's `only' function.
40360SN/A
41360SN/A   varargs:
42360SN/A
43360SN/A   +---
441354SN/A   | arg[n-1]
45360SN/A   | ..
461809SN/A   | arg[0]
471809SN/A   +---
481809SN/A   | ret pc	=== `qt_vstart'
493113Sgblack@eecs.umich.edu   +---
503113Sgblack@eecs.umich.edu   | %ebp	=== `startup'
511999SN/A   | %esi	=== `cleanup'
52360SN/A   | %edi	=== `pt'
533113Sgblack@eecs.umich.edu   | %ebx	=== `vuserf'		<--- qt_t.sp
542474SN/A   +---
55360SN/A
562462SN/A   When a varargs thread is started, it ``returns'' to the `qt_vstart'
571354SN/A   startup code.  The startup code calls the appropriate functions. */
582474SN/A
592680Sktlim@umich.edu
602474SN/A/* What to do to start a varargs thread running. */
612474SN/Aextern void qt_vstart (void);
621354SN/A
63360SN/A
64360SN/A/* Hold 4 saved regs plus two return pcs (qt_error, qt_start) plus
65360SN/A   three args. */
66360SN/A#define QUICKTHREADS_STKBASE	(13 * 4)
67360SN/A
68360SN/A/* Hold 4 saved regs plus one return pc (qt_vstart). */
69360SN/A#define QUICKTHREADS_VSTKBASE	(5 * 4)
70360SN/A
71378SN/A
721450SN/A/* Stack must be 16-byte aligned at function call instr. (SSE data support) */
733114Sgblack@eecs.umich.edu#define QUICKTHREADS_STKALIGN	(16)
74360SN/A
75360SN/A
76360SN/A/* Where to place various arguments. */
77360SN/A#define QUICKTHREADS_ONLY_INDEX	(QUICKTHREADS_PC)
78360SN/A#define QUICKTHREADS_USER_INDEX	(QUICKTHREADS_ARG2)
79360SN/A#define QUICKTHREADS_ARGT_INDEX	(QUICKTHREADS_ARG1)
80360SN/A#define QUICKTHREADS_ARGU_INDEX	(QUICKTHREADS_ARG0)
81360SN/A
82360SN/A#define QUICKTHREADS_VSTARTUP_INDEX	(QUICKTHREADS_EBP)
832680Sktlim@umich.edu#define QUICKTHREADS_VUSERF_INDEX		(QUICKTHREADS_EBX)
84360SN/A#define QUICKTHREADS_VCLEANUP_INDEX	(QUICKTHREADS_ESI)
85360SN/A#define QUICKTHREADS_VARGT_INDEX		(QUICKTHREADS_EDI)
86360SN/A
87360SN/A
88360SN/A#define QUICKTHREADS_EBX        0
89360SN/A#define QUICKTHREADS_EDI        1
90360SN/A#define QUICKTHREADS_ESI        2
91360SN/A#define QUICKTHREADS_EBP        3
92360SN/A#define QUICKTHREADS_POP0       4
93360SN/A#define QUICKTHREADS_POP1       5
94360SN/A#define QUICKTHREADS_POP2       6
953114Sgblack@eecs.umich.edu#define QUICKTHREADS_PC         7
96360SN/A/* The following are defined only for non-varargs. */
97360SN/A#define QUICKTHREADS_POPE       8
98360SN/A#define QUICKTHREADS_ARG0       9
99360SN/A#define QUICKTHREADS_ARG1      10
100360SN/A#define QUICKTHREADS_ARG2      11
101360SN/A#define QUICKTHREADS_RPC       12
102360SN/A
103360SN/A
104360SN/A/* Stack grows down.  The top of the stack is the first thing to
105360SN/A   pop off (preincrement, postdecrement). */
106360SN/A#define QUICKTHREADS_GROW_DOWN
107360SN/A
108360SN/Aextern void qt_error (void);
109360SN/A
110360SN/A/* For correct 16-byte stack alignment (auto-relocatable functions) */
111360SN/Aextern void qt_tramp (void);
112360SN/Aextern void qt_align (void);
113360SN/A
114360SN/A/* Push on the error return address and the alignment/trampoline functions. */
115360SN/A#define QUICKTHREADS_ARGS_MD(sto) \
116360SN/A  (QUICKTHREADS_SPUT (sto, QUICKTHREADS_POP0, qt_align), \
1172400SN/A   QUICKTHREADS_SPUT (sto, QUICKTHREADS_POP1, qt_align), \
118360SN/A   QUICKTHREADS_SPUT (sto, QUICKTHREADS_POP2, qt_align), \
1192461SN/A   QUICKTHREADS_SPUT (sto, QUICKTHREADS_POPE, qt_tramp), \
120360SN/A   QUICKTHREADS_SPUT (sto, QUICKTHREADS_RPC, qt_error))
121360SN/A
122360SN/A
123360SN/A/* When varargs are pushed, allocate space for all the args. */
124360SN/A#define QUICKTHREADS_VARGS_MD0(sto, nbytes) \
125360SN/A  ((qt_t *)(((char *)(sto)) - QUICKTHREADS_STKROUNDUP(nbytes)))
1262400SN/A
127360SN/A#define QUICKTHREADS_VARGS_MD1(sto) \
1282461SN/A  (QUICKTHREADS_SPUT (sto, QUICKTHREADS_PC, qt_vstart))
129360SN/A
130360SN/A#define QUICKTHREADS_VARGS_DEFAULT
131360SN/A
132360SN/A#endif /* QUICKTHREADS_386_H */
133360SN/A