Mercurial > repos > blastem
annotate jagdis.c @ 2138:b6338e18787e
Fix some dynarec code invalidation issues
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 19 Mar 2022 15:50:45 -0700 |
parents | 4987fddd42a0 |
children |
rev | line source |
---|---|
1093
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 /* |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 Copyright 2013 Michael Pavone |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 This file is part of BlastEm. |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
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. |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 */ |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include <stdio.h> |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include <stdlib.h> |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include <string.h> |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include <stdarg.h> |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include <ctype.h> |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 #include "tern.h" |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 #include "util.h" |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 #include "jagcpu.h" |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 uint8_t visited[(16*1024*1024)/16]; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 uint16_t label[(16*1024*1024)/8]; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 void fatal_error(char *format, ...) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 va_list args; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 va_start(args, format); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 vfprintf(stderr, format, args); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 va_end(args); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 exit(1); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 void visit(uint32_t address) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 address &= 0xFFFFFF; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 visited[address/16] |= 1 << ((address / 2) % 8); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 void reference(uint32_t address) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 address &= 0xFFFFFF; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 //printf("referenced: %X\n", address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 label[address/16] |= 1 << (address % 16); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 uint8_t is_visited(uint32_t address) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 address &= 0xFFFFFF; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 return visited[address/16] & (1 << ((address / 2) % 8)); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 uint16_t is_label(uint32_t address) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 address &= 0xFFFFFF; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 return label[address/16] & (1 << (address % 16)); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 typedef struct { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 uint32_t num_labels; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 uint32_t storage; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 char *labels[]; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 } label_names; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 tern_node * add_label(tern_node * head, char * name, uint32_t address) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 char key[MAX_INT_KEY_SIZE]; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 address &= 0xFFFFFF; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 reference(address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 tern_int_key(address, key); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 label_names * names = tern_find_ptr(head, key); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 if (names) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 if (names->num_labels == names->storage) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 names->storage = names->storage + (names->storage >> 1); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 names = realloc(names, sizeof(label_names) + names->storage * sizeof(char *)); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 } else { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 names = malloc(sizeof(label_names) + 4 * sizeof(char *)); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 names->num_labels = 0; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 names->storage = 4; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 head = tern_insert_ptr(head, key, names); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 names->labels[names->num_labels++] = strdup(name); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 return head; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 typedef struct deferred { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 uint32_t address; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 struct deferred *next; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 } deferred; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 deferred * defer(uint32_t address, deferred * next) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 if (is_visited(address) || address & 1) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 return next; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 //printf("deferring %X\n", address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 deferred * d = malloc(sizeof(deferred)); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 d->address = address; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 d->next = next; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 return d; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 void check_reference(uint16_t inst, uint32_t address, uint8_t is_gpu) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 if (jag_opcode(inst, is_gpu) == JAG_JR) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 reference(jag_jr_dest(inst, address)); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 char * strip_ws(char * text) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 while (*text && (!isprint(*text) || isblank(*text))) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 text++; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 char * ret = text; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 text = ret + strlen(ret) - 1; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 while (text > ret && (!isprint(*text) || isblank(*text))) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 *text = 0; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 text--; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 return ret; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 int main(int argc, char ** argv) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 long filesize; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 unsigned short *filebuf; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 char disbuf[1024]; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 unsigned short * cur; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 deferred *def = NULL, *tmpd; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 uint32_t start = 0xFFFFFFFF; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 uint8_t labels = 0, addr = 0, only = 0, vos = 0, reset = 0; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 tern_node * named_labels = NULL; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 uint32_t address_off = 0xFFFFFFFF, address_end; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 uint8_t is_gpu = 1; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 for(uint8_t opt = 2; opt < argc; ++opt) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 if (argv[opt][0] == '-') { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 FILE * address_log; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 switch (argv[opt][1]) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 case 'l': |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 labels = 1; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 break; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 case 'a': |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 addr = 1; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 break; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 case 'o': |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 only = 1; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 break; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 case 'r': |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 reset = 1; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 break; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 case 's': |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 opt++; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 if (opt >= argc) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 fputs("-s must be followed by an offset\n", stderr); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 exit(1); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 address_off = strtol(argv[opt], NULL, 0); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 break; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 case 'p': |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 opt++; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 if (opt >= argc) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 fputs("-p must be followed by a starting PC value\n", stderr); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 exit(1); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 start = strtol(argv[opt], NULL, 0); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 break; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 case 'd': |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 is_gpu = 0; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 break; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 case 'f': |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 opt++; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 if (opt >= argc) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 fputs("-f must be followed by a filename\n", stderr); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 exit(1); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 address_log = fopen(argv[opt], "r"); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 if (!address_log) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 fprintf(stderr, "Failed to open %s for reading\n", argv[opt]); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 exit(1); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 while (fgets(disbuf, sizeof(disbuf), address_log)) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 if (disbuf[0]) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 char *end; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 uint32_t address = strtol(disbuf, &end, 16); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 if (address) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 def = defer(address, def); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 reference(address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 if (*end == '=') { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 named_labels = add_label(named_labels, strip_ws(end+1), address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 } else { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 char *end; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 uint32_t address = strtol(argv[opt], &end, 16); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 def = defer(address, def); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 reference(address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 if (*end == '=') { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 named_labels = add_label(named_labels, end+1, address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 if (address_off == 0xFFFFFFFF) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 address_off = is_gpu ? 0xF03000 : 0xF1B000; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 if (start == 0xFFFFFFFF) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 start = address_off; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 FILE * f = fopen(argv[1], "rb"); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 fseek(f, 0, SEEK_END); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 filesize = ftell(f); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 fseek(f, 0, SEEK_SET); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 char int_key[MAX_INT_KEY_SIZE]; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
220 address_end = address_off + filesize; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 filebuf = malloc(filesize); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 if (fread(filebuf, 2, filesize/2, f) != filesize/2) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
223 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 fprintf(stderr, "Failure while reading file %s\n", argv[1]); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 fclose(f); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
227 for(cur = filebuf; cur - filebuf < (filesize/2); ++cur) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 *cur = (*cur >> 8) | (*cur << 8); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 named_labels = add_label(named_labels, "start", start); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 if (!def || !only) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 def = defer(start, def); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 uint16_t *encoded, *next; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 uint32_t size, tmp_addr; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 uint32_t address; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 while(def) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 do { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 encoded = NULL; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
242 address = def->address; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 if (!is_visited(address)) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 encoded = filebuf + (address - address_off)/2; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 tmpd = def; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
247 def = def->next; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 free(tmpd); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 } while(def && encoded == NULL); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 if (!encoded) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 break; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 for(;;) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 if (address > address_end || address < address_off) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 break; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 visit(address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 uint16_t inst = *encoded; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 uint32_t inst_address = address; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 check_reference(inst, address, is_gpu); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 uint16_t opcode = jag_opcode(inst, is_gpu); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 if (opcode == JAG_MOVEI) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 address += 6; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 encoded += 3; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 } else { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 address += 2; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 encoded++; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 if (opcode == JAG_JR || opcode == JAG_JUMP) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 if (!(jag_reg2(inst) & 0xF)) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 //unconditional jump |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 if (opcode == JAG_JR) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 address = jag_jr_dest(inst, inst_address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 reference(address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 if (is_visited(address)) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 break; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
279 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
280 } else { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
281 break; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 } else if (opcode == JAG_JR) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 uint32_t dest = jag_jr_dest(inst, inst_address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 reference(dest); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
286 def = defer(dest, def); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
287 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
288 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
289 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
290 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
291 if (labels) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
292 for (address = 0; address < address_off; address++) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
293 if (is_label(address)) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
294 printf("ADR_%X equ $%X\n", address, address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
295 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
296 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
297 for (address = filesize; address < (16*1024*1024); address++) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
298 char key[MAX_INT_KEY_SIZE]; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 tern_int_key(address, key); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
300 label_names *names = tern_find_ptr(named_labels, key); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
301 if (names) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
302 for (int i = 0; i < names->num_labels; i++) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
303 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
304 printf("%s equ $%X\n", names->labels[i], address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
305 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
306 } else if (is_label(address)) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
307 printf("ADR_%X equ $%X\n", address, address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
308 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
309 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
310 puts(""); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
311 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
312 for (address = address_off; address < address_end; address+=2) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
313 if (is_visited(address)) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
314 encoded = filebuf + (address-address_off)/2; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
315 jag_cpu_disasm(&encoded, address, disbuf, is_gpu, labels); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 if (labels) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 char keybuf[MAX_INT_KEY_SIZE]; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 label_names * names = tern_find_ptr(named_labels, tern_int_key(address, keybuf)); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 if (names) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
321 for (int i = 0; i < names->num_labels; i++) |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
322 { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
323 printf("%s:\n", names->labels[i]); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
324 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
325 } else if (is_label(address)) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
326 printf("ADR_%X:\n", address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
327 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
328 if (addr) { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
329 printf("\t%s\t;%X\n", disbuf, address); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
330 } else { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
331 printf("\t%s\n", disbuf); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
332 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
333 } else { |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 printf("%X: %s\n", address, disbuf); |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
335 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
336 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
337 } |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
338 return 0; |
4987fddd42a0
Initial stab at jaguar disassemler
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
339 } |