Cleaned up MSVC specific stuff
[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  0x00            /* 16 bit */
176 #define R_BYTE  0x01            /*  8 bit */
177
178 #define R_AREA  0x00            /* Base type */
179 #define R_SYM   0x02
180
181 #define R_NORM  0x00            /* PC adjust */
182 #define R_PCR   0x04
183
184 #define R_BYT1  0x00            /* Byte count for R_BYTE = 1 */
185 #define R_BYT2  0x08            /* Byte count for R_BYTE = 2 */
186
187 #define R_SGND  0x00            /* Signed Byte */
188 #define R_USGN  0x10            /* Unsigned Byte */
189
190 #define R_NOPAG 0x00            /* Page Mode */
191 #define R_PAG0  0x20            /* Page '0' */
192 #define R_PAG   0x40            /* Page 'nnn' */
193
194 #define R_LSB   0x00            /* low byte */
195 #define R_MSB   0x80            /* high byte */
196
197 #define R_BYT3  0x100           /* if R_BYTE is set, this is a 
198                                  * 3 byte address, of which
199                                  * the linker must select one byte.
200                                  */
201 #define R_HIB   0x200           /* If R_BYTE & R_BYT3 are set, linker
202                                  * will select byte 3 of the relocated
203                                  * 24 bit address.
204                                  */
205
206 #define R_J11   (R_WORD|R_BYT2) /* JLH: 11 bit JMP and CALL (8051) */
207 #define R_J19   (R_WORD|R_BYT2|R_MSB) /* 19 bit JMP/CALL (DS80C390) */
208 #define R_C24   (R_WORD|R_BYT1|R_MSB) /* 24 bit address (DS80C390) */
209 #define R_J19_MASK (R_BYTE|R_BYT2|R_MSB)
210
211 #define IS_R_J19(x) (((x) & R_J19_MASK) == R_J19)
212 #define IS_R_J11(x) (((x) & R_J19_MASK) == R_J11)
213 #define IS_C24(x) (((x) & R_J19_MASK) == R_C24)
214
215 #define R_ESCAPE_MASK   0xf0    /* Used to escape relocation modes
216                                  * greater than 0xff in the .rel
217                                  * file.
218                                  */
219
220 /*
221  * Listing Control Flags
222  */
223
224 #define R_HIGH  0040000         /* High Byte */
225 #define R_RELOC 0100000         /* Relocation */
226
227 #define R_DEF   00              /* Global def. */
228 #define R_REF   01              /* Global ref. */
229 #define R_REL   00              /* Relocatable */
230 #define R_ABS   02              /* Absolute */
231 #define R_GBL   00              /* Global */
232 #define R_LCL   04              /* Local */
233
234 /*
235  *      The mne structure is a linked list of the assembler
236  *      mnemonics and directives.  The list of mnemonics and
237  *      directives contained in the device dependent file
238  *      xxxpst.c are hashed and linked into NHASH lists in
239  *      module assym.c by syminit().  The structure contains
240  *      the mnemonic/directive name, a subtype which directs
241  *      the evaluation of this mnemonic/directive, a flag which
242  *      is used to detect the end of the mnemonic/directive
243  *      list in xxxpst.c, and a value which is normally
244  *      associated with the assembler mnemonic base instruction
245  *      value.
246  */
247 struct  mne
248 {
249         struct  mne *m_mp;      /* Hash link */
250         char    *m_id;          /* Mnemonic JLH: change from [NCPS] */
251         char    m_type;         /* Mnemonic subtype */
252         char    m_flag;         /* Mnemonic flags */
253         Addr_T  m_valu;         /* Value */
254 };
255
256 /*
257  *      The sym structure is a linked list of symbols defined
258  *      in the assembler source files.  The first symbol is "."
259  *      defined in asdata.c.  The entry 'struct tsym *s_tsym'
260  *      links any temporary symbols following this symbol and
261  *      preceeding the next normal symbol.  The structure also
262  *      contains the symbol's name, type (USER or NEW), flag
263  *      (global, assigned, and multiply defined), a pointer
264  *      to the area structure defining where the symbol is
265  *      located, a reference number assigned by outgsd() in
266  *      asout.c, and the symbols address relative to the base
267  *      address of the area where the symbol is located.
268  */
269 struct  sym
270 {
271         struct  sym  *s_sp;     /* Hash link */
272         struct  tsym *s_tsym;   /* Temporary symbol link */
273         char    *s_id;          /* Symbol: JLH change from [NCPS] */
274         char    s_type;         /* Symbol subtype */
275         char    s_flag;         /* Symbol flags */
276         struct  area *s_area;   /* Area line, 0 if absolute */
277         int     s_ref;          /* Ref. number */
278         Addr_T  s_addr;         /* Address */
279 };
280
281 #define S_GBL           01      /* Global */
282 #define S_ASG           02      /* Assigned */
283 #define S_MDF           04      /* Mult. def */
284 #define S_END           010     /* End mark for pst. */
285
286 #define S_NEW           0       /* New name */
287 #define S_USER          1       /* User name */
288                                 /* unused slot */
289                                 /* unused slot */
290                                 /* unused slot */
291
292 #define S_BYTE          5       /* .byte */
293 #define S_WORD          6       /* .word */
294 #define S_ASCII         7       /* .ascii */
295 #define S_ASCIZ         8       /* .asciz */
296 #define S_BLK           9       /* .blkb or .blkw */
297 #define S_INCL          10      /* .include */
298 #define S_DAREA         11      /* .area */
299 #define S_ATYP          12      /* .area type */
300 #define S_AREA          13      /* .area name */
301 #define S_GLOBL         14      /* .globl */
302 #define S_PAGE          15      /* .page */
303 #define S_TITLE         16      /* .title */
304 #define S_SBTL          17      /* .sbttl */
305 #define S_IF            18      /* .if */
306 #define S_ELSE          19      /* .else */
307 #define S_ENDIF         20      /* .endif */
308 #define S_EVEN          21      /* .even */
309 #define S_ODD           22      /* .odd */
310 #define S_RADIX         23      /* .radix */
311 #define S_ORG           24      /* .org */
312 #define S_MODUL         25      /* .module */
313 #define S_ASCIS         26      /* .ascis */
314 #define S_FLAT24        27      /* .flat24 */
315
316
317 /*
318  *      The tsym structure is a linked list of temporary
319  *      symbols defined in the assembler source files following
320  *      a normal symbol.  The structure contains the temporary
321  *      symbols number, a flag (multiply defined), a pointer to the
322  *      area structure defining where the temporary structure
323  *      is located, and the temporary symbol's address relative
324  *      to the base address of the area where the symbol
325  *      is located.
326  */
327 struct  tsym
328 {
329         struct  tsym *t_lnk;    /* Link to next */
330 /* sandeep changed to 'int' from 'char' */
331 /* this will increase the number temp symbols
332    that can be defined from 255 to INT_MAX */
333         int t_num;              /* 0-INT_MAX$ */
334         int t_flg;              /* flags */
335
336         struct  area *t_area;   /* Area */
337         Addr_T  t_addr;         /* Address */
338 };
339
340 /*
341  *      External Definitions for all Global Variables
342  */
343
344 extern  int     aserr;          /*      ASxxxx error counter
345                                  */
346 extern  jmp_buf jump_env;       /*      compiler dependent structure
347                                  *      used by setjmp() and longjmp()
348                                  */
349 extern  int     inpfil;         /*      count of assembler
350                                  *      input files specified
351                                  */
352 extern  int     incfil;         /*      current file handle index
353                                  *      for include files
354                                  */
355 extern  int     cfile;          /*      current file handle index
356                                  *      of input assembly files
357                                  */
358 extern  int     flevel;         /*      IF-ELSE-ENDIF flag will be non
359                                  *      zero for false conditional case
360                                  */
361 extern  int     tlevel;         /*      current conditional level
362                                  */
363 extern  int     ifcnd[MAXIF+1]; /*      array of IF statement condition
364                                  *      values (0 = FALSE) indexed by tlevel
365                                  */
366 extern  int     iflvl[MAXIF+1]; /*      array of IF-ELSE-ENDIF flevel
367                                  *      values indexed by tlevel
368                                  */
369 extern  char
370         afn[FILSPC];            /*      afile() temporary filespec
371                                  */
372 extern  char
373         srcfn[MAXFIL][FILSPC];  /*      array of source file names
374                                  */
375 extern  int
376         srcline[MAXFIL];        /*      current source file line
377                                  */
378 extern  char
379         incfn[MAXINC][FILSPC];  /*      array of include file names
380                                  */
381 extern  int
382         incline[MAXINC];        /*      current include file line
383                                  */
384 extern  int     radix;          /*      current number conversion radix:
385                                  *      2 (binary), 8 (octal), 10 (decimal),
386                                  *      16 (hexadecimal)
387                                  */
388 extern  int     line;           /*      current assembler source
389                                  *      line number
390                                  */
391 extern  int     page;           /*      current page number
392                                  */
393 extern  int     lop;            /*      current line number on page
394                                  */
395 extern  int     pass;           /*      assembler pass number
396                                  */
397 extern  int     lflag;          /*      -l, generate listing flag
398                                  */
399 extern  int     cflag;          /*      -c, generate sdcdb debug information
400                                  */
401 extern  int     gflag;          /*      -g, make undefined symbols global flag
402                                  */
403 extern  int     aflag;          /*      -a, make all symbols global flag
404                                  */
405 extern  int     jflag;          /*      -j, generate debug information flag
406                                  */
407 extern  int     oflag;          /*      -o, generate relocatable output flag
408                                  */
409 extern  int     sflag;          /*      -s, generate symbol table flag
410                                  */
411 extern  int     pflag;          /*      -p, enable listing pagination
412                                  */
413 extern  int     xflag;          /*      -x, listing radix flag
414                                  */
415 extern  int     fflag;          /*      -f(f), relocations flagged flag
416                                  */
417 extern  Addr_T  laddr;          /*      address of current assembler line
418                                  *      or value of .if argument
419                                  */
420 extern  Addr_T  fuzz;           /*      tracks pass to pass changes in the
421                                  *      address of symbols caused by
422                                  *      variable length instruction formats
423                                  */
424 extern  int     lmode;          /*      listing mode
425                                  */
426 extern  struct  area    area[]; /*      array of 1 area
427                                  */
428 extern  struct  area *areap;    /*      pointer to an area structure
429                                  */
430 extern  struct  sym     sym[];  /*      array of 1 symbol
431                                  */
432 extern  struct  sym *symp;      /*      pointer to a symbol structure
433                                  */
434 extern  struct  sym *symhash[NHASH]; /* array of pointers to NHASH
435                                       * linked symbol lists
436                                       */
437 extern  struct  mne *mnehash[NHASH]; /* array of pointers to NHASH
438                                       * linked mnemonic/directive lists
439                                       */
440 extern  char    *ep;            /*      pointer into error list
441                                  *      array eb[NERR]
442                                  */
443 extern  char    eb[NERR];       /*      array of generated error codes
444                                  */
445 extern  char    *ip;            /*      pointer into the assembler-source
446                                  *      text line in ib[]
447                                  */
448 extern  char    ib[NINPUT];     /*      assembler-source text line
449                                  */
450 extern  char    *cp;            /*      pointer to assembler output
451                                  *      array cb[]
452                                  */
453 extern  char    cb[NCODE];      /*      array of assembler output values
454                                  */
455 extern  int     *cpt;           /*      pointer to assembler relocation type
456                                  *      output array cbt[]
457                                  */
458 extern  int     cbt[NCODE];     /*      array of assembler relocation types
459                                  *      describing the data in cb[]
460                                  */
461 extern  char    tb[NTITL];      /*      Title string buffer
462                                  */
463 extern  char    stb[NSBTL];     /*      Subtitle string buffer
464                                  */
465 extern  int     flat24Mode;     /*      non-zero if we are using DS390 24 bit 
466                                  *      flat mode (via .flat24 directive). 
467                                  */
468 extern  char    symtbl[];       /*      string "Symbol Table"
469                                  */
470 extern  char    aretbl[];       /*      string "Area Table"
471                                  */
472 extern  char    module[NCPS];   /*      module name string
473                                  */
474 extern  FILE    *lfp;           /*      list output file handle
475                                  */
476 extern  FILE    *ofp;           /*      relocation output file handle
477                                  */
478 extern  FILE    *tfp;           /*      symbol table output file handle
479                                  */
480 extern  FILE    *sfp[MAXFIL];   /*      array of assembler-source file handles
481                                  */
482 extern  FILE    *ifp[MAXINC];   /*      array of include-file file handles
483                                  */
484 extern  char    ctype[128];     /*      array of character types, one per
485                                  *      ASCII character
486                                  */
487
488 extern  char    ccase[128];     /* an array of characters which 
489                                  * perform the case translation function
490                                  */
491 /*
492  * Definitions for Character Types
493  */
494 #define SPACE   0000
495 #define ETC     0000
496 #define LETTER  0001
497 #define DIGIT   0002
498 #define BINOP   0004
499 #define RAD2    0010
500 #define RAD8    0020
501 #define RAD10   0040
502 #define RAD16   0100
503 #define ILL     0200
504
505 #define DGT2    DIGIT|RAD16|RAD10|RAD8|RAD2
506 #define DGT8    DIGIT|RAD16|RAD10|RAD8
507 #define DGT10   DIGIT|RAD16|RAD10
508 #define LTR16   LETTER|RAD16
509
510 /*
511  *      The exp structure is used to return the evaluation
512  *      of an expression.  The structure supports three valid
513  *      cases:
514  *      (1)     The expression evaluates to a constant,
515  *              mode = S_USER, flag = 0, addr contains the
516  *              constant, and base = NULL.
517  *      (2)     The expression evaluates to a defined symbol
518  *              plus or minus a constant, mode = S_USER,
519  *              flag = 0, addr contains the constant, and
520  *              base = pointer to area symbol.
521  *      (3)     The expression evaluates to a external
522  *              global symbol plus or minus a constant,
523  *              mode = S_NEW, flag = 1, addr contains the
524  *              constant, and base = pointer to symbol.
525  */
526 struct  expr
527 {
528         char    e_mode;         /* Address mode */
529         char    e_flag;         /* Symbol flag */
530         Addr_T  e_addr;         /* Address */
531         union   {
532                 struct area *e_ap;
533                 struct sym  *e_sp;
534         } e_base;               /* Rel. base */
535         int     e_rlcf;         /* Rel. flags */
536 };
537
538 /* C Library functions */
539 /* for reference only
540 extern  VOID            exit();
541 extern  int             fclose();
542 extern  char *          fgets();
543 extern  FILE *          fopen();
544 extern  int             fprintf();
545 extern  VOID            longjmp();
546 extern  VOID *          malloc();
547 extern  int             printf();
548 extern  char            putc();
549 extern  int             rewind();
550 extern  int             setjmp();
551 extern  int             strcmp();
552 extern  char *          strcpy();
553 extern  int             strlen();
554 extern  char *          strncpy();
555 */
556
557 /* Machine independent functions */
558
559 /* asmain.c */
560 extern  FILE *          afile();
561 extern  VOID            asexit();
562 extern  VOID            asmbl();
563 extern  int             main();
564 extern  VOID            newdot();
565 extern  VOID            phase();
566 extern  VOID            usage();
567
568 /* aslex.c */
569 extern  char            endline();
570 extern  char            get();
571 extern  VOID            getid();
572 extern  int             getline();
573 extern  int             getmap();
574 extern  char            getnb();
575 extern  VOID            getst();
576 extern  int             more();
577 extern  VOID            unget();
578 extern  VOID            chop_crlf();
579
580 /* assym.c */
581 extern  struct  area *  alookup();
582 extern  struct  mne *   mlookup();
583 extern  int             hash();
584 extern  struct  sym *   lookup();
585 extern  VOID *          new();
586 extern  int             symeq();
587 extern  VOID            syminit();
588 extern  VOID            symglob();
589 extern  VOID            allglob();
590
591 /* assubr.c */
592 extern  VOID            aerr();
593 extern  VOID            diag();
594 extern  VOID            err();
595 extern  VOID            warnBanner(void);
596 extern  char *          geterr();
597 extern  VOID            qerr();
598 extern  VOID            rerr();
599
600 /* asexpr.c */
601 extern  VOID            abscheck();
602 extern  Addr_T          absexpr();
603 extern  VOID            clrexpr();
604 extern  int             digit();
605 extern  int             is_abs();
606 extern  VOID            expr();
607 extern  int             oprio();
608 extern  VOID            term();
609
610 /* aslist.c */
611 extern  VOID            list();
612 extern  VOID            list1();
613 extern  VOID            list2();
614 extern  VOID            lstsym();
615 extern  VOID            slew();
616
617 /* asout.c */
618 extern  int             hibyte();
619 extern  int             lobyte();
620 extern  int             byte3(int);
621 extern  VOID            out();
622 extern  VOID            outab();
623 extern  VOID            outarea();
624 extern  VOID            outaw();
625 extern  VOID            outall();
626 extern  VOID            outdot();
627 extern  VOID            outbuf();
628 extern  VOID            outchk();
629 extern  VOID            outgsd();
630 extern  VOID            outrb();
631 extern  VOID            outrw(struct expr *, int);
632 extern  VOID            outr24(struct expr *, int);
633 extern  VOID            outsym();
634 extern  VOID            out_lb();
635 extern  VOID            out_lw();
636 extern  VOID            out_l24(int, int);
637 extern  VOID            out_rw();
638 extern  VOID            out_tw();
639 extern  VOID            out_t24(int);
640 extern  VOID            outr11();       /* JLH */
641 extern  VOID            outr19(struct expr *, int, int);
642
643 /* asstore.c */
644 extern char *StoreString( char *str );
645
646 /* asnoice.c */
647 extern void DefineNoICE_Line();
648 extern void DefineCDB_Line();
649
650 /* Machine dependent variables */
651
652 extern  char *          cpu;
653 extern  char *          dsft;
654 extern  int             hilo;
655 extern  struct  mne     mne[];
656
657 /* Machine dependent functions */
658
659 extern  VOID            minit();
660 extern VOID machine(struct mne *);
661
662 /* SD added THIS define to change
663    strcmpi --> strcmp (strcmpi is NOT ANSI) */
664 #define strcmpi strcmp