Merge mainline into gfxmenu

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-02-03 01:24:07 +01:00
commit 1f534b6908
279 changed files with 9437 additions and 3021 deletions

View file

@ -25,6 +25,7 @@
#include <grub/efi/api.h>
#include <grub/efi/efi.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_dl_t my_mod;
@ -321,7 +322,7 @@ static grub_command_t cmd;
GRUB_MOD_INIT(appleloader)
{
cmd = grub_register_command ("appleloader", grub_cmd_appleloader,
"[OPTS]", "Boot legacy system.");
"[OPTS]", N_("Boot legacy system."));
my_mod = mod;
}

View file

@ -33,6 +33,7 @@
#include <grub/efi/efi.h>
#include <grub/efi/disk.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_dl_t my_mod;
@ -336,7 +337,7 @@ static grub_command_t cmd;
GRUB_MOD_INIT(chainloader)
{
cmd = grub_register_command ("chainloader", grub_cmd_chainloader,
0, "Load another boot loader.");
0, N_("Load another boot loader."));
my_mod = mod;
}

View file

@ -1,6 +1,6 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008, 2009 Free Software Foundation, Inc.
* Copyright (C) 2008,2009,2010 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
@ -35,7 +35,7 @@
#include <grub/command.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
#include <grub/video.h>
#ifdef GRUB_MACHINE_PCBIOS
#include <grub/machine/biosnum.h>
#endif
@ -461,14 +461,14 @@ grub_freebsd_boot (void)
}
grub_memset (&bi, 0, sizeof (bi));
bi.bi_version = FREEBSD_BOOTINFO_VERSION;
bi.bi_size = sizeof (bi);
bi.version = FREEBSD_BOOTINFO_VERSION;
bi.length = sizeof (bi);
grub_bsd_get_device (&biosdev, &unit, &slice, &part);
bootdev = (FREEBSD_B_DEVMAGIC + ((slice + 1) << FREEBSD_B_SLICESHIFT) +
(unit << FREEBSD_B_UNITSHIFT) + (part << FREEBSD_B_PARTSHIFT));
bi.bi_bios_dev = biosdev;
bi.boot_device = biosdev;
p = (char *) kern_end;
@ -478,7 +478,7 @@ grub_freebsd_boot (void)
{
*(p++) = 0;
bi.bi_envp = kern_end;
bi.environment = kern_end;
kern_end = ALIGN_PAGE ((grub_uint32_t) p);
}
@ -491,23 +491,25 @@ grub_freebsd_boot (void)
return grub_errno;
grub_memcpy ((char *) kern_end, mod_buf, mod_buf_len);
bi.bi_modulep = kern_end;
bi.tags = kern_end;
kern_end = ALIGN_PAGE (kern_end + mod_buf_len);
if (is_64bit)
kern_end += 4096 * 4;
md_ofs = bi.bi_modulep + kern_end_mdofs;
md_ofs = bi.tags + kern_end_mdofs;
ofs = (is_64bit) ? 16 : 12;
*((grub_uint32_t *) md_ofs) = kern_end;
md_ofs -= ofs;
*((grub_uint32_t *) md_ofs) = bi.bi_envp;
*((grub_uint32_t *) md_ofs) = bi.environment;
md_ofs -= ofs;
*((grub_uint32_t *) md_ofs) = bootflags;
}
bi.bi_kernend = kern_end;
bi.kern_end = kern_end;
grub_video_set_mode ("text", 0, 0);
if (is_64bit)
{
@ -552,12 +554,12 @@ grub_freebsd_boot (void)
&grub_bsd64_trampoline_end - &grub_bsd64_trampoline_start);
/* Launch trampoline. */
launch_trampoline (entry, entry_hi, pagetable, bi.bi_modulep,
launch_trampoline (entry, entry_hi, pagetable, bi.tags,
kern_end);
}
else
grub_unix_real_boot (entry, bootflags | FREEBSD_RB_BOOTINFO, bootdev,
0, 0, 0, &bi, bi.bi_modulep, kern_end);
0, 0, 0, &bi, bi.tags, kern_end);
/* Not reached. */
return GRUB_ERR_NONE;
@ -617,6 +619,8 @@ grub_openbsd_boot (void)
pa->ba_type = OPENBSD_BOOTARG_END;
pa++;
grub_video_set_mode ("text", 0, 0);
grub_unix_real_boot (entry, bootflags, openbsd_root, OPENBSD_BOOTARG_APIVER,
0, (grub_uint32_t) (grub_mmap_get_upper () >> 10),
(grub_uint32_t) (grub_mmap_get_lower () >> 10),
@ -680,7 +684,7 @@ grub_netbsd_boot (void)
+ sizeof (struct grub_netbsd_btinfo_mmap_header)
+ count * sizeof (struct grub_netbsd_btinfo_mmap_entry)
> grub_os_area_addr + grub_os_area_size)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "no memory for boot info");
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
curarg = mmap = (struct grub_netbsd_btinfo_mmap_header *) kern_end;
pm = (struct grub_netbsd_btinfo_mmap_entry *) (mmap + 1);
@ -713,6 +717,8 @@ grub_netbsd_boot (void)
bootinfo->bi_data[0] = mmap;
}
grub_video_set_mode ("text", 0, 0);
grub_unix_real_boot (entry, bootflags, 0, bootinfo,
0, (grub_uint32_t) (grub_mmap_get_upper () >> 10),
(grub_uint32_t) (grub_mmap_get_lower () >> 10));
@ -888,7 +894,7 @@ grub_bsd_load_elf (grub_elf_t elf)
return grub_elf64_load (elf, grub_bsd_elf64_hook, 0, 0);
}
else
return grub_error (GRUB_ERR_BAD_OS, "invalid elf");
return grub_error (GRUB_ERR_BAD_OS, "invalid ELF");
}
static grub_err_t
@ -1081,7 +1087,7 @@ grub_cmd_freebsd_loadenv (grub_command_t cmd __attribute__ ((unused)),
if (kernel_type != KERNEL_TYPE_FREEBSD)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"only FreeBSD support environment");
"only FreeBSD supports environment");
if (argc == 0)
{
@ -1139,14 +1145,20 @@ grub_cmd_freebsd_loadenv (grub_command_t cmd __attribute__ ((unused)),
if (*curr)
{
char name[grub_strlen (curr) + sizeof("kFreeBSD.")];
char *name;
if (*p == '"')
p++;
grub_sprintf (name, "kFreeBSD.%s", curr);
if (grub_env_set (name, p))
name = grub_xasprintf ("kFreeBSD.%s", curr);
if (!name)
goto fail;
if (grub_env_set (name, p))
{
grub_free (name);
goto fail;
}
grub_free (name);
}
}
@ -1175,11 +1187,11 @@ grub_cmd_freebsd_module (grub_command_t cmd __attribute__ ((unused)),
if (kernel_type != KERNEL_TYPE_FREEBSD)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"only FreeBSD support module");
"only FreeBSD supports module");
if (!is_elf_kernel)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"only ELF kernel support module");
"only ELF kernel supports module");
/* List the current modules if no parameter. */
if (!argc)
@ -1241,11 +1253,11 @@ grub_cmd_freebsd_module_elf (grub_command_t cmd __attribute__ ((unused)),
if (kernel_type != KERNEL_TYPE_FREEBSD)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"only FreeBSD support module");
"only FreeBSD supports module");
if (! is_elf_kernel)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"only ELF kernel support module");
"only ELF kernel supports module");
/* List the current modules if no parameter. */
if (! argc)

View file

@ -271,7 +271,7 @@ SUFFIX (grub_freebsd_load_elf_meta) (grub_file_t file, grub_addr_t *kern_end)
(grub_ssize_t) symsize)
{
if (! grub_errno)
return grub_error (GRUB_ERR_BAD_OS, "invalid elf");
return grub_error (GRUB_ERR_BAD_OS, "invalid ELF");
return grub_errno;
}
curload += symsize;
@ -285,7 +285,7 @@ SUFFIX (grub_freebsd_load_elf_meta) (grub_file_t file, grub_addr_t *kern_end)
!= (grub_ssize_t) strsize)
{
if (! grub_errno)
return grub_error (GRUB_ERR_BAD_OS, "invalid elf");
return grub_error (GRUB_ERR_BAD_OS, "invalid ELF");
return grub_errno;
}
curload += strsize;

View file

@ -1,6 +1,6 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 2006,2007,2008,2009,2010 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
@ -33,6 +33,7 @@
#include <grub/pci.h>
#include <grub/command.h>
#include <grub/memory.h>
#include <grub/i18n.h>
#define GRUB_LINUX_CL_OFFSET 0x1000
#define GRUB_LINUX_CL_END_OFFSET 0x2000
@ -477,7 +478,7 @@ find_framebuf (grub_uint32_t *fb_base, grub_uint32_t *line_len)
{
grub_pci_address_t addr;
addr = grub_pci_make_address (dev, 2);
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
if (grub_pci_read (addr) >> 24 == 0x3)
{
int i;
@ -586,7 +587,7 @@ grub_linux_setup_video (struct linux_kernel_params *params)
params->reserved_mask_size = 8;
params->reserved_field_pos = 24;
params->have_vga = GRUB_VIDEO_TYPE_VLFB;
params->have_vga = GRUB_VIDEO_LINUX_TYPE_VESA;
params->vid_mode = 0x338; /* 1024x768x32 */
return 0;
@ -619,7 +620,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
{
grub_error (GRUB_ERR_READ_ERROR, "cannot read the linux header");
grub_error (GRUB_ERR_READ_ERROR, "cannot read the Linux header");
goto fail;
}
@ -675,8 +676,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
goto fail;
}
/* XXX Linux assumes that only elilo can boot Linux on EFI!!! */
params->type_of_loader = (LINUX_LOADER_ID_ELILO << 4);
params->type_of_loader = (LINUX_LOADER_ID_GRUB << 4);
params->cl_magic = GRUB_LINUX_CL_MAGIC;
params->cl_offset = 0x1000;
@ -697,7 +697,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
grub_term_output_t term;
int found = 0;
FOR_ACTIVE_TERM_OUTPUTS(term)
if (grub_strcmp (term->name, "vga_text") == 0)
if (grub_strcmp (term->name, "vga_text") == 0
|| grub_strcmp (term->name, "console") == 0)
{
grub_uint16_t pos = grub_term_getxy (term);
params->video_cursor_x = pos >> 8;
@ -705,18 +706,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
params->video_width = grub_term_width (term);
params->video_height = grub_term_height (term);
found = 1;
break;
}
if (!found)
FOR_ACTIVE_TERM_OUTPUTS(term)
if (grub_strcmp (term->name, "console") == 0)
{
grub_uint16_t pos = grub_term_getxy (term);
params->video_cursor_x = pos >> 8;
params->video_cursor_y = pos & 0xff;
params->video_width = grub_term_width (term);
params->video_height = grub_term_height (term);
found = 1;
}
if (!found)
{
params->video_cursor_x = 0;
@ -860,7 +851,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
else if (grub_memcmp (argv[i], "video=efifb", 11) == 0)
{
if (params->have_vga)
params->have_vga = GRUB_VIDEO_TYPE_EFI;
params->have_vga = GRUB_VIDEO_LINUX_TYPE_SIMPLE;
}
/* Specify the boot file. */
@ -1017,9 +1008,9 @@ static grub_command_t cmd_linux, cmd_initrd;
GRUB_MOD_INIT(linux)
{
cmd_linux = grub_register_command ("linux", grub_cmd_linux,
0, "Load Linux.");
0, N_("Load Linux."));
cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd,
0, "Load initrd.");
0, N_("Load initrd."));
my_mod = mod;
}

View file

