comparison arm7dis/armdis.c @ 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
comparison
equal deleted inserted replaced
86:537cf2245d98 87:f7fba8518fa2
2 #include <stdio.h> 2 #include <stdio.h>
3 #include <stdlib.h> 3 #include <stdlib.h>
4 4
5 extern char *binfilename; 5 extern char *binfilename;
6 extern u_char *filemap; 6 extern u_char *filemap;
7 extern u_long disasm_len, base_vma; 7 extern unsigned disasm_len, base_vma;
8 8
9 extern unsigned get_u16(), get_u32(); 9 extern unsigned get_u16(), get_u32();
10 10
11 extern char *regnames[16], *condition_decode[16];
12
13 static void
14 arm_branch(off, word)
15 unsigned off, word;
16 {
17 unsigned dest;
18
19 dest = (word & 0x00FFFFFF) << 2;
20 if (dest & 0x02000000)
21 dest |= 0xFC000000;
22 dest += base_vma + off + 8;
23 printf("b%s%s\t0x%x\n", word&0x1000000 ? "l" : "",
24 condition_decode[word>>28], dest);
25 }
26
11 void 27 void
12 arm_disasm_line(off) 28 arm_disasm_line(off)
13 u_long off; 29 unsigned off;
14 { 30 {
15 u_long word; 31 unsigned word;
16 32
17 word = get_u32(filemap + off); 33 word = get_u32(filemap + off);
18 printf("%8x:\t%08x\t", base_vma + off, word); 34 printf("%8x:\t%08x\t", base_vma + off, word);
19 if ((word >> 28) == 0xF) { 35 if ((word >> 28) == 0xF) {
20 printf("invalid\n"); 36 printf("invalid-F\n");
21 return; 37 return;
22 } 38 }
23 39 switch ((word >> 24) & 0xF) {
24 40 case 0:
41 case 1:
42 printf("<data processing, register operand>\n");
43 return;
44 case 2:
45 case 3:
46 printf("<data processing, immediate operand>\n");
47 return;
48 case 4:
49 case 5:
50 printf("<ldr/str, immediate offset>\n");
51 return;
52 case 6:
53 case 7:
54 printf("<ldr/str, register offset>\n");
55 return;
56 case 8:
57 case 9:
58 printf("<ldm/stm>\n");
59 return;
60 case 0xA:
61 case 0xB:
62 arm_branch(off, word);
63 return;
64 case 0xC:
65 case 0xD:
66 case 0xE:
67 printf("<COPROCESSOR>\n");
68 return;
69 case 0xF:
70 printf("swi%s\t0x%x\n", condition_decode[word>>28],
71 word & 0xFFFFFF);
72 return;
73 }
25 } 74 }
26 75
27 main(argc, argv) 76 main(argc, argv)
28 char **argv; 77 char **argv;
29 { 78 {
30 u_long off; 79 unsigned off;
31 80
32 common_init(argc, argv, 4); 81 common_init(argc, argv, 4);
33 for (off = 0; off < disasm_len; off += 4) 82 for (off = 0; off < disasm_len; off += 4)
34 arm_disasm_line(off); 83 arm_disasm_line(off);
35 exit(0); 84 exit(0);