about summary refs log tree commit diff stats
path: root/miasm2/jitter
diff options
context:
space:
mode:
Diffstat (limited to 'miasm2/jitter')
-rw-r--r--miasm2/jitter/codegen.py10
-rw-r--r--miasm2/jitter/llvmconvert.py16
2 files changed, 18 insertions, 8 deletions
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))