grub/grub-core/loader/i386/xnu.c

1140 lines
29 KiB
C
Raw Normal View History

/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 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/env.h>
#include <grub/file.h>
#include <grub/disk.h>
#include <grub/xnu.h>
#include <grub/cpu/xnu.h>
#include <grub/mm.h>
#include <grub/loader.h>
#include <grub/autoefi.h>
#include <grub/i386/tsc.h>
2009-11-09 17:43:53 +00:00
#include <grub/efi/api.h>
#include <grub/i386/pit.h>
#include <grub/misc.h>
2009-11-09 17:43:53 +00:00
#include <grub/charset.h>
#include <grub/term.h>
2009-11-09 17:43:53 +00:00
#include <grub/command.h>
2010-01-08 Carles Pina i Estany <carles@pina.cat> * loader/efi/appleloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/efi/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/efi/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/xnu.c: Include `<grub/i18n.h>'. (grub_cpu_xnu_init): Gettextizze. * loader/multiboot_loader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/powerpc/ieee1275/linux.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/sparc64/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_linux_load64): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/xnu.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * po/POTFILES: Add `loader/efi/appleloader.c', `loader/efi/chainloader.c', `loader/i386/efi/linux.c', `loader/i386/ieee1275/linux.c', `loader/i386/linux.c', `loader/i386/pc/chainloader.c', `loader/i386/pc/linux.c', `loader/i386/xnu.c', `loader/multiboot_loader.c', `loader/powerpc/ieee1275/linux.c', `loader/sparc64/ieee1275/linux.c' and `loader/xnu.c'.
2010-01-08 21:35:38 +00:00
#include <grub/i18n.h>
2010-04-01 20:17:26 +00:00
#include <grub/bitmap_scale.h>
2009-12-16 18:04:58 +00:00
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define DEFAULT_VIDEO_MODE "auto"
char grub_xnu_cmdline[1024];
2009-11-27 08:42:50 +00:00
grub_uint32_t grub_xnu_entry_point, grub_xnu_arg1, grub_xnu_stack;
/* Aliases set for some tables. */
struct tbl_alias
{
grub_efi_guid_t guid;
Add missing const qualifiers. * grub-core/commands/i386/pc/sendkey.c (keysym): Add missing const. * grub-core/commands/lspci.c (grub_pci_classname): Likewise. * grub-core/commands/menuentry.c (hotkey_aliases): Likewise. * grub-core/disk/lvm.c (grub_lvm_getvalue): Likewise. (grub_lvm_check_flag): Likewise. * grub-core/efiemu/i386/coredetect.c (grub_efiemu_get_default_core_name): Likewise * grub-core/efiemu/main.c (grub_efiemu_autocore): Likewise. * grub-core/fs/hfsplus.c (grub_hfsplus_catkey_internal): Likewise. * grub-core/fs/ntfs.c (fixup): Likewise. * grub-core/fs/xfs.c (grub_xfs_iterate_dir): Likewise. * grub-core/fs/zfs/zfs.c (decomp_entry): Likewise. (fzap_lookup): Likewise. (zap_lookup): Likewise. * grub-core/gnulib/regcomp.c (init_dfa): Likewise. * grub-core/lib/legacy_parse.c (check_option): Likewise. * grub-core/lib/posix_wrap/langinfo.h (nl_langinfo): Likewise. * grub-core/loader/i386/bsd.c (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. (grub_cmd_freebsd_module): Likewise. * grub-core/loader/i386/xnu.c (tbl_alias): Likewise. * grub-core/loader/xnu.c (grub_xnu_register_memory): Likewise. (grub_xnu_writetree_get_size): Likewise. (grub_xnu_writetree_toheap_real): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_register_memory): Likewise. (grub_xnu_check_os_bundle_required): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * grub-core/normal/color.c (color_list): Likewise. * grub-core/normal/completion.c (current_word): Likewise. * grub-core/normal/menu_entry.c (insert_string): Likewise. * grub-core/term/serial.c (grub_serial_find): Likewise. * grub-core/term/tparm.c (grub_terminfo_tparm): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_get_default_core_name): Likewise. * include/grub/i386/bsd.h (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. * include/grub/lib/arg.h (grub_arg_option): Likewise. * include/grub/net.h (grub_net_card_driver): Likewise. (grub_net_card): Likewise. (grub_net_app_protocol): Likewise. * include/grub/parttool.h (grub_parttool_argdesc): Likewise. * include/grub/serial.h (grub_serial_find): Likewise. * include/grub/tparm.h (grub_terminfo_tparm): Likewise. * include/grub/xnu.h (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * include/grub/zfs/zio_checksum.h (zio_checksum_t): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_t): ...here. * include/grub/zfs/zio_checksum.h (zio_checksum_info): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_info): ... here. Added missing const.
2011-11-30 15:20:13 +00:00
const char *name;
};
static struct tbl_alias table_aliases[] =
{
{GRUB_EFI_ACPI_20_TABLE_GUID, "ACPI_20"},
{GRUB_EFI_ACPI_TABLE_GUID, "ACPI"},
};
2009-11-09 17:43:53 +00:00
struct grub_xnu_devprop_device_descriptor
{
struct grub_xnu_devprop_device_descriptor *next;
struct grub_xnu_devprop_device_descriptor **prev;
2009-11-09 17:43:53 +00:00
struct property_descriptor *properties;
struct grub_efi_device_path *path;
int pathlen;
};
static int
utf16_strlen (grub_uint16_t *in)
{
int i;
for (i = 0; in[i]; i++);
return i;
}
/* Read frequency from a string in MHz and return it in Hz. */
static grub_uint64_t
readfrequency (const char *str)
{
grub_uint64_t num = 0;
int mul = 1000000;
int found = 0;
while (*str)
{
unsigned long digit;
2009-06-10 21:04:23 +00:00
digit = grub_tolower (*str) - '0';
if (digit > 9)
break;
found = 1;
num = num * 10 + digit;
str++;
}
num *= 1000000;
if (*str == '.')
{
str++;
while (*str)
{
unsigned long digit;
2009-06-10 21:04:23 +00:00
digit = grub_tolower (*str) - '0';
if (digit > 9)
break;
found = 1;
mul /= 10;
num = num + mul * digit;
str++;
}
}
if (! found)
return 0;
return num;
}
/* Thanks to Kabyl for precious information about Intel architecture. */
static grub_uint64_t
guessfsb (void)
{
const grub_uint64_t sane_value = 100000000;
grub_uint32_t manufacturer[3], max_cpuid, capabilities, msrlow;
grub_uint64_t start_tsc;
grub_uint64_t end_tsc;
grub_uint64_t tsc_ticks_per_ms;
if (! grub_cpu_is_cpuid_supported ())
return sane_value;
2009-06-10 21:04:23 +00:00
#ifdef APPLE_CC
asm volatile ("movl $0, %%eax\n"
#ifdef __x86_64__
"push %%rbx\n"
#else
"push %%ebx\n"
#endif
"cpuid\n"
#ifdef __x86_64__
"pop %%rbx\n"
#else
"pop %%ebx\n"
2009-06-10 21:04:23 +00:00
#endif
: "=a" (max_cpuid),
"=d" (manufacturer[1]), "=c" (manufacturer[2]));
2009-06-10 21:04:23 +00:00
/* Only Intel for now is done. */
if (grub_memcmp (manufacturer + 1, "ineIntel", 12) != 0)
return sane_value;
2009-06-10 21:04:23 +00:00
#else
asm volatile ("movl $0, %%eax\n"
"cpuid"
2009-06-10 21:04:23 +00:00
: "=a" (max_cpuid), "=b" (manufacturer[0]),
"=d" (manufacturer[1]), "=c" (manufacturer[2]));
/* Only Intel for now is done. */
if (grub_memcmp (manufacturer, "GenuineIntel", 12) != 0)
return sane_value;
#endif
/* Check Speedstep. */
if (max_cpuid < 1)
return sane_value;
#ifdef APPLE_CC
asm volatile ("movl $1, %%eax\n"
#ifdef __x86_64__
"push %%rbx\n"
#else
"push %%ebx\n"
2009-06-10 21:04:23 +00:00
#endif
"cpuid\n"
#ifdef __x86_64__
"pop %%rbx\n"
#else
"pop %%ebx\n"
#endif
: "=c" (capabilities):
2009-06-10 21:04:23 +00:00
: "%rax", "%rdx");
#else
asm volatile ("movl $1, %%eax\n"
"cpuid"
: "=c" (capabilities):
: "%rax", "%rbx", "%rdx");
#endif
if (! (capabilities & (1 << 7)))
return sane_value;
/* Calibrate the TSC rate. */
start_tsc = grub_get_tsc ();
grub_pit_wait (0xffff);
end_tsc = grub_get_tsc ();
tsc_ticks_per_ms = grub_divmod64 (end_tsc - start_tsc, 55, 0);
/* Read the multiplier. */
asm volatile ("movl $0x198, %%ecx\n"
"rdmsr"
: "=d" (msrlow)
:
: "%ecx", "%eax");
2009-06-10 21:04:23 +00:00
return grub_divmod64 (2000 * tsc_ticks_per_ms,
((msrlow >> 7) & 0x3e) + ((msrlow >> 14) & 1), 0);
}
2009-11-09 17:43:53 +00:00
struct property_descriptor
{
struct property_descriptor *next;
struct property_descriptor **prev;
2009-11-09 17:43:53 +00:00
grub_uint8_t *name;
grub_uint16_t *name16;
int name16len;
int length;
void *data;
};
static struct grub_xnu_devprop_device_descriptor *devices = 0;
2009-11-09 17:43:53 +00:00
grub_err_t
grub_xnu_devprop_remove_property (struct grub_xnu_devprop_device_descriptor *dev,
char *name)
{
struct property_descriptor *prop;
prop = grub_named_list_find (GRUB_AS_NAMED_LIST (dev->properties), name);
2009-11-09 17:43:53 +00:00
if (!prop)
return GRUB_ERR_NONE;
grub_free (prop->name);
grub_free (prop->name16);
grub_free (prop->data);
grub_list_remove (GRUB_AS_LIST (prop));
2009-11-09 17:43:53 +00:00
return GRUB_ERR_NONE;
}
grub_err_t
grub_xnu_devprop_remove_device (struct grub_xnu_devprop_device_descriptor *dev)
{
void *t;
struct property_descriptor *prop;
grub_list_remove (GRUB_AS_LIST (dev));
2009-11-09 17:43:53 +00:00
for (prop = dev->properties; prop; )
{
grub_free (prop->name);
grub_free (prop->name16);
grub_free (prop->data);
t = prop;
prop = prop->next;
grub_free (t);
}
grub_free (dev->path);
grub_free (dev);
return GRUB_ERR_NONE;
}
struct grub_xnu_devprop_device_descriptor *
grub_xnu_devprop_add_device (struct grub_efi_device_path *path, int length)
{
struct grub_xnu_devprop_device_descriptor *ret;
ret = grub_zalloc (sizeof (*ret));
if (!ret)
return 0;
ret->path = grub_malloc (length);
if (!ret->path)
{
grub_free (ret);
return 0;
}
ret->pathlen = length;
grub_memcpy (ret->path, path, length);
grub_list_push (GRUB_AS_LIST_P (&devices), GRUB_AS_LIST (ret));
return ret;
}
static grub_err_t
grub_xnu_devprop_add_property (struct grub_xnu_devprop_device_descriptor *dev,
grub_uint8_t *utf8, grub_uint16_t *utf16,
int utf16len, void *data, int datalen)
{
struct property_descriptor *prop;
prop = grub_malloc (sizeof (*prop));
if (!prop)
return grub_errno;
prop->name = utf8;
prop->name16 = utf16;
prop->name16len = utf16len;
prop->length = datalen;
prop->data = grub_malloc (prop->length);
if (!prop->data)
{
grub_free (prop);
grub_free (prop->name);
grub_free (prop->name16);
return grub_errno;
}
grub_memcpy (prop->data, data, prop->length);
grub_list_push (GRUB_AS_LIST_P (&dev->properties),
GRUB_AS_LIST (prop));
return GRUB_ERR_NONE;
}
grub_err_t
grub_xnu_devprop_add_property_utf8 (struct grub_xnu_devprop_device_descriptor *dev,
char *name, void *data, int datalen)
{
grub_uint8_t *utf8;
grub_uint16_t *utf16;
int len, utf16len;
grub_err_t err;
utf8 = (grub_uint8_t *) grub_strdup (name);
if (!utf8)
return grub_errno;
len = grub_strlen (name);
utf16 = grub_malloc (sizeof (grub_uint16_t) * len);
if (!utf16)
{
grub_free (utf8);
return grub_errno;
}
utf16len = grub_utf8_to_utf16 (utf16, len, utf8, len, NULL);
if (utf16len < 0)
{
grub_free (utf8);
grub_free (utf16);
return grub_errno;
}
err = grub_xnu_devprop_add_property (dev, utf8, utf16,
utf16len, data, datalen);
if (err)
{
grub_free (utf8);
grub_free (utf16);
return err;
}
return GRUB_ERR_NONE;
}
grub_err_t
grub_xnu_devprop_add_property_utf16 (struct grub_xnu_devprop_device_descriptor *dev,
grub_uint16_t *name, int namelen,
void *data, int datalen)
{
grub_uint8_t *utf8;
grub_uint16_t *utf16;
grub_err_t err;
utf16 = grub_malloc (sizeof (grub_uint16_t) * namelen);
if (!utf16)
return grub_errno;
grub_memcpy (utf16, name, sizeof (grub_uint16_t) * namelen);
utf8 = grub_malloc (namelen * 4 + 1);
if (!utf8)
{
grub_free (utf8);
return grub_errno;
}
*grub_utf16_to_utf8 ((grub_uint8_t *) utf8, name, namelen) = '\0';
err = grub_xnu_devprop_add_property (dev, utf8, utf16,
namelen, data, datalen);
if (err)
{
grub_free (utf8);
grub_free (utf16);
return err;
}
return GRUB_ERR_NONE;
}
static inline int
hextoval (char c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'a' && c <= 'z')
return c - 'a' + 10;
if (c >= 'A' && c <= 'Z')
return c - 'A' + 10;
return 0;
}
void
grub_cpu_xnu_unload (void)
{
struct grub_xnu_devprop_device_descriptor *dev1, *dev2;
for (dev1 = devices; dev1; )
{
dev2 = dev1->next;
grub_xnu_devprop_remove_device (dev1);
dev1 = dev2;
}
}
static grub_err_t
grub_cpu_xnu_fill_devprop (void)
{
struct grub_xnu_devtree_key *efikey;
int total_length = sizeof (struct grub_xnu_devprop_header);
struct grub_xnu_devtree_key *devprop;
struct grub_xnu_devprop_device_descriptor *device;
void *ptr;
struct grub_xnu_devprop_header *head;
void *t;
int numdevs = 0;
/* The key "efi". */
efikey = grub_xnu_create_key (&grub_xnu_devtree_root, "efi");
if (! efikey)
return grub_errno;
for (device = devices; device; device = device->next)
{
struct property_descriptor *propdesc;
total_length += sizeof (struct grub_xnu_devprop_device_header);
total_length += device->pathlen;
for (propdesc = device->properties; propdesc; propdesc = propdesc->next)
{
total_length += sizeof (grub_uint32_t);
total_length += sizeof (grub_uint16_t)
* (propdesc->name16len + 1);
total_length += sizeof (grub_uint32_t);
total_length += propdesc->length;
}
numdevs++;
}
devprop = grub_xnu_create_value (&(efikey->first_child), "device-properties");
if (!devprop)
return grub_errno;
devprop->data = grub_malloc (total_length);
devprop->datasize = total_length;
2009-11-09 17:43:53 +00:00
ptr = devprop->data;
head = ptr;
ptr = head + 1;
head->length = total_length;
head->alwaysone = 1;
head->num_devices = numdevs;
for (device = devices; device; )
{
struct grub_xnu_devprop_device_header *devhead;
struct property_descriptor *propdesc;
devhead = ptr;
devhead->num_values = 0;
ptr = devhead + 1;
grub_memcpy (ptr, device->path, device->pathlen);
ptr = (char *) ptr + device->pathlen;
for (propdesc = device->properties; propdesc; )
{
grub_uint32_t *len;
grub_uint16_t *name;
void *data;
len = ptr;
*len = 2 * propdesc->name16len + sizeof (grub_uint16_t)
+ sizeof (grub_uint32_t);
ptr = len + 1;
name = ptr;
grub_memcpy (name, propdesc->name16, 2 * propdesc->name16len);
name += propdesc->name16len;
/* NUL terminator. */
*name = 0;
ptr = name + 1;
len = ptr;
*len = propdesc->length + sizeof (grub_uint32_t);
data = len + 1;
ptr = data;
grub_memcpy (ptr, propdesc->data, propdesc->length);
ptr = (char *) ptr + propdesc->length;
grub_free (propdesc->name);
grub_free (propdesc->name16);
grub_free (propdesc->data);
t = propdesc;
propdesc = propdesc->next;
grub_free (t);
devhead->num_values++;
}
devhead->length = (char *) ptr - (char *) devhead;
t = device;
device = device->next;
grub_free (t);
}
devices = 0;
return GRUB_ERR_NONE;
}
static grub_err_t
grub_cmd_devprop_load (grub_command_t cmd __attribute__ ((unused)),
int argc, char *args[])
{
grub_file_t file;
void *buf, *bufstart, *bufend;
struct grub_xnu_devprop_header *head;
grub_size_t size;
unsigned i, j;
if (argc != 1)
2009-12-24 Carles Pina i Estany <carles@pina.cat> * bus/usb/usbhub.c: Fix capitalization, fullstop and newlines in grub_errno calls. * commands/acpi.c: Likewise. * commands/blocklist.c: Likewise. * commands/efi/loadbios.c: Likewise. * commands/i386/pc/drivemap.c: Likewise. * commands/loadenv.c: Likewise. * commands/memrw.c: Likewise. * commands/password.c: Likewise. * commands/videotest.c: Likewise. * disk/ata.c: Likewise. * disk/ata_pthru.c: Likewise. * disk/dmraid_nvidia.c: Likewise. * disk/ieee1275/nand.c: Likewise. * disk/ieee1275/ofdisk.c: Likewise. * disk/loopback.c: Likewise. * disk/lvm.c: Likewise. * disk/mdraid_linux.c: Likewise. * disk/raid.c: Likewise. * disk/raid6_recover.c: Likewise. * disk/scsi.c: Likewise. * efiemu/main.c: Likewise. * efiemu/mm.c: Likewise. * efiemu/pnvram.c: Likewise. * efiemu/symbols.c: Likewise. * font/font.c: Likewise. * fs/cpio.c: Likewise. * fs/hfsplus.c: Likewise. * fs/iso9660.c: Likewise. * fs/jfs.c: Likewise. * fs/minix.c: Likewise. * fs/ntfs.c: Likewise. * fs/ntfscomp.c: Likewise. * fs/reiserfs.c: Likewise. * fs/ufs.c: Likewise. * fs/xfs.c: Likewise. * gettext/gettext.c: Likewise. * include/grub/auth.h: Likewise. * kern/elf.c: Likewise. * kern/file.c: Likewise. * kern/ieee1275/init.c: Likewise. * kern/ieee1275/mmap.c: Likewise. * kern/ieee1275/openfw.c: Likewise. * kern/powerpc/dl.c: Likewise. * kern/sparc64/dl.c: Likewise. * lib/arg.c: Likewise. * loader/i386/bsd.c: Likewise. * loader/i386/bsdXX.c: Likewise. * loader/i386/efi/linux.c: Likewise. * loader/i386/efi/xnu.c: Likewise. * loader/i386/ieee1275/linux.c: Likewise. * loader/i386/linux.c: Likewise. * loader/i386/multiboot.c: Likewise. * loader/i386/pc/linux.c: Likewise. * loader/i386/pc/multiboot2.c: Likewise. * loader/i386/xnu.c: Likewise. * loader/ieee1275/multiboot2.c: Likewise. * loader/macho.c: Likewise. * loader/machoXX.c: Likewise. * loader/multiboot2.c: Likewise. * loader/multiboot_loader.c: Likewise. * loader/powerpc/ieee1275/linux.c: Likewise. * loader/sparc64/ieee1275/linux.c: Likewise. * loader/xnu.c: Likewise. * loader/xnu_resume.c: Likewise. * mmap/i386/pc/mmap.c: Likewise. * normal/menu_viewer.c: Likewise. * partmap/acorn.c: Likewise. * partmap/amiga.c: Likewise. * partmap/apple.c: Likewise. * script/lexer.c: Likewise. * term/gfxterm.c: Likewise. * term/i386/pc/serial.c: Likewise. * term/i386/pc/vga.c: Likewise. * term/ieee1275/ofconsole.c: Likewise. * term/terminfo.c: Likewise. * video/bitmap.c: Likewise. * video/efi_gop.c: Likewise. * video/efi_uga.c: Likewise. * video/fb/video_fb.c: Likewise. * video/i386/pc/vbe.c: Likewise. * video/readers/tga.c: Likewise. * video/video.c: Likewise.
2009-12-24 22:53:05 +00:00
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
2009-11-09 17:43:53 +00:00
file = grub_file_open (args[0]);
2009-11-09 17:43:53 +00:00
if (! file)
return grub_error (GRUB_ERR_FILE_NOT_FOUND,
2009-12-24 Carles Pina i Estany <carles@pina.cat> * bus/usb/usbhub.c: Fix capitalization, fullstop and newlines in grub_errno calls. * commands/acpi.c: Likewise. * commands/blocklist.c: Likewise. * commands/efi/loadbios.c: Likewise. * commands/i386/pc/drivemap.c: Likewise. * commands/loadenv.c: Likewise. * commands/memrw.c: Likewise. * commands/password.c: Likewise. * commands/videotest.c: Likewise. * disk/ata.c: Likewise. * disk/ata_pthru.c: Likewise. * disk/dmraid_nvidia.c: Likewise. * disk/ieee1275/nand.c: Likewise. * disk/ieee1275/ofdisk.c: Likewise. * disk/loopback.c: Likewise. * disk/lvm.c: Likewise. * disk/mdraid_linux.c: Likewise. * disk/raid.c: Likewise. * disk/raid6_recover.c: Likewise. * disk/scsi.c: Likewise. * efiemu/main.c: Likewise. * efiemu/mm.c: Likewise. * efiemu/pnvram.c: Likewise. * efiemu/symbols.c: Likewise. * font/font.c: Likewise. * fs/cpio.c: Likewise. * fs/hfsplus.c: Likewise. * fs/iso9660.c: Likewise. * fs/jfs.c: Likewise. * fs/minix.c: Likewise. * fs/ntfs.c: Likewise. * fs/ntfscomp.c: Likewise. * fs/reiserfs.c: Likewise. * fs/ufs.c: Likewise. * fs/xfs.c: Likewise. * gettext/gettext.c: Likewise. * include/grub/auth.h: Likewise. * kern/elf.c: Likewise. * kern/file.c: Likewise. * kern/ieee1275/init.c: Likewise. * kern/ieee1275/mmap.c: Likewise. * kern/ieee1275/openfw.c: Likewise. * kern/powerpc/dl.c: Likewise. * kern/sparc64/dl.c: Likewise. * lib/arg.c: Likewise. * loader/i386/bsd.c: Likewise. * loader/i386/bsdXX.c: Likewise. * loader/i386/efi/linux.c: Likewise. * loader/i386/efi/xnu.c: Likewise. * loader/i386/ieee1275/linux.c: Likewise. * loader/i386/linux.c: Likewise. * loader/i386/multiboot.c: Likewise. * loader/i386/pc/linux.c: Likewise. * loader/i386/pc/multiboot2.c: Likewise. * loader/i386/xnu.c: Likewise. * loader/ieee1275/multiboot2.c: Likewise. * loader/macho.c: Likewise. * loader/machoXX.c: Likewise. * loader/multiboot2.c: Likewise. * loader/multiboot_loader.c: Likewise. * loader/powerpc/ieee1275/linux.c: Likewise. * loader/sparc64/ieee1275/linux.c: Likewise. * loader/xnu.c: Likewise. * loader/xnu_resume.c: Likewise. * mmap/i386/pc/mmap.c: Likewise. * normal/menu_viewer.c: Likewise. * partmap/acorn.c: Likewise. * partmap/amiga.c: Likewise. * partmap/apple.c: Likewise. * script/lexer.c: Likewise. * term/gfxterm.c: Likewise. * term/i386/pc/serial.c: Likewise. * term/i386/pc/vga.c: Likewise. * term/ieee1275/ofconsole.c: Likewise. * term/terminfo.c: Likewise. * video/bitmap.c: Likewise. * video/efi_gop.c: Likewise. * video/efi_uga.c: Likewise. * video/fb/video_fb.c: Likewise. * video/i386/pc/vbe.c: Likewise. * video/readers/tga.c: Likewise. * video/video.c: Likewise.
2009-12-24 22:53:05 +00:00
"couldn't load device-propertie dump");
2009-11-09 17:43:53 +00:00
size = grub_file_size (file);
buf = grub_malloc (size);
if (!buf)
{
grub_file_close (file);
return grub_errno;
}
if (grub_file_read (file, buf, size) != (grub_ssize_t) size)
{
grub_file_close (file);
return grub_errno;
}
grub_file_close (file);
bufstart = buf;
bufend = (char *) buf + size;
head = buf;
buf = head + 1;
for (i = 0; i < grub_le_to_cpu32 (head->num_devices) && buf < bufend; i++)
{
struct grub_efi_device_path *dp, *dpstart;
struct grub_xnu_devprop_device_descriptor *dev;
struct grub_xnu_devprop_device_header *devhead;
devhead = buf;
buf = devhead + 1;
dpstart = buf;
do
{
dp = buf;
buf = (char *) buf + GRUB_EFI_DEVICE_PATH_LENGTH (dp);
}
while (!GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp) && buf < bufend);
dev = grub_xnu_devprop_add_device (dpstart, (char *) buf
- (char *) dpstart);
for (j = 0; j < grub_le_to_cpu32 (devhead->num_values) && buf < bufend;
j++)
{
grub_uint32_t *namelen;
grub_uint32_t *datalen;
grub_uint16_t *utf16;
void *data;
grub_err_t err;
namelen = buf;
buf = namelen + 1;
if (buf >= bufend)
break;
utf16 = buf;
buf = (char *) buf + *namelen - sizeof (grub_uint32_t);
if (buf >= bufend)
break;
datalen = buf;
buf = datalen + 1;
if (buf >= bufend)
break;
data = buf;
buf = (char *) buf + *datalen - sizeof (grub_uint32_t);
if (buf >= bufend)
break;
err = grub_xnu_devprop_add_property_utf16
(dev, utf16, (*namelen - sizeof (grub_uint32_t)
- sizeof (grub_uint16_t)) / sizeof (grub_uint16_t),
data, *datalen - sizeof (grub_uint32_t));
if (err)
{
grub_free (bufstart);
return err;
}
}
}
grub_free (bufstart);
return GRUB_ERR_NONE;
}
/* Fill device tree. */
/* FIXME: some entries may be platform-agnostic. Move them to loader/xnu.c. */
grub_err_t
grub_cpu_xnu_fill_devicetree (void)
{
struct grub_xnu_devtree_key *efikey;
struct grub_xnu_devtree_key *cfgtablekey;
struct grub_xnu_devtree_key *curval;
struct grub_xnu_devtree_key *runtimesrvkey;
struct grub_xnu_devtree_key *platformkey;
unsigned i, j;
/* The value "model". */
/* FIXME: may this value be sometimes different? */
curval = grub_xnu_create_value (&grub_xnu_devtree_root, "model");
if (! curval)
return grub_errno;
curval->datasize = sizeof ("ACPI");
curval->data = grub_strdup ("ACPI");
curval = grub_xnu_create_value (&grub_xnu_devtree_root, "compatible");
if (! curval)
return grub_errno;
curval->datasize = sizeof ("ACPI");
curval->data = grub_strdup ("ACPI");
/* The key "efi". */
efikey = grub_xnu_create_key (&grub_xnu_devtree_root, "efi");
if (! efikey)
return grub_errno;
/* Information about firmware. */
curval = grub_xnu_create_value (&(efikey->first_child), "firmware-revision");
if (! curval)
return grub_errno;
curval->datasize = (SYSTEM_TABLE_SIZEOF (firmware_revision));
curval->data = grub_malloc (curval->datasize);
if (! curval->data)
return grub_errno;
grub_memcpy (curval->data, (SYSTEM_TABLE_VAR(firmware_revision)),
curval->datasize);
curval = grub_xnu_create_value (&(efikey->first_child), "firmware-vendor");
if (! curval)
return grub_errno;
2009-06-10 21:04:23 +00:00
curval->datasize =
2 * (utf16_strlen (SYSTEM_TABLE_PTR (firmware_vendor)) + 1);
curval->data = grub_malloc (curval->datasize);
if (! curval->data)
2009-09-04 13:50:32 +00:00
return grub_errno;
grub_memcpy (curval->data, SYSTEM_TABLE_PTR (firmware_vendor),
curval->datasize);
curval = grub_xnu_create_value (&(efikey->first_child), "firmware-abi");
if (! curval)
return grub_errno;
curval->datasize = sizeof ("EFI32");
curval->data = grub_malloc (curval->datasize);
if (! curval->data)
return grub_errno;
if (SIZEOF_OF_UINTN == 4)
grub_memcpy (curval->data, "EFI32", curval->datasize);
else
grub_memcpy (curval->data, "EFI64", curval->datasize);
/* The key "platform". */
2009-06-10 21:04:23 +00:00
platformkey = grub_xnu_create_key (&(efikey->first_child),
"platform");
if (! platformkey)
return grub_errno;
/* Pass FSB frequency to the kernel. */
curval = grub_xnu_create_value (&(platformkey->first_child), "FSBFrequency");
if (! curval)
return grub_errno;
curval->datasize = sizeof (grub_uint64_t);
curval->data = grub_malloc (curval->datasize);
if (!curval->data)
return grub_errno;
/* First see if user supplies the value. */
const char *fsbvar = grub_env_get ("fsb");
if (! fsbvar)
2009-06-10 21:04:23 +00:00
*((grub_uint64_t *) curval->data) = 0;
else
*((grub_uint64_t *) curval->data) = readfrequency (fsbvar);
/* Try autodetect. */
if (! *((grub_uint64_t *) curval->data))
2009-06-10 21:04:23 +00:00
*((grub_uint64_t *) curval->data) = guessfsb ();
grub_dprintf ("xnu", "fsb autodetected as %llu\n",
(unsigned long long) *((grub_uint64_t *) curval->data));
2009-06-10 21:04:23 +00:00
cfgtablekey = grub_xnu_create_key (&(efikey->first_child),
"configuration-table");
if (!cfgtablekey)
return grub_errno;
/* Fill "configuration-table" key. */
for (i = 0; i < SYSTEM_TABLE (num_table_entries); i++)
{
void *ptr;
struct grub_xnu_devtree_key *curkey;
grub_efi_guid_t guid;
char guidbuf[64];
/* Retrieve current key. */
#ifdef GRUB_MACHINE_EFI
{
2009-06-10 21:04:23 +00:00
ptr = (void *)
grub_efi_system_table->configuration_table[i].vendor_table;
guid = grub_efi_system_table->configuration_table[i].vendor_guid;
}
2009-06-10 21:04:23 +00:00
#else
if (SIZEOF_OF_UINTN == 4)
{
ptr = (void *) (grub_addr_t) ((grub_efiemu_configuration_table32_t *)
SYSTEM_TABLE_PTR (configuration_table))[i]
.vendor_table;
guid =
((grub_efiemu_configuration_table32_t *)
SYSTEM_TABLE_PTR (configuration_table))[i].vendor_guid;
}
else
{
ptr = (void *) (grub_addr_t) ((grub_efiemu_configuration_table64_t *)
SYSTEM_TABLE_PTR (configuration_table))[i]
.vendor_table;
2009-06-10 21:04:23 +00:00
guid =
((grub_efiemu_configuration_table64_t *)
SYSTEM_TABLE_PTR (configuration_table))[i].vendor_guid;
}
#endif
/* The name of key for new table. */
2009-12-29 09:04:06 +00:00
grub_snprintf (guidbuf, sizeof (guidbuf), "%08x-%04x-%04x-%02x%02x-",
guid.data1, guid.data2, guid.data3, guid.data4[0],
guid.data4[1]);
for (j = 2; j < 8; j++)
2009-12-29 09:04:06 +00:00
grub_snprintf (guidbuf + grub_strlen (guidbuf),
sizeof (guidbuf) - grub_strlen (guidbuf),
"%02x", guid.data4[j]);
/* For some reason GUID has to be in uppercase. */
for (j = 0; guidbuf[j] ; j++)
if (guidbuf[j] >= 'a' && guidbuf[j] <= 'f')
guidbuf[j] += 'A' - 'a';
curkey = grub_xnu_create_key (&(cfgtablekey->first_child), guidbuf);
if (! curkey)
return grub_errno;
curval = grub_xnu_create_value (&(curkey->first_child), "guid");
if (! curval)
return grub_errno;
curval->datasize = sizeof (guid);
curval->data = grub_malloc (curval->datasize);
if (! curval->data)
2009-09-04 13:50:32 +00:00
return grub_errno;
grub_memcpy (curval->data, &guid, curval->datasize);
/* The value "table". */
curval = grub_xnu_create_value (&(curkey->first_child), "table");
if (! curval)
return grub_errno;
curval->datasize = SIZEOF_OF_UINTN;
curval->data = grub_malloc (curval->datasize);
if (! curval->data)
return grub_errno;
if (SIZEOF_OF_UINTN == 4)
*((grub_uint32_t *) curval->data) = (grub_addr_t) ptr;
else
*((grub_uint64_t *) curval->data) = (grub_addr_t) ptr;
/* Create alias. */
for (j = 0; j < sizeof (table_aliases) / sizeof (table_aliases[0]); j++)
if (grub_memcmp (&table_aliases[j].guid, &guid, sizeof (guid)) == 0)
break;
if (j != sizeof (table_aliases) / sizeof (table_aliases[0]))
{
curval = grub_xnu_create_value (&(curkey->first_child), "alias");
if (!curval)
return grub_errno;
curval->datasize = grub_strlen (table_aliases[j].name) + 1;
curval->data = grub_malloc (curval->datasize);
if (!curval->data)
return grub_errno;
grub_memcpy (curval->data, table_aliases[j].name, curval->datasize);
}
}
2009-06-10 21:04:23 +00:00
/* Create and fill "runtime-services" key. */
2009-06-10 21:04:23 +00:00
runtimesrvkey = grub_xnu_create_key (&(efikey->first_child),
"runtime-services");
if (! runtimesrvkey)
return grub_errno;
curval = grub_xnu_create_value (&(runtimesrvkey->first_child), "table");
if (! curval)
return grub_errno;
curval->datasize = SIZEOF_OF_UINTN;
curval->data = grub_malloc (curval->datasize);
if (! curval->data)
return grub_errno;
if (SIZEOF_OF_UINTN == 4)
2009-06-10 21:04:23 +00:00
*((grub_uint32_t *) curval->data)
= (grub_addr_t) SYSTEM_TABLE_PTR (runtime_services);
else
2009-06-10 21:04:23 +00:00
*((grub_uint64_t *) curval->data)
= (grub_addr_t) SYSTEM_TABLE_PTR (runtime_services);
2009-06-10 21:04:23 +00:00
return GRUB_ERR_NONE;
}
2009-11-27 08:42:50 +00:00
grub_err_t
grub_xnu_boot_resume (void)
{
struct grub_relocator32_state state;
state.esp = grub_xnu_stack;
state.ebp = grub_xnu_stack;
2009-11-27 08:42:50 +00:00
state.eip = grub_xnu_entry_point;
state.eax = grub_xnu_arg1;
2010-01-11 12:43:44 +00:00
return grub_relocator32_boot (grub_xnu_relocator, state);
2009-11-27 08:42:50 +00:00
}
2009-12-16 18:04:58 +00:00
/* Setup video for xnu. */
static grub_err_t
grub_xnu_set_video (struct grub_xnu_boot_params *params)
{
struct grub_video_mode_info mode_info;
int ret;
2010-04-01 20:17:26 +00:00
char *tmp;
const char *modevar;
2009-12-16 18:04:58 +00:00
void *framebuffer;
grub_err_t err;
2010-04-01 20:17:26 +00:00
struct grub_video_bitmap *bitmap = NULL;
2009-12-16 18:04:58 +00:00
modevar = grub_env_get ("gfxpayload");
/* Consider only graphical 32-bit deep modes. */
if (! modevar || *modevar == 0)
err = grub_video_set_mode (DEFAULT_VIDEO_MODE,
GRUB_VIDEO_MODE_TYPE_PURE_TEXT
| GRUB_VIDEO_MODE_TYPE_DEPTH_MASK,
32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS);
else
{
tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar);
2009-12-16 18:04:58 +00:00
if (! tmp)
2010-04-01 20:17:26 +00:00
return grub_errno;
2009-12-16 18:04:58 +00:00
err = grub_video_set_mode (tmp,
GRUB_VIDEO_MODE_TYPE_PURE_TEXT
| GRUB_VIDEO_MODE_TYPE_DEPTH_MASK,
32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS);
grub_free (tmp);
}
if (err)
return err;
2010-04-01 20:17:26 +00:00
ret = grub_video_get_info (&mode_info);
if (ret)
return grub_error (GRUB_ERR_IO, "couldn't retrieve video parameters");
2009-12-16 18:04:58 +00:00
if (grub_xnu_bitmap)
2010-04-01 20:17:26 +00:00
{
if (grub_xnu_bitmap_mode == GRUB_XNU_BITMAP_STRETCH)
err = grub_video_bitmap_create_scaled (&bitmap,
mode_info.width,
mode_info.height,
grub_xnu_bitmap,
GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST);
else
bitmap = grub_xnu_bitmap;
}
2010-06-24 19:22:40 +00:00
if (bitmap)
2010-06-12 11:17:28 +00:00
{
if (grub_xnu_bitmap_mode == GRUB_XNU_BITMAP_STRETCH)
err = grub_video_bitmap_create_scaled (&bitmap,
mode_info.width,
mode_info.height,
grub_xnu_bitmap,
GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST);
else
bitmap = grub_xnu_bitmap;
}
2010-04-01 20:17:26 +00:00
if (bitmap)
2009-12-16 18:04:58 +00:00
{
int x, y;
2010-04-01 20:17:26 +00:00
x = mode_info.width - bitmap->mode_info.width;
2009-12-16 18:04:58 +00:00
x /= 2;
2010-04-01 20:17:26 +00:00
y = mode_info.height - bitmap->mode_info.height;
2009-12-16 18:04:58 +00:00
y /= 2;
2010-04-01 20:17:26 +00:00
err = grub_video_blit_bitmap (bitmap,
2009-12-16 18:04:58 +00:00
GRUB_VIDEO_BLIT_REPLACE,
x > 0 ? x : 0,
y > 0 ? y : 0,
x < 0 ? -x : 0,
y < 0 ? -y : 0,
2010-04-01 20:17:26 +00:00
min (bitmap->mode_info.width,
2009-12-16 18:04:58 +00:00
mode_info.width),
2010-04-01 20:17:26 +00:00
min (bitmap->mode_info.height,
2009-12-16 18:04:58 +00:00
mode_info.height));
2010-06-12 11:17:28 +00:00
}
if (err)
{
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
bitmap = 0;
2009-12-16 18:04:58 +00:00
}
ret = grub_video_get_info_and_fini (&mode_info, &framebuffer);
if (ret)
return grub_error (GRUB_ERR_IO, "couldn't retrieve video parameters");
params->lfb_width = mode_info.width;
params->lfb_height = mode_info.height;
params->lfb_depth = mode_info.bpp;
params->lfb_line_len = mode_info.pitch;
params->lfb_base = (grub_addr_t) framebuffer;
2010-06-12 11:17:28 +00:00
params->lfb_mode = bitmap ? GRUB_XNU_VIDEO_SPLASH
2010-04-01 20:17:26 +00:00
: GRUB_XNU_VIDEO_TEXT_IN_VIDEO;
2009-12-16 18:04:58 +00:00
return GRUB_ERR_NONE;
}
/* Boot xnu. */
2009-06-10 21:04:23 +00:00
grub_err_t
grub_xnu_boot (void)
{
2010-01-11 12:43:44 +00:00
struct grub_xnu_boot_params *bootparams;
void *bp_in;
2010-01-11 12:43:44 +00:00
grub_addr_t bootparams_target;
grub_err_t err;
grub_efi_uintn_t memory_map_size = 0;
void *memory_map;
2010-01-11 12:43:44 +00:00
grub_addr_t memory_map_target;
grub_efi_uintn_t map_key = 0;
grub_efi_uintn_t descriptor_size = 0;
grub_efi_uint32_t descriptor_version = 0;
grub_uint64_t firstruntimepage, lastruntimepage;
grub_uint64_t curruntimepage;
2010-01-11 12:43:44 +00:00
grub_addr_t devtree_target;
grub_size_t devtreelen;
int i;
2009-11-27 08:42:50 +00:00
struct grub_relocator32_state state;
2009-11-09 17:43:53 +00:00
err = grub_autoefi_prepare ();
if (err)
return err;
err = grub_cpu_xnu_fill_devprop ();
if (err)
return err;
err = grub_cpu_xnu_fill_devicetree ();
if (err)
return err;
err = grub_xnu_fill_devicetree ();
if (err)
return err;
/* Page-align to avoid following parts to be inadvertently freed. */
err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE);
if (err)
return err;
/* Pass memory map to kernel. */
memory_map_size = 0;
memory_map = 0;
map_key = 0;
descriptor_size = 0;
descriptor_version = 0;
2009-09-03 17:19:59 +00:00
grub_dprintf ("xnu", "eip=%x\n", grub_xnu_entry_point);
const char *debug = grub_env_get ("debug");
if (debug && (grub_strword (debug, "all") || grub_strword (debug, "xnu")))
{
grub_printf ("Press any key to launch xnu\n");
grub_getkey ();
}
/* Relocate the boot parameters to heap. */
2010-01-11 12:43:44 +00:00
err = grub_xnu_heap_malloc (sizeof (*bootparams),
&bp_in, &bootparams_target);
2010-01-11 12:43:44 +00:00
if (err)
return err;
bootparams = bp_in;
2009-09-03 17:19:59 +00:00
/* Set video. */
2010-01-11 12:43:44 +00:00
err = grub_xnu_set_video (bootparams);
2009-09-03 17:19:59 +00:00
if (err != GRUB_ERR_NONE)
{
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
* grub-core/commands/acpihalt.c: Gettextized. * grub-core/commands/cacheinfo.c: Likewise. * grub-core/commands/cmp.c: Likewise. * grub-core/commands/efi/loadbios.c: Likewise. * grub-core/commands/gptsync.c: Likewise. * grub-core/commands/ieee1275/suspend.c: Likewise. * grub-core/commands/legacycfg.c: Likewise. * grub-core/commands/memrw.c: Likewise. * grub-core/commands/minicmd.c: Likewise. * grub-core/commands/parttool.c: Likewise. * grub-core/commands/time.c: Likewise. * grub-core/commands/videoinfo.c: Likewise. * grub-core/disk/geli.c: Likewise. * grub-core/disk/i386/pc/biosdisk.c: Likewise. * grub-core/disk/luks.c: Likewise. * grub-core/disk/lvm.c: Likewise. * grub-core/font/font_cmd.c: Likewise. * grub-core/fs/zfs/zfscrypt.c: Likewise. * grub-core/fs/zfs/zfsinfo.c: Likewise. * grub-core/gfxmenu/view.c: Likewise. * grub-core/kern/emu/hostdisk.c: Likewise. * grub-core/kern/emu/main.c: Likewise. * grub-core/kern/emu/misc.c: Likewise. * grub-core/kern/emu/mm.c: Likewise. * grub-core/kern/mips/arc/init.c: Likewise. * grub-core/kern/mips/loongson/init.c: Likewise. * grub-core/kern/partition.c: Likewise. * grub-core/lib/i386/halt.c: Likewise. * grub-core/lib/mips/arc/reboot.c: Likewise. * grub-core/lib/mips/loongson/reboot.c: Likewise. * grub-core/loader/i386/pc/chainloader.c: Likewise. * grub-core/loader/i386/xnu.c: Likewise. * grub-core/loader/multiboot.c: Likewise. * grub-core/net/bootp.c: Likewise. * grub-core/net/net.c: Likewise. * grub-core/normal/term.c: Likewise. * grub-core/partmap/bsdlabel.c: Likewise. * grub-core/parttool/msdospart.c: Likewise. * grub-core/term/gfxterm.c: Likewise. * grub-core/term/terminfo.c: Likewise. * grub-core/video/i386/pc/vbe.c: Likewise. * util/grub-menulst2cfg.c: Likewise. * util/grub-mkdevicemap.c: Likewise. * util/grub-mklayout.c: Likewise. * util/grub-mkrelpath.c: Likewise. * util/grub-script-check.c: Likewise. * util/ieee1275/grub-ofpathname.c: Likewise. * util/resolve.c: Likewise.
2011-11-11 20:44:56 +00:00
grub_puts_ (N_("Booting in blind mode"));
2009-09-03 17:19:59 +00:00
2010-01-11 12:43:44 +00:00
bootparams->lfb_mode = 0;
bootparams->lfb_width = 0;
bootparams->lfb_height = 0;
bootparams->lfb_depth = 0;
bootparams->lfb_line_len = 0;
bootparams->lfb_base = 0;
2009-09-03 17:19:59 +00:00
}
if (grub_autoefi_get_memory_map (&memory_map_size, memory_map,
&map_key, &descriptor_size,
&descriptor_version) < 0)
return grub_errno;
2009-09-03 17:19:59 +00:00
/* We will do few allocations later. Reserve some space for possible
memory map growth. */
memory_map_size += 20 * descriptor_size;
2010-01-11 12:43:44 +00:00
err = grub_xnu_heap_malloc (memory_map_size,
&memory_map, &memory_map_target);
if (err)
return err;
2010-01-11 12:43:44 +00:00
err = grub_xnu_writetree_toheap (&devtree_target, &devtreelen);
if (err)
return err;
2010-01-11 12:43:44 +00:00
grub_memcpy (bootparams->cmdline, grub_xnu_cmdline,
sizeof (bootparams->cmdline));
2010-01-11 12:43:44 +00:00
bootparams->devtree = devtree_target;
bootparams->devtreelen = devtreelen;
2009-09-03 17:19:59 +00:00
2010-04-21 08:01:41 +00:00
err = grub_autoefi_finish_boot_services (&memory_map_size, memory_map,
&map_key, &descriptor_size,
&descriptor_version);
2010-04-20 16:08:26 +00:00
if (err)
return err;
2009-09-03 17:19:59 +00:00
bootparams->efi_system_table = (grub_addr_t) grub_autoefi_system_table;
2009-09-03 17:19:59 +00:00
2010-01-11 12:43:44 +00:00
firstruntimepage = (((grub_addr_t) grub_xnu_heap_target_start
+ grub_xnu_heap_size + GRUB_XNU_PAGESIZE - 1)
/ GRUB_XNU_PAGESIZE) + 20;
curruntimepage = firstruntimepage;
2009-09-02 16:18:11 +00:00
for (i = 0; (unsigned) i < memory_map_size / descriptor_size; i++)
{
grub_efi_memory_descriptor_t *curdesc = (grub_efi_memory_descriptor_t *)
((char *) memory_map + descriptor_size * i);
curdesc->virtual_start = curdesc->physical_start;
if (curdesc->type == GRUB_EFI_RUNTIME_SERVICES_DATA
|| curdesc->type == GRUB_EFI_RUNTIME_SERVICES_CODE)
{
curdesc->virtual_start = curruntimepage << 12;
curruntimepage += curdesc->num_pages;
2009-09-02 16:18:11 +00:00
if (curdesc->physical_start
<= (grub_addr_t) grub_autoefi_system_table
2009-09-02 16:18:11 +00:00
&& curdesc->physical_start + (curdesc->num_pages << 12)
> (grub_addr_t) grub_autoefi_system_table)
2010-01-11 12:43:44 +00:00
bootparams->efi_system_table
= (grub_addr_t) grub_autoefi_system_table
2009-09-02 16:18:11 +00:00
- curdesc->physical_start + curdesc->virtual_start;
if (SIZEOF_OF_UINTN == 8 && grub_xnu_is_64bit)
2009-09-02 16:18:11 +00:00
curdesc->virtual_start |= 0xffffff8000000000ULL;
}
}
lastruntimepage = curruntimepage;
2009-09-02 16:18:11 +00:00
2010-01-11 12:43:44 +00:00
bootparams->efi_mmap = memory_map_target;
bootparams->efi_mmap_size = memory_map_size;
bootparams->efi_mem_desc_size = descriptor_size;
bootparams->efi_mem_desc_version = descriptor_version;
2009-09-03 17:19:59 +00:00
2010-01-11 12:43:44 +00:00
bootparams->heap_start = grub_xnu_heap_target_start;
bootparams->heap_size = grub_xnu_heap_size;
bootparams->efi_runtime_first_page = firstruntimepage;
2009-09-05 22:25:33 +00:00
2010-01-11 12:43:44 +00:00
bootparams->efi_runtime_npages = lastruntimepage - firstruntimepage;
bootparams->efi_uintnbits = SIZEOF_OF_UINTN * 8;
2010-01-11 12:43:44 +00:00
bootparams->verminor = GRUB_XNU_BOOTARGS_VERMINOR;
bootparams->vermajor = GRUB_XNU_BOOTARGS_VERMAJOR;
/* Parameters for asm helper. */
2010-01-11 12:43:44 +00:00
grub_xnu_stack = bootparams->heap_start
+ bootparams->heap_size + GRUB_XNU_PAGESIZE;
grub_xnu_arg1 = bootparams_target;
2009-09-02 11:34:40 +00:00
grub_autoefi_set_virtual_address_map (memory_map_size, descriptor_size,
descriptor_version, memory_map);
2009-09-02 11:34:40 +00:00
2009-11-27 08:42:50 +00:00
state.eip = grub_xnu_entry_point;
state.eax = grub_xnu_arg1;
state.esp = grub_xnu_stack;
state.ebp = grub_xnu_stack;
2010-01-11 12:43:44 +00:00
return grub_relocator32_boot (grub_xnu_relocator, state);
}
2009-11-09 17:43:53 +00:00
static grub_command_t cmd_devprop_load;
void
grub_cpu_xnu_init (void)
{
cmd_devprop_load = grub_register_command ("xnu_devprop_load",
grub_cmd_devprop_load,
2010-01-08 Carles Pina i Estany <carles@pina.cat> * loader/efi/appleloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/efi/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/efi/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/chainloader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/i386/pc/linux.c: Include `<grub/i18n.h>'. (grub_cmd_linux): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/i386/xnu.c: Include `<grub/i18n.h>'. (grub_cpu_xnu_init): Gettextizze. * loader/multiboot_loader.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/powerpc/ieee1275/linux.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * loader/sparc64/ieee1275/linux.c: Include `<grub/i18n.h>'. (grub_linux_load64): Capitalise Linux. (GRUB_MOD_INIT): Gettextizze. * loader/xnu.c: Include `<grub/i18n.h>'. (GRUB_MOD_INIT): Gettextizze. * po/POTFILES: Add `loader/efi/appleloader.c', `loader/efi/chainloader.c', `loader/i386/efi/linux.c', `loader/i386/ieee1275/linux.c', `loader/i386/linux.c', `loader/i386/pc/chainloader.c', `loader/i386/pc/linux.c', `loader/i386/xnu.c', `loader/multiboot_loader.c', `loader/powerpc/ieee1275/linux.c', `loader/sparc64/ieee1275/linux.c' and `loader/xnu.c'.
2010-01-08 21:35:38 +00:00
0, N_("Load device-properties dump."));
2009-11-09 17:43:53 +00:00
}
void
grub_cpu_xnu_fini (void)
{
grub_unregister_command (cmd_devprop_load);
}