292
|
1 import unittest
|
342
|
2 from ppci.outstream import BinaryOutputStream
|
335
|
3 from ppci.objectfile import ObjectFile
|
292
|
4 from asm import Assembler
|
|
5 from testasm import AsmTestCaseBase
|
342
|
6 from ppci.target.target_list import arm_target, thumb_target
|
292
|
7
|
|
8
|
341
|
9 class ThumbAssemblerTestCase(AsmTestCaseBase):
|
292
|
10 def setUp(self):
|
341
|
11 self.t = thumb_target
|
335
|
12 self.obj = ObjectFile()
|
342
|
13 self.o = BinaryOutputStream(self.obj)
|
292
|
14 self.o.selectSection('.text')
|
|
15 self.a = Assembler(target=self.t, stream=self.o)
|
|
16
|
|
17 def testMovImm8(self):
|
|
18 self.feed('mov r4, 100')
|
|
19 self.check('6424')
|
|
20
|
|
21 @unittest.skip
|
|
22 def testMovExt(self):
|
|
23 self.feed('mov r3, sp')
|
|
24 self.check('')
|
|
25
|
|
26 def testYield(self):
|
|
27 self.feed('yield')
|
|
28 self.check('10bf')
|
|
29
|
|
30 def testPush(self):
|
|
31 self.feed('push {r2,r3,lr}')
|
|
32 self.check('0cb5')
|
|
33
|
|
34 def testPop(self):
|
|
35 self.feed('pop {r4-r6, pc}')
|
|
36 self.check('70bd')
|
|
37
|
|
38 def testStr5(self):
|
|
39 self.feed('str r4, [r1 + 0]')
|
|
40 self.check('0c60')
|
|
41
|
|
42 def testLdr5(self):
|
|
43 self.feed('ldr r4, [r0 + 0]')
|
|
44 self.check('0468')
|
|
45
|
|
46 def testLdrSpRel(self):
|
|
47 self.feed('ldr r0, [sp + 4]')
|
|
48 self.check('0198')
|
|
49
|
|
50 def testStrSpRel(self):
|
|
51 self.feed('str r0, [sp + 4]')
|
|
52 self.check('0190')
|
|
53
|
|
54 def testLdrPcRel(self):
|
|
55 self.feed('ldr r7, henkie')
|
|
56 self.feed('ldr r6, henkie')
|
|
57 self.feed('ldr r1, henkie')
|
|
58 self.feed('align 4')
|
|
59 self.feed('dcd 1')
|
|
60 self.feed('henkie: dcd 2')
|
|
61 self.check('024F024E 01490000 01000000 02000000')
|
|
62
|
|
63 def testBranch(self):
|
|
64 self.feed('start: b henkie')
|
|
65 self.feed('beq henkie')
|
|
66 self.feed('bne henkie')
|
|
67 self.feed('henkie: b start')
|
|
68 self.feed('eof: b eof')
|
|
69 self.check('01e000d0 ffd1fbe7 fee7')
|
|
70
|
|
71 def testConditions(self):
|
|
72 self.feed('blt x')
|
|
73 self.feed('bgt x')
|
|
74 self.feed('x:')
|
|
75 self.check('00dbffdc')
|
|
76
|
|
77 def testBoff(self):
|
|
78 self.feed('b henkie')
|
|
79 self.feed('b henkie')
|
|
80 self.feed('b henkie')
|
|
81 self.feed('b henkie')
|
|
82 self.feed('b henkie')
|
|
83 self.feed('b henkie')
|
|
84 self.feed('b henkie')
|
|
85 self.feed('henkie:')
|
|
86 self.feed('b henkie')
|
|
87 self.feed('b henkie')
|
|
88 self.feed('b henkie')
|
|
89 self.feed('b henkie')
|
|
90 self.check('05e004e0 03e002e0 01e000e0 ffe7fee7 fde7fce7 fbe7')
|
|
91
|
|
92 def testBl(self):
|
|
93 self.feed('bl henkie')
|
|
94 self.feed('bl henkie')
|
|
95 self.feed('henkie:')
|
|
96 self.feed('bl henkie')
|
|
97 self.feed('bl henkie')
|
|
98 self.check('00f0 02f8 00f0 00f8 fff7 feff fff7 fcff')
|
|
99
|
|
100 def testCmpRegReg(self):
|
|
101 self.feed('cmp r0, r1')
|
|
102 self.check('8842')
|
|
103
|
|
104 def testAddimm3(self):
|
|
105 self.feed('add r3, r5, 2')
|
|
106 self.feed('add r4, r1, 6')
|
|
107 self.check('ab1c8c1d')
|
|
108
|
|
109 def testSubImm3(self):
|
|
110 self.feed('sub r3, r5, 2')
|
|
111 self.feed('sub r4, r1, 6')
|
|
112 self.check('ab1e8c1f')
|
|
113
|
|
114 def testLeftShift(self):
|
|
115 self.feed('lsl r3, r5')
|
|
116 self.check('ab40')
|
|
117
|
|
118 def testAddSp(self):
|
|
119 self.feed('add sp,sp,8')
|
|
120 self.feed('add sp,sp,16')
|
|
121 self.check('02b004b0')
|
|
122
|
|
123 def testSubSp(self):
|
|
124 self.feed('sub sp,sp,32')
|
|
125 self.feed('sub sp,sp,4')
|
|
126 self.check('88b081b0')
|
|
127
|
|
128 def testSequence1(self):
|
|
129 self.feed('mov r5, 3')
|
|
130 self.feed('add r4, r5, 0')
|
|
131 self.feed('loop: add r6, r4, 7')
|
|
132 self.feed('cmp r6, 5')
|
|
133 self.check('0325 2c1c e61d 052e')
|
|
134
|
|
135 def testSequence2(self):
|
|
136 self.feed('henkie:')
|
|
137 self.feed('push {r1,r4,r5}')
|
|
138 self.feed('add r5, r2, r4')
|
|
139 self.feed('cmp r4, r2')
|
|
140 self.feed('ldr r0, [sp + 4]')
|
|
141 self.feed('str r3, [sp + 16]')
|
|
142 self.feed('pop {r1, r4, r5}')
|
|
143 self.feed('lsl r3, r4')
|
|
144 self.feed('cmp r3, r5')
|
|
145 self.feed('beq henkie')
|
|
146 self.feed('bne henkie')
|
|
147 self.feed('b henkie')
|
|
148 self.check('32b41519 94420198 049332bc a340ab42 f6d0f5d1 f4e7')
|
340
|
149
|
|
150
|
|
151 class AssemblerArmTestCase(AsmTestCaseBase):
|
|
152 """ ARM-mode (not thumb-mode) instruction assembly test case """
|
|
153 def setUp(self):
|
341
|
154 self.t = arm_target
|
340
|
155 self.obj = ObjectFile()
|
342
|
156 self.o = BinaryOutputStream(self.obj)
|
340
|
157 self.o.selectSection('.text')
|
|
158 self.a = Assembler(target=self.t, stream=self.o)
|
|
159
|
|
160 def testMovImm(self):
|
|
161 self.feed('mov r4, 100')
|
|
162 self.check('6440a0e3')
|