Kernel/arm7 - Fiddling, still having issues with VMM
[tpg/acess2.git] / Kernel / arch / x86_64 / mm_phys.c
index 062b138..fcc8547 100644 (file)
@@ -32,7 +32,7 @@ void  MM_InitPhys_Multiboot(tMBoot_Info *MBoot);
 
 // === 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

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