struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / sdas / linksrc / aslink.h
blob4033cfa83f3df9a7c81f4346f2a188ad094203b7
1 /* aslink.h */
3 /*
4 * Copyright (C) 1989-2021 Alan R. Baldwin
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Alan R. Baldwin
21 * 721 Berkeley St.
22 * Kent, Ohio 44240
24 * With enhancements from
25 * John L. Hartman (JLH)
26 * jhartman@compuserve.com
30 * System Include Files
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include "sdld.h"
39 * Local Definitions
42 #define VERSION "V03.00/V05.40 + sdld"
43 #define COPYRIGHT "2021"
46 * To include NoICE Debugging set non-zero
48 #define NOICE 1
51 * To include SDCC Debugging set non-zero
53 #define SDCDB 1
56 * The assembler requires certain variables to have
57 * at least 32 bits to allow correct address processing.
59 * The type INT32 is defined so that compiler dependent
60 * variable sizes may be specified in one place.
62 * LONGINT is defined when INT32 is 'long' to
63 * select the 'l' forms for format strings.
66 /* Turbo C++ 3.0 for DOS */
67 /* 'int' is 16-bits, 'long' is 32-bits */
69 #ifdef __TURBOC__
70 #define INT32 long
71 #define LONGINT
72 #endif
74 /* Symantec C++ V6.x/V7.x for DOS (not DOSX) */
75 /* 'int' is 16-bits, 'long' is 32-bits */
77 #ifdef __SC__
78 #define INT32 long
79 #define LONGINT
80 #endif
82 /* The DEFAULT is 'int' is 32 bits */
83 #ifndef INT32
84 #define INT32 int
85 #endif
88 /*)Module aslink.h
90 * The module aslink.h contains the definitions for constants,
91 * structures, global variables, and LKxxxx functions
92 * contained in the LKxxxx.c files.
95 /*)BUILD
96 $(PROGRAM) = ASLINK
97 $(INCLUDE) = ASLINK.H
98 $(FILES) = {
99 LKMAIN.C
100 LKLEX.C
101 LKAREA.C
102 LKBANK.C
103 LKHEAD.C
104 LKSYM.C
105 LKEVAL.C
106 LKDATA.C
107 LKLIST.C
108 LKNOICE.C
109 LKSDCDB.C
110 LKRLOC.C
111 LKRLOC3.C
112 LKLIBR.C
113 LKOUT.C
114 LKS19.C
116 $(STACK) = 2000
119 #undef VOID
121 /* DECUS C void definition */
122 /* File/extension seperator */
124 #ifdef DECUS
125 #define VOID char
126 #define FSEPX '.'
127 #endif
129 /* PDOS C void definition */
130 /* File/extension seperator */
132 #ifdef PDOS
133 #define VOID char
134 #define FSEPX ':'
135 #endif
137 /* Default void definition */
138 /* File/extension seperator */
140 #ifndef VOID
141 #define VOID void
142 #define FSEPX '.'
143 #define OTHERSYSTEM
144 #endif
146 #ifdef UNIX
147 /* UNIX void definition */
148 /* File/extension seperator */
150 #define LKDIRSEP '/'
151 #define LKDIRSEPSTR "/"
153 #else
154 /* DOS/WINDOWS void definition */
155 /* File/extension seperator */
157 #define LKDIRSEP '\\'
158 #define LKDIRSEPSTR "\\"
160 #endif
163 * PATH_MAX
165 #include <limits.h>
166 #ifndef PATH_MAX /* POSIX, but not required */
167 #if defined(__BORLANDC__) || defined(_MSC_VER)
168 #include <stdlib.h>
169 #define PATH_MAX _MAX_PATH
170 #elif defined(__x86_64__)
171 #define PATH_MAX 4096
172 #else
173 #define PATH_MAX 255 /* define a reasonable value */
174 #endif
175 #endif
177 #ifdef _WIN32 /* WIN32 native */
178 # define NATIVE_WIN32 1
179 # ifdef __MINGW32__ /* GCC MINGW32 depends on configure */
180 # include "../../sdccconf.h"
181 # else
182 # include "../../sdcc_vc.h"
183 # define PATH_MAX _MAX_PATH
184 # endif
185 #else /* Assume *nix style system */
186 # include "../../sdccconf.h"
187 #endif
189 #define LKOBJEXT "rel"
192 * Global symbol types.
194 #define S_REF 1 /* referenced */
195 #define S_DEF 2 /* defined */
198 * File types
200 #define F_OUT 0 /* File.ixx / File.sxx */
201 #define F_STD 1 /* stdin */
202 #define F_LNK 2 /* File.lnk */
203 #define F_REL 3 /* File.rel */
206 * Error definitions
208 #define ER_NONE 0 /* No error */
209 #define ER_WARNING 1 /* Warning */
210 #define ER_ERROR 2 /* Assembly error */
211 #define ER_FATAL 3 /* Fatal error */
214 * This file defines the format of the
215 * relocatable binary file.
218 #define NCPS PATH_MAX /* characters per symbol */
219 #define NINPUT PATH_MAX /* Input buffer size */
220 #define NHASH (1 << 6) /* Buckets in hash table */
221 #define HMASK (NHASH - 1) /* Hash mask */
222 #define NLPP 60 /* Lines per page */
223 #define NMAX 78 /* IXX/SXX/DBX Buffer Length */
224 #define IXXMAXBYTES 32 /* NMAX > (2 * IXXMAXBYTES) */
225 #define SXXMAXBYTES 32 /* NMAX > (2 * SXXMAXBYTES) */
226 #define DBXMAXBYTES 64 /* NMAX > ( DBXMAXBYTES ) */
227 #define FILSPC PATH_MAX /* File spec length */
229 #define NDATA 16 /* actual data */
231 * NTXT must be defined to have the same value in
232 * the ASxxxx assemblers and ASLink.
234 * The R Line coding allows only 4-bits for coding
235 * the T Line index. The MAXIMUM value for NTXT
236 * is 16. It should not be changed.
238 #define NTXT 16 /* T values */
241 * Opcode Cycle definitions (Must Be The Same In ASxxxx / ASLink)
243 #define CYCNT_BGN '[' /* Cycle count begin delimiter */
244 #define CYCNT_END ']' /* Cycle count end delimiter */
247 * Internal ASxxxx Version Variable
249 extern int ASxxxx_VERSION;
253 * ASLINK - Version 3 Definitions
257 * The "A3_" area constants define values used in
258 * generating the assembler area output data.
260 * Area flags
262 * 7 6 5 4 3 2 1 0
263 * +-----+-----+-----+-----+-----+-----+-----+-----+
264 * | | | | PAG | ABS | OVR | | |
265 * +-----+-----+-----+-----+-----+-----+-----+-----+
268 #define A3_CON 000 /* concatenate */
269 #define A3_OVR 004 /* overlay */
270 #define A3_REL 000 /* relocatable */
271 #define A3_ABS 010 /* absolute */
272 #define A3_NOPAG 000 /* non-paged */
273 #define A3_PAG 020 /* paged */
275 /* sdld specific */
276 /* Additional flags for 8051 address spaces */
277 #define A_DATA 0000 /* data space (default)*/
278 #define A_CODE 0040 /* code space */
279 #define A_XDATA 0100 /* external data space */
280 #define A_BIT 0200 /* bit addressable space */
282 /* Additional flags for hc08 */
283 #define A_NOLOAD 0400 /* nonloadable */
284 #define A_LOAD 0000 /* loadable (default) */
285 /* end sdld specific */
288 * The "R3_" relocation constants define values used in
289 * generating the assembler relocation output data for
290 * areas, symbols, and code.
293 * Relocation types.
295 * 7 6 5 4 3 2 1 0
296 * +-----+-----+-----+-----+-----+-----+-----+-----+
297 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
298 * +-----+-----+-----+-----+-----+-----+-----+-----+
301 #define R3_WORD 0000 /* 16 bit */
302 #define R3_BYTE 0001 /* 8 bit */
304 #define R3_AREA 0000 /* Base type */
305 #define R3_SYM 0002
307 #define R3_NORM 0000 /* PC adjust */
308 #define R3_PCR 0004
310 #define R3_BYT1 0000 /* Byte count for R_BYTE = 1 */
311 #define R3_BYTX 0010 /* Byte count for R_BYTE = X */
313 #define R3_SGND 0000 /* Signed value */
314 #define R3_USGN 0020 /* Unsigned value */
316 #define R3_NOPAG 0000 /* Page Mode */
317 #define R3_PAG0 0040 /* Page '0' */
318 #define R3_PAG 0100 /* Page 'nnn' */
320 #define R3_LSB 0000 /* output low byte */
321 #define R3_MSB 0200 /* output high byte */
324 * Additional "R3_" functionality is required to support
325 * some microprocesssor architectures. The 'illegal'
326 * "R3_" mode of R3_WORD | R3_BYTX is used as a designator
327 * of the extended R3_ modes. The extended modes replace
328 * the PAGING modes and are being added in an adhoc manner
329 * as follows:
331 * Extended Mode relocation flags
333 * 7 6 5 4 3 2 1 0
334 * +-----+-----+-----+-----+-----+-----+-----+-----+
335 * | MSB | x | x | USGN| 1 | PCR | SYM | 0 |
336 * +-----+-----+-----+-----+-----+-----+-----+-----+
339 #define R3_ECHEK 0011 /* Extended Mode Check Bits */
340 #define R3_EXTND 0010 /* Extended Mode Code */
341 #define R3_EMASK 0151 /* Extended Mode Mask */
343 /* #define R3_AREA 0000 */ /* Base type */
344 /* #define R3_SYM 0002 */
346 /* #define R3_NORM 0000 */ /* PC adjust */
347 /* #define R3_PCR 0004 */
349 /* #define R3_SGND 0000 */ /* Signed value */
350 /* #define R3_USGN 0020 */ /* Unsigned value */
352 /* #define R3_LSB 0000 */ /* output low byte */
353 /* #define R3_MSB 0200 */ /* output high byte */
355 #define R3_J11 (R3_WORD|R3_BYTX) /* JLH: 11 bit JMP and CALL (8051) */
356 #define R3_J19 (R3_WORD|R3_BYTX|R3_MSB) /* BM: 19 bit JMP and CALL (DS80C390) */
357 #define R_C24 (R3_WORD|R3_BYT1|R3_MSB) /* 24 bit address (DS80C390) */
358 #define R_J19_MASK (R3_BYTE|R3_BYTX|R3_MSB)
360 #define IS_R_J19(x) (((x) & R_J19_MASK) == R3_J19)
361 #define IS_R_J11(x) (((x) & R_J19_MASK) == R3_J11)
362 #define IS_C24(x) (((x) & R_J19_MASK) == R_C24)
364 /* sdld specific */
365 #define R_BYT3 0x100 /* if R3_BYTE is set, this is a
366 * 3 byte address, of which
367 * the linker must select one byte.
369 #define R_HIB 0x200 /* If R3_BYTE & R_BYT3 are set, linker
370 * will select byte 3 of the relocated
371 * 24 bit address.
374 #define R_BIT 0x400 /* Linker will convert from byte-addressable
375 * space to bit-addressable space.
378 #define R_ESCAPE_MASK 0xf0 /* Used to escape relocation modes
379 * greater than 0xff in the .rel
380 * file.
382 /* end sdld specific */
386 * The "A4_" area constants define values used in
387 * generating the assembler area output data.
389 * Area flags
391 * 7 6 5 4 3 2 1 0
392 * +-----+-----+-----+-----+-----+-----+-----+-----+
393 * | BNK | SEG | | PAG | ABS | OVR | WL1 | WL0 |
394 * +-----+-----+-----+-----+-----+-----+-----+-----+
397 #define A4_BYTE 0x0000 /* 8 bit */
398 #define A4_WORD 0x0001 /* 16 bit */
400 #define A4_1BYTE 0x0000 /* 1 Byte Word Length */
401 #define A4_2BYTE 0x0001 /* 2 Byte Word Length */
402 #define A4_3BYTE 0x0002 /* 3 Byte Word Length */
403 #define A4_4BYTE 0x0003 /* 4 Byte Word Length */
404 #define A4_WLMSK 0x0003 /* Word Length Mask */
406 #define A4_CON 0x0400 /* Concatenating */
407 #define A4_OVR 0x0404 /* Overlaying */
408 #define A4_REL 0x0800 /* Relocatable */
409 #define A4_ABS 0x0808 /* absolute */
410 #define A4_NOPAG 0x1000 /* Non-Paged */
411 #define A4_PAG 0x1010 /* Paged */
413 #define A4_CSEG 0x4000 /* CSEG */
414 #define A4_DSEG 0x4040 /* DSEG */
415 #define A4_NOBNK 0x8000 /* Non-Banked */
416 #define A4_BNK 0x8080 /* Banked */
418 #define A4_OUT 0x0100 /* Output Code Flag */
421 * The "R4_" relocation constants define values used in
422 * generating the assembler relocation output data for
423 * areas, symbols, and code.
425 * Note: The PAGE modes, PCR modes, Signed, Unsigned,
426 * and MSB codes are mutually exclusive !!!
429 * Relocation flags
431 * 7 6 5 4 3 2 1 0
432 * +-----+-----+-----+-----+-----+-----+-----+-----+
433 * | SYM | PCR | PAGn| PAG0| USGN| SGND| BYT1| BYT0|
434 * +-----+-----+-----+-----+-----+-----+-----+-----+
437 #define R4_BYTE 0x0000 /* 8 bit */
438 #define R4_WORD 0x0001 /* 16 bit */
440 #define R4_1BYTE 0x0000 /* 1 Byte */
441 #define R4_2BYTE 0x0001 /* 2 Byte */
442 #define R4_3BYTE 0x0002 /* 3 Byte */
443 #define R4_4BYTE 0x0003 /* 4 Byte */
444 #define R4_BYTES 0x0003 /* Data Size */
446 #define R4_SGND 0x0004 /* Signed */
447 #define R4_USGN 0x0008 /* Unsigned */
448 #define R4_OVRF 0x0008 /* Overflow */
450 #define R4_MBRS 0x0004 /* Merge Bit Range Signed */
451 /* An alias for Signed */
452 #define R4_MBRU 0x0008 /* Merge Bit Range Unsigned */
453 /* An alias for Unsigned */
454 #define R4_MBRO 0x0008 /* Merge Bit Range Overflow */
455 /* An alias for Unsigned */
457 #define R4_MSB 0x000C /* MSB */
458 /* Mutually exclusive with Signed / Unsigned */
460 #define R4_AREA 0x0000 /* Base type */
461 #define R4_SYM 0x0080
464 * Paging Modes:
467 #define R4_NOPAG 0x0000 /* Page Mode */
468 #define R4_PBITS 0x003C /* Paging Bits */
469 #define R4_PAGE 0x0030 /* Paged Addressing */
470 #define R4_PAG0 0x0010 /* Page '0' .setdp */
471 #define R4_PAGN 0x0020 /* Page 'nnn' .setdp */
472 #define R4_PAGX 0x0030 /* Page 'x', Extended Relocation Mode */
473 #define R4_PAGX0 0x0030 /* Page 'x', pc + 0 */
474 #define R4_PAGX1 0x0034 /* Page 'x', pc + 1 */
475 #define R4_PAGX2 0x0038 /* Page 'x', pc + 2 */
476 #define R4_PAGX3 0x003C /* Page 'x', pc + 3 */
479 * PCR Modes:
482 #define R4_PCR 0x0040 /* PC adjust (default) */
483 #define R4_PCRN 0x0050 /* PC adjust (default) no range check */
485 #define R4_PCR0 0x0054 /* PC adjust (offset = 0) */
486 #define R4_PCR1 0x0060 /* PC adjust (offset = 1) */
487 #define R4_PCR2 0x0064 /* PC adjust (offset = 2) */
488 #define R4_PCR3 0x0068 /* PC adjust (offset = 3) */
489 #define R4_PCR4 0x006C /* PC adjust (offset = 4) */
491 #define R4_PCR0N 0x0058 /* PC adjust (offset = 0) no range check */
492 #define R4_PCR1N 0x0070 /* PC adjust (offset = 1) no range check */
493 #define R4_PCR2N 0x0074 /* PC adjust (offset = 2) no range check */
494 #define R4_PCR3N 0x0078 /* PC adjust (offset = 3) no range check */
495 #define R4_PCR4N 0x007C /* PC adjust (offset = 4) no range check */
498 * Basic Relocation Modes
501 #define R4_NORM 0x0000 /* No Bit Positioning */
505 * The defined type 'a_uint' is used for all address and
506 * unsigned variable value calculations. Its size is
507 * required to be at least 32-bits to allow upto
508 * 32-bit addressing or 32-bit value manipulation.
510 typedef unsigned INT32 a_uint;
513 * The defined type 'v_sint' is used for address and
514 * variable value calculations requiring a sign.
515 * Its size is required to be at least 32-bits to allow
516 * upto 32-bit addressing or 32-bit value manipulation.
518 typedef signed INT32 v_sint;
521 * The structures of head, mode, bank, area, areax, and sym
522 * are created as the REL files are read during the first
523 * pass of the linker. The struct head is created upon
524 * encountering a H directive in the REL file. The
525 * structure contains a link to a link file structure
526 * (struct lfile) which describes the file containing the H
527 * directive, a pointer to an array of merge mode
528 * definition pointers, the number of data/code areas
529 * contained in this header segment, the number of
530 * symbols referenced/defined in this header segment, a pointer
531 * to an array of pointers to areax structures (struct areax)
532 * created as each A directive is read, a pointer to an
533 * array of pointers to symbol structures (struct sym) for
534 * all referenced/defined symbols and a pointer to an array
535 * of pointers to bank structures (struct bank) referenced
536 * by this module. As H directives are read
537 * from the REL files a linked list of head structures is
538 * created by placing a link to the new head structure
539 * in the previous head structure.
541 struct head
543 struct head *h_hp; /* Header link */
544 struct lfile *h_lfile; /* Associated file */
545 int h_narea; /* # of areas */
546 struct areax **a_list; /* Area list */
547 int h_nsym; /* # of symbols */
548 struct sym **s_list; /* Symbol list */
549 int h_nbank; /* # of banks */
550 struct bank **b_list; /* Bank list */
551 int h_nmode; /* # of modes */
552 struct mode **m_list; /* Mode list */
553 char * m_id; /* Module name */
557 * The MODE structure contains the specification of one of the
558 * assemblers' relocation modes. Each assembler must specify
559 * at least one relocation mode. The relocation specification
560 * allows arbitrarily defined active bits and bit positions.
561 * The 32 element arrays are indexed from 0 to 31.
562 * Index 0 corresponds to bit 0, ..., and 31 corresponds to bit 31
563 * of a normal integer value.
565 * The value an array element defines if the normal integer bit is
566 * active (bit <7> is set, 0x80) and what destination bit
567 * (bits <4:0>, 0 - 31) should be loaded with this normal
568 * integer bit.
570 * The specification for a 32-bit integer:
572 * char mode_[32] = {
573 * 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
574 * 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
575 * 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
576 * 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F
577 * };
580 * The specification for the 11-bit 8051 addressing mode:
582 * char mode_[32] = {
583 * 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
584 * 0x8D, 0x8E, 0x8F, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
585 * 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
586 * 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
587 * };
590 * m_def is the bit relocation definition array.
591 * m_flag indicates that bit position swapping is required.
592 * m_dbits contains the active bit positions for the output.
593 * m_sbits contains the active bit positions for the input.
595 struct mode
597 char m_def[32]; /* Bit Relocation Definition */
598 int m_flag; /* Bit Swapping Flag */
599 a_uint m_dbits; /* Destination Bit Mask */
600 a_uint m_sbits; /* Source Bit Mask */
604 * The bank structure contains the parameter values for a
605 * specific program or data bank. The bank structure
606 * is a linked list of banks. The initial default bank
607 * is unnamed and is defined in lkdata.c, the next bank structure
608 * will be linked to this structure through the structure
609 * element 'struct bank *b_bp'. The structure contains the
610 * bank name, the bank base address (default = 0), the bank size
611 * (default = 0, whole addressing space), the bank mapping,
612 * and the file name suffix. (default is none) These optional
613 * parameters are from the .bank assembler directive.
614 * The bank structure also contains the bank data output
615 * file specification, file handle pointer and the
616 * bank first output flag.
618 struct bank
620 struct bank *b_bp; /* Bank link */
621 char * b_id; /* Bank Name */
622 char * b_fsfx; /* Bank File Suffix / File Specification */
623 a_uint b_base; /* Bank base address */
624 a_uint b_size; /* Bank size */
625 a_uint b_map; /* Bank mapping */
626 int b_flag; /* Bank flags */
627 char * b_fspec; /* Bank File Specification */
628 FILE * b_ofp; /* Bank File Handle */
629 char * b_ofspec; /* Bank Output File Specification */
630 int b_oflag; /* Bank has output flag */
631 int b_rtaflg; /* Bank First Output flag */
634 #define B_BASE 0001 /* 'base' address specified */
635 #define B_SIZE 0002 /* 'size' of bank specified */
636 #define B_FSFX 0004 /* File suffix specified */
637 #define B_MAP 0010 /* Mapped Bank Flag */
640 * A structure area is created for each 'unique' data/code
641 * area definition found as the REL files are read. The
642 * struct area contains the name of the area, a flag byte
643 * which contains the area attributes (REL/CON/OVR/ABS),
644 * the area base address set flag byte (-b option), and the
645 * area base address and total size which will be filled
646 * in at the end of the first pass through the REL files.
647 * The area structure also contains a link to the bank
648 * this area is a part of and a data output file handle
649 * pointer which is loaded from from the bank structure.
650 * As A directives are read from the REL files a linked
651 * list of unique area structures is created by placing a
652 * link to the new area structure in the previous area structure.
654 struct area
656 struct area *a_ap; /* Area link */
657 struct areax *a_axp; /* Area extension link */
658 struct bank *a_bp; /* Bank link */
659 FILE * a_ofp; /* Area File Handle */
660 a_uint a_addr; /* Beginning address of area */
661 a_uint a_size; /* Total size of the area */
662 int a_bset; /* Area base address set */
663 /* sdld specific */
664 a_uint a_unaloc; /* Total number of unallocated bytes, for error reporting */
665 /* end sdld specific */
666 int a_flag; /* Flags */
667 char * a_id; /* Name */
668 /* sdld specific */
669 char *a_image; /* Something for hc08/lkelf */
670 char *a_used; /* Something for hc08/lkelf */
671 a_uint a_imagesize; /* Something for hc08/lkelf */
672 /* end sdld specific */
676 * An areax structure is created for every A directive found
677 * while reading the REL files. The struct areax contains a
678 * link to the 'unique' area structure referenced by the A
679 * directive and to the head structure this area segment is
680 * a part of. The size of this area segment as read from the
681 * A directive is placed in the areax structure. The beginning
682 * address of this segment will be filled in at the end of the
683 * first pass through the REL files. As A directives are read
684 * from the REL files a linked list of areax structures is
685 * created for each unique area. The final areax linked
686 * list has at its head the 'unique' area structure linked
687 * to the linked areax structures (one areax structure for
688 * each A directive for this area).
690 struct areax
692 struct areax *a_axp; /* Area extension link */
693 struct area *a_bap; /* Base area link */
694 struct head *a_bhp; /* Base header link */
695 a_uint a_addr; /* Beginning address of section */
696 a_uint a_size; /* Size of the area in section */
700 * A sym structure is created for every unique symbol
701 * referenced/defined while reading the REL files. The
702 * struct sym contains the symbol's name, a flag value
703 * (not used in this linker), a symbol type denoting
704 * referenced/defined, and an address which is loaded
705 * with the relative address within the area in which
706 * the symbol was defined. The sym structure also
707 * contains a link to the area where the symbol was defined.
708 * The sym structures are linked into linked lists using
709 * the symbol link element.
711 struct sym
713 struct sym *s_sp; /* Symbol link */
714 struct areax *s_axp; /* Symbol area link */
715 char s_type; /* Symbol subtype */
716 char s_flag; /* Flag byte */
717 a_uint s_addr; /* Address */
718 char *s_id; /* Name (JLH) */
719 char *m_id; /* Module symbol define in */
723 * The structure lfile contains a pointer to a
724 * file specification string, an index which points
725 * to the file name (past the 'path'), the file type,
726 * an object output flag, and a link to the next
727 * lfile structure.
729 struct lfile
731 struct lfile *f_flp; /* lfile link */
732 int f_type; /* File type */
733 char *f_idp; /* Pointer to file spec */
734 int f_idx; /* Index to file name */
735 int f_obj; /* Object output flag */
739 * The struct base contains a pointer to a
740 * base definition string and a link to the next
741 * base structure.
743 struct base
745 struct base *b_base; /* Base link */
746 char *b_strp; /* String pointer */
750 * The struct globl contains a pointer to a
751 * global definition string and a link to the next
752 * global structure.
754 struct globl
756 struct globl *g_globl; /* Global link */
757 char *g_strp; /* String pointer */
761 * A structure sdp is created for each 'unique' paged
762 * area definition found as the REL files are read.
763 * As P directives are read from the REL files a linked
764 * list of unique sdp structures is created by placing a
765 * link to the new sdp structure in the previous area structure.
767 struct sdp
769 struct area *s_area; /* Paged Area link */
770 struct areax *s_areax; /* Paged Area Extension Link */
771 a_uint s_addr; /* Page address offset */
775 * The structure rerr is loaded with the information
776 * required to report an error during the linking
777 * process. The structure contains an index value
778 * which selects the areax structure from the header
779 * areax structure list, a mode value which selects
780 * symbol or area relocation, the base address in the
781 * area section, an area/symbol list index value, and
782 * an area/symbol offset value.
784 struct rerr
786 int aindex; /* Linking area */
787 int mode; /* Relocation mode */
788 a_uint rtbase; /* Base address in section */
789 int rindex; /* Area/Symbol reloaction index */
790 a_uint rval; /* Area/Symbol offset value */
794 * The structure lbpath is created for each library
795 * path specification input by the -k option. The
796 * lbpath structures are linked into a list using
797 * the next link element.
799 struct lbpath {
800 struct lbpath *next;
801 char *path;
805 * The structure lbname is created for all combinations of the
806 * library path specifications (input by the -k option) and the
807 * library file specifications (input by the -l option) that
808 * lead to an existing file. The element path points to
809 * the path string, element libfil points to the library
810 * file string, and the element libspc is the concatenation
811 * of the valid path and libfil strings.
813 * The lbpath structures are linked into a list
814 * using the next link element.
816 * Each library file contains a list of object files
817 * that are contained in the particular library. e.g.:
819 * \iolib\termio
820 * \inilib\termio
822 * Only one specification per line is allowed.
824 struct lbname {
825 struct lbname *next;
826 char *path;
827 char *libfil;
828 char *libspc;
829 int f_obj;
833 * The function fndsym() searches through all combinations of the
834 * library path specifications (input by the -k option) and the
835 * library file specifications (input by the -l option) that
836 * lead to an existing file for a symbol definition.
838 * The structure lbfile is created for the first library
839 * object file which contains the definition for the
840 * specified undefined symbol.
842 * The element libspc points to the library file path specification
843 * and element relfil points to the object file specification string.
844 * The element filspc is the complete path/file specification for
845 * the library file to be imported into the linker. The f_obj
846 * flag specifies if the object code from this file is
847 * to be output by the linker. The file specification
848 * may be formed in one of two ways:
850 * (1) If the library file contained an absolute
851 * path/file specification then this becomes filspc.
852 * (i.e. C:\...)
854 * (2) If the library file contains a relative path/file
855 * specification then the concatenation of the path
856 * and this file specification becomes filspc.
857 * (i.e. \...)
859 * The lbpath structures are linked into a list
860 * using the next link element.
862 struct lbfile {
863 struct lbfile *next;
864 char *libspc;
865 char *relfil;
866 char *filspc;
867 int f_obj;
868 /* sdld specific */
869 long offset;
870 unsigned int type;
871 /* end sdld specific */
875 * External Definitions for all Global Variables
878 extern char *_abs_; /* = { ". .ABS." };
880 extern int lkerr; /* ASLink error flag
882 extern char *ip; /* pointer into the REL file
883 * text line in ib[]
885 extern char ib[NINPUT]; /* REL file text line
887 extern char *rp; /* pointer into the LST file
888 * text line in rb[]
890 extern char rb[NINPUT]; /* LST file text line being
891 * address relocated
893 extern char ctype[]; /* array of character types, one per
894 * ASCII/OEM character
898 * Character Type Definitions
900 #define SPACE '\000'
901 #define ETC '\000'
902 #define LETTER '\001'
903 #define DIGIT '\002'
904 #define BINOP '\004'
905 #define RAD2 '\010'
906 #define RAD8 '\020'
907 #define RAD10 '\040'
908 #define RAD16 '\100'
909 #define ILL '\200'
911 #define DGT2 DIGIT|RAD16|RAD10|RAD8|RAD2
912 #define DGT8 DIGIT|RAD16|RAD10|RAD8
913 #define DGT10 DIGIT|RAD16|RAD10
914 #define LTR16 LETTER|RAD16
916 extern char afspec[]; /* The filespec created by afile()
918 extern char ccase[]; /* an array of characters which
919 * perform the case translation function
922 extern struct lfile *filep; /* The pointers (lfile *) filep,
923 * (lfile *) cfp, and (FILE *) sfp
924 * are used in conjunction with
925 * the routine nxtline() to read
926 * aslink commands from
927 * (1) the standard input or
928 * (2) or a command file
929 * and to read the REL files
930 * sequentially as defined by the
931 * aslink input commands.
933 * The pointer *filep points to the
934 * beginning of a linked list of
935 * lfile structures.
937 extern struct lfile *cfp; /* The pointer *cfp points to the
938 * current lfile structure
940 extern struct lfile *startp;/* aslink startup file structure
942 extern struct lfile *linkp; /* pointer to first lfile structure
943 * containing an input REL file
944 * specification
946 extern struct lfile *lfp; /* pointer to current lfile structure
947 * being processed by parse()
949 extern struct head *headp; /* The pointer to the first
950 * head structure of a linked list
952 extern struct head *hp; /* Pointer to the current
953 * head structure
955 extern struct bank *bankp; /* The pointer to the first
956 * bank structure of a linked list
958 extern struct bank *bp; /* Pointer to the current
959 * bank structure
961 extern struct area *areap; /* The pointer to the first
962 * area structure of a linked list
964 extern struct area *ap; /* Pointer to the current
965 * area structure
967 extern struct areax *axp; /* Pointer to the current
968 * areax structure
970 extern struct sym *symhash[NHASH]; /* array of pointers to NHASH
971 * linked symbol lists
973 extern struct base *basep; /* The pointer to the first
974 * base structure
976 extern struct base *bsp; /* Pointer to the current
977 * base structure
979 extern struct globl *globlp;/* The pointer to the first
980 * globl structure
982 extern struct globl *gsp; /* Pointer to the current
983 * globl structure
985 extern struct sdp sdp; /* Base Paged structure
987 extern struct rerr rerr; /* Structure containing the
988 * linker error information
990 extern FILE *nbofp; /* Non Banked Linker Output
991 * File Handle
993 extern FILE *ofp; /* Linker Output file handle
996 #if NOICE
997 extern FILE *jfp; /* NoICE output file handle
999 #endif
1001 extern FILE *mfp; /* Map output file handle
1003 extern FILE *rfp; /* File handle for output
1004 * address relocated ASxxxx
1005 * listing file
1007 extern FILE *sfp; /* The file handle sfp points to the
1008 * currently open file
1010 extern FILE *tfp; /* File handle for input
1011 * ASxxxx listing file
1014 #if SDCDB
1015 extern FILE *yfp; /* SDCDB output file handle
1017 #endif
1019 extern int oflag; /* Output file type flag
1021 extern int objflg; /* Linked file/library object output flag
1024 #if NOICE
1025 extern int jflag; /* -j, enable NoICE Debug output
1027 #endif
1029 extern int mflag; /* Map output flag
1031 extern int xflag; /* Map file radix type flag
1034 #if SDCDB
1035 extern int yflag; /* -y, enable SDCC Debug output
1037 #endif
1039 extern int pflag; /* print linker command file flag
1041 extern int uflag; /* Listing relocation flag
1043 extern int wflag; /* Enable wide format listing
1045 extern int zflag; /* Disable symbol case sensitivity
1047 extern int radix; /* current number conversion radix:
1048 * 2 (binary), 8 (octal), 10 (decimal),
1049 * 16 (hexadecimal)
1051 extern int line; /* current line number
1053 extern int page; /* current page number
1055 extern int lop; /* current line number on page
1057 extern int pass; /* linker pass number
1059 extern a_uint pc; /* current relocation address
1061 extern int pcb; /* current bytes per pc word
1063 extern int rtcnt; /* count of elements in the
1064 * rtval[] and rtflg[] arrays
1066 extern a_uint rtval[]; /* data associated with relocation
1068 extern int rtflg[]; /* indicates if rtval[] value is
1069 * to be sent to the output file.
1071 extern int rterr[]; /* indicates if rtval[] value should
1072 * be flagged as a relocation error.
1074 extern char rtbuf[]; /* S19/IHX output buffer
1076 extern struct bank *rtabnk; /* rtbuf[] processing
1078 extern int rtaflg; /* rtbuf[] processing
1080 extern a_uint rtadr0; /*
1082 extern a_uint rtadr1; /*
1084 extern a_uint rtadr2; /*
1086 extern int obj_flag; /* Linked file/library object output flag
1088 extern int a_bytes; /* REL file T Line address length
1090 extern int hilo; /* REL file byte ordering
1092 extern a_uint a_mask; /* Address Mask
1094 extern a_uint s_mask; /* Sign Mask
1096 extern a_uint v_mask; /* Value Mask
1098 extern int gline; /* LST file relocation active
1099 * for current line
1101 extern int gcntr; /* LST file relocation active
1102 * counter
1104 extern struct lbpath *lbphead; /* pointer to the first
1105 * library path structure
1107 extern struct lbname *lbnhead; /* pointer to the first
1108 * library name structure
1110 extern struct lbfile *lbfhead; /* pointer to the first
1111 * library file structure
1113 /* sdld specific */
1114 extern int sflag; /* JCF: Memory usage output flag
1116 extern int stacksize; /* Stack size
1118 extern int rflag; /* Extended linear address record flag.
1120 extern a_uint iram_size; /* internal ram size
1122 extern long xram_size; /* external ram size
1124 extern long code_size; /* code size
1126 extern char *sdld_output; /* output file name, --output argument
1128 extern char *optsdcc;
1129 extern char *optsdcc_module;
1130 /* sdld 8015 specific */
1131 extern char idatamap[256]; /* ' ' means unused
1133 /* end sdld 8051 specific */
1134 /* end sdld specific */
1138 /* C Library function definitions */
1139 /* for reference only
1140 extern VOID exit();
1141 extern int fclose();
1142 extern char * fgets();
1143 extern FILE * fopen();
1144 extern int fprintf();
1145 extern VOID free();
1146 extern VOID * malloc();
1147 extern char putc();
1148 extern char * sprintf();
1149 extern char * strcpy();
1150 extern int strlen();
1151 extern char * strncpy();
1152 extern char * strrchr();
1155 /* Program function definitions */
1157 #ifdef OTHERSYSTEM
1159 /* lkmain.c */
1160 extern FILE * afile(char *fn, char *ft, int wf);
1161 extern VOID bassav(void);
1162 extern int fndidx(char *str);
1163 extern int fndext(char *str);
1164 extern VOID gblsav(void);
1165 extern int intsiz(void);
1166 extern VOID iramsav(void);
1167 extern VOID xramsav(void);
1168 extern VOID codesav(void);
1169 extern VOID iramcheck(void);
1170 extern VOID link_main(void);
1171 extern VOID lkexit(int i);
1172 extern int main(int argc, char *argv[]);
1173 extern VOID map(void);
1174 extern VOID sym(void);
1175 extern int parse(void);
1176 extern VOID doparse(void);
1177 extern VOID setarea(void);
1178 extern VOID setgbl(void);
1179 extern VOID usage(int n);
1180 extern VOID copyfile (FILE *dest, FILE *src);
1182 /* lklex.c */
1183 extern VOID chopcrlf(char *str);
1184 extern char endline(void);
1185 extern int get(void);
1186 extern VOID getfid(char *str, int c);
1187 extern VOID getid(char *id, int c);
1188 extern VOID getSid(char *id);
1189 extern int getmap(int d);
1190 extern int getnb(void);
1191 extern int more(void);
1192 extern int nxtline(void);
1193 extern VOID skip(int c);
1194 extern VOID unget(int c);
1196 /* lkarea.c */
1197 extern VOID lkparea(char *id);
1198 extern VOID lnkarea(void);
1199 extern VOID lnkarea2(void);
1200 extern VOID newarea(void);
1202 /* lkbank.c */
1203 extern VOID chkbank(FILE *fp);
1204 extern VOID lkfclose(void);
1205 extern VOID lkfopen(void);
1206 extern VOID lkpbank(char * id);
1207 extern VOID newbank(void);
1208 extern VOID setbank(void);
1210 /* lkhead.c */
1211 extern VOID module(void);
1212 extern VOID newhead(void);
1213 extern VOID newmode(void);
1215 /* lksym.c */
1216 extern int hash(char *p, int cflag);
1217 extern struct sym * lkpsym(char *id, int f);
1218 extern char * new(unsigned int n);
1219 extern struct sym * newsym(void);
1220 extern char * strsto(char *str);
1221 extern VOID symdef(FILE *fp);
1222 extern int symeq(char *p1, char *p2, int cflag);
1223 extern VOID syminit(void);
1224 extern VOID symmod(FILE *fp, struct sym *tsp);
1225 extern a_uint symval(struct sym *tsp);
1227 /* lkeval.c */
1228 extern int digit(int c, int r);
1229 extern a_uint eval(void);
1230 extern a_uint expr(int n);
1231 extern int oprio(int c);
1232 extern a_uint term(void);
1234 /* lklist.c */
1235 extern int dgt(int rdx, char *str, int n);
1236 extern VOID newpag(FILE *fp);
1237 extern VOID slew(struct area *xp, struct bank *yp);
1238 extern VOID lstarea(struct area *xp, struct bank *yp);
1239 extern VOID lkulist(int i);
1240 extern VOID lkalist(a_uint cpc);
1241 extern VOID lkglist(a_uint cpc, int v, int err);
1243 /* lknoice.c */
1244 extern VOID NoICEfopen(void);
1245 extern VOID NoICEmagic(void);
1246 extern VOID DefineNoICE(char *name, a_uint value, struct bank *yp);
1247 extern VOID DefineGlobal(char *name, a_uint value, struct bank *yp);
1248 extern VOID DefineScoped(char *name, a_uint value, struct bank *yp);
1249 extern VOID DefineFile(char *name, a_uint value, struct bank *yp);
1250 extern VOID DefineFunction(char *name, a_uint value, struct bank *yp);
1251 extern VOID DefineStaticFunction(char *name, a_uint value, struct bank *yp);
1252 extern VOID DefineEndFunction(a_uint value, struct bank *yp);
1253 extern VOID DefineLine(char *lineString, a_uint value, struct bank *yp);
1254 extern VOID PagedAddress(a_uint value, struct bank *yp);
1256 /* lksdcdb.c */
1257 extern VOID SDCDBfopen(void);
1258 extern VOID SDCDBcopy(char * str);
1259 extern VOID DefineSDCDB(char *name, a_uint value);
1261 /* lkrloc.c */
1262 extern a_uint adb_1b(a_uint v, int i);
1263 extern a_uint adb_2b(a_uint v, int i);
1264 extern a_uint adb_3b(a_uint v, int i);
1265 extern a_uint adb_4b(a_uint v, int i);
1266 extern a_uint adb_xb(a_uint v, int i);
1267 extern a_uint evword(void);
1268 extern VOID prntval(FILE *fptr, a_uint v);
1269 extern VOID reloc(int c);
1271 /* lkrloc3.c */
1272 extern a_uint adb_bit(a_uint v, int i);
1273 extern a_uint adb_24_bit(a_uint v, int i);
1274 extern a_uint adb_24_hi(a_uint v, int i);
1275 extern a_uint adb_24_mid(a_uint v, int i);
1276 extern a_uint adb_24_lo(a_uint v, int i);
1277 extern a_uint adb_hi(a_uint v, int i);
1278 extern a_uint adb_lo(a_uint v, int i);
1279 extern char * errmsg3[];
1280 extern VOID errdmp3(FILE *fptr, char *str);
1281 extern VOID erpdmp3(FILE *fptr, char *str);
1282 extern VOID rele3(void);
1283 extern VOID reloc3(int c);
1284 extern VOID relt3(void);
1285 extern VOID relr3(void);
1286 extern VOID relp3(void);
1287 extern VOID relerr3(char *str);
1288 extern VOID relerp3(char *str);
1289 extern int vpdkinst(int inst, int addr, int ver);
1291 /* lklibr.c */
1292 extern int addfile(char *path, char *libfil);
1293 extern VOID addlib(void);
1294 extern VOID addpath(void);
1295 extern int fndsym(char *name);
1296 extern VOID library(void);
1297 extern VOID loadfile(char *filspc);
1298 extern VOID search(void);
1300 /* lkout.c */
1301 extern VOID lkout(int i);
1302 extern VOID lkflush(void);
1303 extern VOID ixx(int i);
1304 extern VOID iflush(void);
1305 extern VOID sxx(int i);
1306 extern VOID sflush(void);
1307 extern VOID dbx(int i);
1308 extern VOID dflush(void);
1310 /* lks19.c */
1311 extern VOID s19(int i);
1312 extern VOID sflush(void);
1314 /* EEP: lkelf.c */
1315 extern VOID elf();
1317 /* JCF: lkmem.c */
1318 extern int summary(struct area * xp);
1319 extern int summary2(struct area * xp);
1321 /* JCF: lkaomf51.c */
1322 extern void SaveLinkedFilePath(char * filepath);
1323 extern void CreateAOMF51(void);
1325 /* lkgb.h */
1326 VOID gb(int in);
1327 VOID gg(int in);
1329 /* strcmpi.h */
1330 extern int as_strcmpi(const char *s1, const char *s2);
1331 extern int as_strncmpi(const char *s1, const char *s2, size_t n);
1333 #else
1335 #endif