Unborking some threading code
[tpg/acess2.git] / Kernel / arch / x86_64 / mm_phys.c
index e5c28c2..c67b905 100644 (file)
@@ -31,10 +31,10 @@ void        MM_DerefPhys(tPAddr PAddr);
  int   MM_int_GetRangeID( tPAddr Addr );
 
 // === GLOBALS ===
-tSpinlock      glPhysicalPages;
-Uint64 *gaSuperBitmap; // 1 bit = 64 Pages, 16 MiB Per Word
-Uint64 *gaMainBitmap;  // 1 bit = 1 Page, 256 KiB per Word
-Uint64 *gaMultiBitmap; // Each bit means that the page is being used multiple times
+tMutex glPhysicalPages;
+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
 tPAddr giFirstFreePage;        // First possibly free page
 Uint64 giPhysRangeFree[NUM_MM_PHYS_RANGES];    // Number of free pages in each range
@@ -208,9 +208,10 @@ void MM_InitPhys_Multiboot(tMBoot_Info *MBoot)
        
        LOG("Clearing multi bitmap");
        // Fill the bitmaps
-       memset(gaMultiBitmap, 0, numPages<<12);
+       memset(gaMultiBitmap, 0, (numPages<<12)/8);
        // - initialise to one, then clear the avaliable areas
-       memset(gaMainBitmap, -1, numPages<<12);
+       memset(gaMainBitmap, -1, (numPages<<12)/8);
+       memset(gaSuperBitmap, -1, (numPages<<12)/(8*64));
        LOG("Setting main bitmap");
        // - Clear all Type=1 areas
        LOG("Clearing valid regions");
@@ -327,7 +328,7 @@ tPAddr MM_AllocPhysRange(int Num, int Bits)
        
        LOG("rangeID = %i", rangeID);
        
-       LOCK(&glPhysicalPages);
+       Mutex_Acquire(&glPhysicalPages);
        
        // Check if the range actually has any free pages
        while(giPhysRangeFree[rangeID] == 0 && rangeID)
@@ -337,7 +338,7 @@ tPAddr MM_AllocPhysRange(int Num, int Bits)
        
        // What the? Oh, man. No free pages
        if(giPhysRangeFree[rangeID] == 0) {
-               RELEASE(&glPhysicalPages);
+               Mutex_Release(&glPhysicalPages);
                // TODO: Page out
                // ATM. Just Warning
                Warning(" MM_AllocPhysRange: Out of free pages");
@@ -405,7 +406,7 @@ tPAddr MM_AllocPhysRange(int Num, int Bits)
                nFree = 1;
                addr = giPhysRangeLast[ rangeID ];
                // TODO
-               RELEASE(&glPhysicalPages);
+               Mutex_Release(&glPhysicalPages);
                // TODO: Page out
                // ATM. Just Warning
                Warning(" MM_AllocPhysRange: Out of memory (unable to fulfil request for %i pages)", Num);
@@ -441,7 +442,7 @@ tPAddr MM_AllocPhysRange(int Num, int Bits)
                        gaSuperBitmap[addr>>12] |= 1LL << ((addr >> 6) & 63);
        }
        
-       RELEASE(&glPhysicalPages);
+       Mutex_Release(&glPhysicalPages);
        LEAVE('x', ret << 12);
        return ret << 12;
 }

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