Skip to contentSkip to conversation

Sendkey patch

PATCH In review phcoder 6 participants 37 messages Sep 2, 2008 – Feb 7, 2009

lore
Share & tools
lore

phcoder

author
#0 lore raw

Hello. I wrote a patch to add sendkey functionality to grub2. After loading sendkey module some new environments variables appear with which one may control the sequence of keys that would be sent to OS or next bootloader. This functionality is useful in different cases. One example
is entering "safe mode" in some OS when without this feature you
desperately try many times to press "magic key" in exactly good moment. Another usage example is chainloading another bootloader. Then you can send someting like "down down enter" to it and avoid another delay. The implementation as environment variables has its downside as I don't know where to put help about it. Perhaps possibility of adding help notice to environment variables would be a good idea. Then we could do like

Quoted 1 line

help root

root is a variable containing root device.
For implementing this functionality I needed my function to be executed right before booting. To do it I added a simple interface for adding "preboot" functions:
struct grub_preboot_t *grub_loader_add_preboot (grub_err_t (*preboot_func) (int));
As parameter this function recieves a callback (integer parameter to callback is noreturn variable). This function returns a handle with which the preboot function may be removed using
void grub_loader_remove_preboot (struct grub_preboot_t *p); Implementation uses linked lists and tries to implement it in as few commands as possible since this code is a part of core image. This interface can later be reused for adding different hooks to bios ("map", "memdisk",...). Now the questions are:
Whether such interface is OK for grub2?
Whether we need also interface for adding "postboot" commands? (in case boot_function returns)
Variables made available after loading sendkey module:
sendkey - a space-separated list of keys to be sent
kb_num, kb_caps, kb_scroll, kb_insert, kb_wait - [keep|on|off] - set numlock, capslock, scrollock, insert or wait state
kb_noled - [0|1] When set to 1 the LED state is not changed to match num-/caps-/scrolllock state
"kb_lshift", "kb_rshift", "kb_sysreq", "kb_numkey", "kb_capskey", "kb_scrollkey", "kb_insertkey", "kb_lalt", "kb_ralt", "kb_lctrl", "kb_rctrl" - [keep|on|off] When set to on emulate pressing and holding of corresponding key. To undo just press the corresponding key on your keyboard

Regards
Vladimir Serbinenko

i386-pc.rmk +7 -2
Index: conf/i386-pc.rmk
===================================================================
@@ -117,7 +117,7 @@
 	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 	\
@@ -161,7 +161,7 @@
 
 # Modules.
 pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \
-	_multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod	\
+	_multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod sendkey.mod	\
 	vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \
 	videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod	\
 	ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \
@@ -214,6 +214,11 @@
 halt_mod_CFLAGS = $(COMMON_CFLAGS)
 halt_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For sendkey.mod.
+sendkey_mod_SOURCES = commands/i386/pc/sendkey.c
+sendkey_mod_CFLAGS = $(COMMON_CFLAGS)
+sendkey_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 # For serial.mod.
 serial_mod_SOURCES = term/i386/pc/serial.c
 serial_mod_CFLAGS = $(COMMON_CFLAGS)
i386-pc.mk +59 -2

79 lines not on this page · raw message

loader.c +37 -0
Index: kern/loader.c
===================================================================
@@ -22,12 +22,41 @@
 #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;
 
