OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Jul 22, 2018 12:48 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Kernel jumps back to GRUB after setting up higher half
PostPosted: Fri May 04, 2018 9:28 am 
Offline

Joined: Fri Apr 20, 2018 9:15 am
Posts: 7
I just set my kernel up to operate in the higher half of memory and knew that I'd have to change my identity page mapping from 0 -> size of kernel, to 3GiB -> 4 GiB. However, my kernel now jumps back into GRUB code immediately after setting the kernel paging directory in the cr3 register, runs my kernel again, jumps back to GRUB after setting the paging directory again and the loop continues forever. Does anyone have any idea what I could be doing wrong? Something tells me that I may have the identity mapping physical and virtual addresses mixed up/wrong, but I've struggled to find the problem by myself. The last debug log statement I see is "Setting paging directory".

I know it's jumping back into GRUB code because the screen says "SeaBIOS <some version>" other details and "Welcome to grub!"

* Kernel source
* Kernel main C file
* Paging C file


Top
 Profile  
 
 Post subject: Re: Kernel jumps back to GRUB after setting up higher half
PostPosted: Fri May 04, 2018 10:12 am 
Offline

Joined: Sun Jun 25, 2017 10:00 am
Posts: 2
Its triple faulting.


Top
 Profile  
 
 Post subject: Re: Kernel jumps back to GRUB after setting up higher half
PostPosted: Fri May 04, 2018 10:15 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1280
tabz wrote:
Something tells me that I may have the identity mapping physical and virtual addresses mixed up/wrong,

"Identity mapping" is where you set up the virtual address to be the same as the physical address. I haven't looked too hard at your code, but I didn't see any identity mapping. I only saw the part that maps the kernel to ~3GB.

tabz wrote:
I know it's jumping back into GRUB code because the screen says "SeaBIOS <some version>"

SeaBIOS is not GRUB, SeaBIOS is the BIOS. If you're seeing the BIOS, the computer probably rebooted. If the computer rebooted, you probably caused a triple fault.


Top
 Profile  
 
 Post subject: Re: Kernel jumps back to GRUB after setting up higher half
PostPosted: Sat May 05, 2018 11:05 am 
Offline

Joined: Fri Apr 20, 2018 9:15 am
Posts: 7
Thanks for the feedback, would you have any idea why it might be triple faulting? I'm guessing it might be for a whole host of reasons.

I've realised I shouldn't be identity mapping as obviously the kernel is loaded in at 1 MiB in physical memory with 0 as the physical addressing base, but uses 3 GiB as the virtual addressing base, so identity mapping would obviously be a bad idea. I've updated my code accordingly.


Top
 Profile  
 
 Post subject: Re: Kernel jumps back to GRUB after setting up higher half
PostPosted: Sat May 05, 2018 2:21 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1280
tabz wrote:
Thanks for the feedback, would you have any idea why it might be triple faulting? I'm guessing it might be for a whole host of reasons.

Some virtual machines will give you some information about the cause of the triple fault. If the one you're using doesn't do that, try running your OS in Bochs and see what it says.

You'll get even more insight by using a debugger.

tabz wrote:
I've realised I shouldn't be identity mapping as obviously the kernel is loaded in at 1 MiB in physical memory with 0 as the physical addressing base, but uses 3 GiB as the virtual addressing base, so identity mapping would obviously be a bad idea.

Identity mapping is a requirement of the x86 architecture. You can't enable paging without identity mapping at least one page (the page containing the code that enables paging). You can remove the identity mapping once paging is enabled.

That brings up another issue: you're trying to enable paging from within C code, but there's no way to change the base address mid-function. That's why examples like this one set up the initial page tables and enable paging before doing anything else. (That example also sets up the initial page table in assembly. There's no reason you couldn't do it in C, but it would make linking more complicated.)

And speaking of enabling paging... are you setting the right bit in CR0?


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 9 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