about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAjax <commial@gmail.com>2016-12-20 16:52:34 +0100
committerAjax <commial@gmail.com>2017-01-04 17:14:55 +0100
commitd554129240394be47c9d99655e7d7feef5567795 (patch)
tree077546ffee43229e2a0a4f26a7e789365d2ea1a3
parentb80b4b4c1737608f147d7c6031be8f16d4561d6b (diff)
downloadmiasm-d554129240394be47c9d99655e7d7feef5567795.tar.gz
miasm-d554129240394be47c9d99655e7d7feef5567795.zip
Update with new MEM R/W API
-rw-r--r--miasm2/jitter/Jitllvm.c4
-rw-r--r--miasm2/jitter/llvmconvert.py26
2 files changed, 18 insertions, 12 deletions
diff --git a/miasm2/jitter/Jitllvm.c b/miasm2/jitter/Jitllvm.c
index ff537728..98e047bf 100644
--- a/miasm2/jitter/Jitllvm.c
+++ b/miasm2/jitter/Jitllvm.c
@@ -13,7 +13,7 @@
 PyObject* llvm_exec_bloc(PyObject* self, PyObject* args)
 {
 	uint64_t func_addr;
-	uint64_t (*func)(void*, void*);
+	uint64_t (*func)(void*, void*, void*);
 	uint64_t vm;
 	uint64_t ret;
 	JitCpu* jitcpu;
@@ -22,7 +22,7 @@ PyObject* llvm_exec_bloc(PyObject* self, PyObject* args)
 		return NULL;
 	vm_cpu_t* cpu = jitcpu->cpu;
 	func = (void *) (intptr_t) func_addr;
-	ret = func((void*)(intptr_t) cpu, (void*)(intptr_t) vm);
+	ret = func((void*) jitcpu, (void*)(intptr_t) cpu, (void*)(intptr_t) vm);
 	return PyLong_FromUnsignedLongLong(ret);
 }
 
diff --git a/miasm2/jitter/llvmconvert.py b/miasm2/jitter/llvmconvert.py
index e30713b4..460d4e4f 100644
--- a/miasm2/jitter/llvmconvert.py
+++ b/miasm2/jitter/llvmconvert.py
@@ -160,11 +160,11 @@ class LLVMContext_JIT(LLVMContext):
         fc = {}
         p8 = llvm_ir.PointerType(LLVMType.IntType(8))
         for i in [8, 16, 32, 64]:
-            fc["vm_MEM_LOOKUP_%02d" % i] = {"ret": LLVMType.IntType(i),
+            fc["MEM_LOOKUP_%02d" % i] = {"ret": LLVMType.IntType(i),
                                          "args": [p8,
                                                   LLVMType.IntType(64)]}
 
-            fc["vm_MEM_WRITE_%02d" % i] = {"ret": llvm_ir.VoidType(),
+            fc["MEM_WRITE_%02d" % i] = {"ret": llvm_ir.VoidType(),
                                         "args": [p8,
                                                  LLVMType.IntType(64),
                                                  LLVMType.IntType(i)]}
@@ -236,12 +236,12 @@ class LLVMContext_JIT(LLVMContext):
     def memory_lookup(self, func, addr, size):
         """Perform a memory lookup at @addr of size @size (in bit)"""
         builder = func.builder
-        fc_name = "vm_MEM_LOOKUP_%02d" % size
+        fc_name = "MEM_LOOKUP_%02d" % size
         fc_ptr = self.mod.get_global(fc_name)
         addr_casted = builder.zext(addr,
                                    LLVMType.IntType(64))
 
-        ret = builder.call(fc_ptr, [func.local_vars["vmmngr"],
+        ret = builder.call(fc_ptr, [func.local_vars["jitcpu"],
                                     addr_casted])
         return ret
 
@@ -249,10 +249,10 @@ class LLVMContext_JIT(LLVMContext):
         """Perform a memory write at @addr of size @size (in bit) with LLVM IR @value"""
         # Function call
         builder = func.builder
-        fc_name = "vm_MEM_WRITE_%02d" % size
+        fc_name = "MEM_WRITE_%02d" % size
         fc_ptr = self.mod.get_global(fc_name)
         dst_casted = builder.zext(addr, LLVMType.IntType(64))
-        builder.call(fc_ptr, [func.local_vars["vmmngr"],
+        builder.call(fc_ptr, [func.local_vars["jitcpu"],
                               dst_casted,
                               value])
 
@@ -836,14 +836,17 @@ class LLVMFunction():
 
     def from_bloc(self, bloc, final_expr):
         """Build the function from a bloc, with the dst equation.
-        Prototype : f(i8* vmcpu, i8* vmmngr)"""
+        Prototype : f(i8* jitcpu, i8* vmcpu, i8* vmmngr)"""
 
         # Build function signature
+        self.my_args.append((m2_expr.ExprId("jitcpu"),
+                             llvm_ir.PointerType(LLVMType.IntType(8)),
+                             "jitcpu"))
         self.my_args.append((m2_expr.ExprId("vmcpu"),
-                             llvm_ir.PointerType.pointer(LLVMType.IntType(8)),
+                             llvm_ir.PointerType(LLVMType.IntType(8)),
                              "vmcpu"))
         self.my_args.append((m2_expr.ExprId("vmmngr"),
-                             llvm_ir.PointerType.pointer(LLVMType.IntType(8)),
+                             llvm_ir.PointerType(LLVMType.IntType(8)),
                              "vmmngr"))
         self.ret_type = LLVMType.IntType(final_expr.size)
 
@@ -960,9 +963,12 @@ class LLVMFunction():
 
     def from_blocs(self, blocs):
         """Build the function from a list of bloc (irbloc instances).
-        Prototype : f(i8* vmcpu, i8* vmmngr)"""
+        Prototype : f(i8* jitcpu, i8* vmcpu, i8* vmmngr)"""
 
         # Build function signature
+        self.my_args.append((m2_expr.ExprId("jitcpu"),
+                             llvm_ir.PointerType(LLVMType.IntType(8)),
+                             "jitcpu"))
         self.my_args.append((m2_expr.ExprId("vmcpu"),
                              llvm_ir.PointerType(LLVMType.IntType(8)),
                              "vmcpu"))