comparison python/ppci/linker.py @ 381:6df89163e114

Fix section and ldr pseudo instruction
author Windel Bouwman
date Sat, 26 Apr 2014 17:41:56 +0200
parents 9667d78ba79e
children 173e20a47fda
comparison
equal deleted inserted replaced
380:67a584582aee 381:6df89163e114
97 offset = (sym.value - (reloc_value + 8)) 97 offset = (sym.value - (reloc_value + 8))
98 U = 1 98 U = 1
99 if offset < 0: 99 if offset < 0:
100 offset = -offset 100 offset = -offset
101 U = 0 101 U = 0
102 assert offset < 4096 102 assert offset < 4096, str(sym) + str(section) + str(reloc)
103 section.data[reloc.offset+2] |= (U << 7) 103 section.data[reloc.offset+2] |= (U << 7)
104 section.data[reloc.offset+1] |= (offset >> 8) & 0xF 104 section.data[reloc.offset+1] |= (offset >> 8) & 0xF
105 section.data[reloc.offset+0] = offset & 0xFF 105 section.data[reloc.offset+0] = offset & 0xFF
106 106
107 @reloc('adr_imm12') 107 @reloc('adr_imm12')
128 section.data[reloc.offset+2] = (offset >> 16) & 0xFF 128 section.data[reloc.offset+2] = (offset >> 16) & 0xFF
129 section.data[reloc.offset+1] = (offset >> 8) & 0xFF 129 section.data[reloc.offset+1] = (offset >> 8) & 0xFF
130 section.data[reloc.offset+0] = offset & 0xFF 130 section.data[reloc.offset+0] = offset & 0xFF
131 131
132 132
133 class Layout:
134 pass
135
136 class Linker: 133 class Linker:
137 """ Merges the sections of several object files and 134 """ Merges the sections of several object files and
138 performs relocation """ 135 performs relocation """
139 def __init__(self): 136 def __init__(self):
140 self.logger = logging.getLogger('Linker') 137 self.logger = logging.getLogger('Linker')
141 138
142 def link(self, objs, layout={}): 139 def link(self, objs, layout):
143 assert type(objs) is list 140 assert type(objs) is list
144 # Create new object file to store output: 141 # Create new object file to store output:
145 self.dst = ObjectFile() 142 self.dst = ObjectFile()
146 143
147 # Create sections with address: 144 # Create sections with address:
173 # Merge relocations: 170 # Merge relocations:
174 for reloc in iobj.relocations: 171 for reloc in iobj.relocations:
175 offset = offsets[reloc.section] + reloc.offset 172 offset = offsets[reloc.section] + reloc.offset
176 self.dst.add_relocation(reloc.sym, offset, reloc.typ, reloc.section) 173 self.dst.add_relocation(reloc.sym, offset, reloc.typ, reloc.section)
177 174
175 # Apply layout rules:
176 # TODO
177
178 # Perform relocations: 178 # Perform relocations:
179 for reloc in self.dst.relocations: 179 for reloc in self.dst.relocations:
180 # Lookup symbol: 180 # Lookup symbol:
181 if reloc.sym not in self.dst.symbols: 181 if reloc.sym not in self.dst.symbols:
182 raise CompilerError('Undefined reference "{}"'.format(reloc.sym)) 182 raise CompilerError('Undefined reference "{}"'.format(reloc.sym))