@ -79,7 +79,7 @@ find_framebuf (grub_uint32_t *fb_base, grub_uint32_t *line_len)
{
grub_pci_address_t addr;
addr = grub_pci_make_address (dev, 2);
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
if (grub_pci_read (addr) >> 24 == 0x3)
{
int i;

View file

@ -1,7 +1,7 @@
/* linux.c - boot Linux zImage or bzImage */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 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
@ -32,6 +32,7 @@
#include <grub/cpu/linux.h>
#include <grub/ieee1275/ieee1275.h>
#include <grub/command.h>
#include <grub/i18n.h>
#define GRUB_OFW_LINUX_PARAMS_ADDR 0x90000
#define GRUB_OFW_LINUX_KERNEL_ADDR 0x100000
@ -113,34 +114,25 @@ grub_linux_boot (void)
grub_term_output_t term;
int found = 0;
FOR_ACTIVE_TERM_OUTPUTS(term)
if (grub_strcmp (term->name, "vga_text") == 0)
{
grub_uint16_t pos = grub_term_getxy (term);
params->video_cursor_x = pos >> 8;
params->video_cursor_y = pos & 0xff;
params->video_width = grub_term_width (term);
params->video_height = grub_term_height (term);
found = 1;
}
if (!found)
FOR_ACTIVE_TERM_OUTPUTS(term)
if (grub_strcmp (term->name, "console") == 0)
{
grub_uint16_t pos = grub_term_getxy (term);
params->video_cursor_x = pos >> 8;
params->video_cursor_y = pos & 0xff;
params->video_width = grub_term_width (term);
params->video_height = grub_term_height (term);
found = 1;
}
if (grub_strcmp (term->name, "ofconsole") == 0)
{
grub_uint16_t pos = grub_term_getxy (term);
params->video_cursor_x = pos >> 8;
params->video_cursor_y = pos & 0xff;
params->video_width = grub_term_width (term);
params->video_height = grub_term_height (term);
found = 1;
break;
}
if (!found)
{
params->video_cursor_x = 0;
params->video_cursor_y = 0;
params->video_width = 80;
params->video_height = 25;
params->video_cursor_x = 0;
params->video_cursor_y = 0;
params->video_width = 80;
params->video_height = 25;
}
}
params->font_size = 16;
params->ofw_signature = GRUB_LINUX_OFW_SIGNATURE;
@ -195,7 +187,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
{
grub_error (GRUB_ERR_READ_ERROR, "cannot read the linux header");
grub_error (GRUB_ERR_READ_ERROR, "cannot read the Linux header");
goto fail;
}
@ -306,9 +298,9 @@ static grub_command_t cmd_linux, cmd_initrd;
GRUB_MOD_INIT(linux)
{
cmd_linux = grub_register_command ("linux", grub_cmd_linux,
0, "Load Linux.");
0, N_("Load Linux."));
cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd,
0, "Load initrd.");
0, N_("Load initrd."));
my_mod = mod;
}

View file

@ -1,6 +1,6 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 2006,2007,2008,2009,2010 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
@ -34,6 +34,7 @@
#include <grub/command.h>
#include <grub/i386/pc/vbe.h>
#include <grub/i386/pc/console.h>
#include <grub/i18n.h>
#define GRUB_LINUX_CL_OFFSET 0x1000
#define GRUB_LINUX_CL_END_OFFSET 0x2000
@ -518,11 +519,9 @@ grub_linux_boot (void)
May change in future if we have modes without framebuffer. */
if (modevar && *modevar != 0)
{
tmp = grub_malloc (grub_strlen (modevar)
+ sizeof (";text"));
tmp = grub_xasprintf ("%s;text", modevar);
if (! tmp)
return grub_errno;
grub_sprintf (tmp, "%s;text", modevar);
err = grub_video_set_mode (tmp, 0, 0);
grub_free (tmp);
}
@ -537,35 +536,32 @@ grub_linux_boot (void)
}
if (! grub_linux_setup_video (params))
params->have_vga = GRUB_VIDEO_TYPE_VLFB;
{
/* Use generic framebuffer unless VESA is known to be supported. */
if (params->have_vga != GRUB_VIDEO_LINUX_TYPE_VESA)
params->have_vga = GRUB_VIDEO_LINUX_TYPE_SIMPLE;
}
else
{
params->have_vga = GRUB_VIDEO_TYPE_TEXT;
params->have_vga = GRUB_VIDEO_LINUX_TYPE_TEXT;
params->video_width = 80;
params->video_height = 25;
}
/* Initialize these last, because terminal position could be affected by printfs above. */
if (params->have_vga == GRUB_VIDEO_TYPE_TEXT)
if (params->have_vga == GRUB_VIDEO_LINUX_TYPE_TEXT)
{
grub_term_output_t term;
int found = 0;
FOR_ACTIVE_TERM_OUTPUTS(term)
if (grub_strcmp (term->name, "vga_text") == 0)
{
grub_uint16_t pos = grub_term_getxy (term);
params->video_cursor_x = pos >> 8;
params->video_cursor_y = pos & 0xff;
found = 1;
}
if (!found)
FOR_ACTIVE_TERM_OUTPUTS(term)
if (grub_strcmp (term->name, "console") == 0)
if (grub_strcmp (term->name, "vga_text") == 0
|| grub_strcmp (term->name, "console") == 0)
{
grub_uint16_t pos = grub_term_getxy (term);
params->video_cursor_x = pos >> 8;
params->video_cursor_y = pos & 0xff;
found = 1;
break;
}
if (!found)
{
@ -636,7 +632,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
{
grub_error (GRUB_ERR_READ_ERROR, "cannot read the linux header");
grub_error (GRUB_ERR_READ_ERROR, "cannot read the Linux header");
goto fail;
}
@ -735,8 +731,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
grub_file_seek (file, real_size + GRUB_DISK_SECTOR_SIZE);
grub_printf (" [Linux-bzImage, setup=0x%x, size=0x%x]\n",
(unsigned) real_size, (unsigned) prot_size);
grub_dprintf ("linux", "bzImage, setup=0x%x, size=0x%x\n",
(unsigned) real_size, (unsigned) prot_size);
/* Look for memory size and video mode specified on the command line. */
linux_mem_size = 0;
@ -802,19 +798,22 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
break;
}
buf = grub_malloc (sizeof ("WWWWxHHHHxDD;WWWWxHHHH"));
if (! buf)
goto fail;
/* We can't detect VESA, but user is implicitly telling us that it
is built-in because `vga=' parameter was used. */
params->have_vga = GRUB_VIDEO_LINUX_TYPE_VESA;
linux_mode
= &linux_vesafb_modes[vid_mode - GRUB_LINUX_VID_MODE_VESA_START];
grub_sprintf (buf, "%ux%ux%u,%ux%u",
linux_vesafb_res[linux_mode->res_index].width,
linux_vesafb_res[linux_mode->res_index].height,
linux_mode->depth,
linux_vesafb_res[linux_mode->res_index].width,
linux_vesafb_res[linux_mode->res_index].height);
buf = grub_xasprintf ("%ux%ux%u,%ux%u",
linux_vesafb_res[linux_mode->res_index].width,
linux_vesafb_res[linux_mode->res_index].height,
linux_mode->depth,
linux_vesafb_res[linux_mode->res_index].width,
linux_vesafb_res[linux_mode->res_index].height);
if (! buf)
goto fail;
grub_printf ("%s is deprecated. "
"Use set gfxpayload=%s before "
"linux command instead.\n",
@ -986,8 +985,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
goto fail;
}
grub_printf (" [Initrd, addr=0x%x, size=0x%x]\n",
(unsigned) addr, (unsigned) size);
grub_dprintf ("linux", "Initrd, addr=0x%x, size=0x%x\n",
(unsigned) addr, (unsigned) size);
lh->ramdisk_image = addr;
lh->ramdisk_size = size;
@ -1005,9 +1004,9 @@ static grub_command_t cmd_linux, cmd_initrd;
GRUB_MOD_INIT(linux)
{
cmd_linux = grub_register_command ("linux", grub_cmd_linux,
0, "Load Linux.");
0, N_("Load Linux."));
cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd,
0, "Load initrd.");
0, N_("Load initrd."));
my_mod = mod;
}

View file

