4 * (C) Copyright 1989-1996
13 * Extensions: P. Felber
17 #define VERSION "V01.75"
20 * Case Sensitivity Flag
22 #define CASE_SENSITIVE 0
26 * The module asmlnk.h contains the definitions for constants,
27 * structures, global variables, and LKxxxx functions
28 * contained in the LKxxxx.c files.
51 /* DECUS C void definition */
52 /* File/extension seperator */
59 /* PDOS C void definition */
60 /* File/extension seperator */
67 /* Default void definition */
68 /* File/extension seperator */
77 * This file defines the format of the
78 * relocatable binary file.
82 #define NCPS 32 /* characters per symbol */
84 #define NCPS 8 /* characters per symbol */
86 /* #define NCPS 32 */ /* characters per symbol */
87 #define NDATA 16 /* actual data */
88 #define NINPUT PATH_MAX /* Input buffer size */
89 #define NHASH 64 /* Buckets in hash table */
90 #define HMASK 077 /* Hash mask */
91 #define NLPP 60 /* Lines per page */
92 #define NTXT 16 /* T values */
93 #define FILSPC PATH_MAX /* 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_INV 0 /* invalid */
154 #define F_STD 1 /* stdin */
155 #define F_LNK 2 /* File.lnk */
156 #define F_REL 3 /* File.rel */
158 #define F_CMD 4 /* Command line */
163 * Multiple banks support
165 extern int nb_rom_banks;
166 extern int nb_ram_banks;
167 extern int current_rom_bank;
169 extern char cart_name[];
171 * ROM patching support
173 typedef struct _patch {
178 extern patch* patches;
181 * General assembler address type
183 typedef unsigned int Addr_T;
186 * The structures of head, area, areax, and sym are created
187 * as the REL files are read during the first pass of the
188 * linker. The struct head is created upon encountering a
189 * H directive in the REL file. The structure contains a
190 * link to a link file structure (struct lfile) which describes
191 * the file containing the H directive, the number of data/code
192 * areas contained in this header segment, the number of
193 * symbols referenced/defined in this header segment, a pointer
194 * to an array of pointers to areax structures (struct areax)
195 * created as each A directive is read, and a pointer to an
196 * array of pointers to symbol structures (struct sym) for
197 * all referenced/defined symbols. As H directives are read
198 * from the REL files a linked list of head structures is
199 * created by placing a link to the new head structure
200 * in the previous head structure.
204 struct head *h_hp; /* Header link */
205 struct lfile *h_lfile;/* Associated file */
206 int h_narea; /* # of areas */
207 struct areax **a_list; /* Area list */
208 int h_nglob; /* # of global symbols */
209 struct sym **s_list; /* Globle symbol list */
210 char m_id[NCPS]; /* Module name */
214 * A structure area is created for each 'unique' data/code
215 * area definition found as the REL files are read. The
216 * struct area contains the name of the area, a flag byte
217 * which contains the area attributes (REL/CON/OVR/ABS),
218 * an area subtype (not used in this assembler), and the
219 * area base address and total size which will be filled
220 * in at the end of the first pass through the REL files.
221 * As A directives are read from the REL files a linked
222 * list of unique area structures is created by placing a
223 * link to the new area structure in the previous area structure.
227 struct area *a_ap; /* Area link */
228 struct areax *a_axp; /* Area extension link */
229 Addr_T a_addr; /* Beginning address of area */
230 Addr_T a_size; /* Total size of the area */
231 char a_type; /* Area subtype */
232 char a_flag; /* Flag byte */
233 char a_id[NCPS]; /* Name */
237 * An areax structure is created for every A directive found
238 * while reading the REL files. The struct areax contains a
239 * link to the 'unique' area structure referenced by the A
240 * directive and to the head structure this area segment is
241 * a part of. The size of this area segment as read from the
242 * A directive is placed in the areax structure. The beginning
243 * address of this segment will be filled in at the end of the
244 * first pass through the REL files. As A directives are read
245 * from the REL files a linked list of areax structures is
246 * created for each unique area. The final areax linked
247 * list has at its head the 'unique' area structure linked
248 * to the linked areax structures (one areax structure for
249 * each A directive for this area).
253 struct areax *a_axp; /* Area extension link */
254 struct area *a_bap; /* Base area link */
255 struct head *a_bhp; /* Base header link */
256 Addr_T a_addr; /* Beginning address of section */
257 Addr_T a_size; /* Size of the area in section */
261 * A sym structure is created for every unique symbol
262 * referenced/defined while reading the REL files. The
263 * struct sym contains the symbol's name, a flag value
264 * (not used in this linker), a symbol type denoting
265 * referenced/defined, and an address which is loaded
266 * with the relative address within the area in which
267 * the symbol was defined. The sym structure also
268 * contains a link to the area where the symbol was defined.
269 * The sym structures are linked into linked lists using
270 * the symbol link element.
274 struct sym *s_sp; /* Symbol link */
275 struct areax *s_axp; /* Symbol area link */
276 char s_type; /* Symbol subtype */
277 char s_flag; /* Flag byte */
278 Addr_T s_addr; /* Address */
279 char s_id[NCPS]; /* Name */
283 * The structure lfile contains a pointer to a
284 * file specification string, the file type, and
285 * a link to the next lfile structure.
289 struct lfile *f_flp; /* lfile link */
290 int f_type; /* File type */
291 char *f_idp; /* Pointer to file spec */
295 * The struct base contains a pointer to a
296 * base definition string and a link to the next
301 struct base *b_base; /* Base link */
302 char *b_strp; /* String pointer */
306 * The struct globl contains a pointer to a
307 * global definition string and a link to the next
312 struct globl *g_globl; /* Global link */
313 char *g_strp; /* String pointer */
317 * A structure sdp is created for each 'unique' paged
318 * area definition found as the REL files are read.
319 * As P directives are read from the REL files a linked
320 * list of unique sdp structures is created by placing a
321 * link to the new sdp structure in the previous area structure.
325 struct area *s_area; /* Paged Area link */
326 struct areax *s_areax; /* Paged Area Extension Link */
327 Addr_T s_addr; /* Page address offset */
331 * The structure rerr is loaded with the information
332 * required to report an error during the linking
333 * process. The structure contains an index value
334 * which selects the areax structure from the header
335 * areax structure list, a mode value which selects
336 * symbol or area relocation, the base address in the
337 * area section, an area/symbol list index value, and
338 * an area/symbol offset value.
342 int aindex; /* Linking area */
343 int mode; /* Relocation mode */
344 Addr_T rtbase; /* Base address in section */
345 int rindex; /* Area/Symbol reloaction index */
346 Addr_T rval; /* Area/Symbol offset value */
350 * The structure lbpath is created for each library
351 * path specification input by the -k option. The
352 * lbpath structures are linked into a list using
353 * the next link element.
361 * The structure lbname is created for all combinations of the
362 * library path specifications (input by the -k option) and the
363 * library file specifications (input by the -l option) that
364 * lead to an existing file. The element path points to
365 * the path string, element libfil points to the library
366 * file string, and the element libspc is the concatenation
367 * of the valid path and libfil strings.
369 * The lbpath structures are linked into a list
370 * using the next link element.
372 * Each library file contains a list of object files
373 * that are contained in the particular library. e.g.:
378 * Only one specification per line is allowed.
388 * The function fndsym() searches through all combinations of the
389 * library path specifications (input by the -k option) and the
390 * library file specifications (input by the -l option) that
391 * lead to an existing file for a symbol definition.
393 * The structure lbfile is created for the first library
394 * object file which contains the definition for the
395 * specified undefined symbol.
397 * The element libspc points to the library file path specification
398 * and element relfil points to the object file specification string.
399 * The element filspc is the complete path/file specification for
400 * the library file to be imported into the linker. The
401 * file specicifation may be formed in one of two ways:
403 * (1) If the library file contained an absolute
404 * path/file specification then this becomes filspc.
407 * (2) If the library file contains a relative path/file
408 * specification then the concatenation of the path
409 * and this file specification becomes filspc.
412 * The lbpath structures are linked into a list
413 * using the next link element.
423 * External Definitions for all Global Variables
426 extern char *_abs_; /* = { ". .ABS." };
428 extern int lkerr; /* ASLink error flag
430 extern char *ip; /* pointer into the REL file
433 extern char ib[NINPUT]; /* REL file text line
435 extern char *rp; /* pointer into the LST file
438 extern char rb[NINPUT]; /* LST file text line being
441 extern char ctype[]; /* array of character types, one per
446 * Character Type Definitions
459 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
460 #define DGT8 DIGIT|RAD16|RAD10|RAD8
461 #define DGT10 DIGIT|RAD16|RAD10
462 #define LTR16 LETTER|RAD16
466 extern char ccase[]; /* an array of characters which
467 * perform the case translation function
471 extern struct lfile *filep; /* The pointers (lfile *) filep,
472 * (lfile *) cfp, and (FILE *) sfp
473 * are used in conjunction with
474 * the routine getline() to read
475 * asmlnk commands from
476 * (1) the standard input or
477 * (2) or a command file
478 * and to read the REL files
479 * sequentially as defined by the
480 * asmlnk input commands.
482 * The pointer *filep points to the
483 * beginning of a linked list of
486 extern struct lfile *cfp; /* The pointer *cfp points to the
487 * current lfile structure
489 extern struct lfile *startp;/* asmlnk startup file structure
491 extern struct lfile *linkp; /* pointer to first lfile structure
492 * containing an input REL file
495 extern struct lfile *lfp; /* pointer to current lfile structure
496 * being processed by parse()
498 extern struct head *headp; /* The pointer to the first
499 * head structure of a linked list
501 extern struct head *hp; /* Pointer to the current
504 extern struct area *areap; /* The pointer to the first
505 * area structure of a linked list
507 extern struct area *ap; /* Pointer to the current
510 extern struct areax *axp; /* Pointer to the current
513 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
514 * linked symbol lists
516 extern struct base *basep; /* The pointer to the first
519 extern struct base *bsp; /* Pointer to the current
522 extern struct globl *globlp;/* The pointer to the first
525 extern struct globl *gsp; /* Pointer to the current
528 extern struct sdp sdp; /* Base Paged structure
530 extern struct rerr rerr; /* Structure containing the
531 * linker error information
533 extern FILE *ofp; /* Linker Output file handle
535 extern FILE *mfp; /* Map output file handle
537 extern FILE *rfp; /* File handle for output
538 * address relocated ASxxxx
541 extern FILE *sfp; /* The file handle sfp points to the
542 * currently open file
544 extern FILE *tfp; /* File handle for input
545 * ASxxxx listing file
547 extern int oflag; /* Output file type flag
549 extern int mflag; /* Map output flag
552 extern int symflag; /* no$gmb .sym output flag
555 extern int xflag; /* Map file radix type flag
557 extern int pflag; /* print linker command file flag
559 extern int uflag; /* Listing relocation flag
561 extern int radix; /* current number conversion radix:
562 * 2 (binary), 8 (octal), 10 (decimal),
565 extern int line; /* current line number
567 extern int page; /* current page number
569 extern int lop; /* current line number on page
571 extern int pass; /* linker pass number
573 extern int rtcnt; /* count of elements in the
574 * rtval[] and rtflg[] arrays
576 extern Addr_T rtval[]; /* data associated with relocation
578 extern int rtflg[]; /* indicates if rtval[] value is
579 * to be sent to the output file.
580 * (always set in this linker)
582 extern int hilo; /* REL file byte ordering
584 extern int gline; /* LST file relocation active
587 extern int gcntr; /* LST file relocation active
590 extern struct lbpath *lbphead; /* pointer to the first
591 * library path structure
593 extern struct lbname *lbnhead; /* pointer to the first
594 * library name structure
596 extern struct lbfile *lbfhead; /* pointer to the first
597 * library file structure
600 /* C Library function definitions */
601 /* for reference only
604 extern char * fgets();
605 extern FILE * fopen();
606 extern int fprintf();
608 extern VOID * malloc();
610 extern char * strcpy();
612 extern char * strncpy();
615 /* Program function definitions */
618 extern FILE * afile();
619 extern VOID bassav();
620 extern VOID gblsav();
622 extern VOID lkexit();
629 extern VOID setbas();
630 extern VOID setgbl();
634 extern char endline();
636 extern VOID getfid();
638 extern int getline();
646 extern VOID lkparea();
647 extern VOID lnkarea();
648 extern VOID lnksect();
649 extern VOID newarea();
652 extern VOID module();
653 extern VOID newhead();
657 extern struct sym * lkpsym();
659 extern struct sym * newsym();
660 extern VOID symdef();
662 extern VOID syminit();
663 extern VOID symmod();
664 extern Addr_T symval();
668 extern Addr_T eval();
669 extern Addr_T expr();
671 extern Addr_T term();
675 extern VOID lkulist();
676 extern VOID lkalist();
677 extern VOID lkglist();
678 extern VOID lstarea();
679 extern VOID newpag();
683 extern Addr_T adb_b();
684 extern Addr_T adb_hi();
685 extern Addr_T adb_lo();
686 extern Addr_T adw_w();
687 extern Addr_T adw_hi();
688 extern Addr_T adw_lo();
689 extern Addr_T evword();
695 extern VOID relerr();
696 extern char * errmsg[];
697 extern VOID errdmp();
698 extern VOID relerp();
699 extern VOID erpdmp();
700 extern VOID prntval();
703 extern VOID addfile();
704 extern VOID addlib();
705 extern VOID addpath();
707 extern VOID library();
708 extern VOID loadfile();
709 extern VOID search();