about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--miasm2/arch/arm/arch.py252
-rw-r--r--miasm2/arch/arm/sem.py1
-rw-r--r--miasm2/arch/msp430/arch.py61
-rw-r--r--miasm2/arch/sh4/arch.py70
-rw-r--r--miasm2/arch/x86/arch.py88
-rw-r--r--miasm2/core/cpu.py52
6 files changed, 248 insertions, 276 deletions
diff --git a/miasm2/arch/arm/arch.py b/miasm2/arch/arm/arch.py
index b7cf48bf..22932042 100644
--- a/miasm2/arch/arm/arch.py
+++ b/miasm2/arch/arm/arch.py
@@ -201,6 +201,16 @@ def deref2expr_pre(s, l, t):
         raise NotImplementedError('len(t) > 2')
 
 
+def deref2expr_pre_mem(s, l, t):
+    t = t[0]
+    if len(t) == 1:
+        return ExprMem(ExprOp("preinc", t[0], ExprInt32(0)))
+    elif len(t) == 2:
+        return ExprMem(ExprOp("preinc", t[0], t[1]))
+    else:
+        raise NotImplementedError('len(t) > 2')
+
+
 def deref2expr_post(s, l, t):
     t = t[0]
     return ExprOp("postinc", t[0], t[1])
@@ -209,8 +219,8 @@ def deref2expr_post(s, l, t):
 def deref_wb(s, l, t):
     t = t[0]
     if t[-1] == '!':
-        return ExprOp('wback', *t[:-1])
-    return t[0]
+        return ExprMem(ExprOp('wback', *t[:-1]))
+    return ExprMem(t[0])
 
 # shift_off.setParseAction(deref_off)
 deref_nooff = Group(
@@ -268,6 +278,78 @@ class instruction_arm(instruction):
     def __init__(self, *args, **kargs):
         super(instruction_arm, self).__init__(*args, **kargs)
 
+    @staticmethod
+    def arg2str(e, pos = None):
+        wb = False
+        if isinstance(e, ExprId) or isinstance(e, ExprInt):
+            return str(e)
+        if isinstance(e, ExprOp) and e.op in expr2shift_dct:
+            if len(e.args) == 1:
+                return '%s %s' % (e.args[0], expr2shift_dct[e.op])
+            elif len(e.args) == 2:
+                return '%s %s %s' % (e.args[0], expr2shift_dct[e.op], e.args[1])
+            else:
+                raise NotImplementedError('zarb arg2str')
+
+
+        sb = False
+        if isinstance(e, ExprOp) and e.op == "sbit":
+            sb = True
+            e = e.args[0]
+        if isinstance(e, ExprOp) and e.op == "reglist":
+            o = [gpregs.expr.index(x) for x in e.args]
+            out = reglist2str(o)
+            if sb:
+                out += "^"
+            return out
+
+
+        if isinstance(e, ExprOp) and e.op == 'wback':
+            wb = True
+            e = e.args[0]
+        if isinstance(e, ExprId):
+            out = str(e)
+            if wb:
+                out += "!"
+            return out
+
+        if not isinstance(e, ExprMem):
+            return str(e)
+
+        e = e.arg
+        if isinstance(e, ExprOp) and e.op == 'wback':
+            wb = True
+            e = e.args[0]
+
+
+        if isinstance(e, ExprId):
+            r, s = e, None
+        elif len(e.args) == 1 and isinstance(e.args[0], ExprId):
+            r, s = e.args[0], None
+        elif isinstance(e.args[0], ExprId):
+            r, s = e.args[0], e.args[1]
+        else:
+            r, s = e.args[0].args
+        if isinstance(s, ExprOp) and s.op in expr2shift_dct:
+            s = ' '.join([str(x)
+                for x in s.args[0], expr2shift_dct[s.op], s.args[1]])
+
+        if isinstance(e, ExprOp) and e.op == 'postinc':
+            o = '[%s]' % r
+            if s and not (isinstance(s, ExprInt) and s.arg == 0):
+                o += ', %s' % s
+        else:
+            if s and not (isinstance(s, ExprInt) and s.arg == 0):
+                o = '[%s, %s]' % (r, s)
+            else:
+                o = '[%s]' % (r)
+
+
+        if wb:
+            o += "!"
+        return o
+
+
     def dstflow(self):
         if self.name.startswith('BIC'):
             return False
@@ -636,12 +718,6 @@ class arm_reg_wb(arm_reg):
     reg_info = gpregs
     parser = gpregs_wb
 
-    @staticmethod
-    def arg2str(e):
-        if isinstance(e, ExprId):
-            return '%s' % e
-        return "%s!" % e.args[0]
-
     def decode(self, v):
         v = v & self.lmask
         e = self.reg_info.expr[v]
@@ -752,12 +828,15 @@ class arm_imm8_12(m_arg):
             e = ExprOp('postinc', self.parent.rn.expr, e)
         if self.parent.wback.value == 1:
             e = ExprOp('wback', e)
-        self.expr = e
+        self.expr = ExprMem(e)
         return True
 
     def encode(self):
         self.parent.updown.value = 1
         e = self.expr
+        if not isinstance(e, ExprMem):
+            return False
+        e = e.arg
         if isinstance(e, ExprOp) and e.op == 'wback':
             self.parent.wback.value = 1
             e = e.args[0]
@@ -789,38 +868,6 @@ class arm_imm8_12(m_arg):
         self.value = v
         return True
 
-    @staticmethod
-    def arg2str(e):
-        wb = False
-        if isinstance(e, ExprOp) and e.op == 'wback':
-            wb = True
-            e = e.args[0]
-        if isinstance(e, ExprId):
-            r = e
-            s = None
-        else:
-            if len(e.args) == 1 and isinstance(e.args[0], ExprId):
-                r, s = e.args[0], None
-            elif isinstance(e.args[0], ExprId):
-                r, s = e.args[0], e.args[1]
-            else:
-                r, s = e.args[0].args
-            if isinstance(s, ExprOp) and s.op in expr2shift_dct:
-                s = ' '.join([str(x)
-                    for x in s.args[0], expr2shift_dct[s.op], s.args[1]])
-        if isinstance(e, ExprOp) and e.op == 'preinc':
-            if s and not (isinstance(s, ExprInt) and s.arg == 0):
-                o = '[%s, %s]' % (r, s)
-            else:
-                o = '[%s]' % (r)
-        else:
-            o = '[%s]' % r
-            if s and not (isinstance(s, ExprInt) and s.arg == 0):
-                o += ', %s' % s
-        if wb:
-            o += "!"
-        return o
-
 
 class arm_imm_4_12(m_arg):
     parser = base_expr
@@ -937,17 +984,6 @@ class arm_op2(m_arg):
             ((((amount << 2) | shift_type) << 1) | shift_kind) << 4) | rm
         return True
 
