summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/thread.cpp')
-rw-r--r--src/core/hle/kernel/thread.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 9dea995f4..f1e5cf3cb 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -441,6 +441,22 @@ std::tuple<u32, u32, bool> GetFreeThreadLocalSlot(std::vector<std::bitset<8>>& t
441 return std::make_tuple(0, 0, true); 441 return std::make_tuple(0, 0, true);
442} 442}
443 443
444/**
445 * Resets a thread context, making it ready to be scheduled and run by the CPU
446 * @param context Thread context to reset
447 * @param stack_top Address of the top of the stack
448 * @param entry_point Address of entry point for execution
449 * @param arg User argument for thread
450 */
451static void ResetThreadContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg) {
452 memset(&context, 0, sizeof(Core::ThreadContext));
453
454 context.cpu_registers[0] = arg;
455 context.pc = entry_point;
456 context.sp = stack_top;
457 context.cpsr = USER32MODE | ((entry_point & 1) << 5); // Usermode and THUMB mode
458}
459
444ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, s32 priority, 460ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, s32 priority,
445 u32 arg, s32 processor_id, VAddr stack_top) { 461 u32 arg, s32 processor_id, VAddr stack_top) {
446 if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) { 462 if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) {
@@ -525,7 +541,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
525 541
526 // TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used 542 // TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used
527 // to initialize the context 543 // to initialize the context
528 Core::g_app_core->ResetContext(thread->context, stack_top, entry_point, arg); 544 ResetThreadContext(thread->context, stack_top, entry_point, arg);
529 545
530 ready_queue.push_back(thread->current_priority, thread.get()); 546 ready_queue.push_back(thread->current_priority, thread.get());
531 thread->status = THREADSTATUS_READY; 547 thread->status = THREADSTATUS_READY;