Suspend/resume working.

This commit is contained in:
Ben Vanik
2013-12-23 19:46:35 -08:00
parent dc48b0a85a
commit 98efc7ddfa
11 changed files with 95 additions and 28 deletions

View File

@@ -119,11 +119,19 @@ 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.
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();
}
IntCode* i = &intcodes_[ia];
if (i->debug_flags) {

View File

@@ -190,7 +190,7 @@ typedef struct XECACHEALIGN64 PPCContext_s {
uint8_t* membase;
runtime::Runtime* runtime;
runtime::ThreadState* thread_state;
uint32_t suspend_flag;
volatile int suspend_flag;
void SetRegFromString(const char* name, const char* value);
bool CompareRegWithString(const char* name, const char* value,

View File

@@ -63,12 +63,12 @@ int Debugger::ResumeThread(uint32_t thread_id) {
return result;
}
int Debugger::ResumeAllThreads() {
int Debugger::ResumeAllThreads(bool force) {
int result = 0;
LockMutex(threads_lock_);
for (auto it = threads_.begin(); it != threads_.end(); ++it) {
ThreadState* thread_state = it->second;
if (thread_state->Resume()) {
if (thread_state->Resume(force)) {
result = 1;
}
}

View File

@@ -84,7 +84,7 @@ public:
int SuspendAllThreads(uint32_t timeout_ms = UINT_MAX);
int ResumeThread(uint32_t thread_id);
int ResumeAllThreads();
int ResumeAllThreads(bool force = false);
int AddBreakpoint(Breakpoint* breakpoint);
int RemoveBreakpoint(Breakpoint* breakpoint);

View File

@@ -32,8 +32,10 @@ public:
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() = 0;
virtual int Resume(bool force = false) = 0;
virtual void EnterSuspend() = 0;
static void Bind(ThreadState* thread_state);
static ThreadState* Get();