4 * (C) Copyright 1989-1995
12 * - add proto for StoreString
13 * - change s_id from [NCPS] to pointer
14 * - change m_id from [NCPS] to pointer
17 * - add R_J11 for 8051 assembler
18 * - add outr11 prototype for 8051 assembler
19 * - always define "ccase"
21 * - add jflag for debug control
22 * - prototypes for DefineNoICE_Line
24 * - add memory space flags to a_flag for 8051
27 * - add DS80C390 flat mode support.
30 #define VERSION "V01.70 + NoICE + SDCC mods + Flat24 Feb-1999"
33 * Case Sensitivity Flag
35 #define CASE_SENSITIVE 1
39 * The module asm.h contains the definitions for constants,
40 * structures, global variables, and ASxxxx functions
41 * contained in the ASxxxx.c files. The two functions
42 * and three global variables from the machine dependent
43 * files are also defined.
47 * compiler/operating system specific definitions
50 /* DECUS C void definition */
51 /* File/extension seperator */
58 /* PDOS C void definition */
59 /* File/extension seperator */
66 /* Default void definition */
67 /* File/extension seperator */
76 * Assembler definitions.
78 #define LFTERM '(' /* Left expression delimeter */
79 #define RTTERM ')' /* Right expression delimeter */
81 #define NCPS 80 /* Chars. per symbol (JLH: change from 8) */
82 #define HUGE 1000 /* A huge number */
83 #define NERR 3 /* Errors per line */
84 #define NINPUT 128 /* Input buffer size */
85 #define NCODE 128 /* Listing code buffer size */
86 #define NTITL 64 /* Title buffer size */
87 #define NSBTL 64 /* SubTitle buffer size */
88 #define NHASH 64 /* Buckets in hash table */
89 #define HMASK 077 /* Hash mask */
90 #define NLPP 60 /* Lines per page */
91 #define MAXFIL 6 /* Maximum command line input files */
92 #define MAXINC 6 /* Maximum nesting of include files */
93 #define MAXIF 10 /* Maximum nesting of if/else/endif */
94 #define FILSPC 80 /* Chars. in filespec */
96 #define NLIST 0 /* No listing */
97 #define SLIST 1 /* Source only */
98 #define ALIST 2 /* Address only */
99 #define BLIST 3 /* Address only with allocation */
100 #define CLIST 4 /* Code */
101 #define ELIST 5 /* Equate only */
103 #define dot sym[0] /* Dot, current loc */
104 #define dca area[0] /* Dca, default code area */
107 /* NB: for Flat24 extentions to work, addr_t must be at least 24
108 * bits. This is checked at runtime when the .flat24 directive
111 typedef unsigned int addr_t;
114 * The area structure contains the parameter values for a
115 * specific program or data section. The area structure
116 * is a linked list of areas. The initial default area
117 * is "_CODE" defined in asdata.c, the next area structure
118 * will be linked to this structure through the structure
119 * element 'struct area *a_ap'. The structure contains the
120 * area name, area reference number ("_CODE" is 0) determined
121 * by the order of .area directives, area size determined
122 * from the total code and/or data in an area, area fuzz is
123 * a variable used to track pass to pass changes in the
124 * area size caused by variable length instruction formats,
125 * and area flags which specify the area's relocation type.
129 struct area *a_ap; /* Area link */
130 char a_id[NCPS]; /* Area Name */
131 int a_ref; /* Ref. number */
132 addr_t a_size; /* Area size */
133 addr_t a_fuzz; /* Area fuzz */
134 int a_flag; /* Area flags */
138 * The "A_" area constants define values used in
139 * generating the assembler area output data.
144 * +-----+-----+-----+-----+-----+-----+-----+-----+
145 * | BIT |XDATA|DATA | PAG | ABS | OVR | | |
146 * +-----+-----+-----+-----+-----+-----+-----+-----+
149 #define A_CON 0000 /* Concatenating */
150 #define A_OVR 0004 /* Overlaying */
151 #define A_REL 0000 /* Relocatable */
152 #define A_ABS 0010 /* absolute */
153 #define A_NOPAG 0000 /* Non-Paged */
154 #define A_PAG 0020 /* Paged */
156 /* Additional flags for 8051 address spaces */
157 #define A_DATA 0000 /* data space (default)*/
158 #define A_CODE 0040 /* code space */
159 #define A_XDATA 0100 /* external data space */
160 #define A_BIT 0200 /* bit addressable space */
163 * The "R_" relocation constants define values used in
164 * generating the assembler relocation output data for
165 * areas, symbols, and code.
170 * +-----+-----+-----+-----+-----+-----+-----+-----+
171 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
172 * +-----+-----+-----+-----+-----+-----+-----+-----+
175 #define R_WORD 0000 /* 16 bit */
176 #define R_BYTE 0001 /* 8 bit */
178 #define R_AREA 0000 /* Base type */
181 #define R_NORM 0000 /* PC adjust */
184 #define R_BYT1 0000 /* Byte count for R_BYTE = 1 */
185 #define R_BYT2 0010 /* Byte count for R_BYTE = 2 */
187 #define R_SGND 0000 /* Signed Byte */
188 #define R_USGN 0020 /* Unsigned Byte */
190 #define R_NOPAG 0000 /* Page Mode */
191 #define R_PAG0 0040 /* Page '0' */
192 #define R_PAG 0100 /* Page 'nnn' */
194 #define R_LSB 0000 /* low byte */
195 #define R_MSB 0200 /* high byte */
197 #define R_J11 (R_WORD|R_BYT2) /* JLH: 11 bit JMP and CALL (8051) */
198 #define R_J19 (R_WORD|R_BYT2|R_MSB) /* 19 bit JMP/CALL (DS80C390) */
199 #define R_C24 (R_WORD|R_BYT1|R_MSB) /* 24 bit address (DS80C390) */
200 #define R_J19_MASK (R_BYTE|R_BYT2|R_MSB)
202 #define IS_R_J19(x) (((x) & R_J19_MASK) == R_J19)
203 #define IS_R_J11(x) (((x) & R_J19_MASK) == R_J11)
204 #define IS_C24(x) (((x) & R_J19_MASK) == R_C24)
207 * Listing Control Flags
210 #define R_HIGH 0040000 /* High Byte */
211 #define R_RELOC 0100000 /* Relocation */
213 #define R_DEF 00 /* Global def. */
214 #define R_REF 01 /* Global ref. */
215 #define R_REL 00 /* Relocatable */
216 #define R_ABS 02 /* Absolute */
217 #define R_GBL 00 /* Global */
218 #define R_LCL 04 /* Local */
221 * The mne structure is a linked list of the assembler
222 * mnemonics and directives. The list of mnemonics and
223 * directives contained in the device dependent file
224 * xxxpst.c are hashed and linked into NHASH lists in
225 * module assym.c by syminit(). The structure contains
226 * the mnemonic/directive name, a subtype which directs
227 * the evaluation of this mnemonic/directive, a flag which
228 * is used to detect the end of the mnemonic/directive
229 * list in xxxpst.c, and a value which is normally
230 * associated with the assembler mnemonic base instruction
235 struct mne *m_mp; /* Hash link */
236 char *m_id; /* Mnemonic JLH: change from [NCPS] */
237 char m_type; /* Mnemonic subtype */
238 char m_flag; /* Mnemonic flags */
239 addr_t m_valu; /* Value */
243 * The sym structure is a linked list of symbols defined
244 * in the assembler source files. The first symbol is "."
245 * defined in asdata.c. The entry 'struct tsym *s_tsym'
246 * links any temporary symbols following this symbol and
247 * preceeding the next normal symbol. The structure also
248 * contains the symbol's name, type (USER or NEW), flag
249 * (global, assigned, and multiply defined), a pointer
250 * to the area structure defining where the symbol is
251 * located, a reference number assigned by outgsd() in
252 * asout.c, and the symbols address relative to the base
253 * address of the area where the symbol is located.
257 struct sym *s_sp; /* Hash link */
258 struct tsym *s_tsym; /* Temporary symbol link */
259 char *s_id; /* Symbol: JLH change from [NCPS] */
260 char s_type; /* Symbol subtype */
261 char s_flag; /* Symbol flags */
262 struct area *s_area; /* Area line, 0 if absolute */
263 int s_ref; /* Ref. number */
264 addr_t s_addr; /* Address */
267 #define S_GBL 01 /* Global */
268 #define S_ASG 02 /* Assigned */
269 #define S_MDF 04 /* Mult. def */
270 #define S_END 010 /* End mark for pst. */
272 #define S_NEW 0 /* New name */
273 #define S_USER 1 /* User name */
278 #define S_BYTE 5 /* .byte */
279 #define S_WORD 6 /* .word */
280 #define S_ASCII 7 /* .ascii */
281 #define S_ASCIZ 8 /* .asciz */
282 #define S_BLK 9 /* .blkb or .blkw */
283 #define S_INCL 10 /* .include */
284 #define S_DAREA 11 /* .area */
285 #define S_ATYP 12 /* .area type */
286 #define S_AREA 13 /* .area name */
287 #define S_GLOBL 14 /* .globl */
288 #define S_PAGE 15 /* .page */
289 #define S_TITLE 16 /* .title */
290 #define S_SBTL 17 /* .sbttl */
291 #define S_IF 18 /* .if */
292 #define S_ELSE 19 /* .else */
293 #define S_ENDIF 20 /* .endif */
294 #define S_EVEN 21 /* .even */
295 #define S_ODD 22 /* .odd */
296 #define S_RADIX 23 /* .radix */
297 #define S_ORG 24 /* .org */
298 #define S_MODUL 25 /* .module */
299 #define S_ASCIS 26 /* .ascis */
300 #define S_FLAT24 27 /* .flat24 */
304 * The tsym structure is a linked list of temporary
305 * symbols defined in the assembler source files following
306 * a normal symbol. The structure contains the temporary
307 * symbols number, a flag (multiply defined), a pointer to the
308 * area structure defining where the temporary structure
309 * is located, and the temporary symbol's address relative
310 * to the base address of the area where the symbol
315 struct tsym *t_lnk; /* Link to next */
316 /* sandeep changed to 'int' from 'char' */
317 /* this will increase the number temp symbols
318 that can be defined from 255 to INT_MAX */
319 int t_num; /* 0-INT_MAX$ */
320 int t_flg; /* flags */
322 struct area *t_area; /* Area */
323 addr_t t_addr; /* Address */
327 * External Definitions for all Global Variables
330 extern int aserr; /* ASxxxx error counter
332 extern jmp_buf jump_env; /* compiler dependent structure
333 * used by setjmp() and longjmp()
335 extern int inpfil; /* count of assembler
336 * input files specified
338 extern int incfil; /* current file handle index
341 extern int cfile; /* current file handle index
342 * of input assembly files
344 extern int flevel; /* IF-ELSE-ENDIF flag will be non
345 * zero for false conditional case
347 extern int tlevel; /* current conditional level
349 extern int ifcnd[MAXIF+1]; /* array of IF statement condition
350 * values (0 = FALSE) indexed by tlevel
352 extern int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel
353 * values indexed by tlevel
356 afn[FILSPC]; /* afile() temporary filespec
359 srcfn[MAXFIL][FILSPC]; /* array of source file names
362 srcline[MAXFIL]; /* current source file line
365 incfn[MAXINC][FILSPC]; /* array of include file names
368 incline[MAXINC]; /* current include file line
370 extern int radix; /* current number conversion radix:
371 * 2 (binary), 8 (octal), 10 (decimal),
374 extern int line; /* current assembler source
377 extern int page; /* current page number
379 extern int lop; /* current line number on page
381 extern int pass; /* assembler pass number
383 extern int lflag; /* -l, generate listing flag
385 extern int cflag; /* -c, generate sdcdb debug information
387 extern int gflag; /* -g, make undefined symbols global flag
389 extern int aflag; /* -a, make all symbols global flag
391 extern int jflag; /* -j, generate debug information flag
393 extern int oflag; /* -o, generate relocatable output flag
395 extern int sflag; /* -s, generate symbol table flag
397 extern int pflag; /* -p, enable listing pagination
399 extern int xflag; /* -x, listing radix flag
401 extern int fflag; /* -f(f), relocations flagged flag
403 extern addr_t laddr; /* address of current assembler line
404 * or value of .if argument
406 extern addr_t fuzz; /* tracks pass to pass changes in the
407 * address of symbols caused by
408 * variable length instruction formats
410 extern int lmode; /* listing mode
412 extern struct area area[]; /* array of 1 area
414 extern struct area *areap; /* pointer to an area structure
416 extern struct sym sym[]; /* array of 1 symbol
418 extern struct sym *symp; /* pointer to a symbol structure
420 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
421 * linked symbol lists
423 extern struct mne *mnehash[NHASH]; /* array of pointers to NHASH
424 * linked mnemonic/directive lists
426 extern char *ep; /* pointer into error list
429 extern char eb[NERR]; /* array of generated error codes
431 extern char *ip; /* pointer into the assembler-source
434 extern char ib[NINPUT]; /* assembler-source text line
436 extern char *cp; /* pointer to assembler output
439 extern char cb[NCODE]; /* array of assembler output values
441 extern int *cpt; /* pointer to assembler relocation type
444 extern int cbt[NCODE]; /* array of assembler relocation types
445 * describing the data in cb[]
447 extern char tb[NTITL]; /* Title string buffer
449 extern char stb[NSBTL]; /* Subtitle string buffer
451 extern int flat24Mode; /* non-zero if we are using DS390 24 bit
452 * flat mode (via .flat24 directive).
454 extern char symtbl[]; /* string "Symbol Table"
456 extern char aretbl[]; /* string "Area Table"
458 extern char module[NCPS]; /* module name string
460 extern FILE *lfp; /* list output file handle
462 extern FILE *ofp; /* relocation output file handle
464 extern FILE *tfp; /* symbol table output file handle
466 extern FILE *sfp[MAXFIL]; /* array of assembler-source file handles
468 extern FILE *ifp[MAXINC]; /* array of include-file file handles
470 extern char ctype[128]; /* array of character types, one per
474 extern char ccase[128]; /* an array of characters which
475 * perform the case translation function
478 * Definitions for Character Types
491 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
492 #define DGT8 DIGIT|RAD16|RAD10|RAD8
493 #define DGT10 DIGIT|RAD16|RAD10
494 #define LTR16 LETTER|RAD16
497 * The exp structure is used to return the evaluation
498 * of an expression. The structure supports three valid
500 * (1) The expression evaluates to a constant,
501 * mode = S_USER, flag = 0, addr contains the
502 * constant, and base = NULL.
503 * (2) The expression evaluates to a defined symbol
504 * plus or minus a constant, mode = S_USER,
505 * flag = 0, addr contains the constant, and
506 * base = pointer to area symbol.
507 * (3) The expression evaluates to a external
508 * global symbol plus or minus a constant,
509 * mode = S_NEW, flag = 1, addr contains the
510 * constant, and base = pointer to symbol.
514 char e_mode; /* Address mode */
515 char e_flag; /* Symbol flag */
516 addr_t e_addr; /* Address */
520 } e_base; /* Rel. base */
521 char e_rlcf; /* Rel. flags */
524 /* C Library functions */
525 /* for reference only
528 extern char * fgets();
529 extern FILE * fopen();
530 extern int fprintf();
531 extern VOID longjmp();
532 extern VOID * malloc();
538 extern char * strcpy();
540 extern char * strncpy();
543 /* Machine independent functions */
546 extern FILE * afile();
547 extern VOID asexit();
550 extern VOID newdot();
555 extern char endline();
558 extern int getline();
566 extern struct area * alookup();
567 extern struct mne * mlookup();
569 extern struct sym * lookup();
572 extern VOID syminit();
573 extern VOID symglob();
574 extern VOID allglob();
580 extern VOID warnBanner(void);
581 extern char * geterr();
586 extern VOID abscheck();
587 extern addr_t absexpr();
588 extern VOID clrexpr();
599 extern VOID lstsym();
605 extern int byte3(int);
608 extern VOID outarea();
610 extern VOID outall();
611 extern VOID outdot();
612 extern VOID outbuf();
613 extern VOID outchk();
614 extern VOID outgsd();
617 extern VOID outr24(struct expr *, int);
618 extern VOID outsym();
619 extern VOID out_lb();
620 extern VOID out_lw();
621 extern VOID out_l24(int, int);
622 extern VOID out_rw();
623 extern VOID out_tw();
624 extern VOID out_t24(int);
625 extern VOID outr11(); /* JLH */
626 extern VOID outr19(struct expr *, int, int);
629 extern char *StoreString( char *str );
632 extern void DefineNoICE_Line();
633 extern void DefineCDB_Line();
635 /* Machine dependent variables */
640 extern struct mne mne[];
642 /* Machine dependent functions */
644 extern VOID machin();
647 /* SD added THIS define to change
648 strcmpi --> strcmp (strcmpi is NOT ANSI) */
649 #define strcmpi strcmp