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