2 * Copyright (c) 2007 Apple 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@
29 * FILE_ID: thread_status.h
33 #ifndef _ARM_THREAD_STATUS_H_
34 #define _ARM_THREAD_STATUS_H_
36 #include <mach/machine/_structs.h>
37 #include <mach/message.h>
38 #include <mach/vm_types.h>
39 #include <mach/arm/thread_state.h>
42 * Support for determining the state of a thread
50 #define ARM_THREAD_STATE 1
51 #define ARM_UNIFIED_THREAD_STATE ARM_THREAD_STATE
52 #define ARM_VFP_STATE 2
53 #define ARM_EXCEPTION_STATE 3
54 #define ARM_DEBUG_STATE 4 /* pre-armv8 */
55 #define THREAD_STATE_NONE 5
56 #define ARM_THREAD_STATE64 6
57 #define ARM_EXCEPTION_STATE64 7
58 // ARM_THREAD_STATE_LAST 8 /* legacy */
59 #define ARM_THREAD_STATE32 9
62 #define ARM_DEBUG_STATE32 14
63 #define ARM_DEBUG_STATE64 15
64 #define ARM_NEON_STATE 16
65 #define ARM_NEON_STATE64 17
66 #define ARM_CPMU_STATE64 18
68 #ifdef XNU_KERNEL_PRIVATE
70 #define ARM_SAVED_STATE32 20
71 #define ARM_SAVED_STATE64 21
72 #define ARM_NEON_SAVED_STATE32 22
73 #define ARM_NEON_SAVED_STATE64 23
74 #endif /* XNU_KERNEL_PRIVATE */
77 #define ARM_STATE_FLAVOR_IS_OTHER_VALID(_flavor_) 0
79 #define ARM_PAGEIN_STATE 27
81 #define VALID_THREAD_STATE_FLAVOR(x) \
82 ((x == ARM_THREAD_STATE) || \
83 (x == ARM_VFP_STATE) || \
84 (x == ARM_EXCEPTION_STATE) || \
85 (x == ARM_DEBUG_STATE) || \
86 (x == THREAD_STATE_NONE) || \
87 (x == ARM_THREAD_STATE32) || \
88 (x == ARM_THREAD_STATE64) || \
89 (x == ARM_EXCEPTION_STATE64) || \
90 (x == ARM_NEON_STATE) || \
91 (x == ARM_NEON_STATE64) || \
92 (x == ARM_DEBUG_STATE32) || \
93 (x == ARM_DEBUG_STATE64) || \
94 (x == ARM_PAGEIN_STATE) || \
95 (ARM_STATE_FLAVOR_IS_OTHER_VALID(x)))
97 struct arm_state_hdr
{
101 typedef struct arm_state_hdr arm_state_hdr_t
;
103 typedef _STRUCT_ARM_THREAD_STATE arm_thread_state_t
;
104 typedef _STRUCT_ARM_THREAD_STATE arm_thread_state32_t
;
105 typedef _STRUCT_ARM_THREAD_STATE64 arm_thread_state64_t
;
108 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL && defined(__arm64__)
110 /* Accessor macros for arm_thread_state64_t pointer fields */
112 /* Return pc field of arm_thread_state64_t as a data pointer value */
113 #define arm_thread_state64_get_pc(ts) \
114 __darwin_arm_thread_state64_get_pc(ts)
115 /* Return pc field of arm_thread_state64_t as a function pointer. May return
116 * NULL if a valid function pointer cannot be constructed, the caller should
117 * fall back to the arm_thread_state64_get_pc() macro in that case. */
118 #define arm_thread_state64_get_pc_fptr(ts) \
119 __darwin_arm_thread_state64_get_pc_fptr(ts)
120 /* Set pc field of arm_thread_state64_t to a function pointer */
121 #define arm_thread_state64_set_pc_fptr(ts, fptr) \
122 __darwin_arm_thread_state64_set_pc_fptr(ts, fptr)
123 /* Return lr field of arm_thread_state64_t as a data pointer value */
124 #define arm_thread_state64_get_lr(ts) \
125 __darwin_arm_thread_state64_get_lr(ts)
126 /* Return lr field of arm_thread_state64_t as a function pointer. May return
127 * NULL if a valid function pointer cannot be constructed, the caller should
128 * fall back to the arm_thread_state64_get_lr() macro in that case. */
129 #define arm_thread_state64_get_lr_fptr(ts) \
130 __darwin_arm_thread_state64_get_lr_fptr(ts)
131 /* Set lr field of arm_thread_state64_t to a function pointer */
132 #define arm_thread_state64_set_lr_fptr(ts, fptr) \
133 __darwin_arm_thread_state64_set_lr_fptr(ts, fptr)
134 /* Return sp field of arm_thread_state64_t as a data pointer value */
135 #define arm_thread_state64_get_sp(ts) \
136 __darwin_arm_thread_state64_get_sp(ts)
137 /* Set sp field of arm_thread_state64_t to a data pointer value */
138 #define arm_thread_state64_set_sp(ts, ptr) \
139 __darwin_arm_thread_state64_set_sp(ts, ptr)
140 /* Return fp field of arm_thread_state64_t as a data pointer value */
141 #define arm_thread_state64_get_fp(ts) \
142 __darwin_arm_thread_state64_get_fp(ts)
143 /* Set fp field of arm_thread_state64_t to a data pointer value */
144 #define arm_thread_state64_set_fp(ts, ptr) \
145 __darwin_arm_thread_state64_set_fp(ts, ptr)
147 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL && defined(__arm64__) */
148 #endif /* !defined(KERNEL) */
150 struct arm_unified_thread_state
{
153 arm_thread_state32_t ts_32
;
154 arm_thread_state64_t ts_64
;
157 #define ts_32 uts.ts_32
158 #define ts_64 uts.ts_64
159 typedef struct arm_unified_thread_state arm_unified_thread_state_t
;
161 #define ARM_THREAD_STATE_COUNT ((mach_msg_type_number_t) \
162 (sizeof (arm_thread_state_t)/sizeof(uint32_t)))
163 #define ARM_THREAD_STATE32_COUNT ((mach_msg_type_number_t) \
164 (sizeof (arm_thread_state32_t)/sizeof(uint32_t)))
165 #define ARM_THREAD_STATE64_COUNT ((mach_msg_type_number_t) \
166 (sizeof (arm_thread_state64_t)/sizeof(uint32_t)))
167 #define ARM_UNIFIED_THREAD_STATE_COUNT ((mach_msg_type_number_t) \
168 (sizeof (arm_unified_thread_state_t)/sizeof(uint32_t)))
171 typedef _STRUCT_ARM_VFP_STATE arm_vfp_state_t
;
172 typedef _STRUCT_ARM_NEON_STATE arm_neon_state_t
;
173 typedef _STRUCT_ARM_NEON_STATE arm_neon_state32_t
;
174 typedef _STRUCT_ARM_NEON_STATE64 arm_neon_state64_t
;
177 typedef _STRUCT_ARM_EXCEPTION_STATE arm_exception_state_t
;
178 typedef _STRUCT_ARM_EXCEPTION_STATE arm_exception_state32_t
;
179 typedef _STRUCT_ARM_EXCEPTION_STATE64 arm_exception_state64_t
;
181 typedef _STRUCT_ARM_DEBUG_STATE32 arm_debug_state32_t
;
182 typedef _STRUCT_ARM_DEBUG_STATE64 arm_debug_state64_t
;
184 typedef _STRUCT_ARM_PAGEIN_STATE arm_pagein_state_t
;
186 #if defined(XNU_KERNEL_PRIVATE) && defined(__arm64__)
187 /* See below for ARM64 kernel structure definition for arm_debug_state. */
188 #else /* defined(XNU_KERNEL_PRIVATE) && defined(__arm64__) */
190 * Otherwise not ARM64 kernel and we must preserve legacy ARM definitions of
191 * arm_debug_state for binary compatability of userland consumers of this file.
194 typedef _STRUCT_ARM_DEBUG_STATE arm_debug_state_t
;
195 #elif defined(__arm64__)
196 typedef _STRUCT_ARM_LEGACY_DEBUG_STATE arm_debug_state_t
;
197 #else /* defined(__arm__) */
198 #error Undefined architecture
199 #endif /* defined(__arm__) */
200 #endif /* defined(XNU_KERNEL_PRIVATE) && defined(__arm64__) */
202 #define ARM_VFP_STATE_COUNT ((mach_msg_type_number_t) \
203 (sizeof (arm_vfp_state_t)/sizeof(uint32_t)))
205 #define ARM_EXCEPTION_STATE_COUNT ((mach_msg_type_number_t) \
206 (sizeof (arm_exception_state_t)/sizeof(uint32_t)))
208 #define ARM_EXCEPTION_STATE64_COUNT ((mach_msg_type_number_t) \
209 (sizeof (arm_exception_state64_t)/sizeof(uint32_t)))
211 #define ARM_DEBUG_STATE_COUNT ((mach_msg_type_number_t) \
212 (sizeof (arm_debug_state_t)/sizeof(uint32_t)))
214 #define ARM_DEBUG_STATE32_COUNT ((mach_msg_type_number_t) \
215 (sizeof (arm_debug_state32_t)/sizeof(uint32_t)))
217 #define ARM_PAGEIN_STATE_COUNT ((mach_msg_type_number_t) \
218 (sizeof (arm_pagein_state_t)/sizeof(uint32_t)))
220 #define ARM_DEBUG_STATE64_COUNT ((mach_msg_type_number_t) \
221 (sizeof (arm_debug_state64_t)/sizeof(uint32_t)))
223 #define ARM_NEON_STATE_COUNT ((mach_msg_type_number_t) \
224 (sizeof (arm_neon_state_t)/sizeof(uint32_t)))
226 #define ARM_NEON_STATE64_COUNT ((mach_msg_type_number_t) \
227 (sizeof (arm_neon_state64_t)/sizeof(uint32_t)))
229 #define MACHINE_THREAD_STATE ARM_THREAD_STATE
230 #define MACHINE_THREAD_STATE_COUNT ARM_UNIFIED_THREAD_STATE_COUNT
234 * Largest state on this machine:
236 #define THREAD_MACHINE_STATE_MAX THREAD_STATE_MAX
238 #ifdef XNU_KERNEL_PRIVATE
240 static inline boolean_t
241 is_thread_state32(const arm_unified_thread_state_t
*its
)
243 return its
->ash
.flavor
== ARM_THREAD_STATE32
;
246 static inline boolean_t
247 is_thread_state64(const arm_unified_thread_state_t
*its
)
249 return its
->ash
.flavor
== ARM_THREAD_STATE64
;
252 static inline arm_thread_state32_t
*
253 thread_state32(arm_unified_thread_state_t
*its
)
258 static inline arm_thread_state64_t
*
259 thread_state64(arm_unified_thread_state_t
*its
)
264 static inline const arm_thread_state32_t
*
265 const_thread_state32(const arm_unified_thread_state_t
*its
)
270 static inline const arm_thread_state64_t
*
271 const_thread_state64(const arm_unified_thread_state_t
*its
)
277 #include <arm/proc_reg.h>
279 #define ARM_SAVED_STATE (THREAD_STATE_NONE + 1)
282 #define VFPSAVE_ALIGN 16
283 #define VFPSAVE_ATTRIB __attribute__((aligned (VFPSAVE_ALIGN)))
284 #define THREAD_ALIGN VFPSAVE_ALIGN
287 * vector floating point saved state
289 struct arm_vfpsaved_state
{
296 struct arm_saved_state
{
297 uint32_t r
[13]; /* General purpose register r0-r12 */
298 uint32_t sp
; /* Stack pointer r13 */
299 uint32_t lr
; /* Link register r14 */
300 uint32_t pc
; /* Program counter r15 */
301 uint32_t cpsr
; /* Current program status register */
302 uint32_t fsr
; /* Fault status */
303 uint32_t far
; /* Virtual Fault Address */
304 uint32_t exception
; /* exception number */
308 struct arm_vfpsaved_state VFPdata VFPSAVE_ATTRIB
;
309 // for packing reasons chtread_self and DebugData
310 // are inside the the PcbData when __ARM_VFP__ is set
311 arm_debug_state_t
*VFPpadding_DebugData
;
312 vm_address_t VFPpadding_cthread_self
;
315 typedef struct arm_saved_state arm_saved_state_t
;
318 * Just for coexistence with AArch64 code.
320 typedef struct arm_saved_state arm_saved_state32_t
;
323 copy_signed_thread_state(arm_saved_state_t
*dst
, const arm_saved_state_t
*src
)
328 static inline arm_saved_state32_t
*
329 saved_state32(arm_saved_state_t
*iss
)
334 static inline boolean_t
335 is_saved_state32(const arm_saved_state_t
*iss __unused
)
341 struct arm_saved_state_tagged
{
343 struct arm_saved_state state
;
345 typedef struct arm_saved_state_tagged arm_saved_state_tagged_t
;
347 #define ARM_SAVED_STATE32_COUNT ((mach_msg_type_number_t) \
348 (sizeof (arm_saved_state_t)/sizeof(unsigned int)))
351 static inline register_t
352 get_saved_state_pc(const arm_saved_state_t
*iss
)
358 add_saved_state_pc(arm_saved_state_t
*iss
, int diff
)
364 set_saved_state_pc(arm_saved_state_t
*iss
, register_t pc
)
369 static inline register_t
370 get_saved_state_sp(const arm_saved_state_t
*iss
)
376 set_saved_state_sp(arm_saved_state_t
*iss
, register_t sp
)
381 static inline register_t
382 get_saved_state_fp(const arm_saved_state_t
*iss
)
388 set_saved_state_fp(arm_saved_state_t
*iss
, register_t fp
)
393 static inline register_t
394 get_saved_state_lr(const arm_saved_state_t
*iss
)
400 set_saved_state_lr(arm_saved_state_t
*iss
, register_t lr
)
405 static inline register_t
406 get_saved_state_cpsr(const arm_saved_state_t
*iss
)
412 mask_saved_state_cpsr(arm_saved_state_t
*iss
, uint32_t set_bits
, uint32_t clear_bits
)
414 iss
->cpsr
|= set_bits
;
415 iss
->cpsr
&= ~clear_bits
;
419 set_saved_state_cpsr(arm_saved_state_t
*iss
, register_t cpsr
)
424 static inline register_t
425 get_saved_state_reg(const arm_saved_state_t
*iss
, unsigned regno
)
427 return iss
->r
[regno
];
431 set_saved_state_reg(arm_saved_state_t
*iss
, unsigned regno
, register_t val
)
436 #elif defined(__arm64__)
438 #include <kern/assert.h>
439 #include <arm64/proc_reg.h>
440 #define CAST_ASSERT_SAFE(type, val) (assert((val) == ((type)(val))), (type)(val))
446 struct arm_saved_state32
{
447 uint32_t r
[13]; /* General purpose register r0-r12 */
448 uint32_t sp
; /* Stack pointer r13 */
449 uint32_t lr
; /* Link register r14 */
450 uint32_t pc
; /* Program counter r15 */
451 uint32_t cpsr
; /* Current program status register */
452 uint32_t far
; /* Virtual fault address */
453 uint32_t esr
; /* Exception syndrome register */
454 uint32_t exception
; /* Exception number */
456 typedef struct arm_saved_state32 arm_saved_state32_t
;
458 struct arm_saved_state32_tagged
{
460 struct arm_saved_state32 state
;
462 typedef struct arm_saved_state32_tagged arm_saved_state32_tagged_t
;
464 #define ARM_SAVED_STATE32_COUNT ((mach_msg_type_number_t) \
465 (sizeof(arm_saved_state32_t)/sizeof(unsigned int)))
467 struct arm_saved_state64
{
468 uint64_t x
[29]; /* General purpose registers x0-x28 */
469 uint64_t fp
; /* Frame pointer x29 */
470 uint64_t lr
; /* Link register x30 */
471 uint64_t sp
; /* Stack pointer x31 */
472 uint64_t pc
; /* Program counter */
473 uint32_t cpsr
; /* Current program status register */
474 uint32_t reserved
; /* Reserved padding */
475 uint64_t far
; /* Virtual fault address */
476 uint32_t esr
; /* Exception syndrome register */
477 uint32_t exception
; /* Exception number */
478 #if defined(HAS_APPLE_PAC)
480 #endif /* defined(HAS_APPLE_PAC) */
482 typedef struct arm_saved_state64 arm_saved_state64_t
;
484 #define ARM_SAVED_STATE64_COUNT ((mach_msg_type_number_t) \
485 (sizeof(arm_saved_state64_t)/sizeof(unsigned int)))
487 struct arm_saved_state64_tagged
{
489 struct arm_saved_state64 state
;
491 typedef struct arm_saved_state64_tagged arm_saved_state64_tagged_t
;
493 struct arm_saved_state
{
496 struct arm_saved_state32 ss_32
;
497 struct arm_saved_state64 ss_64
;
499 } __attribute__((aligned(16)));
500 #define ss_32 uss.ss_32
501 #define ss_64 uss.ss_64
503 typedef struct arm_saved_state arm_saved_state_t
;
505 #if defined(XNU_KERNEL_PRIVATE)
506 #if defined(HAS_APPLE_PAC)
508 #include <sys/cdefs.h>
511 * Used by MANIPULATE_SIGNED_THREAD_STATE(), potentially from C++ (IOKit) code.
512 * Open-coded to prevent a circular dependency between mach/arm/thread_status.h
513 * and osfmk/arm/machine_routines.h.
516 extern boolean_t
ml_set_interrupts_enabled(boolean_t
);
520 * Methods used to sign and check thread state to detect corruptions of saved
521 * thread state across exceptions and context switches.
523 extern void ml_sign_thread_state(arm_saved_state_t
*, uint64_t, uint32_t, uint64_t, uint64_t, uint64_t);
525 extern void ml_check_signed_state(const arm_saved_state_t
*, uint64_t, uint32_t, uint64_t, uint64_t, uint64_t);
527 /* XXX: including stddef.f here breaks ctfmerge on some builds, so use __builtin_offsetof() instead of offsetof() */
528 #define ss64_offsetof(x) __builtin_offsetof(struct arm_saved_state, ss_64.x)
531 * Verify the signed thread state in _iss, execute the assembly instructions
532 * _instr, and re-sign the modified thread state. Varargs specify additional
535 * _instr may read or modify the thread state in the following registers:
538 * x1: authed _iss->ss_64.pc
539 * w2: authed _iss->ss_64.cpsr
540 * x3: authed _iss->ss_64.lr
541 * x4: authed _iss->ss_64.x16
542 * x5: authed _iss->ss_64.x17
543 * x6: scratch register
544 * x7: scratch register
546 #define MANIPULATE_SIGNED_THREAD_STATE(_iss, _instr, ...) \
548 boolean_t _intr = ml_set_interrupts_enabled(FALSE); \
551 "mov x0, %[iss]" "\n" \
552 "ldp x4, x5, [x0, %[SS64_X16]]" "\n" \
553 "ldr x6, [x0, %[SS64_PC]]" "\n" \
554 "ldr w7, [x0, %[SS64_CPSR]]" "\n" \
555 "ldr x3, [x0, %[SS64_LR]]" "\n" \
558 "bl _ml_check_signed_state" "\n" \
562 "bl _ml_sign_thread_state" "\n" \
566 [SS64_X16] "i"(ss64_offsetof(x[16])), \
567 [SS64_PC] "i"(ss64_offsetof(pc)), \
568 [SS64_CPSR] "i"(ss64_offsetof(cpsr)), \
569 [SS64_LR] "i"(ss64_offsetof(lr)),##__VA_ARGS__ \
570 : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8" \
572 ml_set_interrupts_enabled(_intr); \
576 check_and_sign_copied_thread_state(arm_saved_state_t
*dst
, const arm_saved_state_t
*src
)
578 MANIPULATE_SIGNED_THREAD_STATE(src
,
583 #endif /* defined(HAS_APPLE_PAC) */
586 copy_signed_thread_state(arm_saved_state_t
*dst
, const arm_saved_state_t
*src
)
589 #if defined(HAS_APPLE_PAC)
590 check_and_sign_copied_thread_state(dst
, src
);
594 #endif /* defined(XNU_KERNEL_PRIVATE) */
596 static inline boolean_t
597 is_saved_state32(const arm_saved_state_t
*iss
)
599 return iss
->ash
.flavor
== ARM_SAVED_STATE32
;
602 static inline boolean_t
603 is_saved_state64(const arm_saved_state_t
*iss
)
605 return iss
->ash
.flavor
== ARM_SAVED_STATE64
;
608 static inline arm_saved_state32_t
*
609 saved_state32(arm_saved_state_t
*iss
)
614 static inline const arm_saved_state32_t
*
615 const_saved_state32(const arm_saved_state_t
*iss
)
620 static inline arm_saved_state64_t
*
621 saved_state64(arm_saved_state_t
*iss
)
626 static inline const arm_saved_state64_t
*
627 const_saved_state64(const arm_saved_state_t
*iss
)
632 static inline register_t
633 get_saved_state_pc(const arm_saved_state_t
*iss
)
635 return is_saved_state32(iss
) ? const_saved_state32(iss
)->pc
: const_saved_state64(iss
)->pc
;
639 add_saved_state_pc(arm_saved_state_t
*iss
, int diff
)
641 if (is_saved_state32(iss
)) {
642 uint64_t pc
= saved_state32(iss
)->pc
+ diff
;
643 saved_state32(iss
)->pc
= CAST_ASSERT_SAFE(uint32_t, pc
);
645 #if defined(XNU_KERNEL_PRIVATE) && defined(HAS_APPLE_PAC)
646 MANIPULATE_SIGNED_THREAD_STATE(iss
,
647 "mov w6, %w[diff] \n"
648 "add x1, x1, w6, sxtw \n"
649 "str x1, [x0, %[SS64_PC]] \n",
653 saved_state64(iss
)->pc
+= diff
;
654 #endif /* defined(XNU_KERNEL_PRIVATE) && defined(HAS_APPLE_PAC) */
659 set_saved_state_pc(arm_saved_state_t
*iss
, register_t pc
)
661 if (is_saved_state32(iss
)) {
662 saved_state32(iss
)->pc
= CAST_ASSERT_SAFE(uint32_t, pc
);
664 #if defined(XNU_KERNEL_PRIVATE) && defined(HAS_APPLE_PAC)
665 MANIPULATE_SIGNED_THREAD_STATE(iss
,
667 "str x1, [x0, %[SS64_PC]] \n",
671 saved_state64(iss
)->pc
= pc
;
672 #endif /* defined(XNU_KERNEL_PRIVATE) && defined(HAS_APPLE_PAC) */
676 static inline register_t
677 get_saved_state_sp(const arm_saved_state_t
*iss
)
679 return is_saved_state32(iss
) ? const_saved_state32(iss
)->sp
: const_saved_state64(iss
)->sp
;
683 set_saved_state_sp(arm_saved_state_t
*iss
, register_t sp
)
685 if (is_saved_state32(iss
)) {
686 saved_state32(iss
)->sp
= CAST_ASSERT_SAFE(uint32_t, sp
);
688 saved_state64(iss
)->sp
= sp
;
692 static inline register_t
693 get_saved_state_lr(const arm_saved_state_t
*iss
)
695 return is_saved_state32(iss
) ? const_saved_state32(iss
)->lr
: const_saved_state64(iss
)->lr
;
699 set_saved_state_lr(arm_saved_state_t
*iss
, register_t lr
)
701 if (is_saved_state32(iss
)) {
702 saved_state32(iss
)->lr
= CAST_ASSERT_SAFE(uint32_t, lr
);
704 #if defined(XNU_KERNEL_PRIVATE) && defined(HAS_APPLE_PAC)
705 MANIPULATE_SIGNED_THREAD_STATE(iss
,
707 "str x3, [x0, %[SS64_LR]] \n",
711 saved_state64(iss
)->lr
= lr
;
712 #endif /* defined(XNU_KERNEL_PRIVATE) && defined(HAS_APPLE_PAC) */
716 static inline register_t
717 get_saved_state_fp(const arm_saved_state_t
*iss
)
719 return is_saved_state32(iss
) ? const_saved_state32(iss
)->r
[7] : const_saved_state64(iss
)->fp
;
723 set_saved_state_fp(arm_saved_state_t
*iss
, register_t fp
)
725 if (is_saved_state32(iss
)) {
726 saved_state32(iss
)->r
[7] = CAST_ASSERT_SAFE(uint32_t, fp
);
728 saved_state64(iss
)->fp
= fp
;
733 check_saved_state_reglimit(const arm_saved_state_t
*iss
, unsigned reg
)
735 return is_saved_state32(iss
) ? (reg
< ARM_SAVED_STATE32_COUNT
) : (reg
< ARM_SAVED_STATE64_COUNT
);
738 static inline register_t
739 get_saved_state_reg(const arm_saved_state_t
*iss
, unsigned reg
)
741 if (!check_saved_state_reglimit(iss
, reg
)) {
745 return is_saved_state32(iss
) ? (const_saved_state32(iss
)->r
[reg
]) : (const_saved_state64(iss
)->x
[reg
]);
749 set_saved_state_reg(arm_saved_state_t
*iss
, unsigned reg
, register_t value
)
751 if (!check_saved_state_reglimit(iss
, reg
)) {
755 if (is_saved_state32(iss
)) {
756 saved_state32(iss
)->r
[reg
] = CAST_ASSERT_SAFE(uint32_t, value
);
758 #if defined(XNU_KERNEL_PRIVATE) && defined(HAS_APPLE_PAC)
759 /* x16 and x17 are part of the jophash */
761 MANIPULATE_SIGNED_THREAD_STATE(iss
,
762 "mov x4, %[value] \n"
763 "str x4, [x0, %[SS64_X16]] \n",
767 } else if (reg
== 17) {
768 MANIPULATE_SIGNED_THREAD_STATE(iss
,
769 "mov x5, %[value] \n"
770 "str x5, [x0, %[SS64_X17]] \n",
772 [SS64_X17
] "i"(ss64_offsetof(x
[17]))
777 saved_state64(iss
)->x
[reg
] = value
;
781 static inline uint32_t
782 get_saved_state_cpsr(const arm_saved_state_t
*iss
)
784 return is_saved_state32(iss
) ? const_saved_state32(iss
)->cpsr
: const_saved_state64(iss
)->cpsr
;
788 mask_saved_state_cpsr(arm_saved_state_t
*iss
, uint32_t set_bits
, uint32_t clear_bits
)
790 if (is_saved_state32(iss
)) {
791 saved_state32(iss
)->cpsr
|= set_bits
;
792 saved_state32(iss
)->cpsr
&= ~clear_bits
;
794 #if defined(XNU_KERNEL_PRIVATE) && defined(HAS_APPLE_PAC)
795 MANIPULATE_SIGNED_THREAD_STATE(iss
,
796 "mov w6, %w[set_bits] \n"
797 "orr w2, w2, w6, lsl #0 \n"
798 "mov w6, %w[clear_bits] \n"
799 "bic w2, w2, w6, lsl #0 \n"
800 "str w2, [x0, %[SS64_CPSR]] \n",
801 [set_bits
] "r"(set_bits
),
802 [clear_bits
] "r"(clear_bits
)
805 saved_state64(iss
)->cpsr
|= set_bits
;
806 saved_state64(iss
)->cpsr
&= ~clear_bits
;
807 #endif /* defined(XNU_KERNEL_PRIVATE) && defined(HAS_APPLE_PAC) */
812 set_saved_state_cpsr(arm_saved_state_t
*iss
, uint32_t cpsr
)
814 if (is_saved_state32(iss
)) {
815 saved_state32(iss
)->cpsr
= cpsr
;
817 #if defined(XNU_KERNEL_PRIVATE) && defined(HAS_APPLE_PAC)
818 MANIPULATE_SIGNED_THREAD_STATE(iss
,
819 "mov w2, %w[cpsr] \n"
820 "str w2, [x0, %[SS64_CPSR]] \n",
824 saved_state64(iss
)->cpsr
= cpsr
;
825 #endif /* defined(XNU_KERNEL_PRIVATE) && defined(HAS_APPLE_PAC) */
829 static inline register_t
830 get_saved_state_far(const arm_saved_state_t
*iss
)
832 return is_saved_state32(iss
) ? const_saved_state32(iss
)->far
: const_saved_state64(iss
)->far
;
836 set_saved_state_far(arm_saved_state_t
*iss
, register_t far
)
838 if (is_saved_state32(iss
)) {
839 saved_state32(iss
)->far
= CAST_ASSERT_SAFE(uint32_t, far
);
841 saved_state64(iss
)->far
= far
;
845 static inline uint32_t
846 get_saved_state_esr(const arm_saved_state_t
*iss
)
848 return is_saved_state32(iss
) ? const_saved_state32(iss
)->esr
: const_saved_state64(iss
)->esr
;
852 set_saved_state_esr(arm_saved_state_t
*iss
, uint32_t esr
)
854 if (is_saved_state32(iss
)) {
855 saved_state32(iss
)->esr
= esr
;
857 saved_state64(iss
)->esr
= esr
;
861 static inline uint32_t
862 get_saved_state_exc(const arm_saved_state_t
*iss
)
864 return is_saved_state32(iss
) ? const_saved_state32(iss
)->exception
: const_saved_state64(iss
)->exception
;
868 set_saved_state_exc(arm_saved_state_t
*iss
, uint32_t exc
)
870 if (is_saved_state32(iss
)) {
871 saved_state32(iss
)->exception
= exc
;
873 saved_state64(iss
)->exception
= exc
;
877 extern void panic_unimplemented(void);
880 get_saved_state_svc_number(const arm_saved_state_t
*iss
)
882 return is_saved_state32(iss
) ? (int)const_saved_state32(iss
)->r
[12] : (int)const_saved_state64(iss
)->x
[ARM64_SYSCALL_CODE_REG_NUM
]; /* Only first word counts here */
885 typedef _STRUCT_ARM_LEGACY_DEBUG_STATE arm_legacy_debug_state_t
;
887 struct arm_debug_aggregate_state
{
890 arm_debug_state32_t ds32
;
891 arm_debug_state64_t ds64
;
893 } __attribute__((aligned(16)));
895 typedef struct arm_debug_aggregate_state arm_debug_state_t
;
897 #define ARM_LEGACY_DEBUG_STATE_COUNT ((mach_msg_type_number_t) \
898 (sizeof (arm_legacy_debug_state_t)/sizeof(uint32_t)))
903 typedef __uint128_t uint128_t
;
904 typedef uint64_t uint64x2_t
__attribute__((ext_vector_type(2)));
905 typedef uint32_t uint32x4_t
__attribute__((ext_vector_type(4)));
907 struct arm_neon_saved_state32
{
916 typedef struct arm_neon_saved_state32 arm_neon_saved_state32_t
;
918 #define ARM_NEON_SAVED_STATE32_COUNT ((mach_msg_type_number_t) \
919 (sizeof (arm_neon_saved_state32_t)/sizeof(unsigned int)))
921 struct arm_neon_saved_state64
{
930 typedef struct arm_neon_saved_state64 arm_neon_saved_state64_t
;
932 #define ARM_NEON_SAVED_STATE64_COUNT ((mach_msg_type_number_t) \
933 (sizeof (arm_neon_saved_state64_t)/sizeof(unsigned int)))
935 struct arm_neon_saved_state
{
938 struct arm_neon_saved_state32 ns_32
;
939 struct arm_neon_saved_state64 ns_64
;
942 typedef struct arm_neon_saved_state arm_neon_saved_state_t
;
943 #define ns_32 uns.ns_32
944 #define ns_64 uns.ns_64
946 static inline boolean_t
947 is_neon_saved_state32(const arm_neon_saved_state_t
*state
)
949 return state
->nsh
.flavor
== ARM_NEON_SAVED_STATE32
;
952 static inline boolean_t
953 is_neon_saved_state64(const arm_neon_saved_state_t
*state
)
955 return state
->nsh
.flavor
== ARM_NEON_SAVED_STATE64
;
958 static inline arm_neon_saved_state32_t
*
959 neon_state32(arm_neon_saved_state_t
*state
)
961 return &state
->ns_32
;
964 static inline arm_neon_saved_state64_t
*
965 neon_state64(arm_neon_saved_state_t
*state
)
967 return &state
->ns_64
;
976 struct arm_saved_state ss
;
977 struct arm_neon_saved_state ns
;
979 typedef struct arm_context arm_context_t
;
981 extern void saved_state_to_thread_state64(const arm_saved_state_t
*, arm_thread_state64_t
*);
982 extern void thread_state64_to_saved_state(const arm_thread_state64_t
*, arm_saved_state_t
*);
984 #else /* defined(__arm__) */
986 #endif /* defined(__arm__) */
988 extern void saved_state_to_thread_state32(const arm_saved_state_t
*, arm_thread_state32_t
*);
989 extern void thread_state32_to_saved_state(const arm_thread_state32_t
*, arm_saved_state_t
*);
991 #endif /* XNU_KERNEL_PRIVATE */
993 #endif /* _ARM_THREAD_STATUS_H_ */