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