292
|
1 import unittest
|
383
|
2 import io
|
342
|
3 from ppci.outstream import BinaryOutputStream
|
335
|
4 from ppci.objectfile import ObjectFile
|
292
|
5 from testasm import AsmTestCaseBase
|
345
|
6 from ppci.target.target_list import arm_target
|
383
|
7 from ppci.layout import load_layout
|
292
|
8
|
|
9
|
345
|
10 class ArmAssemblerTestCase(AsmTestCaseBase):
|
340
|
11 """ ARM-mode (not thumb-mode) instruction assembly test case """
|
|
12 def setUp(self):
|
385
|
13 self.target = arm_target
|
340
|
14 self.obj = ObjectFile()
|
346
|
15 self.ostream = BinaryOutputStream(self.obj)
|
383
|
16 self.ostream.select_section('code')
|
381
|
17 self.assembler = arm_target.assembler
|
386
|
18 self.assembler.prepare()
|
340
|
19
|
|
20 def testMovImm(self):
|
|
21 self.feed('mov r4, 100')
|
|
22 self.check('6440a0e3')
|
345
|
23
|
346
|
24 def testMovImm2(self):
|
|
25 self.feed('mov sp, 0x6000')
|
|
26 self.check('06daa0e3')
|
|
27
|
362
|
28 def testMovReg(self):
|
|
29 self.feed('mov r3, sp')
|
|
30 self.feed('mov pc, lr')
|
|
31 self.feed('mov pc, r2')
|
|
32 self.feed('mov sp, r4')
|
|
33 self.feed('mov r5, r6')
|
|
34 self.check('0d30a0e1 0ef0a0e1 02f0a0e1 04d0a0e1 0650a0e1')
|
|
35
|
345
|
36 def testAdd2(self):
|
|
37 self.feed('add r12, r11, 300')
|
|
38 self.check('4bcf8be2')
|
|
39
|
|
40 def testAdd1(self):
|
|
41 self.feed('add r9, r7, r2')
|
|
42 self.check('029087e0')
|
|
43
|
|
44 def testSub1(self):
|
|
45 self.feed('sub r5, r6, r2')
|
|
46 self.check('025046e0')
|
|
47
|
|
48 def testSub2(self):
|
|
49 self.feed('sub r0, r1, 0x80000001')
|
|
50 self.check('060141e2')
|
|
51
|
356
|
52 def testAnd1(self):
|
|
53 self.feed('and r9, r0, r2')
|
|
54 self.feed('and r4, r8, r6')
|
|
55 self.check('029000e0 064008e0')
|
|
56
|
345
|
57 def testOrr1(self):
|
|
58 self.feed('orr r8, r7, r6')
|
|
59 self.check('068087e1')
|
|
60
|
356
|
61 def testLsl(self):
|
|
62 self.feed('lsl r11, r5, r3')
|
|
63 self.feed('lsl r4, r8, r6')
|
|
64 self.check('15b3a0e1 1846a0e1')
|
|
65
|
|
66 def testLsr(self):
|
|
67 self.feed('lsr r9, r0, r2')
|
|
68 self.feed('lsr r4, r8, r6')
|
|
69 self.check('3092a0e1 3846a0e1')
|
|
70
|
345
|
71 def testBranches(self):
|
381
|
72 self.feed("""b sjakie
|
|
73 ble sjakie
|
|
74 bgt sjakie
|
|
75 beq sjakie
|
|
76 bl sjakie
|
|
77 sjakie:
|
|
78 b sjakie
|
|
79 ble sjakie
|
|
80 bgt sjakie
|
|
81 beq sjakie
|
|
82 bl sjakie""")
|
345
|
83 self.check('030000ea 020000da 010000ca 0000000a ffffffeb feffffea fdffffda fcffffca fbffff0a faffffeb')
|
346
|
84
|
|
85 def testPush(self):
|
|
86 self.feed('push {r11,r5,r4,lr}')
|
|
87 self.check('30482de9')
|
|
88
|
|
89 def testPop(self):
|
|
90 self.feed('pop {r4,r5,r6}')
|
|
91 self.check('7000bde8')
|
|
92
|
|
93 def testStr(self):
|
|
94 self.feed('str r9, [r2, 33]')
|
|
95 self.check('219082e5')
|
|
96
|
|
97 def testLdr(self):
|
|
98 self.feed('ldr r5, [r3, 87]')
|
|
99 self.check('575093e5')
|
|
100
|
349
|
101 def testLdrLabel(self):
|
|
102 self.feed('ldr r5, lab1')
|
|
103 self.feed('ldr r11, lab1')
|
|
104 self.feed('ldr r10, lab1')
|
|
105 self.feed('lab1:')
|
|
106 self.feed('dcd 0x12345566')
|
|
107 self.check('04509fe5 00b09fe5 04a01fe5 66553412')
|
|
108
|
375
|
109 def testAdr(self):
|
|
110 self.feed('adr r5, cval')
|
|
111 self.feed('adr r9, cval')
|
|
112 self.feed('adr r8, cval')
|
|
113 self.feed('cval:')
|
|
114 self.feed('adr r11, cval')
|
|
115 self.feed('adr r12, cval')
|
|
116 self.feed('adr r1, cval')
|
|
117 self.check('04508fe2 00908fe2 04804fe2 08b04fe2 0cc04fe2 10104fe2')
|
|
118
|
|
119 def testLdrLabelAddress(self):
|
|
120 self.feed('ldr r8, =a')
|
|
121 self.feed('a:')
|
381
|
122 self.check('04801fe5 04000000')
|
|
123
|
|
124 def testLdrLabelAddressAt10000(self):
|
|
125 """ Link code at 0x10000 and check if symbol was correctly patched """
|
|
126 self.feed('ldr r8, =a')
|
|
127 self.feed('a:')
|
383
|
128 spec = """
|
|
129 MEMORY flash LOCATION=0x10000 SIZE=0x10000 {
|
|
130 SECTION(code)
|
|
131 }
|
|
132 """
|
|
133 layout = load_layout(io.StringIO(spec))
|
|
134 self.check('04801fe5 04000100', layout)
|
375
|
135
|
352
|
136 def testCmp(self):
|
|
137 self.feed('cmp r4, r11')
|
|
138 self.feed('cmp r5, 0x50000')
|
|
139 self.check('0b0054e1 050855e3')
|
|
140
|
346
|
141 def testSequence1(self):
|
|
142 self.feed('sub r4,r5,23')
|
|
143 self.feed('blt x')
|
|
144 self.feed('x:')
|
|
145 self.feed('mul r4,r5,r2')
|
|
146 self.check('174045e2 ffffffba 950204e0')
|
|
147
|
362
|
148 def testMcr(self):
|
|
149 """ Test move coprocessor register from arm register """
|
|
150 self.feed('mcr p15, 0, r1, c2, c0, 0')
|
|
151 self.feed('mcr p14, 0, r1, c8, c7, 0')
|
|
152 self.check('101f02ee 171e08ee')
|
|
153
|
|
154 def testMrc(self):
|
|
155 self.feed('mrc p15, 0, r1, c2, c0, 0')
|
|
156 self.feed('mrc p14, 0, r1, c8, c7, 0')
|
|
157 self.check('101f12ee 171e18ee')
|
|
158
|
386
|
159 def testRepeat(self):
|
|
160 self.feed('repeat 0x5')
|
|
161 self.feed('dcd 0x11')
|
|
162 self.feed('endrepeat')
|
|
163 self.check('11000000 11000000 11000000 11000000 11000000')
|
|
164
|
346
|
165
|
|
166 if __name__ == '__main__':
|
|
167 unittest.main()
|