- # Find start positions
- text16_start = getSectionsStart(textsections, firstfixed)
- data16_start = getSectionsStart(rodatasections + datasections, text16_start)
-
- # Write header and regular sections
- output = open(outname, 'wb')
- output.write(COMMONHEADER + """
- data16_start = 0x%x ;
- .data16 data16_start : {
-""" % data16_start)
- outSections(output, datasections)
- output.write("code16_rodata = . ;\n")
- outSections(output, rodatasections)
- output.write("""
- }
-
- text16_start = 0x%x ;
- .text16 text16_start : {
-""" % text16_start)
- outSections(output, textsections)
-
- # Write fixed sections
- for addr, section, extrasections in fixedsections:
- name = section[2]
- output.write(". = ( 0x%x - text16_start ) ;\n" % (addr,))
- output.write("*(%s)\n" % (name,))
- for extrasection in extrasections:
- output.write("*(%s)\n" % (extrasection[2],))
-
- # Write trailer
- output.write("""
- text16_end = ABSOLUTE(.) ;
- }
-
- /* Discard regular data sections to force a link error if
- * 16bit code attempts to access data not marked with VAR16
- */
- /DISCARD/ : { *(.text*) *(.rodata*) *(.data*) *(.bss*) *(COMMON) }
-""" + COMMONTRAILER)
-
- return data16_start
+ return fixedsections + extrasections, firstfixed
+
+def doLayout(sections16, sections32seg, sections32flat):
+ # Determine 16bit positions
+ textsections = getSectionsPrefix(sections16, '.text.')
+ rodatasections = (getSectionsPrefix(sections16, '.rodata.str1.1')
+ + getSectionsPrefix(sections16, '.rodata.__func__.'))
+ datasections = getSectionsPrefix(sections16, '.data16.')
+ fixedsections = getSectionsPrefix(sections16, '.fixedaddr.')
+
+ locs16fixed, firstfixed = fitSections(fixedsections, textsections)
+ prunesections = [i[1] for i in locs16fixed]
+ remsections = [i for i in textsections+rodatasections+datasections
+ if i not in prunesections]
+ locs16, code16_start = getSectionsStart(remsections, firstfixed)
+ locs16 = locs16 + locs16fixed
+ locs16.sort()
+
+ # Determine 32seg positions
+ textsections = getSectionsPrefix(sections32seg, '.text.')
+ rodatasections = (getSectionsPrefix(sections32seg, '.rodata.str1.1')
+ + getSectionsPrefix(sections32seg, '.rodata.__func__.'))
+ datasections = getSectionsPrefix(sections32seg, '.data32seg.')
+
+ locs32seg, code32seg_start = getSectionsStart(
+ textsections + rodatasections + datasections, code16_start)
+
+ # Determine 32flat positions
+ textsections = getSectionsPrefix(sections32flat, '.text.')
+ rodatasections = getSectionsPrefix(sections32flat, '.rodata')
+ datasections = getSectionsPrefix(sections32flat, '.data.')
+ bsssections = getSectionsPrefix(sections32flat, '.bss.')
+
+ locs32flat, code32flat_start = getSectionsStart(
+ textsections + rodatasections + datasections + bsssections
+ , code32seg_start + BUILD_BIOS_ADDR, 16)
+
+ # Print statistics
+ size16 = BUILD_BIOS_SIZE - code16_start
+ size32seg = code16_start - code32seg_start
+ size32flat = code32seg_start + BUILD_BIOS_ADDR - code32flat_start
+ print "16bit size: %d" % size16
+ print "32bit segmented size: %d" % size32seg
+ print "32bit flat size: %d" % size32flat
+
+ return locs16, locs32seg, locs32flat