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 */
92 #ifdef _WIN32 /* WIN32 native */
94 # define NATIVE_WIN32 1
95 # ifdef __MINGW32__ /* GCC MINGW32 depends on configure */
96 # include "../../sdccconf.h"
98 # include "../../sdcc_vc.h"
99 # define PATH_MAX _MAX_PATH
102 #else /* Assume Un*x style system */
103 # include "../../sdccconf.h"
107 * Assembler definitions.
109 #define LFTERM '(' /* Left expression delimeter */
110 #define RTTERM ')' /* Right expression delimeter */
112 #define NCPS 80 /* Chars. per symbol (JLH: change from 8) */
113 #define HUGE 1000 /* A huge number */
114 #define NERR 3 /* Errors per line */
115 #define NINPUT 1024 /* Input buffer size (icodes need space) */
116 #define NCODE 128 /* Listing code buffer size */
117 #define NTITL 64 /* Title buffer size */
118 #define NSBTL 64 /* SubTitle buffer size */
119 #define NHASH 64 /* Buckets in hash table */
120 #define HMASK 077 /* Hash mask */
121 #define NLPP 60 /* Lines per page */
122 #define MAXFIL 6 /* Maximum command line input files */
123 #define MAXINC 6 /* Maximum nesting of include files */
124 #define MAXIF 10 /* Maximum nesting of if/else/endif */
126 #define NLIST 0 /* No listing */
127 #define SLIST 1 /* Source only */
128 #define ALIST 2 /* Address only */
129 #define BLIST 3 /* Address only with allocation */
130 #define CLIST 4 /* Code */
131 #define ELIST 5 /* Equate only */
133 #define dot sym[0] /* Dot, current loc */
134 #define dca area[0] /* Dca, default code area */
137 /* NB: for Flat24 extentions to work, Addr_T must be at least 24
138 * bits. This is checked at runtime when the .flat24 directive
141 typedef unsigned int Addr_T;
144 * The area structure contains the parameter values for a
145 * specific program or data section. The area structure
146 * is a linked list of areas. The initial default area
147 * is "_CODE" defined in asdata.c, the next area structure
148 * will be linked to this structure through the structure
149 * element 'struct area *a_ap'. The structure contains the
150 * area name, area reference number ("_CODE" is 0) determined
151 * by the order of .area directives, area size determined
152 * from the total code and/or data in an area, area fuzz is
153 * a variable used to track pass to pass changes in the
154 * area size caused by variable length instruction formats,
155 * and area flags which specify the area's relocation type.
159 struct area *a_ap; /* Area link */
160 char a_id[NCPS]; /* Area Name */
161 int a_ref; /* Ref. number */
162 Addr_T a_addr; /* Area address */
163 Addr_T a_size; /* Area size */
164 Addr_T a_fuzz; /* Area fuzz */
165 int a_flag; /* Area flags */
169 * The "A_" area constants define values used in
170 * generating the assembler area output data.
175 * +-----+-----+-----+-----+-----+-----+-----+-----+
176 * | BIT |XDATA|DATA | PAG | ABS | OVR | | |
177 * +-----+-----+-----+-----+-----+-----+-----+-----+
180 #define A_CON 0000 /* Concatenating */
181 #define A_OVR 0004 /* Overlaying */
182 #define A_REL 0000 /* Relocatable */
183 #define A_ABS 0010 /* absolute */
184 #define A_NOPAG 0000 /* Non-Paged */
185 #define A_PAG 0020 /* Paged */
187 /* Additional flags for 8051 address spaces */
188 #define A_DATA 0000 /* data space (default)*/
189 #define A_CODE 0040 /* code space */
190 #define A_XDATA 0100 /* external data space */
191 #define A_BIT 0200 /* bit addressable space */
194 * The "R_" relocation constants define values used in
195 * generating the assembler relocation output data for
196 * areas, symbols, and code.
201 * +-----+-----+-----+-----+-----+-----+-----+-----+
202 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
203 * +-----+-----+-----+-----+-----+-----+-----+-----+
206 #define R_WORD 0x00 /* 16 bit */
207 #define R_BYTE 0x01 /* 8 bit */
209 #define R_AREA 0x00 /* Base type */
212 #define R_NORM 0x00 /* PC adjust */
215 #define R_BYT1 0x00 /* Byte count for R_BYTE = 1 */
216 #define R_BYT2 0x08 /* Byte count for R_BYTE = 2 */
218 #define R_SGND 0x00 /* Signed Byte */
219 #define R_USGN 0x10 /* Unsigned Byte */
221 #define R_NOPAG 0x00 /* Page Mode */
222 #define R_PAG0 0x20 /* Page '0' */
223 #define R_PAG 0x40 /* Page 'nnn' */
225 #define R_LSB 0x00 /* low byte */
226 #define R_MSB 0x80 /* high byte */
228 #define R_BYT3 0x100 /* if R_BYTE is set, this is a
229 * 3 byte address, of which
230 * the linker must select one byte.
232 #define R_HIB 0x200 /* If R_BYTE & R_BYT3 are set, linker
233 * will select byte 3 of the relocated
237 #define R_BIT 0x400 /* Linker will convert from byte-addressable
238 * space to bit-addressable space.
241 #define R_J11 (R_WORD|R_BYT2) /* JLH: 11 bit JMP and CALL (8051) */
242 #define R_J19 (R_WORD|R_BYT2|R_MSB) /* 19 bit JMP/CALL (DS80C390) */
243 #define R_C24 (R_WORD|R_BYT1|R_MSB) /* 24 bit address (DS80C390) */
244 #define R_J19_MASK (R_BYTE|R_BYT2|R_MSB)
246 #define IS_R_J19(x) (((x) & R_J19_MASK) == R_J19)
247 #define IS_R_J11(x) (((x) & R_J19_MASK) == R_J11)
248 #define IS_C24(x) (((x) & R_J19_MASK) == R_C24)
250 #define R_ESCAPE_MASK 0xf0 /* Used to escape relocation modes
251 * greater than 0xff in the .rel
256 * Listing Control Flags
259 #define R_HIGH 0040000 /* High Byte */
260 #define R_RELOC 0100000 /* Relocation */
262 #define R_DEF 00 /* Global def. */
263 #define R_REF 01 /* Global ref. */
264 #define R_REL 00 /* Relocatable */
265 #define R_ABS 02 /* Absolute */
266 #define R_GBL 00 /* Global */
267 #define R_LCL 04 /* Local */
270 * The mne structure is a linked list of the assembler
271 * mnemonics and directives. The list of mnemonics and
272 * directives contained in the device dependent file
273 * xxxpst.c are hashed and linked into NHASH lists in
274 * module assym.c by syminit(). The structure contains
275 * the mnemonic/directive name, a subtype which directs
276 * the evaluation of this mnemonic/directive, a flag which
277 * is used to detect the end of the mnemonic/directive
278 * list in xxxpst.c, and a value which is normally
279 * associated with the assembler mnemonic base instruction
284 struct mne *m_mp; /* Hash link */
285 char *m_id; /* Mnemonic JLH: change from [NCPS] */
286 char m_type; /* Mnemonic subtype */
287 char m_flag; /* Mnemonic flags */
288 Addr_T m_valu; /* Value */
292 * The sym structure is a linked list of symbols defined
293 * in the assembler source files. The first symbol is "."
294 * defined in asdata.c. The entry 'struct tsym *s_tsym'
295 * links any temporary symbols following this symbol and
296 * preceeding the next normal symbol. The structure also
297 * contains the symbol's name, type (USER or NEW), flag
298 * (global, assigned, and multiply defined), a pointer
299 * to the area structure defining where the symbol is
300 * located, a reference number assigned by outgsd() in
301 * asout.c, and the symbols address relative to the base
302 * address of the area where the symbol is located.
306 struct sym *s_sp; /* Hash link */
307 struct tsym *s_tsym; /* Temporary symbol link */
308 char *s_id; /* Symbol: JLH change from [NCPS] */
309 char s_type; /* Symbol subtype */
310 char s_flag; /* Symbol flags */
311 struct area *s_area; /* Area line, 0 if absolute */
312 int s_ref; /* Ref. number */
313 Addr_T s_addr; /* Address */
314 Addr_T s_org; /* Start Address if absolute */
317 #define S_GBL 01 /* Global */
318 #define S_ASG 02 /* Assigned */
319 #define S_MDF 04 /* Mult. def */
320 #define S_END 010 /* End mark for pst. */
321 #define S_BIT 020 /* address of bit in byte memory */
323 #define S_NEW 0 /* New name */
324 #define S_USER 1 /* User name */
329 #define S_BYTE 5 /* .byte */
330 #define S_WORD 6 /* .word */
331 #define S_ASCII 7 /* .ascii */
332 #define S_ASCIZ 8 /* .asciz */
333 #define S_BLK 9 /* .blkb or .blkw */
334 #define S_INCL 10 /* .include */
335 #define S_DAREA 11 /* .area */
336 #define S_ATYP 12 /* .area type */
337 #define S_AREA 13 /* .area name */
338 #define S_GLOBL 14 /* .globl */
339 #define S_PAGE 15 /* .page */
340 #define S_TITLE 16 /* .title */
341 #define S_SBTL 17 /* .sbttl */
342 #define S_IF 18 /* .if */
343 #define S_ELSE 19 /* .else */
344 #define S_ENDIF 20 /* .endif */
345 #define S_EVEN 21 /* .even */
346 #define S_ODD 22 /* .odd */
347 #define S_RADIX 23 /* .radix */
348 #define S_ORG 24 /* .org */
349 #define S_MODUL 25 /* .module */
350 #define S_ASCIS 26 /* .ascis */
351 #define S_FLAT24 27 /* .flat24 */
352 #define S_OPTSDCC 28 /* .optsdcc */
356 * The tsym structure is a linked list of temporary
357 * symbols defined in the assembler source files following
358 * a normal symbol. The structure contains the temporary
359 * symbols number, a flag (multiply defined), a pointer to the
360 * area structure defining where the temporary structure
361 * is located, and the temporary symbol's address relative
362 * to the base address of the area where the symbol
367 struct tsym *t_lnk; /* Link to next */
368 /* sandeep changed to 'int' from 'char' */
369 /* this will increase the number temp symbols
370 that can be defined from 255 to INT_MAX */
371 int t_num; /* 0-INT_MAX$ */
372 int t_flg; /* flags */
374 struct area *t_area; /* Area */
375 Addr_T t_addr; /* Address */
379 * External Definitions for all Global Variables
382 extern int aserr; /* ASxxxx error counter
384 extern jmp_buf jump_env; /* compiler dependent structure
385 * used by setjmp() and longjmp()
387 extern int inpfil; /* count of assembler
388 * input files specified
390 extern int incfil; /* current file handle index
393 extern int cfile; /* current file handle index
394 * of input assembly files
396 extern int flevel; /* IF-ELSE-ENDIF flag will be non
397 * zero for false conditional case
399 extern int tlevel; /* current conditional level
401 extern int ifcnd[MAXIF+1]; /* array of IF statement condition
402 * values (0 = FALSE) indexed by tlevel
404 extern int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel
405 * values indexed by tlevel
408 afn[PATH_MAX]; /* afile() temporary filespec
411 srcfn[MAXFIL][PATH_MAX]; /* array of source file names
414 srcline[MAXFIL]; /* current source file line
417 incfn[MAXINC][PATH_MAX]; /* array of include file names
420 incline[MAXINC]; /* current include file line
422 extern int radix; /* current number conversion radix:
423 * 2 (binary), 8 (octal), 10 (decimal),
426 extern int line; /* current assembler source
429 extern int page; /* current page number
431 extern int lop; /* current line number on page
433 extern int pass; /* assembler pass number
435 extern int lflag; /* -l, generate listing flag
437 extern int cflag; /* -c, generate sdcdb debug information
439 extern int gflag; /* -g, make undefined symbols global flag
441 extern int aflag; /* -a, make all symbols global flag
443 extern int jflag; /* -j, generate debug information flag
445 extern int oflag; /* -o, generate relocatable output flag
447 extern int sflag; /* -s, generate symbol table flag
449 extern int pflag; /* -p, enable listing pagination
451 extern int xflag; /* -x, listing radix flag
453 extern int fflag; /* -f(f), relocations flagged flag
455 extern Addr_T laddr; /* address of current assembler line
456 * or value of .if argument
458 extern Addr_T fuzz; /* tracks pass to pass changes in the
459 * address of symbols caused by
460 * variable length instruction formats
462 extern int lmode; /* listing mode
464 extern struct area area[]; /* array of 1 area
466 extern struct area *areap; /* pointer to an area structure
468 extern struct sym sym[]; /* array of 1 symbol
470 extern struct sym *symp; /* pointer to a symbol structure
472 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
473 * linked symbol lists
475 extern struct mne *mnehash[NHASH]; /* array of pointers to NHASH
476 * linked mnemonic/directive lists
478 extern char *ep; /* pointer into error list
481 extern char eb[NERR]; /* array of generated error codes
483 extern char *ip; /* pointer into the assembler-source
486 extern char ib[NINPUT]; /* assembler-source text line
488 extern char *cp; /* pointer to assembler output
491 extern char cb[NCODE]; /* array of assembler output values
493 extern int *cpt; /* pointer to assembler relocation type
496 extern int cbt[NCODE]; /* array of assembler relocation types
497 * describing the data in cb[]
499 extern char tb[NTITL]; /* Title string buffer
501 extern char stb[NSBTL]; /* Subtitle string buffer
503 extern char optsdcc[NINPUT]; /* sdcc compile options
505 extern int flat24Mode; /* non-zero if we are using DS390 24 bit
506 * flat mode (via .flat24 directive).
508 extern char symtbl[]; /* string "Symbol Table"
510 extern char aretbl[]; /* string "Area Table"
512 extern char module[NCPS]; /* module name string
514 extern FILE *lfp; /* list output file handle
516 extern FILE *ofp; /* relocation output file handle
518 extern FILE *tfp; /* symbol table output file handle
520 extern FILE *sfp[MAXFIL]; /* array of assembler-source file handles
522 extern FILE *ifp[MAXINC]; /* array of include-file file handles
524 extern unsigned char ctype[128]; /* array of character types, one per
528 extern char ccase[128]; /* an array of characters which
529 * perform the case translation function
532 * Definitions for Character Types
545 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
546 #define DGT8 DIGIT|RAD16|RAD10|RAD8
547 #define DGT10 DIGIT|RAD16|RAD10
548 #define LTR16 LETTER|RAD16
551 * The exp structure is used to return the evaluation
552 * of an expression. The structure supports three valid
554 * (1) The expression evaluates to a constant,
555 * mode = S_USER, flag = 0, addr contains the
556 * constant, and base = NULL.
557 * (2) The expression evaluates to a defined symbol
558 * plus or minus a constant, mode = S_USER,
559 * flag = 0, addr contains the constant, and
560 * base = pointer to area symbol.
561 * (3) The expression evaluates to a external
562 * global symbol plus or minus a constant,
563 * mode = S_NEW, flag = 1, addr contains the
564 * constant, and base = pointer to symbol.
568 char e_mode; /* Address mode */
569 char e_flag; /* Symbol flag */
570 Addr_T e_addr; /* Address */
574 } e_base; /* Rel. base */
575 int e_rlcf; /* Rel. flags */
578 /* C Library functions */
579 /* for reference only
582 extern char * fgets();
583 extern FILE * fopen();
584 extern int fprintf();
585 extern VOID longjmp();
586 extern VOID * malloc();
592 extern char * strcpy();
594 extern char * strncpy();
597 /* Machine independent functions */
600 extern FILE * afile();
601 extern VOID asexit();
604 extern VOID newdot();
609 extern char endline();
612 extern int as_getline();
618 extern VOID chop_crlf();
621 extern struct area * alookup();
622 extern struct mne * mlookup();
624 extern struct sym * lookup();
627 extern VOID syminit();
628 extern VOID symglob();
629 extern VOID allglob();
635 extern VOID warnBanner(void);
636 extern char * geterr();
641 extern VOID abscheck();
642 extern Addr_T absexpr();
643 extern VOID clrexpr();
654 extern VOID lstsym();
660 extern int byte3(int);
663 extern VOID outarea();
665 extern VOID outall();
666 extern VOID outdot();
667 extern VOID outbuf();
668 extern VOID outchk();
669 extern VOID outgsd();
671 extern VOID outrw(struct expr *, int);
672 extern VOID outr24(struct expr *, int);
673 extern VOID outsym();
674 extern VOID out_lb();
675 extern VOID out_lw();
676 extern VOID out_l24(int, int);
677 extern VOID out_rw();
678 extern VOID out_tw();
679 extern VOID out_t24(int);
680 extern VOID outr11(); /* JLH */
681 extern VOID outr19(struct expr *, int, int);
684 extern char *StoreString( char *str );
687 extern void DefineNoICE_Line();
688 extern void DefineCDB_Line();
690 /* Machine dependent variables */
695 extern struct mne mne[];
697 /* Machine dependent functions */
700 extern VOID machine(struct mne *);
703 extern int as_strcmpi(const char *s1, const char *s2);
704 extern int as_strncmpi(const char *s1, const char *s2, size_t n);