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