X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86%2Fmm_phys.c;h=acca5f5c3afdb183ed4ca8bfb34c3917298317b3;hb=8fbb4dea9912d22c1758d38b843e406a263fdd42;hp=80e92fe66f4042332edae17bb95d5e9c926ea73c;hpb=8bc40333b1401d7616b225945fee53d972c2f418;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86/mm_phys.c b/Kernel/arch/x86/mm_phys.c index 80e92fe6..acca5f5c 100644 --- a/Kernel/arch/x86/mm_phys.c +++ b/Kernel/arch/x86/mm_phys.c @@ -2,6 +2,7 @@ AcessOS Microkernel Version mm_phys.c */ +#define DEBUG 1 #include #include #include @@ -32,7 +33,7 @@ void MM_Install(tMBoot_Info *MBoot) // Initialise globals giPageCount = (MBoot->HighMem >> 2) + 256; // HighMem is a kByte value - Log("giPageCount = %i", giPageCount); + LOG("giPageCount = %i", giPageCount); // Get used page count kernelPages = (Uint)&gKernelEnd - KERNEL_BASE; @@ -65,7 +66,7 @@ void MM_Install(tMBoot_Info *MBoot) } // Allocate References - Log("Reference Pages %i", (giPageCount*4+0xFFF)>>12); + LOG("Reference Pages %i", (giPageCount*4+0xFFF)>>12); for(num = 0; num < (giPageCount*4+0xFFF)>>12; num++) { MM_Allocate( REFERENCE_BASE + (num<<12) ); @@ -76,16 +77,12 @@ void MM_Install(tMBoot_Info *MBoot) memsetd(gaPageReferences, 1, kernelPages); for( num = kernelPages; num < giPageCount; num++ ) { - //if(gaPageBitmap[ num2 / 32 ] == 0) { - // memsetd(&gaPageReferences[num2], 0, 31-(num2&31)); - // num2 = (num2 + 32) & ~31; - //} else - gaPageReferences[num] = (gaPageBitmap[ num / 32 ] >> (num&31)) & 1; + gaPageReferences[num] = (gaPageBitmap[ num / 32 ] >> (num&31)) & 1; } } /** - * \fn Uint32 MM_AllocPhys() + * \fn tPAddr MM_AllocPhys() * \brief Allocates a physical page */ tPAddr MM_AllocPhys() @@ -100,6 +97,7 @@ tPAddr MM_AllocPhys() for(a=0;gaSuperBitmap[a]==-1&&a>= 12; @@ -177,6 +176,7 @@ void MM_DerefPhys(Uint32 Addr) // Mark as free in bitmaps if( gaPageReferences[ Addr ] == 0 ) { + LOG("Freed 0x%x by %p\n", Addr<<12, __builtin_return_address(0)); gaPageBitmap[ Addr / 32 ] &= ~(1 << (Addr&31)); if(gaPageReferences[ Addr ] == 0) gaSuperBitmap[ Addr >> 10 ] &= ~(1 << ((Addr >> 5)&31)); @@ -185,3 +185,18 @@ void MM_DerefPhys(Uint32 Addr) // Release spinlock RELEASE( &giPhysAlloc ); } + +/** + * \fn int MM_GetRefCount(tPAddr Addr) + */ +int MM_GetRefCount(tPAddr Addr) +{ + // Get page number + Addr >>= 12; + + // We don't care about non-ram pages + if(Addr >= giPageCount) return -1; + + // Check if it is freed + return gaPageReferences[ Addr ]; +}