2 * Copyright (c) 2000-2020 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/machine/_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 #include <i386/proc_reg.h>
81 * the i386_xxxx form is kept for legacy purposes since these types
82 * are externally known... eventually they should be deprecated.
83 * our internal implementation has moved to the following naming convention
85 * x86_xxxx32 names are used to deal with 32 bit states
86 * x86_xxxx64 names are used to deal with 64 bit states
87 * x86_xxxx names are used to deal with either 32 or 64 bit states
88 * via a self-describing mechanism
92 * these are the legacy names which should be deprecated in the future
93 * they are externally known which is the only reason we don't just get
96 #define i386_THREAD_STATE 1
97 #define i386_FLOAT_STATE 2
98 #define i386_EXCEPTION_STATE 3
101 * THREAD_STATE_FLAVOR_LIST 0
102 * these are the supported flavors
104 #define x86_THREAD_STATE32 1
105 #define x86_FLOAT_STATE32 2
106 #define x86_EXCEPTION_STATE32 3
107 #define x86_THREAD_STATE64 4
108 #define x86_FLOAT_STATE64 5
109 #define x86_EXCEPTION_STATE64 6
110 #define x86_THREAD_STATE 7
111 #define x86_FLOAT_STATE 8
112 #define x86_EXCEPTION_STATE 9
113 #define x86_DEBUG_STATE32 10
114 #define x86_DEBUG_STATE64 11
115 #define x86_DEBUG_STATE 12
116 #define THREAD_STATE_NONE 13
117 /* 14 and 15 are used for the internal x86_SAVED_STATE flavours */
118 /* Arrange for flavors to take sequential values, 32-bit, 64-bit, non-specific */
119 #define x86_AVX_STATE32 16
120 #define x86_AVX_STATE64 (x86_AVX_STATE32 + 1)
121 #define x86_AVX_STATE (x86_AVX_STATE32 + 2)
122 #define x86_AVX512_STATE32 19
123 #define x86_AVX512_STATE64 (x86_AVX512_STATE32 + 1)
124 #define x86_AVX512_STATE (x86_AVX512_STATE32 + 2)
125 #define x86_PAGEIN_STATE 22
126 #define x86_THREAD_FULL_STATE64 23
127 #define x86_INSTRUCTION_STATE 24
128 #define x86_LAST_BRANCH_STATE 25
131 * Largest state on this machine:
132 * (be sure mach/machine/thread_state.h matches!)
134 #define THREAD_MACHINE_STATE_MAX THREAD_STATE_MAX
137 * VALID_THREAD_STATE_FLAVOR is a platform specific macro that when passed
138 * an exception flavor will return if that is a defined flavor for that
139 * platform. The macro must be manually updated to include all of the valid
140 * exception flavors as defined above.
142 #define VALID_THREAD_STATE_FLAVOR(x) \
143 ((x == x86_THREAD_STATE32) || \
144 (x == x86_FLOAT_STATE32) || \
145 (x == x86_EXCEPTION_STATE32) || \
146 (x == x86_DEBUG_STATE32) || \
147 (x == x86_THREAD_STATE64) || \
148 (x == x86_THREAD_FULL_STATE64) || \
149 (x == x86_FLOAT_STATE64) || \
150 (x == x86_EXCEPTION_STATE64) || \
151 (x == x86_DEBUG_STATE64) || \
152 (x == x86_THREAD_STATE) || \
153 (x == x86_FLOAT_STATE) || \
154 (x == x86_EXCEPTION_STATE) || \
155 (x == x86_DEBUG_STATE) || \
156 (x == x86_AVX_STATE32) || \
157 (x == x86_AVX_STATE64) || \
158 (x == x86_AVX_STATE) || \
159 (x == x86_AVX512_STATE32) || \
160 (x == x86_AVX512_STATE64) || \
161 (x == x86_AVX512_STATE) || \
162 (x == x86_PAGEIN_STATE) || \
163 (x == x86_INSTRUCTION_STATE) || \
164 (x == x86_LAST_BRANCH_STATE) || \
165 (x == THREAD_STATE_NONE))
167 struct x86_state_hdr
{
171 typedef struct x86_state_hdr x86_state_hdr_t
;
174 * Default segment register values.
177 #define USER_CODE_SELECTOR 0x0017
178 #define USER_DATA_SELECTOR 0x001f
179 #define KERN_CODE_SELECTOR 0x0008
180 #define KERN_DATA_SELECTOR 0x0010
183 * to be deprecated in the future
185 typedef _STRUCT_X86_THREAD_STATE32 i386_thread_state_t
;
186 #define i386_THREAD_STATE_COUNT ((mach_msg_type_number_t) \
187 ( sizeof (i386_thread_state_t) / sizeof (int) ))
189 typedef _STRUCT_X86_THREAD_STATE32 x86_thread_state32_t
;
190 #define x86_THREAD_STATE32_COUNT ((mach_msg_type_number_t) \
191 ( sizeof (x86_thread_state32_t) / sizeof (int) ))
194 * to be deprecated in the future
196 typedef _STRUCT_X86_FLOAT_STATE32 i386_float_state_t
;
197 #define i386_FLOAT_STATE_COUNT ((mach_msg_type_number_t) \
198 (sizeof(i386_float_state_t)/sizeof(unsigned int)))
200 typedef _STRUCT_X86_FLOAT_STATE32 x86_float_state32_t
;
201 #define x86_FLOAT_STATE32_COUNT ((mach_msg_type_number_t) \
202 (sizeof(x86_float_state32_t)/sizeof(unsigned int)))
204 typedef _STRUCT_X86_AVX_STATE32 x86_avx_state32_t
;
205 #define x86_AVX_STATE32_COUNT ((mach_msg_type_number_t) \
206 (sizeof(x86_avx_state32_t)/sizeof(unsigned int)))
208 typedef _STRUCT_X86_AVX512_STATE32 x86_avx512_state32_t
;
209 #define x86_AVX512_STATE32_COUNT ((mach_msg_type_number_t) \
210 (sizeof(x86_avx512_state32_t)/sizeof(unsigned int)))
213 * to be deprecated in the future
215 typedef _STRUCT_X86_EXCEPTION_STATE32 i386_exception_state_t
;
216 #define i386_EXCEPTION_STATE_COUNT ((mach_msg_type_number_t) \
217 ( sizeof (i386_exception_state_t) / sizeof (int) ))
219 typedef _STRUCT_X86_EXCEPTION_STATE32 x86_exception_state32_t
;
220 #define x86_EXCEPTION_STATE32_COUNT ((mach_msg_type_number_t) \
221 ( sizeof (x86_exception_state32_t) / sizeof (int) ))
223 #define I386_EXCEPTION_STATE_COUNT i386_EXCEPTION_STATE_COUNT
225 typedef _STRUCT_X86_DEBUG_STATE32 x86_debug_state32_t
;
226 #define x86_DEBUG_STATE32_COUNT ((mach_msg_type_number_t) \
227 ( sizeof (x86_debug_state32_t) / sizeof (int) ))
229 #define X86_DEBUG_STATE32_COUNT x86_DEBUG_STATE32_COUNT
231 typedef _STRUCT_X86_THREAD_STATE64 x86_thread_state64_t
;
232 #define x86_THREAD_STATE64_COUNT ((mach_msg_type_number_t) \
233 ( sizeof (x86_thread_state64_t) / sizeof (int) ))
235 typedef _STRUCT_X86_THREAD_FULL_STATE64 x86_thread_full_state64_t
;
236 #define x86_THREAD_FULL_STATE64_COUNT ((mach_msg_type_number_t) \
237 ( sizeof (x86_thread_full_state64_t) / sizeof (int) ))
239 typedef _STRUCT_X86_FLOAT_STATE64 x86_float_state64_t
;
240 #define x86_FLOAT_STATE64_COUNT ((mach_msg_type_number_t) \
241 (sizeof(x86_float_state64_t)/sizeof(unsigned int)))
243 typedef _STRUCT_X86_AVX_STATE64 x86_avx_state64_t
;
244 #define x86_AVX_STATE64_COUNT ((mach_msg_type_number_t) \
245 (sizeof(x86_avx_state64_t)/sizeof(unsigned int)))
247 typedef _STRUCT_X86_AVX512_STATE64 x86_avx512_state64_t
;
248 #define x86_AVX512_STATE64_COUNT ((mach_msg_type_number_t) \
249 (sizeof(x86_avx512_state64_t)/sizeof(unsigned int)))
251 typedef _STRUCT_X86_EXCEPTION_STATE64 x86_exception_state64_t
;
252 #define x86_EXCEPTION_STATE64_COUNT ((mach_msg_type_number_t) \
253 ( sizeof (x86_exception_state64_t) / sizeof (int) ))
255 #define X86_EXCEPTION_STATE64_COUNT x86_EXCEPTION_STATE64_COUNT
257 typedef _STRUCT_X86_DEBUG_STATE64 x86_debug_state64_t
;
258 #define x86_DEBUG_STATE64_COUNT ((mach_msg_type_number_t) \
259 ( sizeof (x86_debug_state64_t) / sizeof (int) ))
261 #define X86_DEBUG_STATE64_COUNT x86_DEBUG_STATE64_COUNT
263 typedef _STRUCT_X86_PAGEIN_STATE x86_pagein_state_t
;
264 #define x86_PAGEIN_STATE_COUNT \
265 ((mach_msg_type_number_t)(sizeof(x86_pagein_state_t) / sizeof(int)))
267 #define X86_PAGEIN_STATE_COUNT x86_PAGEIN_STATE_COUNT
269 typedef _STRUCT_X86_INSTRUCTION_STATE x86_instruction_state_t
;
270 #define x86_INSTRUCTION_STATE_COUNT \
271 ((mach_msg_type_number_t)(sizeof(x86_instruction_state_t) / sizeof(int)))
273 #define X86_INSTRUCTION_STATE_COUNT x86_INSTRUCTION_STATE_COUNT
275 typedef _STRUCT_LAST_BRANCH_STATE last_branch_state_t
;
276 #define x86_LAST_BRANCH_STATE_COUNT \
277 ((mach_msg_type_number_t)(sizeof(last_branch_state_t) / sizeof(int)))
279 #define X86_LAST_BRANCH_STATE_COUNT x86_LAST_BRANCH_STATE_COUNT
283 * Combined thread, float and exception states
285 struct x86_thread_state
{
288 x86_thread_state32_t ts32
;
289 x86_thread_state64_t ts64
;
293 struct x86_float_state
{
296 x86_float_state32_t fs32
;
297 x86_float_state64_t fs64
;
301 struct x86_exception_state
{
304 x86_exception_state32_t es32
;
305 x86_exception_state64_t es64
;
309 struct x86_debug_state
{
312 x86_debug_state32_t ds32
;
313 x86_debug_state64_t ds64
;
317 struct x86_avx_state
{
320 x86_avx_state32_t as32
;
321 x86_avx_state64_t as64
;
325 struct x86_avx512_state
{
328 x86_avx512_state32_t as32
;
329 x86_avx512_state64_t as64
;
333 typedef struct x86_thread_state x86_thread_state_t
;
334 #define x86_THREAD_STATE_COUNT ((mach_msg_type_number_t) \
335 ( sizeof (x86_thread_state_t) / sizeof (int) ))
337 typedef struct x86_float_state x86_float_state_t
;
338 #define x86_FLOAT_STATE_COUNT ((mach_msg_type_number_t) \
339 (sizeof(x86_float_state_t)/sizeof(unsigned int)))
341 typedef struct x86_exception_state x86_exception_state_t
;
342 #define x86_EXCEPTION_STATE_COUNT ((mach_msg_type_number_t) \
343 (sizeof(x86_exception_state_t)/sizeof(unsigned int)))
345 typedef struct x86_debug_state x86_debug_state_t
;
346 #define x86_DEBUG_STATE_COUNT ((mach_msg_type_number_t) \
347 (sizeof(x86_debug_state_t)/sizeof(unsigned int)))
349 typedef struct x86_avx_state x86_avx_state_t
;
350 #define x86_AVX_STATE_COUNT ((mach_msg_type_number_t) \
351 (sizeof(x86_avx_state_t)/sizeof(unsigned int)))
353 typedef struct x86_avx512_state x86_avx512_state_t
;
354 #define x86_AVX512_STATE_COUNT ((mach_msg_type_number_t) \
355 (sizeof(x86_avx512_state_t)/sizeof(unsigned int)))
358 * Machine-independent way for servers and Mach's exception mechanism to
359 * choose the most efficient state flavor for exception RPC's:
361 #define MACHINE_THREAD_STATE x86_THREAD_STATE
362 #define MACHINE_THREAD_STATE_COUNT x86_THREAD_STATE_COUNT
364 #ifdef XNU_KERNEL_PRIVATE
366 #define x86_SAVED_STATE32 THREAD_STATE_NONE + 1
367 #define x86_SAVED_STATE64 THREAD_STATE_NONE + 2
370 * The format in which thread state is saved by Mach on this machine. This
371 * state flavor is most efficient for exception RPC's to kernel-loaded
372 * servers, because copying can be avoided:
374 struct x86_saved_state32
{
382 uint32_t cr2
; /* kernel esp stored by pusha - we save cr2 here later */
396 typedef struct x86_saved_state32 x86_saved_state32_t
;
398 #define x86_SAVED_STATE32_COUNT ((mach_msg_type_number_t) \
399 (sizeof (x86_saved_state32_t)/sizeof(unsigned int)))
404 * This is the state pushed onto the 64-bit interrupt stack
405 * on any exception/trap/interrupt.
407 struct x86_64_intr_stack_frame
{
419 typedef struct x86_64_intr_stack_frame x86_64_intr_stack_frame_t
;
420 _Static_assert((sizeof(x86_64_intr_stack_frame_t
) % 16) == 0,
421 "interrupt stack frame size must be a multiple of 16 bytes");
424 * thread state format for task running in 64bit long mode
425 * in long mode, the same hardware frame is always pushed regardless
426 * of whether there was a change in privilege level... therefore, there
427 * is no need for an x86_saved_state64_from_kernel variant
429 struct x86_saved_state64
{
430 uint64_t rdi
; /* arg0 for system call */
433 uint64_t r10
; /* R10 := RCX prior to syscall trap */
435 uint64_t r9
; /* arg5 for system call */
454 struct x86_64_intr_stack_frame isf
;
456 typedef struct x86_saved_state64 x86_saved_state64_t
;
457 #define x86_SAVED_STATE64_COUNT ((mach_msg_type_number_t) \
458 (sizeof (struct x86_saved_state64)/sizeof(unsigned int)))
460 extern uint32_t get_eflags_exportmask(void);
463 * Unified, tagged saved state:
467 uint32_t _pad_for_16byte_alignment
[3];
469 x86_saved_state32_t ss_32
;
470 x86_saved_state64_t ss_64
;
473 #define ss_32 uss.ss_32
474 #define ss_64 uss.ss_64
477 static inline boolean_t
478 is_saved_state64(x86_saved_state_t
*iss
)
480 return iss
->flavor
== x86_SAVED_STATE64
;
483 static inline boolean_t
484 is_saved_state32(x86_saved_state_t
*iss
)
486 return iss
->flavor
== x86_SAVED_STATE32
;
489 static inline x86_saved_state32_t
*
490 saved_state32(x86_saved_state_t
*iss
)
495 static inline x86_saved_state64_t
*
496 saved_state64(x86_saved_state_t
*iss
)
501 #endif /* XNU_KERNEL_PRIVATE */
503 #endif /* _MACH_I386_THREAD_STATUS_H_ */