Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
Classes | Functions | Variables
miasm2.arch.msp430.sem Namespace Reference

Classes

class  ir_msp430
 

Functions

def hex2bcd
 
def bcd2hex
 
def reset_sr_res
 
def update_flag_zf
 
def update_flag_nf
 
def update_flag_pf
 
def update_flag_cf_inv_zf
 
def update_flag_zn_r
 
def update_flag_sub_cf
 
def update_flag_add_cf
 
def update_flag_add_of
 
def update_flag_sub_of
 
def mng_autoinc
 
def mov_b
 
def mov_w
 
def and_b
 
def and_w
 
def bic_b
 
def bic_w
 
def bis_w
 
def bit_w
 
def sub_w
 
def add_b
 
def add_w
 
def dadd_w
 
def xor_w
 
def push_w
 
def call
 
def swpb
 
def cmp_w
 
def cmp_b
 
def jz
 
def jnz
 
def jl
 
def jc
 
def jnc
 
def jge
 
def jmp
 
def rrc_w
 
def rra_w
 
def sxt
 
def ComposeExprAff
 

Variables

dictionary mnemo_func
 
tuple composed_sr
 

Function Documentation

def miasm2.arch.msp430.sem.add_b (   ir,
  instr,
  a,
  b 
)

Definition at line 179 of file sem.py.

180 def add_b(ir, instr, a, b):
181  e, a, b = mng_autoinc(a, b, 8)
182  if isinstance(b, ExprMem):
183  b = ExprMem(b.arg, 8)
184  else:
185  b = b[:8]
186  a = a[:8]
187  c = b + a
188  e.append(ExprAff(b, c))
189  e += update_flag_zn_r(c)
190  e += update_flag_add_cf(a, b, c)
191  e += update_flag_add_of(a, b, c)
192  return e, []
193 
def update_flag_zn_r
Definition: sem.py:47
def update_flag_add_of
Definition: sem.py:64
def update_flag_add_cf
Definition: sem.py:60

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.add_w (   ir,
  instr,
  a,
  b 
)

Definition at line 194 of file sem.py.

195 def add_w(ir, instr, a, b):
196  e, a, b = mng_autoinc(a, b, 16)
197  c = b + a
198  e.append(ExprAff(b, c))
199  e += update_flag_zn_r(c)
200  e += update_flag_add_cf(a, b, c)
201  e += update_flag_add_of(a, b, c)
202  return e, []
203 
def update_flag_zn_r
Definition: sem.py:47
def update_flag_add_of
Definition: sem.py:64
def update_flag_add_cf
Definition: sem.py:60

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.and_b (   ir,
  instr,
  a,
  b 
)

Definition at line 106 of file sem.py.

107 def and_b(ir, instr, a, b):
108  e, a, b = mng_autoinc(a, b, 8)
109  c = a[:8] & b[:8]
110  e.append(ExprAff(b, c.zeroExtend(16)))
111  e += update_flag_zn_r(c)
112  e += update_flag_cf_inv_zf(c)
113  e += [ExprAff(of, ExprInt1(0))]
114  return e, []
115 
def update_flag_cf_inv_zf
Definition: sem.py:43
def update_flag_zn_r
Definition: sem.py:47

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.and_w (   ir,
  instr,
  a,
  b 
)

Definition at line 116 of file sem.py.

117 def and_w(ir, instr, a, b):
118  e, a, b = mng_autoinc(a, b, 16)
119  c = a & b
120  e.append(ExprAff(b, c))
121  e += update_flag_zn_r(c)
122  e += update_flag_cf_inv_zf(c)
123  e += [ExprAff(of, ExprInt1(0))]
124  return e, []
125 
def update_flag_cf_inv_zf
Definition: sem.py:43
def update_flag_zn_r
Definition: sem.py:47

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.bcd2hex (   val)

Definition at line 19 of file sem.py.

19 
20 def bcd2hex(val):
21  "Return the hex value of a BCD"
22  try:
23  return int("0x%d" % val, 16)
24  except ValueError:
25  raise NotImplementedError("Not defined behaviour")
26 
def miasm2.arch.msp430.sem.bic_b (   ir,
  instr,
  a,
  b 
)

Definition at line 126 of file sem.py.

127 def bic_b(ir, instr, a, b):
128  e, a, b = mng_autoinc(a, b, 8)
129  c = (a[:8] ^ ExprInt8(0xff)) & b[:8]
130  c = c.zeroExtend(b.size)
131  e.append(ExprAff(b, c))
132  return e, []
133 

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.bic_w (   ir,
  instr,
  a,
  b 
)

