1 | /* |
2 | * Copyright (c) 2007 Apple Inc. All rights reserved. |
3 | * |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
5 | * |
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. |
14 | * |
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 |
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. |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
27 | */ |
28 | /* |
29 | * FILE_ID: thread_status.h |
30 | */ |
31 | |
32 | |
33 | #ifndef _ARM_THREAD_STATUS_H_ |
34 | #define _ARM_THREAD_STATUS_H_ |
35 | |
36 | #include <mach/machine/_structs.h> |
37 | #include <mach/message.h> |
38 | #include <mach/arm/thread_state.h> |
39 | |
40 | /* |
41 | * Support for determining the state of a thread |
42 | */ |
43 | |
44 | |
45 | /* |
46 | * Flavors |
47 | */ |
48 | |
49 | #define ARM_THREAD_STATE 1 |
50 | #define ARM_UNIFIED_THREAD_STATE ARM_THREAD_STATE |
51 | #define ARM_VFP_STATE 2 |
52 | #define ARM_EXCEPTION_STATE 3 |
53 | #define ARM_DEBUG_STATE 4 /* pre-armv8 */ |
54 | #define THREAD_STATE_NONE 5 |
55 | #define ARM_THREAD_STATE64 6 |
56 | #define ARM_EXCEPTION_STATE64 7 |
57 | // ARM_THREAD_STATE_LAST (legacy) 8 |
58 | #define ARM_THREAD_STATE32 9 |
59 | |
60 | /* API */ |
61 | #define ARM_DEBUG_STATE32 14 |
62 | #define ARM_DEBUG_STATE64 15 |
63 | #define ARM_NEON_STATE 16 |
64 | #define ARM_NEON_STATE64 17 |
65 | #define ARM_CPMU_STATE64 18 |
66 | |
67 | #ifdef XNU_KERNEL_PRIVATE |
68 | /* For kernel use */ |
69 | #define ARM_SAVED_STATE32 20 |
70 | #define ARM_SAVED_STATE64 21 |
71 | #define ARM_NEON_SAVED_STATE32 22 |
72 | #define ARM_NEON_SAVED_STATE64 23 |
73 | #endif /* XNU_KERNEL_PRIVATE */ |
74 | |
75 | #define VALID_THREAD_STATE_FLAVOR(x)\ |
76 | ((x == ARM_THREAD_STATE) || \ |
77 | (x == ARM_VFP_STATE) || \ |
78 | (x == ARM_EXCEPTION_STATE) || \ |
79 | (x == ARM_DEBUG_STATE) || \ |
80 | (x == THREAD_STATE_NONE) || \ |
81 | (x == ARM_THREAD_STATE32) || \ |
82 | (x == ARM_THREAD_STATE64) || \ |
83 | (x == ARM_EXCEPTION_STATE64) || \ |
84 | (x == ARM_NEON_STATE) || \ |
85 | (x == ARM_NEON_STATE64) || \ |
86 | (x == ARM_DEBUG_STATE32) || \ |
87 | (x == ARM_DEBUG_STATE64)) |
88 | |
89 | struct arm_state_hdr { |
90 | uint32_t flavor; |
91 | uint32_t count; |
92 | }; |
93 | typedef struct arm_state_hdr arm_state_hdr_t; |
94 | |
95 | typedef _STRUCT_ARM_THREAD_STATE arm_thread_state_t; |
96 | typedef _STRUCT_ARM_THREAD_STATE arm_thread_state32_t; |
97 | typedef _STRUCT_ARM_THREAD_STATE64 arm_thread_state64_t; |
98 | |
99 | #if !defined(KERNEL) |
100 | #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL && defined(__arm64__) |
101 | #define arm_thread_state64_get_pc(ts) \ |
102 | __darwin_arm_thread_state64_get_pc(ts) |
103 | #define arm_thread_state64_get_pc_fptr(ts) \ |
104 | __darwin_arm_thread_state64_get_pc_fptr(ts) |
105 | #define arm_thread_state64_set_pc_fptr(ts, fptr) \ |
106 | __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) |
107 | #define arm_thread_state64_get_lr(ts) \ |
108 | __darwin_arm_thread_state64_get_lr(ts) |
109 | #define arm_thread_state64_get_lr_fptr(ts) \ |
110 | __darwin_arm_thread_state64_get_lr_fptr(ts) |
111 | #define arm_thread_state64_set_lr_fptr(ts, fptr) \ |
112 | __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) |
113 | #define arm_thread_state64_get_sp(ts) \ |
114 | __darwin_arm_thread_state64_get_sp(ts) |
115 | #define arm_thread_state64_set_sp(ts, ptr) \ |
116 | __darwin_arm_thread_state64_set_sp(ts, ptr) |
117 | #define arm_thread_state64_get_fp(ts) \ |
118 | __darwin_arm_thread_state64_get_fp(ts) |
119 | #define arm_thread_state64_set_fp(ts, ptr) \ |
120 | __darwin_arm_thread_state64_set_fp(ts, ptr) |
121 | #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL && defined(__arm64__) */ |
122 | #endif /* !defined(KERNEL) */ |
123 | |
124 | struct arm_unified_thread_state { |
125 | arm_state_hdr_t ash; |
126 | union { |
127 | arm_thread_state32_t ts_32; |
128 | arm_thread_state64_t ts_64; |
129 | } uts; |
130 | }; |
131 | #define ts_32 uts.ts_32 |
132 | #define ts_64 uts.ts_64 |
133 | typedef struct arm_unified_thread_state arm_unified_thread_state_t; |
134 | |
135 | #define ARM_THREAD_STATE_COUNT ((mach_msg_type_number_t) \ |
136 | (sizeof (arm_thread_state_t)/sizeof(uint32_t))) |
137 | #define ARM_THREAD_STATE32_COUNT ((mach_msg_type_number_t) \ |
138 | (sizeof (arm_thread_state32_t)/sizeof(uint32_t))) |
139 | #define ARM_THREAD_STATE64_COUNT ((mach_msg_type_number_t) \ |
140 | (sizeof (arm_thread_state64_t)/sizeof(uint32_t))) |
141 | #define ARM_UNIFIED_THREAD_STATE_COUNT ((mach_msg_type_number_t) \ |
142 | (sizeof (arm_unified_thread_state_t)/sizeof(uint32_t))) |
143 | |
144 | |
145 | typedef _STRUCT_ARM_VFP_STATE arm_vfp_state_t; |
146 | typedef _STRUCT_ARM_NEON_STATE arm_neon_state_t; |
147 | typedef _STRUCT_ARM_NEON_STATE arm_neon_state32_t; |
148 | typedef _STRUCT_ARM_NEON_STATE64 arm_neon_state64_t; |
149 | |
150 | typedef _STRUCT_ARM_EXCEPTION_STATE arm_exception_state_t; |
151 | typedef _STRUCT_ARM_EXCEPTION_STATE arm_exception_state32_t; |
152 | typedef _STRUCT_ARM_EXCEPTION_STATE64 arm_exception_state64_t; |
153 | |
154 | typedef _STRUCT_ARM_DEBUG_STATE32 arm_debug_state32_t; |
155 | typedef _STRUCT_ARM_DEBUG_STATE64 arm_debug_state64_t; |
156 | |
157 | #if defined(XNU_KERNEL_PRIVATE) && defined(__arm64__) |
158 | /* See below for ARM64 kernel structure definition for arm_debug_state. */ |
159 | #else |
160 | /* |
161 | * Otherwise not ARM64 kernel and we must preserve legacy ARM definitions of |
162 | * arm_debug_state for binary compatability of userland consumers of this file. |
163 | */ |
164 | #if defined(__arm__) |
165 | typedef _STRUCT_ARM_DEBUG_STATE arm_debug_state_t; |
166 | #elif defined(__arm64__) |
167 | typedef _STRUCT_ARM_LEGACY_DEBUG_STATE arm_debug_state_t; |
168 | #else |
169 | #error Undefined architecture |
170 | #endif |
171 | #endif |
172 | |
173 | #define ARM_VFP_STATE_COUNT ((mach_msg_type_number_t) \ |
174 | (sizeof (arm_vfp_state_t)/sizeof(uint32_t))) |
175 | |
176 | #define ARM_EXCEPTION_STATE_COUNT ((mach_msg_type_number_t) \ |
177 | (sizeof (arm_exception_state_t)/sizeof(uint32_t))) |
178 | |
179 | #define ARM_EXCEPTION_STATE64_COUNT ((mach_msg_type_number_t) \ |
180 | (sizeof (arm_exception_state64_t)/sizeof(uint32_t))) |
181 | |
182 | #define ARM_DEBUG_STATE_COUNT ((mach_msg_type_number_t) \ |
183 | (sizeof (arm_debug_state_t)/sizeof(uint32_t))) |
184 | |
185 | #define ARM_DEBUG_STATE32_COUNT ((mach_msg_type_number_t) \ |
186 | (sizeof (arm_debug_state32_t)/sizeof(uint32_t))) |
187 | |
188 | #define ARM_DEBUG_STATE64_COUNT ((mach_msg_type_number_t) \ |
189 | (sizeof (arm_debug_state64_t)/sizeof(uint32_t))) |
190 | |
191 | #define ARM_NEON_STATE_COUNT ((mach_msg_type_number_t) \ |
192 | (sizeof (arm_neon_state_t)/sizeof(uint32_t))) |
193 | |
194 | #define ARM_NEON_STATE64_COUNT ((mach_msg_type_number_t) \ |
195 | (sizeof (arm_neon_state64_t)/sizeof(uint32_t))) |
196 | |
197 | #define MACHINE_THREAD_STATE ARM_THREAD_STATE |
198 | #define MACHINE_THREAD_STATE_COUNT ARM_UNIFIED_THREAD_STATE_COUNT |
199 | |
200 | /* |
201 | * Largest state on this machine: |
202 | */ |
203 | #define THREAD_MACHINE_STATE_MAX THREAD_STATE_MAX |
204 | |
205 | #ifdef XNU_KERNEL_PRIVATE |
206 | |
207 | static inline boolean_t |
208 | is_thread_state32(const arm_unified_thread_state_t *its) |
209 | { |
210 | return (its->ash.flavor == ARM_THREAD_STATE32); |
211 | } |
212 | |
213 | static inline boolean_t |
214 | is_thread_state64(const arm_unified_thread_state_t *its) |
215 | { |
216 | return (its->ash.flavor == ARM_THREAD_STATE64); |
217 | } |
218 | |
219 | static inline arm_thread_state32_t* |
220 | thread_state32(arm_unified_thread_state_t *its) |
221 | { |
222 | return &its->ts_32; |
223 | } |
224 | |
225 | static inline arm_thread_state64_t* |
226 | thread_state64(arm_unified_thread_state_t *its) |
227 | { |
228 | return &its->ts_64; |
229 | } |
230 | |
231 | static inline const arm_thread_state32_t* |
232 | const_thread_state32(const arm_unified_thread_state_t *its) |
233 | { |
234 | return &its->ts_32; |
235 | } |
236 | |
237 | static inline const arm_thread_state64_t* |
238 | const_thread_state64(const arm_unified_thread_state_t *its) |
239 | { |
240 | return &its->ts_64; |
241 | } |
242 | |
243 | #if defined(__arm__) |
244 | #include <arm/proc_reg.h> |
245 | |
246 | #define ARM_SAVED_STATE THREAD_STATE_NONE + 1 |
247 | |
248 | struct arm_saved_state { |
249 | uint32_t r[13]; /* General purpose register r0-r12 */ |
250 | uint32_t sp; /* Stack pointer r13 */ |
251 | uint32_t lr; /* Link register r14 */ |
252 | uint32_t pc; /* Program counter r15 */ |
253 | uint32_t cpsr; /* Current program status register */ |
254 | uint32_t fsr; /* Fault status */ |
255 | uint32_t far; /* Virtual Fault Address */ |
256 | uint32_t exception; /* exception number */ |
257 | }; |
258 | typedef struct arm_saved_state arm_saved_state_t; |
259 | |
260 | /* |
261 | * Just for coexistence with AArch64 code. |
262 | */ |
263 | typedef struct arm_saved_state arm_saved_state32_t; |
264 | |
265 | static inline arm_saved_state32_t* |
266 | saved_state32(arm_saved_state_t *iss) |
267 | { |
268 | return iss; |
269 | } |
270 | |
271 | static inline boolean_t |
272 | is_saved_state32(const arm_saved_state_t *iss __unused) |
273 | { |
274 | return TRUE; |
275 | } |
276 | |
277 | |
278 | struct arm_saved_state_tagged { |
279 | uint32_t tag; |
280 | struct arm_saved_state state; |
281 | }; |
282 | typedef struct arm_saved_state_tagged arm_saved_state_tagged_t; |
283 | |
284 | #define ARM_SAVED_STATE32_COUNT ((mach_msg_type_number_t) \ |
285 | (sizeof (arm_saved_state_t)/sizeof(unsigned int))) |
286 | |
287 | |
288 | static inline register_t |
289 | get_saved_state_pc(const arm_saved_state_t *iss) |
290 | { |
291 | return iss->pc; |
292 | } |
293 | |
294 | static inline void |
295 | set_saved_state_pc(arm_saved_state_t *iss, register_t pc) |
296 | { |
297 | iss->pc = pc; |
298 | } |
299 | |
300 | static inline register_t |
301 | get_saved_state_sp(const arm_saved_state_t *iss) |
302 | { |
303 | return iss->sp; |
304 | } |
305 | |
306 | static inline void |
307 | set_saved_state_sp(arm_saved_state_t *iss, register_t sp) |
308 | { |
309 | iss->sp = sp; |
310 | } |
311 | |
312 | static inline register_t |
313 | get_saved_state_fp(const arm_saved_state_t *iss) |
314 | { |
315 | return iss->r[7]; |
316 | } |
317 | |
318 | static inline void |
319 | set_saved_state_fp(arm_saved_state_t *iss, register_t fp) |
320 | { |
321 | iss->r[7] = fp; |
322 | } |
323 | |
324 | static inline register_t |
325 | get_saved_state_lr(const arm_saved_state_t *iss) |
326 | { |
327 | return iss->lr; |
328 | } |
329 | |
330 | static inline void |
331 | set_saved_state_lr(arm_saved_state_t *iss, register_t lr) |
332 | { |
333 | iss->lr = lr; |
334 | } |
335 | |
336 | static inline register_t |
337 | get_saved_state_cpsr(const arm_saved_state_t *iss) |
338 | { |
339 | return iss->cpsr; |
340 | } |
341 | |
342 | static inline void |
343 | set_saved_state_cpsr(arm_saved_state_t *iss, register_t cpsr) |
344 | { |
345 | iss->cpsr = cpsr; |
346 | } |
347 | |
348 | static inline register_t |
349 | get_saved_state_reg(const arm_saved_state_t *iss, unsigned regno) |
350 | { |
351 | return iss->r[regno]; |
352 | } |
353 | |
354 | static inline void |
355 | set_saved_state_reg(arm_saved_state_t *iss, unsigned regno, register_t val) |
356 | { |
357 | iss->r[regno] = val; |
358 | } |
359 | |
360 | #elif defined(__arm64__) |
361 | |
362 | #include <kern/assert.h> |
363 | #include <arm64/proc_reg.h> |
364 | #define CAST_ASSERT_SAFE(type, val) (assert((val) == ((type)(val))), (type)(val)) |
365 | |
366 | /* |
367 | * GPR context |
368 | */ |
369 | |
370 | struct arm_saved_state32 { |
371 | uint32_t r[13]; /* General purpose register r0-r12 */ |
372 | uint32_t sp; /* Stack pointer r13 */ |
373 | uint32_t lr; /* Link register r14 */ |
374 | uint32_t pc; /* Program counter r15 */ |
375 | uint32_t cpsr; /* Current program status register */ |
376 | uint32_t far; /* Virtual fault address */ |
377 | uint32_t esr; /* Exception syndrome register */ |
378 | uint32_t exception; /* Exception number */ |
379 | }; |
380 | typedef struct arm_saved_state32 arm_saved_state32_t; |
381 | |
382 | struct arm_saved_state32_tagged { |
383 | uint32_t tag; |
384 | struct arm_saved_state32 state; |
385 | }; |
386 | typedef struct arm_saved_state32_tagged arm_saved_state32_tagged_t; |
387 | |
388 | #define ARM_SAVED_STATE32_COUNT ((mach_msg_type_number_t) \ |
389 | (sizeof (arm_saved_state32_t)/sizeof(unsigned int))) |
390 | |
391 | struct arm_saved_state64 { |
392 | uint64_t x[29]; /* General purpose registers x0-x28 */ |
393 | uint64_t fp; /* Frame pointer x29 */ |
394 | uint64_t lr; /* Link register x30 */ |
395 | uint64_t sp; /* Stack pointer x31 */ |
396 | uint64_t pc; /* Program counter */ |
397 | uint32_t cpsr; /* Current program status register */ |
398 | uint32_t reserved; /* Reserved padding */ |
399 | uint64_t far; /* Virtual fault address */ |
400 | uint32_t esr; /* Exception syndrome register */ |
401 | uint32_t exception; /* Exception number */ |
402 | }; |
403 | typedef struct arm_saved_state64 arm_saved_state64_t; |
404 | |
405 | #define ARM_SAVED_STATE64_COUNT ((mach_msg_type_number_t) \ |
406 | (sizeof (arm_saved_state64_t)/sizeof(unsigned int))) |
407 | |
408 | struct arm_saved_state64_tagged { |
409 | uint32_t tag; |
410 | struct arm_saved_state64 state; |
411 | }; |
412 | typedef struct arm_saved_state64_tagged arm_saved_state64_tagged_t; |
413 | |
414 | struct arm_saved_state { |
415 | arm_state_hdr_t ash; |
416 | union { |
417 | struct arm_saved_state32 ss_32; |
418 | struct arm_saved_state64 ss_64; |
419 | } uss; |
420 | } __attribute__((aligned(16))); |
421 | #define ss_32 uss.ss_32 |
422 | #define ss_64 uss.ss_64 |
423 | |
424 | typedef struct arm_saved_state arm_saved_state_t; |
425 | |
426 | |
427 | static inline boolean_t |
428 | is_saved_state32(const arm_saved_state_t *iss) |
429 | { |
430 | return (iss->ash.flavor == ARM_SAVED_STATE32); |
431 | } |
432 | |
433 | static inline boolean_t |
434 | is_saved_state64(const arm_saved_state_t *iss) |
435 | { |
436 | return (iss->ash.flavor == ARM_SAVED_STATE64); |
437 | } |
438 | |
439 | static inline arm_saved_state32_t* |
440 | saved_state32(arm_saved_state_t *iss) |
441 | { |
442 | return &iss->ss_32; |
443 | } |
444 | |
445 | static inline const arm_saved_state32_t* |
446 | const_saved_state32(const arm_saved_state_t *iss) |
447 | { |
448 | return &iss->ss_32; |
449 | } |
450 | |
451 | static inline arm_saved_state64_t* |
452 | saved_state64(arm_saved_state_t *iss) |
453 | { |
454 | return &iss->ss_64; |
455 | } |
456 | |
457 | static inline const arm_saved_state64_t* |
458 | const_saved_state64(const arm_saved_state_t *iss) |
459 | { |
460 | return &iss->ss_64; |
461 | } |
462 | |
463 | static inline register_t |
464 | get_saved_state_pc(const arm_saved_state_t *iss) |
465 | { |
466 | return (is_saved_state32(iss) ? const_saved_state32(iss)->pc : const_saved_state64(iss)->pc); |
467 | } |
468 | |
469 | static inline void |
470 | set_saved_state_pc(arm_saved_state_t *iss, register_t pc) |
471 | { |
472 | if (is_saved_state32(iss)) { |
473 | saved_state32(iss)->pc = CAST_ASSERT_SAFE(uint32_t, pc); |
474 | } else { |
475 | saved_state64(iss)->pc = pc; |
476 | } |
477 | } |
478 | |
479 | static inline register_t |
480 | get_saved_state_sp(const arm_saved_state_t *iss) |
481 | { |
482 | return (is_saved_state32(iss) ? const_saved_state32(iss)->sp : const_saved_state64(iss)->sp); |
483 | } |
484 | |
485 | static inline void |
486 | set_saved_state_sp(arm_saved_state_t *iss, register_t sp) |
487 | { |
488 | if (is_saved_state32(iss)) { |
489 | saved_state32(iss)->sp = CAST_ASSERT_SAFE(uint32_t, sp); |
490 | } else { |
491 | saved_state64(iss)->sp = sp; |
492 | } |
493 | } |
494 | |
495 | static inline register_t |
496 | get_saved_state_lr(const arm_saved_state_t *iss) |
497 | { |
498 | return (is_saved_state32(iss) ? const_saved_state32(iss)->lr : const_saved_state64(iss)->lr); |
499 | } |
500 | |
501 | static inline void |
502 | set_saved_state_lr(arm_saved_state_t *iss, register_t lr) |
503 | { |
504 | if (is_saved_state32(iss)) { |
505 | saved_state32(iss)->lr = CAST_ASSERT_SAFE(uint32_t, lr); |
506 | } else { |
507 | saved_state64(iss)->lr = lr; |
508 | } |
509 | } |
510 | |
511 | static inline register_t |
512 | get_saved_state_fp(const arm_saved_state_t *iss) |
513 | { |
514 | return (is_saved_state32(iss) ? const_saved_state32(iss)->r[7] : const_saved_state64(iss)->fp); |
515 | } |
516 | |
517 | static inline void |
518 | set_saved_state_fp(arm_saved_state_t *iss, register_t fp) |
519 | { |
520 | if (is_saved_state32(iss)) { |
521 | saved_state32(iss)->r[7] = CAST_ASSERT_SAFE(uint32_t, fp); |
522 | } else { |
523 | saved_state64(iss)->fp = fp; |
524 | } |
525 | } |
526 | |
527 | static inline int |
528 | check_saved_state_reglimit(const arm_saved_state_t *iss, unsigned reg) |
529 | { |
530 | return (is_saved_state32(iss) ? (reg < ARM_SAVED_STATE32_COUNT) : (reg < ARM_SAVED_STATE64_COUNT)); |
531 | } |
532 | |
533 | static inline register_t |
534 | get_saved_state_reg(const arm_saved_state_t *iss, unsigned reg) |
535 | { |
536 | if (!check_saved_state_reglimit(iss, reg)) return 0; |
537 | |
538 | return (is_saved_state32(iss) ? (const_saved_state32(iss)->r[reg]) : (const_saved_state64(iss)->x[reg])); |
539 | } |
540 | |
541 | static inline void |
542 | set_saved_state_reg(arm_saved_state_t *iss, unsigned reg, register_t value) |
543 | { |
544 | if (!check_saved_state_reglimit(iss, reg)) return; |
545 | |
546 | if (is_saved_state32(iss)) { |
547 | saved_state32(iss)->r[reg] = CAST_ASSERT_SAFE(uint32_t, value); |
548 | } else { |
549 | saved_state64(iss)->x[reg] = value; |
550 | } |
551 | } |
552 | |
553 | static inline uint32_t |
554 | get_saved_state_cpsr(const arm_saved_state_t *iss) |
555 | { |
556 | return (is_saved_state32(iss) ? const_saved_state32(iss)->cpsr : const_saved_state64(iss)->cpsr); |
557 | } |
558 | |
559 | static inline void |
560 | set_saved_state_cpsr(arm_saved_state_t *iss, uint32_t cpsr) |
561 | { |
562 | if (is_saved_state32(iss)) { |
563 | saved_state32(iss)->cpsr = cpsr; |
564 | } else { |
565 | saved_state64(iss)->cpsr = cpsr; |
566 | } |
567 | } |
568 | |
569 | static inline register_t |
570 | get_saved_state_far(const arm_saved_state_t *iss) |
571 | { |
572 | return (is_saved_state32(iss) ? const_saved_state32(iss)->far : const_saved_state64(iss)->far); |
573 | } |
574 | |
575 | static inline void |
576 | set_saved_state_far(arm_saved_state_t *iss, register_t far) |
577 | { |
578 | if (is_saved_state32(iss)) { |
579 | saved_state32(iss)->far = CAST_ASSERT_SAFE(uint32_t, far); |
580 | } else { |
581 | saved_state64(iss)->far = far; |
582 | } |
583 | } |
584 | |
585 | static inline uint32_t |
586 | get_saved_state_esr(const arm_saved_state_t *iss) |
587 | { |
588 | return (is_saved_state32(iss) ? const_saved_state32(iss)->esr : const_saved_state64(iss)->esr); |
589 | } |
590 | |
591 | static inline void |
592 | set_saved_state_esr(arm_saved_state_t *iss, uint32_t esr) |
593 | { |
594 | if (is_saved_state32(iss)) { |
595 | saved_state32(iss)->esr = esr; |
596 | } else { |
597 | saved_state64(iss)->esr = esr; |
598 | } |
599 | } |
600 | |
601 | static inline uint32_t |
602 | get_saved_state_exc(const arm_saved_state_t *iss) |
603 | { |
604 | return (is_saved_state32(iss) ? const_saved_state32(iss)->exception : const_saved_state64(iss)->exception); |
605 | } |
606 | |
607 | static inline void |
608 | set_saved_state_exc(arm_saved_state_t *iss, uint32_t exc) |
609 | { |
610 | if (is_saved_state32(iss)) { |
611 | saved_state32(iss)->exception = exc; |
612 | } else { |
613 | saved_state64(iss)->exception = exc; |
614 | } |
615 | } |
616 | |
617 | extern void panic_unimplemented(void); |
618 | |
619 | static inline int |
620 | get_saved_state_svc_number(const arm_saved_state_t *iss) |
621 | { |
622 | 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 */ |
623 | } |
624 | |
625 | typedef _STRUCT_ARM_LEGACY_DEBUG_STATE arm_legacy_debug_state_t; |
626 | |
627 | struct arm_debug_aggregate_state { |
628 | arm_state_hdr_t dsh; |
629 | union { |
630 | arm_debug_state32_t ds32; |
631 | arm_debug_state64_t ds64; |
632 | } uds; |
633 | } __attribute__((aligned(16))); |
634 | |
635 | typedef struct arm_debug_aggregate_state arm_debug_state_t; |
636 | |
637 | #define ARM_LEGACY_DEBUG_STATE_COUNT ((mach_msg_type_number_t) \ |
638 | (sizeof (arm_legacy_debug_state_t)/sizeof(uint32_t))) |
639 | |
640 | /* |
641 | * NEON context |
642 | */ |
643 | typedef __uint128_t uint128_t; |
644 | typedef uint64_t uint64x2_t __attribute__((ext_vector_type(2))); |
645 | typedef uint32_t uint32x4_t __attribute__((ext_vector_type(4))); |
646 | |
647 | struct arm_neon_saved_state32 { |
648 | union { |
649 | uint128_t q[16]; |
650 | uint64_t d[32]; |
651 | uint32_t s[32]; |
652 | } v; |
653 | uint32_t fpsr; |
654 | uint32_t fpcr; |
655 | }; |
656 | typedef struct arm_neon_saved_state32 arm_neon_saved_state32_t; |
657 | |
658 | #define ARM_NEON_SAVED_STATE32_COUNT ((mach_msg_type_number_t) \ |
659 | (sizeof (arm_neon_saved_state32_t)/sizeof(unsigned int))) |
660 | |
661 | struct arm_neon_saved_state64 { |
662 | union { |
663 | uint128_t q[32]; |
664 | uint64x2_t d[32]; |
665 | uint32x4_t s[32]; |
666 | } v; |
667 | uint32_t fpsr; |
668 | uint32_t fpcr; |
669 | }; |
670 | typedef struct arm_neon_saved_state64 arm_neon_saved_state64_t; |
671 | |
672 | #define ARM_NEON_SAVED_STATE64_COUNT ((mach_msg_type_number_t) \ |
673 | (sizeof (arm_neon_saved_state64_t)/sizeof(unsigned int))) |
674 | |
675 | struct arm_neon_saved_state { |
676 | arm_state_hdr_t nsh; |
677 | union { |
678 | struct arm_neon_saved_state32 ns_32; |
679 | struct arm_neon_saved_state64 ns_64; |
680 | } uns; |
681 | }; |
682 | typedef struct arm_neon_saved_state arm_neon_saved_state_t; |
683 | #define ns_32 uns.ns_32 |
684 | #define ns_64 uns.ns_64 |
685 | |
686 | static inline boolean_t |
687 | is_neon_saved_state32(const arm_neon_saved_state_t *state) |
688 | { |
689 | return (state->nsh.flavor == ARM_NEON_SAVED_STATE32); |
690 | } |
691 | |
692 | static inline boolean_t |
693 | is_neon_saved_state64(const arm_neon_saved_state_t *state) |
694 | { |
695 | return (state->nsh.flavor == ARM_NEON_SAVED_STATE64); |
696 | } |
697 | |
698 | static inline arm_neon_saved_state32_t * |
699 | neon_state32(arm_neon_saved_state_t *state) |
700 | { |
701 | return &state->ns_32; |
702 | } |
703 | |
704 | static inline arm_neon_saved_state64_t * |
705 | neon_state64(arm_neon_saved_state_t *state) |
706 | { |
707 | return &state->ns_64; |
708 | } |
709 | |
710 | |
711 | /* |
712 | * Aggregated context |
713 | */ |
714 | |
715 | struct arm_context { |
716 | struct arm_saved_state ss; |
717 | struct arm_neon_saved_state ns; |
718 | }; |
719 | typedef struct arm_context arm_context_t; |
720 | |
721 | extern void saved_state_to_thread_state64(const arm_saved_state_t*, arm_thread_state64_t*); |
722 | extern void thread_state64_to_saved_state(const arm_thread_state64_t*, arm_saved_state_t*); |
723 | |
724 | #else |
725 | #error Unknown arch |
726 | #endif |
727 | |
728 | extern void saved_state_to_thread_state32(const arm_saved_state_t*, arm_thread_state32_t*); |
729 | extern void thread_state32_to_saved_state(const arm_thread_state32_t*, arm_saved_state_t*); |
730 | |
731 | #endif /* XNU_KERNEL_PRIVATE */ |
732 | |
733 | #endif /* _ARM_THREAD_STATUS_H_ */ |
734 | |