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