64 bit paging 4 level pages (4kb)
Posted: Fri Jul 06, 2012 12:28 pm
I'm hitting a brick wall setting up paging in 64bit with 4kb pages. Using 2MB pages...I have absolutely no problem. I've oversimplified my code to show what works and what doesn't...hopefully someone can point me in the right direction.
This code sets up 2MB pages and it works fine
This code sets up 4kb pages (4 levels) and IMO should work...but does not, crashes the second I load CR3
Thanks.
This code sets up 2MB pages and it works fine
Code: Select all
u64 *pml, *pdp, *pd, *pt;
pml = (u64 *)physmem_getpage();
pdp = (u64 *)physmem_getpage();
pd = (u64 *)physmem_getpage();
memset((void*)pml, 0x0, PAGE_SIZE);
memset((void*)pdp, 0x0, PAGE_SIZE);
memset((void*)pd, 0x0, PAGE_SIZE);
// +3 = present & write
pml[0] = ((u64)pdp) + 0x3;
pdp[0] = ((u64)pd) + 0x3;
pd[0] = ((u64)pt) + 0x3;
for (int i = 0;i < 512;i++) {
pd[i] = ((u64)i << 21) + 0x83;
}
asm volatile ("movq %0,%%cr3\n\t"
"jmp 1f\n\t"
"1:\n\t"
"movq $2f, %%rax\n\t"
"jmp *%%rax\n\t"
"2:\n\t" ::"r"(pml):"memory","rax");
Code: Select all
u64 *pml, *pdp, *pd, *pt;
pml = (u64 *)physmem_getpage();
pdp = (u64 *)physmem_getpage();
pd = (u64 *)physmem_getpage();
pt = (u64 *)physmem_getpage();
memset((void*)pml, 0x0, PAGE_SIZE);
memset((void*)pdp, 0x0, PAGE_SIZE);
memset((void*)pd, 0x0, PAGE_SIZE);
memset((void*)pt, 0x0, PAGE_SIZE);
// +3 = present & write
pml[0] = ((u64)pdp) + 0x3;
pdp[0] = ((u64)pd) + 0x3;
pd[0] = ((u64)pt) + 0x3;
for (int i = 0;i < 512;i++) {
pt[i] = ((u64)i << 12) + 0x3;
}
asm volatile ("movq %0,%%cr3\n\t"
"jmp 1f\n\t"
"1:\n\t"
"movq $2f, %%rax\n\t"
"jmp *%%rax\n\t"
"2:\n\t" ::"r"(pml):"memory","rax");