Remove xenia-cpu dependency on xenia-kernel

This commit is contained in:
Dr. Chat
2017-02-06 21:04:00 -06:00
parent b66f10f2b8
commit 4c55039c22
9 changed files with 130 additions and 57 deletions

View File

@@ -12,9 +12,6 @@ project("xenia-cpu-ppc-tests")
"xenia-core",
"xenia-cpu",
"xenia-cpu-backend-x64",
-- TODO(benvanik): remove these dependencies.
"xenia-kernel"
})
files({
"ppc_testing_main.cc",

View File

@@ -28,12 +28,10 @@
#include "xenia/cpu/ppc/ppc_decode_data.h"
#include "xenia/cpu/ppc/ppc_frontend.h"
#include "xenia/cpu/stack_walker.h"
#include "xenia/cpu/thread.h"
#include "xenia/cpu/thread_state.h"
#include "xenia/cpu/xex_module.h"
// HACK(benvanik): XThread has too much stuff :/
#include "xenia/kernel/xthread.h"
// TODO(benvanik): based on compiler support
#include "xenia/cpu/backend/x64/x64_backend.h"
@@ -49,6 +47,10 @@ DEFINE_string(trace_function_data_path, "", "File to write trace data to.");
DEFINE_bool(break_on_start, false, "Break into the debugger on startup.");
namespace xe {
namespace kernel {
class XThread;
} // namespace kernel
namespace cpu {
using xe::cpu::ppc::PPCOpcode;
@@ -491,8 +493,7 @@ void Processor::OnFunctionDefined(Function* function) {
}
void Processor::OnThreadCreated(uint32_t thread_handle,
ThreadState* thread_state,
kernel::XThread* thread) {
ThreadState* thread_state, Thread* thread) {
auto global_lock = global_critical_region_.Acquire();
auto thread_info = std::make_unique<ThreadDebugInfo>();
thread_info->thread_handle = thread_handle;
@@ -683,7 +684,7 @@ bool Processor::OnThreadBreakpointHit(Exception* ex) {
debug_listener_->OnExecutionPaused();
}
thread_info->thread->Suspend(nullptr);
thread_info->thread->thread()->Suspend();
// Apply thread context changes.
// TODO(benvanik): apply to all threads?
@@ -711,7 +712,7 @@ bool Processor::OnUnhandledException(Exception* ex) {
}
// If this isn't a managed thread, fail - let VS handle it for now.
if (!XThread::IsInThread()) {
if (!Thread::IsInThread()) {
return false;
}
@@ -720,7 +721,7 @@ bool Processor::OnUnhandledException(Exception* ex) {
// Suspend all guest threads (but this one).
SuspendAllThreads();
UpdateThreadExecutionStates(XThread::GetCurrentThreadId(),
UpdateThreadExecutionStates(Thread::GetCurrentThreadId(),
ex->thread_context());
// Stop and notify the listener.
@@ -733,7 +734,7 @@ bool Processor::OnUnhandledException(Exception* ex) {
debug_listener_->OnExecutionPaused();
// Suspend self.
XThread::GetCurrentThread()->Suspend(nullptr);
Thread::GetCurrentThread()->thread()->Suspend();
return true;
}
@@ -757,8 +758,8 @@ bool Processor::SuspendAllThreads() {
thread_info->state == ThreadDebugInfo::State::kExited) {
// Thread is dead and cannot be suspended - ignore.
continue;
} else if (XThread::IsInThread() &&
thread_info->thread_id == XThread::GetCurrentThreadId()) {
} else if (Thread::IsInThread() &&
thread_info->thread_id == Thread::GetCurrentThreadId()) {
// Can't suspend ourselves.
continue;
}
@@ -767,7 +768,7 @@ bool Processor::SuspendAllThreads() {
// Thread is a host thread, and we aren't suspending those (for now).
continue;
}
bool did_suspend = XSUCCEEDED(thread->Suspend(nullptr));
bool did_suspend = thread->thread()->Suspend(nullptr);
assert_true(did_suspend);
thread_info->suspended = true;
}
@@ -786,7 +787,7 @@ bool Processor::ResumeThread(uint32_t thread_id) {
thread_info->state == ThreadDebugInfo::State::kZombie);
thread_info->suspended = false;
auto thread = thread_info->thread;
return XSUCCEEDED(thread->Resume());
return thread->thread()->Resume();
}
bool Processor::ResumeAllThreads() {
@@ -800,8 +801,8 @@ bool Processor::ResumeAllThreads() {
thread_info->state == ThreadDebugInfo::State::kExited) {
// Thread is dead and cannot be resumed - ignore.
continue;
} else if (XThread::IsInThread() &&
thread_info->thread_id == XThread::GetCurrentThreadId()) {
} else if (Thread::IsInThread() &&
thread_info->thread_id == Thread::GetCurrentThreadId()) {
// Can't resume ourselves.
continue;
}
@@ -811,7 +812,7 @@ bool Processor::ResumeAllThreads() {
continue;
}
thread_info->suspended = false;
bool did_resume = XSUCCEEDED(thread->Resume());
bool did_resume = thread->thread()->Resume();
assert_true(did_resume);
}
return true;
@@ -987,7 +988,7 @@ bool Processor::StepToGuestAddress(uint32_t thread_id, uint32_t pc) {
if (functions.empty()) {
// Function hasn't been generated yet. Generate it.
if (!ResolveFunction(pc)) {
XELOGE("XThread::StepToAddress(%.8X) - Function could not be resolved",
XELOGE("Processor::StepToAddress(%.8X) - Function could not be resolved",
pc);
return false;
}
@@ -1005,7 +1006,7 @@ bool Processor::StepToGuestAddress(uint32_t thread_id, uint32_t pc) {
auto thread_info = QueryThreadDebugInfo(thread_id);
uint32_t suspend_count = 1;
while (suspend_count) {
thread_info->thread->Resume(&suspend_count);
thread_info->thread->thread()->Resume(&suspend_count);
}
fence.Wait();
@@ -1075,7 +1076,7 @@ uint32_t Processor::StepIntoGuestBranchTarget(uint32_t thread_id, uint32_t pc) {
// HACK
uint32_t suspend_count = 1;
while (suspend_count) {
thread->Resume(&suspend_count);
thread->thread()->Resume(&suspend_count);
}
fence.Wait();
@@ -1090,7 +1091,7 @@ uint32_t Processor::StepToGuestSafePoint(uint32_t thread_id, bool ignore_host) {
// This cannot be done if we're the calling thread!
if (thread_id == ThreadState::GetThreadID()) {
assert_always(
"XThread::StepToSafePoint(): target thread is the calling thread!");
"Processor::StepToSafePoint(): target thread is the calling thread!");
return 0;
}
auto thread_info = QueryThreadDebugInfo(thread_id);
@@ -1213,11 +1214,15 @@ uint32_t Processor::StepToGuestSafePoint(uint32_t thread_id, bool ignore_host) {
} else {
// We've managed to catch a thread before it called into the guest.
// Set a breakpoint on its startup procedure and capture it there.
// TODO(DrChat): Reimplement
assert_always("Unimplemented");
/*
auto creation_params = thread->creation_params();
pc = creation_params->xapi_thread_startup
? creation_params->xapi_thread_startup
: creation_params->start_address;
StepToGuestAddress(thread_id, pc);
*/
}
}

View File

@@ -189,7 +189,7 @@ class Processor {
public:
// TODO(benvanik): hide.
void OnThreadCreated(uint32_t handle, ThreadState* thread_state,
kernel::XThread* thread);
Thread* thread);
void OnThreadExit(uint32_t thread_id);
void OnThreadDestroyed(uint32_t thread_id);
void OnThreadEnteringWait(uint32_t thread_id);

29
src/xenia/cpu/thread.cc Normal file
View File

@@ -0,0 +1,29 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2017 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "xenia/cpu/thread.h"
#include "xenia/cpu/thread_state.h"
namespace xe {
namespace cpu {
thread_local Thread* Thread::current_thread_tls_ = nullptr;
Thread::Thread() {}
Thread::~Thread() {}
bool Thread::IsInThread() { return current_thread_tls_ != nullptr; }
Thread* Thread::GetCurrentThread() { return current_thread_tls_; }
uint32_t Thread::GetCurrentThreadId() {
return Thread::GetCurrentThread()->thread_state()->thread_id();
}
} // namespace cpu
} // namespace xe

55
src/xenia/cpu/thread.h Normal file
View File

@@ -0,0 +1,55 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2017 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_CPU_THREAD_H_
#define XENIA_CPU_THREAD_H_
#include "xenia/base/threading.h"
#include <cstdint>
namespace xe {
namespace cpu {
class ThreadState;
// Represents a thread that runs guest code.
class Thread {
public:
Thread();
~Thread();
static bool IsInThread();
static Thread* GetCurrentThread();
static uint32_t GetCurrentThreadId();
ThreadState* thread_state() const { return thread_state_; }
// True if the thread should be paused by the debugger.
// All threads that can run guest code must be stopped for the debugger to
// work properly.
bool can_debugger_suspend() const { return can_debugger_suspend_; }
void set_can_debugger_suspend(bool value) { can_debugger_suspend_ = value; }
xe::threading::Thread* thread() { return thread_.get(); }
const std::string& thread_name() const { return thread_name_; }
protected:
static thread_local Thread* current_thread_tls_;
ThreadState* thread_state_ = nullptr;
std::unique_ptr<xe::threading::Thread> thread_ = nullptr;
bool can_debugger_suspend_ = true;
std::string thread_name_;
};
} // namespace cpu
} // namespace xe
#endif // XENIA_CPU_THREAD_H_

View File

@@ -13,14 +13,9 @@
#include <vector>
#include "xenia/base/x64_context.h"
#include "xenia/cpu/thread.h"
#include "xenia/cpu/thread_state.h"
namespace xe {
namespace kernel {
class XThread;
} // namespace kernel
} // namespace xe
namespace xe {
namespace cpu {
@@ -53,8 +48,8 @@ struct ThreadDebugInfo {
// XThread::handle() of the thread.
// This will be invalidated when the thread dies.
uint32_t thread_handle = 0;
// Kernel thread object. Only valid when the thread is alive.
kernel::XThread* thread = nullptr;
// Thread object. Only valid when the thread is alive.
Thread* thread = nullptr;
// Current state of the thread.
State state = State::kAlive;
// Whether the debugger has forcefully suspended this thread.