Initial import of Leif's work

This commit is contained in:
Leif Lindholm 2013-04-07 02:41:07 +02:00 committed by Vladimir 'phcoder' Serbinenko
parent 21026747df
commit 389b31cd71
65 changed files with 7311 additions and 13 deletions

View file

@ -58,6 +58,11 @@
#error "I'm confused"
#endif
static Elf_Addr SUFFIX (entry_point);
grub_err_t reloc_thm_call (grub_uint16_t *addr, Elf32_Addr sym_addr);
grub_err_t reloc_thm_jump19 (grub_uint16_t *addr, Elf32_Addr sym_addr);
/* Relocate symbols; note that this function overwrites the symbol table.
Return the address of a start symbol. */
static Elf_Addr
@ -528,6 +533,48 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
}
break;
#endif
#if defined(MKIMAGE_ELF32)
case EM_ARM:
{
sym_addr += addend;
sym_addr -= SUFFIX (entry_point);
switch (ELF_R_TYPE (info))
{
case R_ARM_ABS32:
{
grub_util_info (" ABS32:\toffset=%d\t(0x%08x)",
(int) sym_addr, (int) sym_addr);
/* Data will be naturally aligned */
// sym_addr -= offset;
sym_addr += 0x400;
*target = grub_host_to_target32 (grub_target_to_host32 (*target) + sym_addr);
}
break;
case R_ARM_THM_CALL:
case R_ARM_THM_JUMP24:
{
grub_util_info (" THM_JUMP24:\ttarget=0x%08x\toffset=(0x%08x)", (unsigned int) target, sym_addr);
sym_addr -= offset;
/* Thumb instructions can be 16-bit aligned */
reloc_thm_call ((grub_uint16_t *) target, sym_addr);
}
break;
case R_ARM_THM_JUMP19:
{
grub_util_info (" THM_JUMP19:\toffset=%d\t(0x%08x)",
sym_addr, sym_addr);
sym_addr -= offset;
/* Thumb instructions can be 16-bit aligned */
reloc_thm_jump19 ((grub_uint16_t *) target, sym_addr);
}
break;
default:
grub_util_error (_("relocation 0x%x is not implemented yet!"), ELF_R_TYPE (info));
break;
}
break;
}
#endif /* MKIMAGE_ELF32 */
default:
grub_util_error ("unknown architecture type %d",
image_target->elf_target);
@ -755,6 +802,46 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out,
break;
}
break;
#if defined(MKIMAGE_ELF32)
case EM_ARM:
switch (ELF_R_TYPE (info))
{
/* Relative relocations do not require fixup entries. */
case R_ARM_JUMP24:
case R_ARM_THM_CALL:
case R_ARM_THM_JUMP19:
case R_ARM_THM_JUMP24:
{
Elf_Addr addr;
addr = section_address + offset;
grub_util_info (" %s: not adding fixup: 0x%08x : 0x%08x", __FUNCTION__, (unsigned int) addr, (unsigned int) current_address);
}
break;
/* Create fixup entry for PE/COFF loader */
case R_ARM_ABS32:
{
Elf_Addr addr;
addr = section_address + offset;
#if 0
grub_util_info (" %s: add_fixup: 0x%08x : 0x%08x",
__FUNCTION__, (unsigned int) addr,
(unsigned int) current_address);
#endif
current_address
= SUFFIX (add_fixup_entry) (&lst,
GRUB_PE32_REL_BASED_HIGHLOW,
addr, 0, current_address,
image_target);
}
break;
default:
grub_util_error (_("relocation 0x%x is not implemented yet2"), ELF_R_TYPE (info));
break;
}
break;
#endif /* defined(MKIMAGE_ELF32) */
default:
grub_util_error ("unknown machine type 0x%x", image_target->elf_target);
}
@ -1065,6 +1152,8 @@ SUFFIX (load_image) (const char *kernel_path, grub_size_t *exec_size,
if (*start == 0)
grub_util_error ("start symbol is not defined");
SUFFIX (entry_point) = (Elf_Addr) *start;
/* Resolve addresses in the virtual address space. */
SUFFIX (relocate_addresses) (e, sections, section_addresses,
section_entsize,