X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86_64%2Fmm_phys.c;h=fcc8547369eef65f643c2b2795cbc6a7f15326ed;hb=5255c9f07cb2e0e43cf283e256c964eaa7970c8e;hp=f3cdceb5179c5e8310782b0f3087c5d1aad9b9df;hpb=f0b06cece87e5f73678413cbbc1e3100ddf6e247;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86_64/mm_phys.c b/Kernel/arch/x86_64/mm_phys.c index f3cdceb5..fcc85473 100644 --- a/Kernel/arch/x86_64/mm_phys.c +++ b/Kernel/arch/x86_64/mm_phys.c @@ -24,15 +24,15 @@ extern char gKernelEnd[]; // === PROTOTYPES === void MM_InitPhys_Multiboot(tMBoot_Info *MBoot); -tPAddr MM_AllocPhysRange(int Num, int Bits); -tPAddr MM_AllocPhys(void); -void MM_RefPhys(tPAddr PAddr); -void MM_DerefPhys(tPAddr PAddr); +//tPAddr MM_AllocPhysRange(int Num, int Bits); +//tPAddr MM_AllocPhys(void); +//void MM_RefPhys(tPAddr PAddr); +//void MM_DerefPhys(tPAddr PAddr); int MM_int_GetRangeID( tPAddr Addr ); // === GLOBALS === tMutex glPhysicalPages; -Uint64 *gaSuperBitmap = (void*)MM_PAGE_SUPBMP; // 1 bit = 64 Pages, 16 MiB Per Word +Uint64 *gaSuperBitmap = (void*)MM_PAGE_SUPBMP; // 1 bit = 64 Pages, 16 MiB per Word Uint64 *gaMainBitmap = (void*)MM_PAGE_BITMAP; // 1 bit = 1 Page, 256 KiB per Word Uint64 *gaMultiBitmap = (void*)MM_PAGE_DBLBMP; // Each bit means that the page is being used multiple times Uint32 *gaiPageReferences = (void*)MM_PAGE_COUNTS; // Reference Counts @@ -249,8 +249,8 @@ void MM_InitPhys_Multiboot(tMBoot_Info *MBoot) if(base & 63) { Uint64 val = -1LL << (base & 63); gaSuperBitmap[base / 64] &= ~val; - size -= (base & 63); - base += 64 - (base & 63); +// size -= (base & 63); +// base += 64 - (base & 63); } } @@ -403,9 +403,9 @@ tPAddr MM_AllocPhysRange(int Pages, int MaxBits) { // Oops. ok, let's do an expensive check (scan down the list // until a free range is found) - nFree = 1; - addr = giPhysRangeLast[ rangeID ]; - // TODO +// nFree = 1; +// addr = giPhysRangeLast[ rangeID ]; + // TODO: Expensive Check Mutex_Release(&glPhysicalPages); // TODO: Page out // ATM. Just Warning @@ -481,6 +481,12 @@ void MM_RefPhys(tPAddr PAddr) { // Reference again gaMultiBitmap[ page >> 6 ] |= 1LL << (page&63); + if( !MM_GetPhysAddr( ((tVAddr)&gaiPageReferences[ page ]) & ~0xFFF ) ) { + if( !MM_Allocate( ((tVAddr)&gaiPageReferences[ page ]) & ~0xFFF ) ) { + Log_Error("Arch", "Out of memory when allocating reference count page"); + return ; + } + } gaiPageReferences[ page ] ++; } else