about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--miasm2/arch/mep/jit.py4
-rw-r--r--miasm2/arch/x86/jit.py8
-rw-r--r--miasm2/jitter/codegen.py10
-rw-r--r--miasm2/jitter/llvmconvert.py16
4 files changed, 26 insertions, 12 deletions
diff --git a/miasm2/arch/mep/jit.py b/miasm2/arch/mep/jit.py
index 913d508f..6c0e6ff5 100644
--- a/miasm2/arch/mep/jit.py
+++ b/miasm2/arch/mep/jit.py
@@ -43,11 +43,11 @@ class mep_CGen(CGen):
 
         return out
 
-    def gen_post_code(self, attrib):
+    def gen_post_code(self, attrib, pc_value):
         """Generate C code inserted after the current bloc"""
 
         # Call the base class method
-        out = super(mep_CGen, self).gen_post_code(attrib)
+        out = super(mep_CGen, self).gen_post_code(attrib, pc_value)
 
         # Implement the *REPEAT instructions logics
         tmp = r"""
diff --git a/miasm2/arch/x86/jit.py b/miasm2/arch/x86/jit.py
index d775cff5..f0a9875e 100644
--- a/miasm2/arch/x86/jit.py
+++ b/miasm2/arch/x86/jit.py
@@ -20,16 +20,20 @@ class x86_32_CGen(CGen):
         self.translator = TranslatorC(self.ir_arch.loc_db)
         self.init_arch_C()
 
-    def gen_post_code(self, attrib):
+    def gen_post_code(self, attrib, pc_value):
         out = []
         if attrib.log_regs:
+            # Update PC for dump_gpregs
+            out.append("%s = %s;" % (self.C_PC, pc_value))
             out.append('dump_gpregs_32(jitcpu->cpu);')
         return out
 
 class x86_64_CGen(x86_32_CGen):
-    def gen_post_code(self, attrib):
+    def gen_post_code(self, attrib, pc_value):
         out = []
         if attrib.log_regs:
+            # Update PC for dump_gpregs
+            out.append("%s = %s;" % (self.C_PC, pc_value))
             out.append('dump_gpregs_64(jitcpu->cpu);')
         return out
 
diff --git a/miasm2/jitter/codegen.py b/miasm2/jitter/codegen.py
index 32af29a2..a9405472 100644
--- a/miasm2/jitter/codegen.py
+++ b/miasm2/jitter/codegen.py
@@ -392,11 +392,13 @@ class CGen(object):
             )
         return out
 
-    def gen_post_code(self, attrib):
+    def gen_post_code(self, attrib, pc_value):
         """Callback to generate code AFTER the instruction execution
         @attrib: Attributes instance"""
         out = []
         if attrib.log_regs:
+            # Update PC for dump_gpregs
+            out.append("%s = %s;" % (self.C_PC, pc_value))
             out.append('dump_gpregs(jitcpu->cpu);')
         return out
 
@@ -408,7 +410,7 @@ class CGen(object):
 
         out = []
         if isinstance(dst, Expr):
-            out += self.gen_post_code(attrib)
+            out += self.gen_post_code(attrib, "DST_value")
             out.append('BlockDst->address = DST_value;')
             out += self.gen_post_instr_checks(attrib)
             out.append('\t\treturn JIT_RET_NO_EXCEPTION;')
@@ -423,11 +425,11 @@ class CGen(object):
             offset in instr_offsets):
             # Only generate goto for next instructions.
             # (consecutive instructions)
-            out += self.gen_post_code(attrib)
+            out += self.gen_post_code(attrib, "0x%x" % offset)
             out += self.gen_post_instr_checks(attrib)
             out.append('goto %s;' % dst)
         else:
-            out += self.gen_post_code(attrib)
+            out += self.gen_post_code(attrib, "0x%x" % offset)
             out.append('BlockDst->address = DST_value;')
             out += self.gen_post_instr_checks(attrib)
             out.append('\t\treturn JIT_RET_NO_EXCEPTION;')
diff --git a/miasm2/jitter/llvmconvert.py b/miasm2/jitter/llvmconvert.py
index 6f024c1e..37ce8d52 100644
--- a/miasm2/jitter/llvmconvert.py
+++ b/miasm2/jitter/llvmconvert.py
@@ -1292,8 +1292,14 @@ class LLVMFunction(object):
             self.printf("%.8X %s\n" % (instr_attrib.instr.offset,
                                        instr_attrib.instr.to_string(loc_db)))
 
-    def gen_post_code(self, attributes):
+    def gen_post_code(self, attributes, pc_value):
         if attributes.log_regs:
+            # Update PC for dump_gpregs
+            PC = self.llvm_context.PC
+            t_size = LLVMType.IntType(PC.size)
+            dst = self.builder.zext(t_size(pc_value), LLVMType.IntType(PC.size))
+            self.affect(dst, PC)
+
             fc_ptr = self.mod.get_global(self.llvm_context.logging_func)
             self.builder.call(fc_ptr, [self.local_vars["vmcpu"]])
 
@@ -1353,8 +1359,10 @@ class LLVMFunction(object):
         # We are no longer in the main stream, deactivate cache
         self.main_stream = False
 
+        offset = None
         if isinstance(dst, ExprInt):
-            loc_key = self.llvm_context.ir_arch.loc_db.get_or_create_offset_location(int(dst))
+            offset = int(dst)
+            loc_key = self.llvm_context.ir_arch.loc_db.get_or_create_offset_location(offset)
             dst = ExprLoc(loc_key, dst.size)
 
         if isinstance(dst, ExprLoc):
@@ -1371,7 +1379,7 @@ class LLVMFunction(object):
                 if (offset in instr_offsets and
                     offset > attrib.instr.offset):
                     # forward local jump (ie. next instruction)
-                    self.gen_post_code(attrib)
+                    self.gen_post_code(attrib, offset)
                     self.gen_post_instr_checks(attrib, offset)
                     self.builder.branch(bbl)
                     return
@@ -1389,7 +1397,7 @@ class LLVMFunction(object):
         if dst.type.width != PC.size:
             dst = self.builder.zext(dst, LLVMType.IntType(PC.size))
 
-        self.gen_post_code(attrib)
+        self.gen_post_code(attrib, offset)
         self.affect(dst, PC)
         self.gen_post_instr_checks(attrib, dst)
         self.affect(self.add_ir(ExprInt(0, 8)), ExprId("status", 32))