4 * (C) Copyright 1989-1996
13 * Extensions: P. Felber
16 #define VERSION "V01.75"
19 * Case Sensitivity Flag
21 #define CASE_SENSITIVE 0
25 * The module asmlnk.h contains the definitions for constants,
26 * structures, global variables, and LKxxxx functions
27 * contained in the LKxxxx.c files.
50 /* DECUS C void definition */
51 /* File/extension seperator */
58 /* PDOS C void definition */
59 /* File/extension seperator */
66 /* Default void definition */
67 /* File/extension seperator */
76 * This file defines the format of the
77 * relocatable binary file.
81 #define NCPS 32 /* characters per symbol */
83 #define NCPS 8 /* characters per symbol */
85 /* #define NCPS 32 */ /* characters per symbol */
86 #define NDATA 16 /* actual data */
87 #define NINPUT 128 /* Input buffer size */
88 #define NHASH 64 /* Buckets in hash table */
89 #define HMASK 077 /* Hash mask */
90 #define NLPP 60 /* Lines per page */
91 #define NTXT 16 /* T values */
92 /** PENDING: Taking this to 256 causes a segfault. */
93 #define FILSPC 100 /* File spec length */
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 value */
122 #define R_USGN 0x10 /* Unsigned value */
124 #define R_NOPAG 0x00 /* Page Mode */
125 #define R_PAG0 0x20 /* Page '0' */
126 #define R_PAG 0x40 /* Page 'nnn' */
131 #define R_LSB 0x00 /* output low byte */
132 #define R_MSB 0x80 /* output high byte */
135 * Global symbol types.
137 #define S_REF 1 /* referenced */
138 #define S_DEF 2 /* defined */
143 #define A_CON 000 /* concatenate */
144 #define A_OVR 004 /* overlay */
145 #define A_REL 000 /* relocatable */
146 #define A_ABS 010 /* absolute */
147 #define A_NOPAG 000 /* non-paged */
148 #define A_PAG 020 /* paged */
153 #define F_STD 1 /* stdin */
154 #define F_LNK 2 /* File.lnk */
155 #define F_REL 3 /* File.rel */
157 #define F_CMD 4 /* Command line */
162 * Multiple banks support
164 extern int nb_rom_banks;
165 extern int nb_ram_banks;
166 extern int current_rom_bank;
168 extern char cart_name[];
170 * ROM patching support
172 typedef struct _patch {
177 extern patch* patches;
180 * General assembler address type
182 typedef unsigned int Addr_T;
185 * The structures of head, area, areax, and sym are created
186 * as the REL files are read during the first pass of the
187 * linker. The struct head is created upon encountering a
188 * H directive in the REL file. The structure contains a
189 * link to a link file structure (struct lfile) which describes
190 * the file containing the H directive, the number of data/code
191 * areas contained in this header segment, the number of
192 * symbols referenced/defined in this header segment, a pointer
193 * to an array of pointers to areax structures (struct areax)
194 * created as each A directive is read, and a pointer to an
195 * array of pointers to symbol structures (struct sym) for
196 * all referenced/defined symbols. As H directives are read
197 * from the REL files a linked list of head structures is
198 * created by placing a link to the new head structure
199 * in the previous head structure.
203 struct head *h_hp; /* Header link */
204 struct lfile *h_lfile;/* Associated file */
205 int h_narea; /* # of areas */
206 struct areax **a_list; /* Area list */
207 int h_nglob; /* # of global symbols */
208 struct sym **s_list; /* Globle symbol list */
209 char m_id[NCPS]; /* Module name */
213 * A structure area is created for each 'unique' data/code
214 * area definition found as the REL files are read. The
215 * struct area contains the name of the area, a flag byte
216 * which contains the area attributes (REL/CON/OVR/ABS),
217 * an area subtype (not used in this assembler), and the
218 * area base address and total size which will be filled
219 * in at the end of the first pass through the REL files.
220 * As A directives are read from the REL files a linked
221 * list of unique area structures is created by placing a
222 * link to the new area structure in the previous area structure.
226 struct area *a_ap; /* Area link */
227 struct areax *a_axp; /* Area extension link */
228 Addr_T a_addr; /* Beginning address of area */
229 Addr_T a_size; /* Total size of the area */
230 char a_type; /* Area subtype */
231 char a_flag; /* Flag byte */
232 char a_id[NCPS]; /* Name */
236 * An areax structure is created for every A directive found
237 * while reading the REL files. The struct areax contains a
238 * link to the 'unique' area structure referenced by the A
239 * directive and to the head structure this area segment is
240 * a part of. The size of this area segment as read from the
241 * A directive is placed in the areax structure. The beginning
242 * address of this segment will be filled in at the end of the
243 * first pass through the REL files. As A directives are read
244 * from the REL files a linked list of areax structures is
245 * created for each unique area. The final areax linked
246 * list has at its head the 'unique' area structure linked
247 * to the linked areax structures (one areax structure for
248 * each A directive for this area).
252 struct areax *a_axp; /* Area extension link */
253 struct area *a_bap; /* Base area link */
254 struct head *a_bhp; /* Base header link */
255 Addr_T a_addr; /* Beginning address of section */
256 Addr_T a_size; /* Size of the area in section */
260 * A sym structure is created for every unique symbol
261 * referenced/defined while reading the REL files. The
262 * struct sym contains the symbol's name, a flag value
263 * (not used in this linker), a symbol type denoting
264 * referenced/defined, and an address which is loaded
265 * with the relative address within the area in which
266 * the symbol was defined. The sym structure also
267 * contains a link to the area where the symbol was defined.
268 * The sym structures are linked into linked lists using
269 * the symbol link element.
273 struct sym *s_sp; /* Symbol link */
274 struct areax *s_axp; /* Symbol area link */
275 char s_type; /* Symbol subtype */
276 char s_flag; /* Flag byte */
277 Addr_T s_addr; /* Address */
278 char s_id[NCPS]; /* Name */
282 * The structure lfile contains a pointer to a
283 * file specification string, the file type, and
284 * a link to the next lfile structure.
288 struct lfile *f_flp; /* lfile link */
289 int f_type; /* File type */
290 char *f_idp; /* Pointer to file spec */
294 * The struct base contains a pointer to a
295 * base definition string and a link to the next
300 struct base *b_base; /* Base link */
301 char *b_strp; /* String pointer */
305 * The struct globl contains a pointer to a
306 * global definition string and a link to the next
311 struct globl *g_globl; /* Global link */
312 char *g_strp; /* String pointer */
316 * A structure sdp is created for each 'unique' paged
317 * area definition found as the REL files are read.
318 * As P directives are read from the REL files a linked
319 * list of unique sdp structures is created by placing a
320 * link to the new sdp structure in the previous area structure.
324 struct area *s_area; /* Paged Area link */
325 struct areax *s_areax; /* Paged Area Extension Link */
326 Addr_T s_addr; /* Page address offset */
330 * The structure rerr is loaded with the information
331 * required to report an error during the linking
332 * process. The structure contains an index value
333 * which selects the areax structure from the header
334 * areax structure list, a mode value which selects
335 * symbol or area relocation, the base address in the
336 * area section, an area/symbol list index value, and
337 * an area/symbol offset value.
341 int aindex; /* Linking area */
342 int mode; /* Relocation mode */
343 Addr_T rtbase; /* Base address in section */
344 int rindex; /* Area/Symbol reloaction index */
345 Addr_T rval; /* Area/Symbol offset value */
349 * The structure lbpath is created for each library
350 * path specification input by the -k option. The
351 * lbpath structures are linked into a list using
352 * the next link element.
360 * The structure lbname is created for all combinations of the
361 * library path specifications (input by the -k option) and the
362 * library file specifications (input by the -l option) that
363 * lead to an existing file. The element path points to
364 * the path string, element libfil points to the library
365 * file string, and the element libspc is the concatenation
366 * of the valid path and libfil strings.
368 * The lbpath structures are linked into a list
369 * using the next link element.
371 * Each library file contains a list of object files
372 * that are contained in the particular library. e.g.:
377 * Only one specification per line is allowed.
387 * The function fndsym() searches through all combinations of the
388 * library path specifications (input by the -k option) and the
389 * library file specifications (input by the -l option) that
390 * lead to an existing file for a symbol definition.
392 * The structure lbfile is created for the first library
393 * object file which contains the definition for the
394 * specified undefined symbol.
396 * The element libspc points to the library file path specification
397 * and element relfil points to the object file specification string.
398 * The element filspc is the complete path/file specification for
399 * the library file to be imported into the linker. The
400 * file specicifation may be formed in one of two ways:
402 * (1) If the library file contained an absolute
403 * path/file specification then this becomes filspc.
406 * (2) If the library file contains a relative path/file
407 * specification then the concatenation of the path
408 * and this file specification becomes filspc.
411 * The lbpath structures are linked into a list
412 * using the next link element.
422 * External Definitions for all Global Variables
425 extern char *_abs_; /* = { ". .ABS." };
427 extern int lkerr; /* ASLink error flag
429 extern char *ip; /* pointer into the REL file
432 extern char ib[NINPUT]; /* REL file text line
434 extern char *rp; /* pointer into the LST file
437 extern char rb[NINPUT]; /* LST file text line being
440 extern char ctype[]; /* array of character types, one per
445 * Character Type Definitions
458 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
459 #define DGT8 DIGIT|RAD16|RAD10|RAD8
460 #define DGT10 DIGIT|RAD16|RAD10
461 #define LTR16 LETTER|RAD16
465 extern char ccase[]; /* an array of characters which
466 * perform the case translation function
470 extern struct lfile *filep; /* The pointers (lfile *) filep,
471 * (lfile *) cfp, and (FILE *) sfp
472 * are used in conjunction with
473 * the routine getline() to read
474 * asmlnk commands from
475 * (1) the standard input or
476 * (2) or a command file
477 * and to read the REL files
478 * sequentially as defined by the
479 * asmlnk input commands.
481 * The pointer *filep points to the
482 * beginning of a linked list of
485 extern struct lfile *cfp; /* The pointer *cfp points to the
486 * current lfile structure
488 extern struct lfile *startp;/* asmlnk startup file structure
490 extern struct lfile *linkp; /* pointer to first lfile structure
491 * containing an input REL file
494 extern struct lfile *lfp; /* pointer to current lfile structure
495 * being processed by parse()
497 extern struct head *headp; /* The pointer to the first
498 * head structure of a linked list
500 extern struct head *hp; /* Pointer to the current
503 extern struct area *areap; /* The pointer to the first
504 * area structure of a linked list
506 extern struct area *ap; /* Pointer to the current
509 extern struct areax *axp; /* Pointer to the current
512 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
513 * linked symbol lists
515 extern struct base *basep; /* The pointer to the first
518 extern struct base *bsp; /* Pointer to the current
521 extern struct globl *globlp;/* The pointer to the first
524 extern struct globl *gsp; /* Pointer to the current
527 extern struct sdp sdp; /* Base Paged structure
529 extern struct rerr rerr; /* Structure containing the
530 * linker error information
532 extern FILE *ofp; /* Linker Output file handle
534 extern FILE *mfp; /* Map output file handle
536 extern FILE *rfp; /* File handle for output
537 * address relocated ASxxxx
540 extern FILE *sfp; /* The file handle sfp points to the
541 * currently open file
543 extern FILE *tfp; /* File handle for input
544 * ASxxxx listing file
546 extern int oflag; /* Output file type flag
548 extern int mflag; /* Map output flag
551 extern int symflag; /* no$gmb .sym output flag
554 extern int xflag; /* Map file radix type flag
556 extern int pflag; /* print linker command file flag
558 extern int uflag; /* Listing relocation 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
599 /* C Library function definitions */
600 /* for reference only
603 extern char * fgets();
604 extern FILE * fopen();
605 extern int fprintf();
607 extern VOID * malloc();
609 extern char * strcpy();
611 extern char * strncpy();
614 /* Program function definitions */
617 extern FILE * afile();
618 extern VOID bassav();
619 extern VOID gblsav();
621 extern VOID lkexit();
628 extern VOID setbas();
629 extern VOID setgbl();
633 extern char endline();
635 extern VOID getfid();
637 extern int getline();
645 extern VOID lkparea();
646 extern VOID lnkarea();
647 extern VOID lnksect();
648 extern VOID newarea();
651 extern VOID module();
652 extern VOID newhead();
656 extern struct sym * lkpsym();
658 extern struct sym * newsym();
659 extern VOID symdef();
661 extern VOID syminit();
662 extern VOID symmod();
663 extern Addr_T symval();
667 extern Addr_T eval();
668 extern Addr_T expr();
670 extern Addr_T term();
674 extern VOID lkulist();
675 extern VOID lkalist();
676 extern VOID lkglist();
677 extern VOID lstarea();
678 extern VOID newpag();
682 extern Addr_T adb_b();
683 extern Addr_T adb_hi();
684 extern Addr_T adb_lo();
685 extern Addr_T adw_w();
686 extern Addr_T adw_hi();
687 extern Addr_T adw_lo();
688 extern Addr_T evword();
694 extern VOID relerr();
695 extern char * errmsg[];
696 extern VOID errdmp();
697 extern VOID relerp();
698 extern VOID erpdmp();
699 extern VOID prntval();
702 extern VOID addfile();
703 extern VOID addlib();
704 extern VOID addpath();
706 extern VOID library();
707 extern VOID loadfile();
708 extern VOID search();