# HG changeset patch # User Michael Spacefalcon # Date 1395990087 0 # Node ID 537cf2245d985918427a2a9ad1890f5cbfbdb11c # Parent 3c420895f68f2ed15f9ff5eeb972c616a4a58d7e beginning of ARM7 disassembler diff -r 3c420895f68f -r 537cf2245d98 arm7dis/armdis.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/arm7dis/armdis.c Fri Mar 28 07:01:27 2014 +0000 @@ -0,0 +1,36 @@ +#include +#include +#include + +extern char *binfilename; +extern u_char *filemap; +extern u_long disasm_len, base_vma; + +extern unsigned get_u16(), get_u32(); + +void +arm_disasm_line(off) + u_long off; +{ + u_long word; + + word = get_u32(filemap + off); + printf("%8x:\t%08x\t", base_vma + off, word); + if ((word >> 28) == 0xF) { + printf("invalid\n"); + return; + } + + +} + +main(argc, argv) + char **argv; +{ + u_long off; + + common_init(argc, argv, 4); + for (off = 0; off < disasm_len; off += 4) + arm_disasm_line(off); + exit(0); +} diff -r 3c420895f68f -r 537cf2245d98 arm7dis/common.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/arm7dis/common.c Fri Mar 28 07:01:27 2014 +0000 @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include +#include +#include + +char *binfilename; +u_char *filemap; +u_long disasm_len, base_vma; + +common_init(argc, argv, instr_size) + char **argv; +{ + int fd; + struct stat st; + u_long fileoff; + + if (argc < 2 || argc > 5) { + fprintf(stderr, + "usage: %s binfile [file-offset [len [vaddr]]]\n", + argv[0]); + exit(1); + } + binfilename = argv[1]; + fd = open(binfilename, O_RDONLY); + if (fd < 0) { + perror(binfilename); + exit(1); + } + fstat(fd, &st); + if (!S_ISREG(st.st_mode)) { + fprintf(stderr, "error: %s is not a regular file\n", + binfilename); + exit(1); + } + if (argc > 2) + fileoff = strtoul(argv[2], 0, 0); + else + fileoff = 0; + if (fileoff > st.st_size) { + fprintf(stderr, + "error: specified file offset is past the end of file\n"); + exit(1); + } + if (argc > 3) { + disasm_len = strtoul(argv[3], 0, 0); + if (disasm_len > st.st_size - fileoff) { + fprintf(stderr, + "error: specified length is past the end of file\n"); + exit(1); + } + } else + disasm_len = st.st_size - fileoff; + if (disasm_len & (instr_size - 1)) { + fprintf(stderr, +"error: length of region to be disassembled must be a multiple of %d bytes\n", + instr_size); + exit(1); + } + filemap = mmap(NULL, disasm_len, PROT_READ, MAP_PRIVATE, fd, fileoff); + if (filemap == MAP_FAILED) { + perror("mmap"); + exit(1); + } + close(fd); + if (argc > 4) + base_vma = strtoul(argv[4], 0, 0); + else + base_vma = fileoff; + return(0); +} + +unsigned +get_u16(ptr) + u_char *ptr; +{ + return ptr[0] | ptr[1] << 8; +} + +unsigned +get_u32(ptr) + u_char *ptr; +{ + return ptr[0] | ptr[1] << 8 | ptr[2] << 16 | ptr[3] << 24; +}