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 */
83 * This file defines the format of the
84 * relocatable binary file.
87 #define NCPS 80 /* characters per symbol (JLH: change from 8) */
88 #define NDATA 16 /* actual data */
89 #define NINPUT 128 /* Input buffer size */
90 #define NHASH 64 /* Buckets in hash table */
91 #define HMASK 077 /* Hash mask */
92 #define NLPP 60 /* Lines per page */
93 #define NTXT 16 /* T values */
94 #define FILSPC 80 /* File spec length */
97 * The "R_" relocation constants define values used in
98 * generating the assembler relocation output data for
99 * areas, symbols, and code.
105 * +-----+-----+-----+-----+-----+-----+-----+-----+
106 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
107 * +-----+-----+-----+-----+-----+-----+-----+-----+
110 #define R_WORD 0000 /* 16 bit */
111 #define R_BYTE 0001 /* 8 bit */
113 #define R_AREA 0000 /* Base type */
116 #define R_NORM 0000 /* PC adjust */
119 #define R_BYT1 0000 /* Byte count for R_BYTE = 1 */
120 #define R_BYT2 0010 /* Byte count for R_BYTE = 2 */
122 #define R_SGND 0000 /* Signed value */
123 #define R_USGN 0020 /* Unsigned value */
125 #define R_NOPAG 0000 /* Page Mode */
126 #define R_PAG0 0040 /* Page '0' */
127 #define R_PAG 0100 /* Page 'nnn' */
132 #define R_LSB 0000 /* output low byte */
133 #define R_MSB 0200 /* output high byte */
135 #define R_J11 (R_WORD|R_BYT2) /* JLH: 11 bit JMP and CALL (8051) */
138 * Global symbol types.
140 #define S_REF 1 /* referenced */
141 #define S_DEF 2 /* defined */
146 #define A_CON 0000 /* concatenate */
147 #define A_OVR 0004 /* overlay */
148 #define A_REL 0000 /* relocatable */
149 #define A_ABS 0010 /* absolute */
150 #define A_NOPAG 0000 /* non-paged */
151 #define A_PAG 0020 /* paged */
153 /* Additional flags for 8051 address spaces */
154 #define A_DATA 0000 /* data space (default)*/
155 #define A_CODE 0040 /* code space */
156 #define A_XDATA 0100 /* external data space */
157 #define A_BIT 0200 /* bit addressable space */
162 #define F_STD 1 /* stdin */
163 #define F_LNK 2 /* File.lnk */
164 #define F_REL 3 /* File.rel */
167 * General assembler address type
169 typedef unsigned int addr_t;
172 * The structures of head, area, areax, and sym are created
173 * as the REL files are read during the first pass of the
174 * linker. The struct head is created upon encountering a
175 * H directive in the REL file. The structure contains a
176 * link to a link file structure (struct lfile) which describes
177 * the file containing the H directive, the number of data/code
178 * areas contained in this header segment, the number of
179 * symbols referenced/defined in this header segment, a pointer
180 * to an array of pointers to areax structures (struct areax)
181 * created as each A directive is read, and a pointer to an
182 * array of pointers to symbol structures (struct sym) for
183 * all referenced/defined symbols. As H directives are read
184 * from the REL files a linked list of head structures is
185 * created by placing a link to the new head structure
186 * in the previous head structure.
190 struct head *h_hp; /* Header link */
191 struct lfile *h_lfile;/* Associated file */
192 int h_narea; /* # of areas */
193 struct areax **a_list; /* Area list */
194 int h_nglob; /* # of global symbols */
195 struct sym **s_list; /* Globle symbol list */
196 char m_id[NCPS]; /* Module name */
200 * A structure area is created for each 'unique' data/code
201 * area definition found as the REL files are read. The
202 * struct area contains the name of the area, a flag byte
203 * which contains the area attributes (REL/CON/OVR/ABS),
204 * an area subtype (not used in this assembler), and the
205 * area base address and total size which will be filled
206 * in at the end of the first pass through the REL files.
207 * As A directives are read from the REL files a linked
208 * list of unique area structures is created by placing a
209 * link to the new area structure in the previous area structure.
213 struct area *a_ap; /* Area link */
214 struct areax *a_axp; /* Area extension link */
215 addr_t a_addr; /* Beginning address of area */
216 addr_t a_size; /* Total size of the area */
217 char a_type; /* Area subtype */
218 char a_flag; /* Flag byte */
219 char a_id[NCPS]; /* Name */
223 * An areax structure is created for every A directive found
224 * while reading the REL files. The struct areax contains a
225 * link to the 'unique' area structure referenced by the A
226 * directive and to the head structure this area segment is
227 * a part of. The size of this area segment as read from the
228 * A directive is placed in the areax structure. The beginning
229 * address of this segment will be filled in at the end of the
230 * first pass through the REL files. As A directives are read
231 * from the REL files a linked list of areax structures is
232 * created for each unique area. The final areax linked
233 * list has at its head the 'unique' area structure linked
234 * to the linked areax structures (one areax structure for
235 * each A directive for this area).
239 struct areax *a_axp; /* Area extension link */
240 struct area *a_bap; /* Base area link */
241 struct head *a_bhp; /* Base header link */
242 addr_t a_addr; /* Beginning address of section */
243 addr_t a_size; /* Size of the area in section */
247 * A sym structure is created for every unique symbol
248 * referenced/defined while reading the REL files. The
249 * struct sym contains the symbol's name, a flag value
250 * (not used in this linker), a symbol type denoting
251 * referenced/defined, and an address which is loaded
252 * with the relative address within the area in which
253 * the symbol was defined. The sym structure also
254 * contains a link to the area where the symbol was defined.
255 * The sym structures are linked into linked lists using
256 * the symbol link element.
260 struct sym *s_sp; /* Symbol link */
261 struct areax *s_axp; /* Symbol area link */
262 char s_type; /* Symbol subtype */
263 char s_flag; /* Flag byte */
264 addr_t s_addr; /* Address */
265 char *s_id; /* Name: JLH change from [NCPS] */
269 * The structure lfile contains a pointer to a
270 * file specification string, the file type, and
271 * a link to the next lfile structure.
275 struct lfile *f_flp; /* lfile link */
276 int f_type; /* File type */
277 char *f_idp; /* Pointer to file spec */
281 * The struct base contains a pointer to a
282 * base definition string and a link to the next
287 struct base *b_base; /* Base link */
288 char *b_strp; /* String pointer */
292 * The struct globl contains a pointer to a
293 * global definition string and a link to the next
298 struct globl *g_globl; /* Global link */
299 char *g_strp; /* String pointer */
303 * A structure sdp is created for each 'unique' paged
304 * area definition found as the REL files are read.
305 * As P directives are read from the REL files a linked
306 * list of unique sdp structures is created by placing a
307 * link to the new sdp structure in the previous area structure.
311 struct area *s_area; /* Paged Area link */
312 struct areax *s_areax; /* Paged Area Extension Link */
313 addr_t s_addr; /* Page address offset */
317 * The structure rerr is loaded with the information
318 * required to report an error during the linking
319 * process. The structure contains an index value
320 * which selects the areax structure from the header
321 * areax structure list, a mode value which selects
322 * symbol or area relocation, the base address in the
323 * area section, an area/symbol list index value, and
324 * an area/symbol offset value.
328 int aindex; /* Linking area */
329 int mode; /* Relocation mode */
330 addr_t rtbase; /* Base address in section */
331 int rindex; /* Area/Symbol reloaction index */
332 addr_t rval; /* Area/Symbol offset value */
336 * The structure lbpath is created for each library
337 * path specification input by the -k option. The
338 * lbpath structures are linked into a list using
339 * the next link element.
347 * The structure lbname is created for all combinations of the
348 * library path specifications (input by the -k option) and the
349 * library file specifications (input by the -l option) that
350 * lead to an existing file. The element path points to
351 * the path string, element libfil points to the library
352 * file string, and the element libspc is the concatenation
353 * of the valid path and libfil strings.
355 * The lbpath structures are linked into a list
356 * using the next link element.
358 * Each library file contains a list of object files
359 * that are contained in the particular library. e.g.:
364 * Only one specification per line is allowed.
374 * The function fndsym() searches through all combinations of the
375 * library path specifications (input by the -k option) and the
376 * library file specifications (input by the -l option) that
377 * lead to an existing file for a symbol definition.
379 * The structure lbfile is created for the first library
380 * object file which contains the definition for the
381 * specified undefined symbol.
383 * The element libspc points to the library file path specification
384 * and element relfil points to the object file specification string.
385 * The element filspc is the complete path/file specification for
386 * the library file to be imported into the linker. The
387 * file specicifation may be formed in one of two ways:
389 * (1) If the library file contained an absolute
390 * path/file specification then this becomes filspc.
393 * (2) If the library file contains a relative path/file
394 * specification then the concatenation of the path
395 * and this file specification becomes filspc.
398 * The lbpath structures are linked into a list
399 * using the next link element.
409 * External Definitions for all Global Variables
412 extern char *_abs_; /* = { ". .ABS." };
414 extern int lkerr; /* ASLink error flag
416 extern char *ip; /* pointer into the REL file
419 extern char ib[NINPUT]; /* REL file text line
421 extern char *rp; /* pointer into the LST file
424 extern char rb[NINPUT]; /* LST file text line being
427 extern char ctype[]; /* array of character types, one per
432 * Character Type Definitions
445 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
446 #define DGT8 DIGIT|RAD16|RAD10|RAD8
447 #define DGT10 DIGIT|RAD16|RAD10
448 #define LTR16 LETTER|RAD16
452 extern char ccase[]; /* an array of characters which
453 * perform the case translation function
457 extern struct lfile *filep; /* The pointers (lfile *) filep,
458 * (lfile *) cfp, and (FILE *) sfp
459 * are used in conjunction with
460 * the routine getline() to read
461 * asmlnk commands from
462 * (1) the standard input or
463 * (2) or a command file
464 * and to read the REL files
465 * sequentially as defined by the
466 * asmlnk input commands.
468 * The pointer *filep points to the
469 * beginning of a linked list of
472 extern struct lfile *cfp; /* The pointer *cfp points to the
473 * current lfile structure
475 extern struct lfile *startp;/* asmlnk startup file structure
477 extern struct lfile *linkp; /* pointer to first lfile structure
478 * containing an input REL file
481 extern struct lfile *lfp; /* pointer to current lfile structure
482 * being processed by parse()
484 extern struct head *headp; /* The pointer to the first
485 * head structure of a linked list
487 extern struct head *hp; /* Pointer to the current
490 extern struct area *areap; /* The pointer to the first
491 * area structure of a linked list
493 extern struct area *ap; /* Pointer to the current
496 extern struct areax *axp; /* Pointer to the current
499 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
500 * linked symbol lists
502 extern struct base *basep; /* The pointer to the first
505 extern struct base *bsp; /* Pointer to the current
508 extern struct globl *globlp;/* The pointer to the first
511 extern struct globl *gsp; /* Pointer to the current
514 extern struct sdp sdp; /* Base Paged structure
516 extern struct rerr rerr; /* Structure containing the
517 * linker error information
519 extern FILE *ofp; /* Linker Output file handle
521 extern FILE *mfp; /* Map output file handle
523 extern FILE *jfp; /* NoICE output file handle
525 extern FILE *rfp; /* File handle for output
526 * address relocated ASxxxx
529 extern FILE *sfp; /* The file handle sfp points to the
530 * currently open file
532 extern FILE *tfp; /* File handle for input
533 * ASxxxx listing file
535 extern FILE *dfp; /* File handle for debug info output
537 extern int dflag; /* Output debug information flag
539 extern int oflag; /* Output file type flag
541 extern int mflag; /* Map output flag
543 extern int jflag; /* NoICE output flag
545 extern int xflag; /* Map file radix type flag
547 extern int pflag; /* print linker command file flag
549 extern int uflag; /* Listing relocation flag
551 extern int radix; /* current number conversion radix:
552 * 2 (binary), 8 (octal), 10 (decimal),
555 extern int line; /* current line number
557 extern int page; /* current page number
559 extern int lop; /* current line number on page
561 extern int pass; /* linker pass number
563 extern int rtcnt; /* count of elements in the
564 * rtval[] and rtflg[] arrays
566 extern addr_t rtval[]; /* data associated with relocation
568 extern int rtflg[]; /* indicates if rtval[] value is
569 * to be sent to the output file.
570 * (always set in this linker)
572 extern int hilo; /* REL file byte ordering
574 extern int gline; /* LST file relocation active
577 extern int gcntr; /* LST file relocation active
580 extern struct lbpath *lbphead; /* pointer to the first
581 * library path structure
583 extern struct lbname *lbnhead; /* pointer to the first
584 * library name structure
586 extern struct lbfile *lbfhead; /* pointer to the first
587 * library file structure
589 extern addr_t iram_size; /* internal ram size
593 /* C Library function definitions */
594 /* for reference only
597 extern char * fgets();
598 extern FILE * fopen();
599 extern int fprintf();
601 extern VOID * malloc();
603 extern char * strcpy();
605 extern char * strncpy();
608 /* Program function definitions */
611 extern FILE * afile();
612 extern VOID bassav();
613 extern VOID gblsav();
614 extern VOID iramsav();
615 extern VOID iramcheck();
617 extern VOID lkexit();
621 extern VOID setbas();
622 extern VOID setgbl();
624 extern VOID copyfile();
627 extern char endline();
629 extern VOID getfid();
631 extern int getline();
639 extern VOID lkparea();
640 extern VOID lnkarea();
641 extern VOID lnksect();
642 extern VOID newarea();
645 extern VOID module();
646 extern VOID newhead();
650 extern struct sym * lkpsym();
652 extern struct sym * newsym();
653 extern VOID symdef();
655 extern VOID syminit();
656 extern VOID symmod();
657 extern addr_t symval();
661 extern addr_t eval();
662 extern addr_t expr();
664 extern addr_t term();
668 extern VOID lkulist();
669 extern VOID lkalist();
670 extern VOID lkglist();
671 extern VOID lstarea();
672 extern VOID newpag();
676 extern addr_t adb_b();
677 extern addr_t adb_hi();
678 extern addr_t adb_lo();
679 extern addr_t adw_w();
680 extern addr_t adw_hi();
681 extern addr_t adw_lo();
682 extern addr_t evword();
688 extern VOID relerr();
689 extern char * errmsg[];
690 extern VOID errdmp();
691 extern VOID relerp();
692 extern VOID erpdmp();
693 extern VOID prntval();
696 extern VOID addfile();
697 extern VOID addlib();
698 extern VOID addpath();
700 extern VOID library();
701 extern VOID loadfile();
702 extern VOID search();
711 extern char *StoreString( char *str );
714 extern void DefineNoICE( char *name, addr_t value, int page );
716 /* SD added this to change
717 strcmpi --> strcmp (strcmpi NOT ANSI) */
718 #define strcmpi strcmp