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 */
86 #ifndef PATH_MAX /* POSIX, but not required */
87 #define PATH_MAX 255 /* define a reasonable value */
91 * This file defines the format of the
92 * relocatable binary file.
95 #define NCPS 80 /* characters per symbol (JLH: change from 8) */
96 #define NDATA 16 /* actual data */
97 #define NINPUT PATH_MAX /* Input buffer size */
98 #define NHASH 64 /* Buckets in hash table */
99 #define HMASK 077 /* Hash mask */
100 #define NLPP 60 /* Lines per page */
101 #define NTXT 16 /* T values */
104 * The "R_" relocation constants define values used in
105 * generating the assembler relocation output data for
106 * areas, symbols, and code.
112 * +-----+-----+-----+-----+-----+-----+-----+-----+
113 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
114 * +-----+-----+-----+-----+-----+-----+-----+-----+
117 #define R_WORD 0x00 /* 16 bit */
118 #define R_BYTE 0x01 /* 8 bit */
120 #define R_AREA 0x00 /* Base type */
123 #define R_NORM 0x00 /* PC adjust */
126 #define R_BYT1 0x00 /* Byte count for R_BYTE = 1 */
127 #define R_BYT2 0x08 /* Byte count for R_BYTE = 2 */
129 #define R_SGND 0x00 /* Signed Byte */
130 #define R_USGN 0x10 /* Unsigned Byte */
132 #define R_NOPAG 0x00 /* Page Mode */
133 #define R_PAG0 0x20 /* Page '0' */
134 #define R_PAG 0x40 /* Page 'nnn' */
136 #define R_LSB 0x00 /* low byte */
137 #define R_MSB 0x80 /* high byte */
139 #define R_BYT3 0x100 /* if R_BYTE is set, this is a
140 * 3 byte address, of which
141 * the linker must select one byte.
143 #define R_HIB 0x200 /* If R_BYTE & R_BYT3 are set, linker
144 * will select byte 3 of the relocated
148 #define R_J11 (R_WORD|R_BYT2) /* JLH: 11 bit JMP and CALL (8051) */
149 #define R_J19 (R_WORD|R_BYT2|R_MSB) /* 19 bit JMP/CALL (DS80C390) */
150 #define R_C24 (R_WORD|R_BYT1|R_MSB) /* 24 bit address (DS80C390) */
151 #define R_J19_MASK (R_BYTE|R_BYT2|R_MSB)
153 #define IS_R_J19(x) (((x) & R_J19_MASK) == R_J19)
154 #define IS_R_J11(x) (((x) & R_J19_MASK) == R_J11)
155 #define IS_C24(x) (((x) & R_J19_MASK) == R_C24)
157 #define R_ESCAPE_MASK 0xf0 /* Used to escape relocation modes
158 * greater than 0xff in the .rel
163 * Global symbol types.
165 #define S_REF 1 /* referenced */
166 #define S_DEF 2 /* defined */
171 #define A_CON 0000 /* concatenate */
172 #define A_OVR 0004 /* overlay */
173 #define A_REL 0000 /* relocatable */
174 #define A_ABS 0010 /* absolute */
175 #define A_NOPAG 0000 /* non-paged */
176 #define A_PAG 0020 /* paged */
178 /* Additional flags for 8051 address spaces */
179 #define A_DATA 0000 /* data space (default)*/
180 #define A_CODE 0040 /* code space */
181 #define A_XDATA 0100 /* external data space */
182 #define A_BIT 0200 /* bit addressable space */
187 #define F_STD 1 /* stdin */
188 #define F_LNK 2 /* File.lnk */
189 #define F_REL 3 /* File.rel */
192 * General assembler address type
194 typedef unsigned int Addr_T;
197 * The structures of head, area, areax, and sym are created
198 * as the REL files are read during the first pass of the
199 * linker. The struct head is created upon encountering a
200 * H directive in the REL file. The structure contains a
201 * link to a link file structure (struct lfile) which describes
202 * the file containing the H directive, the number of data/code
203 * areas contained in this header segment, the number of
204 * symbols referenced/defined in this header segment, a pointer
205 * to an array of pointers to areax structures (struct areax)
206 * created as each A directive is read, and a pointer to an
207 * array of pointers to symbol structures (struct sym) for
208 * all referenced/defined symbols. As H directives are read
209 * from the REL files a linked list of head structures is
210 * created by placing a link to the new head structure
211 * in the previous head structure.
215 struct head *h_hp; /* Header link */
216 struct lfile *h_lfile;/* Associated file */
217 int h_narea; /* # of areas */
218 struct areax **a_list; /* Area list */
219 int h_nglob; /* # of global symbols */
220 struct sym **s_list; /* Globle symbol list */
221 char m_id[NCPS]; /* Module name */
225 * A structure area is created for each 'unique' data/code
226 * area definition found as the REL files are read. The
227 * struct area contains the name of the area, a flag byte
228 * which contains the area attributes (REL/CON/OVR/ABS),
229 * an area subtype (not used in this assembler), and the
230 * area base address and total size which will be filled
231 * in at the end of the first pass through the REL files.
232 * As A directives are read from the REL files a linked
233 * list of unique area structures is created by placing a
234 * link to the new area structure in the previous area structure.
238 struct area *a_ap; /* Area link */
239 struct areax *a_axp; /* Area extension link */
240 Addr_T a_addr; /* Beginning address of area */
241 Addr_T a_size; /* Total size of the area */
242 char a_type; /* Area subtype */
243 char a_flag; /* Flag byte */
244 char a_id[NCPS]; /* Name */
248 * An areax structure is created for every A directive found
249 * while reading the REL files. The struct areax contains a
250 * link to the 'unique' area structure referenced by the A
251 * directive and to the head structure this area segment is
252 * a part of. The size of this area segment as read from the
253 * A directive is placed in the areax structure. The beginning
254 * address of this segment will be filled in at the end of the
255 * first pass through the REL files. As A directives are read
256 * from the REL files a linked list of areax structures is
257 * created for each unique area. The final areax linked
258 * list has at its head the 'unique' area structure linked
259 * to the linked areax structures (one areax structure for
260 * each A directive for this area).
264 struct areax *a_axp; /* Area extension link */
265 struct area *a_bap; /* Base area link */
266 struct head *a_bhp; /* Base header link */
267 Addr_T a_addr; /* Beginning address of section */
268 Addr_T a_size; /* Size of the area in section */
272 * A sym structure is created for every unique symbol
273 * referenced/defined while reading the REL files. The
274 * struct sym contains the symbol's name, a flag value
275 * (not used in this linker), a symbol type denoting
276 * referenced/defined, and an address which is loaded
277 * with the relative address within the area in which
278 * the symbol was defined. The sym structure also
279 * contains a link to the area where the symbol was defined.
280 * The sym structures are linked into linked lists using
281 * the symbol link element.
285 struct sym *s_sp; /* Symbol link */
286 struct areax *s_axp; /* Symbol area link */
287 char s_type; /* Symbol subtype */
288 char s_flag; /* Flag byte */
289 Addr_T s_addr; /* Address */
290 char *s_id; /* Name: JLH change from [NCPS] */
294 * The structure lfile contains a pointer to a
295 * file specification string, the file type, and
296 * a link to the next lfile structure.
300 struct lfile *f_flp; /* lfile link */
301 int f_type; /* File type */
302 char *f_idp; /* Pointer to file spec */
306 * The struct base contains a pointer to a
307 * base definition string and a link to the next
312 struct base *b_base; /* Base link */
313 char *b_strp; /* String pointer */
317 * The struct globl contains a pointer to a
318 * global definition string and a link to the next
323 struct globl *g_globl; /* Global link */
324 char *g_strp; /* String pointer */
328 * A structure sdp is created for each 'unique' paged
329 * area definition found as the REL files are read.
330 * As P directives are read from the REL files a linked
331 * list of unique sdp structures is created by placing a
332 * link to the new sdp structure in the previous area structure.
336 struct area *s_area; /* Paged Area link */
337 struct areax *s_areax; /* Paged Area Extension Link */
338 Addr_T s_addr; /* Page address offset */
342 * The structure rerr is loaded with the information
343 * required to report an error during the linking
344 * process. The structure contains an index value
345 * which selects the areax structure from the header
346 * areax structure list, a mode value which selects
347 * symbol or area relocation, the base address in the
348 * area section, an area/symbol list index value, and
349 * an area/symbol offset value.
353 int aindex; /* Linking area */
354 int mode; /* Relocation mode */
355 Addr_T rtbase; /* Base address in section */
356 int rindex; /* Area/Symbol reloaction index */
357 Addr_T rval; /* Area/Symbol offset value */
361 * The structure lbpath is created for each library
362 * path specification input by the -k option. The
363 * lbpath structures are linked into a list using
364 * the next link element.
372 * The structure lbname is created for all combinations of the
373 * library path specifications (input by the -k option) and the
374 * library file specifications (input by the -l option) that
375 * lead to an existing file. The element path points to
376 * the path string, element libfil points to the library
377 * file string, and the element libspc is the concatenation
378 * of the valid path and libfil strings.
380 * The lbpath structures are linked into a list
381 * using the next link element.
383 * Each library file contains a list of object files
384 * that are contained in the particular library. e.g.:
389 * Only one specification per line is allowed.
399 * The function fndsym() searches through all combinations of the
400 * library path specifications (input by the -k option) and the
401 * library file specifications (input by the -l option) that
402 * lead to an existing file for a symbol definition.
404 * The structure lbfile is created for the first library
405 * object file which contains the definition for the
406 * specified undefined symbol.
408 * The element libspc points to the library file path specification
409 * and element relfil points to the object file specification string.
410 * The element filspc is the complete path/file specification for
411 * the library file to be imported into the linker. The
412 * file specicifation may be formed in one of two ways:
414 * (1) If the library file contained an absolute
415 * path/file specification then this becomes filspc.
418 * (2) If the library file contains a relative path/file
419 * specification then the concatenation of the path
420 * and this file specification becomes filspc.
423 * The lbpath structures are linked into a list
424 * using the next link element.
434 * External Definitions for all Global Variables
437 extern char *_abs_; /* = { ". .ABS." };
439 extern int lkerr; /* ASLink error flag
441 extern char *ip; /* pointer into the REL file
444 extern char ib[NINPUT]; /* REL file text line
446 extern char *rp; /* pointer into the LST file
449 extern char rb[NINPUT]; /* LST file text line being
452 extern char ctype[]; /* array of character types, one per
457 * Character Type Definitions
470 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
471 #define DGT8 DIGIT|RAD16|RAD10|RAD8
472 #define DGT10 DIGIT|RAD16|RAD10
473 #define LTR16 LETTER|RAD16
477 extern char ccase[]; /* an array of characters which
478 * perform the case translation function
482 extern struct lfile *filep; /* The pointers (lfile *) filep,
483 * (lfile *) cfp, and (FILE *) sfp
484 * are used in conjunction with
485 * the routine getline() to read
486 * asmlnk commands from
487 * (1) the standard input or
488 * (2) or a command file
489 * and to read the REL files
490 * sequentially as defined by the
491 * asmlnk input commands.
493 * The pointer *filep points to the
494 * beginning of a linked list of
497 extern struct lfile *cfp; /* The pointer *cfp points to the
498 * current lfile structure
500 extern struct lfile *startp;/* asmlnk startup file structure
502 extern struct lfile *linkp; /* pointer to first lfile structure
503 * containing an input REL file
506 extern struct lfile *lfp; /* pointer to current lfile structure
507 * being processed by parse()
509 extern struct head *headp; /* The pointer to the first
510 * head structure of a linked list
512 extern struct head *hp; /* Pointer to the current
515 extern struct area *areap; /* The pointer to the first
516 * area structure of a linked list
518 extern struct area *ap; /* Pointer to the current
521 extern struct areax *axp; /* Pointer to the current
524 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
525 * linked symbol lists
527 extern struct base *basep; /* The pointer to the first
530 extern struct base *bsp; /* Pointer to the current
533 extern struct globl *globlp;/* The pointer to the first
536 extern struct globl *gsp; /* Pointer to the current
539 extern struct sdp sdp; /* Base Paged structure
541 extern struct rerr rerr; /* Structure containing the
542 * linker error information
544 extern FILE *ofp; /* Linker Output file handle
546 extern FILE *mfp; /* Map output file handle
548 extern FILE *jfp; /* NoICE output file handle
550 extern FILE *rfp; /* File handle for output
551 * address relocated ASxxxx
554 extern FILE *sfp; /* The file handle sfp points to the
555 * currently open file
557 extern FILE *tfp; /* File handle for input
558 * ASxxxx listing file
560 extern FILE *dfp; /* File handle for debug info output
562 extern int dflag; /* Output debug information flag
564 extern int oflag; /* Output file type flag
566 extern int mflag; /* Map output flag
568 extern int sflag; /* JCF: Memory usage output flag
570 extern int jflag; /* NoICE output flag
572 extern int xflag; /* Map file radix type flag
574 extern int pflag; /* print linker command file flag
576 extern int uflag; /* Listing relocation flag
578 extern int rflag; /* Extended linear address record flag.
580 extern int radix; /* current number conversion radix:
581 * 2 (binary), 8 (octal), 10 (decimal),
584 extern int line; /* current line number
586 extern int page; /* current page number
588 extern int lop; /* current line number on page
590 extern int pass; /* linker pass number
592 extern int rtcnt; /* count of elements in the
593 * rtval[] and rtflg[] arrays
595 extern Addr_T rtval[]; /* data associated with relocation
597 extern int rtflg[]; /* indicates if rtval[] value is
598 * to be sent to the output file.
599 * (always set in this linker)
601 extern int hilo; /* REL file byte ordering
603 extern int gline; /* LST file relocation active
606 extern int gcntr; /* LST file relocation active
609 extern struct lbpath *lbphead; /* pointer to the first
610 * library path structure
612 extern struct lbname *lbnhead; /* pointer to the first
613 * library name structure
615 extern struct lbfile *lbfhead; /* pointer to the first
616 * library file structure
618 extern Addr_T iram_size; /* internal ram size
622 /* C Library function definitions */
623 /* for reference only
626 extern char * fgets();
627 extern FILE * fopen();
628 extern int fprintf();
630 extern VOID * malloc();
632 extern char * strcpy();
634 extern char * strncpy();
637 /* Program function definitions */
640 extern FILE * afile();
641 extern VOID bassav();
642 extern VOID gblsav();
643 extern VOID iramsav();
644 extern VOID iramcheck();
645 extern VOID link_main();
646 extern VOID lkexit();
650 extern VOID setbas();
651 extern VOID setgbl();
653 extern VOID copyfile();
656 extern char endline();
658 extern VOID getfid();
660 extern VOID getSid();
661 extern int getline();
667 extern VOID chop_crlf();
670 extern VOID lkparea();
671 extern VOID lnkarea();
672 extern VOID lnksect();
673 extern VOID newarea();
676 extern VOID module();
677 extern VOID newhead();
681 extern struct sym * lkpsym();
683 extern struct sym * newsym();
684 extern VOID symdef();
686 extern VOID syminit();
687 extern VOID symmod();
688 extern Addr_T symval();
692 extern Addr_T eval();
693 extern Addr_T expr();
695 extern Addr_T term();
699 extern VOID lkulist();
700 extern VOID lkalist();
701 extern VOID lkglist();
702 extern VOID lstarea();
703 extern VOID newpag();
707 extern Addr_T adb_b();
708 extern Addr_T adb_hi();
709 extern Addr_T adb_lo();
710 extern Addr_T adb_24_hi(Addr_T v, int i);
711 extern Addr_T adb_24_mid(Addr_T v, int i);
712 extern Addr_T adb_24_lo(Addr_T v, int i);
713 extern Addr_T adw_w();
714 extern Addr_T adw_24(Addr_T, int);
715 extern Addr_T adw_hi();
716 extern Addr_T adw_lo();
717 extern Addr_T evword();
723 extern VOID relerr();
724 extern char * errmsg[];
725 extern VOID errdmp();
726 extern VOID relerp();
727 extern VOID erpdmp();
728 extern VOID prntval();
729 extern int lastExtendedAddress;
732 extern VOID addfile();
733 extern VOID addlib();
734 extern VOID addpath();
736 extern VOID library();
737 extern VOID loadfile();
738 extern VOID search();
745 extern VOID ihxEntendedLinearAddress(Addr_T);
747 extern char *StoreString( char *str );
750 extern void DefineNoICE( char *name, Addr_T value, int page );
753 extern int summary(struct area * xp);
755 /* SD added this to change
756 strcmpi --> strcmp (strcmpi NOT ANSI) */
757 #define strcmpi strcmp