X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86%2Fmm_phys.c;h=ef289acd2466a6243f9ce289de11a6766213e503;hb=01fbfb424865291e00242681662ed9b20c33a524;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..ef289acd 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 @@ -143,6 +144,7 @@ tPAddr MM_AllocPhys(void) indx -= 1024; continue; } + if( gaPageBitmap[indx>>5] == -1 ) { indx -= 32; continue; @@ -164,7 +166,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 +177,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 +209,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 +328,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 +342,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));