diff options
Diffstat (limited to 'miasm2/jitter/codegen.py')
| -rw-r--r-- | miasm2/jitter/codegen.py | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/miasm2/jitter/codegen.py b/miasm2/jitter/codegen.py index 9d005451..09a6fecf 100644 --- a/miasm2/jitter/codegen.py +++ b/miasm2/jitter/codegen.py @@ -65,7 +65,7 @@ class CGen(object): CODE_CPU_EXCEPTION_POST_INSTR = r""" if (CPU_exception_flag) { - %s = %s; + %s = DST_value; BlockDst->address = DST_value; return JIT_RET_EXCEPTION; } @@ -75,7 +75,7 @@ class CGen(object): check_memory_breakpoint(&(jitcpu->pyvm->vm_mngr)); check_invalid_code_blocs(&(jitcpu->pyvm->vm_mngr)); if (VM_exception_flag) { - %s = %s; + %s = DST_value; BlockDst->address = DST_value; return JIT_RET_EXCEPTION; } @@ -106,6 +106,11 @@ class CGen(object): self.C_PC = self.id_to_c(self.PC) + @staticmethod + def label_to_jitlabel(lbl): + assert lbl.offset is not None + return "jitblock_%X" % lbl.offset + def dst_to_c(self, src): if not isinstance(src, m2_expr.Expr): src = m2_expr.ExprInt(src, self.PC.size) @@ -296,13 +301,12 @@ class CGen(object): '%s' % ret, '%s' % retb], dst2index - def gen_post_instr_checks(self, attrib, dst): + def gen_post_instr_checks(self, attrib): out = [] - dst = self.dst_to_c(dst) if attrib.mem_read | attrib.mem_write: - out += (self.CODE_VM_EXCEPTION_POST_INSTR % (self.C_PC, dst)).split('\n') + out += (self.CODE_VM_EXCEPTION_POST_INSTR % (self.C_PC)).split('\n') if attrib.set_exception or attrib.op_set_exception: - out += (self.CODE_CPU_EXCEPTION_POST_INSTR % (self.C_PC, dst)).split('\n') + out += (self.CODE_CPU_EXCEPTION_POST_INSTR % (self.C_PC)).split('\n') if attrib.mem_read | attrib.mem_write: out.append("reset_memory_access(&(jitcpu->pyvm->vm_mngr));") @@ -340,12 +344,12 @@ class CGen(object): # (consecutive instructions) lbl = self.ir_arch.symbol_pool.getby_offset_create(dst) out += self.gen_post_code(attrib) - out += self.gen_post_instr_checks(attrib, dst) - out.append('goto %s;' % lbl.name) + out += self.gen_post_instr_checks(attrib) + out.append('goto %s;' % self.label_to_jitlabel(lbl)) else: out += self.gen_post_code(attrib) out.append('BlockDst->address = DST_value;') - out += self.gen_post_instr_checks(attrib, dst) + out += self.gen_post_instr_checks(attrib) out.append('\t\treturn JIT_RET_NO_EXCEPTION;') return out @@ -497,7 +501,7 @@ class CGen(object): instr_offsets = [line.offset for line in block.lines] instr_offsets.append(self.get_block_post_label(block).offset) lbl_start = self.ir_arch.symbol_pool.getby_offset_create(instr_offsets[0]) - return (self.CODE_INIT % lbl_start.name).split("\n"), instr_offsets + return (self.CODE_INIT % self.label_to_jitlabel(lbl_start)).split("\n"), instr_offsets def gen_irblock(self, attrib, instr_offsets, instr, irblock): """ @@ -535,7 +539,7 @@ class CGen(object): lbl = self.get_block_post_label(block) dst = self.dst_to_c(lbl.offset) - code = self.CODE_RETURN_NO_EXCEPTION % (lbl.name, self.C_PC, dst, dst) + code = self.CODE_RETURN_NO_EXCEPTION % (self.label_to_jitlabel(lbl), self.C_PC, dst, dst) return code.split('\n') def gen_c(self, block, log_mn=False, log_regs=False): @@ -558,8 +562,12 @@ class CGen(object): self.ir_arch.irbloc_fix_regs_for_mode( irblock, self.ir_arch.attrib) - out.append("%-40s // %.16X %s" % - (str(irblock.label.name) + ":", instr.offset, instr)) + if irblock.label.offset is None: + out.append("%-40s // %.16X %s" % + (str(irblock.label.name) + ":", instr.offset, instr)) + else: + out.append("%-40s // %.16X %s" % + (self.label_to_jitlabel(irblock.label) + ":", instr.offset, instr)) if index == 0: out += self.gen_pre_code(attrib) out += self.gen_irblock(attrib, instr_offsets, instr, irblock) |