I am trying to implement paging in my o/s
First I have simply copy - pasted the code taken from this tutorial and it was working
My idea now was to map virtual memory exactly as physical memory (identity mapping or something like that)
Here are some definitions:
Code: Select all
typedef unsigned int pageEntry;
pageEntry pageDirectory[1024];
pageEntry* pageTable = (void*)0x200000;
Code: Select all
printf("Initialisating page directory... ");
for (i = 0; i < 1024; ++i) {
pageDirectory[i] = (unsigned int)(pageTable + i * 1024 * sizeof(pageEntry)) | 3; // each entry points to another page table
}
printf("ok\r");
printf("Initialisating page tables... ");
for (i = 0; i < 1024 * 1024; ++i) { // we write every page tables at once
pageTable[i] = (i << 12) | 3; // each entry to another page
}
asm("mov %%eax, %%cr3" : : "a"(pageDirectory));
printf("ok\r");
Each page has the flags "read/write" and "present" (set by the "| 3").
But as soon as I enable paging the kernel crashes and BOCHS tells me that it crashed because of "page not present".
As the page fault exception handler is also on a "page not present", the whole computer crashes.