s-matyukevich/raspberry-pi-os

[Lesson02] exercises - Switching EL in qemu

obstriker opened this issue · 2 comments

Did anyone manage to switch Exception levels in qemu?
I know when booting in qemu its on EL2 but even running the example or other solutions (Switching from EL2 -> EL1) didn't print anything.
Previous exercises were printing to screen but this one not printing or not working for some reason.

X-141 commented

bump, I haven't found clear leads. There have been some pointers to possibly modifying QEMU's startup, however I have been looking for a easier solution first before I get into the weeds with that.

Because we are in EL2, we do not have access to sys registers that more privileged exception level (EL3) have access to. From what I've found and read, the instruction "msr scr_el3, x0" causes a "prefetch abort" which will cause the system to hang-up. Commenting the instruction will allow the system to run, but of course we don't configure the Secure Config register.

Found the solution in this StackOverflow post: https://stackoverflow.com/questions/71006360/qemu-system-aarch64-always-entering-exception-level-2-and-hangs-when-switching-t

In short,
If you use qemu with the '-kernel' switch it will start in "Linux loader" mode, meaning it will try to start in EL2 is possible. Instead of using the -kernel kernel8.img flag, use -device loader,file=./kernel8.img, this will start qemu in EL1 mode.