@ -1,7 +1,7 @@
/* multiboot.c - boot a multiboot OS image. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 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
@ -27,11 +27,12 @@
* - APM table
*/
/* The bits in the required part of flags field we don't support. */
#define UNSUPPORTED_FLAGS 0x0000fff8
#include <grub/loader.h>
#include <grub/machine/loader.h>
#include <grub/multiboot.h>
#include <grub/machine/init.h>
#include <grub/machine/memory.h>
#include <grub/cpu/multiboot.h>
#include <grub/elf.h>
#include <grub/aout.h>
@ -42,31 +43,29 @@
#include <grub/misc.h>
#include <grub/gzio.h>
#include <grub/env.h>
#ifdef GRUB_MACHINE_PCBIOS
#include <grub/machine/biosnum.h>
#include <grub/disk.h>
#include <grub/device.h>
#include <grub/partition.h>
#endif
#include <grub/i386/relocator.h>
#include <grub/video.h>
#ifdef GRUB_MACHINE_EFI
#include <grub/efi/efi.h>
#endif
extern grub_dl_t my_mod;
static struct multiboot_info *mbi, *mbi_dest;
static grub_size_t code_size;
static grub_size_t code_size, alloc_mbi;
char *grub_multiboot_payload_orig;
grub_addr_t grub_multiboot_payload_dest;
grub_size_t grub_multiboot_payload_size;
grub_size_t grub_multiboot_pure_size;
grub_uint32_t grub_multiboot_payload_eip;
static grub_err_t
grub_multiboot_boot (void)
{
grub_size_t mbi_size;
grub_err_t err;
struct grub_relocator32_state state =
{
.eax = MULTIBOOT_BOOTLOADER_MAGIC,
.ebx = PTR_TO_UINT32 (mbi_dest),
.ecx = 0,
.edx = 0,
.eip = grub_multiboot_payload_eip,
@ -75,6 +74,29 @@ grub_multiboot_boot (void)
.esp = 0x7ff00
};
mbi_size = grub_multiboot_get_mbi_size ();
if (alloc_mbi < mbi_size)
{
grub_multiboot_payload_orig
= grub_relocator32_realloc (grub_multiboot_payload_orig,
grub_multiboot_pure_size + mbi_size);
if (!grub_multiboot_payload_orig)
return grub_errno;
alloc_mbi = mbi_size;
}
state.ebx = grub_multiboot_payload_dest + grub_multiboot_pure_size;
err = grub_multiboot_make_mbi (grub_multiboot_payload_orig,
grub_multiboot_payload_dest,
grub_multiboot_pure_size, mbi_size);
if (err)
return err;
#ifdef GRUB_MACHINE_EFI
if (! grub_efi_finish_boot_services ())
grub_fatal ("cannot exit boot services");
#endif
grub_relocator32_boot (grub_multiboot_payload_orig,
grub_multiboot_payload_dest,
state);
@ -86,69 +108,18 @@ grub_multiboot_boot (void)
static grub_err_t
grub_multiboot_unload (void)
{
if (mbi)
{
unsigned int i;
for (i = 0; i < mbi->mods_count; i++)
{
grub_free ((void *)
((struct multiboot_mod_list *) mbi->mods_addr)[i].mod_start);
grub_free ((void *)
((struct multiboot_mod_list *) mbi->mods_addr)[i].cmdline);
}
grub_free ((void *) mbi->mods_addr);
}
grub_multiboot_free_mbi ();
grub_relocator32_free (grub_multiboot_payload_orig);
mbi = NULL;
alloc_mbi = 0;
grub_multiboot_payload_orig = NULL;
grub_dl_unref (my_mod);
return GRUB_ERR_NONE;
}
/* Return the length of the Multiboot mmap that will be needed to allocate
our platform's map. */
static grub_uint32_t
grub_get_multiboot_mmap_len (void)
{
grub_size_t count = 0;
auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t);
int NESTED_FUNC_ATTR hook (grub_uint64_t addr __attribute__ ((unused)),
grub_uint64_t size __attribute__ ((unused)),
grub_uint32_t type __attribute__ ((unused)))
{
count++;
return 0;
}
grub_mmap_iterate (hook);
return count * sizeof (struct multiboot_mmap_entry);
}
/* Fill previously allocated Multiboot mmap. */
static void
grub_fill_multiboot_mmap (struct multiboot_mmap_entry *first_entry)
{
struct multiboot_mmap_entry *mmap_entry = (struct multiboot_mmap_entry *) first_entry;
auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t);
int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type)
{
mmap_entry->addr = addr;
mmap_entry->len = size;
mmap_entry->type = type;
mmap_entry->size = sizeof (struct multiboot_mmap_entry) - sizeof (mmap_entry->size);
mmap_entry++;
return 0;
}
grub_mmap_iterate (hook);
}
#define MULTIBOOT_LOAD_ELF64
#include "multiboot_elfxx.c"
#undef MULTIBOOT_LOAD_ELF64
@ -169,58 +140,13 @@ grub_multiboot_load_elf (grub_file_t file, void *buffer)
return grub_error (GRUB_ERR_UNKNOWN_OS, "unknown ELF class");
}
static int
grub_multiboot_get_bootdev (grub_uint32_t *bootdev)
{
#ifdef GRUB_MACHINE_PCBIOS
char *p;
grub_uint32_t biosdev, slice = ~0, part = ~0;
grub_device_t dev;
biosdev = grub_get_root_biosnumber ();
dev = grub_device_open (0);
if (dev && dev->disk && dev->disk->partition)
{
p = dev->disk->partition->partmap->get_name (dev->disk->partition);
if (p)
{
if ((p[0] >= '0') && (p[0] <= '9'))
{
slice = grub_strtoul (p, &p, 0) - 1;
if ((p) && (p[0] == ','))
p++;
}
if ((p[0] >= 'a') && (p[0] <= 'z'))
part = p[0] - 'a';
}
}
if (dev)
grub_device_close (dev);
*bootdev = ((biosdev & 0xff) << 24) | ((slice & 0xff) << 16)
| ((part & 0xff) << 8) | 0xff;
return (biosdev != ~0UL);
#else
*bootdev = 0xffffffff;
return 0;
#endif
}
void
grub_multiboot (int argc, char *argv[])
{
grub_file_t file = 0;
char buffer[MULTIBOOT_SEARCH], *cmdline = 0, *p;
char buffer[MULTIBOOT_SEARCH];
struct multiboot_header *header;
grub_ssize_t len, cmdline_length, boot_loader_name_length;
grub_uint32_t mmap_length;
int i;
int cmdline_argc;
char **cmdline_argv;
grub_ssize_t len;
grub_loader_unset ();
@ -261,7 +187,7 @@ grub_multiboot (int argc, char *argv[])
goto fail;
}
if (header->flags & MULTIBOOT_UNSUPPORTED)
if (header->flags & UNSUPPORTED_FLAGS)
{
grub_error (GRUB_ERR_UNKNOWN_OS,
"unsupported flag: 0x%x", header->flags);
@ -271,31 +197,8 @@ grub_multiboot (int argc, char *argv[])
grub_relocator32_free (grub_multiboot_payload_orig);
grub_multiboot_payload_orig = NULL;
mmap_length = grub_get_multiboot_mmap_len ();
/* Figure out cmdline length. */
/* Skip filename. */
cmdline_argc = argc - 1;
cmdline_argv = argv + 1;
for (i = 0, cmdline_length = 0; i < cmdline_argc; i++)
cmdline_length += grub_strlen (cmdline_argv[i]) + 1;
if (cmdline_length == 0)
cmdline_length = 1;
boot_loader_name_length = sizeof(PACKAGE_STRING);
#define cmdline_addr(x) ((void *) ((x) + code_size))
#define boot_loader_name_addr(x) \
((void *) ((x) + code_size + cmdline_length))
#define mbi_addr(x) ((void *) ((x) + code_size + cmdline_length + boot_loader_name_length))
#define mmap_addr(x) ((void *) ((x) + code_size + cmdline_length + boot_loader_name_length + sizeof (struct multiboot_info)))
grub_multiboot_payload_size = cmdline_length
/* boot_loader_name_length might need to grow for mbi,etc to be aligned (see below) */
+ boot_loader_name_length + 3
+ sizeof (struct multiboot_info) + mmap_length;
grub_multiboot_init_mbi (argc - 1, argv + 1);
if (header->flags & MULTIBOOT_AOUT_KLUDGE)
{
@ -310,10 +213,12 @@ grub_multiboot (int argc, char *argv[])
code_size = load_size;
grub_multiboot_payload_dest = header->load_addr;
grub_multiboot_payload_size += code_size;
grub_multiboot_pure_size += code_size;
/* Allocate a bit more to avoid relocations in most cases. */
alloc_mbi = grub_multiboot_get_mbi_size () + 65536;
grub_multiboot_payload_orig
= grub_relocator32_alloc (grub_multiboot_payload_size);
= grub_relocator32_alloc (grub_multiboot_pure_size + alloc_mbi);
if (! grub_multiboot_payload_orig)
goto fail;
@ -335,53 +240,40 @@ grub_multiboot (int argc, char *argv[])
else if (grub_multiboot_load_elf (file, buffer) != GRUB_ERR_NONE)
goto fail;
/* This provides alignment for the MBI, the memory map and the backward relocator. */
boot_loader_name_length += (0x04 - ((unsigned long) mbi_addr (grub_multiboot_payload_dest) & 0x03));
mbi = mbi_addr (grub_multiboot_payload_orig);
mbi_dest = mbi_addr (grub_multiboot_payload_dest);
grub_memset (mbi, 0, sizeof (struct multiboot_info));
mbi->mmap_length = mmap_length;
grub_fill_multiboot_mmap (mmap_addr (grub_multiboot_payload_orig));
/* FIXME: grub_uint32_t will break for addresses above 4 GiB, but is mandated
by the spec. Is there something we can do about it? */
mbi->mmap_addr = (grub_uint32_t) mmap_addr (grub_multiboot_payload_dest);
mbi->flags |= MULTIBOOT_INFO_MEM_MAP;
/* Convert from bytes to kilobytes. */
mbi->mem_lower = grub_mmap_get_lower () / 1024;
mbi->mem_upper = grub_mmap_get_upper () / 1024;
mbi->flags |= MULTIBOOT_INFO_MEMORY;
cmdline = p = cmdline_addr (grub_multiboot_payload_orig);
if (! cmdline)
goto fail;
for (i = 0; i < cmdline_argc; i++)
if (header->flags & MULTIBOOT_VIDEO_MODE)
{
p = grub_stpcpy (p, cmdline_argv[i]);
*(p++) = ' ';
switch (header->mode_type)
{
case 1:
grub_env_set ("gfxpayload", "text");
break;
case 0:
{
char *buf;
if (header->depth && header->width && header->height)
buf = grub_xasprintf ("%dx%dx%d,%dx%d,auto", header->width,
header->height, header->depth, header->width,
header->height);
else if (header->width && header->height)
buf = grub_xasprintf ("%dx%d,auto", header->width, header->height);
else
buf = grub_strdup ("auto");
if (!buf)
goto fail;
grub_env_set ("gfxpayload", buf);
grub_free (buf);
break;
}
}
}
/* Remove the space after the last word. */
if (p != cmdline)
p--;
*p = 0;
grub_multiboot_set_accepts_video (!!(header->flags & MULTIBOOT_VIDEO_MODE));
mbi->flags |= MULTIBOOT_INFO_CMDLINE;
mbi->cmdline = (grub_uint32_t) cmdline_addr (grub_multiboot_payload_dest);
grub_multiboot_set_bootdev ();
grub_strcpy (boot_loader_name_addr (grub_multiboot_payload_orig), PACKAGE_STRING);
mbi->flags |= MULTIBOOT_INFO_BOOT_LOADER_NAME;
mbi->boot_loader_name = (grub_uint32_t) boot_loader_name_addr (grub_multiboot_payload_dest);
if (grub_multiboot_get_bootdev (&mbi->boot_device))
mbi->flags |= MULTIBOOT_INFO_BOOTDEV;
grub_loader_set (grub_multiboot_boot, grub_multiboot_unload, 1);
grub_loader_set (grub_multiboot_boot, grub_multiboot_unload, 0);
fail:
if (file)
@ -389,22 +281,18 @@ grub_multiboot (int argc, char *argv[])
if (grub_errno != GRUB_ERR_NONE)
{
grub_free (cmdline);
grub_free (mbi);
grub_relocator32_free (grub_multiboot_payload_orig);
grub_dl_unref (my_mod);
}
}
void
grub_module (int argc, char *argv[])
{
grub_file_t file = 0;
grub_ssize_t size, len = 0;
char *module = 0, *cmdline = 0, *p;
int i;
int cmdline_argc;
char **cmdline_argv;
grub_ssize_t size;
char *module = 0;
grub_err_t err;
if (argc == 0)
{
@ -412,7 +300,7 @@ grub_module (int argc, char *argv[])
goto fail;
}
if (!mbi)
if (!grub_multiboot_payload_orig)
{
grub_error (GRUB_ERR_BAD_ARGUMENT,
"you need to load the multiboot kernel first");
@ -428,73 +316,19 @@ grub_module (int argc, char *argv[])
if (! module)
goto fail;
err = grub_multiboot_add_module ((grub_addr_t) module, size,
argc - 1, argv + 1);
if (err)
goto fail;
if (grub_file_read (file, module, size) != size)
{
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
goto fail;
}
/* Skip module name. */
cmdline_argc = argc - 1;
cmdline_argv = argv + 1;
for (i = 0; i < cmdline_argc; i++)
len += grub_strlen (cmdline_argv[i]) + 1;
if (len == 0)
len = 1;
cmdline = p = grub_malloc (len);
if (! cmdline)
goto fail;
for (i = 0; i < cmdline_argc; i++)
{
p = grub_stpcpy (p, cmdline_argv[i]);
*(p++) = ' ';
}
/* Remove the space after the last word. */
if (p != cmdline)
p--;
*p = '\0';
if (mbi->flags & MULTIBOOT_INFO_MODS)
{
struct multiboot_mod_list *modlist = (struct multiboot_mod_list *) mbi->mods_addr;
modlist = grub_realloc (modlist, (mbi->mods_count + 1)
* sizeof (struct multiboot_mod_list));
if (! modlist)
goto fail;
mbi->mods_addr = (grub_uint32_t) modlist;
modlist += mbi->mods_count;
modlist->mod_start = (grub_uint32_t) module;
modlist->mod_end = (grub_uint32_t) module + size;
modlist->cmdline = (grub_uint32_t) cmdline;
modlist->pad = 0;
mbi->mods_count++;
}
else
{
struct multiboot_mod_list *modlist = grub_zalloc (sizeof (struct multiboot_mod_list));
if (! modlist)
goto fail;
modlist->mod_start = (grub_uint32_t) module;
modlist->mod_end = (grub_uint32_t) module + size;
modlist->cmdline = (grub_uint32_t) cmdline;
mbi->mods_count = 1;
mbi->mods_addr = (grub_uint32_t) modlist;
mbi->flags |= MULTIBOOT_INFO_MODS;
}
fail:
if (file)
grub_file_close (file);
if (grub_errno != GRUB_ERR_NONE)
{
grub_free (module);
grub_free (cmdline);
}
}

View file

@ -100,10 +100,11 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer)
code_size = (phdr(highest_segment)->p_paddr + phdr(highest_segment)->p_memsz) - phdr(lowest_segment)->p_paddr;
grub_multiboot_payload_dest = phdr(lowest_segment)->p_paddr;
grub_multiboot_payload_size += code_size;
grub_multiboot_pure_size += code_size;
alloc_mbi = grub_multiboot_get_mbi_size ();
grub_multiboot_payload_orig
= grub_relocator32_alloc (grub_multiboot_payload_size);
= grub_relocator32_alloc (grub_multiboot_pure_size + alloc_mbi + 65536);
if (!grub_multiboot_payload_orig)
return grub_errno;

View file

@ -1,43 +0,0 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/symbol.h>
#include <multiboot.h>
#include <multiboot2.h>
.p2align 2 /* force 4-byte alignment */
/*
* This starts the multiboot 2 kernel.
*/
FUNCTION(grub_multiboot2_real_boot)
/* Push the entry address on the stack. */
pushl %eax
/* Move the address of the multiboot information structure to ebx. */
movl %edx,%ebx
/* Interrupts should be disabled. */
cli
/* Move the magic value into eax and jump to the kernel. */
movl $MULTIBOOT2_BOOTLOADER_MAGIC,%eax
popl %ecx
cld
jmp *%ecx

473
loader/i386/multiboot_mbi.c Normal file
View file

@ -0,0 +1,473 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/machine/memory.h>
#include <grub/memory.h>
#ifdef GRUB_MACHINE_PCBIOS
#include <grub/machine/biosnum.h>
#endif
#include <grub/multiboot.h>
#include <grub/cpu/multiboot.h>
#include <grub/disk.h>
#include <grub/device.h>
#include <grub/partition.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/env.h>
#include <grub/video.h>
#if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU)
#include <grub/i386/pc/vbe.h>
#define DEFAULT_VIDEO_MODE "text"
#define HAS_VGA_TEXT 1
#else
#define DEFAULT_VIDEO_MODE "auto"
#define HAS_VGA_TEXT 0
#endif
struct module
{
struct module *next;
grub_addr_t start;
grub_size_t size;
char *cmdline;
int cmdline_size;
};
struct module *modules, *modules_last;
static grub_size_t cmdline_size;
static grub_size_t total_modcmd;
static unsigned modcnt;
static char *cmdline = NULL;
static grub_uint32_t bootdev;
static int bootdev_set;
static int accepts_video;
void
grub_multiboot_set_accepts_video (int val)
{
accepts_video = val;
}
/* Return the length of the Multiboot mmap that will be needed to allocate
our platform's map. */
static grub_uint32_t
grub_get_multiboot_mmap_len (void)
{
grub_size_t count = 0;
auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t);
int NESTED_FUNC_ATTR hook (grub_uint64_t addr __attribute__ ((unused)),
grub_uint64_t size __attribute__ ((unused)),
grub_uint32_t type __attribute__ ((unused)))
{
count++;
return 0;
}
grub_mmap_iterate (hook);
return count * sizeof (struct multiboot_mmap_entry);
}
grub_size_t
grub_multiboot_get_mbi_size (void)
{
return sizeof (struct multiboot_info) + ALIGN_UP (cmdline_size, 4)
+ modcnt * sizeof (struct multiboot_mod_list) + total_modcmd
+ ALIGN_UP (sizeof(PACKAGE_STRING), 4) + grub_get_multiboot_mmap_len ()
+ 256 * sizeof (struct multiboot_color);
}
/* Fill previously allocated Multiboot mmap. */
static void
grub_fill_multiboot_mmap (struct multiboot_mmap_entry *first_entry)
{
struct multiboot_mmap_entry *mmap_entry = (struct multiboot_mmap_entry *) first_entry;
auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t);
int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type)
{
mmap_entry->addr = addr;
mmap_entry->len = size;
switch (type)
{
case GRUB_MACHINE_MEMORY_AVAILABLE:
mmap_entry->type = MULTIBOOT_MEMORY_AVAILABLE;
break;
#ifdef GRUB_MACHINE_MEMORY_ACPI_RECLAIMABLE
case GRUB_MACHINE_MEMORY_ACPI_RECLAIMABLE:
mmap_entry->type = MULTIBOOT_MEMORY_ACPI_RECLAIMABLE;
break;
#endif
#ifdef GRUB_MACHINE_MEMORY_NVS
case GRUB_MACHINE_MEMORY_NVS:
mmap_entry->type = MULTIBOOT_MEMORY_NVS;
break;
#endif
default:
mmap_entry->type = MULTIBOOT_MEMORY_RESERVED;
break;
}
mmap_entry->size = sizeof (struct multiboot_mmap_entry) - sizeof (mmap_entry->size);
mmap_entry++;
return 0;
}
grub_mmap_iterate (hook);
}
static grub_err_t
set_video_mode (void)
{
grub_err_t err;
const char *modevar;
if (accepts_video || !HAS_VGA_TEXT)
{
modevar = grub_env_get ("gfxpayload");
if (! modevar || *modevar == 0)
err = grub_video_set_mode (DEFAULT_VIDEO_MODE, 0, 0);
else
{
char *tmp;
tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar);
if (! tmp)
return grub_errno;
err = grub_video_set_mode (tmp, 0, 0);
grub_free (tmp);
}
}
else
err = grub_video_set_mode ("text", 0, 0);
return err;
}
static grub_err_t
retrieve_video_parameters (struct multiboot_info *mbi,
grub_uint8_t *ptrorig, grub_uint32_t ptrdest)
{
grub_err_t err;
struct grub_video_mode_info mode_info;
void *framebuffer;
grub_video_driver_id_t driv_id;
struct grub_video_palette_data palette[256];
err = set_video_mode ();
if (err)
{
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
}
grub_video_get_palette (0, ARRAY_SIZE (palette), palette);
driv_id = grub_video_get_driver_id ();
if (driv_id == GRUB_VIDEO_DRIVER_NONE)
return GRUB_ERR_NONE;
err = grub_video_get_info_and_fini (&mode_info, &framebuffer);
if (err)
return err;
mbi->framebuffer_addr = (grub_addr_t) framebuffer;
mbi->framebuffer_pitch = mode_info.pitch;
mbi->framebuffer_width = mode_info.width;
mbi->framebuffer_height = mode_info.height;
mbi->framebuffer_bpp = mode_info.bpp;
if (mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_INDEX_COLOR)
{
struct multiboot_color *mb_palette;
unsigned i;
mbi->framebuffer_type = MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED;
mbi->framebuffer_palette_addr = ptrdest;
mbi->framebuffer_palette_num_colors = mode_info.number_of_colors;
if (mbi->framebuffer_palette_num_colors > ARRAY_SIZE (palette))
mbi->framebuffer_palette_num_colors = ARRAY_SIZE (palette);
mb_palette = (struct multiboot_color *) ptrorig;
for (i = 0; i < mbi->framebuffer_palette_num_colors; i++)
{
mb_palette[i].red = palette[i].r;
mb_palette[i].green = palette[i].g;
mb_palette[i].blue = palette[i].b;
}
ptrorig += mbi->framebuffer_palette_num_colors
* sizeof (struct multiboot_color);
ptrdest += mbi->framebuffer_palette_num_colors
* sizeof (struct multiboot_color);
}
else
{
mbi->framebuffer_type = MULTIBOOT_FRAMEBUFFER_TYPE_RGB;
mbi->framebuffer_red_field_position = mode_info.green_field_pos;
mbi->framebuffer_red_mask_size = mode_info.green_mask_size;
mbi->framebuffer_green_field_position = mode_info.green_field_pos;
mbi->framebuffer_green_mask_size = mode_info.green_mask_size;
mbi->framebuffer_blue_field_position = mode_info.blue_field_pos;
mbi->framebuffer_blue_mask_size = mode_info.blue_mask_size;
}
mbi->flags |= MULTIBOOT_INFO_FRAMEBUFFER_INFO;
return GRUB_ERR_NONE;
}
grub_err_t
grub_multiboot_make_mbi (void *orig, grub_uint32_t dest, grub_off_t buf_off,
grub_size_t bufsize)
{
grub_uint8_t *ptrorig = (grub_uint8_t *) orig + buf_off;
grub_uint32_t ptrdest = dest + buf_off;
struct multiboot_info *mbi;
struct multiboot_mod_list *modlist;
unsigned i;
struct module *cur;
grub_size_t mmap_size;
grub_err_t err;
if (bufsize < grub_multiboot_get_mbi_size ())
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "mbi buffer is too small");
mbi = (struct multiboot_info *) ptrorig;
ptrorig += sizeof (*mbi);
ptrdest += sizeof (*mbi);
grub_memset (mbi, 0, sizeof (*mbi));
grub_memcpy (ptrorig, cmdline, cmdline_size);
mbi->flags |= MULTIBOOT_INFO_CMDLINE;
mbi->cmdline = ptrdest;
ptrorig += ALIGN_UP (cmdline_size, 4);
ptrdest += ALIGN_UP (cmdline_size, 4);
grub_memcpy (ptrorig, PACKAGE_STRING, sizeof(PACKAGE_STRING));
mbi->flags |= MULTIBOOT_INFO_BOOT_LOADER_NAME;
mbi->boot_loader_name = ptrdest;
ptrorig += ALIGN_UP (sizeof(PACKAGE_STRING), 4);
ptrdest += ALIGN_UP (sizeof(PACKAGE_STRING), 4);
if (modcnt)
{
mbi->flags |= MULTIBOOT_INFO_MODS;
mbi->mods_addr = ptrdest;
mbi->mods_count = modcnt;
modlist = (struct multiboot_mod_list *) ptrorig;
ptrorig += modcnt * sizeof (struct multiboot_mod_list);
ptrdest += modcnt * sizeof (struct multiboot_mod_list);
for (i = 0, cur = modules; i < modcnt; i++, cur = cur->next)
{
modlist[i].mod_start = cur->start;
modlist[i].mod_end = modlist[i].mod_start + cur->size;
modlist[i].cmdline = ptrdest;
grub_memcpy (ptrorig, cur->cmdline, cur->cmdline_size);
ptrorig += ALIGN_UP (cur->cmdline_size, 4);
ptrdest += ALIGN_UP (cur->cmdline_size, 4);
}
}
else
{
mbi->mods_addr = 0;
mbi->mods_count = 0;
}
mmap_size = grub_get_multiboot_mmap_len ();
grub_fill_multiboot_mmap ((struct multiboot_mmap_entry *) ptrorig);
mbi->mmap_length = mmap_size;
mbi->mmap_addr = ptrdest;
mbi->flags |= MULTIBOOT_INFO_MEM_MAP;
ptrorig += mmap_size;
ptrdest += mmap_size;
/* Convert from bytes to kilobytes. */
mbi->mem_lower = grub_mmap_get_lower () / 1024;
mbi->mem_upper = grub_mmap_get_upper () / 1024;
mbi->flags |= MULTIBOOT_INFO_MEMORY;
if (bootdev_set)
{
mbi->boot_device = bootdev;
mbi->flags |= MULTIBOOT_INFO_BOOTDEV;
}
err = retrieve_video_parameters (mbi, ptrorig, ptrdest);
if (err)
{
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
}
return GRUB_ERR_NONE;
}
void
grub_multiboot_free_mbi (void)
{
struct module *cur, *next;
cmdline_size = 0;
total_modcmd = 0;
modcnt = 0;
grub_free (cmdline);
cmdline = NULL;
bootdev_set = 0;
for (cur = modules; cur; cur = next)
{
next = cur->next;
grub_free (cur->cmdline);
grub_free (cur);
}
modules = NULL;
modules_last = NULL;
}
grub_err_t
grub_multiboot_init_mbi (int argc, char *argv[])
{
grub_ssize_t len = 0;
char *p;
int i;
grub_multiboot_free_mbi ();
for (i = 0; i < argc; i++)
len += grub_strlen (argv[i]) + 1;
if (len == 0)
len = 1;
cmdline = p = grub_malloc (len);
if (! cmdline)
return grub_errno;
cmdline_size = len;
for (i = 0; i < argc; i++)
{
p = grub_stpcpy (p, argv[i]);
*(p++) = ' ';
}
/* Remove the space after the last word. */
if (p != cmdline)
p--;
*p = '\0';
return GRUB_ERR_NONE;
}
grub_err_t
grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
int argc, char *argv[])
{
struct module *newmod;
char *p;
grub_ssize_t len = 0;
int i;
newmod = grub_malloc (sizeof (*newmod));
if (!newmod)
return grub_errno;
newmod->start = start;
newmod->size = size;
for (i = 0; i < argc; i++)
len += grub_strlen (argv[i]) + 1;
if (len == 0)
len = 1;
newmod->cmdline = p = grub_malloc (len);
if (! newmod->cmdline)
{
grub_free (newmod);
return grub_errno;
}
newmod->cmdline_size = len;
total_modcmd += ALIGN_UP (len, 4);
for (i = 0; i < argc; i++)
{
p = grub_stpcpy (p, argv[i]);
*(p++) = ' ';
}
/* Remove the space after the last word. */
if (p != newmod->cmdline)
p--;
*p = '\0';
if (modules_last)
modules_last->next = newmod;
else
{
modules = newmod;
modules_last->next = NULL;
}
modules_last = newmod;
modcnt++;
return GRUB_ERR_NONE;
}
void
grub_multiboot_set_bootdev (void)
{
char *p;
grub_uint32_t biosdev, slice = ~0, part = ~0;
grub_device_t dev;
#ifdef GRUB_MACHINE_PCBIOS
biosdev = grub_get_root_biosnumber ();
#else
biosdev = 0xffffffff;
#endif
dev = grub_device_open (0);
if (dev && dev->disk && dev->disk->partition)
{
p = dev->disk->partition->partmap->get_name (dev->disk->partition);
if (p)
{
if ((p[0] >= '0') && (p[0] <= '9'))
{
slice = grub_strtoul (p, &p, 0) - 1;
if ((p) && (p[0] == ','))
p++;
}
if ((p[0] >= 'a') && (p[0] <= 'z'))
part = p[0] - 'a';
}
}
if (dev)
grub_device_close (dev);
bootdev = ((biosdev & 0xff) << 24) | ((slice & 0xff) << 16)
| ((part & 0xff) << 8) | 0xff;
bootdev_set = 1;
}

