Skip to contentSkip to conversation

PPC build fixes

PATCH Hollis Blanchard 2 participants 4 messages Mar 24, 2005 – Mar 25, 2005

lore
Share & tools
lore
#0 lore raw

5 weeks later...

Here I did not combine i386 and PPC halt/reboot as I did in my original patch.

-Hollis

2005-03-23 Hollis Blanchard <[email protected]>

* commands/ieee1275/halt.c (grub_cmd_halt): Call grub_halt instead of grub_ieee1275_interpret.
(grub_halt_init): New function.
(grub_halt_fini): Likewise.
(GRUB_MOD_INIT): Correct message grammar.
* commands/ieee1275/reboot.c (grub_cmd_reboot): Call grub_reboot instead of grub_ieee1275_interpret. (grub_reboot_init): New function.
(grub_reboot_fini): Likewise.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Replace commands/i386/pc/halt.c, commands/i386/pc/reboot.c, and util/i386/pc/misc.c with
commands/ieee1275/halt.c, commands/ieee1275/reboot.c, and util/powerpc/ieee1275/misc.c.
* disk/powerpc/ieee1275/ofdisk.c (grub_ofdisk_fini): New function.
* include/grub/powerpc/ieee1275/console.h (grub_console_fini):
Add prototype.
* include/grub/powerpc/ieee1275/ieee1275.h (grub_reboot): Add prototype.
(grub_halt): Likewise.
* include/grub/powerpc/ieee1275/init.h: Remove inaccurate comment. (cmain): Remove __attribute__((unused)).
* kern/powerpc/ieee1275/init.c (grub_heap_start): New variable. (grub_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_console_fini): New function.
* util/powerpc/ieee1275/misc.c (grub_reboot): New function. (grub_halt): Likewise.

Index: commands/ieee1275/halt.c
===================================================================
RCS file: /cvsroot/grub/grub2/commands/ieee1275/halt.c,v retrieving revision 1.1

ieee1275/halt.c +18 -3
diff -u -p -r1.1 halt.c
@@ -28,21 +28,36 @@ grub_cmd_halt (struct grub_arg_list *sta
 	       int argc __attribute__ ((unused)),
 	       char **args __attribute__ ((unused)))
 {
-  grub_ieee1275_interpret ("shut-down", 0);
+  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 every firmware.", 0);
+			 " work on all firmware.", 0);
 }
 
 GRUB_MOD_FINI
 {
   grub_unregister_command ("halt");
 }
-
+#endif

Index: commands/ieee1275/reboot.c
===================================================================
RCS file: /cvsroot/grub/grub2/commands/ieee1275/reboot.c,v retrieving revision 1.1

ieee1275/reboot.c +16 -1
diff -u -p -r1.1 reboot.c
@@ -28,11 +28,25 @@ grub_cmd_reboot (struct grub_arg_list *s
 		 int argc __attribute__ ((unused)),
 		 char **args __attribute__ ((unused)))
 {
-  grub_ieee1275_interpret ("reset-all", 0);
+  grub_reboot ();
   return 0;
 }
 
 
