1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# Toshiba MeP-c4 - Control instructions unit tests
# Guillaume Valadon <guillaume@valadon.net>
from ut_helpers_ir import exec_instruction
from miasm.expression.expression import ExprId, ExprInt, ExprCond, ExprOp
class TestControl(object):
def test_stc(self):
"""Test STC execution"""
# STC Rn,imm5
exec_instruction("STC R1, SAR",
[(ExprId("R1", 32), ExprInt(0x28, 32))],
[(ExprId("SAR", 32), ExprInt(0x28, 32))])
def test_ldc(self):
"""Test LDC execution"""
# LDC Rn,imm5
exec_instruction("LDC R1, SAR",
[(ExprId("SAR", 32), ExprInt(0x28, 32))],
[(ExprId("R1", 32), ExprInt(0x28, 32))])
def test_di(self):
"""Test DI execution"""
# DI
exec_instruction("DI",
[(ExprId("PSW", 32), ExprInt(1, 32))],
[(ExprId("PSW", 32), ExprInt(0, 32))])
def test_ei(self):
"""Test EI execution"""
# EI
exec_instruction("EI",
[(ExprId("PSW", 32), ExprInt(0, 32))],
[(ExprId("PSW", 32), ExprInt(1, 32))])
def test_reti(self):
"""Test RETI execution"""
# RETI
exec_instruction("RETI",
[(ExprId("PSW", 32), ExprInt(0xF0000201, 32)), # PSW_NMI = 1
(ExprId("NPC", 32), ExprInt(0x43, 32))],
[(ExprId("PSW", 32), ExprInt(0xF0000001, 32)),
(ExprId("PC", 32), ExprInt(0x42, 32))])
exec_instruction("RETI",
[(ExprId("PSW", 32), ExprInt(0b1010, 32)), # PSW_UMP = 1 & PSW_IEP = 1
(ExprId("EPC", 32), ExprInt(0x29, 32))],
[(ExprId("PSW", 32), ExprInt(0b1111, 32)), # PSW_UMC = 1 & PSW_IEC = 1
(ExprId("PC", 32), ExprInt(0x28, 32))])
def test_swi(self):
"""Test SWI execution"""
# SWI
exec_instruction("SWI 0",
[(ExprId("EXC", 32), ExprInt(0xF0000001, 32))],
[(ExprId("EXC", 32), ExprInt(0xF0000001 + (1 << 4), 32))])
exec_instruction("SWI 1",
[(ExprId("EXC", 32), ExprInt(0xF0000001, 32))],
[(ExprId("EXC", 32), ExprInt(0xF0000001 + (1 << 5), 32))])
def test_halt(self):
"""Test HALT execution"""
# HALT
exec_instruction("HALT", [], [])
def test_sleep(self):
"""Test SLEEP execution"""
# SLEEP
exec_instruction("SLEEP", [], [])
def test_break(self):
"""Test BREAK execution"""
# BREAK
exec_instruction("BREAK", [], [])
def test_syncm(self):
"""Test SYNCM execution"""
# SYNCM
exec_instruction("SYNCM", [], [])
def test_stcb(self):
"""Test STCB execution"""
# STCB Rn,abs16
exec_instruction("STCB R0, 0x0", [], [])
def test_ldcb(self):
"""Test LDCB execution"""
# LDCB Rn,abs16
exec_instruction("LDCB R0, 0x0", [], [])
|