]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/i386/thread_status.h
eb740972bbb528690cc1c947358cc901a70898c8
[apple/xnu.git] / osfmk / mach / i386 / thread_status.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28 /*
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
31 * All Rights Reserved.
32 *
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
38 *
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
42 *
43 * Carnegie Mellon requests users of this software to return to
44 *
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
49 *
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
52 */
53 /*
54 */
55 /*
56 * File: thread_status.h
57 * Author: Avadis Tevanian, Jr.
58 * Date: 1985
59 *
60 * This file contains the structure definitions for the thread
61 * state as applied to I386 processors.
62 */
63
64 #ifndef _MACH_I386_THREAD_STATUS_H_
65 #define _MACH_I386_THREAD_STATUS_H_
66
67 #include <mach/i386/fp_reg.h>
68 #include <mach/i386/thread_state.h>
69 #include <architecture/i386/frame.h> /* FIXME */
70 #include <architecture/i386/fpu.h> /* FIXME */
71 /*
72 * i386_thread_state this is the structure that is exported
73 * to user threads for use in status/mutate
74 * calls. This structure should never
75 * change.
76 *
77 * i386_float_state exported to use threads for access to
78 * floating point registers. Try not to
79 * change this one, either.
80 *
81 * i386_isa_port_map_state exported to user threads to allow
82 * selective in/out operations
83 *
84 * i386_v86_assist_state
85 *
86 * thread_syscall_state
87 */
88
89 /* THREAD_STATE_FLAVOR_LIST 0 */
90 #define i386_NEW_THREAD_STATE 1 /* used to be i386_THREAD_STATE */
91 #define i386_FLOAT_STATE 2
92 #define i386_ISA_PORT_MAP_STATE 3
93 #define i386_V86_ASSIST_STATE 4
94 #define i386_REGS_SEGS_STATE 5
95 #define THREAD_SYSCALL_STATE 6
96 #define THREAD_STATE_NONE 7
97 #define i386_SAVED_STATE 8
98
99
100 /*
101 * VALID_THREAD_STATE_FLAVOR is a platform specific macro that when passed
102 * an exception flavor will return if that is a defined flavor for that
103 * platform. The macro must be manually updated to include all of the valid
104 * exception flavors as defined above.
105 */
106 #define VALID_THREAD_STATE_FLAVOR(x) \
107 ((x == i386_NEW_THREAD_STATE) || \
108 (x == i386_FLOAT_STATE) || \
109 (x == i386_ISA_PORT_MAP_STATE) || \
110 (x == i386_V86_ASSIST_STATE) || \
111 (x == i386_REGS_SEGS_STATE) || \
112 (x == THREAD_SYSCALL_STATE) || \
113 (x == THREAD_STATE_NONE) || \
114 (x == i386_SAVED_STATE))
115
116 /*
117 * This structure is used for both
118 * i386_THREAD_STATE and i386_REGS_SEGS_STATE.
119 */
120 struct i386_new_thread_state {
121 unsigned int gs;
122 unsigned int fs;
123 unsigned int es;
124 unsigned int ds;
125 unsigned int edi;
126 unsigned int esi;
127 unsigned int ebp;
128 unsigned int esp;
129 unsigned int ebx;
130 unsigned int edx;
131 unsigned int ecx;
132 unsigned int eax;
133 unsigned int eip;
134 unsigned int cs;
135 unsigned int efl;
136 unsigned int uesp;
137 unsigned int ss;
138 };
139 #define i386_NEW_THREAD_STATE_COUNT \
140 (sizeof (struct i386_new_thread_state)/sizeof(unsigned int))
141
142 /*
143 * Subset of saved state stored by processor on kernel-to-kernel
144 * trap. (Used by ddb to examine state guaranteed to be present
145 * on all traps into debugger.)
146 */
147 struct i386_saved_state_from_kernel {
148 unsigned int gs;
149 unsigned int fs;
150 unsigned int es;
151 unsigned int ds;
152 unsigned int edi;
153 unsigned int esi;
154 unsigned int ebp;
155 unsigned int esp; /* kernel esp stored by pusha -
156 we save cr2 here later */
157 unsigned int ebx;
158 unsigned int edx;
159 unsigned int ecx;
160 unsigned int eax;
161 unsigned int trapno;
162 unsigned int err;
163 unsigned int eip;
164 unsigned int cs;
165 unsigned int efl;
166 };
167
168 /*
169 * The format in which thread state is saved by Mach on this machine. This
170 * state flavor is most efficient for exception RPC's to kernel-loaded
171 * servers, because copying can be avoided:
172 */
173 struct i386_saved_state {
174 unsigned int gs;
175 unsigned int fs;
176 unsigned int es;
177 unsigned int ds;
178 unsigned int edi;
179 unsigned int esi;
180 unsigned int ebp;
181 unsigned int esp; /* kernel esp stored by pusha -
182 we save cr2 here later */
183 unsigned int ebx;
184 unsigned int edx;
185 unsigned int ecx;
186 unsigned int eax;
187 unsigned int trapno;
188 unsigned int err;
189 unsigned int eip;
190 unsigned int cs;
191 unsigned int efl;
192 unsigned int uesp;
193 unsigned int ss;
194 struct v86_segs {
195 unsigned int v86_es; /* virtual 8086 segment registers */
196 unsigned int v86_ds;
197 unsigned int v86_fs;
198 unsigned int v86_gs;
199 } v86_segs;
200 #define i386_SAVED_ARGV_COUNT 7
201 unsigned int argv_status; /* Boolean flag indicating whether or
202 * not Mach copied in the args */
203 unsigned int argv[i386_SAVED_ARGV_COUNT];
204 /* The return address, and the first several
205 * function call args from the stack, for
206 * efficient syscall exceptions */
207 };
208 #define i386_SAVED_STATE_COUNT (sizeof (struct i386_saved_state)/sizeof(unsigned int))
209 #define i386_REGS_SEGS_STATE_COUNT i386_SAVED_STATE_COUNT
210
211 /*
212 * Machine-independent way for servers and Mach's exception mechanism to
213 * choose the most efficient state flavor for exception RPC's:
214 */
215 #define MACHINE_THREAD_STATE i386_SAVED_STATE
216 #define MACHINE_THREAD_STATE_COUNT i386_SAVED_STATE_COUNT
217
218 /*
219 * Largest state on this machine:
220 * (be sure mach/machine/thread_state.h matches!)
221 */
222 #define THREAD_MACHINE_STATE_MAX i386_SAVED_STATE_COUNT
223
224 /*
225 * Floating point state.
226 *
227 * fpkind tells in what way floating point operations are supported.
228 * See the values for fp_kind in <mach/i386/fp_reg.h>.
229 *
230 * If the kind is FP_NO, then calls to set the state will fail, and
231 * thread_getstatus will return garbage for the rest of the state.
232 * If "initialized" is false, then the rest of the state is garbage.
233 * Clients can set "initialized" to false to force the coprocessor to
234 * be reset.
235 * "exc_status" is non-zero if the thread has noticed (but not
236 * proceeded from) a coprocessor exception. It contains the status
237 * word with the exception bits set. The status word in "fp_status"
238 * will have the exception bits turned off. If an exception bit in
239 * "fp_status" is turned on, then "exc_status" should be zero. This
240 * happens when the coprocessor exception is noticed after the system
241 * has context switched to some other thread.
242 *
243 * If kind is FP_387, then "state" is a i387_state. Other kinds might
244 * also use i387_state, but somebody will have to verify it (XXX).
245 * Note that the registers are ordered from top-of-stack down, not
246 * according to physical register number.
247 */
248
249 #define FP_STATE_BYTES \
250 (sizeof (struct i386_fp_save) + sizeof (struct i386_fp_regs))
251
252 struct i386_float_state {
253 int fpkind; /* FP_NO..FP_387 (readonly) */
254 int initialized;
255 unsigned char hw_state[FP_STATE_BYTES]; /* actual "hardware" state */
256 int exc_status; /* exception status (readonly) */
257 };
258 #define i386_FLOAT_STATE_COUNT \
259 (sizeof(struct i386_float_state)/sizeof(unsigned int))
260
261
262 #define PORT_MAP_BITS 0x400
263 struct i386_isa_port_map_state {
264 unsigned char pm[PORT_MAP_BITS>>3];
265 };
266
267 #define i386_ISA_PORT_MAP_STATE_COUNT \
268 (sizeof(struct i386_isa_port_map_state)/sizeof(unsigned int))
269
270 /*
271 * V8086 assist supplies a pointer to an interrupt
272 * descriptor table in task space.
273 */
274 struct i386_v86_assist_state {
275 unsigned int int_table; /* interrupt table address */
276 int int_count; /* interrupt table size */
277 };
278
279 struct v86_interrupt_table {
280 unsigned int count; /* count of pending interrupts */
281 unsigned short mask; /* ignore this interrupt if true */
282 unsigned short vec; /* vector to take */
283 };
284
285 #define i386_V86_ASSIST_STATE_COUNT \
286 (sizeof(struct i386_v86_assist_state)/sizeof(unsigned int))
287
288 struct thread_syscall_state {
289 unsigned eax;
290 unsigned edx;
291 unsigned efl;
292 unsigned eip;
293 unsigned esp;
294 };
295
296 #define i386_THREAD_SYSCALL_STATE_COUNT \
297 (sizeof(struct thread_syscall_state) / sizeof(unsigned int))
298
299 /*
300 * Main thread state consists of
301 * general registers, segment registers,
302 * eip and eflags.
303 */
304
305 #define i386_THREAD_STATE -1
306
307 typedef struct {
308 unsigned int eax;
309 unsigned int ebx;
310 unsigned int ecx;
311 unsigned int edx;
312 unsigned int edi;
313 unsigned int esi;
314 unsigned int ebp;
315 unsigned int esp;
316 unsigned int ss;
317 unsigned int eflags;
318 unsigned int eip;
319 unsigned int cs;
320 unsigned int ds;
321 unsigned int es;
322 unsigned int fs;
323 unsigned int gs;
324 } i386_thread_state_t;
325
326 #define i386_THREAD_STATE_COUNT \
327 ( sizeof (i386_thread_state_t) / sizeof (int) )
328
329 /*
330 * Default segment register values.
331 */
332
333 #define USER_CODE_SELECTOR 0x0017
334 #define USER_DATA_SELECTOR 0x001f
335 #define KERN_CODE_SELECTOR 0x0008
336 #define KERN_DATA_SELECTOR 0x0010
337
338 /*
339 * Thread floating point state
340 * includes FPU environment as
341 * well as the register stack.
342 */
343
344 #define i386_THREAD_FPSTATE -2
345
346 typedef struct {
347 fp_env_t environ;
348 fp_stack_t stack;
349 } i386_thread_fpstate_t;
350
351 #define i386_THREAD_FPSTATE_COUNT \
352 ( sizeof (i386_thread_fpstate_t) / sizeof (int) )
353
354 /*
355 * Extra state that may be
356 * useful to exception handlers.
357 */
358
359 #define i386_THREAD_EXCEPTSTATE -3
360
361 typedef struct {
362 unsigned int trapno;
363 err_code_t err;
364 } i386_thread_exceptstate_t;
365
366 #define i386_THREAD_EXCEPTSTATE_COUNT \
367 ( sizeof (i386_thread_exceptstate_t) / sizeof (int) )
368
369 /*
370 * Per-thread variable used
371 * to store 'self' id for cthreads.
372 */
373
374 #define i386_THREAD_CTHREADSTATE -4
375
376 typedef struct {
377 unsigned int self;
378 } i386_thread_cthreadstate_t;
379
380 #define i386_THREAD_CTHREADSTATE_COUNT \
381 ( sizeof (i386_thread_cthreadstate_t) / sizeof (int) )
382
383 #endif /* _MACH_I386_THREAD_STATUS_H_ */