merge mainline up to r2075 (videomask merge)

This commit is contained in:
Colin Watson 2010-06-12 11:30:11 +01:00
commit 8253ee6bd7
327 changed files with 12261 additions and 6070 deletions

View file

@ -1,7 +1,7 @@
/* appleloader.c - apple legacy boot loader. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 Free Software Foundation, Inc.
* Copyright (C) 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
@ -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;
@ -59,58 +60,171 @@ grub_appleloader_boot (void)
return grub_errno;
}
/* early 2006 Core Duo / Core Solo models */
static grub_uint8_t devpath_1[] =
struct piwg_full_device_path
{
0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xF9, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B,
0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B,
0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00,
struct grub_efi_memory_mapped_device_path comp1;
struct grub_efi_piwg_device_path comp2;
struct grub_efi_device_path end;
};
/* early 2006 Core Duo / Core Solo models */
static struct piwg_full_device_path devpath_1 =
{
.comp1 =
{
.header = {
.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE,
.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE,
.length = {sizeof (struct grub_efi_memory_mapped_device_path), 0}
},
.memory_type = GRUB_EFI_MEMORY_MAPPED_IO,
.start_address = 0xffe00000,
.end_address = 0xfff9ffff
},
.comp2 =
{
.header = {
.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE,
.subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE,
.length = {sizeof (struct grub_efi_piwg_device_path), 0}
},
.guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
0x01, 0xAE, 0xF2, 0xB7}}
},
.end =
{
.type = GRUB_EFI_END_DEVICE_PATH_TYPE,
.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE,
.length = {sizeof (struct grub_efi_device_path), 0}
}
};
/* mid-2006 Mac Pro (and probably other Core 2 models) */
static grub_uint8_t devpath_2[] =
static struct piwg_full_device_path devpath_2 =
{
0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xF7, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B,
0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B,
0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00,
.comp1 =
{
.header = {
.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE,
.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE,
.length = {sizeof (struct grub_efi_memory_mapped_device_path), 0}
},
.memory_type = GRUB_EFI_MEMORY_MAPPED_IO,
.start_address = 0xffe00000,
.end_address = 0xfff7ffff
},
.comp2 =
{
.header = {
.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE,
.subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE,
.length = {sizeof (struct grub_efi_piwg_device_path), 0}
},
.guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
0x01, 0xAE, 0xF2, 0xB7}}
},
.end =
{
.type = GRUB_EFI_END_DEVICE_PATH_TYPE,
.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE,
.length = {sizeof (struct grub_efi_device_path), 0}
}
};
/* mid-2007 MBP ("Santa Rosa" based models) */
static grub_uint8_t devpath_3[] =
static struct piwg_full_device_path devpath_3 =
{
0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xF8, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B,
0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B,
0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00,
.comp1 =
{
.header = {
.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE,
.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE,
.length = {sizeof (struct grub_efi_memory_mapped_device_path), 0}
},
.memory_type = GRUB_EFI_MEMORY_MAPPED_IO,
.start_address = 0xffe00000,
.end_address = 0xfff8ffff
},
.comp2 =
{
.header = {
.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE,
.subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE,
.length = {sizeof (struct grub_efi_piwg_device_path), 0}
},
.guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
0x01, 0xAE, 0xF2, 0xB7}}
},
.end =
{
.type = GRUB_EFI_END_DEVICE_PATH_TYPE,
.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE,
.length = {sizeof (struct grub_efi_device_path), 0}
}
};
/* early-2008 MBA */
static grub_uint8_t devpath_4[] =
static struct piwg_full_device_path devpath_4 =
{
0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
0x00, 0x00, 0xC0, 0xFF, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xF8, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B,
0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B,
0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00,
.comp1 =
{
.header = {
.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE,
.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE,
.length = {sizeof (struct grub_efi_memory_mapped_device_path), 0}
},
.memory_type = GRUB_EFI_MEMORY_MAPPED_IO,
.start_address = 0xffc00000,
.end_address = 0xfff8ffff
},
.comp2 =
{
.header = {
.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE,
.subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE,
.length = {sizeof (struct grub_efi_piwg_device_path), 0}
},
.guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
0x01, 0xAE, 0xF2, 0xB7}}
},
.end =
{
.type = GRUB_EFI_END_DEVICE_PATH_TYPE,
.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE,
.length = {sizeof (struct grub_efi_device_path), 0}
}
};
/* late-2008 MB/MBP (NVidia chipset) */
static grub_uint8_t devpath_5[] = {
0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
0x00, 0x40, 0xCB, 0xFF, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xBF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B,
0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B,
0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00,
static struct piwg_full_device_path devpath_5 =
{
.comp1 =
{
.header = {
.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE,
.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE,
.length = {sizeof (struct grub_efi_memory_mapped_device_path), 0}
},
.memory_type = GRUB_EFI_MEMORY_MAPPED_IO,
.start_address = 0xffcb4000,
.end_address = 0xffffbfff
},
.comp2 =
{
.header = {
.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE,
.subtype = GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE,
.length = {sizeof (struct grub_efi_piwg_device_path), 0}
},
.guid = {0x2B0585EB, 0xD8B8, 0x49A9, {0x8B, 0x8C, 0xE2, 0x1B,
0x01, 0xAE, 0xF2, 0xB7}}
},
.end =
{
.type = GRUB_EFI_END_DEVICE_PATH_TYPE,
.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE,
.length = {sizeof (struct grub_efi_device_path), 0}
}
};
struct devdata
@ -121,11 +235,11 @@ struct devdata
struct devdata devs[] =
{
{"Core Duo/Solo", (grub_efi_device_path_t *) devpath_1},
{"Mac Pro", (grub_efi_device_path_t *) devpath_2},
{"MBP", (grub_efi_device_path_t *) devpath_3},
{"MBA", (grub_efi_device_path_t *) devpath_4},
{"MB NV", (grub_efi_device_path_t *) devpath_5},
{"Core Duo/Solo", (grub_efi_device_path_t *) &devpath_1},
{"Mac Pro", (grub_efi_device_path_t *) &devpath_2},
{"MBP", (grub_efi_device_path_t *) &devpath_3},
{"MBA", (grub_efi_device_path_t *) &devpath_4},
{"MB NV", (grub_efi_device_path_t *) &devpath_5},
{NULL, NULL},
};
@ -208,7 +322,7 @@ static grub_command_t cmd;
GRUB_MOD_INIT(appleloader)
{
cmd = grub_register_command ("appleloader", grub_cmd_appleloader,
"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
@ -34,7 +34,8 @@
#include <grub/aout.h>
#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
@ -61,20 +62,20 @@ static grub_uint32_t openbsd_root;
static const struct grub_arg_option freebsd_opts[] =
{
{"dual", 'D', 0, "Display output on all consoles.", 0, 0},
{"serial", 'h', 0, "Use serial console.", 0, 0},
{"askname", 'a', 0, "Ask for file name to reboot from.", 0, 0},
{"cdrom", 'C', 0, "Use cdrom as root.", 0, 0},
{"config", 'c', 0, "Invoke user configuration routing.", 0, 0},
{"kdb", 'd', 0, "Enter in KDB on boot.", 0, 0},
{"gdb", 'g', 0, "Use GDB remote debugger instead of DDB.", 0, 0},
{"mute", 'm', 0, "Disable all boot output.", 0, 0},
{"dual", 'D', 0, N_("Display output on all consoles."), 0, 0},
{"serial", 'h', 0, N_("Use serial console."), 0, 0},
{"askname", 'a', 0, N_("Ask for file name to reboot from."), 0, 0},
{"cdrom", 'C', 0, N_("Use CDROM as root."), 0, 0},
{"config", 'c', 0, N_("Invoke user configuration routing."), 0, 0},
{"kdb", 'd', 0, N_("Enter in KDB on boot."), 0, 0},
{"gdb", 'g', 0, N_("Use GDB remote debugger instead of DDB."), 0, 0},
{"mute", 'm', 0, N_("Disable all boot output."), 0, 0},
{"nointr", 'n', 0, "", 0, 0},
{"pause", 'p', 0, "Wait for keypress after every line of output.", 0, 0},
{"pause", 'p', 0, N_("Wait for keypress after every line of output."), 0, 0},
{"quiet", 'q', 0, "", 0, 0},
{"dfltroot", 'r', 0, "Use compiled-in rootdev.", 0, 0},
{"single", 's', 0, "Boot into single mode.", 0, 0},
{"verbose", 'v', 0, "Boot with verbose messages.", 0, 0},
{"dfltroot", 'r', 0, N_("Use compiled-in rootdev."), 0, 0},
{"single", 's', 0, N_("Boot into single mode."), 0, 0},
{"verbose", 'v', 0, N_("Boot with verbose messages."), 0, 0},
{0, 0, 0, 0, 0, 0}
};
@ -89,12 +90,12 @@ static const grub_uint32_t freebsd_flags[] =
static const struct grub_arg_option openbsd_opts[] =
{
{"askname", 'a', 0, "Ask for file name to reboot from.", 0, 0},
{"halt", 'b', 0, "Don't reboot, just halt.", 0, 0},
{"config", 'c', 0, "Change configured devices.", 0, 0},
{"single", 's', 0, "Boot into single mode.", 0, 0},
{"kdb", 'd', 0, "Enter in KDB on boot.", 0, 0},
{"root", 'r', 0, "Set root device.", "wdXY", ARG_TYPE_STRING},
{"askname", 'a', 0, N_("Ask for file name to reboot from."), 0, 0},
{"halt", 'b', 0, N_("Don't reboot, just halt."), 0, 0},
{"config", 'c', 0, N_("Change configured devices."), 0, 0},
{"single", 's', 0, N_("Boot into single mode."), 0, 0},
{"kdb", 'd', 0, N_("Enter in KDB on boot."), 0, 0},
{"root", 'r', 0, N_("Set root device."), "wdXY", ARG_TYPE_STRING},
{0, 0, 0, 0, 0, 0}
};
@ -108,19 +109,19 @@ static const grub_uint32_t openbsd_flags[] =
static const struct grub_arg_option netbsd_opts[] =
{
{"no-smp", '1', 0, "Disable SMP.", 0, 0},
{"no-acpi", '2', 0, "Disable ACPI.", 0, 0},
{"askname", 'a', 0, "Ask for file name to reboot from.", 0, 0},
{"halt", 'b', 0, "Don't reboot, just halt.", 0, 0},
{"config", 'c', 0, "Change configured devices.", 0, 0},
{"kdb", 'd', 0, "Enter in KDB on boot.", 0, 0},
{"no-smp", '1', 0, N_("Disable SMP."), 0, 0},
{"no-acpi", '2', 0, N_("Disable ACPI."), 0, 0},
{"askname", 'a', 0, N_("Ask for file name to reboot from."), 0, 0},
{"halt", 'b', 0, N_("Don't reboot, just halt."), 0, 0},
{"config", 'c', 0, N_("Change configured devices."), 0, 0},
{"kdb", 'd', 0, N_("Enter in KDB on boot."), 0, 0},
{"miniroot", 'm', 0, "", 0, 0},
{"quiet", 'q', 0, "Don't display boot diagnostic messages.", 0, 0},
{"single", 's', 0, "Boot into single mode.", 0, 0},
{"verbose", 'v', 0, "Boot with verbose messages.", 0, 0},
{"debug", 'x', 0, "Boot with debug messages.", 0, 0},
{"silent", 'z', 0, "Supress normal output (warnings remain).", 0, 0},
{"root", 'r', 0, "Set root device.", "DEVICE", ARG_TYPE_STRING},
{"quiet", 'q', 0, N_("Don't display boot diagnostic messages."), 0, 0},
{"single", 's', 0, N_("Boot into single mode."), 0, 0},
{"verbose", 'v', 0, N_("Boot with verbose messages."), 0, 0},
{"debug", 'x', 0, N_("Boot with debug messages."), 0, 0},
{"silent", 'z', 0, N_("Supress normal output (warnings remain)."), 0, 0},
{"root", 'r', 0, N_("Set root device."), N_("DEVICE"), ARG_TYPE_STRING},
{0, 0, 0, 0, 0, 0}
};
@ -140,7 +141,7 @@ grub_bsd_get_device (grub_uint32_t * biosdev,
grub_uint32_t * slice, grub_uint32_t * part)
{
char *p;
grub_device_t dev;
grub_device_t dev;
#ifdef GRUB_MACHINE_PCBIOS
*biosdev = grub_get_root_biosnumber () & 0xff;
@ -508,6 +509,8 @@ grub_freebsd_boot (void)
bi.bi_kernend = kern_end;
grub_video_set_mode ("text", 0, 0);
if (is_64bit)
{
grub_uint32_t *gdt;
@ -616,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),
@ -679,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);
@ -712,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));
@ -750,10 +757,10 @@ grub_bsd_load_aout (grub_file_t file)
return grub_errno;
if (grub_file_read (file, &ah, sizeof (ah)) != sizeof (ah))
return grub_error (GRUB_ERR_READ_ERROR, "Cannot read the a.out header");
return grub_error (GRUB_ERR_READ_ERROR, "cannot read the a.out header");
if (grub_aout_get_type (&ah) != AOUT_TYPE_AOUT32)
return grub_error (GRUB_ERR_BAD_OS, "Invalid a.out header");
return grub_error (GRUB_ERR_BAD_OS, "invalid a.out header");
entry = ah.aout32.a_entry & 0xFFFFFF;
@ -771,7 +778,7 @@ grub_bsd_load_aout (grub_file_t file)
}
if (load_addr < 0x100000)
return grub_error (GRUB_ERR_BAD_OS, "Load address below 1M");
return grub_error (GRUB_ERR_BAD_OS, "load address below 1M");
kern_start = load_addr;
kern_end = load_addr + ah.aout32.a_text + ah.aout32.a_data;
@ -811,7 +818,7 @@ grub_bsd_elf32_hook (Elf32_Phdr * phdr, grub_addr_t * addr, int *do_load)
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",
return grub_error (GRUB_ERR_OUT_OF_RANGE, "address 0x%x is out of range",
paddr);
if ((!kern_start) || (paddr < kern_start))
@ -842,7 +849,7 @@ grub_bsd_elf64_hook (Elf64_Phdr * phdr, grub_addr_t * addr, int *do_load)
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",
return grub_error (GRUB_ERR_OUT_OF_RANGE, "address 0x%x is out of range",
paddr);
if ((!kern_start) || (paddr < kern_start))
@ -871,7 +878,7 @@ grub_bsd_load_elf (grub_elf_t elf)
is_64bit = 1;
if (! grub_cpuid_has_longmode)
return grub_error (GRUB_ERR_BAD_OS, "Your CPU does not implement AMD64 architecture.");
return grub_error (GRUB_ERR_BAD_OS, "your CPU does not implement AMD64 architecture");
/* FreeBSD has 64-bit entry point. */
if (kernel_type == KERNEL_TYPE_FREEBSD)
@ -887,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
@ -902,7 +909,7 @@ grub_bsd_load (int argc, char *argv[])
if (argc == 0)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "No kernel specified");
grub_error (GRUB_ERR_BAD_ARGUMENT, "no kernel specified");
goto fail;
}
@ -1024,14 +1031,14 @@ grub_cmd_openbsd (grub_extcmd_t cmd, int argc, char *argv[])
int unit, part;
if (*(arg++) != 'w' || *(arg++) != 'd')
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"Only device specifications of form "
"wd<number><lowercase letter> are supported.");
"only device specifications of form "
"wd<number><lowercase letter> are supported");
unit = grub_strtoul (arg, (char **) &arg, 10);
if (! (arg && *arg >= 'a' && *arg <= 'z'))
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"Only device specifications of form "
"wd<number><lowercase letter> are supported.");
"only device specifications of form "
"wd<number><lowercase letter> are supported");
part = *arg - 'a';
@ -1076,15 +1083,15 @@ grub_cmd_freebsd_loadenv (grub_command_t cmd __attribute__ ((unused)),
if (kernel_type == KERNEL_TYPE_NONE)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"You need to load the kernel first.");
"you need to load the kernel first");
if (kernel_type != KERNEL_TYPE_FREEBSD)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"Only FreeBSD support environment");
"only FreeBSD supports environment");
if (argc == 0)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "No filename");
grub_error (GRUB_ERR_BAD_ARGUMENT, "no filename");
goto fail;
}
@ -1170,15 +1177,15 @@ grub_cmd_freebsd_module (grub_command_t cmd __attribute__ ((unused)),
if (kernel_type == KERNEL_TYPE_NONE)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"You need to load the kernel first.");
"you need to load the kernel first");
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)
@ -1193,7 +1200,7 @@ grub_cmd_freebsd_module (grub_command_t cmd __attribute__ ((unused)),
if (kern_end + file->size > grub_os_area_addr + grub_os_area_size)
{
grub_error (GRUB_ERR_OUT_OF_RANGE, "Not enough memory for the module");
grub_error (GRUB_ERR_OUT_OF_RANGE, "not enough memory for the module");
goto fail;
}
@ -1236,15 +1243,15 @@ grub_cmd_freebsd_module_elf (grub_command_t cmd __attribute__ ((unused)),
if (kernel_type == KERNEL_TYPE_NONE)
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"You need to load the kernel first.");
"you need to load the kernel first");
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)
@ -1280,25 +1287,25 @@ GRUB_MOD_INIT (bsd)
{
cmd_freebsd = grub_register_extcmd ("kfreebsd", grub_cmd_freebsd,
GRUB_COMMAND_FLAG_BOTH,
"kfreebsd FILE", "Load kernel of FreeBSD.",
N_("FILE"), N_("Load kernel of FreeBSD."),
freebsd_opts);
cmd_openbsd = grub_register_extcmd ("kopenbsd", grub_cmd_openbsd,
GRUB_COMMAND_FLAG_BOTH,
"kopenbsd FILE", "Load kernel of OpenBSD.",
N_("FILE"), N_("Load kernel of OpenBSD."),
openbsd_opts);
cmd_netbsd = grub_register_extcmd ("knetbsd", grub_cmd_netbsd,
GRUB_COMMAND_FLAG_BOTH,
"knetbsd FILE", "Load kernel of NetBSD.",
N_("FILE"), N_("Load kernel of NetBSD."),
netbsd_opts);
cmd_freebsd_loadenv =
grub_register_command ("kfreebsd_loadenv", grub_cmd_freebsd_loadenv,
0, "load FreeBSD env");
0, N_("Load FreeBSD env."));
cmd_freebsd_module =
grub_register_command ("kfreebsd_module", grub_cmd_freebsd_module,
0, "load FreeBSD kernel module");
0, N_("Load FreeBSD kernel module."));
cmd_freebsd_module_elf =
grub_register_command ("kfreebsd_module_elf", grub_cmd_freebsd_module_elf,
0, "load FreeBSD kernel module (ELF)");
0, N_("Load FreeBSD kernel module (ELF)."));
my_mod = mod;
}

