292
|
1 import unittest
|
342
|
2 from ppci.outstream import BinaryOutputStream
|
335
|
3 from ppci.objectfile import ObjectFile
|
292
|
4 from asm import Assembler
|
|
5 from testasm import AsmTestCaseBase
|
345
|
6 from ppci.target.target_list import arm_target
|
292
|
7
|
|
8
|
346
|
9 a = Assembler(arm_target)
|
292
|
10
|
345
|
11 class ArmAssemblerTestCase(AsmTestCaseBase):
|
340
|
12 """ ARM-mode (not thumb-mode) instruction assembly test case """
|
|
13 def setUp(self):
|
341
|
14 self.t = arm_target
|
340
|
15 self.obj = ObjectFile()
|
346
|
16 self.ostream = BinaryOutputStream(self.obj)
|
348
|
17 self.ostream.select_section('.text')
|
346
|
18 self.a = a #Assembler(target=self.t)
|
340
|
19
|
|
20 def testMovImm(self):
|
|
21 self.feed('mov r4, 100')
|
|
22 self.check('6440a0e3')
|
345
|
23
|
346
|
24 def testMovImm2(self):
|
|
25 self.feed('mov sp, 0x6000')
|
|
26 self.check('06daa0e3')
|
|
27
|
345
|
28 def testAdd2(self):
|
|
29 self.feed('add r12, r11, 300')
|
|
30 self.check('4bcf8be2')
|
|
31
|
|
32 def testAdd1(self):
|
|
33 self.feed('add r9, r7, r2')
|
|
34 self.check('029087e0')
|
|
35
|
|
36 def testSub1(self):
|
|
37 self.feed('sub r5, r6, r2')
|
|
38 self.check('025046e0')
|
|
39
|
|
40 def testSub2(self):
|
|
41 self.feed('sub r0, r1, 0x80000001')
|
|
42 self.check('060141e2')
|
|
43
|
|
44 def testOrr1(self):
|
|
45 self.feed('orr r8, r7, r6')
|
|
46 self.check('068087e1')
|
|
47
|
|
48 def testBranches(self):
|
|
49 self.feed('b sjakie')
|
|
50 self.feed('ble sjakie')
|
|
51 self.feed('bgt sjakie')
|
|
52 self.feed('beq sjakie')
|
|
53 self.feed('bl sjakie')
|
|
54 self.feed('sjakie:')
|
|
55 self.feed('b sjakie')
|
|
56 self.feed('ble sjakie')
|
|
57 self.feed('bgt sjakie')
|
|
58 self.feed('beq sjakie')
|
|
59 self.feed('bl sjakie')
|
|
60 self.check('030000ea 020000da 010000ca 0000000a ffffffeb feffffea fdffffda fcffffca fbffff0a faffffeb')
|
346
|
61
|
|
62 def testPush(self):
|
|
63 self.feed('push {r11,r5,r4,lr}')
|
|
64 self.check('30482de9')
|
|
65
|
|
66 def testPop(self):
|
|
67 self.feed('pop {r4,r5,r6}')
|
|
68 self.check('7000bde8')
|
|
69
|
|
70 def testStr(self):
|
|
71 self.feed('str r9, [r2, 33]')
|
|
72 self.check('219082e5')
|
|
73
|
|
74 def testLdr(self):
|
|
75 self.feed('ldr r5, [r3, 87]')
|
|
76 self.check('575093e5')
|
|
77
|
349
|
78 def testLdrLabel(self):
|
|
79 self.feed('ldr r5, lab1')
|
|
80 self.feed('ldr r11, lab1')
|
|
81 self.feed('ldr r10, lab1')
|
|
82 self.feed('lab1:')
|
|
83 self.feed('dcd 0x12345566')
|
|
84 self.check('04509fe5 00b09fe5 04a01fe5 66553412')
|
|
85
|
352
|
86 def testCmp(self):
|
|
87 self.feed('cmp r4, r11')
|
|
88 self.feed('cmp r5, 0x50000')
|
|
89 self.check('0b0054e1 050855e3')
|
|
90
|
346
|
91 def testSequence1(self):
|
|
92 self.feed('sub r4,r5,23')
|
|
93 self.feed('blt x')
|
|
94 self.feed('x:')
|
|
95 self.feed('mul r4,r5,r2')
|
|
96 self.check('174045e2 ffffffba 950204e0')
|
|
97
|
354
|
98 def testAdr(self):
|
|
99 self.feed('adr r5, cval')
|
|
100 self.feed('adr r9, cval')
|
|
101 self.feed('adr r8, cval')
|
|
102 self.feed('cval:')
|
|
103 self.feed('adr r11, cval')
|
|
104 self.feed('adr r12, cval')
|
|
105 self.feed('adr r1, cval')
|
|
106 self.check('04508fe2 00908fe2 04804fe2 08b04fe2 0cc04fe2 10104fe2')
|
|
107
|
346
|
108
|
|
109 if __name__ == '__main__':
|
|
110 unittest.main()
|