OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 12:04 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: [Solved] Page fault right after enabling paging
PostPosted: Fri Jun 30, 2017 12:07 pm 
Offline
Member
Member
User avatar

Joined: Sun Apr 30, 2017 12:16 pm
Posts: 68
Location: Poland
Hello!
I decided to move my kernel to 64bits. In my bootstrap code, which is the entry point GRUB jumps to, I set up paging and all that, and right after enabling paging I instantly get a crash. The cause of the crash is a triple fault because I haven't set any interrupt handlers and all that. The address in cr2 at the time of the exception is 0x00000000000000af. I cannot figure out why that happens, but it's probably something easy that I didn't notice. Source code of the bootstrap code is https://github.com/0xqookie/KukkiOS/blo ... oot/boot.S

_________________
Working on managarm.


Last edited by qookie on Sun Jul 02, 2017 7:14 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Page fault right after enabling paging
PostPosted: Fri Jun 30, 2017 12:26 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Single-step the code in a debugger. And set up exception handlers.


Top
 Profile  
 
 Post subject: Re: Page fault right after enabling paging
PostPosted: Fri Jun 30, 2017 12:53 pm 
Offline
Member
Member
User avatar

Joined: Tue Mar 06, 2007 11:17 am
Posts: 1225
Probably your very first page is badly set up and it faults when you try to access a byte in 0xAF.

_________________
Live PC 1: Image Live PC 2: Image

YouTube:
http://youtube.com/@AltComp126/streams
http://youtube.com/@proyectos/streams

http://master.dl.sourceforge.net/projec ... 7z?viasf=1


Top
 Profile  
 
 Post subject: Re: Page fault right after enabling paging
PostPosted: Fri Jun 30, 2017 2:05 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

qookie wrote:
I decided to move my kernel to 64bits. In my bootstrap code, which is the entry point GRUB jumps to, I set up paging and all that, and right after enabling paging I instantly get a crash. The cause of the crash is a triple fault because I haven't set any interrupt handlers and all that. The address in cr2 at the time of the exception is 0x00000000000000af. I cannot figure out why that happens, but it's probably something easy that I didn't notice. Source code of the bootstrap code is https://github.com/0xqookie/KukkiOS/blo ... oot/boot.S


There's problems with "address fix-ups" in multiple places because you've forgotten to adjust for the address the code is actually loaded.

For example, if the linker thinks that "init_pml4:" is at 0xffffffff800012000 but it's actually at the (physical) address 0x0x00112000 (because GRUB loaded it at 1 MiB and not at 0), then you do "movl $(init_pml4 - KERNEL_VMA), %eax" and load the value 0x0x00012000 into EAX (and don't load the value 0x0x00112000 into EAX).

You'd probably want to add "#define LOAD_PHYSICAL_ADDRESS 0x00100000" somewhere; then change most of your address fix-ups to be more like "init_pml4 - KERNEL_VMA + LOAD_PHYSICAL_ADDRESS".


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: Page fault right after enabling paging
PostPosted: Sat Jul 01, 2017 11:13 am 
Offline
Member
Member
User avatar

Joined: Sun Apr 30, 2017 12:16 pm
Posts: 68
Location: Poland
@Brendan

The 0xffffffff80000000 address is mapped to the 0x0000000000000000, and the kernel is loaded at 2 MiB, so everything should be at the correct positions after just subtracting the KERNEL_VMA. I am suspicious of the 0xffffffff... part, it may be causing problems.

_________________
Working on managarm.


Top
 Profile  
 
 Post subject: Re: Page fault right after enabling paging
PostPosted: Sun Jul 02, 2017 7:14 am 
Offline
Member
Member
User avatar

Joined: Sun Apr 30, 2017 12:16 pm
Posts: 68
Location: Poland
My god, I just realized my linker script defines KERNEL_VMA as 0xFFFFFFFF80000000 + KERNEL_LMA instead of just 0xFFFFFFFF80000000

_________________
Working on managarm.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 81 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