-    @staticmethod
-    def arg2str(e):
-        if isinstance(e, ExprInt) or isinstance(e, ExprId):
-            return str(e)
-        if isinstance(e, ExprOp) and e.op in expr2shift_dct:
-            if len(e.args) == 1:
-                return '%s %s' % (e.args[0], expr2shift_dct[e.op])
-            elif len(e.args) == 2:
-                return '%s %s %s' % (e.args[0], expr2shift_dct[e.op], e.args[1])
-        return str(e)
-
 # op2imm + rn
 
 
@@ -973,7 +1009,7 @@ class arm_op2imm(arm_imm8_12):
                 e = ExprOp('postinc', self.parent.rn.expr, ExprInt32(imm))
             if self.parent.wback.value == 1:
                 e = ExprOp('wback', e)
-            self.expr = e
+            self.expr = ExprMem(e)
             return True
         rm = val & 0xf
         shift = val >> 4
@@ -1000,7 +1036,7 @@ class arm_op2imm(arm_imm8_12):
             e = ExprOp('postinc', self.parent.rn.expr, a)
         if self.parent.wback.value == 1:
             e = ExprOp('wback', e)
-        self.expr = e
+        self.expr = ExprMem(e)
         return True
 
     def encode(self):
@@ -1008,6 +1044,8 @@ class arm_op2imm(arm_imm8_12):
         self.parent.updown.value = 1
 
         e = self.expr
+        assert(isinstance(e, ExprMem))
+        e = e.arg
         if e.op == 'wback':
             self.parent.wback.value = 1
             e = e.args[0]
@@ -1112,19 +1150,6 @@ class arm_rlist(m_arg):
         self.expr = e
         return True
 
