Lengthened the maximum filename to 100 chars
[fw/sdcc] / link / z80 / aslink.h
1 /* aslink.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  0
22
23 /*)Module       asmlnk.h
24  *
25  *      The module asmlnk.h contains the definitions for constants,
26  *      structures, global variables, and LKxxxx functions
27  *      contained in the LKxxxx.c files.
28  */
29
30 /*)BUILD
31         $(PROGRAM) =    ASLINK
32         $(INCLUDE) =    ASLINK.H
33         $(FILES) = {
34                 LKMAIN.C
35                 LKLEX.C
36                 LKAREA.C
37                 LKHEAD.C
38                 LKSYM.C
39                 LKEVAL.C
40                 LKDATA.C
41                 LKLIST.C
42                 LKRLOC.C
43                 LKLIBR.C
44                 LKS19.C
45                 LKIHX.C
46         }
47         $(STACK) = 2000
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  * This file defines the format of the
77  * relocatable binary file.
78  */
79
80 #ifdef SDK
81 #define NCPS    32              /* characters per symbol */
82 #else /* SDK */
83 #define NCPS    8               /* characters per symbol */
84 #endif /* SDK */
85 /* #define      NCPS    32 */   /* characters per symbol */
86 #define NDATA   16              /* actual data */
87 #define NINPUT  128             /* Input 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 NTXT    16              /* T values */
92 /** PENDING: Taking this to 256 causes a segfault. */
93 #define FILSPC  100             /* File spec length */
94
95 /*
96  *      The "R_" relocation constants define values used in
97  *      generating the assembler relocation output data for
98  *      areas, symbols, and code.
99  *
100  *
101  *      Relocation types.
102  *
103  *             7     6     5     4     3     2     1     0
104  *          +-----+-----+-----+-----+-----+-----+-----+-----+
105  *          | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
106  *          +-----+-----+-----+-----+-----+-----+-----+-----+
107  */
108
109 #define R_WORD  0x00            /* 16 bit */
110 #define R_BYTE  0x01            /*  8 bit */
111
112 #define R_AREA  0x00            /* Base type */
113 #define R_SYM   0x02
114
115 #define R_NORM  0x00            /* PC adjust */
116 #define R_PCR   0x04
117
118 #define R_BYT1  0x00            /* Byte count for R_BYTE = 1 */
119 #define R_BYT2  0x08            /* Byte count for R_BYTE = 2 */
120
121 #define R_SGND  0x00            /* Signed value */
122 #define R_USGN  0x10            /* Unsigned value */
123
124 #define R_NOPAG 0x00            /* Page Mode */
125 #define R_PAG0  0x20            /* Page '0' */
126 #define R_PAG   0x40            /* Page 'nnn' */
127
128 /*
129  * Valid for R_BYT2:
130  */
131 #define R_LSB   0x00            /* output low byte */
132 #define R_MSB   0x80            /* output high byte */
133
134 /*
135  * Global symbol types.
136  */
137 #define S_REF   1               /* referenced */
138 #define S_DEF   2               /* defined */
139
140 /*
141  * Area types
142  */
143 #define A_CON   000             /* concatenate */
144 #define A_OVR   004             /* overlay */
145 #define A_REL   000             /* relocatable */
146 #define A_ABS   010             /* absolute */
147 #define A_NOPAG 000             /* non-paged */
148 #define A_PAG   020             /* paged */
149
150 /*
151  * File types
152  */
153 #define F_STD   1               /* stdin */
154 #define F_LNK   2               /* File.lnk */
155 #define F_REL   3               /* File.rel */
156 #ifdef SDK
157 #define F_CMD   4               /* Command line */
158 #endif /* SDK */
159
160 #ifdef GAMEBOY
161 /*
162  * Multiple banks support
163  */
164 extern int nb_rom_banks;
165 extern int nb_ram_banks;
166 extern int current_rom_bank;
167 extern int mbc_type;
168 extern char cart_name[];
169 /*
170  * ROM patching support
171  */
172 typedef struct _patch {
173   unsigned int addr;
174   unsigned char value;
175   struct _patch *next;
176 } patch;
177 extern patch* patches;
178 #endif /* GAMEBOY */
179 /*
180  *      General assembler address type
181  */
182 typedef unsigned int Addr_T;
183
184 /*
185  *      The structures of head, area, areax, and sym are created
186  *      as the REL files are read during the first pass of the
187  *      linker.  The struct head is created upon encountering a
188  *      H directive in the REL file.  The structure contains a
189  *      link to a link file structure (struct lfile) which describes
190  *      the file containing the H directive, the number of data/code
191  *      areas contained in this header segment, the number of
192  *      symbols referenced/defined in this header segment, a pointer
193  *      to an array of pointers to areax structures (struct areax)
194  *      created as each A directive is read, and a pointer to an
195  *      array of pointers to symbol structures (struct sym) for
196  *      all referenced/defined symbols.  As H directives are read
197  *      from the REL files a linked list of head structures is
198  *      created by placing a link to the new head structure
199  *      in the previous head structure.
200  */
201 struct  head
202 {
203         struct  head   *h_hp;   /* Header link */
204         struct  lfile  *h_lfile;/* Associated file */
205         int     h_narea;        /* # of areas */
206         struct  areax **a_list; /* Area list */
207         int     h_nglob;        /* # of global symbols */
208         struct  sym   **s_list; /* Globle symbol list */
209         char    m_id[NCPS];     /* Module name */
210 };
211
212 /*
213  *      A structure area is created for each 'unique' data/code
214  *      area definition found as the REL files are read.  The
215  *      struct area contains the name of the area, a flag byte
216  *      which contains the area attributes (REL/CON/OVR/ABS),
217  *      an area subtype (not used in this assembler), and the
218  *      area base address and total size which will be filled
219  *      in at the end of the first pass through the REL files.
220  *      As A directives are read from the REL files a linked
221  *      list of unique area structures is created by placing a
222  *      link to the new area structure in the previous area structure.
223  */
224 struct  area
225 {
226         struct  area    *a_ap;  /* Area link */
227         struct  areax   *a_axp; /* Area extension link */
228         Addr_T  a_addr;         /* Beginning address of area */
229         Addr_T  a_size;         /* Total size of the area */
230         char    a_type;         /* Area subtype */
231         char    a_flag;         /* Flag byte */
232         char    a_id[NCPS];     /* Name */
233 };
234
235 /*
236  *      An areax structure is created for every A directive found
237  *      while reading the REL files.  The struct areax contains a
238  *      link to the 'unique' area structure referenced by the A
239  *      directive and to the head structure this area segment is
240  *      a part of.  The size of this area segment as read from the
241  *      A directive is placed in the areax structure.  The beginning
242  *      address of this segment will be filled in at the end of the
243  *      first pass through the REL files.  As A directives are read
244  *      from the REL files a linked list of areax structures is
245  *      created for each unique area.  The final areax linked
246  *      list has at its head the 'unique' area structure linked
247  *      to the linked areax structures (one areax structure for
248  *      each A directive for this area).
249  */
250 struct  areax
251 {
252         struct  areax   *a_axp; /* Area extension link */
253         struct  area    *a_bap; /* Base area link */
254         struct  head    *a_bhp; /* Base header link */
255         Addr_T  a_addr;         /* Beginning address of section */
256         Addr_T  a_size;         /* Size of the area in section */
257 };
258
259 /*
260  *      A sym structure is created for every unique symbol
261  *      referenced/defined while reading the REL files.  The
262  *      struct sym contains the symbol's name, a flag value
263  *      (not used in this linker), a symbol type denoting
264  *      referenced/defined, and an address which is loaded
265  *      with the relative address within the area in which
266  *      the symbol was defined.  The sym structure also
267  *      contains a link to the area where the symbol was defined.
268  *      The sym structures are linked into linked lists using
269  *      the symbol link element.
270  */
271 struct  sym
272 {
273         struct  sym     *s_sp;  /* Symbol link */
274         struct  areax   *s_axp; /* Symbol area link */
275         char    s_type;         /* Symbol subtype */
276         char    s_flag;         /* Flag byte */
277         Addr_T  s_addr;         /* Address */
278         char    s_id[NCPS];     /* Name */
279 };
280
281 /*
282  *      The structure lfile contains a pointer to a
283  *      file specification string, the file type, and
284  *      a link to the next lfile structure.
285  */
286 struct  lfile
287 {
288         struct  lfile   *f_flp; /* lfile link */
289         int     f_type;         /* File type */
290         char    *f_idp;         /* Pointer to file spec */
291 };
292
293 /*
294  *      The struct base contains a pointer to a
295  *      base definition string and a link to the next
296  *      base structure.
297  */
298 struct  base
299 {
300         struct  base  *b_base;  /* Base link */
301         char          *b_strp;  /* String pointer */
302 };
303
304 /*
305  *      The struct globl contains a pointer to a
306  *      global definition string and a link to the next
307  *      global structure.
308  */
309 struct  globl
310 {
311         struct  globl *g_globl; /* Global link */
312         char          *g_strp;  /* String pointer */
313 };
314
315 /*
316  *      A structure sdp is created for each 'unique' paged
317  *      area definition found as the REL files are read.
318  *      As P directives are read from the REL files a linked
319  *      list of unique sdp structures is created by placing a
320  *      link to the new sdp structure in the previous area structure.
321  */
322 struct  sdp
323 {
324         struct  area  *s_area;  /* Paged Area link */
325         struct  areax *s_areax; /* Paged Area Extension Link */
326         Addr_T  s_addr;         /* Page address offset */
327 };
328
329 /*
330  *      The structure rerr is loaded with the information
331  *      required to report an error during the linking
332  *      process.  The structure contains an index value
333  *      which selects the areax structure from the header
334  *      areax structure list, a mode value which selects
335  *      symbol or area relocation, the base address in the
336  *      area section, an area/symbol list index value, and
337  *      an area/symbol offset value.
338  */
339 struct  rerr
340 {
341         int     aindex;         /* Linking area */
342         int     mode;           /* Relocation mode */
343         Addr_T  rtbase;         /* Base address in section */
344         int     rindex;         /* Area/Symbol reloaction index */
345         Addr_T  rval;           /* Area/Symbol offset value */
346 };
347
348 /*
349  *      The structure lbpath is created for each library
350  *      path specification input by the -k option.  The
351  *      lbpath structures are linked into a list using
352  *      the next link element.
353  */
354 struct lbpath {
355         struct  lbpath  *next;
356         char            *path;
357 };
358
359 /*
360  *      The structure lbname is created for all combinations of the
361  *      library path specifications (input by the -k option) and the
362  *      library file specifications (input by the -l option) that
363  *      lead to an existing file.  The element path points to
364  *      the path string, element libfil points to the library
365  *      file string, and the element libspc is the concatenation
366  *      of the valid path and libfil strings.
367  *
368  *      The lbpath structures are linked into a list
369  *      using the next link element.
370  *
371  *      Each library file contains a list of object files
372  *      that are contained in the particular library. e.g.:
373  *
374  *              \iolib\termio
375  *              \inilib\termio
376  *
377  *      Only one specification per line is allowed.
378  */
379 struct lbname {
380         struct  lbname  *next;
381         char            *path;
382         char            *libfil;
383         char            *libspc;
384 };
385
386 /*
387  *      The function fndsym() searches through all combinations of the
388  *      library path specifications (input by the -k option) and the
389  *      library file specifications (input by the -l option) that
390  *      lead to an existing file for a symbol definition.
391  *
392  *      The structure lbfile is created for the first library
393  *      object file which contains the definition for the
394  *      specified undefined symbol.
395  *
396  *      The element libspc points to the library file path specification
397  *      and element relfil points to the object file specification string.
398  *      The element filspc is the complete path/file specification for
399  *      the library file to be imported into the linker.  The
400  *      file specicifation may be formed in one of two ways:
401  *
402  *      (1)     If the library file contained an absolute
403  *              path/file specification then this becomes filspc.
404  *              (i.e. C:\...)
405  *
406  *      (2)     If the library file contains a relative path/file
407  *              specification then the concatenation of the path
408  *              and this file specification becomes filspc.
409  *              (i.e. \...)
410  *
411  *      The lbpath structures are linked into a list
412  *      using the next link element.
413  */
414 struct lbfile {
415         struct  lbfile  *next;
416         char            *libspc;
417         char            *relfil;
418         char            *filspc;
419 };
420
421 /*
422  *      External Definitions for all Global Variables
423  */
424
425 extern  char    *_abs_;         /*      = { ".  .ABS." };
426                                  */
427 extern  int     lkerr;          /*      ASLink error flag
428                                  */
429 extern  char    *ip;            /*      pointer into the REL file
430                                  *      text line in ib[]
431                                  */
432 extern  char    ib[NINPUT];     /*      REL file text line
433                                  */
434 extern  char    *rp;            /*      pointer into the LST file
435                                  *      text line in rb[]
436                                  */
437 extern  char    rb[NINPUT];     /*      LST file text line being
438                                  *      address relocated
439                                  */
440 extern  char    ctype[];        /*      array of character types, one per
441                                  *      ASCII character
442                                  */
443
444 /*
445  *      Character Type Definitions
446  */
447 #define SPACE   0000
448 #define ETC     0000
449 #define LETTER  0001
450 #define DIGIT   0002
451 #define BINOP   0004
452 #define RAD2    0010
453 #define RAD8    0020
454 #define RAD10   0040
455 #define RAD16   0100
456 #define ILL     0200
457
458 #define DGT2    DIGIT|RAD16|RAD10|RAD8|RAD2
459 #define DGT8    DIGIT|RAD16|RAD10|RAD8
460 #define DGT10   DIGIT|RAD16|RAD10
461 #define LTR16   LETTER|RAD16
462
463 #if     CASE_SENSITIVE
464 #else
465 extern  char    ccase[];        /*      an array of characters which
466                                  *      perform the case translation function
467                                  */
468 #endif
469
470 extern  struct  lfile   *filep; /*      The pointers (lfile *) filep,
471                                  *      (lfile *) cfp, and (FILE *) sfp
472                                  *      are used in conjunction with
473                                  *      the routine getline() to read
474                                  *      asmlnk commands from
475                                  *      (1) the standard input or
476                                  *      (2) or a command file
477                                  *      and to read the REL files
478                                  *      sequentially as defined by the
479                                  *      asmlnk input commands.
480                                  *
481                                  *      The pointer *filep points to the
482                                  *      beginning of a linked list of
483                                  *      lfile structures.
484                                  */
485 extern  struct  lfile   *cfp;   /*      The pointer *cfp points to the
486                                  *      current lfile structure
487                                  */
488 extern  struct  lfile   *startp;/*      asmlnk startup file structure
489                                  */
490 extern  struct  lfile   *linkp; /*      pointer to first lfile structure
491                                  *      containing an input REL file
492                                  *      specification
493                                  */
494 extern  struct  lfile   *lfp;   /*      pointer to current lfile structure
495                                  *      being processed by parse()
496                                  */
497 extern  struct  head    *headp; /*      The pointer to the first
498                                  *      head structure of a linked list
499                                  */
500 extern  struct  head    *hp;    /*      Pointer to the current
501                                  *      head structure
502                                  */
503 extern  struct  area    *areap; /*      The pointer to the first
504                                  *      area structure of a linked list
505                                  */
506 extern  struct  area    *ap;    /*      Pointer to the current
507                                  *      area structure
508                                  */
509 extern  struct  areax   *axp;   /*      Pointer to the current
510                                  *      areax structure
511                                  */
512 extern  struct  sym *symhash[NHASH]; /* array of pointers to NHASH
513                                       * linked symbol lists
514                                       */
515 extern  struct  base    *basep; /*      The pointer to the first
516                                  *      base structure
517                                  */
518 extern  struct  base    *bsp;   /*      Pointer to the current
519                                  *      base structure
520                                  */
521 extern  struct  globl   *globlp;/*      The pointer to the first
522                                  *      globl structure
523                                  */
524 extern  struct  globl   *gsp;   /*      Pointer to the current
525                                  *      globl structure
526                                  */
527 extern  struct  sdp     sdp;    /*      Base Paged structure
528                                  */
529 extern  struct  rerr    rerr;   /*      Structure containing the
530                                  *      linker error information
531                                  */
532 extern  FILE    *ofp;           /*      Linker Output file handle
533                                  */
534 extern  FILE    *mfp;           /*      Map output file handle
535                                  */
536 extern  FILE    *rfp;           /*      File handle for output
537                                  *      address relocated ASxxxx
538                                  *      listing file
539                                  */
540 extern  FILE    *sfp;           /*      The file handle sfp points to the
541                                  *      currently open file
542                                  */
543 extern  FILE    *tfp;           /*      File handle for input
544                                  *      ASxxxx listing file
545                                  */
546 extern  int     oflag;          /*      Output file type flag
547                                  */
548 extern  int     mflag;          /*      Map output flag
549                                  */
550 #ifdef SDK
551 extern  int     symflag;        /*      no$gmb .sym output flag
552                                  */
553 #endif
554 extern  int     xflag;          /*      Map file radix type flag
555                                  */
556 extern  int     pflag;          /*      print linker command file flag
557                                  */
558 extern  int     uflag;          /*      Listing relocation flag
559                                  */
560 extern  int     radix;          /*      current number conversion radix:
561                                  *      2 (binary), 8 (octal), 10 (decimal),
562                                  *      16 (hexadecimal)
563                                  */
564 extern  int     line;           /*      current line number
565                                  */
566 extern  int     page;           /*      current page number
567                                  */
568 extern  int     lop;            /*      current line number on page
569                                  */
570 extern  int     pass;           /*      linker pass number
571                                  */
572 extern  int     rtcnt;          /*      count of elements in the
573                                  *      rtval[] and rtflg[] arrays
574                                  */
575 extern  Addr_T  rtval[];        /*      data associated with relocation
576                                  */
577 extern  int     rtflg[];        /*      indicates if rtval[] value is
578                                  *      to be sent to the output file.
579                                  *      (always set in this linker)
580                                  */
581 extern  int     hilo;           /*      REL file byte ordering
582                                  */
583 extern  int     gline;          /*      LST file relocation active
584                                  *      for current line
585                                  */
586 extern  int     gcntr;          /*      LST file relocation active
587                                  *      counter
588                                  */
589 extern  struct lbpath *lbphead; /*      pointer to the first
590                                  *      library path structure
591                                  */
592 extern  struct lbname *lbnhead; /*      pointer to the first
593                                  *      library name structure
594                                  */
595 extern  struct lbfile *lbfhead; /*      pointer to the first
596                                  *      library file structure
597                                  */
598
599 /* C Library function definitions */
600 /* for reference only
601 extern  VOID            exit();
602 extern  int             fclose();
603 extern  char *          fgets();
604 extern  FILE *          fopen();
605 extern  int             fprintf();
606 extern  VOID            free();
607 extern  VOID *          malloc();
608 extern  char            putc();
609 extern  char *          strcpy();
610 extern  int             strlen();
611 extern  char *          strncpy();
612 */
613
614 /* Program function definitions */
615
616 /* lkmain.c */
617 extern  FILE *          afile();
618 extern  VOID            bassav();
619 extern  VOID            gblsav();
620 extern  VOID            link();
621 extern  VOID            lkexit();
622 extern  int             main();
623 extern  VOID            map();
624 #ifdef SDK
625 extern  VOID            sym();
626 #endif
627 extern  int             parse();
628 extern  VOID            setbas();
629 extern  VOID            setgbl();
630 extern  VOID            usage();
631
632 /* lklex.c */
633 extern  char            endline();
634 extern  char            get();
635 extern  VOID            getfid();
636 extern  VOID            getid();
637 extern  int             getline();
638 extern  int             getmap();
639 extern  char            getnb();
640 extern  int             more();
641 extern  VOID            skip();
642 extern  VOID            unget();
643
644 /* lkarea.c */
645 extern  VOID            lkparea();
646 extern  VOID            lnkarea();
647 extern  VOID            lnksect();
648 extern  VOID            newarea();
649
650 /* lkhead.c */
651 extern  VOID            module();
652 extern  VOID            newhead();
653
654 /* lksym.c */
655 extern  int             hash();
656 extern  struct  sym *   lkpsym();
657 extern  VOID *          new();
658 extern  struct  sym *   newsym();
659 extern  VOID            symdef();
660 extern  int             symeq();
661 extern  VOID            syminit();
662 extern  VOID            symmod();
663 extern  Addr_T          symval();
664
665 /* lkeval.c */
666 extern  int             digit();
667 extern  Addr_T          eval();
668 extern  Addr_T          expr();
669 extern  int             oprio();
670 extern  Addr_T          term();
671
672 /* lklist.c */
673 extern  int             dgt();
674 extern  VOID            lkulist();
675 extern  VOID            lkalist();
676 extern  VOID            lkglist();
677 extern  VOID            lstarea();
678 extern  VOID            newpag();
679 extern  VOID            slew();
680
681 /* lkrloc.c */
682 extern  Addr_T          adb_b();
683 extern  Addr_T          adb_hi();
684 extern  Addr_T          adb_lo();
685 extern  Addr_T          adw_w();
686 extern  Addr_T          adw_hi();
687 extern  Addr_T          adw_lo();
688 extern  Addr_T          evword();
689 extern  VOID            rele();
690 extern  VOID            reloc();
691 extern  VOID            relt();
692 extern  VOID            relr();
693 extern  VOID            relp();
694 extern  VOID            relerr();
695 extern  char *          errmsg[];
696 extern  VOID            errdmp();
697 extern  VOID            relerp();
698 extern  VOID            erpdmp();
699 extern  VOID            prntval();
700
701 /* lklibr.c */
702 extern  VOID            addfile();
703 extern  VOID            addlib();
704 extern  VOID            addpath();
705 extern  int             fndsym();
706 extern  VOID            library();
707 extern  VOID            loadfile();
708 extern  VOID            search();
709
710 /* lks19.c */
711 extern  VOID            s19();
712
713 /* lkihx.c */
714 extern  VOID            ihx();