Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 1 | /* |
Boyan Karatotev | 7a5246e | 2025-03-26 15:54:55 +0000 | [diff] [blame] | 2 | * Copyright (c) 2019-2025, Arm Limited. All rights reserved. |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 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 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 11 | .globl pauth_load_bl31_apiakey |
Alexei Fedorov | 3dd9f2b | 2019-10-01 13:58:23 +0100 | [diff] [blame] | 12 | .globl pauth_load_bl1_apiakey_enable |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 13 | |
| 14 | /* ------------------------------------------------------------- |
Alexei Fedorov | 3dd9f2b | 2019-10-01 13:58:23 +0100 | [diff] [blame] | 15 | * The following functions strictly follow the AArch64 PCS |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 16 | * to use x9-x17 (temporary caller-saved registers) to load |
Alexei Fedorov | 3dd9f2b | 2019-10-01 13:58:23 +0100 | [diff] [blame] | 17 | * the APIAKey_EL1 and enable pointer authentication. |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 18 | * ------------------------------------------------------------- |
| 19 | */ |
| 20 | func 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 |
| 32 | endfunc pauth_load_bl31_apiakey |
Alexei Fedorov | 3dd9f2b | 2019-10-01 13:58:23 +0100 | [diff] [blame] | 33 | |
| 34 | func 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 Fedorov | 3dd9f2b | 2019-10-01 13:58:23 +0100 | [diff] [blame] | 47 | msr sctlr_el3, x9 |
| 48 | isb |
| 49 | ret |
| 50 | endfunc pauth_load_bl1_apiakey_enable |