about summary refs log tree commit diff stats
path: root/miasm2/arch/x86/sem.py
diff options
context:
space:
mode:
authorCamille Mougey <camille.mougey@cea.fr>2014-09-05 15:44:19 +0200
committerCamille Mougey <camille.mougey@cea.fr>2014-09-05 15:44:19 +0200
commit60f793133e93e88e6c3c1d475e403c9542bc2e32 (patch)
tree81bd187c135a3f12d14ed28e21b8000780aea1eb /miasm2/arch/x86/sem.py
parent962a44eafce28be0146b46e097b24e3db1b78bf3 (diff)
downloadmiasm-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.py35
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):