grub-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Move kern/loader.c to boot.mod and add preboot_support (was


From: phcoder
Subject: Re: [PATCH] Move kern/loader.c to boot.mod and add preboot_support (was Re: Sendkey patch)
Date: Sun, 08 Feb 2009 00:02:19 +0100
User-agent: Thunderbird 2.0.0.19 (X11/20090105)

A version with biosdisk, pc and ext2
before: 24800
after: 24687
But another matter is expandability - preboot hooks are important. Without them implementation of sendkey or map is impossible. And adding preboot hooks to kernel would increase its size by 150-200 bytes. Also I don't see how this change would prevent integrating e.g. _linux in the core. But modules for loading kernels are often reltively big since they have to treat multiple versions of boot protocol. It also seems that some parts of my patch were missing. I send a completed version.
Thanks
Vladimir 'phcoder' Serbinenko
Robert Millan wrote:
On Mon, Sep 08, 2008 at 10:11:33PM +0200, Javier Martín wrote:
El lun, 08-09-2008 a las 22:48 +0300, Vesa Jääskeläinen escribió:
phcoder wrote:
Hello. As I said in another email there is no need for it. I send a
patch for it.
Doesn't this break our rescue mode ?
How would it? As with other commands, there would be two versions of it,
one for rescue and one for normal. Besides, what is the point in having
the "boot" command in kernel -and thus always available- if you can't
load a kernel to boot?

Vladimir, you're proposing an important change because it modifies the goals
of the rescue mode, but I see there's neither significant support for or
against your proposal.

I think it would help if you provide numbers on how much size do kernel and
boot.mod have before and after the proposed change (on i386-pc).


Index: conf/common.rmk
===================================================================
--- conf/common.rmk     (revision 1967)
+++ conf/common.rmk     (working copy)
@@ -325,7 +325,7 @@
 scsi_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # Commands.
-pkglib_MODULES += hello.mod boot.mod terminal.mod ls.mod       \
+pkglib_MODULES += hello.mod _boot.mod boot.mod terminal.mod ls.mod     \
        cmp.mod cat.mod help.mod search.mod                                     
\
        loopback.mod fs_uuid.mod configfile.mod echo.mod        \
        terminfo.mod test.mod blocklist.mod hexdump.mod         \
@@ -336,8 +336,13 @@
 hello_mod_CFLAGS = $(COMMON_CFLAGS)
 hello_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For _boot.mod.
+_boot_mod_SOURCES = commands/boot.c
+_boot_mod_CFLAGS = $(COMMON_CFLAGS)
+_boot_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 # For boot.mod.
-boot_mod_SOURCES = commands/boot.c
+boot_mod_SOURCES = commands/boot_normal.c
 boot_mod_CFLAGS = $(COMMON_CFLAGS)
 boot_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
Index: conf/i386-pc.rmk
===================================================================
--- conf/i386-pc.rmk    (revision 1967)
+++ conf/i386-pc.rmk    (working copy)
@@ -41,7 +41,7 @@
 # For kernel.img.
 kernel_img_SOURCES = kern/i386/pc/startup.S kern/main.c kern/device.c \
        kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
-       kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
+       kern/misc.c kern/mm.c kern/rescue.c kern/term.c \
        kern/time.c \
        kern/i386/dl.c kern/i386/pc/init.c kern/i386/pc/mmap.c \
        kern/parser.c kern/partition.c \
@@ -52,7 +52,7 @@
        term/i386/pc/console.c term/i386/vga_common.c \
        symlist.c
 kernel_img_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h 
\
-       env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
+       env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h \
        partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \
        machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \
        machine/memory.h machine/loader.h machine/vga.h machine/vbe.h \
@@ -112,7 +112,7 @@
 
 # For grub-emu.
 util/grub-emu.c_DEPENDENCIES = grub_emu_init.h
-grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c       \
+grub_emu_SOURCES = commands/boot.c commands/boot_normal.c commands/cat.c 
commands/cmp.c        \
        commands/configfile.c commands/echo.c commands/help.c           \
        commands/terminal.c commands/ls.c commands/test.c               \
        commands/search.c commands/blocklist.c commands/hexdump.c       \
@@ -125,7 +125,7 @@
        kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c       \
        kern/err.c                                                      \
        normal/execute.c kern/file.c kern/fs.c normal/lexer.c           \
-       kern/loader.c kern/main.c kern/misc.c kern/parser.c             \
+       kern/main.c kern/misc.c kern/parser.c           \
        grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c    \
        normal/arg.c normal/cmdline.c normal/command.c normal/function.c\
        normal/completion.c normal/main.c normal/color.c                \
Index: conf/i386-efi.rmk
===================================================================
--- conf/i386-efi.rmk   (revision 1967)
+++ conf/i386-efi.rmk   (working copy)
@@ -49,7 +49,7 @@
        kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c       \
        kern/err.c                                                      \
        normal/execute.c kern/file.c kern/fs.c normal/lexer.c           \
-       kern/loader.c kern/main.c kern/misc.c kern/parser.c             \
+       kern/main.c kern/misc.c kern/parser.c           \
        grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c    \
        normal/arg.c normal/cmdline.c normal/command.c normal/function.c\
        normal/completion.c normal/context.c normal/main.c              \
@@ -82,7 +82,7 @@
 kernel_mod_EXPORTS = no
 kernel_mod_SOURCES = kern/i386/efi/startup.S kern/main.c kern/device.c \
        kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
-       kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
+       kern/misc.c kern/mm.c kern/rescue.c kern/term.c \
        kern/i386/dl.c kern/i386/efi/init.c kern/parser.c kern/partition.c \
        kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \
        term/efi/console.c disk/efi/efidisk.c \
@@ -91,7 +91,7 @@
        kern/generic/rtc_get_time_ms.c \
        kern/generic/millisleep.c
 kernel_mod_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h 
\
-       env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
+       env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h \
        partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \
        efi/efi.h efi/time.h efi/disk.h
 kernel_mod_CFLAGS = $(COMMON_CFLAGS)
Index: conf/x86_64-efi.rmk
===================================================================
--- conf/x86_64-efi.rmk (revision 1967)
+++ conf/x86_64-efi.rmk (working copy)
@@ -51,7 +51,7 @@
        kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c       \
        kern/err.c                                                      \
        normal/execute.c kern/file.c kern/fs.c normal/lexer.c           \
-       kern/loader.c kern/main.c kern/misc.c kern/parser.c             \
+       kern/main.c kern/misc.c kern/parser.c           \
        grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c    \
        normal/arg.c normal/cmdline.c normal/command.c normal/function.c\
        normal/completion.c normal/context.c normal/main.c              \
@@ -85,7 +85,7 @@
 kernel_mod_SOURCES = kern/x86_64/efi/startup.S kern/x86_64/efi/callwrap.S \
        kern/main.c kern/device.c \
        kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
-       kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
+       kern/misc.c kern/mm.c kern/rescue.c kern/term.c \
        kern/x86_64/dl.c kern/i386/efi/init.c kern/parser.c kern/partition.c \
        kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \
        kern/time.c \
@@ -93,7 +93,7 @@
        kern/generic/millisleep.c kern/generic/rtc_get_time_ms.c \
        term/efi/console.c disk/efi/efidisk.c
 kernel_mod_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h 
\
-       env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
+       env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h \
        partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \
        efi/efi.h efi/time.h efi/disk.h machine/loader.h
 kernel_mod_CFLAGS = $(COMMON_CFLAGS)
Index: conf/powerpc-ieee1275.rmk
===================================================================
--- conf/powerpc-ieee1275.rmk   (revision 1967)
+++ conf/powerpc-ieee1275.rmk   (working copy)
@@ -15,7 +15,7 @@
 
 kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.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 time.h types.h powerpc/libgcc.h loader.h partition.h \
+       symbol.h term.h time.h types.h powerpc/libgcc.h partition.h \
        pc_partition.h ieee1275/ieee1275.h machine/kernel.h
 
 symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h 
gensymlist.sh
@@ -52,7 +52,7 @@
        \
        io/gzio.c                                                       \
        kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c       \
-       kern/err.c kern/file.c kern/fs.c kern/loader.c kern/main.c      \
+       kern/err.c kern/file.c kern/fs.c kern/main.c    \
        kern/misc.c kern/parser.c kern/partition.c kern/rescue.c        \
        kern/term.c fs/fshelp.c                                         \
        normal/arg.c normal/cmdline.c normal/command.c                  \
@@ -75,7 +75,7 @@
 kernel_elf_SOURCES = kern/powerpc/ieee1275/startup.S kern/ieee1275/cmain.c \
        kern/ieee1275/ieee1275.c kern/main.c kern/device.c              \
        kern/disk.c kern/dl.c kern/err.c kern/file.c kern/fs.c          \
-       kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c   \
+       kern/misc.c kern/mm.c kern/rescue.c kern/term.c         \
        kern/ieee1275/init.c                                            \
        kern/ieee1275/mmap.c                                            \
        term/ieee1275/ofconsole.c               \
Index: conf/i386-coreboot.rmk
===================================================================
--- conf/i386-coreboot.rmk      (revision 1967)
+++ conf/i386-coreboot.rmk      (working copy)
@@ -16,7 +16,7 @@
        kern/i386/multiboot_mmap.c \
        kern/main.c kern/device.c \
        kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
-       kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
+       kern/misc.c kern/mm.c kern/rescue.c kern/term.c \
        kern/time.c \
        kern/i386/dl.c kern/parser.c kern/partition.c \
        kern/i386/tsc.c kern/i386/pit.c \
@@ -27,7 +27,7 @@
        term/i386/pc/at_keyboard.c \
        symlist.c
 kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h 
\
-       env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
+       env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h \
        partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \
        machine/boot.h machine/console.h machine/init.h \
        machine/memory.h machine/loader.h
Index: conf/sparc64-ieee1275.rmk
===================================================================
--- conf/sparc64-ieee1275.rmk   (revision 1967)
+++ conf/sparc64-ieee1275.rmk   (working copy)
@@ -15,7 +15,7 @@
 
 kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.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 time.h types.h sparc64/libgcc.h loader.h partition.h \
+       symbol.h term.h time.h types.h sparc64/libgcc.h partition.h \
        pc_partition.h ieee1275/ieee1275.h machine/kernel.h
 
 symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h 
gensymlist.sh
@@ -53,7 +53,7 @@
 #      grub_script.tab.c                                               \
 #      io/gzio.c                                                       \
 #      kern/device.c kern/disk.c kern/dl.c kern/env.c kern/err.c       \
-#      kern/file.c kern/fs.c kern/loader.c kern/main.c kern/misc.c     \
+#      kern/file.c kern/fs.c kern/main.c kern/misc.c   \
 #      kern/parser.c kern/partition.c kern/rescue.c kern/term.c        \
 #      normal/arg.c normal/cmdline.c normal/command.c                  \
 #      normal/completion.c normal/context.c normal/execute.c           \
@@ -69,7 +69,7 @@
 
 kernel_elf_SOURCES = kern/sparc64/ieee1275/init.c kern/ieee1275/ieee1275.c \
        kern/main.c kern/device.c kern/disk.c kern/dl.c kern/file.c \
-       kern/fs.c kern/err.c kern/misc.c kern/mm.c kern/loader.c \
+       kern/fs.c kern/err.c kern/misc.c kern/mm.c \
        kern/rescue.c kern/term.c term/ieee1275/ofconsole.c \
        kern/sparc64/ieee1275/openfw.c disk/ieee1275/ofdisk.c \
        kern/partition.c kern/env.c kern/sparc64/dl.c symlist.c \
Index: conf/i386-ieee1275.rmk
===================================================================
--- conf/i386-ieee1275.rmk      (revision 1967)
+++ conf/i386-ieee1275.rmk      (working copy)
@@ -17,7 +17,7 @@
        kern/ieee1275/cmain.c kern/ieee1275/openfw.c \
        kern/main.c kern/device.c \
        kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
-       kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
+       kern/misc.c kern/mm.c kern/rescue.c kern/term.c \
        kern/i386/dl.c kern/parser.c kern/partition.c \
        kern/env.c \
        kern/time.c \
@@ -27,7 +27,7 @@
        disk/ieee1275/ofdisk.c \
        symlist.c
 kernel_elf_HEADERS = arg.h cache.h device.h disk.h dl.h elf.h elfload.h \
-       env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
+       env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h \
        partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \
        ieee1275/ieee1275.h machine/kernel.h machine/loader.h machine/memory.h
 kernel_elf_CFLAGS = $(COMMON_CFLAGS)
@@ -71,7 +71,7 @@
        kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c       \
        kern/err.c                                                      \
        normal/execute.c kern/file.c kern/fs.c normal/lexer.c           \
-       kern/loader.c kern/main.c kern/misc.c kern/parser.c             \
+       kern/main.c kern/misc.c kern/parser.c           \
        grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c    \
        normal/arg.c normal/cmdline.c normal/command.c normal/function.c\
        normal/completion.c normal/main.c                               \
Index: kern/loader.c
===================================================================
--- kern/loader.c       (revision 1967)
+++ kern/loader.c       (working copy)
@@ -1,75 +0,0 @@
-/*
- *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2002,2003,2004,2006,2007  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 3 of the License, or
- *  (at your option) any later version.
- *
- *  GRUB 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, see <http://www.gnu.org/licenses/>.
- */
-
-#include <grub/loader.h>
-#include <grub/misc.h>
-#include <grub/mm.h>
-#include <grub/err.h>
-#include <grub/kernel.h>
-
-static grub_err_t (*grub_loader_boot_func) (void);
-static grub_err_t (*grub_loader_unload_func) (void);
-static int grub_loader_noreturn;
-
-static int grub_loader_loaded;
-
-int
-grub_loader_is_loaded (void)
-{
-  return grub_loader_loaded;
-}
-
-void
-grub_loader_set (grub_err_t (*boot) (void),
-                grub_err_t (*unload) (void),
-                int noreturn)
-{
-  if (grub_loader_loaded && grub_loader_unload_func)
-    grub_loader_unload_func ();
-  
-  grub_loader_boot_func = boot;
-  grub_loader_unload_func = unload;
-  grub_loader_noreturn = noreturn;
-  
-  grub_loader_loaded = 1;
-}
-
-void
-grub_loader_unset(void)
-{
-  if (grub_loader_loaded && grub_loader_unload_func)
-    grub_loader_unload_func ();
-  
-  grub_loader_boot_func = 0;
-  grub_loader_unload_func = 0;
-
-  grub_loader_loaded = 0;
-}
-
-grub_err_t
-grub_loader_boot (void)
-{
-  if (! grub_loader_loaded)
-    return grub_error (GRUB_ERR_NO_KERNEL, "no loaded kernel");
-
-  if (grub_loader_noreturn)
-    grub_machine_fini ();
-  
-  return (grub_loader_boot_func) ();
-}
-
Index: kern/rescue.c
===================================================================
--- kern/rescue.c       (revision 1967)
+++ kern/rescue.c       (working copy)
@@ -117,14 +117,6 @@
   grub_refresh ();
 }
 
