]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
aout image support
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 13 Feb 2010 15:26:50 +0000 (16:26 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 13 Feb 2010 15:26:50 +0000 (16:26 +0100)
boot/sparc64/ieee1275/diskboot.S
conf/sparc64-ieee1275.rmk
include/grub/aout.h
include/grub/kernel.h
include/grub/sparc64/ieee1275/kernel.h
kern/main.c
kern/mips/yeeloong/init.c
kern/sparc64/ieee1275/crt0.S
kern/sparc64/ieee1275/init.c
util/grub-mkrawimage.c

index 68ed0eee04d5714e5969619d6db72172cc6d9156..5016bf9e09908a54890c08089d1449102c77f140 100644 (file)
@@ -129,7 +129,7 @@ bootit:
         mov    NOTIFICATION_DONE_LEN, %o3
        sethi   %hi(GRUB_BOOT_MACHINE_IMAGE_ADDRESS), %o2
        jmpl    %o2 + %lo(GRUB_BOOT_MACHINE_IMAGE_ADDRESS), %o7
-        mov    CIF_REG, %o0
+        mov    CIF_REG, %o4
 1:     ba,a    1b
 
 lastlist:
index 6a91b40ee3e17c0fad41ec3b116dc96a3dc22aa8..4b51a5c3ee095891cb860d8c8e8cc7f0b75e1f9c 100644 (file)
@@ -48,7 +48,7 @@ kernel_img_SOURCES = kern/sparc64/ieee1275/crt0.S kern/ieee1275/cmain.c       \
        symlist.c kern/$(target_cpu)/cache.S
 kernel_img_CFLAGS = $(COMMON_CFLAGS)
 kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
-kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,0x200000,-Bstatic,-melf64_sparc -static-libgcc -lgcc
+kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,0x4400,-Bstatic,-melf64_sparc -static-libgcc -lgcc
 kernel_img_FORMAT = binary
 
 symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh
index 04e85f8b077342a4a17f6d153890af056a77d8ee..f962a97b365d2aad8e67190b5cb14f2c0139f165 100644 (file)
@@ -102,6 +102,7 @@ union grub_aout_header
 #define AOUT_MID_I386          134     /* i386 BSD binary */
 #define AOUT_MID_SPARC         138     /* sparc */
 #define        AOUT_MID_HP200          200     /* hp200 (68010) BSD binary */
+#define        AOUT_MID_SUN            0x103
 #define        AOUT_MID_HP300          300     /* hp300 (68020+68881) BSD binary */
 #define        AOUT_MID_HPUX           0x20C   /* hp200/300 HP-UX binary */
 #define        AOUT_MID_HPUX800        0x20B   /* hp800 HP-UX binary */
@@ -114,10 +115,14 @@ union grub_aout_header
 #define AOUT_GETMID(header) ((header).a_midmag >> 16) & 0x03ff)
 #define AOUT_GETFLAG(header) ((header).a_midmag >> 26) & 0x3f)
 
+#ifndef GRUB_UTIL
+
 int EXPORT_FUNC(grub_aout_get_type) (union grub_aout_header *header);
 
 grub_err_t EXPORT_FUNC(grub_aout_load) (grub_file_t file, int offset,
                                         grub_addr_t load_addr, int load_size,
                                         grub_addr_t bss_end_addr);
 
+#endif
+
 #endif /* ! GRUB_AOUT_HEADER */
index 9586a90b977285ae00ffa10b6c9c66da52f8ae6d..bf52ffcb4716a5ab3cdbbbcab7b8dd39b7c8b6aa 100644 (file)
@@ -59,6 +59,8 @@ extern grub_addr_t grub_arch_modules_addr (void);
 
 extern void EXPORT_FUNC(grub_module_iterate) (int (*hook) (struct grub_module_header *));
 
+grub_addr_t grub_modules_get_end (void);
+
 /* The start point of the C code.  */
 void grub_main (void);
 
index 8eb1671a8d47f1dc13db8c0d556c6beabcf6d7dd..78e039bc53d86dfd28085e8b9bc1df780546869e 100644 (file)
 
 #define GRUB_KERNEL_MACHINE_RAW_SIZE                   0
 
+#define GRUB_PLATFORM_IMAGE_FORMATS     "raw, aout"
+#define GRUB_PLATFORM_IMAGE_DEFAULT_FORMAT     "raw"
+
+#define GRUB_PLATFORM_IMAGE_DEFAULT GRUB_PLATFORM_IMAGE_RAW
+
 #ifndef ASM_FILE
 
+typedef enum {
+  GRUB_PLATFORM_IMAGE_RAW,
+  GRUB_PLATFORM_IMAGE_AOUT
+}
+  grub_platform_image_format_t;
+#define GRUB_PLATFORM_IMAGE_RAW GRUB_PLATFORM_IMAGE_RAW
+#define GRUB_PLATFORM_IMAGE_AOUT GRUB_PLATFORM_IMAGE_AOUT
+
 #include <grub/symbol.h>
 #include <grub/types.h>
 
index 45610537897f7cbd70116c8b88a4b73f2bd0f15d..54235821d92231858c77446dcd996d15842d0926 100644 (file)
@@ -53,6 +53,25 @@ grub_module_iterate (int (*hook) (struct grub_module_header *header))
     }
 }
 
