diff options
| author | Camille Mougey <camille.mougey@cea.fr> | 2014-09-05 15:44:19 +0200 |
|---|---|---|
| committer | Camille Mougey <camille.mougey@cea.fr> | 2014-09-05 15:44:19 +0200 |
| commit | 60f793133e93e88e6c3c1d475e403c9542bc2e32 (patch) | |
| tree | 81bd187c135a3f12d14ed28e21b8000780aea1eb /miasm2/arch/x86/sem.py | |
| parent | 962a44eafce28be0146b46e097b24e3db1b78bf3 (diff) | |
| download | miasm-60f793133e93e88e6c3c1d475e403c9542bc2e32.tar.gz miasm-60f793133e93e88e6c3c1d475e403c9542bc2e32.zip | |
X86 sem: fix shr case when argument is 0 during runtime
Diffstat (limited to '')
| -rw-r--r-- | miasm2/arch/x86/sem.py | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/miasm2/arch/x86/sem.py b/miasm2/arch/x86/sem.py index aac61dbf..5dd1168a 100644 --- a/miasm2/arch/x86/sem.py +++ b/miasm2/arch/x86/sem.py @@ -410,21 +410,34 @@ def sar(ir, instr, a, b): def shr(ir, instr, a, b): - e = [] - # TODO FIX AS SAR! + shifter = get_shift(a, b) c = ExprOp('>>', a, shifter) + lbl_do = ExprId(ir.gen_label(), instr.mode) + lbl_skip = ExprId(ir.get_next_label(instr), instr.mode) + new_cf = ExprOp('>>', a, (shifter - ExprInt_from(a, 1)))[:1] - e.append(ExprAff(cf, ExprCond(shifter, - new_cf, - cf) - ) - ) - e.append(ExprAff(of, a.msb())) - e += update_flag_znp(c) - e.append(ExprAff(a, c)) - return e, [] + + e_do = [ + ExprAff(cf, new_cf), + ExprAff(of, ExprInt_from(of, 0)), + ExprAff(a, c), + ExprAff(ir.IRDst, lbl_skip) + ] + + e_do += update_flag_znp(c) + + # dont generate conditional shifter on constant + if isinstance(shifter, ExprInt): + if int(shifter.arg) != 0: + return e_do, [] + else: + return [], [] + + e = [] + e.append(ExprAff(ir.IRDst, ExprCond(shifter, lbl_do, lbl_skip))) + return e, [irbloc(lbl_do.name, [e_do])] def shrd_cl(ir, instr, a, b): |