Factor code stubs out of JITX86.

This commit is contained in:
David Anderson
2015-02-24 02:03:58 -08:00
parent 21f5400d9c
commit 111dd7eb68
12 changed files with 348 additions and 198 deletions
+24 -4
View File
@@ -15,6 +15,7 @@
#include "watchdog_timer.h"
#include "debug-trace.h"
#include "api.h"
#include "code-stubs.h"
#include "watchdog_timer.h"
using namespace sp;
@@ -63,13 +64,14 @@ Environment::Initialize()
{
api_v1_ = new SourcePawnEngine();
api_v2_ = new SourcePawnEngine2();
code_stubs_ = new CodeStubs(this);
watchdog_timer_ = new WatchdogTimer(this);
if ((code_pool_ = Knight::KE_CreateCodeCache()) == nullptr)
return false;
// Safe to initialize JIT now that we have the code cache.
if (!g_Jit.InitializeJIT())
// Safe to initialize code now that we have the code cache.
if (!code_stubs_->Initialize())
return false;
return true;
@@ -79,7 +81,7 @@ void
Environment::Shutdown()
{
watchdog_timer_->Shutdown();
g_Jit.ShutdownJIT();
code_stubs_->Shutdown();
Knight::KE_DestroyCodeCache(code_pool_);
assert(sEnvironment == this);
@@ -208,7 +210,7 @@ Environment::PatchAllJumpsForTimeout()
for (size_t j = 0; j < fun->NumLoopEdges(); j++) {
const LoopEdge &e = fun->GetLoopEdge(j);
int32_t diff = intptr_t(g_Jit.TimeoutStub()) - intptr_t(base + e.offset);
int32_t diff = intptr_t(code_stubs_->TimeoutStub()) - intptr_t(base + e.offset);
*reinterpret_cast<int32_t *>(base + e.offset - 4) = diff;
}
}
@@ -232,3 +234,21 @@ Environment::UnpatchAllJumpsFromTimeout()
}
}
}
int
Environment::Invoke(PluginRuntime *runtime, CompiledFunction *fn, cell_t *result)
{
sp_context_t *ctx = runtime->GetBaseContext()->GetCtx();
// Note that cip, hp, sp are saved and restored by Execute2().
ctx->cip = fn->GetCodeOffset();
InvokeStubFn invoke = code_stubs_->InvokeStub();
EnterInvoke();
int err = invoke(ctx, runtime->plugin()->memory, fn->GetEntryAddress());
LeaveInvoke();
*result = ctx->rval;
return err;
}