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