annotate test/testarmasm.py @ 394:988f3fb861e4

c3 code generator rewrite
author Windel Bouwman
date Thu, 22 May 2014 08:14:12 +0200
parents 2ec730e45ea1
children
rev   line source
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
1 import unittest
383
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
2 import io
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
3 from ppci.outstream import BinaryOutputStream
335
582a1aaa3983 Added long branch format
Windel Bouwman
parents: 322
diff changeset
4 from ppci.objectfile import ObjectFile
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
5 from testasm import AsmTestCaseBase
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
6 from ppci.target.target_list import arm_target
383
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
7 from ppci.layout import load_layout
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
8
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
9
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
10 class ArmAssemblerTestCase(AsmTestCaseBase):
340
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 335
diff changeset
11 """ ARM-mode (not thumb-mode) instruction assembly test case """
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 335
diff changeset
12 def setUp(self):
385
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
13 self.target = arm_target
340
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 335
diff changeset
14 self.obj = ObjectFile()
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
15 self.ostream = BinaryOutputStream(self.obj)
383
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
16 self.ostream.select_section('code')
381
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
17 self.assembler = arm_target.assembler
386
2a970e7270e2 Added repeat assembler macro
Windel Bouwman
parents: 385
diff changeset
18 self.assembler.prepare()
340
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 335
diff changeset
19
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 335
diff changeset
20 def testMovImm(self):
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 335
diff changeset
21 self.feed('mov r4, 100')
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 335
diff changeset
22 self.check('6440a0e3')
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
23
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
24 def testMovImm2(self):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
25 self.feed('mov sp, 0x6000')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
26 self.check('06daa0e3')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
27
362
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
28 def testMovReg(self):
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
29 self.feed('mov r3, sp')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
30 self.feed('mov pc, lr')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
31 self.feed('mov pc, r2')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
32 self.feed('mov sp, r4')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
33 self.feed('mov r5, r6')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
34 self.check('0d30a0e1 0ef0a0e1 02f0a0e1 04d0a0e1 0650a0e1')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
35
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
36 def testAdd2(self):
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
37 self.feed('add r12, r11, 300')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
38 self.check('4bcf8be2')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
39
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
40 def testAdd1(self):
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
41 self.feed('add r9, r7, r2')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
42 self.check('029087e0')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
43
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
44 def testSub1(self):
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
45 self.feed('sub r5, r6, r2')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
46 self.check('025046e0')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
47
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
48 def testSub2(self):
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
49 self.feed('sub r0, r1, 0x80000001')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
50 self.check('060141e2')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
51
356
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
52 def testAnd1(self):
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
53 self.feed('and r9, r0, r2')
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
54 self.feed('and r4, r8, r6')
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
55 self.check('029000e0 064008e0')
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
56
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
57 def testOrr1(self):
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
58 self.feed('orr r8, r7, r6')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
59 self.check('068087e1')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
60
356
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
61 def testLsl(self):
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
62 self.feed('lsl r11, r5, r3')
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
63 self.feed('lsl r4, r8, r6')
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
64 self.check('15b3a0e1 1846a0e1')
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
65
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
66 def testLsr(self):
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
67 self.feed('lsr r9, r0, r2')
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
68 self.feed('lsr r4, r8, r6')
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
69 self.check('3092a0e1 3846a0e1')
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
70
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
71 def testBranches(self):
381
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
72 self.feed("""b sjakie
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
73 ble sjakie
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
74 bgt sjakie
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
75 beq sjakie
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
76 bl sjakie
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
77 sjakie:
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
78 b sjakie
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
79 ble sjakie
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
80 bgt sjakie
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
81 beq sjakie
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
82 bl sjakie""")
389
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 386
diff changeset
83 self.check('030000ea 020000da 010000ca 0000000a ffffffeb feffffea \
2ec730e45ea1 Added check for recursive struct
Windel Bouwman
parents: 386
diff changeset
84 fdffffda fcffffca fbffff0a faffffeb')
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
85
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
86 def testPush(self):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
87 self.feed('push {r11,r5,r4,lr}')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
88 self.check('30482de9')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
89
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
90 def testPop(self):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
91 self.feed('pop {r4,r5,r6}')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
92 self.check('7000bde8')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
93
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
94 def testStr(self):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
95 self.feed('str r9, [r2, 33]')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
96 self.check('219082e5')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
97
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
98 def testLdr(self):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
99 self.feed('ldr r5, [r3, 87]')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
100 self.check('575093e5')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
101
349
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
102 def testLdrLabel(self):
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
103 self.feed('ldr r5, lab1')
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
104 self.feed('ldr r11, lab1')
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
105 self.feed('ldr r10, lab1')
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
106 self.feed('lab1:')
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
107 self.feed('dcd 0x12345566')
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
108 self.check('04509fe5 00b09fe5 04a01fe5 66553412')
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
109
375
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 362
diff changeset
110 def testAdr(self):
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 362
diff changeset
111 self.feed('adr r5, cval')
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 362
diff changeset
112 self.feed('adr r9, cval')
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 362
diff changeset
113 self.feed('adr r8, cval')
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 362
diff changeset
114 self.feed('cval:')
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 362
diff changeset
115 self.feed('adr r11, cval')
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 362
diff changeset
116 self.feed('adr r12, cval')
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 362
diff changeset
117 self.feed('adr r1, cval')
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 362
diff changeset
118 self.check('04508fe2 00908fe2 04804fe2 08b04fe2 0cc04fe2 10104fe2')
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 362
diff changeset
119
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 362
diff changeset
120 def testLdrLabelAddress(self):
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 362
diff changeset
121 self.feed('ldr r8, =a')
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 362
diff changeset
122 self.feed('a:')
381
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
123 self.check('04801fe5 04000000')
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
124
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
125 def testLdrLabelAddressAt10000(self):
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
126 """ Link code at 0x10000 and check if symbol was correctly patched """
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
127 self.feed('ldr r8, =a')
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 375
diff changeset
128 self.feed('a:')
383
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
129 spec = """
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
130 MEMORY flash LOCATION=0x10000 SIZE=0x10000 {
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
131 SECTION(code)
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
132 }
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
133 """
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
134 layout = load_layout(io.StringIO(spec))
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
135 self.check('04801fe5 04000100', layout)
375
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 362
diff changeset
136
352
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 349
diff changeset
137 def testCmp(self):
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 349
diff changeset
138 self.feed('cmp r4, r11')
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 349
diff changeset
139 self.feed('cmp r5, 0x50000')
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 349
diff changeset
140 self.check('0b0054e1 050855e3')
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 349
diff changeset
141
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
142 def testSequence1(self):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
143 self.feed('sub r4,r5,23')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
144 self.feed('blt x')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
145 self.feed('x:')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
146 self.feed('mul r4,r5,r2')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
147 self.check('174045e2 ffffffba 950204e0')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
148
362
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
149 def testMcr(self):
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
150 """ Test move coprocessor register from arm register """
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
151 self.feed('mcr p15, 0, r1, c2, c0, 0')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
152 self.feed('mcr p14, 0, r1, c8, c7, 0')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
153 self.check('101f02ee 171e08ee')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
154
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
155 def testMrc(self):
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
156 self.feed('mrc p15, 0, r1, c2, c0, 0')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
157 self.feed('mrc p14, 0, r1, c8, c7, 0')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
158 self.check('101f12ee 171e18ee')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
159
386
2a970e7270e2 Added repeat assembler macro
Windel Bouwman
parents: 385
diff changeset
160 def testRepeat(self):
2a970e7270e2 Added repeat assembler macro
Windel Bouwman
parents: 385
diff changeset
161 self.feed('repeat 0x5')
2a970e7270e2 Added repeat assembler macro
Windel Bouwman
parents: 385
diff changeset
162 self.feed('dcd 0x11')
2a970e7270e2 Added repeat assembler macro
Windel Bouwman
parents: 385
diff changeset
163 self.feed('endrepeat')
2a970e7270e2 Added repeat assembler macro
Windel Bouwman
parents: 385
diff changeset
164 self.check('11000000 11000000 11000000 11000000 11000000')
2a970e7270e2 Added repeat assembler macro
Windel Bouwman
parents: 385
diff changeset
165
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
166
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
167 if __name__ == '__main__':
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
168 unittest.main()