4 * (C) Copyright 1989-1995
12 * - add proto for StoreString
13 * - change s_id from [NCPS] to pointer
16 * - add R_J11 for 8051 assembler
18 * - add jflag and jfp for NoICE output
20 * - add memory space flags to a_flag for 8051
23 #define VERSION "V01.70 + NoICE + SDCC Feb 1999"
26 * Case Sensitivity Flag
28 #define CASE_SENSITIVE 1
32 * The module asmlnk.h contains the definitions for constants,
33 * structures, global variables, and LKxxxx functions
34 * contained in the LKxxxx.c files.
57 /* DECUS C void definition */
58 /* File/extension seperator */
65 /* PDOS C void definition */
66 /* File/extension seperator */
73 /* Default void definition */
74 /* File/extension seperator */
83 * This file defines the format of the
84 * relocatable binary file.
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 */
97 * The "R_" relocation constants define values used in
98 * generating the assembler relocation output data for
99 * areas, symbols, and code.
105 * +-----+-----+-----+-----+-----+-----+-----+-----+
106 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
107 * +-----+-----+-----+-----+-----+-----+-----+-----+
110 #define R_WORD 0x00 /* 16 bit */
111 #define R_BYTE 0x01 /* 8 bit */
113 #define R_AREA 0x00 /* Base type */
116 #define R_NORM 0x00 /* PC adjust */
119 #define R_BYT1 0x00 /* Byte count for R_BYTE = 1 */
120 #define R_BYT2 0x08 /* Byte count for R_BYTE = 2 */
122 #define R_SGND 0x00 /* Signed Byte */
123 #define R_USGN 0x10 /* Unsigned Byte */
125 #define R_NOPAG 0x00 /* Page Mode */
126 #define R_PAG0 0x20 /* Page '0' */
127 #define R_PAG 0x40 /* Page 'nnn' */
129 #define R_LSB 0x00 /* low byte */
130 #define R_MSB 0x80 /* high byte */
132 #define R_BYT3 0x100 /* if R_BYTE is set, this is a
133 * 3 byte address, of which
134 * the linker must select one byte.
136 #define R_HIB 0x200 /* If R_BYTE & R_BYT3 are set, linker
137 * will select byte 3 of the relocated
141 #define R_J11 (R_WORD|R_BYT2) /* JLH: 11 bit JMP and CALL (8051) */
142 #define R_J19 (R_WORD|R_BYT2|R_MSB) /* 19 bit JMP/CALL (DS80C390) */
143 #define R_C24 (R_WORD|R_BYT1|R_MSB) /* 24 bit address (DS80C390) */
144 #define R_J19_MASK (R_BYTE|R_BYT2|R_MSB)
146 #define IS_R_J19(x) (((x) & R_J19_MASK) == R_J19)
147 #define IS_R_J11(x) (((x) & R_J19_MASK) == R_J11)
148 #define IS_C24(x) (((x) & R_J19_MASK) == R_C24)
150 #define R_ESCAPE_MASK 0xf0 /* Used to escape relocation modes
151 * greater than 0xff in the .rel
156 * Global symbol types.
158 #define S_REF 1 /* referenced */
159 #define S_DEF 2 /* defined */
164 #define A_CON 0000 /* concatenate */
165 #define A_OVR 0004 /* overlay */
166 #define A_REL 0000 /* relocatable */
167 #define A_ABS 0010 /* absolute */
168 #define A_NOPAG 0000 /* non-paged */
169 #define A_PAG 0020 /* paged */
171 /* Additional flags for 8051 address spaces */
172 #define A_DATA 0000 /* data space (default)*/
173 #define A_CODE 0040 /* code space */
174 #define A_XDATA 0100 /* external data space */
175 #define A_BIT 0200 /* bit addressable space */
180 #define F_STD 1 /* stdin */
181 #define F_LNK 2 /* File.lnk */
182 #define F_REL 3 /* File.rel */
185 * General assembler address type
187 typedef unsigned int addr_t;
190 * The structures of head, area, areax, and sym are created
191 * as the REL files are read during the first pass of the
192 * linker. The struct head is created upon encountering a
193 * H directive in the REL file. The structure contains a
194 * link to a link file structure (struct lfile) which describes
195 * the file containing the H directive, the number of data/code
196 * areas contained in this header segment, the number of
197 * symbols referenced/defined in this header segment, a pointer
198 * to an array of pointers to areax structures (struct areax)
199 * created as each A directive is read, and a pointer to an
200 * array of pointers to symbol structures (struct sym) for
201 * all referenced/defined symbols. As H directives are read
202 * from the REL files a linked list of head structures is
203 * created by placing a link to the new head structure
204 * in the previous head structure.
208 struct head *h_hp; /* Header link */
209 struct lfile *h_lfile;/* Associated file */
210 int h_narea; /* # of areas */
211 struct areax **a_list; /* Area list */
212 int h_nglob; /* # of global symbols */
213 struct sym **s_list; /* Globle symbol list */
214 char m_id[NCPS]; /* Module name */
218 * A structure area is created for each 'unique' data/code
219 * area definition found as the REL files are read. The
220 * struct area contains the name of the area, a flag byte
221 * which contains the area attributes (REL/CON/OVR/ABS),
222 * an area subtype (not used in this assembler), and the
223 * area base address and total size which will be filled
224 * in at the end of the first pass through the REL files.
225 * As A directives are read from the REL files a linked
226 * list of unique area structures is created by placing a
227 * link to the new area structure in the previous area structure.
231 struct area *a_ap; /* Area link */
232 struct areax *a_axp; /* Area extension link */
233 addr_t a_addr; /* Beginning address of area */
234 addr_t a_size; /* Total size of the area */
235 char a_type; /* Area subtype */
236 char a_flag; /* Flag byte */
237 char a_id[NCPS]; /* Name */
241 * An areax structure is created for every A directive found
242 * while reading the REL files. The struct areax contains a
243 * link to the 'unique' area structure referenced by the A
244 * directive and to the head structure this area segment is
245 * a part of. The size of this area segment as read from the
246 * A directive is placed in the areax structure. The beginning
247 * address of this segment will be filled in at the end of the
248 * first pass through the REL files. As A directives are read
249 * from the REL files a linked list of areax structures is
250 * created for each unique area. The final areax linked
251 * list has at its head the 'unique' area structure linked
252 * to the linked areax structures (one areax structure for
253 * each A directive for this area).
257 struct areax *a_axp; /* Area extension link */
258 struct area *a_bap; /* Base area link */
259 struct head *a_bhp; /* Base header link */
260 addr_t a_addr; /* Beginning address of section */
261 addr_t a_size; /* Size of the area in section */
265 * A sym structure is created for every unique symbol
266 * referenced/defined while reading the REL files. The
267 * struct sym contains the symbol's name, a flag value
268 * (not used in this linker), a symbol type denoting
269 * referenced/defined, and an address which is loaded
270 * with the relative address within the area in which
271 * the symbol was defined. The sym structure also
272 * contains a link to the area where the symbol was defined.
273 * The sym structures are linked into linked lists using
274 * the symbol link element.
278 struct sym *s_sp; /* Symbol link */
279 struct areax *s_axp; /* Symbol area link */
280 char s_type; /* Symbol subtype */
281 char s_flag; /* Flag byte */
282 addr_t s_addr; /* Address */
283 char *s_id; /* Name: JLH change from [NCPS] */
287 * The structure lfile contains a pointer to a
288 * file specification string, the file type, and
289 * a link to the next lfile structure.
293 struct lfile *f_flp; /* lfile link */
294 int f_type; /* File type */
295 char *f_idp; /* Pointer to file spec */
299 * The struct base contains a pointer to a
300 * base definition string and a link to the next
305 struct base *b_base; /* Base link */
306 char *b_strp; /* String pointer */
310 * The struct globl contains a pointer to a
311 * global definition string and a link to the next
316 struct globl *g_globl; /* Global link */
317 char *g_strp; /* String pointer */
321 * A structure sdp is created for each 'unique' paged
322 * area definition found as the REL files are read.
323 * As P directives are read from the REL files a linked
324 * list of unique sdp structures is created by placing a
325 * link to the new sdp structure in the previous area structure.
329 struct area *s_area; /* Paged Area link */
330 struct areax *s_areax; /* Paged Area Extension Link */
331 addr_t s_addr; /* Page address offset */
335 * The structure rerr is loaded with the information
336 * required to report an error during the linking
337 * process. The structure contains an index value
338 * which selects the areax structure from the header
339 * areax structure list, a mode value which selects
340 * symbol or area relocation, the base address in the
341 * area section, an area/symbol list index value, and
342 * an area/symbol offset value.
346 int aindex; /* Linking area */
347 int mode; /* Relocation mode */
348 addr_t rtbase; /* Base address in section */
349 int rindex; /* Area/Symbol reloaction index */
350 addr_t rval; /* Area/Symbol offset value */
354 * The structure lbpath is created for each library
355 * path specification input by the -k option. The
356 * lbpath structures are linked into a list using
357 * the next link element.
365 * The structure lbname is created for all combinations of the
366 * library path specifications (input by the -k option) and the
367 * library file specifications (input by the -l option) that
368 * lead to an existing file. The element path points to
369 * the path string, element libfil points to the library
370 * file string, and the element libspc is the concatenation
371 * of the valid path and libfil strings.
373 * The lbpath structures are linked into a list
374 * using the next link element.
376 * Each library file contains a list of object files
377 * that are contained in the particular library. e.g.:
382 * Only one specification per line is allowed.
392 * The function fndsym() searches through all combinations of the
393 * library path specifications (input by the -k option) and the
394 * library file specifications (input by the -l option) that
395 * lead to an existing file for a symbol definition.
397 * The structure lbfile is created for the first library
398 * object file which contains the definition for the
399 * specified undefined symbol.
401 * The element libspc points to the library file path specification
402 * and element relfil points to the object file specification string.
403 * The element filspc is the complete path/file specification for
404 * the library file to be imported into the linker. The
405 * file specicifation may be formed in one of two ways:
407 * (1) If the library file contained an absolute
408 * path/file specification then this becomes filspc.
411 * (2) If the library file contains a relative path/file
412 * specification then the concatenation of the path
413 * and this file specification becomes filspc.
416 * The lbpath structures are linked into a list
417 * using the next link element.
427 * External Definitions for all Global Variables
430 extern char *_abs_; /* = { ". .ABS." };
432 extern int lkerr; /* ASLink error flag
434 extern char *ip; /* pointer into the REL file
437 extern char ib[NINPUT]; /* REL file text line
439 extern char *rp; /* pointer into the LST file
442 extern char rb[NINPUT]; /* LST file text line being
445 extern char ctype[]; /* array of character types, one per
450 * Character Type Definitions
463 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
464 #define DGT8 DIGIT|RAD16|RAD10|RAD8
465 #define DGT10 DIGIT|RAD16|RAD10
466 #define LTR16 LETTER|RAD16
470 extern char ccase[]; /* an array of characters which
471 * perform the case translation function
475 extern struct lfile *filep; /* The pointers (lfile *) filep,
476 * (lfile *) cfp, and (FILE *) sfp
477 * are used in conjunction with
478 * the routine getline() to read
479 * asmlnk commands from
480 * (1) the standard input or
481 * (2) or a command file
482 * and to read the REL files
483 * sequentially as defined by the
484 * asmlnk input commands.
486 * The pointer *filep points to the
487 * beginning of a linked list of
490 extern struct lfile *cfp; /* The pointer *cfp points to the
491 * current lfile structure
493 extern struct lfile *startp;/* asmlnk startup file structure
495 extern struct lfile *linkp; /* pointer to first lfile structure
496 * containing an input REL file
499 extern struct lfile *lfp; /* pointer to current lfile structure
500 * being processed by parse()
502 extern struct head *headp; /* The pointer to the first
503 * head structure of a linked list
505 extern struct head *hp; /* Pointer to the current
508 extern struct area *areap; /* The pointer to the first
509 * area structure of a linked list
511 extern struct area *ap; /* Pointer to the current
514 extern struct areax *axp; /* Pointer to the current
517 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
518 * linked symbol lists
520 extern struct base *basep; /* The pointer to the first
523 extern struct base *bsp; /* Pointer to the current
526 extern struct globl *globlp;/* The pointer to the first
529 extern struct globl *gsp; /* Pointer to the current
532 extern struct sdp sdp; /* Base Paged structure
534 extern struct rerr rerr; /* Structure containing the
535 * linker error information
537 extern FILE *ofp; /* Linker Output file handle
539 extern FILE *mfp; /* Map output file handle
541 extern FILE *jfp; /* NoICE output file handle
543 extern FILE *rfp; /* File handle for output
544 * address relocated ASxxxx
547 extern FILE *sfp; /* The file handle sfp points to the
548 * currently open file
550 extern FILE *tfp; /* File handle for input
551 * ASxxxx listing file
553 extern FILE *dfp; /* File handle for debug info output
555 extern int dflag; /* Output debug information flag
557 extern int oflag; /* Output file type flag
559 extern int mflag; /* Map output flag
561 extern int jflag; /* NoICE output flag
563 extern int xflag; /* Map file radix type flag
565 extern int pflag; /* print linker command file flag
567 extern int uflag; /* Listing relocation flag
569 extern int rflag; /* Extended linear address record flag.
571 extern int radix; /* current number conversion radix:
572 * 2 (binary), 8 (octal), 10 (decimal),
575 extern int line; /* current line number
577 extern int page; /* current page number
579 extern int lop; /* current line number on page
581 extern int pass; /* linker pass number
583 extern int rtcnt; /* count of elements in the
584 * rtval[] and rtflg[] arrays
586 extern addr_t rtval[]; /* data associated with relocation
588 extern int rtflg[]; /* indicates if rtval[] value is
589 * to be sent to the output file.
590 * (always set in this linker)
592 extern int hilo; /* REL file byte ordering
594 extern int gline; /* LST file relocation active
597 extern int gcntr; /* LST file relocation active
600 extern struct lbpath *lbphead; /* pointer to the first
601 * library path structure
603 extern struct lbname *lbnhead; /* pointer to the first
604 * library name structure
606 extern struct lbfile *lbfhead; /* pointer to the first
607 * library file structure
609 extern addr_t iram_size; /* internal ram size
613 /* C Library function definitions */
614 /* for reference only
617 extern char * fgets();
618 extern FILE * fopen();
619 extern int fprintf();
621 extern VOID * malloc();
623 extern char * strcpy();
625 extern char * strncpy();
628 /* Program function definitions */
631 extern FILE * afile();
632 extern VOID bassav();
633 extern VOID gblsav();
634 extern VOID iramsav();
635 extern VOID iramcheck();
636 extern VOID link_main();
637 extern VOID lkexit();
641 extern VOID setbas();
642 extern VOID setgbl();
644 extern VOID copyfile();
647 extern char endline();
649 extern VOID getfid();
651 extern int getline();
659 extern VOID lkparea();
660 extern VOID lnkarea();
661 extern VOID lnksect();
662 extern VOID newarea();
665 extern VOID module();
666 extern VOID newhead();
670 extern struct sym * lkpsym();
672 extern struct sym * newsym();
673 extern VOID symdef();
675 extern VOID syminit();
676 extern VOID symmod();
677 extern addr_t symval();
681 extern addr_t eval();
682 extern addr_t expr();
684 extern addr_t term();
688 extern VOID lkulist();
689 extern VOID lkalist();
690 extern VOID lkglist();
691 extern VOID lstarea();
692 extern VOID newpag();
696 extern addr_t adb_b();
697 extern addr_t adb_hi();
698 extern addr_t adb_lo();
699 extern addr_t adb_24_hi(addr_t v, int i);
700 extern addr_t adb_24_mid(addr_t v, int i);
701 extern addr_t adb_24_lo(addr_t v, int i);
702 extern addr_t adw_w();
703 extern addr_t adw_24(addr_t, int);
704 extern addr_t adw_hi();
705 extern addr_t adw_lo();
706 extern addr_t evword();
712 extern VOID relerr();
713 extern char * errmsg[];
714 extern VOID errdmp();
715 extern VOID relerp();
716 extern VOID erpdmp();
717 extern VOID prntval();
718 extern int lastExtendedAddress;
721 extern VOID addfile();
722 extern VOID addlib();
723 extern VOID addpath();
725 extern VOID library();
726 extern VOID loadfile();
727 extern VOID search();
734 extern VOID ihxEntendedLinearAddress(addr_t);
736 extern char *StoreString( char *str );
739 extern void DefineNoICE( char *name, addr_t value, int page );
741 /* SD added this to change
742 strcmpi --> strcmp (strcmpi NOT ANSI) */
743 #define strcmpi strcmp