Is there any example code of going from AArch64 EL3 to AArch32 EL1? I'm trying to do this now with code similar to this, but I am aborting because the CPSR is incorrect after the eret.
mrs x0, currentel
cmp x0, #0xc
b.ne br_to_test
mov x0, #0x030 // RES1 field
tst x26, #0x1 // do we switch to 32-bit for lower EL's?
beq 1f
orr x0, x0, #0x400 // Lower EL's are AArch64
1:
orr x0, x0, #0x100 // HVC instruction enabled
msr scr_el3, x0
msr cptr_el3, xzr // don't trap to EL3
msr sctlr_el2, xzr
// setup some EL2 stuff
tst x26, #0x1 // do we switch to 32-bit for lower EL's?
beq 1f
mrs x0, hcr_el2
orr x0, x0, #(1 << 31) // 64-bit EL1
msr hcr_el2, x0
1:
msr ttbr0_el2, xzr // clear out the page table address for EL2
// Coprocessor traps.
mov x0, #0x33ff
msr cptr_el2, x0 // Disable copro. traps to EL2
msr hstr_el2, xzr // Disable CP15 traps to EL2 in AArch32
// now go to EL1 with eret
ldr w0, [x29, #0] // next image address
tst x26, #0x1
b.eq 1f // need to setup for 32-bit
mov x1, #0x3c5 // AArch64 - EL1h + D,A,I,F disabled
b 2f
1: mov x1, #0x10 // AArch32 - Supervisor + D,A,I,F disabled
2: msr elr_el3, x0
msr spsr_el3, x1
eret