Increased buffer size for regression tests:
[fw/sdcc] / as / mcs51 / asm.h
1 /* asm.h */
2
3 /*
4  * (C) Copyright 1989-1995
5  * All Rights Reserved
6  *
7  * Alan R. Baldwin
8  * 721 Berkeley St.
9  * Kent, Ohio  44240
10  *
11  * 28-Oct-97 JLH: 
12  *           - add proto for StoreString
13  *           - change s_id from [NCPS] to pointer
14  *           - change m_id from [NCPS] to pointer
15  *           - change NCPS to 80
16  *           - case sensitive
17  *           - add R_J11 for 8051 assembler
18  *           - add outr11 prototype for 8051 assembler
19  *           - always define "ccase"
20  *  2-Nov-97 JLH:
21  *           - add jflag for debug control
22  *           - prototypes for DefineNoICE_Line
23  * 30-Jan-98 JLH:
24  *           - add memory space flags to a_flag for 8051
25  *
26  *  3-Feb-00 KV:
27  *           - add DS80C390 flat mode support.
28  */
29
30 #define VERSION "V01.70 + NoICE + SDCC mods + Flat24 Feb-1999"
31
32 #if !defined(__BORLANDC__) && !defined(_MSC_VER)
33 #include <unistd.h>
34 #endif
35
36 /*
37  * Case Sensitivity Flag
38  */
39 #define CASE_SENSITIVE  1
40
41 /*)Module       asm.h
42  *
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.
48  */
49
50 /*
51  *       compiler/operating system specific definitions
52  */
53
54 /* DECUS C void definition */
55 /* File/extension seperator */
56
57 #ifdef  decus
58 #define VOID    char
59 #define FSEPX   '.'
60 #endif
61
62 /* PDOS C void definition */
63 /* File/extension seperator */
64
65 #ifdef  PDOS
66 #define VOID    char
67 #define FSEPX   ':'
68 #endif
69
70 /* Default void definition */
71 /* File/extension seperator */
72
73 #ifndef VOID
74 #define VOID    void
75 #define FSEPX   '.'
76 #define OTHERSYSTEM
77 #endif
78
79 /*
80  * Assembler definitions.
81  */
82 #define LFTERM  '('             /* Left expression delimeter */
83 #define RTTERM  ')'             /* Right expression delimeter */
84
85 #define NCPS    80              /* Chars. per symbol (JLH: change from 8) */
86 #define HUGE    1000            /* A huge number */
87 #define NERR    3               /* Errors per line */
88 #define NINPUT  FILENAME_MAX    /* Input buffer size (BH: change from 128) */
89 #define NCODE   128             /* Listing code buffer size */
90 #define NTITL   64              /* Title buffer size */
91 #define NSBTL   64              /* SubTitle buffer size */
92 #define NHASH   64              /* Buckets in hash table */
93 #define HMASK   077             /* Hash mask */
94 #define NLPP    60              /* Lines per page */
95 #define MAXFIL  6               /* Maximum command line input files */
96 #define MAXINC  6               /* Maximum nesting of include files */
97 #define MAXIF   10              /* Maximum nesting of if/else/endif */
98
99 #define NLIST   0               /* No listing */
100 #define SLIST   1               /* Source only */
101 #define ALIST   2               /* Address only */
102 #define BLIST   3               /* Address only with allocation */
103 #define CLIST   4               /* Code */
104 #define ELIST   5               /* Equate only */
105
106 #define dot     sym[0]          /* Dot, current loc */
107 #define dca     area[0]         /* Dca, default code area */
108
109
110 /* NB: for Flat24 extentions to work, Addr_T must be at least 24
111  * bits. This is checked at runtime when the .flat24 directive 
112  * is processed.
113  */
114 typedef unsigned int Addr_T;
115
116 /*
117  *      The area structure contains the parameter values for a
118  *      specific program or data section.  The area structure
119  *      is a linked list of areas.  The initial default area
120  *      is "_CODE" defined in asdata.c, the next area structure
121  *      will be linked to this structure through the structure
122  *      element 'struct area *a_ap'.  The structure contains the
123  *      area name, area reference number ("_CODE" is 0) determined
124  *      by the order of .area directives, area size determined
125  *      from the total code and/or data in an area, area fuzz is
126  *      a variable used to track pass to pass changes in the
127  *      area size caused by variable length instruction formats,
128  *      and area flags which specify the area's relocation type.
129  */
130 struct  area
131 {
132         struct  area *a_ap;     /* Area link */
133         char    a_id[NCPS];     /* Area Name */
134         int     a_ref;          /* Ref. number */
135         Addr_T  a_size;         /* Area size */
136         Addr_T  a_fuzz;         /* Area fuzz */
137         int     a_flag;         /* Area flags */
138 };
139
140 /*
141  *      The "A_" area constants define values used in
142  *      generating the assembler area output data.
143  *
144  * Area flags
145  *
146  *         7     6      5    4     3     2     1     0
147  *      +-----+-----+-----+-----+-----+-----+-----+-----+
148  *      | BIT |XDATA|DATA | PAG | ABS | OVR |     |     |
149  *      +-----+-----+-----+-----+-----+-----+-----+-----+
150  */
151
152 #define A_CON   0000            /* Concatenating */
153 #define A_OVR   0004            /* Overlaying */
154 #define A_REL   0000            /* Relocatable */
155 #define A_ABS   0010            /* absolute */
156 #define A_NOPAG 0000            /* Non-Paged */
157 #define A_PAG   0020            /* Paged */
158
159 /* Additional flags for 8051 address spaces */
160 #define A_DATA  0000            /* data space (default)*/
161 #define A_CODE  0040            /* code space */
162 #define A_XDATA 0100            /* external data space */
163 #define A_BIT   0200            /* bit addressable space */
164
165 /*
166  *      The "R_" relocation constants define values used in
167  *      generating the assembler relocation output data for
168  *      areas, symbols, and code.
169  *
170  * Relocation flags
171  *
172  *         7     6     5     4     3     2     1     0
173  *      +-----+-----+-----+-----+-----+-----+-----+-----+
174  *      | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
175  *      +-----+-----+-----+-----+-----+-----+-----+-----+
176  */
177
178 #define R_WORD  0x00            /* 16 bit */
179 #define R_BYTE  0x01            /*  8 bit */
180
181 #define R_AREA  0x00            /* Base type */
182 #define R_SYM   0x02
183
184 #define R_NORM  0x00            /* PC adjust */
185 #define R_PCR   0x04
186
187 #define R_BYT1  0x00            /* Byte count for R_BYTE = 1 */
188 #define R_BYT2  0x08            /* Byte count for R_BYTE = 2 */
189
190 #define R_SGND  0x00            /* Signed Byte */
191 #define R_USGN  0x10            /* Unsigned Byte */
192
193 #define R_NOPAG 0x00            /* Page Mode */
194 #define R_PAG0  0x20            /* Page '0' */
195 #define R_PAG   0x40            /* Page 'nnn' */
196
197 #define R_LSB   0x00            /* low byte */
198 #define R_MSB   0x80            /* high byte */
199
200 #define R_BYT3  0x100           /* if R_BYTE is set, this is a 
201                                  * 3 byte address, of which
202                                  * the linker must select one byte.
203                                  */
204 #define R_HIB   0x200           /* If R_BYTE & R_BYT3 are set, linker
205                                  * will select byte 3 of the relocated
206                                  * 24 bit address.
207                                  */
208
209 #define R_J11   (R_WORD|R_BYT2) /* JLH: 11 bit JMP and CALL (8051) */
210 #define R_J19   (R_WORD|R_BYT2|R_MSB) /* 19 bit JMP/CALL (DS80C390) */
211 #define R_C24   (R_WORD|R_BYT1|R_MSB) /* 24 bit address (DS80C390) */
212 #define R_J19_MASK (R_BYTE|R_BYT2|R_MSB)
213
214 #define IS_R_J19(x) (((x) & R_J19_MASK) == R_J19)
215 #define IS_R_J11(x) (((x) & R_J19_MASK) == R_J11)
216 #define IS_C24(x) (((x) & R_J19_MASK) == R_C24)
217
218 #define R_ESCAPE_MASK   0xf0    /* Used to escape relocation modes
219                                  * greater than 0xff in the .rel
220                                  * file.
221                                  */
222
223 /*
224  * Listing Control Flags
225  */
226
227 #define R_HIGH  0040000         /* High Byte */
228 #define R_RELOC 0100000         /* Relocation */
229
230 #define R_DEF   00              /* Global def. */
231 #define R_REF   01              /* Global ref. */
232 #define R_REL   00              /* Relocatable */
233 #define R_ABS   02              /* Absolute */
234 #define R_GBL   00              /* Global */
235 #define R_LCL   04              /* Local */
236
237 /*
238  *      The mne structure is a linked list of the assembler
239  *      mnemonics and directives.  The list of mnemonics and
240  *      directives contained in the device dependent file
241  *      xxxpst.c are hashed and linked into NHASH lists in
242  *      module assym.c by syminit().  The structure contains
243  *      the mnemonic/directive name, a subtype which directs
244  *      the evaluation of this mnemonic/directive, a flag which
245  *      is used to detect the end of the mnemonic/directive
246  *      list in xxxpst.c, and a value which is normally
247  *      associated with the assembler mnemonic base instruction
248  *      value.
249  */
250 struct  mne
251 {
252         struct  mne *m_mp;      /* Hash link */
253         char    *m_id;          /* Mnemonic JLH: change from [NCPS] */
254         char    m_type;         /* Mnemonic subtype */
255         char    m_flag;         /* Mnemonic flags */
256         Addr_T  m_valu;         /* Value */
257 };
258
259 /*
260  *      The sym structure is a linked list of symbols defined
261  *      in the assembler source files.  The first symbol is "."
262  *      defined in asdata.c.  The entry 'struct tsym *s_tsym'
263  *      links any temporary symbols following this symbol and
264  *      preceeding the next normal symbol.  The structure also
265  *      contains the symbol's name, type (USER or NEW), flag
266  *      (global, assigned, and multiply defined), a pointer
267  *      to the area structure defining where the symbol is
268  *      located, a reference number assigned by outgsd() in
269  *      asout.c, and the symbols address relative to the base
270  *      address of the area where the symbol is located.
271  */
272 struct  sym
273 {
274         struct  sym  *s_sp;     /* Hash link */
275         struct  tsym *s_tsym;   /* Temporary symbol link */
276         char    *s_id;          /* Symbol: JLH change from [NCPS] */
277         char    s_type;         /* Symbol subtype */
278         char    s_flag;         /* Symbol flags */
279         struct  area *s_area;   /* Area line, 0 if absolute */
280         int     s_ref;          /* Ref. number */
281         Addr_T  s_addr;         /* Address */
282 };
283
284 #define S_GBL           01      /* Global */
285 #define S_ASG           02      /* Assigned */
286 #define S_MDF           04      /* Mult. def */
287 #define S_END           010     /* End mark for pst. */
288
289 #define S_NEW           0       /* New name */
290 #define S_USER          1       /* User name */
291                                 /* unused slot */
292                                 /* unused slot */
293                                 /* unused slot */
294
295 #define S_BYTE          5       /* .byte */
296 #define S_WORD          6       /* .word */
297 #define S_ASCII         7       /* .ascii */
298 #define S_ASCIZ         8       /* .asciz */
299 #define S_BLK           9       /* .blkb or .blkw */
300 #define S_INCL          10      /* .include */
301 #define S_DAREA         11      /* .area */
302 #define S_ATYP          12      /* .area type */
303 #define S_AREA          13      /* .area name */
304 #define S_GLOBL         14      /* .globl */
305 #define S_PAGE          15      /* .page */
306 #define S_TITLE         16      /* .title */
307 #define S_SBTL          17      /* .sbttl */
308 #define S_IF            18      /* .if */
309 #define S_ELSE          19      /* .else */
310 #define S_ENDIF         20      /* .endif */
311 #define S_EVEN          21      /* .even */
312 #define S_ODD           22      /* .odd */
313 #define S_RADIX         23      /* .radix */
314 #define S_ORG           24      /* .org */
315 #define S_MODUL         25      /* .module */
316 #define S_ASCIS         26      /* .ascis */
317 #define S_FLAT24        27      /* .flat24 */
318
319
320 /*
321  *      The tsym structure is a linked list of temporary
322  *      symbols defined in the assembler source files following
323  *      a normal symbol.  The structure contains the temporary
324  *      symbols number, a flag (multiply defined), a pointer to the
325  *      area structure defining where the temporary structure
326  *      is located, and the temporary symbol's address relative
327  *      to the base address of the area where the symbol
328  *      is located.
329  */
330 struct  tsym
331 {
332         struct  tsym *t_lnk;    /* Link to next */
333 /* sandeep changed to 'int' from 'char' */
334 /* this will increase the number temp symbols
335    that can be defined from 255 to INT_MAX */
336         int t_num;              /* 0-INT_MAX$ */
337         int t_flg;              /* flags */
338
339         struct  area *t_area;   /* Area */
340         Addr_T  t_addr;         /* Address */
341 };
342
343 /*
344  *      External Definitions for all Global Variables
345  */
346
347 extern  int     aserr;          /*      ASxxxx error counter
348                                  */
349 extern  jmp_buf jump_env;       /*      compiler dependent structure
350                                  *      used by setjmp() and longjmp()
351                                  */
352 extern  int     inpfil;         /*      count of assembler
353                                  *      input files specified
354                                  */
355 extern  int     incfil;         /*      current file handle index
356                                  *      for include files
357                                  */
358 extern  int     cfile;          /*      current file handle index
359                                  *      of input assembly files
360                                  */
361 extern  int     flevel;         /*      IF-ELSE-ENDIF flag will be non
362                                  *      zero for false conditional case
363                                  */
364 extern  int     tlevel;         /*      current conditional level
365                                  */
366 extern  int     ifcnd[MAXIF+1]; /*      array of IF statement condition
367                                  *      values (0 = FALSE) indexed by tlevel
368                                  */
369 extern  int     iflvl[MAXIF+1]; /*      array of IF-ELSE-ENDIF flevel
370                                  *      values indexed by tlevel
371                                  */
372 extern  char
373         afn[FILENAME_MAX];              /*      afile() temporary filespec
374                                  */
375 extern  char
376         srcfn[MAXFIL][FILENAME_MAX];    /*      array of source file names
377                                  */
378 extern  int
379         srcline[MAXFIL];        /*      current source file line
380                                  */
381 extern  char
382         incfn[MAXINC][FILENAME_MAX];    /*      array of include file names
383                                  */
384 extern  int
385         incline[MAXINC];        /*      current include file line
386                                  */
387 extern  int     radix;          /*      current number conversion radix:
388                                  *      2 (binary), 8 (octal), 10 (decimal),
389                                  *      16 (hexadecimal)
390                                  */
391 extern  int     line;           /*      current assembler source
392                                  *      line number
393                                  */
394 extern  int     page;           /*      current page number
395                                  */
396 extern  int     lop;            /*      current line number on page
397                                  */
398 extern  int     pass;           /*      assembler pass number
399                                  */
400 extern  int     lflag;          /*      -l, generate listing flag
401                                  */
402 extern  int     cflag;          /*      -c, generate sdcdb debug information
403                                  */
404 extern  int     gflag;          /*      -g, make undefined symbols global flag
405                                  */
406 extern  int     aflag;          /*      -a, make all symbols global flag
407                                  */
408 extern  int     jflag;          /*      -j, generate debug information flag
409                                  */
410 extern  int     oflag;          /*      -o, generate relocatable output flag
411                                  */
412 extern  int     sflag;          /*      -s, generate symbol table flag
413                                  */
414 extern  int     pflag;          /*      -p, enable listing pagination
415                                  */
416 extern  int     xflag;          /*      -x, listing radix flag
417                                  */
418 extern  int     fflag;          /*      -f(f), relocations flagged flag
419                                  */
420 extern  Addr_T  laddr;          /*      address of current assembler line
421                                  *      or value of .if argument
422                                  */
423 extern  Addr_T  fuzz;           /*      tracks pass to pass changes in the
424                                  *      address of symbols caused by
425                                  *      variable length instruction formats
426                                  */
427 extern  int     lmode;          /*      listing mode
428                                  */
429 extern  struct  area    area[]; /*      array of 1 area
430                                  */
431 extern  struct  area *areap;    /*      pointer to an area structure
432                                  */
433 extern  struct  sym     sym[];  /*      array of 1 symbol
434                                  */
435 extern  struct  sym *symp;      /*      pointer to a symbol structure
436                                  */
437 extern  struct  sym *symhash[NHASH]; /* array of pointers to NHASH
438                                       * linked symbol lists
439                                       */
440 extern  struct  mne *mnehash[NHASH]; /* array of pointers to NHASH
441                                       * linked mnemonic/directive lists
442                                       */
443 extern  char    *ep;            /*      pointer into error list
444                                  *      array eb[NERR]
445                                  */
446 extern  char    eb[NERR];       /*      array of generated error codes
447                                  */
448 extern  char    *ip;            /*      pointer into the assembler-source
449                                  *      text line in ib[]
450                                  */
451 extern  char    ib[NINPUT];     /*      assembler-source text line
452                                  */
453 extern  char    *cp;            /*      pointer to assembler output
454                                  *      array cb[]
455                                  */
456 extern  char    cb[NCODE];      /*      array of assembler output values
457                                  */
458 extern  int     *cpt;           /*      pointer to assembler relocation type
459                                  *      output array cbt[]
460                                  */
461 extern  int     cbt[NCODE];     /*      array of assembler relocation types
462                                  *      describing the data in cb[]
463                                  */
464 extern  char    tb[NTITL];      /*      Title string buffer
465                                  */
466 extern  char    stb[NSBTL];     /*      Subtitle string buffer
467                                  */
468 extern  int     flat24Mode;     /*      non-zero if we are using DS390 24 bit 
469                                  *      flat mode (via .flat24 directive). 
470                                  */
471 extern  char    symtbl[];       /*      string "Symbol Table"
472                                  */
473 extern  char    aretbl[];       /*      string "Area Table"
474                                  */
475 extern  char    module[NCPS];   /*      module name string
476                                  */
477 extern  FILE    *lfp;           /*      list output file handle
478                                  */
479 extern  FILE    *ofp;           /*      relocation output file handle
480                                  */
481 extern  FILE    *tfp;           /*      symbol table output file handle
482                                  */
483 extern  FILE    *sfp[MAXFIL];   /*      array of assembler-source file handles
484                                  */
485 extern  FILE    *ifp[MAXINC];   /*      array of include-file file handles
486                                  */
487 extern  char    ctype[128];     /*      array of character types, one per
488                                  *      ASCII character
489                                  */
490
491 extern  char    ccase[128];     /* an array of characters which 
492                                  * perform the case translation function
493                                  */
494 /*
495  * Definitions for Character Types
496  */
497 #define SPACE   0000
498 #define ETC     0000
499 #define LETTER  0001
500 #define DIGIT   0002
501 #define BINOP   0004
502 #define RAD2    0010
503 #define RAD8    0020
504 #define RAD10   0040
505 #define RAD16   0100
506 #define ILL     0200
507
508 #define DGT2    DIGIT|RAD16|RAD10|RAD8|RAD2
509 #define DGT8    DIGIT|RAD16|RAD10|RAD8
510 #define DGT10   DIGIT|RAD16|RAD10
511 #define LTR16   LETTER|RAD16
512
513 /*
514  *      The exp structure is used to return the evaluation
515  *      of an expression.  The structure supports three valid
516  *      cases:
517  *      (1)     The expression evaluates to a constant,
518  *              mode = S_USER, flag = 0, addr contains the
519  *              constant, and base = NULL.
520  *      (2)     The expression evaluates to a defined symbol
521  *              plus or minus a constant, mode = S_USER,
522  *              flag = 0, addr contains the constant, and
523  *              base = pointer to area symbol.
524  *      (3)     The expression evaluates to a external
525  *              global symbol plus or minus a constant,
526  *              mode = S_NEW, flag = 1, addr contains the
527  *              constant, and base = pointer to symbol.
528  */
529 struct  expr
530 {
531         char    e_mode;         /* Address mode */
532         char    e_flag;         /* Symbol flag */
533         Addr_T  e_addr;         /* Address */
534         union   {
535                 struct area *e_ap;
536                 struct sym  *e_sp;
537         } e_base;               /* Rel. base */
538         int     e_rlcf;         /* Rel. flags */
539 };
540
541 /* C Library functions */
542 /* for reference only
543 extern  VOID            exit();
544 extern  int             fclose();
545 extern  char *          fgets();
546 extern  FILE *          fopen();
547 extern  int             fprintf();
548 extern  VOID            longjmp();
549 extern  VOID *          malloc();
550 extern  int             printf();
551 extern  char            putc();
552 extern  int             rewind();
553 extern  int             setjmp();
554 extern  int             strcmp();
555 extern  char *          strcpy();
556 extern  int             strlen();
557 extern  char *          strncpy();
558 */
559
560 /* Machine independent functions */
561
562 /* asmain.c */
563 extern  FILE *          afile();
564 extern  VOID            asexit();
565 extern  VOID            asmbl();
566 extern  int             main();
567 extern  VOID            newdot();
568 extern  VOID            phase();
569 extern  VOID            usage();
570
571 /* aslex.c */
572 extern  char            endline();
573 extern  char            get();
574 extern  VOID            getid();
575 extern  int             getline();
576 extern  int             getmap();
577 extern  char            getnb();
578 extern  VOID            getst();
579 extern  int             more();
580 extern  VOID            unget();
581 extern  VOID            chop_crlf();
582
583 /* assym.c */
584 extern  struct  area *  alookup();
585 extern  struct  mne *   mlookup();
586 extern  int             hash();
587 extern  struct  sym *   lookup();
588 extern  VOID *          new();
589 extern  int             symeq();
590 extern  VOID            syminit();
591 extern  VOID            symglob();
592 extern  VOID            allglob();
593
594 /* assubr.c */
595 extern  VOID            aerr();
596 extern  VOID            diag();
597 extern  VOID            err();
598 extern  VOID            warnBanner(void);
599 extern  char *          geterr();
600 extern  VOID            qerr();
601 extern  VOID            rerr();
602
603 /* asexpr.c */
604 extern  VOID            abscheck();
605 extern  Addr_T          absexpr();
606 extern  VOID            clrexpr();
607 extern  int             digit();
608 extern  int             is_abs();
609 extern  VOID            expr();
610 extern  int             oprio();
611 extern  VOID            term();
612
613 /* aslist.c */
614 extern  VOID            list();
615 extern  VOID            list1();
616 extern  VOID            list2();
617 extern  VOID            lstsym();
618 extern  VOID            slew();
619
620 /* asout.c */
621 extern  int             hibyte();
622 extern  int             lobyte();
623 extern  int             byte3(int);
624 extern  VOID            out();
625 extern  VOID            outab();
626 extern  VOID            outarea();
627 extern  VOID            outaw();
628 extern  VOID            outall();
629 extern  VOID            outdot();
630 extern  VOID            outbuf();
631 extern  VOID            outchk();
632 extern  VOID            outgsd();
633 extern  VOID            outrb();
634 extern  VOID            outrw(struct expr *, int);
635 extern  VOID            outr24(struct expr *, int);
636 extern  VOID            outsym();
637 extern  VOID            out_lb();
638 extern  VOID            out_lw();
639 extern  VOID            out_l24(int, int);
640 extern  VOID            out_rw();
641 extern  VOID            out_tw();
642 extern  VOID            out_t24(int);
643 extern  VOID            outr11();       /* JLH */
644 extern  VOID            outr19(struct expr *, int, int);
645
646 /* asstore.c */
647 extern char *StoreString( char *str );
648
649 /* asnoice.c */
650 extern void DefineNoICE_Line();
651 extern void DefineCDB_Line();
652
653 /* Machine dependent variables */
654
655 extern  char *          cpu;
656 extern  char *          dsft;
657 extern  int             hilo;
658 extern  struct  mne     mne[];
659
660 /* Machine dependent functions */
661
662 extern  VOID            minit();
663 extern VOID machine(struct mne *);
664
665 /* SD added THIS define to change
666    strcmpi --> strcmp (strcmpi is NOT ANSI) */
667 #define strcmpi strcmp