Pack 16bit code into last part of f-segment.
authorKevin O'Connor <kevin@koconnor.net>
Sat, 23 May 2009 21:49:44 +0000 (17:49 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sat, 23 May 2009 21:49:44 +0000 (17:49 -0400)
Locate 16bit code into the top of the f-segment.  (Before some of the
    16bit code was located just after the 32bit code.)

src/rombios16.lds.S
src/rombios32.lds.S
tools/checkrom.py
tools/layoutrom.py

index a25392ce097e5cf3049afa72d1a1f69562166ac3..4793f56eceebd3888dea84284735df79025dabe6 100644 (file)
@@ -10,16 +10,11 @@ OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
 OUTPUT_ARCH("i386")
 SECTIONS
 {
-        .text16 ALIGN(_code32_code32_end - _code32_code32_start, 16) : {
-                code16_start = ABSOLUTE(.) ;
 
 // The actual placement of the 16bit sections is determined by the
 // script tools/layoutrom.py
 #include "../out/romlayout.lds"
 
-                code16_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) }
index 311da2579ce952ecc930bd0a1177cab7728acede..908201c90b7d8c14dfdf22bcf1b647e03c9cacfe 100644 (file)
@@ -19,6 +19,7 @@ SECTIONS
                 *(.data)
                 *(.bss)
                 *(COMMON)
+                freespace_start = . ;
                 code32_end = ABSOLUTE(.) ;
                 }
 }
index d03c794c98722785d7508376006b727f7afef075..7dc5afcbab5d75917ccc9c61bc8e25883cd19bbc 100755 (executable)
@@ -24,8 +24,8 @@ def main():
             c16e, f16e)
         sys.exit(1)
 
-    sizefree = syms['freespace1_end'] - syms['freespace1_start']
-    size16 = syms['code16_end'] - syms['code16_start'] - sizefree
+    sizefree = syms['freespace_end'] - syms['freespace_start']
+    size16 = syms['code16_end'] - syms['code16_start']
     size32 = syms['code32_end'] - syms['code32_start']
     totalc = size16+size32
     print "16bit size: %d" % size16
index bdafec0ab83f8fff9ae6af6581ce8d98dff83469..319111b6b9b101b7880e3459cbf231066b194aa5 100755 (executable)
@@ -31,6 +31,9 @@ def alignpos(pos, alignbytes):
 
 MAXPOS = 0x10000
 
+def outsection(file, name):
+    file.write("*(%s)\n" % (name,))
+
 def doLayout(sections, outname):
     textsections = []
     rodatasections = []
@@ -113,39 +116,57 @@ def doLayout(sections, outname):
 #            print "    Adding %s (size %d align %d) pos=%x avail=%d" % (
 #                fitsection[2], fitsection[0], fitsection[1]
 #                , fitnextaddr, nextfixedaddr - fitnextaddr)
-
     firstfixed = fixedsections[0][0]
+
+    # Find overall start position
+    restalign = 0
+    restspace = 0
+    restsections = []
+    for section in textsections + rodatasections + datasections:
+        size, align, name = section
+        if align > restalign:
+            restalign = align
+        restspace = alignpos(restspace, align) + size
+        restsections.append(section)
+    startrest = (firstfixed - restspace) / restalign * restalign
+
+    # Report stats
     total = MAXPOS-firstfixed
-    print "Fixed space: 0x%x-0x%x  total: %d  used: %d  Percent used: %.1f%%" % (
-        firstfixed, MAXPOS, total, totalused,
-        (float(totalused) / total) * 100.0)
+    slack = total - totalused
+    print ("Fixed space: 0x%x-0x%x  total: %d  slack: %d"
+           "  Percent slack: %.1f%%" % (
+            firstfixed, MAXPOS, total, slack,
+            (float(slack) / total) * 100.0))
 
-    # Write regular sections
+    # Write header
     output = open(outname, 'wb')
-    for section in textsections:
-        name = section[2]
-        output.write("*(%s)\n" % (name,))
-    output.write("code16_rodata = . ;\n")
-    for section in rodatasections:
-        name = section[2]
-        output.write("*(%s)\n" % (name,))
-    for section in datasections:
+    output.write("""
+        .text16 0x%x : {
+                code16_start = ABSOLUTE(.) ;
+                freespace_end = . ;
+""" % startrest)
+
+    # Write regular sections
+    for section in restsections:
         name = section[2]
-        output.write("*(%s)\n" % (name,))
+        if name == rodatasections[0][2]:
+            output.write("code16_rodata = . ;\n")
+        outsection(output, name)
 
     # Write fixed sections
-    output.write("freespace1_start = . ;\n")
-    first = 1
     for addr, section, extrasections in fixedsections:
         name = section[2]
         output.write(". = ( 0x%x - code16_start ) ;\n" % (addr,))
-        if first:
-            first = 0
-            output.write("freespace1_end = . ;\n")
         output.write("*(%s)\n" % (name,))
         for extrasection in extrasections:
-            name = extrasection[2]
-            output.write("*(%s)\n" % (name,))
+            outsection(output, extrasection[2])
+
+    # Write trailer
+    output.write("""
+                code16_end = ABSOLUTE(.) ;
+        }
+""")
+
 
 if __name__ == '__main__':
     main()