Properly using XapiThreadStartup routines, if present.

This commit is contained in:
Ben Vanik 2013-06-30 10:27:06 -07:00
parent 8d5e877a03
commit 39ef8d8263
3 changed files with 28 additions and 12 deletions

View File

@ -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 Processor::Execute(ThreadState* thread_state, uint32_t address,
uint64_t arg0) { uint64_t arg0) {
xe_ppc_state_t* ppc_state = thread_state->ppc_state(); xe_ppc_state_t* ppc_state = thread_state->ppc_state();
ppc_state->r[3] = arg0; ppc_state->r[3] = arg0;
if (Execute(thread_state, address)) { if (Execute(thread_state, address)) {
@ -234,6 +234,17 @@ uint64_t Processor::Execute(ThreadState* thread_state, uint32_t address,
return ppc_state->r[3]; 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) { FunctionSymbol* Processor::GetFunction(uint32_t address) {
// Attempt to grab the function symbol from the global lookup table. // Attempt to grab the function symbol from the global lookup table.
FunctionSymbol* fn_symbol = sym_table_->GetFunction(address); FunctionSymbol* fn_symbol = sym_table_->GetFunction(address);

View File

@ -58,6 +58,8 @@ public:
void DeallocThread(ThreadState* thread_state); void DeallocThread(ThreadState* thread_state);
int Execute(ThreadState* thread_state, uint32_t address); 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 Execute(ThreadState* thread_state, uint32_t address,
uint64_t arg0, uint64_t arg1);
sdb::FunctionSymbol* GetFunction(uint32_t address); sdb::FunctionSymbol* GetFunction(uint32_t address);
void* GetFunctionPointer(uint32_t address); void* GetFunctionPointer(uint32_t address);

View File

@ -254,17 +254,20 @@ X_STATUS XThread::PlatformExit(int exit_code) {
#endif // WIN32 #endif // WIN32
void XThread::Execute() { 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) { 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);
} }