source: rtems/cpukit/libdl/rtl-mdreloc-bfin.c @ 3feb372

4.115
Last change on this file since 3feb372 was 1dc5b0e0, checked in by Joel Sherrill <joel.sherrill@…>, on 11/04/14 at 20:55:21

libdl/rtl-mdreloc-bfin.c: Include rtems/rtl/rtl.h not rtl.h

  • Property mode set to 100644
File size: 2.8 KB
Line 
1#include <sys/cdefs.h>
2
3#include <stdio.h>
4#include <rtems/rtl/rtl.h>
5#include <errno.h>
6#include "rtl-elf.h"
7#include "rtl-error.h"
8#include "rtl-trace.h"
9
10bool
11rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
12{
13  return true;
14}
15
16static inline Elf_Addr
17load_ptr(void *where)
18{
19        Elf_Addr res;
20
21        memcpy(&res, where, sizeof(res));
22
23        return (res);
24}
25
26bool
27rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t*      obj,
28                             const Elf_Rela*             rela,
29                             const rtems_rtl_obj_sect_t* sect,
30                             const char*                 symname,
31                             const Elf_Byte              syminfo,
32                             const Elf_Word              symvalue)
33{
34  Elf_Addr      target = 0;
35  Elf_Addr      *where;
36  Elf_Word      tmp;
37  Elf_Word      size; //byte
38
39  where = (Elf_Addr *)(sect->base + rela->r_offset);
40
41  if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
42      printf("rela relocation type is %d relocated address 0x%08x",
43              ELF_R_TYPE(rela->r_info), where);
44  }
45
46  tmp = symvalue;
47  switch (ELF_R_TYPE(rela->r_info)) {
48    case R_TYPE(UNUSED0):
49      break;
50
51    case R_TYPE(HUIMM16):
52      tmp = symvalue >> 16;
53    case R_TYPE(LUIMM16):
54    case R_TYPE(RIMM16):
55      size = 2;
56      break;
57
58    case R_TYPE(BYTE4_DATA):
59      size = 4;
60      break;
61
62    case R_TYPE(PCREL24):
63    case R_TYPE(PCREL24_JU):
64      where = (Elf_Addr*)((Elf_Addr)where - 2); /* Back 2 bytes */
65      tmp = symvalue - (Elf_Addr)where;
66      tmp >>= 1;
67      if ((tmp & 0x20000000) == 0x20000000)
68        tmp |= 0xc0000000;
69
70      if ((tmp & 0xff000000) && (~tmp & 0xff800000)) {
71        printf("PCREL24/PCREL24_JU Overflow\n");
72        return false;
73      }
74
75      tmp = (load_ptr(where) & 0x0000ff00) | ((tmp & 0x0000ffff) << 16) |
76             ((tmp & 0x00ff0000) >> 16);
77      size = 4;
78      break;
79
80    case R_TYPE(PCREL12_JUMP_S):
81      tmp = symvalue - (Elf_Addr)where;
82      tmp >>= 1;
83      if ((tmp & 0x20000000) == 0x20000000)
84        tmp |= 0xc0000000;
85
86      if ((tmp & 0xfffff000) && (~tmp & 0xfffff800)) {
87        printf("PCREL12_JUMP_S Overflow\n");
88        return false;
89      }
90
91      tmp = ((*(uint16_t *)where) & 0xf000) | (tmp & 0xfff);
92      size = 2;
93      break;
94
95    default:
96      printf("Unspported rela type\n");
97      return false;
98  }
99
100  memcpy((void*)where, &tmp, size);
101
102  return true;
103}
104
105bool
106rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t*      obj,
107                            const Elf_Rel*              rel,
108                            const rtems_rtl_obj_sect_t* sect,
109                            const char*                 symname,
110                            const Elf_Byte              syminfo,
111                            const Elf_Word              symvalue)
112{
113  rtems_rtl_set_error (EINVAL, "rel type record not supported");
114  return false;
115}
Note: See TracBrowser for help on using the repository browser.