-    @staticmethod
-    def arg2str(e):
-        o = []
-        sb = False
-        if isinstance(e, ExprOp) and e.op == "sbit":
-            sb = True
-            e = e.args[0]
-        o = [gpregs.expr.index(x) for x in e.args]
-        out = reglist2str(o)
-        if sb:
-            out += "^"
-        return out
-
 
 class updown_b_nosp_mn(bs_mod_name):
     mn_mod = ['D', 'I']
@@ -1280,7 +1305,7 @@ class arm_immed(m_arg):
             e = ExprOp('postinc', self.parent.rn.expr, imm)
         if self.parent.wback.value == 1:
             e = ExprOp('wback', e)
-        self.expr = e
+        self.expr = ExprMem(e)
 
         return True
 
@@ -1288,6 +1313,9 @@ class arm_immed(m_arg):
         self.parent.immop.value = 1
         self.parent.updown.value = 1
         e = self.expr
+        if not isinstance(e, ExprMem):
+            return False
+        e = e.arg
         if isinstance(e, ExprOp) and e.op == 'wback':
             self.parent.wback.value = 1
             e = e.args[0]
@@ -1329,10 +1357,6 @@ class arm_immed(m_arg):
         else:
             raise ValueError('e should be int: %r' % e)
 
-    @staticmethod
-    def arg2str(e):
-        return arm_imm8_12.arg2str(e)
-
 immedH = bs(l=4, fname='immedH')
 immedL = bs(l=4, cls=(arm_immed, m_arg), fname='immedL')
 hb = bs(l=1)
@@ -1503,11 +1527,11 @@ gpregs_sppc = reg_info(regs_str[-1:] + regs_str[13:14],
                        regs_expr[-1:] + regs_expr[13:14])
 
 deref_low = Group(LBRACK + gpregs_l.parser + Optional(
-    COMMA + shift_off) + RBRACK).setParseAction(deref2expr_pre)
+    COMMA + shift_off) + RBRACK).setParseAction(deref2expr_pre_mem)
 deref_pc = Group(LBRACK + gpregs_pc.parser + Optional(
-    COMMA + shift_off) + RBRACK).setParseAction(deref2expr_pre)
+    COMMA + shift_off) + RBRACK).setParseAction(deref2expr_pre_mem)
 deref_sp = Group(LBRACK + gpregs_sp.parser + COMMA +
-                 shift_off + RBRACK).setParseAction(deref2expr_pre)
+                 shift_off + RBRACK).setParseAction(deref2expr_pre_mem)
 
 gpregs_l_wb = Group(
     gpregs_l.parser + Optional('!')).setParseAction(parsegpreg_wb)
@@ -1549,37 +1573,46 @@ class arm_offreg(m_arg):
         self.value = v
         return True
 
-    @staticmethod
-    def arg2str(e):
-        if isinstance(e, ExprId):
-            o = str(e)
-        elif (len(e.args) == 2 and
-            isinstance(e.args[1], ExprInt) and e.args[1].arg == 0):
-            o = "%s" % e.args[0]
-        else:
-            o = '%s, %s' % (e.args[0], e.args[1])
-        return '[%s]' % o
-
 
 class arm_offpc(arm_offreg):
     off_reg = regs_expr[15]
-    def decodeval(self, v):
-        return v << 2
 
-    def encodeval(self, v):
-        return v >> 2
+    def decode(self, v):
+        v = v & self.lmask
+        v <<= 2
+        if v:
+            self.expr = ExprMem(self.off_reg + ExprInt32(v))
+        else:
+            self.expr = ExprMem(self.off_reg)
 
+        e = self.expr.arg
+        if isinstance(e, ExprOp) and e.op == 'wback':
+            self.parent.wback.value = 1
+            e = e.args[0]
+        return True
 
+    def encode(self):
+        e = self.expr
+        if not isinstance(e, ExprMem):
+            return False
+        e = e.arg
+        if not (isinstance(e, ExprOp) and e.op == "preinc"):
+            log.debug('cannot encode %r' % e)
+            return False
+        if e.args[0] != self.off_reg:
+            log.debug('cannot encode reg %r' % e.args[0])
+            return False
+        v = int(e.args[1].arg)
+        v >>= 2
+        self.value = v
+        return True
 
-class arm_offsp(arm_offreg):
-    parser = deref_sp
-    off_reg = regs_expr[13]
 
