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