annotate leo-obj/tool/disasm.c @ 164:f80bd142971d

leo-obj/frame_na7_db_ir: os_mem.hints added
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 15 Jun 2014 01:43:55 +0000
parents fcf1ef773a57
children 71e25510f5af
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 * Putting it all together: section-, symbol- and reloc-aware 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"
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "coffconst.h"
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();
125
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
15 extern char *storage_class_to_string();
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16
133
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
17 int auto_xlat_section_relocs = 1;
152
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
18 int disasm_richsym, disasm_lineno;
148
13cc7e19ecec tiobjd disasm -g: support -b as well
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 147
diff changeset
19 extern int richsym_print_bitsize;
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
20
118
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
21 static void
121
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
22 find_better_symbol(sec, symp, addp)
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
23 struct internal_scnhdr *sec;
118
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
24 struct internal_syment **symp;
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
25 unsigned *addp;
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
26 {
120
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
27 unsigned addr, delta;
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
28 struct internal_syment *sym;
118
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
29 unsigned n;
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
30
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
31 addr = *addp;
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
32 for (n = 0; n < sec->nsymbols; n++) {
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
33 sym = sec->sorted_symbols[n];
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
34 if (sym->value > addr)
120
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
35 return;
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
36 if (sym->class != C_EXT && sym->class != C_STAT)
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
37 continue;
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
38 delta = addr - sym->value;
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
39 if (sym->name[0] == '_' && !delta ||
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
40 sym->name[0] == '$' && delta <= 1) {
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
41 *symp = sym;
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
42 *addp = delta;
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
43 }
118
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
44 }
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
45 }
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
46
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 void
112
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
48 disasm_reloc_target(sec, rel, addend)
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
49 struct internal_scnhdr *sec;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
50 struct internal_reloc *rel;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
51 unsigned addend;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
52 {
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
53 struct internal_syment *sym = rel->sym;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
54
121
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
55 if (sym)
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
56 addend -= sym->value;
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
57 if (auto_xlat_section_relocs &&
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
58 (!sym || sym->section && !strcmp(sym->name, sym->section->name)))
121
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
59 find_better_symbol(sym ? sym->section : sec, &sym, &addend);
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
60 if (sym)
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
61 fputs(sym->name, stdout);
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
62 else
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
63 fputs(sec->name, stdout);
112
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
64 if (addend >= 10)
121
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
65 printf("+0x%x", addend);
112
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
66 else if (addend)
121
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
67 printf("+%u", addend);
112
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
68 }
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
69
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
70 void
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
71 disasm_word32_reloc(sec, rel)
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
72 struct internal_scnhdr *sec;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
73 struct internal_reloc *rel;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
74 {
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
75 unsigned word;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
76
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
77 word = get_u32(filemap + sec->data_offset + rel->location);
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
78 printf("%08x R\t.word\t", word);
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
79 disasm_reloc_target(sec, rel, word);
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
80 putchar('\n');
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
81 }
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
82
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
83 static void
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
84 handle_symbol(sym, statep, linebrkp)
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
85 struct internal_syment *sym;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
86 int *statep, *linebrkp;
124
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
87 {
147
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
88 char *sym_comment, *cpref;
124
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
89
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
90 if (sym->class == C_FCN && !strcmp(sym->name, ".ef")) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
91 printf("; End function\n");
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
92 return;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
93 }
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
94 if (!*linebrkp) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
95 putchar('\n');
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
96 *linebrkp = 1;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
97 }
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
98 if (sym->class == C_FCN && !strcmp(sym->name, ".bf")) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
99 printf("; Begin function\n");
150
df01a4f4c272 tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 148
diff changeset
100 if (disasm_richsym)
151
6fe08feee018 tiobjd disasm -g: line break after function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 150
diff changeset
101 if (richsym_function_locals(sym))
6fe08feee018 tiobjd disasm -g: line break after function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 150
diff changeset
102 putchar('\n');
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
103 return;
124
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
104 }
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
105 switch (sym->class) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
106 case C_EXT:
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
107 sym_comment = "Global";
147
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
108 cpref = "; ";
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
109 break;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
110 case C_STAT:
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
111 sym_comment = "static";
147
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
112 cpref = "; static ";
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
113 break;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
114 case C_LABEL:
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
115 sym_comment = "label";
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
116 if (!strcmp(sym->name, "$CODE16"))
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
117 *statep = 1;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
118 else if (!strcmp(sym->name, "$CODE32"))
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
119 *statep = 0;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
120 break;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
121 default:
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
122 sym_comment = "unexpected class!";
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
123 }
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
124 printf("%s:\t; %s\n", sym->name, sym_comment);
147
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
125 if (!disasm_richsym || sym->class != C_EXT && sym->class != C_STAT)
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
126 return;
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
127 if (!sym->aux || sym->name[0] != '_' && sym->name[0] != '$')
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
128 return;
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
129 richsym_print_in_c(cpref, sym, 0);
124
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
130 }
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
131
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
132 void
136
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
133 disasm_emit_asciz(sec, pos, len)
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
134 struct internal_scnhdr *sec;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
135 unsigned pos, len;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
136 {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
137 int c;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
138 unsigned endpos = pos + len;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
139
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
140 fputs("\t.asciz\t\"", stdout);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
141 for (; pos < endpos; pos++) {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
142 c = filemap[sec->data_offset + pos];
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
143 switch (c) {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
144 case '\b':
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
145 fputs("\\b", stdout);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
146 continue;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
147 case '\t':
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
148 fputs("\\t", stdout);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
149 continue;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
150 case '\n':
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
151 fputs("\\n", stdout);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
152 continue;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
153 case '\r':
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
154 fputs("\\r", stdout);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
155 continue;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
156 case '"':
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
157 fputs("\\\"", stdout);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
158 continue;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
159 case '\\':
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
160 fputs("\\\\", stdout);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
161 continue;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
162 }
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
163 if (c >= ' ' && c <= '~')
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
164 putchar(c);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
165 else
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
166 printf("\\%03o", c);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
167 }
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
168 putchar('"');
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
169 putchar('\n');
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
170 }
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
171
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
172 void
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
173 disasm_codedata_section(sec)
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
174 struct internal_scnhdr *sec;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
175 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
176 unsigned symnum, relnum;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
177 unsigned pos, incr, headroom;
136
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
178 int state = -1, linebrk = 0, gothint;
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
179 struct internal_syment *sym;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
180 struct internal_reloc *rel;
136
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
181 struct hint *hint = sec->hints;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
182 u_char *asciz_end;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
183 unsigned asciz_len;
152
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
184 unsigned *lineno_arr;
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
185 unsigned lineno_cur, lineno_total;
111
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 if (sec->nreloc)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
188 get_relocs_of_sec(sec);
152
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
189 if (disasm_lineno && sec->nlineent)
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
190 get_lineno_addrs(sec, &lineno_arr, &lineno_total);
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
191 else {
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
192 lineno_arr = 0;
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
193 lineno_total = 0;
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
194 }
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
195 symnum = relnum = 0;
152
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
196 lineno_cur = 0;
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
197 for (pos = 0; pos < sec->size; pos += incr) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
198 headroom = sec->size - pos;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
199 while (symnum < sec->nsymbols) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
200 sym = sec->sorted_symbols[symnum];
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
201 if (sym->value > pos) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
202 if (sym->value - pos < headroom)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
203 headroom = sym->value - pos;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
204 break;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
205 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
206 /* hit symbol */
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
207 handle_symbol(sym, &state, &linebrk);
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
208 symnum++;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
209 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
210 if (relnum < sec->nreloc) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
211 rel = sec->int_relocs + relnum;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
212 if (rel->location == pos)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
213 relnum++; /* it's ours */
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
214 else {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
215 if (rel->location - pos < headroom)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
216 headroom = rel->location - pos;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
217 rel = 0; /* no reloc for current pos */
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
218 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
219 } else
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
220 rel = 0;
136
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
221 if (hint) {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
222 if (pos >= hint->pos)
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
223 gothint++;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
224 else {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
225 gothint = 0;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
226 if (hint->pos - pos < headroom)
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
227 headroom = hint->pos - pos;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
228 }
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
229 } else
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
230 gothint = 0;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
231 if (gothint && pos == hint->pos && hint->linebrk)
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
232 putchar('\n');
152
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
233 if (lineno_cur < lineno_total) {
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
234 if (pos >= lineno_arr[lineno_cur]) {
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
235 puts("; line");
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
236 lineno_cur++;
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
237 } else {
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
238 if (lineno_arr[lineno_cur] - pos < headroom)
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
239 headroom = lineno_arr[lineno_cur] - pos;
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
240 }
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
241 }
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
242 printf("%8x:\t", pos);
136
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
243 if (gothint && hint->type) {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
244 if (rel) {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
245 printf("error: hint/reloc conflict\n");
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
246 return;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
247 }
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
248 switch (hint->type) {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
249 case HINT_D8:
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
250 printf("%02x\n",
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
251 filemap[sec->data_offset + pos]);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
252 incr = 1;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
253 break;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
254 case HINT_D16:
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
255 printf("%04x\n",
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
256 get_u16(filemap+sec->data_offset+pos));
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
257 incr = 2;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
258 break;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
259 case HINT_D32:
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
260 printf("%08x\n",
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
261 get_u32(filemap+sec->data_offset+pos));
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
262 incr = 4;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
263 break;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
264 case HINT_ASCIZ:
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
265 asciz_end = memchr(filemap+sec->data_offset+pos,
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
266 0, headroom);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
267 if (!asciz_end) {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
268 printf("bad asciz hint: no 0 found\n");
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
269 return;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
270 }
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
271 asciz_len = asciz_end - filemap -
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
272 sec->data_offset - pos;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
273 disasm_emit_asciz(sec, pos, asciz_len);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
274 incr = asciz_len + 1;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
275 }
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
276 goto next;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
277 }
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
278 if (rel) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
279 if (rel->type == RTYPE_LONG) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
280 if (pos & 3) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
281 printf("MISALIGNED pos for word32 reloc, aborting\n");
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
282 return;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
283 }
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
284 disasm_word32_reloc(sec, rel);
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
285 incr = 4;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
286 goto next;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
287 } else if (sec->disasm_mode == DISASM_MODE_DATA) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
288 printf("error: reloc other than word32 in data section\n");
112
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
289 return;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
290 }
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
291 }
123
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
292 if (pos & 1 || headroom < 2) {
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
293 if (rel) {
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
294 printf("error: reloc at byte pos, aborting\n");
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
295 return;
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
296 }
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
297 printf("%02x\n", filemap[sec->data_offset + pos]);
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
298 incr = 1;
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
299 goto next;
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
300 }
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
301 if (sec->disasm_mode == DISASM_MODE_DATA) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
302 if (pos & 2 || headroom < 4) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
303 printf("%04x\n",
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
304 get_u16(filemap+sec->data_offset+pos));
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
305 incr = 2;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
306 } else {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
307 printf("%08x\n",
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
308 get_u32(filemap+sec->data_offset+pos));
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
309 incr = 4;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
310 }
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
311 goto next;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
312 }
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
313 switch (state) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
314 case 0: /* ARM */
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
315 if (pos & 3) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
316 printf("MISALIGNED pos in CODE32 state, aborting\n");
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
317 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
318 }
114
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
319 if (rel) {
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
320 if (rel->type != RTYPE_ARM_B) {
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
321 printf("Wrong reloc type in CODE32 state, aborting\n");
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
322 return;
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
323 }
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
324 arm_branch_reloc(sec, rel);
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
325 } else
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
326 arm_disasm_line(sec, pos);
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
327 incr = 4;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
328 break;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
329 case 1: /* Thumb */
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
330 if (pos & 1) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
331 printf("MISALIGNED pos in CODE16 state, aborting\n");
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
332 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
333 }
117
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
334 if (rel) {
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
335 if (rel->type != RTYPE_THUMB_BL) {
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
336 printf("Wrong reloc type in CODE16 state, aborting\n");
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
337 return;
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
338 }
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
339 thumb_bl_reloc(sec, rel);
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
340 incr = 4;
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
341 } else if (headroom >= 4 && thumb_check_bl(sec, pos))
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
342 incr = 4;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
343 else {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
344 thumb_disasm_line(sec, pos);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
345 incr = 2;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
346 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
347 break;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
348 default:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
349 printf("UNKNOWN T state, aborting\n");
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
350 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
351 }
112
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
352 next: linebrk = 0;
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
353 if (incr > headroom) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
354 printf("error: increment %u > headroom %u, aborting\n",
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
355 incr, headroom);
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 }
136
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
358 if (hint && pos >= hint->endpos)
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
359 hint = hint->next;
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
360 }
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
361 while (symnum < sec->nsymbols) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
362 sym = sec->sorted_symbols[symnum];
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
363 if (sym->value != sec->size) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
364 printf("error: expecting symbol at end of section\n");
124
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
365 return;
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
366 }
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
367 handle_symbol(sym, &state, &linebrk);
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
368 symnum++;
124
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
369 }
139
acdf75463e30 tiobjd disasm: smarter logic for when the <end of section> line
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 136
diff changeset
370 if (linebrk)
acdf75463e30 tiobjd disasm: smarter logic for when the <end of section> line
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 136
diff changeset
371 printf("%8x:\t<end of section>\n", sec->size);
152
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
372 if (lineno_arr)
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
373 free(lineno_arr);
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
374 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
375
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
376 void
125
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
377 disasm_bss(sec)
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
378 struct internal_scnhdr *sec;
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
379 {
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
380 unsigned m;
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
381 struct internal_syment *sym;
147
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
382 char classbuf[8], *cpref;
125
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
383
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
384 putchar('\n');
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
385 for (m = 0; m < sec->nsymbols; m++) {
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
386 sym = sec->sorted_symbols[m];
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
387 printf("%08X %-7s %s\n", sym->value,
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
388 storage_class_to_string(sym->class, classbuf),
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
389 sym->name);
147
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
390 if (!disasm_richsym || !sym->aux || sym->name[0] != '_')
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
391 continue;
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
392 switch (sym->class) {
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
393 case C_EXT:
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
394 cpref = "; ";
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
395 break;
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
396 case C_STAT:
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
397 cpref = "; static ";
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
398 break;
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
399 default:
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
400 continue;
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
401 }
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
402 richsym_print_in_c(cpref, sym, 0);
125
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
403 }
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
404 printf("%08X <end of section>\n", sec->size);
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
405 }
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
406
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
407 void
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
408 disasm_sec_by_type(sec)
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
409 struct internal_scnhdr *sec;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
410 {
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
411 switch (sec->disasm_mode) {
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
412 case DISASM_MODE_CODE:
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
413 printf("Disassembling code section:\n");
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
414 disasm_codedata_section(sec);
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
415 return;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
416 case DISASM_MODE_DATA:
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
417 printf("Disassembling data section:\n");
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
418 disasm_codedata_section(sec);
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
419 return;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
420 case DISASM_MODE_BSS:
125
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
421 disasm_bss(sec);
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
422 return;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
423 default:
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
424 printf("Unrecognized section type, skipped\n");
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
425 }
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
426 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
427
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
428 cmd_disasm(argc, argv)
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
429 char **argv;
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
430 {
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
431 extern char *optarg;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
432 char *hintsfile = 0;
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
433 struct internal_scnhdr *sec;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
434 unsigned secnum;
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
435 int c;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
436
152
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
437 while ((c = getopt(argc, argv, "bgh:ls")) != EOF)
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
438 switch (c) {
148
13cc7e19ecec tiobjd disasm -g: support -b as well
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 147
diff changeset
439 case 'b':
13cc7e19ecec tiobjd disasm -g: support -b as well
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 147
diff changeset
440 richsym_print_bitsize++;
13cc7e19ecec tiobjd disasm -g: support -b as well
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 147
diff changeset
441 continue;
147
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
442 case 'g':
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
443 disasm_richsym++;
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
444 continue;
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
445 case 'h':
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
446 hintsfile = optarg;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
447 continue;
152
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
448 case 'l':
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
449 disasm_lineno++;
fcf1ef773a57 tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 151
diff changeset
450 continue;
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
451 case 's':
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
452 auto_xlat_section_relocs = 0;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
453 continue;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
454 default:
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
455 /* error msg already printed */
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
456 exit(1);
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
457 }
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
458
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
459 printf("%s:\n", objfilename);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
460 dump_filehdr_info();
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
461 putchar('\n');
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
462 get_int_section_table();
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
463 get_int_symbol_table();
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
464 if (hintsfile)
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
465 read_hints_file(hintsfile);
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
466 extern_profile_report("Module");
118
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
467 sort_symbols_of_all_sec();
147
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
468 if (disasm_richsym)
1e1815a6d701 tiobjd: beginning of disasm -g
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 139
diff changeset
469 richsym_initial_preen();
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
470 for (secnum = 0; secnum < nsections; secnum++) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
471 sec = sections + secnum;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
472 printf("=== %s ===\n", sec->name);
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
473 disasm_sec_by_type(sec);
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
474 putchar('\n');
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
475 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
476 exit(0);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
477 }