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