261
|
1 import struct
|
290
|
2 from .basetarget import Register, Instruction, Target, Label, LabelRef
|
|
3 from .basetarget import Imm32, Imm8, Imm7, Imm3
|
292
|
4 from .arminstructions import allins, Reg8Op, ArmRegister
|
|
5 from .arminstructions import Dcd, B
|
|
6 from .arminstructions import R0, R1, R2, R3, R4, R5, R6, R7, LR, PC, SP
|
202
|
7
|
290
|
8
|
|
9 """ ARM target description. """
|
287
|
10
|
218
|
11 # TODO: encode this in DSL (domain specific language)
|
275
|
12 # TBD: is this required?
|
292
|
13 # TODO: make a difference between armv7 and armv5?
|
219
|
14
|
277
|
15
|
292
|
16 class ArmTarget(Target):
|
|
17 def __init__(self):
|
|
18 super().__init__('arm')
|
|
19 for i in allins:
|
|
20 self.addInstruction(i)
|
|
21 # TODO: fix this nicer?
|
|
22 #setattr(self, i.__name__, i)
|
|
23 self.check()
|
277
|
24
|
292
|
25 def startCode(self, outs):
|
|
26 """ Emit some startup code in the output stream """
|
|
27 outs.selectSection('code')
|
|
28 # assembly glue to make it work:
|
|
29 # TODO: this must be in source code, not in compiler
|
|
30 outs.emit(Dcd(Imm32(0x20000678))) # initial SP
|
|
31 outs.emit(Dcd(Imm32(0x08000009))) # reset vector
|
|
32 outs.emit(B(LabelRef('main')))
|