]>
Commit | Line | Data |
---|---|---|
f427ee49 A |
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 | #ifndef _ARM64_PAC_ASM_H_ | |
30 | #define _ARM64_PAC_ASM_H_ | |
31 | ||
32 | #ifndef __ASSEMBLER__ | |
33 | #error "This header should only be used in .s files" | |
34 | #endif | |
35 | ||
36 | #include <pexpert/arm64/board_config.h> | |
37 | #include <arm64/proc_reg.h> | |
38 | #include "assym.s" | |
39 | ||
40 | #if defined(HAS_APPLE_PAC) | |
41 | ||
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 | |
45 | ||
46 | .macro IF_PAC_FAST_A_KEY_SWITCHING label, tmp | |
47 | .error "This macro should never need to be used on this CPU family." | |
48 | .endmacro | |
49 | ||
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 | |
52 | .endmacro | |
53 | ||
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 | |
57 | ||
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 | |
60 | .endmacro | |
61 | ||
62 | .macro IF_PAC_SLOW_A_KEY_SWITCHING label, tmp | |
63 | .error "This macro should never need to be used on this CPU family." | |
64 | .endmacro | |
65 | ||
66 | #endif /**/ | |
67 | ||
68 | /* BEGIN IGNORE CODESTYLE */ | |
69 | ||
70 | /** | |
71 | * REPROGRAM_JOP_KEYS | |
72 | * | |
73 | * Reprograms the A-key registers if needed, and updates current_cpu_datap()->jop_key. | |
74 | * | |
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. | |
77 | * | |
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 | |
82 | */ | |
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 | |
86 | b.eq \skip_label | |
87 | SET_JOP_KEY_REGISTERS \new_jop_key, \tmp | |
88 | str \new_jop_key, [\cpudatap, CPU_JOP_KEY] | |
89 | .endmacro | |
90 | ||
91 | /** | |
92 | * SET_JOP_KEY_REGISTERS | |
93 | * | |
94 | * Unconditionally reprograms the A-key registers. The caller is responsible for | |
95 | * updating current_cpu_datap()->jop_key as needed. | |
96 | * | |
97 | * new_jop_key - new APIAKeyLo value | |
98 | * tmp - scratch register | |
99 | */ | |
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 */ | |
110 | ||
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 | |
116 | add \tmp, \tmp, #1 | |
117 | msr APDAKeyLo_EL1, \tmp | |
118 | add \tmp, \tmp, #1 | |
119 | msr APDAKeyHi_EL1, \tmp | |
120 | #endif /* HAS_PAC_SLOW_A_KEY_SWITCHING */ | |
121 | ||
122 | Lset_jop_key_registers_done_\@: | |
123 | .endmacro | |
124 | ||
125 | /* END IGNORE CODESTYLE */ | |
126 | ||
127 | #endif /* defined(HAS_APPLE_PAC) */ | |
128 | ||
129 | #endif /* _ARM64_PAC_ASM_H_ */ | |
130 | ||
131 | /* vim: set ts=4 ft=asm: */ |