Skip to contentSkip to conversation

PPC build fixes

PATCH In review Hollis Blanchard 3 participants 6 messages Feb 20, 2005 – Feb 21, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PPC build fixes

This patch fixes PowerPC build breakage from the recent grub-emu changes. Of note:

- grub_reboot and grub_halt in util/i386/pc/misc.c are not architecture-specific, so have been moved to util/grub-emu.c.

- commands/ieee1275/halt.c and reboot.c are no longer architecture-specific either. This is because we now want those commands to be loaded in grub-emu, and of course grub-emu does not emulate Open Firmware. Accordingly, these files are moved up to the commands directory. Since i386 needs a special argument ("no-apm"), it still uses its version in commands/i386/pc.

- since grub_machine_fini isn't called yet, I haven't yet figured out how to release the memory indicated in the comments.

OK?

-Hollis

2005-02-19 Hollis Blanchard <[email protected]>

* commands/ieee1275/halt.c (grub_cmd_halt): Call grub_halt. Move file...
* commands/halt.c: ... to here.
* commands/ieee1275/reboot.c (grub_cmd_reboot): Call grub_reboot. Move file...
* commands/reboot.c: ... to here.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Add commands/halt.c and commands/reboot.c. (reboot_mod_SOURCES): Set to commands/reboot.c. (halt_mod_SOURCES): Set to commands/halt.c.
* disk/powerpc/ieee1275/ofdisk.c (grub_ofdisk_fini): New function.
* include/grub/powerpc/ieee1275/ieee1275.h (grub_reboot): Add prototype.
(grub_halt): Likewise.
* kern/powerpc/ieee1275/init.c (heap_start): Make global. (heap_len): Likewise.
(grub_machine_fini): New function.
* kern/powerpc/ieee1275/openfw.c (grub_reboot): New function. (grub_halt): Likewise.
* term/powerpc/ieee1275/ofconsole.c (grub_ofconsole_fini): New function.
* util/i386/pc/misc.c: Remove file.
(grub_reboot): Move to ...
* util/grub-emu.c: ... here.
* util/i386/pc/misc.c (grub_halt): Move to ...
* util/grub-emu.c: ... here.

Index: commands/halt.c
===================================================================
RCS file: commands/halt.c

halt.c new file +64 -0
diff -N commands/halt.c
@@ -0,0 +1,64 @@
+/* halt.c - command to halt the computer.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2005  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
+ *  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 GRUB; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/normal.h>
+#include <grub/dl.h>
+#include <grub/misc.h>
+#include <grub/machine/ieee1275.h>
+#include <grub/machine/kernel.h>
+
+static grub_err_t
+grub_cmd_halt (struct grub_arg_list *state __attribute__ ((unused)),
+	       int argc __attribute__ ((unused)),
+	       char **args __attribute__ ((unused)))
+{
+  grub_halt ();
+  return 0;
+}
+
+
+#ifdef GRUB_UTIL
+void
+grub_halt_init (void)
+{
+  grub_register_command ("halt", grub_cmd_halt, GRUB_COMMAND_FLAG_BOTH,
+			 "halt", "halts the computer.  This command does not"
+			 " work on all firmware.", 0);
+}
+
+void
+grub_halt_fini (void)
+{
+  grub_unregister_command ("halt");
+}
+#else /* ! GRUB_UTIL */
+GRUB_MOD_INIT
+{
+  (void)mod;			/* To stop warning. */
+  grub_register_command ("halt", grub_cmd_halt, GRUB_COMMAND_FLAG_BOTH,
+			 "halt", "halts the computer.  This command does not"
+			 " work on all firmware.", 0);
+}
+
+GRUB_MOD_FINI
+{
+  grub_unregister_command ("halt");
+}
+#endif

Index: commands/reboot.c
===================================================================
RCS file: commands/reboot.c

reboot.c new file +62 -0

62 lines not on this page · raw message

Index: commands/ieee1275/halt.c
===================================================================
RCS file: commands/ieee1275/halt.c

ieee1275/halt.c deleted +0 -48

48 lines not on this page · raw message

Index: commands/ieee1275/reboot.c
===================================================================
RCS file: commands/ieee1275/reboot.c

ieee1275/reboot.c deleted +0 -46

46 lines not on this page · raw message

