FreeCalypso > hg > freecalypso-reveng
annotate leo-obj/tool/ln.c @ 386:8d19e61d202f
pirelli/chg-circuit: found VBUS, VCHG and ICTL
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 23 Mar 2022 20:06:08 +0000 |
parents | 71e25510f5af |
children |
rev | line source |
---|---|
143
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
211
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
2 * Making use of line number records |
143
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdlib.h> |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include "filestruct.h" |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include "intstruct.h" |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include "coffconst.h" |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "globals.h" |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 extern unsigned get_u16(), get_u32(); |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 cmd_ln() |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 { |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 unsigned n, m; |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 struct internal_scnhdr *sec; |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 u_char *rec; |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 get_int_section_table(); |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 for (n = 0; n < nsections; n++) { |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 sec = sections + n; |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 if (!sec->nlineent) |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 continue; |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 printf("%s:\n\n", sec->name); |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 rec = filemap + sec->line_offset; |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 for (m = 0; m < sec->nlineent; m++, rec += 6) |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 printf("%08X %04X\n", get_u32(rec), get_u16(rec + 4)); |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 putchar('\n'); |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 } |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 exit(0); |
fbdb7686a9e9
tiobjd: raw dump of line number records implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 } |
152
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
34 |
211
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
35 static unsigned |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
36 get_lineno_base(func_symidx) |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
37 unsigned func_symidx; |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
38 { |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
39 struct internal_syment *func_sym, *bf_sym; |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
40 |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
41 if (func_symidx >= nsymtab) |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
42 return 0; |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
43 func_sym = symtab[func_symidx]; |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
44 if (!func_sym->aux) |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
45 return 0; |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
46 if (func_symidx + 2 >= nsymtab) |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
47 return 0; |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
48 bf_sym = symtab[func_symidx + 2]; |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
49 if (!bf_sym->aux) |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
50 return 0; |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
51 return get_u16(bf_sym->aux + 4); |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
52 } |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
53 |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
54 get_lineno_array(sec, arr_rtn, count_rtn, actual_numbers) |
152
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
55 struct internal_scnhdr *sec; |
211
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
56 struct internal_lineno **arr_rtn; |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
57 unsigned *count_rtn; |
152
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
58 { |
211
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
59 struct internal_lineno *array; |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
60 unsigned cur, last; |
152
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
61 unsigned n, m; |
211
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
62 unsigned base, incr; |
152
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
63 u_char *rec; |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
64 |
211
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
65 array = malloc(sizeof(struct internal_lineno) * sec->nlineent); |
152
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
66 if (!array) { |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
67 perror("malloc"); |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
68 exit(1); |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
69 } |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
70 m = 0; |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
71 rec = filemap + sec->line_offset; |
211
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
72 base = 0; |
152
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
73 for (n = 0; n < sec->nlineent; n++, rec += 6) { |
211
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
74 incr = get_u16(rec + 4); |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
75 if (!incr) { |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
76 if (actual_numbers) |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
77 base = get_lineno_base(get_u32(rec)); |
152
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
78 continue; |
211
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
79 } |
152
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
80 cur = get_u32(rec); |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
81 if (m) { |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
82 if (cur < last) { |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
83 fprintf(stderr, |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
84 "error: line # addresses in section %s going backward\n", |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
85 sec->name); |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
86 exit(1); |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
87 } |
211
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
88 if (cur == last && !actual_numbers) |
152
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
89 continue; |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
90 } |
211
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
91 if (actual_numbers) { |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
92 if (!base) { |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
93 fprintf(stderr, |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
94 "error: no line # base in section %s\n", |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
95 sec->name); |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
96 exit(1); |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
97 } |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
98 array[m].lineno = base + incr - 1; |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
99 } |
71e25510f5af
tiobjd disasm -ll: show the actual line numbers
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
152
diff
changeset
|
100 array[m++].location = cur; |
152
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
101 last = cur; |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
102 } |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
103 *arr_rtn = array; |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
104 *count_rtn = m; |
fcf1ef773a57
tiobjd disasm: implemented -l option to show line markers
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
143
diff
changeset
|
105 } |