2 ** Copyright 2002-2004, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
5 #include <kernel/kernel.h>
6 #include <kernel/debug.h>
7 #include <kernel/elf.h>
8 #include <newos/elf32.h>
9 #include <kernel/arch/elf.h>
13 int arch_elf_relocate_rel(struct elf_image_info
*image
, const char *sym_prepend
,
14 struct elf_image_info
*resolve_image
, struct Elf32_Rel
*rel
, int rel_len
)
16 // there are no rel entries in PPC elf
20 int arch_elf_relocate_rela(struct elf_image_info
*image
, const char *sym_prepend
,
21 struct elf_image_info
*resolve_image
, struct Elf32_Rela
*rel
, int rel_len
)
24 struct Elf32_Sym
*sym
;
29 #define P ((addr_t)(image->regions[0].delta + rel[i].r_offset))
30 #define A ((addr_t)rel[i].r_addend)
31 #define B (image->regions[0].delta)
33 for(i
= 0; i
* (int)sizeof(struct Elf32_Rela
) < rel_len
; i
++) {
35 dprintf("looking at rel type %d, offset 0x%x, sym 0x%x, addend 0x%x\n",
36 ELF32_R_TYPE(rel
[i
].r_info
), rel
[i
].r_offset
, ELF32_R_SYM(rel
[i
].r_info
), rel
[i
].r_addend
);
38 switch(ELF32_R_TYPE(rel
[i
].r_info
)) {
46 sym
= SYMBOL(image
, ELF32_R_SYM(rel
[i
].r_info
));
48 vlErr
= elf_resolve_symbol(image
, sym
, resolve_image
, sym_prepend
, &S
);
54 switch(ELF32_R_TYPE(rel
[i
].r_info
)) {
67 *(Elf32_Half
*)P
= S
& 0xffff;
71 *(Elf32_Half
*)P
= (S
>> 16) & 0xffff;
75 *(Elf32_Half
*)P
= ((S
>> 16) + ((S
& 0x8000) ? 1 : 0)) & 0xFFFF;
79 final_val
= (*(Elf32_Word
*)P
& 0xff000003) | ((S
+ A
- P
) & 0x3fffffc);
87 panic("arch_elf_relocate_rela: unhandled relocation type %d\n", ELF32_R_TYPE(rel
[i
].r_info
));
91 dprintf("going to put 0x%x at 0x%x\n", final_val
, P
);
93 *(addr_t
*)P
= final_val
;