View file

@ -1,7 +1,7 @@
/* chainloader.c - boot another boot loader */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2004,2007,2009 Free Software Foundation, Inc.
* Copyright (C) 2002,2004,2007,2009,2010 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
@ -32,6 +32,9 @@
#include <grub/dl.h>
#include <grub/command.h>
#include <grub/machine/biosnum.h>
#include <grub/i18n.h>
#include <grub/video.h>
#include <grub/mm.h>
static grub_dl_t my_mod;
static int boot_drive;
@ -40,6 +43,7 @@ static void *boot_part_addr;
static grub_err_t
grub_chainloader_boot (void)
{
grub_video_set_mode ("text", 0, 0);
grub_chainloader_real_boot (boot_drive, boot_part_addr);
/* Never reach here. */
@ -146,7 +150,7 @@ static grub_command_t cmd;
GRUB_MOD_INIT(chainloader)
{
cmd = grub_register_command ("chainloader", grub_cmd_chainloader,
0, "Load another boot loader.");
0, N_("Load another boot loader."));
my_mod = mod;
}

View file

@ -1,7 +1,7 @@
/* linux.c - boot Linux zImage or bzImage */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 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
@ -30,6 +30,9 @@
#include <grub/dl.h>
#include <grub/cpu/linux.h>
#include <grub/command.h>
#include <grub/i18n.h>
#include <grub/mm.h>
#include <grub/video.h>
#define GRUB_LINUX_CL_OFFSET 0x9000
#define GRUB_LINUX_CL_END_OFFSET 0x90FF
@ -47,6 +50,16 @@ grub_linux_unload (void)
return GRUB_ERR_NONE;
}
static grub_err_t
grub_linux16_boot (void)
{
grub_video_set_mode ("text", 0, 0);
grub_linux16_real_boot ();
/* Not reached. */
return GRUB_ERR_NONE;
}
static grub_err_t
grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
@ -81,7 +94,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
{
grub_error (GRUB_ERR_READ_ERROR, "cannot read the linux header");
grub_error (GRUB_ERR_READ_ERROR, "cannot read the Linux header");
goto fail;
}
@ -383,10 +396,10 @@ GRUB_MOD_INIT(linux16)
{
cmd_linux =
grub_register_command ("linux16", grub_cmd_linux,
0, "Load Linux.");
0, N_("Load Linux."));
cmd_initrd =
grub_register_command ("initrd16", grub_cmd_initrd,
0, "Load initrd.");
0, N_("Load initrd."));
my_mod = mod;
}

