};
// === IMPORTS ===
-extern void gKernelBase;
-extern void gKernelEnd;
+extern char gKernelBase[];
+extern char gKernelEnd[];
// === PROTOTYPES ===
void MM_InitPhys_Multiboot(tMBoot_Info *MBoot);
// === 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
+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
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");
size = ent->Size >> 12;
if(base & 63) {
- Uint64 val = -1L << (base & 63);
+ Uint64 val = -1LL << (base & 63);
gaMainBitmap[base / 64] &= ~val;
size -= (base & 63);
base += 64 - (base & 63);
}
memset( &gaMainBitmap[base / 64], 0, size/8 );
if( size & 7 ) {
- Uint64 val = -1L << (size & 7);
+ Uint64 val = -1LL << (size & 7);
val <<= (size/8)&7;
gaMainBitmap[base / 64] &= ~val;
}
size = (size + (base & 63) + 63) >> 6;
base = base >> 6;
if(base & 63) {
- Uint64 val = -1L << (base & 63);
+ Uint64 val = -1LL << (base & 63);
gaSuperBitmap[base / 64] &= ~val;
size -= (base & 63);
base += 64 - (base & 63);
size = firstFreePage >> 12;
memset( &gaMainBitmap[base / 64], -1, size/8 );
if( size & 7 ) {
- Uint64 val = -1L << (size & 7);
+ Uint64 val = -1LL << (size & 7);
val <<= (size/8)&7;
gaMainBitmap[base / 64] |= val;
}
if(gaiStaticAllocPages[i] != 0)
continue;
gaMainBitmap[ gaiStaticAllocPages[i] >> (12+6) ]
- &= ~(1L << ((gaiStaticAllocPages[i]>>12)&63));
+ &= ~(1LL << ((gaiStaticAllocPages[i]>>12)&63));
}
// Fill the super bitmap
for( base = 0; base < (size+63)/64; base ++)
{
if( gaMainBitmap[ base ] + 1 == 0 )
- gaSuperBitmap[ base/64 ] |= 1L << (base&63);
+ gaSuperBitmap[ base/64 ] |= 1LL << (base&63);
}
// Set free page counts
{
int rangeID;
// Skip allocated
- if( gaMainBitmap[ base >> 6 ] & (1L << (base&63)) ) continue;
+ if( gaMainBitmap[ base >> 6 ] & (1LL << (base&63)) ) continue;
// Get range ID
rangeID = MM_int_GetRangeID( base << 12 );
if( Bits <= 0 || Bits >= 64 ) // Speedup for the common case
rangeID = MM_PHYS_MAX;
else
- rangeID = MM_int_GetRangeID( (1L << Bits) - 1 );
+ rangeID = MM_int_GetRangeID( (1LL << Bits) - 1 );
LOG("rangeID = %i", rangeID);
if( gaSuperBitmap[addr >> (6+6)] + 1 == 0 ) {
LOG("nFree = %i = 0 (super) (0x%x)", nFree, addr);
nFree = 0;
- addr += 1L << (6+6);
- addr &= ~0xFFF; // (1L << 6+6) - 1
+ addr += 1LL << (6+6);
+ addr &= ~0xFFF; // (1LL << 6+6) - 1
continue;
}
// Check page block (64 pages)
if( gaMainBitmap[addr >> 6] + 1 == 0) {
LOG("nFree = %i = 0 (main) (0x%x)", nFree, addr);
nFree = 0;
- addr += 1L << (6);
+ addr += 1LL << (6);
addr &= ~0x3F;
continue;
}
// Check individual page
- if( gaMainBitmap[addr >> 6] & (1L << (addr & 63)) ) {
+ if( gaMainBitmap[addr >> 6] & (1LL << (addr & 63)) ) {
LOG("nFree = %i = 0 (page) (0x%x)", nFree, addr);
nFree = 0;
addr ++;
addr -= Num;
for( i = 0; i < Num; i++, addr++ )
{
- gaMainBitmap[addr >> 6] |= 1L << (addr & 63);
+ gaMainBitmap[addr >> 6] |= 1LL << (addr & 63);
rangeID = MM_int_GetRangeID(addr << 12);
giPhysRangeFree[ rangeID ] --;
LOG("%x == %x", addr, giPhysRangeFirst[ rangeID ]);
for( i = 0; i < Num/64; i++ )
{
if( gaMainBitmap[ addr >> 6 ] + 1 == 0 )
- gaSuperBitmap[addr>>12] |= 1L << ((addr >> 6) & 63);
+ gaSuperBitmap[addr>>12] |= 1LL << ((addr >> 6) & 63);
}
RELEASE(&glPhysicalPages);
if( PAddr >> 12 > giMaxPhysPage ) return ;
- if( gaMainBitmap[ page >> 6 ] & (1L << (page&63)) )
+ if( gaMainBitmap[ page >> 6 ] & (1LL << (page&63)) )
{
// Reference again
- gaMultiBitmap[ page >> 6 ] |= 1L << (page&63);
+ gaMultiBitmap[ page >> 6 ] |= 1LL << (page&63);
gaiPageReferences[ page ] ++;
}
else
{
// Allocate
- gaMainBitmap[page >> 6] |= 1L << (page&63);
+ gaMainBitmap[page >> 6] |= 1LL << (page&63);
if( gaMainBitmap[page >> 6 ] + 1 == 0 )
- gaSuperBitmap[page>> 12] |= 1L << ((page >> 6) & 63);
+ gaSuperBitmap[page>> 12] |= 1LL << ((page >> 6) & 63);
}
}
if( PAddr >> 12 > giMaxPhysPage ) return ;
- if( gaMultiBitmap[ page >> 6 ] & (1L << (page&63)) ) {
+ if( gaMultiBitmap[ page >> 6 ] & (1LL << (page&63)) ) {
gaiPageReferences[ page ] --;
if( gaiPageReferences[ page ] == 1 )
- gaMultiBitmap[ page >> 6 ] &= ~(1L << (page&63));
+ gaMultiBitmap[ page >> 6 ] &= ~(1LL << (page&63));
if( gaiPageReferences[ page ] == 0 )
- gaMainBitmap[ page >> 6 ] &= ~(1L << (page&63));
+ gaMainBitmap[ page >> 6 ] &= ~(1LL << (page&63));
}
else
- gaMainBitmap[ page >> 6 ] &= ~(1L << (page&63));
+ gaMainBitmap[ page >> 6 ] &= ~(1LL << (page&63));
// Update the free counts if the page was freed
- if( !(gaMainBitmap[ page >> 6 ] & (1L << (page&63))) )
+ if( !(gaMainBitmap[ page >> 6 ] & (1LL << (page&63))) )
{
int rangeID;
rangeID = MM_int_GetRangeID( PAddr );
// If the bitmap entry is not -1, unset the bit in the super bitmap
if(gaMainBitmap[ page >> 6 ] + 1 != 0 ) {
- gaSuperBitmap[page >> 12] &= ~(1L << ((page >> 6) & 63));
+ gaSuperBitmap[page >> 12] &= ~(1LL << ((page >> 6) & 63));
}
}