-    def decodeval(self, v):
-        return v << 2
 
-    def encodeval(self, v):
-        return v >> 2
+
+class arm_offsp(arm_offpc):
+    parser = deref_sp
+    off_reg = regs_expr[13]
 
 
 class arm_offspc(arm_offs):
@@ -1634,11 +1667,14 @@ class arm_deref(m_arg):
         v = v & self.lmask
         rbase = regs_expr[v]
         e = ExprOp('preinc', rbase, self.parent.off.expr)
-        self.expr = e
+        self.expr = ExprMem(e)
         return True
 
     def encode(self):
         e = self.expr
+        if not isinstance(e, ExprMem):
+            return False
+        e = e.arg
         if not (isinstance(e, ExprOp) and e.op == 'preinc'):
             log.debug('cannot encode %r' % e)
             return False
@@ -1656,13 +1692,6 @@ class arm_deref(m_arg):
             return False
         return True
 
-    @staticmethod
-    def arg2str(e):
-        if not (isinstance(e, ExprOp) and e.op == 'preinc'):
-            log.debug('cannot str %r' % e)
-            raise ValueError()
-        return '[%s, %s]' % (e.args[0], e.args[1])
-
 
 class arm_offbw(imm_noarg):
 
@@ -1728,13 +1757,6 @@ class armt_rlist(m_arg):
         self.expr = e
         return True
 
-    @staticmethod
-    def arg2str(e):
-        o = []
-        o = [gpregs.expr.index(x) for x in e.args]
-        out = reglist2str(o)
-        return out
-
 
 class armt_rlist_pclr(armt_rlist):
 
@@ -2020,12 +2042,6 @@ class armt_gpreg_rm_shift_off(arm_reg):
         self.parent.imm5_3.value = i >> 2
         return True
 
-    @staticmethod
-    def arg2str(e):
-        if isinstance(e, ExprId):
-            return str(e)
-        return str(e)[1:-1]
-
 rn_nosppc = bs(l=4, cls=(arm_gpreg_nosppc,), fname="rn")
 rd_nosppc = bs(l=4, cls=(arm_gpreg_nosppc,), fname="rd")
 rm_sh = bs(l=4, cls=(armt_gpreg_rm_shift_off,), fname="rm")
diff --git a/miasm2/arch/arm/sem.py b/miasm2/arch/arm/sem.py
index 9608c1f0..498017c9 100644
--- a/miasm2/arch/arm/sem.py
+++ b/miasm2/arch/arm/sem.py
@@ -516,6 +516,7 @@ def st_ld_r(ir, instr, a, b, store=False, size=32, s_ext=False, z_ext=False):
     wb = False
     b = b.copy()
     postinc = False
+    b = b.arg
     if isinstance(b, ExprOp):
         if b.op == "wback":
             wb = True
diff --git a/miasm2/arch/msp430/arch.py b/miasm2/arch/msp430/arch.py
index 74cce9ea..ac62dd3e 100644
--- a/miasm2/arch/msp430/arch.py
+++ b/miasm2/arch/msp430/arch.py
@@ -115,6 +115,29 @@ class instruction_msp430(instruction):
             return True
         return self.name in ['call']
 
+    @staticmethod
+    def arg2str(e, pos = None):
+        if isinstance(e, ExprId):
+            o = str(e)
+        elif isinstance(e, ExprInt):
+            o = str(e)
+        elif isinstance(e, ExprOp) and e.op == "autoinc":
+            o = "@%s+" % str(e.args[0])
+        elif isinstance(e, ExprMem):
+            if isinstance(e.arg, ExprId):
+                if pos == 0:
+                    o = "@%s" % e.arg
+                else:
+                    o = "0x0(%s)" % e.arg
+            elif isinstance(e.arg, ExprInt):
+                o = "@%s" % e.arg
+            elif isinstance(e.arg, ExprOp):
+                o = "%s(%s)" % (e.arg.args[1], e.arg.args[0])
+        else:
+            raise NotImplementedError('unknown instance e = %s' % type(e))
+        return o
+
+
     def dstflow2label(self, symbol_pool):
         e = self.args[0]
         if not isinstance(e, ExprInt):
@@ -395,25 +418,6 @@ class msp430_sreg_arg(reg_noarg, m_arg):
             raise NotImplementedError('unknown instance e = %s' % type(e))
         return True
 
