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 FILENAME_MAX /* Input buffer size (BH: change from 128) */
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 */
96 * The "R_" relocation constants define values used in
97 * generating the assembler relocation output data for
98 * areas, symbols, and code.
104 * +-----+-----+-----+-----+-----+-----+-----+-----+
105 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
106 * +-----+-----+-----+-----+-----+-----+-----+-----+
109 #define R_WORD 0x00 /* 16 bit */
110 #define R_BYTE 0x01 /* 8 bit */
112 #define R_AREA 0x00 /* Base type */
115 #define R_NORM 0x00 /* PC adjust */
118 #define R_BYT1 0x00 /* Byte count for R_BYTE = 1 */
119 #define R_BYT2 0x08 /* Byte count for R_BYTE = 2 */
121 #define R_SGND 0x00 /* Signed Byte */
122 #define R_USGN 0x10 /* Unsigned Byte */
124 #define R_NOPAG 0x00 /* Page Mode */
125 #define R_PAG0 0x20 /* Page '0' */
126 #define R_PAG 0x40 /* Page 'nnn' */
128 #define R_LSB 0x00 /* low byte */
129 #define R_MSB 0x80 /* high byte */
131 #define R_BYT3 0x100 /* if R_BYTE is set, this is a
132 * 3 byte address, of which
133 * the linker must select one byte.
135 #define R_HIB 0x200 /* If R_BYTE & R_BYT3 are set, linker
136 * will select byte 3 of the relocated
140 #define R_J11 (R_WORD|R_BYT2) /* JLH: 11 bit JMP and CALL (8051) */
141 #define R_J19 (R_WORD|R_BYT2|R_MSB) /* 19 bit JMP/CALL (DS80C390) */
142 #define R_C24 (R_WORD|R_BYT1|R_MSB) /* 24 bit address (DS80C390) */
143 #define R_J19_MASK (R_BYTE|R_BYT2|R_MSB)
145 #define IS_R_J19(x) (((x) & R_J19_MASK) == R_J19)
146 #define IS_R_J11(x) (((x) & R_J19_MASK) == R_J11)
147 #define IS_C24(x) (((x) & R_J19_MASK) == R_C24)
149 #define R_ESCAPE_MASK 0xf0 /* Used to escape relocation modes
150 * greater than 0xff in the .rel
155 * Global symbol types.
157 #define S_REF 1 /* referenced */
158 #define S_DEF 2 /* defined */
163 #define A_CON 0000 /* concatenate */
164 #define A_OVR 0004 /* overlay */
165 #define A_REL 0000 /* relocatable */
166 #define A_ABS 0010 /* absolute */
167 #define A_NOPAG 0000 /* non-paged */
168 #define A_PAG 0020 /* paged */
170 /* Additional flags for 8051 address spaces */
171 #define A_DATA 0000 /* data space (default)*/
172 #define A_CODE 0040 /* code space */
173 #define A_XDATA 0100 /* external data space */
174 #define A_BIT 0200 /* bit addressable space */
179 #define F_STD 1 /* stdin */
180 #define F_LNK 2 /* File.lnk */
181 #define F_REL 3 /* File.rel */
184 * General assembler address type
186 typedef unsigned int Addr_T;
189 * The structures of head, area, areax, and sym are created
190 * as the REL files are read during the first pass of the
191 * linker. The struct head is created upon encountering a
192 * H directive in the REL file. The structure contains a
193 * link to a link file structure (struct lfile) which describes
194 * the file containing the H directive, the number of data/code
195 * areas contained in this header segment, the number of
196 * symbols referenced/defined in this header segment, a pointer
197 * to an array of pointers to areax structures (struct areax)
198 * created as each A directive is read, and a pointer to an
199 * array of pointers to symbol structures (struct sym) for
200 * all referenced/defined symbols. As H directives are read
201 * from the REL files a linked list of head structures is
202 * created by placing a link to the new head structure
203 * in the previous head structure.
207 struct head *h_hp; /* Header link */
208 struct lfile *h_lfile;/* Associated file */
209 int h_narea; /* # of areas */
210 struct areax **a_list; /* Area list */
211 int h_nglob; /* # of global symbols */
212 struct sym **s_list; /* Globle symbol list */
213 char m_id[NCPS]; /* Module name */
217 * A structure area is created for each 'unique' data/code
218 * area definition found as the REL files are read. The
219 * struct area contains the name of the area, a flag byte
220 * which contains the area attributes (REL/CON/OVR/ABS),
221 * an area subtype (not used in this assembler), and the
222 * area base address and total size which will be filled
223 * in at the end of the first pass through the REL files.
224 * As A directives are read from the REL files a linked
225 * list of unique area structures is created by placing a
226 * link to the new area structure in the previous area structure.
230 struct area *a_ap; /* Area link */
231 struct areax *a_axp; /* Area extension link */
232 Addr_T a_addr; /* Beginning address of area */
233 Addr_T a_size; /* Total size of the area */
234 char a_type; /* Area subtype */
235 char a_flag; /* Flag byte */
236 char a_id[NCPS]; /* Name */
240 * An areax structure is created for every A directive found
241 * while reading the REL files. The struct areax contains a
242 * link to the 'unique' area structure referenced by the A
243 * directive and to the head structure this area segment is
244 * a part of. The size of this area segment as read from the
245 * A directive is placed in the areax structure. The beginning
246 * address of this segment will be filled in at the end of the
247 * first pass through the REL files. As A directives are read
248 * from the REL files a linked list of areax structures is
249 * created for each unique area. The final areax linked
250 * list has at its head the 'unique' area structure linked
251 * to the linked areax structures (one areax structure for
252 * each A directive for this area).
256 struct areax *a_axp; /* Area extension link */
257 struct area *a_bap; /* Base area link */
258 struct head *a_bhp; /* Base header link */
259 Addr_T a_addr; /* Beginning address of section */
260 Addr_T a_size; /* Size of the area in section */
264 * A sym structure is created for every unique symbol
265 * referenced/defined while reading the REL files. The
266 * struct sym contains the symbol's name, a flag value
267 * (not used in this linker), a symbol type denoting
268 * referenced/defined, and an address which is loaded
269 * with the relative address within the area in which
270 * the symbol was defined. The sym structure also
271 * contains a link to the area where the symbol was defined.
272 * The sym structures are linked into linked lists using
273 * the symbol link element.
277 struct sym *s_sp; /* Symbol link */
278 struct areax *s_axp; /* Symbol area link */
279 char s_type; /* Symbol subtype */
280 char s_flag; /* Flag byte */
281 Addr_T s_addr; /* Address */
282 char *s_id; /* Name: JLH change from [NCPS] */
286 * The structure lfile contains a pointer to a
287 * file specification string, the file type, and
288 * a link to the next lfile structure.
292 struct lfile *f_flp; /* lfile link */
293 int f_type; /* File type */
294 char *f_idp; /* Pointer to file spec */
298 * The struct base contains a pointer to a
299 * base definition string and a link to the next
304 struct base *b_base; /* Base link */
305 char *b_strp; /* String pointer */
309 * The struct globl contains a pointer to a
310 * global definition string and a link to the next
315 struct globl *g_globl; /* Global link */
316 char *g_strp; /* String pointer */
320 * A structure sdp is created for each 'unique' paged
321 * area definition found as the REL files are read.
322 * As P directives are read from the REL files a linked
323 * list of unique sdp structures is created by placing a
324 * link to the new sdp structure in the previous area structure.
328 struct area *s_area; /* Paged Area link */
329 struct areax *s_areax; /* Paged Area Extension Link */
330 Addr_T s_addr; /* Page address offset */
334 * The structure rerr is loaded with the information
335 * required to report an error during the linking
336 * process. The structure contains an index value
337 * which selects the areax structure from the header
338 * areax structure list, a mode value which selects
339 * symbol or area relocation, the base address in the
340 * area section, an area/symbol list index value, and
341 * an area/symbol offset value.
345 int aindex; /* Linking area */
346 int mode; /* Relocation mode */
347 Addr_T rtbase; /* Base address in section */
348 int rindex; /* Area/Symbol reloaction index */
349 Addr_T rval; /* Area/Symbol offset value */
353 * The structure lbpath is created for each library
354 * path specification input by the -k option. The
355 * lbpath structures are linked into a list using
356 * the next link element.
364 * The structure lbname is created for all combinations of the
365 * library path specifications (input by the -k option) and the
366 * library file specifications (input by the -l option) that
367 * lead to an existing file. The element path points to
368 * the path string, element libfil points to the library
369 * file string, and the element libspc is the concatenation
370 * of the valid path and libfil strings.
372 * The lbpath structures are linked into a list
373 * using the next link element.
375 * Each library file contains a list of object files
376 * that are contained in the particular library. e.g.:
381 * Only one specification per line is allowed.
391 * The function fndsym() searches through all combinations of the
392 * library path specifications (input by the -k option) and the
393 * library file specifications (input by the -l option) that
394 * lead to an existing file for a symbol definition.
396 * The structure lbfile is created for the first library
397 * object file which contains the definition for the
398 * specified undefined symbol.
400 * The element libspc points to the library file path specification
401 * and element relfil points to the object file specification string.
402 * The element filspc is the complete path/file specification for
403 * the library file to be imported into the linker. The
404 * file specicifation may be formed in one of two ways:
406 * (1) If the library file contained an absolute
407 * path/file specification then this becomes filspc.
410 * (2) If the library file contains a relative path/file
411 * specification then the concatenation of the path
412 * and this file specification becomes filspc.
415 * The lbpath structures are linked into a list
416 * using the next link element.
426 * External Definitions for all Global Variables
429 extern char *_abs_; /* = { ". .ABS." };
431 extern int lkerr; /* ASLink error flag
433 extern char *ip; /* pointer into the REL file
436 extern char ib[NINPUT]; /* REL file text line
438 extern char *rp; /* pointer into the LST file
441 extern char rb[NINPUT]; /* LST file text line being
444 extern char ctype[]; /* array of character types, one per
449 * Character Type Definitions
462 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
463 #define DGT8 DIGIT|RAD16|RAD10|RAD8
464 #define DGT10 DIGIT|RAD16|RAD10
465 #define LTR16 LETTER|RAD16
469 extern char ccase[]; /* an array of characters which
470 * perform the case translation function
474 extern struct lfile *filep; /* The pointers (lfile *) filep,
475 * (lfile *) cfp, and (FILE *) sfp
476 * are used in conjunction with
477 * the routine getline() to read
478 * asmlnk commands from
479 * (1) the standard input or
480 * (2) or a command file
481 * and to read the REL files
482 * sequentially as defined by the
483 * asmlnk input commands.
485 * The pointer *filep points to the
486 * beginning of a linked list of
489 extern struct lfile *cfp; /* The pointer *cfp points to the
490 * current lfile structure
492 extern struct lfile *startp;/* asmlnk startup file structure
494 extern struct lfile *linkp; /* pointer to first lfile structure
495 * containing an input REL file
498 extern struct lfile *lfp; /* pointer to current lfile structure
499 * being processed by parse()
501 extern struct head *headp; /* The pointer to the first
502 * head structure of a linked list
504 extern struct head *hp; /* Pointer to the current
507 extern struct area *areap; /* The pointer to the first
508 * area structure of a linked list
510 extern struct area *ap; /* Pointer to the current
513 extern struct areax *axp; /* Pointer to the current
516 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
517 * linked symbol lists
519 extern struct base *basep; /* The pointer to the first
522 extern struct base *bsp; /* Pointer to the current
525 extern struct globl *globlp;/* The pointer to the first
528 extern struct globl *gsp; /* Pointer to the current
531 extern struct sdp sdp; /* Base Paged structure
533 extern struct rerr rerr; /* Structure containing the
534 * linker error information
536 extern FILE *ofp; /* Linker Output file handle
538 extern FILE *mfp; /* Map output file handle
540 extern FILE *jfp; /* NoICE output file handle
542 extern FILE *rfp; /* File handle for output
543 * address relocated ASxxxx
546 extern FILE *sfp; /* The file handle sfp points to the
547 * currently open file
549 extern FILE *tfp; /* File handle for input
550 * ASxxxx listing file
552 extern FILE *dfp; /* File handle for debug info output
554 extern int dflag; /* Output debug information flag
556 extern int oflag; /* Output file type flag
558 extern int mflag; /* Map output flag
560 extern int jflag; /* NoICE output flag
562 extern int xflag; /* Map file radix type flag
564 extern int pflag; /* print linker command file flag
566 extern int uflag; /* Listing relocation flag
568 extern int rflag; /* Extended linear address record flag.
570 extern int radix; /* current number conversion radix:
571 * 2 (binary), 8 (octal), 10 (decimal),
574 extern int line; /* current line number
576 extern int page; /* current page number
578 extern int lop; /* current line number on page
580 extern int pass; /* linker pass number
582 extern int rtcnt; /* count of elements in the
583 * rtval[] and rtflg[] arrays
585 extern Addr_T rtval[]; /* data associated with relocation
587 extern int rtflg[]; /* indicates if rtval[] value is
588 * to be sent to the output file.
589 * (always set in this linker)
591 extern int hilo; /* REL file byte ordering
593 extern int gline; /* LST file relocation active
596 extern int gcntr; /* LST file relocation active
599 extern struct lbpath *lbphead; /* pointer to the first
600 * library path structure
602 extern struct lbname *lbnhead; /* pointer to the first
603 * library name structure
605 extern struct lbfile *lbfhead; /* pointer to the first
606 * library file structure
608 extern Addr_T iram_size; /* internal ram size
612 /* C Library function definitions */
613 /* for reference only
616 extern char * fgets();
617 extern FILE * fopen();
618 extern int fprintf();
620 extern VOID * malloc();
622 extern char * strcpy();
624 extern char * strncpy();
627 /* Program function definitions */
630 extern FILE * afile();
631 extern VOID bassav();
632 extern VOID gblsav();
633 extern VOID iramsav();
634 extern VOID iramcheck();
635 extern VOID link_main();
636 extern VOID lkexit();
640 extern VOID setbas();
641 extern VOID setgbl();
643 extern VOID copyfile();
646 extern char endline();
648 extern VOID getfid();
650 extern VOID getSid();
651 extern int getline();
657 extern VOID chop_crlf();
660 extern VOID lkparea();
661 extern VOID lnkarea();
662 extern VOID lnksect();
663 extern VOID newarea();
666 extern VOID module();
667 extern VOID newhead();
671 extern struct sym * lkpsym();
673 extern struct sym * newsym();
674 extern VOID symdef();
676 extern VOID syminit();
677 extern VOID symmod();
678 extern Addr_T symval();
682 extern Addr_T eval();
683 extern Addr_T expr();
685 extern Addr_T term();
689 extern VOID lkulist();
690 extern VOID lkalist();
691 extern VOID lkglist();
692 extern VOID lstarea();
693 extern VOID newpag();
697 extern Addr_T adb_b();
698 extern Addr_T adb_hi();
699 extern Addr_T adb_lo();
700 extern Addr_T adb_24_hi(Addr_T v, int i);
701 extern Addr_T adb_24_mid(Addr_T v, int i);
702 extern Addr_T adb_24_lo(Addr_T v, int i);
703 extern Addr_T adw_w();
704 extern Addr_T adw_24(Addr_T, int);
705 extern Addr_T adw_hi();
706 extern Addr_T adw_lo();
707 extern Addr_T evword();
713 extern VOID relerr();
714 extern char * errmsg[];
715 extern VOID errdmp();
716 extern VOID relerp();
717 extern VOID erpdmp();
718 extern VOID prntval();
719 extern int lastExtendedAddress;
722 extern VOID addfile();
723 extern VOID addlib();
724 extern VOID addpath();
726 extern VOID library();
727 extern VOID loadfile();
728 extern VOID search();
735 extern VOID ihxEntendedLinearAddress(Addr_T);
737 extern char *StoreString( char *str );
740 extern void DefineNoICE( char *name, Addr_T value, int page );
742 /* SD added this to change
743 strcmpi --> strcmp (strcmpi NOT ANSI) */
744 #define strcmpi strcmp