Mercurial > repos > blastem
annotate dis.c @ 865:305c85c0b954
Allow 68K debug print to read from arbitrary memory regions
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 06 Nov 2015 11:44:51 -0800 |
parents | 3eced113081c |
children | d29722e3359c |
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> |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
11 #include "vos_program_module.h" |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
12 #include "tern.h" |
2
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
14 uint8_t visited[(16*1024*1024)/16]; |
635
6992a1b07714
Fix logic for automatic label generation.
Michael Pavone <pavone@retrodev.com>
parents:
634
diff
changeset
|
15 uint16_t label[(16*1024*1024)/8]; |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
16 |
805 | 17 void fatal_error(char *format, ...) |
18 { | |
19 va_list args; | |
20 va_start(args, format); | |
21 vfprintf(stderr, format, args); | |
22 va_end(args); | |
23 exit(1); | |
24 } | |
25 | |
26 | |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
27 void visit(uint32_t address) |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
28 { |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
29 address &= 0xFFFFFF; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
30 visited[address/16] |= 1 << ((address / 2) % 8); |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
31 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
32 |
134 | 33 void reference(uint32_t address) |
34 { | |
35 address &= 0xFFFFFF; | |
36 //printf("referenced: %X\n", address); | |
635
6992a1b07714
Fix logic for automatic label generation.
Michael Pavone <pavone@retrodev.com>
parents:
634
diff
changeset
|
37 label[address/16] |= 1 << (address % 16); |
134 | 38 } |
39 | |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
40 uint8_t is_visited(uint32_t address) |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
41 { |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
42 address &= 0xFFFFFF; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
43 return visited[address/16] & (1 << ((address / 2) % 8)); |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
44 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
45 |
635
6992a1b07714
Fix logic for automatic label generation.
Michael Pavone <pavone@retrodev.com>
parents:
634
diff
changeset
|
46 uint16_t is_label(uint32_t address) |
134 | 47 { |
48 address &= 0xFFFFFF; | |
635
6992a1b07714
Fix logic for automatic label generation.
Michael Pavone <pavone@retrodev.com>
parents:
634
diff
changeset
|
49 return label[address/16] & (1 << (address % 16)); |
134 | 50 } |
51 | |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
52 typedef struct { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
53 uint32_t num_labels; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
54 uint32_t storage; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
55 char *labels[]; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
56 } label_names; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
57 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
58 tern_node * add_label(tern_node * head, char * name, uint32_t address) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
59 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
60 char key[MAX_INT_KEY_SIZE]; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
61 address &= 0xFFFFFF; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
62 reference(address); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
63 tern_int_key(address, key); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
64 label_names * names = tern_find_ptr(head, key); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
65 if (names) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
66 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
67 if (names->num_labels == names->storage) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
68 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
69 names->storage = names->storage + (names->storage >> 1); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
70 names = realloc(names, sizeof(label_names) + names->storage * sizeof(char *)); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
71 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
72 } else { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
73 names = malloc(sizeof(label_names) + 4 * sizeof(char *)); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
74 names->num_labels = 0; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
75 names->storage = 4; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
76 head = tern_insert_ptr(head, key, names); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
77 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
78 names->labels[names->num_labels++] = strdup(name); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
79 return head; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
80 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
81 |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
82 typedef struct deferred { |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
83 uint32_t address; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
84 struct deferred *next; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
85 } deferred; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
86 |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
87 deferred * defer(uint32_t address, deferred * next) |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
88 { |
639
e263e1ac6038
Ignore odd addresses in calls to defer in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
635
diff
changeset
|
89 if (is_visited(address) || address & 1) { |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
90 return next; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
91 } |
111 | 92 //printf("deferring %X\n", address); |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
93 deferred * d = malloc(sizeof(deferred)); |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
94 d->address = address; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
95 d->next = next; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
96 return d; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
97 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
98 |
134 | 99 void check_reference(m68kinst * inst, m68k_op_info * op) |
100 { | |
101 switch(op->addr_mode) | |
102 { | |
103 case MODE_PC_DISPLACE: | |
104 reference(inst->address + 2 + op->params.regs.displacement); | |
105 break; | |
106 case MODE_ABSOLUTE: | |
107 case MODE_ABSOLUTE_SHORT: | |
108 reference(op->params.immed); | |
109 break; | |
110 } | |
111 } | |
112 | |
634
4a6ec64acd79
Better support for labels sourced from VOS program module header
Michael Pavone <pavone@retrodev.com>
parents:
633
diff
changeset
|
113 int label_fun(char *dst, uint32_t address, void * data) |
4a6ec64acd79
Better support for labels sourced from VOS program module header
Michael Pavone <pavone@retrodev.com>
parents:
633
diff
changeset
|
114 { |
4a6ec64acd79
Better support for labels sourced from VOS program module header
Michael Pavone <pavone@retrodev.com>
parents:
633
diff
changeset
|
115 tern_node * labels = data; |
4a6ec64acd79
Better support for labels sourced from VOS program module header
Michael Pavone <pavone@retrodev.com>
parents:
633
diff
changeset
|
116 char key[MAX_INT_KEY_SIZE]; |
4a6ec64acd79
Better support for labels sourced from VOS program module header
Michael Pavone <pavone@retrodev.com>
parents:
633
diff
changeset
|
117 label_names * names = tern_find_ptr(labels, tern_int_key(address & 0xFFFFFF, key)); |
4a6ec64acd79
Better support for labels sourced from VOS program module header
Michael Pavone <pavone@retrodev.com>
parents:
633
diff
changeset
|
118 if (names) |
4a6ec64acd79
Better support for labels sourced from VOS program module header
Michael Pavone <pavone@retrodev.com>
parents:
633
diff
changeset
|
119 { |
4a6ec64acd79
Better support for labels sourced from VOS program module header
Michael Pavone <pavone@retrodev.com>
parents:
633
diff
changeset
|
120 return sprintf(dst, "%s", names->labels[0]); |
4a6ec64acd79
Better support for labels sourced from VOS program module header
Michael Pavone <pavone@retrodev.com>
parents:
633
diff
changeset
|
121 } else { |
4a6ec64acd79
Better support for labels sourced from VOS program module header
Michael Pavone <pavone@retrodev.com>
parents:
633
diff
changeset
|
122 return m68k_default_label_fun(dst, address, NULL); |
4a6ec64acd79
Better support for labels sourced from VOS program module header
Michael Pavone <pavone@retrodev.com>
parents:
633
diff
changeset
|
123 } |
4a6ec64acd79
Better support for labels sourced from VOS program module header
Michael Pavone <pavone@retrodev.com>
parents:
633
diff
changeset
|
124 } |
4a6ec64acd79
Better support for labels sourced from VOS program module header
Michael Pavone <pavone@retrodev.com>
parents:
633
diff
changeset
|
125 |
2
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 int main(int argc, char ** argv) |
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 { |
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 long filesize; |
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 unsigned short *filebuf; |
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 char disbuf[1024]; |
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 m68kinst instbuf; |
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 unsigned short * cur; |
151
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
148
diff
changeset
|
133 deferred *def = NULL, *tmpd; |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
134 |
632
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
135 uint8_t labels = 0, addr = 0, only = 0, vos = 0, reset = 0; |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
136 |
134 | 137 for(uint8_t opt = 2; opt < argc; ++opt) { |
138 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
|
139 FILE * address_log; |
134 | 140 switch (argv[opt][1]) |
141 { | |
142 case 'l': | |
143 labels = 1; | |
144 break; | |
145 case 'a': | |
146 addr = 1; | |
147 break; | |
151
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
148
diff
changeset
|
148 case 'o': |
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
148
diff
changeset
|
149 only = 1; |
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
148
diff
changeset
|
150 break; |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
151 case 'v': |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
152 vos = 1; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
153 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 } |
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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 } |
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
|
168 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
|
169 if (disbuf[0]) { |
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
|
170 uint32_t address = strtol(disbuf, NULL, 16); |
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
|
171 if (address) { |
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
|
172 def = defer(address, def); |
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
|
173 reference(address); |
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
|
174 } |
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
|
175 } |
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
|
176 } |
134 | 177 } |
151
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
148
diff
changeset
|
178 } else { |
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
148
diff
changeset
|
179 uint32_t address = strtol(argv[opt], NULL, 16); |
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
148
diff
changeset
|
180 def = defer(address, def); |
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
148
diff
changeset
|
181 reference(address); |
134 | 182 } |
183 } | |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
184 |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
185 FILE * f = fopen(argv[1], "rb"); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
186 fseek(f, 0, SEEK_END); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
187 filesize = ftell(f); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
188 fseek(f, 0, SEEK_SET); |
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 tern_node * named_labels = NULL; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
191 char int_key[MAX_INT_KEY_SIZE]; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
192 uint32_t address_off, address_end; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
193 if (vos) |
2
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 { |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
195 vos_program_module header; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
196 vos_read_header(f, &header); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
197 vos_read_alloc_module_map(f, &header); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
198 address_off = header.user_boundary; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
199 address_end = address_off + filesize - 0x1000; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
200 def = defer(header.main_entry_link.code_address, def); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
201 named_labels = add_label(named_labels, "main_entry_link", header.main_entry_link.code_address); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
202 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
|
203 { |
632
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
204 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
|
205 { |
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
206 def = defer(header.module_map_entries[i].code_address, def); |
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
207 } |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
208 named_labels = add_label(named_labels, header.module_map_entries[i].name.str, header.module_map_entries[i].code_address); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
209 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
210 fseek(f, 0x1000, SEEK_SET); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
211 filebuf = malloc(filesize - 0x1000); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
212 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
|
213 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
214 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
|
215 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
216 fclose(f); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
217 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
|
218 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
219 *cur = (*cur >> 8) | (*cur << 8); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
220 } |
632
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
221 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
|
222 { |
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
223 def = defer(filebuf[2] << 16 | filebuf[3], def); |
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
224 named_labels = add_label(named_labels, "reset", filebuf[2] << 16 | filebuf[3]); |
80e111b48d4b
Add -r option to indicate VOS program module contains a 68K reset vector
Michael Pavone <pavone@retrodev.com>
parents:
631
diff
changeset
|
225 } |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
226 } else { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
227 address_off = 0; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
228 address_end = filesize; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
229 filebuf = malloc(filesize); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
230 if (fread(filebuf, 2, filesize/2, f) != filesize/2) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
231 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
232 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
|
233 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
234 fclose(f); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
235 for(cur = filebuf; cur - filebuf < (filesize/2); ++cur) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
236 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
237 *cur = (*cur >> 8) | (*cur << 8); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
238 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
239 uint32_t start = filebuf[2] << 16 | filebuf[3]; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
240 uint32_t int_2 = filebuf[0x68/2] << 16 | filebuf[0x6A/2]; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
241 uint32_t int_4 = filebuf[0x70/2] << 16 | filebuf[0x72/2]; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
242 uint32_t int_6 = filebuf[0x78/2] << 16 | filebuf[0x7A/2]; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
243 named_labels = add_label(named_labels, "start", start); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
244 named_labels = add_label(named_labels, "int_2", int_2); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
245 named_labels = add_label(named_labels, "int_4", int_4); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
246 named_labels = add_label(named_labels, "int_6", int_6); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
247 if (!def || !only) { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
248 def = defer(start, def); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
249 def = defer(int_2, def); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
250 def = defer(int_4, def); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
251 def = defer(int_6, def); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
252 } |
2
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 } |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
254 uint16_t *encoded, *next; |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
255 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
|
256 uint32_t address; |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
257 while(def) { |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
258 do { |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
259 encoded = NULL; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
260 address = def->address; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
261 if (!is_visited(address)) { |
633
a759f4e38488
Fix translation of 68K address to buffer location when address_off != 0
Michael Pavone <pavone@retrodev.com>
parents:
632
diff
changeset
|
262 encoded = filebuf + (address - address_off)/2; |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
263 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
264 tmpd = def; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
265 def = def->next; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
266 free(tmpd); |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
267 } while(def && encoded == NULL); |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
268 if (!encoded) { |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
269 break; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
270 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
271 for(;;) { |
633
a759f4e38488
Fix translation of 68K address to buffer location when address_off != 0
Michael Pavone <pavone@retrodev.com>
parents:
632
diff
changeset
|
272 if (address > 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
|
273 break; |
0bdda50c7364
Don't try to disassemble addresses beyond the end of the cartridge
Mike Pavone <pavone@retrodev.com>
parents:
47
diff
changeset
|
274 } |
47
4b6c667326a1
Fix bug in address visitation in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
44
diff
changeset
|
275 visit(address); |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
276 next = m68k_decode(encoded, &instbuf, address); |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
277 address += (next-encoded)*2; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
278 encoded = next; |
111 | 279 //m68k_disasm(&instbuf, disbuf); |
280 //printf("%X: %s\n", instbuf.address, disbuf); | |
134 | 281 check_reference(&instbuf, &(instbuf.src)); |
282 check_reference(&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
|
283 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
|
284 break; |
164
afbfb0ac0256
Small fix to disassembler
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
285 } |
afbfb0ac0256
Small fix to disassembler
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
286 if (instbuf.op == M68K_BCC || instbuf.op == M68K_DBCC || instbuf.op == M68K_BSR) { |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
287 if (instbuf.op == M68K_BCC && instbuf.extra.cond == COND_TRUE) { |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
288 address = instbuf.address + 2 + instbuf.src.params.immed; |
633
a759f4e38488
Fix translation of 68K address to buffer location when address_off != 0
Michael Pavone <pavone@retrodev.com>
parents:
632
diff
changeset
|
289 encoded = filebuf + (address - address_off)/2; |
134 | 290 reference(address); |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
291 if (is_visited(address)) { |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
292 break; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
293 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
294 } else { |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
295 tmp_addr = instbuf.address + 2 + instbuf.src.params.immed; |
134 | 296 reference(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
|
297 def = defer(tmp_addr, def); |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
298 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
299 } 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
|
300 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
|
301 address = instbuf.src.params.immed; |
633
a759f4e38488
Fix translation of 68K address to buffer location when address_off != 0
Michael Pavone <pavone@retrodev.com>
parents:
632
diff
changeset
|
302 encoded = filebuf + (address - address_off)/2; |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
303 if (is_visited(address)) { |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
304 break; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
305 } |
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
|
306 } 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
|
307 address = instbuf.src.params.regs.displacement + instbuf.address + 2; |
633
a759f4e38488
Fix translation of 68K address to buffer location when address_off != 0
Michael Pavone <pavone@retrodev.com>
parents:
632
diff
changeset
|
308 encoded = filebuf + (address - address_off)/2; |
114
e821b6fde0e4
Allow jmp/jsr to follow pc-relative addresses in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
111
diff
changeset
|
309 if (is_visited(address)) { |
e821b6fde0e4
Allow jmp/jsr to follow pc-relative addresses in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
111
diff
changeset
|
310 break; |
e821b6fde0e4
Allow jmp/jsr to follow pc-relative addresses in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
111
diff
changeset
|
311 } |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
312 } else { |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
313 break; |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
314 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
315 } 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
|
316 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
|
317 def = defer(instbuf.src.params.immed, def); |
164
afbfb0ac0256
Small fix to disassembler
Mike Pavone <pavone@retrodev.com>
parents:
151
diff
changeset
|
318 } 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
|
319 def = defer(instbuf.src.params.regs.displacement + instbuf.address + 2, def); |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
320 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
321 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
322 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
323 } |
134 | 324 if (labels) { |
640
c806b96b86eb
Add equates for address references below address_off
Michael Pavone <pavone@retrodev.com>
parents:
639
diff
changeset
|
325 for (address = 0; address < address_off; address++) { |
c806b96b86eb
Add equates for address references below address_off
Michael Pavone <pavone@retrodev.com>
parents:
639
diff
changeset
|
326 if (is_label(address)) { |
c806b96b86eb
Add equates for address references below address_off
Michael Pavone <pavone@retrodev.com>
parents:
639
diff
changeset
|
327 printf("ADR_%X equ $%X\n", address, address); |
c806b96b86eb
Add equates for address references below address_off
Michael Pavone <pavone@retrodev.com>
parents:
639
diff
changeset
|
328 } |
c806b96b86eb
Add equates for address references below address_off
Michael Pavone <pavone@retrodev.com>
parents:
639
diff
changeset
|
329 } |
134 | 330 for (address = filesize; address < (16*1024*1024); address++) { |
704
1a14f5f6c6a1
Properly print equ for named labels that point outside the cartridge area in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
652
diff
changeset
|
331 char key[MAX_INT_KEY_SIZE]; |
1a14f5f6c6a1
Properly print equ for named labels that point outside the cartridge area in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
652
diff
changeset
|
332 tern_int_key(address, key); |
1a14f5f6c6a1
Properly print equ for named labels that point outside the cartridge area in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
652
diff
changeset
|
333 label_names *names = tern_find_ptr(named_labels, key); |
1a14f5f6c6a1
Properly print equ for named labels that point outside the cartridge area in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
652
diff
changeset
|
334 if (names) { |
1a14f5f6c6a1
Properly print equ for named labels that point outside the cartridge area in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
652
diff
changeset
|
335 for (int i = 0; i < names->num_labels; i++) |
1a14f5f6c6a1
Properly print equ for named labels that point outside the cartridge area in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
652
diff
changeset
|
336 { |
1a14f5f6c6a1
Properly print equ for named labels that point outside the cartridge area in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
652
diff
changeset
|
337 printf("%s equ $%X\n", names->labels[i], address); |
1a14f5f6c6a1
Properly print equ for named labels that point outside the cartridge area in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
652
diff
changeset
|
338 } |
1a14f5f6c6a1
Properly print equ for named labels that point outside the cartridge area in disassembler
Michael Pavone <pavone@retrodev.com>
parents:
652
diff
changeset
|
339 } else if (is_label(address)) { |
134 | 340 printf("ADR_%X equ $%X\n", address, address); |
341 } | |
342 } | |
343 puts(""); | |
344 } | |
633
a759f4e38488
Fix translation of 68K address to buffer location when address_off != 0
Michael Pavone <pavone@retrodev.com>
parents:
632
diff
changeset
|
345 for (address = address_off; address < address_end; 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
|
346 if (is_visited(address)) { |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
347 encoded = filebuf + (address-address_off)/2; |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
348 m68k_decode(encoded, &instbuf, address); |
134 | 349 if (labels) { |
634
4a6ec64acd79
Better support for labels sourced from VOS program module header
Michael Pavone <pavone@retrodev.com>
parents:
633
diff
changeset
|
350 m68k_disasm_labels(&instbuf, disbuf, label_fun, named_labels); |
631
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
351 char keybuf[MAX_INT_KEY_SIZE]; |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
352 label_names * names = tern_find_ptr(named_labels, tern_int_key(address, keybuf)); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
353 if (names) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
354 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
355 for (int i = 0; i < names->num_labels; i++) |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
356 { |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
357 printf("%s:\n", names->labels[i]); |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
358 } |
de6f00204fa2
Add support for disassembling VOS program modules
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
359 } else if (is_label(instbuf.address)) { |
134 | 360 printf("ADR_%X:\n", instbuf.address); |
361 } | |
362 if (addr) { | |
363 printf("\t%s\t;%X\n", disbuf, instbuf.address); | |
364 } else { | |
365 printf("\t%s\n", disbuf); | |
366 } | |
367 } else { | |
368 m68k_disasm(&instbuf, disbuf); | |
369 printf("%X: %s\n", instbuf.address, disbuf); | |
370 } | |
44
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
371 } |
ec71370820f2
Add logic for following control flow based on logic in the translator
Mike Pavone <pavone@retrodev.com>
parents:
20
diff
changeset
|
372 } |
2
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
373 return 0; |
5df303bf72e6
Improve 68K instruction decoding. Add simple disassembler.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
374 } |