Consolidate all relocations in relocate_section
[tinycc.git] / c67-link.c
blobd8b0f7e882b07d563bd0dae91c472d64865bb42d
1 #include "tcc.h"
2 #define HAVE_SECTION_RELOC
4 void relocate_init(Section *sr) {}
6 void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)
8 switch(type) {
9 case R_C60_32:
10 *(int *)ptr += val;
11 break;
12 case R_C60LO16:
14 uint32_t orig;
16 /* put the low 16 bits of the absolute address add to what is
17 already there */
18 orig = ((*(int *)(ptr )) >> 7) & 0xffff;
19 orig |= (((*(int *)(ptr+4)) >> 7) & 0xffff) << 16;
21 /* patch both at once - assumes always in pairs Low - High */
22 *(int *) ptr = (*(int *) ptr & (~(0xffff << 7)) ) |
23 (((val+orig) & 0xffff) << 7);
24 *(int *)(ptr+4) = (*(int *)(ptr+4) & (~(0xffff << 7)) ) |
25 ((((val+orig)>>16) & 0xffff) << 7);
27 break;
28 case R_C60HI16:
29 break;
30 default:
31 fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n",
32 type, (unsigned) addr, ptr, (unsigned) val);
33 break;