diff options
| -rw-r--r-- | miasm2/arch/x86/sem.py | 77 | ||||
| -rw-r--r-- | test/test_all.py | 3 |
2 files changed, 30 insertions, 50 deletions
diff --git a/miasm2/arch/x86/sem.py b/miasm2/arch/x86/sem.py index 51bf5d3b..f1784692 100644 --- a/miasm2/arch/x86/sem.py +++ b/miasm2/arch/x86/sem.py @@ -2574,6 +2574,7 @@ def daa(ir, instr): al_c1 + m2_expr.ExprInt8(0x60), al_c1) e.append(m2_expr.ExprAff(r_al, new_al)) + e += update_flag_znp(new_al) return e, [] def das(ir, instr): @@ -2604,6 +2605,7 @@ def das(ir, instr): al_c1 - m2_expr.ExprInt8(0x60), al_c1) e.append(m2_expr.ExprAff(r_al, new_al)) + e += update_flag_znp(new_al) return e, [] @@ -2617,6 +2619,7 @@ def aam(ir, instr, a): ]) e += [m2_expr.ExprAff(mRAX[instr.mode], newEAX)] e += update_flag_arith(newEAX) + e.append(m2_expr.ExprAff(af, m2_expr.ExprInt1(0))) return e, [] @@ -2632,65 +2635,41 @@ def aad(ir, instr, a): ]) e += [m2_expr.ExprAff(mRAX[instr.mode], newEAX)] e += update_flag_arith(newEAX) + e.append(m2_expr.ExprAff(af, m2_expr.ExprInt1(0))) return e, [] -def aaa(ir, instr, ): +def _tpl_aaa(ir, instr, op): + """Templating for aaa, aas with operation @op + @op: operation to apply + """ e = [] - c = (mRAX[instr.mode][:8] & m2_expr.ExprInt8(0xf)) - m2_expr.ExprInt8(9) - - c = m2_expr.ExprCond(c.msb(), - m2_expr.ExprInt1(0), - m2_expr.ExprInt1(1)) & \ - m2_expr.ExprCond(c, - m2_expr.ExprInt1(1), - m2_expr.ExprInt1(0)) - - c |= af & m2_expr.ExprInt1(1) + r_al = mRAX[instr.mode][:8] + r_ah = mRAX[instr.mode][8:16] + r_ax = mRAX[instr.mode][:16] + i0 = m2_expr.ExprInt1(0) + i1 = m2_expr.ExprInt1(1) + # cond: if (al & 0xf) > 9 OR af == 1 + cond = (r_al & m2_expr.ExprInt8(0xf)) - m2_expr.ExprInt8(9) + cond = ~cond.msb() & m2_expr.ExprCond(cond, i1, i0) + cond |= af & i1 + + to_add = m2_expr.ExprInt(0x106, size=r_ax.size) + new_ax = m2_expr.ExprOp(op, r_ax, to_add) & m2_expr.ExprInt(0xff0f, + size=r_ax.size) # set AL - m_al = m2_expr.ExprCond(c, - (mRAX[instr.mode][:8] + m2_expr.ExprInt8(6)) & \ - m2_expr.ExprInt8(0xF), - mRAX[instr.mode][:8] & m2_expr.ExprInt8(0xF)) - m_ah = m2_expr.ExprCond(c, - mRAX[instr.mode][8:16] + m2_expr.ExprInt8(1), - mRAX[instr.mode][8:16]) - - e.append(m2_expr.ExprAff(mRAX[instr.mode], m2_expr.ExprCompose([ - (m_al, 0, 8), (m_ah, 8, 16), - (mRAX[instr.mode][16:], 16, mRAX[instr.mode].size)]))) - e.append(m2_expr.ExprAff(af, c)) - e.append(m2_expr.ExprAff(cf, c)) + e.append(m2_expr.ExprAff(r_ax, m2_expr.ExprCond(cond, new_ax, r_ax))) + e.append(m2_expr.ExprAff(af, cond)) + e.append(m2_expr.ExprAff(cf, cond)) return e, [] -def aas(ir, instr, ): - e = [] - c = (mRAX[instr.mode][:8] & m2_expr.ExprInt8(0xf)) - m2_expr.ExprInt8(9) +def aaa(ir, instr): + return _tpl_aaa(ir, instr, "+") - c = m2_expr.ExprCond(c.msb(), - m2_expr.ExprInt1(0), - m2_expr.ExprInt1(1)) & \ - m2_expr.ExprCond(c, - m2_expr.ExprInt1(1), - m2_expr.ExprInt1(0)) - c |= af & m2_expr.ExprInt1(1) - # set AL - m_al = m2_expr.ExprCond(c, - (mRAX[instr.mode][:8] - m2_expr.ExprInt8(6)) & \ - m2_expr.ExprInt8(0xF), - mRAX[instr.mode][:8] & m2_expr.ExprInt8(0xF)) - m_ah = m2_expr.ExprCond(c, - mRAX[instr.mode][8:16] - m2_expr.ExprInt8(1), - mRAX[instr.mode][8:16]) - - e.append(m2_expr.ExprAff(mRAX[instr.mode], m2_expr.ExprCompose([ - (m_al, 0, 8), (m_ah, 8, 16), - (mRAX[instr.mode][16:], 16, mRAX[instr.mode].size)]))) - e.append(m2_expr.ExprAff(af, c)) - e.append(m2_expr.ExprAff(cf, c)) - return e, [] +def aas(ir, instr): + return _tpl_aaa(ir, instr, "-") def bsr_bsf(ir, instr, a, b, op_name): diff --git a/test/test_all.py b/test/test_all.py index 6288466a..fe9c6880 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -107,8 +107,9 @@ QEMU_TESTS = { "lea": ("tcc", "python"), "self_modifying_code": ("tcc", "python"), "conv": ("tcc", "python"), + "bcd": ("tcc", "python"), # Unsupported - # "floats", "bcd", "xchg", "string", "misc", "segs", "code16", "exceptions", + # "floats", "xchg", "string", "misc", "segs", "code16", "exceptions", # "single_step" } |