annotate test/testarmasm.py @ 382:0c44e494ef58

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