Sandbox getting close to running.

This commit is contained in:
Ben Vanik 2014-07-12 22:59:16 -07:00
parent 4a0531abc5
commit 48425da8ff
7 changed files with 11 additions and 61 deletions

View File

@ -128,8 +128,6 @@ int IVMFunction::CallImpl(ThreadState* thread_state, uint64_t return_address) {
ics.return_address = return_address;
ics.call_return_address = 0;
volatile int* suspend_flag_address = thread_state->suspend_flag_address();
// TODO(benvanik): DID_CARRY -- need HIR to set a OPCODE_FLAG_SET_CARRY
// or something so the fns can set an ics flag.
@ -139,12 +137,6 @@ int IVMFunction::CallImpl(ThreadState* thread_state, uint64_t return_address) {
uint32_t ia = 0;
while (true) {
// Check suspend. We could do this only on certain instructions, if we
// wanted to speed things up.
if (*suspend_flag_address) {
thread_state->EnterSuspend();
}
#ifdef TRACE_SOURCE_OFFSET
uint64_t source_offset = -1;
if (source_index < this->source_map_count_ &&

View File

@ -199,7 +199,6 @@ typedef struct XECACHEALIGN64 PPCContext_s {
// Runtime-specific data pointer. Used on callbacks to get access to the
// current runtime and its data.
runtime::Runtime* runtime;
volatile int suspend_flag;
void SetRegFromString(const char* name, const char* value);
bool CompareRegWithString(const char* name, const char* value,

View File

@ -31,7 +31,7 @@ class Runtime {
typedef std::vector<Module*> ModuleList;
public:
Runtime(Memory* memory);
explicit Runtime(Memory* memory);
virtual ~Runtime();
Memory* memory() const { return memory_; }

View File

@ -32,10 +32,8 @@ class ThreadState {
void* backend_data() const { return backend_data_; }
void* raw_context() const { return raw_context_; }
virtual volatile int* suspend_flag_address() const = 0;
virtual int Suspend(uint32_t timeout_ms = UINT_MAX) = 0;
virtual int Resume(bool force = false) = 0;
virtual void EnterSuspend() = 0;
virtual int Suspend(uint32_t timeout_ms = UINT_MAX) { return 1; }
virtual int Resume(bool force = false) { return 1; }
static void Bind(ThreadState* thread_state);
static ThreadState* Get();

View File

@ -23,13 +23,12 @@ using namespace xe::cpu;
XenonThreadState::XenonThreadState(
XenonRuntime* runtime, uint32_t thread_id,
size_t stack_size, uint64_t thread_state_address) :
stack_size_(stack_size), thread_state_address_(thread_state_address),
ThreadState(runtime, thread_id) {
ThreadState(runtime, thread_id),
stack_size_(stack_size),
thread_state_address_(thread_state_address) {
stack_address_ = memory_->HeapAlloc(
0, stack_size, MEMORY_FLAG_ZERO);
debug_break_ = CreateEvent(NULL, FALSE, FALSE, NULL);
// Allocate with 64b alignment.
context_ = (PPCContext*)xe_malloc_aligned(sizeof(PPCContext));
assert_true(((uint64_t)context_ & 0xF) == 0);
@ -60,40 +59,9 @@ XenonThreadState::XenonThreadState(
XenonThreadState::~XenonThreadState() {
runtime_->debugger()->OnThreadDestroyed(this);
CloseHandle(debug_break_);
alloy::tracing::WriteEvent(EventType::ThreadDeinit({
}));
xe_free_aligned(context_);
memory_->HeapFree(stack_address_, stack_size_);
}
volatile int* XenonThreadState::suspend_flag_address() const {
return &context_->suspend_flag;
}
int XenonThreadState::Suspend(uint32_t timeout_ms) {
// Set suspend flag.
// One of the checks should call in to OnSuspend() at some point.
poly::atomic_inc(&context_->suspend_flag);
return 0;
}
int XenonThreadState::Resume(bool force) {
if (context_->suspend_flag) {
if (force) {
context_->suspend_flag = 0;
SetEvent(debug_break_);
} else {
if (!poly::atomic_dec(&context_->suspend_flag)) {
SetEvent(debug_break_);
}
}
}
return 0;
}
void XenonThreadState::EnterSuspend() {
WaitForSingleObject(debug_break_, INFINITE);
}

View File

@ -34,11 +34,6 @@ public:
uint64_t thread_state_address() const { return thread_state_address_; }
PPCContext* context() const { return context_; }
virtual volatile int* suspend_flag_address() const;
virtual int Suspend(uint32_t timeout_ms = UINT_MAX);
virtual int Resume(bool force = false);
virtual void EnterSuspend();
private:
uint64_t stack_address_;
size_t stack_size_;
@ -46,8 +41,6 @@ private:
// NOTE: must be 64b aligned for SSE ops.
PPCContext* context_;
HANDLE debug_break_;
};

View File

@ -7,12 +7,12 @@
******************************************************************************
*/
#include <xenia/xenia.h>
#include <alloy/alloy.h>
#include <alloy/runtime/raw_module.h>
#include <xenia/export_resolver.h>
#include <xenia/cpu/xenon_memory.h>
#include <xenia/cpu/xenon_runtime.h>
#include <xenia/cpu/xenon_thread_state.h>
#include <gflags/gflags.h>
@ -22,7 +22,6 @@ using namespace alloy::runtime;
using namespace xe;
using namespace xe::cpu;
int alloy_sandbox(int argc, xechar_t** argv) {
Profiler::Initialize();
xe::Profiler::ThreadEnter("main");
@ -43,8 +42,8 @@ int alloy_sandbox(int argc, xechar_t** argv) {
module->LoadFile(0x82000000, "test\\codegen\\instr_add.bin");
runtime->AddModule(module);
XenonThreadState* thread_state = new XenonThreadState(
runtime, 100, 64 * 1024, 0);
XenonThreadState* thread_state =
new XenonThreadState(runtime, 100, 64 * 1024, 0);
Function* fn;
runtime->ResolveFunction(0x82000000, &fn);
@ -54,6 +53,7 @@ int alloy_sandbox(int argc, xechar_t** argv) {
ctx->r[25] = 25;
fn->Call(thread_state, ctx->lr);
auto result = ctx->r[11];
printf("%llu", result);
delete thread_state;