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"
32 #if !defined(__BORLANDC__) && !defined(_MSC_VER)
37 * Case Sensitivity Flag
39 #define CASE_SENSITIVE 1
43 * The module asm.h contains the definitions for constants,
44 * structures, global variables, and ASxxxx functions
45 * contained in the ASxxxx.c files. The two functions
46 * and three global variables from the machine dependent
47 * files are also defined.
51 * compiler/operating system specific definitions
54 /* DECUS C void definition */
55 /* File/extension seperator */
62 /* PDOS C void definition */
63 /* File/extension seperator */
70 /* Default void definition */
71 /* File/extension seperator */
83 #ifndef PATH_MAX /* POSIX, but not required */
84 #if defined(_MSC_VER) || defined(__BORLANDC__) /* Microsoft C or Borland C*/
86 #define PATH_MAX _MAX_PATH
88 #define PATH_MAX /* define a reasonable value */
93 * Assembler definitions.
95 #define LFTERM '(' /* Left expression delimeter */
96 #define RTTERM ')' /* Right expression delimeter */
98 #define NCPS 80 /* Chars. per symbol (JLH: change from 8) */
99 #define HUGE 1000 /* A huge number */
100 #define NERR 3 /* Errors per line */
101 #define NINPUT 1024 /* Input buffer size (icodes need space) */
102 #define NCODE 128 /* Listing code buffer size */
103 #define NTITL 64 /* Title buffer size */
104 #define NSBTL 64 /* SubTitle buffer size */
105 #define NHASH 64 /* Buckets in hash table */
106 #define HMASK 077 /* Hash mask */
107 #define NLPP 60 /* Lines per page */
108 #define MAXFIL 6 /* Maximum command line input files */
109 #define MAXINC 6 /* Maximum nesting of include files */
110 #define MAXIF 10 /* Maximum nesting of if/else/endif */
112 #define NLIST 0 /* No listing */
113 #define SLIST 1 /* Source only */
114 #define ALIST 2 /* Address only */
115 #define BLIST 3 /* Address only with allocation */
116 #define CLIST 4 /* Code */
117 #define ELIST 5 /* Equate only */
119 #define dot sym[0] /* Dot, current loc */
120 #define dca area[0] /* Dca, default code area */
123 /* NB: for Flat24 extentions to work, Addr_T must be at least 24
124 * bits. This is checked at runtime when the .flat24 directive
127 typedef unsigned int Addr_T;
130 * The area structure contains the parameter values for a
131 * specific program or data section. The area structure
132 * is a linked list of areas. The initial default area
133 * is "_CODE" defined in asdata.c, the next area structure
134 * will be linked to this structure through the structure
135 * element 'struct area *a_ap'. The structure contains the
136 * area name, area reference number ("_CODE" is 0) determined
137 * by the order of .area directives, area size determined
138 * from the total code and/or data in an area, area fuzz is
139 * a variable used to track pass to pass changes in the
140 * area size caused by variable length instruction formats,
141 * and area flags which specify the area's relocation type.
145 struct area *a_ap; /* Area link */
146 char a_id[NCPS]; /* Area Name */
147 int a_ref; /* Ref. number */
148 Addr_T a_addr; /* Area address */
149 Addr_T a_size; /* Area size */
150 Addr_T a_fuzz; /* Area fuzz */
151 int a_flag; /* Area flags */
155 * The "A_" area constants define values used in
156 * generating the assembler area output data.
161 * +-----+-----+-----+-----+-----+-----+-----+-----+
162 * | BIT |XDATA|DATA | PAG | ABS | OVR | | |
163 * +-----+-----+-----+-----+-----+-----+-----+-----+
166 #define A_CON 0000 /* Concatenating */
167 #define A_OVR 0004 /* Overlaying */
168 #define A_REL 0000 /* Relocatable */
169 #define A_ABS 0010 /* absolute */
170 #define A_NOPAG 0000 /* Non-Paged */
171 #define A_PAG 0020 /* Paged */
173 /* Additional flags for 8051 address spaces */
174 #define A_DATA 0000 /* data space (default)*/
175 #define A_CODE 0040 /* code space */
176 #define A_XDATA 0100 /* external data space */
177 #define A_BIT 0200 /* bit addressable space */
179 #define A_NOLOAD 0400 /* nonloadable */
180 #define A_LOAD 0000 /* loadable (default) */
183 * The "R_" relocation constants define values used in
184 * generating the assembler relocation output data for
185 * areas, symbols, and code.
190 * +-----+-----+-----+-----+-----+-----+-----+-----+
191 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
192 * +-----+-----+-----+-----+-----+-----+-----+-----+
195 #define R_WORD 0x00 /* 16 bit */
196 #define R_BYTE 0x01 /* 8 bit */
198 #define R_AREA 0x00 /* Base type */
201 #define R_NORM 0x00 /* PC adjust */
204 #define R_BYT1 0x00 /* Byte count for R_BYTE = 1 */
205 #define R_BYT2 0x08 /* Byte count for R_BYTE = 2 */
207 #define R_SGND 0x00 /* Signed Byte */
208 #define R_USGN 0x10 /* Unsigned Byte */
210 #define R_NOPAG 0x00 /* Page Mode */
211 #define R_PAG0 0x20 /* Page '0' */
212 #define R_PAG 0x40 /* Page 'nnn' */
214 #define R_LSB 0x00 /* low byte */
215 #define R_MSB 0x80 /* high byte */
217 #define R_BYT3 0x100 /* if R_BYTE is set, this is a
218 * 3 byte address, of which
219 * the linker must select one byte.
221 #define R_HIB 0x200 /* If R_BYTE & R_BYT3 are set, linker
222 * will select byte 3 of the relocated
226 #define R_J11 (R_WORD|R_BYT2) /* JLH: 11 bit JMP and CALL (8051) */
227 #define R_J19 (R_WORD|R_BYT2|R_MSB) /* 19 bit JMP/CALL (DS80C390) */
228 #define R_C24 (R_WORD|R_BYT1|R_MSB) /* 24 bit address (DS80C390) */
229 #define R_J19_MASK (R_BYTE|R_BYT2|R_MSB)
231 #define IS_R_J19(x) (((x) & R_J19_MASK) == R_J19)
232 #define IS_R_J11(x) (((x) & R_J19_MASK) == R_J11)
233 #define IS_C24(x) (((x) & R_J19_MASK) == R_C24)
235 #define R_ESCAPE_MASK 0xf0 /* Used to escape relocation modes
236 * greater than 0xff in the .rel
241 * Listing Control Flags
244 #define R_HIGH 0040000 /* High Byte */
245 #define R_RELOC 0100000 /* Relocation */
247 #define R_DEF 00 /* Global def. */
248 #define R_REF 01 /* Global ref. */
249 #define R_REL 00 /* Relocatable */
250 #define R_ABS 02 /* Absolute */
251 #define R_GBL 00 /* Global */
252 #define R_LCL 04 /* Local */
255 * The mne structure is a linked list of the assembler
256 * mnemonics and directives. The list of mnemonics and
257 * directives contained in the device dependent file
258 * xxxpst.c are hashed and linked into NHASH lists in
259 * module assym.c by syminit(). The structure contains
260 * the mnemonic/directive name, a subtype which directs
261 * the evaluation of this mnemonic/directive, a flag which
262 * is used to detect the end of the mnemonic/directive
263 * list in xxxpst.c, and a value which is normally
264 * associated with the assembler mnemonic base instruction
269 struct mne *m_mp; /* Hash link */
270 char *m_id; /* Mnemonic JLH: change from [NCPS] */
271 char m_type; /* Mnemonic subtype */
272 char m_flag; /* Mnemonic flags */
273 Addr_T m_valu; /* Value */
277 * The sym structure is a linked list of symbols defined
278 * in the assembler source files. The first symbol is "."
279 * defined in asdata.c. The entry 'struct tsym *s_tsym'
280 * links any temporary symbols following this symbol and
281 * preceeding the next normal symbol. The structure also
282 * contains the symbol's name, type (USER or NEW), flag
283 * (global, assigned, and multiply defined), a pointer
284 * to the area structure defining where the symbol is
285 * located, a reference number assigned by outgsd() in
286 * asout.c, and the symbols address relative to the base
287 * address of the area where the symbol is located.
291 struct sym *s_sp; /* Hash link */
292 struct tsym *s_tsym; /* Temporary symbol link */
293 char *s_id; /* Symbol: JLH change from [NCPS] */
294 char s_type; /* Symbol subtype */
295 char s_flag; /* Symbol flags */
296 struct area *s_area; /* Area line, 0 if absolute */
297 int s_ref; /* Ref. number */
298 Addr_T s_addr; /* Address */
299 Addr_T s_org; /* Start Address if absolute */
302 #define S_GBL 01 /* Global */
303 #define S_ASG 02 /* Assigned */
304 #define S_MDF 04 /* Mult. def */
305 #define S_END 010 /* End mark for pst. */
307 #define S_NEW 0 /* New name */
308 #define S_USER 1 /* User name */
313 #define S_BYTE 5 /* .byte */
314 #define S_WORD 6 /* .word */
315 #define S_ASCII 7 /* .ascii */
316 #define S_ASCIZ 8 /* .asciz */
317 #define S_BLK 9 /* .blkb or .blkw */
318 #define S_INCL 10 /* .include */
319 #define S_DAREA 11 /* .area */
320 #define S_ATYP 12 /* .area type */
321 #define S_AREA 13 /* .area name */
322 #define S_GLOBL 14 /* .globl */
323 #define S_PAGE 15 /* .page */
324 #define S_TITLE 16 /* .title */
325 #define S_SBTL 17 /* .sbttl */
326 #define S_IF 18 /* .if */
327 #define S_ELSE 19 /* .else */
328 #define S_ENDIF 20 /* .endif */
329 #define S_EVEN 21 /* .even */
330 #define S_ODD 22 /* .odd */
331 #define S_RADIX 23 /* .radix */
332 #define S_ORG 24 /* .org */
333 #define S_MODUL 25 /* .module */
334 #define S_ASCIS 26 /* .ascis */
335 #define S_FLAT24 27 /* .flat24 */
336 #define S_OPTSDCC 28 /* .optsdcc */
337 #define S_ULEB128 29 /* .uleb128 */
338 #define S_SLEB128 30 /* .sleb128 */
341 * The tsym structure is a linked list of temporary
342 * symbols defined in the assembler source files following
343 * a normal symbol. The structure contains the temporary
344 * symbols number, a flag (multiply defined), a pointer to the
345 * area structure defining where the temporary structure
346 * is located, and the temporary symbol's address relative
347 * to the base address of the area where the symbol
352 struct tsym *t_lnk; /* Link to next */
353 /* sandeep changed to 'int' from 'char' */
354 /* this will increase the number temp symbols
355 that can be defined from 255 to INT_MAX */
356 int t_num; /* 0-INT_MAX$ */
357 int t_flg; /* flags */
359 struct area *t_area; /* Area */
360 Addr_T t_addr; /* Address */
364 * External Definitions for all Global Variables
367 extern int aserr; /* ASxxxx error counter
369 extern jmp_buf jump_env; /* compiler dependent structure
370 * used by setjmp() and longjmp()
372 extern int inpfil; /* count of assembler
373 * input files specified
375 extern int incfil; /* current file handle index
378 extern int cfile; /* current file handle index
379 * of input assembly files
381 extern int flevel; /* IF-ELSE-ENDIF flag will be non
382 * zero for false conditional case
384 extern int tlevel; /* current conditional level
386 extern int ifcnd[MAXIF+1]; /* array of IF statement condition
387 * values (0 = FALSE) indexed by tlevel
389 extern int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel
390 * values indexed by tlevel
393 afn[PATH_MAX]; /* afile() temporary filespec
396 srcfn[MAXFIL][PATH_MAX]; /* array of source file names
399 srcline[MAXFIL]; /* current source file line
402 incfn[MAXINC][PATH_MAX]; /* array of include file names
405 incline[MAXINC]; /* current include file line
407 extern int radix; /* current number conversion radix:
408 * 2 (binary), 8 (octal), 10 (decimal),
411 extern int line; /* current assembler source
414 extern int page; /* current page number
416 extern int lop; /* current line number on page
418 extern int pass; /* assembler pass number
420 extern int lflag; /* -l, generate listing flag
422 extern int cflag; /* -c, generate sdcdb debug information
424 extern int gflag; /* -g, make undefined symbols global flag
426 extern int aflag; /* -a, make all symbols global flag
428 extern int jflag; /* -j, generate debug information flag
430 extern int oflag; /* -o, generate relocatable output flag
432 extern int sflag; /* -s, generate symbol table flag
434 extern int pflag; /* -p, enable listing pagination
436 extern int xflag; /* -x, listing radix flag
438 extern int fflag; /* -f(f), relocations flagged flag
440 extern Addr_T laddr; /* address of current assembler line
441 * or value of .if argument
443 extern Addr_T fuzz; /* tracks pass to pass changes in the
444 * address of symbols caused by
445 * variable length instruction formats
447 extern int lmode; /* listing mode
449 extern struct area area[]; /* array of 1 area
451 extern struct area *areap; /* pointer to an area structure
453 extern struct sym sym[]; /* array of 1 symbol
455 extern struct sym *symp; /* pointer to a symbol structure
457 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
458 * linked symbol lists
460 extern struct mne *mnehash[NHASH]; /* array of pointers to NHASH
461 * linked mnemonic/directive lists
463 extern char *ep; /* pointer into error list
466 extern char eb[NERR]; /* array of generated error codes
468 extern char *ip; /* pointer into the assembler-source
471 extern char ib[NINPUT]; /* assembler-source text line
473 extern char *cp; /* pointer to assembler output
476 extern char cb[NCODE]; /* array of assembler output values
478 extern int *cpt; /* pointer to assembler relocation type
481 extern int cbt[NCODE]; /* array of assembler relocation types
482 * describing the data in cb[]
484 extern char tb[NTITL]; /* Title string buffer
486 extern char stb[NSBTL]; /* Subtitle string buffer
488 extern char optsdcc[NINPUT]; /* sdcc compile options
490 extern int flat24Mode; /* non-zero if we are using DS390 24 bit
491 * flat mode (via .flat24 directive).
493 extern char symtbl[]; /* string "Symbol Table"
495 extern char aretbl[]; /* string "Area Table"
497 extern char module[NCPS]; /* module name string
499 extern FILE *lfp; /* list output file handle
501 extern FILE *ofp; /* relocation output file handle
503 extern FILE *tfp; /* symbol table output file handle
505 extern FILE *sfp[MAXFIL]; /* array of assembler-source file handles
507 extern FILE *ifp[MAXINC]; /* array of include-file file handles
509 extern unsigned char ctype[128]; /* array of character types, one per
513 extern char ccase[128]; /* an array of characters which
514 * perform the case translation function
517 * Definitions for Character Types
530 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
531 #define DGT8 DIGIT|RAD16|RAD10|RAD8
532 #define DGT10 DIGIT|RAD16|RAD10
533 #define LTR16 LETTER|RAD16
536 * The exp structure is used to return the evaluation
537 * of an expression. The structure supports three valid
539 * (1) The expression evaluates to a constant,
540 * mode = S_USER, flag = 0, addr contains the
541 * constant, and base = NULL.
542 * (2) The expression evaluates to a defined symbol
543 * plus or minus a constant, mode = S_USER,
544 * flag = 0, addr contains the constant, and
545 * base = pointer to area symbol.
546 * (3) The expression evaluates to a external
547 * global symbol plus or minus a constant,
548 * mode = S_NEW, flag = 1, addr contains the
549 * constant, and base = pointer to symbol.
553 char e_mode; /* Address mode */
554 char e_flag; /* Symbol flag */
555 Addr_T e_addr; /* Address */
559 } e_base; /* Rel. base */
560 int e_rlcf; /* Rel. flags */
563 /* C Library functions */
564 /* for reference only
567 extern char * fgets();
568 extern FILE * fopen();
569 extern int fprintf();
570 extern VOID longjmp();
571 extern VOID * malloc();
577 extern char * strcpy();
579 extern char * strncpy();
582 /* Machine independent functions */
585 extern FILE * afile();
586 extern VOID asexit();
589 extern VOID newdot();
594 extern char endline();
597 extern int as_getline();
603 extern VOID chop_crlf();
606 extern struct area * alookup();
607 extern struct mne * mlookup();
609 extern struct sym * lookup();
612 extern VOID syminit();
613 extern VOID symglob();
614 extern VOID allglob();
620 extern VOID warnBanner(void);
621 extern char * geterr();
626 extern VOID abscheck();
627 extern Addr_T absexpr();
628 extern VOID clrexpr();
639 extern VOID lstsym();
645 extern int byte3(int);
648 extern VOID outarea();
650 extern VOID outall();
651 extern VOID outdot();
652 extern VOID outbuf();
653 extern VOID outchk();
654 extern VOID outgsd();
656 extern VOID outrw(struct expr *, int);
657 extern VOID outr24(struct expr *, int);
658 extern VOID outsym();
659 extern VOID out_lb();
660 extern VOID out_lw();
661 extern VOID out_l24(int, int);
662 extern VOID out_rw();
663 extern VOID out_tw();
664 extern VOID out_t24(int);
665 extern VOID outr11(); /* JLH */
666 extern VOID outr19(struct expr *, int, int);
667 extern VOID outdp(struct area *, struct expr *);
670 extern char *StoreString( char *str );
673 extern void DefineNoICE_Line();
674 extern void DefineCDB_Line();
676 /* Machine dependent variables */
681 extern struct mne mne[];
683 /* Machine dependent functions */
686 extern VOID machine(struct mne *);
689 extern int as_strcmpi(const char *s1, const char *s2);
690 extern int as_strncmpi(const char *s1, const char *s2, size_t n);