+#ifdef GRUB_UTIL
+void
+grub_reboot_init (void)
+{
+  grub_register_command ("reboot", grub_cmd_reboot, GRUB_COMMAND_FLAG_BOTH,
+			 "reboot", "Reboot the computer", 0);
+}
+
+void
+grub_reboot_fini (void)
+{
+  grub_unregister_command ("reboot");
+}
+#else /* ! GRUB_UTIL */
 GRUB_MOD_INIT
 {
   (void)mod;			/* To stop warning. */
@@ -44,3 +58,4 @@ GRUB_MOD_FINI
 {
   grub_unregister_command ("reboot");
 }
+#endif

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

powerpc-ieee1275.rmk +2 -2
diff -u -p -r1.28 powerpc-ieee1275.rmk
@@ -35,7 +35,7 @@ grub_mkimage_SOURCES = util/powerpc/ieee
 grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c 	\
 	commands/configfile.c commands/default.c commands/help.c	\
 	commands/terminal.c commands/ls.c commands/timeout.c		\
-	commands/i386/pc/halt.c commands/i386/pc/reboot.c		\
+	commands/ieee1275/halt.c commands/ieee1275/reboot.c		\
 	disk/loopback.c							\
 	fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c fs/jfs.c	\
 	fs/minix.c fs/ufs.c						\
@@ -47,7 +47,7 @@ grub_emu_SOURCES = commands/boot.c comma
 	partmap/amiga.c	partmap/apple.c partmap/pc.c partmap/sun.c	\
 	util/console.c util/grub-emu.c util/misc.c			\
 	util/i386/pc/biosdisk.c util/i386/pc/getroot.c			\
-	util/i386/pc/misc.c
+	util/powerpc/ieee1275/misc.c
 
 grub_emu_LDFLAGS = -lncurses
 

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/console.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/ieee1275/console.h,v retrieving revision 1.2

grub/powerpc/ieee1275/console.h +3 -0
diff -u -p -r1.2 console.h
@@ -51,6 +51,9 @@ void grub_console_setcursor (int on);
 /* Initialize the console system.  */
 void grub_console_init (void);
 
+/* Finish the console system.  */
+void grub_console_fini (void);
+
 #endif
 
 #endif /* ! GRUB_CONSOLE_MACHINE_HEADER */

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
@@ -131,6 +131,8 @@ grub_err_t EXPORT_FUNC(grub_children_ite
 int EXPORT_FUNC(grub_claimmap) (grub_addr_t addr, grub_size_t size);
 
 void EXPORT_FUNC(abort) (void);
+void EXPORT_FUNC (grub_reboot) (void);
+void EXPORT_FUNC (grub_halt) (void);
 
 
 #endif /* ! GRUB_IEEE1275_MACHINE_HEADER */

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

grub/powerpc/ieee1275/init.h +1 -2
diff -u -p -r1.1 init.h
@@ -1,4 +1,3 @@
-/* ieee1275.h - Access the Open Firmware client interface.  */
 /*
  *  GRUB  --  GRand Unified Bootloader
  *  Copyright (C) 2004  Free Software Foundation, Inc.
@@ -21,7 +20,7 @@
 #ifndef GRUB_INIT_MACHINE_HEADER
 #define GRUB_INIT_MACHINE_HEADER	1
 
-void cmain (uint32_t r3, uint32_t r4 __attribute__((unused)), uint32_t r5);
+void cmain (uint32_t r3, uint32_t r4, uint32_t r5);
 void grub_ofdisk_init (void);
 void grub_console_init (void);
 

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 +21 -9
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 grub_heap_start = 0x4000;
+static grub_addr_t grub_heap_len;
+
 void
 abort (void)
 {
@@ -46,24 +50,20 @@ 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;
+  grub_heap_len = (grub_addr_t) &_start - 0x1000 - grub_heap_start;
 
-  if (grub_ieee1275_claim (heap_start, heap_len, 0, 0))
+  if (grub_ieee1275_claim (grub_heap_start, grub_heap_len, 0, 0))
     {
-      grub_printf ("Failed to claim heap at 0x%x, len 0x%x\n", heap_start,
-		   heap_len);
+      grub_printf ("Failed to claim heap at 0x%x, len 0x%x\n", grub_heap_start,
+		   grub_heap_len);
       abort ();
     }
-  grub_mm_init_region ((void *) heap_start, heap_len);
+  grub_mm_init_region ((void *) grub_heap_start, grub_heap_len);
 
   grub_env_set ("prefix", "");
 
@@ -71,6 +71,18 @@ grub_machine_init (void)
 }
 
 void
+grub_machine_fini (void)
+{
+  grub_loader_unset ();
+
+  grub_ofdisk_fini ();
+  grub_console_fini ();
+
+  grub_ieee1275_release (grub_heap_start, grub_heap_len);
+  /* 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/powerpc/ieee1275/misc.c
===================================================================
RCS file: util/powerpc/ieee1275/misc.c

powerpc/ieee1275/misc.c new file +34 -0
diff -N util/powerpc/ieee1275/misc.c
@@ -0,0 +1,34 @@
+/*
+ *  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 (void)
+{
+  grub_reboot ();
+}
#1 lore raw
Quoted 1 line · Hollis Blanchard

5 weeks later...

np.

Quoted 2 lines

Here I did not combine i386 and PPC halt/reboot as I did in my original patch.

Cool!

Quoted 2 lines

(grub_halt_init): New function.
(grub_halt_fini): Likewise.

Why do you need this?

Quoted 2 lines

(grub_reboot_init): New function.
(grub_reboot_fini): Likewise.

Same here.

Quoted 2 lines

* include/grub/powerpc/ieee1275/init.h: Remove inaccurate comment.

Can you change the comment to something sane?

Quoted 2 lines

* util/powerpc/ieee1275/misc.c (grub_reboot): New function. (grub_halt): Likewise.

Isn't this just a completely new file?

Thanks,
Marco

#2 lore raw
Quoted 10 lines · Marco Gerards
Quoted 2 lines · Hollis Blanchard

(grub_halt_init): New function.
(grub_halt_fini): Likewise.

Why do you need this?

Quoted 2 lines

(grub_reboot_init): New function.
(grub_reboot_fini): Likewise.

Same here.

Because these commands need to be accessible from grub-emu (that is how you quit).

Quoted 4 lines
Quoted 2 lines

* include/grub/powerpc/ieee1275/init.h: Remove inaccurate comment.

Can you change the comment to something sane?

include/grub/i386/pc/init.h has no comment, and I don't know how to describe this anyways:

	void cmain (uint32_t r3, uint32_t r4, uint32_t r5);
	void grub_ofdisk_init (void);
	void grub_console_init (void);

"A tiny bit of miscellaneous stuff"? "Things related to booting"?

Quoted 4 lines
Quoted 2 lines

* util/powerpc/ieee1275/misc.c (grub_reboot): New function. (grub_halt): Likewise.

Isn't this just a completely new file?

Er, yes, sorry. :)

-Hollis

#3 lore raw

Hollis Blanchard <[email protected]> writes:

[...]

Quoted 2 lines

Because these commands need to be accessible from grub-emu (that is how you quit).

Oh, right.

Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

* include/grub/powerpc/ieee1275/init.h: Remove inaccurate comment.

Can you change the comment to something sane?

Quoted 7 lines

include/grub/i386/pc/init.h has no comment, and I don't know how to describe this anyways:

	void cmain (uint32_t r3, uint32_t r4, uint32_t r5);
	void grub_ofdisk_init (void);
	void grub_console_init (void);

"A tiny bit of miscellaneous stuff"? "Things related to booting"?

Ok, just remove it. You are right again. :)

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

* util/powerpc/ieee1275/misc.c (grub_reboot): New function. (grub_halt): Likewise.

Isn't this just a completely new file?

Er, yes, sorry. :)

Can you change these two lines to this:

* util/powerpc/ieee1275/misc.c: New file

If you do this, you could commit the patch. I can also do it if you want. After this we can concentrate on getting that boot-path patch committed. I will fix the initrd problem this weekend.

Thanks,
Marco