-    @staticmethod
-    def arg2str(e):
-        if isinstance(e, ExprId):
-            o = str(e)
-        elif isinstance(e, ExprInt):
-            o = str(e)
-        elif isinstance(e, ExprOp) and e.op == "autoinc":
-            o = "@%s+" % str(e.args[0])
-        elif isinstance(e, ExprMem):
-            if isinstance(e.arg, ExprId):
-                o = "@%s" % e.arg
-            elif isinstance(e.arg, ExprInt):
-                o = "@%s" % e.arg
-            elif isinstance(e.arg, ExprOp):
-                o = "%s(%s)" % (e.arg.args[1], e.arg.args[0])
-        else:
-            raise NotImplementedError('unknown instance e = %s' % type(e))
-        return o
-
 
 class msp430_dreg_arg(msp430_sreg_arg):
     prio = default_prio + 1
@@ -464,25 +468,6 @@ class msp430_dreg_arg(msp430_sreg_arg):
             raise NotImplementedError('unknown instance e = %s' % type(e))
         return True
 
-    @staticmethod
-    def arg2str(e):
-        if isinstance(e, ExprId):
-            o = str(e)
-        elif isinstance(e, ExprMem):
-            if isinstance(e.arg, ExprId):
-                o = "0x0(%s)" % e.arg
-            elif isinstance(e.arg, ExprInt):
-                o = "@%s" % e.arg
-            elif isinstance(e.arg, ExprOp):
-                o = "%s(%s)" % (e.arg.args[1], e.arg.args[0])
-            else:
-                raise NotImplementedError(
-                    'unknown instance e.arg = %s' % type(e.arg))
-        else:
-            raise NotImplementedError('unknown instance e = %s' % type(e))
-        return o
-
-
 class bs_cond_off_s(bs_cond):
 
     @classmethod
diff --git a/miasm2/arch/sh4/arch.py b/miasm2/arch/sh4/arch.py
index d6a44881..61c909cc 100644
--- a/miasm2/arch/sh4/arch.py
+++ b/miasm2/arch/sh4/arch.py
@@ -69,13 +69,13 @@ def parse_deref_mem(s, l, t):
 
 def parse_predec(s, l, t):
     t = t[0]
-    e = ExprOp('predec', t[0])
+    e = ExprMem(ExprOp('predec', t[0]))
     return e
 
 
 def parse_postinc(s, l, t):
     t = t[0]
-    e = ExprOp('postinc', t[0])
+    e = ExprMem(ExprOp('postinc', t[0]))
     return e
 
 
@@ -173,37 +173,31 @@ class sh4_dgpreg(m_arg):
         self.value = v
         return True
 
-    @staticmethod
-    def arg2str(e):
-        ad = e.arg
-        if isinstance(ad, ExprOp):
-            s = ','.join([str(x).replace('(', '').replace(')', '')
-                         for x in ad.args])
-            s = "@(%s)" % s
-        else:
-            s = "@%s" % ad
-        return s
-
 
 class sh4_dgpregpinc(m_arg):
     parser = dgpregs_p
 
     def fromstring(self, s, parser_result=None):
         start, stop = super(sh4_dgpregpinc, self).fromstring(s, parser_result)
-        if not isinstance(self.expr, ExprOp):
+        if self.expr is None:
+            return None, None
+        if not isinstance(self.expr.arg, ExprOp):
             return None, None
-        if self.expr.op != self.op:
+        if self.expr.arg.op != self.op:
             return None, None
         return start, stop
 
     def decode(self, v):
         r = gpregs.expr[v]
-        e = ExprOp(self.op, r, ExprInt32(self.sz))
-        self.expr = e
+        e = ExprOp(self.op, r)
+        self.expr = ExprMem(e, self.sz)
         return True
 
     def encode(self):
         e = self.expr
+        if not isinstance(e, ExprMem):
+            return False
+        e = e.arg
         res = MatchExpr(e, ExprOp(self.op, jra), [jra])
         if not res:
             return False
@@ -214,16 +208,6 @@ class sh4_dgpregpinc(m_arg):
         self.value = v
         return True
 