View file

@ -1,122 +0,0 @@
/* multiboot2.c - boot a multiboot 2 OS image. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/multiboot2.h>
#include <multiboot2.h>
#include <grub/elf.h>
#include <grub/err.h>
#include <grub/machine/loader.h>
#include <grub/mm.h>
#include <grub/multiboot.h>
#include <grub/cpu/multiboot.h>
grub_err_t
grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr,
grub_addr_t *addr __attribute__ ((unused)),
int *do_load)
{
Elf32_Addr paddr = phdr->p_paddr;
if (phdr->p_type != PT_LOAD)
{
*do_load = 0;
return 0;
}
*do_load = 1;
if ((paddr < grub_os_area_addr)
|| (paddr + phdr->p_memsz > grub_os_area_addr + grub_os_area_size))
return grub_error(GRUB_ERR_OUT_OF_RANGE,"address 0x%x is out of range",
paddr);
return GRUB_ERR_NONE;
}
grub_err_t
grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr,
grub_addr_t *addr __attribute__ ((unused)),
int *do_load)
{
Elf64_Addr paddr = phdr->p_paddr;
if (phdr->p_type != PT_LOAD)
{
*do_load = 0;
return 0;
}
*do_load = 1;
if ((paddr < grub_os_area_addr)
|| (paddr + phdr->p_memsz > grub_os_area_addr + grub_os_area_size))
return grub_error (GRUB_ERR_OUT_OF_RANGE, "address 0x%x is out of range",
paddr);
return GRUB_ERR_NONE;
}
grub_err_t
grub_mb2_arch_module_alloc (grub_size_t size, grub_addr_t *addr)
{
grub_addr_t modaddr;
modaddr = (grub_addr_t) grub_memalign (MULTIBOOT2_MOD_ALIGN, size);
if (! modaddr)
return grub_errno;
*addr = modaddr;
return GRUB_ERR_NONE;
}
grub_err_t
grub_mb2_arch_module_free (grub_addr_t addr,
grub_size_t size __attribute__ ((unused)))
{
grub_free((void *) addr);
return GRUB_ERR_NONE;
}
void
grub_mb2_arch_boot (grub_addr_t entry, void *tags)
{
grub_multiboot2_real_boot (entry, tags);
}
void
grub_mb2_arch_unload (struct multiboot2_tag_header *tags)
{
struct multiboot2_tag_header *tag;
/* Free all module memory in the tag list. */
for_each_tag (tag, tags)
{
if (tag->key == MULTIBOOT2_TAG_MODULE)
{
struct multiboot2_tag_module *module =
(struct multiboot2_tag_module *) tag;
grub_free((void *) module->addr);
}
}
}
grub_err_t
grub_mb2_tags_arch_create (void)
{
/* XXX Create boot device et al. */
return GRUB_ERR_NONE;
}

View file

@ -49,12 +49,10 @@ grub_xnu_set_video (struct grub_xnu_boot_params *params)
32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS);
else
{
tmp = grub_malloc (grub_strlen (modevar)
+ sizeof (DEFAULT_VIDEO_MODE) + 1);
tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar);
if (! tmp)
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't allocate temporary storag");
grub_sprintf (tmp, "%s;" DEFAULT_VIDEO_MODE, modevar);
err = grub_video_set_mode (tmp,
GRUB_VIDEO_MODE_TYPE_PURE_TEXT
| GRUB_VIDEO_MODE_TYPE_DEPTH_MASK,

View file

@ -32,6 +32,7 @@
#include <grub/term.h>
#include <grub/command.h>
#include <grub/gzio.h>
#include <grub/i18n.h>
char grub_xnu_cmdline[1024];
grub_uint32_t grub_xnu_heap_will_be_at;
@ -748,11 +749,13 @@ grub_cpu_xnu_fill_devicetree (void)
#endif
/* The name of key for new table. */
grub_sprintf (guidbuf, "%08x-%04x-%04x-%02x%02x-",
guid.data1, guid.data2, guid.data3, guid.data4[0],
guid.data4[1]);
grub_snprintf (guidbuf, sizeof (guidbuf), "%08x-%04x-%04x-%02x%02x-",
guid.data1, guid.data2, guid.data3, guid.data4[0],
guid.data4[1]);
for (j = 2; j < 8; j++)
grub_sprintf (guidbuf + grub_strlen (guidbuf), "%02x", guid.data4[j]);
grub_snprintf (guidbuf + grub_strlen (guidbuf),
sizeof (guidbuf) - grub_strlen (guidbuf),
"%02x", guid.data4[j]);
/* For some reason GUID has to be in uppercase. */
for (j = 0; guidbuf[j] ; j++)
if (guidbuf[j] >= 'a' && guidbuf[j] <= 'f')
@ -1026,7 +1029,7 @@ grub_cpu_xnu_init (void)
{
cmd_devprop_load = grub_register_command ("xnu_devprop_load",
grub_cmd_devprop_load,
0, "Load device-properties dump.");
0, N_("Load device-properties dump."));
}
void

View file

