OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 3:31 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: QEMU OVMF kernel stuck in reboot loop. Works on Legacy Bios
PostPosted: Fri May 07, 2021 1:45 pm 
Offline

Joined: Sun Apr 04, 2021 7:51 pm
Posts: 4
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.


Top
 Profile  
 
 Post subject: Re: QEMU OVMF kernel stuck in reboot loop. Works on Legacy B
PostPosted: Fri May 07, 2021 9:51 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
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.


Top
 Profile  
 
 Post subject: Re: QEMU OVMF kernel stuck in reboot loop. Works on Legacy B
PostPosted: Sun May 09, 2021 11:18 am 
Offline

Joined: Sun Apr 04, 2021 7:51 pm
Posts: 4
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot] and 57 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group