From 39ef8d826350b21aaaffbbd0a37cc08c73ebbcad Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sun, 30 Jun 2013 10:27:06 -0700 Subject: [PATCH] Properly using XapiThreadStartup routines, if present. --- src/xenia/cpu/processor.cc | 13 +++++++++- src/xenia/cpu/processor.h | 2 ++ .../modules/xboxkrnl/objects/xthread.cc | 25 +++++++++++-------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/xenia/cpu/processor.cc b/src/xenia/cpu/processor.cc index 4e0df4c03..6a214c1db 100644 --- a/src/xenia/cpu/processor.cc +++ b/src/xenia/cpu/processor.cc @@ -225,7 +225,7 @@ int Processor::Execute(ThreadState* thread_state, uint32_t address) { } uint64_t Processor::Execute(ThreadState* thread_state, uint32_t address, - uint64_t arg0) { + uint64_t arg0) { xe_ppc_state_t* ppc_state = thread_state->ppc_state(); ppc_state->r[3] = arg0; if (Execute(thread_state, address)) { @@ -234,6 +234,17 @@ uint64_t Processor::Execute(ThreadState* thread_state, uint32_t address, return ppc_state->r[3]; } +uint64_t Processor::Execute(ThreadState* thread_state, uint32_t address, + uint64_t arg0, uint64_t arg1) { + xe_ppc_state_t* ppc_state = thread_state->ppc_state(); + ppc_state->r[3] = arg0; + ppc_state->r[4] = arg1; + if (Execute(thread_state, address)) { + return 0xDEADBABE; + } + return ppc_state->r[3]; +} + FunctionSymbol* Processor::GetFunction(uint32_t address) { // Attempt to grab the function symbol from the global lookup table. FunctionSymbol* fn_symbol = sym_table_->GetFunction(address); diff --git a/src/xenia/cpu/processor.h b/src/xenia/cpu/processor.h index 20cb25fe9..a1bc2159a 100644 --- a/src/xenia/cpu/processor.h +++ b/src/xenia/cpu/processor.h @@ -58,6 +58,8 @@ public: void DeallocThread(ThreadState* thread_state); int Execute(ThreadState* thread_state, uint32_t address); uint64_t Execute(ThreadState* thread_state, uint32_t address, uint64_t arg0); + uint64_t Execute(ThreadState* thread_state, uint32_t address, + uint64_t arg0, uint64_t arg1); sdb::FunctionSymbol* GetFunction(uint32_t address); void* GetFunctionPointer(uint32_t address); diff --git a/src/xenia/kernel/modules/xboxkrnl/objects/xthread.cc b/src/xenia/kernel/modules/xboxkrnl/objects/xthread.cc index ff9185ded..e64dc72bc 100644 --- a/src/xenia/kernel/modules/xboxkrnl/objects/xthread.cc +++ b/src/xenia/kernel/modules/xboxkrnl/objects/xthread.cc @@ -254,17 +254,20 @@ X_STATUS XThread::PlatformExit(int exit_code) { #endif // WIN32 void XThread::Execute() { - // Run XapiThreadStartup first, if present. + // If a XapiThreadStartup value is present, we use that as a trampoline. + // Otherwise, we are a raw thread. if (creation_params_.xapi_thread_startup) { - XELOGE("xapi_thread_startup not implemented"); + kernel_state()->processor()->Execute( + thread_state_, + creation_params_.xapi_thread_startup, + creation_params_.start_address, creation_params_.start_context); + } else { + // Run user code. + int exit_code = (int)kernel_state()->processor()->Execute( + thread_state_, + creation_params_.start_address, creation_params_.start_context); + // If we got here it means the execute completed without an exit being called. + // Treat the return code as an implicit exit code. + Exit(exit_code); } - - // Run user code. - int exit_code = (int)kernel_state()->processor()->Execute( - thread_state_, - creation_params_.start_address, creation_params_.start_context); - - // If we got here it means the execute completed without an exit being called. - // Treat the return code as an implicit exit code. - Exit(exit_code); }