+/* This is actualy platform-independant but used only on yeeloong and sparc.  */
+#if defined (GRUB_MACHINE_MIPS_YEELOONG) || defined (GRUB_MACHINE_SPARC64)
+grub_addr_t
+grub_modules_get_end (void)
+{
+  struct grub_module_info *modinfo;
+  grub_addr_t modbase;
+
+  modbase = grub_arch_modules_addr ();
+  modinfo = (struct grub_module_info *) modbase;
+
+  /* Check if there are any modules.  */
+  if ((modinfo == 0) || modinfo->magic != GRUB_MODULE_MAGIC)
+    return modbase;
+
+  return modbase + modinfo->size;
+}
+#endif
+
 /* Load all modules in core.  */
 static void
 grub_load_modules (void)
index 14e8a39a241721f03b62a5b7a750ee273e07f2e6..d148d08dc0427e70e64aec7b1ef50f01ba26d3a7 100644 (file)
@@ -63,35 +63,13 @@ grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t,
   return GRUB_ERR_NONE;
 }
 
-
-static void *
-get_modules_end (void)
-{
-  struct grub_module_info *modinfo;
-  struct grub_module_header *header;
-  grub_addr_t modbase;
-
-  modbase = grub_arch_modules_addr ();
-  modinfo = (struct grub_module_info *) modbase;
-
-  /* Check if there are any modules.  */
-  if ((modinfo == 0) || modinfo->magic != GRUB_MODULE_MAGIC)
-    return modinfo;
-
-  for (header = (struct grub_module_header *) (modbase + modinfo->offset);
-       header < (struct grub_module_header *) (modbase + modinfo->size);
-       header = (struct grub_module_header *) ((char *) header + header->size));
-
-  return header;
-}
-
 void
 grub_machine_init (void)
 {
-  void *modend;
-  modend = get_modules_end ();
+  grub_addr_t modend;
+  modend = grub_modules_get_end ();
   grub_mm_init_region (modend, (grub_arch_memsize << 20)
-                      - (((grub_addr_t) modend) - GRUB_ARCH_LOWMEMVSTART));
+                      - (modend - GRUB_ARCH_LOWMEMVSTART));
   /* FIXME: use upper memory as well.  */
   grub_install_get_time_ms (grub_rtc_get_time_ms);
 
index 4e67cbc1973bc429d3f27e437428260eb5c2644a..1dc65dc649b14bf44c065b712b4ec87c30b04eda 100644 (file)
@@ -24,7 +24,7 @@
        .globl  _start
 _start:
        ba      codestart
-        nop
+        mov  %o4, %o0
 
        . = EXT_C(_start) + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE
 
index 115328f406d00dc2b4a12b4fadab9742ab683c3c..5827be65878e85bad50b0303c1741030ceb75171 100644 (file)
@@ -104,7 +104,7 @@ grub_machine_set_prefix (void)
 static void
 grub_heap_init (void)
 {
-  grub_mm_init_region ((void *)(long)0x4000UL, 0x200000 - 0x4000);
+  grub_mm_init_region ((void *) grub_modules_get_end (), 0x200000);
 }
 
 static void
index e17446f7811a4a5387ba95fcc0032d0135ffad33..26ccd7d94ea3ba87eaeea96b6c597d1b76372a79 100644 (file)
@@ -23,6 +23,7 @@
 #include <grub/machine/kernel.h>
 #include <grub/machine/memory.h>
 #include <grub/elf.h>
+#include <grub/aout.h>
 #include <grub/i18n.h>
 #include <grub/kernel.h>
 #include <grub/disk.h>
@@ -230,6 +231,36 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
 
   grub_util_info ("the core size is 0x%x", core_size);
 
+#ifdef GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE
+  *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE))
+    = grub_host_to_target32 (total_module_size);
+#endif
+  *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE))
+    = grub_host_to_target32 (kernel_size);
+#ifdef GRUB_KERNEL_MACHINE_COMPRESSED_SIZE
+  *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE))
+    = grub_host_to_target32 (core_size - GRUB_KERNEL_MACHINE_RAW_SIZE);
+#endif
+
+#if defined(GRUB_KERNEL_MACHINE_INSTALL_DOS_PART) && defined(GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)
+  /* If we included a drive in our prefix, let GRUB know it doesn't have to
+     prepend the drive told by BIOS.  */
+  if (prefix[0] == '(')
+    {
+      *((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART))
+       = grub_host_to_target32 (-2);
+      *((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART))
+       = grub_host_to_target32 (-2);
+    }
+#endif
+
+#ifdef GRUB_MACHINE_PCBIOS
+  if (GRUB_KERNEL_MACHINE_LINK_ADDR + core_size > GRUB_MEMORY_MACHINE_UPPER)
+    grub_util_error (_("core image is too big (%p > %p)"),
+                    GRUB_KERNEL_MACHINE_LINK_ADDR + core_size,
+                    GRUB_MEMORY_MACHINE_UPPER);
+#endif
+
 #if defined(GRUB_MACHINE_PCBIOS)
   {
     unsigned num;
@@ -299,62 +330,50 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
     free (boot_path);
   }
 #elif defined (GRUB_MACHINE_SPARC64)