+static struct grub_preboot_t *grub_loader_preboots=0;
+
+struct grub_preboot_t *
+grub_loader_add_preboot (grub_err_t (*preboot_func) (int))
+{
+  struct grub_preboot_t **cur=&grub_loader_preboots;
+  if (!preboot_func)
+    return 0;
+  while (*cur)    
+    cur=&((*cur)->next);
+  *cur=(struct grub_preboot_t *)grub_malloc (sizeof (struct grub_preboot_t));
+  (*cur)->prev_pointer=cur;
+  (*cur)->next=0;
+  (*cur)->preboot_func=preboot_func;
+  return *cur;
+}
+
+void
+grub_loader_remove_preboot (struct grub_preboot_t *p)
+{
+  if (!p)
+    return;
+  *(p->prev_pointer)=p->next;
+  if (p->next)
+    (p->next)->prev_pointer=p->prev_pointer;
+  grub_free (p);
+}
+
 int
 grub_loader_is_loaded (void)
 {
@@ -64,11 +93,19 @@
 grub_err_t
 grub_loader_boot (void)
 {
+  struct grub_preboot_t *iter=grub_loader_preboots;
   if (! grub_loader_loaded)
     return grub_error (GRUB_ERR_NO_KERNEL, "no loaded kernel");
 
   if (grub_loader_noreturn)
     grub_machine_fini ();
+
+  while (iter)
+    {
+      if (iter->preboot_func)
+	iter->preboot_func (grub_loader_noreturn);
+      iter=iter->next;
+    }
   
   return (grub_loader_boot_func) ();
 }
grub/loader.h +14 -0
Index: include/grub/loader.h
===================================================================
@@ -25,6 +25,14 @@
 #include <grub/err.h>
 #include <grub/types.h>
 
+struct grub_preboot_t
+{
+  grub_err_t (*preboot_func) (int);  
+  struct grub_preboot_t *next;
+  struct grub_preboot_t **prev_pointer;
+};
+
+
 /* Check if a loader is loaded.  */
 int EXPORT_FUNC(grub_loader_is_loaded) (void);
 
@@ -37,6 +45,12 @@
 /* Unset current loader, if any.  */
 void EXPORT_FUNC(grub_loader_unset) (void);
 
+/*Add a preboot function*/
+struct grub_preboot_t *EXPORT_FUNC(grub_loader_add_preboot) (grub_err_t (*preboot_func) (int noreturn));
+
+/*Remove given preboot function*/
+void EXPORT_FUNC(grub_loader_remove_preboot) (struct grub_preboot_t *p);
+
 /* 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);
i386/pc/sendkey.c +392 -0

392 lines not on this page · raw message

#1 lore raw
Quoted 6 lines · phcoder

For implementing this functionality I needed my function to be executed right before booting. To do it I added a simple interface for adding "preboot" functions:
struct grub_preboot_t *grub_loader_add_preboot (grub_err_t (*preboot_func) (int));
As parameter this function recieves a callback (integer parameter to

Quoted 8 lines

callback is noreturn variable). This function returns a handle with which the preboot function may be removed using
void grub_loader_remove_preboot (struct grub_preboot_t *p); Implementation uses linked lists and tries to implement it in as few commands as possible since this code is a part of core image. This interface can later be reused for adding different hooks to bios ("map", "memdisk",...). Now the questions are:
Whether such interface is OK for grub2?

An interface like this is implemented in another patch in "discussion", my drivemap patch (see the August list archives). As yours, it is linked-list based and very similar in the prototypes. I haven't checked if your code has any kind of errors/corner cases, but it seems terser than mine even though it's a bit more difficult to understand because you use double pointers to avoid my handling of the head case. I don't understand the purpose of doubly-linking the list though...

Quoted 2 lines

Whether we need also interface for adding "postboot" commands? (in case boot_function returns)

I don't think it would offer a lot of functionality because most loaders don't return on failure, they just get stuck or their payload triple-faults and reboots. The same question applies for the failure of one of the preboot routines. Sure, things like an INT13 handler are easy to remove and restore the old machine state, but I really think the best option here would be panic and offer to reboot.

-Habbit

author
#2 lore raw

Hello, again
I had a look at your patch. In some mail it was suggested that kernel patch should be split from module that uses it. So I resend the kernel part of my patch. Another question is whether we need some kind of abortion procedure (like in your patch) if a preboot hook fails.

Quoted 4 lines · Javier Martín

An interface like this is implemented in another patch in "discussion", my drivemap patch (see the August list archives). As yours, it is linked-list based and very similar in the prototypes. I haven't checked if your code has any kind of errors/corner cases,

I checked and found that I didn't check if grub_malloc succeeded

Quoted 5 lines

but it seems terser
than mine even though it's a bit more difficult to understand because you use double pointers to avoid my handling of the head case. I don't understand the purpose of doubly-linking the list though...

The goal is to avoid walking through list when deleting an entry from it.

Quoted 5 lines
Quoted 2 lines

Whether we need also interface for adding "postboot" commands? (in case boot_function returns)

I don't think it would offer a lot of functionality because most loaders don't return on failure, they just get stuck or their payload triple-faults and reboots.

It's the case for i386-pc loaders but not the case of some other targets (e.g. EFI). So the question remains.

Vladimir Serbinenko

author
#3 lore raw

Sorry, forgot to attach

Quoted 21 lines · phcoder

Hello, again
I had a look at your patch. In some mail it was suggested that kernel patch should be split from module that uses it. So I resend the kernel part of my patch. Another question is whether we need some kind of abortion procedure (like in your patch) if a preboot hook fails.

Quoted 4 lines · Javier Martín

An interface like this is implemented in another patch in "discussion", my drivemap patch (see the August list archives). As yours, it is linked-list based and very similar in the prototypes. I haven't checked if your code has any kind of errors/corner cases,

I checked and found that I didn't check if grub_malloc succeeded

Quoted 5 lines

but it seems terser
than mine even though it's a bit more difficult to understand because you use double pointers to avoid my handling of the head case. I don't understand the purpose of doubly-linking the list though...

The goal is to avoid walking through list when deleting an entry from it.

Quoted 2 lines
Quoted 2 lines

Whether we need also interface for adding "postboot" commands? (in case boot_function returns)

Quoted 8 lines
Quoted 3 lines

I don't think it would offer a lot of functionality because most loaders don't return on failure, they just get stuck or their payload triple-faults and reboots.

It's the case for i386-pc loaders but not the case of some other targets (e.g. EFI). So the question remains.

Vladimir Serbinenko

loader.c +42 -0
Index: kern/loader.c
===================================================================
@@ -22,12 +22,46 @@
 #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;
 
+static struct grub_preboot_t *grub_loader_preboots=0;
+
+struct grub_preboot_t *
+grub_loader_add_preboot (grub_err_t (*preboot_func) (int))
+{
+  struct grub_preboot_t **cur=&grub_loader_preboots;
+  if (!preboot_func)
+    return 0;
+  while (*cur)    
+    cur=&((*cur)->next);
+  *cur=(struct grub_preboot_t *)grub_malloc (sizeof (struct grub_preboot_t));
+  if (!*cur)
+    {
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, "hook not added");
+      return 0;
+    }
+  (*cur)->prev_pointer=cur;
+  (*cur)->next=0;
+  (*cur)->preboot_func=preboot_func;
+  return *cur;
+}
+
+void
+grub_loader_remove_preboot (struct grub_preboot_t *p)
+{
+  if (!p)
+    return;
+  *(p->prev_pointer)=p->next;
+  if (p->next)
+    (p->next)->prev_pointer=p->prev_pointer;
+  grub_free (p);
+}
+
 int
 grub_loader_is_loaded (void)
 {
@@ -64,11 +98,19 @@
 grub_err_t
 grub_loader_boot (void)
 {
+  struct grub_preboot_t *iter=grub_loader_preboots;
   if (! grub_loader_loaded)
     return grub_error (GRUB_ERR_NO_KERNEL, "no loaded kernel");
 
   if (grub_loader_noreturn)
     grub_machine_fini ();
+
+  while (iter)
+    {
+      if (iter->preboot_func)
+	iter->preboot_func (grub_loader_noreturn);
+      iter=iter->next;
+    }
   
   return (grub_loader_boot_func) ();
 }
grub/loader.h +14 -0
Index: include/grub/loader.h
===================================================================
@@ -25,6 +25,14 @@
 #include <grub/err.h>
 #include <grub/types.h>
 
+struct grub_preboot_t
+{
+  grub_err_t (*preboot_func) (int);  
+  struct grub_preboot_t *next;
+  struct grub_preboot_t **prev_pointer;
+};
+
+
 /* Check if a loader is loaded.  */
 int EXPORT_FUNC(grub_loader_is_loaded) (void);
 
@@ -37,6 +45,12 @@
 /* Unset current loader, if any.  */
 void EXPORT_FUNC(grub_loader_unset) (void);
 
+/*Add a preboot function*/
+struct grub_preboot_t *EXPORT_FUNC(grub_loader_add_preboot) (grub_err_t (*preboot_func) (int noreturn));
+
+/*Remove given preboot function*/
+void EXPORT_FUNC(grub_loader_remove_preboot) (struct grub_preboot_t *p);
+
 /* 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);
#4 lore raw
In reply to phcoder

Hi,

Now that we have two use cases for this. I would propose that we first fine tune interface and then use common one. This is the critical part of the design and needs to be solved. I wasn't really convinced with the other proposed interface.

So if you two could propose improved one that can handle following:

- BIOS interrupt service hooks
- drivemap
- eltorito emulation
- custom int13h handler for unsupported controllers
- custom GRUB code to be executed
- sendkey feature

This way it would be also easier to incorporate patches as there is already skeleton that can be used easily.

What we don't want is to increase kernel size too much. So please try to think alternatives that reside on loaded module. There might be some other options too, but I'll let you guys think a bit first :)

Thanks,
Vesa Jääskeläinen

author
#5 lore raw

Well the interface is as we described: the module gives a callback function which will be called before launching boot function. This interface is enough for both (and probaly many other) needs. The only problem is that callback functions can conflict with each other and with boot function. E.g. if callback sets an INT13h hook and then boot function reads harddrive then it could get wrong data. In my opinion the ese callback and boot functions shouldn't use device access at all. This is especially true because theese functions are after grub_machine_fini.

Quoted 4 lines

This way it would be also easier to incorporate patches as there is already skeleton that can be used easily.

There could several templates for using such feature because it's quite universal

Vladimir Serbinenko

#6 lore raw
Quoted 8 lines · phcoder

Well the interface is as we described: the module gives a callback function which will be called before launching boot function. This interface is enough for both (and probaly many other) needs. The only problem is that callback functions can conflict with each other and with boot function. E.g. if callback sets an INT13h hook and then boot function reads harddrive then it could get wrong data. In my opinion the ese callback and boot functions shouldn't use device access at all. This is especially true because theese functions are after grub_machine_fini.

That is more like a textual description of the issues not an interface description. It has to be more concrete than that. And mechanism should support hook installation. And I do not see reason why that same thing cannot support also this send key stuff.

Quoted 5 lines
Quoted 3 lines

This way it would be also easier to incorporate patches as there is already skeleton that can be used easily.

There could several templates for using such feature because it's quite universal

I am not really delighted about that... Just one or two connection points and that should be able to handle those cases. If not then we have something wrong somewhere...

#7 lore raw
In reply to phcoder
Quoted 6 lines · phcoder
Quoted 5 lines

but it seems terser
than mine even though it's a bit more difficult to understand because you use double pointers to avoid my handling of the head case. I don't understand the purpose of doubly-linking the list though...

The goal is to avoid walking through list when deleting an entry from it.

But you negate any performance gain when you _do_ traverse the list to add an entry to it instead of just make it the new head as I do. Besides, even for that, double indirection should be avoided in the structure previous pointer because it makes things oh-so-incredibly confusing.

Besides, I think the "user" (i.e. module) visible type returned by _add and taken by _remove should be a "blank hidden type", i.e. you don't need to declare "struct grub_preboot_t" in loader.h because the public interface only uses _pointers_ to it, whose size is known. This is all the C compiler requires and you avoid polluting the namespace with internal implementation details. I recommend the following typedefs:

typedef struct grub_preboot_t* grub_preboot_hnd; typedef grub_err_t *(grub_preboot_func)(int noreturn);

So that the prototypes would look

grub_preboot_hnd add(grub_preboot_func f);
void remove(grub_preboot_hnd handle);

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Whether we need also interface for adding "postboot" commands? (in case boot_function returns)

I don't think it would offer a lot of functionality because most loaders don't return on failure, they just get stuck or their payload triple-faults and reboots.

It's the case for i386-pc loaders but not the case of some other targets (e.g. EFI). So the question remains.

And same question for abortion procedures. This is a spinous matter because clean handling is difficult, not always possible and requires registering "undo" functions, i.e. more bloat in kernel.

-Habbit

author
#8 lore raw
Quoted 5 lines · Javier Martín

But you negate any performance gain when you _do_ traverse the list to add an entry to it instead of just make it the new head as I do. Besides, even for that, double indirection should be avoided in the structure previous pointer because it makes things oh-so-incredibly confusing.

I was thinking about code size then about performance or easy of understanding. On my system this code results in 91 addition bytes in core image (63 if I remove grub_error). Do you have any idea how it would be possible to do an error message without description or put some generic description?

Quoted 8 lines

Besides, I think the "user" (i.e. module) visible type returned by _add and taken by _remove should be a "blank hidden type", i.e. you don't need to declare "struct grub_preboot_t" in loader.h because the public interface only uses _pointers_ to it, whose size is known. This is all the C compiler requires and you avoid polluting the namespace with internal implementation details. I recommend the following typedefs:

Quoted 7 lines

typedef struct grub_preboot_t* grub_preboot_hnd; typedef grub_err_t *(grub_preboot_func)(int noreturn);

So that the prototypes would look

grub_preboot_hnd add(grub_preboot_func f);
void remove(grub_preboot_hnd handle);

I noticed that actually no code needs the size of grub_preoot_hnd. So I changed it to void *
Vladimir Serbinenko

loader.c +49 -1
Index: kern/loader.c
===================================================================
@@ -22,12 +22,54 @@
 #include <grub/err.h>
 #include <grub/kernel.h>
 
+#define PREBOOT_HND(x) (((struct grub_preboot_t *)x))
+
+struct grub_preboot_t
+{
+  grub_err_t (*preboot_func) (int);  
+  struct grub_preboot_t *next;
+  struct grub_preboot_t **prev_pointer;
+};
+
 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_preboot_t *grub_loader_preboots=0;
+
+void *
+grub_loader_add_preboot (grub_err_t (*preboot_func) (int))
+{
+  struct grub_preboot_t *cur;
+  if (!preboot_func)
+    return 0;
+  cur=(struct grub_preboot_t *)grub_malloc (sizeof (struct grub_preboot_t));
+  if (!cur)
+    {
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, "hook not added");
+      return 0;
+    }
+  cur->next=grub_loader_preboots;
+  cur->prev_pointer=0;
+  cur->next->prev_pointer=&(cur->next);
+  cur->preboot_func=preboot_func;
+  grub_loader_preboots=cur;
+  return cur;
+}
+
+void
+grub_loader_remove_preboot (void *p)
+{
+  if (!p)
+    return;
+  *(PREBOOT_HND(p)->prev_pointer)=PREBOOT_HND(p)->next;
+  if (PREBOOT_HND(p)->next)
+    PREBOOT_HND(p)->next->prev_pointer=PREBOOT_HND(p)->prev_pointer;
+    grub_free (p);
+}
+
 int
 grub_loader_is_loaded (void)
 {
@@ -64,12 +106,18 @@
 grub_err_t
 grub_loader_boot (void)
 {
+  struct grub_preboot_t *iter=grub_loader_preboots;
   if (! grub_loader_loaded)
     return grub_error (GRUB_ERR_NO_KERNEL, "no loaded kernel");
 
   if (grub_loader_noreturn)
     grub_machine_fini ();
-  
+  while (iter)
+    {
+      if (iter->preboot_func)
+	iter->preboot_func (grub_loader_noreturn);
+      iter=iter->next;
+    }
   return (grub_loader_boot_func) ();
 }
 
grub/loader.h +7 -0
Index: include/grub/loader.h
===================================================================
@@ -25,6 +25,7 @@
 #include <grub/err.h>
 #include <grub/types.h>
 
+
 /* Check if a loader is loaded.  */
 int EXPORT_FUNC(grub_loader_is_loaded) (void);
 
@@ -37,6 +38,12 @@
 /* Unset current loader, if any.  */
 void EXPORT_FUNC(grub_loader_unset) (void);
 
+/*Add a preboot function*/
+void *EXPORT_FUNC(grub_loader_add_preboot) (grub_err_t (*preboot_func) (int noreturn));
+
+/*Remove given preboot function*/
+void EXPORT_FUNC(grub_loader_remove_preboot) (void *hnd);
+
 /* 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);
#9 lore raw

Review

Quoted 6 lines · phcoder
(quoted diff) +6 -0
+void
+grub_loader_remove_preboot (void *p)
+{
+  if (!p)
+    return;
+  *(PREBOOT_HND(p)->prev_pointer)=PREBOOT_HND(p)->next;

This line will "crash" if p is the head of the list (with prev_pointer being 0). I quote crash because a crash is what happens under an OS:
under GRUB you just overwrite address 0x0 which in i386-pc is the start of the real mode IVT.

Review

Quoted 4 lines
(quoted diff) +4 -0
+  if (PREBOOT_HND(p)->next)
+    PREBOOT_HND(p)->next->prev_pointer=PREBOOT_HND(p)->prev_pointer;
+    grub_free (p);
+}

All these macro plays are nonsense and a hindrance to readability just because you did not want to add a local variable and do the cast once.

Here is my "version" of your patch, without the double indirection and the strange plays. The overhead is 103 bytes without the error line against 63 of yours, but I really think that the symmetric and understandable handling of previous and next is worth 40 bytes.

PS:

Quoted 1 line

+void *EXPORT_FUNC(grub_loader_add_preboot) (grub_err_t ...

I think that (only) in function declarations it's better to write "void* f()" than "void *f()" because otherwise the * can be easily overlooked. However, this is my word and does not come from the GCS.

loader.c +49 -1
Index: kern/loader.c
===================================================================
@@ -22,12 +22,54 @@
 #include <grub/err.h>
 #include <grub/kernel.h>
 
+struct grub_preboot_t
+{
+  grub_err_t (*preboot_func) (int);  
+  struct grub_preboot_t *next;
+  struct grub_preboot_t *previous;
+};
+
 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_preboot_t *grub_loader_preboots=0;
+
+void *
+grub_loader_add_preboot (grub_err_t (*preboot_func) (int))
+{
+  struct grub_preboot_t *cur;
+  if (!preboot_func)
+    return 0;
+  cur = (struct grub_preboot_t *) grub_malloc (sizeof (struct grub_preboot_t));
+  if (!cur)
+    {
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, "no memory left to register hook");
+      return 0;
+    }
+  cur->next = grub_loader_preboots;
+  cur->previous = 0;
+  cur->next->previous = cur;
+  cur->preboot_func = preboot_func;
+  grub_loader_preboots = cur;
+  return cur;
+}
+
+void
+grub_loader_remove_preboot (void *p)
+{
+  struct grub_preboot_t *hnd = (struct grub_preboot_t *)p;
+  if (!hnd)
+    return;
+  if (hnd->previous)
+    hnd->previous->next = hnd->next;
+  if (hnd->next)
+    hnd->next->previous = hnd->previous;
+  grub_free (hnd);
+}
+
 int
 grub_loader_is_loaded (void)
 {
@@ -64,12 +106,18 @@
 grub_err_t
 grub_loader_boot (void)
 {
+  struct grub_preboot_t *iter=grub_loader_preboots;
   if (! grub_loader_loaded)
     return grub_error (GRUB_ERR_NO_KERNEL, "no loaded kernel");
 
   if (grub_loader_noreturn)
     grub_machine_fini ();
-  
+  while (iter)
+    {
+      if (iter->preboot_func)
+	iter->preboot_func (grub_loader_noreturn);
+      iter=iter->next;
+    }
   return (grub_loader_boot_func) ();
 }
 
grub/loader.h +8 -0
Index: include/grub/loader.h
===================================================================
@@ -25,6 +25,8 @@
 #include <grub/err.h>
 #include <grub/types.h>
 
+typedef grub_err_t (*grub_preboot_func) (int noreturn);
+
 /* Check if a loader is loaded.  */
 int EXPORT_FUNC(grub_loader_is_loaded) (void);
 
@@ -37,6 +39,12 @@
 /* Unset current loader, if any.  */
 void EXPORT_FUNC(grub_loader_unset) (void);
 
+/*Add a preboot function*/
+void* EXPORT_FUNC(grub_loader_add_preboot) (grub_preboot_func func);
+
+/*Remove given preboot function*/
+void EXPORT_FUNC(grub_loader_remove_preboot) (void *hnd);
+
 /* 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);
author
#10 lore raw
Quoted 11 lines · Javier Martín

Review

Quoted 6 lines · phcoder
(quoted diff) +6 -0
+void
+grub_loader_remove_preboot (void *p)
+{
+  if (!p)
+    return;
+  *(PREBOOT_HND(p)->prev_pointer)=PREBOOT_HND(p)->next;

This line will "crash" if p is the head of the list (with prev_pointer being 0). I quote crash because a crash is what happens under an OS:
under GRUB you just overwrite address 0x0 which in i386-pc is the start of the real mode IVT.

Thank you for pointing at this mistake. Corrected. I should really go to bed now.

Quoted 5 lines

Review

Quoted 5 lines
(quoted diff) +4 -0
+  if (PREBOOT_HND(p)->next)
+    PREBOOT_HND(p)->next->prev_pointer=PREBOOT_HND(p)->prev_pointer;
+    grub_free (p);
+}
Quoted 8 lines

All these macro plays are nonsense and a hindrance to readability just because you did not want to add a local variable and do the cast once.

Here is my "version" of your patch, without the double indirection and the strange plays. The overhead is 103 bytes without the error line against 63 of yours, but I really think that the symmetric and understandable handling of previous and next is worth 40 bytes.

Well let's summ up what we have:
-my version in 63 bytes but difficult to read (could some comments help with it?)
-your version much easier to read but in 103 bytes
Neither of versions is right or wrong. It's a question of priorities. I had some experiences that past some point it's difficult to decrease size past some point. Core image has to be embed in first cylinder. There we have 62 sectors=31744 bytes. And now our core image (my version with error reporting) with ata,pc and reiserfs is 29654 bytes. This leaves us 2090 bytes. This combination is not something completely out of the ordinary. So I suggest to give the priority to the size of the kernel over readability (perhaps adding some comments to my version).

Quoted 6 lines

PS:

Quoted 1 line

+void *EXPORT_FUNC(grub_loader_add_preboot) (grub_err_t ...

I think that (only) in function declarations it's better to write "void* f()" than "void *f()" because otherwise the * can be easily overlooked. However, this is my word and does not come from the GCS.

I've just made the same that I see in include/grub/mm.h . But for me it doesn't really matter
Vladimir Serbinenko

loader.c +49 -1
Index: kern/loader.c
===================================================================
@@ -22,12 +22,54 @@
 #include <grub/err.h>
 #include <grub/kernel.h>
 
+#define PREBOOT_HND(x) (((struct grub_preboot_t *)x))
+
+struct grub_preboot_t
+{
+  grub_err_t (*preboot_func) (int);  
+  struct grub_preboot_t *next;
+  struct grub_preboot_t **prev_pointer;
+};
+
 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_preboot_t *grub_loader_preboots=0;
+
+void *
+grub_loader_add_preboot (grub_err_t (*preboot_func) (int))
+{
+  struct grub_preboot_t *cur;
+  if (!preboot_func)
+    return 0;
+  cur=(struct grub_preboot_t *)grub_malloc (sizeof (struct grub_preboot_t));
+  if (!cur)
+    {
+      grub_error (GRUB_ERR_OUT_OF_MEMORY, "hook not added");
+      return 0;
+    }
+  cur->next=grub_loader_preboots;
+  cur->prev_pointer=&grub_loader_preboots;
+  cur->next->prev_pointer=&(cur->next);
+  cur->preboot_func=preboot_func;
+  grub_loader_preboots=cur;
+  return cur;
+}
+
+void
+grub_loader_remove_preboot (void *p)
+{
+  if (!p)
+    return;
+  *(PREBOOT_HND(p)->prev_pointer)=PREBOOT_HND(p)->next;
+  if (PREBOOT_HND(p)->next)
+    PREBOOT_HND(p)->next->prev_pointer=PREBOOT_HND(p)->prev_pointer;
+    grub_free (p);
+}
+
 int
 grub_loader_is_loaded (void)
 {
@@ -64,12 +106,18 @@
 grub_err_t
 grub_loader_boot (void)
 {
+  struct grub_preboot_t *iter=grub_loader_preboots;
   if (! grub_loader_loaded)
     return grub_error (GRUB_ERR_NO_KERNEL, "no loaded kernel");
 
   if (grub_loader_noreturn)
     grub_machine_fini ();
-  
+  while (iter)
+    {
+      if (iter->preboot_func)
+	iter->preboot_func (grub_loader_noreturn);
+      iter=iter->next;
+    }
   return (grub_loader_boot_func) ();
 }
 
grub/loader.h +7 -0
Index: include/grub/loader.h
===================================================================
@@ -25,6 +25,7 @@
 #include <grub/err.h>
 #include <grub/types.h>
 
+
 /* Check if a loader is loaded.  */
 int EXPORT_FUNC(grub_loader_is_loaded) (void);
 
@@ -37,6 +38,12 @@
 /* Unset current loader, if any.  */
 void EXPORT_FUNC(grub_loader_unset) (void);
 
+/*Add a preboot function*/
+void *EXPORT_FUNC(grub_loader_add_preboot) (grub_err_t (*preboot_func) (int noreturn));
+
+/*Remove given preboot function*/
+void EXPORT_FUNC(grub_loader_remove_preboot) (void *hnd);
+
 /* 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);
#11 lore raw
Quoted 5 lines · phcoder
Quoted 5 lines

Here is my "version" of your patch, without the double indirection and the strange plays. The overhead is 103 bytes without the error line against 63 of yours, but I really think that the symmetric and understandable handling of previous and next is worth 40 bytes.

Quoted 8 lines

Well let's summ up what we have:
-my version in 63 bytes but difficult to read (could some comments help with it?)
-your version much easier to read but in 103 bytes
Neither of versions is right or wrong. It's a question of priorities. I had some experiences that past some point it's difficult to decrease size past some point. Core image has to be embed in first cylinder. There we have 62 sectors=31744 bytes.

We have 63 sectors = 32256 bytes (sectors range from 0 to 63 and the first is used by the MBR).

Quoted 5 lines

And now our core image (my version
with error reporting) with ata,pc and reiserfs is 29654 bytes. This leaves us 2090 bytes. This combination is not something completely out of the ordinary. So I suggest to give the priority to the size of the kernel over readability (perhaps adding some comments to my version).

I was wondering why my data did not match yours, and then I realized I was using my usual "extreme" combination of modules: "biosdisk pc ext2 lvm raid" yields 29298 bytes, "plenty" of space. But ata and reiserfs are quite the bloaters... The reiserfs case is particularly strange: in the linux kernel, the reiserfs module is 50% bigger than ext3.ko; while in GRUB, reiserfs.mod (without journaling) is twice the size of ext2.mod (which includes full support for ext2, partial journal support in ext3 and extents in ext4).

Thus, while you are right in prioritizing kernel size; why not optimize reiserfs a bit instead of killing our (and future maintainers') eyes and brains to shave less than 40 bytes from kernel? I suppose the story would be similar with ata, because it is a new module that is yet in development.

-Habbit

author
#12 lore raw

Hello, again.

Quoted 3 lines · Javier Martín

We have 63 sectors = 32256 bytes (sectors range from 0 to 63 and the first is used by the MBR).

I've just rechecked on my system. My first partition begins at sector number 63. This is the value I've seen at most systems. So last usable sector is 62. Sector 0 is MBR. So we have 62 sectors

Quoted 5 lines
Quoted 5 lines

And now our core image (my version
with error reporting) with ata,pc and reiserfs is 29654 bytes. This leaves us 2090 bytes. This combination is not something completely out of the ordinary. So I suggest to give the priority to the size of the kernel over readability (perhaps adding some comments to my version).

Quoted 9 lines

I was wondering why my data did not match yours, and then I realized I was using my usual "extreme" combination of modules: "biosdisk pc ext2 lvm raid" yields 29298 bytes, "plenty" of space. But ata and reiserfs are quite the bloaters... The reiserfs case is particularly strange: in the linux kernel, the reiserfs module is 50% bigger than ext3.ko; while in GRUB, reiserfs.mod (without journaling) is twice the size of ext2.mod (which includes full support for ext2, partial journal support in ext3 and extents in ext4).

I'll have a look at it but not sure to find anything since I'm not familiar with either ata or reiserfs internal structure.

Quoted 5 lines

Thus, while you are right in prioritizing kernel size; why not optimize reiserfs a bit instead of killing our (and future maintainers') eyes and brains to shave less than 40 bytes from kernel? I suppose the story would be similar with ata, because it is a new module that is yet in development.

Well the point is that if we don't do it now and then one day we'll have to squeeze the core it will be very difficult to find places like this.

Quoted 3 lines

-Habbit

Vladimir 'phcoder' Serbinenko

#13 lore raw
Quoted 8 lines · phcoder

Hello, again.

Quoted 3 lines · Javier Martín

We have 63 sectors = 32256 bytes (sectors range from 0 to 63 and the first is used by the MBR).

I've just rechecked on my system. My first partition begins at sector number 63. This is the value I've seen at most systems. So last usable sector is 62. Sector 0 is MBR. So we have 62 sectors

Oops, true! How strange. So there was no sector 63 in the CHS model and that is why the first sector of cyl 1 (the start of the first partition) is LBA 63... Does anyone know the historical reasons for this?

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines

And now our core image (my version
with error reporting) with ata,pc and reiserfs is 29654 bytes. This leaves us 2090 bytes. This combination is not something completely out of the ordinary. So I suggest to give the priority to the size of the kernel over readability (perhaps adding some comments to my version).

Quoted 9 lines

I was wondering why my data did not match yours, and then I realized I was using my usual "extreme" combination of modules: "biosdisk pc ext2 lvm raid" yields 29298 bytes, "plenty" of space. But ata and reiserfs are quite the bloaters... The reiserfs case is particularly strange: in the linux kernel, the reiserfs module is 50% bigger than ext3.ko; while in GRUB, reiserfs.mod (without journaling) is twice the size of ext2.mod (which includes full support for ext2, partial journal support in ext3 and extents in ext4).

Quoted 2 lines

I'll have a look at it but not sure to find anything since I'm not familiar with either ata or reiserfs internal structure.

I was not suggesting that it was you or me who did it; it was a general "call" for GRUB devs... (ahem xD)

Quoted 7 lines
Quoted 5 lines

Thus, while you are right in prioritizing kernel size; why not optimize reiserfs a bit instead of killing our (and future maintainers') eyes and brains to shave less than 40 bytes from kernel? I suppose the story would be similar with ata, because it is a new module that is yet in development.

Well the point is that if we don't do it now and then one day we'll have to squeeze the core it will be very difficult to find places like this.

Yes, but my point is that 40 bytes is so small a difference that it can offset by simply rewriting error strings in kernel and other smallish non-intrusive changes and thus we should prioritize future maintainability. However, eventually this is not our decision to make:
the Overlords here (mainly Marco, but also Robert, Vesa and Bean) are the ones who should, likely only once the interface is established, decide how to conjugate the Prime Directive of "keep kernel small" with code complexity in this particular case.

-Habbit

author
#14 lore raw
Quoted 6 lines · Javier Martín
Quoted 5 lines · phcoder

Hello, again.

Quoted 3 lines · Javier Martín

We have 63 sectors = 32256 bytes (sectors range from 0 to 63 and the first is used by the MBR).

Quoted 7 lines
Quoted 3 lines

I've just rechecked on my system. My first partition begins at sector number 63. This is the value I've seen at most systems. So last usable sector is 62. Sector 0 is MBR. So we have 62 sectors

Oops, true! How strange. So there was no sector 63 in the CHS model and that is why the first sector of cyl 1 (the start of the first partition) is LBA 63... Does anyone know the historical reasons for this?

int 0x13:0x08 can't return more than 63 sectors per track.
http://en.wikipedia.org/wiki/Int_13h#INT_13h_AH.3D08h:_Read_Drive_Parameters

Quoted 5 lines
Quoted 2 lines

I'll have a look at it but not sure to find anything since I'm not familiar with either ata or reiserfs internal structure.

I was not suggesting that it was you or me who did it; it was a general "call" for GRUB devs... (ahem xD)

I understand. I was saying that I'll just have a look at least to know what I'm talking about. But even if we manage to decrease the size of reiserfs module there are still other FS which could result in big modules e.g. ZFS.

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

Thus, while you are right in prioritizing kernel size; why not optimize reiserfs a bit instead of killing our (and future maintainers') eyes and brains to shave less than 40 bytes from kernel? I suppose the story would be similar with ata, because it is a new module that is yet in development.

Well the point is that if we don't do it now and then one day we'll have to squeeze the core it will be very difficult to find places like this.

Yes, but my point is that 40 bytes is so small a difference

40 bytes are small but 40 bytes per small interface is a big difference

Quoted 9 lines

that it can
offset by simply rewriting error strings in kernel and other smallish non-intrusive changes and thus we should prioritize future maintainability. However, eventually this is not our decision to make:
the Overlords here (mainly Marco, but also Robert, Vesa and Bean) are the ones who should, likely only once the interface is established, decide how to conjugate the Prime Directive of "keep kernel small" with code complexity in this particular case.

You have the point. But if we don't discuss this matter the choice made by maintainers can be random.

Quoted 1 line

-Habbit

Vladimir 'phcoder' Serbinenko

#15 lore raw

Hi again,

Quoted 9 lines · phcoder
Quoted 5 lines
Quoted 2 lines

I'll have a look at it but not sure to find anything since I'm not familiar with either ata or reiserfs internal structure.

I was not suggesting that it was you or me who did it; it was a general "call" for GRUB devs... (ahem xD)

I understand. I was saying that I'll just have a look at least to know what I'm talking about. But even if we manage to decrease the size of reiserfs module there are still other FS which could result in big modules e.g. ZFS.

Of course, but even though we should strive to support te widest module configurations possible, GRUB is no panacea. Even when an initialized GRUB could cope with a ZFS partition in a LVM+RAID on SATA drives not supported by the BIOS, one should not really expect to be able to boot directly off it - get a simpler boot scheme, man! extN, FAT or even SFS are way simpler filesystems which should be used for boot partitions. More complex filesystems such as ReiserFS or NTFS require _less_ complex schemes such as no LVM+RAID in order to keep the total core size manageable.

#16 lore raw
In reply to Javier Martín
Quoted 7 lines · Javier Martín
Quoted 6 lines · phcoder

Hello, again.

Quoted 2 lines · Javier Martín

We have 63 sectors = 32256 bytes (sectors range from 0 to 63 and the first is used by the MBR).

Quoted 7 lines
Quoted 3 lines

I've just rechecked on my system. My first partition begins at sector number 63. This is the value I've seen at most systems. So last usable sector is 62. Sector 0 is MBR. So we have 62 sectors

Oops, true! How strange. So there was no sector 63 in the CHS model and that is why the first sector of cyl 1 (the start of the first partition) is LBA 63... Does anyone know the historical reasons for this?

Well, the point is, in CHS addressing sector numbering starts with 1, not 0, and since there are only 6 bits available for the sector number (the other 2 being used for cylinder number bits #8 and #9), the maximum number of sectors per track in CHS in 63.

Regards,
Niels

#17 lore raw
In reply to Javier Martín

Am Mittwoch, den 03.09.2008, 01:38 +0200 schrieb Javier Martín:

Quoted 6 lines

But ata and reiserfs
are quite the bloaters... The reiserfs case is particularly strange: in the linux kernel, the reiserfs module is 50% bigger than ext3.ko; while in GRUB, reiserfs.mod (without journaling) is twice the size of ext2.mod (which includes full support for ext2, partial journal support in ext3 and extents in ext4).

ata.mod needs work anyway to be ready to end up in core.img fs/ext2.c doestn't support the journaling at all.
The code was reverted, just not 100% complete.
The structures are still defined but not used, just use your favourite editor and search for `journal'.
But comparing the size difference between ext2.ko and reiserfs.ko (or however exactly it's called, I used it ages ago last)
with the size difference of grub2's ext2.mod and reiserfs.mod is probable like apples and oranges.
Kernel has full support for everything, wheres grub2 only needs small read support.

Quoted 5 lines

Thus, while you are right in prioritizing kernel size; why not optimize reiserfs a bit instead of killing our (and future maintainers') eyes and brains to shave less than 40 bytes from kernel? I suppose the story would be similar with ata, because it is a new module that is yet in development.

If you can reduce the size of the modules, without making the code ugly then feel free to do so, but please keep things consistently to the current commited code.
If you want to introduce new ideas/concepts then I suggest you do a [RFC] topic on the list to discuss it first.

Signature · 1 line
Felix Zielcke
#18 lore raw
In reply to Javier Martín

Hi,

How about following (may not be syntaxically correct):

In kernel:

/* Variable holding pointer to preboot hook function. */ preboot_hook:

	.long	0

...

	/* Check if there is preboot hook installed.  */
	movl	preboot_hook, %eax
	testl	%eax, %eax
	jne	1f
	call	%eax
1:
	/* Continue boot.  */

Then in module code:

void grub_preboot_hook_handler(void)

{
	/* Process list of registered preboot hooks.  */
}

void grub_preboot_register_hook(...);
void grub_preboot_unregister_hook(...);

GRUB_MOD_INIT(preboot)

{
	preboot_hook = grub_preboot_hook_handler;
}

GRUB_MOD_FINI(preboot)

{
	preboot_hook = 0;
}

If preboot.mod gets loaded then it goes and registers preboot handler to kernel to do its tricks. Other modules then would use preboot.mod to register their own handlers.

This would have minimal impact for kernel.

Thanks,
Vesa Jääskeläinen

#19 lore raw
Quoted 35 lines · Vesa Jääskeläinen

Hi,

How about following (may not be syntaxically correct):

In kernel:

/* Variable holding pointer to preboot hook function. */ preboot_hook:

	.long	0

...

	/* Check if there is preboot hook installed.  */
	movl	preboot_hook, %eax
	testl	%eax, %eax
	jne	1f
	call	%eax
1:
	/* Continue boot.  */

Then in module code:

void grub_preboot_hook_handler(void)

{
	/* Process list of registered preboot hooks.  */
}

void grub_preboot_register_hook(...);
void grub_preboot_unregister_hook(...);

GRUB_MOD_INIT(preboot)

{
	preboot_hook = grub_preboot_hook_handler;
}
Quoted 8 lines

GRUB_MOD_FINI(preboot)

{
	preboot_hook = 0;
}

If preboot.mod gets loaded then it goes and registers preboot handler to kernel to do its tricks. Other modules then would use preboot.mod to register their own handlers.

This is certainly a good solution, and would probably add less than 10 bytes to the kernel. I only have to add two things:
* This is not as elegant as it could be, as it forces us to expose
preboot_hook in the kernel, thus breaking encapsulation a bit. But it is a price that I'm more than willing to pay.
* I doubt: is the current DL system in GRUB able to hand dependencies
directly? In other words, is our "insmod" more like modprobe or Linux insmod? This affects the handling of "insmod drivemap" or "insmod sendkey" if preboot.mod is not loaded beforehand.

-Habbit

#20 lore raw

Am Mittwoch, den 03.09.2008, 19:23 +0200 schrieb Javier Martín:

Quoted 4 lines

* I doubt: is the current DL system in GRUB able to hand dependencies
directly? In other words, is our "insmod" more like modprobe or Linux insmod? This affects the handling of "insmod drivemap" or "insmod sendkey" if preboot.mod is not loaded beforehand.

Urm /boot/grub/moddep.lst ?
I think grub2 is able to handle module dependencys. Though I haven't bothered to check the code ;)

Signature · 1 line
Felix Zielcke
author
#21 lore raw
In reply to Vesa Jääskeläinen

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.
Vladimir 'phcoder' Serbinenko

Quoted 54 lines · Vesa Jääskeläinen

Hi,

How about following (may not be syntaxically correct):

In kernel:

/* Variable holding pointer to preboot hook function. */ preboot_hook:

	.long	0

...

	/* Check if there is preboot hook installed.  */
	movl	preboot_hook, %eax
	testl	%eax, %eax
	jne	1f
	call	%eax
1:
	/* Continue boot.  */

Then in module code:

void grub_preboot_hook_handler(void)

{
	/* Process list of registered preboot hooks.  */
}

void grub_preboot_register_hook(...);
void grub_preboot_unregister_hook(...);

GRUB_MOD_INIT(preboot)

{
	preboot_hook = grub_preboot_hook_handler;
}

GRUB_MOD_FINI(preboot)

{
	preboot_hook = 0;
}

If preboot.mod gets loaded then it goes and registers preboot handler to kernel to do its tricks. Other modules then would use preboot.mod to register their own handlers.

This would have minimal impact for kernel.

Thanks,
Vesa Jääskeläinen

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

#22 lore raw
Quoted 4 lines · phcoder

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.

author
#23 lore raw
Quoted 10 lines · Vesa Jääskeläinen
Quoted 4 lines · phcoder

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.

kern/loader.c is always executed in PM. It just chooses which kernel-specific function to call next. RM helpers are found in kern/i386/loader.S and kern/i386/pc/startup.S (for chainloader).

Vladimir 'phcoder' Serbinenko

#24 lore raw
In reply to Vesa Jääskeläinen
Quoted 9 lines · Vesa Jääskeläinen
Quoted 4 lines · phcoder

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

author
#25 lore raw

PATCH 1/1 Move kern/loader.c to boot.mod and add preboot_support (was Re: Sendkey patch)

Hello. As I said in another email there is no need for it. I send a patch for it.
Vladimir 'phcoder' Serbinenko

Quoted 18 lines · Javier Martín
Quoted 8 lines · Vesa Jääskeläinen
Quoted 4 lines · phcoder

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

Quoted 6 lines

------------------------------------------------------------------------

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

common.rmk +7 -2
Index: conf/common.rmk
===================================================================
@@ -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)
 
