now hangs at maxDec

This commit is contained in:
phcoder 2009-09-02 13:34:40 +02:00
parent 72db7c22f3
commit 8a10b2c632
10 changed files with 177 additions and 28 deletions

View file

@ -36,7 +36,6 @@ SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks,
int cntconftables = 0;
struct SUFFIX (grub_efiemu_configuration_table) *conftables = 0;
struct SUFFIX (grub_efiemu_runtime_services) *runtime_services;
int i;
int handle;
grub_off_t off;
@ -54,6 +53,7 @@ SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks,
/* Switch from phase 1 (counting) to phase 2 (real job) */
grub_efiemu_alloc_syms ();
grub_efiemu_mm_do_alloc ();
grub_efiemu_write_sym_markers ();
grub_efiemu_system_table32 = 0;
grub_efiemu_system_table64 = 0;
@ -81,16 +81,6 @@ SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks,
= (struct SUFFIX (grub_efi_system_table) *)
((grub_uint8_t *) grub_efiemu_mm_obtain_request (handle) + off);
/* compute CRC32 of runtime_services */
if ((err = grub_efiemu_resolve_symbol ("efiemu_runtime_services",
&handle, &off)))
return err;
runtime_services = (struct SUFFIX (grub_efiemu_runtime_services) *)
((grub_uint8_t *) grub_efiemu_mm_obtain_request (handle) + off);
runtime_services->hdr.crc32 = 0;
runtime_services->hdr.crc32 = grub_getcrc32
(0, runtime_services, runtime_services->hdr.header_size);
/* Put pointer to the list of configuration tables in system table */
grub_efiemu_write_value
(&(SUFFIX (grub_efiemu_system_table)->configuration_table), 0,
@ -113,16 +103,51 @@ SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks,
conftables[i].vendor_table = PTR_TO_UINT64 (cur->data);
}
err = SUFFIX (grub_efiemu_crc) ();
if (err)
{
grub_efiemu_unload ();
return err;
}
grub_dprintf ("efiemu","system_table = %p, conftables = %p (%d entries)\n",
SUFFIX (grub_efiemu_system_table), conftables, cntconftables);
return GRUB_ERR_NONE;
}
grub_err_t
SUFFIX (grub_efiemu_crc) (void)
{
grub_err_t err;
int handle;
grub_off_t off;
struct SUFFIX (grub_efiemu_runtime_services) *runtime_services;
/* compute CRC32 of runtime_services */
err = grub_efiemu_resolve_symbol ("efiemu_runtime_services",
&handle, &off);
if (err)
return err;
runtime_services = (struct SUFFIX (grub_efiemu_runtime_services) *)
((grub_uint8_t *) grub_efiemu_mm_obtain_request (handle) + off);
runtime_services->hdr.crc32 = 0;
runtime_services->hdr.crc32 = grub_getcrc32
(0, runtime_services, runtime_services->hdr.header_size);
err = grub_efiemu_resolve_symbol ("efiemu_system_table", &handle, &off);
if (err)
return err;
/* compute CRC32 of system table */
SUFFIX (grub_efiemu_system_table)->hdr.crc32 = 0;
SUFFIX (grub_efiemu_system_table)->hdr.crc32
= grub_getcrc32 (0, SUFFIX (grub_efiemu_system_table),
SUFFIX (grub_efiemu_system_table)->hdr.header_size);
grub_dprintf ("efiemu","system_table = %p, runtime_services = %p,"
" conftables = %p (%d entries)\n",
SUFFIX (grub_efiemu_system_table), runtime_services,
conftables, cntconftables);
grub_dprintf ("efiemu","system_table = %p, runtime_services = %p\n",
SUFFIX (grub_efiemu_system_table), runtime_services);
return GRUB_ERR_NONE;
}

View file

@ -111,9 +111,8 @@ static grub_uint8_t loge[1000] = "EFIEMULOG";
static int logn = 9;
#define LOG(x) { if (logn<900) loge[logn++]=x; }
static int ptv_relocated = 0;
/* Interface with grub */
extern grub_uint8_t efiemu_ptv_relocated;
struct grub_efi_runtime_services efiemu_runtime_services;
struct grub_efi_system_table efiemu_system_table;
extern struct grub_efiemu_ptv_rel efiemu_ptv_relloc[];
@ -343,9 +342,9 @@ grub_efi_status_t EFI_FUNC
LOG ('e');
/* Ensure that we are called only once */
if (ptv_relocated)
if (efiemu_ptv_relocated)
return GRUB_EFI_UNSUPPORTED;
ptv_relocated = 1;
efiemu_ptv_relocated = 1;
/* Correct addresses using information supplied by grub */
for (cur_relloc = efiemu_ptv_relloc; cur_relloc->size;cur_relloc++)

