4 * (C) Copyright 1989-1996
13 * Extensions: P. Felber
16 #define VERSION "V01.75"
19 * Case Sensitivity Flag
21 #define CASE_SENSITIVE 0
25 * The module asm.h contains the definitions for constants,
26 * structures, global variables, and ASxxxx functions
27 * contained in the ASxxxx.c files. The two functions
28 * and three global variables from the machine dependent
29 * files are also defined.
33 * compiler/operating system specific definitions
36 /* DECUS C void definition */
37 /* File/extension seperator */
44 /* PDOS C void definition */
45 /* File/extension seperator */
52 /* Default void definition */
53 /* File/extension seperator */
62 * Assembler definitions.
64 #define LFTERM '(' /* Left expression delimeter */
65 #define RTTERM ')' /* Right expression delimeter */
68 #define NCPS 32 /* characters per symbol */
70 #define NCPS 8 /* Chars. per symbol */
72 /* #define NCPS 32 */ /* Chars. per symbol */
73 #define HUGE 1000 /* A huge number */
74 #define NERR 3 /* Errors per line */
75 #define NINPUT 1024 /* Input buffer size */
76 #define NCODE 128 /* Listing code buffer size */
77 #define NTITL 64 /* Title buffer size */
78 #define NSBTL 64 /* SubTitle buffer size */
79 #define NHASH 64 /* Buckets in hash table */
80 #define HMASK 077 /* Hash mask */
81 #define NLPP 60 /* Lines per page */
82 #define MAXFIL 6 /* Maximum command line input files */
83 #define MAXINC 6 /* Maximum nesting of include files */
84 #define MAXIF 10 /* Maximum nesting of if/else/endif */
85 #define FILSPC 256 /* Chars. in filespec */
87 #define NLIST 0 /* No listing */
88 #define SLIST 1 /* Source only */
89 #define ALIST 2 /* Address only */
90 #define BLIST 3 /* Address only with allocation */
91 #define CLIST 4 /* Code */
92 #define ELIST 5 /* Equate only */
94 #define dot sym[0] /* Dot, current loc */
95 #define dca area[0] /* Dca, default code area */
98 typedef unsigned int Addr_T;
101 * The area structure contains the parameter values for a
102 * specific program or data section. The area structure
103 * is a linked list of areas. The initial default area
104 * is "_CODE" defined in asdata.c, the next area structure
105 * will be linked to this structure through the structure
106 * element 'struct area *a_ap'. The structure contains the
107 * area name, area reference number ("_CODE" is 0) determined
108 * by the order of .area directives, area size determined
109 * from the total code and/or data in an area, area fuzz is
110 * a variable used to track pass to pass changes in the
111 * area size caused by variable length instruction formats,
112 * and area flags which specify the area's relocation type.
116 struct area *a_ap; /* Area link */
117 char a_id[NCPS]; /* Area Name */
118 int a_ref; /* Ref. number */
119 Addr_T a_size; /* Area size */
120 Addr_T a_fuzz; /* Area fuzz */
121 int a_flag; /* Area flags */
125 * The "A_" area constants define values used in
126 * generating the assembler area output data.
131 * +-----+-----+-----+-----+-----+-----+-----+-----+
132 * | | | | PAG | ABS | OVR | | |
133 * +-----+-----+-----+-----+-----+-----+-----+-----+
136 #define A_CON 000 /* Concatenating */
137 #define A_OVR 004 /* Overlaying */
138 #define A_REL 000 /* Relocatable */
139 #define A_ABS 010 /* absolute */
140 #define A_NOPAG 000 /* Non-Paged */
141 #define A_PAG 020 /* Paged */
144 * The "R_" relocation constants define values used in
145 * generating the assembler relocation output data for
146 * areas, symbols, and code.
151 * +-----+-----+-----+-----+-----+-----+-----+-----+
152 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
153 * +-----+-----+-----+-----+-----+-----+-----+-----+
156 #define R_WORD 0000 /* 16 bit */
157 #define R_BYTE 0001 /* 8 bit */
159 #define R_AREA 0000 /* Base type */
162 #define R_NORM 0000 /* PC adjust */
165 #define R_BYT1 0000 /* Byte count for R_BYTE = 1 */
166 #define R_BYT2 0010 /* Byte count for R_BYTE = 2 */
168 #define R_SGND 0000 /* Signed Byte */
169 #define R_USGN 0020 /* Unsigned Byte */
171 #define R_NOPAG 0000 /* Page Mode */
172 #define R_PAG0 0040 /* Page '0' */
173 #define R_PAG 0100 /* Page 'nnn' */
175 #define R_LSB 0000 /* low byte */
176 #define R_MSB 0200 /* high byte */
179 * Listing Control Flags
182 #define R_HIGH 0040000 /* High Byte */
183 #define R_RELOC 0100000 /* Relocation */
185 #define R_DEF 00 /* Global def. */
186 #define R_REF 01 /* Global ref. */
187 #define R_REL 00 /* Relocatable */
188 #define R_ABS 02 /* Absolute */
189 #define R_GBL 00 /* Global */
190 #define R_LCL 04 /* Local */
193 * The mne structure is a linked list of the assembler
194 * mnemonics and directives. The list of mnemonics and
195 * directives contained in the device dependent file
196 * xxxpst.c are hashed and linked into NHASH lists in
197 * module assym.c by syminit(). The structure contains
198 * the mnemonic/directive name, a subtype which directs
199 * the evaluation of this mnemonic/directive, a flag which
200 * is used to detect the end of the mnemonic/directive
201 * list in xxxpst.c, and a value which is normally
202 * associated with the assembler mnemonic base instruction
207 struct mne *m_mp; /* Hash link */
208 char m_id[NCPS]; /* Mnemonic */
209 char m_type; /* Mnemonic subtype */
210 char m_flag; /* Mnemonic flags */
211 Addr_T m_valu; /* Value */
215 * The sym structure is a linked list of symbols defined
216 * in the assembler source files. The first symbol is "."
217 * defined in asdata.c. The entry 'struct tsym *s_tsym'
218 * links any temporary symbols following this symbol and
219 * preceeding the next normal symbol. The structure also
220 * contains the symbol's name, type (USER or NEW), flag
221 * (global, assigned, and multiply defined), a pointer
222 * to the area structure defining where the symbol is
223 * located, a reference number assigned by outgsd() in
224 * asout.c, and the symbols address relative to the base
225 * address of the area where the symbol is located.
229 struct sym *s_sp; /* Hash link */
230 struct tsym *s_tsym; /* Temporary symbol link */
231 char s_id[NCPS]; /* Symbol */
232 char s_type; /* Symbol subtype */
233 char s_flag; /* Symbol flags */
234 struct area *s_area; /* Area line, 0 if absolute */
235 int s_ref; /* Ref. number */
236 Addr_T s_addr; /* Address */
239 #define S_GBL 01 /* Global */
240 #define S_ASG 02 /* Assigned */
241 #define S_MDF 04 /* Mult. def */
242 #define S_END 010 /* End mark for pst. */
244 #define S_NEW 0 /* New name */
245 #define S_USER 1 /* User name */
250 #define S_BYTE 5 /* .byte */
251 #define S_WORD 6 /* .word */
252 #define S_ASCII 7 /* .ascii */
253 #define S_ASCIZ 8 /* .asciz */
254 #define S_BLK 9 /* .blkb or .blkw */
255 #define S_INCL 10 /* .include */
256 #define S_DAREA 11 /* .area */
257 #define S_ATYP 12 /* .area type */
258 #define S_AREA 13 /* .area name */
259 #define S_GLOBL 14 /* .globl */
260 #define S_PAGE 15 /* .page */
261 #define S_TITLE 16 /* .title */
262 #define S_SBTL 17 /* .sbttl */
263 #define S_IF 18 /* .if */
264 #define S_ELSE 19 /* .else */
265 #define S_ENDIF 20 /* .endif */
266 #define S_EVEN 21 /* .even */
267 #define S_ODD 22 /* .odd */
268 #define S_RADIX 23 /* .radix */
269 #define S_ORG 24 /* .org */
270 #define S_MODUL 25 /* .module */
271 #define S_ASCIS 26 /* .ascis */
273 # define S_FLOAT 27 /* .df */
275 #define S_OPTSDCC 28 /* .optsdcc */
278 * The tsym structure is a linked list of temporary
279 * symbols defined in the assembler source files following
280 * a normal symbol. The structure contains the temporary
281 * symbols number, a flag (multiply defined), a pointer to the
282 * area structure defining where the temporary structure
283 * is located, and the temporary symbol's address relative
284 * to the base address of the area where the symbol
289 struct tsym *t_lnk; /* Link to next */
290 int t_num; /* 0-lots$ */
291 char t_flg; /* flags */
292 struct area *t_area; /* Area */
293 Addr_T t_addr; /* Address */
297 * External Definitions for all Global Variables
300 extern int aserr; /* ASxxxx error counter
302 extern jmp_buf jump_env; /* compiler dependent structure
303 * used by setjmp() and longjmp()
305 extern int inpfil; /* count of assembler
306 * input files specified
308 extern int incfil; /* current file handle index
311 extern int cfile; /* current file handle index
312 * of input assembly files
314 extern int flevel; /* IF-ELSE-ENDIF flag will be non
315 * zero for false conditional case
317 extern int tlevel; /* current conditional level
319 extern int ifcnd[MAXIF+1]; /* array of IF statement condition
320 * values (0 = FALSE) indexed by tlevel
322 extern int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel
323 * values indexed by tlevel
326 afn[FILSPC]; /* afile() temporary filespec
329 srcfn[MAXFIL][FILSPC]; /* array of source file names
332 srcline[MAXFIL]; /* current source file line
335 incfn[MAXINC][FILSPC]; /* array of include file names
338 incline[MAXINC]; /* current include file line
340 extern int radix; /* current number conversion radix:
341 * 2 (binary), 8 (octal), 10 (decimal),
344 extern int line; /* current assembler source
347 extern int page; /* current page number
349 extern int lop; /* current line number on page
351 extern int pass; /* assembler pass number
353 extern int lflag; /* -l, generate listing flag
355 extern int gflag; /* -g, make undefined symbols global flag
357 extern int aflag; /* -a, make all symbols global flag
359 extern int oflag; /* -o, generate relocatable output flag
361 extern int sflag; /* -s, generate symbol table flag
363 extern int pflag; /* -p, enable listing pagination
365 extern int xflag; /* -x, listing radix flag
367 extern int fflag; /* -f(f), relocations flagged flag
369 extern Addr_T laddr; /* address of current assembler line
370 * or value of .if argument
372 extern Addr_T fuzz; /* tracks pass to pass changes in the
373 * address of symbols caused by
374 * variable length instruction formats
376 extern int lmode; /* listing mode
378 extern struct area area[]; /* array of 1 area
380 extern struct area *areap; /* pointer to an area structure
382 extern struct sym sym[]; /* array of 1 symbol
384 extern struct sym *symp; /* pointer to a symbol structure
386 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
387 * linked symbol lists
389 extern struct mne *mnehash[NHASH]; /* array of pointers to NHASH
390 * linked mnemonic/directive lists
392 extern char *ep; /* pointer into error list
395 extern char eb[NERR]; /* array of generated error codes
397 extern char *ip; /* pointer into the assembler-source
400 extern char ib[NINPUT]; /* assembler-source text line
402 extern char *cp; /* pointer to assembler output
405 extern char cb[NCODE]; /* array of assembler output values
407 extern int *cpt; /* pointer to assembler relocation type
410 extern int cbt[NCODE]; /* array of assembler relocation types
411 * describing the data in cb[]
413 extern char tb[NTITL]; /* Title string buffer
415 extern char stb[NSBTL]; /* Subtitle string buffer
417 extern char optsdcc[NINPUT]; /* sdcc compile options
419 extern char symtbl[]; /* string "Symbol Table"
421 extern char aretbl[]; /* string "Area Table"
423 extern char module[NCPS]; /* module name string
425 extern FILE *lfp; /* list output file handle
427 extern FILE *ofp; /* relocation output file handle
429 extern FILE *tfp; /* symbol table output file handle
431 extern FILE *sfp[MAXFIL]; /* array of assembler-source file handles
433 extern FILE *ifp[MAXINC]; /* array of include-file file handles
435 extern unsigned char ctype[128]; /* array of character types, one per
441 extern char ccase[128]; /* an array of characters which
442 * perform the case translation function
447 * Definitions for Character Types
460 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
461 #define DGT8 DIGIT|RAD16|RAD10|RAD8
462 #define DGT10 DIGIT|RAD16|RAD10
463 #define LTR16 LETTER|RAD16
466 * The exp structure is used to return the evaluation
467 * of an expression. The structure supports three valid
469 * (1) The expression evaluates to a constant,
470 * mode = S_USER, flag = 0, addr contains the
471 * constant, and base = NULL.
472 * (2) The expression evaluates to a defined symbol
473 * plus or minus a constant, mode = S_USER,
474 * flag = 0, addr contains the constant, and
475 * base = pointer to area symbol.
476 * (3) The expression evaluates to a external
477 * global symbol plus or minus a constant,
478 * mode = S_NEW, flag = 1, addr contains the
479 * constant, and base = pointer to symbol.
483 char e_mode; /* Address mode */
484 char e_flag; /* Symbol flag */
485 Addr_T e_addr; /* Address */
489 } e_base; /* Rel. base */
490 char e_rlcf; /* Rel. flags */
493 /* C Library functions */
494 /* for reference only
497 extern char * fgets();
498 extern FILE * fopen();
499 extern int fprintf();
500 extern VOID longjmp();
501 extern VOID * malloc();
507 extern char * strcpy();
509 extern char * strncpy();
512 /* Machine independent functions */
515 extern FILE * afile();
516 extern VOID asexit();
519 extern VOID newdot();
524 extern char endline();
527 extern int getline();
535 extern struct area * alookup();
536 extern struct mne * mlookup();
538 extern struct sym * lookup();
541 extern VOID syminit();
542 extern VOID symglob();
543 extern VOID allglob();
549 extern char * geterr();
554 extern VOID abscheck();
555 extern Addr_T absexpr();
556 extern VOID clrexpr();
567 extern VOID lstsym();
575 extern VOID outarea();
577 extern VOID outall();
578 extern VOID outdot();
579 extern VOID outbuf();
580 extern VOID outchk();
581 extern VOID outgsd();
584 extern VOID outsym();
585 extern VOID out_lb();
586 extern VOID out_lw();
587 extern VOID out_rw();
588 extern VOID out_tw();
591 /* Machine dependent variables */
596 extern struct mne mne[];
598 /* Machine dependent functions */