2009-12-18 Vladimir Serbinenko <phcoder@gmail.com>
Fix potential EfiEmu double prepare. * efiemu/main.c (prepared): New variable (grub_efiemu_unload): Set prepare to '0'. (grub_efiemu_prepare): Return if already prepared. Set prepared. set_virtual_address_map support. * include/grub/efi/efi.h (grub_efi_set_virtual_address_map): New prototype. * include/grub/efiemu/efiemu.h (grub_efiemu_write_sym_markers): New prototype. (grub_efiemu_crc32): Likewise. (grub_efiemu_crc64): Likewise. (grub_efiemu_set_virtual_address_map): Likewise. * include/grub/autoefi.h (grub_autoefi_exit_boot_services): New definition. (grub_autoefi_set_virtual_address_map): Likewise. * kern/efi/efi.c (grub_efi_set_virtual_address_map): New function. * loader/i386/xnu.c (grub_xnu_boot): Call set_virtual_address_map. Restructure flow to accomodate it. * efiemu/prepare.c (grub_efiemu_prepare): Support set_virtual_address_map. (grub_efiemu_crc): Recompute CRC32. * efiemu/runtime/efiemu.c (ptv_relocated): Renamed to ... (efiemu_ptv_relocated): ... this. Made global. All users updated. * efiemu/symbols.c (relocated_handle): New variable. (grub_efiemu_free_syms): Free relocated_handle. (grub_efiemu_alloc_syms): Allocate relocated_handle. (grub_efiemu_write_sym_markers): New function. (grub_efiemu_set_virtual_address_map): Likewise. Newer XNU parameters. * include/grub/i386/xnu.h (GRUB_XNU_BOOTARGS_VERMINOR): Change to 5. * include/grub/xnu.h (grub_xnu_extheader): Add nameaddr and namesize. (grub_xnu_fill_devicetree): New prototype. (grub_xnu_heap_real_start): New variable. * loader/xnu.c (get_name_ptr): New function. (grub_xnu_load_driver): Fill namelen and name. 64-bit xnu support. * conf/i386-efi.rmk (xnu_mod_SOURCES): Add 'loader/macho32.c' and 'loader/macho64.c'. * conf/i386-pc.rmk: Likewise. * conf/x86_64-efi.rmk: Likewise. * include/grub/i386/macho.h (grub_macho_thread64): New structure. * include/grub/xnu.h (grub_xnu_is_64bit): New variable. * include/grub/macho.h (grub_macho_segment64): New structure. * include/grub/machoload.h (grub_macho32_size): Renamed from ... (grub_macho_size32): ... to this. (grub_macho32_get_entry_point): Renamed from ... (grub_macho_get_entry_point32): ... to this. (grub_macho_contains_macho64): New prototype. (grub_macho_size64): Likewise. (grub_macho_get_entry_point64): Likewise. (grub_macho32_load): Renamed from ... (grub_macho_load32): ... to this. (grub_macho32_filesize): Renamed from ... (grub_macho_filesize32): ... to this. (grub_macho32_readfile): Renamed from ... (grub_macho_readfile32): ... to this. (grub_macho_filesize64): New prototype. (grub_macho_readfile64): Likewise. (grub_macho_parse32): Likewise. (grub_macho_parse64): Likewise. * loader/macho.c: Split into ... * loader/machoXX.c: ... and this. Replace 32 with XX. * loader/macho32.c: New file. * loader/macho64.c: Likewise. * loader/xnu.c (grub_xnu_is_64bit): New variable. (grub_cmd_xnu_kernel): Make 32-bit only. (grub_cmd_xnu_kernel64): New function. (grub_xnu_load_driver): Support Mach-O 64. (grub_cmd_xnu_mkext): Likewise. * util/grub.d/30_os-prober.in (osx_entry): New function. Generate entries for 64-bit boot too. Eliminate ad-hoc tree format in XNU and EfiEmu. * efiemu/main.c (grub_efiemu_prepare): Update comment. * efiemu/pnvram.c: Rewritten to use environment variables. All users updated. Inline utf16_to_utf8. * kern/misc.c (grub_utf16_to_utf8): Move from here ... * include/grub/charset.h (grub_utf16_to_utf8): ... to here. Inlined. All users updated. * include/grub/misc.h (grub_utf16_to_utf8): Removed. * bus/usb/usb.c (grub_usb_get_string): Move from here ... * commands/usbtest.c (grub_usb_get_string): ... move here. (usb_print_str): Fix error handling. * include/grub/usb.h (grub_usb_get_string): Remove. UTF-8 to UTF-16 transformation. * conf/common.rmk (pkglib_MODULES): Add charset.mod (charset_mod_SOURCES): New variable. (charset_mod_CFLAGS): Likewise. (charset_mod_LDFLAGS): Likewise. * include/grub/utf.h: New file. * lib/utf.c: New file. (Based on grub_utf8_to_ucs4 from kern/misc.c) Support for device properties. * include/grub/i386/xnu.h (grub_xnu_devprop_header): New structure. (grub_xnu_devprop_device_header): Likewise. (grub_xnu_devprop_device_descriptor): Likewise. (grub_xnu_devprop_add_device): New prototype. (grub_xnu_devprop_remove_device): Likewise. (grub_xnu_devprop_remove_property): Likewise. (grub_xnu_devprop_add_property_utf8): Likewise. (grub_xnu_devprop_add_property_utf16): Likewise. (grub_cpu_xnu_init): Likewise. (grub_cpu_xnu_fini): Likewise. (grub_cpu_xnu_unload): Likewise. * loader/i386/xnu.c (grub_xnu_devprop_device_descriptor): New structure. (property_descriptor): Likewise. (devices): New variable. (grub_xnu_devprop_remove_property): New function. (grub_xnu_devprop_add_device): Likewise. (grub_xnu_devprop_remove_device): Likewise. (grub_xnu_devprop_add_property): Likewise. (grub_xnu_devprop_add_property_utf8): Likewise. (grub_xnu_devprop_add_property_utf16): Likewise. (hextoval): Likewise. (grub_cpu_xnu_fill_devprop): Likewise. (grub_cmd_devprop_load): Likewise. (grub_xnu_boot): Call grub_cpu_xnu_fill_devprop, grub_xnu_fill_devicetree, grub_xnu_fill_devicetree (cmd_devprop_load): New variable. (grub_cpu_xnu_init): New function. (grub_cpu_xnu_fini): Likewise. * loader/i386/xnu.c (grub_xnu_unload): Call grub_cpu_xnu_unload. * loader/xnu.c (grub_xnu_parse_devtree): Remove. (grub_cmd_xnu_devtree): Likewise. (hextoval): New function. (unescape): Likewise. (grub_xnu_fill_devicetree): Likewise. * util/grub.d/30_os-prober.in: Load devprop.bin. Don't load devtree.txt. * util/i386/efi/grub-dumpdevtree: Generate devprop.bin.
This commit is contained in:
commit
b045f00a84
42 changed files with 2070 additions and 1004 deletions
147
ChangeLog
147
ChangeLog
|
@ -1,3 +1,150 @@
|
|||
2009-12-18 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
Fix potential EfiEmu double prepare.
|
||||
|
||||
* efiemu/main.c (prepared): New variable
|
||||
(grub_efiemu_unload): Set prepare to '0'.
|
||||
(grub_efiemu_prepare): Return if already prepared. Set prepared.
|
||||
|
||||
set_virtual_address_map support.
|
||||
|
||||
* include/grub/efi/efi.h (grub_efi_set_virtual_address_map): New
|
||||
prototype.
|
||||
* include/grub/efiemu/efiemu.h (grub_efiemu_write_sym_markers): New
|
||||
prototype.
|
||||
(grub_efiemu_crc32): Likewise.
|
||||
(grub_efiemu_crc64): Likewise.
|
||||
(grub_efiemu_set_virtual_address_map): Likewise.
|
||||
* include/grub/autoefi.h (grub_autoefi_exit_boot_services):
|
||||
New definition.
|
||||
(grub_autoefi_set_virtual_address_map): Likewise.
|
||||
* kern/efi/efi.c (grub_efi_set_virtual_address_map): New function.
|
||||
* loader/i386/xnu.c (grub_xnu_boot): Call set_virtual_address_map.
|
||||
Restructure flow to accomodate it.
|
||||
* efiemu/prepare.c (grub_efiemu_prepare): Support set_virtual_address_map.
|
||||
(grub_efiemu_crc): Recompute CRC32.
|
||||
* efiemu/runtime/efiemu.c (ptv_relocated): Renamed to ...
|
||||
(efiemu_ptv_relocated): ... this. Made global. All users updated.
|
||||
* efiemu/symbols.c (relocated_handle): New variable.
|
||||
(grub_efiemu_free_syms): Free relocated_handle.
|
||||
(grub_efiemu_alloc_syms): Allocate relocated_handle.
|
||||
(grub_efiemu_write_sym_markers): New function.
|
||||
(grub_efiemu_set_virtual_address_map): Likewise.
|
||||
|
||||
Newer XNU parameters.
|
||||
|
||||
* include/grub/i386/xnu.h (GRUB_XNU_BOOTARGS_VERMINOR): Change to 5.
|
||||
* include/grub/xnu.h (grub_xnu_extheader): Add nameaddr and namesize.
|
||||
(grub_xnu_fill_devicetree): New prototype.
|
||||
(grub_xnu_heap_real_start): New variable.
|
||||
* loader/xnu.c (get_name_ptr): New function.
|
||||
(grub_xnu_load_driver): Fill namelen and name.
|
||||
|
||||
64-bit xnu support.
|
||||
|
||||
* conf/i386-efi.rmk (xnu_mod_SOURCES): Add 'loader/macho32.c'
|
||||
and 'loader/macho64.c'.
|
||||
* conf/i386-pc.rmk: Likewise.
|
||||
* conf/x86_64-efi.rmk: Likewise.
|
||||
* include/grub/i386/macho.h (grub_macho_thread64): New structure.
|
||||
* include/grub/xnu.h (grub_xnu_is_64bit): New variable.
|
||||
* include/grub/macho.h (grub_macho_segment64): New structure.
|
||||
* include/grub/machoload.h (grub_macho32_size): Renamed from ...
|
||||
(grub_macho_size32): ... to this.
|
||||
(grub_macho32_get_entry_point): Renamed from ...
|
||||
(grub_macho_get_entry_point32): ... to this.
|
||||
(grub_macho_contains_macho64): New prototype.
|
||||
(grub_macho_size64): Likewise.
|
||||
(grub_macho_get_entry_point64): Likewise.
|
||||
(grub_macho32_load): Renamed from ...
|
||||
(grub_macho_load32): ... to this.
|
||||
(grub_macho32_filesize): Renamed from ...
|
||||
(grub_macho_filesize32): ... to this.
|
||||
(grub_macho32_readfile): Renamed from ...
|
||||
(grub_macho_readfile32): ... to this.
|
||||
(grub_macho_filesize64): New prototype.
|
||||
(grub_macho_readfile64): Likewise.
|
||||
(grub_macho_parse32): Likewise.
|
||||
(grub_macho_parse64): Likewise.
|
||||
* loader/macho.c: Split into ...
|
||||
* loader/machoXX.c: ... and this. Replace 32 with XX.
|
||||
* loader/macho32.c: New file.
|
||||
* loader/macho64.c: Likewise.
|
||||
* loader/xnu.c (grub_xnu_is_64bit): New variable.
|
||||
(grub_cmd_xnu_kernel): Make 32-bit only.
|
||||
(grub_cmd_xnu_kernel64): New function.
|
||||
(grub_xnu_load_driver): Support Mach-O 64.
|
||||
(grub_cmd_xnu_mkext): Likewise.
|
||||
* util/grub.d/30_os-prober.in (osx_entry): New function.
|
||||
Generate entries for 64-bit boot too.
|
||||
|
||||
Eliminate ad-hoc tree format in XNU and EfiEmu.
|
||||
|
||||
* efiemu/main.c (grub_efiemu_prepare): Update comment.
|
||||
* efiemu/pnvram.c: Rewritten to use environment variables.
|
||||
All users updated.
|
||||
|
||||
Inline utf16_to_utf8.
|
||||
|
||||
* kern/misc.c (grub_utf16_to_utf8): Move from here ...
|
||||
* include/grub/charset.h (grub_utf16_to_utf8): ... to here. Inlined.
|
||||
All users updated.
|
||||
* include/grub/misc.h (grub_utf16_to_utf8): Removed.
|
||||
|
||||
* bus/usb/usb.c (grub_usb_get_string): Move from here ...
|
||||
* commands/usbtest.c (grub_usb_get_string): ... move here.
|
||||
(usb_print_str): Fix error handling.
|
||||
* include/grub/usb.h (grub_usb_get_string): Remove.
|
||||
|
||||
UTF-8 to UTF-16 transformation.
|
||||
|
||||
* conf/common.rmk (pkglib_MODULES): Add charset.mod
|
||||
(charset_mod_SOURCES): New variable.
|
||||
(charset_mod_CFLAGS): Likewise.
|
||||
(charset_mod_LDFLAGS): Likewise.
|
||||
* include/grub/utf.h: New file.
|
||||
* lib/utf.c: New file. (Based on grub_utf8_to_ucs4 from kern/misc.c)
|
||||
|
||||
Support for device properties.
|
||||
|
||||
* include/grub/i386/xnu.h (grub_xnu_devprop_header): New structure.
|
||||
(grub_xnu_devprop_device_header): Likewise.
|
||||
(grub_xnu_devprop_device_descriptor): Likewise.
|
||||
(grub_xnu_devprop_add_device): New prototype.
|
||||
(grub_xnu_devprop_remove_device): Likewise.
|
||||
(grub_xnu_devprop_remove_property): Likewise.
|
||||
(grub_xnu_devprop_add_property_utf8): Likewise.
|
||||
(grub_xnu_devprop_add_property_utf16): Likewise.
|
||||
(grub_cpu_xnu_init): Likewise.
|
||||
(grub_cpu_xnu_fini): Likewise.
|
||||
(grub_cpu_xnu_unload): Likewise.
|
||||
* loader/i386/xnu.c (grub_xnu_devprop_device_descriptor): New structure.
|
||||
(property_descriptor): Likewise.
|
||||
(devices): New variable.
|
||||
(grub_xnu_devprop_remove_property): New function.
|
||||
(grub_xnu_devprop_add_device): Likewise.
|
||||
(grub_xnu_devprop_remove_device): Likewise.
|
||||
(grub_xnu_devprop_add_property): Likewise.
|
||||
(grub_xnu_devprop_add_property_utf8): Likewise.
|
||||
(grub_xnu_devprop_add_property_utf16): Likewise.
|
||||
(hextoval): Likewise.
|
||||
(grub_cpu_xnu_fill_devprop): Likewise.
|
||||
(grub_cmd_devprop_load): Likewise.
|
||||
(grub_xnu_boot): Call grub_cpu_xnu_fill_devprop,
|
||||
grub_xnu_fill_devicetree, grub_xnu_fill_devicetree
|
||||
(cmd_devprop_load): New variable.
|
||||
(grub_cpu_xnu_init): New function.
|
||||
(grub_cpu_xnu_fini): Likewise.
|
||||
* loader/i386/xnu.c (grub_xnu_unload): Call grub_cpu_xnu_unload.
|
||||
* loader/xnu.c (grub_xnu_parse_devtree): Remove.
|
||||
(grub_cmd_xnu_devtree): Likewise.
|
||||
(hextoval): New function.
|
||||
(unescape): Likewise.
|
||||
(grub_xnu_fill_devicetree): Likewise.
|
||||
|
||||
* util/grub.d/30_os-prober.in: Load devprop.bin. Don't load devtree.txt.
|
||||
* util/i386/efi/grub-dumpdevtree: Generate devprop.bin.
|
||||
|
||||
2009-12-18 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
Workaround for broken ATI VBE.
|
||||
|
|
|
@ -155,42 +155,6 @@ grub_usb_get_endpdescriptor (grub_usb_device_t usbdev, int addr)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
grub_usb_err_t
|
||||
grub_usb_get_string (grub_usb_device_t dev, grub_uint8_t index, int langid,
|
||||
char **string)
|
||||
{
|
||||
struct grub_usb_desc_str descstr;
|
||||
struct grub_usb_desc_str *descstrp;
|
||||
grub_usb_err_t err;
|
||||
|
||||
/* Only get the length. */
|
||||
err = grub_usb_control_msg (dev, 1 << 7,
|
||||
0x06, (3 << 8) | index,
|
||||
langid, 1, (char *) &descstr);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
descstrp = grub_malloc (descstr.length);
|
||||
if (! descstrp)
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
err = grub_usb_control_msg (dev, 1 << 7,
|
||||
0x06, (3 << 8) | index,
|
||||
langid, descstr.length, (char *) descstrp);
|
||||
|
||||
*string = grub_malloc (descstr.length / 2);
|
||||
if (! *string)
|
||||
{
|
||||
grub_free (descstrp);
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
}
|
||||
|
||||
grub_utf16_to_utf8 ((grub_uint8_t *) *string, descstrp->str, descstrp->length / 2 - 1);
|
||||
(*string)[descstr.length / 2 - 1] = '\0';
|
||||
grub_free (descstrp);
|
||||
|
||||
return GRUB_USB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_usb_err_t
|
||||
grub_usb_device_initialize (grub_usb_device_t dev)
|
||||
{
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <grub/types.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/charset.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/dl.h>
|
||||
|
@ -59,19 +60,61 @@ static const char *usb_devspeed[] =
|
|||
"High"
|
||||
};
|
||||
|
||||
static grub_usb_err_t
|
||||
grub_usb_get_string (grub_usb_device_t dev, grub_uint8_t index, int langid,
|
||||
char **string)
|
||||
{
|
||||
struct grub_usb_desc_str descstr;
|
||||
struct grub_usb_desc_str *descstrp;
|
||||
grub_usb_err_t err;
|
||||
|
||||
/* Only get the length. */
|
||||
err = grub_usb_control_msg (dev, 1 << 7,
|
||||
0x06, (3 << 8) | index,
|
||||
langid, 1, (char *) &descstr);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
descstrp = grub_malloc (descstr.length);
|
||||
if (! descstrp)
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
err = grub_usb_control_msg (dev, 1 << 7,
|
||||
0x06, (3 << 8) | index,
|
||||
langid, descstr.length, (char *) descstrp);
|
||||
|
||||
*string = grub_malloc (descstr.length / 2);
|
||||
if (! *string)
|
||||
{
|
||||
grub_free (descstrp);
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
}
|
||||
|
||||
grub_utf16_to_utf8 ((grub_uint8_t *) *string, descstrp->str, descstrp->length / 2 - 1);
|
||||
(*string)[descstr.length / 2 - 1] = '\0';
|
||||
grub_free (descstrp);
|
||||
|
||||
return GRUB_USB_ERR_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
usb_print_str (const char *description, grub_usb_device_t dev, int idx)
|
||||
{
|
||||
char *name;
|
||||
grub_usb_err_t err;
|
||||
/* XXX: LANGID */
|
||||
|
||||
if (! idx)
|
||||
return;
|
||||
|
||||
grub_usb_get_string (dev, idx, 0x0409, &name);
|
||||
err = grub_usb_get_string (dev, idx, 0x0409, &name);
|
||||
if (err)
|
||||
grub_printf ("Error %d retrieving %s\n", err, description);
|
||||
else
|
||||
{
|
||||
grub_printf ("%s: `%s'\n", description, name);
|
||||
grub_free (name);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
usb_iterate (grub_usb_device_t dev)
|
||||
|
|
|
@ -638,3 +638,8 @@ pkglib_MODULES += setjmp.mod
|
|||
setjmp_mod_SOURCES = lib/$(target_cpu)/setjmp.S
|
||||
setjmp_mod_ASFLAGS = $(COMMON_ASFLAGS)
|
||||
setjmp_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
||||
|
||||
pkglib_MODULES += charset.mod
|
||||
charset_mod_SOURCES = lib/charset.c
|
||||
charset_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||
charset_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
||||
|
|
|
@ -155,7 +155,7 @@ efi_gop_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
|||
|
||||
pkglib_MODULES += xnu.mod
|
||||
xnu_mod_SOURCES = loader/xnu_resume.c loader/i386/xnu.c loader/i386/efi/xnu.c \
|
||||
loader/macho.c loader/xnu.c
|
||||
loader/macho32.c loader/macho64.c loader/macho.c loader/xnu.c
|
||||
xnu_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||
xnu_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
||||
xnu_mod_ASFLAGS = $(COMMON_ASFLAGS)
|
||||
|
|
|
@ -184,7 +184,7 @@ linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
|||
|
||||
pkglib_MODULES += xnu.mod
|
||||
xnu_mod_SOURCES = loader/xnu_resume.c loader/i386/xnu.c loader/i386/pc/xnu.c \
|
||||
loader/macho.c loader/xnu.c
|
||||
loader/macho32.c loader/macho64.c loader/macho.c loader/xnu.c
|
||||
xnu_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||
xnu_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
||||
xnu_mod_ASFLAGS = $(COMMON_ASFLAGS)
|
||||
|
|
|
@ -161,7 +161,7 @@ efi_gop_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
|||
|
||||
pkglib_MODULES += xnu.mod
|
||||
xnu_mod_SOURCES = loader/xnu_resume.c loader/i386/xnu.c loader/i386/efi/xnu.c \
|
||||
loader/macho.c loader/xnu.c
|
||||
loader/macho32.c loader/macho64.c loader/macho.c loader/xnu.c
|
||||
xnu_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||
xnu_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
||||
xnu_mod_ASFLAGS = $(COMMON_ASFLAGS)
|
||||
|
|
|
@ -39,6 +39,7 @@ grub_efi_system_table64_t *grub_efiemu_system_table64 = 0;
|
|||
static struct grub_efiemu_prepare_hook *efiemu_prepare_hooks = 0;
|
||||
/* Linked list of configuration tables */
|
||||
static struct grub_efiemu_configuration_table *efiemu_config_tables = 0;
|
||||
static int prepared = 0;
|
||||
|
||||
/* Free all allocated space */
|
||||
grub_err_t
|
||||
|
@ -70,6 +71,8 @@ grub_efiemu_unload (void)
|
|||
}
|
||||
efiemu_prepare_hooks = 0;
|
||||
|
||||
prepared = 0;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
|
@ -277,14 +280,19 @@ grub_efiemu_prepare (void)
|
|||
{
|
||||
grub_err_t err;
|
||||
|
||||
if (prepared)
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
grub_dprintf ("efiemu", "Preparing %d-bit efiemu\n",
|
||||
8 * grub_efiemu_sizeof_uintn_t ());
|
||||
|
||||
err = grub_efiemu_autocore ();
|
||||
|
||||
/* Create NVRAM if not yet done. */
|
||||
/* Create NVRAM. */
|
||||
grub_efiemu_pnvram ();
|
||||
|
||||
prepared = 1;
|
||||
|
||||
if (grub_efiemu_sizeof_uintn_t () == 4)
|
||||
return grub_efiemu_prepare32 (efiemu_prepare_hooks, efiemu_config_tables);
|
||||
else
|
||||
|
@ -316,9 +324,6 @@ grub_cmd_efiemu_load (grub_command_t cmd __attribute__ ((unused)),
|
|||
|
||||
static grub_command_t cmd_loadcore, cmd_prepare, cmd_unload;
|
||||
|
||||
void
|
||||
grub_efiemu_pnvram_cmd_register (void);
|
||||
|
||||
GRUB_MOD_INIT(efiemu)
|
||||
{
|
||||
cmd_loadcore = grub_register_command ("efiemu_loadcore",
|
||||
|
@ -332,7 +337,6 @@ GRUB_MOD_INIT(efiemu)
|
|||
cmd_unload = grub_register_command ("efiemu_unload", grub_cmd_efiemu_unload,
|
||||
"efiemu_unload",
|
||||
"Unload EFI emulator");
|
||||
grub_efiemu_pnvram_cmd_register ();
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(efiemu)
|
||||
|
@ -340,5 +344,4 @@ GRUB_MOD_FINI(efiemu)
|
|||
grub_unregister_command (cmd_loadcore);
|
||||
grub_unregister_command (cmd_prepare);
|
||||
grub_unregister_command (cmd_unload);
|
||||
grub_efiemu_pnvram_cmd_unregister ();
|
||||
}
|
||||
|
|
452
efiemu/pnvram.c
452
efiemu/pnvram.c
|
@ -22,6 +22,7 @@
|
|||
#include <grub/normal.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/charset.h>
|
||||
#include <grub/efiemu/efiemu.h>
|
||||
#include <grub/efiemu/runtime.h>
|
||||
#include <grub/extcmd.h>
|
||||
|
@ -34,62 +35,184 @@ static int timezone_handle = 0;
|
|||
static int accuracy_handle = 0;
|
||||
static int daylight_handle = 0;
|
||||
|
||||
/* Temporary place */
|
||||
static grub_uint8_t *nvram;
|
||||
static grub_size_t nvramsize;
|
||||
static grub_uint32_t high_monotonic_count;
|
||||
static grub_int16_t timezone;
|
||||
static grub_uint8_t daylight;
|
||||
static grub_uint32_t accuracy;
|
||||
|
||||
static const struct grub_arg_option options[] = {
|
||||
{"size", 's', 0, "number of bytes to reserve for pseudo NVRAM", 0,
|
||||
ARG_TYPE_INT},
|
||||
{"high-monotonic-count", 'm', 0,
|
||||
"Initial value of high monotonic count", 0, ARG_TYPE_INT},
|
||||
{"timezone", 't', 0,
|
||||
"Timezone, offset in minutes from GMT", 0, ARG_TYPE_INT},
|
||||
{"accuracy", 'a', 0,
|
||||
"Accuracy of clock, in 1e-12 units", 0, ARG_TYPE_INT},
|
||||
{"daylight", 'd', 0,
|
||||
"Daylight value, as per EFI specifications", 0, ARG_TYPE_INT},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
/* Parse signed value */
|
||||
static int
|
||||
grub_strtosl (char *arg, char **end, int base)
|
||||
grub_strtosl (const char *arg, char **end, int base)
|
||||
{
|
||||
if (arg[0] == '-')
|
||||
return -grub_strtoul (arg + 1, end, base);
|
||||
return grub_strtoul (arg, end, base);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static inline grub_err_t
|
||||
unescape (char *in, char *out, char *outmax, int *len)
|
||||
{
|
||||
char *ptr, *dptr;
|
||||
dptr = out;
|
||||
for (ptr = in; *ptr && dptr < outmax; )
|
||||
if (*ptr == '%' && ptr[1] && ptr[2])
|
||||
{
|
||||
*dptr = (hextoval (ptr[1]) << 4) | (hextoval (ptr[2]));
|
||||
ptr += 3;
|
||||
dptr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*dptr = *ptr;
|
||||
ptr++;
|
||||
dptr++;
|
||||
}
|
||||
if (dptr == outmax)
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
|
||||
"Too many NVRAM variables for reserved variable space."
|
||||
" Try increasing EfiEmu.pnvram.size.");
|
||||
*len = dptr - out;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Export stuff for efiemu */
|
||||
static grub_err_t
|
||||
nvram_set (void * data __attribute__ ((unused)))
|
||||
{
|
||||
const char *env;
|
||||
/* Take definitive pointers */
|
||||
grub_uint8_t *nvram_def = grub_efiemu_mm_obtain_request (nvram_handle);
|
||||
char *nvram = grub_efiemu_mm_obtain_request (nvram_handle);
|
||||
grub_uint32_t *nvramsize_def
|
||||
= grub_efiemu_mm_obtain_request (nvramsize_handle);
|
||||
grub_uint32_t *high_monotonic_count_def
|
||||
grub_uint32_t *high_monotonic_count
|
||||
= grub_efiemu_mm_obtain_request (high_monotonic_count_handle);
|
||||
grub_int16_t *timezone_def
|
||||
grub_int16_t *timezone
|
||||
= grub_efiemu_mm_obtain_request (timezone_handle);
|
||||
grub_uint8_t *daylight_def
|
||||
grub_uint8_t *daylight
|
||||
= grub_efiemu_mm_obtain_request (daylight_handle);
|
||||
grub_uint32_t *accuracy_def
|
||||
grub_uint32_t *accuracy
|
||||
= grub_efiemu_mm_obtain_request (accuracy_handle);
|
||||
char *nvramptr;
|
||||
|
||||
auto int iterate_env (struct grub_env_var *var);
|
||||
int iterate_env (struct grub_env_var *var)
|
||||
{
|
||||
char *guid, *attr, *name, *varname;
|
||||
struct efi_variable *efivar;
|
||||
int len = 0;
|
||||
int i;
|
||||
grub_uint64_t guidcomp;
|
||||
|
||||
if (grub_memcmp (var->name, "EfiEmu.pnvram.",
|
||||
sizeof ("EfiEmu.pnvram.") - 1) != 0)
|
||||
return 0;
|
||||
|
||||
guid = var->name + sizeof ("EfiEmu.pnvram.") - 1;
|
||||
|
||||
attr = grub_strchr (guid, '.');
|
||||
if (!attr)
|
||||
return 0;
|
||||
attr++;
|
||||
|
||||
name = grub_strchr (attr, '.');
|
||||
if (!name)
|
||||
return 0;
|
||||
name++;
|
||||
|
||||
efivar = (struct efi_variable *) nvramptr;
|
||||
if (nvramptr - nvram + sizeof (struct efi_variable) > nvramsize)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY,
|
||||
"Too many NVRAM variables for reserved variable space."
|
||||
" Try increasing EfiEmu.pnvram.size.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
nvramptr += sizeof (struct efi_variable);
|
||||
|
||||
efivar->guid.data1 = grub_cpu_to_le32 (grub_strtoul (guid, &guid, 16));
|
||||
if (*guid != '-')
|
||||
return 0;
|
||||
guid++;
|
||||
|
||||
efivar->guid.data2 = grub_cpu_to_le16 (grub_strtoul (guid, &guid, 16));
|
||||
if (*guid != '-')
|
||||
return 0;
|
||||
guid++;
|
||||
|
||||
efivar->guid.data3 = grub_cpu_to_le16 (grub_strtoul (guid, &guid, 16));
|
||||
if (*guid != '-')
|
||||
return 0;
|
||||
guid++;
|
||||
|
||||
guidcomp = grub_strtoull (guid, 0, 16);
|
||||
for (i = 0; i < 8; i++)
|
||||
efivar->guid.data4[i] = (guidcomp >> (56 - 8 * i)) & 0xff;
|
||||
|
||||
efivar->attributes = grub_strtoull (attr, 0, 16);
|
||||
|
||||
varname = grub_malloc (grub_strlen (name) + 1);
|
||||
if (! varname)
|
||||
return 1;
|
||||
|
||||
if (unescape (name, varname, varname + grub_strlen (name) + 1, &len))
|
||||
return 1;
|
||||
|
||||
len = grub_utf8_to_utf16 ((grub_uint16_t *) nvramptr,
|
||||
(nvramsize - (nvramptr - nvram)) / 2,
|
||||
(grub_uint8_t *) varname, len, NULL);
|
||||
|
||||
if (len < 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "Broken UTF-8 in variable name\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
nvramptr += 2 * len;
|
||||
*((grub_uint16_t *) nvramptr) = 0;
|
||||
nvramptr += 2;
|
||||
efivar->namelen = 2 * len + 2;
|
||||
|
||||
if (unescape (var->value, nvramptr, nvram + nvramsize, &len))
|
||||
{
|
||||
efivar->namelen = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
nvramptr += len;
|
||||
|
||||
efivar->size = len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Copy to definitive loaction */
|
||||
grub_dprintf ("efiemu", "preparing pnvram\n");
|
||||
grub_memcpy (nvram_def, nvram, nvramsize);
|
||||
|
||||
env = grub_env_get ("EfiEmu.pnvram.high_monotonic_count");
|
||||
*high_monotonic_count = env ? grub_strtoul (env, 0, 0) : 1;
|
||||
env = grub_env_get ("EfiEmu.pnvram.timezone");
|
||||
*timezone = env ? grub_strtosl (env, 0, 0) : GRUB_EFI_UNSPECIFIED_TIMEZONE;
|
||||
env = grub_env_get ("EfiEmu.pnvram.accuracy");
|
||||
*accuracy = env ? grub_strtoul (env, 0, 0) : 50000000;
|
||||
env = grub_env_get ("EfiEmu.pnvram.daylight");
|
||||
*daylight = env ? grub_strtoul (env, 0, 0) : 0;
|
||||
|
||||
nvramptr = nvram;
|
||||
grub_memset (nvram, 0, nvramsize);
|
||||
grub_env_iterate (iterate_env);
|
||||
if (grub_errno)
|
||||
return grub_errno;
|
||||
*nvramsize_def = nvramsize;
|
||||
*high_monotonic_count_def = high_monotonic_count;
|
||||
*timezone_def = timezone;
|
||||
*daylight_def = daylight;
|
||||
*accuracy_def = accuracy;
|
||||
|
||||
/* Register symbols */
|
||||
grub_efiemu_register_symbol ("efiemu_variables", nvram_handle, 0);
|
||||
|
@ -113,197 +236,27 @@ nvram_unload (void * data __attribute__ ((unused)))
|
|||
grub_efiemu_mm_return_request (timezone_handle);
|
||||
grub_efiemu_mm_return_request (accuracy_handle);
|
||||
grub_efiemu_mm_return_request (daylight_handle);
|
||||
|
||||
grub_free (nvram);
|
||||
nvram = 0;
|
||||
}
|
||||
|
||||
/* Load the variables file It's in format
|
||||
guid1:attr1:name1:data1;
|
||||
guid2:attr2:name2:data2;
|
||||
...
|
||||
Where all fields are in hex
|
||||
*/
|
||||
static grub_err_t
|
||||
read_pnvram (char *filename)
|
||||
{
|
||||
char *buf, *ptr, *ptr2;
|
||||
grub_file_t file;
|
||||
grub_size_t size;
|
||||
grub_uint8_t *nvramptr = nvram;
|
||||
struct efi_variable *efivar;
|
||||
grub_size_t guidlen, datalen;
|
||||
unsigned i, j;
|
||||
|
||||
file = grub_file_open (filename);
|
||||
if (!file)
|
||||
return grub_error (GRUB_ERR_BAD_OS, "couldn't read pnvram");
|
||||
size = grub_file_size (file);
|
||||
buf = grub_malloc (size + 1);
|
||||
if (!buf)
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't read pnvram");
|
||||
if (grub_file_read (file, buf, size) != (grub_ssize_t) size)
|
||||
return grub_error (GRUB_ERR_BAD_OS, "couldn't read pnvram");
|
||||
buf[size] = 0;
|
||||
grub_file_close (file);
|
||||
|
||||
for (ptr = buf; *ptr; )
|
||||
{
|
||||
if (grub_isspace (*ptr))
|
||||
{
|
||||
ptr++;
|
||||
continue;
|
||||
}
|
||||
|
||||
efivar = (struct efi_variable *) nvramptr;
|
||||
if (nvramptr - nvram + sizeof (struct efi_variable) > nvramsize)
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
|
||||
"file is too large for reserved variable space");
|
||||
|
||||
nvramptr += sizeof (struct efi_variable);
|
||||
|
||||
/* look ahow long guid field is*/
|
||||
guidlen = 0;
|
||||
for (ptr2 = ptr; (grub_isspace (*ptr2)
|
||||
|| (*ptr2 >= '0' && *ptr2 <= '9')
|
||||
|| (*ptr2 >= 'a' && *ptr2 <= 'f')
|
||||
|| (*ptr2 >= 'A' && *ptr2 <= 'F'));
|
||||
ptr2++)
|
||||
if (!grub_isspace (*ptr2))
|
||||
guidlen++;
|
||||
guidlen /= 2;
|
||||
|
||||
/* Read guid */
|
||||
if (guidlen != sizeof (efivar->guid))
|
||||
{
|
||||
grub_free (buf);
|
||||
return grub_error (GRUB_ERR_BAD_OS, "can't parse %s", filename);
|
||||
}
|
||||
for (i = 0; i < 2 * sizeof (efivar->guid); i++)
|
||||
{
|
||||
int hex = 0;
|
||||
while (grub_isspace (*ptr))
|
||||
ptr++;
|
||||
if (*ptr >= '0' && *ptr <= '9')
|
||||
hex = *ptr - '0';
|
||||
if (*ptr >= 'a' && *ptr <= 'f')
|
||||
hex = *ptr - 'a' + 10;
|
||||
if (*ptr >= 'A' && *ptr <= 'F')
|
||||
hex = *ptr - 'A' + 10;
|
||||
|
||||
if (i%2 == 0)
|
||||
((grub_uint8_t *)&(efivar->guid))[i/2] = hex << 4;
|
||||
else
|
||||
((grub_uint8_t *)&(efivar->guid))[i/2] |= hex;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
while (grub_isspace (*ptr))
|
||||
ptr++;
|
||||
if (*ptr != ':')
|
||||
{
|
||||
grub_dprintf ("efiemu", "Not colon\n");
|
||||
grub_free (buf);
|
||||
return grub_error (GRUB_ERR_BAD_OS, "can't parse %s", filename);
|
||||
}
|
||||
ptr++;
|
||||
while (grub_isspace (*ptr))
|
||||
ptr++;
|
||||
|
||||
/* Attributes can be just parsed by existing functions */
|
||||
efivar->attributes = grub_strtoul (ptr, &ptr, 16);
|
||||
|
||||
while (grub_isspace (*ptr))
|
||||
ptr++;
|
||||
if (*ptr != ':')
|
||||
{
|
||||
grub_dprintf ("efiemu", "Not colon\n");
|
||||
grub_free (buf);
|
||||
return grub_error (GRUB_ERR_BAD_OS, "can't parse %s", filename);
|
||||
}
|
||||
ptr++;
|
||||
while (grub_isspace (*ptr))
|
||||
ptr++;
|
||||
|
||||
/* Read name and value */
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
/* Look the length */
|
||||
datalen = 0;
|
||||
for (ptr2 = ptr; *ptr2 && (grub_isspace (*ptr2)
|
||||
|| (*ptr2 >= '0' && *ptr2 <= '9')
|
||||
|| (*ptr2 >= 'a' && *ptr2 <= 'f')
|
||||
|| (*ptr2 >= 'A' && *ptr2 <= 'F'));
|
||||
ptr2++)
|
||||
if (!grub_isspace (*ptr2))
|
||||
datalen++;
|
||||
datalen /= 2;
|
||||
|
||||
if (nvramptr - nvram + datalen > nvramsize)
|
||||
{
|
||||
grub_free (buf);
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
|
||||
"file is too large for reserved "
|
||||
" variable space");
|
||||
}
|
||||
|
||||
for (i = 0; i < 2 * datalen; i++)
|
||||
{
|
||||
int hex = 0;
|
||||
while (grub_isspace (*ptr))
|
||||
ptr++;
|
||||
if (*ptr >= '0' && *ptr <= '9')
|
||||
hex = *ptr - '0';
|
||||
if (*ptr >= 'a' && *ptr <= 'f')
|
||||
hex = *ptr - 'a' + 10;
|
||||
if (*ptr >= 'A' && *ptr <= 'F')
|
||||
hex = *ptr - 'A' + 10;
|
||||
|
||||
if (i%2 == 0)
|
||||
nvramptr[i/2] = hex << 4;
|
||||
else
|
||||
nvramptr[i/2] |= hex;
|
||||
ptr++;
|
||||
}
|
||||
nvramptr += datalen;
|
||||
while (grub_isspace (*ptr))
|
||||
ptr++;
|
||||
if (*ptr != (j ? ';' : ':'))
|
||||
{
|
||||
grub_free (buf);
|
||||
grub_dprintf ("efiemu", j?"Not semicolon\n":"Not colon\n");
|
||||
return grub_error (GRUB_ERR_BAD_OS, "can't parse %s", filename);
|
||||
}
|
||||
if (j)
|
||||
efivar->size = datalen;
|
||||
else
|
||||
efivar->namelen = datalen;
|
||||
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
grub_free (buf);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_efiemu_make_nvram (void)
|
||||
grub_err_t
|
||||
grub_efiemu_pnvram (void)
|
||||
{
|
||||
const char *size;
|
||||
grub_err_t err;
|
||||
|
||||
err = grub_efiemu_autocore ();
|
||||
if (err)
|
||||
{
|
||||
grub_free (nvram);
|
||||
return err;
|
||||
}
|
||||
nvramsize = 0;
|
||||
|
||||
size = grub_env_get ("EfiEmu.pnvram.size");
|
||||
if (size)
|
||||
nvramsize = grub_strtoul (size, 0, 0);
|
||||
|
||||
if (!nvramsize)
|
||||
nvramsize = 2048;
|
||||
|
||||
err = grub_efiemu_register_prepare_hook (nvram_set, nvram_unload, 0);
|
||||
if (err)
|
||||
{
|
||||
grub_free (nvram);
|
||||
return err;
|
||||
}
|
||||
|
||||
nvram_handle
|
||||
= grub_efiemu_request_memalign (1, nvramsize,
|
||||
GRUB_EFI_RUNTIME_SERVICES_DATA);
|
||||
|
@ -323,78 +276,5 @@ grub_efiemu_make_nvram (void)
|
|||
= grub_efiemu_request_memalign (1, sizeof (grub_uint32_t),
|
||||
GRUB_EFI_RUNTIME_SERVICES_DATA);
|
||||
|
||||
grub_efiemu_request_symbols (6);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_efiemu_pnvram (void)
|
||||
{
|
||||
if (nvram)
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
nvramsize = 2048;
|
||||
high_monotonic_count = 1;
|
||||
timezone = GRUB_EFI_UNSPECIFIED_TIMEZONE;
|
||||
accuracy = 50000000;
|
||||
daylight = 0;
|
||||
|
||||
nvram = grub_zalloc (nvramsize);
|
||||
if (!nvram)
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
|
||||
"Couldn't allocate space for temporary pnvram storage");
|
||||
|
||||
return grub_efiemu_make_nvram ();
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_efiemu_pnvram (struct grub_extcmd *cmd,
|
||||
int argc, char **args)
|
||||
{
|
||||
struct grub_arg_list *state = cmd->state;
|
||||
grub_err_t err;
|
||||
|
||||
if (argc > 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "only one argument expected");
|
||||
|
||||
nvramsize = state[0].set ? grub_strtoul (state[0].arg, 0, 0) : 2048;
|
||||
high_monotonic_count = state[1].set ? grub_strtoul (state[1].arg, 0, 0) : 1;
|
||||
timezone = state[2].set ? grub_strtosl (state[2].arg, 0, 0)
|
||||
: GRUB_EFI_UNSPECIFIED_TIMEZONE;
|
||||
accuracy = state[3].set ? grub_strtoul (state[3].arg, 0, 0) : 50000000;
|
||||
daylight = state[4].set ? grub_strtoul (state[4].arg, 0, 0) : 0;
|
||||
|
||||
nvram = grub_zalloc (nvramsize);
|
||||
if (!nvram)
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
|
||||
"Couldn't allocate space for temporary pnvram storage");
|
||||
|
||||
if (argc == 1 && (err = read_pnvram (args[0])))
|
||||
{
|
||||
grub_free (nvram);
|
||||
return err;
|
||||
}
|
||||
return grub_efiemu_make_nvram ();
|
||||
}
|
||||
|
||||
static grub_extcmd_t cmd;
|
||||
|
||||
void grub_efiemu_pnvram_cmd_register (void);
|
||||
void grub_efiemu_pnvram_cmd_unregister (void);
|
||||
|
||||
void
|
||||
grub_efiemu_pnvram_cmd_register (void)
|
||||
{
|
||||
cmd = grub_register_extcmd ("efiemu_pnvram", grub_cmd_efiemu_pnvram,
|
||||
GRUB_COMMAND_FLAG_BOTH,
|
||||
"efiemu_pnvram [FILENAME]",
|
||||
"Initialise pseudo-NVRAM and load variables "
|
||||
"from FILE",
|
||||
options);
|
||||
}
|
||||
|
||||
void
|
||||
grub_efiemu_pnvram_cmd_unregister (void)
|
||||
{
|
||||
grub_unregister_extcmd (cmd);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks,
|
|||
|
||||
int cntconftables = 0;
|
||||
struct SUFFIX (grub_efiemu_configuration_table) *conftables = 0;
|
||||
struct SUFFIX (grub_efiemu_runtime_services) *runtime_services;
|
||||
int i;
|
||||
int handle;
|
||||
grub_off_t off;
|
||||
|
@ -54,6 +53,7 @@ SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks,
|
|||
/* Switch from phase 1 (counting) to phase 2 (real job) */
|
||||
grub_efiemu_alloc_syms ();
|
||||
grub_efiemu_mm_do_alloc ();
|
||||
grub_efiemu_write_sym_markers ();
|
||||
|
||||
grub_efiemu_system_table32 = 0;
|
||||
grub_efiemu_system_table64 = 0;
|
||||
|
@ -81,16 +81,6 @@ SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks,
|
|||
= (struct SUFFIX (grub_efi_system_table) *)
|
||||
((grub_uint8_t *) grub_efiemu_mm_obtain_request (handle) + off);
|
||||
|
||||
/* compute CRC32 of runtime_services */
|
||||
if ((err = grub_efiemu_resolve_symbol ("efiemu_runtime_services",
|
||||
&handle, &off)))
|
||||
return err;
|
||||
runtime_services = (struct SUFFIX (grub_efiemu_runtime_services) *)
|
||||
((grub_uint8_t *) grub_efiemu_mm_obtain_request (handle) + off);
|
||||
runtime_services->hdr.crc32 = 0;
|
||||
runtime_services->hdr.crc32 = grub_getcrc32
|
||||
(0, runtime_services, runtime_services->hdr.header_size);
|
||||
|
||||
/* Put pointer to the list of configuration tables in system table */
|
||||
grub_efiemu_write_value
|
||||
(&(SUFFIX (grub_efiemu_system_table)->configuration_table), 0,
|
||||
|
@ -113,16 +103,51 @@ SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks,
|
|||
conftables[i].vendor_table = PTR_TO_UINT64 (cur->data);
|
||||
}
|
||||
|
||||
err = SUFFIX (grub_efiemu_crc) ();
|
||||
if (err)
|
||||
{
|
||||
grub_efiemu_unload ();
|
||||
return err;
|
||||
}
|
||||
|
||||
grub_dprintf ("efiemu","system_table = %p, conftables = %p (%d entries)\n",
|
||||
SUFFIX (grub_efiemu_system_table), conftables, cntconftables);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
SUFFIX (grub_efiemu_crc) (void)
|
||||
{
|
||||
grub_err_t err;
|
||||
int handle;
|
||||
grub_off_t off;
|
||||
struct SUFFIX (grub_efiemu_runtime_services) *runtime_services;
|
||||
|
||||
/* compute CRC32 of runtime_services */
|
||||
err = grub_efiemu_resolve_symbol ("efiemu_runtime_services",
|
||||
&handle, &off);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
runtime_services = (struct SUFFIX (grub_efiemu_runtime_services) *)
|
||||
((grub_uint8_t *) grub_efiemu_mm_obtain_request (handle) + off);
|
||||
runtime_services->hdr.crc32 = 0;
|
||||
runtime_services->hdr.crc32 = grub_getcrc32
|
||||
(0, runtime_services, runtime_services->hdr.header_size);
|
||||
|
||||
err = grub_efiemu_resolve_symbol ("efiemu_system_table", &handle, &off);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* compute CRC32 of system table */
|
||||
SUFFIX (grub_efiemu_system_table)->hdr.crc32 = 0;
|
||||
SUFFIX (grub_efiemu_system_table)->hdr.crc32
|
||||
= grub_getcrc32 (0, SUFFIX (grub_efiemu_system_table),
|
||||
SUFFIX (grub_efiemu_system_table)->hdr.header_size);
|
||||
|
||||
grub_dprintf ("efiemu","system_table = %p, runtime_services = %p,"
|
||||
" conftables = %p (%d entries)\n",
|
||||
SUFFIX (grub_efiemu_system_table), runtime_services,
|
||||
conftables, cntconftables);
|
||||
grub_dprintf ("efiemu","system_table = %p, runtime_services = %p\n",
|
||||
SUFFIX (grub_efiemu_system_table), runtime_services);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
|
|
@ -111,9 +111,8 @@ static grub_uint8_t loge[1000] = "EFIEMULOG";
|
|||
static int logn = 9;
|
||||
#define LOG(x) { if (logn<900) loge[logn++]=x; }
|
||||
|
||||
static int ptv_relocated = 0;
|
||||
|
||||
/* Interface with grub */
|
||||
extern grub_uint8_t efiemu_ptv_relocated;
|
||||
struct grub_efi_runtime_services efiemu_runtime_services;
|
||||
struct grub_efi_system_table efiemu_system_table;
|
||||
extern struct grub_efiemu_ptv_rel efiemu_ptv_relloc[];
|
||||
|
@ -343,9 +342,9 @@ grub_efi_status_t EFI_FUNC
|
|||
LOG ('e');
|
||||
|
||||
/* Ensure that we are called only once */
|
||||
if (ptv_relocated)
|
||||
if (efiemu_ptv_relocated)
|
||||
return GRUB_EFI_UNSUPPORTED;
|
||||
ptv_relocated = 1;
|
||||
efiemu_ptv_relocated = 1;
|
||||
|
||||
/* Correct addresses using information supplied by grub */
|
||||
for (cur_relloc = efiemu_ptv_relloc; cur_relloc->size;cur_relloc++)
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
static int ptv_written = 0;
|
||||
static int ptv_alloc = 0;
|
||||
static int ptv_handle = 0;
|
||||
static int relocated_handle = 0;
|
||||
static int ptv_requested = 0;
|
||||
static struct grub_efiemu_sym *efiemu_syms = 0;
|
||||
|
||||
|
@ -54,6 +55,8 @@ grub_efiemu_free_syms (void)
|
|||
ptv_requested = 0;
|
||||
grub_efiemu_mm_return_request (ptv_handle);
|
||||
ptv_handle = 0;
|
||||
grub_efiemu_mm_return_request (relocated_handle);
|
||||
relocated_handle = 0;
|
||||
}
|
||||
|
||||
/* Announce that the module will need NUM allocators */
|
||||
|
@ -114,10 +117,26 @@ grub_efiemu_alloc_syms (void)
|
|||
ptv_handle = grub_efiemu_request_memalign
|
||||
(1, (ptv_requested + 1) * sizeof (struct grub_efiemu_ptv_rel),
|
||||
GRUB_EFI_RUNTIME_SERVICES_DATA);
|
||||
relocated_handle = grub_efiemu_request_memalign
|
||||
(1, sizeof (grub_uint8_t), GRUB_EFI_RUNTIME_SERVICES_DATA);
|
||||
|
||||
grub_efiemu_register_symbol ("efiemu_ptv_relocated", relocated_handle, 0);
|
||||
grub_efiemu_register_symbol ("efiemu_ptv_relloc", ptv_handle, 0);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_efiemu_write_sym_markers (void)
|
||||
{
|
||||
struct grub_efiemu_ptv_rel *ptv_rels
|
||||
= grub_efiemu_mm_obtain_request (ptv_handle);
|
||||
grub_uint8_t *relocated = grub_efiemu_mm_obtain_request (relocated_handle);
|
||||
grub_memset (ptv_rels, 0, (ptv_requested + 1)
|
||||
* sizeof (struct grub_efiemu_ptv_rel));
|
||||
*relocated = 0;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/* Write value (pointer to memory PLUS_HANDLE)
|
||||
- (pointer to memory MINUS_HANDLE) + VALUE to ADDR assuming that the
|
||||
size SIZE bytes. If PTV_NEEDED is 1 then announce it to runtime that this
|
||||
|
@ -186,3 +205,67 @@ grub_efiemu_write_value (void *addr, grub_uint32_t value, int plus_handle,
|
|||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_efiemu_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
|
||||
grub_efi_uintn_t descriptor_size,
|
||||
grub_efi_uint32_t descriptor_version
|
||||
__attribute__ ((unused)),
|
||||
grub_efi_memory_descriptor_t *virtual_map)
|
||||
{
|
||||
grub_uint8_t *ptv_relocated;
|
||||
struct grub_efiemu_ptv_rel *cur_relloc;
|
||||
struct grub_efiemu_ptv_rel *ptv_rels;
|
||||
|
||||
ptv_relocated = grub_efiemu_mm_obtain_request (relocated_handle);
|
||||
ptv_rels = grub_efiemu_mm_obtain_request (ptv_handle);
|
||||
|
||||
/* Ensure that we are called only once */
|
||||
if (*ptv_relocated)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "EfiEmu is already relocated.");
|
||||
*ptv_relocated = 1;
|
||||
|
||||
/* Correct addresses using information supplied by grub */
|
||||
for (cur_relloc = ptv_rels; cur_relloc->size; cur_relloc++)
|
||||
{
|
||||
grub_int64_t corr = 0;
|
||||
grub_efi_memory_descriptor_t *descptr;
|
||||
|
||||
/* Compute correction */
|
||||
for (descptr = virtual_map;
|
||||
(grub_size_t) ((grub_uint8_t *) descptr
|
||||
- (grub_uint8_t *) virtual_map) < memory_map_size;
|
||||
descptr = (grub_efi_memory_descriptor_t *)
|
||||
((grub_uint8_t *) descptr + descriptor_size))
|
||||
{
|
||||
if (descptr->type == cur_relloc->plustype)
|
||||
corr += descptr->virtual_start - descptr->physical_start;
|
||||
if (descptr->type == cur_relloc->minustype)
|
||||
corr -= descptr->virtual_start - descptr->physical_start;
|
||||
}
|
||||
|
||||
/* Apply correction */
|
||||
switch (cur_relloc->size)
|
||||
{
|
||||
case 8:
|
||||
*((grub_uint64_t *) UINT_TO_PTR (cur_relloc->addr)) += corr;
|
||||
break;
|
||||
case 4:
|
||||
*((grub_uint32_t *) UINT_TO_PTR (cur_relloc->addr)) += corr;
|
||||
break;
|
||||
case 2:
|
||||
*((grub_uint16_t *) UINT_TO_PTR (cur_relloc->addr)) += corr;
|
||||
break;
|
||||
case 1:
|
||||
*((grub_uint8_t *) UINT_TO_PTR (cur_relloc->addr)) += corr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Recompute crc32 of system table and runtime services */
|
||||
|
||||
if (grub_efiemu_sizeof_uintn_t () == 4)
|
||||
return grub_efiemu_crc32 ();
|
||||
else
|
||||
return grub_efiemu_crc64 ();
|
||||
}
|
||||
|
|
1
fs/fat.c
1
fs/fat.c
|
@ -25,6 +25,7 @@
|
|||
#include <grub/mm.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/charset.h>
|
||||
|
||||
#define GRUB_FAT_DIR_ENTRY_SIZE 32
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <grub/types.h>
|
||||
#include <grub/fshelp.h>
|
||||
#include <grub/hfs.h>
|
||||
#include <grub/charset.h>
|
||||
|
||||
#define GRUB_HFSPLUS_MAGIC 0x482B
|
||||
#define GRUB_HFSPLUSX_MAGIC 0x4858
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <grub/dl.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/fshelp.h>
|
||||
#include <grub/charset.h>
|
||||
|
||||
#define GRUB_ISO9660_FSTYPE_DIR 0040000
|
||||
#define GRUB_ISO9660_FSTYPE_REG 0100000
|
||||
|
|
1
fs/jfs.c
1
fs/jfs.c
|
@ -24,6 +24,7 @@
|
|||
#include <grub/disk.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/charset.h>
|
||||
|
||||
#define GRUB_JFS_MAX_SYMLNK_CNT 8
|
||||
#define GRUB_JFS_FILETYPE_MASK 0170000
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <grub/dl.h>
|
||||
#include <grub/fshelp.h>
|
||||
#include <grub/ntfs.h>
|
||||
#include <grub/charset.h>
|
||||
|
||||
static grub_dl_t my_mod;
|
||||
|
||||
|
|
0
gendistlist.sh
Normal file → Executable file
0
gendistlist.sh
Normal file → Executable file
|
@ -26,8 +26,10 @@
|
|||
# include <grub/efi/efi.h>
|
||||
# define grub_autoefi_get_memory_map grub_efi_get_memory_map
|
||||
# define grub_autoefi_finish_boot_services grub_efi_finish_boot_services
|
||||
# define grub_autoefi_exit_boot_services grub_efi_exit_boot_services
|
||||
# define grub_autoefi_system_table grub_efi_system_table
|
||||
# define grub_autoefi_mmap_iterate grub_machine_mmap_iterate
|
||||
# define grub_autoefi_set_virtual_address_map grub_efi_set_virtual_address_map
|
||||
static inline grub_err_t grub_autoefi_prepare (void)
|
||||
{
|
||||
return GRUB_ERR_NONE;
|
||||
|
@ -53,9 +55,11 @@ static inline grub_err_t grub_autoefi_prepare (void)
|
|||
# include <grub/efiemu/efiemu.h>
|
||||
# define grub_autoefi_get_memory_map grub_efiemu_get_memory_map
|
||||
# define grub_autoefi_finish_boot_services grub_efiemu_finish_boot_services
|
||||
# define grub_autoefi_exit_boot_services grub_efiemu_exit_boot_services
|
||||
# define grub_autoefi_system_table grub_efiemu_system_table
|
||||
# define grub_autoefi_mmap_iterate grub_efiemu_mmap_iterate
|
||||
# define grub_autoefi_prepare grub_efiemu_prepare
|
||||
# define grub_autoefi_set_virtual_address_map grub_efiemu_set_virtual_address_map
|
||||
# define GRUB_AUTOEFI_MEMORY_AVAILABLE GRUB_EFIEMU_MEMORY_AVAILABLE
|
||||
# define GRUB_AUTOEFI_MEMORY_RESERVED GRUB_EFIEMU_MEMORY_RESERVED
|
||||
# define GRUB_AUTOEFI_MEMORY_ACPI GRUB_EFIEMU_MEMORY_ACPI
|
||||
|
|
112
include/grub/charset.h
Normal file
112
include/grub/charset.h
Normal file
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004,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/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_CHARSET_HEADER
|
||||
#define GRUB_CHARSET_HEADER 1
|
||||
|
||||
#include <grub/types.h>
|
||||
|
||||
#define GRUB_UINT8_1_LEADINGBIT 0x80
|
||||
#define GRUB_UINT8_2_LEADINGBITS 0xc0
|
||||
#define GRUB_UINT8_3_LEADINGBITS 0xe0
|
||||
#define GRUB_UINT8_4_LEADINGBITS 0xf0
|
||||
#define GRUB_UINT8_5_LEADINGBITS 0xf8
|
||||
#define GRUB_UINT8_6_LEADINGBITS 0xfc
|
||||
#define GRUB_UINT8_7_LEADINGBITS 0xfe
|
||||
|
||||
#define GRUB_UINT8_1_TRAILINGBIT 0x01
|
||||
#define GRUB_UINT8_2_TRAILINGBITS 0x03
|
||||
#define GRUB_UINT8_3_TRAILINGBITS 0x07
|
||||
#define GRUB_UINT8_4_TRAILINGBITS 0x0f
|
||||
#define GRUB_UINT8_5_TRAILINGBITS 0x1f
|
||||
#define GRUB_UINT8_6_TRAILINGBITS 0x3f
|
||||
|
||||
#define GRUB_UCS2_LIMIT 0x10000
|
||||
#define GRUB_UTF16_UPPER_SURROGATE(code) \
|
||||
(0xD800 + ((((code) - GRUB_UCS2_LIMIT) >> 12) & 0xfff))
|
||||
#define GRUB_UTF16_LOWER_SURROGATE(code) \
|
||||
(0xDC00 + (((code) - GRUB_UCS2_LIMIT) & 0xfff))
|
||||
|
||||
grub_ssize_t
|
||||
grub_utf8_to_utf16 (grub_uint16_t *dest, grub_size_t destsize,
|
||||
const grub_uint8_t *src, grub_size_t srcsize,
|
||||
const grub_uint8_t **srcend);
|
||||
|
||||
/* Convert UTF-16 to UTF-8. */
|
||||
static inline grub_uint8_t *
|
||||
grub_utf16_to_utf8 (grub_uint8_t *dest, grub_uint16_t *src,
|
||||
grub_size_t size)
|
||||
{
|
||||
grub_uint32_t code_high = 0;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
grub_uint32_t code = *src++;
|
||||
|
||||
if (code_high)
|
||||
{
|
||||
if (code >= 0xDC00 && code <= 0xDFFF)
|
||||
{
|
||||
/* Surrogate pair. */
|
||||
code = ((code_high - 0xD800) << 12) + (code - 0xDC00) + 0x10000;
|
||||
|
||||
*dest++ = (code >> 18) | 0xF0;
|
||||
*dest++ = ((code >> 12) & 0x3F) | 0x80;
|
||||
*dest++ = ((code >> 6) & 0x3F) | 0x80;
|
||||
*dest++ = (code & 0x3F) | 0x80;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Error... */
|
||||
*dest++ = '?';
|
||||
}
|
||||
|
||||
code_high = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (code <= 0x007F)
|
||||
*dest++ = code;
|
||||
else if (code <= 0x07FF)
|
||||
{
|
||||
*dest++ = (code >> 6) | 0xC0;
|
||||
*dest++ = (code & 0x3F) | 0x80;
|
||||
}
|
||||
else if (code >= 0xD800 && code <= 0xDBFF)
|
||||
{
|
||||
code_high = code;
|
||||
continue;
|
||||
}
|
||||
else if (code >= 0xDC00 && code <= 0xDFFF)
|
||||
{
|
||||
/* Error... */
|
||||
*dest++ = '?';
|
||||
}
|
||||
else
|
||||
{
|
||||
*dest++ = (code >> 12) | 0xE0;
|
||||
*dest++ = ((code >> 6) & 0x3F) | 0x80;
|
||||
*dest++ = (code & 0x3F) | 0x80;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -21,6 +21,7 @@
|
|||
#define GRUB_EFI_API_HEADER 1
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/symbol.h>
|
||||
|
||||
/* For consistency and safety, we name the EFI-defined types differently.
|
||||
All names are transformed into lower case, _t appended, and
|
||||
|
|
|
@ -55,6 +55,10 @@ grub_efi_device_path_t *
|
|||
EXPORT_FUNC(grub_efi_get_device_path) (grub_efi_handle_t handle);
|
||||
int EXPORT_FUNC(grub_efi_exit_boot_services) (grub_efi_uintn_t map_key);
|
||||
int EXPORT_FUNC (grub_efi_finish_boot_services) (void);
|
||||
grub_err_t EXPORT_FUNC (grub_efi_set_virtual_address_map) (grub_efi_uintn_t memory_map_size,
|
||||
grub_efi_uintn_t descriptor_size,
|
||||
grub_efi_uint32_t descriptor_version,
|
||||
grub_efi_memory_descriptor_t *virtual_map);
|
||||
|
||||
void grub_efi_mm_init (void);
|
||||
void grub_efi_mm_fini (void);
|
||||
|
|
|
@ -268,9 +268,19 @@ void grub_efiemu_free_syms (void);
|
|||
grub_err_t grub_efiemu_write_value (void * addr, grub_uint32_t value,
|
||||
int plus_handle,
|
||||
int minus_handle, int ptv_needed, int size);
|
||||
grub_err_t grub_efiemu_write_sym_markers (void);
|
||||
grub_err_t grub_efiemu_pnvram (void);
|
||||
grub_err_t grub_efiemu_prepare (void);
|
||||
char *grub_efiemu_get_default_core_name (void);
|
||||
void grub_efiemu_pnvram_cmd_unregister (void);
|
||||
grub_err_t grub_efiemu_autocore (void);
|
||||
grub_err_t grub_efiemu_crc32 (void);
|
||||
grub_err_t grub_efiemu_crc64 (void);
|
||||
grub_err_t
|
||||
grub_efiemu_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
|
||||
grub_efi_uintn_t descriptor_size,
|
||||
grub_efi_uint32_t descriptor_version
|
||||
__attribute__ ((unused)),
|
||||
grub_efi_memory_descriptor_t *virtual_map);
|
||||
|
||||
#endif /* ! GRUB_EFI_EMU_HEADER */
|
||||
|
|
|
@ -1,3 +1,26 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_CPU_MACHO_H
|
||||
#define GRUB_CPU_MACHO_H 1
|
||||
|
||||
#include <grub/macho.h>
|
||||
|
||||
#define GRUB_MACHO_CPUTYPE_IS_HOST32(x) ((x)==0x00000007)
|
||||
#define GRUB_MACHO_CPUTYPE_IS_HOST64(x) ((x)==0x01000007)
|
||||
|
||||
|
@ -9,3 +32,15 @@ struct grub_macho_thread32
|
|||
grub_uint32_t entry_point;
|
||||
grub_uint8_t unknown2[20];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
|
||||
struct grub_macho_thread64
|
||||
{
|
||||
grub_uint32_t cmd;
|
||||
grub_uint32_t cmdsize;
|
||||
grub_uint8_t unknown1[0x88];
|
||||
grub_uint64_t entry_point;
|
||||
grub_uint8_t unknown2[0x20];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#endif
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#define GRUB_CPU_XNU_H 1
|
||||
|
||||
#include <grub/err.h>
|
||||
#include <grub/efi/api.h>
|
||||
#include <grub/cpu/relocator.h>
|
||||
|
||||
#define XNU_RELOCATOR(x) (grub_relocator32_ ## x)
|
||||
|
@ -67,15 +68,54 @@ struct grub_xnu_boot_params
|
|||
/* Size of grub_efi_uintn_t in bits. */
|
||||
grub_uint8_t efi_uintnbits;
|
||||
} __attribute__ ((packed));
|
||||
#define GRUB_XNU_BOOTARGS_VERMINOR 4
|
||||
#define GRUB_XNU_BOOTARGS_VERMINOR 5
|
||||
#define GRUB_XNU_BOOTARGS_VERMAJOR 1
|
||||
|
||||
struct grub_xnu_devprop_header
|
||||
{
|
||||
grub_uint32_t length;
|
||||
/* Always set to 1. Version? */
|
||||
grub_uint32_t alwaysone;
|
||||
grub_uint32_t num_devices;
|
||||
};
|
||||
|
||||
struct grub_xnu_devprop_device_header
|
||||
{
|
||||
grub_uint32_t length;
|
||||
grub_uint32_t num_values;
|
||||
};
|
||||
|
||||
void grub_cpu_xnu_unload (void);
|
||||
|
||||
struct grub_xnu_devprop_device_descriptor;
|
||||
|
||||
struct grub_xnu_devprop_device_descriptor *
|
||||
grub_xnu_devprop_add_device (struct grub_efi_device_path *path, int length);
|
||||
grub_err_t
|
||||
grub_xnu_devprop_remove_device (struct grub_xnu_devprop_device_descriptor *dev);
|
||||
grub_err_t
|
||||
grub_xnu_devprop_remove_property (struct grub_xnu_devprop_device_descriptor *dev,
|
||||
char *name);
|
||||
grub_err_t
|
||||
grub_xnu_devprop_add_property_utf8 (struct grub_xnu_devprop_device_descriptor *dev,
|
||||
char *name, void *data, int datalen);
|
||||
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_err_t
|
||||
grub_xnu_devprop_remove_property_utf8 (struct grub_xnu_devprop_device_descriptor *dev,
|
||||
char *name);
|
||||
void grub_cpu_xnu_init (void);
|
||||
void grub_cpu_xnu_fini (void);
|
||||
|
||||
extern grub_uint32_t grub_xnu_entry_point;
|
||||
extern grub_uint32_t grub_xnu_stack;
|
||||
extern grub_uint32_t grub_xnu_arg1;
|
||||
extern char grub_xnu_cmdline[1024];
|
||||
grub_err_t grub_xnu_boot (void);
|
||||
grub_err_t grub_cpu_xnu_fill_devicetree (void);
|
||||
grub_err_t grub_xnu_set_video (struct grub_xnu_boot_params *bootparams_relloc);
|
||||
grub_err_t
|
||||
grub_cpu_xnu_fill_devicetree (void);
|
||||
extern grub_uint32_t grub_xnu_heap_will_be_at;
|
||||
#endif
|
||||
|
|
|
@ -102,6 +102,23 @@ struct grub_macho_segment32
|
|||
grub_uint32_t flags;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/* 64-bit segment command. */
|
||||
struct grub_macho_segment64
|
||||
{
|
||||
#define GRUB_MACHO_CMD_SEGMENT64 0x19
|
||||
grub_uint32_t cmd;
|
||||
grub_uint32_t cmdsize;
|
||||
grub_uint8_t segname[16];
|
||||
grub_uint64_t vmaddr;
|
||||
grub_uint64_t vmsize;
|
||||
grub_uint64_t fileoff;
|
||||
grub_uint64_t filesize;
|
||||
grub_macho_vmprot_t maxprot;
|
||||
grub_macho_vmprot_t initprot;
|
||||
grub_uint32_t nsects;
|
||||
grub_uint32_t flags;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#define GRUB_MACHO_CMD_THREAD 5
|
||||
|
||||
#endif
|
||||
|
|
|
@ -46,17 +46,28 @@ grub_macho_t grub_macho_file (grub_file_t);
|
|||
grub_err_t grub_macho_close (grub_macho_t);
|
||||
|
||||
int grub_macho_contains_macho32 (grub_macho_t);
|
||||
grub_err_t grub_macho32_size (grub_macho_t macho, grub_addr_t *segments_start,
|
||||
grub_addr_t *segments_end, int flags);
|
||||
grub_uint32_t grub_macho32_get_entry_point (grub_macho_t macho);
|
||||
grub_err_t grub_macho_size32 (grub_macho_t macho, grub_uint32_t *segments_start,
|
||||
grub_uint32_t *segments_end, int flags);
|
||||
grub_uint32_t grub_macho_get_entry_point32 (grub_macho_t macho);
|
||||
|
||||
int grub_macho_contains_macho64 (grub_macho_t);
|
||||
grub_err_t grub_macho_size64 (grub_macho_t macho, grub_uint64_t *segments_start,
|
||||
grub_uint64_t *segments_end, int flags);
|
||||
grub_uint64_t grub_macho_get_entry_point64 (grub_macho_t macho);
|
||||
|
||||
/* Ignore BSS segments when loading. */
|
||||
#define GRUB_MACHO_NOBSS 0x1
|
||||
grub_err_t grub_macho32_load (grub_macho_t macho, char *offset, int flags);
|
||||
grub_err_t grub_macho_load32 (grub_macho_t macho, char *offset, int flags);
|
||||
grub_err_t grub_macho_load64 (grub_macho_t macho, char *offset, int flags);
|
||||
|
||||
/* Like filesize and file_read but take only 32-bit part
|
||||
for current architecture. */
|
||||
grub_size_t grub_macho32_filesize (grub_macho_t macho);
|
||||
grub_err_t grub_macho32_readfile (grub_macho_t macho, void *dest);
|
||||
grub_size_t grub_macho_filesize32 (grub_macho_t macho);
|
||||
grub_err_t grub_macho_readfile32 (grub_macho_t macho, void *dest);
|
||||
grub_size_t grub_macho_filesize64 (grub_macho_t macho);
|
||||
grub_err_t grub_macho_readfile64 (grub_macho_t macho, void *dest);
|
||||
|
||||
void grub_macho_parse32 (grub_macho_t macho);
|
||||
void grub_macho_parse64 (grub_macho_t macho);
|
||||
|
||||
#endif /* ! GRUB_MACHOLOAD_HEADER */
|
||||
|
|
|
@ -183,9 +183,6 @@ int EXPORT_FUNC(grub_sprintf) (char *str, const char *fmt, ...) __attribute__ ((
|
|||
int EXPORT_FUNC(grub_vsprintf) (char *str, const char *fmt, va_list args);
|
||||
void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn));
|
||||
void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn));
|
||||
grub_uint8_t *EXPORT_FUNC(grub_utf16_to_utf8) (grub_uint8_t *dest,
|
||||
grub_uint16_t *src,
|
||||
grub_size_t size);
|
||||
grub_ssize_t EXPORT_FUNC(grub_utf8_to_ucs4) (grub_uint32_t *dest,
|
||||
grub_size_t destsize,
|
||||
const grub_uint8_t *src,
|
||||
|
|
|
@ -64,9 +64,6 @@ grub_usb_err_t grub_usb_clear_halt (grub_usb_device_t dev, int endpoint);
|
|||
grub_usb_err_t grub_usb_set_configuration (grub_usb_device_t dev,
|
||||
int configuration);
|
||||
|
||||
grub_usb_err_t grub_usb_get_string (grub_usb_device_t dev, grub_uint8_t index,
|
||||
int langid, char **string);
|
||||
|
||||
void grub_usb_controller_dev_register (grub_usb_controller_dev_t usb);
|
||||
|
||||
void grub_usb_controller_dev_unregister (grub_usb_controller_dev_t usb);
|
||||
|
|
|
@ -76,6 +76,8 @@ struct grub_xnu_extheader
|
|||
grub_uint32_t infoplistsize;
|
||||
grub_uint32_t binaryaddr;
|
||||
grub_uint32_t binarysize;
|
||||
grub_uint32_t nameaddr;
|
||||
grub_uint32_t namesize;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_xnu_devtree_key *grub_xnu_create_key (struct grub_xnu_devtree_key **parent,
|
||||
|
@ -101,7 +103,10 @@ grub_err_t grub_xnu_scan_dir_for_kexts (char *dirname, char *osbundlerequired,
|
|||
grub_err_t grub_xnu_load_kext_from_dir (char *dirname, char *osbundlerequired,
|
||||
int maxrecursion);
|
||||
void *grub_xnu_heap_malloc (int size);
|
||||
grub_err_t grub_xnu_fill_devicetree (void);
|
||||
extern grub_uint32_t grub_xnu_heap_real_start;
|
||||
extern grub_size_t grub_xnu_heap_size;
|
||||
extern void *grub_xnu_heap_start;
|
||||
extern struct grub_video_bitmap *grub_xnu_bitmap;
|
||||
extern int grub_xnu_is_64bit;
|
||||
#endif
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include <grub/misc.h>
|
||||
#include <grub/charset.h>
|
||||
#include <grub/efi/api.h>
|
||||
#include <grub/efi/efi.h>
|
||||
#include <grub/efi/console_control.h>
|
||||
|
@ -188,6 +189,25 @@ grub_efi_exit_boot_services (grub_efi_uintn_t map_key)
|
|||
return status == GRUB_EFI_SUCCESS;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
|
||||
grub_efi_uintn_t descriptor_size,
|
||||
grub_efi_uint32_t descriptor_version,
|
||||
grub_efi_memory_descriptor_t *virtual_map)
|
||||
{
|
||||
grub_efi_runtime_services_t *r;
|
||||
grub_efi_status_t status;
|
||||
|
||||
r = grub_efi_system_table->runtime_services;
|
||||
status = efi_call_4 (r->set_virtual_address_map, memory_map_size,
|
||||
descriptor_size, descriptor_version, virtual_map);
|
||||
|
||||
if (status == GRUB_EFI_SUCCESS)
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
return grub_error (GRUB_ERR_IO, "set_virtual_address_map failed");
|
||||
}
|
||||
|
||||
grub_uint32_t
|
||||
grub_get_rtc (void)
|
||||
{
|
||||
|
|
62
kern/misc.c
62
kern/misc.c
|
@ -879,68 +879,6 @@ grub_sprintf (char *str, const char *fmt, ...)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/* Convert UTF-16 to UTF-8. */
|
||||
grub_uint8_t *
|
||||
grub_utf16_to_utf8 (grub_uint8_t *dest, grub_uint16_t *src,
|
||||
grub_size_t size)
|
||||
{
|
||||
grub_uint32_t code_high = 0;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
grub_uint32_t code = *src++;
|
||||
|
||||
if (code_high)
|
||||
{
|
||||
if (code >= 0xDC00 && code <= 0xDFFF)
|
||||
{
|
||||
/* Surrogate pair. */
|
||||
code = ((code_high - 0xD800) << 12) + (code - 0xDC00) + 0x10000;
|
||||
|
||||
*dest++ = (code >> 18) | 0xF0;
|
||||
*dest++ = ((code >> 12) & 0x3F) | 0x80;
|
||||
*dest++ = ((code >> 6) & 0x3F) | 0x80;
|
||||
*dest++ = (code & 0x3F) | 0x80;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Error... */
|
||||
*dest++ = '?';
|
||||
}
|
||||
|
||||
code_high = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (code <= 0x007F)
|
||||
*dest++ = code;
|
||||
else if (code <= 0x07FF)
|
||||
{
|
||||
*dest++ = (code >> 6) | 0xC0;
|
||||
*dest++ = (code & 0x3F) | 0x80;
|
||||
}
|
||||
else if (code >= 0xD800 && code <= 0xDBFF)
|
||||
{
|
||||
code_high = code;
|
||||
continue;
|
||||
}
|
||||
else if (code >= 0xDC00 && code <= 0xDFFF)
|
||||
{
|
||||
/* Error... */
|
||||
*dest++ = '?';
|
||||
}
|
||||
else
|
||||
{
|
||||
*dest++ = (code >> 12) | 0xE0;
|
||||
*dest++ = ((code >> 6) & 0x3F) | 0x80;
|
||||
*dest++ = (code & 0x3F) | 0x80;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/* Convert a (possibly null-terminated) UTF-8 string of at most SRCSIZE
|
||||
bytes (if SRCSIZE is -1, it is ignored) in length to a UCS-4 string.
|
||||
Return the number of characters converted. DEST must be able to hold
|
||||
|
|
116
lib/charset.c
Normal file
116
lib/charset.c
Normal file
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004,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/>.
|
||||
*/
|
||||
|
||||
/* Convert a (possibly null-terminated) UTF-8 string of at most SRCSIZE
|
||||
bytes (if SRCSIZE is -1, it is ignored) in length to a UTF-16 string.
|
||||
Return the number of characters converted. DEST must be able to hold
|
||||
at least DESTSIZE characters. If an invalid sequence is found, return -1.
|
||||
If SRCEND is not NULL, then *SRCEND is set to the next byte after the
|
||||
last byte used in SRC. */
|
||||
|
||||
#include <grub/charset.h>
|
||||
|
||||
grub_ssize_t
|
||||
grub_utf8_to_utf16 (grub_uint16_t *dest, grub_size_t destsize,
|
||||
const grub_uint8_t *src, grub_size_t srcsize,
|
||||
const grub_uint8_t **srcend)
|
||||
{
|
||||
grub_uint16_t *p = dest;
|
||||
int count = 0;
|
||||
grub_uint32_t code = 0;
|
||||
|
||||
if (srcend)
|
||||
*srcend = src;
|
||||
|
||||
while (srcsize && destsize)
|
||||
{
|
||||
grub_uint32_t c = *src++;
|
||||
if (srcsize != (grub_size_t)-1)
|
||||
srcsize--;
|
||||
if (count)
|
||||
{
|
||||
if ((c & GRUB_UINT8_2_LEADINGBITS) != GRUB_UINT8_1_LEADINGBIT)
|
||||
{
|
||||
/* invalid */
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
code <<= 6;
|
||||
code |= (c & GRUB_UINT8_6_TRAILINGBITS);
|
||||
count--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c == 0)
|
||||
break;
|
||||
|
||||
if ((c & GRUB_UINT8_1_LEADINGBIT) == 0)
|
||||
code = c;
|
||||
else if ((c & GRUB_UINT8_3_LEADINGBITS) == GRUB_UINT8_2_LEADINGBITS)
|
||||
{
|
||||
count = 1;
|
||||
code = c & GRUB_UINT8_5_TRAILINGBITS;
|
||||
}
|
||||
else if ((c & GRUB_UINT8_4_LEADINGBITS) == GRUB_UINT8_3_LEADINGBITS)
|
||||
{
|
||||
count = 2;
|
||||
code = c & GRUB_UINT8_4_TRAILINGBITS;
|
||||
}
|
||||
else if ((c & GRUB_UINT8_5_LEADINGBITS) == GRUB_UINT8_4_LEADINGBITS)
|
||||
{
|
||||
count = 3;
|
||||
code = c & GRUB_UINT8_3_TRAILINGBITS;
|
||||
}
|
||||
else if ((c & GRUB_UINT8_6_LEADINGBITS) == GRUB_UINT8_5_LEADINGBITS)
|
||||
{
|
||||
count = 4;
|
||||
code = c & GRUB_UINT8_2_TRAILINGBITS;
|
||||
}
|
||||
else if ((c & GRUB_UINT8_7_LEADINGBITS) == GRUB_UINT8_6_LEADINGBITS)
|
||||
{
|
||||
count = 5;
|
||||
code = c & GRUB_UINT8_1_TRAILINGBIT;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
if (destsize < 2 && code >= GRUB_UCS2_LIMIT)
|
||||
break;
|
||||
if (code >= GRUB_UCS2_LIMIT)
|
||||
{
|
||||
*p++ = GRUB_UTF16_UPPER_SURROGATE (code);
|
||||
*p++ = GRUB_UTF16_LOWER_SURROGATE (code);
|
||||
destsize -= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
*p++ = code;
|
||||
destsize--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (srcend)
|
||||
*srcend = src;
|
||||
return p - dest;
|
||||
}
|
|
@ -25,6 +25,7 @@
|
|||
#include <grub/device.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/charset.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/dl.h>
|
||||
|
|
|
@ -25,9 +25,13 @@
|
|||
#include <grub/loader.h>
|
||||
#include <grub/autoefi.h>
|
||||
#include <grub/i386/tsc.h>
|
||||
#include <grub/efi/api.h>
|
||||
#include <grub/i386/pit.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/charset.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/gzio.h>
|
||||
|
||||
char grub_xnu_cmdline[1024];
|
||||
grub_uint32_t grub_xnu_heap_will_be_at;
|
||||
|
@ -46,6 +50,14 @@ struct tbl_alias table_aliases[] =
|
|||
{GRUB_EFI_ACPI_TABLE_GUID, "ACPI"},
|
||||
};
|
||||
|
||||
struct grub_xnu_devprop_device_descriptor
|
||||
{
|
||||
struct grub_xnu_devprop_device_descriptor *next;
|
||||
struct property_descriptor *properties;
|
||||
struct grub_efi_device_path *path;
|
||||
int pathlen;
|
||||
};
|
||||
|
||||
static int
|
||||
utf16_strlen (grub_uint16_t *in)
|
||||
{
|
||||
|
@ -192,6 +204,417 @@ guessfsb (void)
|
|||
((msrlow >> 7) & 0x3e) + ((msrlow >> 14) & 1), 0);
|
||||
}
|
||||
|
||||
struct property_descriptor
|
||||
{
|
||||
struct property_descriptor *next;
|
||||
grub_uint8_t *name;
|
||||
grub_uint16_t *name16;
|
||||
int name16len;
|
||||
int length;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct grub_xnu_devprop_device_descriptor *devices = 0;
|
||||
|
||||
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_P (&dev->properties), name);
|
||||
if (!prop)
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
grub_free (prop->name);
|
||||
grub_free (prop->name16);
|
||||
grub_free (prop->data);
|
||||
|
||||
grub_list_remove (GRUB_AS_LIST_P (&dev->properties), GRUB_AS_LIST (prop));
|
||||
|
||||
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_P (&devices), GRUB_AS_LIST (dev));
|
||||
|
||||
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)
|
||||
{
|
||||
devprop->data = grub_malloc (total_length);
|
||||
devprop->datasize = total_length;
|
||||
}
|
||||
|
||||
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)
|
||||
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. ");
|
||||
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
|
||||
|
@ -203,11 +626,6 @@ grub_cpu_xnu_fill_devicetree (void)
|
|||
struct grub_xnu_devtree_key *runtimesrvkey;
|
||||
struct grub_xnu_devtree_key *platformkey;
|
||||
unsigned i, j;
|
||||
grub_err_t err;
|
||||
|
||||
err = grub_autoefi_prepare ();
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* The value "model". */
|
||||
/* FIXME: may this value be sometimes different? */
|
||||
|
@ -430,12 +848,29 @@ grub_xnu_boot (void)
|
|||
grub_efi_uintn_t map_key = 0;
|
||||
grub_efi_uintn_t descriptor_size = 0;
|
||||
grub_efi_uint32_t descriptor_version = 0;
|
||||
grub_uint64_t firstruntimeaddr, lastruntimeaddr;
|
||||
grub_uint64_t firstruntimepage, lastruntimepage;
|
||||
grub_uint64_t curruntimepage;
|
||||
void *devtree;
|
||||
grub_size_t devtreelen;
|
||||
int i;
|
||||
struct grub_relocator32_state state;
|
||||
|
||||
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)
|
||||
|
@ -448,89 +883,6 @@ grub_xnu_boot (void)
|
|||
descriptor_size = 0;
|
||||
descriptor_version = 0;
|
||||
|
||||
if (grub_autoefi_get_memory_map (&memory_map_size, memory_map,
|
||||
&map_key, &descriptor_size,
|
||||
&descriptor_version) < 0)
|
||||
return grub_errno;
|
||||
|
||||
memory_map = grub_xnu_heap_malloc (memory_map_size);
|
||||
if (! memory_map)
|
||||
return grub_errno;
|
||||
|
||||
if (grub_autoefi_get_memory_map (&memory_map_size, memory_map,
|
||||
&map_key, &descriptor_size,
|
||||
&descriptor_version) <= 0)
|
||||
return grub_errno;
|
||||
mmap_relloc_off = (grub_uint8_t *) memory_map
|
||||
- (grub_uint8_t *) grub_xnu_heap_start;
|
||||
|
||||
firstruntimeaddr = (grub_uint64_t) (-1);
|
||||
lastruntimeaddr = 0;
|
||||
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);
|
||||
|
||||
/* Some EFI implementations set physical_start to 0 which
|
||||
causes XNU crash. */
|
||||
curdesc->virtual_start = curdesc->physical_start;
|
||||
|
||||
if (curdesc->type == GRUB_EFI_RUNTIME_SERVICES_DATA
|
||||
|| curdesc->type == GRUB_EFI_RUNTIME_SERVICES_CODE)
|
||||
{
|
||||
if (firstruntimeaddr > curdesc->physical_start)
|
||||
firstruntimeaddr = curdesc->physical_start;
|
||||
if (lastruntimeaddr < curdesc->physical_start
|
||||
+ curdesc->num_pages * 4096)
|
||||
lastruntimeaddr = curdesc->physical_start
|
||||
+ curdesc->num_pages * 4096;
|
||||
}
|
||||
}
|
||||
|
||||
/* Relocate the boot parameters to heap. */
|
||||
bootparams_relloc = grub_xnu_heap_malloc (sizeof (*bootparams_relloc));
|
||||
if (! bootparams_relloc)
|
||||
return grub_errno;
|
||||
bootparams_relloc_off = (grub_uint8_t *) bootparams_relloc
|
||||
- (grub_uint8_t *) grub_xnu_heap_start;
|
||||
err = grub_xnu_writetree_toheap (&devtree, &devtreelen);
|
||||
if (err)
|
||||
return err;
|
||||
bootparams_relloc = (struct grub_xnu_boot_params *)
|
||||
(bootparams_relloc_off + (grub_uint8_t *) grub_xnu_heap_start);
|
||||
|
||||
grub_memcpy (bootparams_relloc->cmdline, grub_xnu_cmdline,
|
||||
sizeof (bootparams_relloc->cmdline));
|
||||
|
||||
bootparams_relloc->devtree
|
||||
= ((grub_uint8_t *) devtree - (grub_uint8_t *) grub_xnu_heap_start)
|
||||
+ grub_xnu_heap_will_be_at;
|
||||
bootparams_relloc->devtreelen = devtreelen;
|
||||
|
||||
bootparams_relloc->heap_start = grub_xnu_heap_will_be_at;
|
||||
bootparams_relloc->heap_size = grub_xnu_heap_size;
|
||||
|
||||
bootparams_relloc->efi_mmap = grub_xnu_heap_will_be_at + mmap_relloc_off;
|
||||
bootparams_relloc->efi_mmap_size = memory_map_size;
|
||||
bootparams_relloc->efi_mem_desc_size = descriptor_size;
|
||||
bootparams_relloc->efi_mem_desc_version = descriptor_version;
|
||||
|
||||
bootparams_relloc->efi_runtime_first_page = firstruntimeaddr
|
||||
/ GRUB_XNU_PAGESIZE;
|
||||
bootparams_relloc->efi_runtime_npages
|
||||
= ((lastruntimeaddr + GRUB_XNU_PAGESIZE - 1) / GRUB_XNU_PAGESIZE)
|
||||
- (firstruntimeaddr / GRUB_XNU_PAGESIZE);
|
||||
bootparams_relloc->efi_uintnbits = SIZEOF_OF_UINTN * 8;
|
||||
bootparams_relloc->efi_system_table
|
||||
= PTR_TO_UINT32 (grub_autoefi_system_table);
|
||||
|
||||
bootparams_relloc->verminor = GRUB_XNU_BOOTARGS_VERMINOR;
|
||||
bootparams_relloc->vermajor = GRUB_XNU_BOOTARGS_VERMAJOR;
|
||||
|
||||
/* Parameters for asm helper. */
|
||||
grub_xnu_stack = bootparams_relloc->heap_start
|
||||
+ bootparams_relloc->heap_size + GRUB_XNU_PAGESIZE;
|
||||
grub_xnu_arg1 = bootparams_relloc_off + grub_xnu_heap_will_be_at;
|
||||
grub_dprintf ("xnu", "eip=%x\n", grub_xnu_entry_point);
|
||||
|
||||
const char *debug = grub_env_get ("debug");
|
||||
|
@ -541,6 +893,13 @@ grub_xnu_boot (void)
|
|||
grub_getkey ();
|
||||
}
|
||||
|
||||
/* Relocate the boot parameters to heap. */
|
||||
bootparams_relloc = grub_xnu_heap_malloc (sizeof (*bootparams_relloc));
|
||||
if (! bootparams_relloc)
|
||||
return grub_errno;
|
||||
bootparams_relloc_off = (grub_uint8_t *) bootparams_relloc
|
||||
- (grub_uint8_t *) grub_xnu_heap_start;
|
||||
|
||||
/* Set video. */
|
||||
err = grub_xnu_set_video (bootparams_relloc);
|
||||
if (err != GRUB_ERR_NONE)
|
||||
|
@ -557,12 +916,121 @@ grub_xnu_boot (void)
|
|||
bootparams_relloc->lfb_base = 0;
|
||||
}
|
||||
|
||||
if (! grub_autoefi_finish_boot_services ())
|
||||
if (grub_autoefi_get_memory_map (&memory_map_size, memory_map,
|
||||
&map_key, &descriptor_size,
|
||||
&descriptor_version) < 0)
|
||||
return grub_errno;
|
||||
|
||||
/* We will do few allocations later. Reserve some space for possible
|
||||
memory map growth. */
|
||||
memory_map_size += 20 * descriptor_size;
|
||||
memory_map = grub_xnu_heap_malloc (memory_map_size);
|
||||
if (! memory_map)
|
||||
return grub_errno;
|
||||
mmap_relloc_off = (grub_uint8_t *) memory_map
|
||||
- (grub_uint8_t *) grub_xnu_heap_start;
|
||||
|
||||
err = grub_xnu_writetree_toheap (&devtree, &devtreelen);
|
||||
if (err)
|
||||
return err;
|
||||
bootparams_relloc = (struct grub_xnu_boot_params *)
|
||||
(bootparams_relloc_off + (grub_uint8_t *) grub_xnu_heap_start);
|
||||
|
||||
grub_memcpy (bootparams_relloc->cmdline, grub_xnu_cmdline,
|
||||
sizeof (bootparams_relloc->cmdline));
|
||||
|
||||
bootparams_relloc->devtree
|
||||
= ((grub_uint8_t *) devtree - (grub_uint8_t *) grub_xnu_heap_start)
|
||||
+ grub_xnu_heap_will_be_at;
|
||||
bootparams_relloc->devtreelen = devtreelen;
|
||||
|
||||
memory_map = (grub_efi_memory_descriptor_t *)
|
||||
((grub_uint8_t *) grub_xnu_heap_start + mmap_relloc_off);
|
||||
|
||||
if (grub_autoefi_get_memory_map (&memory_map_size, memory_map,
|
||||
&map_key, &descriptor_size,
|
||||
&descriptor_version) <= 0)
|
||||
return grub_errno;
|
||||
|
||||
bootparams_relloc->efi_system_table
|
||||
= PTR_TO_UINT32 (grub_autoefi_system_table);
|
||||
|
||||
firstruntimepage = (((grub_addr_t) grub_xnu_heap_will_be_at
|
||||
+ grub_xnu_heap_size + GRUB_XNU_PAGESIZE - 1)
|
||||
/ GRUB_XNU_PAGESIZE) + 20;
|
||||
curruntimepage = firstruntimepage;
|
||||
|
||||
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;
|
||||
if (curdesc->physical_start
|
||||
<= PTR_TO_UINT64 (grub_autoefi_system_table)
|
||||
&& curdesc->physical_start + (curdesc->num_pages << 12)
|
||||
> PTR_TO_UINT64 (grub_autoefi_system_table))
|
||||
bootparams_relloc->efi_system_table
|
||||
= PTR_TO_UINT64 (grub_autoefi_system_table)
|
||||
- curdesc->physical_start + curdesc->virtual_start;
|
||||
if (SIZEOF_OF_UINTN == 8 && grub_xnu_is_64bit)
|
||||
curdesc->virtual_start |= 0xffffff8000000000ULL;
|
||||
}
|
||||
}
|
||||
|
||||
lastruntimepage = curruntimepage;
|
||||
|
||||
bootparams_relloc->efi_mmap = grub_xnu_heap_will_be_at + mmap_relloc_off;
|
||||
bootparams_relloc->efi_mmap_size = memory_map_size;
|
||||
bootparams_relloc->efi_mem_desc_size = descriptor_size;
|
||||
bootparams_relloc->efi_mem_desc_version = descriptor_version;
|
||||
|
||||
bootparams_relloc->heap_start = grub_xnu_heap_will_be_at;
|
||||
bootparams_relloc->heap_size = grub_xnu_heap_size;
|
||||
bootparams_relloc->efi_runtime_first_page = firstruntimepage;
|
||||
|
||||
bootparams_relloc->efi_runtime_npages = lastruntimepage - firstruntimepage;
|
||||
bootparams_relloc->efi_uintnbits = SIZEOF_OF_UINTN * 8;
|
||||
|
||||
bootparams_relloc->verminor = GRUB_XNU_BOOTARGS_VERMINOR;
|
||||
bootparams_relloc->vermajor = GRUB_XNU_BOOTARGS_VERMAJOR;
|
||||
|
||||
/* Parameters for asm helper. */
|
||||
grub_xnu_stack = bootparams_relloc->heap_start
|
||||
+ bootparams_relloc->heap_size + GRUB_XNU_PAGESIZE;
|
||||
grub_xnu_arg1 = bootparams_relloc_off + grub_xnu_heap_will_be_at;
|
||||
|
||||
if (! grub_autoefi_exit_boot_services (map_key))
|
||||
return grub_error (GRUB_ERR_IO, "can't exit boot services");
|
||||
|
||||
grub_autoefi_set_virtual_address_map (memory_map_size, descriptor_size,
|
||||
descriptor_version,memory_map);
|
||||
|
||||
state.eip = grub_xnu_entry_point;
|
||||
state.eax = grub_xnu_arg1;
|
||||
state.esp = grub_xnu_stack;
|
||||
return grub_relocator32_boot (grub_xnu_heap_start, grub_xnu_heap_will_be_at,
|
||||
state);
|
||||
}
|
||||
|
||||
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,
|
||||
0, "Load device-properties dump.");
|
||||
}
|
||||
|
||||
void
|
||||
grub_cpu_xnu_fini (void)
|
||||
{
|
||||
grub_unregister_command (cmd_devprop_load);
|
||||
}
|
||||
|
|
236
loader/macho.c
236
loader/macho.c
|
@ -30,239 +30,6 @@
|
|||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
|
||||
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
/* 32-bit. */
|
||||
|
||||
int
|
||||
grub_macho_contains_macho32 (grub_macho_t macho)
|
||||
{
|
||||
return macho->offset32 != -1;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_macho_parse32 (grub_macho_t macho)
|
||||
{
|
||||
struct grub_macho_header32 head;
|
||||
|
||||
/* Is there any candidate at all? */
|
||||
if (macho->offset32 == -1)
|
||||
return;
|
||||
|
||||
/* Read header and check magic*/
|
||||
if (grub_file_seek (macho->file, macho->offset32) == (grub_off_t) -1
|
||||
|| grub_file_read (macho->file, &head, sizeof (head))
|
||||
!= sizeof(head))
|
||||
{
|
||||
grub_error (GRUB_ERR_READ_ERROR, "Cannot read Mach-O header.");
|
||||
macho->offset32 = -1;
|
||||
return;
|
||||
}
|
||||
if (head.magic != GRUB_MACHO_MAGIC32)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_OS, "Invalid Mach-O 32-bit header.");
|
||||
macho->offset32 = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Read commands. */
|
||||
macho->ncmds32 = head.ncmds;
|
||||
macho->cmdsize32 = head.sizeofcmds;
|
||||
macho->cmds32 = grub_malloc(macho->cmdsize32);
|
||||
if (! macho->cmds32)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "not enough memory to read commands");
|
||||
return;
|
||||
}
|
||||
if (grub_file_read (macho->file, macho->cmds32,
|
||||
(grub_size_t) macho->cmdsize32)
|
||||
!= (grub_ssize_t) macho->cmdsize32)
|
||||
{
|
||||
grub_error (GRUB_ERR_READ_ERROR, "Cannot read Mach-O header.");
|
||||
macho->offset32 = -1;
|
||||
}
|
||||
}
|
||||
|
||||
typedef int NESTED_FUNC_ATTR (*grub_macho_iter_hook_t)
|
||||
(grub_macho_t , struct grub_macho_cmd *,
|
||||
void *);
|
||||
|
||||
static grub_err_t
|
||||
grub_macho32_cmds_iterate (grub_macho_t macho,
|
||||
grub_macho_iter_hook_t hook,
|
||||
void *hook_arg)
|
||||
{
|
||||
grub_uint8_t *hdrs = macho->cmds32;
|
||||
int i;
|
||||
if (! macho->cmds32)
|
||||
return grub_error (GRUB_ERR_BAD_OS, "Couldn't find 32-bit Mach-O");
|
||||
for (i = 0; i < macho->ncmds32; i++)
|
||||
{
|
||||
struct grub_macho_cmd *hdr = (struct grub_macho_cmd *) hdrs;
|
||||
if (hook (macho, hdr, hook_arg))
|
||||
break;
|
||||
hdrs += hdr->cmdsize;
|
||||
}
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
grub_size_t
|
||||
grub_macho32_filesize (grub_macho_t macho)
|
||||
{
|
||||
if (grub_macho_contains_macho32 (macho))
|
||||
return macho->end32 - macho->offset32;
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_macho32_readfile (grub_macho_t macho, void *dest)
|
||||
{
|
||||
grub_ssize_t read;
|
||||
if (! grub_macho_contains_macho32 (macho))
|
||||
return grub_error (GRUB_ERR_BAD_OS,
|
||||
"Couldn't read architecture-specific part");
|
||||
|
||||
if (grub_file_seek (macho->file, macho->offset32) == (grub_off_t) -1)
|
||||
{
|
||||
grub_error_push ();
|
||||
return grub_error (GRUB_ERR_BAD_OS,
|
||||
"Invalid offset in program header.");
|
||||
}
|
||||
|
||||
read = grub_file_read (macho->file, dest,
|
||||
macho->end32 - macho->offset32);
|
||||
if (read != (grub_ssize_t) (macho->end32 - macho->offset32))
|
||||
{
|
||||
grub_error_push ();
|
||||
return grub_error (GRUB_ERR_BAD_OS,
|
||||
"Couldn't read architecture-specific part");
|
||||
}
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/* Calculate the amount of memory spanned by the segments. */
|
||||
grub_err_t
|
||||
grub_macho32_size (grub_macho_t macho, grub_addr_t *segments_start,
|
||||
grub_addr_t *segments_end, int flags)
|
||||
{
|
||||
int nr_phdrs = 0;
|
||||
|
||||
/* Run through the program headers to calculate the total memory size we
|
||||
should claim. */
|
||||
auto int NESTED_FUNC_ATTR calcsize (grub_macho_t _macho,
|
||||
struct grub_macho_cmd *phdr, void *_arg);
|
||||
int NESTED_FUNC_ATTR calcsize (grub_macho_t UNUSED _macho,
|
||||
struct grub_macho_cmd *hdr0, void UNUSED *_arg)
|
||||
{
|
||||
struct grub_macho_segment32 *hdr = (struct grub_macho_segment32 *) hdr0;
|
||||
if (hdr->cmd != GRUB_MACHO_CMD_SEGMENT32)
|
||||
return 0;
|
||||
if (! hdr->filesize && (flags & GRUB_MACHO_NOBSS))
|
||||
return 0;
|
||||
|
||||
nr_phdrs++;
|
||||
if (hdr->vmaddr < *segments_start)
|
||||
*segments_start = hdr->vmaddr;
|
||||
if (hdr->vmaddr + hdr->vmsize > *segments_end)
|
||||
*segments_end = hdr->vmaddr + hdr->vmsize;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*segments_start = (grub_uint32_t) -1;
|
||||
*segments_end = 0;
|
||||
|
||||
grub_macho32_cmds_iterate (macho, calcsize, 0);
|
||||
|
||||
if (nr_phdrs == 0)
|
||||
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_ERR_NONE;
|
||||
}
|
||||
|
||||
/* Load every loadable segment into memory specified by `_load_hook'. */
|
||||
grub_err_t
|
||||
grub_macho32_load (grub_macho_t macho, char *offset, int flags)
|
||||
{
|
||||
grub_err_t err = 0;
|
||||
auto int NESTED_FUNC_ATTR do_load(grub_macho_t _macho,
|
||||
struct grub_macho_cmd *hdr0,
|
||||
void UNUSED *_arg);
|
||||
int NESTED_FUNC_ATTR do_load(grub_macho_t _macho,
|
||||
struct grub_macho_cmd *hdr0,
|
||||
void UNUSED *_arg)
|
||||
{
|
||||
struct grub_macho_segment32 *hdr = (struct grub_macho_segment32 *) hdr0;
|
||||
|
||||
if (hdr->cmd != GRUB_MACHO_CMD_SEGMENT32)
|
||||
return 0;
|
||||
|
||||
if (! hdr->filesize && (flags & GRUB_MACHO_NOBSS))
|
||||
return 0;
|
||||
if (! hdr->vmsize)
|
||||
return 0;
|
||||
|
||||
if (grub_file_seek (_macho->file, hdr->fileoff
|
||||
+ _macho->offset32) == (grub_off_t) -1)
|
||||
{
|
||||
grub_error_push ();
|
||||
grub_error (GRUB_ERR_BAD_OS,
|
||||
"Invalid offset in program header.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (hdr->filesize)
|
||||
{
|
||||
grub_ssize_t read;
|
||||
read = grub_file_read (_macho->file, offset + hdr->vmaddr,
|
||||
min (hdr->filesize, hdr->vmsize));
|
||||
if (read != (grub_ssize_t) min (hdr->filesize, hdr->vmsize))
|
||||
{
|
||||
/* 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.",
|
||||
hdr->filesize, read);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (hdr->filesize < hdr->vmsize)
|
||||
grub_memset (offset + hdr->vmaddr + hdr->filesize,
|
||||
0, hdr->vmsize - hdr->filesize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_macho32_cmds_iterate (macho, do_load, 0);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
grub_uint32_t
|
||||
grub_macho32_get_entry_point (grub_macho_t macho)
|
||||
{
|
||||
grub_uint32_t entry_point = 0;
|
||||
auto int NESTED_FUNC_ATTR hook(grub_macho_t _macho,
|
||||
struct grub_macho_cmd *hdr,
|
||||
void UNUSED *_arg);
|
||||
int NESTED_FUNC_ATTR hook(grub_macho_t UNUSED _macho,
|
||||
struct grub_macho_cmd *hdr,
|
||||
void UNUSED *_arg)
|
||||
{
|
||||
if (hdr->cmd == GRUB_MACHO_CMD_THREAD)
|
||||
entry_point = ((struct grub_macho_thread32 *) hdr)->entry_point;
|
||||
return 0;
|
||||
}
|
||||
grub_macho32_cmds_iterate (macho, hook, 0);
|
||||
return entry_point;
|
||||
}
|
||||
|
||||
|
||||
grub_err_t
|
||||
grub_macho_close (grub_macho_t macho)
|
||||
{
|
||||
|
@ -367,8 +134,7 @@ grub_macho_file (grub_file_t file)
|
|||
}
|
||||
|
||||
grub_macho_parse32 (macho);
|
||||
/* FIXME: implement 64-bit.*/
|
||||
/* grub_macho_parse64 (macho); */
|
||||
grub_macho_parse64 (macho);
|
||||
|
||||
return macho;
|
||||
|
||||
|
|
18
loader/macho32.c
Normal file
18
loader/macho32.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <grub/cpu/macho.h>
|
||||
#include <grub/machoload.h>
|
||||
|
||||
#define SUFFIX(x) x ## 32
|
||||
typedef struct grub_macho_header32 grub_macho_header_t;
|
||||
typedef struct grub_macho_segment32 grub_macho_segment_t;
|
||||
typedef grub_uint32_t grub_macho_addr_t;
|
||||
typedef struct grub_macho_thread32 grub_macho_thread_t;
|
||||
#define offsetXX offset32
|
||||
#define ncmdsXX ncmds32
|
||||
#define cmdsizeXX cmdsize32
|
||||
#define cmdsXX cmds32
|
||||
#define endXX end32
|
||||
#define XX "32"
|
||||
#define GRUB_MACHO_MAGIC GRUB_MACHO_MAGIC32
|
||||
#define GRUB_MACHO_CMD_SEGMENT GRUB_MACHO_CMD_SEGMENT32
|
||||
#include "machoXX.c"
|
||||
|
18
loader/macho64.c
Normal file
18
loader/macho64.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <grub/cpu/macho.h>
|
||||
#include <grub/machoload.h>
|
||||
|
||||
#define SUFFIX(x) x ## 64
|
||||
typedef struct grub_macho_header64 grub_macho_header_t;
|
||||
typedef struct grub_macho_segment64 grub_macho_segment_t;
|
||||
typedef grub_uint64_t grub_macho_addr_t;
|
||||
typedef struct grub_macho_thread64 grub_macho_thread_t;
|
||||
#define offsetXX offset64
|
||||
#define ncmdsXX ncmds64
|
||||
#define cmdsizeXX cmdsize64
|
||||
#define cmdsXX cmds64
|
||||
#define endXX end64
|
||||
#define XX "64"
|
||||
#define GRUB_MACHO_MAGIC GRUB_MACHO_MAGIC64
|
||||
#define GRUB_MACHO_CMD_SEGMENT GRUB_MACHO_CMD_SEGMENT64
|
||||
#include "machoXX.c"
|
||||
|
238
loader/machoXX.c
Normal file
238
loader/machoXX.c
Normal file
|
@ -0,0 +1,238 @@
|
|||
|
||||
#include <grub/file.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
|
||||
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
int
|
||||
SUFFIX (grub_macho_contains_macho) (grub_macho_t macho)
|
||||
{
|
||||
return macho->offsetXX != -1;
|
||||
}
|
||||
|
||||
void
|
||||
SUFFIX (grub_macho_parse) (grub_macho_t macho)
|
||||
{
|
||||
grub_macho_header_t head;
|
||||
|
||||
/* Is there any candidate at all? */
|
||||
if (macho->offsetXX == -1)
|
||||
return;
|
||||
|
||||
/* Read header and check magic*/
|
||||
if (grub_file_seek (macho->file, macho->offsetXX) == (grub_off_t) -1
|
||||
|| grub_file_read (macho->file, &head, sizeof (head))
|
||||
!= sizeof(head))
|
||||
{
|
||||
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.");
|
||||
macho->offsetXX = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Read commands. */
|
||||
macho->ncmdsXX = head.ncmds;
|
||||
macho->cmdsizeXX = head.sizeofcmds;
|
||||
macho->cmdsXX = grub_malloc(macho->cmdsizeXX);
|
||||
if (! macho->cmdsXX)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "not enough memory to read commands");
|
||||
return;
|
||||
}
|
||||
if (grub_file_read (macho->file, macho->cmdsXX,
|
||||
(grub_size_t) macho->cmdsizeXX)
|
||||
!= (grub_ssize_t) macho->cmdsizeXX)
|
||||
{
|
||||
grub_error (GRUB_ERR_READ_ERROR, "Cannot read Mach-O header.");
|
||||
macho->offsetXX = -1;
|
||||
}
|
||||
}
|
||||
|
||||
typedef int NESTED_FUNC_ATTR (*grub_macho_iter_hook_t)
|
||||
(grub_macho_t , struct grub_macho_cmd *,
|
||||
void *);
|
||||
|
||||
static grub_err_t
|
||||
grub_macho_cmds_iterate (grub_macho_t macho,
|
||||
grub_macho_iter_hook_t hook,
|
||||
void *hook_arg)
|
||||
{
|
||||
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");
|
||||
for (i = 0; i < macho->ncmdsXX; i++)
|
||||
{
|
||||
struct grub_macho_cmd *hdr = (struct grub_macho_cmd *) hdrs;
|
||||
if (hook (macho, hdr, hook_arg))
|
||||
break;
|
||||
hdrs += hdr->cmdsize;
|
||||
}
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
grub_size_t
|
||||
SUFFIX (grub_macho_filesize) (grub_macho_t macho)
|
||||
{
|
||||
if (SUFFIX (grub_macho_contains_macho) (macho))
|
||||
return macho->endXX - macho->offsetXX;
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
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");
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
read = grub_file_read (macho->file, dest,
|
||||
macho->endXX - macho->offsetXX);
|
||||
if (read != (grub_ssize_t) (macho->endXX - macho->offsetXX))
|
||||
{
|
||||
grub_error_push ();
|
||||
return grub_error (GRUB_ERR_BAD_OS,
|
||||
"Couldn't read architecture-specific part");
|
||||
}
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/* Calculate the amount of memory spanned by the segments. */
|
||||
grub_err_t
|
||||
SUFFIX (grub_macho_size) (grub_macho_t macho, grub_macho_addr_t *segments_start,
|
||||
grub_macho_addr_t *segments_end, int flags)
|
||||
{
|
||||
int nr_phdrs = 0;
|
||||
|
||||
/* Run through the program headers to calculate the total memory size we
|
||||
should claim. */
|
||||
auto int NESTED_FUNC_ATTR calcsize (grub_macho_t _macho,
|
||||
struct grub_macho_cmd *phdr, void *_arg);
|
||||
int NESTED_FUNC_ATTR calcsize (grub_macho_t UNUSED _macho,
|
||||
struct grub_macho_cmd *hdr0, void UNUSED *_arg)
|
||||
{
|
||||
grub_macho_segment_t *hdr = (grub_macho_segment_t *) hdr0;
|
||||
if (hdr->cmd != GRUB_MACHO_CMD_SEGMENT)
|
||||
return 0;
|
||||
|
||||
if (! hdr->vmsize)
|
||||
return 0;
|
||||
|
||||
if (! hdr->filesize && (flags & GRUB_MACHO_NOBSS))
|
||||
return 0;
|
||||
|
||||
nr_phdrs++;
|
||||
if (hdr->vmaddr < *segments_start)
|
||||
*segments_start = hdr->vmaddr;
|
||||
if (hdr->vmaddr + hdr->vmsize > *segments_end)
|
||||
*segments_end = hdr->vmaddr + hdr->vmsize;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*segments_start = (grub_macho_addr_t) -1;
|
||||
*segments_end = 0;
|
||||
|
||||
grub_macho_cmds_iterate (macho, calcsize, 0);
|
||||
|
||||
if (nr_phdrs == 0)
|
||||
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_ERR_NONE;
|
||||
}
|
||||
|
||||
/* Load every loadable segment into memory specified by `_load_hook'. */
|
||||
grub_err_t
|
||||
SUFFIX (grub_macho_load) (grub_macho_t macho, char *offset, int flags)
|
||||
{
|
||||
grub_err_t err = 0;
|
||||
auto int NESTED_FUNC_ATTR do_load(grub_macho_t _macho,
|
||||
struct grub_macho_cmd *hdr0,
|
||||
void UNUSED *_arg);
|
||||
int NESTED_FUNC_ATTR do_load(grub_macho_t _macho,
|
||||
struct grub_macho_cmd *hdr0,
|
||||
void UNUSED *_arg)
|
||||
{
|
||||
grub_macho_segment_t *hdr = (grub_macho_segment_t *) hdr0;
|
||||
|
||||
if (hdr->cmd != GRUB_MACHO_CMD_SEGMENT)
|
||||
return 0;
|
||||
|
||||
if (! hdr->filesize && (flags & GRUB_MACHO_NOBSS))
|
||||
return 0;
|
||||
if (! hdr->vmsize)
|
||||
return 0;
|
||||
|
||||
if (grub_file_seek (_macho->file, hdr->fileoff
|
||||
+ _macho->offsetXX) == (grub_off_t) -1)
|
||||
{
|
||||
grub_error_push ();
|
||||
grub_error (GRUB_ERR_BAD_OS,
|
||||
"Invalid offset in program header.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (hdr->filesize)
|
||||
{
|
||||
grub_ssize_t read;
|
||||
read = grub_file_read (_macho->file, offset + hdr->vmaddr,
|
||||
min (hdr->filesize, hdr->vmsize));
|
||||
if (read != (grub_ssize_t) min (hdr->filesize, hdr->vmsize))
|
||||
{
|
||||
/* 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.",
|
||||
hdr->filesize, read);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (hdr->filesize < hdr->vmsize)
|
||||
grub_memset (offset + hdr->vmaddr + hdr->filesize,
|
||||
0, hdr->vmsize - hdr->filesize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_macho_cmds_iterate (macho, do_load, 0);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
grub_macho_addr_t
|
||||
SUFFIX (grub_macho_get_entry_point) (grub_macho_t macho)
|
||||
{
|
||||
grub_macho_addr_t entry_point = 0;
|
||||
auto int NESTED_FUNC_ATTR hook(grub_macho_t _macho,
|
||||
struct grub_macho_cmd *hdr,
|
||||
void UNUSED *_arg);
|
||||
int NESTED_FUNC_ATTR hook(grub_macho_t UNUSED _macho,
|
||||
struct grub_macho_cmd *hdr,
|
||||
void UNUSED *_arg)
|
||||
{
|
||||
if (hdr->cmd == GRUB_MACHO_CMD_THREAD)
|
||||
entry_point = ((grub_macho_thread_t *) hdr)->entry_point;
|
||||
return 0;
|
||||
}
|
||||
grub_macho_cmds_iterate (macho, hook, 0);
|
||||
return entry_point;
|
||||
}
|
474
loader/xnu.c
474
loader/xnu.c
|
@ -31,10 +31,12 @@
|
|||
#include <grub/gzio.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/env.h>
|
||||
|
||||
struct grub_xnu_devtree_key *grub_xnu_devtree_root = 0;
|
||||
static int driverspackagenum = 0;
|
||||
static int driversnum = 0;
|
||||
int grub_xnu_is_64bit = 0;
|
||||
|
||||
void *grub_xnu_heap_start = 0;
|
||||
grub_size_t grub_xnu_heap_size = 0;
|
||||
|
@ -326,6 +328,8 @@ grub_xnu_create_value (struct grub_xnu_devtree_key **parent, char *name)
|
|||
static grub_err_t
|
||||
grub_xnu_unload (void)
|
||||
{
|
||||
grub_cpu_xnu_unload ();
|
||||
|
||||
grub_xnu_free_devtree (grub_xnu_devtree_root);
|
||||
grub_xnu_devtree_root = 0;
|
||||
|
||||
|
@ -345,7 +349,7 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
|
|||
{
|
||||
grub_err_t err;
|
||||
grub_macho_t macho;
|
||||
grub_addr_t startcode, endcode;
|
||||
grub_uint32_t startcode, endcode;
|
||||
int i;
|
||||
char *ptr, *loadaddr;
|
||||
|
||||
|
@ -361,10 +365,10 @@ 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 architecture");
|
||||
"Kernel doesn't contain suitable 32-bit architecture");
|
||||
}
|
||||
|
||||
err = grub_macho32_size (macho, &startcode, &endcode, GRUB_MACHO_NOBSS);
|
||||
err = grub_macho_size32 (macho, &startcode, &endcode, GRUB_MACHO_NOBSS);
|
||||
if (err)
|
||||
{
|
||||
grub_macho_close (macho);
|
||||
|
@ -387,7 +391,7 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
|
|||
}
|
||||
|
||||
/* Load kernel. */
|
||||
err = grub_macho32_load (macho, loadaddr - startcode, GRUB_MACHO_NOBSS);
|
||||
err = grub_macho_load32 (macho, loadaddr - startcode, GRUB_MACHO_NOBSS);
|
||||
if (err)
|
||||
{
|
||||
grub_macho_close (macho);
|
||||
|
@ -395,7 +399,7 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
|
|||
return err;
|
||||
}
|
||||
|
||||
grub_xnu_entry_point = grub_macho32_get_entry_point (macho);
|
||||
grub_xnu_entry_point = grub_macho_get_entry_point32 (macho);
|
||||
if (! grub_xnu_entry_point)
|
||||
{
|
||||
grub_macho_close (macho);
|
||||
|
@ -429,13 +433,112 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
|
|||
if (ptr != grub_xnu_cmdline)
|
||||
*(ptr - 1) = 0;
|
||||
|
||||
err = grub_cpu_xnu_fill_devicetree ();
|
||||
grub_loader_set (grub_xnu_boot, grub_xnu_unload, 0);
|
||||
|
||||
grub_xnu_lock ();
|
||||
grub_xnu_is_64bit = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char *args[])
|
||||
{
|
||||
grub_err_t err;
|
||||
grub_macho_t macho;
|
||||
grub_uint64_t startcode, endcode;
|
||||
int i;
|
||||
char *ptr, *loadaddr;
|
||||
|
||||
if (argc < 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
|
||||
|
||||
grub_xnu_unload ();
|
||||
|
||||
macho = grub_macho_open (args[0]);
|
||||
if (! macho)
|
||||
return grub_errno;
|
||||
if (! grub_macho_contains_macho64 (macho))
|
||||
{
|
||||
grub_macho_close (macho);
|
||||
return grub_error (GRUB_ERR_BAD_OS,
|
||||
"Kernel doesn't contain suitable 64-bit architecture");
|
||||
}
|
||||
|
||||
err = grub_macho_size64 (macho, &startcode, &endcode, GRUB_MACHO_NOBSS);
|
||||
if (err)
|
||||
{
|
||||
grub_macho_close (macho);
|
||||
grub_xnu_unload ();
|
||||
return err;
|
||||
}
|
||||
|
||||
startcode &= 0x0fffffff;
|
||||
endcode &= 0x0fffffff;
|
||||
|
||||
grub_dprintf ("xnu", "endcode = %lx, startcode = %lx\n",
|
||||
(unsigned long) endcode, (unsigned long) startcode);
|
||||
|
||||
loadaddr = grub_xnu_heap_malloc (endcode - startcode);
|
||||
grub_xnu_heap_will_be_at = startcode;
|
||||
|
||||
if (! loadaddr)
|
||||
{
|
||||
grub_macho_close (macho);
|
||||
grub_xnu_unload ();
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
|
||||
"not enough memory to load kernel");
|
||||
}
|
||||
|
||||
/* Load kernel. */
|
||||
err = grub_macho_load64 (macho, loadaddr - startcode, GRUB_MACHO_NOBSS);
|
||||
if (err)
|
||||
{
|
||||
grub_macho_close (macho);
|
||||
grub_xnu_unload ();
|
||||
return err;
|
||||
}
|
||||
|
||||
grub_xnu_entry_point = grub_macho_get_entry_point64 (macho) & 0x0fffffff;
|
||||
if (! grub_xnu_entry_point)
|
||||
{
|
||||
grub_macho_close (macho);
|
||||
grub_xnu_unload ();
|
||||
return grub_error (GRUB_ERR_BAD_OS, "couldn't find entry point");
|
||||
}
|
||||
|
||||
grub_macho_close (macho);
|
||||
|
||||
err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE);
|
||||
if (err)
|
||||
{
|
||||
grub_xnu_unload ();
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Copy parameters to kernel command line. */
|
||||
ptr = grub_xnu_cmdline;
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if (ptr + grub_strlen (args[i]) + 1
|
||||
>= grub_xnu_cmdline + sizeof (grub_xnu_cmdline))
|
||||
break;
|
||||
grub_memcpy (ptr, args[i], grub_strlen (args[i]));
|
||||
ptr += grub_strlen (args[i]);
|
||||
*ptr = ' ';
|
||||
ptr++;
|
||||
}
|
||||
|
||||
/* Replace last space by '\0'. */
|
||||
if (ptr != grub_xnu_cmdline)
|
||||
*(ptr - 1) = 0;
|
||||
|
||||
grub_loader_set (grub_xnu_boot, grub_xnu_unload, 0);
|
||||
|
||||
grub_xnu_lock ();
|
||||
grub_xnu_is_64bit = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -487,6 +590,34 @@ grub_xnu_register_memory (char *prefix, int *suffix,
|
|||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static inline char *
|
||||
get_name_ptr (char *name)
|
||||
{
|
||||
char *p = name, *p2;
|
||||
/* Skip Info.plist. */
|
||||
p2 = grub_strrchr (p, '/');
|
||||
if (!p2)
|
||||
return name;
|
||||
if (p2 == name)
|
||||
return name + 1;
|
||||
p = p2 - 1;
|
||||
|
||||
p2 = grub_strrchr (p, '/');
|
||||
if (!p2)
|
||||
return name;
|
||||
if (p2 == name)
|
||||
return name + 1;
|
||||
if (grub_memcmp (p2, "/Contents/", sizeof ("/Contents/") - 1) != 0)
|
||||
return p2 + 1;
|
||||
|
||||
p = p2 - 1;
|
||||
|
||||
p2 = grub_strrchr (p, '/');
|
||||
if (!p2)
|
||||
return name;
|
||||
return p2 + 1;
|
||||
}
|
||||
|
||||
/* Load .kext. */
|
||||
static grub_err_t
|
||||
grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
|
||||
|
@ -498,6 +629,18 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
|
|||
int neededspace = sizeof (*exthead);
|
||||
grub_uint8_t *buf;
|
||||
grub_size_t infoplistsize = 0, machosize = 0;
|
||||
char *name, *nameend;
|
||||
int namelen;
|
||||
|
||||
name = get_name_ptr (infoplistname);
|
||||
nameend = grub_strchr (name, '/');
|
||||
|
||||
if (nameend)
|
||||
namelen = nameend - name;
|
||||
else
|
||||
namelen = grub_strlen (name);
|
||||
|
||||
neededspace += namelen + 1;
|
||||
|
||||
if (! grub_xnu_heap_size)
|
||||
return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded");
|
||||
|
@ -513,7 +656,10 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
|
|||
return grub_error (GRUB_ERR_BAD_OS,
|
||||
"Extension doesn't contain suitable architecture");
|
||||
}
|
||||
machosize = grub_macho32_filesize (macho);
|
||||
if (grub_xnu_is_64bit)
|
||||
machosize = grub_macho_filesize64 (macho);
|
||||
else
|
||||
machosize = grub_macho_filesize32 (macho);
|
||||
neededspace += machosize;
|
||||
}
|
||||
else
|
||||
|
@ -548,7 +694,11 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
|
|||
exthead->binaryaddr = (buf - (grub_uint8_t *) grub_xnu_heap_start)
|
||||
+ grub_xnu_heap_will_be_at;
|
||||
exthead->binarysize = machosize;
|
||||
if ((err = grub_macho32_readfile (macho, buf)))
|
||||
if (grub_xnu_is_64bit)
|
||||
err = grub_macho_readfile64 (macho, buf);
|
||||
else
|
||||
err = grub_macho_readfile32 (macho, buf);
|
||||
if (err)
|
||||
{
|
||||
grub_macho_close (macho);
|
||||
return err;
|
||||
|
@ -574,9 +724,17 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
|
|||
}
|
||||
grub_file_close (infoplist);
|
||||
buf[infoplistsize] = 0;
|
||||
buf += infoplistsize + 1;
|
||||
}
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
exthead->nameaddr = (buf - (grub_uint8_t *) grub_xnu_heap_start)
|
||||
+ grub_xnu_heap_will_be_at;
|
||||
exthead->namesize = namelen + 1;
|
||||
grub_memcpy (buf, name, namelen);
|
||||
buf[namelen] = 0;
|
||||
buf += namelen + 1;
|
||||
|
||||
/* Announce to kernel */
|
||||
return grub_xnu_register_memory ("Driver-", &driversnum, exthead,
|
||||
neededspace);
|
||||
|
@ -641,7 +799,13 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
|
|||
}
|
||||
for (i = 0; i < narchs; i++)
|
||||
{
|
||||
if (GRUB_MACHO_CPUTYPE_IS_HOST32
|
||||
if (!grub_xnu_is_64bit && GRUB_MACHO_CPUTYPE_IS_HOST32
|
||||
(grub_be_to_cpu32 (archs[i].cputype)))
|
||||
{
|
||||
readoff = grub_be_to_cpu32 (archs[i].offset);
|
||||
readlen = grub_be_to_cpu32 (archs[i].size);
|
||||
}
|
||||
if (grub_xnu_is_64bit && GRUB_MACHO_CPUTYPE_IS_HOST64
|
||||
(grub_be_to_cpu32 (archs[i].cputype)))
|
||||
{
|
||||
readoff = grub_be_to_cpu32 (archs[i].offset);
|
||||
|
@ -732,135 +896,6 @@ grub_cmd_xnu_ramdisk (grub_command_t cmd __attribute__ ((unused)),
|
|||
return grub_xnu_register_memory ("RAMDisk", 0, loadto, size);
|
||||
}
|
||||
|
||||
/* Parse a devtree file. It uses the following format:
|
||||
valuename:valuedata;
|
||||
keyname{
|
||||
contents
|
||||
}
|
||||
keyname, valuename and valuedata are in hex.
|
||||
*/
|
||||
static char *
|
||||
grub_xnu_parse_devtree (struct grub_xnu_devtree_key **parent,
|
||||
char *start, char *end)
|
||||
{
|
||||
char *ptr, *ptr2;
|
||||
char *name, *data;
|
||||
int namelen, datalen, i;
|
||||
for (ptr = start; ptr && ptr < end; )
|
||||
{
|
||||
if (grub_isspace (*ptr))
|
||||
{
|
||||
ptr++;
|
||||
continue;
|
||||
}
|
||||
if (*ptr == '}')
|
||||
return ptr + 1;
|
||||
namelen = 0;
|
||||
|
||||
/* Parse the name. */
|
||||
for (ptr2 = ptr; ptr2 < end && (grub_isspace (*ptr2)
|
||||
|| (*ptr2 >= '0' && *ptr2 <= '9')
|
||||
|| (*ptr2 >= 'a' && *ptr2 <= 'f')
|
||||
|| (*ptr2 >= 'A' && *ptr2 <= 'F'));
|
||||
ptr2++)
|
||||
if (! grub_isspace (*ptr2))
|
||||
namelen++;
|
||||
if (ptr2 == end)
|
||||
return 0;
|
||||
namelen /= 2;
|
||||
name = grub_malloc (namelen + 1);
|
||||
if (!name)
|
||||
return 0;
|
||||
for (i = 0; i < 2 * namelen; i++)
|
||||
{
|
||||
int hex = 0;
|
||||
while (grub_isspace (*ptr))
|
||||
ptr++;
|
||||
if (*ptr >= '0' && *ptr <= '9')
|
||||
hex = *ptr - '0';
|
||||
if (*ptr >= 'a' && *ptr <= 'f')
|
||||
hex = *ptr - 'a' + 10;
|
||||
if (*ptr >= 'A' && *ptr <= 'F')
|
||||
hex = *ptr - 'A' + 10;
|
||||
|
||||
if (i % 2 == 0)
|
||||
name[i / 2] = hex << 4;
|
||||
else
|
||||
name[i / 2] |= hex;
|
||||
ptr++;
|
||||
}
|
||||
name [namelen] = 0;
|
||||
while (grub_isspace (*ptr))
|
||||
ptr++;
|
||||
|
||||
/* If it describes a key recursively invoke the function. */
|
||||
if (*ptr == '{')
|
||||
{
|
||||
struct grub_xnu_devtree_key *newkey
|
||||
= grub_xnu_create_key (parent, name);
|
||||
grub_free (name);
|
||||
if (! newkey)
|
||||
return 0;
|
||||
ptr = grub_xnu_parse_devtree (&(newkey->first_child), ptr + 1, end);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Parse the data. */
|
||||
if (*ptr != ':')
|
||||
return 0;
|
||||
ptr++;
|
||||
datalen = 0;
|
||||
for (ptr2 = ptr; ptr2 < end && (grub_isspace (*ptr2)
|
||||
|| (*ptr2 >= '0' && *ptr2 <= '9')
|
||||
|| (*ptr2 >= 'a' && *ptr2 <= 'f')
|
||||
|| (*ptr2 >= 'A' && *ptr2 <= 'F'));
|
||||
ptr2++)
|
||||
if (! grub_isspace (*ptr2))
|
||||
datalen++;
|
||||
if (ptr2 == end)
|
||||
return 0;
|
||||
datalen /= 2;
|
||||
data = grub_malloc (datalen);
|
||||
if (! data)
|
||||
return 0;
|
||||
for (i = 0; i < 2 * datalen; i++)
|
||||
{
|
||||
int hex = 0;
|
||||
while (grub_isspace (*ptr))
|
||||
ptr++;
|
||||
if (*ptr >= '0' && *ptr <= '9')
|
||||
hex = *ptr - '0';
|
||||
if (*ptr >= 'a' && *ptr <= 'f')
|
||||
hex = *ptr - 'a' + 10;
|
||||
if (*ptr >= 'A' && *ptr <= 'F')
|
||||
hex = *ptr - 'A' + 10;
|
||||
|
||||
if (i % 2 == 0)
|
||||
data[i / 2] = hex << 4;
|
||||
else
|
||||
data[i / 2] |= hex;
|
||||
ptr++;
|
||||
}
|
||||
while (ptr < end && grub_isspace (*ptr))
|
||||
ptr++;
|
||||
{
|
||||
struct grub_xnu_devtree_key *newkey
|
||||
= grub_xnu_create_value (parent, name);
|
||||
grub_free (name);
|
||||
if (! newkey)
|
||||
return 0;
|
||||
newkey->datasize = datalen;
|
||||
newkey->data = data;
|
||||
}
|
||||
if (*ptr != ';')
|
||||
return 0;
|
||||
ptr++;
|
||||
}
|
||||
if (ptr >= end && *parent != grub_xnu_devtree_root)
|
||||
return 0;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* Returns true if the kext should be loaded according to plist
|
||||
and osbundlereq. Also fill BINNAME. */
|
||||
static int
|
||||
|
@ -1157,53 +1192,6 @@ grub_xnu_load_kext_from_dir (char *dirname, char *osbundlerequired,
|
|||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/* Load devtree file. */
|
||||
static grub_err_t
|
||||
grub_cmd_xnu_devtree (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char *args[])
|
||||
{
|
||||
grub_file_t file;
|
||||
char *data, *endret;
|
||||
grub_size_t datalen;
|
||||
|
||||
if (argc != 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Filename required");
|
||||
|
||||
if (! grub_xnu_heap_size)
|
||||
return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded");
|
||||
|
||||
/* Load the file. */
|
||||
file = grub_gzfile_open (args[0], 1);
|
||||
if (! file)
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load device tree");
|
||||
datalen = grub_file_size (file);
|
||||
data = grub_malloc (datalen + 1);
|
||||
if (! data)
|
||||
{
|
||||
grub_file_close (file);
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
|
||||
"Could load device tree into memory");
|
||||
}
|
||||
if (grub_file_read (file, data, datalen) != (grub_ssize_t) datalen)
|
||||
{
|
||||
grub_file_close (file);
|
||||
grub_free (data);
|
||||
grub_error_push ();
|
||||
return grub_error (GRUB_ERR_BAD_OS, "Couldn't read file %s", args[0]);
|
||||
}
|
||||
grub_file_close (file);
|
||||
data[datalen] = 0;
|
||||
|
||||
/* Parse the file. */
|
||||
endret = grub_xnu_parse_devtree (&grub_xnu_devtree_root,
|
||||
data, data + datalen);
|
||||
grub_free (data);
|
||||
|
||||
if (! endret)
|
||||
return grub_error (GRUB_ERR_BAD_OS, "Couldn't parse devtree");
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static int locked=0;
|
||||
static grub_dl_t my_mod;
|
||||
|
@ -1264,6 +1252,107 @@ grub_cmd_xnu_kextdir (grub_command_t cmd __attribute__ ((unused)),
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static inline void
|
||||
unescape (char *name, char *curdot, char *nextdot, int *len)
|
||||
{
|
||||
char *ptr, *dptr;
|
||||
dptr = name;
|
||||
for (ptr = curdot; ptr < nextdot;)
|
||||
if (ptr + 2 < nextdot && *ptr == '%')
|
||||
{
|
||||
*dptr = (hextoval (ptr[1]) << 4) | (hextoval (ptr[2]));
|
||||
ptr += 3;
|
||||
dptr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*dptr = *ptr;
|
||||
ptr++;
|
||||
dptr++;
|
||||
}
|
||||
*len = dptr - name;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_xnu_fill_devicetree (void)
|
||||
{
|
||||
auto int iterate_env (struct grub_env_var *var);
|
||||
int iterate_env (struct grub_env_var *var)
|
||||
{
|
||||
char *nextdot = 0, *curdot;
|
||||
struct grub_xnu_devtree_key **curkey = &grub_xnu_devtree_root;
|
||||
struct grub_xnu_devtree_key *curvalue;
|
||||
char *name = 0, *data;
|
||||
int len;
|
||||
|
||||
if (grub_memcmp (var->name, "XNU.DeviceTree.",
|
||||
sizeof ("XNU.DeviceTree.") - 1) != 0)
|
||||
return 0;
|
||||
|
||||
curdot = var->name + sizeof ("XNU.DeviceTree.") - 1;
|
||||
nextdot = grub_strchr (curdot, '.');
|
||||
if (nextdot)
|
||||
nextdot++;
|
||||
while (nextdot)
|
||||
{
|
||||
name = grub_realloc (name, nextdot - curdot + 1);
|
||||
|
||||
if (!name)
|
||||
return 1;
|
||||
|
||||
unescape (name, curdot, nextdot, &len);
|
||||
name[len - 1] = 0;
|
||||
|
||||
curkey = &(grub_xnu_create_key (curkey, name)->first_child);
|
||||
|
||||
curdot = nextdot;
|
||||
nextdot = grub_strchr (nextdot, '.');
|
||||
if (nextdot)
|
||||
nextdot++;
|
||||
}
|
||||
|
||||
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;
|
||||
curvalue->data = data;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_env_iterate (iterate_env);
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
struct grub_video_bitmap *grub_xnu_bitmap = 0;
|
||||
|
||||
static grub_err_t
|
||||
|
@ -1309,13 +1398,15 @@ grub_xnu_unlock ()
|
|||
locked = 0;
|
||||
}
|
||||
|
||||
static grub_command_t cmd_kernel, cmd_mkext, cmd_kext, cmd_kextdir,
|
||||
cmd_ramdisk, cmd_devtree, cmd_resume, cmd_splash;
|
||||
static grub_command_t cmd_kernel64, cmd_kernel, cmd_mkext, cmd_kext;
|
||||
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");
|
||||
cmd_kernel64 = grub_register_command ("xnu_kernel64", grub_cmd_xnu_kernel64,
|
||||
0, "load a 64-bit xnu kernel");
|
||||
cmd_mkext = grub_register_command ("xnu_mkext", grub_cmd_xnu_mkext, 0,
|
||||
"Load XNU extension package.");
|
||||
cmd_kext = grub_register_command ("xnu_kext", grub_cmd_xnu_kext, 0,
|
||||
|
@ -1326,8 +1417,6 @@ GRUB_MOD_INIT(xnu)
|
|||
cmd_ramdisk = grub_register_command ("xnu_ramdisk", grub_cmd_xnu_ramdisk, 0,
|
||||
"Load XNU ramdisk. "
|
||||
"It will be seen as md0");
|
||||
cmd_devtree = grub_register_command ("xnu_devtree", grub_cmd_xnu_devtree, 0,
|
||||
"Load XNU devtree");
|
||||
cmd_splash = grub_register_command ("xnu_splash", grub_cmd_xnu_splash, 0,
|
||||
"Load a splash image for XNU");
|
||||
|
||||
|
@ -1335,6 +1424,9 @@ GRUB_MOD_INIT(xnu)
|
|||
cmd_resume = grub_register_command ("xnu_resume", grub_cmd_xnu_resume,
|
||||
0, "Load XNU hibernate image.");
|
||||
#endif
|
||||
|
||||
grub_cpu_xnu_init ();
|
||||
|
||||
my_mod = mod;
|
||||
}
|
||||
|
||||
|
@ -1346,8 +1438,10 @@ GRUB_MOD_FINI(xnu)
|
|||
grub_unregister_command (cmd_mkext);
|
||||
grub_unregister_command (cmd_kext);
|
||||
grub_unregister_command (cmd_kextdir);
|
||||
grub_unregister_command (cmd_devtree);
|
||||
grub_unregister_command (cmd_ramdisk);
|
||||
grub_unregister_command (cmd_kernel);
|
||||
grub_unregister_command (cmd_kernel64);
|
||||
grub_unregister_command (cmd_splash);
|
||||
|
||||
grub_cpu_xnu_fini ();
|
||||
}
|
||||
|
|
|
@ -37,6 +37,56 @@ if [ -z "${OSPROBED}" ] ; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
function osx_entry {
|
||||
cat << EOF
|
||||
menuentry "${LONGNAME} (${2}-bit) (on ${DEVICE})" {
|
||||
EOF
|
||||
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
|
||||
cat << EOF
|
||||
insmod ${GRUB_VIDEO_BACKEND}
|
||||
do_resume=0
|
||||
if [ /var/vm/sleepimage -nt10 / ]; then
|
||||
if xnu_resume /var/vm/sleepimage; then
|
||||
do_resume=1
|
||||
fi
|
||||
fi
|
||||
if [ \$do_resume == 0 ]; then
|
||||
xnu_uuid ${OSXUUID} uuid
|
||||
if [ -f /Extra/DSDT.aml ]; then
|
||||
acpi -e /Extra/DSDT.aml
|
||||
fi
|
||||
$1 /mach_kernel boot-uuid=\${uuid} rd=*uuid
|
||||
if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
|
||||
xnu_mkext /System/Library/Extensions.mkext
|
||||
else
|
||||
xnu_kextdir /System/Library/Extensions
|
||||
fi
|
||||
if [ -f /Extra/Extensions.mkext ]; then
|
||||
xnu_mkext /Extra/Extensions.mkext
|
||||
fi
|
||||
if [ -d /Extra/Extensions ]; then
|
||||
xnu_kextdir /Extra/Extensions
|
||||
fi
|
||||
if [ -f /Extra/devprop.bin ]; then
|
||||
xnu_devprop_load /Extra/devprop.bin
|
||||
fi
|
||||
if [ -f /Extra/splash.jpg ]; then
|
||||
insmod jpeg
|
||||
xnu_splash /Extra/splash.jpg
|
||||
fi
|
||||
if [ -f /Extra/splash.png ]; then
|
||||
insmod png
|
||||
xnu_splash /Extra/splash.png
|
||||
fi
|
||||
if [ -f /Extra/splash.tga ]; then
|
||||
insmod tga
|
||||
xnu_splash /Extra/splash.tga
|
||||
fi
|
||||
fi
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
for OS in ${OSPROBED} ; do
|
||||
DEVICE="`echo ${OS} | cut -d ':' -f 1`"
|
||||
LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
|
||||
|
@ -115,53 +165,8 @@ EOF
|
|||
;;
|
||||
macosx)
|
||||
OSXUUID="`grub-probe --target=fs_uuid --device ${DEVICE} 2> /dev/null`"
|
||||
cat << EOF
|
||||
menuentry "${LONGNAME} (on ${DEVICE})" {
|
||||
EOF
|
||||
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
|
||||
cat << EOF
|
||||
insmod ${GRUB_VIDEO_BACKEND}
|
||||
do_resume=0
|
||||
if [ /var/vm/sleepimage -nt10 / ]; then
|
||||
if xnu_resume /var/vm/sleepimage; then
|
||||
do_resume=1
|
||||
fi
|
||||
fi
|
||||
if [ \$do_resume == 0 ]; then
|
||||
xnu_uuid ${OSXUUID} uuid
|
||||
if [ -f /Extra/DSDT.aml ]; then
|
||||
acpi -e /Extra/DSDT.aml
|
||||
fi
|
||||
xnu_kernel /mach_kernel boot-uuid=\${uuid} rd=*uuid
|
||||
if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
|
||||
xnu_mkext /System/Library/Extensions.mkext
|
||||
else
|
||||
xnu_kextdir /System/Library/Extensions
|
||||
fi
|
||||
if [ -f /Extra/Extensions.mkext ]; then
|
||||
xnu_mkext /Extra/Extensions.mkext
|
||||
fi
|
||||
if [ -d /Extra/Extensions ]; then
|
||||
xnu_kextdir /Extra/Extensions
|
||||
fi
|
||||
if [ -f /Extra/devtree.txt ]; then
|
||||
xnu_devtree /Extra/devtree.txt
|
||||
fi
|
||||
if [ -f /Extra/splash.jpg ]; then
|
||||
insmod jpeg
|
||||
xnu_splash /Extra/splash.jpg
|
||||
fi
|
||||
if [ -f /Extra/splash.png ]; then
|
||||
insmod png
|
||||
xnu_splash /Extra/splash.png
|
||||
fi
|
||||
if [ -f /Extra/splash.tga ]; then
|
||||
insmod tga
|
||||
xnu_splash /Extra/splash.tga
|
||||
fi
|
||||
fi
|
||||
}
|
||||
EOF
|
||||
osx_entry xnu_kernel 32
|
||||
osx_entry xnu_kernel64 64
|
||||
;;
|
||||
hurd)
|
||||
cat << EOF
|
||||
|
|
|
@ -15,11 +15,8 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
hexify()
|
||||
{
|
||||
echo -n "$@" | od -A n -t x1 - | sed -e 's/ //g' | tr '\n' '\0'
|
||||
}
|
||||
if [ x$1 == x ]; then
|
||||
echo "Filename required".
|
||||
fi
|
||||
|
||||
echo "`hexify efi`{ `hexify device-properties`:"
|
||||
ioreg -lw0 -p IODeviceTree -n efi -r -x |grep device-properties | sed 's/.*<//;s/>.*//;'
|
||||
echo ";}"
|
||||
ioreg -lw0 -p IODeviceTree -n efi -r -x |grep device-properties | sed 's/.*<//;s/>.*//;' | xxd -r -p > $1
|
||||
|
|
Loading…
Reference in a new issue