grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ppc patch] Old World Mac booting


From: Hollis Blanchard
Subject: [ppc patch] Old World Mac booting
Date: Sun, 3 Oct 2004 13:59:38 -0500 (CDT)

This patch allows us to enter GRUB from a stage1 on Old World Macintosh. 
Unfortunately that is needed, because Old World firmware cannot read a 
filesystem on a disk partition. It can, however, blindy load and run a 
contiguous range of sectors (identified in the Apple partition map).

The quik bootloader uses 1KB of data at the very front of a partition,
since filesystems leave that space alone. This is our stage1. There are
still various firmware quirks we need to work around in GRUB, though, such
as claiming firmware's memory for it.

This patch allows GRUB to boot via quik's stage1. Marco doesn't believe we 
should depend on quik for a stage1 long-term, but for now it's working 
great.

There are still other patches needed to GRUB functional on Old World,
notably claiming memory for memory management, and using grub_of_flags in
ofdisk.c (after the SCSI patch is committed). But this gets us closer.
Please apply.

-Hollis

Index: boot/powerpc/ieee1275/cmain.c
===================================================================
RCS file: /cvsroot/grub/grub2/boot/powerpc/ieee1275/cmain.c,v
retrieving revision 1.2
diff -u -r1.2 cmain.c
--- boot/powerpc/ieee1275/cmain.c       4 Apr 2004 13:45:59 -0000       1.2
+++ boot/powerpc/ieee1275/cmain.c       3 Oct 2004 18:43:39 -0000
@@ -35,6 +35,8 @@
 /* OpenFirmware entry point passed to us from the real bootloader.  */
 intptr_t (*grub_ieee1275_entry_fn) (void *);
 
+grub_uint32_t grub_of_flags;
+
 
 /* Return a help text for this architecture.  */
 const char *
@@ -48,14 +50,36 @@
 /* Setup the argument vector and pass control over to the main
    function.  */
 void
-cmain (uint32_t firmware_entry)
+cmain (uint32_t r3, uint32_t r4 __attribute__((unused)), uint32_t r5)
 {
   char **argv, args[256];
   grub_ieee1275_phandle_t chosen;
   int argc = 0, actual;
   long batl, batu;
 
-  grub_ieee1275_entry_fn = (intptr_t (*)(void *)) firmware_entry;
+  if (r5 == 0xdeadbeef)
+    {
+      /* Entered from Old World stage1.  */
+      extern char _start;
+      extern char _end;
+
+      grub_ieee1275_entry_fn = (intptr_t (*)(void *)) r3;
+
+      grub_of_flags = GRUB_IEEE1275_NO_PARTITION_0;
+
+      /* Old World Open Firmware may use 4M-5M without claiming it.  */
+      grub_ieee1275_claim (0x00400000, 0x00100000, 0, 0);
+
+      /* need to claim ourselves so we don't cannibalize our memory later.  */
+      if (grub_claim ((grub_addr_t) &_start, (grub_addr_t) &_end
+          - (grub_addr_t) &_start))
+       abort();
+    }
+  else
+    {
+      /* Assume we were entered from Open Firmware.  */
+      grub_ieee1275_entry_fn = (intptr_t (*)(void *)) r5;
+    }
 
   /* Initialize BAT registers to unmapped to not generate overlapping
      mappings below.  */
Index: boot/powerpc/ieee1275/crt0.S
===================================================================
RCS file: /cvsroot/grub/grub2/boot/powerpc/ieee1275/crt0.S,v
retrieving revision 1.2
diff -u -r1.2 crt0.S
--- boot/powerpc/ieee1275/crt0.S        4 Apr 2004 13:45:59 -0000       1.2
+++ boot/powerpc/ieee1275/crt0.S        3 Oct 2004 18:43:39 -0000
@@ -32,7 +32,10 @@
        .long   0xffffffff      /* virt-base */
        .long   0xffffffff      /* virt-size */
        .long   0x00030000      /* load-base */
-       
+
+.extern __bss_start
+.extern _end
+
        .text
        .align  2
        .globl  _start
@@ -43,9 +46,17 @@
 
        li      2, 0
        li      13, 0
-       
 
-       mr      3, 5    
+       /* If we came from stage1, we *must* zero BSS. Otherwise, why not?  */
+       lis     6, address@hidden
+       ori     6, 6, address@hidden - 4
+       lis     7, address@hidden
+       ori     7, 7, address@hidden
+       subf    7, 6, 7
+       mtctr   7
+2:     stwu    2, 4(6) /* we know r2 is already 0 from above */
+       bdnz    2b
+
        bl      cmain
 1:     b       1b
 
Index: include/grub/powerpc/ieee1275/ieee1275.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/ieee1275/ieee1275.h,v
retrieving revision 1.5
diff -u -r1.5 ieee1275.h
--- include/grub/powerpc/ieee1275/ieee1275.h    3 Oct 2004 09:19:10 -0000       
1.5
+++ include/grub/powerpc/ieee1275/ieee1275.h    3 Oct 2004 18:43:40 -0000
@@ -44,6 +44,11 @@
 typedef intptr_t grub_ieee1275_phandle_t;
 
 extern intptr_t (*grub_ieee1275_entry_fn) (void *);
+extern grub_uint32_t grub_of_flags;
+
+/* Old World firmware fails seek when "dev:0" is opened.  */
+#define GRUB_IEEE1275_NO_PARTITION_0 0x1
+
 
 
 uint32_t EXPORT_FUNC(grub_ieee1275_decode_int_4) (unsigned char *p);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]