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