@ -1,147 +0,0 @@
/* multiboot.c - boot a multiboot 2 OS image. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/loader.h>
#include <grub/ieee1275/ieee1275.h>
#include <grub/multiboot2.h>
#include <multiboot2.h>
#include <grub/err.h>
#include <grub/elf.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/machine/kernel.h>
#include <grub/machine/loader.h>
#ifdef __i386__
#include <grub/cpu/multiboot.h>
#endif
typedef void (*kernel_entry_t) (unsigned long, void *, int (void *),
unsigned long, unsigned long);
/* Claim the memory occupied by the multiboot kernel. */
grub_err_t
grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr,
grub_addr_t *addr __attribute__((unused)),
int *do_load)
{
int rc;
if (phdr->p_type != PT_LOAD)
{
*do_load = 0;
return 0;
}
*do_load = 1;
rc = grub_claimmap (phdr->p_paddr, phdr->p_memsz);
if (rc)
return grub_error(GRUB_ERR_OUT_OF_MEMORY, "couldn't claim %x - %x",
phdr->p_paddr, phdr->p_paddr + phdr->p_memsz);
grub_dprintf ("loader", "Loading segment at 0x%x - 0x%x\n", phdr->p_paddr,
phdr->p_paddr + phdr->p_memsz);
return GRUB_ERR_NONE;
}
/* Claim the memory occupied by the multiboot kernel. */
grub_err_t
grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr,
grub_addr_t *addr __attribute__((unused)),
int *do_load)
{
int rc;
if (phdr->p_type != PT_LOAD)
{
*do_load = 0;
return 0;
}
*do_load = 1;
rc = grub_claimmap (phdr->p_paddr, phdr->p_memsz);
if (rc)
return grub_error(GRUB_ERR_OUT_OF_MEMORY, "couldn't claim 0x%lx - 0x%lx",
phdr->p_paddr, phdr->p_paddr + phdr->p_memsz);
grub_dprintf ("loader", "Loading segment at 0x%lx - 0x%lx\n",
(unsigned long) phdr->p_paddr,
(unsigned long) (phdr->p_paddr + phdr->p_memsz));
return GRUB_ERR_NONE;
}
grub_err_t
grub_mb2_arch_module_alloc (grub_size_t size, grub_addr_t *addr)
{
int rc;
/* XXX Will need to map on some firmwares. */
rc = grub_ieee1275_claim (0, size, MULTIBOOT2_MOD_ALIGN, addr);
if (rc)
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"firmware couldn't allocate memory (size 0x%lx)", size);
return GRUB_ERR_NONE;
}
grub_err_t
grub_mb2_arch_module_free (grub_addr_t addr, grub_size_t size)
{
grub_ieee1275_release (addr, size);
return GRUB_ERR_NONE;
}
grub_err_t
grub_mb2_tags_arch_create (void)
{
/* Nothing special. */
return GRUB_ERR_NONE;
}
/* Release the memory we claimed from Open Firmware above. */
void
grub_mb2_arch_unload (struct multiboot2_tag_header *tags)
{
struct multiboot2_tag_header *tag;
/* Free all module memory in the tag list. */
for_each_tag (tag, tags)
{
if (tag->key == MULTIBOOT2_TAG_MODULE)
{
struct multiboot2_tag_module *module =
(struct multiboot2_tag_module *) tag;
grub_ieee1275_release (module->addr, module->size);
}
}
}
void
grub_mb2_arch_boot (grub_addr_t entry_addr, void *tags)
{
#if defined(__powerpc__)
kernel_entry_t entry = (kernel_entry_t) entry_addr;
entry (MULTIBOOT2_BOOTLOADER_MAGIC, tags, grub_ieee1275_entry_fn, 0, 0);
#elif defined(__i386__)
grub_multiboot2_real_boot (entry_addr, tags);
#else
#error
#endif
}

398
loader/mips/linux.c Normal file
View file

@ -0,0 +1,398 @@
/* linux.c - boot Linux */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2004,2005,2007,2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/elf.h>
#include <grub/elfload.h>
#include <grub/loader.h>
#include <grub/dl.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/machine/loader.h>
#include <grub/command.h>
#include <grub/mips/relocator.h>
#include <grub/machine/memory.h>
#include <grub/i18n.h>
/* For frequencies. */
#include <grub/pci.h>
#include <grub/machine/time.h>
#define ELF32_LOADMASK (0x00000000UL)
#define ELF64_LOADMASK (0x0000000000000000ULL)
static grub_dl_t my_mod;
static int loaded;
static grub_size_t linux_size;
static grub_uint8_t *playground;
static grub_addr_t target_addr, entry_addr;
static int linux_argc;
static grub_off_t argv_off, envp_off;
static grub_off_t rd_addr_arg_off, rd_size_arg_off;
static int initrd_loaded = 0;
static grub_err_t
grub_linux_boot (void)
{
struct grub_relocator32_state state;
/* Boot the kernel. */
state.gpr[1] = entry_addr;
state.gpr[4] = linux_argc;
state.gpr[5] = target_addr + argv_off;
state.gpr[6] = target_addr + envp_off;
state.jumpreg = 1;
grub_relocator32_boot (playground, target_addr, state);
return GRUB_ERR_NONE;
}
static grub_err_t
grub_linux_release_mem (void)
{
grub_relocator32_free (playground);
return GRUB_ERR_NONE;
}
static grub_err_t
grub_linux_unload (void)
{
grub_err_t err;
err = grub_linux_release_mem ();
grub_dl_unref (my_mod);
loaded = 0;
return err;
}
static grub_err_t
grub_linux_load32 (grub_elf_t elf, void **extra_mem, grub_size_t extra_size)
{
Elf32_Addr base;
int extraoff;
/* Linux's entry point incorrectly contains a virtual address. */
entry_addr = elf->ehdr.ehdr32.e_entry & ~ELF32_LOADMASK;
linux_size = grub_elf32_size (elf, &base);
if (linux_size == 0)
return grub_errno;
target_addr = base;
/* Pad it; the kernel scribbles over memory beyond its load address. */
linux_size += 0x100000;
linux_size = ALIGN_UP (base + linux_size, 4) - base;
extraoff = linux_size;
linux_size += extra_size;
playground = grub_relocator32_alloc (linux_size);
if (!playground)
return grub_errno;
*extra_mem = playground + extraoff;
/* Now load the segments into the area we claimed. */
auto grub_err_t offset_phdr (Elf32_Phdr *phdr, grub_addr_t *addr, int *do_load);
grub_err_t offset_phdr (Elf32_Phdr *phdr, grub_addr_t *addr, int *do_load)
{
if (phdr->p_type != PT_LOAD)
{
*do_load = 0;
return 0;
}
*do_load = 1;
/* Linux's program headers incorrectly contain virtual addresses.
* Translate those to physical, and offset to the area we claimed. */
*addr = (grub_addr_t) (phdr->p_paddr - base + playground);
return 0;
}
return grub_elf32_load (elf, offset_phdr, 0, 0);
}
static grub_err_t
grub_linux_load64 (grub_elf_t elf, void **extra_mem, grub_size_t extra_size)
{
Elf64_Addr base;
int extraoff;
/* Linux's entry point incorrectly contains a virtual address. */
entry_addr = elf->ehdr.ehdr64.e_entry & ~ELF64_LOADMASK;
linux_size = grub_elf64_size (elf, &base);
if (linux_size == 0)
return grub_errno;
target_addr = base;
/* Pad it; the kernel scribbles over memory beyond its load address. */
linux_size += 0x100000;
linux_size = ALIGN_UP (base + linux_size, 4) - base;
extraoff = linux_size;
linux_size += extra_size;
playground = grub_relocator32_alloc (linux_size);
if (!playground)
return grub_errno;
*extra_mem = playground + extraoff;
/* Now load the segments into the area we claimed. */
auto grub_err_t offset_phdr (Elf64_Phdr *phdr, grub_addr_t *addr, int *do_load);
grub_err_t offset_phdr (Elf64_Phdr *phdr, grub_addr_t *addr, int *do_load)
{
if (phdr->p_type != PT_LOAD)
{
*do_load = 0;
return 0;
}
*do_load = 1;
/* Linux's program headers incorrectly contain virtual addresses.
* Translate those to physical, and offset to the area we claimed. */
*addr = (grub_addr_t) (phdr->p_paddr - base + playground);
return 0;
}
return grub_elf64_load (elf, offset_phdr, 0, 0);
}
static grub_err_t
grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
grub_elf_t elf = 0;
int i;
int size;
void *extra = NULL;
grub_uint32_t *linux_argv, *linux_envp;
char *linux_args, *linux_envs;
grub_err_t err;
if (argc == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no kernel specified");
elf = grub_elf_open (argv[0]);
if (! elf)
return grub_errno;
if (elf->ehdr.ehdr32.e_type != ET_EXEC)
{
grub_elf_close (elf);
return grub_error (GRUB_ERR_UNKNOWN_OS,
"this ELF file is not of the right type\n");
}
/* Release the previously used memory. */
grub_loader_unset ();
loaded = 0;
/* For arguments. */
linux_argc = argc;
/* Main arguments. */
size = (linux_argc) * sizeof (grub_uint32_t);
/* Initrd address and size. */
size += 2 * sizeof (grub_uint32_t);
/* NULL terminator. */
size += sizeof (grub_uint32_t);
/* First argument is always "a0". */
size += ALIGN_UP (sizeof ("a0"), 4);
/* Normal arguments. */
for (i = 1; i < argc; i++)
size += ALIGN_UP (grub_strlen (argv[i]) + 1, 4);
/* rd arguments. */
size += ALIGN_UP (sizeof ("rd_start=0xXXXXXXXXXXXXXXXX"), 4);
size += ALIGN_UP (sizeof ("rd_size=0xXXXXXXXXXXXXXXXX"), 4);
/* For the environment. */
size += sizeof (grub_uint32_t);
size += 4 * sizeof (grub_uint32_t);
size += ALIGN_UP (sizeof ("memsize=XXXXXXXXXXXXXXXXXXXX"), 4)
+ ALIGN_UP (sizeof ("highmemsize=XXXXXXXXXXXXXXXXXXXX"), 4)
+ ALIGN_UP (sizeof ("busclock=XXXXXXXXXX"), 4)
+ ALIGN_UP (sizeof ("cpuclock=XXXXXXXXXX"), 4);
if (grub_elf_is_elf32 (elf))
err = grub_linux_load32 (elf, &extra, size);
else
if (grub_elf_is_elf64 (elf))
err = grub_linux_load64 (elf, &extra, size);
else
err = grub_error (GRUB_ERR_BAD_FILE_TYPE, "unknown ELF class");
grub_elf_close (elf);
if (err)
return err;
linux_argv = extra;
argv_off = (grub_uint8_t *) linux_argv - (grub_uint8_t *) playground;
extra = linux_argv + (linux_argc + 1 + 2);
linux_args = extra;
grub_memcpy (linux_args, "a0", sizeof ("a0"));
*linux_argv = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground
+ target_addr;
linux_argv++;
linux_args += ALIGN_UP (sizeof ("a0"), 4);
for (i = 1; i < argc; i++)
{
grub_memcpy (linux_args, argv[i], grub_strlen (argv[i]) + 1);
*linux_argv = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground
+ target_addr;
linux_argv++;
linux_args += ALIGN_UP (grub_strlen (argv[i]) + 1, 4);
}
/* Reserve space for rd arguments. */
rd_addr_arg_off = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground;
linux_args += ALIGN_UP (sizeof ("rd_start=0xXXXXXXXXXXXXXXXX"), 4);
*linux_argv = 0;
linux_argv++;
rd_size_arg_off = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground;
linux_args += ALIGN_UP (sizeof ("rd_size=0xXXXXXXXXXXXXXXXX"), 4);
*linux_argv = 0;
linux_argv++;
*linux_argv = 0;
extra = linux_args;
linux_envp = extra;
envp_off = (grub_uint8_t *) linux_envp - (grub_uint8_t *) playground;
linux_envs = (char *) (linux_envp + 5);
grub_snprintf (linux_envs, sizeof ("memsize=XXXXXXXXXXXXXXXXXXXX"),
"memsize=%lld",
(unsigned long long) grub_mmap_get_lower () >> 20);
linux_envp[0] = (grub_uint8_t *) linux_envs - (grub_uint8_t *) playground
+ target_addr;
linux_envs += ALIGN_UP (grub_strlen (linux_envs) + 1, 4);
grub_snprintf (linux_envs, sizeof ("highmemsize=XXXXXXXXXXXXXXXXXXXX"),
"highmemsize=%lld",
(unsigned long long) grub_mmap_get_upper () >> 20);
linux_envp[1] = (grub_uint8_t *) linux_envs - (grub_uint8_t *) playground
+ target_addr;
linux_envs += ALIGN_UP (grub_strlen (linux_envs) + 1, 4);
grub_snprintf (linux_envs, sizeof ("busclock=XXXXXXXXXX"),
"busclock=%d", grub_arch_busclock);
linux_envp[2] = (grub_uint8_t *) linux_envs - (grub_uint8_t *) playground
+ target_addr;
linux_envs += ALIGN_UP (grub_strlen (linux_envs) + 1, 4);
grub_snprintf (linux_envs, sizeof ("cpuclock=XXXXXXXXXX"),
"cpuclock=%d", grub_arch_cpuclock);
linux_envp[3] = (grub_uint8_t *) linux_envs - (grub_uint8_t *) playground
+ target_addr;
linux_envs += ALIGN_UP (grub_strlen (linux_envs) + 1, 4);
linux_envp[4] = 0;
grub_loader_set (grub_linux_boot, grub_linux_unload, 1);
initrd_loaded = 0;
loaded = 1;
grub_dl_ref (my_mod);
return GRUB_ERR_NONE;
}
static grub_err_t
grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
grub_file_t file = 0;
grub_ssize_t size;
grub_size_t overhead;
if (argc == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no initrd specified");
if (!loaded)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "you need to load Linux first.");
if (initrd_loaded)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "only one initrd can be loaded.");
file = grub_file_open (argv[0]);
if (! file)
return grub_errno;
size = grub_file_size (file);
overhead = ALIGN_UP (target_addr + linux_size + 0x10000, 0x10000)
- (target_addr + linux_size);
playground = grub_relocator32_realloc (playground,
linux_size + overhead + size);
if (!playground)
{
grub_file_close (file);
return grub_errno;
}
if (grub_file_read (file, playground + linux_size + overhead, size) != size)
{
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
grub_file_close (file);
return grub_errno;
}
grub_snprintf ((char *) playground + rd_addr_arg_off,
sizeof ("rd_start=0xXXXXXXXXXXXXXXXX"), "rd_start=0x%llx",
(unsigned long long) target_addr + linux_size + overhead);
((grub_uint32_t *) (playground + argv_off))[linux_argc]
= target_addr + rd_addr_arg_off;
linux_argc++;
grub_snprintf ((char *) playground + rd_size_arg_off,
sizeof ("rd_size=0xXXXXXXXXXXXXXXXXX"), "rd_size=0x%llx",
(unsigned long long) size);
((grub_uint32_t *) (playground + argv_off))[linux_argc]
= target_addr + rd_size_arg_off;
linux_argc++;
initrd_loaded = 1;
grub_file_close (file);
return GRUB_ERR_NONE;
}
static grub_command_t cmd_linux, cmd_initrd;
GRUB_MOD_INIT(linux)
{
cmd_linux = grub_register_command ("linux", grub_cmd_linux,
0, N_("Load Linux."));
cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd,
0, N_("Load initrd."));
my_mod = mod;
}
GRUB_MOD_FINI(linux)
{
grub_unregister_command (cmd_linux);
grub_unregister_command (cmd_initrd);
}

