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

@ -21,11 +21,13 @@
#include <grub/types.h>
#include <grub/symbol.h>
#include <grub/machine/multiboot.h>
#include <grub/multiboot.h>
extern grub_uint32_t EXPORT_VAR(grub_linux_prot_size);
extern char *EXPORT_VAR(grub_linux_tmp_addr);
extern char *EXPORT_VAR(grub_linux_real_addr);
extern grub_addr_t EXPORT_VAR(grub_os_area_addr);
extern grub_size_t EXPORT_VAR(grub_os_area_size);
void EXPORT_FUNC(grub_linux_boot_zimage) (void) __attribute__ ((noreturn));
void EXPORT_FUNC(grub_linux_boot_bzimage) (void) __attribute__ ((noreturn));
@ -37,12 +39,13 @@ void EXPORT_FUNC(grub_chainloader_real_boot) (int drive, void *part_addr) __attr
void EXPORT_FUNC(grub_multiboot_real_boot) (grub_addr_t entry,
struct grub_multiboot_info *mbi)
__attribute__ ((noreturn));
void EXPORT_FUNC(grub_multiboot2_real_boot) (grub_addr_t entry,
struct grub_multiboot_info *mbi)
__attribute__ ((noreturn));
/* It is necessary to export these functions, because normal mode commands
reuse rescue mode commands. */
void grub_rescue_cmd_linux (int argc, char *argv[]);
void grub_rescue_cmd_initrd (int argc, char *argv[]);
void grub_rescue_cmd_multiboot (int argc, char *argv[]);
void grub_rescue_cmd_module (int argc, char *argv[]);
#endif /* ! GRUB_LOADER_MACHINE_HEADER */

View file

