diff options
Diffstat (limited to 'include/common/asm_macros.S')
-rw-r--r-- | include/common/asm_macros.S | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/include/common/asm_macros.S b/include/common/asm_macros.S index 238fa82..491ed60 100644 --- a/include/common/asm_macros.S +++ b/include/common/asm_macros.S @@ -195,3 +195,61 @@ wait_for_entrypoint: _mov_imm16 \_reg, (\_val), 48 .endif .endm + + .macro asm_read_sysreg_el1_or_el2 sysreg + mrs x0, CurrentEL + cmp x0, #(MODE_EL1 << MODE_EL_SHIFT) + b.eq 1f + cmp x0, #(MODE_EL2 << MODE_EL_SHIFT) + b.eq 2f + b dead +1: + mrs x0, \sysreg\()_el1 + b 3f +2: + mrs x0, \sysreg\()_el1 +3: + .endm + + .macro asm_write_sysreg_el1_or_el2 sysreg scratch_reg + mrs \scratch_reg, CurrentEL + cmp \scratch_reg, #(MODE_EL1 << MODE_EL_SHIFT) + b.eq 1f + cmp \scratch_reg, #(MODE_EL2 << MODE_EL_SHIFT) + b.eq 2f + b dead +1: + msr \sysreg\()_el1, x0 + b 3f +2: + msr \sysreg\()_el2, x0 +3: + .endm + + .macro asm_read_sctlr_el1_or_el2 + asm_read_sysreg_el1_or_el2 sctlr + .endm + + .macro asm_write_sctlr_el1_or_el2 scratch_reg + asm_write_sysreg_el1_or_el2 sctlr \scratch_reg + .endm + + .macro asm_write_vbar_el1_or_el2 scratch_reg + asm_write_sysreg_el1_or_el2 vbar \scratch_reg + .endm + +/* + * Depending on the current exception level, jump to 'label_el1' or 'label_el2'. + * If the current exception level is neither EL1 nor EL2, jump to an infinite + * loop instead. + * Provide the macro with a scratch 64-bit register to use, its contents prior + * to calling this function will be lost. + */ + .macro JUMP_EL1_OR_EL2 scratch_reg, label_el1, label_el2 + mrs \scratch_reg, CurrentEL + cmp \scratch_reg, #(MODE_EL1 << MODE_EL_SHIFT) + b.eq \label_el1 + cmp \scratch_reg, #(MODE_EL2 << MODE_EL_SHIFT) + b.eq \label_el2 + b dead + .endm |