merge mainline into videomask

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2009-12-16 17:52:17 +01:00
commit 45da21ff5a
154 changed files with 4592 additions and 6246 deletions

View file

@ -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>

View file

@ -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)
{

View file

@ -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)
{

View file

@ -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>

View file

@ -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;
@ -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;

View file

@ -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;
}

View file

@ -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.
*/

View file

@ -30,6 +30,8 @@
#include <grub/term.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,21 +46,6 @@ 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)
{
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)
{
@ -417,6 +404,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)
@ -434,6 +434,7 @@ grub_xnu_boot (void)
void *devtree;
grub_size_t devtreelen;
int i;
struct grub_relocator32_state state;
/* Page-align to avoid following parts to be inadvertently freed. */
err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE);
@ -501,7 +502,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;
@ -529,12 +531,7 @@ 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_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");
@ -560,16 +557,12 @@ 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_finish_boot_services ())
return grub_error (GRUB_ERR_IO, "can't exit boot services");
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);
}

View file

@ -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)

View file

@ -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>

View file

@ -36,6 +36,9 @@ struct grub_xnu_devtree_key *grub_xnu_devtree_root = 0;
static int driverspackagenum = 0;
static int driversnum = 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
@ -46,12 +49,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. */
@ -63,25 +60,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.
@ -251,7 +244,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;
@ -503,7 +496,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;
if (! grub_xnu_heap_size)
@ -552,7 +545,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 ((err = grub_macho32_readfile (macho, buf)))
@ -568,7 +561,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)

View file

@ -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. */