about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorserpilliere <devnull@localhost>2014-06-16 14:31:58 +0200
committerserpilliere <devnull@localhost>2014-06-16 14:31:58 +0200
commita69e745e8bd937789e527f8ce2cd986451819dd1 (patch)
treef5044cd63448ae8961dbd188971eb8a95f313278
parentc7165bd6bc403676d5fb6d1822776b69f0b1217e (diff)
downloadmiasm-a69e745e8bd937789e527f8ce2cd986451819dd1.tar.gz
miasm-a69e745e8bd937789e527f8ce2cd986451819dd1.zip
Arm sem: add mnemonics (tx to nsarlin)
TODO: fix cf shifters
-rw-r--r--miasm2/arch/arm/arch.py2
-rw-r--r--miasm2/arch/arm/sem.py39
2 files changed, 38 insertions, 3 deletions
diff --git a/miasm2/arch/arm/arch.py b/miasm2/arch/arm/arch.py
index 3c219710..b169d608 100644
--- a/miasm2/arch/arm/arch.py
+++ b/miasm2/arch/arm/arch.py
@@ -366,7 +366,7 @@ class instruction_armt(instruction_arm):
             self.args[0] = s
 
     def breakflow(self):
-        if self.name in ['B', 'BL', 'BLX',
+        if self.name in ['B', 'BX', 'BL', 'BLX',
                          'BEQ', 'BNE', 'BCS', 'BCC', 'BMI', 'BPL', 'BVS',
                          'BVC', 'BHI', 'BLS', 'BGE', 'BLT', 'BGT', 'BLE',
                          'CBZ', 'CBNZ']:
diff --git a/miasm2/arch/arm/sem.py b/miasm2/arch/arm/sem.py
index e23e2da8..4e932403 100644
--- a/miasm2/arch/arm/sem.py
+++ b/miasm2/arch/arm/sem.py
@@ -413,6 +413,17 @@ def mvns(ir, instr, a, b):
     return dst, e
 
 
+def neg(ir, instr, a, b):
+    e = []
+    c = - b
+    e.append(ExprAff(a, c))
+    dst = get_dst(a)
+    return dst, e
+
+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):
     e = []
     if x is None:
@@ -580,6 +591,10 @@ def ldrb(ir, instr, a, b):
     dst, e = st_ld_r(ir, instr, a, b, store=False, size=8, z_ext=True)
     return dst, e
 
+def ldrsb(ir, instr, a, b):
+    dst, e = st_ld_r(
+        ir, instr, a, b, store=False, size=8, s_ext=True, z_ext=False)
+    return dst, e
 
 def strb(ir, instr, a, b):
     dst, e = st_ld_r(ir, instr, a, b, store=True, size=8)
@@ -690,7 +705,7 @@ def und(ir, instr, a, b):
     e = []
     return None, e
 
-
+# TODO XXX implement correct CF for shifters
 def lsr(ir, instr, a, b, x):
     e = []
     c = b >> x
@@ -707,6 +722,20 @@ def lsrs(ir, instr, a, b, x):
     dst = get_dst(a)
     return dst, e
 
+def asr(ir, instr, a, b, x):
+    e = []
+    c = ExprOp("a>>", b, x)
+    e.append(ExprAff(a, c))
+    dst = get_dst(a)
+    return dst, e
+
+def asrs(ir, instr, a, b, x):
+    e = []
+    c = ExprOp("a>>", b, x)
+    e.append(ExprAff(a, c))
+    e += update_flag_logic(c)
+    dst = get_dst(a)
+    return dst, e
 
 def lsl(ir, instr, a, b, x):
     e = []
@@ -873,6 +902,7 @@ mnemo_condm0 = {'add': add,
                 'movt': movt,
                 'bic': bic,
                 'mvn': mvn,
+                'neg': neg,
 
                 'mul': mul,
                 'mla': mla,
@@ -888,6 +918,7 @@ mnemo_condm0 = {'add': add,
                 'ldrh': ldrh,
                 'strh': strh,
                 'ldrsh': ldrsh,
+                'ldsh': ldrsh,
                 }
 
 mnemo_condm1 = {'adds': add,
@@ -903,14 +934,16 @@ mnemo_condm1 = {'adds': add,
                 'movs': movs,
                 'bics': bics,
                 'mvns': mvns,
+                'negs': negs,
 
                 'muls': muls,
                 'mlas': mlas,
                 'blx': blx,
 
                 'ldrb': ldrb,
+                'ldrsb': ldrsb,
+                'ldsb': ldrsb,
                 'strb': strb,
-
                 }
 
 mnemo_condm2 = {'ldmia': ldmia,
@@ -942,6 +975,8 @@ mnemo_nocond = {'lsr': lsr,
                 'lsls': lsls,
                 'push': push,
                 'pop': pop,
+                'asr': asr,
+                'asrs': asrs,
                 'cbz': cbz,
                 'cbnz': cbnz,
                 }