diff --git a/ChangeLog b/ChangeLog index 485bad963..9a6ff3118 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,38 @@ +2005-04-30 Hollis Blanchard + + * boot/powerpc/ieee1275/cmain.c: Don't include grub/machine/init.h. + (roundup): Remove macro. + (grub_ieee1275_flags): Make static. + (grub_ieee1275_realmode): Remove. + (grub_ieee1275_test_flag): New function. + (grub_ieee1275_set_flag): Likewise. + (find_options): Rename to `grub_ieee1275_find_options'; update + callers. Set GRUB_IEEE1275_FLAG_REAL_MODE and + GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS. + (cmain): New prototype. + (cmain): Use `grub_ieee1275_set_flag' instead of accessing + `grub_ieee1275_flags' directly. + * conf/powerpc-ieee1275.rmk (grubof_HEADERS): Remove + machine/biosdisk.h. + * disk/powerpc/ieee1275/ofdisk.c: Include grub/machine/ofdisk.h. + Don't include grub/machine/init.h. + (grub_ofdisk_open): Call `grub_ieee1275_test_flag'. + * include/grub/powerpc/ieee1275/ieee1275.h (grub_ieee1275_flags): + Remove prototype. + (grub_ieee1275_realmode): Likewise. + (grub_ieee1275_flag): New enum. + (grub_ieee1275_test_flag): New prototype. + (grub_ieee1275_set_flag): New prototype. + * include/grub/powerpc/ieee1275/init.h: Remove file. + * include/grub/powerpc/ieee1275/ofdisk.h: New file. + * kern/powerpc/ieee1275/init.c: Don't include grub/machine/init.h. + Include grub/machine/console.h. Include grub/machine/ofdisk.h. + (grub_machine_fini): Don't call `grub_ieee1275_release'. Remove + comment. + * kern/powerpc/ieee1275/openfw.c (grub_claimmap): Call + `grub_ieee1275_test_flag'. + (grub_ieee1275_encode_devname): Likewise. + 2005-04-21 Hollis Blanchard * include/grub/powerpc/ieee1275/ieee1275.h diff --git a/boot/powerpc/ieee1275/cmain.c b/boot/powerpc/ieee1275/cmain.c index b1ce37462..775d355bd 100644 --- a/boot/powerpc/ieee1275/cmain.c +++ b/boot/powerpc/ieee1275/cmain.c @@ -23,7 +23,6 @@ #include #include -#include struct module_info { @@ -31,26 +30,47 @@ struct module_info uint32_t end; }; -#define roundup(a, s) (((a) + ((s) - 1)) & ~((s) - 1)) - /* OpenFirmware entry point passed to us from the real bootloader. */ intptr_t (*grub_ieee1275_entry_fn) (void *); -grub_uint32_t grub_ieee1275_flags; -int grub_ieee1275_realmode; +static grub_uint32_t grub_ieee1275_flags; -static void -find_options (void) +int +grub_ieee1275_test_flag (enum grub_ieee1275_flag flag) { - grub_ieee1275_phandle_t options; - - grub_ieee1275_finddevice ("/options", &options); - grub_ieee1275_get_property (options, "real-mode?", &grub_ieee1275_realmode, - sizeof (grub_ieee1275_realmode), 0); + return (grub_ieee1275_flags & (1 << flag)); } +void +grub_ieee1275_set_flag (enum grub_ieee1275_flag flag) +{ + grub_ieee1275_flags |= (1 << flag); +} + +static void +grub_ieee1275_find_options (void) +{ + grub_ieee1275_phandle_t options; + grub_ieee1275_phandle_t openprom; + int realmode; + int smartfw; + + grub_ieee1275_finddevice ("/options", &options); + grub_ieee1275_get_property (options, "real-mode?", &realmode, + sizeof (realmode), 0); + if (realmode) + grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_REAL_MODE); + + grub_ieee1275_finddevice ("/openprom", &openprom); + smartfw = grub_ieee1275_get_property (openprom, "SmartFirmware-version", + 0, 0, 0); + if (smartfw != -1) + grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS); +} + +void cmain (uint32_t r3, uint32_t r4, uint32_t r5); /* Setup the argument vector and pass control over to the main function. */ void @@ -68,7 +88,7 @@ cmain (uint32_t r3, uint32_t r4 __attribute__((unused)), uint32_t r5) grub_ieee1275_entry_fn = (intptr_t (*)(void *)) r3; - grub_ieee1275_flags = GRUB_IEEE1275_NO_PARTITION_0; + grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0); /* Old World Open Firmware may use 4M-5M without claiming it. */ grub_ieee1275_claim (0x00400000, 0x00100000, 0, 0); @@ -84,7 +104,7 @@ cmain (uint32_t r3, uint32_t r4 __attribute__((unused)), uint32_t r5) grub_ieee1275_entry_fn = (intptr_t (*)(void *)) r5; } - find_options (); + grub_ieee1275_find_options (); /* If any argument was passed to the kernel (us), they are put in the bootargs property of /chosen. The string can diff --git a/conf/powerpc-ieee1275.mk b/conf/powerpc-ieee1275.mk index 34fccec72..1f4d83c41 100644 --- a/conf/powerpc-ieee1275.mk +++ b/conf/powerpc-ieee1275.mk @@ -11,7 +11,7 @@ DEFSYMFILES += kernel_syms.lst grubof_HEADERS = arg.h boot.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 rescue.h symbol.h \ - term.h types.h machine/biosdisk.h powerpc/libgcc.h loader.h \ + term.h types.h powerpc/libgcc.h loader.h \ partition.h pc_partition.h machine/time.h machine/ieee1275.h grubof_symlist.c: $(addprefix include/grub/,$(grubof_HEADERS)) gensymlist.sh diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index 5f5077594..228911cba 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -11,7 +11,7 @@ DEFSYMFILES += kernel_syms.lst grubof_HEADERS = arg.h boot.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 rescue.h symbol.h \ - term.h types.h machine/biosdisk.h powerpc/libgcc.h loader.h \ + term.h types.h powerpc/libgcc.h loader.h \ partition.h pc_partition.h machine/time.h machine/ieee1275.h grubof_symlist.c: $(addprefix include/grub/,$(grubof_HEADERS)) gensymlist.sh diff --git a/disk/powerpc/ieee1275/ofdisk.c b/disk/powerpc/ieee1275/ofdisk.c index 8914b3c6d..8e95d8ba6 100644 --- a/disk/powerpc/ieee1275/ofdisk.c +++ b/disk/powerpc/ieee1275/ofdisk.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include static int grub_ofdisk_iterate (int (*hook) (const char *name)) @@ -60,7 +60,7 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) return grub_errno; /* To access the complete disk add `:0'. */ - if (! (grub_ieee1275_flags & GRUB_IEEE1275_NO_PARTITION_0)) + if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0)) grub_strcat (devpath, ":0"); grub_ieee1275_open (devpath, &dev_ihandle); diff --git a/include/grub/powerpc/ieee1275/ieee1275.h b/include/grub/powerpc/ieee1275/ieee1275.h index ea4b19eb5..bb6e28a3c 100644 --- a/include/grub/powerpc/ieee1275/ieee1275.h +++ b/include/grub/powerpc/ieee1275/ieee1275.h @@ -65,11 +65,24 @@ typedef intptr_t grub_ieee1275_ihandle_t; typedef intptr_t grub_ieee1275_phandle_t; extern intptr_t (*grub_ieee1275_entry_fn) (void *); -extern grub_uint32_t grub_ieee1275_flags; -extern int grub_ieee1275_realmode; -/* Old World firmware fails seek when "dev:0" is opened. */ -#define GRUB_IEEE1275_NO_PARTITION_0 0x1 +enum grub_ieee1275_flag +{ + /* Old World firmware fails seek when "dev:0" is opened. */ + GRUB_IEEE1275_FLAG_NO_PARTITION_0, + + /* Apple firmware runs in translated mode and requires use of the "map" + method. Other firmware runs in untranslated mode and doesn't like "map" + calls. */ + GRUB_IEEE1275_FLAG_REAL_MODE, + + /* CHRP specifies partitions are numbered from 1 (partition 0 refers to the + whole disk). However, CodeGen firmware numbers partitions from 0. */ + GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS, +}; + +extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag); +extern void EXPORT_FUNC(grub_ieee1275_set_flag) (enum grub_ieee1275_flag flag); diff --git a/include/grub/powerpc/ieee1275/init.h b/include/grub/powerpc/ieee1275/ofdisk.h similarity index 77% rename from include/grub/powerpc/ieee1275/init.h rename to include/grub/powerpc/ieee1275/ofdisk.h index 4c87a8585..736fab37f 100644 --- a/include/grub/powerpc/ieee1275/init.h +++ b/include/grub/powerpc/ieee1275/ofdisk.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2004 Free Software Foundation, Inc. + * 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 @@ -17,11 +17,10 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef GRUB_INIT_MACHINE_HEADER -#define GRUB_INIT_MACHINE_HEADER 1 +#ifndef GRUB_OFDISK_MACHINE_HEADER +#define GRUB_OFDISK_MACHINE_HEADER 1 -void cmain (uint32_t r3, uint32_t r4, uint32_t r5); -void grub_ofdisk_init (void); -void grub_console_init (void); +extern void grub_ofdisk_init (void); +extern void grub_ofdisk_fini (void); #endif /* ! GRUB_INIT_MACHINE_HEADER */ diff --git a/kern/powerpc/ieee1275/init.c b/kern/powerpc/ieee1275/init.c index dff312625..eacf4a1e8 100644 --- a/kern/powerpc/ieee1275/init.c +++ b/kern/powerpc/ieee1275/init.c @@ -29,9 +29,10 @@ #include #include #include -#include #include #include +#include +#include /* Apple OF 1.0.5 reserves 0x0 to 0x4000 for the exception handlers. */ static const grub_addr_t grub_heap_start = 0x4000; @@ -42,7 +43,7 @@ abort (void) { /* Trap to Open Firmware. */ asm ("trap"); - + for (;;); } @@ -72,7 +73,7 @@ grub_set_prefix (void) grub_ieee1275_finddevice ("/chosen", &chosen); if (grub_ieee1275_get_property (chosen, "bootpath", &bootpath, sizeof (bootpath), 0)) - { + { /* Should never happen. */ grub_printf ("/chosen/bootpath property missing!\n"); grub_env_set ("prefix", ""); @@ -138,9 +139,6 @@ grub_machine_fini (void) { grub_ofdisk_fini (); grub_console_fini (); - - grub_ieee1275_release (grub_heap_start, grub_heap_len); - /* XXX Release memory claimed for Old World firmware. */ } void diff --git a/kern/powerpc/ieee1275/openfw.c b/kern/powerpc/ieee1275/openfw.c index 9d1654c2f..5da790db9 100644 --- a/kern/powerpc/ieee1275/openfw.c +++ b/kern/powerpc/ieee1275/openfw.c @@ -196,7 +196,8 @@ grub_claimmap (grub_addr_t addr, grub_size_t size) if (grub_ieee1275_claim (addr, size, 0, 0)) return -1; - if ((! grub_ieee1275_realmode) && grub_map (addr, addr, size, 0x00)) + if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_REAL_MODE) + && grub_map (addr, addr, size, 0x00)) { grub_printf ("map failed: address 0x%x, size 0x%x\n", addr, size); grub_ieee1275_release (addr, size); @@ -338,7 +339,10 @@ grub_ieee1275_encode_devname (const char *path) if (partition) { unsigned int partno = grub_strtoul (partition, 0, 0); - partno--; /* GRUB partition numbering is 0-based. */ + + /* GRUB partition numbering is 0-based. */ + if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS)) + partno--; /* Assume partno will require less than five bytes to encode. */ encoding = grub_malloc (grub_strlen (device) + 3 + 5);