changeset 87:f7fba8518fa2

armdis: skeleton compiles
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 29 Mar 2014 00:23:16 +0000
parents 537cf2245d98
children 691551f0635b
files .hgignore arm7dis/Makefile arm7dis/armdis.c arm7dis/atcommon.c arm7dis/common.c
diffstat 5 files changed, 82 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Mar 28 07:01:27 2014 +0000
+++ b/.hgignore	Sat Mar 29 00:23:16 2014 +0000
@@ -9,6 +9,8 @@
 ^pirimei$
 ^rfcap-grep$
 
+^arm7dis/armdis$
+
 ^mpffs/mpffs-cat$
 ^mpffs/mpffs-dbgls$
 ^mpffs/mpffs-ls$
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/arm7dis/Makefile	Sat Mar 29 00:23:16 2014 +0000
@@ -0,0 +1,13 @@
+CC=	gcc
+CFLAGS=	-O2
+PROGS=	armdis
+ARMDIS_OBJS=	armdis.o atcommon.o common.o
+INSTDIR=/usr/local/bin
+
+all:	${PROGS}
+
+armdis:	${ARMDIS_OBJS}
+	${CC} -o $@ ${ARMDIS_OBJS}
+
+clean:
+	rm -f *.o ${PROGS} *errs
--- a/arm7dis/armdis.c	Fri Mar 28 07:01:27 2014 +0000
+++ b/arm7dis/armdis.c	Sat Mar 29 00:23:16 2014 +0000
@@ -4,30 +4,79 @@
 
 extern char *binfilename;
 extern u_char *filemap;
-extern u_long disasm_len, base_vma;
+extern unsigned disasm_len, base_vma;
 
 extern unsigned get_u16(), get_u32();
 
+extern char *regnames[16], *condition_decode[16];
+
+static void
+arm_branch(off, word)
+	unsigned off, word;
+{
+	unsigned dest;
+
+	dest = (word & 0x00FFFFFF) << 2;
+	if (dest & 0x02000000)
+		dest |= 0xFC000000;
+	dest += base_vma + off + 8;
+	printf("b%s%s\t0x%x\n", word&0x1000000 ? "l" : "",
+		condition_decode[word>>28], dest);
+}
+
 void
 arm_disasm_line(off)
-	u_long off;
+	unsigned off;
 {
-	u_long word;
+	unsigned word;
 
 	word = get_u32(filemap + off);
 	printf("%8x:\t%08x\t", base_vma + off, word);
 	if ((word >> 28) == 0xF) {
-		printf("invalid\n");
+		printf("invalid-F\n");
 		return;
 	}
-
-
+	switch ((word >> 24) & 0xF) {
+	case 0:
+	case 1:
+		printf("<data processing, register operand>\n");
+		return;
+	case 2:
+	case 3:
+		printf("<data processing, immediate operand>\n");
+		return;
+	case 4:
+	case 5:
+		printf("<ldr/str, immediate offset>\n");
+		return;
+	case 6:
+	case 7:
+		printf("<ldr/str, register offset>\n");
+		return;
+	case 8:
+	case 9:
+		printf("<ldm/stm>\n");
+		return;
+	case 0xA:
+	case 0xB:
+		arm_branch(off, word);
+		return;
+	case 0xC:
+	case 0xD:
+	case 0xE:
+		printf("<COPROCESSOR>\n");
+		return;
+	case 0xF:
+		printf("swi%s\t0x%x\n", condition_decode[word>>28],
+			word & 0xFFFFFF);
+		return;
+	}
 }
 
 main(argc, argv)
 	char **argv;
 {
-	u_long off;
+	unsigned off;
 
 	common_init(argc, argv, 4);
 	for (off = 0; off < disasm_len; off += 4)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/arm7dis/atcommon.c	Sat Mar 29 00:23:16 2014 +0000
@@ -0,0 +1,7 @@
+/* a few disassembly bits common between ARM and Thumb */
+
+char *regnames[16] = {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
+			"r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc"};
+
+char *condition_decode[16] = {"eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
+				"hi", "ls", "ge", "lt", "gt", "le", "", "INV"};
--- a/arm7dis/common.c	Fri Mar 28 07:01:27 2014 +0000
+++ b/arm7dis/common.c	Sat Mar 29 00:23:16 2014 +0000
@@ -8,14 +8,14 @@
 
 char *binfilename;
 u_char *filemap;
-u_long disasm_len, base_vma;
+unsigned disasm_len, base_vma;
 
 common_init(argc, argv, instr_size)
 	char **argv;
 {
 	int fd;
 	struct stat st;
-	u_long fileoff;
+	unsigned fileoff;
 
 	if (argc < 2 || argc > 5) {
 		fprintf(stderr,
@@ -59,7 +59,8 @@
 			instr_size);
 		exit(1);
 	}
-	filemap = mmap(NULL, disasm_len, PROT_READ, MAP_PRIVATE, fd, fileoff);
+	filemap = mmap(NULL, (size_t) disasm_len, PROT_READ, MAP_PRIVATE, fd,
+			(off_t) fileoff);
 	if (filemap == MAP_FAILED) {
 		perror("mmap");
 		exit(1);