annotate leo-obj/tool/thumbdis.c @ 278:42575bc59702

benq-fw-disasm: dug a little into BenQ's M32 firmware
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Dec 2018 07:48:48 +0000
parents 4d7f36110f1c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * Thumb state disassembly
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdlib.h>
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "intstruct.h"
133
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
11 #include "coffconst.h"
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "globals.h"
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 extern unsigned get_u16(), get_u32();
115
2f23301d2f86 tiobjd: literal reloc recognition restricted to RTYPE_LONG
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 113
diff changeset
15 extern struct internal_reloc *find_word32_reloc();
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 extern char *regnames[16], *condition_decode[16], *shift_types[4];
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18
133
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
19 extern int auto_xlat_section_relocs;
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
20
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 format_1_2(word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 unsigned word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 unsigned op, imm;
153
4d7f36110f1c leo-obj: frame_na7_db_fl/os_pro.obj disassembles the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
26 int is_mov;
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 op = (word >> 11) & 3;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 if (op != 3) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 /* format 1 */
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 imm = (word >> 6) & 0x1F;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 if (op != 0 && imm == 0)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 imm = 32;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 printf("%s\t%s, %s, #%u\n", shift_types[op], regnames[word&7],
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 regnames[(word>>3)&7], imm);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 /* format 2 */
153
4d7f36110f1c leo-obj: frame_na7_db_fl/os_pro.obj disassembles the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
39 if ((word & 0xFDC0) == 0x1C00) {
4d7f36110f1c leo-obj: frame_na7_db_fl/os_pro.obj disassembles the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
40 printf("mov\t%s, %s\t\t(", regnames[word&7],
4d7f36110f1c leo-obj: frame_na7_db_fl/os_pro.obj disassembles the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
41 regnames[(word>>3)&7]);
4d7f36110f1c leo-obj: frame_na7_db_fl/os_pro.obj disassembles the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
42 is_mov = 1;
4d7f36110f1c leo-obj: frame_na7_db_fl/os_pro.obj disassembles the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
43 } else
4d7f36110f1c leo-obj: frame_na7_db_fl/os_pro.obj disassembles the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
44 is_mov = 0;
4d7f36110f1c leo-obj: frame_na7_db_fl/os_pro.obj disassembles the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
45 printf("%s%c%s, %s, ", word&0x200 ? "sub" : "add",
4d7f36110f1c leo-obj: frame_na7_db_fl/os_pro.obj disassembles the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
46 is_mov ? ' ' : '\t', regnames[word&7], regnames[(word>>3)&7]);
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 if (word & 0x400)
153
4d7f36110f1c leo-obj: frame_na7_db_fl/os_pro.obj disassembles the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
48 printf("#%u", (word >> 6) & 7);
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 else
153
4d7f36110f1c leo-obj: frame_na7_db_fl/os_pro.obj disassembles the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
50 printf("%s", regnames[(word >> 6) & 7]);
4d7f36110f1c leo-obj: frame_na7_db_fl/os_pro.obj disassembles the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
51 if (is_mov)
4d7f36110f1c leo-obj: frame_na7_db_fl/os_pro.obj disassembles the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
52 putchar(')');
4d7f36110f1c leo-obj: frame_na7_db_fl/os_pro.obj disassembles the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
53 putchar('\n');
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 format_3(word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 unsigned word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 static char *opctab[4] = {"mov", "cmp", "add", "sub"};
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 unsigned imm;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 imm = word & 0xFF;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 printf("%s\t%s, #%u", opctab[(word>>11)&3], regnames[(word>>8)&7], imm);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 if (imm > 9)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 printf("\t; 0x%x", imm);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 putchar('\n');
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 format_4(word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 unsigned word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 static char *opc[16] = {"and", "eor", "lsl", "lsr",
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 "asr", "adc", "sbc", "ror",
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 "tst", "neg", "cmp", "cmn",
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 "orr", "mul", "bic", "mvn"};
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 printf("%s\t%s, %s\n", opc[(word>>6)&0xF], regnames[word&7],
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 regnames[(word>>3)&7]);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 format_5_bx(word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 unsigned word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 if (word & 0x80)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 printf("<invalid: blx instead of bx>\n");
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 else
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 printf("bx\t%s\n", regnames[(word>>3)&0xF]);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 format_5_hiops(word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 unsigned word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 static char *opctab[3] = {"add", "cmp", "mov"};
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 int reg1, reg2, op;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 if (word & 0xC0) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 reg1 = word & 7;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 if (word & 0x80)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 reg1 += 8;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 reg2 = (word >> 3) & 0xF;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 op = (word >> 8) & 3;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 if (op == 2 && reg1 == reg2 && reg1 != 15)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 printf("nop\t\t\t(mov %s, %s)\n",
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 regnames[reg1], regnames[reg2]);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 else
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 printf("%s\t%s, %s\n", opctab[op],
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 regnames[reg1], regnames[reg2]);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 } else
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113 printf("<invalid: hi-reg format with both low regs>\n");
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 format_5(word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 unsigned word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 if ((word & 0x300) == 0x300)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 format_5_bx(word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 else
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 format_5_hiops(word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 format_6(sec, off, word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128 struct internal_scnhdr *sec;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129 unsigned off, word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130 {
113
d97fbe98600b tiobjd: recognizing relocs in ldr literals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
131 unsigned loff, litoff, datum;
d97fbe98600b tiobjd: recognizing relocs in ldr literals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
132 struct internal_reloc *rel;
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134 loff = (word & 0xFF) << 2;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135 off &= ~3;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136 off += 4;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137 litoff = off + loff;
113
d97fbe98600b tiobjd: recognizing relocs in ldr literals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
138 if (litoff+4 <= sec->size) {
115
2f23301d2f86 tiobjd: literal reloc recognition restricted to RTYPE_LONG
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 113
diff changeset
139 rel = find_word32_reloc(sec, litoff);
113
d97fbe98600b tiobjd: recognizing relocs in ldr literals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
140 datum = get_u32(filemap + sec->data_offset + litoff);
d97fbe98600b tiobjd: recognizing relocs in ldr literals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
141 printf("ldr\t%s, =", regnames[(word>>8)&7]);
d97fbe98600b tiobjd: recognizing relocs in ldr literals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
142 if (rel)
d97fbe98600b tiobjd: recognizing relocs in ldr literals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
143 disasm_reloc_target(sec, rel, datum);
d97fbe98600b tiobjd: recognizing relocs in ldr literals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
144 else
d97fbe98600b tiobjd: recognizing relocs in ldr literals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
145 printf("0x%x", datum);
d97fbe98600b tiobjd: recognizing relocs in ldr literals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
146 printf("\t; via 0x%x\n", litoff);
d97fbe98600b tiobjd: recognizing relocs in ldr literals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
147 } else
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 printf("ldr\t%s, [pc, #%u]\t(0x%x)\n", regnames[(word>>8)&7],
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149 loff, litoff);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153 format_7(word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 unsigned word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 printf("%s%s\t%s, [%s, %s]\n", word&0x800 ? "ldr" : "str",
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157 word&0x400 ? "b" : "", regnames[word&7],
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158 regnames[(word>>3)&7], regnames[(word>>6)&7]);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162 format_8(word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 unsigned word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 static char *opc[4] = {"strh", "ldrsb", "ldrh", "ldrsh"};
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 printf("%s\t%s, [%s, %s]\n", opc[(word>>10)&3], regnames[word&7],
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 regnames[(word>>3)&7], regnames[(word>>6)&7]);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
169 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
170
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
171 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
172 format_9(word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
173 unsigned word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
174 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
175 unsigned loff;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
176
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
177 loff = (word >> 6) & 0x1F;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
178 if (!(word & 0x1000))
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
179 loff <<= 2;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
180 printf("%s%s\t%s, [%s, #%u]", word&0x800 ? "ldr" : "str",
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
181 word&0x1000 ? "b" : "", regnames[word&7],
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
182 regnames[(word>>3)&7], loff);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
183 if (loff >= 10)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
184 printf("\t; 0x%x", loff);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
185 putchar('\n');
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
186 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
187
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
188 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
189 format_10(word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
190 unsigned word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
191 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
192 unsigned loff;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
193
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
194 loff = (word >> 6) & 0x1F;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
195 loff <<= 1;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
196 printf("%sh\t%s, [%s, #%u]", word&0x800 ? "ldr" : "str",
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
197 regnames[word&7], regnames[(word>>3)&7], loff);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
198 if (loff >= 10)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
199 printf("\t; 0x%x", loff);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
200 putchar('\n');
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
201 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
202
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
203 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
204 format_11(word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
205 unsigned word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
206 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
207 unsigned loff;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
208
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
209 loff = (word & 0xFF) << 2;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
210 printf("%s\t%s, [sp, #%u]", word&0x800 ? "ldr" : "str",
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
211 regnames[(word>>8)&7], loff);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
212 if (loff >= 10)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
213 printf("\t; 0x%x", loff);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
214 putchar('\n');
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
215 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
216
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
217 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
218 format_12(off, word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
219 unsigned off, word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
220 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
221 unsigned loff;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
222
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
223 loff = (word & 0xFF) << 2;
122
ca82528ec84d tiobjd Thumb disasm: compute results of adding to pc
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
224 printf("add\t%s, ", regnames[(word>>8)&7]);
ca82528ec84d tiobjd Thumb disasm: compute results of adding to pc
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
225 if (word & 0x800) {
ca82528ec84d tiobjd Thumb disasm: compute results of adding to pc
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
226 printf("sp, #%u", loff);
ca82528ec84d tiobjd Thumb disasm: compute results of adding to pc
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
227 if (loff >= 10)
ca82528ec84d tiobjd Thumb disasm: compute results of adding to pc
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
228 printf("\t; 0x%x", loff);
ca82528ec84d tiobjd Thumb disasm: compute results of adding to pc
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
229 putchar('\n');
ca82528ec84d tiobjd Thumb disasm: compute results of adding to pc
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
230 } else {
ca82528ec84d tiobjd Thumb disasm: compute results of adding to pc
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
231 off &= ~3;
ca82528ec84d tiobjd Thumb disasm: compute results of adding to pc
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
232 printf("pc, #%u\t; 0x%x\n", loff, off + 4 + loff);
ca82528ec84d tiobjd Thumb disasm: compute results of adding to pc
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
233 }
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
234 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
235
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
236 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
237 format_13(word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
238 unsigned word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
239 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
240 unsigned loff;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
241
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
242 if ((word & 0xFF00) != 0xB000) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
243 printf("<invalid format 13>\n");
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
244 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
245 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
246 loff = (word & 0x7F) << 2;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
247 printf("%s\tsp, #%u", word&0x80 ? "sub" : "add", loff);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
248 if (loff >= 10)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
249 printf("\t; 0x%x", loff);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
250 putchar('\n');
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
251 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
252
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
253 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
254 format_14(word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
255 unsigned word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
256 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
257 int r, flag;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
258
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
259 if ((word & 0xF600) != 0xB400) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
260 printf("<invalid format 14>\n");
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
261 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
262 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
263 printf("%s\t{", word&0x800 ? "pop" : "push");
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
264 flag = 0;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
265 for (r = 0; r < 9; r++)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
266 if (word & (1 << r)) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
267 if (flag)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
268 fputs(", ", stdout);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
269 if (r == 8)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
270 fputs(word&0x800 ? "pc" : "lr", stdout);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
271 else
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
272 fputs(regnames[r], stdout);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
273 flag = 1;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
274 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
275 putchar('}');
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
276 putchar('\n');
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
277 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
278
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
279 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
280 format_15(word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
281 unsigned word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
282 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
283 int r, flag;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
284
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
285 printf("%sia\t%s!, {", word&0x800 ? "ldm" : "stm",
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
286 regnames[(word>>8)&7]);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
287 flag = 0;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
288 for (r = 0; r < 8; r++)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
289 if (word & (1 << r)) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
290 if (flag)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
291 fputs(", ", stdout);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
292 fputs(regnames[r], stdout);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
293 flag = 1;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
294 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
295 putchar('}');
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
296 putchar('\n');
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
297 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
298
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
299 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
300 format_16_17(off, word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
301 unsigned off, word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
302 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
303 unsigned cond;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
304 unsigned dest;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
305
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
306 cond = (word >> 8) & 0xF;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
307 switch (cond) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
308 case 0xE:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
309 printf("<invalid: bal>\n");
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
310 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
311 case 0xF:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
312 printf("swi\t0x%x\n", word & 0xFF);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
313 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
314 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
315 dest = (word & 0xFF) << 1;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
316 if (dest & 0x00000100)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
317 dest |= 0xFFFFFE00;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
318 dest += off + 4;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
319 printf("b%s\t0x%x\n", condition_decode[cond], dest);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
320 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
321
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
322 static void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
323 format_18(off, word)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
324 unsigned off, word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
325 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
326 unsigned dest;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
327
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
328 if (word & 0x800) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
329 printf("<invalid format 18>\n");
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
330 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
331 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
332 dest = (word & 0x7FF) << 1;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
333 if (dest & 0x00000800)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
334 dest |= 0xFFFFF000;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
335 dest += off + 4;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
336 printf("b\t0x%x\n", dest);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
337 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
338
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
339 void
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
340 thumb_disasm_line(sec, off)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
341 struct internal_scnhdr *sec;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
342 unsigned off;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
343 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
344 unsigned word;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
345
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
346 word = get_u16(filemap + sec->data_offset + off);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
347 printf("%04x\t\t", word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
348 switch (word >> 12) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
349 case 0:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
350 case 1:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
351 format_1_2(word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
352 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
353 case 2:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
354 case 3:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
355 format_3(word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
356 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
357 case 4:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
358 if (word & 0x800)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
359 format_6(sec, off, word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
360 else if (word & 0x400)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
361 format_5(word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
362 else
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
363 format_4(word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
364 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
365 case 5:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
366 if (word & 0x200)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
367 format_8(word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
368 else
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
369 format_7(word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
370 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
371 case 6:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
372 case 7:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
373 format_9(word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
374 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
375 case 8:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
376 format_10(word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
377 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
378 case 9:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
379 format_11(word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
380 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
381 case 0xA:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
382 format_12(off, word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
383 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
384 case 0xB:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
385 if (word & 0x400)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
386 format_14(word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
387 else
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
388 format_13(word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
389 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
390 case 0xC:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
391 format_15(word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
392 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
393 case 0xD:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
394 format_16_17(off, word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
395 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
396 case 0xE:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
397 format_18(off, word);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
398 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
399 case 0xF:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
400 printf("<half-bl>\n");
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
401 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
402 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
403 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
404
133
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
405 static char *
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
406 bl_norel_find_symbol(sec, dest)
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
407 struct internal_scnhdr *sec;
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
408 unsigned dest;
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
409 {
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
410 struct internal_syment *sym;
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
411 unsigned n;
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
412
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
413 for (n = 0; n < sec->nsymbols; n++) {
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
414 sym = sec->sorted_symbols[n];
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
415 if (sym->value > dest)
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
416 break;
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
417 if (sym->value < dest)
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
418 continue;
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
419 if (sym->class != C_EXT && sym->class != C_STAT)
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
420 continue;
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
421 if (sym->name[0] == '$')
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
422 return(sym->name);
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
423 }
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
424 return(0);
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
425 }
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
426
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
427 thumb_check_bl(sec, off)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
428 struct internal_scnhdr *sec;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
429 unsigned off;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
430 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
431 unsigned ins1, ins2;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
432 unsigned dest;
133
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
433 char *destsym;
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
434
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
435 ins1 = get_u16(filemap + sec->data_offset + off);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
436 if ((ins1 & 0xF800) != 0xF000)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
437 return(0);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
438 ins2 = get_u16(filemap + sec->data_offset + off + 2);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
439 if ((ins2 & 0xF800) != 0xF800)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
440 return(0);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
441 /* match */
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
442 dest = ((ins1 & 0x7FF) << 12) | ((ins2 & 0x7FF) << 1);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
443 if (dest & 0x00400000)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
444 dest |= 0xFF800000;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
445 dest += off + 4;
133
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
446 printf("%04x %04x\tbl\t", ins1, ins2);
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
447 destsym = bl_norel_find_symbol(sec, dest);
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
448 if (destsym)
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
449 printf("%s\t; ", destsym);
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
450 printf("0x%x\n", dest);
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
451 return(1);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
452 }
117
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
453
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
454 void
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
455 thumb_bl_reloc(sec, rel)
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
456 struct internal_scnhdr *sec;
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
457 struct internal_reloc *rel;
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
458 {
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
459 unsigned ins1, ins2;
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
460 unsigned dest;
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
461
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
462 ins1 = get_u16(filemap + sec->data_offset + rel->location);
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
463 ins2 = get_u16(filemap + sec->data_offset + rel->location + 2);
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
464 printf("%04x %04x R\t", ins1, ins2);
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
465 if ((ins1 & 0xF800) != 0xF000 || (ins2 & 0xF800) != 0xF800) {
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
466 printf("<invalid Thumb_BL reloc: opcode not BL>\n");
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
467 return;
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
468 }
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
469 dest = ((ins1 & 0x7FF) << 12) | ((ins2 & 0x7FF) << 1);
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
470 if (dest & 0x00400000)
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
471 dest |= 0xFF800000;
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
472 dest += rel->location + 4;
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
473 fputs("bl\t", stdout);
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
474 disasm_reloc_target(sec, rel, dest);
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
475 putchar('\n');
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 115
diff changeset
476 }