Mercurial > repos > blastem
annotate dis.c @ 2279:3b5fef896475
Fix edge case in m68k_invalidate_code_range that caused problems when loading save states
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 08 Jan 2023 14:20:43 -0800 |
parents | bf1bb893f104 |
children |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
197
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
197
diff
changeset
|
2 Copyright 2013 Michael Pavone |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
3 This file is part of BlastEm. |
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
197
diff
changeset
|
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
197
diff
changeset
|
5 */ |
2
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "68kinst.h" |
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include <stdio.h> |
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include <stdlib.h> |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
9 #include <string.h> |
805 | 10 #include <stdarg.h> |
947
d29722e3359c
Allow specification of named labels as command line arguments to the 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
11 #include <ctype.h> |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
12 #include "vos_program_module.h" |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
13 #include "tern.h" |
947
d29722e3359c
Allow specification of named labels as command line arguments to the 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
14 #include "util.h" |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
15 #include "disasm.h" |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
16 |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
17 int headless; |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
18 void render_errorbox(char *title, char *message) {} |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
19 void render_warnbox(char *title, char *message) {} |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
20 void render_infobox(char *title, char *message) {} |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
21 |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
22 void check_reference(disasm_context *context, m68kinst * inst, m68k_op_info * op) |
134 | 23 { |
24 switch(op->addr_mode) | |
25 { | |
26 case MODE_PC_DISPLACE: | |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
27 reference(context, inst->address + 2 + op->params.regs.displacement); |
134 | 28 break; |
29 case MODE_ABSOLUTE: | |
30 case MODE_ABSOLUTE_SHORT: | |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
31 reference(context, op->params.immed); |
134 | 32 break; |
33 } | |
34 } | |
35 | |
2132
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
36 typedef struct { |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
37 uint32_t address_off; |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
38 uint32_t address_end; |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
39 uint16_t *buffer; |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
40 } rom_def; |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
41 |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
42 uint16_t fetch(uint32_t address, void *data) |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
43 { |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
44 rom_def *rom = data; |
2273
ff726f53d75a
Fix diassembly involving absolute addresses with high bits set
Michael Pavone <pavone@retrodev.com>
parents:
2251
diff
changeset
|
45 address &= 0xFFFFFF; |
2132
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
46 if (address >= rom->address_off && address < rom->address_end) { |
2273
ff726f53d75a
Fix diassembly involving absolute addresses with high bits set
Michael Pavone <pavone@retrodev.com>
parents:
2251
diff
changeset
|
47 return rom->buffer[(address - rom->address_off) >> 1]; |
2132
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
48 } |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
49 return 0; |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
50 } |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
51 |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
52 void print_label_def(char *key, tern_val val, uint8_t valtype, void *data) |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
53 { |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
54 rom_def *rom = data; |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
55 label_def *label = val.ptrval; |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
56 uint32_t address = label->full_address & 0xFFFFFFF; |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
57 if (address >= rom->address_off && address < rom->address_end) { |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
58 return; |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
59 } |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
60 if (!label->referenced) { |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
61 return; |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
62 } |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
63 if (label->num_labels) { |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
64 for (int i = 0; i < label->num_labels; i++) |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
65 { |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
66 printf("%s equ $%X\n", label->labels[i], label->full_address); |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
67 } |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
68 } else { |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
69 printf("ADR_%X equ $%X\n", label->full_address, label->full_address); |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
70 } |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
71 } |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
72 |
2
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 int main(int argc, char ** argv) |
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 { |
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 long filesize; |
2091
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
76 unsigned short *filebuf = NULL; |
2
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 char disbuf[1024]; |
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 m68kinst instbuf; |
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 unsigned short * cur; |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
80 |
632
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
81 uint8_t labels = 0, addr = 0, only = 0, vos = 0, reset = 0; |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
82 disasm_context *context = create_68000_disasm(); |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
83 |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
84 |
1078
c4bfbf55d418
Added some hacky support for specifying a start offset in 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
947
diff
changeset
|
85 uint32_t address_off = 0, address_end; |
2105
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
86 uint8_t do_cd_labels = 0, main_cpu = 0; |
134 | 87 for(uint8_t opt = 2; opt < argc; ++opt) { |
88 if (argv[opt][0] == '-') { | |
197
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
89 FILE * address_log; |
134 | 90 switch (argv[opt][1]) |
91 { | |
92 case 'l': | |
93 labels = 1; | |
94 break; | |
95 case 'a': | |
96 addr = 1; | |
97 break; | |
151
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
148
diff
changeset
|
98 case 'o': |
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
148
diff
changeset
|
99 only = 1; |
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
148
diff
changeset
|
100 break; |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
101 case 'v': |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
102 vos = 1; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
103 break; |
632
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
104 case 'r': |
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
105 reset = 1; |
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
106 break; |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
107 case 'c': |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
108 do_cd_labels = 1; |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
109 break; |
2105
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
110 case 'm': |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
111 main_cpu = 1; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
112 break; |
1078
c4bfbf55d418
Added some hacky support for specifying a start offset in 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
947
diff
changeset
|
113 case 's': |
c4bfbf55d418
Added some hacky support for specifying a start offset in 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
947
diff
changeset
|
114 opt++; |
c4bfbf55d418
Added some hacky support for specifying a start offset in 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
947
diff
changeset
|
115 if (opt >= argc) { |
c4bfbf55d418
Added some hacky support for specifying a start offset in 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
947
diff
changeset
|
116 fputs("-s must be followed by an offset\n", stderr); |
c4bfbf55d418
Added some hacky support for specifying a start offset in 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
947
diff
changeset
|
117 exit(1); |
c4bfbf55d418
Added some hacky support for specifying a start offset in 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
947
diff
changeset
|
118 } |
c4bfbf55d418
Added some hacky support for specifying a start offset in 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
947
diff
changeset
|
119 address_off = strtol(argv[opt], NULL, 0); |
c4bfbf55d418
Added some hacky support for specifying a start offset in 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
947
diff
changeset
|
120 break; |
197
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
121 case 'f': |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
122 opt++; |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
123 if (opt >= argc) { |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
124 fputs("-f must be followed by a filename\n", stderr); |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
125 exit(1); |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
126 } |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
127 address_log = fopen(argv[opt], "r"); |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
128 if (!address_log) { |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
129 fprintf(stderr, "Failed to open %s for reading\n", argv[opt]); |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
130 exit(1); |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
131 } |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
132 while (fgets(disbuf, sizeof(disbuf), address_log)) { |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
133 if (disbuf[0]) { |
947
d29722e3359c
Allow specification of named labels as command line arguments to the 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
134 char *end; |
d29722e3359c
Allow specification of named labels as command line arguments to the 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
135 uint32_t address = strtol(disbuf, &end, 16); |
197
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
136 if (address) { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
137 defer_disasm(context, address); |
947
d29722e3359c
Allow specification of named labels as command line arguments to the 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
138 if (*end == '=') { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
139 add_label(context, strip_ws(end+1), address); |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
140 } else { |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
141 reference(context, address); |
947
d29722e3359c
Allow specification of named labels as command line arguments to the 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
142 } |
197
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
143 } |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
144 } |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
164
diff
changeset
|
145 } |
1594
137dbd05ceab
Fix some issues identified by cppcheck
Michael Pavone <pavone@retrodev.com>
parents:
1078
diff
changeset
|
146 fclose(address_log); |
134 | 147 } |
151
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
148
diff
changeset
|
148 } else { |
947
d29722e3359c
Allow specification of named labels as command line arguments to the 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
149 char *end; |
d29722e3359c
Allow specification of named labels as command line arguments to the 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
150 uint32_t address = strtol(argv[opt], &end, 16); |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
151 defer_disasm(context, address); |
947
d29722e3359c
Allow specification of named labels as command line arguments to the 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
152 if (*end == '=') { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
153 add_label(context, end+1, address); |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
154 } else { |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
155 reference(context, address); |
947
d29722e3359c
Allow specification of named labels as command line arguments to the 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
805
diff
changeset
|
156 } |
134 | 157 } |
158 } | |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
159 FILE * f = fopen(argv[1], "rb"); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
160 fseek(f, 0, SEEK_END); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
161 filesize = ftell(f); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
162 fseek(f, 0, SEEK_SET); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
163 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
164 char int_key[MAX_INT_KEY_SIZE]; |
2091
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
165 uint8_t is_scd_iso = 0; |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
166 uint8_t has_manual_defs = !!context->deferred; |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
167 if (vos) |
2
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 { |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
169 vos_program_module header; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
170 vos_read_header(f, &header); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
171 vos_read_alloc_module_map(f, &header); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
172 address_off = header.user_boundary; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
173 address_end = address_off + filesize - 0x1000; |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
174 defer_disasm(context, header.main_entry_link.code_address); |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
175 add_label(context, "main_entry_link", header.main_entry_link.code_address); |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
176 for (int i = 0; i < header.n_modules; i++) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
177 { |
632
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
178 if (!reset || header.module_map_entries[i].code_address != header.user_boundary) |
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
179 { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
180 defer_disasm(context, header.module_map_entries[i].code_address); |
632
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
181 } |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
182 add_label(context, header.module_map_entries[i].name.str, header.module_map_entries[i].code_address); |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
183 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
184 fseek(f, 0x1000, SEEK_SET); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
185 filebuf = malloc(filesize - 0x1000); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
186 if (fread(filebuf, 2, (filesize - 0x1000)/2, f) != (filesize - 0x1000)/2) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
187 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
188 fprintf(stderr, "Failure while reading file %s\n", argv[1]); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
189 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
190 fclose(f); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
191 for(cur = filebuf; cur - filebuf < ((filesize - 0x1000)/2); ++cur) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
192 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
193 *cur = (*cur >> 8) | (*cur << 8); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
194 } |
632
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
195 if (reset) |
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
196 { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
197 defer_disasm(context, filebuf[2] << 16 | filebuf[3]); |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
198 add_label(context, "reset", filebuf[2] << 16 | filebuf[3]); |
632
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
199 } |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
200 } else if (filesize > 0x1000) { |
2251
80dde7fb445b
Fix bug in disassembler SCD header handling
Michael Pavone <pavone@retrodev.com>
parents:
2213
diff
changeset
|
201 long boot_size = filesize > (16*2352) ? 16*2352 : filesize; |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
202 filebuf = malloc(boot_size); |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
203 if (fread(filebuf, 1, boot_size, f) != boot_size) { |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
204 fprintf(stderr, "Failure while reading file %s\n", argv[1]); |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
205 return 1; |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
206 } |
2091
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
207 is_scd_iso = !memcmp("SEGADISCSYSTEM ", filebuf, 0x10); |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
208 if (!is_scd_iso && !memcmp("SEGADISCSYSTEM ", filebuf + 0x8, 0x10)) { |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
209 is_scd_iso = 1; |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
210 uint32_t end = 16 * 2352; |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
211 if (end > filesize) { |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
212 end = (filesize / 2352) * 2352; |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
213 } |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
214 for(uint32_t offset = 0x10, dst_offset = 0; offset < end; offset += 2352, dst_offset += 2048) |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
215 { |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
216 memmove(filebuf + dst_offset/2, filebuf + offset/2, 2048); |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
217 } |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
218 boot_size = (end / 2352) * 2048; |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
219 } |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
220 if (is_scd_iso) { |
2105
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
221 fclose(f); |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
222 for(cur = filebuf; cur - filebuf < (boot_size/2); ++cur) |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
223 { |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
224 *cur = (*cur >> 8) | (*cur << 8); |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
225 } |
2105
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
226 if (main_cpu) { |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
227 uint32_t main_start = 0x200; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
228 uint32_t extra_start = filebuf[0x30/2] << 16 | filebuf[0x32/2]; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
229 uint32_t main_end = (filebuf[0x34/2] << 16 | filebuf[0x36/2]) + extra_start; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
230 if (main_end > boot_size) { |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
231 main_end = boot_size; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
232 } |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
233 address_off = 0xFF0000; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
234 address_end = address_off + main_end-main_start; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
235 filebuf += main_start / 2; |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
236 add_label(context, "start", 0xFF0000); |
2105
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
237 if (!has_manual_defs || !only) { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
238 defer_disasm(context, 0xFF0000); |
2105
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
239 } |
2110
f1238ffb30a3
Some very minor Sega CD disassembler improvements
Michael Pavone <pavone@retrodev.com>
parents:
2105
diff
changeset
|
240 uint32_t user_start; |
f1238ffb30a3
Some very minor Sega CD disassembler improvements
Michael Pavone <pavone@retrodev.com>
parents:
2105
diff
changeset
|
241 if (filebuf[0xA/2] == 0x57A) { |
f1238ffb30a3
Some very minor Sega CD disassembler improvements
Michael Pavone <pavone@retrodev.com>
parents:
2105
diff
changeset
|
242 //US |
f1238ffb30a3
Some very minor Sega CD disassembler improvements
Michael Pavone <pavone@retrodev.com>
parents:
2105
diff
changeset
|
243 user_start = 0xFF0584; |
f1238ffb30a3
Some very minor Sega CD disassembler improvements
Michael Pavone <pavone@retrodev.com>
parents:
2105
diff
changeset
|
244 } else if (filebuf[0xA/2] == 0x564) { |
f1238ffb30a3
Some very minor Sega CD disassembler improvements
Michael Pavone <pavone@retrodev.com>
parents:
2105
diff
changeset
|
245 //EU |
f1238ffb30a3
Some very minor Sega CD disassembler improvements
Michael Pavone <pavone@retrodev.com>
parents:
2105
diff
changeset
|
246 user_start = 0xFF056E; |
f1238ffb30a3
Some very minor Sega CD disassembler improvements
Michael Pavone <pavone@retrodev.com>
parents:
2105
diff
changeset
|
247 } else { |
f1238ffb30a3
Some very minor Sega CD disassembler improvements
Michael Pavone <pavone@retrodev.com>
parents:
2105
diff
changeset
|
248 //JP |
f1238ffb30a3
Some very minor Sega CD disassembler improvements
Michael Pavone <pavone@retrodev.com>
parents:
2105
diff
changeset
|
249 user_start = 0xFF0156; |
f1238ffb30a3
Some very minor Sega CD disassembler improvements
Michael Pavone <pavone@retrodev.com>
parents:
2105
diff
changeset
|
250 } |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
251 add_label(context, "user_start", user_start); |
2105
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
252 do_cd_labels = 1; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
253 } else { |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
254 uint32_t sub_start =filebuf[0x40/2] << 16 | filebuf[0x42/2]; |
2274
bf1bb893f104
Properly ignore low bits of SP start address in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2273
diff
changeset
|
255 sub_start &= ~0x7FF; |
2146
0c0d4233d826
Fix SP end address in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2132
diff
changeset
|
256 uint32_t sub_end = sub_start + (filebuf[0x44/2] << 16 | filebuf[0x46/2]); |
2105
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
257 if (sub_start > (boot_size - 0x20)) { |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
258 fprintf(stderr, "System Program start offset is %X, but image is only %X bytes\n", sub_start, (uint32_t)boot_size); |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
259 return 1; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
260 } |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
261 if (sub_end > boot_size) { |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
262 sub_end = boot_size; |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
263 } |
2105
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
264 uint32_t offset_start = (filebuf[(sub_start + 0x18)/2] << 16 | filebuf[(sub_start + 0x1A)/2]) + sub_start; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
265 for(uint32_t cur = offset_start, index = 0; cur < sub_end && filebuf[cur/2]; cur+=2, ++index) |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
266 { |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
267 uint32_t offset = offset_start + filebuf[cur/2]; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
268 if (offset >= boot_size) { |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
269 break; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
270 } |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
271 static const char* fixed_names[3] = { |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
272 "init", |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
273 "main", |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
274 "int_2" |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
275 }; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
276 char namebuf[32]; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
277 const char *name; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
278 if (index < 3) { |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
279 name = fixed_names[index]; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
280 } else { |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
281 name = namebuf; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
282 sprintf(namebuf, "usercall%u", index); |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
283 } |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
284 uint32_t address = 0x6000 + offset - sub_start; |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
285 add_label(context, name, address); |
2105
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
286 if (!has_manual_defs || !only) { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
287 defer_disasm(context, address); |
2105
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
288 } |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
289 } |
2105
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
290 |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
291 do_cd_labels = 1; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
292 filebuf += sub_start / 2; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
293 address_off = 0x6000; |
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
294 address_end = sub_end-sub_start + address_off; |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
295 } |
2091
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
296 } |
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
297 } |
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
298 if (!vos && !is_scd_iso) { |
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
299 if (filebuf) { |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
300 if (filesize > (32*1024)) { |
2091
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
301 filebuf = realloc(filebuf, filesize); |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
302 fseek(f, 32*1024, SEEK_SET); |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
303 uint32_t to_read = filesize/2 - 16*1024; |
2091
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
304 if (fread(filebuf + 16*1024, 2, to_read, f) != to_read) |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
305 { |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
306 fprintf(stderr, "Failure while reading file %s\n", argv[1]); |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
307 } |
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
308 } |
2091
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
309 } else { |
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
310 filebuf = malloc(filesize); |
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
311 if (fread(filebuf, 2, filesize/2, f) != filesize/2) |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
312 { |
2091
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
313 fprintf(stderr, "Failure while reading file %s\n", argv[1]); |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
314 } |
2091
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
315 } |
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
316 address_end = address_off + filesize; |
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
317 fclose(f); |
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
318 for(cur = filebuf; cur - filebuf < (filesize/2); ++cur) |
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
319 { |
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
320 *cur = (*cur >> 8) | (*cur << 8); |
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
321 } |
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
322 if (!address_off) { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
323 process_m68k_vectors(context, filebuf, context->deferred && only); |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
324 } |
2
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
325 } |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
326 if (do_cd_labels) { |
2105
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
327 if (main_cpu) { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
328 add_segacd_maincpu_labels(context); |
2105
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
329 } else { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
330 add_segacd_subcpu_labels(context); |
2105
1bda10d60b29
Add some enhancements for disassembling Main CPU Sega CD code
Michael Pavone <pavone@retrodev.com>
parents:
2102
diff
changeset
|
331 } |
2085
1ff67ce37085
Add some Sega CD specific enhancements to disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
332 } |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
333 uint32_t size, tmp_addr; |
139
cce22fb4c450
Properly support references to odd addresses in label generation in disassembler. Add labels for start and interrupts.
Mike Pavone <pavone@retrodev.com>
parents:
134
diff
changeset
|
334 uint32_t address; |
2132
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
335 rom_def rom = { |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
336 .address_off = address_off, |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
337 .address_end = address_end, |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
338 .buffer = filebuf |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
339 }; |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
340 uint8_t valid_address; |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
341 while(context->deferred) { |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
342 do { |
2132
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
343 valid_address = 0; |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
344 address = context->deferred->address; |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
345 if (!is_visited(context, address)) { |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
346 address &= context->address_mask; |
2132
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
347 if (address < address_end && address >= address_off) { |
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
348 valid_address = 1; |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
349 address = context->deferred->address; |
2091
36a9cf4db65f
Fix some disassembler bugs introduced with Sega CD changes
Michael Pavone <pavone@retrodev.com>
parents:
2085
diff
changeset
|
350 } |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
351 } |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
352 deferred_addr *tmpd = context->deferred; |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
353 context->deferred = context->deferred->next; |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
354 free(tmpd); |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
355 } while(context->deferred && !valid_address); |
2132
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
356 if (!valid_address) { |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
357 break; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
358 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
359 for(;;) { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
360 if ((address & context->address_mask) > address_end || address < address_off) { |
48
0bdda50c7364
Don't try to disassemble addresses beyond the end of the cartridge
Mike Pavone <pavone@retrodev.com>
parents:
47
diff
changeset
|
361 break; |
0bdda50c7364
Don't try to disassemble addresses beyond the end of the cartridge
Mike Pavone <pavone@retrodev.com>
parents:
47
diff
changeset
|
362 } |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
363 visit(context, address); |
2132
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
364 address = m68k_decode(fetch, &rom, &instbuf, address); |
111 | 365 //m68k_disasm(&instbuf, disbuf); |
366 //printf("%X: %s\n", instbuf.address, disbuf); | |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
367 check_reference(context, &instbuf, &(instbuf.src)); |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
368 check_reference(context, &instbuf, &(instbuf.dst)); |
148
4a400aec81bb
Bail out of disassembly of a particular stream when we hit an invalid instruction
Mike Pavone <pavone@retrodev.com>
parents:
139
diff
changeset
|
369 if (instbuf.op == M68K_ILLEGAL || instbuf.op == M68K_RTS || instbuf.op == M68K_RTE || instbuf.op == M68K_INVALID) { |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
370 break; |
164
afbfb0ac0256
Small fix to disassembler
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
371 } |
afbfb0ac0256
Small fix to disassembler
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
372 if (instbuf.op == M68K_BCC || instbuf.op == M68K_DBCC || instbuf.op == M68K_BSR) { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
373 tmp_addr = instbuf.address + 2 + instbuf.src.params.immed; |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
374 reference(context, tmp_addr); |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
375 if (instbuf.op == M68K_BCC && instbuf.extra.cond == COND_TRUE) { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
376 address = tmp_addr; |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
377 if (is_visited(context, address)) { |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
378 break; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
379 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
380 } else { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
381 defer_disasm(context, tmp_addr); |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
382 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
383 } else if(instbuf.op == M68K_JMP) { |
80
7b1e16e981ef
Fix bug in disassembler that caused it to disassemble addresses it shouldn't
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
384 if (instbuf.src.addr_mode == MODE_ABSOLUTE || instbuf.src.addr_mode == MODE_ABSOLUTE_SHORT) { |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
385 address = instbuf.src.params.immed; |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
386 if (is_visited(context, address)) { |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
387 break; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
388 } |
564
316facea756d
Fix PC displacement mode check in disassembler so that jmps involving a register are handled correctly
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
389 } else if (instbuf.src.addr_mode == MODE_PC_DISPLACE) { |
114
e821b6fde0e4
Allow jmp/jsr to follow pc-relative addresses in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
111
diff
changeset
|
390 address = instbuf.src.params.regs.displacement + instbuf.address + 2; |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
391 if (is_visited(context, address)) { |
114
e821b6fde0e4
Allow jmp/jsr to follow pc-relative addresses in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
111
diff
changeset
|
392 break; |
e821b6fde0e4
Allow jmp/jsr to follow pc-relative addresses in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
111
diff
changeset
|
393 } |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
394 } else { |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
395 break; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
396 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
397 } else if(instbuf.op == M68K_JSR) { |
80
7b1e16e981ef
Fix bug in disassembler that caused it to disassemble addresses it shouldn't
Mike Pavone <pavone@retrodev.com>
parents:
48
diff
changeset
|
398 if (instbuf.src.addr_mode == MODE_ABSOLUTE || instbuf.src.addr_mode == MODE_ABSOLUTE_SHORT) { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
399 defer_disasm(context, instbuf.src.params.immed); |
164
afbfb0ac0256
Small fix to disassembler
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
400 } else if (instbuf.src.addr_mode == MODE_PC_DISPLACE) { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
401 defer_disasm(context, instbuf.src.params.regs.displacement + instbuf.address + 2); |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
402 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
403 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
404 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
405 } |
134 | 406 if (labels) { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
407 tern_foreach(context->labels, print_label_def, &rom); |
134 | 408 puts(""); |
409 } | |
633
a759f4e38488
Fix translation of 68K address to buffer location when address_off != 0
Michael Pavone <pavone@retrodev.com>
parents:
632
diff
changeset
|
410 for (address = address_off; address < address_end; address+=2) { |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
411 if (is_visited(context, address)) { |
2132
7451f970ee66
Add some weak labels for a few exception vectors in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2110
diff
changeset
|
412 m68k_decode(fetch, &rom, &instbuf, address); |
134 | 413 if (labels) { |
2213
53411df7fc71
More 68K disassembler refactoring and fix Windows build failure
Michael Pavone <pavone@retrodev.com>
parents:
2206
diff
changeset
|
414 m68k_disasm_labels(&instbuf, disbuf, context); |
2206
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
415 label_def *label = find_label(context, address); |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
416 if (label) { |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
417 if (label->num_labels) { |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
418 for (int i = 0; i < label->num_labels; i++) |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
419 { |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
420 printf("%s:\n", label->labels[i]); |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
421 } |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
422 } else { |
4c265d2f6c88
Minor refactor of 68K disassembler
Michael Pavone <pavone@retrodev.com>
parents:
2146
diff
changeset
|
423 printf("ADR_%X:\n", label->full_address); |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
424 } |
134 | 425 } |
426 if (addr) { | |
427 printf("\t%s\t;%X\n", disbuf, instbuf.address); | |
428 } else { | |
429 printf("\t%s\n", disbuf); | |
430 } | |
431 } else { | |
432 m68k_disasm(&instbuf, disbuf); | |
433 printf("%X: %s\n", instbuf.address, disbuf); | |
434 } | |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
435 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
436 } |
2
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
437 return 0; |
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
438 } |