From: John Hodge Date: Mon, 31 May 2010 15:12:33 +0000 (+0800) Subject: Speedups to physical memory allocation, fixed a stupid error in the X-Git-Tag: rel0.06~153 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=e6d539f85a06fb3d25b985d1a27d8648d23736f0;p=tpg%2Facess2.git Speedups to physical memory allocation, fixed a stupid error in the stack moving code --- diff --git a/Kernel/arch/x86_64/mm_phys.c b/Kernel/arch/x86_64/mm_phys.c index 68701b28..5d9f2ef3 100644 --- a/Kernel/arch/x86_64/mm_phys.c +++ b/Kernel/arch/x86_64/mm_phys.c @@ -372,11 +372,11 @@ tPAddr MM_AllocPhysRange(int Num, int Bits) continue; } // Check page block (64 pages) - if( gaSuperBitmap[addr >> (6+6)] & (1 << (addr>>6)&63)) { + if( gaMainBitmap[addr >> 6] == -1) { LOG("nFree = %i = 0 (main) (0x%x)", nFree, addr); nFree = 0; - addr += 1 << (12+6); - addr &= ~( (1 << (12+6)) - 1 ); + addr += 1 << (6); + addr &= ~( (1 << (6)) - 1 ); continue; } // Check individual page @@ -425,7 +425,7 @@ tPAddr MM_AllocPhysRange(int Num, int Bits) gaMainBitmap[addr >> 6] |= 1 << (addr & 63); rangeID = MM_int_GetRangeID(addr << 12); giPhysRangeFree[ rangeID ] --; - if(addr << 12 == giPhysRangeFirst[ rangeID ]) + if(addr == giPhysRangeFirst[ rangeID ]) giPhysRangeFirst[ rangeID ] += 1; } ret = addr; // Save the return address diff --git a/Kernel/arch/x86_64/proc.c b/Kernel/arch/x86_64/proc.c index a1d5c86a..1c81991d 100644 --- a/Kernel/arch/x86_64/proc.c +++ b/Kernel/arch/x86_64/proc.c @@ -381,11 +381,11 @@ void Proc_ChangeStack() curBase = (Uint)&gInitialKernelStack; - LOG("curBase = 0x%x, newBase = 0x%x", curBase, newBase); + Log("curBase = 0x%x, newBase = 0x%x", curBase, newBase); // Get ESP as a used size rsp = curBase - rsp; - LOG("memcpy( %p, %p, 0x%x )", (void*)(newBase - rsp), (void*)(curBase - rsp), rsp ); + Log("memcpy( %p, %p, 0x%x )", (void*)(newBase - rsp), (void*)(curBase - rsp), rsp ); // Copy used stack memcpy( (void*)(newBase - rsp), (void*)(curBase - rsp), rsp ); // Get ESP as an offset in the new stack @@ -393,16 +393,17 @@ void Proc_ChangeStack() // Adjust EBP rbp = newBase - (curBase - rbp); + Log("Update stack"); // Repair EBPs & Stack Addresses // Catches arguments also, but may trash stack-address-like values - for(tmp_rbp = rsp; tmp_rbp < newBase; tmp_rbp += 4) + for(tmp_rbp = rsp; tmp_rbp < newBase; tmp_rbp += sizeof(Uint)) { if(old_rsp < *(Uint*)tmp_rbp && *(Uint*)tmp_rbp < curBase) *(Uint*)tmp_rbp += newBase - curBase; } + Log("Applying Changes"); Proc_GetCurThread()->KernelStack = newBase; - __asm__ __volatile__ ("mov %0, %%rsp"::"r"(rsp)); __asm__ __volatile__ ("mov %0, %%rbp"::"r"(rbp)); }