btauro
Posts: 30
Joined: Fri Jan 12, 2018 3:11 am

Switch between exception level 3 to exception level 2

Sat Jan 20, 2018 6:13 am

Hello,

I have been trying an rpi3 Exception level tutorial from https://github.com/bztsrc/raspi3-tutori ... tionlevel/ .


But some how in the the assembly code start.S switching from El level 2 to El level 1 does not work and results in no serial output in Minicom

And wen i print my current El it gives me 00000003.

in specific the following code is causing me an error

Code: Select all

 mov     x2, #0x3c4
    msr     spsr_el2, x2
    adr     x2, 5f
    msr     elr_el2, x2
    eret
Could any one help me with this and also point me to some related links

Thanks,.

bzt
Posts: 98
Joined: Sat Oct 14, 2017 9:57 pm

Re: Switch between exception level 3 to exception level 2

Sat Jan 20, 2018 1:32 pm

Hi,

As I've told you on the github issue page, setting system registers for EL2 do no good when you're in EL3. You have to use EL3 registers.

I've also noted that Raspberry Pi was primarily designed for the Linux kernel, and Linux does not support EL3, only EL2/EL1 so I am sceptical. I wonder if EL3 parameter in config.txt was ever implemented. Or maybe you have a special arm8stub.bin on your card which does not switch to EL2? I'm pretty sure there's something wrong with your configuration as normally Raspberry starts kernel8.img in EL2.

Anyway, I've added code for switching to EL2 from EL3, let me know if it works! (I can't test it, as my hardware runs kernel8.img at EL2).

Cheers,
bzt

btauro
Posts: 30
Joined: Fri Jan 12, 2018 3:11 am

Re: Switch between exception level 3 to exception level 2

Sat Jan 20, 2018 6:19 pm

Hey,
Yes you are right.in my config.txt the lines below cause my Exception Level to go to 00000003

Code: Select all

 kernel_old=1
disable_commandline_tags=1
Thank you so much for helping me.

But I still did not get serial output.

For some reason the change from execution level 2 to level 1 code is not working resulting in no serial output.

so when i remove the below lines I will get a serial output stating that that now my Current EL is: 00000002

Code: Select all

mov     x2, #0x3c4
msr     spsr_el2, x2
adr     x2, 5f
msr     elr_el2, x2
eret
i have also updated the GitHub issue

btauro

btauro
Posts: 30
Joined: Fri Jan 12, 2018 3:11 am

Re: Switch between exception level 3 to exception level 2

Sun Jan 21, 2018 2:10 am

Finally got it working by adding these two lines to switch from el2 to el1

Code: Select all

//set up el1 toAARCH64
mov     x1,#0x80000000
msr     hcr_el2,x1
But i would like to know why in oder to switch from EL2 to EL1 why do we need to set Hypervisor Configuration Register on Raspberry Pi 3.
I have gone through the documentation which tells that this bit is necessary for EL1 to be in AArch64.Is my understanding correct?.
Could any one explain or point me to relevant links explaining this.


Thanks,

bzt
Posts: 98
Joined: Sat Oct 14, 2017 9:57 pm

Re: Switch between exception level 3 to exception level 2

Sun Jan 21, 2018 10:45 am

Hi btauro,

Yes, you are correct, that bit in hcr_el2 tells the CPU that EL1 is running in AArch64 mode.
Screen shot 2018-01-21 at 11.40.46 AM.png
Screen shot 2018-01-21 at 11.40.46 AM.png (30.58 KiB) Viewed 402 times
I've set it in the rest of the tutorials, but somehow forgot in the CurrentEL one, mea culpa. It seems that qemu does not emulate that bit correctly, therefore I haven't noticed. Just for the records it is not the only bit, I've noticed that bit 1 (SWIO) is cleared in qemu but reserved to be one on real hardware.

I've added the code to the tutorial, and modified the comments in the others to make it clear.

Thank you for helping me fixing the tutorials, and make them better!
bzt

Return to “Bare metal”

Who is online

Users browsing this forum: No registered users and 2 guests