Index: conf/powerpc-ieee1275.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/powerpc-ieee1275.rmk,v retrieving revision 1.25

powerpc-ieee1275.rmk +4 -3
diff -u -p -r1.25 powerpc-ieee1275.rmk
@@ -42,7 +42,8 @@ grub_emu_SOURCES = kern/main.c kern/devi
 	normal/menu_entry.c normal/arg.c kern/partition.c	\
 	util/console.c util/grub-emu.c util/misc.c util/i386/pc/getroot.c \
 	kern/env.c disk/loopback.c commands/ls.c commands/help.c	\
-	commands/terminal.c commands/boot.c commands/cmp.c commands/cat.c
+	commands/terminal.c commands/boot.c commands/cmp.c commands/cat.c \
+	commands/halt.c commands/reboot.c 
 grub_emu_LDFLAGS = -lncurses
 
 grubof_SOURCES = boot/powerpc/ieee1275/crt0.S boot/powerpc/ieee1275/cmain.c \
@@ -163,11 +164,11 @@ suspend_mod_SOURCES = commands/ieee1275/
 suspend_mod_CFLAGS = $(COMMON_CFLAGS)
 
 # For reboot.mod
-reboot_mod_SOURCES = commands/ieee1275/reboot.c
+reboot_mod_SOURCES = commands/reboot.c
 reboot_mod_CFLAGS = $(COMMON_CFLAGS)
 
 # For halt.mod
-halt_mod_SOURCES = commands/ieee1275/halt.c
+halt_mod_SOURCES = commands/halt.c
 halt_mod_CFLAGS = $(COMMON_CFLAGS)
 
 # For help.mod.

Index: disk/powerpc/ieee1275/ofdisk.c
===================================================================
RCS file: /cvsroot/grub/grub2/disk/powerpc/ieee1275/ofdisk.c,v retrieving revision 1.7

powerpc/ieee1275/ofdisk.c +6 -0
diff -u -p -r1.7 ofdisk.c
@@ -164,3 +164,9 @@ grub_ofdisk_init (void)
 {
   grub_disk_dev_register (&grub_ofdisk_dev);
 }
+
+void
+grub_ofdisk_fini (void)
+{
+  grub_disk_dev_unregister (&grub_ofdisk_dev);
+}

Index: include/grub/powerpc/ieee1275/ieee1275.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/ieee1275/ieee1275.h,v retrieving revision 1.14