View file

@ -26,9 +26,11 @@
static int ptv_written = 0;
static int ptv_alloc = 0;
static int ptv_handle = 0;
static int relocated_handle = 0;
static int ptv_requested = 0;
static struct grub_efiemu_sym *efiemu_syms = 0;
struct grub_efiemu_sym
{
struct grub_efiemu_sym *next;
@ -54,6 +56,8 @@ grub_efiemu_free_syms (void)
ptv_requested = 0;
grub_efiemu_mm_return_request (ptv_handle);
ptv_handle = 0;
grub_efiemu_mm_return_request (relocated_handle);
relocated_handle = 0;
}
/* Announce that the module will need NUM allocators */
@ -114,10 +118,26 @@ grub_efiemu_alloc_syms (void)
ptv_handle = grub_efiemu_request_memalign
(1, (ptv_requested + 1) * sizeof (struct grub_efiemu_ptv_rel),
GRUB_EFI_RUNTIME_SERVICES_DATA);
relocated_handle = grub_efiemu_request_memalign
(1, sizeof (grub_uint8_t), GRUB_EFI_RUNTIME_SERVICES_DATA);
grub_efiemu_register_symbol ("efiemu_ptv_relocated", relocated_handle, 0);
grub_efiemu_register_symbol ("efiemu_ptv_relloc", ptv_handle, 0);
return grub_errno;
}
grub_err_t
grub_efiemu_write_sym_markers (void)
{
struct grub_efiemu_ptv_rel *ptv_rels
= grub_efiemu_mm_obtain_request (ptv_handle);
grub_uint8_t *relocated = grub_efiemu_mm_obtain_request (relocated_handle);
grub_memset (ptv_rels, 0, (ptv_requested + 1)
* sizeof (struct grub_efiemu_ptv_rel));
*relocated = 0;
return GRUB_ERR_NONE;
}
/* Write value (pointer to memory PLUS_HANDLE)
- (pointer to memory MINUS_HANDLE) + VALUE to ADDR assuming that the
size SIZE bytes. If PTV_NEEDED is 1 then announce it to runtime that this
@ -186,3 +206,67 @@ grub_efiemu_write_value (void *addr, grub_uint32_t value, int plus_handle,
return GRUB_ERR_NONE;
}
grub_err_t
grub_efiemu_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
grub_efi_uintn_t descriptor_size,
grub_efi_uint32_t descriptor_version
__attribute__ ((unused)),
grub_efi_memory_descriptor_t *virtual_map)
{
grub_uint8_t *ptv_relocated;
struct grub_efiemu_ptv_rel *cur_relloc;
struct grub_efiemu_ptv_rel *ptv_rels;
ptv_relocated = grub_efiemu_mm_obtain_request (relocated_handle);
ptv_rels = grub_efiemu_mm_obtain_request (ptv_handle);
/* Ensure that we are called only once */
if (*ptv_relocated)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "EfiEmu is already relocated.");
*ptv_relocated = 1;
/* Correct addresses using information supplied by grub */
for (cur_relloc = ptv_rels; cur_relloc->size; cur_relloc++)
{
grub_int64_t corr = 0;
grub_efi_memory_descriptor_t *descptr;
/* Compute correction */
for (descptr = virtual_map;
(grub_size_t) ((grub_uint8_t *) descptr
- (grub_uint8_t *) virtual_map) < memory_map_size;
descptr = (grub_efi_memory_descriptor_t *)
((grub_uint8_t *) descptr + descriptor_size))
{
if (descptr->type == cur_relloc->plustype)
corr += descptr->virtual_start - descptr->physical_start;
if (descptr->type == cur_relloc->minustype)
corr -= descptr->virtual_start - descptr->physical_start;
}
/* Apply correction */
switch (cur_relloc->size)
{
case 8:
*((grub_uint64_t *) UINT_TO_PTR (cur_relloc->addr)) += corr;
break;
case 4:
*((grub_uint32_t *) UINT_TO_PTR (cur_relloc->addr)) += corr;
break;
case 2:
*((grub_uint16_t *) UINT_TO_PTR (cur_relloc->addr)) += corr;
break;
case 1:
*((grub_uint8_t *) UINT_TO_PTR (cur_relloc->addr)) += corr;
break;
}
}
/* Recompute crc32 of system table and runtime services */
if (grub_efiemu_sizeof_uintn_t () == 4)
return grub_efiemu_crc32 ();
else
return grub_efiemu_crc64 ();
}