@ -1,4 +1,4 @@
/* multiboot.h - multiboot header file. */
/* multiboot.h - multiboot header file with grub definitions. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2007 Free Software Foundation, Inc.
@ -17,77 +17,13 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_MULTIBOOT_MACHINE_HEADER
#define GRUB_MULTIBOOT_MACHINE_HEADER 1
#ifndef GRUB_MULTIBOOT_HEADER
#define GRUB_MULTIBOOT_HEADER 1
/* How many bytes from the start of the file we search for the header. */
#define GRUB_MB_SEARCH 8192
#include <multiboot.h>
/* The magic field should contain this. */
#define GRUB_MB_MAGIC 0x1BADB002
/* This should be in %eax. */
#define GRUB_MB_MAGIC2 0x2BADB002
/* The bits in the required part of flags field we don't support. */
#define GRUB_MB_UNSUPPORTED 0x0000fffc
/* Alignment of multiboot modules. */
#define GRUB_MB_MOD_ALIGN 0x00001000
/*
* Flags set in the 'flags' member of the multiboot header.
*/
/* Align all boot modules on i386 page (4KB) boundaries. */
#define GRUB_MB_PAGE_ALIGN 0x00000001
/* Must pass memory information to OS. */
#define GRUB_MB_MEMORY_INFO 0x00000002
/* Must pass video information to OS. */
#define GRUB_MB_VIDEO_MODE 0x00000004
/* This flag indicates the use of the address fields in the header. */
#define GRUB_MB_AOUT_KLUDGE 0x00010000
/*
* Flags to be set in the 'flags' member of the multiboot info structure.
*/
/* is there basic lower/upper memory information? */
#define GRUB_MB_INFO_MEMORY 0x00000001
/* is there a boot device set? */
#define GRUB_MB_INFO_BOOTDEV 0x00000002
/* is the command-line defined? */
#define GRUB_MB_INFO_CMDLINE 0x00000004
/* are there modules to do something with? */
#define GRUB_MB_INFO_MODS 0x00000008
/* These next two are mutually exclusive */
/* is there a symbol table loaded? */
#define GRUB_MB_INFO_AOUT_SYMS 0x00000010
/* is there an ELF section header table? */
#define GRUB_MB_INFO_ELF_SHDR 0x00000020
/* is there a full memory map? */
#define GRUB_MB_INFO_MEM_MAP 0x00000040
/* Is there drive info? */
#define GRUB_MB_INFO_DRIVE_INFO 0x00000080
/* Is there a config table? */
#define GRUB_MB_INFO_CONFIG_TABLE 0x00000100
/* Is there a boot loader name? */
#define GRUB_MB_INFO_BOOT_LOADER_NAME 0x00000200
/* Is there a APM table? */
#define GRUB_MB_INFO_APM_TABLE 0x00000400
/* Is there video information? */
#define GRUB_MB_INFO_VIDEO_INFO 0x00000800
void grub_multiboot (int argc, char *argv[]);
void grub_module (int argc, char *argv[]);
#ifndef ASM_FILE
@ -95,7 +31,7 @@
struct grub_multiboot_header
{
/* Must be GRUB_MB_MAGIC - see above. */
/* Must be MULTIBOOT_MAGIC - see above. */
grub_uint32_t magic;
/* Feature flags. */
@ -104,14 +40,14 @@ struct grub_multiboot_header
/* The above fields plus this one must equal 0 mod 2^32. */
grub_uint32_t checksum;
/* These are only valid if GRUB_MB_AOUT_KLUDGE is set. */
/* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
grub_uint32_t header_addr;
grub_uint32_t load_addr;
grub_uint32_t load_end_addr;
grub_uint32_t bss_end_addr;
grub_uint32_t entry_addr;
/* These are only valid if GRUB_MB_VIDEO_MODE is set. */
/* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
grub_uint32_t mode_type;
grub_uint32_t width;
grub_uint32_t height;
@ -180,4 +116,4 @@ struct grub_mod_list
#endif /* ! ASM_FILE */
#endif /* ! GRUB_MULTIBOOT_MACHINE_HEADER */
#endif /* ! GRUB_MULTIBOOT_HEADER */

64
include/grub/multiboot2.h Normal file
View file

@ -0,0 +1,64 @@
/* multiboot2.h - multiboot2 header file with grub definitions. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_MULTIBOOT2_HEADER
#define GRUB_MULTIBOOT2_HEADER 1
#include <grub/types.h>
#include <grub/err.h>
#include <grub/elf.h>
struct multiboot_tag_header;
grub_err_t
grub_mb2_tag_alloc (grub_addr_t *addr, int key, grub_size_t len);
grub_err_t
grub_mb2_tags_arch_create (void);
void
grub_mb2_arch_boot (grub_addr_t entry, void *tags);
void
grub_mb2_arch_unload (struct multiboot_tag_header *tags);
grub_err_t
grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, grub_addr_t *addr);
grub_err_t
grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr, grub_addr_t *addr);
grub_err_t
grub_mb2_arch_module_alloc (grub_size_t size, grub_addr_t *addr);
grub_err_t
grub_mb2_arch_module_free (grub_addr_t addr, grub_size_t size);
void
grub_multiboot2 (int argc, char *argv[]);
void
grub_module2 (int argc, char *argv[]);
#define for_each_tag(tag, tags) \
for (tag = tags; \
tag && tag->key != MULTIBOOT2_TAG_END; \
tag = (struct multiboot_tag_header *)((char *)tag + tag->len))
#endif /* ! GRUB_MULTIBOOT2_HEADER */

View file

@ -0,0 +1,28 @@
/* multiboot_loader.h - multiboot loader header file. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_MULTIBOOT_LOADER_HEADER
#define GRUB_MULTIBOOT_LOADER_HEADER 1
/* Provided by the core ("rescue mode"). */
void grub_rescue_cmd_multiboot_loader (int argc, char *argv[]);
void grub_rescue_cmd_module_loader (int argc, char *argv[]);
#endif /* ! GRUB_MULTIBOOT_LOADER_HEADER */

View file

@ -1,183 +0,0 @@
/* multiboot.h - multiboot header file. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2004,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/>.
*/
#ifndef GRUB_MULTIBOOT_MACHINE_HEADER
#define GRUB_MULTIBOOT_MACHINE_HEADER 1
/* How many bytes from the start of the file we search for the header. */
#define GRUB_MB_SEARCH 8192
/* The magic field should contain this. */
#define GRUB_MB_MAGIC 0x1BADB002
/* This should be in %eax. */
#define GRUB_MB_MAGIC2 0x2BADB002
/* The bits in the required part of flags field we don't support. */
#define GRUB_MB_UNSUPPORTED 0x0000fffc
/* Alignment of multiboot modules. */
#define GRUB_MB_MOD_ALIGN 0x00001000
/*
* Flags set in the 'flags' member of the multiboot header.
*/
/* Align all boot modules on i386 page (4KB) boundaries. */
#define GRUB_MB_PAGE_ALIGN 0x00000001
/* Must pass memory information to OS. */
#define GRUB_MB_MEMORY_INFO 0x00000002
/* Must pass video information to OS. */
#define GRUB_MB_VIDEO_MODE 0x00000004
/* This flag indicates the use of the address fields in the header. */
#define GRUB_MB_AOUT_KLUDGE 0x00010000
/*
* Flags to be set in the 'flags' member of the multiboot info structure.
*/
/* is there basic lower/upper memory information? */
#define GRUB_MB_INFO_MEMORY 0x00000001
/* is there a boot device set? */
#define GRUB_MB_INFO_BOOTDEV 0x00000002
/* is the command-line defined? */
#define GRUB_MB_INFO_CMDLINE 0x00000004
/* are there modules to do something with? */
#define GRUB_MB_INFO_MODS 0x00000008
/* These next two are mutually exclusive */
/* is there a symbol table loaded? */
#define GRUB_MB_INFO_AOUT_SYMS 0x00000010
/* is there an ELF section header table? */
#define GRUB_MB_INFO_ELF_SHDR 0x00000020
/* is there a full memory map? */
#define GRUB_MB_INFO_MEM_MAP 0x00000040
/* Is there drive info? */
#define GRUB_MB_INFO_DRIVE_INFO 0x00000080
/* Is there a config table? */
#define GRUB_MB_INFO_CONFIG_TABLE 0x00000100
/* Is there a boot loader name? */
#define GRUB_MB_INFO_BOOT_LOADER_NAME 0x00000200
/* Is there a APM table? */
#define GRUB_MB_INFO_APM_TABLE 0x00000400
/* Is there video information? */
#define GRUB_MB_INFO_VIDEO_INFO 0x00000800
#ifndef ASM_FILE
#include <grub/types.h>
struct grub_multiboot_header
{
/* Must be GRUB_MB_MAGIC - see above. */
grub_uint32_t magic;
/* Feature flags. */
grub_uint32_t flags;
/* The above fields plus this one must equal 0 mod 2^32. */
grub_uint32_t checksum;
/* These are only valid if GRUB_MB_AOUT_KLUDGE is set. */
grub_uint32_t header_addr;
grub_uint32_t load_addr;
grub_uint32_t load_end_addr;
grub_uint32_t bss_end_addr;
grub_uint32_t entry_addr;
/* These are only valid if GRUB_MB_VIDEO_MODE is set. */
grub_uint32_t mode_type;
grub_uint32_t width;
grub_uint32_t height;
grub_uint32_t depth;
};
struct grub_multiboot_info
{
/* MultiBoot info version number */
grub_uint32_t flags;
/* Available memory from BIOS */
grub_uint32_t mem_lower;
grub_uint32_t mem_upper;
/* "root" partition */
grub_uint32_t boot_device;
/* Kernel command line */
grub_uint32_t cmdline;
/* Boot-Module list */
grub_uint32_t mods_count;
grub_uint32_t mods_addr;
grub_uint32_t syms[4];
/* Memory Mapping buffer */
grub_uint32_t mmap_length;
grub_uint32_t mmap_addr;
/* Drive Info buffer */
grub_uint32_t drives_length;
grub_uint32_t drives_addr;
/* ROM configuration table */
grub_uint32_t config_table;
/* Boot Loader Name */
grub_uint32_t boot_loader_name;
/* APM table */
grub_uint32_t apm_table;
/* Video */
grub_uint32_t vbe_control_info;
grub_uint32_t vbe_mode_info;
grub_uint16_t vbe_mode;
grub_uint16_t vbe_interface_seg;
grub_uint16_t vbe_interface_off;
grub_uint16_t vbe_interface_len;
};
struct grub_mod_list
{
/* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
grub_uint32_t mod_start;
grub_uint32_t mod_end;
/* Module command line */
grub_uint32_t cmdline;
/* padding to take it to 16 bytes (must be zero) */
grub_uint32_t pad;
};
#endif /* ! ASM_FILE */
#endif /* ! GRUB_MULTIBOOT_MACHINE_HEADER */

92
include/multiboot.h Normal file
View file

@ -0,0 +1,92 @@
/* multiboot.h - multiboot header file. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,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/>.
*/
#ifndef MULTIBOOT_HEADER
#define MULTIBOOT_HEADER 1
/* How many bytes from the start of the file we search for the header. */
#define MULTIBOOT_SEARCH 8192
/* The magic field should contain this. */
#define MULTIBOOT_MAGIC 0x1BADB002
/* This should be in %eax. */
#define MULTIBOOT_MAGIC2 0x2BADB002
/* The bits in the required part of flags field we don't support. */
#define MULTIBOOT_UNSUPPORTED 0x0000fffc
/* Alignment of multiboot modules. */
#define MULTIBOOT_MOD_ALIGN 0x00001000
/*
* Flags set in the 'flags' member of the multiboot header.
*/
/* Align all boot modules on i386 page (4KB) boundaries. */
#define MULTIBOOT_PAGE_ALIGN 0x00000001
/* Must pass memory information to OS. */
#define MULTIBOOT_MEMORY_INFO 0x00000002
/* Must pass video information to OS. */
#define MULTIBOOT_VIDEO_MODE 0x00000004
/* This flag indicates the use of the address fields in the header. */
#define MULTIBOOT_AOUT_KLUDGE 0x00010000
/*
* Flags to be set in the 'flags' member of the multiboot info structure.
*/
/* is there basic lower/upper memory information? */
#define MULTIBOOT_INFO_MEMORY 0x00000001
/* is there a boot device set? */
#define MULTIBOOT_INFO_BOOTDEV 0x00000002
/* is the command-line defined? */
#define MULTIBOOT_INFO_CMDLINE 0x00000004
/* are there modules to do something with? */
#define MULTIBOOT_INFO_MODS 0x00000008
/* These next two are mutually exclusive */
/* is there a symbol table loaded? */
#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010
/* is there an ELF section header table? */
#define MULTIBOOT_INFO_ELF_SHDR 0x00000020
/* is there a full memory map? */
#define MULTIBOOT_INFO_MEM_MAP 0x00000040
/* Is there drive info? */
#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080
/* Is there a config table? */
#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100
/* Is there a boot loader name? */
#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200
/* Is there a APM table? */
#define MULTIBOOT_INFO_APM_TABLE 0x00000400
/* Is there video information? */
#define MULTIBOOT_INFO_VIDEO_INFO 0x00000800
#endif /* ! MULTIBOOT_HEADER */

107
include/multiboot2.h Normal file
View file

@ -0,0 +1,107 @@
/* multiboot2.h - multiboot 2 header file. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 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/>.
*/
#ifndef MULTIBOOT2_HEADER
#define MULTIBOOT2_HEADER 1
/* How many bytes from the start of the file we search for the header. */
#define MULTIBOOT2_HEADER_SEARCH 8192
/* The magic field should contain this. */
#define MULTIBOOT2_HEADER_MAGIC 0xe85250d6
/* Passed from the bootloader to the kernel. */
#define MULTIBOOT2_BOOTLOADER_MAGIC 0x36d76289
/* Alignment of multiboot modules. */
#define MULTIBOOT2_MOD_ALIGN 0x00001000
#ifndef ASM_FILE
#include "stdint.h"
/* XXX not portable? */
#if __WORDSIZE == 64
typedef uint64_t multiboot_word;
#else
typedef uint32_t multiboot_word;
#endif
struct multiboot_header
{
uint32_t magic;
};
struct multiboot_tag_header
{
uint32_t key;
uint32_t len;
};
#define MULTIBOOT2_TAG_RESERVED1 0
#define MULTIBOOT2_TAG_RESERVED2 (~0)
#define MULTIBOOT2_TAG_START 1
struct multiboot_tag_start
{
struct multiboot_tag_header header;
multiboot_word size; /* Total size of all multiboot tags. */
};
#define MULTIBOOT2_TAG_NAME 2
struct multiboot_tag_name
{
struct multiboot_tag_header header;
char name[1];
};
#define MULTIBOOT2_TAG_MODULE 3
struct multiboot_tag_module
{
struct multiboot_tag_header header;
multiboot_word addr;
multiboot_word size;
unsigned char type[36];
unsigned char cmdline[1];
};
#define MULTIBOOT2_TAG_MEMORY 4
struct multiboot_tag_memory
{
struct multiboot_tag_header header;
multiboot_word addr;
multiboot_word size;
multiboot_word type;
};
#define MULTIBOOT2_TAG_UNUSED 5
struct multiboot_tag_unused
{
struct multiboot_tag_header header;
};
#define MULTIBOOT2_TAG_END 0xffff
struct multiboot_tag_end
{
struct multiboot_tag_header header;
};
#endif /* ! ASM_FILE */
#endif /* ! MULTIBOOT2_HEADER */