View file

@ -12,7 +12,7 @@ load (grub_file_t file, void *where, grub_off_t off, grub_size_t size)
{
if (PTR_TO_UINT32 (where) + size > grub_os_area_addr + grub_os_area_size)
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"Not enough memory for the module");
"not enough memory for the module");
if (grub_file_seek (file, off) == (grub_off_t) -1)
return grub_errno;
if (grub_file_read (file, where, size)
@ -116,7 +116,7 @@ SUFFIX (grub_freebsd_load_elfmodule_obj) (grub_file_t file, int argc,
case SHT_NOBITS:
if (curload + s->sh_size > grub_os_area_addr + grub_os_area_size)
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"Not enough memory for the module");
"not enough memory for the module");
grub_memset (UINT_TO_PTR (curload), 0, s->sh_size);
break;
}
@ -185,7 +185,7 @@ SUFFIX (grub_freebsd_load_elfmodule) (grub_file_t file, int argc, char *argv[],
if (module + s->sh_addr + s->sh_size
> grub_os_area_addr + grub_os_area_size)
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"Not enough memory for the module");
"not enough memory for the module");
grub_memset (UINT_TO_PTR (module + s->sh_addr), 0, s->sh_size);
break;
}
@ -259,7 +259,7 @@ SUFFIX (grub_freebsd_load_elf_meta) (grub_file_t file, grub_addr_t *kern_end)
if (*kern_end + 4 * sizeof (grub_freebsd_addr_t) + symsize + strsize
> grub_os_area_addr + grub_os_area_size)
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"Not enough memory for kernel symbols");
"not enough memory for kernel symbols");
symstart = curload = ALIGN_UP (*kern_end, sizeof (grub_freebsd_addr_t));
*((grub_freebsd_addr_t *) UINT_TO_PTR (curload)) = symsize;
@ -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

