]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/i386/thread_status.h
xnu-517.7.7.tar.gz
[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 * 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/i386/fp_reg.h>
65 #include <mach/i386/thread_state.h>
66 #include <architecture/i386/frame.h> /* FIXME */
67 #include <architecture/i386/fpu.h> /* FIXME */
68 /*
69 * i386_thread_state this is the structure that is exported
70 * to user threads for use in status/mutate
71 * calls. This structure should never
72 * change.
73 *
74 * i386_float_state exported to use threads for access to
75 * floating point registers. Try not to
76 * change this one, either.
77 *
78 * i386_isa_port_map_state exported to user threads to allow
79 * selective in/out operations
80 *
81 * i386_v86_assist_state
82 *
83 * thread_syscall_state
84 */
85
86 /* THREAD_STATE_FLAVOR_LIST 0 */
87 #define i386_NEW_THREAD_STATE 1 /* used to be i386_THREAD_STATE */
88 #define i386_FLOAT_STATE 2
89 #define i386_ISA_PORT_MAP_STATE 3
90 #define i386_V86_ASSIST_STATE 4
91 #define i386_REGS_SEGS_STATE 5
92 #define THREAD_SYSCALL_STATE 6
93 #define THREAD_STATE_NONE 7
94 #define i386_SAVED_STATE 8
95
96
97 /*
98 * VALID_THREAD_STATE_FLAVOR is a platform specific macro that when passed
99 * an exception flavor will return if that is a defined flavor for that
100 * platform. The macro must be manually updated to include all of the valid
101 * exception flavors as defined above.
102 */
103 #define VALID_THREAD_STATE_FLAVOR(x) \
104 ((x == i386_NEW_THREAD_STATE) || \
105 (x == i386_FLOAT_STATE) || \
106 (x == i386_ISA_PORT_MAP_STATE) || \
107 (x == i386_V86_ASSIST_STATE) || \
108 (x == i386_REGS_SEGS_STATE) || \
109 (x == THREAD_SYSCALL_STATE) || \
110 (x == THREAD_STATE_NONE) || \
111 (x == i386_SAVED_STATE))
112
113 /*
114 * This structure is used for both
115 * i386_THREAD_STATE and i386_REGS_SEGS_STATE.
116 */
117 struct i386_new_thread_state {
118 unsigned int gs;
119 unsigned int fs;
120 unsigned int es;
121 unsigned int ds;
122 unsigned int edi;
123 unsigned int esi;
124 unsigned int ebp;
125 unsigned int esp;
126 unsigned int ebx;
127 unsigned int edx;
128 unsigned int ecx;
129 unsigned int eax;
130 unsigned int eip;
131 unsigned int cs;
132 unsigned int efl;
133 unsigned int uesp;
134 unsigned int ss;
135 };
136 #define i386_NEW_THREAD_STATE_COUNT \
137 (sizeof (struct i386_new_thread_state)/sizeof(unsigned int))
138
139 /*
140 * Subset of saved state stored by processor on kernel-to-kernel
141 * trap. (Used by ddb to examine state guaranteed to be present
142 * on all traps into debugger.)
143 */
144 struct i386_saved_state_from_kernel {
145 unsigned int gs;
146 unsigned int fs;
147 unsigned int es;
148 unsigned int ds;
149 unsigned int edi;
150 unsigned int esi;
151 unsigned int ebp;
152 unsigned int esp; /* kernel esp stored by pusha -
153 we save cr2 here later */
154 unsigned int ebx;
155 unsigned int edx;
156 unsigned int ecx;
157 unsigned int eax;
158 unsigned int trapno;
159 unsigned int err;
160 unsigned int eip;
161 unsigned int cs;
162 unsigned int efl;
163 };
164
165 /*
166 * The format in which thread state is saved by Mach on this machine. This
167 * state flavor is most efficient for exception RPC's to kernel-loaded
168 * servers, because copying can be avoided:
169 */
170 struct i386_saved_state {
171 unsigned int gs;
172 unsigned int fs;
173 unsigned int es;
174 unsigned int ds;
175 unsigned int edi;
176 unsigned int esi;
177 unsigned int ebp;
178 unsigned int esp; /* kernel esp stored by pusha -
179 we save cr2 here later */
180 unsigned int ebx;
181 unsigned int edx;
182 unsigned int ecx;
183 unsigned int eax;
184 unsigned int trapno;
185 unsigned int err;
186 unsigned int eip;
187 unsigned int cs;
188 unsigned int efl;
189 unsigned int uesp;
190 unsigned int ss;
191 struct v86_segs {
192 unsigned int v86_es; /* virtual 8086 segment registers */
193 unsigned int v86_ds;
194 unsigned int v86_fs;
195 unsigned int v86_gs;
196 } v86_segs;
197 #define i386_SAVED_ARGV_COUNT 7
198 unsigned int argv_status; /* Boolean flag indicating whether or
199 * not Mach copied in the args */
200 unsigned int argv[i386_SAVED_ARGV_COUNT];
201 /* The return address, and the first several
202 * function call args from the stack, for
203 * efficient syscall exceptions */
204 };
205 #define i386_SAVED_STATE_COUNT (sizeof (struct i386_saved_state)/sizeof(unsigned int))
206 #define i386_REGS_SEGS_STATE_COUNT i386_SAVED_STATE_COUNT
207
208 /*
209 * Machine-independent way for servers and Mach's exception mechanism to
210 * choose the most efficient state flavor for exception RPC's:
211 */
212 #define MACHINE_THREAD_STATE i386_SAVED_STATE
213 #define MACHINE_THREAD_STATE_COUNT 144
214
215 /*
216 * Largest state on this machine:
217 * (be sure mach/machine/thread_state.h matches!)
218 */
219 #define THREAD_MACHINE_STATE_MAX THREAD_STATE_MAX
220
221 /*
222 * Floating point state.
223 *
224 * fpkind tells in what way floating point operations are supported.
225 * See the values for fp_kind in <mach/i386/fp_reg.h>.
226 *
227 * If the kind is FP_NO, then calls to set the state will fail, and
228 * thread_getstatus will return garbage for the rest of the state.
229 * If "initialized" is false, then the rest of the state is garbage.
230 * Clients can set "initialized" to false to force the coprocessor to
231 * be reset.
232 * "exc_status" is non-zero if the thread has noticed (but not
233 * proceeded from) a coprocessor exception. It contains the status
234 * word with the exception bits set. The status word in "fp_status"
235 * will have the exception bits turned off. If an exception bit in
236 * "fp_status" is turned on, then "exc_status" should be zero. This
237 * happens when the coprocessor exception is noticed after the system
238 * has context switched to some other thread.
239 *
240 * If kind is FP_387, then "state" is a i387_state. Other kinds might
241 * also use i387_state, but somebody will have to verify it (XXX).
242 * Note that the registers are ordered from top-of-stack down, not
243 * according to physical register number.
244 */
245
246 #define FP_STATE_BYTES 512
247
248 struct i386_float_state {
249 int fpkind; /* FP_NO..FP_387 (readonly) */
250 int initialized;
251 unsigned char hw_state[FP_STATE_BYTES]; /* actual "hardware" state */
252 int exc_status; /* exception status (readonly) */
253 };
254 #define i386_FLOAT_STATE_COUNT \
255 (sizeof(struct i386_float_state)/sizeof(unsigned int))
256
257
258 #define FP_old_STATE_BYTES \
259 (sizeof (struct i386_fp_save) + sizeof (struct i386_fp_regs))
260
261 struct i386_old_float_state {
262 int fpkind; /* FP_NO..FP_387 (readonly) */
263 int initialized;
264 unsigned char hw_state[FP_old_STATE_BYTES]; /* actual "hardware" state */
265 int exc_status; /* exception status (readonly) */
266 };
267 #define i386_old_FLOAT_STATE_COUNT \
268 (sizeof(struct i386_old_float_state)/sizeof(unsigned int))
269
270
271 #define PORT_MAP_BITS 0x400
272 struct i386_isa_port_map_state {
273 unsigned char pm[PORT_MAP_BITS>>3];
274 };
275
276 #define i386_ISA_PORT_MAP_STATE_COUNT \
277 (sizeof(struct i386_isa_port_map_state)/sizeof(unsigned int))
278
279 /*
280 * V8086 assist supplies a pointer to an interrupt
281 * descriptor table in task space.
282 */
283 struct i386_v86_assist_state {
284 unsigned int int_table; /* interrupt table address */
285 int int_count; /* interrupt table size */
286 };
287
288 struct v86_interrupt_table {
289 unsigned int count; /* count of pending interrupts */
290 unsigned short mask; /* ignore this interrupt if true */
291 unsigned short vec; /* vector to take */
292 };
293
294 #define i386_V86_ASSIST_STATE_COUNT \
295 (sizeof(struct i386_v86_assist_state)/sizeof(unsigned int))
296
297 struct thread_syscall_state {
298 unsigned eax;
299 unsigned edx;
300 unsigned efl;
301 unsigned eip;
302 unsigned esp;
303 };
304
305 #define i386_THREAD_SYSCALL_STATE_COUNT \
306 (sizeof(struct thread_syscall_state) / sizeof(unsigned int))
307
308 /*
309 * Main thread state consists of
310 * general registers, segment registers,
311 * eip and eflags.
312 */
313
314 #define i386_THREAD_STATE -1
315
316 typedef struct {
317 unsigned int eax;
318 unsigned int ebx;
319 unsigned int ecx;
320 unsigned int edx;
321 unsigned int edi;
322 unsigned int esi;
323 unsigned int ebp;
324 unsigned int esp;
325 unsigned int ss;
326 unsigned int eflags;
327 unsigned int eip;
328 unsigned int cs;
329 unsigned int ds;
330 unsigned int es;
331 unsigned int fs;
332 unsigned int gs;
333 } i386_thread_state_t;
334
335 #define i386_THREAD_STATE_COUNT \
336 ( sizeof (i386_thread_state_t) / sizeof (int) )
337
338 /*
339 * Default segment register values.
340 */
341
342 #define USER_CODE_SELECTOR 0x0017
343 #define USER_DATA_SELECTOR 0x001f
344 #define KERN_CODE_SELECTOR 0x0008
345 #define KERN_DATA_SELECTOR 0x0010
346
347 /*
348 * Thread floating point state
349 * includes FPU environment as
350 * well as the register stack.
351 */
352
353 #define i386_THREAD_FPSTATE -2
354
355 typedef struct {
356 fp_env_t environ;
357 fp_stack_t stack;
358 } i386_thread_fpstate_t;
359
360 #define i386_THREAD_FPSTATE_COUNT \
361 ( sizeof (i386_thread_fpstate_t) / sizeof (int) )
362
363 /*
364 * Extra state that may be
365 * useful to exception handlers.
366 */
367
368 #define i386_THREAD_EXCEPTSTATE -3
369
370 typedef struct {
371 unsigned int trapno;
372 err_code_t err;
373 } i386_thread_exceptstate_t;
374
375 #define i386_THREAD_EXCEPTSTATE_COUNT \
376 ( sizeof (i386_thread_exceptstate_t) / sizeof (int) )
377
378 /*
379 * Per-thread variable used
380 * to store 'self' id for cthreads.
381 */
382
383 #define i386_THREAD_CTHREADSTATE -4
384
385 typedef struct {
386 unsigned int self;
387 } i386_thread_cthreadstate_t;
388
389 #define i386_THREAD_CTHREADSTATE_COUNT \
390 ( sizeof (i386_thread_cthreadstate_t) / sizeof (int) )
391
392 #endif /* _MACH_I386_THREAD_STATUS_H_ */