From: John Hodge Date: Sat, 29 May 2010 01:02:52 +0000 (+0800) Subject: Now with less fail X-Git-Tag: rel0.06~168 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=a2360ffa72000ad502d20dca3997dd970f39a8fd;p=tpg%2Facess2.git Now with less fail --- diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index f16d7bb1..74050b66 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 2267 +BUILD_NUM = 2277 diff --git a/Kernel/arch/x86_64/link.ld b/Kernel/arch/x86_64/link.ld index 9859c4ec..a1d9da70 100644 --- a/Kernel/arch/x86_64/link.ld +++ b/Kernel/arch/x86_64/link.ld @@ -15,7 +15,9 @@ OUTPUT_ARCH(i386:x86-64) ENTRY (start) SECTIONS { - . = 0x100000 + SIZEOF_HEADERS; + . = 0x100000; + gKernelBase = .; + . += SIZEOF_HEADERS; __load_addr = .; .multiboot : AT(ADDR(.multiboot)) { *(.multiboot) diff --git a/Kernel/arch/x86_64/mm_phys.c b/Kernel/arch/x86_64/mm_phys.c index 86f1ac6b..47fea403 100644 --- a/Kernel/arch/x86_64/mm_phys.c +++ b/Kernel/arch/x86_64/mm_phys.c @@ -18,6 +18,7 @@ enum eMMPhys_Ranges }; // === IMPORTS === +extern void gKernelBase; extern void gKernelEnd; // === GLOBALS === @@ -86,7 +87,7 @@ void MM_InitPhys_Multiboot(tMBoot_Info *MBoot) 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) { @@ -139,22 +140,26 @@ void MM_InitPhys_Multiboot(tMBoot_Info *MBoot) 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 ++ ) @@ -163,23 +168,26 @@ void MM_InitPhys_Multiboot(tMBoot_Info *MBoot) 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; @@ -221,7 +229,8 @@ void MM_InitPhys_Multiboot(tMBoot_Info *MBoot) // 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 ) { @@ -229,7 +238,8 @@ void MM_InitPhys_Multiboot(tMBoot_Info *MBoot) 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 ++ ) { @@ -250,6 +260,7 @@ void MM_InitPhys_Multiboot(tMBoot_Info *MBoot) } // Fill the super bitmap + Log(" MM_InitPhys_Multiboot: Filling super bitmap"); memset(gaSuperBitmap, 0, superPages<<12); for( base = 0; base < giMaxPhysPage/64; base ++) { diff --git a/Kernel/arch/x86_64/mm_virt.c b/Kernel/arch/x86_64/mm_virt.c index 1a70d3e7..cf00f6e2 100644 --- a/Kernel/arch/x86_64/mm_virt.c +++ b/Kernel/arch/x86_64/mm_virt.c @@ -47,6 +47,8 @@ int MM_Map(tVAddr VAddr, tPAddr PAddr) { tPAddr tmp; + Log("MM_Map: (VAddr=0x%x, PAddr=0x%x)", VAddr, PAddr); + // Check PML4 if( !(PAGEMAPLVL4(VAddr >> 39) & 1) ) { @@ -138,14 +140,19 @@ void MM_Deallocate(tVAddr VAddr) */ 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); } diff --git a/Kernel/arch/x86_64/start32.asm b/Kernel/arch/x86_64/start32.asm index 7983d2c0..4769ee49 100644 --- a/Kernel/arch/x86_64/start32.asm +++ b/Kernel/arch/x86_64/start32.asm @@ -112,9 +112,11 @@ gInitialPML4: ; Covers 256 TiB (Full 48-bit Virtual Address Space) dd gInitialPDP - KERNEL_BASE + 3, 0 ; Identity Map Low 4Mb times 256-1 dq 0 dd gInitialPDP - KERNEL_BASE + 3, 0 ; Map Low 4Mb to kernel base - times 256-1-2 dq 0 + times 256-1-4 dq 0 dd gInitialPML4 - KERNEL_BASE + 3, 0 ; Fractal Mapping dq 0 + dq 0 + dq 0 gInitialPDP: ; Covers 512 GiB dd gInitialPD - KERNEL_BASE + 3, 0