};
// === IMPORTS ===
+extern void gKernelBase;
extern void gKernelEnd;
// === GLOBALS ===
superPages = ((giMaxPhysPage+64*8-1)/(64*8) + 0xFFF) >> 12;
numPages = (giMaxPhysPage + 7) / 8;
numPages = (numPages + 0xFFF) >> 12;
- Log(" MM_InitPhys_Multiboot: numPages = %i, superPages = ",
+ Log(" MM_InitPhys_Multiboot: numPages = %i, superPages = %i",
numPages, superPages);
if(maxAddr == 0)
{
continue;
// Let's not put it below the kernel, shall we?
- if( ent->Base + ent->Size < (tPAddr)&gKernelEnd )
+ if( ent->Base + ent->Size < (tPAddr)&gKernelBase )
continue;
// Check if the kernel is in this range
- if( ent->Base < (tPAddr)&gKernelEnd - KERNEL_BASE && ent->Base + ent->Size > (tPAddr)&gKernelEnd )
+ if( ent->Base <= (tPAddr)&gKernelBase
+ && ent->Base + ent->Size > (tPAddr)&gKernelEnd - KERNEL_BASE )
{
- avail = (ent->Size-((tPAddr)&gKernelEnd-KERNEL_BASE-ent->Base)) >> 12;
+ avail = ent->Length >> 12;
+ avail -= ((tPAddr)&gKernelEnd - KERNEL_BASE - ent->Base) >> 12;
paddr = (tPAddr)&gKernelEnd - KERNEL_BASE;
}
// No? then we can use all of the block
else
{
- avail = ent->Size >> 12;
+ avail = ent->Length >> 12;
paddr = ent->Base;
}
+ Log(" MM_InitPhys_Multiboot: paddr=0x%x, avail=%i", paddr, avail);
+
// Map
max = todo < avail ? todo : avail;
for( i = 0; i < max; i ++ )
todo --;
vaddr += 0x1000;
paddr += 0x1000;
+ // Alter the destination address when needed
+ if(todo == superPages+numPages)
+ vaddr = MM_PAGE_DBLBMP;
+ if(todo == superPages)
+ vaddr = MM_PAGE_SUPBMP;
}
- // Alter the destination address when needed
- if(todo == superPages+numPages)
- vaddr = MM_PAGE_DBLBMP;
- if(todo == superPages)
- vaddr = MM_PAGE_SUPBMP;
// Fast quit if there's nothing left to allocate
if( !todo ) break;
}
}
+ Log(" MM_InitPhys_Multiboot: Cearing multi bitmap");
// Fill the bitmaps
+ memset(gaMultiBitmap, 0, numPages<<12);
// - initialise to one, then clear the avaliable areas
memset(gaMainBitmap, -1, numPages<<12);
- memset(gaMultiBitmap, 0, numPages<<12);
+ Log(" MM_InitPhys_Multiboot: Setting main bitmap");
// - Clear all Type=1 areas
+ Log(" MM_InitPhys_Multiboot: Clearing valid regions");
for(
ent = mmapStart;
(Uint)ent < (Uint)mmapStart + MBoot->MMapLength;
// Reference the used pages
// - Kernel
- base = 0x100000 >> 12;
+ Log(" MM_InitPhys_Multiboot: Setting kernel area");
+ base = (tPAddr)&gKernelBase >> 12;
size = ((tPAddr)&gKernelEnd - KERNEL_BASE - base) >> 12;
memset( &gaMainBitmap[base / 64], -1, size/8 );
if( size & 7 ) {
val <<= (size/8)&7;
gaMainBitmap[base / 64] |= val;
}
- // - Reference Counts and Bitmap
+ // - Bitmaps
+ Log(" MM_InitPhys_Multiboot: Setting bitmaps' memory");
vaddr = MM_PAGE_BITMAP;
for( i = 0; i < numPages; i++, vaddr ++ )
{
}
// Fill the super bitmap
+ Log(" MM_InitPhys_Multiboot: Filling super bitmap");
memset(gaSuperBitmap, 0, superPages<<12);
for( base = 0; base < giMaxPhysPage/64; base ++)
{
{
tPAddr tmp;
+ Log("MM_Map: (VAddr=0x%x, PAddr=0x%x)", VAddr, PAddr);
+
// Check PML4
if( !(PAGEMAPLVL4(VAddr >> 39) & 1) )
{
*/
tPAddr MM_GetPhysAddr(tVAddr Addr)
{
+ Log("MM_GetPhysAddr: (Addr=0x%x)", Addr);
if( !(PAGEMAPLVL4(Addr >> 39) & 1) )
return 0;
+ Log(" MM_GetPhysAddr: PDP Valid");
if( !(PAGEDIRPTR(Addr >> 30) & 1) )
return 0;
+ Log(" MM_GetPhysAddr: PD Valid");
if( !(PAGEDIR(Addr >> 21) & 1) )
return 0;
+ Log(" MM_GetPhysAddr: PT Valid");
if( !(PAGETABLE(Addr >> 12) & 1) )
return 0;
+ Log(" MM_GetPhysAddr: Page Valid");
return (PAGETABLE(Addr >> 12) & ~0xFFF) | (Addr & 0xFFF);
}