* D000 00000000 - D080 00000000 39 512 GiB Per-Process Data
* D080 00000000 - D100 00000000 39 512 GiB Kernel Supplied User Code
* E000 00000000 - E400 00000000 42 4 TiB Physical Page Reference Counts (2**40 = 2**52 bytes)
+ * E400 00000000 - E400 80000000 31 2 GiB Physical Page Super Bitmap (64 pages per bit)
* FD00 00000000 - FD80 00000000 39 512 GiB Local APIC
* FE00 00000000 - FE80 00000000 39 512 GiB Fractal Mapping (PML4 510)
* FE80 00000000 - FF00 00000000 39 512 GiB Temp Fractal Mapping
#define MM_PPD_VFS (KERNEL_BASE|(0xD008##00000000))
#define MM_USER_CODE (KERNEL_BASE|(0xD080##00000000))
#define MM_PAGE_COUNTS (KERNEL_BASE|(0xE000##00000000))
+#define MM_PAGE_SUPBMP (KERNEL_BASE|(0xE400##00000000))
#define MM_LOCALAPIC (KERNEL_BASE|(0xFD00##00000000))
#define MM_FRACTAL_BASE (KERNEL_BASE|(0xFE00##00000000))
tMBoot_MMapEnt *ent;
Uint64 maxAddr = 0;
int numPages;
+ int superPages;
Log("MM_InitPhys_Multiboot: (MBoot=%p)", MBoot);
// Find a contigous section of memory to hold it in
// - Starting from the end of the kernel
// - We also need a region for the super bitmap
+ superPages = ((giMaxPhysPage+64*8-1)/(64*8) + 0xFFF) >> 12;
numPages = (giMaxPhysPage + 7) * sizeof(*gaiPageReferences);
numPages = (numPages + 0xFFF) >> 12;
Log(" MM_InitPhys_Multiboot: numPages = %i", numPages);
// Scan for a nice range
else
{
-
+ int todo = numPages + superPages;
+ tPAddr paddr = 0;
+ tVAddr vaddr = MM_PAGE_COUNTS;
+ // Scan!
+ for(
+ ent = mmapStart;
+ (Uint)ent < (Uint)mmapStart + MBoot->MMapLength;
+ ent = (tMBoot_MMapEnt *)( (Uint)ent + ent->Size )
+ )
+ {
+ int avail;
+
+ // RAM only please
+ if( ent->Type != 1 )
+ continue;
+
+ // Let's not put it below the kernel, shall we?
+ if( ent->Base + ent->Size < (tPAddr)&gKernelEnd )
+ continue;
+
+ // Check if the kernel is in this range
+ if( ent->Base < (tPAddr)&gKernelEnd - KERNEL_BASE && ent->Base + ent->Size > (tPAddr)&gKernelEnd )
+ {
+ avail = (ent->Size-((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;
+ paddr = ent->Base;
+ }
+
+ // Map
+ // - Counts
+ if( todo ) {
+ int i, max;
+ max = todo < avail ? todo : avail;
+ for( i = 0; i < max; i ++ )
+ {
+ MM_Map(vaddr, paddr);
+ todo --;
+ vaddr += 0x1000;
+ paddr += 0x1000;
+ }
+ // Alter the destination address when needed
+ if(todo == superPages)
+ vaddr = MM_PAGE_SUPBMP;
+ }
+ else
+ break;
+ }
}
// Fill the bitmaps
(ent->Size>>12)*sizeof(*gaiPageReferences)
);
}
+
+ // Reference the used pages
+ // - Kernel
+ // - Reference Counts and Bitmap
}
/**