1 | |
---|
2 | #include <sys/cdefs.h> |
---|
3 | |
---|
4 | #include <errno.h> |
---|
5 | #include <stdio.h> |
---|
6 | #include <sys/types.h> |
---|
7 | #include <sys/stat.h> |
---|
8 | |
---|
9 | #include <rtems/rtl/rtl.h> |
---|
10 | #include "rtl-elf.h" |
---|
11 | #include "rtl-error.h" |
---|
12 | #include "rtl-trace.h" |
---|
13 | |
---|
14 | bool |
---|
15 | rtems_rtl_elf_rel_resolve_sym (Elf_Word type) |
---|
16 | { |
---|
17 | return true; |
---|
18 | } |
---|
19 | |
---|
20 | bool |
---|
21 | rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t* obj, |
---|
22 | const Elf_Rela* rela, |
---|
23 | const rtems_rtl_obj_sect_t* sect, |
---|
24 | const char* symname, |
---|
25 | const Elf_Byte syminfo, |
---|
26 | const Elf_Word symvalue) |
---|
27 | { |
---|
28 | Elf_Addr *where; |
---|
29 | Elf_Sword tmp; |
---|
30 | |
---|
31 | where = (Elf_Addr *)(sect->base + rela->r_offset); |
---|
32 | |
---|
33 | /* Handle the not 4byte aligned address carefully */ |
---|
34 | |
---|
35 | switch (ELF_R_TYPE(rela->r_info)) { |
---|
36 | case R_TYPE(NONE): |
---|
37 | break; |
---|
38 | |
---|
39 | case R_TYPE(32): |
---|
40 | *(uint16_t *)where = ((symvalue + rela->r_addend) >> 16) & 0xffff; |
---|
41 | *((uint16_t *)where + 1) = (symvalue + rela->r_addend) & 0xffff; |
---|
42 | |
---|
43 | if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) { |
---|
44 | printf("*where 0x%04x%04x\n", *((uint16_t *)where + 1), *(uint16_t *)where); |
---|
45 | } |
---|
46 | break; |
---|
47 | |
---|
48 | case R_TYPE(PCREL10): |
---|
49 | /* beq, bge, bgeu, bgt, bgtu, ble, bleu, blt, bltu, bne */ |
---|
50 | if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) { |
---|
51 | printf("*where %x\n", *(uint16_t *)where); |
---|
52 | printf("symvalue - where %x\n", (int)(symvalue - (Elf_Word)where)); |
---|
53 | } |
---|
54 | tmp = (symvalue + rela->r_addend - ((Elf_Word)where + 2)); /* pc is the next instruction */ |
---|
55 | tmp = (Elf_Sword)tmp >> 1; |
---|
56 | if (((Elf32_Sword)tmp > 0x1ff) || ((Elf32_Sword)tmp < -(Elf32_Sword)0x200)){ |
---|
57 | printf("Overflow for PCREL10: %d exceed -0x200:0x1ff\n", tmp); |
---|
58 | return false; |
---|
59 | } |
---|
60 | |
---|
61 | *(uint16_t *)where = (*(uint16_t *)where & 0xfc00) | (tmp & 0x3ff); |
---|
62 | |
---|
63 | if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) { |
---|
64 | printf("*where 0x%04x\n", *(uint16_t *)where); |
---|
65 | } |
---|
66 | |
---|
67 | break; |
---|
68 | |
---|
69 | default: |
---|
70 | rtems_rtl_set_error (EINVAL, "rela type record not supported"); |
---|
71 | printf("Unsupported reloc types\n"); |
---|
72 | return false; |
---|
73 | } |
---|
74 | |
---|
75 | return true; |
---|
76 | } |
---|
77 | |
---|
78 | bool |
---|
79 | rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj, |
---|
80 | const Elf_Rel* rel, |
---|
81 | const rtems_rtl_obj_sect_t* sect, |
---|
82 | const char* symname, |
---|
83 | const Elf_Byte syminfo, |
---|
84 | const Elf_Word symvalue) |
---|
85 | { |
---|
86 | rtems_rtl_set_error (EINVAL, "rel type record not supported"); |
---|
87 | return false; |
---|
88 | } |
---|