--- a/commands/boot.c +++ b/commands/boot.c @@ -1,7 +1,7 @@ /* boot.c - command to boot an operating system */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2005,2007 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2004,2005,2007,2009 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 @@ -21,29 +21,82 @@ #include #include #include +#include -static grub_err_t -grub_cmd_boot (struct grub_arg_list *state __attribute__ ((unused)), - int argc, char **args __attribute__ ((unused))) +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 (argc) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "too many arguments"); + if (grub_loader_loaded && grub_loader_unload_func) + grub_loader_unload_func (); - grub_loader_boot (); + 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 0; + return (grub_loader_boot_func) (); +} + + +/* boot */ +static grub_err_t +grub_cmd_boot (struct grub_command *cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char *argv[] __attribute__ ((unused))) +{ + return grub_loader_boot (); } +static grub_command_t cmd_boot; + 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); + cmd_boot = + grub_register_command ("boot", grub_cmd_boot, + 0, "boot an operating system"); } GRUB_MOD_FINI(boot) { - grub_unregister_command ("boot"); + grub_unregister_command (cmd_boot); } diff --git a/commands/minicmd.c b/commands/minicmd.c index 071c889..5083291 100644 --- a/commands/minicmd.c +++ b/commands/minicmd.c @@ -1,7 +1,7 @@ /* minicmd.c - commands for the rescue mode */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2005,2006,2007 Free Software Foundation, Inc. + * Copyright (C) 2003,2005,2006,2007,2009 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 @@ -28,15 +28,6 @@ #include #include -/* boot */ -static grub_err_t -grub_mini_cmd_boot (struct grub_command *cmd __attribute__ ((unused)), - int argc __attribute__ ((unused)), - char *argv[] __attribute__ ((unused))) -{ - return grub_loader_boot (); -} - /* cat FILE */ static grub_err_t grub_mini_cmd_cat (struct grub_command *cmd __attribute__ ((unused)), @@ -345,16 +336,13 @@ grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)), return 0; } -static grub_command_t cmd_boot, cmd_cat, cmd_help, cmd_root; +static grub_command_t cmd_cat, cmd_help, cmd_root; static grub_command_t cmd_dump, cmd_rmmod, cmd_lsmod, cmd_exit; GRUB_MOD_INIT(minicmd) { (void) mod; /* To stop warning. */ - cmd_boot = - grub_register_command ("boot", grub_mini_cmd_boot, - 0, "boot an operating system"); cmd_cat = grub_register_command ("cat", grub_mini_cmd_cat, "cat FILE", "show the contents of a file"); @@ -380,7 +368,6 @@ GRUB_MOD_INIT(minicmd) GRUB_MOD_FINI(minicmd) { - grub_unregister_command (cmd_boot); grub_unregister_command (cmd_cat); grub_unregister_command (cmd_help); grub_unregister_command (cmd_root); diff --git a/conf/common.rmk b/conf/common.rmk index 43bc683..062d6b6 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -335,7 +335,12 @@ pkglib_MODULES += minicmd.mod extcmd.mod hello.mod handler.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 \ - read.mod sleep.mod loadenv.mod crc.mod + read.mod sleep.mod loadenv.mod crc.mod boot.mod + +# For boot.mod. +boot_mod_SOURCES = commands/boot.c +boot_mod_CFLAGS = $(COMMON_CFLAGS) +boot_mod_LDFLAGS = $(COMMON_LDFLAGS) # For minicmd.mod. minicmd_mod_SOURCES = commands/minicmd.c diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index 0b4f216..018f0a5 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -16,7 +16,7 @@ kernel_elf_SOURCES = kern/i386/coreboot/startup.S \ 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/list.c kern/handler.c kern/command.c kern/corecmd.c \ kern/i386/dl.c kern/parser.c kern/partition.c \ kern/i386/tsc.c kern/i386/pit.c \ @@ -73,7 +73,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ kern/err.c kern/list.c kern/handler.c \ kern/command.c kern/corecmd.c commands/extcmd.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 \ + commands/boot.c kern/main.c kern/misc.c kern/parser.c \ grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c \ lib/arg.c normal/cmdline.c normal/command.c normal/function.c\ normal/completion.c normal/main.c normal/menu_text.c \ diff --git a/conf/i386-efi.rmk b/conf/i386-efi.rmk index 18a99df..0b5928b 100644 --- a/conf/i386-efi.rmk +++ b/conf/i386-efi.rmk @@ -50,7 +50,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ kern/err.c kern/list.c kern/handler.c \ kern/command.c kern/corecmd.c commands/extcmd.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 \ + commands/boot.c kern/main.c kern/misc.c kern/parser.c \ grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c \ lib/arg.c normal/cmdline.c normal/command.c normal/function.c \ normal/completion.c normal/context.c normal/main.c \ @@ -85,7 +85,7 @@ pkglib_MODULES = kernel.mod normal.mod chain.mod appleldr.mod \ 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 \ diff --git a/conf/i386-ieee1275.rmk b/conf/i386-ieee1275.rmk index dbcbb4a..144ff66 100644 --- a/conf/i386-ieee1275.rmk +++ b/conf/i386-ieee1275.rmk @@ -17,7 +17,7 @@ kernel_elf_SOURCES = kern/i386/ieee1275/startup.S kern/i386/ieee1275/init.c \ 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 kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ @@ -73,7 +73,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ kern/err.c kern/list.c kern/handler.c \ kern/command.c kern/corecmd.c commands/extcmd.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 \ + commands/boot.c kern/main.c kern/misc.c kern/parser.c \ grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c \ lib/arg.c normal/cmdline.c normal/command.c normal/function.c\ normal/completion.c normal/main.c normal/menu_text.c \ diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index cc845ed..fae505b 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -41,7 +41,7 @@ cdboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,7C00 # 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/list.c kern/handler.c kern/command.c kern/corecmd.c \ kern/i386/dl.c kern/i386/pc/init.c kern/i386/pc/mmap.c \ kern/parser.c kern/partition.c \ @@ -126,7 +126,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ kern/err.c kern/list.c kern/handler.c \ kern/command.c kern/corecmd.c commands/extcmd.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 \ + commands/boot.c kern/main.c kern/misc.c kern/parser.c \ grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c \ lib/arg.c normal/cmdline.c normal/command.c normal/function.c \ normal/completion.c normal/main.c normal/color.c \ diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index 5aaaf56..825341a 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -52,7 +52,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ \ 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 commands/boot.c kern/main.c \ kern/misc.c kern/parser.c kern/partition.c kern/rescue.c \ kern/term.c kern/list.c kern/handler.c fs/fshelp.c \ kern/command.c kern/corecmd.c commands/extcmd.c \ @@ -78,7 +78,7 @@ grub_emu_LDFLAGS = $(LIBCURSES) 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/list.c kern/handler.c kern/command.c kern/corecmd.c \ kern/ieee1275/init.c \ kern/ieee1275/mmap.c \ diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index 1658a66..66eaae6 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -53,7 +53,7 @@ grub_mkimage_SOURCES = util/sparc64/ieee1275/grub-mkimage.c util/misc.c \ # 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 commands/boot.c kern/main.c kern/misc.c \ # kern/parser.c kern/partition.c kern/rescue.c kern/term.c \ # kern/list.c kern/handler.c \ # normal/arg.c normal/cmdline.c normal/command.c \ @@ -72,7 +72,7 @@ grub_emu_LDFLAGS = $(LIBCURSES) 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 \ diff --git a/conf/x86_64-efi.rmk b/conf/x86_64-efi.rmk index faa59fb..37d983f 100644 --- a/conf/x86_64-efi.rmk +++ b/conf/x86_64-efi.rmk @@ -52,7 +52,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ kern/err.c kern/list.c kern/handler.c \ kern/command.c kern/corecmd.c commands/extcmd.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 \ + commands/boot.c kern/main.c kern/misc.c kern/parser.c \ grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c \ lib/arg.c normal/cmdline.c normal/command.c normal/function.c\ normal/completion.c normal/context.c normal/main.c \ @@ -88,7 +88,7 @@ kernel_mod_EXPORTS = no 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 kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ diff --git a/include/grub/kernel.h b/include/grub/kernel.h index adaee58..74aca40 100644 --- a/include/grub/kernel.h +++ b/include/grub/kernel.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2002,2005,2006,2007,2008,2009 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 @@ -64,7 +64,7 @@ void grub_main (void); 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); diff --git a/include/grub/loader.h b/include/grub/loader.h index 1ae5fdd..185d297 100644 --- a/include/grub/loader.h +++ b/include/grub/loader.h @@ -1,7 +1,7 @@ /* loader.h - OS loaders */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2004,2006,2007 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2004,2006,2007,2009 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 @@ -26,19 +26,19 @@ #include /* 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), - grub_err_t (*unload) (void), - int noreturn); +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); +grub_err_t grub_loader_boot (void); #endif /* ! GRUB_LOADER_HEADER */ diff --git a/kern/loader.c b/kern/loader.c deleted file mode 100644 index 2b67d49..0000000 --- a/kern/loader.c +++ /dev/null @@ -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 . - */ - -#include -#include -#include -#include -#include - -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) (); -} -