blob: f9777bbfecf7c5cea9b20f76aeb22027acc85a79 [file] [log] [blame]
Alexei Fedorovf41355c2019-09-13 14:11:59 +01001/*
Boyan Karatotev7a5246e2025-03-26 15:54:55 +00002 * Copyright (c) 2019-2025, Arm Limited. All rights reserved.
Alexei Fedorovf41355c2019-09-13 14:11:59 +01003 *
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
Alexei Fedorovf41355c2019-09-13 14:11:59 +010011 .globl pauth_load_bl31_apiakey
Alexei Fedorov3dd9f2b2019-10-01 13:58:23 +010012 .globl pauth_load_bl1_apiakey_enable
Alexei Fedorovf41355c2019-09-13 14:11:59 +010013
14/* -------------------------------------------------------------
Alexei Fedorov3dd9f2b2019-10-01 13:58:23 +010015 * The following functions strictly follow the AArch64 PCS
Alexei Fedorovf41355c2019-09-13 14:11:59 +010016 * to use x9-x17 (temporary caller-saved registers) to load
Alexei Fedorov3dd9f2b2019-10-01 13:58:23 +010017 * the APIAKey_EL1 and enable pointer authentication.
Alexei Fedorovf41355c2019-09-13 14:11:59 +010018 * -------------------------------------------------------------
19 */
20func pauth_load_bl31_apiakey
21 /* tpidr_el3 contains the address of cpu_data structure */
22 mrs x9, tpidr_el3
23
24 /* Load apiakey from cpu_data */
25 ldp x10, x11, [x9, #CPU_DATA_APIAKEY_OFFSET]
26
27 /* Program instruction key A */
28 msr APIAKeyLo_EL1, x10
29 msr APIAKeyHi_EL1, x11
30 isb
31 ret
32endfunc pauth_load_bl31_apiakey
Alexei Fedorov3dd9f2b2019-10-01 13:58:23 +010033
34func pauth_load_bl1_apiakey_enable
35 /* Load instruction key A used by the Trusted Firmware */
36 adrp x9, bl1_apiakey
37 add x9, x9, :lo12:bl1_apiakey
38 ldp x10, x11, [x9]
39
40 /* Program instruction key A */
41 msr APIAKeyLo_EL1, x10
42 msr APIAKeyHi_EL1, x11
43
44 /* Enable pointer authentication */
45 mrs x9, sctlr_el3
46 orr x9, x9, #SCTLR_EnIA_BIT
Alexei Fedorov3dd9f2b2019-10-01 13:58:23 +010047 msr sctlr_el3, x9
48 isb
49 ret
50endfunc pauth_load_bl1_apiakey_enable