i386-pc.rmk +4 -4
Index: conf/i386-pc.rmk
===================================================================
@@ -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		\
loader.c +0 -75

75 lines not on this page · raw message

rescue.c +0 -10
Index: kern/rescue.c
===================================================================
@@ -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,
grub/loader.h +12 -6
Index: include/grub/loader.h
===================================================================
@@ -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 */
grub/kernel.h +1 -1
Index: include/grub/kernel.h
===================================================================
@@ -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);
boot.c +124 -18

158 lines not on this page · raw message

#26 lore raw

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

Quoted 2 lines · phcoder

Hello. As I said in another email there is no need for it. I send a patch for it.

Well, I won't deny the patch is clever and looks good (I haven't tested it yet). However, taking the generic "boot" command out of kernel and leaving the several loader-specific assembly routines (which would be the parts needing relocation) there is as elegant as vogon poetry. However, if there is no opposition and your patch works fine - I'm about to test it right now - we can first commit it (thus making core.img smaller) and then work on getting the loader asm routines out of kernel.

-Habbit

Quoted 31 lines

Vladimir 'phcoder' Serbinenko

Quoted 18 lines · Javier Martín
Quoted 8 lines · Vesa Jääskeläinen
Quoted 4 lines · phcoder

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

Quoted 6 lines

