QEMU OVMF kernel stuck in reboot loop. Works on Legacy Bios

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
wireboy5
Posts: 4
Joined: Sun Apr 04, 2021 7:51 pm

QEMU OVMF kernel stuck in reboot loop. Works on Legacy Bios

Post by wireboy5 »

I have a very simple higher half long mode kernel.

When I load this kernel using grub on a UEFI BIOS (QEMU OVMF) right after I press enter on the grub boot screen, it hangs for ~5 seconds, and then restarts at the TianoCore logo.

When I load it using a Legacy BIOS (QEMU default bios) it runs as expected (hangs forever)

I have determined (using jmp $) that this problem lies between the call instruction that calls my kernel main function, and the body of my kernel main function. I have absolutely no idea what this problem could be, and have been trying to figure it out for a few days now. Here is the github URL: https://github.com/wireboy5/64bitOS
Here are the versions of the software I am using:

grub-mkrescue 2.04-1ubuntu26.7
x86_64-elf-g++ (GCC) 10.2.0
GNU ld (GNU Binutils) 2.35
qemu x86_64 4.2.1


Any help or pointers on how I should solve this problem would be greatly appreciated.

Thank you for your consideration.
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: QEMU OVMF kernel stuck in reboot loop. Works on Legacy B

Post by Octocontrabass »

wireboy5 wrote:I have a very simple higher half long mode kernel.
Higher half? This address is nowhere near the higher half. Addresses have 64 bits in long mode.

While you could choose any canonical address in the higher half, I recommend something at or above 0xFFFFFFFF80000000 so you can compile with the -mcmodel=kernel option. (And speaking of options, I don't see -mno-red-zone anywhere...)
wireboy5 wrote:I have determined (using jmp $) that this problem lies between the call instruction that calls my kernel main function, and the body of my kernel main function. I have absolutely no idea what this problem could be, and have been trying to figure it out for a few days now.
Did you try stepping through each instruction in your debugger to find the one that faults?

Try adding "-d int" and "-no-reboot" to your QEMU command line. These will tell QEMU to dump the registers on each interrupt, including exceptions. If the reboot is caused by a triple fault - which it probably is - then you might be able to see what the CPU was doing. You may also need to disable hardware acceleration for this to work.
wireboy5
Posts: 4
Joined: Sun Apr 04, 2021 7:51 pm

Re: QEMU OVMF kernel stuck in reboot loop. Works on Legacy B

Post by wireboy5 »

Thank you! It ended up as a paging problem where the read/write bits on the page tables were not being set. I probably would have never found this issue without the tips you provided. I looked up the options you suggested, and see how they can be useful (Using them now!).

Thank you for your help! :D
Post Reply