2 # Script to arrange sections to ensure fixed offsets.
4 # Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
6 # This file may be distributed under the terms of the GNU GPLv3 license.
11 # Read in section names and sizes
13 # sections = [(idx, name, size, align), ...]
15 for line in sys.stdin.readlines():
17 idx, name, size, vma, lma, fileoff, align = line.split()
18 if align[:3] != '2**':
21 int(idx), name, int(size, 16), int(align[3:])))
25 # fixedsections = [(addr, sectioninfo), ...]
31 # Find desired sections.
32 for section in sections:
34 if name[:11] == '.fixedaddr.':
35 addr = int(name[11:], 16)
36 fixedsections.append((addr, section))
37 if name[:6] == '.text.':
38 textsections.append(section)
39 if name[:17] == '.rodata.__func__.' or name == '.rodata.str1.1':
40 rodatasections.append(section)
41 if name[:8] == '.data16.':
42 datasections.append(section)
44 # Write regular sections
45 for section in textsections:
47 sys.stdout.write("*(%s)\n" % (name,))
48 sys.stdout.write("code16_rodata = . ;\n")
49 for section in rodatasections:
51 sys.stdout.write("*(%s)\n" % (name,))
52 for section in datasections:
54 sys.stdout.write("*(%s)\n" % (name,))
56 # Write fixed sections
57 sys.stdout.write("freespace1_start = . ;\n")
59 for addr, section in fixedsections:
61 sys.stdout.write(". = ( 0x%x - code16_start ) ;\n" % (addr,))
64 sys.stdout.write("freespace1_end = . ;\n")
65 sys.stdout.write("*(%s)\n" % (name,))
67 if __name__ == '__main__':