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"
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 */
71 * Assembler definitions.
73 #define LFTERM '(' /* Left expression delimeter */
74 #define RTTERM ')' /* Right expression delimeter */
77 #define NCPS 80 /* characters per symbol */
79 #define NCPS 8 /* Chars. per symbol */
81 /* #define NCPS 32 */ /* Chars. per symbol */
82 #define HUGE 1000 /* A huge number */
83 #define NERR 3 /* Errors per line */
84 #define NINPUT 1024 /* 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 256 /* 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 typedef unsigned int Addr_T;
110 * The area structure contains the parameter values for a
111 * specific program or data section. The area structure
112 * is a linked list of areas. The initial default area
113 * is "_CODE" defined in asdata.c, the next area structure
114 * will be linked to this structure through the structure
115 * element 'struct area *a_ap'. The structure contains the
116 * area name, area reference number ("_CODE" is 0) determined
117 * by the order of .area directives, area size determined
118 * from the total code and/or data in an area, area fuzz is
119 * a variable used to track pass to pass changes in the
120 * area size caused by variable length instruction formats,
121 * and area flags which specify the area's relocation type.
125 struct area *a_ap; /* Area link */
126 char *a_id; /* Area Name */
127 int a_ref; /* Ref. number */
128 Addr_T a_size; /* Area size */
129 Addr_T a_fuzz; /* Area fuzz */
130 int a_flag; /* Area flags */
134 * The "A_" area constants define values used in
135 * generating the assembler area output data.
140 * +-----+-----+-----+-----+-----+-----+-----+-----+
141 * | | | | PAG | ABS | OVR | | |
142 * +-----+-----+-----+-----+-----+-----+-----+-----+
145 #define A_CON 000 /* Concatenating */
146 #define A_OVR 004 /* Overlaying */
147 #define A_REL 000 /* Relocatable */
148 #define A_ABS 010 /* absolute */
149 #define A_NOPAG 000 /* Non-Paged */
150 #define A_PAG 020 /* Paged */
153 * The "R_" relocation constants define values used in
154 * generating the assembler relocation output data for
155 * areas, symbols, and code.
160 * +-----+-----+-----+-----+-----+-----+-----+-----+
161 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
162 * +-----+-----+-----+-----+-----+-----+-----+-----+
165 #define R_WORD 0000 /* 16 bit */
166 #define R_BYTE 0001 /* 8 bit */
168 #define R_AREA 0000 /* Base type */
171 #define R_NORM 0000 /* PC adjust */
174 #define R_BYT1 0000 /* Byte count for R_BYTE = 1 */
175 #define R_BYT2 0010 /* Byte count for R_BYTE = 2 */
177 #define R_SGND 0000 /* Signed Byte */
178 #define R_USGN 0020 /* Unsigned Byte */
180 #define R_NOPAG 0000 /* Page Mode */
181 #define R_PAG0 0040 /* Page '0' */
182 #define R_PAG 0100 /* Page 'nnn' */
184 #define R_LSB 0000 /* low byte */
185 #define R_MSB 0200 /* high byte */
188 * Listing Control Flags
191 #define R_HIGH 0040000 /* High Byte */
192 #define R_RELOC 0100000 /* Relocation */
194 #define R_DEF 00 /* Global def. */
195 #define R_REF 01 /* Global ref. */
196 #define R_REL 00 /* Relocatable */
197 #define R_ABS 02 /* Absolute */
198 #define R_GBL 00 /* Global */
199 #define R_LCL 04 /* Local */
202 * The mne structure is a linked list of the assembler
203 * mnemonics and directives. The list of mnemonics and
204 * directives contained in the device dependent file
205 * xxxpst.c are hashed and linked into NHASH lists in
206 * module assym.c by syminit(). The structure contains
207 * the mnemonic/directive name, a subtype which directs
208 * the evaluation of this mnemonic/directive, a flag which
209 * is used to detect the end of the mnemonic/directive
210 * list in xxxpst.c, and a value which is normally
211 * associated with the assembler mnemonic base instruction
216 struct mne *m_mp; /* Hash link */
217 char *m_id; /* Mnemonic */
218 char m_type; /* Mnemonic subtype */
219 char m_flag; /* Mnemonic flags */
220 Addr_T m_valu; /* Value */
224 * The sym structure is a linked list of symbols defined
225 * in the assembler source files. The first symbol is "."
226 * defined in asdata.c. The entry 'struct tsym *s_tsym'
227 * links any temporary symbols following this symbol and
228 * preceeding the next normal symbol. The structure also
229 * contains the symbol's name, type (USER or NEW), flag
230 * (global, assigned, and multiply defined), a pointer
231 * to the area structure defining where the symbol is
232 * located, a reference number assigned by outgsd() in
233 * asout.c, and the symbols address relative to the base
234 * address of the area where the symbol is located.
238 struct sym *s_sp; /* Hash link */
239 struct tsym *s_tsym; /* Temporary symbol link */
240 char *s_id; /* Symbol */
241 char s_type; /* Symbol subtype */
242 char s_flag; /* Symbol flags */
243 struct area *s_area; /* Area line, 0 if absolute */
244 int s_ref; /* Ref. number */
245 Addr_T s_addr; /* Address */
248 #define S_GBL 01 /* Global */
249 #define S_ASG 02 /* Assigned */
250 #define S_MDF 04 /* Mult. def */
251 #define S_END 010 /* End mark for pst. */
253 #define S_NEW 0 /* New name */
254 #define S_USER 1 /* User name */
259 #define S_BYTE 5 /* .byte */
260 #define S_WORD 6 /* .word */
261 #define S_ASCII 7 /* .ascii */
262 #define S_ASCIZ 8 /* .asciz */
263 #define S_BLK 9 /* .blkb or .blkw */
264 #define S_INCL 10 /* .include */
265 #define S_DAREA 11 /* .area */
266 #define S_ATYP 12 /* .area type */
267 #define S_AREA 13 /* .area name */
268 #define S_GLOBL 14 /* .globl */
269 #define S_PAGE 15 /* .page */
270 #define S_TITLE 16 /* .title */
271 #define S_SBTL 17 /* .sbttl */
272 #define S_IF 18 /* .if */
273 #define S_ELSE 19 /* .else */
274 #define S_ENDIF 20 /* .endif */
275 #define S_EVEN 21 /* .even */
276 #define S_ODD 22 /* .odd */
277 #define S_RADIX 23 /* .radix */
278 #define S_ORG 24 /* .org */
279 #define S_MODUL 25 /* .module */
280 #define S_ASCIS 26 /* .ascis */
282 # define S_FLOAT 27 /* .df */
284 #define S_OPTSDCC 28 /* .optsdcc */
287 * The tsym structure is a linked list of temporary
288 * symbols defined in the assembler source files following
289 * a normal symbol. The structure contains the temporary
290 * symbols number, a flag (multiply defined), a pointer to the
291 * area structure defining where the temporary structure
292 * is located, and the temporary symbol's address relative
293 * to the base address of the area where the symbol
298 struct tsym *t_lnk; /* Link to next */
299 int t_num; /* 0-lots$ */
300 char t_flg; /* flags */
301 struct area *t_area; /* Area */
302 Addr_T t_addr; /* Address */
306 * External Definitions for all Global Variables
309 extern int aserr; /* ASxxxx error counter
311 extern jmp_buf jump_env; /* compiler dependent structure
312 * used by setjmp() and longjmp()
314 extern int inpfil; /* count of assembler
315 * input files specified
317 extern int incfil; /* current file handle index
320 extern int cfile; /* current file handle index
321 * of input assembly files
323 extern int flevel; /* IF-ELSE-ENDIF flag will be non
324 * zero for false conditional case
326 extern int tlevel; /* current conditional level
328 extern int ifcnd[MAXIF+1]; /* array of IF statement condition
329 * values (0 = FALSE) indexed by tlevel
331 extern int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel
332 * values indexed by tlevel
335 afn[FILSPC]; /* afile() temporary filespec
338 srcfn[MAXFIL][FILSPC]; /* array of source file names
341 srcline[MAXFIL]; /* current source file line
344 incfn[MAXINC][FILSPC]; /* array of include file names
347 incline[MAXINC]; /* current include file line
349 extern int radix; /* current number conversion radix:
350 * 2 (binary), 8 (octal), 10 (decimal),
353 extern int line; /* current assembler source
356 extern int page; /* current page number
358 extern int lop; /* current line number on page
360 extern int pass; /* assembler pass number
362 extern int lflag; /* -l, generate listing flag
364 extern int gflag; /* -g, make undefined symbols global flag
366 extern int aflag; /* -a, make all symbols global flag
368 extern int oflag; /* -o, generate relocatable output flag
370 extern int sflag; /* -s, generate symbol table flag
372 extern int pflag; /* -p, enable listing pagination
374 extern int xflag; /* -x, listing radix flag
376 extern int fflag; /* -f(f), relocations flagged flag
378 extern Addr_T laddr; /* address of current assembler line
379 * or value of .if argument
381 extern Addr_T fuzz; /* tracks pass to pass changes in the
382 * address of symbols caused by
383 * variable length instruction formats
385 extern int lmode; /* listing mode
387 extern struct area area[]; /* array of 1 area
389 extern struct area *areap; /* pointer to an area structure
391 extern struct sym sym[]; /* array of 1 symbol
393 extern struct sym *symp; /* pointer to a symbol structure
395 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
396 * linked symbol lists
398 extern struct mne *mnehash[NHASH]; /* array of pointers to NHASH
399 * linked mnemonic/directive lists
401 extern char *ep; /* pointer into error list
404 extern char eb[NERR]; /* array of generated error codes
406 extern const char *ip; /* pointer into the assembler-source
409 extern const char *ib; /* assembler-source text line
411 extern char *cp; /* pointer to assembler output
414 extern char cb[NCODE]; /* array of assembler output values
416 extern int *cpt; /* pointer to assembler relocation type
419 extern int cbt[NCODE]; /* array of assembler relocation types
420 * describing the data in cb[]
422 extern char tb[NTITL]; /* Title string buffer
424 extern char stb[NSBTL]; /* Subtitle string buffer
426 extern char optsdcc[NINPUT]; /* sdcc compile options
428 extern char symtbl[]; /* string "Symbol Table"
430 extern char aretbl[]; /* string "Area Table"
432 extern char module[NCPS]; /* module name string
434 extern FILE *lfp; /* list output file handle
436 extern FILE *ofp; /* relocation output file handle
438 extern FILE *tfp; /* symbol table output file handle
440 extern FILE *sfp[MAXFIL]; /* array of assembler-source file handles
442 extern FILE *ifp[MAXINC]; /* array of include-file file handles
444 extern unsigned char ctype[128]; /* array of character types, one per
447 extern char ccase[128]; /* an array of characters which
448 * perform the case translation function
452 * Definitions for Character Types
465 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
466 #define DGT8 DIGIT|RAD16|RAD10|RAD8
467 #define DGT10 DIGIT|RAD16|RAD10
468 #define LTR16 LETTER|RAD16
471 * The exp structure is used to return the evaluation
472 * of an expression. The structure supports three valid
474 * (1) The expression evaluates to a constant,
475 * mode = S_USER, flag = 0, addr contains the
476 * constant, and base = NULL.
477 * (2) The expression evaluates to a defined symbol
478 * plus or minus a constant, mode = S_USER,
479 * flag = 0, addr contains the constant, and
480 * base = pointer to area symbol.
481 * (3) The expression evaluates to a external
482 * global symbol plus or minus a constant,
483 * mode = S_NEW, flag = 1, addr contains the
484 * constant, and base = pointer to symbol.
488 char e_mode; /* Address mode */
489 char e_flag; /* Symbol flag */
490 Addr_T e_addr; /* Address */
494 } e_base; /* Rel. base */
495 char e_rlcf; /* Rel. flags */
498 /* C Library functions */
499 /* for reference only
502 extern char * fgets();
503 extern FILE * fopen();
504 extern int fprintf();
505 extern VOID longjmp();
506 extern VOID * malloc();
512 extern char * strcpy();
514 extern char * strncpy();
517 /* Machine independent functions */
520 extern FILE * afile();
521 extern VOID asexit();
524 extern VOID newdot();
529 extern char endline();
532 extern int as_getline();
540 extern struct area * alookup();
541 extern struct mne * mlookup();
543 extern struct sym * lookup();
545 extern char * strsto(char *str);
547 extern VOID syminit();
548 extern VOID symglob();
549 extern VOID allglob();
555 extern char * geterr();
560 extern VOID abscheck();
561 extern Addr_T absexpr();
562 extern VOID clrexpr();
573 extern VOID lstsym();
581 extern VOID outarea();
583 extern VOID outall();
584 extern VOID outdot();
585 extern VOID outbuf();
586 extern VOID outchk();
587 extern VOID outgsd();
590 extern VOID outsym();
591 extern VOID out_lb();
592 extern VOID out_lw();
593 extern VOID out_rw();
594 extern VOID out_tw();
597 /* Machine dependent variables */
602 extern struct mne mne[];
604 /* Machine dependent functions */
609 extern int as_strcmpi(const char *s1, const char *s2);
610 extern int as_strncmpi(const char *s1, const char *s2, size_t n);