-/* boot */
-static void
-grub_rescue_cmd_boot (int argc __attribute__ ((unused)),
-                     char *argv[] __attribute__ ((unused)))
-{
-  grub_loader_boot ();
-}
-
 /* cat FILE */
 static void
 grub_rescue_cmd_cat (int argc, char *argv[])
@@ -620,8 +612,6 @@
 
   grub_printf ("Entering rescue mode...\n");
   
-  grub_rescue_register_command ("boot", grub_rescue_cmd_boot,
-                               "boot an operating system");
   grub_rescue_register_command ("cat", grub_rescue_cmd_cat,
                                "show the contents of a file");
   grub_rescue_register_command ("help", grub_rescue_cmd_help,
Index: include/grub/loader.h
===================================================================
--- include/grub/loader.h       (revision 1967)
+++ include/grub/loader.h       (working copy)
@@ -25,20 +25,26 @@
 #include <grub/err.h>
 #include <grub/types.h>
 
+
 /* Check if a loader is loaded.  */
-int EXPORT_FUNC(grub_loader_is_loaded) (void);
+int grub_loader_is_loaded (void);
 
 /* Set loader functions. NORETURN must be set to true, if BOOT won't return
    to the original state.  */
-void EXPORT_FUNC(grub_loader_set) (grub_err_t (*boot) (void),
+void grub_loader_set (grub_err_t (*boot) (void),
                                   grub_err_t (*unload) (void),
                                   int noreturn);
 
 /* Unset current loader, if any.  */
-void EXPORT_FUNC(grub_loader_unset) (void);
+void grub_loader_unset (void);
 
-/* Call the boot hook in current loader. This may or may not return,
-   depending on the setting by grub_loader_set.  */
-grub_err_t EXPORT_FUNC(grub_loader_boot) (void);
+/*Add a preboot function*/
+void *grub_loader_add_preboot (grub_err_t (*preboot_func) (int noreturn));
 
+/*Remove given preboot function*/
+void grub_loader_remove_preboot (void *hnd);
+
+void grub_rescue_cmd_boot (int argc, char *argv[]);
+
+
 #endif /* ! GRUB_LOADER_HEADER */
Index: include/grub/kernel.h
===================================================================
--- include/grub/kernel.h       (revision 1967)
+++ include/grub/kernel.h       (working copy)
@@ -64,7 +64,7 @@
 void grub_machine_init (void);
 
 /* The machine-specific finalization.  */
-void grub_machine_fini (void);
+void EXPORT_FUNC(grub_machine_fini) (void);
 
 /* The machine-specific prefix initialization.  */
 void grub_machine_set_prefix (void);
Index: ChangeLog
===================================================================
--- ChangeLog   (revision 1967)
+++ ChangeLog   (working copy)
@@ -1,3 +1,24 @@
+2009-02-07  Vladimir Serbinenko  <address@hidden>
+
+       Add preboot hooks and move boot out of kernel
+       
+       * conf/common.rmk: Added _boot.mod
+       * conf/i386-pc.rmk: Removed loader.c and loader.h from 
+       kernel and grub-emu sources
+       * conf/i386-coreboot.rmk: Likewise
+       * conf/i386-efi.rmk: Likewise
+       * conf/i386-ieee1275.rmk: Likewise
+       * conf/powerpc-ieee1275.rmk: Likewise
+       * conf/sparc64-ieee1275.rmk: Likewise
+       * commands/boot.c: Moved from here...
+       * commands/boot_normal.c: ...moved here
+       * kern/loader.c: Moved to ..
+       * commands/boot.c: ... moved here
+       * commands/boot.c: preboot hook support
+       * kern/rescue.c: removed grub_rescue_cmd_boot
+       * include/grub/loader.h: removed EXPORT_FUNC
+       * include/grub/kernel.h: added EXPORT_FUNC to grub_machine_init
+
 2009-02-01  Felix Zielcke  <address@hidden>
 
        * INSTALL: Note that we now require at least autconf 2.59 and that LZO
Index: commands/boot.c
===================================================================
--- commands/boot.c     (revision 1967)
+++ commands/boot.c     (working copy)
@@ -17,34 +17,140 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <grub/normal.h>
+#include <grub/loader.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/err.h>
+#include <grub/kernel.h>
+#include <grub/rescue.h>
 #include <grub/dl.h>
-#include <grub/arg.h>
-#include <grub/misc.h>
-#include <grub/loader.h>
 
-static grub_err_t
-grub_cmd_boot (struct grub_arg_list *state __attribute__ ((unused)),
-              int argc, char **args __attribute__ ((unused)))
+struct grub_loader_preboot_t
 {
-  if (argc)
-    return grub_error (GRUB_ERR_BAD_ARGUMENT, "too many arguments");
+  struct grub_loader_preboot_t *prev;
+  struct grub_loader_preboot_t *next;
+  grub_err_t (*preboot_func) (int noreturn);
+};
+
+static grub_dl_t my_mod;
+
+static grub_err_t (*grub_loader_boot_func) (void);
+static grub_err_t (*grub_loader_unload_func) (void);
+static int grub_loader_noreturn;
+static int grub_loader_loaded;
+static struct grub_loader_preboot_t *grub_loader_preboots=0;
+
+void *
+grub_loader_add_preboot (grub_err_t (*preboot_func) (int noreturn))
+{
+  struct grub_loader_preboot_t *cur;
+
+  if (!preboot_func)
+    return 0;
+
+  cur=(struct grub_loader_preboot_t *)
+    grub_malloc (sizeof (struct grub_loader_preboot_t));
+  if (!cur)
+    {
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, "hook not added");
+      return 0;
+    }
+
+  cur->preboot_func=preboot_func;
+  cur->prev=0;
+  if (grub_loader_preboots)
+    {
+      cur->next=grub_loader_preboots;
+      cur->next->prev=cur;
+    }
+  else
+    cur->next=0;    
+  grub_loader_preboots=cur;
+
+  return cur;
+}
+
+void 
+grub_loader_remove_preboot (void *hnd)
+{
+  struct grub_loader_preboot_t *cur=(struct grub_loader_preboot_t *)hnd;
+
+  if (cur->next)
+    cur->next->prev=cur->prev;
+
+  if (cur->prev)
+    cur->prev->next=cur->next;
+  else
+    grub_loader_preboots=cur->next;
+
+  grub_free (cur);
+}
+
+int
+grub_loader_is_loaded (void)
+{
+  return grub_loader_loaded;
+}
+
+void
+grub_loader_set (grub_err_t (*boot) (void),
+                grub_err_t (*unload) (void),
+                int noreturn)
+{
+  if (grub_loader_loaded && grub_loader_unload_func)
+    grub_loader_unload_func ();
   
-  grub_loader_boot ();
+  grub_loader_boot_func = boot;
+  grub_loader_unload_func = unload;
+  grub_loader_noreturn = noreturn;
   
-  return 0;
+  grub_loader_loaded = 1;
 }
 
-
+void
+grub_loader_unset(void)
+{
+  if (grub_loader_loaded && grub_loader_unload_func)
+    grub_loader_unload_func ();
+  
+  grub_loader_boot_func = 0;
+  grub_loader_unload_func = 0;
 
-GRUB_MOD_INIT(boot)
+  grub_loader_loaded = 0;
+}
+
+
+void
+grub_rescue_cmd_boot (int argc __attribute__ ((unused)), 
+                     char *argv[] __attribute__ ((unused)))
 {
-  (void) mod;                  /* To stop warning. */
-  grub_register_command ("boot", grub_cmd_boot, GRUB_COMMAND_FLAG_BOTH,
-                        "boot", "Boot an operating system.", 0);
+  struct grub_loader_preboot_t *cur;
+  if (! grub_loader_loaded)
+    {
+      grub_error (GRUB_ERR_NO_KERNEL, "no loaded kernel");
+      return;
+    }
+
+  if (grub_loader_noreturn)
+    grub_machine_fini ();
+
+  for (cur=grub_loader_preboots; cur; cur=cur->next)
+    if (cur->preboot_func)
+      cur->preboot_func (grub_loader_noreturn);
+  
+  (grub_loader_boot_func) ();
 }
 
-GRUB_MOD_FINI(boot)
+
+GRUB_MOD_INIT(_boot)
 {
-  grub_unregister_command ("boot");
+  grub_rescue_register_command ("boot",
+                               grub_rescue_cmd_boot,
+                               "boot OS");
+  my_mod = mod;
 }
+
+GRUB_MOD_FINI(_boot)
+{
+  grub_rescue_unregister_command ("boot");
+}
Index: commands/boot_normal.c
===================================================================
--- commands/boot_normal.c      (revision 0)
+++ commands/boot_normal.c      (revision 0)
@@ -0,0 +1,48 @@
+/* boot_normal.c - wraper of boot command for normal mode */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2003,2005,2007  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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/normal.h>
+#include <grub/dl.h>
+#include <grub/arg.h>
+#include <grub/misc.h>
+#include <grub/loader.h>
+
+static grub_err_t
+grub_cmd_boot (struct grub_arg_list *state __attribute__ ((unused)),
+              int argc, char **args __attribute__ ((unused)))
+{
+
+  grub_rescue_cmd_boot (argc, args);
+  
+  return grub_errno;
+}
+
+
+
+GRUB_MOD_INIT(boot)
+{
+  (void) mod;                  /* To stop warning. */
+  grub_register_command ("boot", grub_cmd_boot, GRUB_COMMAND_FLAG_BOTH,
+                        "boot", "Boot an operating system.", 0);
+}
+
+GRUB_MOD_FINI(boot)
+{
+  grub_unregister_command ("boot");
+}

reply via email to

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