Relinking rom32.o twice seems flaky - make third link stage.
authorKevin O'Connor <kevin@koconnor.net>
Sun, 6 Jul 2008 13:56:14 +0000 (09:56 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 6 Jul 2008 13:56:14 +0000 (09:56 -0400)
Sigh - ld seems to move things around when relinking files.  So,
    separate out the link stages so that everything is incremental.
Also, improve diagnostics of checkrom.py tool.

Makefile
src/rombios.lds.S [new file with mode: 0644]
src/rombios16.lds.S
src/rombios32.lds.S
tools/checkrom.py

index 70b0a3efae6c21e842b4fc3da46732ecfbc0c018..caf3fcc4269a9900c8ca1cddc0fcb41d7528bf63 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -91,20 +91,20 @@ $(OUT)romlayout16.o: romlayout.S $(OUT)blob.16.s $(TABLEASM)
 
 $(OUT)romlayout32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
 
-$(OUT)rom32.notreloc.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
+$(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
        @echo "  Linking (no relocs) $@"
-       $(Q)ld -r -T $(OUT)rombios32.lds $< -o $@.raw
-       $(Q)objcopy --prefix-symbols=_code32_ $@.raw $@
+       $(Q)ld -r -T $(OUT)rombios32.lds $< -o $@
 
-$(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.notreloc.o $(OUT)rombios16.lds
+$(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)rombios16.lds
        @echo "  Linking $@"
-       $(Q)ld -T $(OUT)rombios16.lds -R $(OUT)rom32.notreloc.o $< -o $@
+       $(Q)objcopy --prefix-symbols=_code32_ $(OUT)rom32.o $(OUT)rom32.rename.o
+       $(Q)ld -T $(OUT)rombios16.lds -R $(OUT)rom32.rename.o $< -o $@
 
-$(OUT)rom32.o: $(OUT)rom16.o $(OUT)romlayout32.o $(OUT)rombios32.lds
+$(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios.lds
        @echo "  Linking $@"
-       $(Q)ld -T $(OUT)rombios32.lds $(OUT)rom16.o $(OUT)romlayout32.o -o $@
+       $(Q)ld -T $(OUT)rombios.lds $(OUT)rom16.o $(OUT)rom32.o -o $@
 
-$(OUT)bios.bin.elf: $(OUT)rom32.o
+$(OUT)bios.bin.elf: $(OUT)rom.o
        @echo "  Prepping $@"
        $(Q)nm $< | ./tools/checkrom.py
        $(Q)strip $< -o $@
diff --git a/src/rombios.lds.S b/src/rombios.lds.S
new file mode 100644 (file)
index 0000000..16347f6
--- /dev/null
@@ -0,0 +1,29 @@
+// Linker definitions for merging 16 and 32 bit code
+//
+// Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
+//
+// This file may be distributed under the terms of the GNU GPLv3 license.
+
+#include "config.h"
+
+OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
+OUTPUT_ARCH("i386")
+ENTRY(post32);
+SECTIONS
+{
+        .text code32_start : {
+                *(.text)
+
+                . = code16_start ;
+                final_code16_start = . ;
+                *(.text16)
+
+                . = code16_fixed_start ;
+                final_code16_fixed_start = . ;
+                *(.text16.fixed.addr)
+                }
+
+        .bss __bss_start : {
+                *(.bss)
+                }
+}
index 4609c1ca4ea9a8675e93d92e6ab5fc74163980e2..43fcdef932bd8f78cd29a75704f0076f678146dc 100644 (file)
@@ -10,13 +10,21 @@ OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
 OUTPUT_ARCH("i386")
 SECTIONS
 {
-        .text16 ( _code32_code16_start - BUILD_BIOS_ADDR ) : {
+        . = ( _code32_code32_end - BUILD_BIOS_ADDR ) ;
+        code16_start = . ;
+        .text16 : {
                 *(.text)
                 *(.rodata*)
                 *(.data)
                 }
+        freespace1_start = . ;
+        code16_end = . ;
 
-        .text16.fixed.addr BUILD_START_FIXED : {
+        . = BUILD_START_FIXED ;
+        code16_fixed_start = . ;
+        freespace1_end = . ;
+        .text16.fixed.addr : {
                 *(.text.fixed.addr)
                 }
+        code16_fixed_end = . ;
 }
index 095703fa25744517886138e71fa58e694338342d..6b66f03e0222b7b7f1b731b6bcfe278900c2fdc4 100644 (file)
@@ -1,4 +1,4 @@
-// Linker definitions for 16 and 32 bit code
+// Linker definitions for 32 bit code
 //
 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
 //
@@ -8,37 +8,25 @@
 
 OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
 OUTPUT_ARCH("i386")
-ENTRY(post32);
 SECTIONS
 {
-        .text BUILD_BIOS_ADDR : {
-                code32_start = . ;
+        . = BUILD_BIOS_ADDR ;
+        code32_start = . ;
+        .text : {
                 *(.text)
-
-                . = ALIGN(16) ;
                 code32_rodata = . ;
                 *(.rodata*)
-
-                . = ALIGN(16) ;
                 code32_data = . ;
                 *(.data)
-                code32_end = . ;
-
                 . = ALIGN(16) ;
-                code16_start = . ;
-                *(.text16)
-                code16_end = . ;
-                freespace1_start = . ;
-
-                . = BUILD_START_FIXED ;
-                freespace1_end = . ;
-                *(.text16.fixed.addr)
                 }
+        code32_end = . ;
 
-        .bss BUILD_BSS_ADDR : {
-                 __bss_start = . ;
+        . = BUILD_BSS_ADDR ;
+        __bss_start = . ;
+        .bss : {
                  *(.bss)
                  *(COMMON)
-                 __bss_end = . ;
                  }
+        __bss_end = . ;
 }
index 032783b6098e0c4ea64bfb1db1f7481aa8da2fd5..139ba9da7f143d6036208458c328042589afa06d 100755 (executable)
@@ -17,20 +17,25 @@ def main():
         except:
             pass
 
-    c16s = syms['code16_start']
-    c32s = syms['_code32_code16_start']
-    if c16s != c32s:
-        print "Error!  16bit code moved during linking (0x%x vs 0x%x)" % (
-            c32s, c16s)
+    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))
         sys.exit(1)
 
     size16 = syms['code16_end'] - syms['code16_start']
     size32 = syms['code32_end'] - syms['code32_start']
     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" % (size16+size32)
     print "Free C-code space: %d" % sizefree
+    print "BIOS table space:  %d" % tablefree
 
 if __name__ == '__main__':
     main()