------------------------------------------------------------------------

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

#27 lore raw

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

In reply to phcoder
Quoted 2 lines · phcoder

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 ?

#28 lore raw

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

Quoted 5 lines · Vesa Jääskeläinen
Quoted 2 lines · phcoder

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?

#29 lore raw

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

Quoted 9 lines · Javier Martín
Quoted 4 lines · Vesa Jääskeläinen
Quoted 2 lines · phcoder

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?

You may want to chainload something?

#30 lore raw

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

Quoted 5 lines · Vesa Jääskeläinen
Quoted 4 lines · Javier Martín
Quoted 3 lines · Vesa Jääskeläinen
Quoted 2 lines · phcoder

Hello. As I said in another email there is no need for it. I send a patch for it.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

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?

You may want to chainload something?

Isn't "chainloader" also a command external to the kernel? I recall seeing _chain.mod (rescue) and chain.mod (normal). So, as long as those don't go with core.img, you won't chainload a thing.

author
#31 lore raw

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

Hello,all. I was busy studying so wasn't watching the list. Is there a particular reason why my patch still isn't incorporated? Thanks
phcoder

Quoted 23 lines · Javier Martín
Quoted 11 lines · Vesa Jääskeläinen
Quoted 9 lines · Javier Martín
Quoted 4 lines · Vesa Jääskeläinen
Quoted 2 lines · phcoder

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?

