Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 1 | /* |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2022, Arm Limited and Contributors. All rights reserved. |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 7 | #include <arch.h> |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 8 | #include <asm_macros.S> |
Jan Dabros | fa01598 | 2019-12-02 13:30:03 +0100 | [diff] [blame] | 9 | #include <assert_macros.S> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 10 | #include <context.h> |
Manish V Badarkhe | e07e808 | 2020-07-23 12:43:25 +0100 | [diff] [blame] | 11 | #include <el3_common_macros.S> |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 12 | |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 13 | #if CTX_INCLUDE_EL2_REGS |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 14 | .global el2_sysregs_context_save_common |
| 15 | .global el2_sysregs_context_restore_common |
| 16 | #if ENABLE_SPE_FOR_LOWER_ELS |
| 17 | .global el2_sysregs_context_save_spe |
| 18 | .global el2_sysregs_context_restore_spe |
| 19 | #endif /* ENABLE_SPE_FOR_LOWER_ELS */ |
| 20 | #if CTX_INCLUDE_MTE_REGS |
| 21 | .global el2_sysregs_context_save_mte |
| 22 | .global el2_sysregs_context_restore_mte |
| 23 | #endif /* CTX_INCLUDE_MTE_REGS */ |
| 24 | #if ENABLE_MPAM_FOR_LOWER_ELS |
| 25 | .global el2_sysregs_context_save_mpam |
| 26 | .global el2_sysregs_context_restore_mpam |
| 27 | #endif /* ENABLE_MPAM_FOR_LOWER_ELS */ |
| 28 | #if ENABLE_FEAT_FGT |
| 29 | .global el2_sysregs_context_save_fgt |
| 30 | .global el2_sysregs_context_restore_fgt |
| 31 | #endif /* ENABLE_FEAT_FGT */ |
| 32 | #if ENABLE_FEAT_ECV |
| 33 | .global el2_sysregs_context_save_ecv |
| 34 | .global el2_sysregs_context_restore_ecv |
| 35 | #endif /* ENABLE_FEAT_ECV */ |
| 36 | #if ENABLE_FEAT_VHE |
| 37 | .global el2_sysregs_context_save_vhe |
| 38 | .global el2_sysregs_context_restore_vhe |
| 39 | #endif /* ENABLE_FEAT_VHE */ |
| 40 | #if RAS_EXTENSION |
| 41 | .global el2_sysregs_context_save_ras |
| 42 | .global el2_sysregs_context_restore_ras |
| 43 | #endif /* RAS_EXTENSION */ |
| 44 | #if CTX_INCLUDE_NEVE_REGS |
| 45 | .global el2_sysregs_context_save_nv2 |
| 46 | .global el2_sysregs_context_restore_nv2 |
| 47 | #endif /* CTX_INCLUDE_NEVE_REGS */ |
| 48 | #if ENABLE_TRF_FOR_NS |
| 49 | .global el2_sysregs_context_save_trf |
| 50 | .global el2_sysregs_context_restore_trf |
| 51 | #endif /* ENABLE_TRF_FOR_NS */ |
| 52 | #if ENABLE_FEAT_CSV2_2 |
| 53 | .global el2_sysregs_context_save_csv2 |
| 54 | .global el2_sysregs_context_restore_csv2 |
| 55 | #endif /* ENABLE_FEAT_CSV2_2 */ |
| 56 | #if ENABLE_FEAT_HCX |
| 57 | .global el2_sysregs_context_save_hcx |
| 58 | .global el2_sysregs_context_restore_hcx |
| 59 | #endif /* ENABLE_FEAT_HCX */ |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 60 | #endif /* CTX_INCLUDE_EL2_REGS */ |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 61 | |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 62 | .global el1_sysregs_context_save |
| 63 | .global el1_sysregs_context_restore |
| 64 | #if CTX_INCLUDE_FPREGS |
| 65 | .global fpregs_context_save |
| 66 | .global fpregs_context_restore |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 67 | #endif /* CTX_INCLUDE_FPREGS */ |
Daniel Boulby | 95fb1aa | 2022-01-19 11:20:05 +0000 | [diff] [blame] | 68 | .global prepare_el3_entry |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 69 | .global restore_gp_pmcr_pauth_regs |
Manish V Badarkhe | e07e808 | 2020-07-23 12:43:25 +0100 | [diff] [blame] | 70 | .global save_and_update_ptw_el1_sys_regs |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 71 | .global el3_exit |
| 72 | |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 73 | #if CTX_INCLUDE_EL2_REGS |
| 74 | |
| 75 | /* ----------------------------------------------------- |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 76 | * The following functions strictly follow the AArch64 |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 77 | * PCS to use x9-x16 (temporary caller-saved registers) |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 78 | * to save/restore EL2 system register context. |
| 79 | * el2_sysregs_context_save/restore_common functions |
| 80 | * save and restore registers that are common to all |
| 81 | * configurations. The rest of the functions save and |
| 82 | * restore EL2 system registers that are present when a |
| 83 | * particular feature is enabled. All functions assume |
| 84 | * that 'x0' is pointing to a 'el2_sys_regs' structure |
| 85 | * where the register context will be saved/restored. |
Max Shvetsov | c9e2c92 | 2020-02-17 16:15:47 +0000 | [diff] [blame] | 86 | * |
| 87 | * The following registers are not added. |
| 88 | * AMEVCNTVOFF0<n>_EL2 |
| 89 | * AMEVCNTVOFF1<n>_EL2 |
| 90 | * ICH_AP0R<n>_EL2 |
| 91 | * ICH_AP1R<n>_EL2 |
| 92 | * ICH_LR<n>_EL2 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 93 | * ----------------------------------------------------- |
| 94 | */ |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 95 | func el2_sysregs_context_save_common |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 96 | mrs x9, actlr_el2 |
Max Shvetsov | c9e2c92 | 2020-02-17 16:15:47 +0000 | [diff] [blame] | 97 | mrs x10, afsr0_el2 |
| 98 | stp x9, x10, [x0, #CTX_ACTLR_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 99 | |
Max Shvetsov | c9e2c92 | 2020-02-17 16:15:47 +0000 | [diff] [blame] | 100 | mrs x11, afsr1_el2 |
| 101 | mrs x12, amair_el2 |
| 102 | stp x11, x12, [x0, #CTX_AFSR1_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 103 | |
Max Shvetsov | c9e2c92 | 2020-02-17 16:15:47 +0000 | [diff] [blame] | 104 | mrs x13, cnthctl_el2 |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 105 | mrs x14, cntvoff_el2 |
Max Shvetsov | c9e2c92 | 2020-02-17 16:15:47 +0000 | [diff] [blame] | 106 | stp x13, x14, [x0, #CTX_CNTHCTL_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 107 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 108 | mrs x15, cptr_el2 |
| 109 | str x15, [x0, #CTX_CPTR_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 110 | |
Arunachalam Ganapathy | dca591b | 2020-05-26 11:32:35 +0100 | [diff] [blame] | 111 | #if CTX_INCLUDE_AARCH32_REGS |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 112 | mrs x16, dbgvcr32_el2 |
| 113 | str x16, [x0, #CTX_DBGVCR32_EL2] |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 114 | #endif /* CTX_INCLUDE_AARCH32_REGS */ |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 115 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 116 | mrs x9, elr_el2 |
| 117 | mrs x10, esr_el2 |
| 118 | stp x9, x10, [x0, #CTX_ELR_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 119 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 120 | mrs x11, far_el2 |
| 121 | mrs x12, hacr_el2 |
| 122 | stp x11, x12, [x0, #CTX_FAR_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 123 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 124 | mrs x13, hcr_el2 |
| 125 | mrs x14, hpfar_el2 |
| 126 | stp x13, x14, [x0, #CTX_HCR_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 127 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 128 | mrs x15, hstr_el2 |
| 129 | mrs x16, ICC_SRE_EL2 |
| 130 | stp x15, x16, [x0, #CTX_HSTR_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 131 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 132 | mrs x9, ICH_HCR_EL2 |
| 133 | mrs x10, ICH_VMCR_EL2 |
| 134 | stp x9, x10, [x0, #CTX_ICH_HCR_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 135 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 136 | mrs x11, mair_el2 |
| 137 | mrs x12, mdcr_el2 |
| 138 | stp x11, x12, [x0, #CTX_MAIR_EL2] |
| 139 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 140 | mrs x14, sctlr_el2 |
| 141 | str x14, [x0, #CTX_SCTLR_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 142 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 143 | mrs x15, spsr_el2 |
| 144 | mrs x16, sp_el2 |
| 145 | stp x15, x16, [x0, #CTX_SPSR_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 146 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 147 | mrs x9, tcr_el2 |
| 148 | mrs x10, tpidr_el2 |
| 149 | stp x9, x10, [x0, #CTX_TCR_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 150 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 151 | mrs x11, ttbr0_el2 |
| 152 | mrs x12, vbar_el2 |
| 153 | stp x11, x12, [x0, #CTX_TTBR0_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 154 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 155 | mrs x13, vmpidr_el2 |
| 156 | mrs x14, vpidr_el2 |
| 157 | stp x13, x14, [x0, #CTX_VMPIDR_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 158 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 159 | mrs x15, vtcr_el2 |
| 160 | mrs x16, vttbr_el2 |
| 161 | stp x15, x16, [x0, #CTX_VTCR_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 162 | ret |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 163 | endfunc el2_sysregs_context_save_common |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 164 | |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 165 | func el2_sysregs_context_restore_common |
Max Shvetsov | c9e2c92 | 2020-02-17 16:15:47 +0000 | [diff] [blame] | 166 | ldp x9, x10, [x0, #CTX_ACTLR_EL2] |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 167 | msr actlr_el2, x9 |
Max Shvetsov | c9e2c92 | 2020-02-17 16:15:47 +0000 | [diff] [blame] | 168 | msr afsr0_el2, x10 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 169 | |
Max Shvetsov | c9e2c92 | 2020-02-17 16:15:47 +0000 | [diff] [blame] | 170 | ldp x11, x12, [x0, #CTX_AFSR1_EL2] |
| 171 | msr afsr1_el2, x11 |
| 172 | msr amair_el2, x12 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 173 | |
Max Shvetsov | c9e2c92 | 2020-02-17 16:15:47 +0000 | [diff] [blame] | 174 | ldp x13, x14, [x0, #CTX_CNTHCTL_EL2] |
| 175 | msr cnthctl_el2, x13 |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 176 | msr cntvoff_el2, x14 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 177 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 178 | ldr x15, [x0, #CTX_CPTR_EL2] |
| 179 | msr cptr_el2, x15 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 180 | |
Arunachalam Ganapathy | dca591b | 2020-05-26 11:32:35 +0100 | [diff] [blame] | 181 | #if CTX_INCLUDE_AARCH32_REGS |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 182 | ldr x16, [x0, #CTX_DBGVCR32_EL2] |
| 183 | msr dbgvcr32_el2, x16 |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 184 | #endif /* CTX_INCLUDE_AARCH32_REGS */ |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 185 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 186 | ldp x9, x10, [x0, #CTX_ELR_EL2] |
| 187 | msr elr_el2, x9 |
| 188 | msr esr_el2, x10 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 189 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 190 | ldp x11, x12, [x0, #CTX_FAR_EL2] |
| 191 | msr far_el2, x11 |
| 192 | msr hacr_el2, x12 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 193 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 194 | ldp x13, x14, [x0, #CTX_HCR_EL2] |
| 195 | msr hcr_el2, x13 |
| 196 | msr hpfar_el2, x14 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 197 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 198 | ldp x15, x16, [x0, #CTX_HSTR_EL2] |
| 199 | msr hstr_el2, x15 |
| 200 | msr ICC_SRE_EL2, x16 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 201 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 202 | ldp x9, x10, [x0, #CTX_ICH_HCR_EL2] |
| 203 | msr ICH_HCR_EL2, x9 |
| 204 | msr ICH_VMCR_EL2, x10 |
| 205 | |
| 206 | ldp x11, x12, [x0, #CTX_MAIR_EL2] |
| 207 | msr mair_el2, x11 |
| 208 | msr mdcr_el2, x12 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 209 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 210 | ldr x14, [x0, #CTX_SCTLR_EL2] |
| 211 | msr sctlr_el2, x14 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 212 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 213 | ldp x15, x16, [x0, #CTX_SPSR_EL2] |
| 214 | msr spsr_el2, x15 |
| 215 | msr sp_el2, x16 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 216 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 217 | ldp x9, x10, [x0, #CTX_TCR_EL2] |
| 218 | msr tcr_el2, x9 |
| 219 | msr tpidr_el2, x10 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 220 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 221 | ldp x11, x12, [x0, #CTX_TTBR0_EL2] |
| 222 | msr ttbr0_el2, x11 |
| 223 | msr vbar_el2, x12 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 224 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 225 | ldp x13, x14, [x0, #CTX_VMPIDR_EL2] |
| 226 | msr vmpidr_el2, x13 |
| 227 | msr vpidr_el2, x14 |
Manish V Badarkhe | d73c1ba | 2020-07-28 07:12:56 +0100 | [diff] [blame] | 228 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 229 | ldp x15, x16, [x0, #CTX_VTCR_EL2] |
| 230 | msr vtcr_el2, x15 |
| 231 | msr vttbr_el2, x16 |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 232 | ret |
| 233 | endfunc el2_sysregs_context_restore_common |
| 234 | |
| 235 | #if ENABLE_SPE_FOR_LOWER_ELS |
| 236 | func el2_sysregs_context_save_spe |
| 237 | mrs x13, PMSCR_EL2 |
| 238 | str x13, [x0, #CTX_PMSCR_EL2] |
| 239 | ret |
| 240 | endfunc el2_sysregs_context_save_spe |
| 241 | |
| 242 | func el2_sysregs_context_restore_spe |
| 243 | ldr x13, [x0, #CTX_PMSCR_EL2] |
| 244 | msr PMSCR_EL2, x13 |
| 245 | ret |
| 246 | endfunc el2_sysregs_context_restore_spe |
| 247 | #endif /* ENABLE_SPE_FOR_LOWER_ELS */ |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 248 | |
Max Shvetsov | c9e2c92 | 2020-02-17 16:15:47 +0000 | [diff] [blame] | 249 | #if CTX_INCLUDE_MTE_REGS |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 250 | func el2_sysregs_context_save_mte |
| 251 | mrs x9, TFSR_EL2 |
| 252 | str x9, [x0, #CTX_TFSR_EL2] |
| 253 | ret |
| 254 | endfunc el2_sysregs_context_save_mte |
| 255 | |
| 256 | func el2_sysregs_context_restore_mte |
Manish V Badarkhe | d73c1ba | 2020-07-28 07:12:56 +0100 | [diff] [blame] | 257 | ldr x9, [x0, #CTX_TFSR_EL2] |
| 258 | msr TFSR_EL2, x9 |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 259 | ret |
| 260 | endfunc el2_sysregs_context_restore_mte |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 261 | #endif /* CTX_INCLUDE_MTE_REGS */ |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 262 | |
Max Shvetsov | c9e2c92 | 2020-02-17 16:15:47 +0000 | [diff] [blame] | 263 | #if ENABLE_MPAM_FOR_LOWER_ELS |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 264 | func el2_sysregs_context_save_mpam |
| 265 | mrs x10, MPAM2_EL2 |
| 266 | str x10, [x0, #CTX_MPAM2_EL2] |
| 267 | |
| 268 | mrs x11, MPAMHCR_EL2 |
| 269 | mrs x12, MPAMVPM0_EL2 |
| 270 | stp x11, x12, [x0, #CTX_MPAMHCR_EL2] |
| 271 | |
| 272 | mrs x13, MPAMVPM1_EL2 |
| 273 | mrs x14, MPAMVPM2_EL2 |
| 274 | stp x13, x14, [x0, #CTX_MPAMVPM1_EL2] |
| 275 | |
| 276 | mrs x15, MPAMVPM3_EL2 |
| 277 | mrs x16, MPAMVPM4_EL2 |
| 278 | stp x15, x16, [x0, #CTX_MPAMVPM3_EL2] |
| 279 | |
| 280 | mrs x9, MPAMVPM5_EL2 |
| 281 | mrs x10, MPAMVPM6_EL2 |
| 282 | stp x9, x10, [x0, #CTX_MPAMVPM5_EL2] |
| 283 | |
| 284 | mrs x11, MPAMVPM7_EL2 |
| 285 | mrs x12, MPAMVPMV_EL2 |
| 286 | stp x11, x12, [x0, #CTX_MPAMVPM7_EL2] |
| 287 | ret |
| 288 | endfunc func el2_sysregs_context_save_mpam |
| 289 | |
| 290 | func el2_sysregs_context_restore_mpam |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 291 | ldr x10, [x0, #CTX_MPAM2_EL2] |
Manish V Badarkhe | d73c1ba | 2020-07-28 07:12:56 +0100 | [diff] [blame] | 292 | msr MPAM2_EL2, x10 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 293 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 294 | ldp x11, x12, [x0, #CTX_MPAMHCR_EL2] |
| 295 | msr MPAMHCR_EL2, x11 |
Manish V Badarkhe | d73c1ba | 2020-07-28 07:12:56 +0100 | [diff] [blame] | 296 | msr MPAMVPM0_EL2, x12 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 297 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 298 | ldp x13, x14, [x0, #CTX_MPAMVPM1_EL2] |
| 299 | msr MPAMVPM1_EL2, x13 |
Manish V Badarkhe | d73c1ba | 2020-07-28 07:12:56 +0100 | [diff] [blame] | 300 | msr MPAMVPM2_EL2, x14 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 301 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 302 | ldp x15, x16, [x0, #CTX_MPAMVPM3_EL2] |
| 303 | msr MPAMVPM3_EL2, x15 |
Manish V Badarkhe | d73c1ba | 2020-07-28 07:12:56 +0100 | [diff] [blame] | 304 | msr MPAMVPM4_EL2, x16 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 305 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 306 | ldp x9, x10, [x0, #CTX_MPAMVPM5_EL2] |
| 307 | msr MPAMVPM5_EL2, x9 |
| 308 | msr MPAMVPM6_EL2, x10 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 309 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 310 | ldp x11, x12, [x0, #CTX_MPAMVPM7_EL2] |
| 311 | msr MPAMVPM7_EL2, x11 |
| 312 | msr MPAMVPMV_EL2, x12 |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 313 | ret |
| 314 | endfunc el2_sysregs_context_restore_mpam |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 315 | #endif /* ENABLE_MPAM_FOR_LOWER_ELS */ |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 316 | |
Jayanth Dodderi Chidanand | 13ae0f4 | 2021-11-25 14:59:30 +0000 | [diff] [blame] | 317 | #if ENABLE_FEAT_FGT |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 318 | func el2_sysregs_context_save_fgt |
| 319 | mrs x13, HDFGRTR_EL2 |
Jayanth Dodderi Chidanand | 13ae0f4 | 2021-11-25 14:59:30 +0000 | [diff] [blame] | 320 | #if ENABLE_FEAT_AMUv1 |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 321 | mrs x14, HAFGRTR_EL2 |
| 322 | stp x13, x14, [x0, #CTX_HDFGRTR_EL2] |
| 323 | #else |
| 324 | str x13, [x0, #CTX_HDFGRTR_EL2] |
| 325 | #endif /* ENABLE_FEAT_AMUv1 */ |
| 326 | mrs x15, HDFGWTR_EL2 |
| 327 | mrs x16, HFGITR_EL2 |
| 328 | stp x15, x16, [x0, #CTX_HDFGWTR_EL2] |
| 329 | |
| 330 | mrs x9, HFGRTR_EL2 |
| 331 | mrs x10, HFGWTR_EL2 |
| 332 | stp x9, x10, [x0, #CTX_HFGRTR_EL2] |
| 333 | ret |
| 334 | endfunc el2_sysregs_context_save_fgt |
| 335 | |
| 336 | func el2_sysregs_context_restore_fgt |
| 337 | #if ENABLE_FEAT_AMUv1 |
Jayanth Dodderi Chidanand | 13ae0f4 | 2021-11-25 14:59:30 +0000 | [diff] [blame] | 338 | ldp x13, x14, [x0, #CTX_HDFGRTR_EL2] |
| 339 | msr HAFGRTR_EL2, x14 |
| 340 | #else |
| 341 | ldr x13, [x0, #CTX_HDFGRTR_EL2] |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 342 | #endif /* ENABLE_FEAT_AMUv1 */ |
Jayanth Dodderi Chidanand | 13ae0f4 | 2021-11-25 14:59:30 +0000 | [diff] [blame] | 343 | msr HDFGRTR_EL2, x13 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 344 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 345 | ldp x15, x16, [x0, #CTX_HDFGWTR_EL2] |
| 346 | msr HDFGWTR_EL2, x15 |
| 347 | msr HFGITR_EL2, x16 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 348 | |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 349 | ldp x9, x10, [x0, #CTX_HFGRTR_EL2] |
| 350 | msr HFGRTR_EL2, x9 |
| 351 | msr HFGWTR_EL2, x10 |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 352 | ret |
| 353 | endfunc el2_sysregs_context_restore_fgt |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 354 | #endif /* ENABLE_FEAT_FGT */ |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 355 | |
Jayanth Dodderi Chidanand | 13ae0f4 | 2021-11-25 14:59:30 +0000 | [diff] [blame] | 356 | #if ENABLE_FEAT_ECV |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 357 | func el2_sysregs_context_save_ecv |
| 358 | mrs x11, CNTPOFF_EL2 |
| 359 | str x11, [x0, #CTX_CNTPOFF_EL2] |
| 360 | ret |
| 361 | endfunc el2_sysregs_context_save_ecv |
| 362 | |
| 363 | func el2_sysregs_context_restore_ecv |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 364 | ldr x11, [x0, #CTX_CNTPOFF_EL2] |
| 365 | msr CNTPOFF_EL2, x11 |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 366 | ret |
| 367 | endfunc el2_sysregs_context_restore_ecv |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 368 | #endif /* ENABLE_FEAT_ECV */ |
| 369 | |
| 370 | #if ENABLE_FEAT_VHE |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 371 | func el2_sysregs_context_save_vhe |
| 372 | /* |
| 373 | * CONTEXTIDR_EL2 register is saved only when FEAT_VHE or |
| 374 | * FEAT_Debugv8p2 (currently not in TF-A) is supported. |
| 375 | */ |
| 376 | mrs x9, contextidr_el2 |
| 377 | mrs x10, ttbr1_el2 |
| 378 | stp x9, x10, [x0, #CTX_CONTEXTIDR_EL2] |
| 379 | ret |
| 380 | endfunc el2_sysregs_context_save_vhe |
| 381 | |
| 382 | func el2_sysregs_context_restore_vhe |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 383 | /* |
| 384 | * CONTEXTIDR_EL2 register is restored only when FEAT_VHE or |
| 385 | * FEAT_Debugv8p2 (currently not in TF-A) is supported. |
| 386 | */ |
| 387 | ldp x9, x10, [x0, #CTX_CONTEXTIDR_EL2] |
| 388 | msr contextidr_el2, x9 |
| 389 | msr ttbr1_el2, x10 |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 390 | ret |
| 391 | endfunc el2_sysregs_context_restore_vhe |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 392 | #endif /* ENABLE_FEAT_VHE */ |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 393 | |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 394 | #if RAS_EXTENSION |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 395 | func el2_sysregs_context_save_ras |
| 396 | /* |
| 397 | * VDISR_EL2 and VSESR_EL2 registers are saved only when |
| 398 | * FEAT_RAS is supported. |
| 399 | */ |
| 400 | mrs x11, vdisr_el2 |
| 401 | mrs x12, vsesr_el2 |
| 402 | stp x11, x12, [x0, #CTX_VDISR_EL2] |
| 403 | ret |
| 404 | endfunc el2_sysregs_context_save_ras |
| 405 | |
| 406 | func el2_sysregs_context_restore_ras |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 407 | /* |
| 408 | * VDISR_EL2 and VSESR_EL2 registers are restored only when FEAT_RAS |
| 409 | * is supported. |
| 410 | */ |
| 411 | ldp x11, x12, [x0, #CTX_VDISR_EL2] |
| 412 | msr vdisr_el2, x11 |
| 413 | msr vsesr_el2, x12 |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 414 | ret |
| 415 | endfunc el2_sysregs_context_restore_ras |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 416 | #endif /* RAS_EXTENSION */ |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 417 | |
Arunachalam Ganapathy | dd3ec7e | 2020-05-28 11:57:09 +0100 | [diff] [blame] | 418 | #if CTX_INCLUDE_NEVE_REGS |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 419 | func el2_sysregs_context_save_nv2 |
| 420 | /* |
| 421 | * VNCR_EL2 register is saved only when FEAT_NV2 is supported. |
| 422 | */ |
| 423 | mrs x16, vncr_el2 |
| 424 | str x16, [x0, #CTX_VNCR_EL2] |
| 425 | ret |
| 426 | endfunc el2_sysregs_context_save_nv2 |
| 427 | |
| 428 | func el2_sysregs_context_restore_nv2 |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 429 | /* |
| 430 | * VNCR_EL2 register is restored only when FEAT_NV2 is supported. |
| 431 | */ |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 432 | ldr x16, [x0, #CTX_VNCR_EL2] |
| 433 | msr vncr_el2, x16 |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 434 | ret |
| 435 | endfunc el2_sysregs_context_restore_nv2 |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 436 | #endif /* CTX_INCLUDE_NEVE_REGS */ |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 437 | |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 438 | #if ENABLE_TRF_FOR_NS |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 439 | func el2_sysregs_context_save_trf |
| 440 | /* |
| 441 | * TRFCR_EL2 register is saved only when FEAT_TRF is supported. |
| 442 | */ |
| 443 | mrs x12, TRFCR_EL2 |
| 444 | str x12, [x0, #CTX_TRFCR_EL2] |
| 445 | ret |
| 446 | endfunc el2_sysregs_context_save_trf |
| 447 | |
| 448 | func el2_sysregs_context_restore_trf |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 449 | /* |
| 450 | * TRFCR_EL2 register is restored only when FEAT_TRF is supported. |
| 451 | */ |
| 452 | ldr x12, [x0, #CTX_TRFCR_EL2] |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 453 | msr TRFCR_EL2, x12 |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 454 | ret |
| 455 | endfunc el2_sysregs_context_restore_trf |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 456 | #endif /* ENABLE_TRF_FOR_NS */ |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 457 | |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 458 | #if ENABLE_FEAT_CSV2_2 |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 459 | func el2_sysregs_context_save_csv2 |
| 460 | /* |
| 461 | * SCXTNUM_EL2 register is saved only when FEAT_CSV2_2 is supported. |
| 462 | */ |
| 463 | mrs x13, scxtnum_el2 |
| 464 | str x13, [x0, #CTX_SCXTNUM_EL2] |
| 465 | ret |
| 466 | endfunc el2_sysregs_context_save_csv2 |
| 467 | |
| 468 | func el2_sysregs_context_restore_csv2 |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 469 | /* |
| 470 | * SCXTNUM_EL2 register is restored only when FEAT_CSV2_2 is supported. |
| 471 | */ |
Max Shvetsov | cf784f7 | 2021-03-31 19:00:38 +0100 | [diff] [blame] | 472 | ldr x13, [x0, #CTX_SCXTNUM_EL2] |
| 473 | msr scxtnum_el2, x13 |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 474 | ret |
| 475 | endfunc el2_sysregs_context_restore_csv2 |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 476 | #endif /* ENABLE_FEAT_CSV2_2 */ |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 477 | |
johpow01 | f91e59f | 2021-08-04 19:38:18 -0500 | [diff] [blame] | 478 | #if ENABLE_FEAT_HCX |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 479 | func el2_sysregs_context_save_hcx |
| 480 | mrs x14, hcrx_el2 |
| 481 | str x14, [x0, #CTX_HCRX_EL2] |
| 482 | ret |
| 483 | endfunc el2_sysregs_context_save_hcx |
| 484 | |
| 485 | func el2_sysregs_context_restore_hcx |
johpow01 | f91e59f | 2021-08-04 19:38:18 -0500 | [diff] [blame] | 486 | ldr x14, [x0, #CTX_HCRX_EL2] |
| 487 | msr hcrx_el2, x14 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 488 | ret |
Zelalem Aweke | 5362beb | 2022-04-04 17:42:48 -0500 | [diff] [blame] | 489 | endfunc el2_sysregs_context_restore_hcx |
| 490 | #endif /* ENABLE_FEAT_HCX */ |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 491 | #endif /* CTX_INCLUDE_EL2_REGS */ |
| 492 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 493 | /* ------------------------------------------------------------------ |
| 494 | * The following function strictly follows the AArch64 PCS to use |
| 495 | * x9-x17 (temporary caller-saved registers) to save EL1 system |
| 496 | * register context. It assumes that 'x0' is pointing to a |
| 497 | * 'el1_sys_regs' structure where the register context will be saved. |
| 498 | * ------------------------------------------------------------------ |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 499 | */ |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 500 | func el1_sysregs_context_save |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 501 | |
| 502 | mrs x9, spsr_el1 |
| 503 | mrs x10, elr_el1 |
| 504 | stp x9, x10, [x0, #CTX_SPSR_EL1] |
| 505 | |
Manish V Badarkhe | e07e808 | 2020-07-23 12:43:25 +0100 | [diff] [blame] | 506 | #if !ERRATA_SPECULATIVE_AT |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 507 | mrs x15, sctlr_el1 |
Manish V Badarkhe | 2b0ee97 | 2020-07-28 07:22:30 +0100 | [diff] [blame] | 508 | mrs x16, tcr_el1 |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 509 | stp x15, x16, [x0, #CTX_SCTLR_EL1] |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 510 | #endif /* ERRATA_SPECULATIVE_AT */ |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 511 | |
| 512 | mrs x17, cpacr_el1 |
| 513 | mrs x9, csselr_el1 |
| 514 | stp x17, x9, [x0, #CTX_CPACR_EL1] |
| 515 | |
| 516 | mrs x10, sp_el1 |
| 517 | mrs x11, esr_el1 |
| 518 | stp x10, x11, [x0, #CTX_SP_EL1] |
| 519 | |
| 520 | mrs x12, ttbr0_el1 |
| 521 | mrs x13, ttbr1_el1 |
| 522 | stp x12, x13, [x0, #CTX_TTBR0_EL1] |
| 523 | |
| 524 | mrs x14, mair_el1 |
| 525 | mrs x15, amair_el1 |
| 526 | stp x14, x15, [x0, #CTX_MAIR_EL1] |
| 527 | |
Manish V Badarkhe | 2b0ee97 | 2020-07-28 07:22:30 +0100 | [diff] [blame] | 528 | mrs x16, actlr_el1 |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 529 | mrs x17, tpidr_el1 |
Manish V Badarkhe | 2b0ee97 | 2020-07-28 07:22:30 +0100 | [diff] [blame] | 530 | stp x16, x17, [x0, #CTX_ACTLR_EL1] |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 531 | |
| 532 | mrs x9, tpidr_el0 |
| 533 | mrs x10, tpidrro_el0 |
| 534 | stp x9, x10, [x0, #CTX_TPIDR_EL0] |
| 535 | |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 536 | mrs x13, par_el1 |
| 537 | mrs x14, far_el1 |
| 538 | stp x13, x14, [x0, #CTX_PAR_EL1] |
| 539 | |
| 540 | mrs x15, afsr0_el1 |
| 541 | mrs x16, afsr1_el1 |
| 542 | stp x15, x16, [x0, #CTX_AFSR0_EL1] |
| 543 | |
| 544 | mrs x17, contextidr_el1 |
| 545 | mrs x9, vbar_el1 |
| 546 | stp x17, x9, [x0, #CTX_CONTEXTIDR_EL1] |
| 547 | |
Soby Mathew | d75d2ba | 2016-05-17 14:01:32 +0100 | [diff] [blame] | 548 | /* Save AArch32 system registers if the build has instructed so */ |
| 549 | #if CTX_INCLUDE_AARCH32_REGS |
| 550 | mrs x11, spsr_abt |
| 551 | mrs x12, spsr_und |
| 552 | stp x11, x12, [x0, #CTX_SPSR_ABT] |
| 553 | |
| 554 | mrs x13, spsr_irq |
| 555 | mrs x14, spsr_fiq |
| 556 | stp x13, x14, [x0, #CTX_SPSR_IRQ] |
| 557 | |
| 558 | mrs x15, dacr32_el2 |
| 559 | mrs x16, ifsr32_el2 |
| 560 | stp x15, x16, [x0, #CTX_DACR32_EL2] |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 561 | #endif /* CTX_INCLUDE_AARCH32_REGS */ |
Soby Mathew | d75d2ba | 2016-05-17 14:01:32 +0100 | [diff] [blame] | 562 | |
Jeenu Viswambharan | d1b6015 | 2014-05-12 15:28:47 +0100 | [diff] [blame] | 563 | /* Save NS timer registers if the build has instructed so */ |
| 564 | #if NS_TIMER_SWITCH |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 565 | mrs x10, cntp_ctl_el0 |
| 566 | mrs x11, cntp_cval_el0 |
| 567 | stp x10, x11, [x0, #CTX_CNTP_CTL_EL0] |
| 568 | |
| 569 | mrs x12, cntv_ctl_el0 |
| 570 | mrs x13, cntv_cval_el0 |
| 571 | stp x12, x13, [x0, #CTX_CNTV_CTL_EL0] |
| 572 | |
| 573 | mrs x14, cntkctl_el1 |
Jeenu Viswambharan | d1b6015 | 2014-05-12 15:28:47 +0100 | [diff] [blame] | 574 | str x14, [x0, #CTX_CNTKCTL_EL1] |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 575 | #endif /* NS_TIMER_SWITCH */ |
Jeenu Viswambharan | d1b6015 | 2014-05-12 15:28:47 +0100 | [diff] [blame] | 576 | |
Justin Chadwell | 1c7c13a | 2019-07-18 14:25:33 +0100 | [diff] [blame] | 577 | /* Save MTE system registers if the build has instructed so */ |
| 578 | #if CTX_INCLUDE_MTE_REGS |
| 579 | mrs x15, TFSRE0_EL1 |
| 580 | mrs x16, TFSR_EL1 |
| 581 | stp x15, x16, [x0, #CTX_TFSRE0_EL1] |
| 582 | |
| 583 | mrs x9, RGSR_EL1 |
| 584 | mrs x10, GCR_EL1 |
| 585 | stp x9, x10, [x0, #CTX_RGSR_EL1] |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 586 | #endif /* CTX_INCLUDE_MTE_REGS */ |
Justin Chadwell | 1c7c13a | 2019-07-18 14:25:33 +0100 | [diff] [blame] | 587 | |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 588 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 589 | endfunc el1_sysregs_context_save |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 590 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 591 | /* ------------------------------------------------------------------ |
| 592 | * The following function strictly follows the AArch64 PCS to use |
| 593 | * x9-x17 (temporary caller-saved registers) to restore EL1 system |
| 594 | * register context. It assumes that 'x0' is pointing to a |
| 595 | * 'el1_sys_regs' structure from where the register context will be |
| 596 | * restored |
| 597 | * ------------------------------------------------------------------ |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 598 | */ |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 599 | func el1_sysregs_context_restore |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 600 | |
| 601 | ldp x9, x10, [x0, #CTX_SPSR_EL1] |
| 602 | msr spsr_el1, x9 |
| 603 | msr elr_el1, x10 |
| 604 | |
Manish V Badarkhe | e07e808 | 2020-07-23 12:43:25 +0100 | [diff] [blame] | 605 | #if !ERRATA_SPECULATIVE_AT |
Manish V Badarkhe | d73c1ba | 2020-07-28 07:12:56 +0100 | [diff] [blame] | 606 | ldp x15, x16, [x0, #CTX_SCTLR_EL1] |
| 607 | msr sctlr_el1, x15 |
Manish V Badarkhe | 2b0ee97 | 2020-07-28 07:22:30 +0100 | [diff] [blame] | 608 | msr tcr_el1, x16 |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 609 | #endif /* ERRATA_SPECULATIVE_AT */ |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 610 | |
| 611 | ldp x17, x9, [x0, #CTX_CPACR_EL1] |
| 612 | msr cpacr_el1, x17 |
| 613 | msr csselr_el1, x9 |
| 614 | |
| 615 | ldp x10, x11, [x0, #CTX_SP_EL1] |
| 616 | msr sp_el1, x10 |
| 617 | msr esr_el1, x11 |
| 618 | |
| 619 | ldp x12, x13, [x0, #CTX_TTBR0_EL1] |
| 620 | msr ttbr0_el1, x12 |
| 621 | msr ttbr1_el1, x13 |
| 622 | |
| 623 | ldp x14, x15, [x0, #CTX_MAIR_EL1] |
| 624 | msr mair_el1, x14 |
| 625 | msr amair_el1, x15 |
| 626 | |
Manish V Badarkhe | 2b0ee97 | 2020-07-28 07:22:30 +0100 | [diff] [blame] | 627 | ldp x16, x17, [x0, #CTX_ACTLR_EL1] |
| 628 | msr actlr_el1, x16 |
Manish V Badarkhe | d73c1ba | 2020-07-28 07:12:56 +0100 | [diff] [blame] | 629 | msr tpidr_el1, x17 |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 630 | |
| 631 | ldp x9, x10, [x0, #CTX_TPIDR_EL0] |
| 632 | msr tpidr_el0, x9 |
| 633 | msr tpidrro_el0, x10 |
| 634 | |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 635 | ldp x13, x14, [x0, #CTX_PAR_EL1] |
| 636 | msr par_el1, x13 |
| 637 | msr far_el1, x14 |
| 638 | |
| 639 | ldp x15, x16, [x0, #CTX_AFSR0_EL1] |
| 640 | msr afsr0_el1, x15 |
| 641 | msr afsr1_el1, x16 |
| 642 | |
| 643 | ldp x17, x9, [x0, #CTX_CONTEXTIDR_EL1] |
| 644 | msr contextidr_el1, x17 |
| 645 | msr vbar_el1, x9 |
| 646 | |
Soby Mathew | d75d2ba | 2016-05-17 14:01:32 +0100 | [diff] [blame] | 647 | /* Restore AArch32 system registers if the build has instructed so */ |
| 648 | #if CTX_INCLUDE_AARCH32_REGS |
| 649 | ldp x11, x12, [x0, #CTX_SPSR_ABT] |
| 650 | msr spsr_abt, x11 |
| 651 | msr spsr_und, x12 |
| 652 | |
| 653 | ldp x13, x14, [x0, #CTX_SPSR_IRQ] |
| 654 | msr spsr_irq, x13 |
| 655 | msr spsr_fiq, x14 |
| 656 | |
| 657 | ldp x15, x16, [x0, #CTX_DACR32_EL2] |
| 658 | msr dacr32_el2, x15 |
| 659 | msr ifsr32_el2, x16 |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 660 | #endif /* CTX_INCLUDE_AARCH32_REGS */ |
| 661 | |
Jeenu Viswambharan | d1b6015 | 2014-05-12 15:28:47 +0100 | [diff] [blame] | 662 | /* Restore NS timer registers if the build has instructed so */ |
| 663 | #if NS_TIMER_SWITCH |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 664 | ldp x10, x11, [x0, #CTX_CNTP_CTL_EL0] |
| 665 | msr cntp_ctl_el0, x10 |
| 666 | msr cntp_cval_el0, x11 |
| 667 | |
| 668 | ldp x12, x13, [x0, #CTX_CNTV_CTL_EL0] |
| 669 | msr cntv_ctl_el0, x12 |
| 670 | msr cntv_cval_el0, x13 |
| 671 | |
Jeenu Viswambharan | d1b6015 | 2014-05-12 15:28:47 +0100 | [diff] [blame] | 672 | ldr x14, [x0, #CTX_CNTKCTL_EL1] |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 673 | msr cntkctl_el1, x14 |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 674 | #endif /* NS_TIMER_SWITCH */ |
| 675 | |
Justin Chadwell | 1c7c13a | 2019-07-18 14:25:33 +0100 | [diff] [blame] | 676 | /* Restore MTE system registers if the build has instructed so */ |
| 677 | #if CTX_INCLUDE_MTE_REGS |
| 678 | ldp x11, x12, [x0, #CTX_TFSRE0_EL1] |
| 679 | msr TFSRE0_EL1, x11 |
| 680 | msr TFSR_EL1, x12 |
| 681 | |
| 682 | ldp x13, x14, [x0, #CTX_RGSR_EL1] |
| 683 | msr RGSR_EL1, x13 |
| 684 | msr GCR_EL1, x14 |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 685 | #endif /* CTX_INCLUDE_MTE_REGS */ |
Jeenu Viswambharan | d1b6015 | 2014-05-12 15:28:47 +0100 | [diff] [blame] | 686 | |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 687 | /* No explict ISB required here as ERET covers it */ |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 688 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 689 | endfunc el1_sysregs_context_restore |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 690 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 691 | /* ------------------------------------------------------------------ |
| 692 | * The following function follows the aapcs_64 strictly to use |
| 693 | * x9-x17 (temporary caller-saved registers according to AArch64 PCS) |
| 694 | * to save floating point register context. It assumes that 'x0' is |
| 695 | * pointing to a 'fp_regs' structure where the register context will |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 696 | * be saved. |
| 697 | * |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 698 | * Access to VFP registers will trap if CPTR_EL3.TFP is set. |
| 699 | * However currently we don't use VFP registers nor set traps in |
| 700 | * Trusted Firmware, and assume it's cleared. |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 701 | * |
| 702 | * TODO: Revisit when VFP is used in secure world |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 703 | * ------------------------------------------------------------------ |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 704 | */ |
Juan Castillo | 258e94f | 2014-06-25 17:26:36 +0100 | [diff] [blame] | 705 | #if CTX_INCLUDE_FPREGS |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 706 | func fpregs_context_save |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 707 | stp q0, q1, [x0, #CTX_FP_Q0] |
| 708 | stp q2, q3, [x0, #CTX_FP_Q2] |
| 709 | stp q4, q5, [x0, #CTX_FP_Q4] |
| 710 | stp q6, q7, [x0, #CTX_FP_Q6] |
| 711 | stp q8, q9, [x0, #CTX_FP_Q8] |
| 712 | stp q10, q11, [x0, #CTX_FP_Q10] |
| 713 | stp q12, q13, [x0, #CTX_FP_Q12] |
| 714 | stp q14, q15, [x0, #CTX_FP_Q14] |
| 715 | stp q16, q17, [x0, #CTX_FP_Q16] |
| 716 | stp q18, q19, [x0, #CTX_FP_Q18] |
| 717 | stp q20, q21, [x0, #CTX_FP_Q20] |
| 718 | stp q22, q23, [x0, #CTX_FP_Q22] |
| 719 | stp q24, q25, [x0, #CTX_FP_Q24] |
| 720 | stp q26, q27, [x0, #CTX_FP_Q26] |
| 721 | stp q28, q29, [x0, #CTX_FP_Q28] |
| 722 | stp q30, q31, [x0, #CTX_FP_Q30] |
| 723 | |
| 724 | mrs x9, fpsr |
| 725 | str x9, [x0, #CTX_FP_FPSR] |
| 726 | |
| 727 | mrs x10, fpcr |
| 728 | str x10, [x0, #CTX_FP_FPCR] |
| 729 | |
David Cunado | d1a1fd4 | 2017-10-20 11:30:57 +0100 | [diff] [blame] | 730 | #if CTX_INCLUDE_AARCH32_REGS |
| 731 | mrs x11, fpexc32_el2 |
| 732 | str x11, [x0, #CTX_FP_FPEXC32_EL2] |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 733 | #endif /* CTX_INCLUDE_AARCH32_REGS */ |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 734 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 735 | endfunc fpregs_context_save |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 736 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 737 | /* ------------------------------------------------------------------ |
| 738 | * The following function follows the aapcs_64 strictly to use x9-x17 |
| 739 | * (temporary caller-saved registers according to AArch64 PCS) to |
| 740 | * restore floating point register context. It assumes that 'x0' is |
| 741 | * pointing to a 'fp_regs' structure from where the register context |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 742 | * will be restored. |
| 743 | * |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 744 | * Access to VFP registers will trap if CPTR_EL3.TFP is set. |
| 745 | * However currently we don't use VFP registers nor set traps in |
| 746 | * Trusted Firmware, and assume it's cleared. |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 747 | * |
| 748 | * TODO: Revisit when VFP is used in secure world |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 749 | * ------------------------------------------------------------------ |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 750 | */ |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 751 | func fpregs_context_restore |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 752 | ldp q0, q1, [x0, #CTX_FP_Q0] |
| 753 | ldp q2, q3, [x0, #CTX_FP_Q2] |
| 754 | ldp q4, q5, [x0, #CTX_FP_Q4] |
| 755 | ldp q6, q7, [x0, #CTX_FP_Q6] |
| 756 | ldp q8, q9, [x0, #CTX_FP_Q8] |
| 757 | ldp q10, q11, [x0, #CTX_FP_Q10] |
| 758 | ldp q12, q13, [x0, #CTX_FP_Q12] |
| 759 | ldp q14, q15, [x0, #CTX_FP_Q14] |
| 760 | ldp q16, q17, [x0, #CTX_FP_Q16] |
| 761 | ldp q18, q19, [x0, #CTX_FP_Q18] |
| 762 | ldp q20, q21, [x0, #CTX_FP_Q20] |
| 763 | ldp q22, q23, [x0, #CTX_FP_Q22] |
| 764 | ldp q24, q25, [x0, #CTX_FP_Q24] |
| 765 | ldp q26, q27, [x0, #CTX_FP_Q26] |
| 766 | ldp q28, q29, [x0, #CTX_FP_Q28] |
| 767 | ldp q30, q31, [x0, #CTX_FP_Q30] |
| 768 | |
| 769 | ldr x9, [x0, #CTX_FP_FPSR] |
| 770 | msr fpsr, x9 |
| 771 | |
Soby Mathew | e77e116 | 2015-12-03 09:42:50 +0000 | [diff] [blame] | 772 | ldr x10, [x0, #CTX_FP_FPCR] |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 773 | msr fpcr, x10 |
| 774 | |
David Cunado | d1a1fd4 | 2017-10-20 11:30:57 +0100 | [diff] [blame] | 775 | #if CTX_INCLUDE_AARCH32_REGS |
| 776 | ldr x11, [x0, #CTX_FP_FPEXC32_EL2] |
| 777 | msr fpexc32_el2, x11 |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 778 | #endif /* CTX_INCLUDE_AARCH32_REGS */ |
| 779 | |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 780 | /* |
| 781 | * No explict ISB required here as ERET to |
Sandrine Bailleux | f4119ec | 2015-12-17 13:58:58 +0000 | [diff] [blame] | 782 | * switch to secure EL1 or non-secure world |
Achin Gupta | 9ac63c5 | 2014-01-16 12:08:03 +0000 | [diff] [blame] | 783 | * covers it |
| 784 | */ |
| 785 | |
| 786 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 787 | endfunc fpregs_context_restore |
Juan Castillo | 258e94f | 2014-06-25 17:26:36 +0100 | [diff] [blame] | 788 | #endif /* CTX_INCLUDE_FPREGS */ |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 789 | |
Daniel Boulby | 928747f | 2021-05-25 18:09:34 +0100 | [diff] [blame] | 790 | /* |
Manish Pandey | 62d532a | 2022-11-17 15:47:05 +0000 | [diff] [blame] | 791 | * Set SCR_EL3.EA bit to enable SErrors at EL3 |
| 792 | */ |
| 793 | .macro enable_serror_at_el3 |
| 794 | mrs x8, scr_el3 |
| 795 | orr x8, x8, #SCR_EA_BIT |
| 796 | msr scr_el3, x8 |
| 797 | .endm |
| 798 | |
| 799 | /* |
Daniel Boulby | 928747f | 2021-05-25 18:09:34 +0100 | [diff] [blame] | 800 | * Set the PSTATE bits not set when the exception was taken as |
| 801 | * described in the AArch64.TakeException() pseudocode function |
| 802 | * in ARM DDI 0487F.c page J1-7635 to a default value. |
| 803 | */ |
| 804 | .macro set_unset_pstate_bits |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 805 | /* |
| 806 | * If Data Independent Timing (DIT) functionality is implemented, |
| 807 | * always enable DIT in EL3 |
| 808 | */ |
Daniel Boulby | 928747f | 2021-05-25 18:09:34 +0100 | [diff] [blame] | 809 | #if ENABLE_FEAT_DIT |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 810 | mov x8, #DIT_BIT |
| 811 | msr DIT, x8 |
Daniel Boulby | 928747f | 2021-05-25 18:09:34 +0100 | [diff] [blame] | 812 | #endif /* ENABLE_FEAT_DIT */ |
| 813 | .endm /* set_unset_pstate_bits */ |
| 814 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 815 | /* ------------------------------------------------------------------ |
Daniel Boulby | 95fb1aa | 2022-01-19 11:20:05 +0000 | [diff] [blame] | 816 | * The following macro is used to save and restore all the general |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 817 | * purpose and ARMv8.3-PAuth (if enabled) registers. |
Jayanth Dodderi Chidanand | 4ec78ad | 2022-09-19 23:32:08 +0100 | [diff] [blame] | 818 | * It also checks if the Secure Cycle Counter (PMCCNTR_EL0) |
| 819 | * is disabled in EL3/Secure (ARMv8.5-PMU), wherein PMCCNTR_EL0 |
| 820 | * needs not to be saved/restored during world switch. |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 821 | * |
| 822 | * Ideally we would only save and restore the callee saved registers |
| 823 | * when a world switch occurs but that type of implementation is more |
| 824 | * complex. So currently we will always save and restore these |
| 825 | * registers on entry and exit of EL3. |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 826 | * clobbers: x18 |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 827 | * ------------------------------------------------------------------ |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 828 | */ |
Daniel Boulby | 95fb1aa | 2022-01-19 11:20:05 +0000 | [diff] [blame] | 829 | .macro save_gp_pmcr_pauth_regs |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 830 | stp x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0] |
| 831 | stp x2, x3, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2] |
| 832 | stp x4, x5, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X4] |
| 833 | stp x6, x7, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X6] |
| 834 | stp x8, x9, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X8] |
| 835 | stp x10, x11, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X10] |
| 836 | stp x12, x13, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X12] |
| 837 | stp x14, x15, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X14] |
| 838 | stp x16, x17, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X16] |
| 839 | stp x18, x19, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X18] |
| 840 | stp x20, x21, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X20] |
| 841 | stp x22, x23, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X22] |
| 842 | stp x24, x25, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X24] |
| 843 | stp x26, x27, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X26] |
| 844 | stp x28, x29, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X28] |
| 845 | mrs x18, sp_el0 |
| 846 | str x18, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_SP_EL0] |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 847 | |
| 848 | /* ---------------------------------------------------------- |
Jayanth Dodderi Chidanand | 4ec78ad | 2022-09-19 23:32:08 +0100 | [diff] [blame] | 849 | * Check if earlier initialization of MDCR_EL3.SCCD/MCCD to 1 |
| 850 | * has failed. |
| 851 | * |
| 852 | * MDCR_EL3: |
| 853 | * MCCD bit set, Prohibits the Cycle Counter PMCCNTR_EL0 from |
| 854 | * counting at EL3. |
| 855 | * SCCD bit set, Secure Cycle Counter Disable. Prohibits PMCCNTR_EL0 |
| 856 | * from counting in Secure state. |
| 857 | * If these bits are not set, meaning that FEAT_PMUv3p5/7 is |
| 858 | * not implemented and PMCR_EL0 should be saved in non-secure |
| 859 | * context. |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 860 | * ---------------------------------------------------------- |
| 861 | */ |
Alexei Fedorov | 307f34b | 2021-05-14 11:21:56 +0100 | [diff] [blame] | 862 | mov_imm x10, (MDCR_SCCD_BIT | MDCR_MCCD_BIT) |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 863 | mrs x9, mdcr_el3 |
Alexei Fedorov | 307f34b | 2021-05-14 11:21:56 +0100 | [diff] [blame] | 864 | tst x9, x10 |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 865 | bne 1f |
| 866 | |
Jayanth Dodderi Chidanand | 4ec78ad | 2022-09-19 23:32:08 +0100 | [diff] [blame] | 867 | /* ---------------------------------------------------------- |
| 868 | * If control reaches here, it ensures the Secure Cycle |
| 869 | * Counter (PMCCNTR_EL0) is not prohibited from counting at |
| 870 | * EL3 and in secure states. |
| 871 | * Henceforth, PMCR_EL0 to be saved before world switch. |
| 872 | * ---------------------------------------------------------- |
| 873 | */ |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 874 | mrs x9, pmcr_el0 |
| 875 | |
| 876 | /* Check caller's security state */ |
| 877 | mrs x10, scr_el3 |
| 878 | tst x10, #SCR_NS_BIT |
| 879 | beq 2f |
| 880 | |
| 881 | /* Save PMCR_EL0 if called from Non-secure state */ |
| 882 | str x9, [sp, #CTX_EL3STATE_OFFSET + CTX_PMCR_EL0] |
| 883 | |
| 884 | /* Disable cycle counter when event counting is prohibited */ |
| 885 | 2: orr x9, x9, #PMCR_EL0_DP_BIT |
| 886 | msr pmcr_el0, x9 |
| 887 | isb |
| 888 | 1: |
| 889 | #if CTX_INCLUDE_PAUTH_REGS |
| 890 | /* ---------------------------------------------------------- |
| 891 | * Save the ARMv8.3-PAuth keys as they are not banked |
| 892 | * by exception level |
| 893 | * ---------------------------------------------------------- |
| 894 | */ |
| 895 | add x19, sp, #CTX_PAUTH_REGS_OFFSET |
| 896 | |
| 897 | mrs x20, APIAKeyLo_EL1 /* x21:x20 = APIAKey */ |
| 898 | mrs x21, APIAKeyHi_EL1 |
| 899 | mrs x22, APIBKeyLo_EL1 /* x23:x22 = APIBKey */ |
| 900 | mrs x23, APIBKeyHi_EL1 |
| 901 | mrs x24, APDAKeyLo_EL1 /* x25:x24 = APDAKey */ |
| 902 | mrs x25, APDAKeyHi_EL1 |
| 903 | mrs x26, APDBKeyLo_EL1 /* x27:x26 = APDBKey */ |
| 904 | mrs x27, APDBKeyHi_EL1 |
| 905 | mrs x28, APGAKeyLo_EL1 /* x29:x28 = APGAKey */ |
| 906 | mrs x29, APGAKeyHi_EL1 |
| 907 | |
| 908 | stp x20, x21, [x19, #CTX_PACIAKEY_LO] |
| 909 | stp x22, x23, [x19, #CTX_PACIBKEY_LO] |
| 910 | stp x24, x25, [x19, #CTX_PACDAKEY_LO] |
| 911 | stp x26, x27, [x19, #CTX_PACDBKEY_LO] |
| 912 | stp x28, x29, [x19, #CTX_PACGAKEY_LO] |
| 913 | #endif /* CTX_INCLUDE_PAUTH_REGS */ |
Daniel Boulby | 95fb1aa | 2022-01-19 11:20:05 +0000 | [diff] [blame] | 914 | .endm /* save_gp_pmcr_pauth_regs */ |
| 915 | |
| 916 | /* ----------------------------------------------------------------- |
Daniel Boulby | 928747f | 2021-05-25 18:09:34 +0100 | [diff] [blame] | 917 | * This function saves the context and sets the PSTATE to a known |
| 918 | * state, preparing entry to el3. |
Daniel Boulby | 95fb1aa | 2022-01-19 11:20:05 +0000 | [diff] [blame] | 919 | * Save all the general purpose and ARMv8.3-PAuth (if enabled) |
| 920 | * registers. |
Daniel Boulby | 928747f | 2021-05-25 18:09:34 +0100 | [diff] [blame] | 921 | * Then set any of the PSTATE bits that are not set by hardware |
| 922 | * according to the Aarch64.TakeException pseudocode in the Arm |
| 923 | * Architecture Reference Manual to a default value for EL3. |
| 924 | * clobbers: x17 |
Daniel Boulby | 95fb1aa | 2022-01-19 11:20:05 +0000 | [diff] [blame] | 925 | * ----------------------------------------------------------------- |
| 926 | */ |
| 927 | func prepare_el3_entry |
| 928 | save_gp_pmcr_pauth_regs |
Manish Pandey | 62d532a | 2022-11-17 15:47:05 +0000 | [diff] [blame] | 929 | enable_serror_at_el3 |
Daniel Boulby | 928747f | 2021-05-25 18:09:34 +0100 | [diff] [blame] | 930 | /* |
| 931 | * Set the PSTATE bits not described in the Aarch64.TakeException |
| 932 | * pseudocode to their default values. |
| 933 | */ |
| 934 | set_unset_pstate_bits |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 935 | ret |
Daniel Boulby | 95fb1aa | 2022-01-19 11:20:05 +0000 | [diff] [blame] | 936 | endfunc prepare_el3_entry |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 937 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 938 | /* ------------------------------------------------------------------ |
| 939 | * This function restores ARMv8.3-PAuth (if enabled) and all general |
| 940 | * purpose registers except x30 from the CPU context. |
| 941 | * x30 register must be explicitly restored by the caller. |
| 942 | * ------------------------------------------------------------------ |
Jeenu Viswambharan | 23d05a8 | 2017-11-29 16:59:34 +0000 | [diff] [blame] | 943 | */ |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 944 | func restore_gp_pmcr_pauth_regs |
| 945 | #if CTX_INCLUDE_PAUTH_REGS |
| 946 | /* Restore the ARMv8.3 PAuth keys */ |
| 947 | add x10, sp, #CTX_PAUTH_REGS_OFFSET |
| 948 | |
| 949 | ldp x0, x1, [x10, #CTX_PACIAKEY_LO] /* x1:x0 = APIAKey */ |
| 950 | ldp x2, x3, [x10, #CTX_PACIBKEY_LO] /* x3:x2 = APIBKey */ |
| 951 | ldp x4, x5, [x10, #CTX_PACDAKEY_LO] /* x5:x4 = APDAKey */ |
| 952 | ldp x6, x7, [x10, #CTX_PACDBKEY_LO] /* x7:x6 = APDBKey */ |
| 953 | ldp x8, x9, [x10, #CTX_PACGAKEY_LO] /* x9:x8 = APGAKey */ |
| 954 | |
| 955 | msr APIAKeyLo_EL1, x0 |
| 956 | msr APIAKeyHi_EL1, x1 |
| 957 | msr APIBKeyLo_EL1, x2 |
| 958 | msr APIBKeyHi_EL1, x3 |
| 959 | msr APDAKeyLo_EL1, x4 |
| 960 | msr APDAKeyHi_EL1, x5 |
| 961 | msr APDBKeyLo_EL1, x6 |
| 962 | msr APDBKeyHi_EL1, x7 |
| 963 | msr APGAKeyLo_EL1, x8 |
| 964 | msr APGAKeyHi_EL1, x9 |
| 965 | #endif /* CTX_INCLUDE_PAUTH_REGS */ |
| 966 | |
| 967 | /* ---------------------------------------------------------- |
| 968 | * Restore PMCR_EL0 when returning to Non-secure state if |
| 969 | * Secure Cycle Counter is not disabled in MDCR_EL3 when |
| 970 | * ARMv8.5-PMU is implemented. |
| 971 | * ---------------------------------------------------------- |
| 972 | */ |
| 973 | mrs x0, scr_el3 |
| 974 | tst x0, #SCR_NS_BIT |
| 975 | beq 2f |
| 976 | |
| 977 | /* ---------------------------------------------------------- |
| 978 | * Back to Non-secure state. |
Alexei Fedorov | 307f34b | 2021-05-14 11:21:56 +0100 | [diff] [blame] | 979 | * Check if earlier initialization MDCR_EL3.SCCD/MCCD to 1 |
| 980 | * failed, meaning that FEAT_PMUv3p5/7 is not implemented and |
| 981 | * PMCR_EL0 should be restored from non-secure context. |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 982 | * ---------------------------------------------------------- |
| 983 | */ |
Alexei Fedorov | 307f34b | 2021-05-14 11:21:56 +0100 | [diff] [blame] | 984 | mov_imm x1, (MDCR_SCCD_BIT | MDCR_MCCD_BIT) |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 985 | mrs x0, mdcr_el3 |
Alexei Fedorov | 307f34b | 2021-05-14 11:21:56 +0100 | [diff] [blame] | 986 | tst x0, x1 |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 987 | bne 2f |
| 988 | ldr x0, [sp, #CTX_EL3STATE_OFFSET + CTX_PMCR_EL0] |
| 989 | msr pmcr_el0, x0 |
| 990 | 2: |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 991 | ldp x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0] |
| 992 | ldp x2, x3, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2] |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 993 | ldp x4, x5, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X4] |
| 994 | ldp x6, x7, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X6] |
| 995 | ldp x8, x9, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X8] |
| 996 | ldp x10, x11, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X10] |
| 997 | ldp x12, x13, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X12] |
| 998 | ldp x14, x15, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X14] |
Jeenu Viswambharan | 23d05a8 | 2017-11-29 16:59:34 +0000 | [diff] [blame] | 999 | ldp x16, x17, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X16] |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 1000 | ldp x18, x19, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X18] |
| 1001 | ldp x20, x21, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X20] |
| 1002 | ldp x22, x23, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X22] |
| 1003 | ldp x24, x25, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X24] |
| 1004 | ldp x26, x27, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X26] |
Jeenu Viswambharan | 23d05a8 | 2017-11-29 16:59:34 +0000 | [diff] [blame] | 1005 | ldr x28, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_SP_EL0] |
| 1006 | msr sp_el0, x28 |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 1007 | ldp x28, x29, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X28] |
Jeenu Viswambharan | 23d05a8 | 2017-11-29 16:59:34 +0000 | [diff] [blame] | 1008 | ret |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 1009 | endfunc restore_gp_pmcr_pauth_regs |
Jeenu Viswambharan | 23d05a8 | 2017-11-29 16:59:34 +0000 | [diff] [blame] | 1010 | |
Manish V Badarkhe | e07e808 | 2020-07-23 12:43:25 +0100 | [diff] [blame] | 1011 | /* |
| 1012 | * In case of ERRATA_SPECULATIVE_AT, save SCTLR_EL1 and TCR_EL1 |
| 1013 | * registers and update EL1 registers to disable stage1 and stage2 |
| 1014 | * page table walk |
| 1015 | */ |
| 1016 | func save_and_update_ptw_el1_sys_regs |
| 1017 | /* ---------------------------------------------------------- |
| 1018 | * Save only sctlr_el1 and tcr_el1 registers |
| 1019 | * ---------------------------------------------------------- |
| 1020 | */ |
| 1021 | mrs x29, sctlr_el1 |
| 1022 | str x29, [sp, #(CTX_EL1_SYSREGS_OFFSET + CTX_SCTLR_EL1)] |
| 1023 | mrs x29, tcr_el1 |
| 1024 | str x29, [sp, #(CTX_EL1_SYSREGS_OFFSET + CTX_TCR_EL1)] |
| 1025 | |
| 1026 | /* ------------------------------------------------------------ |
| 1027 | * Must follow below order in order to disable page table |
| 1028 | * walk for lower ELs (EL1 and EL0). First step ensures that |
| 1029 | * page table walk is disabled for stage1 and second step |
| 1030 | * ensures that page table walker should use TCR_EL1.EPDx |
| 1031 | * bits to perform address translation. ISB ensures that CPU |
| 1032 | * does these 2 steps in order. |
| 1033 | * |
| 1034 | * 1. Update TCR_EL1.EPDx bits to disable page table walk by |
| 1035 | * stage1. |
| 1036 | * 2. Enable MMU bit to avoid identity mapping via stage2 |
| 1037 | * and force TCR_EL1.EPDx to be used by the page table |
| 1038 | * walker. |
| 1039 | * ------------------------------------------------------------ |
| 1040 | */ |
| 1041 | orr x29, x29, #(TCR_EPD0_BIT) |
| 1042 | orr x29, x29, #(TCR_EPD1_BIT) |
| 1043 | msr tcr_el1, x29 |
| 1044 | isb |
| 1045 | mrs x29, sctlr_el1 |
| 1046 | orr x29, x29, #SCTLR_M_BIT |
| 1047 | msr sctlr_el1, x29 |
| 1048 | isb |
| 1049 | |
| 1050 | ret |
| 1051 | endfunc save_and_update_ptw_el1_sys_regs |
| 1052 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 1053 | /* ------------------------------------------------------------------ |
| 1054 | * This routine assumes that the SP_EL3 is pointing to a valid |
| 1055 | * context structure from where the gp regs and other special |
| 1056 | * registers can be retrieved. |
| 1057 | * ------------------------------------------------------------------ |
Antonio Nino Diaz | 13adfb1 | 2019-01-30 20:41:31 +0000 | [diff] [blame] | 1058 | */ |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 1059 | func el3_exit |
Jan Dabros | fa01598 | 2019-12-02 13:30:03 +0100 | [diff] [blame] | 1060 | #if ENABLE_ASSERTIONS |
| 1061 | /* el3_exit assumes SP_EL0 on entry */ |
| 1062 | mrs x17, spsel |
| 1063 | cmp x17, #MODE_SP_EL0 |
| 1064 | ASM_ASSERT(eq) |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 1065 | #endif /* ENABLE_ASSERTIONS */ |
Jan Dabros | fa01598 | 2019-12-02 13:30:03 +0100 | [diff] [blame] | 1066 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 1067 | /* ---------------------------------------------------------- |
| 1068 | * Save the current SP_EL0 i.e. the EL3 runtime stack which |
| 1069 | * will be used for handling the next SMC. |
| 1070 | * Then switch to SP_EL3. |
| 1071 | * ---------------------------------------------------------- |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 1072 | */ |
| 1073 | mov x17, sp |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 1074 | msr spsel, #MODE_SP_ELX |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 1075 | str x17, [sp, #CTX_EL3STATE_OFFSET + CTX_RUNTIME_SP] |
| 1076 | |
Max Shvetsov | c450277 | 2021-03-22 11:59:37 +0000 | [diff] [blame] | 1077 | #if IMAGE_BL31 |
| 1078 | /* ---------------------------------------------------------- |
Arunachalam Ganapathy | cac7d16 | 2021-07-08 09:35:57 +0100 | [diff] [blame] | 1079 | * Restore CPTR_EL3. |
Max Shvetsov | c450277 | 2021-03-22 11:59:37 +0000 | [diff] [blame] | 1080 | * ZCR is only restored if SVE is supported and enabled. |
| 1081 | * Synchronization is required before zcr_el3 is addressed. |
| 1082 | * ---------------------------------------------------------- |
| 1083 | */ |
Max Shvetsov | c450277 | 2021-03-22 11:59:37 +0000 | [diff] [blame] | 1084 | ldp x19, x20, [sp, #CTX_EL3STATE_OFFSET + CTX_CPTR_EL3] |
| 1085 | msr cptr_el3, x19 |
| 1086 | |
| 1087 | ands x19, x19, #CPTR_EZ_BIT |
| 1088 | beq sve_not_enabled |
| 1089 | |
| 1090 | isb |
| 1091 | msr S3_6_C1_C2_0, x20 /* zcr_el3 */ |
| 1092 | sve_not_enabled: |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 1093 | #endif /* IMAGE_BL31 */ |
Max Shvetsov | c450277 | 2021-03-22 11:59:37 +0000 | [diff] [blame] | 1094 | |
Dimitris Papastamos | ba51d9e | 2018-05-16 11:36:14 +0100 | [diff] [blame] | 1095 | #if IMAGE_BL31 && DYNAMIC_WORKAROUND_CVE_2018_3639 |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 1096 | /* ---------------------------------------------------------- |
| 1097 | * Restore mitigation state as it was on entry to EL3 |
| 1098 | * ---------------------------------------------------------- |
| 1099 | */ |
Dimitris Papastamos | ba51d9e | 2018-05-16 11:36:14 +0100 | [diff] [blame] | 1100 | ldr x17, [sp, #CTX_CVE_2018_3639_OFFSET + CTX_CVE_2018_3639_DISABLE] |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 1101 | cbz x17, 1f |
Dimitris Papastamos | ba51d9e | 2018-05-16 11:36:14 +0100 | [diff] [blame] | 1102 | blr x17 |
Antonio Nino Diaz | 13adfb1 | 2019-01-30 20:41:31 +0000 | [diff] [blame] | 1103 | 1: |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 1104 | #endif /* IMAGE_BL31 && DYNAMIC_WORKAROUND_CVE_2018_3639 */ |
| 1105 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 1106 | #if IMAGE_BL31 && RAS_EXTENSION |
| 1107 | /* ---------------------------------------------------------- |
| 1108 | * Issue Error Synchronization Barrier to synchronize SErrors |
| 1109 | * before exiting EL3. We're running with EAs unmasked, so |
| 1110 | * any synchronized errors would be taken immediately; |
| 1111 | * therefore no need to inspect DISR_EL1 register. |
| 1112 | * ---------------------------------------------------------- |
| 1113 | */ |
| 1114 | esb |
Madhukar Pappireddy | fba2572 | 2020-07-24 03:27:12 -0500 | [diff] [blame] | 1115 | #else |
| 1116 | dsb sy |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 1117 | #endif /* IMAGE_BL31 && RAS_EXTENSION */ |
| 1118 | |
Manish Pandey | 53bc59a | 2022-11-17 14:43:15 +0000 | [diff] [blame] | 1119 | /* ---------------------------------------------------------- |
| 1120 | * Restore SPSR_EL3, ELR_EL3 and SCR_EL3 prior to ERET |
| 1121 | * ---------------------------------------------------------- |
| 1122 | */ |
| 1123 | ldr x18, [sp, #CTX_EL3STATE_OFFSET + CTX_SCR_EL3] |
| 1124 | ldp x16, x17, [sp, #CTX_EL3STATE_OFFSET + CTX_SPSR_EL3] |
| 1125 | msr scr_el3, x18 |
| 1126 | msr spsr_el3, x16 |
| 1127 | msr elr_el3, x17 |
| 1128 | |
| 1129 | restore_ptw_el1_sys_regs |
| 1130 | |
| 1131 | /* ---------------------------------------------------------- |
| 1132 | * Restore general purpose (including x30), PMCR_EL0 and |
| 1133 | * ARMv8.3-PAuth registers. |
| 1134 | * Exit EL3 via ERET to a lower exception level. |
| 1135 | * ---------------------------------------------------------- |
| 1136 | */ |
| 1137 | bl restore_gp_pmcr_pauth_regs |
| 1138 | ldr x30, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR] |
| 1139 | |
Madhukar Pappireddy | fba2572 | 2020-07-24 03:27:12 -0500 | [diff] [blame] | 1140 | #ifdef IMAGE_BL31 |
| 1141 | str xzr, [sp, #CTX_EL3STATE_OFFSET + CTX_IS_IN_EL3] |
Jayanth Dodderi Chidanand | 72b69b8 | 2022-01-26 17:14:43 +0000 | [diff] [blame] | 1142 | #endif /* IMAGE_BL31 */ |
| 1143 | |
Anthony Steinhauser | 0f7e601 | 2020-01-07 15:44:06 -0800 | [diff] [blame] | 1144 | exception_return |
Antonio Nino Diaz | 594811b | 2019-01-31 11:58:00 +0000 | [diff] [blame] | 1145 | |
Yatharth Kochar | 6c0566c | 2015-10-02 17:56:48 +0100 | [diff] [blame] | 1146 | endfunc el3_exit |