From 0743882d3276a11c1cf21d99ea444946cd05bec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Sat, 27 Oct 2007 11:49:59 +0000 Subject: [PATCH] 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 --- src/system/kernel/arch/ppc/arch_elf.cpp | 24 +++++++++++++++++++++--- src/system/kernel/arch/x86/arch_elf.c | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/system/kernel/arch/ppc/arch_elf.cpp b/src/system/kernel/arch/ppc/arch_elf.cpp index e45492de24..2217b39403 100644 --- a/src/system/kernel/arch/ppc/arch_elf.cpp +++ b/src/system/kernel/arch/ppc/arch_elf.cpp @@ -7,6 +7,9 @@ * Distributed under the terms of the NewOS License. */ +#ifdef _BOOT_MODE +#include +#endif #include @@ -16,10 +19,15 @@ #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 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) +#endif { // there are no rel entries in PPC elf 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 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) +#endif { int i; 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: 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); +#endif 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, " - "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_addend); return vlErr; diff --git a/src/system/kernel/arch/x86/arch_elf.c b/src/system/kernel/arch/x86/arch_elf.c index 6b7d31f629..93946eeb0c 100644 --- a/src/system/kernel/arch/x86/arch_elf.c +++ b/src/system/kernel/arch/x86/arch_elf.c @@ -4,6 +4,10 @@ */ +#ifdef _BOOT_MODE +#include +#endif + #include #include @@ -35,9 +39,15 @@ static const char *kRelocations[] = { #endif +#ifdef _BOOT_MODE +status_t +boot_arch_elf_relocate_rel(struct preloaded_image *image, + struct Elf32_Rel *rel, int rel_len) +#else int 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) +#endif { struct Elf32_Sym *sym; 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)); +#ifdef _BOOT_MODE + vlErr = boot_elf_resolve_symbol(image, sym, &S); +#else vlErr = elf_resolve_symbol(image, sym, resolve_image, sym_prepend, &S); +#endif if (vlErr < 0) return vlErr; 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 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) +#endif { dprintf("arch_elf_relocate_rela: not supported on x86\n"); return B_ERROR;