This patch is to introduce multiboot 2 loading capabilities to grub2

for powerpc & i386-pc. This patch was more so started by Hollis
Blanchard getting multiboot 2 working for powerpc and I added to it
and cleaned it up.

One of the ideas with this patch is to keep everything under one
command for the user. So instead of having a "multiboot2" & "module2"
command, I created a proxy like mechanism so that you have only one
command for both multiboot 1 & 2 ... "multiboot". This is where
"loader/multiboot_loader.c" comes from. I could have integrated things
more but I figure the current approach will less likely break
anything.

So if your OS is multiboot 2 capable, the user would do the following
to load it up from a grub prompt:

grub> multiboot <location of kernel> <kernel args>
grub> module <some image> <multiboot tag> <image arguments>
grub> module <isome mage> <multiboot tag> <image arguments>
grub .....


The other thing that this patch does is it begins to make the
multiboot 1 code a bit more architecture agnostic so IF someone wanted
to implement it on another architecture they can.

A bit of file moving around and definition renaming is also apart of
this patch. I have also taken the time to make sure that it does not
break multiboot 1 loading on i386-pc. But mulitboot 2 may still need a
little more testing and work for i386-pc. Powerpc multiboot 2 has been
heavily tested and does work.
This commit is contained in:
jerone 2007-07-25 00:44:03 +00:00
parent daf0f0ba3e
commit e5dfe7775a
17 changed files with 1315 additions and 300 deletions

View file

