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 0000 /* 16 bit */
111 #define R_BYTE 0001 /* 8 bit */
113 #define R_AREA 0000 /* Base type */
116 #define R_NORM 0000 /* PC adjust */
119 #define R_BYT1 0000 /* Byte count for R_BYTE = 1 */
120 #define R_BYT2 0010 /* Byte count for R_BYTE = 2 */
122 #define R_SGND 0000 /* Signed value */
123 #define R_USGN 0020 /* Unsigned value */
125 #define R_NOPAG 0000 /* Page Mode */
126 #define R_PAG0 0040 /* Page '0' */
127 #define R_PAG 0100 /* Page 'nnn' */
132 #define R_LSB 0000 /* output low byte */
133 #define R_MSB 0200 /* output high byte */
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)
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)
145 * Global symbol types.
147 #define S_REF 1 /* referenced */
148 #define S_DEF 2 /* defined */
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 */
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 */
169 #define F_STD 1 /* stdin */
170 #define F_LNK 2 /* File.lnk */
171 #define F_REL 3 /* File.rel */
174 * General assembler address type
176 typedef unsigned int addr_t;
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.
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 */
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.
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 */
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).
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 */
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.
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] */
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.
282 struct lfile *f_flp; /* lfile link */
283 int f_type; /* File type */
284 char *f_idp; /* Pointer to file spec */
288 * The struct base contains a pointer to a
289 * base definition string and a link to the next
294 struct base *b_base; /* Base link */
295 char *b_strp; /* String pointer */
299 * The struct globl contains a pointer to a
300 * global definition string and a link to the next
305 struct globl *g_globl; /* Global link */
306 char *g_strp; /* String pointer */
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.
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 */
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.
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 */
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.
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.
362 * The lbpath structures are linked into a list
363 * using the next link element.
365 * Each library file contains a list of object files
366 * that are contained in the particular library. e.g.:
371 * Only one specification per line is allowed.
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.
386 * The structure lbfile is created for the first library
387 * object file which contains the definition for the
388 * specified undefined symbol.
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:
396 * (1) If the library file contained an absolute
397 * path/file specification then this becomes filspc.
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.
405 * The lbpath structures are linked into a list
406 * using the next link element.
416 * External Definitions for all Global Variables
419 extern char *_abs_; /* = { ". .ABS." };
421 extern int lkerr; /* ASLink error flag
423 extern char *ip; /* pointer into the REL file
426 extern char ib[NINPUT]; /* REL file text line
428 extern char *rp; /* pointer into the LST file
431 extern char rb[NINPUT]; /* LST file text line being
434 extern char ctype[]; /* array of character types, one per
439 * Character Type Definitions
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
459 extern char ccase[]; /* an array of characters which
460 * perform the case translation function
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.
475 * The pointer *filep points to the
476 * beginning of a linked list of
479 extern struct lfile *cfp; /* The pointer *cfp points to the
480 * current lfile structure
482 extern struct lfile *startp;/* asmlnk startup file structure
484 extern struct lfile *linkp; /* pointer to first lfile structure
485 * containing an input REL file
488 extern struct lfile *lfp; /* pointer to current lfile structure
489 * being processed by parse()
491 extern struct head *headp; /* The pointer to the first
492 * head structure of a linked list
494 extern struct head *hp; /* Pointer to the current
497 extern struct area *areap; /* The pointer to the first
498 * area structure of a linked list
500 extern struct area *ap; /* Pointer to the current
503 extern struct areax *axp; /* Pointer to the current
506 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
507 * linked symbol lists
509 extern struct base *basep; /* The pointer to the first
512 extern struct base *bsp; /* Pointer to the current
515 extern struct globl *globlp;/* The pointer to the first
518 extern struct globl *gsp; /* Pointer to the current
521 extern struct sdp sdp; /* Base Paged structure
523 extern struct rerr rerr; /* Structure containing the
524 * linker error information
526 extern FILE *ofp; /* Linker Output file handle
528 extern FILE *mfp; /* Map output file handle
530 extern FILE *jfp; /* NoICE output file handle
532 extern FILE *rfp; /* File handle for output
533 * address relocated ASxxxx
536 extern FILE *sfp; /* The file handle sfp points to the
537 * currently open file
539 extern FILE *tfp; /* File handle for input
540 * ASxxxx listing file
542 extern FILE *dfp; /* File handle for debug info output
544 extern int dflag; /* Output debug information flag
546 extern int oflag; /* Output file type flag
548 extern int mflag; /* Map output flag
550 extern int jflag; /* NoICE output flag
552 extern int xflag; /* Map file radix type flag
554 extern int pflag; /* print linker command file flag
556 extern int uflag; /* Listing relocation flag
558 extern int rflag; /* Extended linear address record flag.
560 extern int radix; /* current number conversion radix:
561 * 2 (binary), 8 (octal), 10 (decimal),
564 extern int line; /* current line number
566 extern int page; /* current page number
568 extern int lop; /* current line number on page
570 extern int pass; /* linker pass number
572 extern int rtcnt; /* count of elements in the
573 * rtval[] and rtflg[] arrays
575 extern addr_t rtval[]; /* data associated with relocation
577 extern int rtflg[]; /* indicates if rtval[] value is
578 * to be sent to the output file.
579 * (always set in this linker)
581 extern int hilo; /* REL file byte ordering
583 extern int gline; /* LST file relocation active
586 extern int gcntr; /* LST file relocation active
589 extern struct lbpath *lbphead; /* pointer to the first
590 * library path structure
592 extern struct lbname *lbnhead; /* pointer to the first
593 * library name structure
595 extern struct lbfile *lbfhead; /* pointer to the first
596 * library file structure
598 extern addr_t iram_size; /* internal ram size
602 /* C Library function definitions */
603 /* for reference only
606 extern char * fgets();
607 extern FILE * fopen();
608 extern int fprintf();
610 extern VOID * malloc();
612 extern char * strcpy();
614 extern char * strncpy();
617 /* Program function definitions */
620 extern FILE * afile();
621 extern VOID bassav();
622 extern VOID gblsav();
623 extern VOID iramsav();
624 extern VOID iramcheck();
626 extern VOID lkexit();
630 extern VOID setbas();
631 extern VOID setgbl();
633 extern VOID copyfile();
636 extern char endline();
638 extern VOID getfid();
640 extern int getline();
648 extern VOID lkparea();
649 extern VOID lnkarea();
650 extern VOID lnksect();
651 extern VOID newarea();
654 extern VOID module();
655 extern VOID newhead();
659 extern struct sym * lkpsym();
661 extern struct sym * newsym();
662 extern VOID symdef();
664 extern VOID syminit();
665 extern VOID symmod();
666 extern addr_t symval();
670 extern addr_t eval();
671 extern addr_t expr();
673 extern addr_t term();
677 extern VOID lkulist();
678 extern VOID lkalist();
679 extern VOID lkglist();
680 extern VOID lstarea();
681 extern VOID newpag();
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();
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;
707 extern VOID addfile();
708 extern VOID addlib();
709 extern VOID addpath();
711 extern VOID library();
712 extern VOID loadfile();
713 extern VOID search();
720 extern VOID ihxEntendedLinearAddress(addr_t);
722 extern char *StoreString( char *str );
725 extern void DefineNoICE( char *name, addr_t value, int page );
727 /* SD added this to change
728 strcmpi --> strcmp (strcmpi NOT ANSI) */
729 #define strcmpi strcmp