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