annotate test/testarmasm.py @ 342:86b02c98a717 devel

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