Heap/Paging Questions
Re: Heap/Paging Questions
I modified the 'check-for-page-alignment', still no success however. On the SVN repository, the code is up-to-date, but the floppy doesn't always update. Here's an image with the kernel binary on revision 75 (the one I committed a few minutes ago after posting, the file is called 'Floppy (r75).zip'). I will try the magic breakpoints soon.
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
Re: Heap/Paging Questions
I guess it's time to revise the entire thing then. I think I'll best start with revising the paging code, since the heap works fairly fine except for the paging issues, which I think is not the heap causing it. The heap is also self-written, but simply inspired by JamesM.berkus wrote:You may want to throw out JamesM example code, as it is indeed very buggy and intended only as an example, and write your own from scratch, or try pondering at my copy (also based off of JamesM tutorial) here.
Drawing pictures of what is happening with the memory also helps, at least me.
Thanks for all your help, other suggestions are still welcome too
Creature
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
Re: Heap/Paging Questions
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 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:
Which goes above
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.
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: 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. */
}
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);
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
Re: Heap/Paging Questions
I would start by separating the allocators into three very separate levels.
- A physical memory allocator- allocates physical pages or frames as they are also called
- A virtual memory allocator- maps physical addresses to virtual ones accesses physical memory allocator for pages
- Heap- manages malloc type allocations, accesses virtual memory allocator when it runs out of pages