1 /* xa65 - 65xx/65816 cross-assembler and utility suite
2  *
3  * Copyright (C) 1989-1997 Andr� Fachat (a.fachat@physik.tu-chemnitz.de)
4  * Maintained by Cameron Kaiser
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 #ifndef __XA65_XAH_H__
21 #define __XA65_XAH_H__
22 
23 #define ANZLAB		5000	/* mal 14 -> Byte */
24 #define LABMEM		40000L
25 #define MAXLAB		32
26 #define MAXBLK		16
27 #define MAXFILE		7
28 #define MAXLINE		2048
29 #define MAXPP		40000L
30 #define ANZDEF		2340	/* mal 14 -> Byte, ANZDEF * 14 < 32768 */
31 #define TMPMEM		200000L	/* Zwischenspeicher von Pass1 nach Pass 2 */
32 
33 typedef struct LabOcc {
34 	struct LabOcc *next;
35 	int line;
36 	char *fname;
37 } LabOcc;
38 
39 typedef struct {
40 	int blk;
41 	int val;
42 	int len;
43 	int fl;		/* 0 = label value not valid/known,
44 			 * 1 = label value known
45 			 */
46 	int afl;	/* 0 = no address (no relocation), 1 = address label */
47 	int nextindex;
48 	char *n;
49 	struct LabOcc *occlist;
50 } Labtab;
51 
52 typedef struct {
53 	char *search;
54 	int s_len;
55 	char *replace;
56 	int p_anz;
57 	int nextindex;
58 } List;
59 
60 
61 #define MEMLEN		(4 + TMPMEM + MAXPP + LABMEM +			\
62 			 (long)(sizeof (Labtab) * ANZLAB) +		\
63 			 (long)(sizeof (List) * ANZDEF))
64 
65 #define DIRCHAR		'/'
66 #define DIRCSTRING	"/"
67 /* for Atari:
68 #define DIRCHAR		'\\'
69 #define DIRCSTRING	"\\"
70 */
71 
72 #define	BUFSIZE		4096	/* File-Puffegroesse (wg Festplatte) */
73 
74 #define E_OK		 0	/* Fehlernummern */
75 #define E_SYNTAX	-1	/* Syntax Fehler */
76 #define E_LABDEF	-2	/* Label definiert */
77 #define E_NODEF		-3	/* Label nicht definiert */
78 #define E_LABFULL	-4	/* Labeltabelle voll */
79 #define E_LABEXP	-5	/* Label erwartet */
80 #define E_NOMEM		-6	/* kein Speicher mehr */
81 #define E_ILLCODE	-7	/* Illegaler Opcode */
82 #define E_ADRESS	-8	/* Illegale Adressierung */
83 #define E_RANGE		-9	/* Branch out of range */
84 #define E_OVERFLOW	-10	/* Ueberlauf */
85 #define E_DIV		-11	/* Division durch Null */
86 #define E_PSOEXP	-12	/* Pseudo-Opcode erwartet */
87 #define E_BLKOVR	-13	/* Block-Stack Uebergelaufen */
88 #define E_FNF		-14	/* File not found (pp) */
89 #define E_EOF		-15	/* End of File */
90 #define E_BLOCK		-16	/* Block inkonsistent */
91 #define E_NOBLK		-17
92 #define E_NOKEY		-18
93 #define E_NOLINE	-19
94 #define E_OKDEF		-20	/* okdef */
95 #define E_DSB		-21
96 #define E_NEWLINE	-22
97 #define E_NEWFILE	-23
98 #define E_CMOS		-24
99 #define E_ANZPAR	-25
100 #define E_ILLPOINTER	-26	/* illegal pointer arithmetic! */
101 #define E_ILLSEGMENT	-27	/* illegal pointer arithmetic! */
102 #define E_OPTLEN	-28	/* file header option too long */
103 #define E_ROMOPT	-29	/* header option not directly after
104 				 * file start in romable mode
105 				 */
106 #define E_ILLALIGN	-30	/* illegal align value */
107 
108 #define E_65816		-31
109 
110 #define E_ORECMAC	-32	/* exceeded recursion limit for label eval */
111 #define E_OPENPP	-33	/* open preprocessor directive */
112 #define E_OUTOFDATA	-34	/* out of data */
113 #define E_ILLQUANT	-35	/* generic illegal quantity error */
114 #define E_BIN		-36	/* okdef */
115 /* errors thru 64 are placeholders available for use */
116 
117 #define W_ADRRELOC	-65	/* word relocation in byte value */
118 #define W_BYTRELOC	-66	/* byte relocation in word value */
119 #define E_WPOINTER	-67	/* illegal pointer arithmetic!   */
120 #define W_ADDRACC	-68	/* addr access to low or high byte pointer */
121 #define W_HIGHACC	-69	/* high byte access to low byte pointer */
122 #define W_LOWACC	-70	/* low byte access to high byte pointer */
123 #define W_FORLAB	-71	/* no zp-optimization for a forward label */
124 #define W_OPENPP	-72	/* warning about open preprocessor directive */
125 #define W_OVER64K	-73	/* included binary over 64K in 6502 mode */
126 #define W_OVER16M	-74	/* included binary over 16M in 65816 mode */
127 #define W_OLDMVNS	-75	/* use of old mv? $xxxx syntax */
128 /* warnings 76-77 are placeholders available for use */
129 
130 #define T_VALUE		-1
131 #define T_LABEL		-2
132 #define T_OP		-3
133 #define T_END		-4
134 #define T_LINE		-5
135 #define T_FILE		-6
136 #define T_POINTER	-7
137 
138 #define P_START		 0	/* Prioritaeten fuer Arithmetik    */
139 #define P_LOR		 1	/* Von zwei Operationen wird immer */
140 #define P_LAND		 2	/* die mit der hoeheren Prioritaet */
141 #define P_OR		 3	/* zuerst ausgefuehrt              */
142 #define P_XOR		 4
143 #define P_AND		 5
144 #define P_EQU		 6
145 #define P_CMP		 7
146 #define P_SHIFT		 8
147 #define P_ADD		 9
148 #define P_MULT		10
149 #define P_INV		11
150 
151 #define A_ADR		0x8000	/* all are or'd with (afl = segment type)<<8 */
152 #define A_HIGH		0x4000	/* or'd with the low byte */
153 #define A_LOW		0x2000
154 #define A_MASK		0xe000	/* reloc type mask */
155 #define A_FMASK		0x0f00	/* segment type mask */
156 
157 #define A_LONG		0xc000
158 
159 #define FM_OBJ		0x1000
160 #define FM_SIZE		0x2000
161 #define FM_RELOC	0x4000
162 #define FM_CPU		0x8000
163 
164 #define SEG_ABS		0
165 #define SEG_UNDEF	1
166 #define SEG_TEXT	2
167 #define SEG_DATA	3
168 #define SEG_BSS		4
169 #define SEG_ZERO	5
170 #define SEG_MAX         6
171 
172 typedef struct Fopt {
173 	signed char *text;	/* text after pass1 */
174 	int len;
175 } Fopt;
176 
177 typedef struct relocateInfo {
178 	int next;
179 	int adr;
180 	int afl;
181 	int lab;
182 } relocateInfo;
183 
184 typedef struct File {
185 	int fmode;
186 	int slen;
187 	int relmode;
188 	int old_abspc;
189 	int base[SEG_MAX];
190 	int len[SEG_MAX];
191 	struct {
192 		signed char *tmp;
193 		unsigned long tmpz;
194 		unsigned long tmpe;
195 	} mn;
196 	struct {
197 		int *ulist;
198 		int un;
199 		int um;
200 	} ud;
201 	struct {
202 		relocateInfo *rlist;
203 		int mlist;
204 		int nlist;
205 		int first;
206 	} rt;
207 	struct {
208 		relocateInfo *rlist;
209 		int mlist;
210 		int nlist;
211 		int first;
212 	} rd;
213 	struct {
214 		Fopt *olist;
215 		int mlist;
216 		int nlist;
217 	} fo;
218 	struct {
219 		int hashindex[256];
220 		Labtab *lt;
221 		int lti;
222 		int ltm;
223 	} la;
224 } File;
225 
226 extern File *afile;
227 
228 #endif /* __XA65_XAH_H__ */
229