From: John Hodge Date: Mon, 31 May 2010 02:39:18 +0000 (+0800) Subject: Fixed bug with physical memory allocation, update MM_Allocate to check mapping before... X-Git-Tag: rel0.06~159 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=e71a426f7cc3cd98e43ca8f529ee8e1e13395885;p=tpg%2Facess2.git Fixed bug with physical memory allocation, update MM_Allocate to check mapping before allocating. --- diff --git a/Kernel/arch/x86_64/mm_phys.c b/Kernel/arch/x86_64/mm_phys.c index 1e7c4c2a..77ca92e7 100644 --- a/Kernel/arch/x86_64/mm_phys.c +++ b/Kernel/arch/x86_64/mm_phys.c @@ -3,7 +3,7 @@ * * Physical Memory Manager */ -#define DEBUG 0 +#define DEBUG 1 #include #include #include @@ -314,7 +314,7 @@ void MM_InitPhys_Multiboot(tMBoot_Info *MBoot) */ tPAddr MM_AllocPhysRange(int Num, int Bits) { - tPAddr addr; + tPAddr addr, ret; int rangeID; int nFree = 0, i; @@ -420,12 +420,13 @@ tPAddr MM_AllocPhysRange(int Num, int Bits) // 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); @@ -438,8 +439,8 @@ tPAddr MM_AllocPhysRange(int Num, int Bits) } RELEASE(&glPhysicalPages); - LEAVE('x', addr << 12); - return addr << 12; + LEAVE('x', ret << 12); + return ret << 12; } /** diff --git a/Kernel/arch/x86_64/mm_virt.c b/Kernel/arch/x86_64/mm_virt.c index 8e5ef9c8..b4b26ec1 100644 --- a/Kernel/arch/x86_64/mm_virt.c +++ b/Kernel/arch/x86_64/mm_virt.c @@ -281,19 +281,31 @@ tPAddr MM_Allocate(tVAddr VAddr) { 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; }