2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
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.
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.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
59 * File: thread_status.h
60 * Author: Avadis Tevanian, Jr.
63 * This file contains the structure definitions for the thread
64 * state as applied to I386 processors.
67 #ifndef _MACH_I386_THREAD_STATUS_H_
68 #define _MACH_I386_THREAD_STATUS_H_
70 #include <mach/i386/_structs.h>
71 #include <mach/message.h>
72 #include <mach/i386/fp_reg.h>
73 #include <mach/i386/thread_state.h>
74 #include <i386/eflags.h>
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
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
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
92 #define i386_THREAD_STATE 1
93 #define i386_FLOAT_STATE 2
94 #define i386_EXCEPTION_STATE 3
97 * THREAD_STATE_FLAVOR_LIST 0
98 * these are the supported flavors
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
112 #define THREAD_STATE_NONE 13
113 /* 14 and 15 are used for the internal x86_SAVED_STATE flavours */
114 #define x86_AVX_STATE32 16
115 #define x86_AVX_STATE64 17
116 #define x86_AVX_STATE 18
120 * Largest state on this machine:
121 * (be sure mach/machine/thread_state.h matches!)
123 #define THREAD_MACHINE_STATE_MAX THREAD_STATE_MAX
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.
131 #define VALID_THREAD_STATE_FLAVOR(x) \
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) || \
144 (x == x86_AVX_STATE32) || \
145 (x == x86_AVX_STATE64) || \
146 (x == x86_AVX_STATE) || \
147 (x == THREAD_STATE_NONE))
149 struct x86_state_hdr
{
153 typedef struct x86_state_hdr x86_state_hdr_t
;
156 * Default segment register values.
159 #define USER_CODE_SELECTOR 0x0017
160 #define USER_DATA_SELECTOR 0x001f
161 #define KERN_CODE_SELECTOR 0x0008
162 #define KERN_DATA_SELECTOR 0x0010
165 * to be deprecated in the future
167 typedef _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) ))
171 typedef _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) ))
176 * to be deprecated in the future
178 typedef _STRUCT_X86_FLOAT_STATE32 i386_float_state_t
;
179 #define i386_FLOAT_STATE_COUNT ((mach_msg_type_number_t) \
180 (sizeof(i386_float_state_t)/sizeof(unsigned int)))
182 typedef _STRUCT_X86_FLOAT_STATE32 x86_float_state32_t
;
183 #define x86_FLOAT_STATE32_COUNT ((mach_msg_type_number_t) \
184 (sizeof(x86_float_state32_t)/sizeof(unsigned int)))
186 typedef _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)))
191 * to be deprecated in the future
193 typedef _STRUCT_X86_EXCEPTION_STATE32 i386_exception_state_t
;
194 #define i386_EXCEPTION_STATE_COUNT ((mach_msg_type_number_t) \
195 ( sizeof (i386_exception_state_t) / sizeof (int) ))
197 typedef _STRUCT_X86_EXCEPTION_STATE32 x86_exception_state32_t
;
198 #define x86_EXCEPTION_STATE32_COUNT ((mach_msg_type_number_t) \
199 ( sizeof (x86_exception_state32_t) / sizeof (int) ))
201 #define I386_EXCEPTION_STATE_COUNT i386_EXCEPTION_STATE_COUNT
203 typedef _STRUCT_X86_DEBUG_STATE32 x86_debug_state32_t
;
204 #define x86_DEBUG_STATE32_COUNT ((mach_msg_type_number_t) \
205 ( sizeof (x86_debug_state32_t) / sizeof (int) ))
207 #define X86_DEBUG_STATE32_COUNT x86_DEBUG_STATE32_COUNT
209 typedef _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) ))
213 typedef _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)))
217 typedef _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)))
221 typedef _STRUCT_X86_EXCEPTION_STATE64 x86_exception_state64_t
;
222 #define x86_EXCEPTION_STATE64_COUNT ((mach_msg_type_number_t) \
223 ( sizeof (x86_exception_state64_t) / sizeof (int) ))
225 #define X86_EXCEPTION_STATE64_COUNT x86_EXCEPTION_STATE64_COUNT
227 typedef _STRUCT_X86_DEBUG_STATE64 x86_debug_state64_t
;
228 #define x86_DEBUG_STATE64_COUNT ((mach_msg_type_number_t) \
229 ( sizeof (x86_debug_state64_t) / sizeof (int) ))
231 #define X86_DEBUG_STATE64_COUNT x86_DEBUG_STATE64_COUNT
234 * Combined thread, float and exception states
236 struct x86_thread_state
{
239 x86_thread_state32_t ts32
;
240 x86_thread_state64_t ts64
;
244 struct x86_float_state
{
247 x86_float_state32_t fs32
;
248 x86_float_state64_t fs64
;
252 struct x86_exception_state
{
255 x86_exception_state32_t es32
;
256 x86_exception_state64_t es64
;
260 struct x86_debug_state
{
263 x86_debug_state32_t ds32
;
264 x86_debug_state64_t ds64
;
268 struct x86_avx_state
{
271 x86_avx_state32_t as32
;
272 x86_avx_state64_t as64
;
276 typedef 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) ))
280 typedef 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)))
284 typedef 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)))
288 typedef 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)))
292 typedef 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)))
297 * Machine-independent way for servers and Mach's exception mechanism to
298 * choose the most efficient state flavor for exception RPC's:
300 #define MACHINE_THREAD_STATE x86_THREAD_STATE
301 #define MACHINE_THREAD_STATE_COUNT x86_THREAD_STATE_COUNT
303 #ifdef XNU_KERNEL_PRIVATE
305 #define x86_SAVED_STATE32 THREAD_STATE_NONE + 1
306 #define x86_SAVED_STATE64 THREAD_STATE_NONE + 2
309 * The format in which thread state is saved by Mach on this machine. This
310 * state flavor is most efficient for exception RPC's to kernel-loaded
311 * servers, because copying can be avoided:
313 struct x86_saved_state32
{
321 uint32_t cr2
; /* kernel esp stored by pusha - we save cr2 here later */
335 typedef struct x86_saved_state32 x86_saved_state32_t
;
337 #define x86_SAVED_STATE32_COUNT ((mach_msg_type_number_t) \
338 (sizeof (x86_saved_state32_t)/sizeof(unsigned int)))
343 * This is the state pushed onto the 64-bit interrupt stack
344 * on any exception/trap/interrupt.
346 struct x86_64_intr_stack_frame
{
358 typedef struct x86_64_intr_stack_frame x86_64_intr_stack_frame_t
;
359 _Static_assert((sizeof(x86_64_intr_stack_frame_t
) % 16) == 0,
360 "interrupt stack frame size must be a multiple of 16 bytes");
363 * thread state format for task running in 64bit long mode
364 * in long mode, the same hardware frame is always pushed regardless
365 * of whether there was a change in privilege level... therefore, there
366 * is no need for an x86_saved_state64_from_kernel variant
368 struct x86_saved_state64
{
369 uint64_t rdi
; /* arg0 for system call */
372 uint64_t r10
; /* R10 := RCX prior to syscall trap */
374 uint64_t r9
; /* arg5 for system call */
392 struct x86_64_intr_stack_frame isf
;
394 typedef struct x86_saved_state64 x86_saved_state64_t
;
395 #define x86_SAVED_STATE64_COUNT ((mach_msg_type_number_t) \
396 (sizeof (struct x86_saved_state64)/sizeof(unsigned int)))
398 extern uint32_t get_eflags_exportmask(void);
401 * Unified, tagged saved state:
405 uint32_t _pad_for_16byte_alignment
[3];
407 x86_saved_state32_t ss_32
;
408 x86_saved_state64_t ss_64
;
411 #define ss_32 uss.ss_32
412 #define ss_64 uss.ss_64
415 static inline boolean_t
416 is_saved_state64(x86_saved_state_t
*iss
)
418 return (iss
->flavor
== x86_SAVED_STATE64
);
421 static inline boolean_t
422 is_saved_state32(x86_saved_state_t
*iss
)
424 return (iss
->flavor
== x86_SAVED_STATE32
);
427 static inline x86_saved_state32_t
*
428 saved_state32(x86_saved_state_t
*iss
)
433 static inline x86_saved_state64_t
*
434 saved_state64(x86_saved_state_t
*iss
)
439 #endif /* XNU_KERNEL_PRIVATE */
441 #endif /* _MACH_I386_THREAD_STATUS_H_ */