]> git.saurik.com Git - apple/xnu.git/blame - osfmk/mach/i386/thread_status.h
xnu-2050.48.11.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
bd504ef0 113/* 14 and 15 are used for the internal x86_SAVED_STATE flavours */
060df5ea
A
114#define x86_AVX_STATE32 16
115#define x86_AVX_STATE64 17
bd504ef0 116#define x86_AVX_STATE 18
060df5ea 117
8ad349bb 118
6601e61a
A
119/*
120 * Largest state on this machine:
121 * (be sure mach/machine/thread_state.h matches!)
122 */
123#define THREAD_MACHINE_STATE_MAX THREAD_STATE_MAX
124
6601e61a 125/*
0c530ab8
A
126 * VALID_THREAD_STATE_FLAVOR is a platform specific macro that when passed
127 * an exception flavor will return if that is a defined flavor for that
128 * platform. The macro must be manually updated to include all of the valid
129 * exception flavors as defined above.
6601e61a 130 */
0c530ab8 131#define VALID_THREAD_STATE_FLAVOR(x) \
2d21ac55
A
132 ((x == x86_THREAD_STATE32) || \
133 (x == x86_FLOAT_STATE32) || \
134 (x == x86_EXCEPTION_STATE32) || \
135 (x == x86_DEBUG_STATE32) || \
136 (x == x86_THREAD_STATE64) || \
137 (x == x86_FLOAT_STATE64) || \
138 (x == x86_EXCEPTION_STATE64) || \
139 (x == x86_DEBUG_STATE64) || \
140 (x == x86_THREAD_STATE) || \
141 (x == x86_FLOAT_STATE) || \
142 (x == x86_EXCEPTION_STATE) || \
143 (x == x86_DEBUG_STATE) || \
060df5ea
A
144 (x == x86_AVX_STATE32) || \
145 (x == x86_AVX_STATE64) || \
bd504ef0 146 (x == x86_AVX_STATE) || \
2d21ac55 147 (x == THREAD_STATE_NONE))
6601e61a 148
0c530ab8 149struct x86_state_hdr {
2d21ac55
A
150 int flavor;
151 int count;
6601e61a 152};
0c530ab8 153typedef struct x86_state_hdr x86_state_hdr_t;
6601e61a 154
c0fea474
A
155/*
156 * Default segment register values.
157 */
158
159#define USER_CODE_SELECTOR 0x0017
160#define USER_DATA_SELECTOR 0x001f
161#define KERN_CODE_SELECTOR 0x0008
162#define KERN_DATA_SELECTOR 0x0010
163
c0fea474 164/*
2d21ac55 165 * to be deprecated in the future
4452a7af 166 */
2d21ac55
A
167typedef _STRUCT_X86_THREAD_STATE32 i386_thread_state_t;
168#define i386_THREAD_STATE_COUNT ((mach_msg_type_number_t) \
169 ( sizeof (i386_thread_state_t) / sizeof (int) ))
89b3af67 170
2d21ac55
A
171typedef _STRUCT_X86_THREAD_STATE32 x86_thread_state32_t;
172#define x86_THREAD_STATE32_COUNT ((mach_msg_type_number_t) \
173 ( sizeof (x86_thread_state32_t) / sizeof (int) ))
c0fea474
A
174
175/*
2d21ac55 176 * to be deprecated in the future
c0fea474 177 */
2d21ac55 178typedef _STRUCT_X86_FLOAT_STATE32 i386_float_state_t;
0c530ab8
A
179#define i386_FLOAT_STATE_COUNT ((mach_msg_type_number_t) \
180 (sizeof(i386_float_state_t)/sizeof(unsigned int)))
2d21ac55
A
181
182typedef _STRUCT_X86_FLOAT_STATE32 x86_float_state32_t;
c0fea474
A
183#define x86_FLOAT_STATE32_COUNT ((mach_msg_type_number_t) \
184 (sizeof(x86_float_state32_t)/sizeof(unsigned int)))
c0fea474 185
060df5ea
A
186typedef _STRUCT_X86_AVX_STATE32 x86_avx_state32_t;
187#define x86_AVX_STATE32_COUNT ((mach_msg_type_number_t) \
188 (sizeof(x86_avx_state32_t)/sizeof(unsigned int)))
189
c0fea474 190/*
2d21ac55 191 * to be deprecated in the future
c0fea474 192 */
2d21ac55 193typedef _STRUCT_X86_EXCEPTION_STATE32 i386_exception_state_t;
0c530ab8
A
194#define i386_EXCEPTION_STATE_COUNT ((mach_msg_type_number_t) \
195 ( sizeof (i386_exception_state_t) / sizeof (int) ))
196
2d21ac55 197typedef _STRUCT_X86_EXCEPTION_STATE32 x86_exception_state32_t;
c0fea474
A
198#define x86_EXCEPTION_STATE32_COUNT ((mach_msg_type_number_t) \
199 ( sizeof (x86_exception_state32_t) / sizeof (int) ))
200
2d21ac55 201#define I386_EXCEPTION_STATE_COUNT i386_EXCEPTION_STATE_COUNT
c0fea474 202
2d21ac55 203typedef _STRUCT_X86_DEBUG_STATE32 x86_debug_state32_t;
c0fea474
A
204#define x86_DEBUG_STATE32_COUNT ((mach_msg_type_number_t) \
205 ( sizeof (x86_debug_state32_t) / sizeof (int) ))
c0fea474 206
2d21ac55 207#define X86_DEBUG_STATE32_COUNT x86_DEBUG_STATE32_COUNT
c0fea474 208
2d21ac55
A
209typedef _STRUCT_X86_THREAD_STATE64 x86_thread_state64_t;
210#define x86_THREAD_STATE64_COUNT ((mach_msg_type_number_t) \
211 ( sizeof (x86_thread_state64_t) / sizeof (int) ))
c0fea474 212
2d21ac55
A
213typedef _STRUCT_X86_FLOAT_STATE64 x86_float_state64_t;
214#define x86_FLOAT_STATE64_COUNT ((mach_msg_type_number_t) \
215 (sizeof(x86_float_state64_t)/sizeof(unsigned int)))
060df5ea
A
216
217typedef _STRUCT_X86_AVX_STATE64 x86_avx_state64_t;
218#define x86_AVX_STATE64_COUNT ((mach_msg_type_number_t) \
219 (sizeof(x86_avx_state64_t)/sizeof(unsigned int)))
220
2d21ac55 221typedef _STRUCT_X86_EXCEPTION_STATE64 x86_exception_state64_t;
c0fea474
A
222#define x86_EXCEPTION_STATE64_COUNT ((mach_msg_type_number_t) \
223 ( sizeof (x86_exception_state64_t) / sizeof (int) ))
224
2d21ac55 225#define X86_EXCEPTION_STATE64_COUNT x86_EXCEPTION_STATE64_COUNT
c0fea474 226
2d21ac55 227typedef _STRUCT_X86_DEBUG_STATE64 x86_debug_state64_t;
c0fea474
A
228#define x86_DEBUG_STATE64_COUNT ((mach_msg_type_number_t) \
229 ( sizeof (x86_debug_state64_t) / sizeof (int) ))
230
231#define X86_DEBUG_STATE64_COUNT x86_DEBUG_STATE64_COUNT
232
2d21ac55
A
233/*
234 * Combined thread, float and exception states
235 */
236struct x86_thread_state {
237 x86_state_hdr_t tsh;
238 union {
239 x86_thread_state32_t ts32;
240 x86_thread_state64_t ts64;
241 } uts;
242};
c0fea474 243
2d21ac55
A
244struct x86_float_state {
245 x86_state_hdr_t fsh;
246 union {
247 x86_float_state32_t fs32;
248 x86_float_state64_t fs64;
249 } ufs;
250};
c0fea474
A
251
252struct x86_exception_state {
2d21ac55
A
253 x86_state_hdr_t esh;
254 union {
255 x86_exception_state32_t es32;
256 x86_exception_state64_t es64;
257 } ues;
258};
c0fea474
A
259
260struct x86_debug_state {
261 x86_state_hdr_t dsh;
262 union {
263 x86_debug_state32_t ds32;
264 x86_debug_state64_t ds64;
265 } uds;
266};
267
bd504ef0
A
268struct x86_avx_state {
269 x86_state_hdr_t ash;
270 union {
271 x86_avx_state32_t as32;
272 x86_avx_state64_t as64;
273 } ufs;
274};
275
2d21ac55
A
276typedef struct x86_thread_state x86_thread_state_t;
277#define x86_THREAD_STATE_COUNT ((mach_msg_type_number_t) \
278 ( sizeof (x86_thread_state_t) / sizeof (int) ))
c0fea474 279
2d21ac55
A
280typedef struct x86_float_state x86_float_state_t;
281#define x86_FLOAT_STATE_COUNT ((mach_msg_type_number_t) \
282 (sizeof(x86_float_state_t)/sizeof(unsigned int)))
283
284typedef struct x86_exception_state x86_exception_state_t;
285#define x86_EXCEPTION_STATE_COUNT ((mach_msg_type_number_t) \
286 (sizeof(x86_exception_state_t)/sizeof(unsigned int)))
c0fea474
A
287
288typedef struct x86_debug_state x86_debug_state_t;
289#define x86_DEBUG_STATE_COUNT ((mach_msg_type_number_t) \
290 (sizeof(x86_debug_state_t)/sizeof(unsigned int)))
291
bd504ef0
A
292typedef struct x86_avx_state x86_avx_state_t;
293#define x86_AVX_STATE_COUNT ((mach_msg_type_number_t) \
294 (sizeof(x86_avx_state_t)/sizeof(unsigned int)))
295
0c530ab8
A
296/*
297 * Machine-independent way for servers and Mach's exception mechanism to
298 * choose the most efficient state flavor for exception RPC's:
299 */
300#define MACHINE_THREAD_STATE x86_THREAD_STATE
301#define MACHINE_THREAD_STATE_COUNT x86_THREAD_STATE_COUNT
302
4452a7af 303/*
0c530ab8
A
304 * when reloading the segment registers on
305 * a return out of the kernel, we may take
306 * a GeneralProtection or SegmentNotPresent
307 * fault if one or more of the segment
308 * registers in the saved state was improperly
309 * specified via an x86_THREAD_STATE32 call
310 * the frame we push on top of the existing
311 * save area looks like this... we need to
312 * carry this as part of the save area
313 * in case we get hit so that we have a big
314 * enough stack
315 */
316struct x86_seg_load_fault32 {
6d2010ae
A
317 uint16_t trapno;
318 uint16_t cpu;
319 uint32_t err;
320 uint32_t eip;
321 uint32_t cs;
322 uint32_t efl;
0c530ab8
A
323};
324
2d21ac55
A
325#ifdef XNU_KERNEL_PRIVATE
326
327#define x86_SAVED_STATE32 THREAD_STATE_NONE + 1
328#define x86_SAVED_STATE64 THREAD_STATE_NONE + 2
0c530ab8
A
329
330/*
331 * Subset of saved state stored by processor on kernel-to-kernel
332 * trap. (Used by ddb to examine state guaranteed to be present
333 * on all traps into debugger.)
334 */
335struct x86_saved_state32_from_kernel {
6d2010ae
A
336 uint32_t gs;
337 uint32_t fs;
338 uint32_t es;
339 uint32_t ds;
340 uint32_t edi;
341 uint32_t esi;
342 uint32_t ebp;
343 uint32_t cr2; /* kernel esp stored by pusha - we save cr2 here later */
344 uint32_t ebx;
345 uint32_t edx;
346 uint32_t ecx;
347 uint32_t eax;
348 uint16_t trapno;
349 uint16_t cpu;
350 uint32_t err;
351 uint32_t eip;
352 uint32_t cs;
353 uint32_t efl;
0c530ab8
A
354};
355
356/*
357 * The format in which thread state is saved by Mach on this machine. This
358 * state flavor is most efficient for exception RPC's to kernel-loaded
359 * servers, because copying can be avoided:
1c79356b 360 */
0c530ab8 361struct x86_saved_state32 {
6d2010ae
A
362 uint32_t gs;
363 uint32_t fs;
364 uint32_t es;
365 uint32_t ds;
366 uint32_t edi;
367 uint32_t esi;
368 uint32_t ebp;
369 uint32_t cr2; /* kernel esp stored by pusha - we save cr2 here later */
370 uint32_t ebx;
371 uint32_t edx;
372 uint32_t ecx;
373 uint32_t eax;
374 uint16_t trapno;
375 uint16_t cpu;
376 uint32_t err;
377 uint32_t eip;
378 uint32_t cs;
379 uint32_t efl;
380 uint32_t uesp;
381 uint32_t ss;
0c530ab8
A
382};
383typedef struct x86_saved_state32 x86_saved_state32_t;
6601e61a 384
0c530ab8
A
385#define x86_SAVED_STATE32_COUNT ((mach_msg_type_number_t) \
386 (sizeof (x86_saved_state32_t)/sizeof(unsigned int)))
387
b0d623f7 388#pragma pack(4)
0c530ab8
A
389struct x86_saved_state32_tagged {
390 uint32_t tag;
391 struct x86_saved_state32 state;
392};
393typedef struct x86_saved_state32_tagged x86_saved_state32_tagged_t;
6d2010ae 394/* Note: sizeof(x86_saved_state32_tagged_t) is a multiple of 16 bytes */
0c530ab8
A
395
396struct x86_sframe32 {
4a3eedf9 397 /*
0c530ab8
A
398 * in case we throw a fault reloading
399 * segment registers on a return out of
400 * the kernel... the 'slf' state is only kept
401 * long enough to rejigger (i.e. restore
402 * the save area to its original state)
403 * the save area and throw the appropriate
404 * kernel trap pointing to the 'ssf' state
405 */
406 struct x86_seg_load_fault32 slf;
407 struct x86_saved_state32_tagged ssf;
408};
409typedef struct x86_sframe32 x86_sframe32_t;
410
0c530ab8
A
411/*
412 * This is the state pushed onto the 64-bit interrupt stack
413 * on any exception/trap/interrupt.
414 */
415struct x86_64_intr_stack_frame {
6d2010ae
A
416 uint16_t trapno;
417 uint16_t cpu;
b0d623f7
A
418 uint32_t _pad;
419 uint64_t trapfn;
0c530ab8
A
420 uint64_t err;
421 uint64_t rip;
422 uint64_t cs;
423 uint64_t rflags;
424 uint64_t rsp;
425 uint64_t ss;
426};
427typedef struct x86_64_intr_stack_frame x86_64_intr_stack_frame_t;
6d2010ae 428/* Note: sizeof(x86_64_intr_stack_frame_t) must be a multiple of 16 bytes */
0c530ab8
A
429
430/*
431 * This defines the state saved before entry into compatibility mode.
432 * The machine state is pushed automatically and the compat state is
433 * synthethized in the exception handling code.
434 */
435struct x86_saved_state_compat32 {
436 struct x86_saved_state32_tagged iss32;
6d2010ae 437 struct x86_64_intr_stack_frame isf64;
0c530ab8
A
438};
439typedef struct x86_saved_state_compat32 x86_saved_state_compat32_t;
440
0c530ab8 441struct x86_sframe_compat32 {
6d2010ae
A
442 uint32_t pad_for_16byte_alignment[2];
443 uint64_t _register_save_slot;
0c530ab8 444 struct x86_64_intr_stack_frame slf;
0c530ab8 445 struct x86_saved_state_compat32 ssf;
0c530ab8
A
446};
447typedef struct x86_sframe_compat32 x86_sframe_compat32_t;
6d2010ae 448/* Note: sizeof(x86_sframe_compat32_t) must be a multiple of 16 bytes */
0c530ab8 449
0c530ab8
A
450/*
451 * thread state format for task running in 64bit long mode
452 * in long mode, the same hardware frame is always pushed regardless
453 * of whether there was a change in privlege level... therefore, there
454 * is no need for an x86_saved_state64_from_kernel variant
455 */
0c530ab8
A
456struct x86_saved_state64 {
457 /*
458 * saved state organized to reflect the
459 * system call ABI register convention
460 * so that we can just pass a pointer
461 * to the saved state when calling through
462 * to the actual system call functions
463 * the ABI limits us to 6 args passed in
464 * registers... I've add v_arg6 - v_arg8
465 * to accomodate our most 'greedy' system
466 * calls (both BSD and MACH)... the individual
467 * system call handlers will fill these in
468 * via copyin if needed...
469 */
470 uint64_t rdi; /* arg0 for system call */
471 uint64_t rsi;
472 uint64_t rdx;
473 uint64_t r10;
474 uint64_t r8;
475 uint64_t r9; /* arg5 for system call */
476 uint64_t v_arg6;
477 uint64_t v_arg7;
478 uint64_t v_arg8;
479
480 uint64_t cr2;
481 uint64_t r15;
482 uint64_t r14;
483 uint64_t r13;
484 uint64_t r12;
485 uint64_t r11;
486 uint64_t rbp;
487 uint64_t rbx;
488 uint64_t rcx;
489 uint64_t rax;
490
491 uint32_t gs;
492 uint32_t fs;
6d2010ae
A
493
494 uint32_t _pad_for_tagged_alignment[3];
495
0c530ab8
A
496 struct x86_64_intr_stack_frame isf;
497};
498typedef struct x86_saved_state64 x86_saved_state64_t;
499#define x86_SAVED_STATE64_COUNT ((mach_msg_type_number_t) \
500 (sizeof (struct x86_saved_state64)/sizeof(unsigned int)))
501
502struct x86_saved_state64_tagged {
503 uint32_t tag;
504 x86_saved_state64_t state;
505};
506typedef struct x86_saved_state64_tagged x86_saved_state64_tagged_t;
507
508struct x86_sframe64 {
6d2010ae
A
509 uint64_t _register_save_slot[2];
510 struct x86_64_intr_stack_frame slf;
511 x86_saved_state64_tagged_t ssf;
0c530ab8
A
512};
513typedef struct x86_sframe64 x86_sframe64_t;
6d2010ae 514/* Note: sizeof(x86_sframe64_t) is a multiple of 16 bytes */
0c530ab8
A
515
516extern uint32_t get_eflags_exportmask(void);
2d21ac55 517
0c530ab8
A
518/*
519 * Unified, tagged saved state:
520 */
521typedef struct {
522 uint32_t flavor;
523 union {
524 x86_saved_state32_t ss_32;
525 x86_saved_state64_t ss_64;
526 } uss;
527} x86_saved_state_t;
528#define ss_32 uss.ss_32
529#define ss_64 uss.ss_64
b0d623f7 530#pragma pack()
0c530ab8
A
531
532static inline boolean_t
533is_saved_state64(x86_saved_state_t *iss)
534{
535 return (iss->flavor == x86_SAVED_STATE64);
536}
537
538static inline boolean_t
539is_saved_state32(x86_saved_state_t *iss)
540{
541 return (iss->flavor == x86_SAVED_STATE32);
542}
543
544static inline x86_saved_state32_t *
545saved_state32(x86_saved_state_t *iss)
546{
547 return &iss->ss_32;
548}
549
550static inline x86_saved_state64_t *
551saved_state64(x86_saved_state_t *iss)
552{
553 return &iss->ss_64;
554}
555
556#endif /* XNU_KERNEL_PRIVATE */
1c79356b
A
557
558#endif /* _MACH_I386_THREAD_STATUS_H_ */