annotate test/testarmasm.py @ 371:9c95f93f5b7a

Python 3.2 compatible issues
author Windel Bouwman
date Fri, 21 Mar 2014 12:01:19 +0100
parents c05ab629976a
children 19eacf4f7270
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
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
6 from ppci.target.target_list import arm_target
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
7
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
8
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
9 a = Assembler(arm_target)
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
10
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
11 class ArmAssemblerTestCase(AsmTestCaseBase):
340
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 335
diff changeset
12 """ ARM-mode (not thumb-mode) instruction assembly test case """
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 335
diff changeset
13 def setUp(self):
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
14 self.t = arm_target
340
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 335
diff changeset
15 self.obj = ObjectFile()
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
16 self.ostream = BinaryOutputStream(self.obj)
348
442fb043d149 Added log option to zcc
Windel Bouwman
parents: 346
diff changeset
17 self.ostream.select_section('.text')
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
18 self.a = a #Assembler(target=self.t)
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):
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
72 self.feed('b sjakie')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
73 self.feed('ble sjakie')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
74 self.feed('bgt sjakie')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
75 self.feed('beq sjakie')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
76 self.feed('bl sjakie')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
77 self.feed('sjakie:')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
78 self.feed('b sjakie')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
79 self.feed('ble sjakie')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
80 self.feed('bgt sjakie')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
81 self.feed('beq sjakie')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
82 self.feed('bl sjakie')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
83 self.check('030000ea 020000da 010000ca 0000000a ffffffeb feffffea fdffffda fcffffca fbffff0a faffffeb')
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
84
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
85 def testPush(self):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
86 self.feed('push {r11,r5,r4,lr}')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
87 self.check('30482de9')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
88
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
89 def testPop(self):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
90 self.feed('pop {r4,r5,r6}')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
91 self.check('7000bde8')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
92
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
93 def testStr(self):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
94 self.feed('str r9, [r2, 33]')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
95 self.check('219082e5')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
96
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
97 def testLdr(self):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
98 self.feed('ldr r5, [r3, 87]')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
99 self.check('575093e5')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
100
349
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
101 def testLdrLabel(self):
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
102 self.feed('ldr r5, lab1')
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
103 self.feed('ldr r11, lab1')
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
104 self.feed('ldr r10, lab1')
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
105 self.feed('lab1:')
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
106 self.feed('dcd 0x12345566')
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
107 self.check('04509fe5 00b09fe5 04a01fe5 66553412')
13a6e73b448f Added test load from label
Windel Bouwman
parents: 348
diff changeset
108
352
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 349
diff changeset
109 def testCmp(self):
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 349
diff changeset
110 self.feed('cmp r4, r11')
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 349
diff changeset
111 self.feed('cmp r5, 0x50000')
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 349
diff changeset
112 self.check('0b0054e1 050855e3')
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 349
diff changeset
113
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
114 def testSequence1(self):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
115 self.feed('sub r4,r5,23')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
116 self.feed('blt x')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
117 self.feed('x:')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
118 self.feed('mul r4,r5,r2')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
119 self.check('174045e2 ffffffba 950204e0')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
120
354
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
121 def testAdr(self):
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
122 self.feed('adr r5, cval')
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
123 self.feed('adr r9, cval')
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
124 self.feed('adr r8, cval')
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
125 self.feed('cval:')
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
126 self.feed('adr r11, cval')
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
127 self.feed('adr r12, cval')
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
128 self.feed('adr r1, cval')
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
129 self.check('04508fe2 00908fe2 04804fe2 08b04fe2 0cc04fe2 10104fe2')
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
130
362
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
131 def testMcr(self):
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
132 """ Test move coprocessor register from arm register """
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
133 self.feed('mcr p15, 0, r1, c2, c0, 0')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
134 self.feed('mcr p14, 0, r1, c8, c7, 0')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
135 self.check('101f02ee 171e08ee')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
136
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
137 def testMrc(self):
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
138 self.feed('mrc p15, 0, r1, c2, c0, 0')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
139 self.feed('mrc p14, 0, r1, c8, c7, 0')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
140 self.check('101f12ee 171e18ee')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 356
diff changeset
141
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
142
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
143 if __name__ == '__main__':
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
144 unittest.main()