I am using qemu-system-aarch64
to emulate raspi3
(ARM Cortex A-53) on a x86 host. Here's the command that I use to launch the baremetal image :
$ qemu-system-aarch64 --version
QEMU emulator version 4.2.1 (Debian 1:4.2-3ubuntu6.18)
Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers
$ qemu-system-aarch64 -M raspi3 -kernel kernel8.img -serial null -serial stdio -display none
The code for kernel8.img
is taken from here : https://github.com/s-matyukevich/raspberry-pi-os/tree/master/src/lesson02/src . The following function is used to get the current exception level :
.globl get_el
get_el:
mrs x0, CurrentEL
lsr x0, x0, #2
ret
The following piece of code tries to switch to EL1 on boot, which I had to comment out, otherwise this piece of code hangs indefinitely :
master:
ldr x0, =SCTLR_VALUE_MMU_DISABLED
msr sctlr_el1, x0
ldr x0, =HCR_VALUE
msr hcr_el2, x0
ldr x0, =SCR_VALUE
msr scr_el3, x0
ldr x0, =SPSR_VALUE
msr spsr_el3, x0
adr x0, el1_entry
msr elr_el3, x0
eret
After the above piece of code is commented, my program at least runs, but prints Exception level as 2.
I have following two questions :
- As per the corresponding repo docs, when we are using a hypervisor, EL2 is used by the host OS so that the guest OS uses EL1 or EL0. But why my baremetal guest OS is entering EL2 by default? It should have been EL1 as per my understanding. Also, this older post on SO also had got EL1 on boot. Not sure if something changed or if I am missing anything.
- Why the code to switch to EL1 hangs at line
msr scr_el3, x0
?