You may want to chainload something?

Isn't "chainloader" also a command external to the kernel? I recall seeing _chain.mod (rescue) and chain.mod (normal). So, as long as those don't go with core.img, you won't chainload a thing.

------------------------------------------------------------------------

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

#32 lore raw

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

Quoted 2 lines · phcoder

Hello,all. I was busy studying so wasn't watching the list. Is there a particular reason why my patch still isn't incorporated?

Perhaps we didn't like the move of loader/boot core functionality out of kernel?

And I do not remember you describing in detail about interfaces and functional design of your idea.

Tip: use threaded view to browse messages.

author
#33 lore raw

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

I did. The discussion seems to simply have died out without any official response Thanks
Vladimir 'phcoder' Serbinenko

Quoted 18 lines · Vesa Jääskeläinen
Quoted 2 lines · phcoder

Hello,all. I was busy studying so wasn't watching the list. Is there a particular reason why my patch still isn't incorporated?

Perhaps we didn't like the move of loader/boot core functionality out of kernel?

And I do not remember you describing in detail about interfaces and functional design of your idea.

Tip: use threaded view to browse messages.

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

#34 lore raw

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

In reply to Javier Martín
Quoted 12 lines · Javier Martín
Quoted 11 lines · Vesa Jääskeläinen
Quoted 9 lines · Javier Martín
Quoted 4 lines · Vesa Jääskeläinen
Quoted 2 lines · phcoder

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?

