rough Mac OS X loader
PATCH 1/1 rough Mac OS X loader
I've been working on a Mac OS X loader for GRUB. During the usual OS X boot process, the firmware loads the BootX bootloader (which is a hybrid CHRP script and XCOFF binary), which has a Mach-O loader and loads the OS X Mach kernel.
Rather than trying to load and run the Mach kernel directly, I chose to focus on the BootX bootloader, since it seems to do a fair amount of setup work that I would rather not duplicate in GRUB. Also important: if OS X is ever updated (for example, the parameter-passing mechanism between BootX and the kernel), we would need to track those changes, which is a lot more long-term maintenance.
Unfortunately, BootX attempts to claim all memory from 0 to 96MiB, which conflicts with GRUB running in this area. To get around that problem, I install a trampoline just above 96MiB which releases all of GRUB's memory and jumps into BootX. It's a bit of a hack, and for example if the code being copied exceeds some fixed size (currently 0x200 bytes) things will fail mysteriously. I'm open to suggestions on that problem.
I'm afraid I don't know if this code works yet. Because the current HFS+ driver doesn't support the HFS wrapper found on all Apple filesystems, I can't boot from an HFS+ installation. I've copied BootX to a plain HFS partition, and that works somewhat (I expect it fails when it cannot find /mach_kernel). I'm relatively optimistic, and I'm working on the HFS wrapper support now.
There are a few rough edges still, but if there are no comments I will be checking this patch in largely unchanged some day.
-Hollis
Index: conf/powerpc-ieee1275.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/powerpc-ieee1275.rmk,v retrieving revision 1.52
powerpc-ieee1275.rmk +12 -2
@@ -9,7 +9,7 @@ COMMON_CFLAGS = -ffreestanding -msoft-fl MOSTLYCLEANFILES += grubof_symlist.c kernel_syms.lst DEFSYMFILES += kernel_syms.lst -grubof_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \ +grubof_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h env.h err.h \ file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h symbol.h \ term.h types.h powerpc/libgcc.h loader.h \ partition.h pc_partition.h ieee1275/ieee1275.h machine/time.h \
@@ -65,7 +65,7 @@ grubof_SOURCES = kern/powerpc/ieee1275/c kern/powerpc/ieee1275/init.c term/ieee1275/ofconsole.c \ kern/powerpc/ieee1275/openfw.c disk/ieee1275/ofdisk.c \ kern/parser.c kern/partition.c kern/env.c kern/powerpc/dl.c \ - grubof_symlist.c kern/powerpc/cache.S + grubof_symlist.c kern/powerpc/cache.S kern/powerpc/misc.S grubof_HEADERS = grub/powerpc/ieee1275/ieee1275.h grubof_CFLAGS = $(COMMON_CFLAGS) grubof_ASFLAGS = $(COMMON_ASFLAGS)
@@ -84,6 +84,8 @@ grub_install_SOURCES = util/powerpc/ieee pkgdata_MODULES = halt.mod \ _linux.mod \ linux.mod \ + _macosx.mod \ + macosx.mod \ normal.mod \ reboot.mod \ suspend.mod
@@ -117,4 +119,12 @@ reboot_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_SOURCES = commands/ieee1275/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) +# For _macosx.mod. +_macosx_mod_SOURCES = loader/powerpc/ieee1275/macosx.c +_macosx_mod_CFLAGS = $(COMMON_CFLAGS) + +# For macosx.mod. +macosx_mod_SOURCES = loader/powerpc/ieee1275/macosx_normal.c +macosx_mod_CFLAGS = $(COMMON_CFLAGS) + include $(srcdir)/conf/common.mk
Index: include/grub/xcoff.h
===================================================================
RCS file: include/grub/xcoff.h
grub/xcoff.h new file +90 -0
90 lines not on this page · raw message
Index: include/grub/powerpc/ieee1275/kernel.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/ieee1275/kernel.h,v retrieving revision 1.3
grub/powerpc/ieee1275/kernel.h +3 -0
@@ -26,6 +26,9 @@ void EXPORT_FUNC (abort) (void);void EXPORT_FUNC (grub_reboot ) (void );void EXPORT_FUNC (grub_halt ) (void ); +void EXPORT_FUNC (grub_jump ) (unsigned long text,unsigned long stack, +unsigned long arg1,unsigned long arg2); +/* Where grub-mkimage places the core modules in memory. */ #define GRUB_IEEE1275_MODULE_BASE 0x00300000
Index: include/grub/powerpc/ieee1275/loader.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/ieee1275/loader.h,v retrieving revision 1.4
grub/powerpc/ieee1275/loader.h +1 -0
@@ -24,6 +24,7 @@loader. */ void grub_rescue_cmd_linux (int argc,char *argv[]);void grub_rescue_cmd_initrd (int argc,char *argv[]); +void grub_rescue_cmd_macosx (int argc,char *argv[]);void grub_linux_init (void );void grub_linux_fini (void );
Index: kern/powerpc/misc.S
===================================================================
RCS file: kern/powerpc/misc.S
powerpc/misc.S new file +30 -0
@@ -0,0 +1,30 @@ +/* misc.S - Miscellaneous assembly routines. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2005 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + .text + + /* Jump to a function and switch to a new stack. */ + .globl grub_jump +grub_jump: + mtctr 3 + mr 1, 4 + mr 3, 5 + mr 4, 6 + bctr
Index: loader/powerpc/ieee1275/macosx.c
===================================================================
RCS file: loader/powerpc/ieee1275/macosx.c
powerpc/ieee1275/macosx.c new file +324 -0
324 lines not on this page · raw message
Index: loader/powerpc/ieee1275/macosx_normal.c
===================================================================
RCS file: loader/powerpc/ieee1275/macosx_normal.c
powerpc/ieee1275/macosx_normal.c new file +49 -0
49 lines not on this page · raw message
Hollis Blanchard <[email protected]> writes:
Hi Hollis,
Quoted 4 lines
I've been working on a Mac OS X loader for GRUB. During the usual OS X boot process, the firmware loads the BootX bootloader (which is a hybrid CHRP script and XCOFF binary), which has a Mach-O loader and loads the OS X Mach kernel.
This is really great news! Thanks a lot for doing this great job. :-)
Quoted 6 lines
Rather than trying to load and run the Mach kernel directly, I chose to focus on the BootX bootloader, since it seems to do a fair amount of setup work that I would rather not duplicate in GRUB. Also
important: if OS X is ever updated (for example, the parameter-passing mechanism between BootX and the kernel), we would need to track those changes, which is a lot more long-term maintenance.
Agreed.
Quoted 8 lines
Unfortunately, BootX attempts to claim all memory from 0 to 96MiB, which conflicts with GRUB running in this area. To get around that problem, I install a trampoline just above 96MiB which releases all of GRUB's memory and jumps into BootX. It's a bit of a hack, and for example if the code being copied exceeds some fixed size (currently
0x200bytes) things will fail mysteriously. I'm open to suggestions on that problem.
Quoted 6 lines
I'm afraid I don't know if this code works yet. Because the current HFS+ driver doesn't support the HFS wrapper found on all Apple filesystems, I can't boot from an HFS+ installation. I've copied BootX to a plain HFS partition, and that works somewhat (I expect it fails when it cannot find /mach_kernel). I'm relatively optimistic, and I'm working on the HFS wrapper support now.
Cool. If you need any help let me know. I will look into this as well, I assume we can discuss things in detail on IRC.
Quoted 2 lines
There are a few rough edges still, but if there are no comments I will be checking this patch in largely unchanged some day.
Can you provide a changelog entry? :-)
There are some comments below, I hope some of them even make sense. ;)
Quoted 3 lines
include $(srcdir)/conf/common.mk
Index:include/grub/xcoff.h
===================================================================
Is it possible to use the grub_ namespace in this file? In elf.h this is not done because it should be possible to update it from glibc, AFAIK.
grub/powerpc/ieee1275/kernel.h void EXPORT_FUNC (abort) (void); · line 30
Quoted 13 lines
Index:
include/grub/powerpc/ieee1275/kernel.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/ieee1275/kernel.h,v retrieving revision 1.3
diff -u -p -r1.3kernel.hgrub/powerpc/ieee1275/kernel.h +2
-0@@ -26,6 +26,9 @@ void EXPORT_FUNC (abort) (void);void EXPORT_FUNC (grub_reboot ) (void );void EXPORT_FUNC (grub_halt ) (void ); +void EXPORT_FUNC (grub_jump ) (unsigned long text,unsigned long stack, +unsigned long arg1,unsigned long arg2);
Shouldn't a pointer be used here?
grub/powerpc/ieee1275/kernel.h void EXPORT_FUNC (abort) (void); · line 32
Quoted 2 lines
grub/powerpc/ieee1275/kernel.h +2
-0+/* BootX, the Mac OS X bootloader, is an XCOFF executable with a CHRP script +* prepended to it. We skip the script and load the XCOFF file. */
What is in this script? Are you completely sure it can be skipped?
Can you please remove the `*' on the second line so the comment matches the style of the other sourcecode?
grub/powerpc/ieee1275/kernel.h void EXPORT_FUNC (abort) (void);
Quoted 4 lines
grub/powerpc/ieee1275/kernel.h +4
-0+static grub_err_t +grub_macosx_release_mem (void ) +{ +/* XXX write me */
I assume you encountered a bug in the firmware while writing this function? :-)
grub/powerpc/ieee1275/kernel.h
Quoted 9 lines
grub/powerpc/ieee1275/kernel.h +9
-0+/* Load all section headers. */ + scnhdr_bytes = filehdr->f_nscns *sizeof (struct xcoff_scnhdr ); + scnhdrs =grub_malloc (scnhdr_bytes); +if (! scnhdrs) +return grub_errno; + +if (grub_file_read (file, (void *)scnhdrs, scnhdr_bytes) != scnhdr_bytes) +return grub_error (GRUB_ERR_READ_ERROR , +"could not read XCOFF section headers" );
You don't free scnhdrs here, is that intentional?
grub/powerpc/ieee1275/kernel.h
Quoted 3 lines
grub/powerpc/ieee1275/kernel.h +3
-0+/* Find NULL-terminated `needle' in non-terminated `haystack'. */ +static void * +grub_memstr (void *haystack,int len,char *needle)
Perhaps it is better to move this to kern/misc.c?
Quoted 4 lines
+/*
grub_chain_trampolineis copied somewhere other than its link address
+ * and executes after all other code has been blown away. In order to call
+ * other functions from here, they must have been copied into a safe place and
+ * their addresses passed as parameters. */
Same as above.
Quoted 15 lines
grub/powerpc/ieee1275/kernel.h +15
-0+typedef void (*kernel_entry_t ) (unsigned long ,unsigned long ,int (void *)); +typedef int (*release_t ) (grub_addr_t addr,grub_size_t size); +static void +grub_chain_trampoline (kernel_entry_t entry,release_t release) +{ +release (0x00003000 ,0x06000000 -0x3000 ); +entry (0 ,0 , grub_ieee1275_entry_fn); +} + +static int +grub_macosx_install_trampoline (void ) +{ +int rc; + +/* XXX don't use magic numbers here */
grub/powerpc/ieee1275/kernel.h
Quoted 10 lines
grub/powerpc/ieee1275/kernel.h +10
-0+ rc =grub_claimmap (GRUB_MACOSX_CHAIN_AREA ,0x200 ); + rc |=grub_claimmap (GRUB_MACOSX_RELEASE_AREA ,0x200 ); + rc |=grub_claimmap (GRUB_MACOSX_STACK_AREA ,0x200 ); +if (rc) +return rc; + +grub_memcpy ((void *)GRUB_MACOSX_CHAIN_AREA , grub_chain_trampoline,0x200 ); +grub_arch_sync_caches ((void *)GRUB_MACOSX_CHAIN_AREA ,0x200 ); +grub_memcpy ((void *)GRUB_MACOSX_RELEASE_AREA , grub_ieee1275_release,0x200 ); +grub_arch_sync_caches ((void *)GRUB_MACOSX_RELEASE_AREA ,0x200 );
What is 0x200? The maximum size of grub_chain_trampoline? Perhaps you can do something like: `grub_macosx_release_area - grub_chain_trampoline', or do you think that is too unpredictable and too ugly?
Thanks,
Marco
Thanks for your comments.
Quoted 7 lines · Marco Gerards
Quoted 3 lines
Index:
include/grub/xcoff.h
===================================================================Is it possible to use the
grub_namespace in this file? Inelf.hthis is not done because it should be possible to update it from glibc, AFAIK.
Ok, that should be fine.
Quoted 12 lines
Quoted 12 lines
Index:
include/grub/powerpc/ieee1275/kernel.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/ieee1275/kernel.h,v retrieving revision 1.3
diff -u -p -r1.3kernel.h
---include/grub/powerpc/ieee1275/kernel.h3 Aug 2005 22:53:50
-0000 1.3
+++include/grub/powerpc/ieee1275/kernel.h2 Jan 2006 00:34:11 -0000grub/powerpc/ieee1275/kernel.h +0
-0@@ -26,6 +26,9 @@ void EXPORT_FUNC (abort) (void);void EXPORT_FUNC (grub_reboot ) (void );void EXPORT_FUNC (grub_halt ) (void );
Quoted 5 lines
Review void EXPORT_FUNC (abort) (void); · line 31
Quoted 3 lines
(quoted diff) +2
-0+void EXPORT_FUNC (grub_jump) (unsigned long text, unsigned long stack, + unsigned long arg1, unsigned long arg2);Shouldn't a pointer be used here?
Used where?
Quoted 5 lines
Quoted 3 lines
(quoted diff) +1
-0+/* BootX, the Mac OS X bootloader, is an XCOFF executable with aCHRP script
+ * prepended to it. We skip the script and load the XCOFF file. */What is in this script? Are you completely sure it can be skipped?
It loads the XCOFF into memory. Yes.
Quoted 2 lines
Can you please remove the `*' on the second line so the comment matches the style of the other sourcecode?
Yes.
Quoted 7 lines
powerpc/ieee1275/macosx.c line 63
Quoted 4 lines
powerpc/ieee1275/macosx.c new file +4
-0+static grub_err_t +grub_macosx_release_mem (void ) +{ +/* XXX write me */ I assume you encountered a bug in the firmware while writing this function? :-)
No, just haven't written it yet. :) I think the XCOFF sections in BootX are contiguous though, so if that's true it should not be difficult.
Quoted 4 lines
Quoted 4 lines
powerpc/ieee1275/macosx.c new file +4
-0+/* Load all section headers. */ + scnhdr_bytes = filehdr->f_nscns *sizeof (struct xcoff_scnhdr ); + scnhdrs =grub_malloc (scnhdr_bytes); +if (! scnhdrs)
Quoted 8 lines
Review
Quoted 6 lines
powerpc/ieee1275/macosx.c new file +3
-0+return grub_errno; + + if (grub_file_read (file, (void *)scnhdrs, scnhdr_bytes) !=
scnhdr_bytes)(quoted diff) +2
-0+ return grub_error (GRUB_ERR_READ_ERROR, + "could not read XCOFF section headers");You don't free scnhdrs here, is that intentional?
Accidental, thanks.
Quoted 5 lines
powerpc/ieee1275/macosx.c line 197
Quoted 3 lines
powerpc/ieee1275/macosx.c new file +3
-0+/* Find NULL-terminated `needle' in non-terminated `haystack'. */ +static void * +grub_memstr (void *haystack,int len,char *needle)Perhaps it is better to move this to
kern/misc.c?
I had that thought, but "memstr" is not a standard POSIX function so I wasn't sure.
Quoted 35 lines
Quoted 7 lines
+/*
grub_chain_trampolineis copied somewhere other than its link address
+ * and executes after all other code has been blown away. In order to call
+ * other functions from here, they must have been copied into a safe place and
+ * their addresses passed as parameters. */Same as above.
Quoted 25 lines
+typedef void (
*kernel_entry_t) (unsigned long, unsigned long, int (void *));powerpc/ieee1275/macosx.c new file +21
-0+typedef int (*release_t ) (grub_addr_t addr,grub_size_t size); +static void +grub_chain_trampoline (kernel_entry_t entry,release_t release) +{ +release (0x00003000 ,0x06000000 -0x3000 ); +entry (0 ,0 , grub_ieee1275_entry_fn); +} + +static int +grub_macosx_install_trampoline (void ) +{ +int rc; + +/* XXX don't use magic numbers here */ + rc =grub_claimmap (GRUB_MACOSX_CHAIN_AREA ,0x200 ); + rc |=grub_claimmap (GRUB_MACOSX_RELEASE_AREA ,0x200 ); + rc |=grub_claimmap (GRUB_MACOSX_STACK_AREA ,0x200 ); +if (rc) +return rc; + + grub_memcpy ((void *) GRUB_MACOSX_CHAIN_AREA,
grub_chain_trampoline,0x200);
+grub_arch_sync_caches((void *)GRUB_MACOSX_CHAIN_AREA,0x200);
Quoted 8 lines
Quoted 3 lines
+
grub_memcpy((void *)GRUB_MACOSX_RELEASE_AREA,grub_ieee1275_release,0x200);
+grub_arch_sync_caches((void *)GRUB_MACOSX_RELEASE_AREA,0x200);What is
0x200? The maximum size ofgrub_chain_trampoline? Perhaps you can do something like: `grub_macosx_release_area -grub_chain_trampoline', or do you think that is too unpredictable and too ugly?
We're copying several functions elsewhere. The problem is this: how big is that function? In other words, how many bytes do we need to copy? I don't have an answer.
-Hollis
Quoted 7 lines · Hollis Blanchard
Quoted 5 lines
grub/powerpc/ieee1275/kernel.h void EXPORT_FUNC (abort) (void); · line 30
Quoted 3 lines
+void
EXPORT_FUNC(grub_jump) (unsigned long text, unsigned long stack,grub/powerpc/ieee1275/kernel.h +1
-0+ unsigned long arg1, unsigned long arg2);Shouldn't a pointer be used here?
Used where?
For grub_jump's arguments. It jumps to some address, right?
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
+/* BootX, the Mac OS X bootloader, is an XCOFF executable with a CHRP script
+ * prepended to it. We skip the script and load the XCOFF file. */What is in this script? Are you completely sure it can be skipped?
It loads the XCOFF into memory. Yes.
Ah! :)
Quoted 11 lines
Quoted 7 lines
powerpc/ieee1275/macosx.c line 63
Quoted 4 lines
powerpc/ieee1275/macosx.c new file +4
-0+static grub_err_t +grub_macosx_release_mem (void ) +{ +/* XXX write me */ I assume you encountered a bug in the firmware while writing this function? :-)
No, just haven't written it yet. :) I think the XCOFF sections in BootX are contiguous though, so if that's true it should not be difficult.
Oh, ok. In that case please add it to the to do list after this patch is committed.
Quoted 8 lines
Quoted 5 lines
powerpc/ieee1275/macosx.c line 197
Quoted 3 lines
powerpc/ieee1275/macosx.c new file +3
-0+/* Find NULL-terminated `needle' in non-terminated `haystack'. */ +static void * +grub_memstr (void *haystack,int len,char *needle)Perhaps it is better to move this to
kern/misc.c?I had that thought, but "memstr" is not a standard POSIX function so I wasn't sure.
It's looks like a useful function to me. We can always move it back if it turns out no one uses it...
Thanks,
Marco
Quoted 11 lines · Marco Gerards
Quoted 7 lines · Hollis Blanchard
Quoted 5 lines
Review
Quoted 3 lines
+void
EXPORT_FUNC(grub_jump) (unsigned long text, unsigned long stack,(quoted diff) +1
-0+ unsigned long arg1, unsigned long arg2);Shouldn't a pointer be used here?
Used where?
For grub_jump's arguments. It jumps to some address, right?
Yes, but I don't believe using pointers would be appropriate here. The addresses passed in are addresses, so would need to be cast into pointers.
Here is the updated patch. I believe I've resolved all your other comments.
-Hollis
Index: ChangeLog
===================================================================
RCS file: /cvsroot/grub/grub2/ChangeLog,v
retrieving revision 1.217
ChangeLog +19 -0
@@ -1,3 +1,22 @@ +2006-01-02 Hollis Blanchard <[email protected]> + + * conf/powerpc-ieee1275.rmk (grubof_HEADERS): Add cache.h. + (grubof_SOURCES): Add kern/powerpc/misc.S. + (pkgdata_MODULES): Add _macosx.mod and macosx.mod. + (_macosx_mod_SOURCES): New variable. + (_macosx_mod_CFLAGS): Likewise. + (macosx_mod_SOURCES): Likewise. + (macosx_mod_CFLAGS): Likewise. + * include/grub/misc.h (grub_memstr): New prototype. + * include/grub/powerpc/ieee1275/kernel.h (grub_jump): Likewise. + * include/grub/powerpc/ieee1275/loader.h (grub_rescue_cmd_macosx): + Likewise. + * kern/misc.c (grub_memstr): New function. + * include/grub/xcoff.h: New file. + * kern/powerpc/misc.S: Likewise. + * loader/powerpc/ieee1275/macosx.c: Likewise. + * loader/powerpc/ieee1275/macosx_normal.c: Likewise. + 2005-12-25 Yoshinori K. Okuji <[email protected]> * include/grub/i386/pc/boot.h (GRUB_BOOT_MACHINE_DRP_ADDR):
Index: conf/powerpc-ieee1275.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/powerpc-ieee1275.rmk,v retrieving revision 1.52
powerpc-ieee1275.rmk +12 -2
@@ -9,7 +9,7 @@ COMMON_CFLAGS = -ffreestanding -msoft-fl MOSTLYCLEANFILES += grubof_symlist.c kernel_syms.lst DEFSYMFILES += kernel_syms.lst -grubof_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \ +grubof_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h env.h err.h \ file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h symbol.h \ term.h types.h powerpc/libgcc.h loader.h \ partition.h pc_partition.h ieee1275/ieee1275.h machine/time.h \
@@ -65,7 +65,7 @@ grubof_SOURCES = kern/powerpc/ieee1275/c kern/powerpc/ieee1275/init.c term/ieee1275/ofconsole.c \ kern/powerpc/ieee1275/openfw.c disk/ieee1275/ofdisk.c \ kern/parser.c kern/partition.c kern/env.c kern/powerpc/dl.c \ - grubof_symlist.c kern/powerpc/cache.S + grubof_symlist.c kern/powerpc/cache.S kern/powerpc/misc.S grubof_HEADERS = grub/powerpc/ieee1275/ieee1275.h grubof_CFLAGS = $(COMMON_CFLAGS) grubof_ASFLAGS = $(COMMON_ASFLAGS)
@@ -84,6 +84,8 @@ grub_install_SOURCES = util/powerpc/ieee pkgdata_MODULES = halt.mod \ _linux.mod \ linux.mod \ + _macosx.mod \ + macosx.mod \ normal.mod \ reboot.mod \ suspend.mod
@@ -117,4 +119,12 @@ reboot_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_SOURCES = commands/ieee1275/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) +# For _macosx.mod. +_macosx_mod_SOURCES = loader/powerpc/ieee1275/macosx.c +_macosx_mod_CFLAGS = $(COMMON_CFLAGS) + +# For macosx.mod. +macosx_mod_SOURCES = loader/powerpc/ieee1275/macosx_normal.c +macosx_mod_CFLAGS = $(COMMON_CFLAGS) + include $(srcdir)/conf/common.mk
Index: include/grub/misc.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/misc.h,v retrieving revision 1.17
grub/misc.h +2 -1
@@ -1,7 +1,7 @@/* misc.h - prototypes for misc functions */ /* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2002,2003,2005 Free Software Foundation, Inc. +* Copyright (C) 2002,2003,2005,2006 Free Software Foundation, Inc. * * GRUB is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -75,5 +75,6 @@ grub_uint8_t *EXPORT_FUNC(grub_utf16_to_grub_ssize_t EXPORT_FUNC (grub_utf8_to_ucs4 ) (grub_uint32_t *dest,const grub_uint8_t *src,grub_size_t size); +void *EXPORT_FUNC (grub_memstr ) (void *haystack,int len,char *needle);#endif /* ! GRUB_MISC_HEADER */
Index: include/grub/xcoff.h
===================================================================
RCS file: include/grub/xcoff.h
grub/xcoff.h new file +90 -0
90 lines not on this page · raw message
Index: include/grub/powerpc/ieee1275/kernel.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/ieee1275/kernel.h,v retrieving revision 1.3
grub/powerpc/ieee1275/kernel.h +4 -1
@@ -1,6 +1,6 @@/* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2005 Free Software Foundation, Inc. +* Copyright (C) 2005,2006 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -26,6 +26,9 @@ void EXPORT_FUNC (abort) (void);void EXPORT_FUNC (grub_reboot ) (void );void EXPORT_FUNC (grub_halt ) (void ); +void EXPORT_FUNC (grub_jump ) (unsigned long text,unsigned long stack, +unsigned long arg1,unsigned long arg2); +/* Where grub-mkimage places the core modules in memory. */ #define GRUB_IEEE1275_MODULE_BASE 0x00300000
Index: include/grub/powerpc/ieee1275/loader.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/ieee1275/loader.h,v retrieving revision 1.4
grub/powerpc/ieee1275/loader.h +2 -1
@@ -1,6 +1,6 @@/* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2004 Free Software Foundation, Inc. +* Copyright (C) 2004,2005,2006 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@loader. */ void grub_rescue_cmd_linux (int argc,char *argv[]);void grub_rescue_cmd_initrd (int argc,char *argv[]); +void grub_rescue_cmd_macosx (int argc,char *argv[]);void grub_linux_init (void );void grub_linux_fini (void );
Index: kern/misc.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/misc.c,v
retrieving revision 1.25
misc.c +18 -1
@@ -1,7 +1,7 @@/* misc.c - definitions of misc functions */ /* * GRUB -- GRand Unified Bootloader -* Copyright (C) 1999,2000,2001,2002,2003,2004,2005 Free Software Foundation, Inc. +* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006 Free Software Foundation, Inc. * * GRUB is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -875,3 +875,20 @@ grub_utf8_to_ucs4 (grub_uint32_t *dest,return p - dest; } + +/* Find NULL-terminated `needle' in non-terminated `haystack'. */ +void * +grub_memstr (void *haystack,int len,char *needle) +{ +char *ptr = haystack; +int needle_len =grub_strlen (needle); +int i; + +for (i =0 ; i < len - needle_len; i++) + { +if (0 ==grub_memcmp (ptr + i, needle, needle_len)) +return ptr + i; + } + +return 0 ; +}
Index: kern/powerpc/misc.S
===================================================================
RCS file: kern/powerpc/misc.S
powerpc/misc.S new file +30 -0
@@ -0,0 +1,30 @@ +/* misc.S - Miscellaneous assembly routines. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2006 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + .text + + /* Jump to a function and switch to a new stack. */ + .globl grub_jump +grub_jump: + mtctr 3 + mr 1, 4 + mr 3, 5 + mr 4, 6 + bctr
Index: loader/powerpc/ieee1275/macosx.c
===================================================================
RCS file: loader/powerpc/ieee1275/macosx.c
powerpc/ieee1275/macosx.c new file +329 -0
329 lines not on this page · raw message
Index: loader/powerpc/ieee1275/macosx_normal.c
===================================================================
RCS file: loader/powerpc/ieee1275/macosx_normal.c
powerpc/ieee1275/macosx_normal.c new file +49 -0
49 lines not on this page · raw message
Quoted 2 lines · Hollis Blanchard
Here is the updated patch. I believe I've resolved all your other comments.
Great! Feel free to commit it, although it would be nice if you could test it first (I am really curious if it all works now). ;-)
Thanks,
Marco