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