Page 1 of 1

Pages at 0x0 with higher half kernel

Posted: Thu Mar 19, 2009 3:10 pm
by Andy1988
Hello everyone,
I just got the higher half kernel with the GDT trick from the Wiki to work.

I understand the process of setting up the different GDTs, setting up paging etc. but one thing confuses me:
The first physical 4 MB are mapped to 0xC0000000 where all my code refers to due to the linker script. Allright.

But why are these 4MB also mapped to 0x0?
And do I need these pages or can I safely remove them from the page directory?

I want to use the full space from 0x0 to 0xC0000000 for my later userspace programs. Or is this a bad idea?

Thanks in advance,
Andreas

Re: Pages at 0x0 with higher half kernel

Posted: Thu Mar 19, 2009 5:29 pm
by Combuster
The GDT trick is a temporary cheat to make your code appear in the upper half - i.e. via segmentation 0x40000000 is added to each address. That means the first MB appears at 0xC0000000 (+ 0x40000000 = 0), and nowhere else.

The idea is that you set up paging later on and then disable the GDT trick. For paging you'll need two mappings initially, one for the original linear address (0x0) and one for the new linear address (0xc0000000) (0xc.. and 0x8.. with the GDT trick enabled). Once you got the paging prepared, you can disable segmentation and jump to 0xc0000000 with the zero offset.

After that you can remove the first mapping at 0x0 since you're not using it anymore - and it appears that you still have to do this step.

Re: Pages at 0x0 with higher half kernel

Posted: Thu Mar 19, 2009 5:42 pm
by Andy1988
Jupp. That's what I wanted to know.

So the lower pages at 0x0 are only for the time after enabling paging and before setting my real GDT with base 0x0 to get to the right addresses via this address overflow?

I'll throw them away now... I only need to copy my multiboot information structure from GRUB to another location because now my pointer to it gets invalid.
Also I need to write my text to 0xC00B8000 instead to 0xB8000. Then everything should work, right? :)

Thank you!

edit: http://wiki.osdev.org/Higher_Half_With_GDT
That's the howto I used.

BTW: The wiki is awesome! Everything is explained very good.