From 000876858d52d7e4fa8e21bc4407d43d548eff30 Mon Sep 17 00:00:00 2001 From: Subv Date: Sun, 10 May 2015 18:35:37 -0500 Subject: Core/Memory: Give every emulated thread it's own TLS area. The TLS area for thread T with id Ti is located at TLS_AREA_VADDR + (Ti - 1) * 0x200. This allows some games like Mario Kart 7 to continue further. --- src/core/arm/arm_interface.h | 3 ++- src/core/arm/dyncom/arm_dyncom.cpp | 5 ++++- src/core/arm/dyncom/arm_dyncom.h | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/core/arm') diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index 85ed2c698..976c339e8 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h @@ -99,8 +99,9 @@ public: * @param stack_top Pointer to the top of the stack * @param entry_point Entry point for execution * @param arg User argument for thread + * @param tls_address Address of the Thread Local Storage for the thread */ - virtual void ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg) = 0; + virtual void ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg, u32 tls_address) = 0; /** * Saves the current CPU context diff --git a/src/core/arm/dyncom/arm_dyncom.cpp b/src/core/arm/dyncom/arm_dyncom.cpp index 0072ae533..1de1d2612 100644 --- a/src/core/arm/dyncom/arm_dyncom.cpp +++ b/src/core/arm/dyncom/arm_dyncom.cpp @@ -90,13 +90,14 @@ void ARM_DynCom::ExecuteInstructions(int num_instructions) { AddTicks(ticks_executed); } -void ARM_DynCom::ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg) { +void ARM_DynCom::ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg, u32 tls_address) { memset(&context, 0, sizeof(Core::ThreadContext)); context.cpu_registers[0] = arg; context.pc = entry_point; context.sp = stack_top; context.cpsr = 0x1F; // Usermode + context.tls = tls_address; } void ARM_DynCom::SaveContext(Core::ThreadContext& ctx) { @@ -123,6 +124,8 @@ void ARM_DynCom::LoadContext(const Core::ThreadContext& ctx) { state->VFP[1] = ctx.fpscr; state->VFP[2] = ctx.fpexc; + + SetCP15Register(CP15_THREAD_URO, ctx.tls); } void ARM_DynCom::PrepareReschedule() { diff --git a/src/core/arm/dyncom/arm_dyncom.h b/src/core/arm/dyncom/arm_dyncom.h index 2488c879c..b3fd708f1 100644 --- a/src/core/arm/dyncom/arm_dyncom.h +++ b/src/core/arm/dyncom/arm_dyncom.h @@ -27,7 +27,7 @@ public: void AddTicks(u64 ticks) override; - void ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg) override; + void ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg, u32 tls_address) override; void SaveContext(Core::ThreadContext& ctx) override; void LoadContext(const Core::ThreadContext& ctx) override; -- cgit v1.2.3