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