]> git.saurik.com Git - apple/xnu.git/blame - osfmk/mach/i386/thread_status.h
xnu-1228.9.59.tar.gz
[apple/xnu.git] / osfmk / mach / i386 / thread_status.h
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * @OSF_COPYRIGHT@
30 */
31/*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
35 *
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
41 *
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45 *
46 * Carnegie Mellon requests users of this software to return to
47 *
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
52 *
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
55 */
56/*
57 */
58/*
59 * File: thread_status.h
60 * Author: Avadis Tevanian, Jr.
61 * Date: 1985
62 *
63 * This file contains the structure definitions for the thread
64 * state as applied to I386 processors.
65 */
66
67#ifndef _MACH_I386_THREAD_STATUS_H_
68#define _MACH_I386_THREAD_STATUS_H_
69
2d21ac55 70#include <mach/i386/_structs.h>
91447636 71#include <mach/message.h>
1c79356b
A
72#include <mach/i386/fp_reg.h>
73#include <mach/i386/thread_state.h>
0c530ab8
A
74#include <i386/eflags.h>
75
1c79356b 76/*
0c530ab8
A
77 * the i386_xxxx form is kept for legacy purposes since these types
78 * are externally known... eventually they should be deprecated.
79 * our internal implementation has moved to the following naming convention
6601e61a 80 *
0c530ab8
A
81 * x86_xxxx32 names are used to deal with 32 bit states
82 * x86_xxxx64 names are used to deal with 64 bit states
83 * x86_xxxx names are used to deal with either 32 or 64 bit states
84 * via a self-describing mechanism
c0fea474
A
85 */
86
c0fea474 87/*
0c530ab8
A
88 * these are the legacy names which should be deprecated in the future
89 * they are externally known which is the only reason we don't just get
90 * rid of them
91 */
92#define i386_THREAD_STATE 1
93#define i386_FLOAT_STATE 2
94#define i386_EXCEPTION_STATE 3
95
0c530ab8 96/*
c0fea474
A
97 * THREAD_STATE_FLAVOR_LIST 0
98 * these are the supported flavors
1c79356b 99 */
c0fea474
A
100#define x86_THREAD_STATE32 1
101#define x86_FLOAT_STATE32 2
102#define x86_EXCEPTION_STATE32 3
103#define x86_THREAD_STATE64 4
104#define x86_FLOAT_STATE64 5
105#define x86_EXCEPTION_STATE64 6
106#define x86_THREAD_STATE 7
107#define x86_FLOAT_STATE 8
108#define x86_EXCEPTION_STATE 9
109#define x86_DEBUG_STATE32 10
110#define x86_DEBUG_STATE64 11
111#define x86_DEBUG_STATE 12
0c530ab8 112#define THREAD_STATE_NONE 13
8ad349bb 113
6601e61a
A
114/*
115 * Largest state on this machine:
116 * (be sure mach/machine/thread_state.h matches!)
117 */
118#define THREAD_MACHINE_STATE_MAX THREAD_STATE_MAX
119
6601e61a 120/*
0c530ab8
A
121 * VALID_THREAD_STATE_FLAVOR is a platform specific macro that when passed
122 * an exception flavor will return if that is a defined flavor for that
123 * platform. The macro must be manually updated to include all of the valid
124 * exception flavors as defined above.
6601e61a 125 */
0c530ab8 126#define VALID_THREAD_STATE_FLAVOR(x) \
2d21ac55
A
127 ((x == x86_THREAD_STATE32) || \
128 (x == x86_FLOAT_STATE32) || \
129 (x == x86_EXCEPTION_STATE32) || \
130 (x == x86_DEBUG_STATE32) || \
131 (x == x86_THREAD_STATE64) || \
132 (x == x86_FLOAT_STATE64) || \
133 (x == x86_EXCEPTION_STATE64) || \
134 (x == x86_DEBUG_STATE64) || \
135 (x == x86_THREAD_STATE) || \
136 (x == x86_FLOAT_STATE) || \
137 (x == x86_EXCEPTION_STATE) || \
138 (x == x86_DEBUG_STATE) || \
139 (x == THREAD_STATE_NONE))
6601e61a 140
0c530ab8 141struct x86_state_hdr {
2d21ac55
A
142 int flavor;
143 int count;
6601e61a 144};
0c530ab8 145typedef struct x86_state_hdr x86_state_hdr_t;
6601e61a 146
c0fea474
A
147/*
148 * Default segment register values.
149 */
150
151#define USER_CODE_SELECTOR 0x0017
152#define USER_DATA_SELECTOR 0x001f
153#define KERN_CODE_SELECTOR 0x0008
154#define KERN_DATA_SELECTOR 0x0010
155
c0fea474 156/*
2d21ac55 157 * to be deprecated in the future
4452a7af 158 */
2d21ac55
A
159typedef _STRUCT_X86_THREAD_STATE32 i386_thread_state_t;
160#define i386_THREAD_STATE_COUNT ((mach_msg_type_number_t) \
161 ( sizeof (i386_thread_state_t) / sizeof (int) ))
89b3af67 162
2d21ac55
A
163typedef _STRUCT_X86_THREAD_STATE32 x86_thread_state32_t;
164#define x86_THREAD_STATE32_COUNT ((mach_msg_type_number_t) \
165 ( sizeof (x86_thread_state32_t) / sizeof (int) ))
c0fea474
A
166
167/*
2d21ac55 168 * to be deprecated in the future
c0fea474 169 */
2d21ac55 170typedef _STRUCT_X86_FLOAT_STATE32 i386_float_state_t;
0c530ab8
A
171#define i386_FLOAT_STATE_COUNT ((mach_msg_type_number_t) \
172 (sizeof(i386_float_state_t)/sizeof(unsigned int)))
2d21ac55
A
173
174typedef _STRUCT_X86_FLOAT_STATE32 x86_float_state32_t;
c0fea474
A
175#define x86_FLOAT_STATE32_COUNT ((mach_msg_type_number_t) \
176 (sizeof(x86_float_state32_t)/sizeof(unsigned int)))
c0fea474
A
177
178/*
2d21ac55 179 * to be deprecated in the future
c0fea474 180 */
2d21ac55 181typedef _STRUCT_X86_EXCEPTION_STATE32 i386_exception_state_t;
0c530ab8
A
182#define i386_EXCEPTION_STATE_COUNT ((mach_msg_type_number_t) \
183 ( sizeof (i386_exception_state_t) / sizeof (int) ))
184
2d21ac55 185typedef _STRUCT_X86_EXCEPTION_STATE32 x86_exception_state32_t;
c0fea474
A
186#define x86_EXCEPTION_STATE32_COUNT ((mach_msg_type_number_t) \
187 ( sizeof (x86_exception_state32_t) / sizeof (int) ))
188
2d21ac55 189#define I386_EXCEPTION_STATE_COUNT i386_EXCEPTION_STATE_COUNT
c0fea474 190
2d21ac55 191typedef _STRUCT_X86_DEBUG_STATE32 x86_debug_state32_t;
c0fea474
A
192#define x86_DEBUG_STATE32_COUNT ((mach_msg_type_number_t) \
193 ( sizeof (x86_debug_state32_t) / sizeof (int) ))
c0fea474 194
2d21ac55 195#define X86_DEBUG_STATE32_COUNT x86_DEBUG_STATE32_COUNT
c0fea474 196
2d21ac55
A
197typedef _STRUCT_X86_THREAD_STATE64 x86_thread_state64_t;
198#define x86_THREAD_STATE64_COUNT ((mach_msg_type_number_t) \
199 ( sizeof (x86_thread_state64_t) / sizeof (int) ))
c0fea474 200
2d21ac55
A
201typedef _STRUCT_X86_FLOAT_STATE64 x86_float_state64_t;
202#define x86_FLOAT_STATE64_COUNT ((mach_msg_type_number_t) \
203 (sizeof(x86_float_state64_t)/sizeof(unsigned int)))
204
205typedef _STRUCT_X86_EXCEPTION_STATE64 x86_exception_state64_t;
c0fea474
A
206#define x86_EXCEPTION_STATE64_COUNT ((mach_msg_type_number_t) \
207 ( sizeof (x86_exception_state64_t) / sizeof (int) ))
208
2d21ac55 209#define X86_EXCEPTION_STATE64_COUNT x86_EXCEPTION_STATE64_COUNT
c0fea474 210
2d21ac55 211typedef _STRUCT_X86_DEBUG_STATE64 x86_debug_state64_t;
c0fea474
A
212#define x86_DEBUG_STATE64_COUNT ((mach_msg_type_number_t) \
213 ( sizeof (x86_debug_state64_t) / sizeof (int) ))
214
215#define X86_DEBUG_STATE64_COUNT x86_DEBUG_STATE64_COUNT
216
2d21ac55
A
217/*
218 * Combined thread, float and exception states
219 */
220struct x86_thread_state {
221 x86_state_hdr_t tsh;
222 union {
223 x86_thread_state32_t ts32;
224 x86_thread_state64_t ts64;
225 } uts;
226};
c0fea474 227
2d21ac55
A
228struct x86_float_state {
229 x86_state_hdr_t fsh;
230 union {
231 x86_float_state32_t fs32;
232 x86_float_state64_t fs64;
233 } ufs;
234};
c0fea474
A
235
236struct x86_exception_state {
2d21ac55
A
237 x86_state_hdr_t esh;
238 union {
239 x86_exception_state32_t es32;
240 x86_exception_state64_t es64;
241 } ues;
242};
c0fea474
A
243
244struct x86_debug_state {
245 x86_state_hdr_t dsh;
246 union {
247 x86_debug_state32_t ds32;
248 x86_debug_state64_t ds64;
249 } uds;
250};
251
2d21ac55
A
252typedef struct x86_thread_state x86_thread_state_t;
253#define x86_THREAD_STATE_COUNT ((mach_msg_type_number_t) \
254 ( sizeof (x86_thread_state_t) / sizeof (int) ))
c0fea474 255
2d21ac55
A
256typedef struct x86_float_state x86_float_state_t;
257#define x86_FLOAT_STATE_COUNT ((mach_msg_type_number_t) \
258 (sizeof(x86_float_state_t)/sizeof(unsigned int)))
259
260typedef struct x86_exception_state x86_exception_state_t;
261#define x86_EXCEPTION_STATE_COUNT ((mach_msg_type_number_t) \
262 (sizeof(x86_exception_state_t)/sizeof(unsigned int)))
c0fea474
A
263
264typedef struct x86_debug_state x86_debug_state_t;
265#define x86_DEBUG_STATE_COUNT ((mach_msg_type_number_t) \
266 (sizeof(x86_debug_state_t)/sizeof(unsigned int)))
267
0c530ab8
A
268/*
269 * Machine-independent way for servers and Mach's exception mechanism to
270 * choose the most efficient state flavor for exception RPC's:
271 */
272#define MACHINE_THREAD_STATE x86_THREAD_STATE
273#define MACHINE_THREAD_STATE_COUNT x86_THREAD_STATE_COUNT
274
4452a7af 275/*
0c530ab8
A
276 * when reloading the segment registers on
277 * a return out of the kernel, we may take
278 * a GeneralProtection or SegmentNotPresent
279 * fault if one or more of the segment
280 * registers in the saved state was improperly
281 * specified via an x86_THREAD_STATE32 call
282 * the frame we push on top of the existing
283 * save area looks like this... we need to
284 * carry this as part of the save area
285 * in case we get hit so that we have a big
286 * enough stack
287 */
288struct x86_seg_load_fault32 {
2d21ac55
A
289 unsigned int trapno;
290 unsigned int err;
291 unsigned int eip;
292 unsigned int cs;
293 unsigned int efl;
0c530ab8
A
294};
295
2d21ac55
A
296#ifdef XNU_KERNEL_PRIVATE
297
298#define x86_SAVED_STATE32 THREAD_STATE_NONE + 1
299#define x86_SAVED_STATE64 THREAD_STATE_NONE + 2
0c530ab8
A
300
301/*
302 * Subset of saved state stored by processor on kernel-to-kernel
303 * trap. (Used by ddb to examine state guaranteed to be present
304 * on all traps into debugger.)
305 */
306struct x86_saved_state32_from_kernel {
307 unsigned int gs;
308 unsigned int fs;
309 unsigned int es;
310 unsigned int ds;
311 unsigned int edi;
312 unsigned int esi;
313 unsigned int ebp;
314 unsigned int cr2; /* kernel esp stored by pusha - we save cr2 here later */
315 unsigned int ebx;
316 unsigned int edx;
317 unsigned int ecx;
318 unsigned int eax;
319 unsigned int trapno;
320 unsigned int err;
321 unsigned int eip;
322 unsigned int cs;
323 unsigned int efl;
324};
325
326/*
327 * The format in which thread state is saved by Mach on this machine. This
328 * state flavor is most efficient for exception RPC's to kernel-loaded
329 * servers, because copying can be avoided:
1c79356b 330 */
0c530ab8
A
331struct x86_saved_state32 {
332 unsigned int gs;
333 unsigned int fs;
334 unsigned int es;
335 unsigned int ds;
336 unsigned int edi;
337 unsigned int esi;
338 unsigned int ebp;
339 unsigned int cr2; /* kernel esp stored by pusha - we save cr2 here later */
340 unsigned int ebx;
341 unsigned int edx;
342 unsigned int ecx;
343 unsigned int eax;
344 unsigned int trapno;
345 unsigned int err;
346 unsigned int eip;
347 unsigned int cs;
348 unsigned int efl;
349 unsigned int uesp;
350 unsigned int ss;
351};
352typedef struct x86_saved_state32 x86_saved_state32_t;
6601e61a 353
0c530ab8
A
354#define x86_SAVED_STATE32_COUNT ((mach_msg_type_number_t) \
355 (sizeof (x86_saved_state32_t)/sizeof(unsigned int)))
356
357struct x86_saved_state32_tagged {
358 uint32_t tag;
359 struct x86_saved_state32 state;
360};
361typedef struct x86_saved_state32_tagged x86_saved_state32_tagged_t;
362
363struct x86_sframe32 {
4a3eedf9 364 /*
0c530ab8
A
365 * in case we throw a fault reloading
366 * segment registers on a return out of
367 * the kernel... the 'slf' state is only kept
368 * long enough to rejigger (i.e. restore
369 * the save area to its original state)
370 * the save area and throw the appropriate
371 * kernel trap pointing to the 'ssf' state
372 */
373 struct x86_seg_load_fault32 slf;
374 struct x86_saved_state32_tagged ssf;
375};
376typedef struct x86_sframe32 x86_sframe32_t;
377
0c530ab8
A
378/*
379 * This is the state pushed onto the 64-bit interrupt stack
380 * on any exception/trap/interrupt.
381 */
382struct x86_64_intr_stack_frame {
383 uint32_t trapno;
384 uint32_t trapfn;
385 uint64_t err;
386 uint64_t rip;
387 uint64_t cs;
388 uint64_t rflags;
389 uint64_t rsp;
390 uint64_t ss;
391};
392typedef struct x86_64_intr_stack_frame x86_64_intr_stack_frame_t;
393
394/*
395 * This defines the state saved before entry into compatibility mode.
396 * The machine state is pushed automatically and the compat state is
397 * synthethized in the exception handling code.
398 */
399struct x86_saved_state_compat32 {
400 struct x86_saved_state32_tagged iss32;
401 uint32_t pad_for_16byte_alignment[2];
402 struct x86_64_intr_stack_frame isf64;
403};
404typedef struct x86_saved_state_compat32 x86_saved_state_compat32_t;
405
0c530ab8
A
406struct x86_sframe_compat32 {
407 struct x86_64_intr_stack_frame slf;
408 uint32_t pad_for_16byte_alignment[2];
409 struct x86_saved_state_compat32 ssf;
410 uint32_t empty[4];
411};
412typedef struct x86_sframe_compat32 x86_sframe_compat32_t;
413
0c530ab8
A
414/*
415 * thread state format for task running in 64bit long mode
416 * in long mode, the same hardware frame is always pushed regardless
417 * of whether there was a change in privlege level... therefore, there
418 * is no need for an x86_saved_state64_from_kernel variant
419 */
0c530ab8
A
420struct x86_saved_state64 {
421 /*
422 * saved state organized to reflect the
423 * system call ABI register convention
424 * so that we can just pass a pointer
425 * to the saved state when calling through
426 * to the actual system call functions
427 * the ABI limits us to 6 args passed in
428 * registers... I've add v_arg6 - v_arg8
429 * to accomodate our most 'greedy' system
430 * calls (both BSD and MACH)... the individual
431 * system call handlers will fill these in
432 * via copyin if needed...
433 */
434 uint64_t rdi; /* arg0 for system call */
435 uint64_t rsi;
436 uint64_t rdx;
437 uint64_t r10;
438 uint64_t r8;
439 uint64_t r9; /* arg5 for system call */
440 uint64_t v_arg6;
441 uint64_t v_arg7;
442 uint64_t v_arg8;
443
444 uint64_t cr2;
445 uint64_t r15;
446 uint64_t r14;
447 uint64_t r13;
448 uint64_t r12;
449 uint64_t r11;
450 uint64_t rbp;
451 uint64_t rbx;
452 uint64_t rcx;
453 uint64_t rax;
454
455 uint32_t gs;
456 uint32_t fs;
457 struct x86_64_intr_stack_frame isf;
458};
459typedef struct x86_saved_state64 x86_saved_state64_t;
460#define x86_SAVED_STATE64_COUNT ((mach_msg_type_number_t) \
461 (sizeof (struct x86_saved_state64)/sizeof(unsigned int)))
462
463struct x86_saved_state64_tagged {
464 uint32_t tag;
465 x86_saved_state64_t state;
466};
467typedef struct x86_saved_state64_tagged x86_saved_state64_tagged_t;
468
469struct x86_sframe64 {
470 struct x86_64_intr_stack_frame slf;
471 uint32_t pad_for_16byte_alignment[3];
472 struct x86_saved_state64_tagged ssf;
473};
474typedef struct x86_sframe64 x86_sframe64_t;
475
476extern uint32_t get_eflags_exportmask(void);
2d21ac55 477
0c530ab8
A
478/*
479 * Unified, tagged saved state:
480 */
481typedef struct {
482 uint32_t flavor;
483 union {
484 x86_saved_state32_t ss_32;
485 x86_saved_state64_t ss_64;
486 } uss;
487} x86_saved_state_t;
488#define ss_32 uss.ss_32
489#define ss_64 uss.ss_64
490
491static inline boolean_t
492is_saved_state64(x86_saved_state_t *iss)
493{
494 return (iss->flavor == x86_SAVED_STATE64);
495}
496
497static inline boolean_t
498is_saved_state32(x86_saved_state_t *iss)
499{
500 return (iss->flavor == x86_SAVED_STATE32);
501}
502
503static inline x86_saved_state32_t *
504saved_state32(x86_saved_state_t *iss)
505{
506 return &iss->ss_32;
507}
508
509static inline x86_saved_state64_t *
510saved_state64(x86_saved_state_t *iss)
511{
512 return &iss->ss_64;
513}
514
515#endif /* XNU_KERNEL_PRIVATE */
1c79356b
A
516
517#endif /* _MACH_I386_THREAD_STATUS_H_ */