Eliminate "_code32_" prefix on 32bit symbols referenced from 16bit code.
authorKevin O'Connor <kevin@koconnor.net>
Sat, 23 May 2009 22:21:18 +0000 (18:21 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sat, 23 May 2009 22:21:18 +0000 (18:21 -0400)
Use linking magic to eliminate the need for the _code32_ prefix.

Makefile
src/layout16.lds.S [new file with mode: 0644]
src/resume.c
src/rombios16.lds.S
src/romlayout.S

index 56d0a5b6fa4262010c9927b1da0d60aaf829efc0..3a4a1e9345bc937f2fbe91696d7a408f24da0d33 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
-# Legacy Bios build system
+# SeaBIOS build system
 #
-# Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
+# Copyright (C) 2008,2009  Kevin O'Connor <kevin@koconnor.net>
 #
 # This file may be distributed under the terms of the GNU LGPLv3 license.
 
@@ -111,16 +111,18 @@ $(OUT)romlayout.lds: $(OUT)romlayout16.o
        @echo "  Building layout information $@"
        $(Q)$(OBJDUMP) -h $< | ./tools/layoutrom.py $@
 
-$(OUT)rombios16.lds: $(OUT)romlayout.lds
+$(OUT)layout16.lds: $(OUT)romlayout.lds
 
-$(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)rombios16.lds
-       @echo "  Linking (16bit) $@"
-       $(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)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)layout16.lds
+       @echo "  Linking (no relocs) $@"
+       $(Q)$(LD) -r -T $(OUT)layout16.lds $< -o $@
 
-$(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios.lds
+$(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios16.lds $(OUT)rombios.lds
        @echo "  Linking $@"
-       $(Q)$(LD) -T $(OUT)rombios.lds $(OUT)rom16.o $(OUT)rom32.o -o $@
+       $(Q)$(LD) -T $(OUT)rombios16.lds $(OUT)rom16.o -R $(OUT)rom32.o -o $(OUT)rom16.final.o
+       $(Q)$(STRIP) $(OUT)rom16.final.o
+       $(Q)$(OBJCOPY) --extract-symbol --adjust-vma 0xf0000 $(OUT)rom16.o $(OUT)rom16.moved.o
+       $(Q)$(LD) -T $(OUT)rombios.lds $(OUT)rom16.final.o $(OUT)rom32.o -R $(OUT)rom16.moved.o -o $@
 
 $(OUT)bios.bin.elf: $(OUT)rom.o
        @echo "  Prepping $@"
diff --git a/src/layout16.lds.S b/src/layout16.lds.S
new file mode 100644 (file)
index 0000000..7b27dd4
--- /dev/null
@@ -0,0 +1,21 @@
+// Placement of the 16bit code.
+//
+// Copyright (C) 2008,2009  Kevin O'Connor <kevin@koconnor.net>
+//
+// This file may be distributed under the terms of the GNU LGPLv3 license.
+
+#include "config.h" // BUILD_BIOS_ADDR
+
+OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
+OUTPUT_ARCH("i386")
+SECTIONS
+{
+
+// The actual placement of the 16bit sections is determined by the
+// script tools/layoutrom.py
+#include "../out/romlayout.lds"
+
+        // 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 38723d8ad0bebaf278e8f636dc5242b349bc0a62..ad868f622d70da42d80d3730ef23bdfece9a951d 100644 (file)
@@ -1,6 +1,6 @@
 // Code for handling calls to "post" that are resume related.
 //
-// Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
+// Copyright (C) 2008,2009  Kevin O'Connor <kevin@koconnor.net>
 //
 // This file may be distributed under the terms of the GNU LGPLv3 license.
 
@@ -40,7 +40,7 @@ handle_resume(u8 status)
             asm volatile(
                 "movw %w1, %%ss\n"
                 "movl %0, %%esp\n"
-                "pushl $_code32_s3_resume\n"
+                "pushl $s3_resume\n"
                 "jmp transition32\n"
                 : : "i"(BUILD_S3RESUME_STACK_ADDR), "r"(0)
                 );
index 4793f56eceebd3888dea84284735df79025dabe6..6e6a2f1f4b125e49aacdae738370eb3d2c83fb28 100644 (file)
@@ -1,6 +1,6 @@
 // Linker definitions for 16bit code
 //
-// Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
+// Copyright (C) 2008,2009  Kevin O'Connor <kevin@koconnor.net>
 //
 // This file may be distributed under the terms of the GNU LGPLv3 license.
 
@@ -10,12 +10,7 @@ OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
 OUTPUT_ARCH("i386")
 SECTIONS
 {
-
-// The actual placement of the 16bit sections is determined by the
-// script tools/layoutrom.py
-#include "../out/romlayout.lds"
-
-        // 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) }
+        .text16 code16_start : {
+                *(.text16)
+                }
 }
index 9fe5c71b11f15b9990e9e61c9f656eeadf7f0eed..a128018f0122871262351e393ab25c5e6b79645a 100644 (file)
@@ -234,7 +234,7 @@ entry_post:
         jnz 1f
 
         // Normal entry point
-        ENTRY_INTO32 _code32__start
+        ENTRY_INTO32 _start
 
         // Entry point when a post call looks like a resume.
 1:
@@ -345,7 +345,7 @@ post32:
         movw %ax, %gs
         movw %ax, %ss
         movl $BUILD_STACK_ADDR, %esp
-        ljmpl $SEG32_MODE32_CS, $_code32__start
+        ljmpl $SEG32_MODE32_CS, $_start
 
         .code16gcc
 
@@ -403,11 +403,11 @@ irqentryarg:
         // int 18/19 are special - they reset stack and call into 32bit mode.
         DECLFUNC entry_19
 entry_19:
-        ENTRY_INTO32 _code32_handle_19
+        ENTRY_INTO32 handle_19
 
         DECLFUNC entry_18
 entry_18:
-        ENTRY_INTO32 _code32_handle_18
+        ENTRY_INTO32 handle_18
 
 
 /****************************************************************