From cb944fc8a944abe6921f7477cf73fc4b23e713a5 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 28 May 2010 23:32:38 +0800 Subject: [PATCH] Untested work on physical mm setup --- Kernel/arch/x86_64/include/mm_virt.h | 2 + Kernel/arch/x86_64/mm_phys.c | 59 +++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Kernel/arch/x86_64/include/mm_virt.h b/Kernel/arch/x86_64/include/mm_virt.h index 206dcd93..26753362 100644 --- a/Kernel/arch/x86_64/include/mm_virt.h +++ b/Kernel/arch/x86_64/include/mm_virt.h @@ -29,6 +29,7 @@ * 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 @@ -55,6 +56,7 @@ #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)) diff --git a/Kernel/arch/x86_64/mm_phys.c b/Kernel/arch/x86_64/mm_phys.c index 5a5f5eab..92a38f2a 100644 --- a/Kernel/arch/x86_64/mm_phys.c +++ b/Kernel/arch/x86_64/mm_phys.c @@ -37,6 +37,7 @@ void MM_InitPhys_Multiboot(tMBoot_Info *MBoot) tMBoot_MMapEnt *ent; Uint64 maxAddr = 0; int numPages; + int superPages; Log("MM_InitPhys_Multiboot: (MBoot=%p)", MBoot); @@ -74,6 +75,7 @@ void MM_InitPhys_Multiboot(tMBoot_Info *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); @@ -97,7 +99,58 @@ void MM_InitPhys_Multiboot(tMBoot_Info *MBoot) // 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 @@ -120,6 +173,10 @@ void MM_InitPhys_Multiboot(tMBoot_Info *MBoot) (ent->Size>>12)*sizeof(*gaiPageReferences) ); } + + // Reference the used pages + // - Kernel + // - Reference Counts and Bitmap } /** -- 2.20.1