Code: Select all
/* ... */
/* Make a page directory. */
KernelDir = (PageDirectory *) AllocAlign(sizeof(PageDirectory));
memset(KernelDir, 0, sizeof(PageDirectory));
KernelDir->Address = (unsigned) KernelDir->TablesPhys;
/* Allocate 1024 page-tables for the page directory (do this now so the addresses can be identity mapped and frozen). */
size_t PhysAddr;
size_t i;
for(i = 0; i < 1024; )
{
KernelDir->PageTables[i] = reinterpret_cast<PageTable *>(AllocAlignGetPhys(sizeof(PageTable), &PhysAddr));
memset(KernelDir->PageTables[i], 0, sizeof(PageTable));
KernelDir->TablesPhys[i++] = PhysAddr | 0x7; /* The physical address with the 'Present', 'Read-Write' and 'UserMode' set. */
}
i = 0;
/* Identity map. */
while(i < CurAddress + PAGE_SIZE)
{
AllocateFrame(PAGE_GET(i, KernelDir), false, false);
i += PAGE_SIZE;
}
/* Allocate frames for the heap's pages (now that everything is identity mapped). */
for(i = HEAP_START; i < HEAP_START + HEAP_START_SIZE; i += PAGE_SIZE)
AllocateFrame(PAGE_GET(i, KernelDir), false, false);
/* Switch page directories and enable paging. */
SwitchPageDir(KernelDir);
The entire source file is located here.
Thanks for your help,
Creature