]> git.saurik.com Git - apple/xnu.git/blob - osfmk/arm64/machine_routines_asm.h
xnu-6153.11.26.tar.gz
[apple/xnu.git] / osfmk / arm64 / machine_routines_asm.h
1 /*
2 * Copyright (c) 2019 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 #include <pexpert/arm64/board_config.h>
30 #include "assym.s"
31
32 #ifndef __ASSEMBLER__
33 #error "This header should only be used in .s files"
34 #endif
35
36 /**
37 * Loads the following values from the thread_kernel_state pointer in x0:
38 *
39 * x1: $x0->ss_64.pc
40 * w2: $x0->ss_64.cpsr
41 * x16: $x0->ss_64.x16
42 * x17: $x0->ss_64.x17
43 * lr: $x0->ss_64.lr
44 *
45 * On CPUs with PAC support, this macro will auth the above values with ml_check_signed_state().
46 *
47 * arg0 - scratch register 1
48 * arg1 - scratch register 2
49 * arg2 - scratch register 3
50 * arg3 - scratch register 4
51 * arg4 - scratch register 5
52 */
53 /* BEGIN IGNORE CODESTYLE */
54 .macro AUTH_THREAD_STATE_IN_X0
55 ldr x1, [x0, SS64_PC]
56 ldr w2, [x0, SS64_CPSR]
57 ldp x16, x17, [x0, SS64_X16]
58
59 #if defined(HAS_APPLE_PAC)
60 // Save x3-x5 to preserve across call
61 mov $2, x3
62 mov $3, x4
63 mov $4, x5
64
65 /*
66 * Arg0: The ARM context pointer (already in x0)
67 * Arg1: PC to check (loaded above)
68 * Arg2: CPSR to check (loaded above)
69 * Arg3: the LR to check
70 *
71 * Stash saved state PC and CPSR in other registers to avoid reloading potentially unauthed
72 * values from memory. (ml_check_signed_state will clobber x1 and x2.)
73 */
74 mov $0, x1
75 mov $1, x2
76 ldr x3, [x0, SS64_LR]
77 mov x4, x16
78 mov x5, x17
79 bl EXT(ml_check_signed_state)
80 mov x1, $0
81 mov x2, $1
82
83 // LR was already loaded/authed earlier, if we reload it we might be loading a potentially unauthed value
84 mov lr, x3
85 mov x3, $2
86 mov x4, $3
87 mov x5, $4
88 #else
89 ldr lr, [x0, SS64_LR]
90 #endif /* defined(HAS_APPLE_PAC) */
91 .endmacro
92 /* END IGNORE CODESTYLE */
93
94 /* vim: set ft=asm: */