Long mode can't page above 4 GB
Posted: Sun Jun 07, 2020 7:50 pm
I'm currently developing a C++ kernel using bochs. I managed to setup Long mode, and have a working GDT and paging. The problem I'm running into is that when I try to add anything to virtual memory above 4GB, entry 4+ in the PDP, it doesn't show up when I look at my pages. I've tried 1GB, 2MB, and 4KB pages. Nothing works.
with the pages defined as
The pages structure is 4KB aligned
And finaly
Code: Select all
this->kb_page = 3;
this->mb_pages = 5;
this->kernel_pages = 4;
// Setup PML4, PDP, PD, and KB page tables
this->pages[0][0] = (uint64_t)this->pages[1] | 3;
this->pages[1][0] = (uint64_t)this->pages[2] | 3;
this->pages[2][0] = (uint64_t)this->pages[3] | 3;
// Setup Kernel map
this->pages[1][3] = (uint64_t)this->pages[this->kernel_pages] | 3;
// Kernel code/data
this->pages[this->kernel_pages][0] = this->kinfo->kernel_addr | 0x83;
this->pages[this->kernel_pages][1] = this->kinfo->kernel_addr + 0x100000 | 0x83;
// Kernel heap
this->pages[this->kernel_pages][2] = 0x200083;
this->pages[this->kernel_pages][3] = 0x400083;
this->pages[this->kernel_pages][4] = 0xa00083;
this->pages[this->kernel_pages][5] = 0xc00083;
// Setup heap
//for (size_t i = 0; i < 64; i++) {
// this->pages[1][4+i] = (uint64_t)this->pages[this->mb_pages+i] | 3;
//}
this->pages[1][4] = (uint64_t)this->pages[this->mb_pages] | 3;
this->pages[1][5] = 0x83;
Code: Select all
typedef uint64_t PageEntry;
typedef PageEntry PageTable[512];
PageTable *pages;
And finaly
Code: Select all
set_paging(this->pages[0]);
global set_paging
set_paging:
mov cr3, rdi
ret