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 128 /* 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 */
277 * The tsym structure is a linked list of temporary
278 * symbols defined in the assembler source files following
279 * a normal symbol. The structure contains the temporary
280 * symbols number, a flag (multiply defined), a pointer to the
281 * area structure defining where the temporary structure
282 * is located, and the temporary symbol's address relative
283 * to the base address of the area where the symbol
288 struct tsym *t_lnk; /* Link to next */
289 int t_num; /* 0-lots$ */
290 char t_flg; /* flags */
291 struct area *t_area; /* Area */
292 Addr_T t_addr; /* Address */
296 * External Definitions for all Global Variables
299 extern int aserr; /* ASxxxx error counter
301 extern jmp_buf jump_env; /* compiler dependent structure
302 * used by setjmp() and longjmp()
304 extern int inpfil; /* count of assembler
305 * input files specified
307 extern int incfil; /* current file handle index
310 extern int cfile; /* current file handle index
311 * of input assembly files
313 extern int flevel; /* IF-ELSE-ENDIF flag will be non
314 * zero for false conditional case
316 extern int tlevel; /* current conditional level
318 extern int ifcnd[MAXIF+1]; /* array of IF statement condition
319 * values (0 = FALSE) indexed by tlevel
321 extern int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel
322 * values indexed by tlevel
325 afn[FILSPC]; /* afile() temporary filespec
328 srcfn[MAXFIL][FILSPC]; /* array of source file names
331 srcline[MAXFIL]; /* current source file line
334 incfn[MAXINC][FILSPC]; /* array of include file names
337 incline[MAXINC]; /* current include file line
339 extern int radix; /* current number conversion radix:
340 * 2 (binary), 8 (octal), 10 (decimal),
343 extern int line; /* current assembler source
346 extern int page; /* current page number
348 extern int lop; /* current line number on page
350 extern int pass; /* assembler pass number
352 extern int lflag; /* -l, generate listing flag
354 extern int gflag; /* -g, make undefined symbols global flag
356 extern int aflag; /* -a, make all symbols global flag
358 extern int oflag; /* -o, generate relocatable output flag
360 extern int sflag; /* -s, generate symbol table flag
362 extern int pflag; /* -p, enable listing pagination
364 extern int xflag; /* -x, listing radix flag
366 extern int fflag; /* -f(f), relocations flagged flag
368 extern Addr_T laddr; /* address of current assembler line
369 * or value of .if argument
371 extern Addr_T fuzz; /* tracks pass to pass changes in the
372 * address of symbols caused by
373 * variable length instruction formats
375 extern int lmode; /* listing mode
377 extern struct area area[]; /* array of 1 area
379 extern struct area *areap; /* pointer to an area structure
381 extern struct sym sym[]; /* array of 1 symbol
383 extern struct sym *symp; /* pointer to a symbol structure
385 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
386 * linked symbol lists
388 extern struct mne *mnehash[NHASH]; /* array of pointers to NHASH
389 * linked mnemonic/directive lists
391 extern char *ep; /* pointer into error list
394 extern char eb[NERR]; /* array of generated error codes
396 extern char *ip; /* pointer into the assembler-source
399 extern char ib[NINPUT]; /* assembler-source text line
401 extern char *cp; /* pointer to assembler output
404 extern char cb[NCODE]; /* array of assembler output values
406 extern int *cpt; /* pointer to assembler relocation type
409 extern int cbt[NCODE]; /* array of assembler relocation types
410 * describing the data in cb[]
412 extern char tb[NTITL]; /* Title string buffer
414 extern char stb[NSBTL]; /* Subtitle string buffer
416 extern char symtbl[]; /* string "Symbol Table"
418 extern char aretbl[]; /* string "Area Table"
420 extern char module[NCPS]; /* module name string
422 extern FILE *lfp; /* list output file handle
424 extern FILE *ofp; /* relocation output file handle
426 extern FILE *tfp; /* symbol table output file handle
428 extern FILE *sfp[MAXFIL]; /* array of assembler-source file handles
430 extern FILE *ifp[MAXINC]; /* array of include-file file handles
432 extern char ctype[128]; /* array of character types, one per
438 extern char ccase[128]; /* an array of characters which
439 * perform the case translation function
444 * Definitions for Character Types
457 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
458 #define DGT8 DIGIT|RAD16|RAD10|RAD8
459 #define DGT10 DIGIT|RAD16|RAD10
460 #define LTR16 LETTER|RAD16
463 * The exp structure is used to return the evaluation
464 * of an expression. The structure supports three valid
466 * (1) The expression evaluates to a constant,
467 * mode = S_USER, flag = 0, addr contains the
468 * constant, and base = NULL.
469 * (2) The expression evaluates to a defined symbol
470 * plus or minus a constant, mode = S_USER,
471 * flag = 0, addr contains the constant, and
472 * base = pointer to area symbol.
473 * (3) The expression evaluates to a external
474 * global symbol plus or minus a constant,
475 * mode = S_NEW, flag = 1, addr contains the
476 * constant, and base = pointer to symbol.
480 char e_mode; /* Address mode */
481 char e_flag; /* Symbol flag */
482 Addr_T e_addr; /* Address */
486 } e_base; /* Rel. base */
487 char e_rlcf; /* Rel. flags */
490 /* C Library functions */
491 /* for reference only
494 extern char * fgets();
495 extern FILE * fopen();
496 extern int fprintf();
497 extern VOID longjmp();
498 extern VOID * malloc();
504 extern char * strcpy();
506 extern char * strncpy();
509 /* Machine independent functions */
512 extern FILE * afile();
513 extern VOID asexit();
516 extern VOID newdot();
521 extern char endline();
524 extern int getline();
532 extern struct area * alookup();
533 extern struct mne * mlookup();
535 extern struct sym * lookup();
538 extern VOID syminit();
539 extern VOID symglob();
540 extern VOID allglob();
546 extern char * geterr();
551 extern VOID abscheck();
552 extern Addr_T absexpr();
553 extern VOID clrexpr();
564 extern VOID lstsym();
572 extern VOID outarea();
574 extern VOID outall();
575 extern VOID outdot();
576 extern VOID outbuf();
577 extern VOID outchk();
578 extern VOID outgsd();
581 extern VOID outsym();
582 extern VOID out_lb();
583 extern VOID out_lw();
584 extern VOID out_rw();
585 extern VOID out_tw();
588 /* Machine dependent variables */
593 extern struct mne mne[];
595 /* Machine dependent functions */