0
|
1 /*\
|
|
2 * dxa v0.1.1 -- symbolic 65xx disassembler
|
|
3 *
|
|
4 * Copyright (C) 1993, 1994 Marko M\"akel\"a
|
|
5 *
|
|
6 * This program is free software; you can redistribute it and/or modify
|
|
7 * it under the terms of the GNU General Public License as published by
|
|
8 * the Free Software Foundation; either version 2 of the License, or
|
|
9 * (at your option) any later version.
|
|
10 *
|
|
11 * This program is distributed in the hope that it will be useful,
|
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 * GNU General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program; if not, write to the Free Software
|
|
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
19 *
|
|
20 * Contacting the author:
|
|
21 *
|
|
22 * Via Internet E-mail:
|
|
23 * <Marko.Makela@FTP.FUNET.FI>
|
|
24 *
|
|
25 * Via Snail Mail:
|
|
26 * Marko M\"akel\"a
|
|
27 * Sillitie 10 A
|
|
28 * FIN-01480 VANTAA
|
|
29 * Finland
|
|
30 \*/
|
|
31
|
|
32 /* structures.h - memory structures and related constants and macros */
|
|
33 #ifndef _STRUCTURES_H_
|
|
34 #define _STRUCTURES_H_
|
|
35
|
|
36 #ifndef FALSE
|
|
37 #define FALSE 0
|
|
38 #define TRUE !FALSE
|
|
39 #endif
|
|
40
|
|
41 #ifndef NULL
|
|
42 #define NULL (void *)0
|
|
43 #endif
|
|
44
|
|
45 #define MAXLINE 50 /* maximum amount of bytes used when reading a label in */
|
|
46
|
|
47 typedef unsigned short int ADDR_T; /* 16-bit unsigned integer */
|
|
48 typedef unsigned char DATA_T; /* 8-bit unsigned integer */
|
|
49
|
|
50 /********************\
|
|
51 * Program code table *
|
|
52 \********************/
|
|
53
|
|
54 #ifndef _MAIN_C_
|
|
55 extern
|
|
56 #endif
|
|
57 DATA_T Memory[1 << 16];
|
|
58
|
|
59 /*************************\
|
|
60 * Memory place type table *
|
|
61 \*************************/
|
|
62
|
|
63 #ifndef _MAIN_C_
|
|
64 extern
|
|
65 #endif
|
|
66 unsigned MemType[(1 << 14) / sizeof(unsigned)];
|
|
67
|
|
68 #define GetMemType(address) \
|
|
69 ((MemType[((ADDR_T)address) / (4 * sizeof *MemType)] >> \
|
|
70 ((address % (4 * sizeof *MemType)) << 1)) & 3)
|
|
71
|
|
72 #define SetMemType(address, type) \
|
|
73 (MemType[((ADDR_T)address) / (4 * sizeof *MemType)] = \
|
|
74 (MemType[((ADDR_T)address) / (4 * sizeof *MemType)] & \
|
|
75 ~(3 << ((address % (4 * sizeof *MemType)) << 1))) | \
|
|
76 (type << ((address % (4 * sizeof *MemType)) << 1)))
|
|
77
|
|
78 /* The table consists of bit pairs with the following values: */
|
|
79
|
|
80 #define MEM_UNPROCESSED 0 /* the memory place has not been processed yet */
|
|
81 #define MEM_INSTRUCTION 1 /* a machine language instruction starts at
|
|
82 this memory place */
|
|
83 #define MEM_DATA 2 /* the memory place contains data */
|
|
84 #define MEM_PARAMETER 3 /* a parameter of a machine language
|
|
85 instruction is at this place */
|
|
86
|
|
87 /*************************\
|
|
88 * Memory place flag table *
|
|
89 \*************************/
|
|
90
|
|
91 #ifndef _MAIN_C_
|
|
92 extern
|
|
93 #endif
|
|
94 unsigned
|
|
95 MemFlag[(1 << 13) / sizeof(unsigned)],
|
|
96 MemLabel[(1 << 13) / sizeof(unsigned)],
|
|
97 LowByte[(1 << 8) / sizeof(unsigned)],
|
|
98 HighByte[(1 << 8) / sizeof(unsigned)];
|
|
99
|
|
100 #define GetMemFlag(address) \
|
|
101 ((MemFlag[((ADDR_T)address) / (8 * sizeof *MemFlag)] >> \
|
|
102 (address % (8 * sizeof *MemFlag))) & 1)
|
|
103
|
|
104 #define SetMemFlag(address) \
|
|
105 (MemFlag[((ADDR_T)address) / (8 * sizeof *MemFlag)] |= \
|
|
106 (1 << (address % (8 * sizeof *MemFlag))))
|
|
107
|
|
108 /* The flag table indicates if there may be a valid routine at the address.
|
|
109 If a flag is set, there cannot be valid routines at the address. */
|
|
110
|
|
111 #define IsLabeled(address) \
|
|
112 ((MemLabel[((ADDR_T)address) / (8 * sizeof *MemLabel)] >> \
|
|
113 (address % (8 * sizeof *MemLabel))) & 1)
|
|
114
|
|
115 #define PutLabel(address) \
|
|
116 (MemLabel[((ADDR_T)address) / (8 * sizeof *MemLabel)] |= \
|
|
117 (1 << (address % (8 * sizeof *MemLabel))))
|
|
118
|
|
119 /* These macros tell if there is a label for a given address, or cause a
|
|
120 label to be produced for an address. */
|
|
121
|
|
122 #define IsLowByte(address) \
|
|
123 ((LowByte[((unsigned char)address) / (8 * sizeof *LowByte)] >> \
|
|
124 (address % (8 * sizeof *LowByte))) & 1)
|
|
125
|
|
126 #define PutLowByte(address) \
|
|
127 (LowByte[((unsigned char)address) / (8 * sizeof *LowByte)] |= \
|
|
128 (1 << (address % (8 * sizeof *LowByte))))
|
|
129
|
|
130 /* Corresponding macros for the low byte address table. */
|
|
131
|
|
132 #define IsHighByte(address) \
|
|
133 ((HighByte[(address >> 8) / (8 * sizeof *HighByte)] >> \
|
|
134 ((address >> 8) % (8 * sizeof *HighByte))) & 1)
|
|
135
|
|
136 #define PutHighByte(address) \
|
|
137 (HighByte[(address >> 8) / (8 * sizeof *HighByte)] |= \
|
|
138 (1 << ((address >> 8) % (8 * sizeof *HighByte))))
|
|
139
|
|
140 /* Corresponding macros for the high byte address table. */
|
|
141
|
|
142 /***************************************\
|
|
143 * Routine/warning address table entries *
|
|
144 \***************************************/
|
|
145
|
|
146 typedef struct table
|
|
147 {
|
|
148 ADDR_T address;
|
|
149 ADDR_T parent;
|
|
150 unsigned char type;
|
|
151 } table;
|
|
152
|
|
153 /* The table.type byte has the following format: */
|
|
154
|
|
155 #define RTN_SURE 0x80 /* address must point to a valid subprogram */
|
|
156 #define RTN_POTENTIAL 0x81 /* address may point to a valid subprogram (an
|
|
157 address following a conditional branch
|
|
158 instruction) */
|
|
159 #define RTN_SUSPECTED 0x82 /* address might point to a valid subprogram
|
|
160 (an address encountered during processing
|
|
161 an RTN_POTENTIAL entry) */
|
|
162 #define RTN_SUSP_POT 0x83 /* address might point to a subprogram (an
|
|
163 address following a conditional branch
|
|
164 instruction that was encountered during
|
|
165 processing an RTN_SUSPECTED or
|
|
166 RTN_POTENTIAL entry) */
|
|
167 #define RTN_B_TEMPORARY 0x10 /* declares the entry as temporary */
|
|
168 #define RTN_B_PROCESSED 0x20 /* address seems to point to a valid
|
|
169 subprogram (a successfully processed
|
|
170 RTN_SUSPECTED entry is
|
|
171 RTN_SUSPECTED | RTN_B_PROCESSED) */
|
|
172
|
|
173 #define MASK_ANY 0xc0 /* mask for determining the type of the entry */
|
|
174
|
|
175 #define RTN_ANY 0x80 /* mask for determining if an entry is a
|
|
176 routine or not */
|
|
177
|
|
178 #define WRN_PARAM_WRITTEN_TO 0x40 /* the parameter of the instruction is
|
|
179 written to */
|
|
180 #define WRN_INSTR_WRITTEN_TO 0x41 /* the instruction is modified by the
|
|
181 program */
|
|
182
|
|
183 #define WRN_PARAM_JUMPED_TO 0x42 /* a jump occurs in the middle of the
|
|
184 instruction, e.g. BIT $01A9 */
|
|
185 #define WRN_RTN_TRUNCATED 0x43 /* the routine is truncated, the rest of
|
|
186 the instructions are retrieved outside
|
|
187 the loaded file (very fatal error) */
|
|
188 #define WRN_I_ACCESSED 0x44 /* not an actual warning: an unprocessed
|
|
189 memory place is accessed by an
|
|
190 RTN_POTENTIAL or RTN_SUSPECTED routine */
|
|
191 #define WRN_I_LABEL_NEEDED 0x45 /* not an actual warning: a label will be
|
|
192 needed for this memory place */
|
|
193
|
|
194 #define WRN_B_TEMPORARY 0x20 /* mask for determining whether a warning
|
|
195 is temporary and may be deleted later */
|
|
196
|
|
197 #define WRN_ANY 0x40 /* mask for determining whether an
|
|
198 entry is a warning or not */
|
|
199
|
|
200 #define TBL_DELETED 0 /* the entry may be reused */
|
|
201
|
|
202 /*********************\
|
|
203 * Label table entries *
|
|
204 \*********************/
|
|
205
|
|
206 typedef struct label
|
|
207 {
|
|
208 ADDR_T address;
|
|
209 char *name;
|
|
210 } label;
|
|
211
|
|
212 /********************\
|
|
213 * Word table entries *
|
|
214 \********************/
|
|
215
|
|
216 typedef struct words
|
|
217 {
|
|
218 ADDR_T start, end;
|
|
219 } words;
|
|
220
|
|
221 #ifndef _MAIN_C_
|
|
222 extern char *prog;
|
|
223 extern ADDR_T StartAddress, EndAddress;
|
|
224 extern int fVerbose;
|
|
225 #else
|
|
226 char *prog;
|
|
227 ADDR_T StartAddress, EndAddress;
|
|
228 int fVerbose = FALSE;
|
|
229 #endif /* _MAIN_C_ */
|
|
230
|
|
231 #ifndef _TABLE_C_
|
|
232 extern unsigned int entrycount;
|
|
233 extern table *scantable; /* table of all warnings generated or routines
|
|
234 encountered */
|
|
235 #else
|
|
236 unsigned int entrycount = 0;
|
|
237 table *scantable = NULL;
|
|
238 #endif /* _TABLE_C_ */
|
|
239
|
|
240 #ifndef _DUMP_C_
|
|
241 extern int listwidth; /* maximum amount of bytes dumped on a source line */
|
|
242 #else
|
|
243 int listwidth = 0;
|
|
244 #endif /* _DUMP_C_ */
|
|
245
|
|
246 #endif /* _STRUCTURES_H_ */
|