3 Copyright (C) 1989-1995 Alan R. Baldwin
4 721 Berkeley St., Kent, Ohio 44240
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
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.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 * - change s_id from [NCPS] to pointer (comment)
23 * - add jflag for debug control
33 * The module asdata.c contains the global constants,
34 * structures, and variables used in the assembler.
37 int aserr; /* ASxxxx error counter
39 jmp_buf jump_env; /* compiler dependent structure
40 * used by setjmp() and longjmp()
42 int inpfil; /* count of assembler
43 * input files specified
45 int incfil; /* current file handle index
48 int cfile; /* current file handle index
49 * of input assembly files
51 int flevel; /* IF-ELSE-ENDIF flag will be non
52 * zero for false conditional case
54 int tlevel; /* current conditional level
56 int ifcnd[MAXIF+1]; /* array of IF statement condition
57 * values (0 = FALSE) indexed by tlevel
59 int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel
60 * values indexed by tlevel
63 char afn[PATH_MAX]; /* afile temporary file name
65 char srcfn[MAXFIL][PATH_MAX];/* array of source file names
67 int srcline[MAXFIL]; /* source line number
69 char incfn[MAXINC][PATH_MAX];/* array of include file names
71 int incline[MAXINC]; /* include line number
74 int radix; /* current number conversion radix:
75 * 2 (binary), 8 (octal), 10 (decimal),
78 int line; /* current assembler source
81 int page; /* current page number
83 int lop; /* current line number on page
85 int pass; /* assembler pass number
87 int org_cnt; /* .org directive counter
89 int lflag; /* -l, generate listing flag
91 int cflag; /* -lc, generate sdcdb debug info
93 int gflag; /* -g, make undefined symbols global flag
95 int aflag; /* -a, make all symbols global flag
97 int jflag; /* -j, generate debug information flag
99 int oflag; /* -o, generate relocatable output flag
101 int sflag; /* -s, generate symbol table flag
103 int pflag; /* -p, enable listing pagination
105 int xflag; /* -x, listing radix flag
107 int fflag; /* -f(f), relocations flagged flag
109 Addr_T laddr; /* address of current assembler line
110 * or value of .if argument
112 Addr_T fuzz; /* tracks pass to pass changes in the
113 * address of symbols caused by
114 * variable length instruction formats
116 int lmode; /* listing mode
118 char *ep; /* pointer into error list
121 char eb[NERR]; /* array of generated error codes
123 const char *ip; /* pointer into the assembler-source
126 const char *ib; /* assembler-source text line
128 char *cp; /* pointer to assembler output
131 char cb[NCODE]; /* array of assembler output values
133 int *cpt; /* pointer to assembler relocation type
136 int cbt[NCODE]; /* array of assembler relocation types
137 * describing the data in cb[]
139 char tb[NTITL]; /* Title string buffer
141 char stb[NSBTL]; /* Subtitle string buffer
143 char optsdcc[NINPUT]; /* sdcc compile options
145 int flat24Mode; /* non-zero if we are using DS390 24 bit
146 * flat mode (via .flat24 directive).
149 char symtbl[] = { "Symbol Table" };
150 char aretbl[] = { "Area Table" };
152 char module[NCPS]; /* module name string
156 * The mne structure is a linked list of the assembler
157 * mnemonics and directives. The list of mnemonics and
158 * directives contained in the device dependent file
159 * xxxpst.c are hashed and linked into NHASH lists in
160 * module assym.c by syminit(). The structure contains
161 * the mnemonic/directive name, a subtype which directs
162 * the evaluation of this mnemonic/directive, a flag which
163 * is used to detect the end of the mnemonic/directive
164 * list in xxxpst.c, and a value which is normally
165 * associated with the assembler mnemonic base instruction
170 * struct mne *m_mp; Hash link
171 * char m_id[NCPS]; Mnemonic
172 * char m_type; Mnemonic subtype
173 * char m_flag; Mnemonic flags
174 * Addr_T m_valu; Value
177 struct mne *mnehash[NHASH];
180 * The sym structure is a linked list of symbols defined
181 * in the assembler source files. The first symbol is "."
182 * defined here. The entry 'struct tsym *s_tsym'
183 * links any temporary symbols following this symbol and
184 * preceeding the next normal symbol. The structure also
185 * contains the symbol's name, type (USER or NEW), flag
186 * (global, assigned, and multiply defined), a pointer
187 * to the area structure defining where the symbol is
188 * located, a reference number assigned by outgsd() in
189 * asout.c, and the symbols address relative to the base
190 * address of the area where the symbol is located.
194 * struct sym *s_sp; Hash link
195 * struct tsym *s_tsym; Temporary symbol link
196 * char *s_id; Symbol (JLH)
197 * char s_type; Symbol subtype
198 * char s_flag; Symbol flags
199 * struct area *s_area; Area line, 0 if absolute
200 * int s_ref; Ref. number
201 * Addr_T s_addr; Address
205 {NULL, NULL, ".", S_USER, S_END, NULL, 0, 0}
208 struct sym *symp; /* pointer to a symbol structure
210 struct sym *symhash[NHASH]; /* array of pointers to NHASH
211 * linked symbol lists
215 * The area structure contains the parameter values for a
216 * specific program or data section. The area structure
217 * is a linked list of areas. The initial default area
218 * is "_CODE" defined here, the next area structure
219 * will be linked to this structure through the structure
220 * element 'struct area *a_ep'. The structure contains the
221 * area name, area reference number ("_CODE" is 0) determined
222 * by the order of .area directives, area size determined
223 * from the total code and/or data in an area, area fuzz is
224 * an variable used to track pass to pass changes in the
225 * area size caused by variable length instruction formats,
226 * and area flags which specify the area's relocation type.
230 * struct area *a_ap; Area link
231 * char a_id[NCPS]; Area Name
232 * int a_ref; Reference number
233 * Addr_T a_size; Area size
234 * Addr_T a_fuzz; Area fuzz
235 * int a_flag; Area flags
238 struct area area[] = {
239 {NULL, "_CODE", 0, 0, 0, A_CON|A_REL}
242 struct area *areap; /* pointer to an area structure
245 FILE *lfp; /* list output file handle
247 FILE *ofp; /* relocation output file handle
249 FILE *tfp; /* symbol table output file handle
251 FILE *sfp[MAXFIL]; /* array of assembler-source file handles
253 FILE *ifp[MAXINC]; /* array of include-file file handles
257 * array of character types, one per
260 unsigned char ctype[128] = {
261 /*NUL*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
262 /*BS*/ ILL, SPACE, ILL, ILL, SPACE, ILL, ILL, ILL,
263 /*DLE*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
264 /*CAN*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
265 /*SPC*/ SPACE, ETC, ETC, ETC, LETTER, BINOP, BINOP, ETC,
266 /*(*/ ETC, ETC, BINOP, BINOP, ETC, BINOP, LETTER, BINOP,
267 /*0*/ DGT2, DGT2, DGT8, DGT8, DGT8, DGT8, DGT8, DGT8,
268 /*8*/ DGT10, DGT10, ETC, ETC, BINOP, ETC, BINOP, ETC,
269 /*@*/ ETC, LTR16, LTR16, LTR16, LTR16, LTR16, LTR16, LETTER,
270 /*H*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
271 /*P*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
272 /*X*/ LETTER, LETTER, LETTER, ETC, ETC, ETC, BINOP, LETTER,
273 /*`*/ ETC, LTR16, LTR16, LTR16, LTR16, LTR16, LTR16, LETTER,
274 /*h*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
275 /*p*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
276 /*x*/ LETTER, LETTER, LETTER, ETC, BINOP, ETC, ETC, ETC
280 * an array of characters which
281 * perform the case translation function
284 /*NUL*/ '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
285 /*BS*/ '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
286 /*DLE*/ '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
287 /*CAN*/ '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
288 /*SPC*/ '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
289 /*(*/ '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
290 /*0*/ '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
291 /*8*/ '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
292 /*@*/ '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
293 /*H*/ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
294 /*P*/ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
295 /*X*/ '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
296 /*`*/ '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
297 /*h*/ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
298 /*p*/ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
299 /*x*/ '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177'