Definition at line 134 of file sem.py.

135 def bic_w(ir, instr, a, b):
136  e, a, b = mng_autoinc(a, b, 16)
137  c = (a ^ ExprInt16(0xffff)) & b
138  e.append(ExprAff(b, c))
139  return e, []
140 

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.bis_w (   ir,
  instr,
  a,
  b 
)

Definition at line 141 of file sem.py.

142 def bis_w(ir, instr, a, b):
143  e, a, b = mng_autoinc(a, b, 16)
144  c = a | b
145  e.append(ExprAff(b, c))
146  return e, []
147 

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.bit_w (   ir,
  instr,
  a,
  b 
)

Definition at line 148 of file sem.py.

149 def bit_w(ir, instr, a, b):
150  e, a, b = mng_autoinc(a, b, 16)
151  c = a & b
152  e += update_flag_zn_r(c)
153  e += update_flag_cf_inv_zf(c)
154  e.append(ExprAff(of, ExprInt1(0)))
155  return e, []
156 
157 """
158 def sub_b(ir, instr, a, b):
159  e, a, b = mng_autoinc(a, b, 8)
160  c = b - a
161  e.append(ExprAff(b, c))
162  e += update_flag_zn_r(c)
163  e += update_flag_sub_cf(b, a, c)
164  return None, e, []
165 """
166 
def update_flag_cf_inv_zf
Definition: sem.py:43
def update_flag_zn_r
Definition: sem.py:47

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.call (   ir,
  instr,
  a 
)

Definition at line 240 of file sem.py.

241 def call(ir, instr, a):
242  e, a, dummy = mng_autoinc(a, None, 16)
243  n = ExprId(ir.get_next_label(instr), 16)
244  e.append(ExprAff(ExprMem(SP - ExprInt16(2), 16), n))
245  e.append(ExprAff(SP, SP - ExprInt16(2)))
246  e.append(ExprAff(PC, a))
247  e.append(ExprAff(ir.IRDst, a))
248  return e, []
249 

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.cmp_b (   ir,
  instr,
  a,
  b 
)

Definition at line 267 of file sem.py.

268 def cmp_b(ir, instr, a, b):
269  e, a, b = mng_autoinc(a, b, 8)
270  c = b[:8] - a[:8]
271  e += update_flag_zn_r(c)
272  e += update_flag_sub_cf(b[:8], a[:8], c)
273  e += update_flag_sub_of(b[:8], a[:8], c)
274  return e, []
275 
def update_flag_zn_r
Definition: sem.py:47
def update_flag_sub_of
Definition: sem.py:68
def update_flag_sub_cf
Definition: sem.py:55

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.cmp_w (   ir,
  instr,
  a,
  b 
)

Definition at line 258 of file sem.py.

259 def cmp_w(ir, instr, a, b):
260  e, a, b = mng_autoinc(a, b, 16)
261  c = b - a
262  e += update_flag_zn_r(c)
263  e += update_flag_sub_cf(b, a, c)
264  e += update_flag_sub_of(b, a, c)
265  return e, []
266 
def update_flag_zn_r
Definition: sem.py:47
def update_flag_sub_of
Definition: sem.py:68
def update_flag_sub_cf
Definition: sem.py:55

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.ComposeExprAff (   dst,
  src 
)

Definition at line 423 of file sem.py.

424 def ComposeExprAff(dst, src):
425  e = []
426  for x, start, stop in dst.args:
427  e.append(ExprAff(x, src[start:stop]))
428  return e
429 

+ Here is the caller graph for this function:

def miasm2.arch.msp430.sem.dadd_w (   ir,
  instr,
  a,
  b 
)

Definition at line 204 of file sem.py.

205 def dadd_w(ir, instr, a, b):
206  e, a, b = mng_autoinc(a, b, 16)
207  # TODO: microcorruption no carryflag
208  c = ExprOp("bcdadd", b, a) # +zeroExtend(cf, 16))
209 
210  e.append(ExprAff(b, c))
211  # e += update_flag_zn_r(c)
212 
213  # micrcorruption
214  e += update_flag_zf(a)
215  # e += update_flag_nf(a)
216  e += reset_sr_res()
217 
218  e.append(ExprAff(cf, ExprOp("bcdadd_cf", b, a))) # +zeroExtend(cf, 16))))
219 
220  # of : undefined
221  return e, []
222 

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.hex2bcd (   val)

Definition at line 11 of file sem.py.

