comparison test/testarmasm.py @ 345:b4882ff0ed06

Added more arm isa tests
author Windel Bouwman
date Sun, 02 Mar 2014 17:12:08 +0100
parents 86b02c98a717
children 3bb7dcfe5529
comparison
equal deleted inserted replaced
344:1378c4b027a0 345:b4882ff0ed06
1 import unittest 1 import unittest
2 from ppci.outstream import BinaryOutputStream 2 from ppci.outstream import BinaryOutputStream
3 from ppci.objectfile import ObjectFile 3 from ppci.objectfile import ObjectFile
4 from asm import Assembler 4 from asm import Assembler
5 from testasm import AsmTestCaseBase 5 from testasm import AsmTestCaseBase
6 from ppci.target.target_list import arm_target, thumb_target 6 from ppci.target.target_list import arm_target
7 7
8 8
9 class ThumbAssemblerTestCase(AsmTestCaseBase):
10 def setUp(self):
11 self.t = thumb_target
12 self.obj = ObjectFile()
13 self.o = BinaryOutputStream(self.obj)
14 self.o.selectSection('.text')
15 self.a = Assembler(target=self.t, stream=self.o)
16 9
17 def testMovImm8(self): 10 class ArmAssemblerTestCase(AsmTestCaseBase):
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')
149
150
151 class AssemblerArmTestCase(AsmTestCaseBase):
152 """ ARM-mode (not thumb-mode) instruction assembly test case """ 11 """ ARM-mode (not thumb-mode) instruction assembly test case """
153 def setUp(self): 12 def setUp(self):
154 self.t = arm_target 13 self.t = arm_target
155 self.obj = ObjectFile() 14 self.obj = ObjectFile()
156 self.o = BinaryOutputStream(self.obj) 15 self.o = BinaryOutputStream(self.obj)
158 self.a = Assembler(target=self.t, stream=self.o) 17 self.a = Assembler(target=self.t, stream=self.o)
159 18
160 def testMovImm(self): 19 def testMovImm(self):
161 self.feed('mov r4, 100') 20 self.feed('mov r4, 100')
162 self.check('6440a0e3') 21 self.check('6440a0e3')
22
23 def testAdd2(self):
24 self.feed('add r12, r11, 300')
25 self.check('4bcf8be2')
26
27 def testAdd1(self):
28 self.feed('add r9, r7, r2')
29 self.check('029087e0')
30
31 def testSub1(self):
32 self.feed('sub r5, r6, r2')
33 self.check('025046e0')
34
35 def testSub2(self):
36 self.feed('sub r0, r1, 0x80000001')
37 self.check('060141e2')
38
39 def testOrr1(self):
40 self.feed('orr r8, r7, r6')
41 self.check('068087e1')
42
43 def testBranches(self):
44 self.feed('b sjakie')
45 self.feed('ble sjakie')
46 self.feed('bgt sjakie')
47 self.feed('beq sjakie')
48 self.feed('bl sjakie')
49 self.feed('sjakie:')
50 self.feed('b sjakie')
51 self.feed('ble sjakie')
52 self.feed('bgt sjakie')
53 self.feed('beq sjakie')
54 self.feed('bl sjakie')
55 self.check('030000ea 020000da 010000ca 0000000a ffffffeb feffffea fdffffda fcffffca fbffff0a faffffeb')