@ -32,7 +32,7 @@
#include <grub/loader.h>
#include <grub/machine/loader.h>
#include <grub/machine/multiboot.h>
#include <grub/multiboot.h>
#include <grub/machine/init.h>
#include <grub/elf.h>
#include <grub/file.h>
@ -43,7 +43,7 @@
#include <grub/misc.h>
#include <grub/gzio.h>
static grub_dl_t my_mod;
extern grub_dl_t my_mod;
static struct grub_multiboot_info *mbi;
static grub_addr_t entry;
@ -107,7 +107,7 @@ grub_multiboot_load_elf32 (grub_file_t file, void *buffer)
return grub_error (GRUB_ERR_UNKNOWN_OS, "invalid ELF file type");
/* FIXME: Should we support program headers at strange locations? */
if (ehdr->e_phoff + ehdr->e_phnum * ehdr->e_phentsize > GRUB_MB_SEARCH)
if (ehdr->e_phoff + ehdr->e_phnum * ehdr->e_phentsize > MULTIBOOT_SEARCH)
return grub_error (GRUB_ERR_BAD_OS, "program header at a too high offset");
entry = ehdr->e_entry;
@ -177,7 +177,7 @@ grub_multiboot_load_elf64 (grub_file_t file, void *buffer)
return grub_error (GRUB_ERR_UNKNOWN_OS, "invalid ELF file type");
/* FIXME: Should we support program headers at strange locations? */
if (ehdr->e_phoff + ehdr->e_phnum * ehdr->e_phentsize > GRUB_MB_SEARCH)
if (ehdr->e_phoff + ehdr->e_phnum * ehdr->e_phentsize > MULTIBOOT_SEARCH)
return grub_error (GRUB_ERR_BAD_OS, "program header at a too high offset");
/* We still in 32-bit mode */
@ -236,16 +236,14 @@ grub_multiboot_load_elf (grub_file_t file, void *buffer)
}
void
grub_rescue_cmd_multiboot (int argc, char *argv[])
grub_multiboot (int argc, char *argv[])
{
grub_file_t file = 0;
char buffer[GRUB_MB_SEARCH], *cmdline = 0, *p;
char buffer[MULTIBOOT_SEARCH], *cmdline = 0, *p;
struct grub_multiboot_header *header;
grub_ssize_t len;
int i;
grub_dl_ref (my_mod);
grub_loader_unset ();
if (argc == 0)
@ -261,7 +259,7 @@ grub_rescue_cmd_multiboot (int argc, char *argv[])
goto fail;
}
len = grub_file_read (file, buffer, GRUB_MB_SEARCH);
len = grub_file_read (file, buffer, MULTIBOOT_SEARCH);
if (len < 32)
{
grub_error (GRUB_ERR_BAD_OS, "File too small");
@ -274,7 +272,7 @@ grub_rescue_cmd_multiboot (int argc, char *argv[])
((char *) header <= buffer + len - 12) || (header = 0);
header = (struct grub_multiboot_header *) ((char *) header + 4))
{
if (header->magic == GRUB_MB_MAGIC
if (header->magic == MULTIBOOT_MAGIC
&& !(header->magic + header->flags + header->checksum))
break;
}
@ -285,7 +283,7 @@ grub_rescue_cmd_multiboot (int argc, char *argv[])
goto fail;
}
if (header->flags & GRUB_MB_UNSUPPORTED)
if (header->flags & MULTIBOOT_UNSUPPORTED)
{
grub_error (GRUB_ERR_UNKNOWN_OS,
"Unsupported flag: 0x%x", header->flags);
@ -299,7 +297,7 @@ grub_rescue_cmd_multiboot (int argc, char *argv[])
if (! mbi)
goto fail;
mbi->flags = GRUB_MB_INFO_MEMORY;
mbi->flags = MULTIBOOT_INFO_MEMORY;
/* Convert from bytes to kilobytes. */
mbi->mem_lower = grub_lower_mem / 1024;
@ -321,10 +319,10 @@ grub_rescue_cmd_multiboot (int argc, char *argv[])
/* Remove the space after the last word. */
*(--p) = '\0';
mbi->flags |= GRUB_MB_INFO_CMDLINE;
mbi->flags |= MULTIBOOT_INFO_CMDLINE;
mbi->cmdline = (grub_uint32_t) cmdline;
mbi->flags |= GRUB_MB_INFO_BOOT_LOADER_NAME;
mbi->flags |= MULTIBOOT_INFO_BOOT_LOADER_NAME;
mbi->boot_loader_name = (grub_uint32_t) grub_strdup (PACKAGE_STRING);
grub_loader_set (grub_multiboot_boot, grub_multiboot_unload, 1);
@ -343,7 +341,7 @@ grub_rescue_cmd_multiboot (int argc, char *argv[])
void
grub_rescue_cmd_module (int argc, char *argv[])
grub_module (int argc, char *argv[])
{
grub_file_t file = 0;
grub_ssize_t size, len = 0;
@ -368,7 +366,7 @@ grub_rescue_cmd_module (int argc, char *argv[])
goto fail;
size = grub_file_size (file);
module = grub_memalign (GRUB_MB_MOD_ALIGN, size);
module = grub_memalign (MULTIBOOT_MOD_ALIGN, size);
if (! module)
goto fail;
@ -394,7 +392,7 @@ grub_rescue_cmd_module (int argc, char *argv[])
/* Remove the space after the last word. */
*(--p) = '\0';
if (mbi->flags & GRUB_MB_INFO_MODS)
if (mbi->flags & MULTIBOOT_INFO_MODS)
{
struct grub_mod_list *modlist = (struct grub_mod_list *) mbi->mods_addr;
@ -421,7 +419,7 @@ grub_rescue_cmd_module (int argc, char *argv[])
modlist->pad = 0;
mbi->mods_count = 1;
mbi->mods_addr = (grub_uint32_t) modlist;
mbi->flags |= GRUB_MB_INFO_MODS;
mbi->flags |= MULTIBOOT_INFO_MODS;
}
fail:
@ -434,19 +432,3 @@ grub_rescue_cmd_module (int argc, char *argv[])
grub_free (cmdline);
}
}
GRUB_MOD_INIT(multiboot)
{
grub_rescue_register_command ("multiboot", grub_rescue_cmd_multiboot,
"load a multiboot kernel");
grub_rescue_register_command ("module", grub_rescue_cmd_module,
"load a multiboot module");
my_mod = mod;
}
GRUB_MOD_FINI(multiboot)
{
grub_rescue_unregister_command ("multiboot");
grub_rescue_unregister_command ("module");
}