annotate arm7dis/armdis.c @ 88:691551f0635b

armdis: implemented decoding of data processing instructions
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 29 Mar 2014 20:28:13 +0000
parents f7fba8518fa2
children c5d52666d2eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
86
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 #include <sys/types.h>
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 #include <stdio.h>
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 #include <stdlib.h>
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 extern char *binfilename;
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 extern u_char *filemap;
87
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
7 extern unsigned disasm_len, base_vma;
86
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 extern unsigned get_u16(), get_u32();
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10
87
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
11 extern char *regnames[16], *condition_decode[16];
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
12
88
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
13 static char *dataproc_ops[16] = {"and", "eor", "sub", "rsb",
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
14 "add", "adc", "sbc", "rsc",
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
15 "tst", "teq", "cmp", "cmn",
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
16 "orr", "mov", "bic", "mvn"};
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
17 static char *shift_types[4] = {"lsl", "lsr", "asr", "ror"};
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
18
87
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
19 static void
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
20 arm_branch(off, word)
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
21 unsigned off, word;
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
22 {
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
23 unsigned dest;
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
24
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
25 dest = (word & 0x00FFFFFF) << 2;
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
26 if (dest & 0x02000000)
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
27 dest |= 0xFC000000;
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
28 dest += base_vma + off + 8;
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
29 printf("b%s%s\t0x%x\n", word&0x1000000 ? "l" : "",
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
30 condition_decode[word>>28], dest);
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
31 }
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
32
88
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
33 static void
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
34 op2_immed(word)
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
35 unsigned word;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
36 {
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
37 unsigned low8, rot, val;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
38
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
39 low8 = word & 0xFF;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
40 rot = (word & 0xF00) >> 7;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
41 val = (low8 << (32 - rot)) | (low8 >> rot);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
42 if (val <= 9)
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
43 printf("#%u\n", val);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
44 else
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
45 printf("#%u\t; 0x%x\n", val, val);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
46 }
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
47
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
48 static void
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
49 op2_regbyconst(word)
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
50 unsigned word;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
51 {
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
52 unsigned c, t;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
53
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
54 c = (word >> 7) & 0x1F;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
55 t = (word >> 5) & 3;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
56 if (!c) {
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
57 switch (t) {
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
58 case 0:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
59 printf("%s\n", regnames[word&0xF]);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
60 return;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
61 case 3:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
62 printf("%s, rrx\n", regnames[word&0xF]);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
63 return;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
64 default:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
65 c = 32;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
66 }
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
67 }
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
68 printf("%s, %s #%u\n", regnames[word&0xF], shift_types[t], c);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
69 }
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
70
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
71 static void
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
72 op2_regbyreg(word)
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
73 unsigned word;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
74 {
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
75 printf("%s, %s %s\n", regnames[word&0xF], shift_types[(word>>5)&3],
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
76 regnames[(word>>8)&0xF]);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
77 }
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
78
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
79 static void
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
80 op2_regshift(word)
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
81 unsigned word;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
82 {
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
83 if (word & 0x10)
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
84 op2_regbyreg(word);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
85 else
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
86 op2_regbyconst(word);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
87 }
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
88
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
89 static void
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
90 dataproc_op2(word)
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
91 unsigned word;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
92 {
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
93 if (word & 0x02000000)
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
94 op2_immed(word);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
95 else
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
96 op2_regshift(word);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
97 }
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
98
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
99 static void
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
100 dataproc_74_overlay(off, word)
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
101 unsigned off, word;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
102 {
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
103 printf("<dataproc overlay with 7&4 set>\n");
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
104 }
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
105
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
106 static void
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
107 dataproc_tstcmp_overlay(off, word)
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
108 unsigned off, word;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
109 {
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
110 printf("<dataproc overlay with S=0 for tst/cmp>\n");
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
111 }
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
112
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
113 static void
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
114 dataproc(off, word)
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
115 unsigned off, word;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
116 {
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
117 unsigned opc;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
118
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
119 opc = (word >> 21) & 0xF;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
120 switch (opc) {
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
121 case 0:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
122 case 1:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
123 case 2:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
124 case 3:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
125 case 4:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
126 case 5:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
127 case 6:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
128 case 7:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
129 case 0xC:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
130 case 0xE:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
131 printf("%s%s%s\t%s, %s, ", dataproc_ops[opc],
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
132 condition_decode[word>>28], word&0x100000 ? "s" : "",
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
133 regnames[(word>>12)&0xF], regnames[(word>>16)&0xF]);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
134 dataproc_op2(word);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
135 return;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
136 case 0xD:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
137 case 0xF:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
138 printf("%s%s%s\t%s, ", dataproc_ops[opc],
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
139 condition_decode[word>>28], word&0x100000 ? "s" : "",
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
140 regnames[(word>>12)&0xF]);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
141 dataproc_op2(word);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
142 return;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
143 case 8:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
144 case 9:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
145 case 0xA:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
146 case 0xB:
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
147 if (word & 0x100000) {
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
148 printf("%s%s\t%s, ", dataproc_ops[opc],
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
149 condition_decode[word>>28],
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
150 regnames[(word>>16)&0xF]);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
151 dataproc_op2(word);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
152 } else
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
153 dataproc_tstcmp_overlay(off, word);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
154 return;
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
155 }
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
156 }
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
157
86
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158 void
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 arm_disasm_line(off)
87
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
160 unsigned off;
86
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 {
87
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
162 unsigned word;
86
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 word = get_u32(filemap + off);
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 printf("%8x:\t%08x\t", base_vma + off, word);
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166 if ((word >> 28) == 0xF) {
87
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
167 printf("invalid-F\n");
86
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 return;
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
169 }
87
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
170 switch ((word >> 24) & 0xF) {
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
171 case 0:
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
172 case 1:
88
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
173 if ((word & 0x90) == 0x90)
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
174 dataproc_74_overlay(off, word);
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
175 else
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
176 dataproc(off, word);
87
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
177 return;
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
178 case 2:
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
179 case 3:
88
691551f0635b armdis: implemented decoding of data processing instructions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 87
diff changeset
180 dataproc(off, word);
87
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
181 return;
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
182 case 4:
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
183 case 5:
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
184 printf("<ldr/str, immediate offset>\n");
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
185 return;
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
186 case 6:
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
187 case 7:
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
188 printf("<ldr/str, register offset>\n");
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
189 return;
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
190 case 8:
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
191 case 9:
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
192 printf("<ldm/stm>\n");
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
193 return;
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
194 case 0xA:
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
195 case 0xB:
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
196 arm_branch(off, word);
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
197 return;
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
198 case 0xC:
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
199 case 0xD:
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
200 case 0xE:
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
201 printf("<COPROCESSOR>\n");
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
202 return;
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
203 case 0xF:
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
204 printf("swi%s\t0x%x\n", condition_decode[word>>28],
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
205 word & 0xFFFFFF);
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
206 return;
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
207 }
86
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
208 }
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
209
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
210 main(argc, argv)
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
211 char **argv;
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
212 {
87
f7fba8518fa2 armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 86
diff changeset
213 unsigned off;
86
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
214
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
215 common_init(argc, argv, 4);
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
216 for (off = 0; off < disasm_len; off += 4)
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
217 arm_disasm_line(off);
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
218 exit(0);
537cf2245d98 beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
219 }