c6808de5b716f50fd471c02ad51bba2e85f3a049
[project/bcm63xx/atf.git] / lib / extensions / pauth / pauth_helpers.S
1 /*
2 * Copyright (c) 2019, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <arch.h>
8 #include <asm_macros.S>
9 #include <lib/el3_runtime/cpu_data.h>
10
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
17 /* -------------------------------------------------------------
18 * Program APIAKey_EL1 and enable pointer authentication in EL1
19 * -------------------------------------------------------------
20 */
21 func pauth_init_enable_el1
22 stp x29, x30, [sp, #-16]!
23
24 /* Initialize platform key */
25 bl plat_init_apkey
26
27 /* Program instruction key A used by the Trusted Firmware */
28 msr APIAKeyLo_EL1, x0
29 msr APIAKeyHi_EL1, x1
30
31 /* Enable pointer authentication */
32 mrs x0, sctlr_el1
33 orr x0, x0, #SCTLR_EnIA_BIT
34
35 #if ENABLE_BTI
36 /* Enable PAC branch type compatibility */
37 bic x0, x0, #(SCTLR_BT0_BIT | SCTLR_BT1_BIT)
38 #endif
39 msr sctlr_el1, x0
40 isb
41
42 ldp x29, x30, [sp], #16
43 ret
44 endfunc pauth_init_enable_el1
45
46 /* -------------------------------------------------------------
47 * Disable pointer authentication in EL3
48 * -------------------------------------------------------------
49 */
50 func pauth_disable_el1
51 mrs x0, sctlr_el1
52 bic x0, x0, #SCTLR_EnIA_BIT
53 msr sctlr_el1, x0
54 isb
55 ret
56 endfunc pauth_disable_el1
57
58 /* -------------------------------------------------------------
59 * Program APIAKey_EL1 and enable pointer authentication in EL3
60 * -------------------------------------------------------------
61 */
62 func pauth_init_enable_el3
63 stp x29, x30, [sp, #-16]!
64
65 /* Initialize platform key */
66 bl plat_init_apkey
67
68 /* Program instruction key A used by the Trusted Firmware */
69 msr APIAKeyLo_EL1, x0
70 msr APIAKeyHi_EL1, x1
71
72 /* Enable pointer authentication */
73 mrs x0, sctlr_el3
74 orr x0, x0, #SCTLR_EnIA_BIT
75
76 #if ENABLE_BTI
77 /* Enable PAC branch type compatibility */
78 bic x0, x0, #SCTLR_BT_BIT
79 #endif
80 msr sctlr_el3, x0
81 isb
82
83 ldp x29, x30, [sp], #16
84 ret
85 endfunc pauth_init_enable_el3
86
87 /* -------------------------------------------------------------
88 * Disable pointer authentication in EL3
89 * -------------------------------------------------------------
90 */
91 func pauth_disable_el3
92 mrs x0, sctlr_el3
93 bic x0, x0, #SCTLR_EnIA_BIT
94 msr sctlr_el3, x0
95 isb
96 ret
97 endfunc pauth_disable_el3
98
99 /* -------------------------------------------------------------
100 * The following function strictly follows the AArch64 PCS
101 * to use x9-x17 (temporary caller-saved registers) to load
102 * the APIAKey_EL1 used by the firmware.
103 * -------------------------------------------------------------
104 */
105 func pauth_load_bl31_apiakey
106 /* tpidr_el3 contains the address of cpu_data structure */
107 mrs x9, tpidr_el3
108
109 /* Load apiakey from cpu_data */
110 ldp x10, x11, [x9, #CPU_DATA_APIAKEY_OFFSET]
111
112 /* Program instruction key A */
113 msr APIAKeyLo_EL1, x10
114 msr APIAKeyHi_EL1, x11
115 isb
116 ret
117 endfunc pauth_load_bl31_apiakey