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/>. */
27 * The module asdata.c contains the global constants,
28 * structures, and variables used in the assembler.
31 int aserr; /* ASxxxx error counter
33 jmp_buf jump_env; /* compiler dependent structure
34 * used by setjmp() and longjmp()
36 int inpfil; /* count of assembler
37 * input files specified
39 int incfil; /* current file handle index
42 int cfile; /* current file handle index
43 * of input assembly files
45 int flevel; /* IF-ELSE-ENDIF flag will be non
46 * zero for false conditional case
48 int tlevel; /* current conditional level
50 int ifcnd[MAXIF+1]; /* array of IF statement condition
51 * values (0 = FALSE) indexed by tlevel
53 int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel
54 * values indexed by tlevel
57 char afn[FILSPC]; /* afile temporary file name
59 char srcfn[MAXFIL][FILSPC]; /* array of source file names
61 int srcline[MAXFIL]; /* source line number
63 char incfn[MAXINC][FILSPC]; /* array of include file names
65 int incline[MAXINC]; /* include line number
68 int radix; /* current number conversion radix:
69 * 2 (binary), 8 (octal), 10 (decimal),
72 int line; /* current assembler source
75 int page; /* current page number
77 int lop; /* current line number on page
79 int pass; /* assembler pass number
81 int lflag; /* -l, generate listing flag
83 int cflag; /* -c, generate sdcdb debug info
85 int gflag; /* -g, make undefined symbols global flag
87 int aflag; /* -a, make all symbols global flag
89 int jflag; /* -j, generate debug information flag
91 int oflag; /* -o, generate relocatable output flag
93 int sflag; /* -s, generate symbol table flag
95 int pflag; /* -p, enable listing pagination
97 int xflag; /* -x, listing radix flag
99 int fflag; /* -f(f), relocations flagged flag
101 Addr_T laddr; /* address of current assembler line
102 * or value of .if argument
104 Addr_T fuzz; /* tracks pass to pass changes in the
105 * address of symbols caused by
106 * variable length instruction formats
108 int lmode; /* listing mode
110 char *ep; /* pointer into error list
113 char eb[NERR]; /* array of generated error codes
115 const char *ip; /* pointer into the assembler-source
118 const char *ib; /* assembler-source text line
120 char *cp; /* pointer to assembler output
123 char cb[NCODE]; /* array of assembler output values
125 int *cpt; /* pointer to assembler relocation type
128 int cbt[NCODE]; /* array of assembler relocation types
129 * describing the data in cb[]
131 char tb[NTITL]; /* Title string buffer
133 char stb[NSBTL]; /* Subtitle string buffer
135 char optsdcc[NINPUT]; /* sdcc compile options
138 char symtbl[] = { "Symbol Table" };
139 char aretbl[] = { "Area Table" };
141 char module[NCPS]; /* module name string
145 * The mne structure is a linked list of the assembler
146 * mnemonics and directives. The list of mnemonics and
147 * directives contained in the device dependent file
148 * xxxpst.c are hashed and linked into NHASH lists in
149 * module assym.c by syminit(). The structure contains
150 * the mnemonic/directive name, a subtype which directs
151 * the evaluation of this mnemonic/directive, a flag which
152 * is used to detect the end of the mnemonic/directive
153 * list in xxxpst.c, and a value which is normally
154 * associated with the assembler mnemonic base instruction
159 * struct mne *m_mp; Hash link
160 * char *m_id; Mnemonic
161 * char m_type; Mnemonic subtype
162 * char m_flag; Mnemonic flags
163 * Addr_T m_valu; Value
166 struct mne *mnehash[NHASH];
169 * The sym structure is a linked list of symbols defined
170 * in the assembler source files. The first symbol is "."
171 * defined here. The entry 'struct tsym *s_tsym'
172 * links any temporary symbols following this symbol and
173 * preceeding the next normal symbol. The structure also
174 * contains the symbol's name, type (USER or NEW), flag
175 * (global, assigned, and multiply defined), a pointer
176 * to the area structure defining where the symbol is
177 * located, a reference number assigned by outgsd() in
178 * asout.c, and the symbols address relative to the base
179 * address of the area where the symbol is located.
183 * struct sym *s_sp; Hash link
184 * struct tsym *s_tsym; Temporary symbol link
186 * char s_type; Symbol subtype
187 * char s_flag; Symbol flags
188 * struct area *s_area; Area line, 0 if absolute
189 * int s_ref; Ref. number
190 * Addr_T s_addr; Address
194 { NULL, NULL, ".", S_USER, S_END, NULL, 0, }
197 struct sym *symp; /* pointer to a symbol structure
199 struct sym *symhash[NHASH]; /* array of pointers to NHASH
200 * linked symbol lists
204 * The area structure contains the parameter values for a
205 * specific program or data section. The area structure
206 * is a linked list of areas. The initial default area
207 * is "_CODE" defined here, the next area structure
208 * will be linked to this structure through the structure
209 * element 'struct area *a_ep'. The structure contains the
210 * area name, area reference number ("_CODE" is 0) determined
211 * by the order of .area directives, area size determined
212 * from the total code and/or data in an area, area fuzz is
213 * an variable used to track pass to pass changes in the
214 * area size caused by variable length instruction formats,
215 * and area flags which specify the area's relocation type.
219 * struct area *a_ap; Area link
220 * char *a_id; Area Name
221 * int a_ref; Reference number
222 * Addr_T a_size; Area size
223 * Addr_T a_fuzz; Area fuzz
224 * int a_flag; Area flags
227 struct area area[] = {
228 { NULL, "_CODE", 0, 0, 0, A_CON|A_REL }
231 struct area *areap; /* pointer to an area structure
234 FILE *lfp; /* list output file handle
236 FILE *ofp; /* relocation output file handle
238 FILE *tfp; /* symbol table output file handle
240 FILE *sfp[MAXFIL]; /* array of assembler-source file handles
242 FILE *ifp[MAXINC]; /* array of include-file file handles
246 * array of character types, one per
249 unsigned char ctype[128] = {
250 /*NUL*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
251 /*BS*/ ILL, SPACE, ILL, ILL, SPACE, ILL, ILL, ILL,
252 /*DLE*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
253 /*CAN*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
254 /*SPC*/ SPACE, ETC, ETC, ETC, LETTER, BINOP, BINOP, ETC,
255 /*(*/ ETC, ETC, BINOP, BINOP, ETC, BINOP, LETTER, BINOP,
256 /*0*/ DGT2, DGT2, DGT8, DGT8, DGT8, DGT8, DGT8, DGT8,
257 /*8*/ DGT10, DGT10, ETC, ETC, BINOP, ETC, BINOP, ETC,
258 /*@*/ ETC, LTR16, LTR16, LTR16, LTR16, LTR16, LTR16, LETTER,
259 /*H*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
260 /*P*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
261 /*X*/ LETTER, LETTER, LETTER, ETC, ETC, ETC, BINOP, LETTER,
262 /*`*/ ETC, LTR16, LTR16, LTR16, LTR16, LTR16, LTR16, LETTER,
263 /*h*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
264 /*p*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
265 /*x*/ LETTER, LETTER, LETTER, ETC, BINOP, ETC, ETC, ETC
269 * an array of characters which
270 * perform the case translation function
273 /*NUL*/ '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
274 /*BS*/ '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
275 /*DLE*/ '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
276 /*CAN*/ '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
277 /*SPC*/ '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
278 /*(*/ '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
279 /*0*/ '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
280 /*8*/ '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
281 /*@*/ '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
282 /*H*/ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
283 /*P*/ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
284 /*X*/ '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
285 /*`*/ '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
286 /*h*/ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
287 /*p*/ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
288 /*x*/ '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177'