3 Copyright (C) 1989-1995 Alan R. Baldwin
4 721 Berkeley St., Kent, Ohio 44240
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 * - add proto for StoreString
22 * - change s_id from [NCPS] to pointer
23 * - change m_id from [NCPS] to pointer
26 * - add R_J11 for 8051 assembler
27 * - add outr11 prototype for 8051 assembler
28 * - always define "ccase"
30 * - add jflag for debug control
31 * - prototypes for DefineNoICE_Line
33 * - add memory space flags to a_flag for 8051
36 * - add DS80C390 flat mode support.
39 #define VERSION "V01.70 + NoICE + SDCC mods + Flat24 Feb-1999"
41 #if !defined(__BORLANDC__) && !defined(_MSC_VER)
46 * Case Sensitivity Flag
48 #define CASE_SENSITIVE 1
52 * The module asm.h contains the definitions for constants,
53 * structures, global variables, and ASxxxx functions
54 * contained in the ASxxxx.c files. The two functions
55 * and three global variables from the machine dependent
56 * files are also defined.
60 * compiler/operating system specific definitions
63 /* DECUS C void definition */
64 /* File/extension seperator */
71 /* PDOS C void definition */
72 /* File/extension seperator */
79 /* Default void definition */
80 /* File/extension seperator */
92 #ifndef PATH_MAX /* POSIX, but not required */
93 #if defined(_MSC_VER) || defined(__BORLANDC__) /* Microsoft C or Borland C*/
95 #define PATH_MAX _MAX_PATH
97 #define PATH_MAX /* define a reasonable value */
101 #ifdef _WIN32 /* WIN32 native */
103 # define NATIVE_WIN32 1
104 # ifdef __MINGW32__ /* GCC MINGW32 depends on configure */
105 # include "../../sdccconf.h"
107 # include "../../sdcc_vc.h"
108 # define PATH_MAX _MAX_PATH
111 #else /* Assume Un*x style system */
112 # include "../../sdccconf.h"
116 * Assembler definitions.
118 #define LFTERM '(' /* Left expression delimeter */
119 #define RTTERM ')' /* Right expression delimeter */
121 #define NCPS 80 /* Chars. per symbol (JLH: change from 8) */
122 #define HUGE 1000 /* A huge number */
123 #define NERR 3 /* Errors per line */
124 #define NINPUT 1024 /* Input buffer size (icodes need space) */
125 #define NCODE 128 /* Listing code buffer size */
126 #define NTITL 64 /* Title buffer size */
127 #define NSBTL 64 /* SubTitle buffer size */
128 #define NHASH 64 /* Buckets in hash table */
129 #define HMASK 077 /* Hash mask */
130 #define NLPP 60 /* Lines per page */
131 #define MAXFIL 6 /* Maximum command line input files */
132 #define MAXINC 6 /* Maximum nesting of include files */
133 #define MAXIF 10 /* Maximum nesting of if/else/endif */
135 #define NLIST 0 /* No listing */
136 #define SLIST 1 /* Source only */
137 #define ALIST 2 /* Address only */
138 #define BLIST 3 /* Address only with allocation */
139 #define CLIST 4 /* Code */
140 #define ELIST 5 /* Equate only */
142 #define dot sym[0] /* Dot, current loc */
143 #define dca area[0] /* Dca, default code area */
146 /* NB: for Flat24 extentions to work, Addr_T must be at least 24
147 * bits. This is checked at runtime when the .flat24 directive
150 typedef unsigned int Addr_T;
153 * The area structure contains the parameter values for a
154 * specific program or data section. The area structure
155 * is a linked list of areas. The initial default area
156 * is "_CODE" defined in asdata.c, the next area structure
157 * will be linked to this structure through the structure
158 * element 'struct area *a_ap'. The structure contains the
159 * area name, area reference number ("_CODE" is 0) determined
160 * by the order of .area directives, area size determined
161 * from the total code and/or data in an area, area fuzz is
162 * a variable used to track pass to pass changes in the
163 * area size caused by variable length instruction formats,
164 * and area flags which specify the area's relocation type.
168 struct area *a_ap; /* Area link */
169 char a_id[NCPS]; /* Area Name */
170 int a_ref; /* Ref. number */
171 Addr_T a_addr; /* Area address */
172 Addr_T a_size; /* Area size */
173 Addr_T a_fuzz; /* Area fuzz */
174 int a_flag; /* Area flags */
178 * The "A_" area constants define values used in
179 * generating the assembler area output data.
184 * +-----+-----+-----+-----+-----+-----+-----+-----+
185 * | BIT |XDATA|DATA | PAG | ABS | OVR | | |
186 * +-----+-----+-----+-----+-----+-----+-----+-----+
189 #define A_CON 0000 /* Concatenating */
190 #define A_OVR 0004 /* Overlaying */
191 #define A_REL 0000 /* Relocatable */
192 #define A_ABS 0010 /* absolute */
193 #define A_NOPAG 0000 /* Non-Paged */
194 #define A_PAG 0020 /* Paged */
196 /* Additional flags for 8051 address spaces */
197 #define A_DATA 0000 /* data space (default)*/
198 #define A_CODE 0040 /* code space */
199 #define A_XDATA 0100 /* external data space */
200 #define A_BIT 0200 /* bit addressable space */
203 * The "R_" relocation constants define values used in
204 * generating the assembler relocation output data for
205 * areas, symbols, and code.
210 * +-----+-----+-----+-----+-----+-----+-----+-----+
211 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
212 * +-----+-----+-----+-----+-----+-----+-----+-----+
215 #define R_WORD 0x00 /* 16 bit */
216 #define R_BYTE 0x01 /* 8 bit */
218 #define R_AREA 0x00 /* Base type */
221 #define R_NORM 0x00 /* PC adjust */
224 #define R_BYT1 0x00 /* Byte count for R_BYTE = 1 */
225 #define R_BYT2 0x08 /* Byte count for R_BYTE = 2 */
227 #define R_SGND 0x00 /* Signed Byte */
228 #define R_USGN 0x10 /* Unsigned Byte */
230 #define R_NOPAG 0x00 /* Page Mode */
231 #define R_PAG0 0x20 /* Page '0' */
232 #define R_PAG 0x40 /* Page 'nnn' */
234 #define R_LSB 0x00 /* low byte */
235 #define R_MSB 0x80 /* high byte */
237 #define R_BYT3 0x100 /* if R_BYTE is set, this is a
238 * 3 byte address, of which
239 * the linker must select one byte.
241 #define R_HIB 0x200 /* If R_BYTE & R_BYT3 are set, linker
242 * will select byte 3 of the relocated
246 #define R_BIT 0x400 /* Linker will convert from byte-addressable
247 * space to bit-addressable space.
250 #define R_J11 (R_WORD|R_BYT2) /* JLH: 11 bit JMP and CALL (8051) */
251 #define R_J19 (R_WORD|R_BYT2|R_MSB) /* 19 bit JMP/CALL (DS80C390) */
252 #define R_C24 (R_WORD|R_BYT1|R_MSB) /* 24 bit address (DS80C390) */
253 #define R_J19_MASK (R_BYTE|R_BYT2|R_MSB)
255 #define IS_R_J19(x) (((x) & R_J19_MASK) == R_J19)
256 #define IS_R_J11(x) (((x) & R_J19_MASK) == R_J11)
257 #define IS_C24(x) (((x) & R_J19_MASK) == R_C24)
259 #define R_ESCAPE_MASK 0xf0 /* Used to escape relocation modes
260 * greater than 0xff in the .rel
265 * Listing Control Flags
268 #define R_HIGH 0040000 /* High Byte */
269 #define R_RELOC 0100000 /* Relocation */
271 #define R_DEF 00 /* Global def. */
272 #define R_REF 01 /* Global ref. */
273 #define R_REL 00 /* Relocatable */
274 #define R_ABS 02 /* Absolute */
275 #define R_GBL 00 /* Global */
276 #define R_LCL 04 /* Local */
279 * The mne structure is a linked list of the assembler
280 * mnemonics and directives. The list of mnemonics and
281 * directives contained in the device dependent file
282 * xxxpst.c are hashed and linked into NHASH lists in
283 * module assym.c by syminit(). The structure contains
284 * the mnemonic/directive name, a subtype which directs
285 * the evaluation of this mnemonic/directive, a flag which
286 * is used to detect the end of the mnemonic/directive
287 * list in xxxpst.c, and a value which is normally
288 * associated with the assembler mnemonic base instruction
293 struct mne *m_mp; /* Hash link */
294 char *m_id; /* Mnemonic JLH: change from [NCPS] */
295 char m_type; /* Mnemonic subtype */
296 char m_flag; /* Mnemonic flags */
297 Addr_T m_valu; /* Value */
301 * The sym structure is a linked list of symbols defined
302 * in the assembler source files. The first symbol is "."
303 * defined in asdata.c. The entry 'struct tsym *s_tsym'
304 * links any temporary symbols following this symbol and
305 * preceeding the next normal symbol. The structure also
306 * contains the symbol's name, type (USER or NEW), flag
307 * (global, assigned, and multiply defined), a pointer
308 * to the area structure defining where the symbol is
309 * located, a reference number assigned by outgsd() in
310 * asout.c, and the symbols address relative to the base
311 * address of the area where the symbol is located.
315 struct sym *s_sp; /* Hash link */
316 struct tsym *s_tsym; /* Temporary symbol link */
317 char *s_id; /* Symbol: JLH change from [NCPS] */
318 char s_type; /* Symbol subtype */
319 char s_flag; /* Symbol flags */
320 struct area *s_area; /* Area line, 0 if absolute */
321 int s_ref; /* Ref. number */
322 Addr_T s_addr; /* Address */
323 Addr_T s_org; /* Start Address if absolute */
326 #define S_GBL 01 /* Global */
327 #define S_ASG 02 /* Assigned */
328 #define S_MDF 04 /* Mult. def */
329 #define S_END 010 /* End mark for pst. */
330 #define S_BIT 020 /* address of bit in byte memory */
332 #define S_NEW 0 /* New name */
333 #define S_USER 1 /* User name */
338 #define S_BYTE 5 /* .byte */
339 #define S_WORD 6 /* .word */
340 #define S_ASCII 7 /* .ascii */
341 #define S_ASCIZ 8 /* .asciz */
342 #define S_BLK 9 /* .blkb or .blkw */
343 #define S_INCL 10 /* .include */
344 #define S_DAREA 11 /* .area */
345 #define S_ATYP 12 /* .area type */
346 #define S_AREA 13 /* .area name */
347 #define S_GLOBL 14 /* .globl */
348 #define S_PAGE 15 /* .page */
349 #define S_TITLE 16 /* .title */
350 #define S_SBTL 17 /* .sbttl */
351 #define S_IF 18 /* .if */
352 #define S_ELSE 19 /* .else */
353 #define S_ENDIF 20 /* .endif */
354 #define S_EVEN 21 /* .even */
355 #define S_ODD 22 /* .odd */
356 #define S_RADIX 23 /* .radix */
357 #define S_ORG 24 /* .org */
358 #define S_MODUL 25 /* .module */
359 #define S_ASCIS 26 /* .ascis */
360 #define S_FLAT24 27 /* .flat24 */
361 #define S_OPTSDCC 28 /* .optsdcc */
364 * The tsym structure is a linked list of temporary
365 * symbols defined in the assembler source files following
366 * a normal symbol. The structure contains the temporary
367 * symbols number, a flag (multiply defined), a pointer to the
368 * area structure defining where the temporary structure
369 * is located, and the temporary symbol's address relative
370 * to the base address of the area where the symbol
375 struct tsym *t_lnk; /* Link to next */
376 /* sandeep changed to 'int' from 'char' */
377 /* this will increase the number temp symbols
378 that can be defined from 255 to INT_MAX */
379 int t_num; /* 0-INT_MAX$ */
380 int t_flg; /* flags */
382 struct area *t_area; /* Area */
383 Addr_T t_addr; /* Address */
387 * External Definitions for all Global Variables
390 extern int aserr; /* ASxxxx error counter
392 extern jmp_buf jump_env; /* compiler dependent structure
393 * used by setjmp() and longjmp()
395 extern int inpfil; /* count of assembler
396 * input files specified
398 extern int incfil; /* current file handle index
401 extern int cfile; /* current file handle index
402 * of input assembly files
404 extern int flevel; /* IF-ELSE-ENDIF flag will be non
405 * zero for false conditional case
407 extern int tlevel; /* current conditional level
409 extern int ifcnd[MAXIF+1]; /* array of IF statement condition
410 * values (0 = FALSE) indexed by tlevel
412 extern int iflvl[MAXIF+1]; /* array of IF-ELSE-ENDIF flevel
413 * values indexed by tlevel
416 afn[PATH_MAX]; /* afile() temporary filespec
419 srcfn[MAXFIL][PATH_MAX]; /* array of source file names
422 srcline[MAXFIL]; /* current source file line
425 incfn[MAXINC][PATH_MAX]; /* array of include file names
428 incline[MAXINC]; /* current include file line
430 extern int radix; /* current number conversion radix:
431 * 2 (binary), 8 (octal), 10 (decimal),
434 extern int line; /* current assembler source
437 extern int page; /* current page number
439 extern int lop; /* current line number on page
441 extern int pass; /* assembler pass number
443 extern int org_cnt; /* .org directive counter
445 extern int lflag; /* -l, generate listing flag
447 extern int cflag; /* -c, generate sdcdb debug information
449 extern int gflag; /* -g, make undefined symbols global flag
451 extern int aflag; /* -a, make all symbols global flag
453 extern int jflag; /* -j, generate debug information flag
455 extern int oflag; /* -o, generate relocatable output flag
457 extern int sflag; /* -s, generate symbol table flag
459 extern int pflag; /* -p, enable listing pagination
461 extern int xflag; /* -x, listing radix flag
463 extern int fflag; /* -f(f), relocations flagged flag
465 extern Addr_T laddr; /* address of current assembler line
466 * or value of .if argument
468 extern Addr_T fuzz; /* tracks pass to pass changes in the
469 * address of symbols caused by
470 * variable length instruction formats
472 extern int lmode; /* listing mode
474 extern struct area area[]; /* array of 1 area
476 extern struct area *areap; /* pointer to an area structure
478 extern struct sym sym[]; /* array of 1 symbol
480 extern struct sym *symp; /* pointer to a symbol structure
482 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
483 * linked symbol lists
485 extern struct mne *mnehash[NHASH]; /* array of pointers to NHASH
486 * linked mnemonic/directive lists
488 extern char *ep; /* pointer into error list
491 extern char eb[NERR]; /* array of generated error codes
493 extern const char *ip; /* pointer into the assembler-source
496 extern const char *ib; /* assembler-source text line
498 extern char *cp; /* pointer to assembler output
501 extern char cb[NCODE]; /* array of assembler output values
503 extern int *cpt; /* pointer to assembler relocation type
506 extern int cbt[NCODE]; /* array of assembler relocation types
507 * describing the data in cb[]
509 extern char tb[NTITL]; /* Title string buffer
511 extern char stb[NSBTL]; /* Subtitle string buffer
513 extern char optsdcc[NINPUT]; /* sdcc compile options
515 extern int flat24Mode; /* non-zero if we are using DS390 24 bit
516 * flat mode (via .flat24 directive).
518 extern char symtbl[]; /* string "Symbol Table"
520 extern char aretbl[]; /* string "Area Table"
522 extern char module[NCPS]; /* module name string
524 extern FILE *lfp; /* list output file handle
526 extern FILE *ofp; /* relocation output file handle
528 extern FILE *tfp; /* symbol table output file handle
530 extern FILE *sfp[MAXFIL]; /* array of assembler-source file handles
532 extern FILE *ifp[MAXINC]; /* array of include-file file handles
534 extern unsigned char ctype[128]; /* array of character types, one per
538 extern char ccase[128]; /* an array of characters which
539 * perform the case translation function
542 * Definitions for Character Types
555 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
556 #define DGT8 DIGIT|RAD16|RAD10|RAD8
557 #define DGT10 DIGIT|RAD16|RAD10
558 #define LTR16 LETTER|RAD16
561 * The exp structure is used to return the evaluation
562 * of an expression. The structure supports three valid
564 * (1) The expression evaluates to a constant,
565 * mode = S_USER, flag = 0, addr contains the
566 * constant, and base = NULL.
567 * (2) The expression evaluates to a defined symbol
568 * plus or minus a constant, mode = S_USER,
569 * flag = 0, addr contains the constant, and
570 * base = pointer to area symbol.
571 * (3) The expression evaluates to a external
572 * global symbol plus or minus a constant,
573 * mode = S_NEW, flag = 1, addr contains the
574 * constant, and base = pointer to symbol.
578 char e_mode; /* Address mode */
579 char e_flag; /* Symbol flag */
580 Addr_T e_addr; /* Address */
584 } e_base; /* Rel. base */
585 int e_rlcf; /* Rel. flags */
588 /* C Library functions */
589 /* for reference only
592 extern char * fgets();
593 extern FILE * fopen();
594 extern int fprintf();
595 extern VOID longjmp();
596 extern VOID * malloc();
602 extern char * strcpy();
604 extern char * strncpy();
607 /* Machine independent functions */
610 extern FILE * afile();
611 extern VOID asexit();
614 extern VOID newdot();
619 extern char endline();
622 extern int as_getline();
628 extern VOID chop_crlf();
631 extern struct area * alookup();
632 extern struct mne * mlookup();
634 extern struct sym * lookup();
636 extern char * strsto(char *str);
638 extern VOID syminit();
639 extern VOID symglob();
640 extern VOID allglob();
646 extern VOID warnBanner(void);
647 extern char * geterr();
652 extern VOID abscheck();
653 extern Addr_T absexpr();
654 extern VOID clrexpr();
665 extern VOID lstsym();
671 extern int byte3(int);
674 extern VOID outarea();
676 extern VOID outall();
677 extern VOID outdot();
678 extern VOID outbuf();
679 extern VOID outchk();
680 extern VOID outgsd();
682 extern VOID outrw(struct expr *, int);
683 extern VOID outr24(struct expr *, int);
684 extern VOID outsym();
685 extern VOID out_lb();
686 extern VOID out_lw();
687 extern VOID out_l24(int, int);
688 extern VOID out_rw();
689 extern VOID out_tw();
690 extern VOID out_t24(int);
691 extern VOID outr11(); /* JLH */
692 extern VOID outr19(struct expr *, int, int);
695 extern void DefineNoICE_Line();
696 extern void DefineCDB_Line();
698 /* Machine dependent variables */
703 extern struct mne mne[];
705 /* Machine dependent functions */
708 extern VOID machine(struct mne *);
711 extern int as_strcmpi(const char *s1, const char *s2);
712 extern int as_strncmpi(const char *s1, const char *s2, size_t n);