40 #include "loader/elf32.h"
41 #include "loader/cle.h"
44 #include "lib/assert.h"
47 #define PRINTF(...) do {} while (0)
49 #define PRINTF(...) printf(__VA_ARGS__)
54 #define R_AVR_7_PCREL 2
55 #define R_AVR_13_PCREL 3
58 #define R_AVR_LO8_LDI 6
59 #define R_AVR_HI8_LDI 7
60 #define R_AVR_HH8_LDI 8
61 #define R_AVR_LO8_LDI_NEG 9
62 #define R_AVR_HI8_LDI_NEG 10
63 #define R_AVR_HH8_LDI_NEG 11
64 #define R_AVR_LO8_LDI_PM 12
65 #define R_AVR_HI8_LDI_PM 13
66 #define R_AVR_HH8_LDI_PM 14
67 #define R_AVR_LO8_LDI_PM_NEG 15
68 #define R_AVR_HI8_LDI_PM_NEG 16
69 #define R_AVR_HH8_LDI_PM_NEG 17
77 cle_write_reloc(
void *pos_,
78 const struct elf32_rela *rela,
80 const struct cle_info *info)
82 unsigned char *pos = pos_;
85 switch(ELF32_R_TYPE(rela->r_info)) {
87 PRINTF(
"cle_upd_reloc: unsupported relocation type: %d\n",
88 ELF32_R_TYPE(rela->r_info));
89 return CLE_UNKNOWN_RELOC;
93 byte = addr - ( + rela->r_offset + 2);
95 pos[0] = (pos[0] & 0x07) | (byte << 3);
96 pos[1] = (pos[1] & 0xfc) | (byte >> 5);
101 addr = addr - (info->text + rela->r_offset + 2);
104 pos[1] = (pos[1] & 0xf0) | ((addr >> 8) & 0x0f);
139 case R_AVR_LO8_LDI_NEG:
143 case R_AVR_HI8_LDI_NEG:
147 case R_AVR_HH8_LDI_NEG:
148 byte = (-addr) >> 16;
151 case R_AVR_LO8_LDI_PM:
155 case R_AVR_HI8_LDI_PM:
159 case R_AVR_HH8_LDI_PM:
163 case R_AVR_LO8_LDI_PM_NEG:
167 case R_AVR_HI8_LDI_PM_NEG:
171 case R_AVR_HH8_LDI_PM_NEG:
172 byte = (-addr) >> 17;
176 pos[0] = (pos[0] & 0xf0) | (byte & 0x0f);
177 pos[1] = (pos[1] & 0xf0) | (byte >> 4);