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