-  {
-    unsigned int num;
-    char *boot_path, *boot_img;
-    size_t boot_size;
-
-    num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
-    num <<= GRUB_DISK_SECTOR_BITS;
+  if (format == GRUB_PLATFORM_IMAGE_AOUT)
+    {
+      void *aout_img;
+      size_t aout_size;
+      struct grub_aout32_header *aout_head;
+
+      aout_size = core_size + sizeof (*aout_head);
+      aout_img = xmalloc (aout_size);
+      aout_head = aout_img;
+      aout_head->a_midmag = grub_host_to_target32 ((AOUT_MID_SUN << 16)
+                                                  | AOUT32_OMAGIC);
+      aout_head->a_text = grub_host_to_target32 (core_size);
+      aout_head->a_entry = grub_host_to_target32 (0x4400);
+      memcpy (aout_img + sizeof (*aout_head), core_img, core_size);
 
-    boot_path = grub_util_get_path (dir, "diskboot.img");
-    boot_size = grub_util_get_image_size (boot_path);
-    if (boot_size != GRUB_DISK_SECTOR_SIZE)
-      grub_util_error ("diskboot.img is not one sector size");
+      free (core_img);
+      core_img = aout_img;
+      core_size = aout_size;
+    }
+  else
+    {
+      unsigned int num;
+      char *boot_path, *boot_img;
+      size_t boot_size;
 
-    boot_img = grub_util_read_image (boot_path);
+      num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
+      num <<= GRUB_DISK_SECTOR_BITS;
 
-    *((grub_uint32_t *) (boot_img + GRUB_DISK_SECTOR_SIZE
-                        - GRUB_BOOT_MACHINE_LIST_SIZE + 8))
-      = grub_host_to_target32 (num);
+      boot_path = grub_util_get_path (dir, "diskboot.img");
+      boot_size = grub_util_get_image_size (boot_path);
+      if (boot_size != GRUB_DISK_SECTOR_SIZE)
+       grub_util_error ("diskboot.img is not one sector size");
 
-    grub_util_write_image (boot_img, boot_size, out);
-    free (boot_img);
-    free (boot_path);
-  }
-#endif
+      boot_img = grub_util_read_image (boot_path);
 
-#ifdef GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE
-  *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE))
-    = grub_host_to_target32 (total_module_size);
-#endif
-  *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE))
-    = grub_host_to_target32 (kernel_size);
-#ifdef GRUB_KERNEL_MACHINE_COMPRESSED_SIZE
-  *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE))
-    = grub_host_to_target32 (core_size - GRUB_KERNEL_MACHINE_RAW_SIZE);
-#endif
+      *((grub_uint32_t *) (boot_img + GRUB_DISK_SECTOR_SIZE
+                          - GRUB_BOOT_MACHINE_LIST_SIZE + 8))
+       = grub_host_to_target32 (num);
 
-#if defined(GRUB_KERNEL_MACHINE_INSTALL_DOS_PART) && defined(GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)
-  /* If we included a drive in our prefix, let GRUB know it doesn't have to
-     prepend the drive told by BIOS.  */
-  if (prefix[0] == '(')
-    {
-      *((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART))
-       = grub_host_to_target32 (-2);
-      *((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART))
-       = grub_host_to_target32 (-2);
+      grub_util_write_image (boot_img, boot_size, out);
+      free (boot_img);
+      free (boot_path);
     }
-#endif
-
-#ifdef GRUB_MACHINE_PCBIOS
-  if (GRUB_KERNEL_MACHINE_LINK_ADDR + core_size > GRUB_MEMORY_MACHINE_UPPER)
-    grub_util_error (_("core image is too big (%p > %p)"),
-                    GRUB_KERNEL_MACHINE_LINK_ADDR + core_size,
-                    GRUB_MEMORY_MACHINE_UPPER);
-#endif
-
-#if defined(GRUB_MACHINE_MIPS)
+#elif defined(GRUB_MACHINE_MIPS)
   if (format == GRUB_PLATFORM_IMAGE_ELF)
     {
       char *elf_img;
@@ -527,6 +546,11 @@ main (int argc, char *argv[])
            if (strcmp (optarg, "elf") == 0)
              format = GRUB_PLATFORM_IMAGE_ELF;
            else 
+#endif
+#ifdef GRUB_PLATFORM_IMAGE_AOUT
+           if (strcmp (optarg, "aout") == 0)
+             format = GRUB_PLATFORM_IMAGE_AOUT;
+           else 
 #endif
              usage (1);
            break;