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 #if defined(__BORLANDC__) || defined(_MSC_VER)
89 #define PATH_MAX _MAX_PATH
91 #define PATH_MAX 255 /* define a reasonable value */
96 * This file defines the format of the
97 * relocatable binary file.
100 #define NCPS 80 /* characters per symbol (JLH: change from 8) */
101 #define NDATA 16 /* actual data */
102 #define NINPUT PATH_MAX /* Input buffer size */
103 #define NHASH 64 /* Buckets in hash table */
104 #define HMASK 077 /* Hash mask */
105 #define NLPP 60 /* Lines per page */
106 #define NTXT 16 /* T values */
109 * The "R_" relocation constants define values used in
110 * generating the assembler relocation output data for
111 * areas, symbols, and code.
117 * +-----+-----+-----+-----+-----+-----+-----+-----+
118 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
119 * +-----+-----+-----+-----+-----+-----+-----+-----+
122 #define R_WORD 0x00 /* 16 bit */
123 #define R_BYTE 0x01 /* 8 bit */
125 #define R_AREA 0x00 /* Base type */
128 #define R_NORM 0x00 /* PC adjust */
131 #define R_BYT1 0x00 /* Byte count for R_BYTE = 1 */
132 #define R_BYT2 0x08 /* Byte count for R_BYTE = 2 */
134 #define R_SGND 0x00 /* Signed Byte */
135 #define R_USGN 0x10 /* Unsigned Byte */
137 #define R_NOPAG 0x00 /* Page Mode */
138 #define R_PAG0 0x20 /* Page '0' */
139 #define R_PAG 0x40 /* Page 'nnn' */
141 #define R_LSB 0x00 /* low byte */
142 #define R_MSB 0x80 /* high byte */
144 #define R_BYT3 0x100 /* if R_BYTE is set, this is a
145 * 3 byte address, of which
146 * the linker must select one byte.
148 #define R_HIB 0x200 /* If R_BYTE & R_BYT3 are set, linker
149 * will select byte 3 of the relocated
153 #define R_J11 (R_WORD|R_BYT2) /* JLH: 11 bit JMP and CALL (8051) */
154 #define R_J19 (R_WORD|R_BYT2|R_MSB) /* 19 bit JMP/CALL (DS80C390) */
155 #define R_C24 (R_WORD|R_BYT1|R_MSB) /* 24 bit address (DS80C390) */
156 #define R_J19_MASK (R_BYTE|R_BYT2|R_MSB)
158 #define IS_R_J19(x) (((x) & R_J19_MASK) == R_J19)
159 #define IS_R_J11(x) (((x) & R_J19_MASK) == R_J11)
160 #define IS_C24(x) (((x) & R_J19_MASK) == R_C24)
162 #define R_ESCAPE_MASK 0xf0 /* Used to escape relocation modes
163 * greater than 0xff in the .rel
168 * Global symbol types.
170 #define S_REF 1 /* referenced */
171 #define S_DEF 2 /* defined */
176 #define A_CON 0000 /* concatenate */
177 #define A_OVR 0004 /* overlay */
178 #define A_REL 0000 /* relocatable */
179 #define A_ABS 0010 /* absolute */
180 #define A_NOPAG 0000 /* non-paged */
181 #define A_PAG 0020 /* paged */
183 /* Additional flags for 8051 address spaces */
184 #define A_DATA 0000 /* data space (default)*/
185 #define A_CODE 0040 /* code space */
186 #define A_XDATA 0100 /* external data space */
187 #define A_BIT 0200 /* bit addressable space */
189 #define A_NOLOAD 0400 /* nonloadable */
190 #define A_LOAD 0000 /* loadable (default) */
195 #define F_STD 1 /* stdin */
196 #define F_LNK 2 /* File.lnk */
197 #define F_REL 3 /* File.rel */
200 * General assembler address type
202 typedef unsigned int Addr_T;
205 * The structures of head, area, areax, and sym are created
206 * as the REL files are read during the first pass of the
207 * linker. The struct head is created upon encountering a
208 * H directive in the REL file. The structure contains a
209 * link to a link file structure (struct lfile) which describes
210 * the file containing the H directive, the number of data/code
211 * areas contained in this header segment, the number of
212 * symbols referenced/defined in this header segment, a pointer
213 * to an array of pointers to areax structures (struct areax)
214 * created as each A directive is read, and a pointer to an
215 * array of pointers to symbol structures (struct sym) for
216 * all referenced/defined symbols. As H directives are read
217 * from the REL files a linked list of head structures is
218 * created by placing a link to the new head structure
219 * in the previous head structure.
223 struct head *h_hp; /* Header link */
224 struct lfile *h_lfile;/* Associated file */
225 int h_narea; /* # of areas */
226 struct areax **a_list; /* Area list */
227 int h_nglob; /* # of global symbols */
228 struct sym **s_list; /* Globle symbol list */
229 char m_id[NCPS]; /* Module name */
233 * A structure area is created for each 'unique' data/code
234 * area definition found as the REL files are read. The
235 * struct area contains the name of the area, a flag byte
236 * which contains the area attributes (REL/CON/OVR/ABS),
237 * an area subtype (not used in this assembler), and the
238 * area base address and total size which will be filled
239 * in at the end of the first pass through the REL files.
240 * As A directives are read from the REL files a linked
241 * list of unique area structures is created by placing a
242 * link to the new area structure in the previous area structure.
246 struct area *a_ap; /* Area link */
247 struct areax *a_axp; /* Area extension link */
248 Addr_T a_addr; /* Beginning address of area */
249 Addr_T a_size; /* Total size of the area */
250 char a_type; /* Area subtype */
251 int a_flag; /* Flag byte */
252 char a_id[NCPS]; /* Name */
258 * An areax structure is created for every A directive found
259 * while reading the REL files. The struct areax contains a
260 * link to the 'unique' area structure referenced by the A
261 * directive and to the head structure this area segment is
262 * a part of. The size of this area segment as read from the
263 * A directive is placed in the areax structure. The beginning
264 * address of this segment will be filled in at the end of the
265 * first pass through the REL files. As A directives are read
266 * from the REL files a linked list of areax structures is
267 * created for each unique area. The final areax linked
268 * list has at its head the 'unique' area structure linked
269 * to the linked areax structures (one areax structure for
270 * each A directive for this area).
274 struct areax *a_axp; /* Area extension link */
275 struct area *a_bap; /* Base area link */
276 struct head *a_bhp; /* Base header link */
277 Addr_T a_addr; /* Beginning address of section */
278 Addr_T a_size; /* Size of the area in section */
282 * A sym structure is created for every unique symbol
283 * referenced/defined while reading the REL files. The
284 * struct sym contains the symbol's name, a flag value
285 * (not used in this linker), a symbol type denoting
286 * referenced/defined, and an address which is loaded
287 * with the relative address within the area in which
288 * the symbol was defined. The sym structure also
289 * contains a link to the area where the symbol was defined.
290 * The sym structures are linked into linked lists using
291 * the symbol link element.
295 struct sym *s_sp; /* Symbol link */
296 struct areax *s_axp; /* Symbol area link */
297 char s_type; /* Symbol subtype */
298 char s_flag; /* Flag byte */
299 Addr_T s_addr; /* Address */
300 char *s_id; /* Name: JLH change from [NCPS] */
304 * The structure lfile contains a pointer to a
305 * file specification string, the file type, and
306 * a link to the next lfile structure.
310 struct lfile *f_flp; /* lfile link */
311 int f_type; /* File type */
312 char *f_idp; /* Pointer to file spec */
316 * The struct base contains a pointer to a
317 * base definition string and a link to the next
322 struct base *b_base; /* Base link */
323 char *b_strp; /* String pointer */
327 * The struct globl contains a pointer to a
328 * global definition string and a link to the next
333 struct globl *g_globl; /* Global link */
334 char *g_strp; /* String pointer */
338 * A structure sdp is created for each 'unique' paged
339 * area definition found as the REL files are read.
340 * As P directives are read from the REL files a linked
341 * list of unique sdp structures is created by placing a
342 * link to the new sdp structure in the previous area structure.
346 struct area *s_area; /* Paged Area link */
347 struct areax *s_areax; /* Paged Area Extension Link */
348 Addr_T s_addr; /* Page address offset */
352 * The structure rerr is loaded with the information
353 * required to report an error during the linking
354 * process. The structure contains an index value
355 * which selects the areax structure from the header
356 * areax structure list, a mode value which selects
357 * symbol or area relocation, the base address in the
358 * area section, an area/symbol list index value, and
359 * an area/symbol offset value.
363 int aindex; /* Linking area */
364 int mode; /* Relocation mode */
365 Addr_T rtbase; /* Base address in section */
366 int rindex; /* Area/Symbol reloaction index */
367 Addr_T rval; /* Area/Symbol offset value */
371 * The structure lbpath is created for each library
372 * path specification input by the -k option. The
373 * lbpath structures are linked into a list using
374 * the next link element.
382 * The structure lbname is created for all combinations of the
383 * library path specifications (input by the -k option) and the
384 * library file specifications (input by the -l option) that
385 * lead to an existing file. The element path points to
386 * the path string, element libfil points to the library
387 * file string, and the element libspc is the concatenation
388 * of the valid path and libfil strings.
390 * The lbpath structures are linked into a list
391 * using the next link element.
393 * Each library file contains a list of object files
394 * that are contained in the particular library. e.g.:
399 * Only one specification per line is allowed.
409 * The function fndsym() searches through all combinations of the
410 * library path specifications (input by the -k option) and the
411 * library file specifications (input by the -l option) that
412 * lead to an existing file for a symbol definition.
414 * The structure lbfile is created for the first library
415 * object file which contains the definition for the
416 * specified undefined symbol.
418 * The element libspc points to the library file path specification
419 * and element relfil points to the object file specification string.
420 * The element filspc is the complete path/file specification for
421 * the library file to be imported into the linker. The
422 * file specicifation may be formed in one of two ways:
424 * (1) If the library file contained an absolute
425 * path/file specification then this becomes filspc.
428 * (2) If the library file contains a relative path/file
429 * specification then the concatenation of the path
430 * and this file specification becomes filspc.
433 * The lbpath structures are linked into a list
434 * using the next link element.
441 long offset; /*>=0 if rel file is embedded in a lib file at this offset*/
445 * External Definitions for all Global Variables
448 extern char *_abs_; /* = { ". .ABS." };
450 extern int lkerr; /* ASLink error flag
452 extern char *ip; /* pointer into the REL file
455 extern char ib[NINPUT]; /* REL file text line
457 extern char *rp; /* pointer into the LST file
460 extern char rb[NINPUT]; /* LST file text line being
463 extern unsigned char ctype[]; /* array of character types, one per
467 extern char sdccopt[NINPUT];
468 extern char sdccopt_module[NINPUT];
469 extern char curr_module[NINPUT];
472 * Character Type Definitions
485 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
486 #define DGT8 DIGIT|RAD16|RAD10|RAD8
487 #define DGT10 DIGIT|RAD16|RAD10
488 #define LTR16 LETTER|RAD16
492 extern char ccase[]; /* an array of characters which
493 * perform the case translation function
497 extern struct lfile *filep; /* The pointers (lfile *) filep,
498 * (lfile *) cfp, and (FILE *) sfp
499 * are used in conjunction with
500 * the routine getline() to read
501 * asmlnk commands from
502 * (1) the standard input or
503 * (2) or a command file
504 * and to read the REL files
505 * sequentially as defined by the
506 * asmlnk input commands.
508 * The pointer *filep points to the
509 * beginning of a linked list of
512 extern struct lfile *cfp; /* The pointer *cfp points to the
513 * current lfile structure
515 extern struct lfile *startp;/* asmlnk startup file structure
517 extern struct lfile *linkp; /* pointer to first lfile structure
518 * containing an input REL file
521 extern struct lfile *lfp; /* pointer to current lfile structure
522 * being processed by parse()
524 extern struct head *headp; /* The pointer to the first
525 * head structure of a linked list
527 extern struct head *hp; /* Pointer to the current
530 extern struct area *areap; /* The pointer to the first
531 * area structure of a linked list
533 extern struct area *ap; /* Pointer to the current
536 extern struct areax *axp; /* Pointer to the current
539 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
540 * linked symbol lists
542 extern struct base *basep; /* The pointer to the first
545 extern struct base *bsp; /* Pointer to the current
548 extern struct globl *globlp;/* The pointer to the first
551 extern struct globl *gsp; /* Pointer to the current
554 extern struct sdp sdp; /* Base Paged structure
556 extern struct rerr rerr; /* Structure containing the
557 * linker error information
559 extern FILE *ofp; /* Linker Output file handle
561 extern FILE *mfp; /* Map output file handle
563 extern FILE *jfp; /* NoICE output file handle
565 extern FILE *rfp; /* File handle for output
566 * address relocated ASxxxx
569 extern FILE *sfp; /* The file handle sfp points to the
570 * currently open file
572 extern FILE *tfp; /* File handle for input
573 * ASxxxx listing file
575 extern FILE *dfp; /* File handle for debug info output
577 extern int dflag; /* Output debug information flag
579 extern int oflag; /* Output file type flag
581 extern int mflag; /* Map output flag
583 extern int sflag; /* JCF: Memory usage output flag
585 extern int jflag; /* NoICE output flag
587 extern int xflag; /* Map file radix type flag
589 extern int pflag; /* print linker command file flag
591 extern int uflag; /* Listing relocation flag
593 extern int rflag; /* Extended linear address record flag.
595 extern int radix; /* current number conversion radix:
596 * 2 (binary), 8 (octal), 10 (decimal),
599 extern int line; /* current line number
601 extern int page; /* current page number
603 extern int lop; /* current line number on page
605 extern int pass; /* linker pass number
607 extern int rtcnt; /* count of elements in the
608 * rtval[] and rtflg[] arrays
610 extern Addr_T rtval[]; /* data associated with relocation
612 extern int rtflg[]; /* indicates if rtval[] value is
613 * to be sent to the output file.
614 * (always set in this linker)
616 extern int hilo; /* REL file byte ordering
618 extern int gline; /* LST file relocation active
621 extern int gcntr; /* LST file relocation active
624 extern struct lbpath *lbphead; /* pointer to the first
625 * library path structure
627 extern struct lbname *lbnhead; /* pointer to the first
628 * library name structure
630 extern struct lbfile *lbfhead; /* pointer to the first
631 * library file structure
633 extern Addr_T iram_size; /* internal ram size
635 extern long xram_size; /* external ram size
637 extern long code_size; /* code size
641 /* C Library function definitions */
642 /* for reference only
645 extern char * fgets();
646 extern FILE * fopen();
647 extern int fprintf();
649 extern VOID * malloc();
651 extern char * strcpy();
653 extern char * strncpy();
656 /* Program function definitions */
659 extern FILE * afile();
660 extern VOID bassav();
661 extern VOID gblsav();
662 extern VOID iramsav();
663 extern VOID xramsav();
664 extern VOID codesav();
665 extern VOID iramcheck();
666 extern VOID link_main();
667 extern VOID lkexit();
671 extern VOID setbas();
672 extern VOID setgbl();
674 extern VOID copyfile();
677 extern char endline();
679 extern VOID getfid();
681 extern VOID getSid();
682 extern int getline();
688 extern VOID chop_crlf();
691 extern VOID lkparea();
692 extern VOID lnkarea();
693 extern VOID lnksect();
694 extern VOID newarea();
697 extern VOID module();
698 extern VOID newhead();
702 extern struct sym * lkpsym();
704 extern struct sym * newsym();
705 extern VOID symdef();
707 extern VOID syminit();
708 extern VOID symmod();
709 extern Addr_T symval();
713 extern Addr_T eval();
714 extern Addr_T expr();
716 extern Addr_T term();
720 extern VOID lkulist();
721 extern VOID lkalist();
722 extern VOID lkglist();
723 extern VOID lstarea();
724 extern VOID newpag();
728 extern Addr_T adb_b();
729 extern Addr_T adb_hi();
730 extern Addr_T adb_lo();
731 extern Addr_T adb_24_hi(Addr_T v, int i);
732 extern Addr_T adb_24_mid(Addr_T v, int i);
733 extern Addr_T adb_24_lo(Addr_T v, int i);
734 extern Addr_T adw_w();
735 extern Addr_T adw_24(Addr_T, int);
736 extern Addr_T adw_hi();
737 extern Addr_T adw_lo();
738 extern Addr_T evword();
744 extern VOID relerr();
745 extern char * errmsg[];
746 extern VOID errdmp();
747 extern VOID relerp();
748 extern VOID erpdmp();
749 extern VOID prntval();
750 extern int lastExtendedAddress;
753 extern int addfile();
754 extern VOID addlib();
755 extern VOID addpath();
757 extern VOID library();
758 extern VOID loadfile();
759 extern VOID search();
766 extern VOID ihxEntendedLinearAddress(Addr_T);
767 extern VOID newArea();
770 extern char *StoreString( char *str );
773 extern void DefineNoICE( char *name, Addr_T value, int page );
776 extern int summary(struct area * xp);
778 /* JCF: lkaomf51.c */
779 extern void SaveLinkedFilePath(char * filepath);
780 extern void CreateAOMF51(void);