changeset 113:d97fbe98600b

tiobjd: recognizing relocs in ldr literals
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 03 Apr 2014 06:20:06 +0000
parents 61a58677dc68
children ca8e43288836
files ticoff/armdis.c ticoff/reloc.c ticoff/thumbdis.c
diffstat 3 files changed, 40 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ticoff/armdis.c	Thu Apr 03 05:54:59 2014 +0000
+++ b/ticoff/armdis.c	Thu Apr 03 06:20:06 2014 +0000
@@ -11,6 +11,7 @@
 #include "globals.h"
 
 extern unsigned get_u16(), get_u32();
+extern struct internal_reloc *find_reloc();
 
 extern char *regnames[16], *condition_decode[16], *shift_types[4];
 
@@ -220,6 +221,7 @@
 	unsigned off, word, loff;
 {
 	unsigned litoff, datum;
+	struct internal_reloc *rel;
 
 	/* base reg must be 15 */
 	if (((word >> 16) & 0xF) != 15)
@@ -245,6 +247,7 @@
 	if (litoff >= sec->size)
 		return(0);
 	/* all checks passed, proceed */
+	rel = find_reloc(sec, litoff);
 	switch (size) {
 	case 1:
 		datum = filemap[sec->data_offset + litoff];
@@ -256,7 +259,12 @@
 		datum = get_u32(filemap + sec->data_offset + litoff);
 		break;
 	}
-	printf("=0x%x\t; via 0x%x\n", datum, litoff);
+	putchar('=');
+	if (rel)
+		disasm_reloc_target(sec, rel, datum);
+	else
+		printf("0x%x", datum);
+	printf("\t; via 0x%x\n", litoff);
 	return(1);
 }
 
--- a/ticoff/reloc.c	Thu Apr 03 05:54:59 2014 +0000
+++ b/ticoff/reloc.c	Thu Apr 03 06:20:06 2014 +0000
@@ -123,3 +123,21 @@
 	}
 	exit(0);
 }
+
+struct internal_reloc *
+find_reloc(sec, loc)
+	struct internal_scnhdr *sec;
+	unsigned loc;
+{
+	struct internal_reloc *rel;
+	unsigned m;
+
+	rel = sec->int_relocs;
+	for (m = 0; m < sec->nreloc; m++, rel++) {
+		if (rel->location == loc)
+			return(rel);
+		if (rel->location > loc)
+			return(0);
+	}
+	return(0);
+}
--- a/ticoff/thumbdis.c	Thu Apr 03 05:54:59 2014 +0000
+++ b/ticoff/thumbdis.c	Thu Apr 03 06:20:06 2014 +0000
@@ -11,6 +11,7 @@
 #include "globals.h"
 
 extern unsigned get_u16(), get_u32();
+extern struct internal_reloc *find_reloc();
 
 extern char *regnames[16], *condition_decode[16], *shift_types[4];
 
@@ -114,16 +115,23 @@
 	struct internal_scnhdr *sec;
 	unsigned off, word;
 {
-	unsigned loff, litoff;
+	unsigned loff, litoff, datum;
+	struct internal_reloc *rel;
 
 	loff = (word & 0xFF) << 2;
 	off &= ~3;
 	off += 4;
 	litoff = off + loff;
-	if (litoff+4 <= sec->size)
-		printf("ldr\t%s, =0x%x\t; via 0x%x\n", regnames[(word>>8)&7],
-			get_u32(filemap + sec->data_offset + litoff), litoff);
-	else
+	if (litoff+4 <= sec->size) {
+		rel = find_reloc(sec, litoff);
+		datum = get_u32(filemap + sec->data_offset + litoff);
+		printf("ldr\t%s, =", regnames[(word>>8)&7]);
+		if (rel)
+			disasm_reloc_target(sec, rel, datum);
+		else
+			printf("0x%x", datum);
+		printf("\t; via 0x%x\n", litoff);
+	} else
 		printf("ldr\t%s, [pc, #%u]\t(0x%x)\n", regnames[(word>>8)&7],
 			loff, litoff);
 }