@ -34,6 +34,7 @@
#include <grub/env.h>
#include <grub/video.h>
#include <grub/time.h>
#include <grub/i18n.h>
#define GRUB_LINUX_CL_OFFSET 0x1000
#define GRUB_LINUX_CL_END_OFFSET 0x2000
@ -552,7 +553,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;
}
@ -604,7 +605,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
len = 0x400 - sizeof (lh);
if (grub_file_read (file, (char *) real_mode_mem + sizeof (lh), len) != len)
{
grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
goto fail;
}
@ -626,13 +627,32 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
params->ext_mem = ((32 * 0x100000) >> 10);
params->alt_mem = ((32 * 0x100000) >> 10);
params->video_cursor_x = grub_getxy () >> 8;
params->video_cursor_y = grub_getxy () & 0xff;
{
grub_term_output_t term;
int found = 0;
FOR_ACTIVE_TERM_OUTPUTS(term)
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;
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_page = 0; /* ??? */
params->video_mode = grub_efi_system_table->con_out->mode->mode;
params->video_width = (grub_getwh () >> 8);
params->video_ega_bx = 0;
params->video_height = (grub_getwh () & 0xff);
params->have_vga = 0;
params->font_size = 16; /* XXX */
@ -784,7 +804,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
len = prot_size;
if (grub_file_read (file, (void *) GRUB_LINUX_BZIMAGE_ADDR, len) != len)
grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
if (grub_errno == GRUB_ERR_NONE)
{
@ -821,13 +841,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (argc == 0)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "No module specified");
grub_error (GRUB_ERR_BAD_ARGUMENT, "no module specified");
goto fail;
}
if (! loaded)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "You need to load the kernel first.");
grub_error (GRUB_ERR_BAD_ARGUMENT, "you need to load the kernel first");
goto fail;
}
@ -897,7 +917,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (grub_file_read (file, initrd_mem, size) != size)
{
grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
goto fail;
}
@ -920,9 +940,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 @@
/* linux.c - boot Linux zImage or bzImage */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008 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
@ -109,8 +110,29 @@ grub_linux_boot (void)
params->cl_magic = GRUB_LINUX_CL_MAGIC;
params->cl_offset = GRUB_OFW_LINUX_CL_OFFSET;
params->video_width = (grub_getwh () >> 8);
params->video_height = (grub_getwh () & 0xff);
{
grub_term_output_t term;
int found = 0;
FOR_ACTIVE_TERM_OUTPUTS(term)
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->font_size = 16;
params->ofw_signature = GRUB_LINUX_OFW_SIGNATURE;
@ -165,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;
}
@ -211,7 +233,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
kernel_size = prot_size;
if (grub_file_read (file, kernel_addr, prot_size) != (int) prot_size)
grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
if (grub_errno == GRUB_ERR_NONE)
grub_loader_set (grub_linux_boot, grub_linux_unload, 1);
@ -242,13 +264,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (argc == 0)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "No module specified");
grub_error (GRUB_ERR_BAD_ARGUMENT, "no module specified");
goto fail;
}
if (! kernel_addr)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "You need to load the kernel first.");
grub_error (GRUB_ERR_BAD_ARGUMENT, "you need to load the kernel first");
goto fail;
}
@ -260,7 +282,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (grub_file_read (file, (void *) GRUB_OFW_LINUX_INITRD_ADDR,
initrd_size) != (int) initrd_size)
{
grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
goto fail;
}
@ -276,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
@ -33,6 +33,8 @@
#include <grub/video_fb.h>
#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
@ -547,8 +549,23 @@ grub_linux_boot (void)
/* Initialize these last, because terminal position could be affected by printfs above. */
if (params->have_vga == GRUB_VIDEO_TYPE_TEXT)
{
params->video_cursor_x = grub_getxy () >> 8;
params->video_cursor_y = grub_getxy () & 0xff;
grub_term_output_t term;
int found = 0;
FOR_ACTIVE_TERM_OUTPUTS(term)
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)
{
params->video_cursor_x = 0;
params->video_cursor_y = 0;
}
}
#ifdef __x86_64__
@ -613,7 +630,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;
}
@ -673,7 +690,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
len = 0x400 - sizeof (lh);
if (grub_file_read (file, (char *) real_mode_mem + sizeof (lh), len) != len)
{
grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
goto fail;
}
@ -712,8 +729,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;
@ -862,7 +879,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
len = prot_size;
if (grub_file_read (file, (void *) GRUB_LINUX_BZIMAGE_ADDR, len) != len)
grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
if (grub_errno == GRUB_ERR_NONE)
{
@ -897,13 +914,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (argc == 0)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "No module specified");
grub_error (GRUB_ERR_BAD_ARGUMENT, "no module specified");
goto fail;
}
if (! loaded)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "You need to load the kernel first.");
grub_error (GRUB_ERR_BAD_ARGUMENT, "you need to load the kernel first");
goto fail;
}
@ -951,7 +968,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (addr < addr_min)
{
grub_error (GRUB_ERR_OUT_OF_RANGE, "The initrd is too big");
grub_error (GRUB_ERR_OUT_OF_RANGE, "the initrd is too big");
goto fail;
}
@ -959,12 +976,12 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (grub_file_read (file, initrd_mem, size) != size)
{
grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
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;
@ -982,9 +999,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_MAGIC2,
.ebx = PTR_TO_UINT32 (mbi_dest),
.eax = MULTIBOOT_BOOTLOADER_MAGIC,
.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,78 +140,33 @@ 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 ();
if (argc == 0)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "No kernel specified");
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");
grub_error (GRUB_ERR_BAD_ARGUMENT, "couldn't open file");
goto fail;
}
len = grub_file_read (file, buffer, MULTIBOOT_SEARCH);
if (len < 32)
{
grub_error (GRUB_ERR_BAD_OS, "File too small");
grub_error (GRUB_ERR_BAD_OS, "file too small");
goto fail;
}
@ -250,52 +176,29 @@ grub_multiboot (int argc, char *argv[])
((char *) header <= buffer + len - 12) || (header = 0);
header = (struct multiboot_header *) ((char *) header + 4))
{
if (header->magic == MULTIBOOT_MAGIC
if (header->magic == MULTIBOOT_HEADER_MAGIC
&& !(header->magic + header->flags + header->checksum))
break;
}
if (header == 0)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "No multiboot header found");
grub_error (GRUB_ERR_BAD_ARGUMENT, "no multiboot header found");
goto fail;
}
if (header->flags & MULTIBOOT_UNSUPPORTED)
if (header->flags & UNSUPPORTED_FLAGS)
{
grub_error (GRUB_ERR_UNKNOWN_OS,
"Unsupported flag: 0x%x", header->flags);
"unsupported flag: 0x%x", header->flags);
goto fail;
}
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,37 @@ 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[sizeof ("XXXXXXXXXXxXXXXXXXXXXxXXXXXXXXXX,XXXXXXXXXXxXXXXXXXXXX,auto")];
if (header->depth && header->width && header->height)
grub_sprintf (buf, "%dx%dx%d,%dx%d,auto", header->width,
header->height, header->depth, header->width,
header->height);
else if (header->width && header->height)
grub_sprintf (buf, "%dx%d,auto", header->width, header->height);
else
grub_sprintf (buf, "auto");
grub_env_set ("gfxpayload", 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,33 +278,29 @@ 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)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "No module specified");
grub_error (GRUB_ERR_BAD_ARGUMENT, "no module specified");
goto fail;
}
if (!mbi)
if (!grub_multiboot_payload_orig)
{
grub_error (GRUB_ERR_BAD_ARGUMENT,
"You need to load the multiboot kernel first");
"you need to load the multiboot kernel first");
goto fail;
}
@ -428,73 +313,19 @@ grub_module (int argc, char *argv[])
if (! module)
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)
err = grub_multiboot_add_module ((grub_addr_t) module, size,
argc - 1, argv + 1);
if (err)
goto fail;
for (i = 0; i < cmdline_argc; i++)
if (grub_file_read (file, module, size) != size)
{
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;
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
goto fail;
}
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

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