Quoted 4 lines
Quoted 1 line

You may want to chainload something?

Isn't "chainloader" also a command external to the kernel? I recall seeing _chain.mod (rescue) and chain.mod (normal). So, as long as those don't go with core.img, you won't chainload a thing.

It is. We just happen to load it by default on i386-pc.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#35 lore raw

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

In reply to Javier Martín
Quoted 10 lines · Javier Martín
Quoted 5 lines · Vesa Jääskeläinen
Quoted 2 lines · phcoder

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).

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
author
#36 lore raw

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

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

Quoted 11 lines · Robert Millan
Quoted 9 lines · Javier Martín
Quoted 4 lines · Vesa Jääskeläinen
Quoted 2 lines · phcoder

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?

Quoted 7 lines

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).

common.rmk +7 -2
Index: conf/common.rmk
===================================================================
@@ -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)
 
i386-pc.rmk +4 -4
Index: conf/i386-pc.rmk
===================================================================
@@ -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		\
i386-efi.rmk +3 -3
Index: conf/i386-efi.rmk
===================================================================
@@ -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)
x86_64-efi.rmk +3 -3
Index: conf/x86_64-efi.rmk
===================================================================
@@ -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)
powerpc-ieee1275.rmk +3 -3
Index: conf/powerpc-ieee1275.rmk
===================================================================
@@ -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 		\
i386-coreboot.rmk +2 -2
Index: conf/i386-coreboot.rmk
===================================================================
@@ -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
sparc64-ieee1275.rmk +3 -3
Index: conf/sparc64-ieee1275.rmk
===================================================================
@@ -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 \
i386-ieee1275.rmk +3 -3
Index: conf/i386-ieee1275.rmk
===================================================================
@@ -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				\
loader.c +0 -75

75 lines not on this page · raw message

rescue.c +0 -10
Index: kern/rescue.c
===================================================================
@@ -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,
grub/loader.h +12 -6
Index: include/grub/loader.h
===================================================================
@@ -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 */
grub/kernel.h +1 -1
Index: include/grub/kernel.h
===================================================================
@@ -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);
ChangeLog +21 -0
Index: ChangeLog
===================================================================
@@ -1,3 +1,24 @@
+2009-02-07  Vladimir Serbinenko  <[email protected]>
+
+	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  <[email protected]>
 
 	* INSTALL: Note that we now require at least autconf 2.59 and that LZO
boot.c +124 -18

158 lines not on this page · raw message

boot_normal.c +48 -0

48 lines not on this page · raw message