View file

@ -1,461 +0,0 @@
/* multiboot2.c - boot a multiboot 2 OS image. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/loader.h>
#include <grub/machine/loader.h>
#include <grub/multiboot2.h>
#include <multiboot2.h>
#include <grub/elfload.h>
#include <grub/file.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/gzio.h>
static grub_addr_t entry;
extern grub_dl_t my_mod;
static char *grub_mb2_tags;
static char *grub_mb2_tags_pos;
static grub_size_t grub_mb2_tags_len;
static int grub_mb2_tags_count;
static void
grub_mb2_tags_free (void)
{
grub_dprintf ("loader", "Freeing all tags...\n");
grub_free (grub_mb2_tags);
grub_mb2_tags = 0;
grub_mb2_tags_pos = 0;
grub_mb2_tags_len = 0;
grub_mb2_tags_count = 0;
}
grub_err_t
grub_mb2_tag_alloc (grub_addr_t *addr, int key, grub_size_t len)
{
struct multiboot2_tag_header *tag;
grub_size_t used;
grub_size_t needed;
grub_dprintf ("loader", "Allocating tag: key 0x%x, size 0x%lx.\n",
key, (unsigned long) len);
used = grub_mb2_tags_pos - grub_mb2_tags;
len = ALIGN_UP (len, sizeof (multiboot2_word));
needed = used + len;
if (needed > grub_mb2_tags_len)
{
/* Allocate new buffer. */
grub_size_t newsize = needed * 2;
char *newarea;
grub_dprintf ("loader", "Reallocating tag buffer (new size 0x%lx).\n",
(unsigned long) newsize);
newarea = grub_malloc (newsize);
if (! newarea)
return grub_errno;
grub_memcpy (newarea, grub_mb2_tags, grub_mb2_tags_len);
grub_free (grub_mb2_tags);
grub_mb2_tags_len = newsize;
grub_mb2_tags = newarea;
grub_mb2_tags_pos = newarea + used;
}
tag = (struct multiboot2_tag_header *) grub_mb2_tags_pos;
grub_mb2_tags_pos += len;
tag->key = key;
tag->len = len;
if (addr)
*addr = (grub_addr_t) tag;
grub_mb2_tags_count++;
grub_dprintf ("loader", "Allocated tag %u at %p.\n", grub_mb2_tags_count, tag);
return 0;
}
static grub_err_t
grub_mb2_tag_start_create (void)
{
return grub_mb2_tag_alloc (0, MULTIBOOT2_TAG_START,
sizeof (struct multiboot2_tag_start));
}
static grub_err_t
grub_mb2_tag_name_create (void)
{
struct multiboot2_tag_name *name;
grub_addr_t name_addr;
grub_err_t err;
const char *grub_version = PACKAGE_STRING;
err = grub_mb2_tag_alloc (&name_addr, MULTIBOOT2_TAG_NAME,
sizeof (struct multiboot2_tag_name) +
sizeof (grub_version) + 1);
if (err)
return err;
name = (struct multiboot2_tag_name *) name_addr;
grub_strcpy (name->name, grub_version);
return GRUB_ERR_NONE;
}
typedef grub_err_t (*tag_create_t) (void);
static tag_create_t grub_mb2_tag_creators[] = {
grub_mb2_tag_start_create,
grub_mb2_tag_name_create,
grub_mb2_tags_arch_create,
0,
};
static grub_err_t
grub_mb2_tags_create (void)
{
tag_create_t *creator;
grub_err_t err;
for (creator = grub_mb2_tag_creators; *creator != 0; creator++)
{
err = (*creator) ();
if (err)
goto error;
}
return GRUB_ERR_NONE;
error:
grub_error_push ();
grub_mb2_tags_free ();
grub_error_pop ();
return err;
}
static grub_err_t
grub_mb2_tags_finish (void)
{
struct multiboot2_tag_start *start;
grub_err_t err;
/* Create the `end' tag. */
err = grub_mb2_tag_alloc (0, MULTIBOOT2_TAG_END,
sizeof (struct multiboot2_tag_end));
if (err)
goto error;
/* We created the `start' tag first. Update it now. */
start = (struct multiboot2_tag_start *) grub_mb2_tags;
start->size = grub_mb2_tags_pos - grub_mb2_tags;
return GRUB_ERR_NONE;
error:
grub_error_push ();
grub_mb2_tags_free ();
grub_error_pop ();
return err;
}
static grub_err_t
grub_mb2_boot (void)
{
grub_mb2_tags_finish ();
grub_dprintf ("loader", "Tags at %p\n", grub_mb2_tags);
grub_mb2_arch_boot (entry, grub_mb2_tags);
/* Not reached. */
return GRUB_ERR_NONE;
}
static grub_err_t
grub_mb2_unload (void)
{
struct multiboot2_tag_header *tag;
struct multiboot2_tag_header *tags =
(struct multiboot2_tag_header *) grub_mb2_tags;
/* Free all module memory in the tag list. */
for_each_tag (tag, tags)
{
if (tag->key == MULTIBOOT2_TAG_MODULE)
{
struct multiboot2_tag_module *module =
(struct multiboot2_tag_module *) tag;
grub_free ((void *) module->addr);
}
}
/* Allow architecture to un-reserve memory. */
grub_mb2_arch_unload (tags);
/* Free the tags themselves. */
grub_mb2_tags_free ();
grub_dl_unref (my_mod);
return GRUB_ERR_NONE;
}
static grub_err_t
grub_mb2_load_other (grub_file_t file __attribute__ ((unused)),
void *buffer __attribute__ ((unused)))
{
/* XXX Create module tag here. */
return grub_error (GRUB_ERR_UNKNOWN_OS, "currently only ELF is supported");
}
/* Create the tag containing the cmdline and the address of the module data. */
static grub_err_t
grub_mb2_tag_module_create (grub_addr_t modaddr, grub_size_t modsize,
char *type, int key, int argc, char *argv[])
{
struct multiboot2_tag_module *module;
grub_ssize_t argslen = 0;
grub_err_t err;
char *p;
grub_addr_t module_addr;
int i;
/* Allocate enough space for the arguments and spaces between them. */
for (i = 0; i < argc; i++)
argslen += grub_strlen (argv[i]) + 1;
/* Note: includes implicit 1-byte cmdline. */
err = grub_mb2_tag_alloc (&module_addr, key,
sizeof (struct multiboot2_tag_module) + argslen);
if (err)
return grub_errno;
module = (struct multiboot2_tag_module *) module_addr;
module->addr = modaddr;
module->size = modsize;
grub_strcpy(module->type, type);
/* Fill in the command line. */
p = module->cmdline;
for (i = 0; i < argc; i++)
{
p = grub_stpcpy (p, argv[i]);
*p++ = ' ';
}
module->cmdline[argslen] = '\0';
return GRUB_ERR_NONE;
}
/* Load ELF32 or ELF64. */
static grub_err_t
grub_mb2_load_elf (grub_elf_t elf, int argc, char *argv[])
{
grub_addr_t kern_base;
grub_size_t kern_size;
grub_err_t err;
if (grub_elf_is_elf32 (elf))
{
entry = elf->ehdr.ehdr32.e_entry;
err = grub_elf32_load (elf, grub_mb2_arch_elf32_hook, &kern_base,
&kern_size);
}
else if (grub_elf_is_elf64 (elf))
{
entry = elf->ehdr.ehdr64.e_entry;
err = grub_elf64_load (elf, grub_mb2_arch_elf64_hook, &kern_base,
&kern_size);
}
else
err = grub_error (GRUB_ERR_UNKNOWN_OS, "unknown ELF class");
if (err)
goto fail;
grub_dprintf ("loader", "Entry point is 0x%lx.\n", (unsigned long) entry);
grub_mb2_tag_module_create (kern_base, kern_size, "kernel",
MULTIBOOT2_TAG_MODULE, argc, argv);
fail:
return err;
}
void
grub_multiboot2 (int argc, char *argv[])
{
char *buffer;
grub_file_t file = 0;
grub_elf_t elf = 0;
struct multiboot2_header *header = 0;
char *p;
grub_ssize_t len;
grub_err_t err;
int header_found = 0;
grub_loader_unset ();
if (argc == 0)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "no kernel specified");
goto fail;
}
file = grub_gzfile_open (argv[0], 1);
if (! file)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "couldn't open file");
goto fail;
}
buffer = grub_malloc (MULTIBOOT2_HEADER_SEARCH);
if (! buffer)
return;
len = grub_file_read (file, buffer, MULTIBOOT2_HEADER_SEARCH);
if (len < 32)
{
grub_error (GRUB_ERR_BAD_OS, "file too small");
goto fail;
}
/* Look for the multiboot header in the buffer. The header should
be at least 8 bytes and aligned on a 8-byte boundary. */
for (p = buffer; p <= buffer + len - 8; p += 8)
{
header = (struct multiboot2_header *) p;
if (header->magic == MULTIBOOT2_HEADER_MAGIC)
{
header_found = 1;
break;
}
}
if (! header_found)
grub_dprintf ("loader", "No multiboot 2 header found.\n");
/* Create the basic tags. */
grub_dprintf ("loader", "Creating multiboot 2 tags\n");
grub_mb2_tags_create ();
/* Load the kernel and create its tag. */
elf = grub_elf_file (file);
if (elf)
{
grub_dprintf ("loader", "Loading ELF multiboot 2 file.\n");
err = grub_mb2_load_elf (elf, argc-1, &argv[1]);
grub_elf_close (elf);
}
else
{
grub_errno = 0;
grub_dprintf ("loader", "Loading non-ELF multiboot 2 file.\n");
if (header)
err = grub_mb2_load_other (file, header);
else
err = grub_error (GRUB_ERR_BAD_OS,
"need multiboot 2 header to load non-ELF files");
grub_file_close (file);
}
grub_free (buffer);
if (err)
goto fail;
/* Good to go. */
grub_loader_set (grub_mb2_boot, grub_mb2_unload, 1);
return;
fail:
grub_mb2_tags_free ();
grub_dl_unref (my_mod);
}
void
grub_module2 (int argc, char *argv[])
{
grub_file_t file;
grub_addr_t modaddr = 0;
grub_ssize_t modsize = 0;
grub_err_t err;
if (argc == 0)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "no module specified");
return;
}
if (argc == 1)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "no module type specified");
return;
}
if (entry == 0)
{
grub_error (GRUB_ERR_BAD_ARGUMENT,
"you need to load the multiboot kernel first");
return;
}
/* Load module data. */
file = grub_gzfile_open (argv[0], 1);
if (! file)
goto out;
modsize = grub_file_size (file);
err = grub_mb2_arch_module_alloc (modsize, &modaddr);
if (err)
goto out;
grub_dprintf ("loader", "Loading module at 0x%x - 0x%x\n", modaddr,
modaddr + modsize);
if (grub_file_read (file, (void *) modaddr, modsize) != modsize)
{
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
goto out;
}
/* Create the module tag. */
err = grub_mb2_tag_module_create (modaddr, modsize,
argv[1], MULTIBOOT2_TAG_MODULE,
argc-2, &argv[2]);
if (err)
goto out;
out:
grub_error_push ();
if (file)
grub_file_close (file);
if (modaddr)
grub_mb2_arch_module_free (modaddr, modsize);
grub_error_pop ();
}