grub/powerpc/ieee1275/ieee1275.h +2 -0
diff -u -p -r1.14 ieee1275.h
@@ -132,5 +132,7 @@ int EXPORT_FUNC(grub_claimmap) (grub_add
 
 void EXPORT_FUNC(abort) (void);
 
+void EXPORT_FUNC (grub_reboot) (void);
+void EXPORT_FUNC (grub_halt) (void);
 
 #endif /* ! GRUB_IEEE1275_MACHINE_HEADER */

Index: kern/powerpc/ieee1275/init.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/ieee1275/init.c,v retrieving revision 1.13

powerpc/ieee1275/init.c +15 -4
diff -u -p -r1.13 init.c
@@ -33,6 +33,10 @@
 #include <grub/machine/time.h>
 #include <grub/machine/kernel.h>
 
+/* Apple OF 1.0.5 reserves 0x0 to 0x4000 for the exception handlers.  */
+static const grub_addr_t heap_start = 0x4000;
+static grub_addr_t heap_len;
+
 void
 abort (void)
 {
@@ -46,13 +50,9 @@ void
 grub_machine_init (void)
 {
   extern char _start;
-  grub_addr_t heap_start;
-  grub_addr_t heap_len;
 
   grub_console_init ();
 
-  /* Apple OF 1.0.5 reserves 0x4000 bytes for the exception handlers.  */
-  heap_start = 0x4000;
   /* Apple OF 3.1.1 reserves an extra 0x1000 bytes below the load address
      of an ELF file.  */
   heap_len = (grub_addr_t) &_start - 0x1000 - heap_start;
@@ -71,6 +71,17 @@ grub_machine_init (void)
 }
 
 void
+grub_machine_fini (void)
+{
+  grub_ofdisk_fini ();
+  grub_console_fini ();
+
+  grub_ieee1275_release (heap_start, heap_len);
+  /* XXX Release memory claimed in 'linux' and 'initrd' commands.  */
+  /* XXX Release memory claimed for Old World firmware.  */
+}
+
+void
 grub_stop (void)
 {
   for (;;);

Index: kern/powerpc/ieee1275/openfw.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/ieee1275/openfw.c,v retrieving revision 1.7

powerpc/ieee1275/openfw.c +12 -0
diff -u -p -r1.7 openfw.c
@@ -199,3 +199,15 @@ grub_claimmap (grub_addr_t addr, grub_si
 
   return 0;
 }
+
+void
+grub_reboot (void)
+{
+  grub_ieee1275_interpret ("reset-all", 0);
+}
+
+void
+grub_halt (void)
+{
+  grub_ieee1275_interpret ("shut-down", 0);
+}

Index: term/powerpc/ieee1275/ofconsole.c
===================================================================
RCS file: /cvsroot/grub/grub2/term/powerpc/ieee1275/ofconsole.c,v retrieving revision 1.5

powerpc/ieee1275/ofconsole.c +6 -0
diff -u -p -r1.5 ofconsole.c
@@ -307,3 +307,9 @@ grub_console_init (void)
   grub_term_register (&grub_ofconsole_term);
   grub_term_set_current (&grub_ofconsole_term);
 }
+
+void
+grub_console_fini (void)
+{
+  grub_term_unregister (&grub_ofconsole_term);
+}

Index: util/grub-emu.c
===================================================================
RCS file: /cvsroot/grub/grub2/util/grub-emu.c,v
retrieving revision 1.15

grub-emu.c +12 -0
diff -u -p -r1.15 grub-emu.c
@@ -73,6 +73,18 @@ grub_arch_dl_relocate_symbols (grub_dl_t
 }
 
 void
+grub_reboot (void)
+{
+  longjmp (main_env, 1);
+}
+
+void
+grub_halt (int no_apm __attribute__ ((unused)))
+{
+  grub_reboot ();
+}
+
+void
 grub_machine_init (void)
 {
   signal (SIGINT, SIG_IGN);

Index: util/i386/pc/misc.c
===================================================================
RCS file: util/i386/pc/misc.c

i386/pc/misc.c deleted +0 -34
diff -N util/i386/pc/misc.c
@@ -1,34 +0,0 @@
-/*
- *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2005  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
- *  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 GRUB; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <setjmp.h>
-
-#include <grub/util/misc.h>
-
-void
-grub_reboot (void)
-{
-  longjmp (main_env, 1);
-}
-
-void
-grub_halt (int no_apm __attribute__ ((unused)))
-{
-  grub_reboot ();
-}
#1 lore raw
Quoted 2 lines · Hollis Blanchard

- grub_reboot and grub_halt in util/i386/pc/misc.c are not architecture-specific, so have been moved to util/grub-emu.c.

grub_halt is clearly arch-specific. Look at the definition grub_halt in PC. It takes one argument, while the PPC version does not. I expect that the same thing might happen in grub_reboot as well.

Okuji

#2 lore raw
Quoted 7 lines · Yoshinori K. Okuji
Quoted 2 lines · Hollis Blanchard

- grub_reboot and grub_halt in util/i386/pc/misc.c are not architecture-specific, so have been moved to util/grub-emu.c.

grub_halt is clearly arch-specific. Look at the definition grub_halt in PC. It takes one argument, while the PPC version does not. I expect that the same thing might happen in grub_reboot as well.

Oops, I meant to convert that into using a more generic "flags" argument, and then "no_apm" becomes one bit in it. How would that be?

grub-emu.c 20 Feb 2005 16:36:49 -0000 renamed from grub-emu.c 15 Feb 2005 00:07:01 -0000 1.15 +12 -0
@@ -73,6 +73,18 @@ grub_arch_dl_relocate_symbols (grub_dl_t
 }
 
 void
+grub_reboot (void)
+{
+  longjmp (main_env, 1);
+}
+
+void
+grub_halt (grub_uint32_t flags __attribute__ ((unused)))
+{
+  grub_reboot ();
+}
+
+void
 grub_machine_init (void)
 {
   signal (SIGINT, SIG_IGN);

-Hollis

#3 lore raw
Quoted 2 lines · Hollis Blanchard

Oops, I meant to convert that into using a more generic "flags" argument, and then "no_apm" becomes one bit in it. How would that be?

Not bad.

Okuji

#5 lore raw
In reply to Hollis Blanchard
Quoted 20 lines · Hollis Blanchard

This patch fixes PowerPC build breakage from the recent grub-emu changes. Of note:

- grub_reboot and grub_halt in util/i386/pc/misc.c are not architecture-specific, so have been moved to util/grub-emu.c.

- commands/ieee1275/halt.c and reboot.c are no longer architecture-specific either. This is because we now want those commands to be loaded in grub-emu, and of course grub-emu does not emulate Open Firmware. Accordingly, these files are moved up to the commands directory. Since i386 needs a special argument ("no-apm"), it still uses its version in commands/i386/pc.

- since grub_machine_fini isn't called yet, I haven't yet figured out how to release the memory indicated in the comments.

OK?

-Hollis

Quoted 8 lines

2005-02-19 Hollis Blanchard <[email protected]>

* commands/ieee1275/halt.c (grub_cmd_halt): Call grub_halt. Move file...
* commands/halt.c: ... to here.
* commands/ieee1275/reboot.c (grub_cmd_reboot): Call grub_reboot. Move file...
* commands/reboot.c: ... to here.

If you do this, you could delete the PC specific reboot and halt commands. Personally I like separate reboot and halt commands. If you do it like this it will become hard/ugly to make platform specific changes, I think.

Quoted 4 lines

* disk/powerpc/ieee1275/ofdisk.c (grub_ofdisk_fini): New function.
* include/grub/powerpc/ieee1275/ieee1275.h (grub_reboot): Add prototype.

Better put this in `include/grub/powerpc/ieee1275/init.h', just like it is done for the PC. Perhaps it would be even better to have a new header file for such things.

Quoted 3 lines

(grub_halt): Likewise.
* kern/powerpc/ieee1275/init.c (heap_start): Make global. (heap_len): Likewise.

`New variable.' would be more appropriate, I think. Can you put a prefix before the function name?

Quoted 1 line

(grub_machine_fini): New function.

It's really nice that we have this now. :)

Quoted 4 lines

* kern/powerpc/ieee1275/openfw.c (grub_reboot): New function. (grub_halt): Likewise.
* term/powerpc/ieee1275/ofconsole.c (grub_ofconsole_fini): New function.

You have added grub_console_fini, not grub_ofconsole_fini.

powerpc/ieee1275/init.c grub_machine_init (void) · line 82

Quoted 10 lines

void

powerpc/ieee1275/init.c +9 -0
+grub_machine_fini (void)
+{
+  grub_ofdisk_fini ();
+  grub_console_fini ();
+
+  grub_ieee1275_release (heap_start, heap_len);
+  /* XXX Release memory claimed in 'linux' and 'initrd' commands.  */
+  /* XXX Release memory claimed for Old World firmware.  */
+}

Why would you release the memory for linux and initrd? IIRC there is a callback function.

I think it should work like this:

In case someone quits GRUB:

- longjump (?)
- Release the memory for the loader (use grub_loader_unset).
- Call grub_console_fini.
- Call grub_ofdisk_fini.
- Release the heap.

In case someone starts a loader the same should be done, except calling grub_loader_unset. After that the OS should be loaded. I wonder what should happen when the OS can not be loaded. Perhaps GRUB just has to fail or so.

Thanks,
Marco

#4 lore raw
In reply to Hollis Blanchard
Quoted 6 lines · Hollis Blanchard
Quoted 4 lines · Yoshinori K. Okuji
Quoted 2 lines · Hollis Blanchard

- grub_reboot and grub_halt in util/i386/pc/misc.c are not architecture-specific, so have been moved to util/grub-emu.c.

Quoted 6 lines
Quoted 3 lines

grub_halt is clearly arch-specific. Look at the definition grub_halt in PC. It takes one argument, while the PPC version does not. I expect that the same thing might happen in grub_reboot as well.

Oops, I meant to convert that into using a more generic "flags" argument, and then "no_apm" becomes one bit in it. How would that be?

And how would the parser work? What if more options have to be added for other archs? I do not have a strong objection against using flags, I am just afraid it might be inadequate and that the current code is easier to maintain.

Thanks,
Marco