+ 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;
+ }