-    @staticmethod
-    def arg2str(e):
-        if e.op == "predec":
-            o = '-%s' % e.args[0]
-        elif e.op == "postinc":
-            o = '%s+' % e.args[0]
-        else:
-            raise ValueError('unknown e.op: %s' % e.op)
-        return "@%s" % o
-
 
 class sh4_dgpregpdec(m_arg):
     parser = dgpregs_postinc
@@ -391,12 +375,6 @@ class sh4_pc32imm(m_arg):
         self.value = v
         return True
 
-    @staticmethod
-    def arg2str(e):
-        s = str(e).replace('(', '').replace(')', '')
-        return "%s" % s
-
-
 class additional_info:
 
     def __init__(self):
@@ -411,6 +389,31 @@ class instruction_sh4(instruction):
 
     def dstflow(self):
         return self.name.startswith('J')
+
+    @staticmethod
+    def arg2str(e, pos = None):
+        if isinstance(e, ExprId) or isinstance(e, ExprInt):
+            return str(e)
+        assert(isinstance(e, ExprMem))
+        e = e.arg
+
+        if isinstance(e, ExprOp):
+            if e.op == "predec":
+                s = '-%s' % e.args[0]
+            elif e.op == "postinc":
+                s = '%s+' % e.args[0]
+            else:
+                s = ','.join([str(x).replace('(', '').replace(')', '')
+                              for x in e.args])
+                s = "(%s)"%s
+            s = "@%s" % s
+        elif isinstance(e, ExprId):
+            s = "@%s" % e
+        else:
+            raise NotImplementedError('zarb arg2str')
+        return s
+
+
     """
     def dstflow2label(self, symbol_pool):
         e = self.args[0]
@@ -472,6 +475,7 @@ class mn_sh4(cls_mn):
     # delayslot:
     # http://resource.renesas.com/lib/eng/e_learnig/sh4/13/index.html
     delayslot = 0  # unit is instruction instruction
+    instruction = instruction_sh4
 
     def additional_info(self):
         info = additional_info()
diff --git a/miasm2/arch/x86/arch.py b/miasm2/arch/x86/arch.py
index 0a1d83e2..5cbf62ff 100644
--- a/miasm2/arch/x86/arch.py
+++ b/miasm2/arch/x86/arch.py
@@ -174,6 +174,10 @@ def parse_deref_ptr(s, l, t):
     t = t[0]
     return ExprMem(ExprOp('segm', t[0], t[1]))
 
+def parse_deref_segmoff(s, l, t):
+    t = t[0]
+    return ExprOp('segm', t[0], t[1])
+
 
 variable, operand, base_expr = gen_base_expr()
 
@@ -222,7 +226,7 @@ deref_mem_ad |= Group(
 
 
 deref_ptr = Group(int_or_expr + COLON +
-                  int_or_expr).setParseAction(parse_deref_ptr)
+                  int_or_expr).setParseAction(parse_deref_segmoff)
 
 
 PTR = Suppress('PTR')
@@ -542,6 +546,32 @@ class instruction_x86(instruction):
             args.append(a)
         return args
 
+    @staticmethod
+    def arg2str(e, pos = None):
+        if isinstance(e, ExprId) or isinstance(e, ExprInt):
+            o = str(e)
+        elif isinstance(e, ExprMem):
+            sz = {8: 'BYTE', 16: 'WORD', 32: 'DWORD',
+                  64: 'QWORD', 80: 'TBYTE'}[e.size]
+            segm = ""
+            if e.is_op_segm():
+                segm = "%s:" % e.arg.args[0]
+                e = e.arg.args[1]
+            else:
+                e = e.arg
+            if isinstance(e, ExprOp):
+                # s = str(e.arg)[1:-1]
+                s = str(e).replace('(', '').replace(')', '')
+            else:
+                s = str(e)
+            o = sz + ' PTR %s[%s]' % (segm, s)
+        elif isinstance(e, ExprOp) and e.op == 'segm':
+            o = "%s:%s" % (e.args[0], e.args[1])
+        else:
+            raise ValueError('check this %r' % e)
+        return "%s" % o
+
+
 
 class mn_x86(cls_mn):
     name = "x86"
@@ -1902,29 +1932,6 @@ class x86_rm_arg(m_arg):
         s = e.size
         return start, stop
 
-    @staticmethod
-    def arg2str(e):
-        if isinstance(e, ExprId):
-            o = str(e)
-        elif isinstance(e, ExprMem):
-            sz = {8: 'BYTE', 16: 'WORD', 32: 'DWORD',
-                  64: 'QWORD', 80: 'TBYTE'}[e.size]
-            segm = ""
-            if e.is_op_segm():
-                segm = "%s:" % e.arg.args[0]
-                e = e.arg.args[1]
-            else:
-                e = e.arg
-            if isinstance(e, ExprOp):
-                # s = str(e.arg)[1:-1]
-                s = str(e).replace('(', '').replace(')', '')
-            else:
-                s = str(e)
-            o = sz + ' PTR %s[%s]' % (segm, s)
-        else:
-            raise ValueError('check this %r' % e)
-        return "%s" % o
-
     def get_modrm(self):
         p = self.parent
         admode = p.v_admode()
@@ -2861,8 +2868,9 @@ class bs_moff(bsi):
         if not hasattr(self.parent, "mseg"):
             raise StopIteration
         m = self.parent.mseg.expr
-        if (not (isinstance(m, ExprMem) and m.is_op_segm() and
-            isinstance(m.arg.args[0], ExprInt))):
+        if not (isinstance(m, ExprOp) and m.op == 'segm'):
+            raise StopIteration
+        if not isinstance(m.args[1], ExprInt):
             raise StopIteration
         l = self.parent.v_opmode()  # self.parent.args[0].expr.size
         if l == 16:
@@ -2870,7 +2878,7 @@ class bs_moff(bsi):
         else:
             self.l = 32
         # print 'imm enc', l, self.parent.rex_w.value
-        v = int(m.arg.args[1].arg)
+        v = int(m.args[1].arg)
         mask = ((1 << self.l) - 1)
         # print 'ext', self.l, l, hex(v), hex(sign_ext(v & ((1<<self.l)-1),
         # self.l, l))
@@ -2964,12 +2972,6 @@ class bs_movoff(m_arg):
         # print self.expr, repr(self.expr)
         return True
 
-    @staticmethod
-    def arg2str(e):
-        sz = {8: 'BYTE', 16: 'WORD', 32: 'DWORD', 64: 'QWORD', 80: 'TBYTE'}
-        o = sz[e.size] + ' PTR [%s]' % e.arg
-        return "%s" % o
-
 
 class bs_msegoff(m_arg):
     parser = deref_ptr
@@ -2988,6 +2990,7 @@ class bs_msegoff(m_arg):
         except StopIteration:
             return None, None
         e = v[0]
+        print "XXX", e
         if e is None:
             log.debug('cannot fromstring int %r' % s)
             return None, None
@@ -2995,20 +2998,25 @@ class bs_msegoff(m_arg):
         return start, stop
 
     def encode(self):
-        if not (isinstance(self.expr, ExprMem) and self.expr.is_op_segm()):
+        print 'ENCODE', self.expr
+        if not (isinstance(self.expr, ExprOp) and self.expr.op == 'segm'):
             raise StopIteration
-        if not isinstance(self.expr.arg.args[0], ExprInt):
+        print 'ENCODE1', self.expr
+        if not isinstance(self.expr.args[0], ExprInt):
             raise StopIteration
-        if not isinstance(self.expr.arg.args[1], ExprInt):
+        print 'ENCODE2', self.expr
+        if not isinstance(self.expr.args[1], ExprInt):
             raise StopIteration
+        print 'ENCODE3', self.expr
         l = self.parent.v_opmode()  # self.parent.args[0].expr.size
         # print 'imm enc', l, self.parent.rex_w.value
-        v = int(self.expr.arg.args[0].arg)
+        v = int(self.expr.args[0].arg)
         mask = ((1 << self.l) - 1)
         # print 'ext', self.l, l, hex(v), hex(sign_ext(v & ((1<<self.l)-1),
         # self.l, l))
         if v != sign_ext(v & mask, self.l, l):
             raise StopIteration
+        print 'ENCODE4', self.expr
         self.value = swap_uint(self.l, v & ((1 << self.l) - 1))
         yield True
 
@@ -3018,15 +3026,11 @@ class bs_msegoff(m_arg):
         self.value = v
         v = sign_ext(v, self.l, opmode)
         v = ExprInt_fromsize(opmode, v)
-        e = ExprMem(ExprOp('segm', v, self.parent.off.expr))
+        e = ExprOp('segm', v, self.parent.off.expr)
         self.expr = e
         # print self.expr, repr(self.expr)
         return True
 
-    @staticmethod
-    def arg2str(e):
-        return "%s:%s" % (e.arg.args[0], e.arg.args[1])
-
 
 d_rex_p = bs(l=0, cls=(bs_fbit,), fname="rex_p")
 d_rex_w = bs(l=0, cls=(bs_fbit,), fname="rex_w")
diff --git a/miasm2/core/cpu.py b/miasm2/core/cpu.py
index 2d52eac0..652ba020 100644
--- a/miasm2/core/cpu.py
+++ b/miasm2/core/cpu.py
@@ -438,10 +438,6 @@ class dum_arg(object):
     def __init__(self, e=None):
         self.expr = e
 
-    @staticmethod
-    def arg2str(e):
-        return str(e)
-
 
 class bsopt(bs):
 
@@ -612,10 +608,6 @@ class m_arg(object):
         self.expr = v[0]
         return start, stop
 
-    @staticmethod
-    def arg2str(e):
-        return str(e)
-
 
 class m_reg(m_arg):
     prio = default_prio
@@ -631,10 +623,6 @@ class m_reg(m_arg):
     def encode(self):
         return self.expr == self.reg.expr[0]
 
-    @staticmethod
-    def arg2str(e):
-        return str(e)
-
 
 class reg_noarg(object):
     reg_info = None
@@ -652,10 +640,6 @@ class reg_noarg(object):
         self.expr = v[0]
         return start, stop
 
-    @staticmethod
-    def arg2str(e):
-        return str(e)
-
     def decode(self, v):
         v = v & self.lmask
         if v >= len(self.reg_info.expr):
@@ -943,13 +927,10 @@ class metamn(type):
 
 class instruction(object):
 
-    def __init__(self, name, mode, args, args_str=None, additional_info=None):
+    def __init__(self, name, mode, args, additional_info=None):
         self.name = name
         self.mode = mode
         self.args = args
-        if args_str is None:
-            raise NotImplementedError('not fully functional')
-        self.args_str = args_str
         self.additional_info = additional_info
 
     def gen_args(self, args):
@@ -959,11 +940,12 @@ class instruction(object):
     def __str__(self):
         o = "%-10s " % self.name
         args = []
-        args_str = self.args_str
-        for arg, arg_str in zip(self.args, args_str):
+        #args_str = self.args_str
+        #for arg, arg_str in zip(self.args, args_str):
+        for i, arg in enumerate(self.args):
             if not isinstance(arg, Expr):
                 raise ValueError('zarb arg type')
-            x = arg_str(arg)
+            x = self.arg2str(arg, pos = i)
             args.append(x)
         o += self.gen_args(args)
         return o
@@ -1253,15 +1235,7 @@ class cls_mn(object):
             if c is None:
                 continue
             c_args = [a.expr for a in c.args]
-            c_args_str = []
-            for a in c.args:
-                if hasattr(a, 'arg2str'):
-                    c_args_str.append(a.arg2str)
-                else:
-                    raise NotImplementedError('not fully functional')
-                    c_args_str.append(str)
-            # c_args_str = [a.arg2str for a in c.args]
-            instr = cls.instruction(c.name, mode, c_args, c_args_str,
+            instr = cls.instruction(c.name, mode, c_args,
                                     additional_info=c.additional_info())
             instr.l = prefix_len + total_l / 8
             instr.b = cls.getbytes(bs, offset, total_l / 8)
@@ -1389,15 +1363,7 @@ class cls_mn(object):
         c = out[0]
         c_args = out_args[0]
 
-        c_args_str = []
-        for a in c.args:
-            if hasattr(a, 'arg2str'):
-                c_args_str.append(a.arg2str)
-            else:
-                raise NotImplementedError('not fully functional')
-                c_args_str.append(str)
-
-        instr = cls.instruction(c.name, mode, c_args, c_args_str,
+        instr = cls.instruction(c.name, mode, c_args,
                                 additional_info=c.additional_info())
         # instruction(name, attrib, args, args_str, additional_info):
         # c = c()
@@ -1720,10 +1686,6 @@ class imm_noarg(object):
             return False
         return v
 
-    @staticmethod
-    def arg2str(e):
-        return str(e)
-
     def decode(self, v):
         v = v & self.lmask
         v = self.decodeval(v)