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