about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--miasm2/arch/arm/sem.py258
1 files changed, 137 insertions, 121 deletions
diff --git a/miasm2/arch/arm/sem.py b/miasm2/arch/arm/sem.py
index b875da8f..8bf5d701 100644
--- a/miasm2/arch/arm/sem.py
+++ b/miasm2/arch/arm/sem.py
@@ -169,37 +169,37 @@ def get_dst(a):
 # instruction definition ##############
 
 
-def adc(ir, instr, a, b, x=None):
+def adc(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = b + x + cf.zeroExtend(32)
+    if c is None:
+        b, c = a, b
+    r = b + c + cf.zeroExtend(32)
     if instr.name == 'ADCS' and a != PC:
         e += update_flag_arith(r)
-        e += update_flag_add(b, x, r)
+        e += update_flag_add(b, c, r)
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def add(ir, instr, a, b, x=None):
+def add(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = b + x
+    if c is None:
+        b, c = a, b
+    r = b + c
     if instr.name == 'ADDS' and a != PC:
         e += update_flag_arith(r)
-        e += update_flag_add(b, x, r)
+        e += update_flag_add(b, c, r)
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def l_and(ir, instr, a, b, x=None):
+def l_and(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = b & x
+    if c is None:
+        b, c = a, b
+    r = b & c
     if instr.name == 'ANDS' and a != PC:
         e += update_flag_logic(r)
     e.append(ExprAff(a, r))
@@ -207,169 +207,169 @@ def l_and(ir, instr, a, b, x=None):
     return dst, e
 
 
-def sub(ir, instr, a, b, x=None):
+def sub(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = b - x
+    if c is None:
+        b, c = a, b
+    r = b - c
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def subs(ir, instr, a, b, x=None):
+def subs(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = b - x
+    if c is None:
+        b, c = a, b
+    r = b - c
     e += update_flag_arith(r)
-    e += update_flag_sub(b, x, r)
+    e += update_flag_sub(b, c, r)
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def eor(ir, instr, a, b, x=None):
+def eor(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = b ^ x
+    if c is None:
+        b, c = a, b
+    r = b ^ c
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def eors(ir, instr, a, b, x=None):
+def eors(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = b ^ x
+    if c is None:
+        b, c = a, b
+    r = b ^ c
     e += update_flag_logic(r)
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def rsb(ir, instr, a, b, x=None):
+def rsb(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = x - b
+    if c is None:
+        b, c = a, b
+    r = c - b
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def rsbs(ir, instr, a, b, x=None):
+def rsbs(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = x - b
+    if c is None:
+        b, c = a, b
+    r = c - b
     e += update_flag_arith(r)
-    e += update_flag_sub(b, x, r)
+    e += update_flag_sub(b, c, r)
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def sbc(ir, instr, a, b, x=None):
+def sbc(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = (b + cf.zeroExtend(32)) - (x + ExprInt32(1))
+    if c is None:
+        b, c = a, b
+    r = (b + cf.zeroExtend(32)) - (c + ExprInt32(1))
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def sbcs(ir, instr, a, b, x=None):
+def sbcs(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = (b + cf.zeroExtend(32)) - (x + ExprInt32(1))
+    if c is None:
+        b, c = a, b
+    r = (b + cf.zeroExtend(32)) - (c + ExprInt32(1))
     e += update_flag_arith(r)
-    e += update_flag_sub(b, x, r)
+    e += update_flag_sub(b, c, r)
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def rsc(ir, instr, x, a, b):
+def rsc(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = (x + cf.zeroExtend(32)) - (b + ExprInt32(1))
+    if c is None:
+        b, c = a, b
+    r = (c + cf.zeroExtend(32)) - (b + ExprInt32(1))
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def rscs(ir, instr, x, a, b):
+def rscs(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = (x + cf.zeroExtend(32)) - (b + ExprInt32(1))
+    if c is None:
+        b, c = a, b
+    r = (c + cf.zeroExtend(32)) - (b + ExprInt32(1))
     e.append(ExprAff(a, r))
     e += update_flag_arith(r)
-    e += update_flag_sub(x, b, r)
+    e += update_flag_sub(c, b, r)
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def tst(ir, instr, a, b, x=None):
+def tst(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = b & x
+    if c is None:
+        b, c = a, b
+    r = b & c
     e += update_flag_logic(r)
     return None, e
 
 
-def teq(ir, instr, a, b, x=None):
+def teq(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = b ^ x
+    if c is None:
+        b, c = a, b
+    r = b ^ c
     e += update_flag_logic(r)
     return None, e
 
 
-def l_cmp(ir, instr, a, b, x=None):
+def l_cmp(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = b - x
+    if c is None:
+        b, c = a, b
+    r = b - c
     e += update_flag_arith(r)
-    e += update_flag_sub(x, b, r)
+    e += update_flag_sub(c, b, r)
     return None, e
 
 
-def cmn(ir, instr, a, b, x=None):
+def cmn(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = b + x
+    if c is None:
+        b, c = a, b
+    r = b + c
     e += update_flag_arith(r)
-    e += update_flag_add(b, x, r)
+    e += update_flag_add(b, c, r)
     return None, e
 
 
-def orr(ir, instr, a, b, x=None):
+def orr(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = b | x
+    if c is None:
+        b, c = a, b
+    r = b | c
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def orrs(ir, instr, a, b, x=None):
+def orrs(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = b | x
+    if c is None:
+        b, c = a, b
+    r = b | c
     e += update_flag_logic(r)
     e.append(ExprAff(a, r))
     dst = get_dst(a)
@@ -424,58 +424,62 @@ def negs(ir, instr, a, b):
     dst, e = subs(ir, instr, a, ExprInt_from(b, 0), b)
     return dst, e
 
-def bic(ir, instr, a, b, x=None):
+def bic(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = b & (x ^ ExprInt(uint32(-1)))
+    if c is None:
+        b, c = a, b
+    r = b & (c ^ ExprInt(uint32(-1)))
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def bics(ir, instr, a, b, x=None):
+def bics(ir, instr, a, b, c=None):
     e = []
-    if x is None:
-        b, x = a, b
-    r = b & (x ^ ExprInt(uint32(-1)))
+    if c is None:
+        b, c = a, b
+    r = b & (c ^ ExprInt(uint32(-1)))
     e += update_flag_logic(r)
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def mla(ir, instr, x, a, b, c):
+def mla(ir, instr, a, b, c, d):
     e = []
-    d = (a * b) + c
-    e.append(ExprAff(x, d))
-    dst = get_dst(x)
+    r = (b * c) + d
+    e.append(ExprAff(a, r))
+    dst = get_dst(a)
     return dst, e
 
 
-def mlas(ir, instr, x, a, b, c):
+def mlas(ir, instr, a, b, c, d):
     e = []
-    d = (a * b) + c
-    e += update_flag_zn(d)
-    e.append(ExprAff(x, d))
-    dst = get_dst(x)
+    r = (b * c) + d
+    e += update_flag_zn(r)
+    e.append(ExprAff(a, r))
+    dst = get_dst(a)
     return dst, e
 
 
-def mul(ir, instr, x, a, b):
+def mul(ir, instr, a, b, c = None):
     e = []
-    r = a * b
-    e.append(ExprAff(x, r))
-    dst = get_dst(x)
+    if c is None:
+        b, c = a, b
+    r = b * c
+    e.append(ExprAff(a, r))
+    dst = get_dst(a)
     return dst, e
 
 
-def muls(ir, instr, x, a, b):
+def muls(ir, instr, a, b, c = None):
     e = []
-    r = a * b
+    if c is None:
+        b, c = a, b
+    r = b * c
     e += update_flag_zn(r)
-    e.append(ExprAff(x, r))
-    dst = get_dst(x)
+    e.append(ExprAff(a, r))
+    dst = get_dst(a)
     return dst, e
 
 
@@ -706,48 +710,60 @@ def und(ir, instr, a, b):
     return None, e
 
 # TODO XXX implement correct CF for shifters
-def lsr(ir, instr, a, b, x):
+def lsr(ir, instr, a, b, c = None):
     e = []
-    r = b >> x
+    if c is None:
+        b, c = a, b
+    r = b >> c
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def lsrs(ir, instr, a, b, x):
+def lsrs(ir, instr, a, b, c = None):
     e = []
-    r = b >> x
+    if c is None:
+        b, c = a, b
+    r = b >> c
     e.append(ExprAff(a, r))
     e += update_flag_logic(r)
     dst = get_dst(a)
     return dst, e
 
-def asr(ir, instr, a, b, x):
+def asr(ir, instr, a, b, c=None):
     e = []
-    r = ExprOp("a>>", b, x)
+    if c is None:
+        b, c = a, b
+    r = ExprOp("a>>", b, c)
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
-def asrs(ir, instr, a, b, x):
+def asrs(ir, instr, a, b, c):
     e = []
-    r = ExprOp("a>>", b, x)
+    if c is None:
+        b, c = a, b
+    r = ExprOp("a>>", b, c)
     e.append(ExprAff(a, r))
     e += update_flag_logic(r)
     dst = get_dst(a)
     return dst, e
 
-def lsl(ir, instr, a, b, x):
+def lsl(ir, instr, a, b, c = None):
     e = []
-    r = b << x
+    if c is None:
+        b, c = a, b
+    r = b << c
     e.append(ExprAff(a, r))
     dst = get_dst(a)
     return dst, e
 
 
-def lsls(ir, instr, a, b, x):
+def lsls(ir, instr, a, b, c = None):
     e = []
-    r = b << x
+    if c is None:
+        b, c = a, b
+    r = b << c
     e.append(ExprAff(a, r))
     e += update_flag_logic(r)
     dst = get_dst(a)