11 
12 def hex2bcd(val):
13  "Return val as BCD"
14  try:
15  return int("%x" % val, 10)
16  except ValueError:
17  raise NotImplementedError("Not defined behaviour")
18 
def miasm2.arch.msp430.sem.jc (   ir,
  instr,
  a 
)

Definition at line 300 of file sem.py.

301 def jc(ir, instr, a):
302  n = ExprId(ir.get_next_label(instr), 16)
303  e = []
304  e.append(ExprAff(PC, ExprCond(cf, a, n)))
305  e.append(ExprAff(ir.IRDst, ExprCond(cf, a, n)))
306  return e, []
307 
def miasm2.arch.msp430.sem.jge (   ir,
  instr,
  a 
)

Definition at line 316 of file sem.py.

317 def jge(ir, instr, a):
318  n = ExprId(ir.get_next_label(instr), 16)
319  e = []
320  e.append(ExprAff(PC, ExprCond(nf ^ of, n, a)))
321  e.append(ExprAff(ir.IRDst, ExprCond(nf ^ of, n, a)))
322  return e, []
323 
def miasm2.arch.msp430.sem.jl (   ir,
  instr,
  a 
)

Definition at line 292 of file sem.py.

293 def jl(ir, instr, a):
294  n = ExprId(ir.get_next_label(instr), 16)
295  e = []
296  e.append(ExprAff(PC, ExprCond(nf ^ of, a, n)))
297  e.append(ExprAff(ir.IRDst, ExprCond(nf ^ of, a, n)))
298  return e, []
299 
def miasm2.arch.msp430.sem.jmp (   ir,
  instr,
  a 
)

Definition at line 324 of file sem.py.

325 def jmp(ir, instr, a):
326  e = []
327  e.append(ExprAff(PC, a))
328  e.append(ExprAff(ir.IRDst, a))
329  return e, []
330 
def miasm2.arch.msp430.sem.jnc (   ir,
  instr,
  a 
)

Definition at line 308 of file sem.py.

309 def jnc(ir, instr, a):
310  n = ExprId(ir.get_next_label(instr), 16)
311  e = []
312  e.append(ExprAff(PC, ExprCond(cf, n, a)))
313  e.append(ExprAff(ir.IRDst, ExprCond(cf, n, a)))
314  return e, []
315 
def miasm2.arch.msp430.sem.jnz (   ir,
  instr,
  a 
)

Definition at line 284 of file sem.py.

285 def jnz(ir, instr, a):
286  n = ExprId(ir.get_next_label(instr), 16)
287  e = []
288  e.append(ExprAff(PC, ExprCond(zf, n, a)))
289  e.append(ExprAff(ir.IRDst, ExprCond(zf, n, a)))
290  return e, []
291 
def miasm2.arch.msp430.sem.jz (   ir,
  instr,
  a 
)

Definition at line 276 of file sem.py.

277 def jz(ir, instr, a):
278  n = ExprId(ir.get_next_label(instr), 16)
279  e = []
280  e.append(ExprAff(PC, ExprCond(zf, a, n)))
281  e.append(ExprAff(ir.IRDst, ExprCond(zf, a, n)))
282  return e, []
283 
def miasm2.arch.msp430.sem.mng_autoinc (   a,
  b,
  size 
)

Definition at line 72 of file sem.py.

72 
73 def mng_autoinc(a, b, size):
74  e = []
75  if not (isinstance(a, ExprOp) and a.op == "autoinc"):
76  return e, a, b
77 
78  a_r = a.args[0]
79  e.append(ExprAff(a_r, a_r + ExprInt_from(a_r, size / 8)))
80  a = ExprMem(a_r, size)
81  if isinstance(b, ExprMem) and a_r in b.arg:
82  b = ExprMem(b.arg + ExprInt16(size / 8), b.size)
83  return e, a, b
84 
85 # Mnemonics
86 

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.arch.msp430.sem.mov_b (   ir,
  instr,
  a,
  b 
)

Definition at line 87 of file sem.py.

87 
88 def mov_b(ir, instr, a, b):
89  e, a, b = mng_autoinc(a, b, 8)
90  if isinstance(b, ExprMem):
91  b = ExprMem(b.arg, 8)
92  a = a[:8]
93  else:
94  a = a[:8].zeroExtend(16)
95  e.append(ExprAff(b, a))
96  return e, []
97 

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.mov_w (   ir,
  instr,
  a,
  b 
)

Definition at line 98 of file sem.py.

