From 9ef2d1baf666c7e92e60b8801914aa61e57e4295 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Thu, 2 Jan 2014 20:56:21 -0800 Subject: [PATCH] Calling generated code. Woo. --- src/alloy/backend/x64/x64_assembler.cc | 3 +-- src/alloy/backend/x64/x64_function.cc | 8 ++++++++ src/alloy/backend/x64/x64_function.h | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/alloy/backend/x64/x64_assembler.cc b/src/alloy/backend/x64/x64_assembler.cc index 810f888a0..7a115e82b 100644 --- a/src/alloy/backend/x64/x64_assembler.cc +++ b/src/alloy/backend/x64/x64_assembler.cc @@ -120,8 +120,7 @@ int X64Assembler::Assemble( X64Function* fn = new X64Function(symbol_info); fn->set_debug_info(debug_info); - - // TODO(benvanik): set mc + fn->Setup(machine_code, code_size); *out_function = fn; diff --git a/src/alloy/backend/x64/x64_function.cc b/src/alloy/backend/x64/x64_function.cc index 3279408fa..bebb609db 100644 --- a/src/alloy/backend/x64/x64_function.cc +++ b/src/alloy/backend/x64/x64_function.cc @@ -20,12 +20,18 @@ using namespace alloy::runtime; X64Function::X64Function(FunctionInfo* symbol_info) : + machine_code_(0), code_size_(0), GuestFunction(symbol_info) { } X64Function::~X64Function() { } +void X64Function::Setup(void* machine_code, size_t code_size) { + machine_code_ = machine_code; + code_size_ = code_size; +} + int X64Function::AddBreakpointImpl(Breakpoint* breakpoint) { return 0; } @@ -35,5 +41,7 @@ int X64Function::RemoveBreakpointImpl(Breakpoint* breakpoint) { } int X64Function::CallImpl(ThreadState* thread_state, uint64_t return_address) { + typedef void(*call_t)(ThreadState* thread_state, uint64_t return_address); + ((call_t)machine_code_)(thread_state, return_address); return 0; } diff --git a/src/alloy/backend/x64/x64_function.h b/src/alloy/backend/x64/x64_function.h index 379c5143f..36d0df88b 100644 --- a/src/alloy/backend/x64/x64_function.h +++ b/src/alloy/backend/x64/x64_function.h @@ -25,7 +25,7 @@ public: X64Function(runtime::FunctionInfo* symbol_info); virtual ~X64Function(); - //void Setup(TranslationContext& ctx); + void Setup(void* machine_code, size_t code_size); protected: virtual int AddBreakpointImpl(runtime::Breakpoint* breakpoint); @@ -34,6 +34,8 @@ protected: uint64_t return_address); private: + void* machine_code_; + size_t code_size_; };