aboutsummaryrefslogtreecommitdiff
path: root/c67-link.c
diff options
context:
space:
mode:
authorThomas Preud'homme <robotux@celest.fr>2016-11-12 23:16:06 +0800
committerThomas Preud'homme <robotux@celest.fr>2016-12-03 17:26:51 +0000
commitcb273fdad891d312c15110cd4eab95f5db39dcb2 (patch)
treeb5cfe985f0ba556bca2e1e6e278db51972c7b862 /c67-link.c
parent60374d01ae56e59308d1b5441bc1986295507ec6 (diff)
downloadtinycc-cb273fdad891d312c15110cd4eab95f5db39dcb2.tar.gz
tinycc-cb273fdad891d312c15110cd4eab95f5db39dcb2.tar.bz2
Do section relocation in architecture backend
Diffstat (limited to 'c67-link.c')
-rw-r--r--c67-link.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/c67-link.c b/c67-link.c
new file mode 100644
index 0000000..d8b0f7e
--- /dev/null
+++ b/c67-link.c
@@ -0,0 +1,35 @@
+#include "tcc.h"
+#define HAVE_SECTION_RELOC
+
+void relocate_init(Section *sr) {}
+
+void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)
+{
+ switch(type) {
+ case R_C60_32:
+ *(int *)ptr += val;
+ break;
+ case R_C60LO16:
+ {
+ uint32_t orig;
+
+ /* put the low 16 bits of the absolute address add to what is
+ already there */
+ orig = ((*(int *)(ptr )) >> 7) & 0xffff;
+ orig |= (((*(int *)(ptr+4)) >> 7) & 0xffff) << 16;
+
+ /* patch both at once - assumes always in pairs Low - High */
+ *(int *) ptr = (*(int *) ptr & (~(0xffff << 7)) ) |
+ (((val+orig) & 0xffff) << 7);
+ *(int *)(ptr+4) = (*(int *)(ptr+4) & (~(0xffff << 7)) ) |
+ ((((val+orig)>>16) & 0xffff) << 7);
+ }
+ break;
+ case R_C60HI16:
+ break;
+ default:
+ fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n",
+ type, (unsigned) addr, ptr, (unsigned) val);
+ break;
+ }
+}