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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# Toshiba MeP-c4 - Multiply 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 TestMultiply(object):
def test_mul(self):
"""Test MUL execution"""
# MUL Rn,Rm
exec_instruction("MUL R0, R1",
[(ExprId("R0", 32), ExprInt(0x80, 32)),
(ExprId("R1", 32), ExprInt(0xFFFFFFFF, 32))],
[(ExprId("HI", 32), ExprInt(0xFFFFFFFF, 32)),
(ExprId("LO", 32), ExprInt(0xFFFFFF80, 32))])
exec_instruction("MUL R0, R1",
[(ExprId("R0", 32), ExprInt(0x80000000, 32)),
(ExprId("R1", 32), ExprInt(0xFFFFFFFF, 32))],
[(ExprId("HI", 32), ExprInt(0x00000000, 32)),
(ExprId("LO", 32), ExprInt(0x80000000, 32))])
def test_mulu(self):
"""Test MULU execution"""
# MULU Rn,Rm
exec_instruction("MULU R0, R1",
[(ExprId("R0", 32), ExprInt(0x2, 32)),
(ExprId("R1", 32), ExprInt(0xFFFFFFFF, 32))],
[(ExprId("HI", 32), ExprInt(0x1, 32)),
(ExprId("LO", 32), ExprInt(0xFFFFFFFE, 32))])
exec_instruction("MULU R0, R1",
[(ExprId("R0", 32), ExprInt(0x80000000, 32)),
(ExprId("R1", 32), ExprInt(0xFFFFFFFF, 32))],
[(ExprId("HI", 32), ExprInt(0x7FFFFFFF, 32)),
(ExprId("LO", 32), ExprInt(0x80000000, 32))])
def test_mulr(self):
"""Test MULR execution"""
# MULR Rn,Rm
exec_instruction("MULR R0, R1",
[(ExprId("R0", 32), ExprInt(0x80, 32)),
(ExprId("R1", 32), ExprInt(0xFFFFFFFF, 32))],
[(ExprId("HI", 32), ExprInt(0xFFFFFFFF, 32)),
(ExprId("LO", 32), ExprInt(0xFFFFFF80, 32)),
(ExprId("R0", 32), ExprInt(0xFFFFFF80, 32))])
def test_mulru(self):
"""Test MULRU execution"""
# MULRU Rn,Rm
exec_instruction("MULRU R0, R1",
[(ExprId("R0", 32), ExprInt(0x2, 32)),
(ExprId("R1", 32), ExprInt(0xFFFFFFFF, 32))],
[(ExprId("HI", 32), ExprInt(0x1, 32)),
(ExprId("LO", 32), ExprInt(0xFFFFFFFE, 32)),
(ExprId("R0", 32), ExprInt(0xFFFFFFFE, 32))])
def test_madd(self):
"""Test MADD execution"""
# MADD Rn,Rm
exec_instruction("MADD R0, R1",
[(ExprId("R0", 32), ExprInt(0x80, 32)),
(ExprId("R1", 32), ExprInt(0xFFFFFFFF, 32)),
(ExprId("HI", 32), ExprInt(0, 32)),
(ExprId("LO", 32), ExprInt(0, 32))],
[(ExprId("HI", 32), ExprInt(0xFFFFFFFF, 32)),
(ExprId("LO", 32), ExprInt(0xFFFFFF80, 32))])
exec_instruction("MADD R0, R1",
[(ExprId("R0", 32), ExprInt(0x80, 32)),
(ExprId("R1", 32), ExprInt(0xFFFFFFFF, 32)),
(ExprId("HI", 32), ExprInt(1, 32)),
(ExprId("LO", 32), ExprInt(1, 32))],
[(ExprId("HI", 32), ExprInt(0xFFFFFFFF, 32)),
(ExprId("LO", 32), ExprInt(0xFFFFFF81, 32))])
def test_maddu(self):
"""Test MADDU execution"""
# MADDU Rn,Rm
exec_instruction("MADDU R0, R1",
[(ExprId("R0", 32), ExprInt(0x2, 32)),
(ExprId("R1", 32), ExprInt(0xFFFFFFFF, 32)),
(ExprId("HI", 32), ExprInt(0, 32)),
(ExprId("LO", 32), ExprInt(0, 32))],
[(ExprId("HI", 32), ExprInt(0x1, 32)),
(ExprId("LO", 32), ExprInt(0xFFFFFFFE, 32))])
exec_instruction("MADDU R0, R1",
[(ExprId("R0", 32), ExprInt(0x2, 32)),
(ExprId("R1", 32), ExprInt(0xFFFFFFFF, 32)),
(ExprId("HI", 32), ExprInt(1, 32)),
(ExprId("LO", 32), ExprInt(1, 32))],
[(ExprId("HI", 32), ExprInt(0x1, 32)),
(ExprId("LO", 32), ExprInt(0xFFFFFFFF, 32))])
def test_maddr(self):
"""Test MADDR execution"""
# MADDR Rn,Rm
exec_instruction("MADDR R0, R1",
[(ExprId("R0", 32), ExprInt(0x80, 32)),
(ExprId("R1", 32), ExprInt(0xFFFFFFFF, 32)),
(ExprId("HI", 32), ExprInt(0, 32)),
(ExprId("LO", 32), ExprInt(0, 32))],
[(ExprId("HI", 32), ExprInt(0xFFFFFFFF, 32)),
(ExprId("LO", 32), ExprInt(0xFFFFFF80, 32)),
(ExprId("R0", 32), ExprInt(0xFFFFFF80, 32))])
exec_instruction("MADDR R0, R1",
[(ExprId("R0", 32), ExprInt(0x80, 32)),
(ExprId("R1", 32), ExprInt(0xFFFFFFFF, 32)),
(ExprId("HI", 32), ExprInt(1, 32)),
(ExprId("LO", 32), ExprInt(1, 32))],
[(ExprId("HI", 32), ExprInt(0xFFFFFFFF, 32)),
(ExprId("LO", 32), ExprInt(0xFFFFFF81, 32)),
(ExprId("R0", 32), ExprInt(0xFFFFFF81, 32))])
def test_maddru(self):
"""Test MADDRU execution"""
# MADDRU Rn,Rm
exec_instruction("MADDRU R0, R1",
[(ExprId("R0", 32), ExprInt(0x2, 32)),
(ExprId("R1", 32), ExprInt(0xFFFFFFFF, 32)),
(ExprId("HI", 32), ExprInt(0, 32)),
(ExprId("LO", 32), ExprInt(0, 32))],
[(ExprId("HI", 32), ExprInt(0x1, 32)),
(ExprId("LO", 32), ExprInt(0xFFFFFFFE, 32)),
(ExprId("R0", 32), ExprInt(0xFFFFFFFE, 32))])
|