2 * Copyright (c) 2019 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 #ifndef _ARM64_PAC_ASM_H_
30 #define _ARM64_PAC_ASM_H_
33 #error "This header should only be used in .s files"
36 #include <pexpert/arm64/board_config.h>
37 #include <arm64/proc_reg.h>
40 #if defined(HAS_APPLE_PAC)
42 #if defined(HAS_APCTL_EL1_USERKEYEN)
43 #define HAS_PAC_FAST_A_KEY_SWITCHING 1
44 #define HAS_PAC_SLOW_A_KEY_SWITCHING 0
46 .macro IF_PAC_FAST_A_KEY_SWITCHING label
, tmp
47 .error
"This macro should never need to be used on this CPU family."
50 /* We know at compile time that this CPU family definitely doesn't need slow A-key switching */
51 .macro IF_PAC_SLOW_A_KEY_SWITCHING label
, tmp
54 #else /* !&& !defined(HAS_APCTL_EL1_USERKEYEN) */
55 #define HAS_PAC_FAST_A_KEY_SWITCHING 0
56 #define HAS_PAC_SLOW_A_KEY_SWITCHING 1
58 /* We know at compile time that this CPU family definitely doesn't support fast A-key switching */
59 .macro IF_PAC_FAST_A_KEY_SWITCHING label
, tmp
62 .macro IF_PAC_SLOW_A_KEY_SWITCHING label
, tmp
63 .error
"This macro should never need to be used on this CPU family."
68 /* BEGIN IGNORE CODESTYLE */
73 * Reprograms the A-key registers if needed, and updates current_cpu_datap()->jop_key.
75 * On CPUs where fast A-key switching is implemented, this macro reprograms KERNKey_EL1.
76 * On other CPUs, it reprograms AP{D,I}AKey_EL1.
78 * skip_label - branch to this label if new_jop_key is already loaded into CPU
79 * new_jop_key - new APIAKeyLo value
80 * cpudatap - current cpu_data_t *
81 * tmp - scratch register
83 .macro REPROGRAM_JOP_KEYS skip_label
, new_jop_key
, cpudatap
, tmp
84 ldr
\tmp
, [\cpudatap
, CPU_JOP_KEY
]
85 cmp
\new_jop_key
, \tmp
87 SET_JOP_KEY_REGISTERS
\new_jop_key
, \tmp
88 str
\new_jop_key
, [\cpudatap
, CPU_JOP_KEY
]
92 * SET_JOP_KEY_REGISTERS
94 * Unconditionally reprograms the A-key registers. The caller is responsible for
95 * updating current_cpu_datap()->jop_key as needed.
97 * new_jop_key - new APIAKeyLo value
98 * tmp - scratch register
100 .macro SET_JOP_KEY_REGISTERS new_jop_key
, tmp
101 #if HAS_PAC_FAST_A_KEY_SWITCHING
102 IF_PAC_SLOW_A_KEY_SWITCHING Lslow_reprogram_jop_keys_\@
, \tmp
103 msr KERNKeyLo_EL1
, \new_jop_key
104 add
\tmp
, \new_jop_key
, #1
105 msr KERNKeyHi_EL1
, \tmp
106 #endif /* HAS_PAC_FAST_A_KEY_SWITCHING */
107 #if HAS_PAC_FAST_A_KEY_SWITCHING && HAS_PAC_SLOW_A_KEY_SWITCHING
108 b Lset_jop_key_registers_done_\@
109 #endif /* HAS_PAC_FAST_A_KEY_SWITCHING && HAS_PAC_SLOW_A_KEY_SWITCHING */
111 #if HAS_PAC_SLOW_A_KEY_SWITCHING
112 Lslow_reprogram_jop_keys_\@
:
113 msr APIAKeyLo_EL1
, \new_jop_key
114 add
\tmp
, \new_jop_key
, #1
115 msr APIAKeyHi_EL1
, \tmp
117 msr APDAKeyLo_EL1
, \tmp
119 msr APDAKeyHi_EL1
, \tmp
120 #endif /* HAS_PAC_SLOW_A_KEY_SWITCHING */
122 Lset_jop_key_registers_done_\@
:
125 /* END IGNORE CODESTYLE */
127 #endif /* defined(HAS_APPLE_PAC) */
129 #endif /* _ARM64_PAC_ASM_H_ */
131 /* vim: set ts=4 ft=asm: */