FreeCalypso > hg > freecalypso-reveng
comparison leo-obj/tool/disasm.c @ 147:1e1815a6d701
tiobjd: beginning of disasm -g
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Tue, 29 Apr 2014 06:26:59 +0000 |
parents | acdf75463e30 |
children | 13cc7e19ecec |
comparison
equal
deleted
inserted
replaced
146:70631c246df0 | 147:1e1815a6d701 |
---|---|
13 | 13 |
14 extern unsigned get_u16(), get_u32(); | 14 extern unsigned get_u16(), get_u32(); |
15 extern char *storage_class_to_string(); | 15 extern char *storage_class_to_string(); |
16 | 16 |
17 int auto_xlat_section_relocs = 1; | 17 int auto_xlat_section_relocs = 1; |
18 int disasm_richsym; | |
18 | 19 |
19 static void | 20 static void |
20 find_better_symbol(sec, symp, addp) | 21 find_better_symbol(sec, symp, addp) |
21 struct internal_scnhdr *sec; | 22 struct internal_scnhdr *sec; |
22 struct internal_syment **symp; | 23 struct internal_syment **symp; |
81 static void | 82 static void |
82 handle_symbol(sym, statep, linebrkp) | 83 handle_symbol(sym, statep, linebrkp) |
83 struct internal_syment *sym; | 84 struct internal_syment *sym; |
84 int *statep, *linebrkp; | 85 int *statep, *linebrkp; |
85 { | 86 { |
86 char *sym_comment; | 87 char *sym_comment, *cpref; |
87 | 88 |
88 if (sym->class == C_FCN && !strcmp(sym->name, ".ef")) { | 89 if (sym->class == C_FCN && !strcmp(sym->name, ".ef")) { |
89 printf("; End function\n"); | 90 printf("; End function\n"); |
90 return; | 91 return; |
91 } | 92 } |
98 return; | 99 return; |
99 } | 100 } |
100 switch (sym->class) { | 101 switch (sym->class) { |
101 case C_EXT: | 102 case C_EXT: |
102 sym_comment = "Global"; | 103 sym_comment = "Global"; |
104 cpref = "; "; | |
103 break; | 105 break; |
104 case C_STAT: | 106 case C_STAT: |
105 sym_comment = "static"; | 107 sym_comment = "static"; |
108 cpref = "; static "; | |
106 break; | 109 break; |
107 case C_LABEL: | 110 case C_LABEL: |
108 sym_comment = "label"; | 111 sym_comment = "label"; |
109 if (!strcmp(sym->name, "$CODE16")) | 112 if (!strcmp(sym->name, "$CODE16")) |
110 *statep = 1; | 113 *statep = 1; |
113 break; | 116 break; |
114 default: | 117 default: |
115 sym_comment = "unexpected class!"; | 118 sym_comment = "unexpected class!"; |
116 } | 119 } |
117 printf("%s:\t; %s\n", sym->name, sym_comment); | 120 printf("%s:\t; %s\n", sym->name, sym_comment); |
121 if (!disasm_richsym || sym->class != C_EXT && sym->class != C_STAT) | |
122 return; | |
123 if (!sym->aux || sym->name[0] != '_' && sym->name[0] != '$') | |
124 return; | |
125 richsym_print_in_c(cpref, sym, 0); | |
118 } | 126 } |
119 | 127 |
120 void | 128 void |
121 disasm_emit_asciz(sec, pos, len) | 129 disasm_emit_asciz(sec, pos, len) |
122 struct internal_scnhdr *sec; | 130 struct internal_scnhdr *sec; |
345 disasm_bss(sec) | 353 disasm_bss(sec) |
346 struct internal_scnhdr *sec; | 354 struct internal_scnhdr *sec; |
347 { | 355 { |
348 unsigned m; | 356 unsigned m; |
349 struct internal_syment *sym; | 357 struct internal_syment *sym; |
350 char classbuf[8]; | 358 char classbuf[8], *cpref; |
351 | 359 |
352 putchar('\n'); | 360 putchar('\n'); |
353 for (m = 0; m < sec->nsymbols; m++) { | 361 for (m = 0; m < sec->nsymbols; m++) { |
354 sym = sec->sorted_symbols[m]; | 362 sym = sec->sorted_symbols[m]; |
355 printf("%08X %-7s %s\n", sym->value, | 363 printf("%08X %-7s %s\n", sym->value, |
356 storage_class_to_string(sym->class, classbuf), | 364 storage_class_to_string(sym->class, classbuf), |
357 sym->name); | 365 sym->name); |
366 if (!disasm_richsym || !sym->aux || sym->name[0] != '_') | |
367 continue; | |
368 switch (sym->class) { | |
369 case C_EXT: | |
370 cpref = "; "; | |
371 break; | |
372 case C_STAT: | |
373 cpref = "; static "; | |
374 break; | |
375 default: | |
376 continue; | |
377 } | |
378 richsym_print_in_c(cpref, sym, 0); | |
358 } | 379 } |
359 printf("%08X <end of section>\n", sec->size); | 380 printf("%08X <end of section>\n", sec->size); |
360 } | 381 } |
361 | 382 |
362 void | 383 void |
387 char *hintsfile = 0; | 408 char *hintsfile = 0; |
388 struct internal_scnhdr *sec; | 409 struct internal_scnhdr *sec; |
389 unsigned secnum; | 410 unsigned secnum; |
390 int c; | 411 int c; |
391 | 412 |
392 while ((c = getopt(argc, argv, "h:s")) != EOF) | 413 while ((c = getopt(argc, argv, "gh:s")) != EOF) |
393 switch (c) { | 414 switch (c) { |
415 case 'g': | |
416 disasm_richsym++; | |
417 continue; | |
394 case 'h': | 418 case 'h': |
395 hintsfile = optarg; | 419 hintsfile = optarg; |
396 continue; | 420 continue; |
397 case 's': | 421 case 's': |
398 auto_xlat_section_relocs = 0; | 422 auto_xlat_section_relocs = 0; |
409 get_int_symbol_table(); | 433 get_int_symbol_table(); |
410 if (hintsfile) | 434 if (hintsfile) |
411 read_hints_file(hintsfile); | 435 read_hints_file(hintsfile); |
412 extern_profile_report("Module"); | 436 extern_profile_report("Module"); |
413 sort_symbols_of_all_sec(); | 437 sort_symbols_of_all_sec(); |
438 if (disasm_richsym) | |
439 richsym_initial_preen(); | |
414 for (secnum = 0; secnum < nsections; secnum++) { | 440 for (secnum = 0; secnum < nsections; secnum++) { |
415 sec = sections + secnum; | 441 sec = sections + secnum; |
416 printf("=== %s ===\n", sec->name); | 442 printf("=== %s ===\n", sec->name); |
417 disasm_sec_by_type(sec); | 443 disasm_sec_by_type(sec); |
418 putchar('\n'); | 444 putchar('\n'); |