[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Move kern/loader.c to boot.mod and add preboot_support (was Re:
From: |
phcoder |
Subject: |
[PATCH] Move kern/loader.c to boot.mod and add preboot_support (was Re: Sendkey patch) |
Date: |
Fri, 05 Sep 2008 18:13:35 +0200 |
User-agent: |
Thunderbird 2.0.0.16 (X11/20080724) |
Hello. As I said in another email there is no need for it. I send a
patch for it.
Vladimir 'phcoder' Serbinenko
Javier Martín wrote:
> El mié, 03-09-2008 a las 20:53 +0300, Vesa Jääskeläinen escribió:
>> phcoder wrote:
>>> Hello. In this case we can transfer the whole functionality located in
>>> kern/loader.c to a dedicated module boot.mod. This module will also
>>> register "boot" command. In this way the encapsulation won't be broken
>>> and kernel will become even smaller.
>> Remember that realmode code needs to reside below < 1 MiB. That is the
>> reason realmode code is embedded in kernel. In there you only see jumps
>> to RM and back to PM.
> We could use the relocator functionality that was once discussed here (I
> don't know if it was finally committed) so that modules could declare
> "bundles" of code+data to be deployed to RM area. Or make sure every
> single instruction in there uses 32-bit addressing, together with
> artificial EIP-relativization of addresses like in drivemap_int13.S
>
> -Habbit
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Grub-devel mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/grub-devel
Index: conf/common.rmk
===================================================================
--- conf/common.rmk (revision 1845)
+++ conf/common.rmk (working copy)
@@ -311,7 +311,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 font.mod search.mod \
loopback.mod fs_uuid.mod configfile.mod echo.mod \
terminfo.mod test.mod blocklist.mod hexdump.mod \
@@ -322,8 +322,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 1845)
+++ 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 \
@@ -113,11 +113,11 @@
# 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 \
- lib/hexdump.c commands/i386/pc/halt.c commands/reboot.c \
+ lib/hexdump.c commands/i386/pc/halt.c commands/reboot.c
\
commands/i386/cpuid.c \
disk/host.c disk/loopback.c \
fs/fshelp.c \
@@ -126,7 +126,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: kern/loader.c
===================================================================
--- kern/loader.c (revision 1845)
+++ 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 1845)
+++ 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 1845)
+++ 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 1845)
+++ 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: commands/boot.c
===================================================================
--- commands/boot.c (revision 1845)
+++ 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");
+}
- Re: Sendkey patch, (continued)
- Re: Sendkey patch, Javier Martín, 2008/09/03
- Re: Sendkey patch, bitbucket, 2008/09/03
- Re: Sendkey patch, Felix Zielcke, 2008/09/03
- Re: Sendkey patch, Vesa Jääskeläinen, 2008/09/03
- Re: Sendkey patch, Javier Martín, 2008/09/03
- Re: Sendkey patch, Felix Zielcke, 2008/09/03
- Re: Sendkey patch, phcoder, 2008/09/03
- Re: Sendkey patch, Vesa Jääskeläinen, 2008/09/03
- Re: Sendkey patch, phcoder, 2008/09/03
- Re: Sendkey patch, Javier Martín, 2008/09/04
- [PATCH] Move kern/loader.c to boot.mod and add preboot_support (was Re: Sendkey patch),
phcoder <=
- Re: [PATCH] Move kern/loader.c to boot.mod and add preboot_support (was Re: Sendkey patch), Javier Martín, 2008/09/05
- Re: [PATCH] Move kern/loader.c to boot.mod and add preboot_support (was Re: Sendkey patch), Vesa Jääskeläinen, 2008/09/08
- Re: [PATCH] Move kern/loader.c to boot.mod and add preboot_support (was Re: Sendkey patch), Javier Martín, 2008/09/08
- Re: [PATCH] Move kern/loader.c to boot.mod and add preboot_support (was Re: Sendkey patch), Vesa Jääskeläinen, 2008/09/08
- Re: [PATCH] Move kern/loader.c to boot.mod and add preboot_support (was Re: Sendkey patch), Javier Martín, 2008/09/08