@ -0,0 +1,463 @@
/*
* 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;
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_malloc (grub_strlen (modevar)
+ sizeof (DEFAULT_VIDEO_MODE) + 1);
if (! tmp)
return grub_errno;
grub_sprintf (tmp, "%s;" DEFAULT_VIDEO_MODE, modevar);
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 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. */
@ -102,7 +106,7 @@ grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags)
if (dev)
grub_device_close (dev);
/* Ignore errors. Perhaps it's not fatal. */
grub_errno = GRUB_ERR_NONE;
@ -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 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;
}
@ -234,7 +247,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
len = real_size + GRUB_DISK_SECTOR_SIZE - sizeof (lh);
if (grub_file_read (file, grub_linux_tmp_addr + sizeof (lh), len) != len)
{
grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
goto fail;
}
@ -265,7 +278,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
len = prot_size;
if (grub_file_read (file, (void *) GRUB_LINUX_BZIMAGE_ADDR, len) != len)
grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
if (grub_errno == GRUB_ERR_NONE)
{
@ -299,13 +312,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (argc == 0)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "No module specified");
grub_error (GRUB_ERR_BAD_ARGUMENT, "no module specified");
goto fail;
}
if (!loaded)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "You need to load the kernel first.");
grub_error (GRUB_ERR_BAD_ARGUMENT, "you need to load the kernel first");
goto fail;
}
@ -314,7 +327,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (!(lh->header == grub_cpu_to_le32 (GRUB_LINUX_MAGIC_SIGNATURE)
&& grub_le_to_cpu16 (lh->version) >= 0x0200))
{
grub_error (GRUB_ERR_BAD_OS, "The kernel is too old for initrd.");
grub_error (GRUB_ERR_BAD_OS, "the kernel is too old for initrd");
goto fail;
}
@ -357,13 +370,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (addr < addr_min)
{
grub_error (GRUB_ERR_OUT_OF_RANGE, "The initrd is too big");
grub_error (GRUB_ERR_OUT_OF_RANGE, "the initrd is too big");
goto fail;
}
if (grub_file_read (file, (void *) addr, size) != size)
{
grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
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 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

@ -32,6 +32,7 @@
#include <grub/term.h>
#include <grub/command.h>
#include <grub/gzio.h>
#include <grub/i18n.h>
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
@ -532,12 +533,12 @@ grub_cmd_devprop_load (grub_command_t cmd __attribute__ ((unused)),
unsigned i, j;
if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "File name required. ");
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
file = grub_gzfile_open (args[0], 1);
if (! file)
return grub_error (GRUB_ERR_FILE_NOT_FOUND,
"Couldn't load device-propertie dump. ");
"couldn't load device-propertie dump");
size = grub_file_size (file);
buf = grub_malloc (size);
if (!buf)
@ -837,7 +838,7 @@ grub_xnu_boot_resume (void)
state.eax = grub_xnu_arg1;
return grub_relocator32_boot (grub_xnu_heap_start, grub_xnu_heap_will_be_at,
state);
state);
}
/* Setup video for xnu. */
@ -1109,7 +1110,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 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
}

