Page 1 of 1
how to setup pages, before jump to 2GB kernel space?
Posted: Sat Apr 11, 2009 1:37 am
by blackoil
Hi,
I want to make the kernel runs at 2GB virtual space, 0x80000000
for PD[0,1023], I initialize PD[512] entry only, that is the beginning of 0x80000000 vaddress
then I got instruction unavaliable in BOCHS, right after
Code: Select all
mov eax,cr0
or eax,0x80000000
mov cr0,eax
so i think mapping the first 1MB physical address was needed, before jump to 0x80000000
How do you guys implement this?
Re: how to setup pages, before jump to 2GB kernel space?
Posted: Sat Apr 11, 2009 1:52 am
by xyzzy
Yes, you need to map the memory where your kernel is currently running before you jump to its virtual address. To make your life easier you can use the large (4MB) page support on x86 CPUs. Using this, you can identity map the first 4MB by setting the first page directory to point to 0x0 and setting the large page bit (bit 7) on it - make sure you enable PSE in CR4 first. Have a look at
http://wiki.osdev.org/Higher_Half_bare_bones
Re: how to setup pages, before jump to 2GB kernel space?
Posted: Sat Apr 11, 2009 2:47 am
by blackoil
thanks alex!
when in 2gb vaddress, clear PD[0,511], mark it for user space. done.
Re: how to setup pages, before jump to 2GB kernel space?
Posted: Sat Apr 11, 2009 5:00 am
by egos
blackoil wrote:so i think mapping the first 1MB physical address was needed, before jump to 0x80000000
You are right if your kernel image and initial stack are placed in conventional memory. I had made identity mapping for first 640 kb. When kernel is starting, it allocates and maps global memory region at KERNEL_BASE virtual address (usually 0x80000000 or 0xC0000000) and then copies the SYMBOLS section into this region.