2 * Copyright (c) 2019, Arm Limited. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
8 #include <asm_macros.S>
9 #include <lib/el3_runtime/cpu_data.h>
11 .global pauth_init_enable_el1
12 .global pauth_disable_el1
13 .global pauth_init_enable_el3
14 .global pauth_disable_el3
15 .globl pauth_load_bl31_apiakey
16 .globl pauth_load_bl1_apiakey_enable
18 /* -------------------------------------------------------------
19 * Program APIAKey_EL1 and enable pointer authentication in EL1
20 * -------------------------------------------------------------
22 func pauth_init_enable_el1
23 stp x29, x30, [sp, #-16]!
25 /* Initialize platform key */
28 /* Program instruction key A used by the Trusted Firmware */
32 /* Enable pointer authentication */
34 orr x0, x0, #SCTLR_EnIA_BIT
37 /* Enable PAC branch type compatibility */
38 bic x0, x0, #(SCTLR_BT0_BIT | SCTLR_BT1_BIT)
43 ldp x29, x30, [sp], #16
45 endfunc pauth_init_enable_el1
47 /* -------------------------------------------------------------
48 * Disable pointer authentication in EL3
49 * -------------------------------------------------------------
51 func pauth_disable_el1
53 bic x0, x0, #SCTLR_EnIA_BIT
57 endfunc pauth_disable_el1
59 /* -------------------------------------------------------------
60 * Program APIAKey_EL1 and enable pointer authentication in EL3
61 * -------------------------------------------------------------
63 func pauth_init_enable_el3
64 stp x29, x30, [sp, #-16]!
66 /* Initialize platform key */
69 /* Program instruction key A used by the Trusted Firmware */
73 /* Enable pointer authentication */
75 orr x0, x0, #SCTLR_EnIA_BIT
78 /* Enable PAC branch type compatibility */
79 bic x0, x0, #SCTLR_BT_BIT
84 ldp x29, x30, [sp], #16
86 endfunc pauth_init_enable_el3
88 /* -------------------------------------------------------------
89 * Disable pointer authentication in EL3
90 * -------------------------------------------------------------
92 func pauth_disable_el3
94 bic x0, x0, #SCTLR_EnIA_BIT
98 endfunc pauth_disable_el3
100 /* -------------------------------------------------------------
101 * The following functions strictly follow the AArch64 PCS
102 * to use x9-x17 (temporary caller-saved registers) to load
103 * the APIAKey_EL1 and enable pointer authentication.
104 * -------------------------------------------------------------
106 func pauth_load_bl31_apiakey
107 /* tpidr_el3 contains the address of cpu_data structure */
110 /* Load apiakey from cpu_data */
111 ldp x10, x11, [x9, #CPU_DATA_APIAKEY_OFFSET]
113 /* Program instruction key A */
114 msr APIAKeyLo_EL1, x10
115 msr APIAKeyHi_EL1, x11
118 endfunc pauth_load_bl31_apiakey
120 func pauth_load_bl1_apiakey_enable
121 /* Load instruction key A used by the Trusted Firmware */
123 add x9, x9, :lo12:bl1_apiakey
126 /* Program instruction key A */
127 msr APIAKeyLo_EL1, x10
128 msr APIAKeyHi_EL1, x11
130 /* Enable pointer authentication */
132 orr x9, x9, #SCTLR_EnIA_BIT
135 /* Enable PAC branch type compatibility */
136 bic x9, x9, #SCTLR_BT_BIT
141 endfunc pauth_load_bl1_apiakey_enable