This commit is contained in:
phcoder 2009-10-16 17:40:59 +02:00
parent 1435b0bc86
commit 81a642e8e2
4 changed files with 35 additions and 24 deletions

View file

@ -46,12 +46,12 @@ grub_elf_t grub_elf_file (grub_file_t);
grub_err_t grub_elf_close (grub_elf_t); grub_err_t grub_elf_close (grub_elf_t);
int grub_elf_is_elf32 (grub_elf_t); int grub_elf_is_elf32 (grub_elf_t);
grub_size_t grub_elf32_size (grub_elf_t); grub_size_t grub_elf32_size (grub_elf_t, Elf32_Addr *);
grub_err_t grub_elf32_load (grub_elf_t, grub_elf32_load_hook_t, grub_addr_t *, grub_err_t grub_elf32_load (grub_elf_t, grub_elf32_load_hook_t, grub_addr_t *,
grub_size_t *); grub_size_t *);
int grub_elf_is_elf64 (grub_elf_t); int grub_elf_is_elf64 (grub_elf_t);
grub_size_t grub_elf64_size (grub_elf_t); grub_size_t grub_elf64_size (grub_elf_t, Elf64_Addr *);
grub_err_t grub_elf64_load (grub_elf_t, grub_elf64_load_hook_t, grub_addr_t *, grub_err_t grub_elf64_load (grub_elf_t, grub_elf64_load_hook_t, grub_addr_t *,
grub_size_t *); grub_size_t *);

View file

@ -172,7 +172,7 @@ grub_elf32_phdr_iterate (grub_elf_t elf,
/* Calculate the amount of memory spanned by the segments. */ /* Calculate the amount of memory spanned by the segments. */
grub_size_t grub_size_t
grub_elf32_size (grub_elf_t elf) grub_elf32_size (grub_elf_t elf, Elf32_Addr *base)
{ {
Elf32_Addr segments_start = (Elf32_Addr) -1; Elf32_Addr segments_start = (Elf32_Addr) -1;
Elf32_Addr segments_end = 0; Elf32_Addr segments_end = 0;
@ -196,6 +196,9 @@ grub_elf32_size (grub_elf_t elf)
grub_elf32_phdr_iterate (elf, calcsize, 0); grub_elf32_phdr_iterate (elf, calcsize, 0);
if (base)
*base = 0;
if (nr_phdrs == 0) if (nr_phdrs == 0)
{ {
grub_error (GRUB_ERR_BAD_OS, "No program headers present"); grub_error (GRUB_ERR_BAD_OS, "No program headers present");
@ -209,10 +212,12 @@ grub_elf32_size (grub_elf_t elf)
return 0; return 0;
} }
if (base)
*base = segments_start;
return segments_end - segments_start; return segments_end - segments_start;
} }
/* Load every loadable segment into memory specified by `_load_hook'. */ /* Load every loadable segment into memory specified by `_load_hook'. */
grub_err_t grub_err_t
grub_elf32_load (grub_elf_t _elf, grub_elf32_load_hook_t _load_hook, grub_elf32_load (grub_elf_t _elf, grub_elf32_load_hook_t _load_hook,
@ -351,7 +356,7 @@ grub_elf64_phdr_iterate (grub_elf_t elf,
/* Calculate the amount of memory spanned by the segments. */ /* Calculate the amount of memory spanned by the segments. */
grub_size_t grub_size_t
grub_elf64_size (grub_elf_t elf) grub_elf64_size (grub_elf_t elf, Elf64_Addr *base)
{ {
Elf64_Addr segments_start = (Elf64_Addr) -1; Elf64_Addr segments_start = (Elf64_Addr) -1;
Elf64_Addr segments_end = 0; Elf64_Addr segments_end = 0;
@ -375,6 +380,9 @@ grub_elf64_size (grub_elf_t elf)
grub_elf64_phdr_iterate (elf, calcsize, 0); grub_elf64_phdr_iterate (elf, calcsize, 0);
if (base)
*base = 0;
if (nr_phdrs == 0) if (nr_phdrs == 0)
{ {
grub_error (GRUB_ERR_BAD_OS, "No program headers present"); grub_error (GRUB_ERR_BAD_OS, "No program headers present");
@ -388,6 +396,9 @@ grub_elf64_size (grub_elf_t elf)
return 0; return 0;
} }
if (base)
*base = segments_start;
return segments_end - segments_start; return segments_end - segments_start;
} }

View file

@ -71,9 +71,9 @@ write_call_relocator_bw (void *ptr0, void *src, grub_uint32_t dest,
{ {
void *ptr = ptr0; void *ptr = ptr0;
int i; int i;
write_reg (1, (grub_uint32_t) src, &ptr); write_reg (2, (grub_uint32_t) src, &ptr);
write_reg (2, dest, &ptr); write_reg (3, dest, &ptr);
write_reg (3, size, &ptr); write_reg (4, size, &ptr);
grub_memcpy (ptr, &grub_relocator32_backward_start, grub_memcpy (ptr, &grub_relocator32_backward_start,
RELOCATOR_SRC_SIZEOF (backward)); RELOCATOR_SRC_SIZEOF (backward));
for (i = 1; i < 32; i++) for (i = 1; i < 32; i++)
@ -88,9 +88,9 @@ write_call_relocator_fw (void *ptr0, void *src, grub_uint32_t dest,
{ {
void *ptr = ptr0; void *ptr = ptr0;
int i; int i;
write_reg (1, (grub_uint32_t) src, &ptr); write_reg (2, (grub_uint32_t) src, &ptr);
write_reg (2, dest, &ptr); write_reg (3, dest, &ptr);
write_reg (3, size, &ptr); write_reg (4, size, &ptr);
grub_memcpy (ptr, &grub_relocator32_forward_start, grub_memcpy (ptr, &grub_relocator32_forward_start,
RELOCATOR_SRC_SIZEOF (forward)); RELOCATOR_SRC_SIZEOF (forward));
for (i = 1; i < 32; i++) for (i = 1; i < 32; i++)

View file

@ -28,23 +28,23 @@
VARIABLE (grub_relocator32_forward_start) VARIABLE (grub_relocator32_forward_start)
copycont1: copycont1:
lb $4,0($1) lb $5,0($2)
sb $4,0($2) sb $5,0($3)
addiu $3, $3, 0xffff addiu $4, $4, 0xffff
subu $4,$3,$0 subu $5,$4,$0
bne $4, $0, copycont1 bne $5, $0, copycont1
VARIABLE (grub_relocator32_forward_end) VARIABLE (grub_relocator32_forward_end)
VARIABLE (grub_relocator32_backward_start) VARIABLE (grub_relocator32_backward_start)
addu $2, $2, $3 addu $3, $3, $4
addu $1, $1, $3 addu $2, $2, $4
/* Backward movsl is implicitly off-by-one. compensate that. */ /* Backward movsl is implicitly off-by-one. compensate that. */
addiu $3, $3, 0xffff
addiu $2, $2, 0xffff addiu $2, $2, 0xffff
addiu $1, $1, 0xffff
copycont2: copycont2:
lb $4,0($1) lb $5,0($2)
sb $4,0($2) sb $5,0($3)
addiu $3, 0xffff addiu $4, 0xffff
subu $4,$3,$0 subu $5,$4,$0
bne $4, $0, copycont2 bne $5, $0, copycont2
VARIABLE (grub_relocator32_backward_end) VARIABLE (grub_relocator32_backward_end)