X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86%2Fmm_phys.c;h=faef2b3e5c69699ed96bf2a18af0ab4da2416a56;hb=e5e272c426a28f2f9e69ed2232469575c7409af1;hp=cb4f9e0b015817d2d9eb3fece802bbd53f52220b;hpb=7d881c2e5fef91a6570e46ef69a5d4a5cf0e8b4d;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86/mm_phys.c b/Kernel/arch/x86/mm_phys.c index cb4f9e0b..faef2b3e 100644 --- a/Kernel/arch/x86/mm_phys.c +++ b/Kernel/arch/x86/mm_phys.c @@ -7,7 +7,8 @@ #include #include -#define USE_STACK 1 +//#define USE_STACK 1 +#define TRACE_ALLOCS 0 // Print trace messages on AllocPhys/DerefPhys #define REFERENCE_BASE 0xE0400000 @@ -106,7 +107,11 @@ void MM_Install(tMBoot_Info *MBoot) //LOG("Reference Pages %i", (giPageCount*4+0xFFF)>>12); for(num = 0; num < (giPageCount*4+0xFFF)>>12; num++) { - MM_Allocate( REFERENCE_BASE + (num<<12) ); + if( !MM_Allocate( REFERENCE_BASE + (num<<12) ) ) + { + Panic("Oh, ****, no space for the reference pages, that's bad"); + for(;;); + } } //LOG("Filling"); @@ -143,6 +148,7 @@ tPAddr MM_AllocPhys(void) indx -= 1024; continue; } + if( gaPageBitmap[indx>>5] == -1 ) { indx -= 32; continue; @@ -164,7 +170,8 @@ tPAddr MM_AllocPhys(void) for( ; gaSuperBitmap[a] == -1 && a >= 0; a-- ); if(a < 0) { Mutex_Release( &glPhysAlloc ); - Warning("MM_AllocPhys - OUT OF MEMORY (Called by %p)", __builtin_return_address(0)); + Warning("MM_AllocPhys - OUT OF MEMORY (Called by %p) - %lli/%lli used", + __builtin_return_address(0), giPhysAlloc, giPageCount); LEAVE('i', 0); return 0; } @@ -174,11 +181,25 @@ tPAddr MM_AllocPhys(void) indx = (a << 10) | (b << 5) | c; #endif + if( indx < 0 ) { + Mutex_Release( &glPhysAlloc ); + Warning("MM_AllocPhys - OUT OF MEMORY (Called by %p) - %lli/%lli used (indx = %x)", + __builtin_return_address(0), giPhysAlloc, giPageCount, indx); + Log_Debug("PMem", "giLastPossibleFree = %lli", giLastPossibleFree); + LEAVE('i', 0); + return 0; + } + + if( indx > 0xFFFFF ) { + Panic("The fuck? Too many pages! (indx = 0x%x)", indx); + } + // Mark page used if(gaPageReferences) gaPageReferences[ indx ] = 1; gaPageBitmap[ indx>>5 ] |= 1 << (indx&31); + giPhysAlloc ++; // Get address ret = indx << 12; @@ -192,7 +213,9 @@ tPAddr MM_AllocPhys(void) Mutex_Release( &glPhysAlloc ); LEAVE('X', ret); - //Log("MM_AllocPhys: RETURN 0x%x", ret); + #if TRACE_ALLOCS + Log_Debug("PMem", "MM_AllocPhys: RETURN 0x%llx (%i free)", ret, giPageCount-giPhysAlloc); + #endif return ret; } @@ -309,6 +332,7 @@ tPAddr MM_AllocPhysRange(int Pages, int MaxBits) gaPageReferences[idx*32+sidx] = 1; gaPageBitmap[ idx ] |= 1 << sidx; sidx ++; + giPhysAlloc ++; if(sidx == 32) { sidx = 0; idx ++; } } @@ -322,6 +346,10 @@ tPAddr MM_AllocPhysRange(int Pages, int MaxBits) Mutex_Release( &glPhysAlloc ); LEAVE('X', ret); + #if TRACE_ALLOCS + Log_Debug("PMem", "MM_AllocPhysRange: RETURN 0x%llx-0x%llx (%i free)", + ret, ret + (1<> 10 ] &= ~(1 << ((PAddr >> 5)&31));