View file

@ -1,7 +1,7 @@
/* multiboot_loader.c - boot multiboot 1 or 2 OS image */
/* multiboot_loader.c - boot multiboot kernel image */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 2007,2008,2009,2010 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
@ -18,8 +18,6 @@
*/
#include <grub/multiboot.h>
#include <grub/multiboot2.h>
#include <multiboot2.h>
#include <grub/elf.h>
#include <grub/file.h>
#include <grub/err.h>
@ -28,18 +26,10 @@
#include <grub/misc.h>
#include <grub/gzio.h>
#include <grub/command.h>
#include <grub/i18n.h>
grub_dl_t my_mod;
/* This tracks which version of multiboot to use when using
* the module command. By default use multiboot version 1.
* values:
* 1 - Multiboot version 1
* 2 - Multiboot version 2
*/
static unsigned int module_version_status = 1;
static int
find_multi_boot1_header (grub_file_t file)
{
@ -69,34 +59,6 @@ find_multi_boot1_header (grub_file_t file)
return found_status;
}
static int
find_multi_boot2_header (grub_file_t file)
{
struct multiboot_header *header;
char buffer[MULTIBOOT_SEARCH];
int found_status = 0;
grub_ssize_t len;
len = grub_file_read (file, buffer, MULTIBOOT_SEARCH);
if (len < 32)
return found_status;
/* Look for the multiboot header in the buffer. The header should
be at least 8 bytes and aligned on a 8-byte boundary. */
for (header = (struct multiboot_header *) buffer;
((char *) header <= buffer + len - 8) || (header = 0);
header = (struct multiboot_header *) ((char *) header + 8))
{
if (header->magic == MULTIBOOT2_HEADER_MAGIC)
{
found_status = 1;
break;
}
}
return found_status;
}
static grub_err_t
grub_cmd_multiboot_loader (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
@ -122,8 +84,6 @@ grub_cmd_multiboot_loader (grub_command_t cmd __attribute__ ((unused)),
/* find which header is in the file */
if (find_multi_boot1_header (file))
header_multi_ver_found = 1;
else if (find_multi_boot2_header (file))
header_multi_ver_found = 2;
else
{
grub_error (GRUB_ERR_BAD_OS, "multiboot header not found");
@ -136,25 +96,9 @@ grub_cmd_multiboot_loader (grub_command_t cmd __attribute__ ((unused)),
/* Launch multi boot with header */
/* XXX Find a better way to identify this.
This is for i386-pc */
#if defined(GRUB_MACHINE_PCBIOS) || defined(GRUB_MACHINE_COREBOOT) || \
defined(GRUB_MACHINE_QEMU)
if (header_multi_ver_found == 1)
{
grub_dprintf ("multiboot_loader",
"Launching multiboot 1 grub_multiboot() function\n");
grub_multiboot (argc, argv);
module_version_status = 1;
}
#endif
if (header_multi_ver_found == 0 || header_multi_ver_found == 2)
{
grub_dprintf ("multiboot_loader",
"Launching multiboot 2 grub_multiboot2() function\n");
grub_multiboot2 (argc, argv);
module_version_status = 2;
}
grub_dprintf ("multiboot_loader",
"Launching multiboot 1 grub_multiboot() function\n");
grub_multiboot (argc, argv);
return grub_errno;
@ -172,21 +116,9 @@ grub_cmd_module_loader (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
#if defined(GRUB_MACHINE_PCBIOS) || defined(GRUB_MACHINE_COREBOOT) || \
defined(GRUB_MACHINE_QEMU)
if (module_version_status == 1)
{
grub_dprintf("multiboot_loader",
"Launching multiboot 1 grub_module() function\n");
grub_module (argc, argv);
}
#endif
if (module_version_status == 2)
{
grub_dprintf("multiboot_loader",
"Launching multiboot 2 grub_module2() function\n");
grub_module2 (argc, argv);
}
grub_dprintf("multiboot_loader",
"Launching multiboot 1 grub_module() function\n");
grub_module (argc, argv);
return grub_errno;
}
@ -196,11 +128,17 @@ static grub_command_t cmd_multiboot, cmd_module;
GRUB_MOD_INIT(multiboot)
{
cmd_multiboot =
#ifdef GRUB_USE_MULTIBOOT2
grub_register_command ("multiboot2", grub_cmd_multiboot_loader,
0, N_("Load a multiboot 2 kernel."));
#else
grub_register_command ("multiboot", grub_cmd_multiboot_loader,
0, "Load a multiboot kernel.");
0, N_("Load a multiboot kernel."));
#endif
cmd_module =
grub_register_command ("module", grub_cmd_module_loader,
0, "Load a multiboot module.");
0, N_("Load a multiboot module."));
my_mod = mod;
}

View file

@ -26,6 +26,7 @@
#include <grub/ieee1275/ieee1275.h>
#include <grub/machine/loader.h>
#include <grub/command.h>
#include <grub/i18n.h>
#define ELF32_LOADMASK (0xc0000000UL)
#define ELF64_LOADMASK (0xc000000000000000ULL)
@ -110,7 +111,7 @@ grub_linux_load32 (grub_elf_t elf)
if (entry == 0)
entry = 0x01400000;
linux_size = grub_elf32_size (elf);
linux_size = grub_elf32_size (elf, 0);
if (linux_size == 0)
return grub_errno;
/* Pad it; the kernel scribbles over memory beyond its load address. */
@ -160,7 +161,7 @@ grub_linux_load64 (grub_elf_t elf)
if (entry == 0)
entry = 0x01400000;
linux_size = grub_elf64_size (elf);
linux_size = grub_elf64_size (elf, 0);
if (linux_size == 0)
return grub_errno;
/* Pad it; the kernel scribbles over memory beyond its load address. */
@ -349,9 +350,9 @@ static grub_command_t cmd_linux, cmd_initrd;
GRUB_MOD_INIT(linux)
{
cmd_linux = grub_register_command ("linux", grub_cmd_linux,
0, "Load Linux.");
0, N_("Load Linux."));
cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd,
0, "Load initrd.");
0, N_("Load initrd."));
my_mod = mod;
}

View file

@ -27,6 +27,7 @@
#include <grub/machine/loader.h>
#include <grub/gzio.h>
#include <grub/command.h>
#include <grub/i18n.h>
static grub_dl_t my_mod;
@ -246,7 +247,7 @@ grub_linux_load64 (grub_elf_t elf)
linux_entry = elf->ehdr.ehdr64.e_entry;
linux_addr = 0x40004000;
off = 0x4000;
linux_size = grub_elf64_size (elf);
linux_size = grub_elf64_size (elf, 0);
if (linux_size == 0)
return grub_errno;
@ -263,7 +264,7 @@ grub_linux_load64 (grub_elf_t elf)
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't map physical memory");
grub_dprintf ("loader", "Loading linux at vaddr 0x%lx, paddr 0x%lx, size 0x%lx\n",
grub_dprintf ("loader", "Loading Linux at vaddr 0x%lx, paddr 0x%lx, size 0x%lx\n",
linux_addr, paddr, linux_size);
linux_paddr = paddr;
@ -516,9 +517,9 @@ GRUB_MOD_INIT(linux)
fetch_translations ();
cmd_linux = grub_register_command ("linux", grub_cmd_linux,
0, "Load Linux.");
0, N_("Load Linux."));
cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd,
0, "Load initrd.");
0, N_("Load initrd."));
my_mod = mod;
}

View file

@ -33,6 +33,7 @@
#include <grub/misc.h>
#include <grub/extcmd.h>
#include <grub/env.h>
#include <grub/i18n.h>
struct grub_xnu_devtree_key *grub_xnu_devtree_root = 0;
static int driverspackagenum = 0;
@ -569,10 +570,9 @@ grub_xnu_register_memory (char *prefix, int *suffix,
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't register memory");
if (suffix)
{
driverkey->name = grub_malloc (grub_strlen (prefix) + 10);
driverkey->name = grub_xasprintf ("%s%d", prefix, (*suffix)++);
if (!driverkey->name)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't register memory");
grub_sprintf (driverkey->name, "%s%d", prefix, (*suffix)++);
}
else
driverkey->name = grub_strdup (prefix);
@ -1425,28 +1425,28 @@ static grub_extcmd_t cmd_splash;
GRUB_MOD_INIT(xnu)
{
cmd_kernel = grub_register_command ("xnu_kernel", grub_cmd_xnu_kernel, 0,
"Load XNU image.");
N_("Load XNU image."));
cmd_kernel64 = grub_register_command ("xnu_kernel64", grub_cmd_xnu_kernel64,
0, "Load 64-bit XNU image.");
0, N_("Load 64-bit XNU image."));
cmd_mkext = grub_register_command ("xnu_mkext", grub_cmd_xnu_mkext, 0,
"Load XNU extension package.");
N_("Load XNU extension package."));
cmd_kext = grub_register_command ("xnu_kext", grub_cmd_xnu_kext, 0,
"Load XNU extension.");
N_("Load XNU extension."));
cmd_kextdir = grub_register_command ("xnu_kextdir", grub_cmd_xnu_kextdir,
"DIRECTORY [OSBundleRequired]",
"Load XNU extension directory.");
N_("DIRECTORY [OSBundleRequired]"),
N_("Load XNU extension directory."));
cmd_ramdisk = grub_register_command ("xnu_ramdisk", grub_cmd_xnu_ramdisk, 0,
"Load XNU ramdisk. "
"It will be seen as md0.");
cmd_splash = grub_register_extcmd ("xnu_splash",
grub_cmd_xnu_splash,
GRUB_COMMAND_FLAG_BOTH, 0,
"Load a splash image for XNU.",
N_("Load a splash image for XNU."),
xnu_splash_cmd_options);
#ifndef GRUB_UTIL
cmd_resume = grub_register_command ("xnu_resume", grub_cmd_xnu_resume,
0, "Load XNU hibernate image.");
0, N_("Load XNU hibernate image."));
#endif
grub_cpu_xnu_init ();