Code: Select all
#include <boot64.h>
uint64_t *PML4; // Initialize a global pointer to the Page Map Level 4 table
uint64_t *PDP; // Initialize a global pointer to the first Page Directory Pointer table
uint64_t *PD; // Initialize a global pointer to the first Page Directory
uint64_t *PT; // Initialize a global pointer to the first Page Table
/*
* Sets up the inital page tables
* @param pagebuf - the location of the temporary buffer for the page tables
*/
extern void page_set(uint64_t pagebuf)
{
uint64_t addr = 0x0; // Initialize and set the addr field to 0. This is for the Page Tables
int i, j; // Initialize an iterator variable.
PML4 = (uint64_t*)pagebuf; // Point PML4 to the address of pagebuf
PDP = (uint64_t*)(pagebuf + 0x1000); // Point PDP to the offset of pagebuf for the Page Directory Pointers
PD = (uint64_t*)(pagebuf + 0x2000); // Point PD to the offset of pagebuf for the Page Directories
PT = (uint64_t*)(pagebuf + 0x3000); // Point PT to the offset of pagebuf for the Page Tables
*PML4 = (uint64_t)PDP | 0x33; // Store the address of the PDP in the address pointed to by PML4, with the Accessed, Dirty, Present, and Read/Write bits set.
*PDP = (uint64_t)PD | 0x33; // Store the address of the PD in the address pointed to by PDP, with the Accessed, Dirty, Present, and Read/Write bits set.
for (j = 0; j < 2; j++) // Map the first 4 Megabytes
{
*(PD+j) = (uint64_t)PT | 0x33; // Store the address of the PT in the address pointed to by PD, with the Accessed, Dirty, Present, and Read/Write bits set.
for (i = 0; i < 512; i++) // Time to fill the Page Tables
{
*PT = addr | 0x33; // Stores addr into the Page Table offset indacated by i, setting the Accessed, Dirty, Present, and Read/Write bits.
addr += 0x1000; // Iterate addr by 4 kilobytes.
PT++; // Iterate the page table pointer index.
}
}
return;
}
Can anyone help?