This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to handle a AArch64.SystemAccessTrap(EL2, 0x18) in baremetal?

I am trying to do follow this tutorial on baremetal code (https://github.com/s-matyukevich/raspberry-pi-os/blob/master/docs/lesson03/rpi-os.md) using QEMU. Specifically, starting at EL1, I'm trying to handle an exception at EL2 and then return to EL1.

To accomplish this, I've set the HCR_EL2.TRVM bit to 1 and then I call asm("msr x0, SCTLR_EL1") in my C code, which should (according to the documentation), cause

AArch64.SystemAccessTrap(EL2, 0x18);

to occur.

However, how would I catch this SystemAccessTrap and proceed to do something with it (in my case, I'd just want to print out the current exception level - which would be 2 while handling the exception - and then return)?

I'm not sure if a SystemAccessTrap is a synchronous exception, and if it is, how to handle it at EL2 (which I assume I'd need to implement given that the asm command will force an EL2 access due to the TRVM bit being set).