changeset 117:f9fde7f36ae3

tiobjd: Thumb_BL reloc handling
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 03 Apr 2014 07:16:20 +0000
parents 5f4141ee175b
children 193926ccd1ec
files ticoff/disasm.c ticoff/thumbdis.c
diffstat 2 files changed, 32 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ticoff/disasm.c	Thu Apr 03 07:00:08 2014 +0000
+++ b/ticoff/disasm.c	Thu Apr 03 07:16:20 2014 +0000
@@ -136,8 +136,14 @@
 			   printf("MISALIGNED pos in CODE16 state, aborting\n");
 				return;
 			}
-			/* reloc handling to be added */
-			if (headroom >= 4 && thumb_check_bl(sec, pos))
+			if (rel) {
+				if (rel->type != RTYPE_THUMB_BL) {
+			printf("Wrong reloc type in CODE16 state, aborting\n");
+					return;
+				}
+				thumb_bl_reloc(sec, rel);
+				incr = 4;
+			} else if (headroom >= 4 && thumb_check_bl(sec, pos))
 				incr = 4;
 			else {
 				thumb_disasm_line(sec, pos);
--- a/ticoff/thumbdis.c	Thu Apr 03 07:00:08 2014 +0000
+++ b/ticoff/thumbdis.c	Thu Apr 03 07:16:20 2014 +0000
@@ -405,3 +405,27 @@
 	printf("%04x %04x\tbl\t0x%x\n", ins1, ins2, dest);
 	return(1);
 }
+
+void
+thumb_bl_reloc(sec, rel)
+	struct internal_scnhdr *sec;
+	struct internal_reloc *rel;
+{
+	unsigned ins1, ins2;
+	unsigned dest;
+
+	ins1 = get_u16(filemap + sec->data_offset + rel->location);
+	ins2 = get_u16(filemap + sec->data_offset + rel->location + 2);
+	printf("%04x %04x R\t", ins1, ins2);
+	if ((ins1 & 0xF800) != 0xF000 || (ins2 & 0xF800) != 0xF800) {
+		printf("<invalid Thumb_BL reloc: opcode not BL>\n");
+		return;
+	}
+	dest = ((ins1 & 0x7FF) << 12) | ((ins2 & 0x7FF) << 1);
+	if (dest & 0x00400000)
+		dest |= 0xFF800000;
+	dest += rel->location + 4;
+	fputs("bl\t", stdout);
+	disasm_reloc_target(sec, rel, dest);
+	putchar('\n');
+}