annotate arm7dis/thumbdis.c @ 97:fb5ea2758482

thumbdis written, compiles
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 30 Mar 2014 23:32:26 +0000
parents
children 78e4702884e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
97
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 #include <sys/types.h>
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 #include <stdio.h>
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 #include <stdlib.h>
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 #include <string.h>
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <strings.h>
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 extern char *binfilename;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 extern u_char *filemap;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 extern unsigned disasm_len, base_vma;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 extern unsigned get_u16(), get_u32();
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 extern char *regnames[16], *condition_decode[16], *shift_types[4];
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 format_1_2(word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 unsigned word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 unsigned op, imm;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 op = (word >> 11) & 3;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 if (op != 3) {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 /* format 1 */
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 imm = (word >> 6) & 0x1F;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 if (op != 0 && imm == 0)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 imm = 32;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 printf("%s\t%s, %s, #%u\n", shift_types[op], regnames[word&7],
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 regnames[(word>>3)&7], imm);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 /* format 2 */
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 printf("%s\t%s, %s, ", word&0x200 ? "sub" : "add", regnames[word&7],
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 regnames[(word>>3)&7]);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 if (word & 0x400)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 printf("#%u\n", (word >> 6) & 7);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 else
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 printf("%s\n", regnames[(word >> 6) & 7]);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 format_3(word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 unsigned word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 static char *opctab[4] = {"mov", "cmp", "add", "sub"};
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 unsigned imm;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 imm = word & 0xFF;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 printf("%s\t%s, #%u", opctab[(word>>11)&3], regnames[(word>>8)&7], imm);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 if (imm > 9)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 printf("\t; 0x%x", imm);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 putchar('\n');
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 format_4(word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 unsigned word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 static char *opc[16] = {"and", "eor", "lsl", "lsr",
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 "asr", "adc", "sbc", "ror",
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 "tst", "neg", "cmp", "cmn",
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 "orr", "mul", "bic", "mvn"};
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 printf("%s\t%s, %s\n", opc[(word>>6)&0xF], regnames[word&7],
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 regnames[(word>>3)&7]);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 format_5_bx(word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 unsigned word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 if (word & 0x80)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 printf("<invalid: blx instead of bx>\n");
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 else
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 printf("bx\t%s\n", regnames[(word>>3)&0xF]);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 format_5_hiops(word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 unsigned word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 static char *opc[3] = {"add", "cmp", "mov"};
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 int reg1, reg2;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 if (word & 0xC0) {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 reg1 = word & 7;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 if (word & 0x80)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 reg1 += 8;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 reg2 = (word >> 3) & 0xF;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 printf("%s\t%s, %s\n", opc[(word>>8)&3],
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 regnames[reg1], regnames[reg2]);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 } else
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 printf("<invalid: hi-reg format with both low regs>\n");
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 format_5(word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 unsigned word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 if ((word & 0x300) == 0x300)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 format_5_bx(word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 else
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 format_5_hiops(word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 format_6(off, word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 unsigned off, word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 unsigned loff, litoff;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 loff = (word & 0xFF) << 2;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 off &= ~3;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113 off += 4;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 litoff = off + loff;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 if (litoff+4 <= disasm_len)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 printf("ldr\t%s, =0x%x\t; via 0x%x\n", regnames[(word>>8)&7],
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 get_u32(filemap + litoff), base_vma + litoff);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 else
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 printf("ldr\t%s, [pc, #%u]\t(0x%x)\n", regnames[(word>>8)&7],
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 loff, base_vma + litoff);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 format_7(word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125 unsigned word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 printf("%s%s\t%s, [%s, %s]\n", word&0x800 ? "ldr" : "str",
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128 word&0x400 ? "b" : "", regnames[word&7],
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129 regnames[(word>>3)&7], regnames[(word>>6)&7]);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
132 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133 format_8(word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134 unsigned word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136 static char *opc[4] = {"strh", "ldrsb", "ldrh", "ldrsh"};
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138 printf("%s\t%s, [%s, %s]\n", opc[(word>>10)&3], regnames[word&7],
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139 regnames[(word>>3)&7], regnames[(word>>6)&7]);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
141
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
142 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
143 format_9(word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 unsigned word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
145 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
146 unsigned loff;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
147
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 loff = (word >> 6) & 0x1F;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149 if (!(word & 0x1000))
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 loff <<= 2;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151 printf("%s%s\t%s, [%s, #%u]", word&0x800 ? "ldr" : "str",
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152 word&0x1000 ? "b" : "", regnames[word&7],
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153 regnames[(word>>3)&7], loff);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 if (loff >= 10)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 printf("\t; 0x%x", loff);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 putchar('\n');
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160 format_10(word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 unsigned word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 unsigned loff;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 loff = (word >> 6) & 0x1F;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166 loff <<= 1;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 printf("%sh\t%s, [%s, #%u]", word&0x800 ? "ldr" : "str",
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 regnames[word&7], regnames[(word>>3)&7], loff);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
169 if (loff >= 10)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
170 printf("\t; 0x%x", loff);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
171 putchar('\n');
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
172 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
173
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
174 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
175 format_11(word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
176 unsigned word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
177 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
178 unsigned loff;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
179
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
180 loff = (word & 0xFF) << 2;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
181 printf("%s\t%s, [sp, #%u]", word&0x800 ? "ldr" : "str",
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
182 regnames[(word>>8)&7], loff);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
183 if (loff >= 10)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
184 printf("\t; 0x%x", loff);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
185 putchar('\n');
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
186 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
187
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
188 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
189 format_12(off, word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
190 unsigned off, word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
191 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
192 unsigned loff;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
193
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
194 loff = (word & 0xFF) << 2;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
195 printf("add\t%s, %s, #%u", regnames[(word>>8)&7],
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
196 word&0x800 ? "sp" : "pc", loff);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
197 if (loff >= 10)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
198 printf("\t; 0x%x", loff);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
199 putchar('\n');
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
200 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
201
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
202 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
203 format_13(word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
204 unsigned word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
205 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
206 unsigned loff;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
207
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
208 if ((word & 0xFF00) != 0xB000) {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
209 printf("<invalid format 13>\n");
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
210 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
211 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
212 loff = (word & 0xFF) << 2;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
213 printf("%s\tsp, #%u", word&0x80 ? "sub" : "add", loff);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
214 if (loff >= 10)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
215 printf("\t; 0x%x", loff);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
216 putchar('\n');
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
217 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
218
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
219 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
220 format_14(word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
221 unsigned word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
222 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
223 int r, flag;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
224
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
225 if ((word & 0xF600) != 0xB400) {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
226 printf("<invalid format 14>\n");
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
227 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
228 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
229 printf("%s\t{", word&0x800 ? "pop" : "push");
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
230 flag = 0;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
231 for (r = 0; r < 9; r++)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
232 if (word & (1 << r)) {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
233 if (flag)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
234 fputs(", ", stdout);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
235 if (r == 8)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
236 fputs(word&0x800 ? "pc" : "lr", stdout);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
237 else
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
238 fputs(regnames[r], stdout);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
239 flag = 1;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
240 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
241 putchar('}');
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
242 putchar('\n');
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
243 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
244
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
245 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
246 format_15(word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
247 unsigned word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
248 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
249 int r, flag;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
250
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
251 printf("%sia\t%s!, {", word&0x800 ? "ldm" : "stm",
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
252 regnames[(word>>8)&7]);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
253 flag = 0;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
254 for (r = 0; r < 8; r++)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
255 if (word & (1 << r)) {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
256 if (flag)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
257 fputs(", ", stdout);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
258 fputs(regnames[r], stdout);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
259 flag = 1;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
260 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
261 putchar('}');
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
262 putchar('\n');
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
263 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
264
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
265 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
266 format_16_17(off, word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
267 unsigned off, word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
268 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
269 unsigned cond;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
270 unsigned dest;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
271
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
272 cond = (word >> 8) & 0xF;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
273 switch (cond) {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
274 case 0xE:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
275 printf("<invalid: bal>\n");
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
276 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
277 case 0xF:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
278 printf("swi\t0x%x\n", word & 0xFF);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
279 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
280 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
281 dest = (word & 0xFF) << 1;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
282 if (dest & 0x00000100)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
283 dest |= 0xFFFFFE00;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
284 dest += base_vma + off + 4;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
285 printf("b%s\t0x%x\n", condition_decode[cond], dest);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
286 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
287
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
288 static void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
289 format_18(off, word)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
290 unsigned off, word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
291 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
292 unsigned dest;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
293
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
294 if (word & 0x800) {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
295 printf("<invalid format 18>\n");
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
296 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
297 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
298 dest = (word & 0x7FF) << 1;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
299 if (dest & 0x00000800)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
300 dest |= 0xFFFFF000;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
301 dest += base_vma + off + 4;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
302 printf("b\t0x%x\n", dest);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
303 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
304
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
305 void
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
306 thumb_disasm_line(off)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
307 unsigned off;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
308 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
309 unsigned word;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
310
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
311 word = get_u16(filemap + off);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
312 printf("%8x:\t%04x\t\t", base_vma + off, word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
313 switch (word >> 12) {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
314 case 0:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
315 case 1:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
316 format_1_2(word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
317 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
318 case 2:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
319 case 3:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
320 format_3(word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
321 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
322 case 4:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
323 if (word & 0x800)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
324 format_6(off, word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
325 else if (word & 0x400)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
326 format_5(word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
327 else
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
328 format_4(word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
329 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
330 case 5:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
331 if (word & 0x200)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
332 format_8(word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
333 else
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
334 format_7(word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
335 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
336 case 6:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
337 case 7:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
338 format_9(word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
339 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
340 case 8:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
341 format_10(word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
342 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
343 case 9:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
344 format_11(word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
345 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
346 case 0xA:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
347 format_12(off, word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
348 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
349 case 0xB:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
350 if (word & 0x400)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
351 format_14(word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
352 else
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
353 format_13(word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
354 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
355 case 0xC:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
356 format_15(word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
357 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
358 case 0xD:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
359 format_16_17(off, word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
360 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
361 case 0xE:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
362 format_18(off, word);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
363 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
364 case 0xF:
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
365 printf("<half-bl>\n");
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
366 return;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
367 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
368 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
369
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
370 thumb_check_bl(off)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
371 unsigned off;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
372 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
373 unsigned ins1, ins2;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
374 unsigned dest;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
375
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
376 if (off + 4 > disasm_len)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
377 return(0);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
378 ins1 = get_u16(filemap + off);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
379 if ((ins1 & 0xF800) != 0xF000)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
380 return(0);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
381 ins2 = get_u16(filemap + off + 2);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
382 if ((ins2 & 0xF800) != 0xF800)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
383 return(0);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
384 /* match */
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
385 dest = ((ins1 & 0x7FF) << 12) | ((ins2 & 0x7FF) << 1);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
386 if (dest & 0x00400000)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
387 dest |= 0xFF800000;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
388 dest += base_vma + off + 4;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
389 printf("%8x:\t%04x %04x\tbl\t0x%x\n", base_vma + off, ins1, ins2, dest);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
390 return(1);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
391 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
392
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
393 main(argc, argv)
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
394 char **argv;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
395 {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
396 unsigned off;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
397
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
398 common_init(argc, argv, 2);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
399 for (off = 0; off < disasm_len; ) {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
400 if (thumb_check_bl(off))
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
401 off += 4;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
402 else {
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
403 thumb_disasm_line(off);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
404 off += 2;
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
405 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
406 }
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
407 exit(0);
fb5ea2758482 thumbdis written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
408 }