98 
99 def mov_w(ir, instr, a, b):
100  e, a, b = mng_autoinc(a, b, 16)
101  e.append(ExprAff(b, a))
102  if b == ir.pc:
103  e.append(ExprAff(ir.IRDst, a))
104  return e, []
105 

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.push_w (   ir,
  instr,
  a 
)

Definition at line 233 of file sem.py.

234 def push_w(ir, instr, a):
235  e = []
236  e.append(ExprAff(ExprMem(SP - ExprInt16(2), 16), a))
237  e.append(ExprAff(SP, SP - ExprInt16(2)))
238  return e, []
239 

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.reset_sr_res ( )

Definition at line 27 of file sem.py.

27 
28 def reset_sr_res():
29  return [ExprAff(res, ExprInt(0, 7))]
30 

+ Here is the caller graph for this function:

def miasm2.arch.msp430.sem.rra_w (   ir,
  instr,
  a 
)

Definition at line 348 of file sem.py.

349 def rra_w(ir, instr, a):
350  e = []
351  c = ExprCompose([(a[1:16], 0, 15),
352  (a[15:16], 15, 16)])
353  e.append(ExprAff(a, c))
354  # TODO: error in disasm microcorruption?
355  # e.append(ExprAff(cf, a[:1]))
356  # e += update_flag_zn_r(c)
357 
358  # micrcorruption
359  e += update_flag_zf(a)
360  # e += update_flag_nf(a)
361  e += reset_sr_res()
362 
363  e.append(ExprAff(of, ExprInt1(0)))
364  return e, []
365 

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.rrc_w (   ir,
  instr,
  a 
)

Definition at line 331 of file sem.py.

332 def rrc_w(ir, instr, a):
333  e = []
334  c = ExprCompose([(a[1:16], 0, 15),
335  (cf, 15, 16)])
336  e.append(ExprAff(a, c))
337  e.append(ExprAff(cf, a[:1]))
338  # e += update_flag_zn_r(c)
339 
340  # micrcorruption
341  e += update_flag_zf(a)
342  # e += update_flag_nf(a)
343  e += reset_sr_res()
344 
345  e.append(ExprAff(of, ExprInt1(0)))
346  return e, []
347 

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.sub_w (   ir,
  instr,
  a,
  b 
)

Definition at line 167 of file sem.py.

168 def sub_w(ir, instr, a, b):
169  e, a, b = mng_autoinc(a, b, 16)
170  c = b - a
171  e.append(ExprAff(b, c))
172  e += update_flag_zn_r(c)
173  e += update_flag_sub_cf(b, a, c)
174  # micrcorruption
175  # e += update_flag_sub_of(a, b, c)
176  # e += update_flag_sub_of(b, a, c)
177  return e, []
178 
def update_flag_zn_r
Definition: sem.py:47
def update_flag_sub_cf
Definition: sem.py:55

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.swpb (   ir,
  instr,
  a 
)

Definition at line 250 of file sem.py.

251 def swpb(ir, instr, a):
252  e = []
253  x, y = a[:8], a[8:16]
254  e.append(ExprAff(a, ExprCompose([(y, 0, 8),
255  (x, 8, 16)])))
256  return e, []
257 
def miasm2.arch.msp430.sem.sxt (   ir,
  instr,
  a 
)

Definition at line 366 of file sem.py.

367 def sxt(ir, instr, a):
368  e = []
369  c = a[:8].signExtend(16)
370  e.append(ExprAff(a, c))
371 
372  e += update_flag_zn_r(c)
373  e += update_flag_cf_inv_zf(c)
374  e.append(ExprAff(of, ExprInt1(0)))
375 
376  return e, []
def update_flag_cf_inv_zf
Definition: sem.py:43
def update_flag_zn_r
Definition: sem.py:47

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.update_flag_add_cf (   a,
  b,
  c 
)

Definition at line 60 of file sem.py.

60 
61 def update_flag_add_cf(a, b, c):
62  return [ExprAff(cf, (((a ^ b) ^ c) ^ ((a ^ c) & (~(a ^ b)))).msb())]
63 
def update_flag_add_cf
Definition: sem.py:60

+ Here is the caller graph for this function:

def miasm2.arch.msp430.sem.update_flag_add_of (   a,
  b,
  c 
)

Definition at line 64 of file sem.py.

64 
65 def update_flag_add_of(a, b, c):
66  return [ExprAff(of, (((a ^ c) & (~(a ^ b)))).msb())]
67 
def update_flag_add_of
Definition: sem.py:64

+ Here is the caller graph for this function:

