]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
ieee1275: Include a.out header in assembly of sparc64 boot loader
authorJohn Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Tue, 26 Mar 2019 09:47:16 +0000 (10:47 +0100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 28 Mar 2019 10:35:12 +0000 (11:35 +0100)
Recent versions of binutils dropped support for the a.out and COFF
formats on sparc64 targets. Since the boot loader on sparc64 is
supposed to be an a.out binary and the a.out header entries are
rather simple to calculate in our case, we just write the header
ourselves instead of relying on external tools to do that.

Signed-off-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/Makefile.core.def
grub-core/boot/sparc64/ieee1275/boot.S
include/grub/sparc64/ieee1275/boot.h

index 43ed421913a5b25acd4b6f3885995f3afb92771b..474a63e68c51b7e88b41b7a40b3de93de4ac29ed 100644 (file)
@@ -425,8 +425,14 @@ image = {
   i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),$(GRUB_BOOT_MACHINE_LINK_ADDR)';
   i386_qemu_ccasflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)';
 
-  sparc64_ieee1275_objcopyflags = '-O a.out-sunos-big';
-  sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x4000';
+  /* The entry point for a.out binaries on sparc64 starts
+     at 0x4000. Since we are writing the 32 bytes long a.out
+     header in the assembly code ourselves, we need to tell
+     the linker to adjust the start of the text segment to
+     0x4000 - 0x20 = 0x3fe0.
+   */
+  sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x3fe0';
+  sparc64_ieee1275_objcopyflags = '-O binary';
 
   objcopyflags = '-O binary';
   enable = i386_pc;
@@ -455,8 +461,10 @@ image = {
   i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00';
 
   sparc64_ieee1275 = boot/sparc64/ieee1275/boot.S;
-  sparc64_ieee1275_objcopyflags = '-O a.out-sunos-big';
-  sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x4000';
+
+  /* See comment for sparc64_ieee1275_ldflags above. */
+  sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x3fe0';
+  sparc64_ieee1275_objcopyflags = '-O binary';
   sparc64_ieee1275_cppflags = '-DCDBOOT=1';
 
   objcopyflags = '-O binary';
index 9ea9b4e06627bbd8b7da422ffba3357b4fba0a6a..374928ed2d4ffd019c3d69784ef81c1d2c807af4 100644 (file)
 
        .text
        .align  4
+       /*
+        * We're writing the a.out header ourselves as newer
+        * upstream versions of binutils no longer support
+        * the a.out format on sparc64.
+        *
+        * The boot loader fits into 512 bytes with 32 bytes
+        * used for the a.out header, hence the text segment
+        * size is 512 - 32. There is no data segment and no
+        * code relocation, thus those fields remain zero.
+        */
+       .word   0x1030107                        /* Magic number. */
+       .word   512 - GRUB_BOOT_AOUT_HEADER_SIZE /* Size of text segment. */
+       .word   0                                /* Size of initialized data. */
+       .word   0                                /* Size of uninitialized data. */
+       .word   0                                /* Size of symbol table || checksum. */
+       .word   _start                           /* Entry point. */
+       .word   0                                /* Size of text relocation. */
+       .word   0                                /* Size of data relocation. */
        .globl  _start
 _start:
        /* OF CIF entry point arrives in %o4 */
@@ -40,10 +58,14 @@ pic_base:
         *
         * After loading in that block we will execute it by jumping to the
         * load address plus the size of the prepended A.OUT header (32 bytes).
+        *
+        * Since this assembly code includes the 32 bytes long a.out header,
+        * we need to move the actual code entry point forward by the size
+        * of the a.out header, i.e. += GRUB_BOOT_AOUT_HEADER_SIZE.
         */
-       .org GRUB_BOOT_MACHINE_BOOT_DEVPATH
+       .org GRUB_BOOT_MACHINE_BOOT_DEVPATH + GRUB_BOOT_AOUT_HEADER_SIZE
 boot_path:
-       .org GRUB_BOOT_MACHINE_KERNEL_BYTE
+       .org GRUB_BOOT_MACHINE_KERNEL_BYTE + GRUB_BOOT_AOUT_HEADER_SIZE
 boot_path_end:
 kernel_byte:           .xword (2 << 9)
 kernel_address:                .word  GRUB_BOOT_MACHINE_KERNEL_ADDR
@@ -52,7 +74,7 @@ kernel_address:               .word  GRUB_BOOT_MACHINE_KERNEL_ADDR
 #define boot_path_end (_start + 1024)
 #include <grub/offsets.h>
 
-       .org 8
+       .org 8 + GRUB_BOOT_AOUT_HEADER_SIZE
 kernel_byte:           .xword (2 << 9)
 kernel_size:           .word  512
 kernel_address:                .word  GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS
index 02d53f28e1ad4db2993cd2858713879813a1cc26..cc5a941e36e5deab91d39324116dd6b06109a47a 100644 (file)
@@ -46,8 +46,7 @@
 
 #define GRUB_BOOT_MACHINE_KERNEL_BYTE 0x80
 
-#define GRUB_BOOT_MACHINE_CODE_END \
-       (0x1fc - GRUB_BOOT_AOUT_HEADER_SIZE)
+#define GRUB_BOOT_MACHINE_CODE_END 0x1fc
 
 #define GRUB_BOOT_MACHINE_KERNEL_ADDR 0x4200