4 * (C) Copyright 1989-1996
12 * - add proto for strsto
13 * - change s_id from [NCPS] to pointer
14 * - change m_id from [NCPS] to pointer
15 * - change a_id from [NCPS] to pointer
18 * - always define "ccase"
22 * Extensions: P. Felber
25 #define VERSION "V01.75 + SDCC mods"
28 * Case Sensitivity Flag
30 #define CASE_SENSITIVE 1
34 * The module asm.h contains the definitions for constants,
35 * structures, global variables, and ASxxxx functions
36 * contained in the ASxxxx.c files. The two functions
37 * and three global variables from the machine dependent
38 * files are also defined.
42 * compiler/operating system specific definitions
45 /* DECUS C void definition */
46 /* File/extension seperator */
53 /* PDOS C void definition */
54 /* File/extension seperator */
61 /* Default void definition */
62 /* File/extension seperator */
74 #ifndef PATH_MAX /* POSIX, but not required */
75 #if defined(_MSC_VER) || defined(__BORLANDC__) /* Microsoft C or Borland C*/
77 #define PATH_MAX _MAX_PATH
79 #define PATH_MAX /* define a reasonable value */
83 #ifdef _WIN32 /* WIN32 native */
85 # define NATIVE_WIN32 1
86 # ifdef __MINGW32__ /* GCC MINGW32 depends on configure */
87 # include "../../sdccconf.h"
89 # include "../../sdcc_vc.h"
90 # define PATH_MAX _MAX_PATH
93 #else /* Assume Un*x style system */
94 # include "../../sdccconf.h"
98 * Assembler definitions.
100 #define LFTERM '(' /* Left expression delimeter */
101 #define RTTERM ')' /* Right expression delimeter */
104 #define NCPS 80 /* characters per symbol */
106 #define NCPS 8 /* Chars. per symbol */
108 /* #define NCPS 32 */ /* Chars. per symbol */
109 #define HUGE 1000 /* A huge number */
110 #define NERR 3 /* Errors per line */
111 #define NINPUT 1024 /* Input buffer size */
112 #define NCODE 128 /* Listing code buffer size */
113 #define NTITL 64 /* Title buffer size */
114 #define NSBTL 64 /* SubTitle buffer size */
115 #define NHASH 64 /* Buckets in hash table */
116 #define HMASK 077 /* Hash mask */
117 #define NLPP 60 /* Lines per page */
118 #define MAXFIL 6 /* Maximum command line input files */
119 #define MAXINC 6 /* Maximum nesting of include files */
120 #define MAXIF 10 /* Maximum nesting of if/else/endif */
121 #define FILSPC 256 /* Chars. in filespec */
123 #define NLIST 0 /* No listing */
124 #define SLIST 1 /* Source only */
125 #define ALIST 2 /* Address only */
126 #define BLIST 3 /* Address only with allocation */
127 #define CLIST 4 /* Code */
128 #define ELIST 5 /* Equate only */
130 #define dot sym[0] /* Dot, current loc */
131 #define dca area[0] /* Dca, default code area */
134 typedef unsigned int Addr_T;
137 * The area structure contains the parameter values for a
138 * specific program or data section. The area structure
139 * is a linked list of areas. The initial default area
140 * is "_CODE" defined in asdata.c, the next area structure
141 * will be linked to this structure through the structure
142 * element 'struct area *a_ap'. The structure contains the
143 * area name, area reference number ("_CODE" is 0) determined
144 * by the order of .area directives, area size determined
145 * from the total code and/or data in an area, area fuzz is
146 * a variable used to track pass to pass changes in the
147 * area size caused by variable length instruction formats,
148 * and area flags which specify the area's relocation type.
152 struct area *a_ap; /* Area link */
153 char *a_id; /* Area Name */
154 int a_ref; /* Ref. number */
155 Addr_T a_size; /* Area size */
156 Addr_T a_fuzz; /* Area fuzz */
157 int a_flag; /* Area flags */
161 * The "A_" area constants define values used in
162 * generating the assembler area output data.
167 * +-----+-----+-----+-----+-----+-----+-----+-----+
168 * | | | | PAG | ABS | OVR | | |
169 * +-----+-----+-----+-----+-----+-----+-----+-----+
172 #define A_CON 000 /* Concatenating */
173 #define A_OVR 004 /* Overlaying */
174 #define A_REL 000 /* Relocatable */
175 #define A_ABS 010 /* absolute */
176 #define A_NOPAG 000 /* Non-Paged */
177 #define A_PAG 020 /* Paged */
180 * The "R_" relocation constants define values used in
181 * generating the assembler relocation output data for
182 * areas, symbols, and code.
187 * +-----+-----+-----+-----+-----+-----+-----+-----+
188 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
189 * +-----+-----+-----+-----+-----+-----+-----+-----+
192 #define R_WORD 0000 /* 16 bit */
193 #define R_BYTE 0001 /* 8 bit */
195 #define R_AREA 0000 /* Base type */
198 #define R_NORM 0000 /* PC adjust */
201 #define R_BYT1 0000 /* Byte count for R_BYTE = 1 */
202 #define R_BYT2 0010 /* Byte count for R_BYTE = 2 */
204 #define R_SGND 0000 /* Signed Byte */
205 #define R_USGN 0020 /* Unsigned Byte */
207 #define R_NOPAG 0000 /* Page Mode */
208 #define R_PAG0 0040 /* Page '0' */
209 #define R_PAG 0100 /* Page 'nnn' */
211 #define R_LSB 0000 /* low byte */
212 #define R_MSB 0200 /* high byte */
215 * Listing Control Flags
218 #define R_HIGH 0040000 /* High Byte */
219 #define R_RELOC 0100000 /* Relocation */
221 #define R_DEF 00 /* Global def. */
222 #define R_REF 01 /* Global ref. */
223 #define R_REL 00 /* Relocatable */
224 #define R_ABS 02 /* Absolute */
225 #define R_GBL 00 /* Global */
226 #define R_LCL 04 /* Local */
229 * The mne structure is a linked list of the assembler
230 * mnemonics and directives. The list of mnemonics and
231 * directives contained in the device dependent file
232 * xxxpst.c are hashed and linked into NHASH lists in
233 * module assym.c by syminit(). The structure contains
234 * the mnemonic/directive name, a subtype which directs
235 * the evaluation of this mnemonic/directive, a flag which
236 * is used to detect the end of the mnemonic/directive
237 * list in xxxpst.c, and a value which is normally
238 * associated with the assembler mnemonic base instruction
243 struct mne *m_mp; /* Hash link */
244 char *m_id; /* Mnemonic */
245 char m_type; /* Mnemonic subtype */
246 char m_flag; /* Mnemonic flags */
247 Addr_T m_valu; /* Value */
251 * The sym structure is a linked list of symbols defined
252 * in the assembler source files. The first symbol is "."
253 * defined in asdata.c. The entry 'struct tsym *s_tsym'
254 * links any temporary symbols following this symbol and
255 * preceeding the next normal symbol. The structure also
256 * contains the symbol's name, type (USER or NEW), flag
257 * (global, assigned, and multiply defined), a pointer
258 * to the area structure defining where the symbol is
259 * located, a reference number assigned by outgsd() in
260 * asout.c, and the symbols address relative to the base
261 * address of the area where the symbol is located.
265 struct sym *s_sp; /* Hash link */
266 struct tsym *s_tsym; /* Temporary symbol link */
267 char *s_id; /* Symbol */
268 char s_type; /* Symbol subtype */
269 char s_flag; /* Symbol flags */
270 struct area *s_area; /* Area line, 0 if absolute */
271 int s_ref; /* Ref. number */
272 Addr_T s_addr; /* Address */
275 #define S_GBL 01 /* Global */
276 #define S_ASG 02 /* Assigned */
277 #define S_MDF 04 /* Mult. def */
278 #define S_END 010 /* End mark for pst. */
280 #define S_NEW 0 /* New name */
281 #define S_USER 1 /* User name */
286 #define S_BYTE 5 /* .byte */
287 #define S_WORD 6 /* .word */
288 #define S_ASCII 7 /* .ascii */
289 #define S_ASCIZ 8 /* .asciz */
290 #define S_BLK 9 /* .blkb or .blkw */
291 #define S_INCL 10 /* .include */
292 #define S_DAREA 11 /* .area */
293 #define S_ATYP 12 /* .area type */
294 #define S_AREA 13 /* .area name */
295 #define S_GLOBL 14 /* .globl */
296 #define S_PAGE 15 /* .page */
297 #define S_TITLE 16 /* .title */
298 #define S_SBTL 17 /* .sbttl */
299 #define S_IF 18 /* .if */
300 #define S_ELSE 19 /* .else */
301 #define S_ENDIF 20 /* .endif */
302 #define S_EVEN 21 /* .even */
303 #define S_ODD 22 /* .odd */
304 #define S_RADIX 23 /* .radix */
305 #define S_ORG 24 /* .org */
306 #define S_MODUL 25 /* .module */
307 #define S_ASCIS 26 /* .ascis */
309 # define S_FLOAT 27 /* .df */
311 #define S_OPTSDCC 28 /* .optsdcc */
314 * The tsym structure is a linked list of temporary
315 * symbols defined in the assembler source files following
316 * a normal symbol. The structure contains the temporary
317 * symbols number, a flag (multiply defined), a pointer to the
318 * area structure defining where the temporary structure
319 * is located, and the temporary symbol's address relative
320 * to the base address of the area where the symbol
325 struct tsym *t_lnk; /* Link to next */
326 int t_num; /* 0-lots$ */
327 char t_flg; /* flags */
328 struct area *t_area; /* Area */
329 Addr_T t_addr; /* Address */
333 * External Definitions for all Global Variables
336 extern int aserr; /* ASxxxx error counter
338 extern jmp_buf jump_env; /* compiler dependent structure
339 * used by setjmp() and longjmp()
341 extern int inpfil; /* count of assembler
342 * input files specified
344 extern int incfil; /* current file handle index
347 extern int cfile; /* current file handle index
348 * of input assembly files
350 extern int flevel; /* IF-ELSE-ENDIF flag will be non
351 * zero for false conditional case
353 extern int tlevel; /* current conditional level
355 extern int ifcnd[MAXIF+1]; /* array of IF statement condition
356 * values (0 = FALSE) indexed by tlevel
358 extern int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel
359 * values indexed by tlevel
362 afn[FILSPC]; /* afile() temporary filespec
365 srcfn[MAXFIL][FILSPC]; /* array of source file names
368 srcline[MAXFIL]; /* current source file line
371 incfn[MAXINC][FILSPC]; /* array of include file names
374 incline[MAXINC]; /* current include file line
376 extern int radix; /* current number conversion radix:
377 * 2 (binary), 8 (octal), 10 (decimal),
380 extern int line; /* current assembler source
383 extern int page; /* current page number
385 extern int lop; /* current line number on page
387 extern int pass; /* assembler pass number
389 extern int lflag; /* -l, generate listing flag
391 extern int cflag; /* -c, generate sdcdb debug information
393 extern int gflag; /* -g, make undefined symbols global flag
395 extern int aflag; /* -a, make all symbols global flag
397 extern int jflag; /* -j, generate debug information flag
399 extern int oflag; /* -o, generate relocatable output flag
401 extern int sflag; /* -s, generate symbol table flag
403 extern int pflag; /* -p, enable listing pagination
405 extern int xflag; /* -x, listing radix flag
407 extern int fflag; /* -f(f), relocations flagged flag
409 extern Addr_T laddr; /* address of current assembler line
410 * or value of .if argument
412 extern Addr_T fuzz; /* tracks pass to pass changes in the
413 * address of symbols caused by
414 * variable length instruction formats
416 extern int lmode; /* listing mode
418 extern struct area area[]; /* array of 1 area
420 extern struct area *areap; /* pointer to an area structure
422 extern struct sym sym[]; /* array of 1 symbol
424 extern struct sym *symp; /* pointer to a symbol structure
426 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
427 * linked symbol lists
429 extern struct mne *mnehash[NHASH]; /* array of pointers to NHASH
430 * linked mnemonic/directive lists
432 extern char *ep; /* pointer into error list
435 extern char eb[NERR]; /* array of generated error codes
437 extern const char *ip; /* pointer into the assembler-source
440 extern const char *ib; /* assembler-source text line
442 extern char *cp; /* pointer to assembler output
445 extern char cb[NCODE]; /* array of assembler output values
447 extern int *cpt; /* pointer to assembler relocation type
450 extern int cbt[NCODE]; /* array of assembler relocation types
451 * describing the data in cb[]
453 extern char tb[NTITL]; /* Title string buffer
455 extern char stb[NSBTL]; /* Subtitle string buffer
457 extern char optsdcc[NINPUT]; /* sdcc compile options
459 extern char symtbl[]; /* string "Symbol Table"
461 extern char aretbl[]; /* string "Area Table"
463 extern char module[NCPS]; /* module name string
465 extern FILE *lfp; /* list output file handle
467 extern FILE *ofp; /* relocation output file handle
469 extern FILE *tfp; /* symbol table output file handle
471 extern FILE *sfp[MAXFIL]; /* array of assembler-source file handles
473 extern FILE *ifp[MAXINC]; /* array of include-file file handles
475 extern unsigned char ctype[128]; /* array of character types, one per
478 extern char ccase[128]; /* an array of characters which
479 * perform the case translation function
483 * Definitions for Character Types
496 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
497 #define DGT8 DIGIT|RAD16|RAD10|RAD8
498 #define DGT10 DIGIT|RAD16|RAD10
499 #define LTR16 LETTER|RAD16
502 * The exp structure is used to return the evaluation
503 * of an expression. The structure supports three valid
505 * (1) The expression evaluates to a constant,
506 * mode = S_USER, flag = 0, addr contains the
507 * constant, and base = NULL.
508 * (2) The expression evaluates to a defined symbol
509 * plus or minus a constant, mode = S_USER,
510 * flag = 0, addr contains the constant, and
511 * base = pointer to area symbol.
512 * (3) The expression evaluates to a external
513 * global symbol plus or minus a constant,
514 * mode = S_NEW, flag = 1, addr contains the
515 * constant, and base = pointer to symbol.
519 char e_mode; /* Address mode */
520 char e_flag; /* Symbol flag */
521 Addr_T e_addr; /* Address */
525 } e_base; /* Rel. base */
526 char e_rlcf; /* Rel. flags */
529 /* C Library functions */
530 /* for reference only
533 extern char * fgets();
534 extern FILE * fopen();
535 extern int fprintf();
536 extern VOID longjmp();
537 extern VOID * malloc();
543 extern char * strcpy();
545 extern char * strncpy();
548 /* Machine independent functions */
551 extern FILE * afile();
552 extern VOID asexit();
555 extern VOID newdot();
560 extern char endline();
563 extern int as_getline();
571 extern struct area * alookup();
572 extern struct mne * mlookup();
574 extern struct sym * lookup();
576 extern char * strsto(char *str);
578 extern VOID syminit();
579 extern VOID symglob();
580 extern VOID allglob();
586 extern char * geterr();
591 extern VOID abscheck();
592 extern Addr_T absexpr();
593 extern VOID clrexpr();
604 extern VOID lstsym();
612 extern VOID outarea();
614 extern VOID outall();
615 extern VOID outdot();
616 extern VOID outbuf();
617 extern VOID outchk();
618 extern VOID outgsd();
621 extern VOID outsym();
622 extern VOID out_lb();
623 extern VOID out_lw();
624 extern VOID out_rw();
625 extern VOID out_tw();
628 extern void DefineNoICE_Line();
629 extern void DefineCDB_Line();
632 /* Machine dependent variables */
637 extern struct mne mne[];
639 /* Machine dependent functions */
644 extern int as_strcmpi(const char *s1, const char *s2);
645 extern int as_strncmpi(const char *s1, const char *s2, size_t n);