*
* Physical Memory Manager
*/
-#define DEBUG 0
+#define DEBUG 1
#include <acess.h>
#include <mboot.h>
#include <mm_virt.h>
*/
tPAddr MM_AllocPhysRange(int Num, int Bits)
{
- tPAddr addr;
+ tPAddr addr, ret;
int rangeID;
int nFree = 0, i;
// Mark pages as allocated
addr -= Num;
- for( i = 0; i < Num; i++ )
+ for( i = 0; i < Num; i++, addr++ )
{
gaMainBitmap[addr >> 6] |= 1 << (addr & 63);
rangeID = MM_int_GetRangeID(addr);
giPhysRangeFree[ rangeID ] --;
}
+ ret = addr; // Save the return address
// Update super bitmap
Num += addr & (64-1);
}
RELEASE(&glPhysicalPages);
- LEAVE('x', addr << 12);
- return addr << 12;
+ LEAVE('x', ret << 12);
+ return ret << 12;
}
/**
{
tPAddr ret;
- Log("MM_Allocate: (VAddr=%x)", VAddr);
- Log("MM_Allocate: MM_AllocPhys()");
+ ENTER("xVAddr", VAddr);
+
+ if( !MM_Map(VAddr, 0) ) // Make sure things are allocated
+ {
+ Warning("MM_Allocate: Unable to map, tables did not initialise");
+ LEAVE('i', 0);
+ return 0;
+ }
+
ret = MM_AllocPhys();
- Log("MM_Allocate: ret = %x", ret);
- if(!ret) return 0;
+ LOG("ret = %x", ret);
+ if(!ret) {
+ LEAVE('i', 0);
+ return 0;
+ }
if( !MM_Map(VAddr, ret) )
{
- Warning("MM_Allocate: Unable to map", ret);
+ Warning("MM_Allocate: Unable to map. Strange, we should have errored earlier");
MM_DerefPhys(ret);
+ LEAVE('i');
return 0;
}
+ LEAVE('x', ret);
return ret;
}