View file

@ -71,7 +71,7 @@ grub_macho_file (grub_file_t file)
!= sizeof (filestart))
{
grub_error_push ();
grub_error (GRUB_ERR_READ_ERROR, "Cannot read Mach-O header.");
grub_error (GRUB_ERR_READ_ERROR, "cannot read Mach-O header");
goto fail;
}
@ -95,7 +95,7 @@ grub_macho_file (grub_file_t file)
{
grub_free (archs);
grub_error_push ();
grub_error (GRUB_ERR_READ_ERROR, "Cannot read Mach-O header.");
grub_error (GRUB_ERR_READ_ERROR, "cannot read Mach-O header");
goto fail;
}

View file

@ -25,13 +25,13 @@ SUFFIX (grub_macho_parse) (grub_macho_t macho)
|| grub_file_read (macho->file, &head, sizeof (head))
!= sizeof(head))
{
grub_error (GRUB_ERR_READ_ERROR, "Cannot read Mach-O header.");
grub_error (GRUB_ERR_READ_ERROR, "cannot read Mach-O header");
macho->offsetXX = -1;
return;
}
if (head.magic != GRUB_MACHO_MAGIC)
{
grub_error (GRUB_ERR_BAD_OS, "Invalid Mach-O " XX "-bit header.");
grub_error (GRUB_ERR_BAD_OS, "invalid Mach-O " XX "-bit header");
macho->offsetXX = -1;
return;
}
@ -49,7 +49,7 @@ SUFFIX (grub_macho_parse) (grub_macho_t macho)
(grub_size_t) macho->cmdsizeXX)
!= (grub_ssize_t) macho->cmdsizeXX)
{
grub_error (GRUB_ERR_READ_ERROR, "Cannot read Mach-O header.");
grub_error (GRUB_ERR_READ_ERROR, "cannot read Mach-O header");
macho->offsetXX = -1;
}
}
@ -66,7 +66,7 @@ grub_macho_cmds_iterate (grub_macho_t macho,
grub_uint8_t *hdrs = macho->cmdsXX;
int i;
if (! macho->cmdsXX)
return grub_error (GRUB_ERR_BAD_OS, "Couldn't find " XX "-bit Mach-O");
return grub_error (GRUB_ERR_BAD_OS, "couldn't find " XX "-bit Mach-O");
for (i = 0; i < macho->ncmdsXX; i++)
{
struct grub_macho_cmd *hdr = (struct grub_macho_cmd *) hdrs;
@ -92,13 +92,13 @@ SUFFIX (grub_macho_readfile) (grub_macho_t macho, void *dest)
grub_ssize_t read;
if (! SUFFIX (grub_macho_contains_macho) (macho))
return grub_error (GRUB_ERR_BAD_OS,
"Couldn't read architecture-specific part");
"couldn't read architecture-specific part");
if (grub_file_seek (macho->file, macho->offsetXX) == (grub_off_t) -1)
{
grub_error_push ();
return grub_error (GRUB_ERR_BAD_OS,
"Invalid offset in program header.");
"invalid offset in program header");
}
read = grub_file_read (macho->file, dest,
@ -107,7 +107,7 @@ SUFFIX (grub_macho_readfile) (grub_macho_t macho, void *dest)
{
grub_error_push ();
return grub_error (GRUB_ERR_BAD_OS,
"Couldn't read architecture-specific part");
"couldn't read architecture-specific part");
}
return GRUB_ERR_NONE;
}
@ -151,11 +151,11 @@ SUFFIX (grub_macho_size) (grub_macho_t macho, grub_macho_addr_t *segments_start,
grub_macho_cmds_iterate (macho, calcsize, 0);
if (nr_phdrs == 0)
return grub_error (GRUB_ERR_BAD_OS, "No program headers present");
return grub_error (GRUB_ERR_BAD_OS, "no program headers present");
if (*segments_end < *segments_start)
/* Very bad addresses. */
return grub_error (GRUB_ERR_BAD_OS, "Bad program header load addresses");
return grub_error (GRUB_ERR_BAD_OS, "bad program header load addresses");
return GRUB_ERR_NONE;
}
@ -187,7 +187,7 @@ SUFFIX (grub_macho_load) (grub_macho_t macho, char *offset, int flags)
{
grub_error_push ();
grub_error (GRUB_ERR_BAD_OS,
"Invalid offset in program header.");
"invalid offset in program header");
return 1;
}
@ -201,8 +201,8 @@ SUFFIX (grub_macho_load) (grub_macho_t macho, char *offset, int flags)
/* XXX How can we free memory from `load_hook'? */
grub_error_push ();
err=grub_error (GRUB_ERR_BAD_OS,
"Couldn't read segment from file: "
"wanted 0x%lx bytes; read 0x%lx bytes.",
"couldn't read segment from file: "
"wanted 0x%lx bytes; read 0x%lx bytes",
hdr->filesize, read);
return 1;
}

