Now with less fail
authorJohn Hodge <[email protected]>
Sat, 29 May 2010 01:02:52 +0000 (09:02 +0800)
committerJohn Hodge <[email protected]>
Sat, 29 May 2010 01:02:52 +0000 (09:02 +0800)
Kernel/Makefile.BuildNum
Kernel/arch/x86_64/link.ld
Kernel/arch/x86_64/mm_phys.c
Kernel/arch/x86_64/mm_virt.c
Kernel/arch/x86_64/start32.asm

index f16d7bb..74050b6 100644 (file)
@@ -1 +1 @@
-BUILD_NUM = 2267
+BUILD_NUM = 2277
index 9859c4e..a1d9da7 100644 (file)
@@ -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)
index 86f1ac6..47fea40 100644 (file)
@@ -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 ++)
        {
index 1a70d3e..cf00f6e 100644 (file)
@@ -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);
 }
index 7983d2c..4769ee4 100644 (file)
@@ -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

UCC git Repository :: git.ucc.asn.au