From 2822bf7a6561ccc8ca8f571beb9f4dcc419d8188 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 12 Aug 2013 00:22:54 +0100 Subject: [PATCH] Eliminate InfoVars::cip (bug 5844 part 7, r=ds). --- sourcepawn/jit/jit_shared.h | 2 +- sourcepawn/jit/sp_vm_basecontext.cpp | 4 ++-- sourcepawn/jit/sp_vm_engine.cpp | 2 +- sourcepawn/jit/x86/jit_x86.cpp | 12 ++++++------ sourcepawn/jit/x86/jit_x86.h | 8 ++++++-- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/sourcepawn/jit/jit_shared.h b/sourcepawn/jit/jit_shared.h index c533bb74..778ccb86 100644 --- a/sourcepawn/jit/jit_shared.h +++ b/sourcepawn/jit/jit_shared.h @@ -73,7 +73,7 @@ typedef struct sp_context_s cell_t sp; /**< Stack pointer */ cell_t frm; /**< Frame pointer */ cell_t rval; /**< Return value from InvokeFunction() */ - int32_t err_cip; /**< Code pointer last error occurred in */ + int32_t cip; /**< Code pointer last error occurred in */ int32_t n_err; /**< Error code set by a native */ uint32_t n_idx; /**< Current native index being executed */ void * vm[8]; /**< VM-specific pointers */ diff --git a/sourcepawn/jit/sp_vm_basecontext.cpp b/sourcepawn/jit/sp_vm_basecontext.cpp index b59dcee3..4d9f923e 100644 --- a/sourcepawn/jit/sp_vm_basecontext.cpp +++ b/sourcepawn/jit/sp_vm_basecontext.cpp @@ -620,7 +620,7 @@ int BaseContext::Execute2(IPluginFunction *function, const cell_t *params, unsig save_exec = m_InExec; save_n_idx = m_ctx.n_idx; save_rp = m_ctx.rp; - save_cip = m_ctx.err_cip; + save_cip = m_ctx.cip; /* Push parameters */ @@ -688,7 +688,7 @@ int BaseContext::Execute2(IPluginFunction *function, const cell_t *params, unsig m_pRuntime->plugin()->profiler->OnCallbackEnd(serial); } - m_ctx.err_cip = save_cip; + m_ctx.cip = save_cip; m_ctx.n_idx = save_n_idx; m_ctx.n_err = SP_ERROR_NONE; m_MsgCache[0] = '\0'; diff --git a/sourcepawn/jit/sp_vm_engine.cpp b/sourcepawn/jit/sp_vm_engine.cpp index a156b9a4..c3fd6ecf 100644 --- a/sourcepawn/jit/sp_vm_engine.cpp +++ b/sourcepawn/jit/sp_vm_engine.cpp @@ -277,7 +277,7 @@ bool CContextTrace::GetTraceInfo(CallStackInfo *trace) if (m_Level == 0) { - cip = m_ctx->err_cip; + cip = m_ctx->cip; } else if (m_ctx->rp > 0) { diff --git a/sourcepawn/jit/x86/jit_x86.cpp b/sourcepawn/jit/x86/jit_x86.cpp index 69cf83ec..fc5a52ba 100644 --- a/sourcepawn/jit/x86/jit_x86.cpp +++ b/sourcepawn/jit/x86/jit_x86.cpp @@ -1298,7 +1298,7 @@ Compiler::emitOp(OPCODE op) case OP_BREAK: { cell_t cip = uintptr_t(cip_ - 1) - uintptr_t(plugin_->pcode); - __ movl(Operand(info, AMX_INFO_CIP), cip); + __ movl(Operand(cipAddr()), cip); break; } @@ -1486,7 +1486,7 @@ Compiler::emitCall() __ addl(Operand(eax, offsetof(sp_context_t, rp)), 1); // Store the CIP of the function we're about to call. - __ movl(Operand(info, AMX_INFO_CIP), offset); + __ movl(Operand(cipAddr()), offset); JitFunction *fun = rt_->GetJittedFunctionByOffset(offset); if (!fun) { @@ -1501,7 +1501,7 @@ Compiler::emitCall() } // Restore the last cip. - __ movl(Operand(info, AMX_INFO_CIP), cip); + __ movl(Operand(cipAddr()), cip); // Mark us as leaving the last frame. __ movl(tmp, intptr_t(rt_->GetBaseContext()->GetCtx())); @@ -1544,7 +1544,7 @@ Compiler::emitCallThunks() __ ret(); __ bind(&error); - __ movl(Operand(info, AMX_INFO_CIP), thunk->pcode_offset); + __ movl(Operand(cipAddr()), thunk->pcode_offset); __ jmp(g_Jit.GetUniversalReturn()); } } @@ -1972,10 +1972,11 @@ int JITX86::InvokeFunction(BaseRuntime *runtime, JitFunction *fn, cell_t *result { sp_context_t *ctx = runtime->GetBaseContext()->GetCtx(); + ctx->cip = fn->GetPCodeAddress(); + InfoVars vars; vars.frm = ctx->sp; vars.hp = ctx->hp; - vars.cip = fn->GetPCodeAddress(); /* vars.esp will be set in the entry code */ JIT_EXECUTE pfn = (JIT_EXECUTE)m_pJitEntry; @@ -1983,7 +1984,6 @@ int JITX86::InvokeFunction(BaseRuntime *runtime, JitFunction *fn, cell_t *result ctx->sp = vars.frm; ctx->hp = vars.hp; - ctx->err_cip = vars.cip; *result = ctx->rval; return err; diff --git a/sourcepawn/jit/x86/jit_x86.h b/sourcepawn/jit/x86/jit_x86.h index f2dd4270..9edebecd 100644 --- a/sourcepawn/jit/x86/jit_x86.h +++ b/sourcepawn/jit/x86/jit_x86.h @@ -39,6 +39,7 @@ #include #include "jit_shared.h" #include "BaseRuntime.h" +#include "sp_vm_basecontext.h" #include "jit_function.h" #include "opcodes.h" @@ -131,6 +132,11 @@ class Compiler void emitErrorPath(Label *dest, int code); void emitErrorPaths(); + ExternalAddress cipAddr() { + sp_context_t *ctx = rt_->GetBaseContext()->GetCtx(); + return ExternalAddress(&ctx->cip); + } + private: AssemblerX86 masm; BaseRuntime *rt_; @@ -197,13 +203,11 @@ const Register frm = ebx; struct InfoVars { ucell_t frm; ucell_t hp; - ucell_t cip; void *esp; }; #define AMX_INFO_FRAME offsetof(InfoVars, frm) #define AMX_INFO_HEAP offsetof(InfoVars, hp) -#define AMX_INFO_CIP offsetof(InfoVars, cip) #define AMX_INFO_NSTACK offsetof(InfoVars, esp) extern Knight::KeCodeCache *g_pCodeCache;