Make kernel elf loaders usable by bootloader to factor them out of it.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22747 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol 2007-10-27 11:49:59 +00:00
parent d5f662106a
commit 0743882d32
2 changed files with 41 additions and 3 deletions

View File

@ -7,6 +7,9 @@
* Distributed under the terms of the NewOS License. * Distributed under the terms of the NewOS License.
*/ */
#ifdef _BOOT_MODE
#include <boot/arch.h>
#endif
#include <KernelExport.h> #include <KernelExport.h>
@ -16,10 +19,15 @@
#define CHATTY 0 #define CHATTY 0
#ifdef _BOOT_MODE
status_t
boot_arch_elf_relocate_rel(struct preloaded_image *image,
struct Elf32_Rel *rel, int rel_len)
#else
int int
arch_elf_relocate_rel(struct elf_image_info *image, const char *sym_prepend, arch_elf_relocate_rel(struct elf_image_info *image, const char *sym_prepend,
struct elf_image_info *resolve_image, struct Elf32_Rel *rel, int rel_len) struct elf_image_info *resolve_image, struct Elf32_Rel *rel, int rel_len)
#endif
{ {
// there are no rel entries in PPC elf // there are no rel entries in PPC elf
return B_NO_ERROR; return B_NO_ERROR;
@ -105,9 +113,15 @@ ha(Elf32_Word value)
} }
#ifdef _BOOT_MODE
status_t
boot_arch_elf_relocate_rela(struct preloaded_image *image,
struct Elf32_Rela *rel, int rel_len)
#else
int int
arch_elf_relocate_rela(struct elf_image_info *image, const char *sym_prepend, arch_elf_relocate_rela(struct elf_image_info *image, const char *sym_prepend,
struct elf_image_info *resolve_image, struct Elf32_Rela *rel, int rel_len) struct elf_image_info *resolve_image, struct Elf32_Rela *rel, int rel_len)
#endif
{ {
int i; int i;
struct Elf32_Sym *sym; struct Elf32_Sym *sym;
@ -172,12 +186,16 @@ arch_elf_relocate_rela(struct elf_image_info *image, const char *sym_prepend,
case R_PPC_JMP_SLOT: case R_PPC_JMP_SLOT:
sym = SYMBOL(image, ELF32_R_SYM(rel[i].r_info)); sym = SYMBOL(image, ELF32_R_SYM(rel[i].r_info));
#ifdef _BOOT_MODE
vlErr = boot_elf_resolve_symbol(image, sym, &S);
#else
vlErr = elf_resolve_symbol(image, sym, resolve_image, vlErr = elf_resolve_symbol(image, sym, resolve_image,
sym_prepend, &S); sym_prepend, &S);
#endif
if (vlErr < 0) { if (vlErr < 0) {
dprintf("arch_elf_relocate_rela(): Failed to relocate " dprintf("%s(): Failed to relocate "
"entry index %d, rel type %d, offset 0x%lx, sym 0x%lx, " "entry index %d, rel type %d, offset 0x%lx, sym 0x%lx, "
"addend 0x%lx\n", i, ELF32_R_TYPE(rel[i].r_info), "addend 0x%lx\n", __FUNCTION__, i, ELF32_R_TYPE(rel[i].r_info),
rel[i].r_offset, ELF32_R_SYM(rel[i].r_info), rel[i].r_offset, ELF32_R_SYM(rel[i].r_info),
rel[i].r_addend); rel[i].r_addend);
return vlErr; return vlErr;

View File

@ -4,6 +4,10 @@
*/ */
#ifdef _BOOT_MODE
#include <boot/arch.h>
#endif
#include <KernelExport.h> #include <KernelExport.h>
#include <elf_priv.h> #include <elf_priv.h>
@ -35,9 +39,15 @@ static const char *kRelocations[] = {
#endif #endif
#ifdef _BOOT_MODE
status_t
boot_arch_elf_relocate_rel(struct preloaded_image *image,
struct Elf32_Rel *rel, int rel_len)
#else
int int
arch_elf_relocate_rel(struct elf_image_info *image, const char *sym_prepend, arch_elf_relocate_rel(struct elf_image_info *image, const char *sym_prepend,
struct elf_image_info *resolve_image, struct Elf32_Rel *rel, int rel_len) struct elf_image_info *resolve_image, struct Elf32_Rel *rel, int rel_len)
#endif
{ {
struct Elf32_Sym *sym; struct Elf32_Sym *sym;
addr_t S; addr_t S;
@ -63,7 +73,11 @@ arch_elf_relocate_rel(struct elf_image_info *image, const char *sym_prepend,
sym = SYMBOL(image, ELF32_R_SYM(rel[i].r_info)); sym = SYMBOL(image, ELF32_R_SYM(rel[i].r_info));
#ifdef _BOOT_MODE
vlErr = boot_elf_resolve_symbol(image, sym, &S);
#else
vlErr = elf_resolve_symbol(image, sym, resolve_image, sym_prepend, &S); vlErr = elf_resolve_symbol(image, sym, resolve_image, sym_prepend, &S);
#endif
if (vlErr < 0) if (vlErr < 0)
return vlErr; return vlErr;
TRACE(("S %p (%s)\n", (void *)S, SYMNAME(image, sym))); TRACE(("S %p (%s)\n", (void *)S, SYMNAME(image, sym)));
@ -123,9 +137,15 @@ arch_elf_relocate_rel(struct elf_image_info *image, const char *sym_prepend,
} }
#ifdef _BOOT_MODE
status_t
boot_arch_elf_relocate_rela(struct preloaded_image *image,
struct Elf32_Rela *rel, int rel_len)
#else
int int
arch_elf_relocate_rela(struct elf_image_info *image, const char *sym_prepend, arch_elf_relocate_rela(struct elf_image_info *image, const char *sym_prepend,
struct elf_image_info *resolve_image, struct Elf32_Rela *rel, int rel_len) struct elf_image_info *resolve_image, struct Elf32_Rela *rel, int rel_len)
#endif
{ {
dprintf("arch_elf_relocate_rela: not supported on x86\n"); dprintf("arch_elf_relocate_rela: not supported on x86\n");
return B_ERROR; return B_ERROR;