merge mtrunk into xnu
This commit is contained in:
commit
7ea73643f5
224 changed files with 43437 additions and 7593 deletions
|
@ -23,7 +23,6 @@
|
|||
#include <grub/machine/init.h>
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/memory.h>
|
||||
#include <grub/machine/machine.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/dl.h>
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
*/
|
||||
|
||||
#include <grub/loader.h>
|
||||
#include <grub/machine/machine.h>
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/machine/loader.h>
|
||||
#include <grub/normal.h>
|
||||
|
|
|
@ -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 grub_multiboot_info *mbi, *mbi_dest;
|
||||
static grub_addr_t entry;
|
||||
static struct multiboot_info *mbi, *mbi_dest;
|
||||
|
||||
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,22 +86,22 @@ 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++)
|
||||
{
|
||||
grub_free ((void *)
|
||||
((struct grub_mod_list *) mbi->mods_addr)[i].mod_start);
|
||||
((struct multiboot_mod_list *) mbi->mods_addr)[i].mod_start);
|
||||
grub_free ((void *)
|
||||
((struct grub_mod_list *) mbi->mods_addr)[i].cmdline);
|
||||
((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;
|
||||
|
@ -107,14 +125,14 @@ grub_get_multiboot_mmap_len (void)
|
|||
|
||||
grub_mmap_iterate (hook);
|
||||
|
||||
return count * sizeof (struct grub_multiboot_mmap_entry);
|
||||
return count * sizeof (struct multiboot_mmap_entry);
|
||||
}
|
||||
|
||||
/* Fill previously allocated Multiboot mmap. */
|
||||
static void
|
||||
grub_fill_multiboot_mmap (struct grub_multiboot_mmap_entry *first_entry)
|
||||
grub_fill_multiboot_mmap (struct multiboot_mmap_entry *first_entry)
|
||||
{
|
||||
struct grub_multiboot_mmap_entry *mmap_entry = (struct grub_multiboot_mmap_entry *) first_entry;
|
||||
struct multiboot_mmap_entry *mmap_entry = (struct multiboot_mmap_entry *) first_entry;
|
||||
|
||||
auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t);
|
||||
int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type)
|
||||
|
@ -122,7 +140,7 @@ grub_fill_multiboot_mmap (struct grub_multiboot_mmap_entry *first_entry)
|
|||
mmap_entry->addr = addr;
|
||||
mmap_entry->len = size;
|
||||
mmap_entry->type = type;
|
||||
mmap_entry->size = sizeof (struct grub_multiboot_mmap_entry) - sizeof (mmap_entry->size);
|
||||
mmap_entry->size = sizeof (struct multiboot_mmap_entry) - sizeof (mmap_entry->size);
|
||||
mmap_entry++;
|
||||
|
||||
return 0;
|
||||
|
@ -197,7 +215,7 @@ grub_multiboot (int argc, char *argv[])
|
|||
{
|
||||
grub_file_t file = 0;
|
||||
char buffer[MULTIBOOT_SEARCH], *cmdline = 0, *p;
|
||||
struct grub_multiboot_header *header;
|
||||
struct multiboot_header *header;
|
||||
grub_ssize_t len, cmdline_length, boot_loader_name_length;
|
||||
grub_uint32_t mmap_length;
|
||||
int i;
|
||||
|
@ -228,9 +246,9 @@ grub_multiboot (int argc, char *argv[])
|
|||
|
||||
/* Look for the multiboot header in the buffer. The header should
|
||||
be at least 12 bytes and aligned on a 4-byte boundary. */
|
||||
for (header = (struct grub_multiboot_header *) buffer;
|
||||
for (header = (struct multiboot_header *) buffer;
|
||||
((char *) header <= buffer + len - 12) || (header = 0);
|
||||
header = (struct grub_multiboot_header *) ((char *) header + 4))
|
||||
header = (struct multiboot_header *) ((char *) header + 4))
|
||||
{
|
||||
if (header->magic == MULTIBOOT_MAGIC
|
||||
&& !(header->magic + header->flags + header->checksum))
|
||||
|
@ -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 ();
|
||||
|
||||
|
@ -275,12 +290,12 @@ grub_multiboot (int argc, char *argv[])
|
|||
#define boot_loader_name_addr(x) \
|
||||
((void *) ((x) + code_size + cmdline_length))
|
||||
#define mbi_addr(x) ((void *) ((x) + code_size + cmdline_length + boot_loader_name_length))
|
||||
#define mmap_addr(x) ((void *) ((x) + code_size + cmdline_length + boot_loader_name_length + sizeof (struct grub_multiboot_info)))
|
||||
#define mmap_addr(x) ((void *) ((x) + code_size + cmdline_length + boot_loader_name_length + sizeof (struct multiboot_info)))
|
||||
|
||||
grub_multiboot_payload_size = cmdline_length
|
||||
/* boot_loader_name_length might need to grow for mbi,etc to be aligned (see below) */
|
||||
+ boot_loader_name_length + 3
|
||||
+ sizeof (struct grub_multiboot_info) + mmap_length;
|
||||
+ sizeof (struct multiboot_info) + mmap_length;
|
||||
|
||||
if (header->flags & MULTIBOOT_AOUT_KLUDGE)
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -324,7 +340,7 @@ grub_multiboot (int argc, char *argv[])
|
|||
|
||||
mbi = mbi_addr (grub_multiboot_payload_orig);
|
||||
mbi_dest = mbi_addr (grub_multiboot_payload_dest);
|
||||
grub_memset (mbi, 0, sizeof (struct grub_multiboot_info));
|
||||
grub_memset (mbi, 0, sizeof (struct multiboot_info));
|
||||
mbi->mmap_length = mmap_length;
|
||||
|
||||
grub_fill_multiboot_mmap (mmap_addr (grub_multiboot_payload_orig));
|
||||
|
@ -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;
|
||||
|
@ -462,10 +461,10 @@ grub_module (int argc, char *argv[])
|
|||
|
||||
if (mbi->flags & MULTIBOOT_INFO_MODS)
|
||||
{
|
||||
struct grub_mod_list *modlist = (struct grub_mod_list *) mbi->mods_addr;
|
||||
struct multiboot_mod_list *modlist = (struct multiboot_mod_list *) mbi->mods_addr;
|
||||
|
||||
modlist = grub_realloc (modlist, (mbi->mods_count + 1)
|
||||
* sizeof (struct grub_mod_list));
|
||||
* sizeof (struct multiboot_mod_list));
|
||||
if (! modlist)
|
||||
goto fail;
|
||||
mbi->mods_addr = (grub_uint32_t) modlist;
|
||||
|
@ -478,7 +477,7 @@ grub_module (int argc, char *argv[])
|
|||
}
|
||||
else
|
||||
{
|
||||
struct grub_mod_list *modlist = grub_zalloc (sizeof (struct grub_mod_list));
|
||||
struct multiboot_mod_list *modlist = grub_zalloc (sizeof (struct multiboot_mod_list));
|
||||
if (! modlist)
|
||||
goto fail;
|
||||
modlist->mod_start = (grub_uint32_t) module;
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -95,17 +95,17 @@ grub_mb2_arch_boot (grub_addr_t entry, void *tags)
|
|||
}
|
||||
|
||||
void
|
||||
grub_mb2_arch_unload (struct multiboot_tag_header *tags)
|
||||
grub_mb2_arch_unload (struct multiboot2_tag_header *tags)
|
||||
{
|
||||
struct multiboot_tag_header *tag;
|
||||
struct multiboot2_tag_header *tag;
|
||||
|
||||
/* Free all module memory in the tag list. */
|
||||
for_each_tag (tag, tags)
|
||||
{
|
||||
if (tag->key == MULTIBOOT2_TAG_MODULE)
|
||||
{
|
||||
struct multiboot_tag_module *module =
|
||||
(struct multiboot_tag_module *) tag;
|
||||
struct multiboot2_tag_module *module =
|
||||
(struct multiboot2_tag_module *) tag;
|
||||
grub_free((void *) module->addr);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
#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
|
||||
|
@ -56,21 +58,6 @@ struct grub_xnu_devprop_device_descriptor
|
|||
int pathlen;
|
||||
};
|
||||
|
||||
/* 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)
|
||||
{
|
||||
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
|
||||
|
||||
static int
|
||||
utf16_strlen (grub_uint16_t *in)
|
||||
{
|
||||
|
@ -835,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)
|
||||
|
@ -853,6 +853,7 @@ grub_xnu_boot (void)
|
|||
void *devtree;
|
||||
grub_size_t devtreelen;
|
||||
int i;
|
||||
struct grub_relocator32_state state;
|
||||
|
||||
err = grub_autoefi_prepare ();
|
||||
if (err)
|
||||
|
@ -938,7 +939,8 @@ grub_xnu_boot (void)
|
|||
grub_memcpy (bootparams_relloc->cmdline, grub_xnu_cmdline,
|
||||
sizeof (bootparams_relloc->cmdline));
|
||||
|
||||
bootparams_relloc->devtree = ((char *) devtree - grub_xnu_heap_start)
|
||||
bootparams_relloc->devtree
|
||||
= ((grub_uint8_t *) devtree - (grub_uint8_t *) grub_xnu_heap_start)
|
||||
+ grub_xnu_heap_will_be_at;
|
||||
bootparams_relloc->devtreelen = devtreelen;
|
||||
|
||||
|
@ -1003,15 +1005,6 @@ grub_xnu_boot (void)
|
|||
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_memcpy (grub_xnu_heap_start + grub_xnu_heap_size,
|
||||
grub_xnu_launcher_start,
|
||||
grub_xnu_launcher_end - grub_xnu_launcher_start);
|
||||
|
||||
|
||||
if (! grub_autoefi_exit_boot_services (map_key))
|
||||
return grub_error (GRUB_ERR_IO, "can't exit boot services");
|
||||
|
@ -1019,10 +1012,11 @@ grub_xnu_boot (void)
|
|||
grub_autoefi_set_virtual_address_map (memory_map_size, descriptor_size,
|
||||
descriptor_version,memory_map);
|
||||
|
||||
grub_xnu_launch ();
|
||||
|
||||
/* 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;
|
||||
|
|
|
@ -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)
|
|
@ -115,17 +115,17 @@ grub_mb2_tags_arch_create (void)
|
|||
|
||||
/* Release the memory we claimed from Open Firmware above. */
|
||||
void
|
||||
grub_mb2_arch_unload (struct multiboot_tag_header *tags)
|
||||
grub_mb2_arch_unload (struct multiboot2_tag_header *tags)
|
||||
{
|
||||
struct multiboot_tag_header *tag;
|
||||
struct multiboot2_tag_header *tag;
|
||||
|
||||
/* Free all module memory in the tag list. */
|
||||
for_each_tag (tag, tags)
|
||||
{
|
||||
if (tag->key == MULTIBOOT2_TAG_MODULE)
|
||||
{
|
||||
struct multiboot_tag_module *module =
|
||||
(struct multiboot_tag_module *) tag;
|
||||
struct multiboot2_tag_module *module =
|
||||
(struct multiboot2_tag_module *) tag;
|
||||
grub_ieee1275_release (module->addr, module->size);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ grub_mb2_tags_free (void)
|
|||
grub_err_t
|
||||
grub_mb2_tag_alloc (grub_addr_t *addr, int key, grub_size_t len)
|
||||
{
|
||||
struct multiboot_tag_header *tag;
|
||||
struct multiboot2_tag_header *tag;
|
||||
grub_size_t used;
|
||||
grub_size_t needed;
|
||||
|
||||
|
@ -59,7 +59,7 @@ grub_mb2_tag_alloc (grub_addr_t *addr, int key, grub_size_t len)
|
|||
key, (unsigned long) len);
|
||||
|
||||
used = grub_mb2_tags_pos - grub_mb2_tags;
|
||||
len = ALIGN_UP (len, sizeof (multiboot_word));
|
||||
len = ALIGN_UP (len, sizeof (multiboot2_word));
|
||||
|
||||
needed = used + len;
|
||||
|
||||
|
@ -83,7 +83,7 @@ grub_mb2_tag_alloc (grub_addr_t *addr, int key, grub_size_t len)
|
|||
grub_mb2_tags_pos = newarea + used;
|
||||
}
|
||||
|
||||
tag = (struct multiboot_tag_header *) grub_mb2_tags_pos;
|
||||
tag = (struct multiboot2_tag_header *) grub_mb2_tags_pos;
|
||||
grub_mb2_tags_pos += len;
|
||||
|
||||
tag->key = key;
|
||||
|
@ -103,24 +103,24 @@ static grub_err_t
|
|||
grub_mb2_tag_start_create (void)
|
||||
{
|
||||
return grub_mb2_tag_alloc (0, MULTIBOOT2_TAG_START,
|
||||
sizeof (struct multiboot_tag_start));
|
||||
sizeof (struct multiboot2_tag_start));
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_mb2_tag_name_create (void)
|
||||
{
|
||||
struct multiboot_tag_name *name;
|
||||
struct multiboot2_tag_name *name;
|
||||
grub_addr_t name_addr;
|
||||
grub_err_t err;
|
||||
const char *grub_version = PACKAGE_STRING;
|
||||
|
||||
err = grub_mb2_tag_alloc (&name_addr, MULTIBOOT2_TAG_NAME,
|
||||
sizeof (struct multiboot_tag_name) +
|
||||
sizeof (struct multiboot2_tag_name) +
|
||||
sizeof (grub_version) + 1);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
name = (struct multiboot_tag_name *) name_addr;
|
||||
name = (struct multiboot2_tag_name *) name_addr;
|
||||
grub_strcpy (name->name, grub_version);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
|
@ -159,17 +159,17 @@ error:
|
|||
static grub_err_t
|
||||
grub_mb2_tags_finish (void)
|
||||
{
|
||||
struct multiboot_tag_start *start;
|
||||
struct multiboot2_tag_start *start;
|
||||
grub_err_t err;
|
||||
|
||||
/* Create the `end' tag. */
|
||||
err = grub_mb2_tag_alloc (0, MULTIBOOT2_TAG_END,
|
||||
sizeof (struct multiboot_tag_end));
|
||||
sizeof (struct multiboot2_tag_end));
|
||||
if (err)
|
||||
goto error;
|
||||
|
||||
/* We created the `start' tag first. Update it now. */
|
||||
start = (struct multiboot_tag_start *) grub_mb2_tags;
|
||||
start = (struct multiboot2_tag_start *) grub_mb2_tags;
|
||||
start->size = grub_mb2_tags_pos - grub_mb2_tags;
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
|
@ -195,17 +195,17 @@ grub_mb2_boot (void)
|
|||
static grub_err_t
|
||||
grub_mb2_unload (void)
|
||||
{
|
||||
struct multiboot_tag_header *tag;
|
||||
struct multiboot_tag_header *tags =
|
||||
(struct multiboot_tag_header *) grub_mb2_tags;
|
||||
struct multiboot2_tag_header *tag;
|
||||
struct multiboot2_tag_header *tags =
|
||||
(struct multiboot2_tag_header *) grub_mb2_tags;
|
||||
|
||||
/* Free all module memory in the tag list. */
|
||||
for_each_tag (tag, tags)
|
||||
{
|
||||
if (tag->key == MULTIBOOT2_TAG_MODULE)
|
||||
{
|
||||
struct multiboot_tag_module *module =
|
||||
(struct multiboot_tag_module *) tag;
|
||||
struct multiboot2_tag_module *module =
|
||||
(struct multiboot2_tag_module *) tag;
|
||||
grub_free ((void *) module->addr);
|
||||
}
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ static grub_err_t
|
|||
grub_mb2_tag_module_create (grub_addr_t modaddr, grub_size_t modsize,
|
||||
char *type, int key, int argc, char *argv[])
|
||||
{
|
||||
struct multiboot_tag_module *module;
|
||||
struct multiboot2_tag_module *module;
|
||||
grub_ssize_t argslen = 0;
|
||||
grub_err_t err;
|
||||
char *p;
|
||||
|
@ -246,11 +246,11 @@ grub_mb2_tag_module_create (grub_addr_t modaddr, grub_size_t modsize,
|
|||
|
||||
/* Note: includes implicit 1-byte cmdline. */
|
||||
err = grub_mb2_tag_alloc (&module_addr, key,
|
||||
sizeof (struct multiboot_tag_module) + argslen);
|
||||
sizeof (struct multiboot2_tag_module) + argslen);
|
||||
if (err)
|
||||
return grub_errno;
|
||||
|
||||
module = (struct multiboot_tag_module *) module_addr;
|
||||
module = (struct multiboot2_tag_module *) module_addr;
|
||||
module->addr = modaddr;
|
||||
module->size = modsize;
|
||||
grub_strcpy(module->type, type);
|
||||
|
@ -308,7 +308,7 @@ grub_multiboot2 (int argc, char *argv[])
|
|||
char *buffer;
|
||||
grub_file_t file = 0;
|
||||
grub_elf_t elf = 0;
|
||||
struct multiboot_header *header = 0;
|
||||
struct multiboot2_header *header = 0;
|
||||
char *p;
|
||||
grub_ssize_t len;
|
||||
grub_err_t err;
|
||||
|
@ -344,7 +344,7 @@ grub_multiboot2 (int argc, char *argv[])
|
|||
be at least 8 bytes and aligned on a 8-byte boundary. */
|
||||
for (p = buffer; p <= buffer + len - 8; p += 8)
|
||||
{
|
||||
header = (struct multiboot_header *) p;
|
||||
header = (struct multiboot2_header *) p;
|
||||
if (header->magic == MULTIBOOT2_HEADER_MAGIC)
|
||||
{
|
||||
header_found = 1;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/machine/machine.h>
|
||||
#include <grub/multiboot.h>
|
||||
#include <grub/multiboot2.h>
|
||||
#include <multiboot2.h>
|
||||
|
@ -44,7 +43,7 @@ static unsigned int module_version_status = 1;
|
|||
static int
|
||||
find_multi_boot1_header (grub_file_t file)
|
||||
{
|
||||
struct grub_multiboot_header *header;
|
||||
struct multiboot_header *header;
|
||||
char buffer[MULTIBOOT_SEARCH];
|
||||
int found_status = 0;
|
||||
grub_ssize_t len;
|
||||
|
@ -55,9 +54,9 @@ find_multi_boot1_header (grub_file_t file)
|
|||
|
||||
/* Look for the multiboot header in the buffer. The header should
|
||||
be at least 12 bytes and aligned on a 4-byte boundary. */
|
||||
for (header = (struct grub_multiboot_header *) buffer;
|
||||
for (header = (struct multiboot_header *) buffer;
|
||||
((char *) header <= buffer + len - 12) || (header = 0);
|
||||
header = (struct grub_multiboot_header *) ((char *) header + 4))
|
||||
header = (struct multiboot_header *) ((char *) header + 4))
|
||||
{
|
||||
if (header->magic == MULTIBOOT_MAGIC
|
||||
&& !(header->magic + header->flags + header->checksum))
|
||||
|
|
44
loader/xnu.c
44
loader/xnu.c
|
@ -38,6 +38,9 @@ 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;
|
||||
|
||||
/* Allocate heap by 32MB-blocks. */
|
||||
#define GRUB_XNU_HEAP_ALLOC_BLOCK 0x2000000
|
||||
|
||||
|
@ -48,12 +51,6 @@ void *
|
|||
grub_xnu_heap_malloc (int size)
|
||||
{
|
||||
void *val;
|
||||
|
||||
#if 0
|
||||
/* This way booting is faster but less reliable.
|
||||
Once we have advanced mm second way will be as fast as this one. */
|
||||
val = grub_xnu_heap_start = (char *) 0x100000;
|
||||
#else
|
||||
int oldblknum, newblknum;
|
||||
|
||||
/* The page after the heap is used for stack. Ensure it's usable. */
|
||||
|
@ -65,25 +62,21 @@ grub_xnu_heap_malloc (int size)
|
|||
newblknum = (grub_xnu_heap_size + size + GRUB_XNU_PAGESIZE
|
||||
+ GRUB_XNU_HEAP_ALLOC_BLOCK - 1) / GRUB_XNU_HEAP_ALLOC_BLOCK;
|
||||
if (oldblknum != newblknum)
|
||||
/* FIXME: instruct realloc to allocate at 1MB if possible once
|
||||
advanced mm is ready. */
|
||||
val = grub_realloc (grub_xnu_heap_start,
|
||||
newblknum * GRUB_XNU_HEAP_ALLOC_BLOCK);
|
||||
else
|
||||
val = grub_xnu_heap_start;
|
||||
if (! val)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY,
|
||||
"not enough space on xnu memory heap");
|
||||
return 0;
|
||||
/* FIXME: instruct realloc to allocate at 1MB if possible once
|
||||
advanced mm is ready. */
|
||||
grub_xnu_heap_start
|
||||
= XNU_RELOCATOR (realloc) (grub_xnu_heap_start,
|
||||
newblknum
|
||||
* GRUB_XNU_HEAP_ALLOC_BLOCK);
|
||||
if (!grub_xnu_heap_start)
|
||||
return NULL;
|
||||
}
|
||||
grub_xnu_heap_start = val;
|
||||
#endif
|
||||
|
||||
val = (char *) grub_xnu_heap_start + grub_xnu_heap_size;
|
||||
val = (grub_uint8_t *) grub_xnu_heap_start + grub_xnu_heap_size;
|
||||
grub_xnu_heap_size += size;
|
||||
grub_dprintf ("xnu", "val=%p\n", val);
|
||||
return (char *) val;
|
||||
return val;
|
||||
}
|
||||
|
||||
/* Make sure next block of the heap will be aligned.
|
||||
|
@ -253,7 +246,7 @@ grub_xnu_writetree_toheap (void **start, grub_size_t *size)
|
|||
- *size % GRUB_XNU_PAGESIZE);
|
||||
|
||||
/* Put real data in the dummy. */
|
||||
extdesc->addr = (char *) *start - grub_xnu_heap_start
|
||||
extdesc->addr = (grub_uint8_t *) *start - (grub_uint8_t *) grub_xnu_heap_start
|
||||
+ grub_xnu_heap_will_be_at;
|
||||
extdesc->size = (grub_uint32_t) *size;
|
||||
|
||||
|
@ -634,7 +627,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
|
|||
grub_file_t infoplist;
|
||||
struct grub_xnu_extheader *exthead;
|
||||
int neededspace = sizeof (*exthead);
|
||||
char *buf;
|
||||
grub_uint8_t *buf;
|
||||
grub_size_t infoplistsize = 0, machosize = 0;
|
||||
char *name, *nameend;
|
||||
int namelen;
|
||||
|
@ -698,7 +691,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
|
|||
/* Load the binary. */
|
||||
if (macho)
|
||||
{
|
||||
exthead->binaryaddr = (buf - grub_xnu_heap_start)
|
||||
exthead->binaryaddr = (buf - (grub_uint8_t *) grub_xnu_heap_start)
|
||||
+ grub_xnu_heap_will_be_at;
|
||||
exthead->binarysize = machosize;
|
||||
if (grub_xnu_is_64bit)
|
||||
|
@ -718,7 +711,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
|
|||
/* Load the plist. */
|
||||
if (infoplist)
|
||||
{
|
||||
exthead->infoplistaddr = (buf - grub_xnu_heap_start)
|
||||
exthead->infoplistaddr = (buf - (grub_uint8_t *) grub_xnu_heap_start)
|
||||
+ grub_xnu_heap_will_be_at;
|
||||
exthead->infoplistsize = infoplistsize + 1;
|
||||
if (grub_file_read (infoplist, buf, infoplistsize)
|
||||
|
@ -735,7 +728,8 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
|
|||
}
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
exthead->nameaddr = (buf - grub_xnu_heap_start) + grub_xnu_heap_will_be_at;
|
||||
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;
|
||||
|
|
|
@ -45,7 +45,7 @@ grub_xnu_resume (char *imagename)
|
|||
grub_file_t file;
|
||||
grub_size_t total_header_size;
|
||||
struct grub_xnu_hibernate_header hibhead;
|
||||
char *buf, *codetmp;
|
||||
grub_uint8_t *buf;
|
||||
|
||||
grub_uint32_t codedest;
|
||||
grub_uint32_t codesize;
|
||||
|
@ -94,17 +94,28 @@ grub_xnu_resume (char *imagename)
|
|||
/* Try to allocate necessary space.
|
||||
FIXME: mm isn't good enough yet to handle huge allocations.
|
||||
*/
|
||||
grub_xnu_hibernate_image = buf = grub_malloc (hibhead.image_size);
|
||||
grub_xnu_hibernate_image = buf = XNU_RELOCATOR (alloc) (hibhead.image_size
|
||||
+ codesize
|
||||
+ GRUB_XNU_PAGESIZE);
|
||||
if (! buf)
|
||||
{
|
||||
grub_file_close (file);
|
||||
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
|
||||
"not enough memory to load image");
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
/* Read code part. */
|
||||
if (grub_file_seek (file, total_header_size) == (grub_off_t) -1
|
||||
|| grub_file_read (file, buf, codesize)
|
||||
!= (grub_ssize_t) codesize)
|
||||
{
|
||||
grub_file_close (file);
|
||||
return grub_error (GRUB_ERR_READ_ERROR, "Cannot read resume image.");
|
||||
}
|
||||
|
||||
/* Read image. */
|
||||
if (grub_file_seek (file, 0) == (grub_off_t)-1
|
||||
|| grub_file_read (file, buf, hibhead.image_size)
|
||||
if (grub_file_seek (file, 0) == (grub_off_t) -1
|
||||
|| grub_file_read (file, buf + codesize + GRUB_XNU_PAGESIZE,
|
||||
hibhead.image_size)
|
||||
!= (grub_ssize_t) hibhead.image_size)
|
||||
{
|
||||
grub_file_close (file);
|
||||
|
@ -112,22 +123,20 @@ grub_xnu_resume (char *imagename)
|
|||
}
|
||||
grub_file_close (file);
|
||||
|
||||
codetmp = grub_memalign (GRUB_XNU_PAGESIZE, codesize + GRUB_XNU_PAGESIZE);
|
||||
/* Setup variables needed by asm helper. */
|
||||
grub_xnu_heap_will_be_at = codedest;
|
||||
grub_xnu_heap_start = codetmp;
|
||||
grub_xnu_heap_size = codesize;
|
||||
grub_xnu_heap_start = buf;
|
||||
grub_xnu_heap_size = codesize + GRUB_XNU_PAGESIZE + hibhead.image_size;
|
||||
grub_xnu_stack = (codedest + hibhead.stack);
|
||||
grub_xnu_entry_point = (codedest + hibhead.entry_point);
|
||||
grub_xnu_arg1 = (long) buf;
|
||||
grub_xnu_arg1 = codedest + codesize + GRUB_XNU_PAGESIZE;
|
||||
|
||||
/* Prepare asm helper. */
|
||||
grub_memcpy (codetmp, ((grub_uint8_t *) buf) + total_header_size, codesize);
|
||||
grub_memcpy (codetmp + codesize, grub_xnu_launcher_start,
|
||||
grub_xnu_launcher_end - grub_xnu_launcher_start);
|
||||
grub_dprintf ("xnu", "entry point 0x%x\n", codedest + hibhead.entry_point);
|
||||
grub_dprintf ("xnu", "image at 0x%x\n",
|
||||
codedest + codesize + GRUB_XNU_PAGESIZE);
|
||||
|
||||
/* We're ready now. */
|
||||
grub_loader_set ((grub_err_t (*) (void)) (codetmp + codesize),
|
||||
grub_loader_set (grub_xnu_boot_resume,
|
||||
grub_xnu_resume_unload, 0);
|
||||
|
||||
/* Prevent module from unloading. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue