Sorry for double post, but I seem to have found the problem! In the GetPage function (based on JamesM's), the function AllocAlignGetPhys (or kmalloc_ap) function gets called. However, this redirects to the AllocEx (kmalloc_int) function, which checks if the heap exists (and it does) and then calls Heap::Alloc all over again! The heap will then try to expand AGAIN, resulting in an infinite loop. I solved this by removing the
Code: Select all
else if(make)
{
u32int tmp;
dir->tables[table_idx] = (page_table_t*)kmalloc_ap(sizeof(page_table_t), &tmp);
memset(dir->tables[table_idx], 0, 0x1000);
dir->tablesPhysical[table_idx] = tmp | 0x7; // PRESENT, RW, US.
return &dir->tables[table_idx]->pages[address%1024];
}
Code from the GetPage function and instead, created all the page tables up front, before the placement address is frozen and identity mapped (as it should). This gave me the following code:
Code: Select all
unsigned PhysAddr;
unsigned i;
for(i = 0; i < 1024; ++i)
{
KernelDir->PageTables[i] = ((PageTable *) AllocAlignGetPhys(sizeof(PageTable), &PhysAddr));
memset(KernelDir->PageTables[i], 0, PAGE_SIZE);
KernelDir->TablesPhys[i] = PhysAddr | 0x7; /* The physical address with the 'Present', 'Read-Write' and 'UserMode' set. */
}
Which goes above
Code: Select all
/* Map kernel heap pages, creating them if necessary. */
for(i = HEAP_START; i < HEAP_START + HEAP_START_SIZE; i += PAGE_SIZE)
GetPage(i, true, KernelDir);
And fixed my issue (the paging initialization time is significantly increased, though, but I have little choice). The Heap::Alloc function was going berserk after looping so many times and that was also why the "#0" string kept getting printed.