Jayanth Dodderi Chidanand | 86e5e5d | 2024-08-05 19:52:29 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2024, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch_features.h> |
| 8 | #include <arch_helpers.h> |
| 9 | #include <lib/context_mgmt/context_el1.h> |
| 10 | |
| 11 | #define EL1_CTX_CORRUPT_MASK ULL(0xffff0000) |
| 12 | #define EL1_CTX_RESTORE_MASK ULL(0x0) |
| 13 | |
| 14 | /** |
| 15 | * --------------------------------------------------------------- |
| 16 | * Private Helper functions to save EL1 system context registers. |
| 17 | * --------------------------------------------------------------- |
| 18 | */ |
| 19 | static void save_el1_ctx_common_regs(const el1_ctx_regs_t *ctx) |
| 20 | { |
| 21 | el1_common_regs_t *el1_common = get_el1_common_regs_ctx(ctx); |
| 22 | |
| 23 | write_el1_ctx_reg(el1_common, spsr_el1, "spsr_el1", read_spsr_el1()); |
| 24 | write_el1_ctx_reg(el1_common, elr_el1, "elr_el1", read_elr_el1()); |
| 25 | write_el1_ctx_reg(el1_common, sctlr_el1, "sctlr_el1", read_sctlr_el1()); |
| 26 | write_el1_ctx_reg(el1_common, tcr_el1, "tcr_el1", read_tcr_el1()); |
| 27 | write_el1_ctx_reg(el1_common, cpacr_el1, "cpacr_el1", read_cpacr_el1()); |
| 28 | write_el1_ctx_reg(el1_common, csselr_el1, "csselr_el1", read_csselr_el1()); |
| 29 | write_el1_ctx_reg(el1_common, sp_el1, "sp_el1", read_sp_el1()); |
| 30 | write_el1_ctx_reg(el1_common, esr_el1, "esr_el1", read_esr_el1()); |
| 31 | write_el1_ctx_reg(el1_common, ttbr0_el1, "ttbr0_el1", read_ttbr0_el1()); |
| 32 | write_el1_ctx_reg(el1_common, ttbr1_el1, "ttbr1_el1", read_ttbr1_el1()); |
| 33 | write_el1_ctx_reg(el1_common, mair_el1, "mair_el1", read_mair_el1()); |
| 34 | write_el1_ctx_reg(el1_common, amair_el1, "amair_el1", read_amair_el1()); |
| 35 | write_el1_ctx_reg(el1_common, actlr_el1, "actlr_el1", read_actlr_el1()); |
| 36 | write_el1_ctx_reg(el1_common, tpidr_el1, "tpidr_el1", read_tpidr_el1()); |
| 37 | write_el1_ctx_reg(el1_common, tpidr_el0, "tpidr_el0", read_tpidr_el0()); |
| 38 | write_el1_ctx_reg(el1_common, tpidrro_el0, "tpidrro_el0", read_tpidrro_el0()); |
| 39 | write_el1_ctx_reg(el1_common, par_el1, "par_el1", read_par_el1()); |
| 40 | write_el1_ctx_reg(el1_common, far_el1, "far_el1", read_far_el1()); |
| 41 | write_el1_ctx_reg(el1_common, afsr0_el1, "afsr0_el1", read_afsr0_el1()); |
| 42 | write_el1_ctx_reg(el1_common, afsr1_el1, "afsr1_el1", read_afsr1_el1()); |
| 43 | write_el1_ctx_reg(el1_common, contextidr_el1, "contextidr_el1", read_contextidr_el1()); |
| 44 | write_el1_ctx_reg(el1_common, vbar_el1, "vbar_el1", read_vbar_el1()); |
| 45 | write_el1_ctx_reg(el1_common, mdccint_el1, "mdccint_el1", read_mdccint_el1()); |
| 46 | write_el1_ctx_reg(el1_common, mdscr_el1, "mdscr_el1", read_mdscr_el1()); |
| 47 | } |
| 48 | |
| 49 | static void save_el1_ctx_aarch32_regs(const el1_ctx_regs_t *ctx) |
| 50 | { |
| 51 | #if CTX_INCLUDE_AARCH32_REGS |
| 52 | el1_aarch32_regs_t *el1_aarch32 = get_el1_aarch32_regs_ctx(ctx); |
| 53 | |
| 54 | write_el1_ctx_reg(el1_aarch32, spsr_abt, "spsr_abt", read_spsr_abt()); |
| 55 | write_el1_ctx_reg(el1_aarch32, spsr_und, "spsr_und", read_spsr_und()); |
| 56 | write_el1_ctx_reg(el1_aarch32, spsr_irq, "spsr_irq", read_spsr_irq()); |
| 57 | write_el1_ctx_reg(el1_aarch32, spsr_fiq, "spsr_fiq", read_spsr_fiq()); |
| 58 | write_el1_ctx_reg(el1_aarch32, dacr32_el2, "dacr32_el2", read_dacr32_el2()); |
| 59 | write_el1_ctx_reg(el1_aarch32, ifsr32_el2, "ifsr32_el2", read_ifsr32_el2()); |
| 60 | #endif |
| 61 | } |
| 62 | |
| 63 | static void save_el1_ctx_timer_regs(const el1_ctx_regs_t *ctx) |
| 64 | { |
| 65 | el1_arch_timer_regs_t *el1_arch_timer = get_el1_arch_timer_regs_ctx(ctx); |
| 66 | |
| 67 | write_el1_ctx_reg(el1_arch_timer, cntp_ctl_el0, "cntp_ctl_el0", read_cntp_ctl_el0()); |
| 68 | write_el1_ctx_reg(el1_arch_timer, cntp_cval_el0, "cntp_cval_el0", read_cntp_cval_el0()); |
| 69 | write_el1_ctx_reg(el1_arch_timer, cntv_ctl_el0, "cntv_ctl_el0", read_cntv_ctl_el0()); |
| 70 | write_el1_ctx_reg(el1_arch_timer, cntv_cval_el0, "cntv_cval_el0", read_cntv_cval_el0()); |
| 71 | write_el1_ctx_reg(el1_arch_timer, cntkctl_el1, "cntkctl_el1", read_cntkctl_el1()); |
| 72 | } |
| 73 | |
| 74 | static void save_el1_ctx_mte2_regs(const el1_ctx_regs_t *ctx) |
| 75 | { |
| 76 | if (is_feat_mte2_present()) { |
| 77 | el1_mte2_regs_t *el1_mte2 = get_el1_mte2_regs_ctx(ctx); |
| 78 | |
| 79 | write_el1_ctx_reg(el1_mte2, tfsre0_el1, "tfsre0_el1", read_tfsre0_el1()); |
| 80 | write_el1_ctx_reg(el1_mte2, tfsr_el1, "tfsr_el1", read_tfsr_el1()); |
| 81 | write_el1_ctx_reg(el1_mte2, rgsr_el1, "rgsr_el1", read_rgsr_el1()); |
| 82 | write_el1_ctx_reg(el1_mte2, gcr_el1, "gcr_el1", read_gcr_el1()); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | static void save_el1_ctx_ras_regs(const el1_ctx_regs_t *ctx) |
| 87 | { |
| 88 | if (is_feat_ras_present()) { |
| 89 | el1_ras_regs_t *el1_ras = get_el1_ras_regs_ctx(ctx); |
| 90 | |
| 91 | write_el1_ctx_reg(el1_ras, disr_el1, "disr_el1", read_disr_el1()); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | static void save_el1_ctx_s1pie_regs(const el1_ctx_regs_t *ctx) |
| 96 | { |
| 97 | if (is_feat_s1pie_present()) { |
| 98 | el1_s1pie_regs_t *el1_s1pie = get_el1_s1pie_regs_ctx(ctx); |
| 99 | write_el1_ctx_reg(el1_s1pie, pire0_el1, "pire0_el1", read_pire0_el1()); |
| 100 | write_el1_ctx_reg(el1_s1pie, pir_el1, "pir_el1", read_pir_el1()); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | static void save_el1_ctx_s1poe_regs(const el1_ctx_regs_t *ctx) |
| 105 | { |
| 106 | if (is_feat_s1poe_present()) { |
| 107 | el1_s1poe_regs_t *el1_s1poe = get_el1_s1poe_regs_ctx(ctx); |
| 108 | |
| 109 | write_el1_ctx_reg(el1_s1poe, por_el1, "por_el1", read_por_el1()); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | static void save_el1_ctx_s2poe_regs(const el1_ctx_regs_t *ctx) |
| 114 | { |
| 115 | if (is_feat_s2poe_present()) { |
| 116 | el1_s2poe_regs_t *el1_s2poe = get_el1_s2poe_regs_ctx(ctx); |
| 117 | |
| 118 | write_el1_ctx_reg(el1_s2poe, s2por_el1, "s2por_el1", read_s2por_el1()); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | static void save_el1_ctx_tcr2_regs(const el1_ctx_regs_t *ctx) |
| 123 | { |
| 124 | if (is_feat_tcr2_supported()) { |
| 125 | el1_tcr2_regs_t *el1_tcr2 = get_el1_tcr2_regs_ctx(ctx); |
| 126 | |
| 127 | write_el1_ctx_reg(el1_tcr2, tcr2_el1, "tcr2_el1", read_tcr2_el1()); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | static void save_el1_ctx_trf_regs(const el1_ctx_regs_t *ctx) |
| 132 | { |
| 133 | if (get_armv8_4_trf_support()) { |
| 134 | el1_trf_regs_t *el1_trf = get_el1_trf_regs_ctx(ctx); |
| 135 | |
| 136 | write_el1_ctx_reg(el1_trf, trfcr_el1, "trfcr_el1", read_trfcr_el1()); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | static void save_el1_ctx_csv2_2_regs(const el1_ctx_regs_t *ctx) |
| 141 | { |
| 142 | if (is_feat_csv2_2_present()) { |
| 143 | el1_csv2_2_regs_t *el1_csv2_2 = get_el1_csv2_2_regs_ctx(ctx); |
| 144 | |
| 145 | write_el1_ctx_reg(el1_csv2_2, scxtnum_el0, "scxtnum_el0", read_scxtnum_el0()); |
| 146 | write_el1_ctx_reg(el1_csv2_2, scxtnum_el1, "scxtnum_el1", read_scxtnum_el1()); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | static void save_el1_ctx_gcs_regs(const el1_ctx_regs_t *ctx) |
| 151 | { |
| 152 | if (is_feat_gcs_present()) { |
| 153 | el1_gcs_regs_t *el1_gcs = get_el1_gcs_regs_ctx(ctx); |
| 154 | |
| 155 | write_el1_ctx_reg(el1_gcs, gcscr_el1, "gcscr_el1", read_gcscr_el1()); |
| 156 | write_el1_ctx_reg(el1_gcs, gcscre0_el1, "gcscre0_el1", read_gcscre0_el1()); |
| 157 | write_el1_ctx_reg(el1_gcs, gcspr_el1, "gcspr_el1", read_gcspr_el1()); |
| 158 | write_el1_ctx_reg(el1_gcs, gcspr_el0, "gcspr_el0", read_gcspr_el0()); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * ------------------------------------------------------------------------ |
| 164 | * Private Helper functions to modify/restore EL1 system context registers. |
| 165 | * ------------------------------------------------------------------------ |
| 166 | */ |
| 167 | static void write_el1_ctx_common_regs(const el1_ctx_regs_t *ctx, uint64_t reg_mask) |
| 168 | { |
| 169 | el1_common_regs_t *el1_common = get_el1_common_regs_ctx(ctx); |
| 170 | |
| 171 | write_spsr_el1((el1_common->spsr_el1.reg_value) | reg_mask); |
| 172 | write_elr_el1((el1_common->elr_el1.reg_value) | reg_mask); |
| 173 | write_sctlr_el1((el1_common->sctlr_el1.reg_value) | reg_mask); |
| 174 | write_tcr_el1((el1_common->tcr_el1.reg_value) | reg_mask); |
| 175 | write_cpacr_el1((el1_common->cpacr_el1.reg_value) | reg_mask); |
| 176 | write_csselr_el1((el1_common->csselr_el1.reg_value) | reg_mask); |
| 177 | write_sp_el1((el1_common->sp_el1.reg_value) | reg_mask); |
| 178 | write_esr_el1((el1_common->esr_el1.reg_value) | reg_mask); |
| 179 | write_ttbr0_el1((el1_common->ttbr0_el1.reg_value) | reg_mask); |
| 180 | write_ttbr1_el1((el1_common->ttbr1_el1.reg_value) | reg_mask); |
| 181 | write_mair_el1((el1_common->mair_el1.reg_value) | reg_mask); |
| 182 | write_amair_el1((el1_common->amair_el1.reg_value) | reg_mask); |
| 183 | write_actlr_el1((el1_common->actlr_el1.reg_value) | reg_mask); |
| 184 | write_tpidr_el1((el1_common->tpidr_el1.reg_value) | reg_mask); |
| 185 | write_tpidr_el0((el1_common->tpidr_el0.reg_value) | reg_mask); |
| 186 | write_tpidrro_el0((el1_common->tpidrro_el0.reg_value) | reg_mask); |
| 187 | write_par_el1((el1_common->par_el1.reg_value) | reg_mask); |
| 188 | write_far_el1((el1_common->far_el1.reg_value) | reg_mask); |
| 189 | write_afsr0_el1((el1_common->afsr0_el1.reg_value) | reg_mask); |
| 190 | write_afsr1_el1((el1_common->afsr1_el1.reg_value) | reg_mask); |
| 191 | write_contextidr_el1((el1_common->contextidr_el1.reg_value) | reg_mask); |
| 192 | write_vbar_el1((el1_common->vbar_el1.reg_value) | reg_mask); |
| 193 | write_mdccint_el1((el1_common->mdccint_el1.reg_value) | reg_mask); |
| 194 | write_mdscr_el1((el1_common->mdscr_el1.reg_value) | reg_mask); |
| 195 | } |
| 196 | |
| 197 | static void write_el1_ctx_aarch32_regs(const el1_ctx_regs_t *ctx, uint64_t reg_mask) |
| 198 | { |
| 199 | #if CTX_INCLUDE_AARCH32_REGS |
| 200 | el1_aarch32_regs_t *el1_aarch32 = get_el1_aarch32_regs_ctx(ctx); |
| 201 | |
| 202 | write_spsr_abt((el1_aarch32->spsr_abt.reg_value) | reg_mask); |
| 203 | write_spsr_und((el1_aarch32->spsr_und.reg_value) | reg_mask); |
| 204 | write_spsr_irq((el1_aarch32->spsr_irq.reg_value) | reg_mask); |
| 205 | write_spsr_fiq((el1_aarch32->spsr_fiq.reg_value) | reg_mask); |
| 206 | write_dacr32_el2((el1_aarch32->dacr32_el2.reg_value) | reg_mask); |
| 207 | write_ifsr32_el2((el1_aarch32->ifsr32_el2.reg_value) | reg_mask); |
| 208 | #endif |
| 209 | } |
| 210 | |
| 211 | static void write_el1_ctx_timer_regs(const el1_ctx_regs_t *ctx, uint64_t reg_mask) |
| 212 | { |
| 213 | el1_arch_timer_regs_t *el1_arch_timer = get_el1_arch_timer_regs_ctx(ctx); |
| 214 | |
| 215 | write_cntp_ctl_el0((el1_arch_timer->cntp_ctl_el0.reg_value) | reg_mask); |
| 216 | write_cntp_cval_el0((el1_arch_timer->cntp_cval_el0.reg_value) | reg_mask); |
| 217 | write_cntv_ctl_el0((el1_arch_timer->cntv_ctl_el0.reg_value) | reg_mask); |
| 218 | write_cntv_cval_el0((el1_arch_timer->cntv_cval_el0.reg_value) | reg_mask); |
| 219 | write_cntkctl_el1((el1_arch_timer->cntkctl_el1.reg_value) | reg_mask); |
| 220 | } |
| 221 | |
| 222 | static void write_el1_ctx_mte2_regs(const el1_ctx_regs_t *ctx, uint64_t reg_mask) |
| 223 | { |
| 224 | if (is_feat_mte2_present()) { |
| 225 | el1_mte2_regs_t *el1_mte2 = get_el1_mte2_regs_ctx(ctx); |
| 226 | |
| 227 | write_tfsre0_el1((el1_mte2->tfsre0_el1.reg_value) | reg_mask); |
| 228 | write_tfsr_el1((el1_mte2->tfsr_el1.reg_value) | reg_mask); |
| 229 | write_rgsr_el1((el1_mte2->rgsr_el1.reg_value) | reg_mask); |
| 230 | write_gcr_el1((el1_mte2->gcr_el1.reg_value) | reg_mask); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | static void write_el1_ctx_ras_regs(const el1_ctx_regs_t *ctx, uint64_t reg_mask) |
| 235 | { |
| 236 | if (is_feat_ras_present()) { |
| 237 | el1_ras_regs_t *el1_ras = get_el1_ras_regs_ctx(ctx); |
| 238 | |
| 239 | write_disr_el1((el1_ras->disr_el1.reg_value) | reg_mask); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | static void write_el1_ctx_s1pie_regs(const el1_ctx_regs_t *ctx, uint64_t reg_mask) |
| 244 | { |
| 245 | if (is_feat_s1pie_present()) { |
| 246 | el1_s1pie_regs_t *el1_s1pie = get_el1_s1pie_regs_ctx(ctx); |
| 247 | |
| 248 | write_pire0_el1((el1_s1pie->pire0_el1.reg_value) | reg_mask); |
| 249 | write_pir_el1((el1_s1pie->pir_el1.reg_value) | reg_mask); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | static void write_el1_ctx_s1poe_regs(const el1_ctx_regs_t *ctx, uint64_t reg_mask) |
| 254 | { |
| 255 | if (is_feat_s1poe_present()) { |
| 256 | el1_s1poe_regs_t *el1_s1poe = get_el1_s1poe_regs_ctx(ctx); |
| 257 | |
| 258 | write_por_el1((el1_s1poe->por_el1.reg_value) | reg_mask); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | static void write_el1_ctx_s2poe_regs(const el1_ctx_regs_t *ctx, uint64_t reg_mask) |
| 263 | { |
| 264 | if (is_feat_s2poe_present()) { |
| 265 | el1_s2poe_regs_t *el1_s2poe = get_el1_s2poe_regs_ctx(ctx); |
| 266 | |
| 267 | write_s2por_el1((el1_s2poe->s2por_el1.reg_value) | reg_mask); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | static void write_el1_ctx_tcr2_regs(const el1_ctx_regs_t *ctx, uint64_t reg_mask) |
| 272 | { |
| 273 | if (is_feat_tcr2_supported()) { |
| 274 | el1_tcr2_regs_t *el1_tcr2 = get_el1_tcr2_regs_ctx(ctx); |
| 275 | |
| 276 | write_tcr2_el1((el1_tcr2->tcr2_el1.reg_value) | reg_mask); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | static void write_el1_ctx_trf_regs(const el1_ctx_regs_t *ctx, uint64_t reg_mask) |
| 281 | { |
| 282 | if (get_armv8_4_trf_support()) { |
| 283 | el1_trf_regs_t *el1_trf = get_el1_trf_regs_ctx(ctx); |
| 284 | |
| 285 | write_trfcr_el1((el1_trf->trfcr_el1.reg_value) | reg_mask); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | static void write_el1_ctx_csv2_2_regs(const el1_ctx_regs_t *ctx, uint64_t reg_mask) |
| 290 | { |
| 291 | if (is_feat_csv2_2_present()) { |
| 292 | el1_csv2_2_regs_t *el1_csv2_2 = get_el1_csv2_2_regs_ctx(ctx); |
| 293 | |
| 294 | write_scxtnum_el0((el1_csv2_2->scxtnum_el0.reg_value) | reg_mask); |
| 295 | write_scxtnum_el1((el1_csv2_2->scxtnum_el1.reg_value) | reg_mask); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | static void write_el1_ctx_gcs_regs(const el1_ctx_regs_t *ctx, uint64_t reg_mask) |
| 300 | { |
| 301 | if (is_feat_gcs_present()) { |
| 302 | el1_gcs_regs_t *el1_gcs = get_el1_gcs_regs_ctx(ctx); |
| 303 | |
| 304 | write_gcscr_el1((el1_gcs->gcscr_el1.reg_value) | reg_mask); |
| 305 | write_gcscre0_el1((el1_gcs->gcscre0_el1.reg_value) | reg_mask); |
| 306 | write_gcspr_el1((el1_gcs->gcspr_el1.reg_value) | reg_mask); |
| 307 | write_gcspr_el0((el1_gcs->gcspr_el0.reg_value) | reg_mask); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * ------------------------------------------------------------------ |
| 313 | * Private helper functions to Print each sub structure of the main |
| 314 | * EL1 system context structure. |
| 315 | * ------------------------------------------------------------------ |
| 316 | */ |
| 317 | static void print_el1_ctx_common_sysregs(const el1_ctx_regs_t *el1_ctx) |
| 318 | { |
| 319 | el1_common_regs_t *el1_common = get_el1_common_regs_ctx(el1_ctx); |
| 320 | |
| 321 | PRINT_CTX_MEMBER(el1_common, spsr_el1); |
| 322 | PRINT_CTX_MEMBER(el1_common, elr_el1); |
| 323 | PRINT_CTX_MEMBER(el1_common, sctlr_el1); |
| 324 | PRINT_CTX_MEMBER(el1_common, tcr_el1); |
| 325 | PRINT_CTX_MEMBER(el1_common, cpacr_el1); |
| 326 | PRINT_CTX_MEMBER(el1_common, csselr_el1); |
| 327 | PRINT_CTX_MEMBER(el1_common, sp_el1); |
| 328 | PRINT_CTX_MEMBER(el1_common, esr_el1); |
| 329 | PRINT_CTX_MEMBER(el1_common, ttbr0_el1); |
| 330 | PRINT_CTX_MEMBER(el1_common, ttbr1_el1); |
| 331 | PRINT_CTX_MEMBER(el1_common, mair_el1); |
| 332 | PRINT_CTX_MEMBER(el1_common, amair_el1); |
| 333 | PRINT_CTX_MEMBER(el1_common, actlr_el1); |
| 334 | PRINT_CTX_MEMBER(el1_common, tpidr_el1); |
| 335 | PRINT_CTX_MEMBER(el1_common, tpidr_el0); |
| 336 | PRINT_CTX_MEMBER(el1_common, tpidrro_el0); |
| 337 | PRINT_CTX_MEMBER(el1_common, par_el1); |
| 338 | PRINT_CTX_MEMBER(el1_common, far_el1); |
| 339 | PRINT_CTX_MEMBER(el1_common, afsr0_el1); |
| 340 | PRINT_CTX_MEMBER(el1_common, afsr1_el1); |
| 341 | PRINT_CTX_MEMBER(el1_common, contextidr_el1); |
| 342 | PRINT_CTX_MEMBER(el1_common, vbar_el1); |
| 343 | PRINT_CTX_MEMBER(el1_common, mdccint_el1); |
| 344 | PRINT_CTX_MEMBER(el1_common, mdscr_el1); |
| 345 | } |
| 346 | |
| 347 | static void print_el1_ctx_aarch32_sysregs(const el1_ctx_regs_t *el1_ctx) |
| 348 | { |
| 349 | #if CTX_INCLUDE_AARCH32_REGS |
| 350 | el1_aarch32_regs_t *el1_aarch32 = get_el1_aarch32_regs_ctx(el1_ctx); |
| 351 | |
| 352 | PRINT_CTX_MEMBER(el1_aarch32, spsr_abt); |
| 353 | PRINT_CTX_MEMBER(el1_aarch32, spsr_und); |
| 354 | PRINT_CTX_MEMBER(el1_aarch32, spsr_irq); |
| 355 | PRINT_CTX_MEMBER(el1_aarch32, spsr_fiq); |
| 356 | PRINT_CTX_MEMBER(el1_aarch32, dacr32_el2); |
| 357 | PRINT_CTX_MEMBER(el1_aarch32, ifsr32_el2); |
| 358 | #endif |
| 359 | } |
| 360 | |
| 361 | static void print_el1_ctx_timer_sysregs(const el1_ctx_regs_t *el1_ctx) |
| 362 | { |
| 363 | el1_arch_timer_regs_t *el1_arch_timer = get_el1_arch_timer_regs_ctx(el1_ctx); |
| 364 | |
| 365 | PRINT_CTX_MEMBER(el1_arch_timer, cntp_ctl_el0); |
| 366 | PRINT_CTX_MEMBER(el1_arch_timer, cntp_cval_el0); |
| 367 | PRINT_CTX_MEMBER(el1_arch_timer, cntv_ctl_el0); |
| 368 | PRINT_CTX_MEMBER(el1_arch_timer, cntv_cval_el0); |
| 369 | PRINT_CTX_MEMBER(el1_arch_timer, cntkctl_el1); |
| 370 | } |
| 371 | |
| 372 | static void print_el1_ctx_mte2_sysregs(const el1_ctx_regs_t *el1_ctx) |
| 373 | { |
| 374 | el1_mte2_regs_t *el1_mte2 = get_el1_mte2_regs_ctx(el1_ctx); |
| 375 | |
| 376 | PRINT_CTX_MEMBER(el1_mte2, tfsre0_el1); |
| 377 | PRINT_CTX_MEMBER(el1_mte2, tfsr_el1); |
| 378 | PRINT_CTX_MEMBER(el1_mte2, rgsr_el1); |
| 379 | PRINT_CTX_MEMBER(el1_mte2, gcr_el1); |
| 380 | } |
| 381 | |
| 382 | static void print_el1_ctx_ras_sysregs(const el1_ctx_regs_t *el1_ctx) |
| 383 | { |
| 384 | el1_ras_regs_t *el1_ras = get_el1_ras_regs_ctx(el1_ctx); |
| 385 | |
| 386 | PRINT_CTX_MEMBER(el1_ras, disr_el1); |
| 387 | } |
| 388 | |
| 389 | static void print_el1_ctx_s1pie_sysregs(const el1_ctx_regs_t *el1_ctx) |
| 390 | { |
| 391 | el1_s1pie_regs_t *el1_s1pie = get_el1_s1pie_regs_ctx(el1_ctx); |
| 392 | |
| 393 | PRINT_CTX_MEMBER(el1_s1pie, pire0_el1); |
| 394 | PRINT_CTX_MEMBER(el1_s1pie, pir_el1); |
| 395 | } |
| 396 | |
| 397 | static void print_el1_ctx_s1poe_sysregs(const el1_ctx_regs_t *el1_ctx) |
| 398 | { |
| 399 | el1_s1poe_regs_t *el1_s1poe = get_el1_s1poe_regs_ctx(el1_ctx); |
| 400 | |
| 401 | PRINT_CTX_MEMBER(el1_s1poe, por_el1); |
| 402 | } |
| 403 | |
| 404 | static void print_el1_ctx_s2poe_sysregs(const el1_ctx_regs_t *el1_ctx) |
| 405 | { |
| 406 | el1_s2poe_regs_t *el1_s2poe = get_el1_s2poe_regs_ctx(el1_ctx); |
| 407 | |
| 408 | PRINT_CTX_MEMBER(el1_s2poe, s2por_el1); |
| 409 | |
| 410 | } |
| 411 | |
| 412 | static void print_el1_ctx_tcr2_sysregs(const el1_ctx_regs_t *el1_ctx) |
| 413 | { |
| 414 | el1_tcr2_regs_t *el1_tcr2 = get_el1_tcr2_regs_ctx(el1_ctx); |
| 415 | |
| 416 | PRINT_CTX_MEMBER(el1_tcr2, tcr2_el1); |
| 417 | |
| 418 | } |
| 419 | |
| 420 | static void print_el1_ctx_trf_sysregs(const el1_ctx_regs_t *el1_ctx) |
| 421 | { |
| 422 | el1_trf_regs_t *el1_trf = get_el1_trf_regs_ctx(el1_ctx); |
| 423 | |
| 424 | PRINT_CTX_MEMBER(el1_trf, trfcr_el1); |
| 425 | } |
| 426 | |
| 427 | static void print_el1_ctx_csv2_2_sysregs(const el1_ctx_regs_t *el1_ctx) |
| 428 | { |
| 429 | el1_csv2_2_regs_t *el1_csv2_2 = get_el1_csv2_2_regs_ctx(el1_ctx); |
| 430 | |
| 431 | PRINT_CTX_MEMBER(el1_csv2_2, scxtnum_el0); |
| 432 | PRINT_CTX_MEMBER(el1_csv2_2, scxtnum_el1); |
| 433 | } |
| 434 | |
| 435 | static void print_el1_ctx_gcs_sysregs(const el1_ctx_regs_t *el1_ctx) |
| 436 | { |
| 437 | el1_gcs_regs_t *el1_gcs = get_el1_gcs_regs_ctx(el1_ctx); |
| 438 | |
| 439 | PRINT_CTX_MEMBER(el1_gcs, gcscr_el1); |
| 440 | PRINT_CTX_MEMBER(el1_gcs, gcscre0_el1); |
| 441 | PRINT_CTX_MEMBER(el1_gcs, gcspr_el1); |
| 442 | PRINT_CTX_MEMBER(el1_gcs, gcspr_el0); |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * Public Function: save_el1_sysregs_context. |
| 447 | * |
| 448 | * @brief: To read the EL1 registers and save it into the context structure. |
| 449 | * @param: EL1 system register context struct(el1_ctx_regs_t) |
| 450 | */ |
| 451 | void save_el1_sysregs_context(const el1_ctx_regs_t *el1_ctx) |
| 452 | { |
| 453 | save_el1_ctx_common_regs(el1_ctx); |
| 454 | save_el1_ctx_aarch32_regs(el1_ctx); |
| 455 | save_el1_ctx_timer_regs(el1_ctx); |
| 456 | save_el1_ctx_mte2_regs(el1_ctx); |
| 457 | save_el1_ctx_ras_regs(el1_ctx); |
| 458 | save_el1_ctx_s1pie_regs(el1_ctx); |
| 459 | save_el1_ctx_s1poe_regs(el1_ctx); |
| 460 | save_el1_ctx_s2poe_regs(el1_ctx); |
| 461 | save_el1_ctx_tcr2_regs(el1_ctx); |
| 462 | save_el1_ctx_trf_regs(el1_ctx); |
| 463 | save_el1_ctx_csv2_2_regs(el1_ctx); |
| 464 | save_el1_ctx_gcs_regs(el1_ctx); |
| 465 | } |
| 466 | |
| 467 | /** |
| 468 | * Public Function: modify_el1_context_sysregs. |
| 469 | * |
| 470 | * @brief: To modify the EL1 registers |
| 471 | * @param: EL1 system register context struct(el1_ctx_regs_t) |
| 472 | */ |
| 473 | void modify_el1_context_sysregs(const el1_ctx_regs_t *el1_ctx, const bool modify_option) |
| 474 | { |
| 475 | uint64_t mask; |
| 476 | if (modify_option == NS_CORRUPT_EL1_REGS) |
| 477 | mask = EL1_CTX_CORRUPT_MASK; |
| 478 | else |
| 479 | mask = EL1_CTX_RESTORE_MASK; |
| 480 | |
| 481 | write_el1_ctx_common_regs(el1_ctx, mask); |
| 482 | write_el1_ctx_aarch32_regs(el1_ctx, mask); |
| 483 | write_el1_ctx_timer_regs(el1_ctx, mask); |
| 484 | write_el1_ctx_mte2_regs(el1_ctx, mask); |
| 485 | write_el1_ctx_ras_regs(el1_ctx, mask); |
| 486 | write_el1_ctx_s1pie_regs(el1_ctx, mask); |
| 487 | write_el1_ctx_s1poe_regs(el1_ctx, mask); |
| 488 | write_el1_ctx_s2poe_regs(el1_ctx, mask); |
| 489 | write_el1_ctx_tcr2_regs(el1_ctx, mask); |
| 490 | write_el1_ctx_trf_regs(el1_ctx, mask); |
| 491 | write_el1_ctx_csv2_2_regs(el1_ctx, mask); |
| 492 | write_el1_ctx_gcs_regs(el1_ctx, mask); |
| 493 | } |
| 494 | |
| 495 | /** |
| 496 | * Public Function: print_el1_sysregs_context |
| 497 | * |
| 498 | * @brief: To print all the members of the EL1 context structure. |
| 499 | * @param: EL1 system register context struct pointer (el1_ctx_regs_t *) |
| 500 | */ |
| 501 | void print_el1_sysregs_context(const el1_ctx_regs_t *el1_ctx) |
| 502 | { |
| 503 | PRINT_CTX_MEM_SEPARATOR(); |
| 504 | printf("| EL1 Context Registers | Value |\n"); |
| 505 | PRINT_CTX_MEM_SEPARATOR(); |
| 506 | print_el1_ctx_common_sysregs(el1_ctx); |
| 507 | print_el1_ctx_aarch32_sysregs(el1_ctx); |
| 508 | print_el1_ctx_timer_sysregs(el1_ctx); |
| 509 | print_el1_ctx_mte2_sysregs(el1_ctx); |
| 510 | print_el1_ctx_ras_sysregs(el1_ctx); |
| 511 | print_el1_ctx_s1pie_sysregs(el1_ctx); |
| 512 | print_el1_ctx_s1poe_sysregs(el1_ctx); |
| 513 | print_el1_ctx_s2poe_sysregs(el1_ctx); |
| 514 | print_el1_ctx_tcr2_sysregs(el1_ctx); |
| 515 | print_el1_ctx_trf_sysregs(el1_ctx); |
| 516 | print_el1_ctx_csv2_2_sysregs(el1_ctx); |
| 517 | print_el1_ctx_gcs_sysregs(el1_ctx); |
| 518 | printf("\n"); |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * Public Function: compare the EL1 context structures. |
| 523 | * |
| 524 | * @brief: To compare two explicit EL1 context structure values and return |
| 525 | * the status as (TRUE) if equal or (FALSE) if not-equal. |
| 526 | * @param: EL1 system register context struct pointers |
| 527 | * ( el1_ctx_regs_t *, el1_ctx_regs_t *) |
| 528 | */ |
| 529 | bool compare_el1_contexts(const el1_ctx_regs_t *el1_ctx1, const el1_ctx_regs_t *el1_ctx2) |
| 530 | { |
| 531 | if (!memcmp(el1_ctx1, el1_ctx2, sizeof(el1_ctx_regs_t))) |
| 532 | return true; |
| 533 | else |
| 534 | return false; |
| 535 | } |