From 202024a27b171700f95717a6ef9c23bcf04d9fc1 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 17 Jan 2009 10:41:28 -0500 Subject: Layout fixed area using linker instead of assembler. The fixed offset requirements of the 16bit code can be done using multiple sections and a linker script. Using the linker allows for more flexibility. Also, have the 16bit code generate sections for every function and variable definition. --- tools/checkrom.py | 19 +++++++-------- tools/layoutrom.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 11 deletions(-) create mode 100755 tools/layoutrom.py (limited to 'tools') diff --git a/tools/checkrom.py b/tools/checkrom.py index 7ba4d0de..6b5f1e9f 100755 --- a/tools/checkrom.py +++ b/tools/checkrom.py @@ -19,22 +19,19 @@ def main(): c16s = syms['code16_start'] + 0xf0000 c32s = syms['final_code16_start'] - f16s = syms['code16_fixed_start'] + 0xf0000 - f32s = syms['final_code16_fixed_start'] - if c16s != c32s or f16s != f32s: - print ("Error! 16bit code moved during linking" - " (0x%x vs 0x%x, 0x%x vs 0x%x)" % ( - c32s, c16s, f16s, f32s)) + if c16s != c32s: + print "Error! 16bit code moved during linking (0x%x vs 0x%x)" % ( + c32s, c16s) sys.exit(1) - size16 = syms['code16_end'] - syms['code16_start'] + sizefree = syms['freespace1_end'] - syms['freespace1_start'] + size16 = syms['code16_end'] - syms['code16_start'] - sizefree size32 = syms['code32_end'] - syms['code32_start'] totalc = size16+size32 - sizefree = syms['freespace1_end'] - syms['freespace1_start'] tablefree = syms['freespace2_end'] - syms['freespace2_start'] - print "16bit C-code size: %d" % size16 - print "32bit C-code size: %d" % size32 - print "Total C-code size: %d Free space: %d Percent used: %.1f%%" % ( + print "16bit size: %d" % size16 + print "32bit size: %d" % size32 + print "Total size: %d Free space: %d Percent used: %.1f%%" % ( totalc, sizefree , (totalc / float(size16+size32+sizefree)) * 100.0) print "BIOS table space: %d" % tablefree diff --git a/tools/layoutrom.py b/tools/layoutrom.py new file mode 100755 index 00000000..f1fe0e10 --- /dev/null +++ b/tools/layoutrom.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# Script to arrange sections to ensure fixed offsets. +# +# Copyright (C) 2008 Kevin O'Connor +# +# This file may be distributed under the terms of the GNU GPLv3 license. + +import sys + +def main(): + # Read in section names and sizes + + # sections = [(idx, name, size, align), ...] + sections = [] + for line in sys.stdin.readlines(): + try: + idx, name, size, vma, lma, fileoff, align = line.split() + if align[:3] != '2**': + continue + sections.append(( + int(idx), name, int(size, 16), int(align[3:]))) + except: + pass + + # fixedsections = [(addr, sectioninfo), ...] + fixedsections = [] + textsections = [] + rodatasections = [] + datasections = [] + + # Find desired sections. + for section in sections: + name = section[1] + if name[:11] == '.fixedaddr.': + addr = int(name[11:], 16) + fixedsections.append((addr, section)) + if name[:6] == '.text.': + textsections.append(section) + if name[:17] == '.rodata.__func__.' or name == '.rodata.str1.1': + rodatasections.append(section) + if name[:8] == '.data16.': + datasections.append(section) + + # Write regular sections + for section in textsections: + name = section[1] + sys.stdout.write("*(%s)\n" % (name,)) + sys.stdout.write("code16_rodata = . ;\n") + for section in rodatasections: + name = section[1] + sys.stdout.write("*(%s)\n" % (name,)) + for section in datasections: + name = section[1] + sys.stdout.write("*(%s)\n" % (name,)) + + # Write fixed sections + sys.stdout.write("freespace1_start = . ;\n") + first = 1 + for addr, section in fixedsections: + name = section[1] + sys.stdout.write(". = ( 0x%x - code16_start ) ;\n" % (addr,)) + if first: + first = 0 + sys.stdout.write("freespace1_end = . ;\n") + sys.stdout.write("*(%s)\n" % (name,)) + +if __name__ == '__main__': + main() -- cgit