From 05e120a4cc380db318a5ee194579053b850f14fe Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 2 Sep 2016 08:53:42 -0400 Subject: [PATCH] arm: ResetContext shouldn't be part of ARM_Interface. --- src/core/arm/arm_interface.h | 9 --------- src/core/arm/dynarmic/arm_dynarmic.cpp | 9 --------- src/core/arm/dynarmic/arm_dynarmic.h | 1 - src/core/arm/dyncom/arm_dyncom.cpp | 9 --------- src/core/arm/dyncom/arm_dyncom.h | 1 - src/core/hle/kernel/thread.cpp | 18 +++++++++++++++++- 6 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index de5e9c8fac..480c90e660 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h @@ -121,15 +121,6 @@ public: */ virtual void AddTicks(u64 ticks) = 0; - /** - * Initializes a CPU context for use on this CPU - * @param context Thread context to reset - * @param stack_top Pointer to the top of the stack - * @param entry_point Entry point for execution - * @param arg User argument for thread - */ - virtual void ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg) = 0; - /** * Saves the current CPU context * @param ctx Thread context to save diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index 46b4d61032..a9cb973df7 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp @@ -130,15 +130,6 @@ void ARM_Dynarmic::ExecuteInstructions(int num_instructions) { AddTicks(num_instructions); } -void ARM_Dynarmic::ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg) { - memset(&context, 0, sizeof(Core::ThreadContext)); - - context.cpu_registers[0] = arg; - context.pc = entry_point; - context.sp = stack_top; - context.cpsr = USER32MODE | ((entry_point & 1) << 5); // Usermode and THUMB mode -} - void ARM_Dynarmic::SaveContext(Core::ThreadContext& ctx) { memcpy(ctx.cpu_registers, jit->Regs().data(), sizeof(ctx.cpu_registers)); memcpy(ctx.fpu_registers, jit->ExtRegs().data(), sizeof(ctx.fpu_registers)); diff --git a/src/core/arm/dynarmic/arm_dynarmic.h b/src/core/arm/dynarmic/arm_dynarmic.h index 58323135db..d493cabd53 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.h +++ b/src/core/arm/dynarmic/arm_dynarmic.h @@ -36,7 +36,6 @@ public: void AddTicks(u64 ticks) override; - void ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg) override; void SaveContext(Core::ThreadContext& ctx) override; void LoadContext(const Core::ThreadContext& ctx) override; diff --git a/src/core/arm/dyncom/arm_dyncom.cpp b/src/core/arm/dyncom/arm_dyncom.cpp index 976e81480e..d849175296 100644 --- a/src/core/arm/dyncom/arm_dyncom.cpp +++ b/src/core/arm/dyncom/arm_dyncom.cpp @@ -93,15 +93,6 @@ 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) { - memset(&context, 0, sizeof(Core::ThreadContext)); - - context.cpu_registers[0] = arg; - context.pc = entry_point; - context.sp = stack_top; - context.cpsr = USER32MODE | ((entry_point & 1) << 5); // Usermode and THUMB mode -} - void ARM_DynCom::SaveContext(Core::ThreadContext& ctx) { memcpy(ctx.cpu_registers, state->Reg.data(), sizeof(ctx.cpu_registers)); memcpy(ctx.fpu_registers, state->ExtReg.data(), sizeof(ctx.fpu_registers)); diff --git a/src/core/arm/dyncom/arm_dyncom.h b/src/core/arm/dyncom/arm_dyncom.h index cc040b174e..70f71a8280 100644 --- a/src/core/arm/dyncom/arm_dyncom.h +++ b/src/core/arm/dyncom/arm_dyncom.h @@ -38,7 +38,6 @@ public: void AddTicks(u64 ticks) override; - void ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg) override; void SaveContext(Core::ThreadContext& ctx) override; void LoadContext(const Core::ThreadContext& ctx) override; diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 9dea995f41..f1e5cf3cbf 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -441,6 +441,22 @@ std::tuple GetFreeThreadLocalSlot(std::vector>& t return std::make_tuple(0, 0, true); } +/** + * Resets a thread context, making it ready to be scheduled and run by the CPU + * @param context Thread context to reset + * @param stack_top Address of the top of the stack + * @param entry_point Address of entry point for execution + * @param arg User argument for thread + */ +static void ResetThreadContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg) { + memset(&context, 0, sizeof(Core::ThreadContext)); + + context.cpu_registers[0] = arg; + context.pc = entry_point; + context.sp = stack_top; + context.cpsr = USER32MODE | ((entry_point & 1) << 5); // Usermode and THUMB mode +} + ResultVal> Thread::Create(std::string name, VAddr entry_point, s32 priority, u32 arg, s32 processor_id, VAddr stack_top) { if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) { @@ -525,7 +541,7 @@ ResultVal> Thread::Create(std::string name, VAddr entry_point, // TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used // to initialize the context - Core::g_app_core->ResetContext(thread->context, stack_top, entry_point, arg); + ResetThreadContext(thread->context, stack_top, entry_point, arg); ready_queue.push_back(thread->current_priority, thread.get()); thread->status = THREADSTATUS_READY;