comparison test/testarmasm.py @ 383:173e20a47fda

Added linker description loader
author Windel Bouwman
date Sun, 27 Apr 2014 17:40:39 +0200
parents 6df89163e114
children d056b552d3f4
comparison
equal deleted inserted replaced
382:0c44e494ef58 383:173e20a47fda
1 import unittest 1 import unittest
2 import io
2 from ppci.outstream import BinaryOutputStream 3 from ppci.outstream import BinaryOutputStream
3 from ppci.objectfile import ObjectFile 4 from ppci.objectfile import ObjectFile
4 from testasm import AsmTestCaseBase 5 from testasm import AsmTestCaseBase
5 from ppci.target.target_list import arm_target 6 from ppci.target.target_list import arm_target
7 from ppci.layout import load_layout
6 8
7 9
8 class ArmAssemblerTestCase(AsmTestCaseBase): 10 class ArmAssemblerTestCase(AsmTestCaseBase):
9 """ ARM-mode (not thumb-mode) instruction assembly test case """ 11 """ ARM-mode (not thumb-mode) instruction assembly test case """
10 def setUp(self): 12 def setUp(self):
11 self.t = arm_target 13 self.t = arm_target
12 self.obj = ObjectFile() 14 self.obj = ObjectFile()
13 self.ostream = BinaryOutputStream(self.obj) 15 self.ostream = BinaryOutputStream(self.obj)
14 self.ostream.select_section('.text') 16 self.ostream.select_section('code')
15 self.assembler = arm_target.assembler 17 self.assembler = arm_target.assembler
16 18
17 def testMovImm(self): 19 def testMovImm(self):
18 self.feed('mov r4, 100') 20 self.feed('mov r4, 100')
19 self.check('6440a0e3') 21 self.check('6440a0e3')
120 122
121 def testLdrLabelAddressAt10000(self): 123 def testLdrLabelAddressAt10000(self):
122 """ Link code at 0x10000 and check if symbol was correctly patched """ 124 """ Link code at 0x10000 and check if symbol was correctly patched """
123 self.feed('ldr r8, =a') 125 self.feed('ldr r8, =a')
124 self.feed('a:') 126 self.feed('a:')
125 self.check('04801fe5 04000100', {'.text':0x10000}) 127 spec = """
128 MEMORY flash LOCATION=0x10000 SIZE=0x10000 {
129 SECTION(code)
130 }
131 """
132 layout = load_layout(io.StringIO(spec))
133 self.check('04801fe5 04000100', layout)
126 134
127 def testCmp(self): 135 def testCmp(self):
128 self.feed('cmp r4, r11') 136 self.feed('cmp r4, r11')
129 self.feed('cmp r5, 0x50000') 137 self.feed('cmp r5, 0x50000')
130 self.check('0b0054e1 050855e3') 138 self.check('0b0054e1 050855e3')