4 * (C) Copyright 1989-1996
13 * Extensions: P. Felber
15 #define VERSION "V01.75"
18 * Case Sensitivity Flag
20 #define CASE_SENSITIVE 1
24 * The module asmlnk.h contains the definitions for constants,
25 * structures, global variables, and LKxxxx functions
26 * contained in the LKxxxx.c files.
49 /* DECUS C void definition */
50 /* File/extension seperator */
57 /* PDOS C void definition */
58 /* File/extension seperator */
65 /* Default void definition */
66 /* File/extension seperator */
78 #ifndef PATH_MAX /* POSIX, but not required */
79 #if defined(__BORLANDC__) || defined(_MSC_VER)
81 #define PATH_MAX _MAX_PATH
83 #define PATH_MAX 255 /* define a reasonable value */
88 * This file defines the format of the
89 * relocatable binary file.
93 #define NCPS 80 /* characters per symbol. Used to be 32... */
95 #define NCPS 8 /* characters per symbol */
97 /* #define NCPS 32 */ /* characters per symbol */
98 #define NDATA 16 /* actual data */
99 #define NINPUT PATH_MAX /* Input buffer size */
100 #define NHASH 64 /* Buckets in hash table */
101 #define HMASK 077 /* Hash mask */
102 #define NLPP 60 /* Lines per page */
103 #define NTXT 16 /* T values */
104 #define FILSPC PATH_MAX /* File spec length */
107 * The "R_" relocation constants define values used in
108 * generating the assembler relocation output data for
109 * areas, symbols, and code.
115 * +-----+-----+-----+-----+-----+-----+-----+-----+
116 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
117 * +-----+-----+-----+-----+-----+-----+-----+-----+
120 #define R_WORD 0x00 /* 16 bit */
121 #define R_BYTE 0x01 /* 8 bit */
123 #define R_AREA 0x00 /* Base type */
126 #define R_NORM 0x00 /* PC adjust */
129 #define R_BYT1 0x00 /* Byte count for R_BYTE = 1 */
130 #define R_BYT2 0x08 /* Byte count for R_BYTE = 2 */
132 #define R_SGND 0x00 /* Signed value */
133 #define R_USGN 0x10 /* Unsigned value */
135 #define R_NOPAG 0x00 /* Page Mode */
136 #define R_PAG0 0x20 /* Page '0' */
137 #define R_PAG 0x40 /* Page 'nnn' */
142 #define R_LSB 0x00 /* output low byte */
143 #define R_MSB 0x80 /* output high byte */
146 * Global symbol types.
148 #define S_REF 1 /* referenced */
149 #define S_DEF 2 /* defined */
154 #define A_CON 0000 /* concatenate */
155 #define A_OVR 0004 /* overlay */
156 #define A_REL 0000 /* relocatable */
157 #define A_ABS 0010 /* absolute */
158 #define A_NOPAG 0000 /* non-paged */
159 #define A_PAG 0020 /* paged */
164 #define F_INV 0 /* invalid */
165 #define F_STD 1 /* stdin */
166 #define F_LNK 2 /* File.lnk */
167 #define F_REL 3 /* File.rel */
169 #define F_CMD 4 /* Command line */
174 * Multiple banks support
176 extern int nb_rom_banks;
177 extern int nb_ram_banks;
178 extern int current_rom_bank;
180 extern char cart_name[];
182 * ROM patching support
184 typedef struct _patch {
189 extern patch* patches;
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[NCPS]; /* Name */
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.
431 long offset; /*>=0 if rel file is embedded in a lib file at this offset*/
435 * External Definitions for all Global Variables
438 extern char *_abs_; /* = { ". .ABS." };
440 extern int lkerr; /* ASLink error flag
442 extern char *ip; /* pointer into the REL file
445 extern char ib[NINPUT]; /* REL file text line
447 extern char *rp; /* pointer into the LST file
450 extern char rb[NINPUT]; /* LST file text line being
453 extern unsigned char ctype[]; /* array of character types, one per
457 extern char sdccopt[NINPUT];
458 extern char sdccopt_module[NINPUT];
459 extern char curr_module[NINPUT];
462 * Character Type Definitions
475 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
476 #define DGT8 DIGIT|RAD16|RAD10|RAD8
477 #define DGT10 DIGIT|RAD16|RAD10
478 #define LTR16 LETTER|RAD16
482 extern char ccase[]; /* an array of characters which
483 * perform the case translation function
487 extern struct lfile *filep; /* The pointers (lfile *) filep,
488 * (lfile *) cfp, and (FILE *) sfp
489 * are used in conjunction with
490 * the routine lk_getline() to read
491 * asmlnk commands from
492 * (1) the standard input or
493 * (2) or a command file
494 * and to read the REL files
495 * sequentially as defined by the
496 * asmlnk input commands.
498 * The pointer *filep points to the
499 * beginning of a linked list of
502 extern struct lfile *cfp; /* The pointer *cfp points to the
503 * current lfile structure
505 extern struct lfile *startp;/* asmlnk startup file structure
507 extern struct lfile *linkp; /* pointer to first lfile structure
508 * containing an input REL file
511 extern struct lfile *lfp; /* pointer to current lfile structure
512 * being processed by parse()
514 extern struct head *headp; /* The pointer to the first
515 * head structure of a linked list
517 extern struct head *hp; /* Pointer to the current
520 extern struct area *areap; /* The pointer to the first
521 * area structure of a linked list
523 extern struct area *ap; /* Pointer to the current
526 extern struct areax *axp; /* Pointer to the current
529 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
530 * linked symbol lists
532 extern struct base *basep; /* The pointer to the first
535 extern struct base *bsp; /* Pointer to the current
538 extern struct globl *globlp;/* The pointer to the first
541 extern struct globl *gsp; /* Pointer to the current
544 extern struct sdp sdp; /* Base Paged structure
546 extern struct rerr rerr; /* Structure containing the
547 * linker error information
549 extern FILE *ofp; /* Linker Output file handle
551 extern FILE *mfp; /* Map output file handle
553 extern FILE *rfp; /* File handle for output
554 * address relocated ASxxxx
557 extern FILE *sfp; /* The file handle sfp points to the
558 * currently open file
560 extern FILE *tfp; /* File handle for input
561 * ASxxxx listing file
563 extern int oflag; /* Output file type flag
565 extern int mflag; /* Map output flag
568 extern int symflag; /* no$gmb .sym output flag
571 extern int xflag; /* Map file radix type flag
573 extern int pflag; /* print linker command file flag
575 extern int uflag; /* Listing relocation flag
577 extern int radix; /* current number conversion radix:
578 * 2 (binary), 8 (octal), 10 (decimal),
581 extern int line; /* current line number
583 extern int page; /* current page number
585 extern int lop; /* current line number on page
587 extern int pass; /* linker pass number
589 extern int rtcnt; /* count of elements in the
590 * rtval[] and rtflg[] arrays
592 extern Addr_T rtval[]; /* data associated with relocation
594 extern int rtflg[]; /* indicates if rtval[] value is
595 * to be sent to the output file.
596 * (always set in this linker)
598 extern int hilo; /* REL file byte ordering
600 extern int gline; /* LST file relocation active
603 extern int gcntr; /* LST file relocation active
606 extern struct lbpath *lbphead; /* pointer to the first
607 * library path structure
609 extern struct lbname *lbnhead; /* pointer to the first
610 * library name structure
612 extern struct lbfile *lbfhead; /* pointer to the first
613 * library file structure
616 /* C Library function definitions */
617 /* for reference only
620 extern char * fgets();
621 extern FILE * fopen();
622 extern int fprintf();
624 extern VOID * malloc();
626 extern char * strcpy();
628 extern char * strncpy();
631 /* Program function definitions */
634 extern FILE * afile();
635 extern VOID bassav();
636 extern VOID gblsav();
638 extern VOID lkexit();
645 extern VOID setbas();
646 extern VOID setgbl();
650 extern char endline();
652 extern VOID getfid();
654 extern int lk_getline();
660 extern VOID chop_crlf();
663 extern VOID lkparea();
664 extern VOID lnkarea();
665 extern VOID lnksect();
666 extern VOID newarea();
669 extern VOID module();
670 extern VOID newhead();
674 extern struct sym * lkpsym();
676 extern struct sym * newsym();
677 extern VOID symdef();
679 extern VOID syminit();
680 extern VOID symmod();
681 extern Addr_T symval();
685 extern Addr_T eval();
686 extern Addr_T expr();
688 extern Addr_T term();
692 extern VOID lkulist();
693 extern VOID lkalist();
694 extern VOID lkglist();
695 extern VOID lstarea();
696 extern VOID newpag();
700 extern Addr_T adb_b();
701 extern Addr_T adb_hi();
702 extern Addr_T adb_lo();
703 extern Addr_T adw_w();
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();
720 extern int addfile();
721 extern VOID addlib();
722 extern VOID addpath();
724 extern VOID library();
725 extern VOID loadfile();
726 extern VOID search();