def miasm2.arch.msp430.sem.update_flag_cf_inv_zf (   a)

Definition at line 43 of file sem.py.

43 
45  return [ExprAff(cf, ExprCond(a, ExprInt_from(cf, 1), ExprInt_from(cf, 0)))]
46 
def update_flag_cf_inv_zf
Definition: sem.py:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.arch.msp430.sem.update_flag_nf (   a)

Definition at line 35 of file sem.py.

35 
36 def update_flag_nf(a):
37  return [ExprAff(nf, a.msb())]
38 

+ Here is the caller graph for this function:

def miasm2.arch.msp430.sem.update_flag_pf (   a)

Definition at line 39 of file sem.py.

39 
40 def update_flag_pf(a):
41  return [ExprAff(pf, ExprOp('parity', a & ExprInt_from(a, 0xFF)))]
42 

+ Here is the call graph for this function:

def miasm2.arch.msp430.sem.update_flag_sub_cf (   a,
  b,
  c 
)

Definition at line 55 of file sem.py.

55 
56 def update_flag_sub_cf(a, b, c):
57  return [ExprAff(cf,
58  ((((a ^ b) ^ c) ^ ((a ^ c) & (a ^ b))).msb()) ^ ExprInt1(1))]
59 
def update_flag_sub_cf
Definition: sem.py:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.arch.msp430.sem.update_flag_sub_of (   a,
  b,
  c 
)

Definition at line 68 of file sem.py.

68 
69 def update_flag_sub_of(a, b, c):
70  return [ExprAff(of, (((a ^ c) & (a ^ b))).msb())]
71 
def update_flag_sub_of
Definition: sem.py:68

+ Here is the caller graph for this function:

def miasm2.arch.msp430.sem.update_flag_zf (   a)

Definition at line 31 of file sem.py.

31 
32 def update_flag_zf(a):
33  return [ExprAff(zf, ExprCond(a, ExprInt_from(zf, 0), ExprInt_from(zf, 1)))]
34 

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.arch.msp430.sem.update_flag_zn_r (   a)

Definition at line 47 of file sem.py.

47 
48 def update_flag_zn_r(a):
49  e = []
50  e += update_flag_zf(a)
51  e += update_flag_nf(a)
52  e += reset_sr_res()
53  return e
54 
def update_flag_zn_r
Definition: sem.py:47

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.arch.msp430.sem.xor_w (   ir,
  instr,
  a,
  b 
)

Definition at line 223 of file sem.py.

224 def xor_w(ir, instr, a, b):
225  e, a, b = mng_autoinc(a, b, 16)
226  c = b ^ a
227  e.append(ExprAff(b, c))
228  e += update_flag_zn_r(c)
229  e += update_flag_cf_inv_zf(c)
230  e.append(ExprAff(of, b.msb() & a.msb()))
231  return e, []
232 
def update_flag_cf_inv_zf
Definition: sem.py:43
def update_flag_zn_r
Definition: sem.py:47

+ Here is the call graph for this function:

Variable Documentation

tuple miasm2.arch.msp430.sem.composed_sr
Initial value:
2  (cf, 0, 1),
3  (zf, 1, 2),
4  (nf, 2, 3),
5  (gie, 3, 4),
6  (cpuoff, 4, 5),
7  (osc, 5, 6),
8  (scg0, 6, 7),
9  (scg1, 7, 8),
10  (of, 8, 9),
11  (res, 9, 16),
12 ])

Definition at line 409 of file sem.py.

dictionary miasm2.arch.msp430.sem.mnemo_func
Initial value:
1 = {
2  "mov.b": mov_b,
3  "mov.w": mov_w,
4  "and.b": and_b,
5  "and.w": and_w,
6  "bic.b": bic_b,
7  "bic.w": bic_w,
8  "bis.w": bis_w,
9  "bit.w": bit_w,
10  "sub.w": sub_w,
11  "add.b": add_b,
12  "add.w": add_w,
13  "push.w": push_w,
14  "dadd.w": dadd_w,
15  "xor.w": xor_w,
16  "call": call,
17  "swpb": swpb,
18  "cmp.w": cmp_w,
19  "cmp.b": cmp_b,
20  "jz": jz,
21  "jnz": jnz,
22  "jl": jl,
23  "jc": jc,
24  "jnc": jnc,
25  "jmp": jmp,
26  "jge": jge,
27  "rrc.w": rrc_w,
28  "rra.w": rra_w,
29  "sxt": sxt,
30 }

Definition at line 377 of file sem.py.