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 * - add proto for strsto
22 * - change s_id from [NCPS] to pointer
23 * - change m_id from [NCPS] to pointer
24 * - change a_id from [NCPS] to pointer
27 * - always define "ccase"
31 * Extensions: P. Felber
34 #define VERSION "V01.75 + SDCC mods"
37 * Case Sensitivity Flag
39 #define CASE_SENSITIVE 1
43 * The module asm.h contains the definitions for constants,
44 * structures, global variables, and ASxxxx functions
45 * contained in the ASxxxx.c files. The two functions
46 * and three global variables from the machine dependent
47 * files are also defined.
51 * compiler/operating system specific definitions
54 /* DECUS C void definition */
55 /* File/extension seperator */
62 /* PDOS C void definition */
63 /* File/extension seperator */
70 /* Default void definition */
71 /* File/extension seperator */
83 #ifndef PATH_MAX /* POSIX, but not required */
84 #if defined(_MSC_VER) || defined(__BORLANDC__) /* Microsoft C or Borland C*/
86 #define PATH_MAX _MAX_PATH
88 #define PATH_MAX /* define a reasonable value */
92 #ifdef _WIN32 /* WIN32 native */
94 # define NATIVE_WIN32 1
95 # ifdef __MINGW32__ /* GCC MINGW32 depends on configure */
96 # include "../../sdccconf.h"
98 # include "../../sdcc_vc.h"
99 # define PATH_MAX _MAX_PATH
102 #else /* Assume Un*x style system */
103 # include "../../sdccconf.h"
107 * Assembler definitions.
109 #define LFTERM '(' /* Left expression delimeter */
110 #define RTTERM ')' /* Right expression delimeter */
113 #define NCPS 80 /* characters per symbol */
115 #define NCPS 8 /* Chars. per symbol */
117 /* #define NCPS 32 */ /* Chars. per symbol */
118 #define HUGE 1000 /* A huge number */
119 #define NERR 3 /* Errors per line */
120 #define NINPUT 1024 /* Input buffer size */
121 #define NCODE 128 /* Listing code buffer size */
122 #define NTITL 64 /* Title buffer size */
123 #define NSBTL 64 /* SubTitle buffer size */
124 #define NHASH 64 /* Buckets in hash table */
125 #define HMASK 077 /* Hash mask */
126 #define NLPP 60 /* Lines per page */
127 #define MAXFIL 6 /* Maximum command line input files */
128 #define MAXINC 6 /* Maximum nesting of include files */
129 #define MAXIF 10 /* Maximum nesting of if/else/endif */
130 #define FILSPC 256 /* Chars. in filespec */
132 #define NLIST 0 /* No listing */
133 #define SLIST 1 /* Source only */
134 #define ALIST 2 /* Address only */
135 #define BLIST 3 /* Address only with allocation */
136 #define CLIST 4 /* Code */
137 #define ELIST 5 /* Equate only */
139 #define dot sym[0] /* Dot, current loc */
140 #define dca area[0] /* Dca, default code area */
143 typedef unsigned int Addr_T;
146 * The area structure contains the parameter values for a
147 * specific program or data section. The area structure
148 * is a linked list of areas. The initial default area
149 * is "_CODE" defined in asdata.c, the next area structure
150 * will be linked to this structure through the structure
151 * element 'struct area *a_ap'. The structure contains the
152 * area name, area reference number ("_CODE" is 0) determined
153 * by the order of .area directives, area size determined
154 * from the total code and/or data in an area, area fuzz is
155 * a variable used to track pass to pass changes in the
156 * area size caused by variable length instruction formats,
157 * and area flags which specify the area's relocation type.
161 struct area *a_ap; /* Area link */
162 char *a_id; /* Area Name */
163 int a_ref; /* Ref. number */
164 Addr_T a_size; /* Area size */
165 Addr_T a_fuzz; /* Area fuzz */
166 int a_flag; /* Area flags */
170 * The "A_" area constants define values used in
171 * generating the assembler area output data.
176 * +-----+-----+-----+-----+-----+-----+-----+-----+
177 * | | | | PAG | ABS | OVR | | |
178 * +-----+-----+-----+-----+-----+-----+-----+-----+
181 #define A_CON 000 /* Concatenating */
182 #define A_OVR 004 /* Overlaying */
183 #define A_REL 000 /* Relocatable */
184 #define A_ABS 010 /* absolute */
185 #define A_NOPAG 000 /* Non-Paged */
186 #define A_PAG 020 /* Paged */
189 * The "R_" relocation constants define values used in
190 * generating the assembler relocation output data for
191 * areas, symbols, and code.
196 * +-----+-----+-----+-----+-----+-----+-----+-----+
197 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
198 * +-----+-----+-----+-----+-----+-----+-----+-----+
201 #define R_WORD 0000 /* 16 bit */
202 #define R_BYTE 0001 /* 8 bit */
204 #define R_AREA 0000 /* Base type */
207 #define R_NORM 0000 /* PC adjust */
210 #define R_BYT1 0000 /* Byte count for R_BYTE = 1 */
211 #define R_BYT2 0010 /* Byte count for R_BYTE = 2 */
213 #define R_SGND 0000 /* Signed Byte */
214 #define R_USGN 0020 /* Unsigned Byte */
216 #define R_NOPAG 0000 /* Page Mode */
217 #define R_PAG0 0040 /* Page '0' */
218 #define R_PAG 0100 /* Page 'nnn' */
220 #define R_LSB 0000 /* low byte */
221 #define R_MSB 0200 /* high byte */
224 * Listing Control Flags
227 #define R_HIGH 0040000 /* High Byte */
228 #define R_RELOC 0100000 /* Relocation */
230 #define R_DEF 00 /* Global def. */
231 #define R_REF 01 /* Global ref. */
232 #define R_REL 00 /* Relocatable */
233 #define R_ABS 02 /* Absolute */
234 #define R_GBL 00 /* Global */
235 #define R_LCL 04 /* Local */
238 * The mne structure is a linked list of the assembler
239 * mnemonics and directives. The list of mnemonics and
240 * directives contained in the device dependent file
241 * xxxpst.c are hashed and linked into NHASH lists in
242 * module assym.c by syminit(). The structure contains
243 * the mnemonic/directive name, a subtype which directs
244 * the evaluation of this mnemonic/directive, a flag which
245 * is used to detect the end of the mnemonic/directive
246 * list in xxxpst.c, and a value which is normally
247 * associated with the assembler mnemonic base instruction
252 struct mne *m_mp; /* Hash link */
253 char *m_id; /* Mnemonic */
254 char m_type; /* Mnemonic subtype */
255 char m_flag; /* Mnemonic flags */
256 Addr_T m_valu; /* Value */
260 * The sym structure is a linked list of symbols defined
261 * in the assembler source files. The first symbol is "."
262 * defined in asdata.c. The entry 'struct tsym *s_tsym'
263 * links any temporary symbols following this symbol and
264 * preceeding the next normal symbol. The structure also
265 * contains the symbol's name, type (USER or NEW), flag
266 * (global, assigned, and multiply defined), a pointer
267 * to the area structure defining where the symbol is
268 * located, a reference number assigned by outgsd() in
269 * asout.c, and the symbols address relative to the base
270 * address of the area where the symbol is located.
274 struct sym *s_sp; /* Hash link */
275 struct tsym *s_tsym; /* Temporary symbol link */
276 char *s_id; /* Symbol */
277 char s_type; /* Symbol subtype */
278 char s_flag; /* Symbol flags */
279 struct area *s_area; /* Area line, 0 if absolute */
280 int s_ref; /* Ref. number */
281 Addr_T s_addr; /* Address */
284 #define S_GBL 01 /* Global */
285 #define S_ASG 02 /* Assigned */
286 #define S_MDF 04 /* Mult. def */
287 #define S_END 010 /* End mark for pst. */
289 #define S_NEW 0 /* New name */
290 #define S_USER 1 /* User name */
295 #define S_BYTE 5 /* .byte */
296 #define S_WORD 6 /* .word */
297 #define S_ASCII 7 /* .ascii */
298 #define S_ASCIZ 8 /* .asciz */
299 #define S_BLK 9 /* .blkb or .blkw */
300 #define S_INCL 10 /* .include */
301 #define S_DAREA 11 /* .area */
302 #define S_ATYP 12 /* .area type */
303 #define S_AREA 13 /* .area name */
304 #define S_GLOBL 14 /* .globl */
305 #define S_PAGE 15 /* .page */
306 #define S_TITLE 16 /* .title */
307 #define S_SBTL 17 /* .sbttl */
308 #define S_IF 18 /* .if */
309 #define S_ELSE 19 /* .else */
310 #define S_ENDIF 20 /* .endif */
311 #define S_EVEN 21 /* .even */
312 #define S_ODD 22 /* .odd */
313 #define S_RADIX 23 /* .radix */
314 #define S_ORG 24 /* .org */
315 #define S_MODUL 25 /* .module */
316 #define S_ASCIS 26 /* .ascis */
318 # define S_FLOAT 27 /* .df */
320 #define S_OPTSDCC 28 /* .optsdcc */
323 * The tsym structure is a linked list of temporary
324 * symbols defined in the assembler source files following
325 * a normal symbol. The structure contains the temporary
326 * symbols number, a flag (multiply defined), a pointer to the
327 * area structure defining where the temporary structure
328 * is located, and the temporary symbol's address relative
329 * to the base address of the area where the symbol
334 struct tsym *t_lnk; /* Link to next */
335 int t_num; /* 0-lots$ */
336 char t_flg; /* flags */
337 struct area *t_area; /* Area */
338 Addr_T t_addr; /* Address */
342 * External Definitions for all Global Variables
345 extern int aserr; /* ASxxxx error counter
347 extern jmp_buf jump_env; /* compiler dependent structure
348 * used by setjmp() and longjmp()
350 extern int inpfil; /* count of assembler
351 * input files specified
353 extern int incfil; /* current file handle index
356 extern int cfile; /* current file handle index
357 * of input assembly files
359 extern int flevel; /* IF-ELSE-ENDIF flag will be non
360 * zero for false conditional case
362 extern int tlevel; /* current conditional level
364 extern int ifcnd[MAXIF+1]; /* array of IF statement condition
365 * values (0 = FALSE) indexed by tlevel
367 extern int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel
368 * values indexed by tlevel
371 afn[FILSPC]; /* afile() temporary filespec
374 srcfn[MAXFIL][FILSPC]; /* array of source file names
377 srcline[MAXFIL]; /* current source file line
380 incfn[MAXINC][FILSPC]; /* array of include file names
383 incline[MAXINC]; /* current include file line
385 extern int radix; /* current number conversion radix:
386 * 2 (binary), 8 (octal), 10 (decimal),
389 extern int line; /* current assembler source
392 extern int page; /* current page number
394 extern int lop; /* current line number on page
396 extern int pass; /* assembler pass number
398 extern int lflag; /* -l, generate listing flag
400 extern int cflag; /* -c, generate sdcdb debug information
402 extern int gflag; /* -g, make undefined symbols global flag
404 extern int aflag; /* -a, make all symbols global flag
406 extern int jflag; /* -j, generate debug information flag
408 extern int oflag; /* -o, generate relocatable output flag
410 extern int sflag; /* -s, generate symbol table flag
412 extern int pflag; /* -p, enable listing pagination
414 extern int xflag; /* -x, listing radix flag
416 extern int fflag; /* -f(f), relocations flagged flag
418 extern Addr_T laddr; /* address of current assembler line
419 * or value of .if argument
421 extern Addr_T fuzz; /* tracks pass to pass changes in the
422 * address of symbols caused by
423 * variable length instruction formats
425 extern int lmode; /* listing mode
427 extern struct area area[]; /* array of 1 area
429 extern struct area *areap; /* pointer to an area structure
431 extern struct sym sym[]; /* array of 1 symbol
433 extern struct sym *symp; /* pointer to a symbol structure
435 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
436 * linked symbol lists
438 extern struct mne *mnehash[NHASH]; /* array of pointers to NHASH
439 * linked mnemonic/directive lists
441 extern char *ep; /* pointer into error list
444 extern char eb[NERR]; /* array of generated error codes
446 extern const char *ip; /* pointer into the assembler-source
449 extern const char *ib; /* assembler-source text line
451 extern char *cp; /* pointer to assembler output
454 extern char cb[NCODE]; /* array of assembler output values
456 extern int *cpt; /* pointer to assembler relocation type
459 extern int cbt[NCODE]; /* array of assembler relocation types
460 * describing the data in cb[]
462 extern char tb[NTITL]; /* Title string buffer
464 extern char stb[NSBTL]; /* Subtitle string buffer
466 extern char optsdcc[NINPUT]; /* sdcc compile options
468 extern char symtbl[]; /* string "Symbol Table"
470 extern char aretbl[]; /* string "Area Table"
472 extern char module[NCPS]; /* module name string
474 extern FILE *lfp; /* list output file handle
476 extern FILE *ofp; /* relocation output file handle
478 extern FILE *tfp; /* symbol table output file handle
480 extern FILE *sfp[MAXFIL]; /* array of assembler-source file handles
482 extern FILE *ifp[MAXINC]; /* array of include-file file handles
484 extern unsigned char ctype[128]; /* array of character types, one per
487 extern char ccase[128]; /* an array of characters which
488 * perform the case translation function
492 * Definitions for Character Types
505 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
506 #define DGT8 DIGIT|RAD16|RAD10|RAD8
507 #define DGT10 DIGIT|RAD16|RAD10
508 #define LTR16 LETTER|RAD16
511 * The exp structure is used to return the evaluation
512 * of an expression. The structure supports three valid
514 * (1) The expression evaluates to a constant,
515 * mode = S_USER, flag = 0, addr contains the
516 * constant, and base = NULL.
517 * (2) The expression evaluates to a defined symbol
518 * plus or minus a constant, mode = S_USER,
519 * flag = 0, addr contains the constant, and
520 * base = pointer to area symbol.
521 * (3) The expression evaluates to a external
522 * global symbol plus or minus a constant,
523 * mode = S_NEW, flag = 1, addr contains the
524 * constant, and base = pointer to symbol.
528 char e_mode; /* Address mode */
529 char e_flag; /* Symbol flag */
530 Addr_T e_addr; /* Address */
534 } e_base; /* Rel. base */
535 char e_rlcf; /* Rel. flags */
538 /* C Library functions */
539 /* for reference only
542 extern char * fgets();
543 extern FILE * fopen();
544 extern int fprintf();
545 extern VOID longjmp();
546 extern VOID * malloc();
552 extern char * strcpy();
554 extern char * strncpy();
557 /* Machine independent functions */
560 extern FILE * afile();
561 extern VOID asexit();
564 extern VOID newdot();
569 extern char endline();
572 extern int as_getline();
580 extern struct area * alookup();
581 extern struct mne * mlookup();
583 extern struct sym * lookup();
585 extern char * strsto(char *str);
587 extern VOID syminit();
588 extern VOID symglob();
589 extern VOID allglob();
595 extern char * geterr();
600 extern VOID abscheck();
601 extern Addr_T absexpr();
602 extern VOID clrexpr();
613 extern VOID lstsym();
621 extern VOID outarea();
623 extern VOID outall();
624 extern VOID outdot();
625 extern VOID outbuf();
626 extern VOID outchk();
627 extern VOID outgsd();
630 extern VOID outsym();
631 extern VOID out_lb();
632 extern VOID out_lw();
633 extern VOID out_rw();
634 extern VOID out_tw();
637 extern void DefineNoICE_Line();
638 extern void DefineCDB_Line();
641 /* Machine dependent variables */
646 extern struct mne mne[];
648 /* Machine dependent functions */
653 extern int as_strcmpi(const char *s1, const char *s2);
654 extern int as_strncmpi(const char *s1, const char *s2, size_t n);