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 #define VERSION "V01.70 + NoICE + SDCC mods Feb-1999"
30 * Case Sensitivity Flag
32 #define CASE_SENSITIVE 1
36 * The module asm.h contains the definitions for constants,
37 * structures, global variables, and ASxxxx functions
38 * contained in the ASxxxx.c files. The two functions
39 * and three global variables from the machine dependent
40 * files are also defined.
44 * compiler/operating system specific definitions
47 /* DECUS C void definition */
48 /* File/extension seperator */
55 /* PDOS C void definition */
56 /* File/extension seperator */
63 /* Default void definition */
64 /* File/extension seperator */
73 * Assembler definitions.
75 #define LFTERM '(' /* Left expression delimeter */
76 #define RTTERM ')' /* Right expression delimeter */
78 #define NCPS 80 /* Chars. per symbol (JLH: change from 8) */
79 #define HUGE 1000 /* A huge number */
80 #define NERR 3 /* Errors per line */
81 #define NINPUT 128 /* Input buffer size */
82 #define NCODE 128 /* Listing code buffer size */
83 #define NTITL 64 /* Title buffer size */
84 #define NSBTL 64 /* SubTitle buffer size */
85 #define NHASH 64 /* Buckets in hash table */
86 #define HMASK 077 /* Hash mask */
87 #define NLPP 60 /* Lines per page */
88 #define MAXFIL 6 /* Maximum command line input files */
89 #define MAXINC 6 /* Maximum nesting of include files */
90 #define MAXIF 10 /* Maximum nesting of if/else/endif */
91 #define FILSPC 80 /* Chars. in filespec */
93 #define NLIST 0 /* No listing */
94 #define SLIST 1 /* Source only */
95 #define ALIST 2 /* Address only */
96 #define BLIST 3 /* Address only with allocation */
97 #define CLIST 4 /* Code */
98 #define ELIST 5 /* Equate only */
100 #define dot sym[0] /* Dot, current loc */
101 #define dca area[0] /* Dca, default code area */
104 typedef unsigned int addr_t;
107 * The area structure contains the parameter values for a
108 * specific program or data section. The area structure
109 * is a linked list of areas. The initial default area
110 * is "_CODE" defined in asdata.c, the next area structure
111 * will be linked to this structure through the structure
112 * element 'struct area *a_ap'. The structure contains the
113 * area name, area reference number ("_CODE" is 0) determined
114 * by the order of .area directives, area size determined
115 * from the total code and/or data in an area, area fuzz is
116 * a variable used to track pass to pass changes in the
117 * area size caused by variable length instruction formats,
118 * and area flags which specify the area's relocation type.
122 struct area *a_ap; /* Area link */
123 char a_id[NCPS]; /* Area Name */
124 int a_ref; /* Ref. number */
125 addr_t a_size; /* Area size */
126 addr_t a_fuzz; /* Area fuzz */
127 int a_flag; /* Area flags */
131 * The "A_" area constants define values used in
132 * generating the assembler area output data.
137 * +-----+-----+-----+-----+-----+-----+-----+-----+
138 * | BIT |XDATA|DATA | PAG | ABS | OVR | | |
139 * +-----+-----+-----+-----+-----+-----+-----+-----+
142 #define A_CON 0000 /* Concatenating */
143 #define A_OVR 0004 /* Overlaying */
144 #define A_REL 0000 /* Relocatable */
145 #define A_ABS 0010 /* absolute */
146 #define A_NOPAG 0000 /* Non-Paged */
147 #define A_PAG 0020 /* Paged */
149 /* Additional flags for 8051 address spaces */
150 #define A_DATA 0000 /* data space (default)*/
151 #define A_CODE 0040 /* code space */
152 #define A_XDATA 0100 /* external data space */
153 #define A_BIT 0200 /* bit addressable space */
156 * The "R_" relocation constants define values used in
157 * generating the assembler relocation output data for
158 * areas, symbols, and code.
163 * +-----+-----+-----+-----+-----+-----+-----+-----+
164 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
165 * +-----+-----+-----+-----+-----+-----+-----+-----+
168 #define R_WORD 0000 /* 16 bit */
169 #define R_BYTE 0001 /* 8 bit */
171 #define R_AREA 0000 /* Base type */
174 #define R_NORM 0000 /* PC adjust */
177 #define R_BYT1 0000 /* Byte count for R_BYTE = 1 */
178 #define R_BYT2 0010 /* Byte count for R_BYTE = 2 */
180 #define R_SGND 0000 /* Signed Byte */
181 #define R_USGN 0020 /* Unsigned Byte */
183 #define R_NOPAG 0000 /* Page Mode */
184 #define R_PAG0 0040 /* Page '0' */
185 #define R_PAG 0100 /* Page 'nnn' */
187 #define R_LSB 0000 /* low byte */
188 #define R_MSB 0200 /* high byte */
190 #define R_J11 (R_WORD|R_BYT2) /* JLH: 11 bit JMP and CALL (8051) */
193 * Listing Control Flags
196 #define R_HIGH 0040000 /* High Byte */
197 #define R_RELOC 0100000 /* Relocation */
199 #define R_DEF 00 /* Global def. */
200 #define R_REF 01 /* Global ref. */
201 #define R_REL 00 /* Relocatable */
202 #define R_ABS 02 /* Absolute */
203 #define R_GBL 00 /* Global */
204 #define R_LCL 04 /* Local */
207 * The mne structure is a linked list of the assembler
208 * mnemonics and directives. The list of mnemonics and
209 * directives contained in the device dependent file
210 * xxxpst.c are hashed and linked into NHASH lists in
211 * module assym.c by syminit(). The structure contains
212 * the mnemonic/directive name, a subtype which directs
213 * the evaluation of this mnemonic/directive, a flag which
214 * is used to detect the end of the mnemonic/directive
215 * list in xxxpst.c, and a value which is normally
216 * associated with the assembler mnemonic base instruction
221 struct mne *m_mp; /* Hash link */
222 char *m_id; /* Mnemonic JLH: change from [NCPS] */
223 char m_type; /* Mnemonic subtype */
224 char m_flag; /* Mnemonic flags */
225 addr_t m_valu; /* Value */
229 * The sym structure is a linked list of symbols defined
230 * in the assembler source files. The first symbol is "."
231 * defined in asdata.c. The entry 'struct tsym *s_tsym'
232 * links any temporary symbols following this symbol and
233 * preceeding the next normal symbol. The structure also
234 * contains the symbol's name, type (USER or NEW), flag
235 * (global, assigned, and multiply defined), a pointer
236 * to the area structure defining where the symbol is
237 * located, a reference number assigned by outgsd() in
238 * asout.c, and the symbols address relative to the base
239 * address of the area where the symbol is located.
243 struct sym *s_sp; /* Hash link */
244 struct tsym *s_tsym; /* Temporary symbol link */
245 char *s_id; /* Symbol: JLH change from [NCPS] */
246 char s_type; /* Symbol subtype */
247 char s_flag; /* Symbol flags */
248 struct area *s_area; /* Area line, 0 if absolute */
249 int s_ref; /* Ref. number */
250 addr_t s_addr; /* Address */
253 #define S_GBL 01 /* Global */
254 #define S_ASG 02 /* Assigned */
255 #define S_MDF 04 /* Mult. def */
256 #define S_END 010 /* End mark for pst. */
258 #define S_NEW 0 /* New name */
259 #define S_USER 1 /* User name */
264 #define S_BYTE 5 /* .byte */
265 #define S_WORD 6 /* .word */
266 #define S_ASCII 7 /* .ascii */
267 #define S_ASCIZ 8 /* .asciz */
268 #define S_BLK 9 /* .blkb or .blkw */
269 #define S_INCL 10 /* .include */
270 #define S_DAREA 11 /* .area */
271 #define S_ATYP 12 /* .area type */
272 #define S_AREA 13 /* .area name */
273 #define S_GLOBL 14 /* .globl */
274 #define S_PAGE 15 /* .page */
275 #define S_TITLE 16 /* .title */
276 #define S_SBTL 17 /* .sbttl */
277 #define S_IF 18 /* .if */
278 #define S_ELSE 19 /* .else */
279 #define S_ENDIF 20 /* .endif */
280 #define S_EVEN 21 /* .even */
281 #define S_ODD 22 /* .odd */
282 #define S_RADIX 23 /* .radix */
283 #define S_ORG 24 /* .org */
284 #define S_MODUL 25 /* .module */
285 #define S_ASCIS 26 /* .ascis */
289 * The tsym structure is a linked list of temporary
290 * symbols defined in the assembler source files following
291 * a normal symbol. The structure contains the temporary
292 * symbols number, a flag (multiply defined), a pointer to the
293 * area structure defining where the temporary structure
294 * is located, and the temporary symbol's address relative
295 * to the base address of the area where the symbol
300 struct tsym *t_lnk; /* Link to next */
301 /* sandeep changed to 'int' from 'char' */
302 /* this will increase the number temp symbols
303 that can be defined from 255 to INT_MAX */
304 int t_num; /* 0-INT_MAX$ */
305 int t_flg; /* flags */
307 struct area *t_area; /* Area */
308 addr_t t_addr; /* Address */
312 * External Definitions for all Global Variables
315 extern int aserr; /* ASxxxx error counter
317 extern jmp_buf jump_env; /* compiler dependent structure
318 * used by setjmp() and longjmp()
320 extern int inpfil; /* count of assembler
321 * input files specified
323 extern int incfil; /* current file handle index
326 extern int cfile; /* current file handle index
327 * of input assembly files
329 extern int flevel; /* IF-ELSE-ENDIF flag will be non
330 * zero for false conditional case
332 extern int tlevel; /* current conditional level
334 extern int ifcnd[MAXIF+1]; /* array of IF statement condition
335 * values (0 = FALSE) indexed by tlevel
337 extern int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel
338 * values indexed by tlevel
341 afn[FILSPC]; /* afile() temporary filespec
344 srcfn[MAXFIL][FILSPC]; /* array of source file names
347 srcline[MAXFIL]; /* current source file line
350 incfn[MAXINC][FILSPC]; /* array of include file names
353 incline[MAXINC]; /* current include file line
355 extern int radix; /* current number conversion radix:
356 * 2 (binary), 8 (octal), 10 (decimal),
359 extern int line; /* current assembler source
362 extern int page; /* current page number
364 extern int lop; /* current line number on page
366 extern int pass; /* assembler pass number
368 extern int lflag; /* -l, generate listing flag
370 extern int cflag; /* -c, generate sdcdb debug information
372 extern int gflag; /* -g, make undefined symbols global flag
374 extern int aflag; /* -a, make all symbols global flag
376 extern int jflag; /* -j, generate debug information flag
378 extern int oflag; /* -o, generate relocatable output flag
380 extern int sflag; /* -s, generate symbol table flag
382 extern int pflag; /* -p, enable listing pagination
384 extern int xflag; /* -x, listing radix flag
386 extern int fflag; /* -f(f), relocations flagged flag
388 extern addr_t laddr; /* address of current assembler line
389 * or value of .if argument
391 extern addr_t fuzz; /* tracks pass to pass changes in the
392 * address of symbols caused by
393 * variable length instruction formats
395 extern int lmode; /* listing mode
397 extern struct area area[]; /* array of 1 area
399 extern struct area *areap; /* pointer to an area structure
401 extern struct sym sym[]; /* array of 1 symbol
403 extern struct sym *symp; /* pointer to a symbol structure
405 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
406 * linked symbol lists
408 extern struct mne *mnehash[NHASH]; /* array of pointers to NHASH
409 * linked mnemonic/directive lists
411 extern char *ep; /* pointer into error list
414 extern char eb[NERR]; /* array of generated error codes
416 extern char *ip; /* pointer into the assembler-source
419 extern char ib[NINPUT]; /* assembler-source text line
421 extern char *cp; /* pointer to assembler output
424 extern char cb[NCODE]; /* array of assembler output values
426 extern int *cpt; /* pointer to assembler relocation type
429 extern int cbt[NCODE]; /* array of assembler relocation types
430 * describing the data in cb[]
432 extern char tb[NTITL]; /* Title string buffer
434 extern char stb[NSBTL]; /* Subtitle string buffer
436 extern char symtbl[]; /* string "Symbol Table"
438 extern char aretbl[]; /* string "Area Table"
440 extern char module[NCPS]; /* module name string
442 extern FILE *lfp; /* list output file handle
444 extern FILE *ofp; /* relocation output file handle
446 extern FILE *tfp; /* symbol table output file handle
448 extern FILE *sfp[MAXFIL]; /* array of assembler-source file handles
450 extern FILE *ifp[MAXINC]; /* array of include-file file handles
452 extern char ctype[128]; /* array of character types, one per
456 extern char ccase[128]; /* an array of characters which
457 * perform the case translation function
460 * Definitions for Character Types
473 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
474 #define DGT8 DIGIT|RAD16|RAD10|RAD8
475 #define DGT10 DIGIT|RAD16|RAD10
476 #define LTR16 LETTER|RAD16
479 * The exp structure is used to return the evaluation
480 * of an expression. The structure supports three valid
482 * (1) The expression evaluates to a constant,
483 * mode = S_USER, flag = 0, addr contains the
484 * constant, and base = NULL.
485 * (2) The expression evaluates to a defined symbol
486 * plus or minus a constant, mode = S_USER,
487 * flag = 0, addr contains the constant, and
488 * base = pointer to area symbol.
489 * (3) The expression evaluates to a external
490 * global symbol plus or minus a constant,
491 * mode = S_NEW, flag = 1, addr contains the
492 * constant, and base = pointer to symbol.
496 char e_mode; /* Address mode */
497 char e_flag; /* Symbol flag */
498 addr_t e_addr; /* Address */
502 } e_base; /* Rel. base */
503 char e_rlcf; /* Rel. flags */
506 /* C Library functions */
507 /* for reference only
510 extern char * fgets();
511 extern FILE * fopen();
512 extern int fprintf();
513 extern VOID longjmp();
514 extern VOID * malloc();
520 extern char * strcpy();
522 extern char * strncpy();
525 /* Machine independent functions */
528 extern FILE * afile();
529 extern VOID asexit();
532 extern VOID newdot();
537 extern char endline();
540 extern int getline();
548 extern struct area * alookup();
549 extern struct mne * mlookup();
551 extern struct sym * lookup();
554 extern VOID syminit();
555 extern VOID symglob();
556 extern VOID allglob();
562 extern char * geterr();
567 extern VOID abscheck();
568 extern addr_t absexpr();
569 extern VOID clrexpr();
580 extern VOID lstsym();
588 extern VOID outarea();
590 extern VOID outall();
591 extern VOID outdot();
592 extern VOID outbuf();
593 extern VOID outchk();
594 extern VOID outgsd();
597 extern VOID outsym();
598 extern VOID out_lb();
599 extern VOID out_lw();
600 extern VOID out_rw();
601 extern VOID out_tw();
602 extern VOID outr11(); /* JLH */
605 extern char *StoreString( char *str );
608 extern void DefineNoICE_Line();
609 extern void DefineCDB_Line();
611 /* Machine dependent variables */
616 extern struct mne mne[];
618 /* Machine dependent functions */
620 extern VOID machin();
623 /* SD added THIS define to change
624 strcmpi --> strcmp (strcmpi is NOT ANSI) */
625 #define strcmpi strcmp