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