Posts: 76
Joined: Sun Apr 10, 2016 1:37 pm
Location: Yokohama

EL switching

Thu Jan 10, 2019 4:48 pm


I still struggle to dynamically change the EL with my PI3 in AARCH64. (If I do it at boot from reset, I can enter EL2 or EL1 successfully, no pb here).
I start the ARM in 64bits at EL3 and keep it at this level. Then I want to dynamically switch to EL2. So, I call HVC #0.

This triggers the Sync Exception of EL3 as expected with EC = 0b010110, meaning HVC call in 64 bits. This is still ok here.
In this exception handler, I modify SPSR_EL3 EL bits to EL2, then after some debug prints (serial terminal), I leave the exception handler with an ERET.
But, as soon as the above exception handler returns, another exception is fired, that one vector 0x480, 'IRQ 64 bits from lower EL' still at EL3.
That IRQ, I have no idea why it is triggered ! IRQ are disabled in my startup. It seems this exception comes from EL2, but I cannot find out why and cannot clear it : so it fires continuously...

I know I don't give much details but just as it, is there anything obviously wrong ? And how can I find out the reason of the IRQ ? I'm not sure I can rely on the EC for an IRQ (I checked it in case, but it returns the same value in the IRQ as in the Sync exception).

Thank you for any idea / advice...

Posts: 246
Joined: Sat Oct 14, 2017 9:57 pm

Re: EL switching

Sun Jan 13, 2019 3:25 pm


As I haven't seen your code, I'm not sure, but I suspect you don't need HVC. That would create a new exception context, therefore all ERET does is returning from there to the original EL3. You need to just return (after setting up system registers of course). I've an example code for that here (tbh only tested with a hacked qemu, not on real hardware, but should be fine). The exception you're getting may be caused by inproperly set up vbar or scr register (again, haven't seen your code, just guessing).

Hope this helps,

Return to “Bare metal, Assembly language”