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