View file

@ -1,461 +0,0 @@
/* multiboot2.c - boot a multiboot 2 OS image. */
/*
* 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/>.
*/
#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 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)
{
@ -58,7 +48,7 @@ find_multi_boot1_header (grub_file_t file)
((char *) header <= buffer + len - 12) || (header = 0);
header = (struct multiboot_header *) ((char *) header + 4))
{
if (header->magic == MULTIBOOT_MAGIC
if (header->magic == MULTIBOOT_HEADER_MAGIC
&& !(header->magic + header->flags + header->checksum))
{
found_status = 1;
@ -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[])
@ -108,25 +70,23 @@ grub_cmd_multiboot_loader (grub_command_t cmd __attribute__ ((unused)),
if (argc == 0)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "No kernel specified");
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");
grub_error (GRUB_ERR_BAD_ARGUMENT, "couldn't open file");
goto fail;
}
/* 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");
grub_error (GRUB_ERR_BAD_OS, "multiboot header not found");
goto fail;
}
@ -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

@ -1,7 +1,7 @@
/* linux.c - boot Linux */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
* Copyright (C) 2003,2004,2005,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
@ -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)
@ -75,10 +76,10 @@ grub_linux_release_mem (void)
linux_args = 0;
if (linux_addr && grub_ieee1275_release (linux_addr, linux_size))
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "Can not release memory");
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot release memory");
if (initrd_addr && grub_ieee1275_release (initrd_addr, initrd_size))
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "Can not release memory");
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot release memory");
linux_addr = 0;
initrd_addr = 0;
@ -128,7 +129,7 @@ grub_linux_load32 (grub_elf_t elf)
break;
}
if (found_addr == -1)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "Could not claim memory.");
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't claim memory");
/* 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);
@ -178,7 +179,7 @@ grub_linux_load64 (grub_elf_t elf)
break;
}
if (found_addr == -1)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "Could not claim memory.");
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't claim memory");
/* 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);
@ -222,7 +223,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
if (elf->ehdr.ehdr32.e_type != ET_EXEC)
{
grub_error (GRUB_ERR_UNKNOWN_OS,
"This ELF file is not of the right type\n");
"this ELF file is not of the right type");
goto out;
}
@ -236,7 +237,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
grub_linux_load64 (elf);
else
{
grub_error (GRUB_ERR_BAD_FILE_TYPE, "Unknown ELF class");
grub_error (GRUB_ERR_BAD_FILE_TYPE, "unknown ELF class");
goto out;
}
@ -297,7 +298,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (!loaded)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "You need to load the kernel first.");
grub_error (GRUB_ERR_BAD_ARGUMENT, "you need to load the kernel first");
goto fail;
}
@ -321,7 +322,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (found_addr == -1)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, "Can not claim memory");
grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot claim memory");
goto fail;
}
@ -330,7 +331,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (grub_file_read (file, (void *) addr, size) != size)
{
grub_ieee1275_release (addr, size);
grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
goto fail;
}
@ -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 a linux kernel");
0, N_("Load Linux."));
cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd,
0, "load an 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;
@ -256,14 +257,14 @@ grub_linux_load64 (grub_elf_t elf)
paddr = alloc_phys (linux_size + off);
if (paddr == (grub_addr_t) -1)
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Could not allocate physical memory.");
"couldn't allocate physical memory");
ret = grub_ieee1275_map_physical (paddr, linux_addr - off,
linux_size + off, IEEE1275_MAP_DEFAULT);
if (ret)
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Could not map physical 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;
@ -317,7 +318,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
if (elf->ehdr.ehdr32.e_type != ET_EXEC)
{
grub_error (GRUB_ERR_UNKNOWN_OS,
"This ELF file is not of the right type\n");
"this ELF file is not of the right type");
goto out;
}
@ -328,7 +329,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
grub_linux_load64 (elf);
else
{
grub_error (GRUB_ERR_BAD_FILE_TYPE, "Unknown ELF class");
grub_error (GRUB_ERR_BAD_FILE_TYPE, "unknown ELF class");
goto out;
}
@ -390,7 +391,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (!loaded)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "You need to load the kernel first.");
grub_error (GRUB_ERR_BAD_ARGUMENT, "you need to load the kernel first");
goto fail;
}
@ -405,14 +406,14 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (paddr == (grub_addr_t) -1)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Could not allocate physical memory.");
"couldn't allocate physical memory");
goto fail;
}
ret = grub_ieee1275_map_physical (paddr, addr, size, IEEE1275_MAP_DEFAULT);
if (ret)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Could not map physical memory.");
"couldn't map physical memory");
goto fail;
}
@ -421,7 +422,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
if (grub_file_read (file, (void *) addr, size) != size)
{
grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
goto fail;
}
@ -516,9 +517,9 @@ GRUB_MOD_INIT(linux)
fetch_translations ();
cmd_linux = grub_register_command ("linux", grub_cmd_linux,
0, "load a linux kernel");
0, N_("Load Linux."));
cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd,
0, "load an initrd");
0, N_("Load initrd."));
my_mod = mod;
}

View file

@ -32,6 +32,7 @@
#include <grub/command.h>
#include <grub/misc.h>
#include <grub/env.h>
#include <grub/i18n.h>
struct grub_xnu_devtree_key *grub_xnu_devtree_root = 0;
static int driverspackagenum = 0;
@ -67,7 +68,7 @@ grub_xnu_heap_malloc (int size)
advanced mm is ready. */
grub_xnu_heap_start
= XNU_RELOCATOR (realloc) (grub_xnu_heap_start,
newblknum
newblknum
* GRUB_XNU_HEAP_ALLOC_BLOCK);
if (!grub_xnu_heap_start)
return NULL;
@ -365,7 +366,7 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
{
grub_macho_close (macho);
return grub_error (GRUB_ERR_BAD_OS,
"Kernel doesn't contain suitable 32-bit architecture");
"kernel doesn't contain suitable 32-bit architecture");
}
err = grub_macho_size32 (macho, &startcode, &endcode, GRUB_MACHO_NOBSS);
@ -463,7 +464,7 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)),
{
grub_macho_close (macho);
return grub_error (GRUB_ERR_BAD_OS,
"Kernel doesn't contain suitable 64-bit architecture");
"kernel doesn't contain suitable 64-bit architecture");
}
err = grub_macho_size64 (macho, &startcode, &endcode, GRUB_MACHO_NOBSS);
@ -654,7 +655,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
if (macho)
grub_macho_close (macho);
return grub_error (GRUB_ERR_BAD_OS,
"Extension doesn't contain suitable architecture");
"extension doesn't contain suitable architecture");
}
if (grub_xnu_is_64bit)
machosize = grub_macho_filesize64 (macho);
@ -719,7 +720,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
{
grub_file_close (infoplist);
grub_error_push ();
return grub_error (GRUB_ERR_BAD_OS, "Couldn't read file %s: ",
return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s: ",
infoplistname);
}
grub_file_close (infoplist);
@ -763,7 +764,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
file = grub_gzfile_open (args[0], 1);
if (! file)
return grub_error (GRUB_ERR_FILE_NOT_FOUND,
"Couldn't load driver package");
"couldn't load driver package");
/* Sometimes caches are fat binary. Errgh. */
if (grub_file_read (file, &head, sizeof (head))
@ -773,7 +774,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
can hardly imagine a valid package shorter than 20 bytes. */
grub_file_close (file);
grub_error_push ();
return grub_error (GRUB_ERR_BAD_OS, "Couldn't read file %s", args[0]);
return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[0]);
}
/* Find the corresponding architecture. */
@ -786,7 +787,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
grub_file_close (file);
grub_error_push ();
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Couldn't read file %s", args[0]);
"couldn't read file %s", args[0]);
}
if (grub_file_read (file, archs,
@ -795,7 +796,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
{
grub_free (archs);
grub_error_push ();
return grub_error (GRUB_ERR_READ_ERROR, "Cannot read fat header.");
return grub_error (GRUB_ERR_READ_ERROR, "cannot read fat header");
}
for (i = 0; i < narchs; i++)
{
@ -848,7 +849,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
{
grub_file_close (file);
grub_error_push ();
return grub_error (GRUB_ERR_BAD_OS, "Couldn't read file %s", args[0]);
return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[0]);
}
grub_file_close (file);
@ -875,7 +876,7 @@ grub_cmd_xnu_ramdisk (grub_command_t cmd __attribute__ ((unused)),
file = grub_gzfile_open (args[0], 1);
if (! file)
return grub_error (GRUB_ERR_FILE_NOT_FOUND,
"Couldn't load ramdisk");
"couldn't load ramdisk");
err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE);
if (err)
@ -891,7 +892,7 @@ grub_cmd_xnu_ramdisk (grub_command_t cmd __attribute__ ((unused)),
{
grub_file_close (file);
grub_error_push ();
return grub_error (GRUB_ERR_BAD_OS, "Couldn't read file %s", args[0]);
return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[0]);
}
return grub_xnu_register_memory ("RAMDisk", 0, loadto, size);
}
@ -917,7 +918,7 @@ grub_xnu_check_os_bundle_required (char *plistname, char *osbundlereq,
{
grub_file_close (file);
grub_error_push ();
grub_error (GRUB_ERR_BAD_OS, "Couldn't read file %s", plistname);
grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", plistname);
return 0;
}
@ -927,14 +928,14 @@ grub_xnu_check_os_bundle_required (char *plistname, char *osbundlereq,
{
grub_file_close (file);
grub_error_push ();
grub_error (GRUB_ERR_OUT_OF_MEMORY, "Couldn't read file %s", plistname);
grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't read file %s", plistname);
return 0;
}
if (grub_file_read (file, buf, size) != (grub_ssize_t) (size))
{
grub_file_close (file);
grub_error_push ();
grub_error (GRUB_ERR_BAD_OS, "Couldn't read file %s", plistname);
grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", plistname);
return 0;
}
grub_file_close (file);
@ -1326,20 +1327,20 @@ grub_xnu_fill_devicetree (void)
nextdot = curdot + grub_strlen (curdot) + 1;
name = grub_realloc (name, nextdot - curdot + 1);
if (!name)
return 1;
unescape (name, curdot, nextdot, &len);
name[len] = 0;
curvalue = grub_xnu_create_value (curkey, name);
grub_free (name);
data = grub_malloc (grub_strlen (var->value) + 1);
if (!data)
return 1;
unescape (data, var->value, var->value + grub_strlen (var->value),
&len);
curvalue->datasize = len;
@ -1404,25 +1405,25 @@ static grub_command_t cmd_kextdir, cmd_ramdisk, cmd_resume, cmd_splash;
GRUB_MOD_INIT(xnu)
{
cmd_kernel = grub_register_command ("xnu_kernel", grub_cmd_xnu_kernel, 0,
"load a xnu kernel");
N_("Load XNU image."));
cmd_kernel64 = grub_register_command ("xnu_kernel64", grub_cmd_xnu_kernel64,
0, "load a 64-bit xnu kernel");
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,
"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");
N_("Load XNU ramdisk. "
"It will be seen as md0."));
cmd_splash = grub_register_command ("xnu_splash", grub_cmd_xnu_splash, 0,
"Load a splash image for XNU");
N_("Load a splash image for XNU."));
#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 ();

View file

@ -109,7 +109,7 @@ grub_xnu_resume (char *imagename)
!= (grub_ssize_t) codesize)
{
grub_file_close (file);
return grub_error (GRUB_ERR_READ_ERROR, "Cannot read resume image.");
return grub_error (GRUB_ERR_READ_ERROR, "cannot read resume image");
}
/* Read image. */
@ -119,7 +119,7 @@ grub_xnu_resume (char *imagename)
!= (grub_ssize_t) hibhead.image_size)
{
grub_file_close (file);
return grub_error (GRUB_ERR_READ_ERROR, "Cannot read resume image.");
return grub_error (GRUB_ERR_READ_ERROR, "cannot read resume image");
}
grub_file_close (file);