X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86_64%2Fmm_phys.c;h=dd8ddf660f0176fec163b765874699b4d48db0f8;hb=9f407c493c33928e0f19b834699d9694036ca42e;hp=3535fbca44a6d1643c54c95409263d970c75ee2f;hpb=e7d03978fb7c0c6ab1250e56e73afba9ffb89923;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86_64/mm_phys.c b/Kernel/arch/x86_64/mm_phys.c index 3535fbca..dd8ddf66 100644 --- a/Kernel/arch/x86_64/mm_phys.c +++ b/Kernel/arch/x86_64/mm_phys.c @@ -4,6 +4,7 @@ * Physical Memory Manager */ #include +#include //#include enum eMMPhys_Ranges @@ -28,8 +29,33 @@ Uint64 giPhysRangeLast[NUM_MM_PHYS_RANGES]; // Last free page in each range Uint64 giMaxPhysPage = 0; // Maximum Physical page // === CODE === -void MM_InitPhys() +void MM_InitPhys(tMBoot_Info *MBoot) { + tMBoot_MMapEnt *mmapStart; + tMBoot_MMapEnt *ent; + Uint64 maxAddr = 0; + + // Scan the physical memory map + mmapStart = (void *)( KERNEL_BASE | MBoot->MMapAddr ); + ent = mmapStart; + while( (Uint)ent < (Uint)mmapStart + MBoot->MMapLength ) + { + // Adjust for the size of the entry + ent->Size += 4; + + // If entry is RAM and is above `maxAddr`, change `maxAddr` + if(ent->Type == 1 && ent->Base + ent->Length > maxAddr) + maxAddr = ent->Base + ent->Length; + // Go to next entry + ent = (tMBoot_MMapEnt *)( (Uint)ent + ent->Size ); + } + + if(maxAddr == 0) { + giMaxPhysPage = (MBoot->HighMem >> 2) + 256; // HighMem is a kByte value + } + else { + giMaxPhysPage = maxAddr >> 12; + } } /** @@ -162,9 +188,12 @@ tPAddr MM_AllocPhys(void) return MM_AllocPhysRange(1, -1); } +/** + * \brief Reference a physical page + */ void MM_RefPhys(tPAddr PAddr) { - if( PAddr > giMaxPhysPage ) return ; + if( PAddr >> 12 > giMaxPhysPage ) return ; gaiPageReferences[ PAddr >> 12 ] ++; gaPrimaryBitmap[PAddr >> 18] |= 1 << ((PAddr>>12) & 63); @@ -172,9 +201,12 @@ void MM_RefPhys(tPAddr PAddr) gaSuperBitmap[PAddr >> 24] |= 1 << ((PAddr >> 18) & 64); } +/** + * \brief Dereference a physical page + */ void MM_DerefPhys(tPAddr PAddr) { - if( PAddr > giMaxPhysPage ) return ; + if( PAddr >> 12 > giMaxPhysPage ) return ; gaiPageReferences[ PAddr >> 12 ] --; if( gaiPageReferences[ PAddr >> 12 ] ) {