4 * (C) Copyright 1989-1995
12 * - change s_id from [NCPS] to pointer (comment)
14 * - add jflag and jfp for NoICE output
23 * The module lkdata contains the global variables
24 * and structures used in the linker aslink.
28 * Definitions for all Global Variables
31 char *_abs_ = { ". .ABS." };
33 int lkerr; /* Linker error flag
35 char *ip; /* Pointer into the REL file text line in ib[]
37 char ib[NINPUT]; /* REL file text line
39 char *rp; /* pointer into the LST file
42 char rb[NINPUT]; /* LST file text line being
46 char sdccopt[NINPUT]="";
47 char sdccopt_module[NINPUT]="";
48 char curr_module[NINPUT]="";
50 int dflag; /* Debug information output flag
52 int oflag; /* Output file type flag
54 int mflag; /* Map output flag
56 int sflag; /* JCF: Memory usage output flag
58 int packflag=0; /* JCF: Pack internal memory flag
60 int stacksize=0; /* JCF: Stack size
62 int aflag; /* Overlapping area warning flag
64 int jflag; /* NoICE output flag
66 int symflag; /* no$gmb .sym output flag
68 int xflag; /* Map file radix type flag
70 int pflag; /* print linker command file flag
72 int uflag; /* Listing relocation flag
74 int rflag; /* Extended linear address record flag.
76 int radix; /* current number conversion radix:
77 * 2 (binary), 8 (octal), 10 (decimal),
80 int line; /* current line number
82 int page; /* current page number
84 int lop; /* current line number on page
86 int pass; /* linker pass number
88 int rtcnt; /* count of elements in the
89 * rtval[] and rtflg[] arrays
91 Addr_T rtval[NTXT]; /* data associated with relocation
93 int rtflg[NTXT]; /* indicates if rtval[] value is
94 * to be sent to the output file.
95 * (always set in this linker)
97 int hilo; /* REL file byte ordering
99 int gline; /* LST file relocation active
102 int gcntr; /* LST file relocation active
105 Addr_T iram_size; /* internal ram size
107 long xram_size=-1; /* external ram size
109 long code_size=-1; /* code size
113 * The structure lfile contains a pointer to a
114 * file specification string, the file type, and
115 * a link to the next lfile structure.
119 * struct lfile *f_flp; lfile link
120 * int f_type; File type
121 * char *f_idp; Pointer to file spec
124 struct lfile *filep; /* The pointers (lfile *) filep,
125 * (lfile *) cfp, and (FILE *) sfp
126 * are used in conjunction with
127 * the routine lk_getline() to read
128 * asmlnk commands from
129 * (1) the standard input or
130 * (2) or a command file
131 * and to read the REL files
132 * sequentially as defined by the
133 * asmlnk input commands.
135 * The pointer *filep points to the
136 * beginning of a linked list of
139 struct lfile *cfp; /* The pointer *cfp points to the
140 * current lfile structure
142 struct lfile *startp;/* asmlnk startup file structure
144 struct lfile *linkp; /* pointer to first lfile structure
145 * containing an input REL file
148 struct lfile *lfp; /* pointer to current lfile structure
149 * being processed by parse()
151 FILE *ofp; /* Output file handle
154 FILE *mfp; /* Map output file handle
156 FILE *jfp; /* NoICE output file handle
158 FILE *rfp; /* File handle for output
159 * address relocated ASxxxx
162 FILE *sfp; /* The file handle sfp points to the
163 * currently open file
165 FILE *tfp; /* File handle for input
166 * ASxxxx listing file
168 FILE *dfp = NULL ; /*
169 * File handle for debug
170 * information output file
173 * The structures of head, area, areax, and sym are created
174 * as the REL files are read during the first pass of the
175 * linker. The struct head is created upon encountering a
176 * H directive in the REL file. The structure contains a
177 * link to a link file structure (struct lfile) which describes
178 * the file containing the H directive, the number of data/code
179 * areas contained in this header segment, the number of
180 * symbols referenced/defined in this header segment, a pointer
181 * to an array of pointers to areax structures (struct areax)
182 * created as each A directive is read, and a pointer to an
183 * array of pointers to symbol structures (struct sym) for
184 * all referenced/defined symbols. As H directives are read
185 * from the REL files a linked list of head structures is
186 * created by placing a link to the new head structure
187 * in the previous head structure.
191 * struct head *h_hp; Header link
192 * struct lfile *h_lfile; Associated file
193 * int h_narea; # of areas
194 * struct areax **a_list; Area list
195 * int h_nglob; # of global symbols
196 * struct sym **s_list; Global symbol list
197 * char m_id[NCPS]; Module name
200 struct head *headp; /* The pointer to the first
201 * head structure of a linked list
203 struct head *hp; /* Pointer to the current
208 * A structure area is created for each 'unique' data/code
209 * area definition found as the REL files are read. The
210 * struct area contains the name of the area, a flag byte
211 * which contains the area attributes (REL/CON/OVR/ABS),
212 * an area subtype (not used in this assembler), and the
213 * area base address and total size which will be filled
214 * in at the end of the first pass through the REL files.
215 * As A directives are read from the REL files a linked
216 * list of unique area structures is created by placing a
217 * link to the new area structure in the previous area structure.
221 * struct area *a_ap; Area link
222 * struct areax *a_axp; Area extension link
223 * Addr_T a_addr; Beginning address of area
224 * Addr_T a_size; Total size of the area
225 * char a_type; Area subtype
226 * char a_flag; Flag byte
227 * char a_id[NCPS]; Name
230 struct area *areap; /* The pointer to the first
231 * area structure of a linked list
233 struct area *ap; /* Pointer to the current
238 * An areax structure is created for every A directive found
239 * while reading the REL files. The struct areax contains a
240 * link to the 'unique' area structure referenced by the A
241 * directive and to the head structure this area segment is
242 * a part of. The size of this area segment as read from the
243 * A directive is placed in the areax structure. The beginning
244 * address of this segment will be filled in at the end of the
245 * first pass through the REL files. As A directives are read
246 * from the REL files a linked list of areax structures is
247 * created for each unique area. The final areax linked
248 * list has at its head the 'unique' area structure linked
249 * to the linked areax structures (one areax structure for
250 * each A directive for this area).
254 * struct areax *a_axp; Area extension link
255 * struct area *a_bap; Base area link
256 * struct head *a_bhp; Base header link
257 * Addr_T a_addr; Beginning address of section
258 * Addr_T a_size; Size of the area in section
261 struct areax *axp; /* Pointer to the current
266 * A sym structure is created for every unique symbol
267 * referenced/defined while reading the REL files. The
268 * struct sym contains the symbol's name, a flag value
269 * (not used in this linker), a symbol type denoting
270 * referenced/defined, and an address which is loaded
271 * with the relative address within the area in which
272 * the symbol was defined. The sym structure also
273 * contains a link to the area where the symbol was defined.
274 * The sym structures are linked into linked lists using
275 * the symbol link element.
279 * struct sym *s_sp; Symbol link
280 * struct areax *s_axp; Symbol area link
281 * char s_type; Symbol subtype
282 * char s_flag; Flag byte
283 * Addr_T s_addr; Address
284 * char *s_id; Name (JLH)
287 struct sym *symhash[NHASH]; /* array of pointers to NHASH
288 * linked symbol lists
291 * The struct base contains a pointer to a
292 * base definition string and a link to the next
297 * struct base *b_base; Base link
298 * char *b_strp; String pointer
301 struct base *basep; /* The pointer to the first
304 struct base *bsp; /* Pointer to the current
309 * The struct globl contains a pointer to a
310 * global definition string and a link to the next
315 * struct globl *g_globl; Global link
316 * char *g_strp; String pointer
319 struct globl *globlp;/* The pointer to the first
322 struct globl *gsp; /* Pointer to the current
327 * A structure sdp is created for each 'unique' paged
328 * area definition found as the REL files are read.
329 * As P directives are read from the REL files a linked
330 * list of unique sdp structures is created by placing a
331 * link to the new sdp structure in the previous area structure.
335 * struct area *s_area; Paged Area link
336 * struct areax *s_areax; Paged Area Extension Link
337 * Addr_T s_addr; Page address offset
340 struct sdp sdp; /* Base Page Structure */
343 * The structure rerr is loaded with the information
344 * required to report an error during the linking
345 * process. The structure contains an index value
346 * which selects the areax structure from the header
347 * areax structure list, a mode value which selects
348 * symbol or area relocation, the base address in the
349 * area section, an area/symbol list index value, and
350 * an area/symbol offset value.
354 * int aindex; Linking area
355 * int mode; Relocation mode
356 * Addr_T rtbase; Base address in section
357 * int rindex; Area/Symbol reloaction index
358 * Addr_T rval; Area/Symbol offset value
361 struct rerr rerr; /* Structure containing the
362 * linker error information
366 * The structure lbpath is created for each library
367 * path specification input by the -k option. The
368 * lbpath structures are linked into a list using
369 * the next link element.
372 * struct lbpath *next;
376 struct lbpath *lbphead; /* pointer to the first
377 * library path structure
381 * The structure lbname is created for all combinations of the
382 * library path specifications (input by the -k option) and the
383 * library file specifications (input by the -l option) that
384 * lead to an existing file. The element path points to
385 * the path string, element libfil points to the library
386 * file string, and the element libspc is the concatenation
387 * of the valid path and libfil strings.
389 * The lbpath structures are linked into a list
390 * using the next link element.
392 * Each library file contains a list of object files
393 * that are contained in the particular library. e.g.:
398 * Only one specification per line is allowed.
401 * struct lbname *next;
407 struct lbname *lbnhead; /* pointer to the first
408 * library name structure
412 * The function fndsym() searches through all combinations of the
413 * library path specifications (input by the -k option) and the
414 * library file specifications (input by the -l option) that
415 * lead to an existing file for a symbol definition.
417 * The structure lbfile is created for the first library
418 * object file which contains the definition for the
419 * specified undefined symbol.
421 * The element libspc points to the library file path specification
422 * and element relfil points to the object file specification string.
423 * The element filspc is the complete path/file specification for
424 * the library file to be imported into the linker. The
425 * file specicifation may be formed in one of two ways:
427 * (1) If the library file contained an absolute
428 * path/file specification then this becomes filspc.
431 * (2) If the library file contains a relative path/file
432 * specification then the concatenation of the path
433 * and this file specification becomes filspc.
436 * The lbpath structures are linked into a list
437 * using the next link element.
440 * struct lbfile *next;
446 struct lbfile *lbfhead; /* pointer to the first
447 * library file structure
451 * array of character types, one per
454 unsigned char ctype[128] = {
455 /*NUL*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
456 /*BS*/ ILL, SPACE, ILL, ILL, SPACE, ILL, ILL, ILL,
457 /*DLE*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
458 /*CAN*/ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL,
459 /*SPC*/ SPACE, ETC, ETC, ETC, LETTER, BINOP, BINOP, ETC,
460 /*(*/ ETC, ETC, BINOP, BINOP, ETC, BINOP, LETTER, BINOP,
461 /*0*/ DGT2, DGT2, DGT8, DGT8, DGT8, DGT8, DGT8, DGT8,
462 /*8*/ DGT10, DGT10, ETC, ETC, BINOP, ETC, BINOP, ETC,
463 /*@*/ ETC, LTR16, LTR16, LTR16, LTR16, LTR16, LTR16, LETTER,
464 /*H*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
465 /*P*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
466 /*X*/ LETTER, LETTER, LETTER, BINOP, ETC, ETC, BINOP, LETTER,
467 /*`*/ ETC, LTR16, LTR16, LTR16, LTR16, LTR16, LTR16, LETTER,
468 /*h*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
469 /*p*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
470 /*x*/ LETTER, LETTER, LETTER, ETC, BINOP, ETC, ETC, ETC
474 * an array of characters which
475 * perform the case translation function
480 /*NUL*/ '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
481 /*BS*/ '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
482 /*DLE*/ '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
483 /*CAN*/ '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
484 /*SPC*/ '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
485 /*(*/ '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
486 /*0*/ '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
487 /*8*/ '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
488 /*@*/ '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
489 /*H*/ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
490 /*P*/ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
491 /*X*/ '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
492 /*`*/ '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
493 /*h*/ '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
494 /*p*/ '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
495 /*x*/ '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177'