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