merge mainline into gfxmenu
This commit is contained in:
commit
9f293ab0df
198 changed files with 5911 additions and 2701 deletions
|
@ -140,7 +140,7 @@ grub_bsd_get_device (grub_uint32_t * biosdev,
|
|||
grub_uint32_t * slice, grub_uint32_t * part)
|
||||
{
|
||||
char *p;
|
||||
grub_device_t dev;
|
||||
grub_device_t dev;
|
||||
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
*biosdev = grub_get_root_biosnumber () & 0xff;
|
||||
|
|
|
@ -469,21 +469,22 @@ find_framebuf (grub_uint32_t *fb_base, grub_uint32_t *line_len)
|
|||
{
|
||||
int found = 0;
|
||||
|
||||
auto int NESTED_FUNC_ATTR find_card (int bus, int dev, int func,
|
||||
auto int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev,
|
||||
grub_pci_id_t pciid);
|
||||
|
||||
int NESTED_FUNC_ATTR find_card (int bus, int dev, int func,
|
||||
int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev,
|
||||
grub_pci_id_t pciid)
|
||||
{
|
||||
grub_pci_address_t addr;
|
||||
|
||||
addr = grub_pci_make_address (bus, dev, func, 2);
|
||||
addr = grub_pci_make_address (dev, 2);
|
||||
if (grub_pci_read (addr) >> 24 == 0x3)
|
||||
{
|
||||
int i;
|
||||
|
||||
grub_printf ("Display controller: %d:%d.%d\nDevice id: %x\n",
|
||||
bus, dev, func, pciid);
|
||||
grub_pci_get_bus (dev), grub_pci_get_device (dev),
|
||||
grub_pci_get_function (dev), pciid);
|
||||
addr += 8;
|
||||
for (i = 0; i < 6; i++, addr += 4)
|
||||
{
|
||||
|
|
|
@ -71,21 +71,22 @@ find_framebuf (grub_uint32_t *fb_base, grub_uint32_t *line_len)
|
|||
{
|
||||
int found = 0;
|
||||
|
||||
auto int NESTED_FUNC_ATTR find_card (int bus, int dev, int func,
|
||||
auto int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev,
|
||||
grub_pci_id_t pciid);
|
||||
|
||||
int NESTED_FUNC_ATTR find_card (int bus, int dev, int func,
|
||||
int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev,
|
||||
grub_pci_id_t pciid)
|
||||
{
|
||||
grub_pci_address_t addr;
|
||||
|
||||
addr = grub_pci_make_address (bus, dev, func, 2);
|
||||
addr = grub_pci_make_address (dev, 2);
|
||||
if (grub_pci_read (addr) >> 24 == 0x3)
|
||||
{
|
||||
int i;
|
||||
|
||||
grub_printf ("Display controller: %d:%d.%d\nDevice id: %x\n",
|
||||
bus, dev, func, pciid);
|
||||
grub_pci_get_bus (dev), grub_pci_get_device (dev),
|
||||
grub_pci_get_function (dev), pciid);
|
||||
addr += 8;
|
||||
for (i = 0; i < 6; i++, addr += 4)
|
||||
{
|
||||
|
|
|
@ -48,18 +48,36 @@
|
|||
#include <grub/device.h>
|
||||
#include <grub/partition.h>
|
||||
#endif
|
||||
#include <grub/i386/relocator.h>
|
||||
|
||||
extern grub_dl_t my_mod;
|
||||
static struct multiboot_info *mbi, *mbi_dest;
|
||||
static grub_addr_t entry;
|
||||
|
||||
static char *playground = 0;
|
||||
static grub_size_t code_size;
|
||||
|
||||
char *grub_multiboot_payload_orig;
|
||||
grub_addr_t grub_multiboot_payload_dest;
|
||||
grub_size_t grub_multiboot_payload_size;
|
||||
grub_uint32_t grub_multiboot_payload_eip;
|
||||
|
||||
static grub_err_t
|
||||
grub_multiboot_boot (void)
|
||||
{
|
||||
grub_multiboot_real_boot (entry, mbi_dest);
|
||||
struct grub_relocator32_state state =
|
||||
{
|
||||
.eax = MULTIBOOT_MAGIC2,
|
||||
.ebx = PTR_TO_UINT32 (mbi_dest),
|
||||
.ecx = 0,
|
||||
.edx = 0,
|
||||
.eip = grub_multiboot_payload_eip,
|
||||
/* Set esp to some random location in low memory to avoid breaking
|
||||
non-compliant kernels. */
|
||||
.esp = 0x7ff00
|
||||
};
|
||||
|
||||
grub_relocator32_boot (grub_multiboot_payload_orig,
|
||||
grub_multiboot_payload_dest,
|
||||
state);
|
||||
|
||||
/* Not reached. */
|
||||
return GRUB_ERR_NONE;
|
||||
|
@ -68,7 +86,7 @@ grub_multiboot_boot (void)
|
|||
static grub_err_t
|
||||
grub_multiboot_unload (void)
|
||||
{
|
||||
if (playground)
|
||||
if (mbi)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < mbi->mods_count; i++)
|
||||
|
@ -79,11 +97,11 @@ grub_multiboot_unload (void)
|
|||
((struct multiboot_mod_list *) mbi->mods_addr)[i].cmdline);
|
||||
}
|
||||
grub_free ((void *) mbi->mods_addr);
|
||||
grub_free (playground);
|
||||
}
|
||||
grub_relocator32_free (grub_multiboot_payload_orig);
|
||||
|
||||
mbi = NULL;
|
||||
playground = NULL;
|
||||
grub_multiboot_payload_orig = NULL;
|
||||
grub_dl_unref (my_mod);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
|
@ -183,7 +201,7 @@ grub_multiboot_get_bootdev (grub_uint32_t *bootdev)
|
|||
if (dev)
|
||||
grub_device_close (dev);
|
||||
|
||||
*bootdev = ((biosdev & 0xff) << 24) | ((slice & 0xff) << 16)
|
||||
*bootdev = ((biosdev & 0xff) << 24) | ((slice & 0xff) << 16)
|
||||
| ((part & 0xff) << 8) | 0xff;
|
||||
return (biosdev != ~0UL);
|
||||
#else
|
||||
|
@ -250,11 +268,8 @@ grub_multiboot (int argc, char *argv[])
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if (playground)
|
||||
{
|
||||
grub_free (playground);
|
||||
playground = NULL;
|
||||
}
|
||||
grub_relocator32_free (grub_multiboot_payload_orig);
|
||||
grub_multiboot_payload_orig = NULL;
|
||||
|
||||
mmap_length = grub_get_multiboot_mmap_len ();
|
||||
|
||||
|
@ -296,13 +311,14 @@ grub_multiboot (int argc, char *argv[])
|
|||
grub_multiboot_payload_dest = header->load_addr;
|
||||
|
||||
grub_multiboot_payload_size += code_size;
|
||||
playground = grub_malloc (RELOCATOR_SIZEOF(forward) + grub_multiboot_payload_size + RELOCATOR_SIZEOF(backward));
|
||||
if (! playground)
|
||||
|
||||
grub_multiboot_payload_orig
|
||||
= grub_relocator32_alloc (grub_multiboot_payload_size);
|
||||
|
||||
if (! grub_multiboot_payload_orig)
|
||||
goto fail;
|
||||
|
||||
grub_multiboot_payload_orig = (long) playground + RELOCATOR_SIZEOF(forward);
|
||||
|
||||
if ((grub_file_seek (file, offset)) == (grub_off_t) - 1)
|
||||
if ((grub_file_seek (file, offset)) == (grub_off_t) -1)
|
||||
goto fail;
|
||||
|
||||
grub_file_read (file, (void *) grub_multiboot_payload_orig, load_size);
|
||||
|
@ -313,7 +329,7 @@ grub_multiboot (int argc, char *argv[])
|
|||
grub_memset ((void *) (grub_multiboot_payload_orig + load_size), 0,
|
||||
header->bss_end_addr - header->load_addr - load_size);
|
||||
|
||||
grub_multiboot_payload_entry_offset = header->entry_addr - header->load_addr;
|
||||
grub_multiboot_payload_eip = header->entry_addr;
|
||||
|
||||
}
|
||||
else if (grub_multiboot_load_elf (file, buffer) != GRUB_ERR_NONE)
|
||||
|
@ -334,23 +350,6 @@ grub_multiboot (int argc, char *argv[])
|
|||
mbi->mmap_addr = (grub_uint32_t) mmap_addr (grub_multiboot_payload_dest);
|
||||
mbi->flags |= MULTIBOOT_INFO_MEM_MAP;
|
||||
|
||||
if (grub_multiboot_payload_dest >= grub_multiboot_payload_orig)
|
||||
{
|
||||
grub_memmove (playground, &grub_multiboot_forward_relocator, RELOCATOR_SIZEOF(forward));
|
||||
entry = (grub_addr_t) playground;
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_memmove ((char *) (grub_multiboot_payload_orig + grub_multiboot_payload_size),
|
||||
&grub_multiboot_backward_relocator, RELOCATOR_SIZEOF(backward));
|
||||
entry = (grub_addr_t) grub_multiboot_payload_orig + grub_multiboot_payload_size;
|
||||
}
|
||||
|
||||
grub_dprintf ("multiboot_loader", "dest=%p, size=0x%x, entry_offset=0x%x\n",
|
||||
(void *) grub_multiboot_payload_dest,
|
||||
grub_multiboot_payload_size,
|
||||
grub_multiboot_payload_entry_offset);
|
||||
|
||||
/* Convert from bytes to kilobytes. */
|
||||
mbi->mem_lower = grub_mmap_get_lower () / 1024;
|
||||
mbi->mem_upper = grub_mmap_get_upper () / 1024;
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#error "I'm confused"
|
||||
#endif
|
||||
|
||||
#include <grub/i386/relocator.h>
|
||||
|
||||
#define CONCAT(a,b) CONCAT_(a, b)
|
||||
#define CONCAT_(a,b) a ## b
|
||||
|
||||
|
@ -99,11 +101,12 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer)
|
|||
grub_multiboot_payload_dest = phdr(lowest_segment)->p_paddr;
|
||||
|
||||
grub_multiboot_payload_size += code_size;
|
||||
playground = grub_malloc (RELOCATOR_SIZEOF(forward) + grub_multiboot_payload_size + RELOCATOR_SIZEOF(backward));
|
||||
if (! playground)
|
||||
return grub_errno;
|
||||
|
||||
grub_multiboot_payload_orig = (long) playground + RELOCATOR_SIZEOF(forward);
|
||||
grub_multiboot_payload_orig
|
||||
= grub_relocator32_alloc (grub_multiboot_payload_size);
|
||||
|
||||
if (!grub_multiboot_payload_orig)
|
||||
return grub_errno;
|
||||
|
||||
/* Load every loadable segment in memory. */
|
||||
for (i = 0; i < ehdr->e_phnum; i++)
|
||||
|
@ -135,8 +138,8 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer)
|
|||
if (phdr(i)->p_vaddr <= ehdr->e_entry
|
||||
&& phdr(i)->p_vaddr + phdr(i)->p_memsz > ehdr->e_entry)
|
||||
{
|
||||
grub_multiboot_payload_entry_offset = (ehdr->e_entry - phdr(i)->p_vaddr)
|
||||
+ (phdr(i)->p_paddr - phdr(lowest_segment)->p_paddr);
|
||||
grub_multiboot_payload_eip = grub_multiboot_payload_dest
|
||||
+ (ehdr->e_entry - phdr(i)->p_vaddr) + (phdr(i)->p_paddr - phdr(lowest_segment)->p_paddr);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,81 +22,6 @@
|
|||
|
||||
.p2align 2 /* force 4-byte alignment */
|
||||
|
||||
/*
|
||||
* This starts the multiboot kernel.
|
||||
*/
|
||||
|
||||
VARIABLE(grub_multiboot_payload_size)
|
||||
.long 0
|
||||
VARIABLE(grub_multiboot_payload_orig)
|
||||
.long 0
|
||||
VARIABLE(grub_multiboot_payload_dest)
|
||||
.long 0
|
||||
VARIABLE(grub_multiboot_payload_entry_offset)
|
||||
.long 0
|
||||
|
||||
/*
|
||||
* The relocators below understand the following parameters:
|
||||
* ecx: Size of the block to be copied.
|
||||
* esi: Where to copy from (always lowest address, even if we're relocating
|
||||
* backwards).
|
||||
* edi: Where to copy to (likewise).
|
||||
* edx: Offset of the entry point (relative to the beginning of the block).
|
||||
*/
|
||||
|
||||
VARIABLE(grub_multiboot_forward_relocator)
|
||||
/* Add entry offset. */
|
||||
addl %edi, %edx
|
||||
|
||||
/* Forward copy. */
|
||||
cld
|
||||
rep
|
||||
movsb
|
||||
|
||||
jmp *%edx
|
||||
VARIABLE(grub_multiboot_forward_relocator_end)
|
||||
|
||||
VARIABLE(grub_multiboot_backward_relocator)
|
||||
/* Add entry offset (before %edi is mangled). */
|
||||
addl %edi, %edx
|
||||
|
||||
/* Backward movsb is implicitly off-by-one. compensate that. */
|
||||
decl %esi
|
||||
decl %edi
|
||||
|
||||
/* Backward copy. */
|
||||
std
|
||||
addl %ecx, %esi
|
||||
addl %ecx, %edi
|
||||
rep
|
||||
movsb
|
||||
|
||||
cld
|
||||
jmp *%edx
|
||||
VARIABLE(grub_multiboot_backward_relocator_end)
|
||||
|
||||
FUNCTION(grub_multiboot_real_boot)
|
||||
/* Push the entry address on the stack. */
|
||||
pushl %eax
|
||||
/* Move the address of the multiboot information structure to ebx. */
|
||||
movl %edx,%ebx
|
||||
|
||||
/* Interrupts should be disabled. */
|
||||
cli
|
||||
|
||||
/* Where do we copy what from. */
|
||||
movl EXT_C(grub_multiboot_payload_size), %ecx
|
||||
movl EXT_C(grub_multiboot_payload_orig), %esi
|
||||
movl EXT_C(grub_multiboot_payload_dest), %edi
|
||||
movl EXT_C(grub_multiboot_payload_entry_offset), %edx
|
||||
|
||||
/* Move the magic value into eax. */
|
||||
movl $MULTIBOOT_MAGIC2, %eax
|
||||
|
||||
/* Jump to the relocator. */
|
||||
popl %ebp
|
||||
jmp *%ebp
|
||||
|
||||
/*
|
||||
* This starts the multiboot 2 kernel.
|
||||
*/
|
||||
|
|
|
@ -102,7 +102,7 @@ grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags)
|
|||
|
||||
if (dev)
|
||||
grub_device_close (dev);
|
||||
|
||||
|
||||
/* Ignore errors. Perhaps it's not fatal. */
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
|
|
|
@ -27,7 +27,8 @@
|
|||
#include <grub/cpu/multiboot.h>
|
||||
|
||||
grub_err_t
|
||||
grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, UNUSED grub_addr_t *addr,
|
||||
grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr,
|
||||
grub_addr_t *addr __attribute__ ((unused)),
|
||||
int *do_load)
|
||||
{
|
||||
Elf32_Addr paddr = phdr->p_paddr;
|
||||
|
@ -48,7 +49,8 @@ grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, UNUSED grub_addr_t *addr,
|
|||
}
|
||||
|
||||
grub_err_t
|
||||
grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr, UNUSED grub_addr_t *addr,
|
||||
grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr,
|
||||
grub_addr_t *addr __attribute__ ((unused)),
|
||||
int *do_load)
|
||||
{
|
||||
Elf64_Addr paddr = phdr->p_paddr;
|
||||
|
@ -82,7 +84,8 @@ grub_mb2_arch_module_alloc (grub_size_t size, grub_addr_t *addr)
|
|||
}
|
||||
|
||||
grub_err_t
|
||||
grub_mb2_arch_module_free (grub_addr_t addr, UNUSED grub_size_t size)
|
||||
grub_mb2_arch_module_free (grub_addr_t addr,
|
||||
grub_size_t size __attribute__ ((unused)))
|
||||
{
|
||||
grub_free((void *) addr);
|
||||
return GRUB_ERR_NONE;
|
||||
|
|
|
@ -25,11 +25,17 @@
|
|||
#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;
|
||||
grub_uint32_t grub_xnu_entry_point, grub_xnu_arg1, grub_xnu_stack;
|
||||
|
||||
/* Aliases set for some tables. */
|
||||
struct tbl_alias
|
||||
|
@ -44,20 +50,13 @@ struct tbl_alias table_aliases[] =
|
|||
{GRUB_EFI_ACPI_TABLE_GUID, "ACPI"},
|
||||
};
|
||||
|
||||
/* The following function is used to be able to debug xnu loader
|
||||
with grub-emu. */
|
||||
#ifdef GRUB_UTIL
|
||||
static grub_err_t
|
||||
grub_xnu_launch (void)
|
||||
struct grub_xnu_devprop_device_descriptor
|
||||
{
|
||||
grub_printf ("Fake launch %x:%p:%p", grub_xnu_entry_point, grub_xnu_arg1,
|
||||
grub_xnu_stack);
|
||||
grub_getkey ();
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
static void (*grub_xnu_launch) (void) = 0;
|
||||
#endif
|
||||
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)
|
||||
|
@ -205,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
|
||||
|
@ -216,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? */
|
||||
|
@ -417,6 +822,19 @@ grub_cpu_xnu_fill_devicetree (void)
|
|||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_xnu_boot_resume (void)
|
||||
{
|
||||
struct grub_relocator32_state state;
|
||||
|
||||
state.esp = grub_xnu_stack;
|
||||
state.eip = grub_xnu_entry_point;
|
||||
state.eax = grub_xnu_arg1;
|
||||
|
||||
return grub_relocator32_boot (grub_xnu_heap_start, grub_xnu_heap_will_be_at,
|
||||
state);
|
||||
}
|
||||
|
||||
/* Boot xnu. */
|
||||
grub_err_t
|
||||
grub_xnu_boot (void)
|
||||
|
@ -430,10 +848,28 @@ 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);
|
||||
|
@ -447,94 +883,7 @@ 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 = ((char *) devtree - 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;
|
||||
#ifndef GRUB_UTIL
|
||||
grub_xnu_launch = (void (*) (void))
|
||||
(grub_xnu_heap_start + grub_xnu_heap_size);
|
||||
#endif
|
||||
grub_dprintf ("xnu", "eip=%x\n", grub_xnu_entry_point);
|
||||
grub_dprintf ("xnu", "launch=%p\n", grub_xnu_launch);
|
||||
|
||||
const char *debug = grub_env_get ("debug");
|
||||
|
||||
|
@ -544,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)
|
||||
|
@ -560,16 +916,121 @@ grub_xnu_boot (void)
|
|||
bootparams_relloc->lfb_base = 0;
|
||||
}
|
||||
|
||||
grub_memcpy (grub_xnu_heap_start + grub_xnu_heap_size,
|
||||
grub_xnu_launcher_start,
|
||||
grub_xnu_launcher_end - grub_xnu_launcher_start);
|
||||
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;
|
||||
|
||||
if (! grub_autoefi_finish_boot_services ())
|
||||
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_xnu_launch ();
|
||||
grub_autoefi_set_virtual_address_map (memory_map_size, descriptor_size,
|
||||
descriptor_version,memory_map);
|
||||
|
||||
/* Never reaches here. */
|
||||
return 0;
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -1,211 +0,0 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/symbol.h>
|
||||
|
||||
|
||||
.p2align 4 /* force 16-byte alignment */
|
||||
|
||||
VARIABLE(grub_xnu_launcher_start)
|
||||
base:
|
||||
cli
|
||||
|
||||
#ifndef __x86_64__
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_xnu_heap_will_be_at)
|
||||
.long 0
|
||||
mov %eax, %edi
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_xnu_heap_start)
|
||||
.long 0
|
||||
mov %eax, %esi
|
||||
|
||||
/* mov imm32, %ecx */
|
||||
.byte 0xb9
|
||||
VARIABLE(grub_xnu_heap_size)
|
||||
.long 0
|
||||
mov %edi, %eax
|
||||
add %ecx, %eax
|
||||
/* %rax now contains our starting position after relocation. */
|
||||
/* One more page to copy: ourselves. */
|
||||
add $0x403, %ecx
|
||||
shr $2, %ecx
|
||||
|
||||
/* Forward copy. */
|
||||
cld
|
||||
rep
|
||||
movsl
|
||||
|
||||
mov %eax, %esi
|
||||
add $(cont0-base), %eax
|
||||
jmp *%eax
|
||||
cont0:
|
||||
#else
|
||||
xorq %rax, %rax
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_xnu_heap_will_be_at)
|
||||
.long 0
|
||||
mov %rax, %rdi
|
||||
|
||||
/* mov imm32, %rax */
|
||||
.byte 0x48
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_xnu_heap_start)
|
||||
.long 0
|
||||
.long 0
|
||||
mov %rax, %rsi
|
||||
|
||||
/* mov imm32, %rcx */
|
||||
.byte 0x48
|
||||
.byte 0xb9
|
||||
VARIABLE(grub_xnu_heap_size)
|
||||
.long 0
|
||||
.long 0
|
||||
mov %rdi, %rax
|
||||
add %rcx, %rax
|
||||
/* %rax now contains our starting position after relocation. */
|
||||
/* One more page to copy: ourselves. */
|
||||
add $0x403, %rcx
|
||||
shr $2, %rcx
|
||||
|
||||
/* Forward copy. */
|
||||
cld
|
||||
rep
|
||||
movsl
|
||||
|
||||
mov %rax, %rsi
|
||||
#ifdef APPLE_CC
|
||||
add $(cont0-base), %eax
|
||||
#else
|
||||
add $(cont0-base), %rax
|
||||
#endif
|
||||
jmp *%rax
|
||||
|
||||
cont0:
|
||||
#ifdef APPLE_CC
|
||||
lea (cont1 - base) (%esi, 1), %eax
|
||||
mov %eax, (jump_vector - base) (%esi, 1)
|
||||
|
||||
lea (gdt - base) (%esi, 1), %eax
|
||||
mov %eax, (gdt_addr - base) (%esi, 1)
|
||||
|
||||
/* Switch to compatibility mode. */
|
||||
|
||||
lgdt (gdtdesc - base) (%esi, 1)
|
||||
|
||||
/* Update %cs. Thanks to David Miller for pointing this mistake out. */
|
||||
ljmp *(jump_vector - base) (%esi,1)
|
||||
#else
|
||||
lea (cont1 - base) (%rsi, 1), %rax
|
||||
mov %eax, (jump_vector - base) (%rsi, 1)
|
||||
|
||||
lea (gdt - base) (%rsi, 1), %rax
|
||||
mov %rax, (gdt_addr - base) (%rsi, 1)
|
||||
|
||||
/* Switch to compatibility mode. */
|
||||
|
||||
lgdt (gdtdesc - base) (%rsi, 1)
|
||||
|
||||
/* Update %cs. Thanks to David Miller for pointing this mistake out. */
|
||||
ljmp *(jump_vector - base) (%rsi, 1)
|
||||
#endif
|
||||
|
||||
cont1:
|
||||
.code32
|
||||
|
||||
/* Update other registers. */
|
||||
mov $0x18, %eax
|
||||
mov %eax, %ds
|
||||
mov %eax, %es
|
||||
mov %eax, %fs
|
||||
mov %eax, %gs
|
||||
mov %eax, %ss
|
||||
|
||||
/* Disable paging. */
|
||||
mov %cr0, %eax
|
||||
and $0x7fffffff, %eax
|
||||
mov %eax, %cr0
|
||||
|
||||
/* Disable amd64. */
|
||||
mov $0xc0000080, %ecx
|
||||
rdmsr
|
||||
and $0xfffffeff, %eax
|
||||
wrmsr
|
||||
|
||||
/* Turn off PAE. */
|
||||
movl %cr4, %eax
|
||||
and $0xffffffcf, %eax
|
||||
mov %eax, %cr4
|
||||
|
||||
jmp cont2
|
||||
cont2:
|
||||
#endif
|
||||
.code32
|
||||
|
||||
/* Registers on XNU boot: eip, esp and eax. */
|
||||
/* mov imm32, %ecx */
|
||||
.byte 0xb9
|
||||
VARIABLE (grub_xnu_entry_point)
|
||||
.long 0
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE (grub_xnu_arg1)
|
||||
.long 0
|
||||
/* mov imm32, %ebx */
|
||||
.byte 0xbb
|
||||
VARIABLE (grub_xnu_stack)
|
||||
.long 0
|
||||
|
||||
movl %ebx, %esp
|
||||
|
||||
jmp *%ecx
|
||||
|
||||
#ifdef __x86_64__
|
||||
/* GDT. Copied from loader/i386/linux.c. */
|
||||
.p2align 4
|
||||
gdt:
|
||||
/* NULL. */
|
||||
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
|
||||
/* Reserved. */
|
||||
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
|
||||
/* Code segment. */
|
||||
.byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x9A, 0xCF, 0x00
|
||||
|
||||
/* Data segment. */
|
||||
.byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x92, 0xCF, 0x00
|
||||
|
||||
gdtdesc:
|
||||
.word 31
|
||||
gdt_addr:
|
||||
/* Filled by the code. */
|
||||
.quad 0
|
||||
|
||||
.p2align 4
|
||||
jump_vector:
|
||||
/* Jump location. Is filled by the code */
|
||||
.long 0
|
||||
.long 0x10
|
||||
#endif
|
||||
VARIABLE(grub_xnu_launcher_end)
|
Loading…
Add table
Add a link
Reference in a new issue