Mercurial > hg > forks > dxa
annotate structures.h @ 16:a2a81589380d default tip
Reformat the whole source via clang-format for better consistency.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 14 Oct 2021 01:53:20 +0300 |
parents | 89183953bddc |
children |
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))) | |
15 | 68 |
0 | 69 /* The table consists of bit pairs with the following values: */ |
70 | |
16
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
71 #define MEM_UNPROCESSED 0 /* the memory place has not been processed yet */ |
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
72 #define MEM_INSTRUCTION 1 /* a machine language instruction starts at this memory place */ |
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
73 #define MEM_DATA 2 /* the memory place contains data */ |
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
74 #define MEM_PARAMETER 3 /* a parameter of a machine language instruction is at this place */ |
0 | 75 |
76 /*************************\ | |
77 * Memory place flag table * | |
78 \*************************/ | |
79 | |
80 #ifndef _MAIN_C_ | |
81 extern | |
82 #endif | |
83 unsigned | |
84 MemFlag[(1 << 13) / sizeof(unsigned)], | |
85 MemLabel[(1 << 13) / sizeof(unsigned)], | |
86 LowByte[(1 << 8) / sizeof(unsigned)], | |
87 HighByte[(1 << 8) / sizeof(unsigned)]; | |
88 | |
11
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
89 |
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
90 #ifndef _MAIN_C_ |
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
91 extern |
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
92 #endif |
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
93 unsigned char MemReferenced[1 << 16]; |
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
94 |
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
95 |
0 | 96 #define GetMemFlag(address) \ |
97 ((MemFlag[((ADDR_T)address) / (8 * sizeof *MemFlag)] >> \ | |
98 (address % (8 * sizeof *MemFlag))) & 1) | |
99 | |
100 #define SetMemFlag(address) \ | |
101 (MemFlag[((ADDR_T)address) / (8 * sizeof *MemFlag)] |= \ | |
102 (1 << (address % (8 * sizeof *MemFlag)))) | |
103 | |
104 /* The flag table indicates if there may be a valid routine at the address. | |
105 If a flag is set, there cannot be valid routines at the address. */ | |
106 | |
107 #define IsLabeled(address) \ | |
108 ((MemLabel[((ADDR_T)address) / (8 * sizeof *MemLabel)] >> \ | |
109 (address % (8 * sizeof *MemLabel))) & 1) | |
110 | |
11
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
111 #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
|
112 |
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
113 |
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
114 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
|
115 { |
16
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
116 (void)name; |
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
117 (void)line; |
14
84c0facfc43c
Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
118 |
16
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
119 MemLabel[((ADDR_T)address) / (8 * sizeof *MemLabel)] |= (1 << (address % (8 * sizeof *MemLabel))); |
11
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
120 } |
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
121 |
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
122 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
|
123 { |
16
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
124 return MemReferenced[address]; |
11
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 |
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 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
|
129 { |
16
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
130 (void)name; |
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
131 (void)line; |
14
84c0facfc43c
Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
132 |
16
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
133 MemReferenced[address]++; |
11
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
134 } |
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
135 |
fe4d840c13eb
Implement reference checking to reduce outputting of useless labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
136 #define PutReference(address) DOPutReference(address, __func__, __LINE__) |
0 | 137 |
138 /* These macros tell if there is a label for a given address, or cause a | |
139 label to be produced for an address. */ | |
140 | |
141 #define IsLowByte(address) \ | |
142 ((LowByte[((unsigned char)address) / (8 * sizeof *LowByte)] >> \ | |
143 (address % (8 * sizeof *LowByte))) & 1) | |
144 | |
145 #define PutLowByte(address) \ | |
146 (LowByte[((unsigned char)address) / (8 * sizeof *LowByte)] |= \ | |
147 (1 << (address % (8 * sizeof *LowByte)))) | |
148 | |
149 /* Corresponding macros for the low byte address table. */ | |
150 | |
151 #define IsHighByte(address) \ | |
152 ((HighByte[(address >> 8) / (8 * sizeof *HighByte)] >> \ | |
153 ((address >> 8) % (8 * sizeof *HighByte))) & 1) | |
154 | |
155 #define PutHighByte(address) \ | |
156 (HighByte[(address >> 8) / (8 * sizeof *HighByte)] |= \ | |
157 (1 << ((address >> 8) % (8 * sizeof *HighByte)))) | |
158 | |
159 /* Corresponding macros for the high byte address table. */ | |
160 | |
161 /***************************************\ | |
162 * Routine/warning address table entries * | |
163 \***************************************/ | |
164 | |
165 typedef struct table | |
166 { | |
16
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
167 ADDR_T address; |
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
168 ADDR_T parent; |
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
169 unsigned char type; |
0 | 170 } table; |
171 | |
172 /* The table.type byte has the following format: */ | |
173 | |
174 #define RTN_SURE 0x80 /* address must point to a valid subprogram */ | |
175 #define RTN_POTENTIAL 0x81 /* address may point to a valid subprogram (an | |
176 address following a conditional branch | |
177 instruction) */ | |
178 #define RTN_SUSPECTED 0x82 /* address might point to a valid subprogram | |
179 (an address encountered during processing | |
180 an RTN_POTENTIAL entry) */ | |
181 #define RTN_SUSP_POT 0x83 /* address might point to a subprogram (an | |
182 address following a conditional branch | |
183 instruction that was encountered during | |
184 processing an RTN_SUSPECTED or | |
185 RTN_POTENTIAL entry) */ | |
186 #define RTN_B_TEMPORARY 0x10 /* declares the entry as temporary */ | |
187 #define RTN_B_PROCESSED 0x20 /* address seems to point to a valid | |
188 subprogram (a successfully processed | |
189 RTN_SUSPECTED entry is | |
190 RTN_SUSPECTED | RTN_B_PROCESSED) */ | |
191 | |
192 #define MASK_ANY 0xc0 /* mask for determining the type of the entry */ | |
193 | |
194 #define RTN_ANY 0x80 /* mask for determining if an entry is a | |
195 routine or not */ | |
196 | |
197 #define WRN_PARAM_WRITTEN_TO 0x40 /* the parameter of the instruction is | |
198 written to */ | |
199 #define WRN_INSTR_WRITTEN_TO 0x41 /* the instruction is modified by the | |
200 program */ | |
201 | |
202 #define WRN_PARAM_JUMPED_TO 0x42 /* a jump occurs in the middle of the | |
203 instruction, e.g. BIT $01A9 */ | |
204 #define WRN_RTN_TRUNCATED 0x43 /* the routine is truncated, the rest of | |
205 the instructions are retrieved outside | |
206 the loaded file (very fatal error) */ | |
207 #define WRN_I_ACCESSED 0x44 /* not an actual warning: an unprocessed | |
208 memory place is accessed by an | |
209 RTN_POTENTIAL or RTN_SUSPECTED routine */ | |
210 #define WRN_I_LABEL_NEEDED 0x45 /* not an actual warning: a label will be | |
211 needed for this memory place */ | |
212 | |
213 #define WRN_B_TEMPORARY 0x20 /* mask for determining whether a warning | |
214 is temporary and may be deleted later */ | |
215 | |
216 #define WRN_ANY 0x40 /* mask for determining whether an | |
217 entry is a warning or not */ | |
218 | |
219 #define TBL_DELETED 0 /* the entry may be reused */ | |
220 | |
221 /*********************\ | |
222 * Label table entries * | |
223 \*********************/ | |
224 | |
225 typedef struct label | |
226 { | |
16
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
227 int is_range; |
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
228 ADDR_T address, len; |
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
229 char *name; |
0 | 230 } label; |
231 | |
232 /********************\ | |
233 * Word table entries * | |
234 \********************/ | |
235 | |
236 typedef struct words | |
237 { | |
16
a2a81589380d
Reformat the whole source via clang-format for better consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
238 ADDR_T start, end; |
0 | 239 } words; |
240 | |
241 #ifndef _MAIN_C_ | |
242 extern char *prog; | |
14
84c0facfc43c
Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
243 extern ADDR_T StartAddress, EndAddress, BasicHeaderLength; |
0 | 244 extern int fVerbose; |
245 #else | |
246 char *prog; | |
247 ADDR_T StartAddress, EndAddress; | |
248 int fVerbose = FALSE; | |
14
84c0facfc43c
Merge changes from upstream v0.1.4.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
249 ADDR_T BasicHeaderLength = 0; |
0 | 250 #endif /* _MAIN_C_ */ |
251 | |
252 #ifndef _TABLE_C_ | |
253 extern unsigned int entrycount; | |
254 extern table *scantable; /* table of all warnings generated or routines | |
255 encountered */ | |
256 #else | |
257 unsigned int entrycount = 0; | |
258 table *scantable = NULL; | |
259 #endif /* _TABLE_C_ */ | |
260 | |
261 #ifndef _DUMP_C_ | |
262 extern int listwidth; /* maximum amount of bytes dumped on a source line */ | |
263 #else | |
264 int listwidth = 0; | |
265 #endif /* _DUMP_C_ */ | |
266 | |
267 #endif /* _STRUCTURES_H_ */ |