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");