From ce4c0d85bb89d28e0a58b3c264764517b6d163b8 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 9 Sep 2013 20:46:19 -0700 Subject: [PATCH] Support some thread stack attr options. May improve memory management in some games. --- Core/HLE/sceKernelThread.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index c6ab762bcc..0a1f90880f 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -92,9 +92,9 @@ enum { PSP_THREAD_ATTR_KERNEL = 0x00001000, PSP_THREAD_ATTR_VFPU = 0x00004000, PSP_THREAD_ATTR_SCRATCH_SRAM = 0x00008000, // Save/restore scratch as part of context??? - PSP_THREAD_ATTR_NO_FILLSTACK = 0x00100000, // TODO: No filling of 0xff (only with PSP_THREAD_ATTR_LOW_STACK?) + PSP_THREAD_ATTR_NO_FILLSTACK = 0x00100000, // No filling of 0xff (only with PSP_THREAD_ATTR_LOW_STACK?) PSP_THREAD_ATTR_CLEAR_STACK = 0x00200000, // TODO: Clear thread stack when deleted - PSP_THREAD_ATTR_LOW_STACK = 0x00400000, // TODO: Allocate stack from bottom not top. + PSP_THREAD_ATTR_LOW_STACK = 0x00400000, // Allocate stack from bottom not top. PSP_THREAD_ATTR_USER = 0x80000000, PSP_THREAD_ATTR_USBWLAN = 0xa0000000, PSP_THREAD_ATTR_VSH = 0xc0000000, @@ -373,14 +373,15 @@ public: { FreeStack(); + bool fromTop = (nt.attr & PSP_THREAD_ATTR_LOW_STACK) == 0; if (nt.attr & PSP_THREAD_ATTR_KERNEL) { // Allocate stacks for kernel threads (idle) in kernel RAM - currentStack.start = kernelMemory.Alloc(stackSize, true, (std::string("stack/") + nt.name).c_str()); + currentStack.start = kernelMemory.Alloc(stackSize, fromTop, (std::string("stack/") + nt.name).c_str()); } else { - currentStack.start = userMemory.Alloc(stackSize, true, (std::string("stack/") + nt.name).c_str()); + currentStack.start = userMemory.Alloc(stackSize, fromTop, (std::string("stack/") + nt.name).c_str()); } if (currentStack.start == (u32)-1) { @@ -396,7 +397,9 @@ public: bool FillStack() { // Fill the stack. - Memory::Memset(currentStack.start, 0xFF, nt.stackSize); + if ((nt.attr & PSP_THREAD_ATTR_NO_FILLSTACK) == 0) { + Memory::Memset(currentStack.start, 0xFF, nt.stackSize); + } context.r[MIPS_REG_SP] = currentStack.start + nt.stackSize; currentStack.end = context.r[MIPS_REG_SP]; // The k0 section is 256 bytes at the top of the stack.