From d2005bd42a1d3afeb6b56383103cc288c1d9e360 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 24 Feb 2015 20:53:44 -0800 Subject: [PATCH] Move cip from sp_context_t to PluginContext. --- sourcepawn/jit/debug-trace.cpp | 2 +- sourcepawn/jit/environment.cpp | 5 +++-- sourcepawn/jit/interpreter.cpp | 6 +++--- sourcepawn/jit/jit_shared.h | 1 - sourcepawn/jit/plugin-context.cpp | 4 ++-- sourcepawn/jit/plugin-context.h | 10 ++++++++++ sourcepawn/jit/x86/jit_x86.cpp | 1 + sourcepawn/jit/x86/jit_x86.h | 4 ++-- 8 files changed, 22 insertions(+), 11 deletions(-) diff --git a/sourcepawn/jit/debug-trace.cpp b/sourcepawn/jit/debug-trace.cpp index 960148dd..df857d8f 100644 --- a/sourcepawn/jit/debug-trace.cpp +++ b/sourcepawn/jit/debug-trace.cpp @@ -66,7 +66,7 @@ CContextTrace::GetTraceInfo(CallStackInfo *trace) cell_t cip; if (m_Level == 0) { - cip = m_ctx->cip; + cip = context_->cip(); } else if (context_->rp() > 0) { /* Entries go from ctx.rp - 1 to m_StartRp */ cell_t offs, start, end; diff --git a/sourcepawn/jit/environment.cpp b/sourcepawn/jit/environment.cpp index 6c2feb67..25e127e1 100644 --- a/sourcepawn/jit/environment.cpp +++ b/sourcepawn/jit/environment.cpp @@ -238,10 +238,11 @@ Environment::UnpatchAllJumpsFromTimeout() int Environment::Invoke(PluginRuntime *runtime, CompiledFunction *fn, cell_t *result) { - sp_context_t *ctx = runtime->GetBaseContext()->GetCtx(); + PluginContext *cx = runtime->GetBaseContext(); + sp_context_t *ctx = cx->GetCtx(); // Note that cip, hp, sp are saved and restored by Execute2(). - ctx->cip = fn->GetCodeOffset(); + *cx->addressOfCip() = fn->GetCodeOffset(); InvokeStubFn invoke = code_stubs_->InvokeStub(); diff --git a/sourcepawn/jit/interpreter.cpp b/sourcepawn/jit/interpreter.cpp index 50d87b87..3e8a8a7b 100644 --- a/sourcepawn/jit/interpreter.cpp +++ b/sourcepawn/jit/interpreter.cpp @@ -777,7 +777,7 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval) } case OP_BREAK: - ctx->cip = uintptr_t(cip - 1) - uintptr_t(plugin->pcode); + *cx->addressOfCip() = uintptr_t(cip - 1) - uintptr_t(plugin->pcode); break; case OP_BOUNDS: @@ -805,13 +805,13 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval) err = SP_ERROR_STACKLOW; goto error; } - ctx->cip = offset; + *cx->addressOfCip() = offset; ctx->sp = uintptr_t(stk) - uintptr_t(plugin->memory); int err = Interpret(rt, offset, &pri); stk = reinterpret_cast(plugin->memory + ctx->sp); - ctx->cip = rcip; + *cx->addressOfCip() = rcip; cx->popReturnCip(); if (err != SP_ERROR_NONE) diff --git a/sourcepawn/jit/jit_shared.h b/sourcepawn/jit/jit_shared.h index e2c4ad15..7b971028 100644 --- a/sourcepawn/jit/jit_shared.h +++ b/sourcepawn/jit/jit_shared.h @@ -76,7 +76,6 @@ typedef struct sp_context_s cell_t sp; /**< Stack pointer */ cell_t frm; /**< Frame pointer */ cell_t rval; /**< Return value from InvokeFunction() */ - int32_t cip; /**< Code pointer last error occurred in */ sp_plugin_t *plugin; PluginContext *basecx; } sp_context_t; diff --git a/sourcepawn/jit/plugin-context.cpp b/sourcepawn/jit/plugin-context.cpp index 61d887ea..afdae4e7 100644 --- a/sourcepawn/jit/plugin-context.cpp +++ b/sourcepawn/jit/plugin-context.cpp @@ -583,7 +583,7 @@ PluginContext::Execute2(IPluginFunction *function, const cell_t *params, unsigne save_exec = m_InExec; save_n_idx = last_native_; save_rp = rp_; - save_cip = m_ctx.cip; + save_cip = cip_; /* Push parameters */ @@ -644,7 +644,7 @@ PluginContext::Execute2(IPluginFunction *function, const cell_t *params, unsigne m_ctx.hp = save_hp; rp_ = save_rp; - m_ctx.cip = save_cip; + cip_ = save_cip; last_native_ = save_n_idx; native_error_ = SP_ERROR_NONE; m_MsgCache[0] = '\0'; diff --git a/sourcepawn/jit/plugin-context.h b/sourcepawn/jit/plugin-context.h index 90b2c9d3..cde2bd68 100644 --- a/sourcepawn/jit/plugin-context.h +++ b/sourcepawn/jit/plugin-context.h @@ -104,6 +104,13 @@ class PluginContext : public IPluginContext return offsetof(PluginContext, native_error_); } + int32_t *addressOfCip() { + return &cip_; + } + int32_t cip() const { + return cip_; + } + // Return stack logic. bool pushReturnCip(cell_t cip) { if (rp_ >= SP_MAX_RETURN_STACK) @@ -157,6 +164,9 @@ class PluginContext : public IPluginContext // Track the currently executing native index, and any error it throws. int32_t last_native_; int native_error_; + + // Most recent CIP. + int32_t cip_; }; #endif //_INCLUDE_SOURCEPAWN_BASECONTEXT_H_ diff --git a/sourcepawn/jit/x86/jit_x86.cpp b/sourcepawn/jit/x86/jit_x86.cpp index dca060d1..f0b0fbbf 100644 --- a/sourcepawn/jit/x86/jit_x86.cpp +++ b/sourcepawn/jit/x86/jit_x86.cpp @@ -303,6 +303,7 @@ CompileFromThunk(PluginRuntime *runtime, cell_t pcode_offs, void **addrp, char * Compiler::Compiler(PluginRuntime *rt, cell_t pcode_offs) : env_(Environment::get()), rt_(rt), + context_(rt->GetBaseContext()), plugin_(rt->plugin()), error_(SP_ERROR_NONE), pcode_start_(pcode_offs), diff --git a/sourcepawn/jit/x86/jit_x86.h b/sourcepawn/jit/x86/jit_x86.h index 3af246b2..7d32957b 100644 --- a/sourcepawn/jit/x86/jit_x86.h +++ b/sourcepawn/jit/x86/jit_x86.h @@ -91,8 +91,7 @@ class Compiler void emitFloatCmp(ConditionCode cc); ExternalAddress cipAddr() { - sp_context_t *ctx = rt_->GetBaseContext()->GetCtx(); - return ExternalAddress(&ctx->cip); + return ExternalAddress(context_->addressOfCip()); } ExternalAddress hpAddr() { sp_context_t *ctx = rt_->GetBaseContext()->GetCtx(); @@ -107,6 +106,7 @@ class Compiler AssemblerX86 masm; sp::Environment *env_; PluginRuntime *rt_; + PluginContext *context_; const sp_plugin_t *plugin_; int error_; uint32_t pcode_start_;