GeekOS Paging
Posted: Sun Dec 31, 2006 10:27 am
Hi all, I'm new to OS development and have downloaded GeekOS in an attempt to learn more, but have gotten stuck implementing paging...
The comments & docs give an idea of what needs doing, and I've written code to do it, but it doesn't work (probably due to me being stupid). Anyway, here is my code:
The code doesn't work, instead the qemu window is cleared to black and seems to freeze (ie, I have to press Ctrl+C in the terminal to close it, as the close button does nothing).
I'm sure the code above is probably completely and obviously wrong, but I don't know why so could someone give some hints? Anyway, off I go to track down the intel manuals.
The comments & docs give an idea of what needs doing, and I've written code to do it, but it doesn't work (probably due to me being stupid). Anyway, here is my code:
Code: Select all
pde_t *page_directory;
pte_t *page_table;
/*
* Initialize virtual memory by building page tables
* for the kernel and physical memory.
*/
void Init_VM(struct Boot_Info *bootInfo)
{
/*
* Hints:
* - Build kernel page directory and page tables
* - Call Enable_Paging() with the kernel page directory
* - Install an interrupt handler for interrupt 14,
* page fault
* - Do not map a page at address 0; this will help trap
* null pointer references
*/
Print("Initializing Paging...\n");
uint_t totalPages = bootInfo->memSizeKB / 4;
Print("Pages Required: %d\n", totalPages);
page_directory = (pde_t *)Alloc_Page();
Print("Page Directory At: %d\n", page_directory);
int reservePages = totalPages * sizeof(pte_t) / 4096;
Print("Page Tables Will Take: %d pages\n", reservePages);
page_table = (pte_t *)Alloc_Page();
int i;
for (i = 0; i < reservePages - 1; i++)
Alloc_Page();
uint_t addr = page_table + (reservePages * 4096);
for (i = 0; i < totalPages; i++)
{
page_table[i].flags = 3;
page_table[i].pageBaseAddr = addr;
addr += 4096;
}
page_directory[0].flags = 3;
page_directory[0].pageTableBaseAddr = page_table;
Install_Interrupt_Handler(14, Page_Fault_Handler);
checkPaging();
Enable_Paging(page_directory);
checkPaging();
}
I'm sure the code above is probably completely and obviously wrong, but I don't know why so could someone give some hints? Anyway, off I go to track down the intel manuals.