avr: automatically generate interrupt vectors

This commit is contained in:
Ayke van Laethem
2018-09-23 20:37:22 +02:00
parent 3850530c88
commit b9638315d2
5 changed files with 61 additions and 15 deletions
+37
View File
@@ -201,6 +201,42 @@ const (
out.write('\n')
out.write(')\n')
def writeAsm(outdir, device):
# The interrupt vector, which is hard to write directly in Go.
out = open(outdir + '/' + device.metadata['nameLower'] + '.s', 'w')
out.write('''\
; Automatically generated file. DO NOT EDIT.
; Generated by gen-device-avr.py from {file}, see {descriptorSource}
; Avoid the need for repeated .weak and .set instructions.
.macro IRQ handler
.weak \\handler
.set \\handler, __vector_default
.endm
; The interrupt vector of this device. Must be placed at address 0 by the linker.
.section .vectors
.global __vectors
'''.format(**device.metadata))
num = 0
for intr in device.interrupts:
if intr['index'] < num:
# Some devices have duplicate interrupts, probably for historical
# reasons.
continue
while intr['index'] > num:
out.write(' jmp __vector_default\n')
num += 1
num += 1
out.write(' jmp __vector_{name}\n'.format(**intr))
out.write('''
; Define default implementations for interrupts, redirecting to
; __vector_default when not implemented.
''')
for intr in device.interrupts:
out.write(' IRQ __vector_{name}\n'.format(**intr))
def writeLD(outdir, device):
# Variables for the linker script.
out = open(outdir + '/' + device.metadata['nameLower'] + '.ld', 'w')
@@ -220,6 +256,7 @@ def generate(indir, outdir):
print(filepath)
device = readATDF(filepath)
writeGo(outdir, device)
writeAsm(outdir, device)
writeLD(outdir, device)