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/>.
24 * With enhancements from
26 * John L. Hartman (JLH)
27 * jhartman at compuserve dot com
30 * w_mckinnon at conknet dot com
32 * Boisy G. Petri (BGP)
33 * boisy at boisypitre dot com
36 * mike dot mccarty at sbcglobal dot net
41 * - add proto for strsto
42 * - change s_id from [NCPS] to pointer
43 * - change m_id from [NCPS] to pointer
46 * - add R_J11 for 8051 assembler
47 * - add outr11 prototype for 8051 assembler
48 * - always define "ccase"
50 * - add jflag for debug control
51 * - prototypes for DefineNoICE_Line
53 * - add memory space flags to a_flag for 8051
56 * - add DS80C390 flat mode support.
58 * - change a_id from [NCPS] to pointer
59 * 02-Feb-22 basxto/bbbbbr:
60 * - raise NCPS to 256 like in upstream
64 * System Include Files
77 #define VERSION "V02.00 + NoICE + SDCC mods"
78 #define COPYRIGHT "2012"
81 * To include NoICE Debugging set non-zero
86 * To include SDCC Debugging set non-zero
92 * The assembler requires certain variables to have
93 * at least 32 bits to allow correct address processing.
95 * The type INT32 is defined so that compiler dependent
96 * variable sizes may be specified in one place.
98 * LONGINT is defined when INT32 is 'long' to
99 * select the 'l' forms for format strings
103 /* Turbo C++ 3.0 for DOS */
104 /* 'int' is 16-bits, 'long' is 32-bits */
111 /* Symantec C++ V6.x/V7.x for DOS (not DOSX) */
112 /* 'int' is 16-bits, 'long' is 32-bits */
119 /* The DEFAULT is 'int' is 32 bits */
124 #if !defined(__BORLANDC__) && !defined(_MSC_VER)
130 * The module asxxxx.h contains the definitions for constants,
131 * structures, global variables, and ASxxxx functions
132 * contained in the ASxxxx.c files. The functions and
133 * global variables from the machine dependent files are
138 * compiler/operating system specific definitions
141 /* DECUS C void definition */
142 /* File/extension seperator */
149 /* PDOS C void definition */
150 /* File/extension seperator */
157 /* Default void definition */
158 /* File/extension seperator */
170 #ifndef PATH_MAX /* POSIX, but not required */
171 # if defined(_MSC_VER) || defined(__BORLANDC__) /* Microsoft C or Borland C */
172 # define PATH_MAX _MAX_PATH
174 # define PATH_MAX FILENAME_MAX /* define a reasonable value */
178 #ifdef _WIN32 /* WIN32 native */
179 # define NATIVE_WIN32 1
180 # ifdef __MINGW32__ /* GCC MINGW32 depends on configure */
181 # include "../../sdccconf.h"
183 # include "../../sdcc_vc.h"
184 # define PATH_MAX _MAX_PATH
186 #else /* Assume *nix style system */
187 # include "../../sdccconf.h"
193 #define ER_NONE 0 /* No error */
194 #define ER_WARNING 1 /* Warning */
195 #define ER_ERROR 2 /* Assembly error */
196 #define ER_FATAL 3 /* Fatal error */
199 * Assembler definitions.
201 #define LFTERM '(' /* Left expression delimeter */
202 #define RTTERM ')' /* Right expression delimeter */
204 #define NCPS 256 /* Characters per symbol */
205 #define ASXHUGE 1000 /* A huge number */
206 #define NERR 3 /* Errors per line */
207 #define NINPUT 1024 /* Input buffer size */
208 #define NCODE 128 /* Listing code buffer size */
209 #define NTITL 80 /* Title buffer size */
210 #define NSBTL 80 /* SubTitle buffer size */
211 #define NHASH (1 << 6) /* Buckets in hash table */
212 #define HMASK (NHASH - 1) /* Hash mask */
213 #define NLPP 60 /* Lines per page */
214 #define MAXMCR 20 /* Maximum nesting of macro expansions */
215 #define MAXIF 10 /* Maximum nesting of if/else/endif */
216 #define FILSPC PATH_MAX /* Chars. in filespec */
218 #define NLIST 0 /* No listing */
219 #define SLIST 1 /* Source only */
220 #define ALIST 2 /* Address only */
221 #define BLIST 3 /* Address only with allocation */
222 #define CLIST 4 /* Code */
223 #define ELIST 5 /* Equate only */
225 #define LIST_ERR 0x0001 /* Error Code(s) */
226 #define LIST_LOC 0x0002 /* Location */
227 #define LIST_BIN 0x0004 /* Generated Binary Value(s)*/
228 #define LIST_EQT 0x0008 /* Assembler Equate Value */
229 #define LIST_CYC 0x0010 /* Opcode Cycles */
230 #define LIST_LIN 0x0020 /* Line Numbers */
231 #define LIST_SRC 0x0040 /* Assembler Source Code */
233 #define LIST_PAG 0x0080 /* Assembler Pagination */
234 #define LIST_LST 0x0100 /* .LIST/.NLIST Listing */
236 #define LIST_MD 0x0200 /* Macro Definition */
237 #define LIST_ME 0x0400 /* Macro Expansion */
238 #define LIST_MEB 0x0800 /* Macro Expansion Binary */
240 #define LIST_BITS 0x0FFF /* LIST Flags Mask */
242 #define LIST_NONE 0x0000 /* NLIST Flags Mask */
243 #define LIST_ASM 0x007F /* LIST Flags Mask for Assembler Line */
244 #define LIST_NORM 0x03FF /* LIST Flags Mask */
246 #define LIST_NOT 0x1000 /* Force Complement of Listing Mode */
248 #define LIST_TORF 0x8000 /* IF-ENDIF Conditional Overide Flag */
250 #define T_ASM 0 /* Assembler Source File */
251 #define T_INCL 1 /* Assembler Include File */
252 #define T_MACRO 2 /* Assembler Macro */
255 * Opcode Cycle definitions (Must Be The Same In ASxxxx / ASLink)
257 #define CYCNT_BGN '[' /* Cycle count begin delimiter */
258 #define CYCNT_END ']' /* Cycle count end delimiter */
261 * OPCY_NONE bit set signifies no opcode cycles set.
263 #define OPCY_NONE ((char) 0x80) /* Opcode Cycle Count Not Set */
264 #define OPCY_MASK ((char) 0x7F) /* Opcode Cycle Count MASK */
267 * NTXT must be defined to have the same value in
268 * the ASxxxx assemblers and ASLink.
270 * The R Line coding allows only 4-bits for coding
271 * the T Line index. The MAXIMUM value for NTXT
272 * is 16. It should not be changed.
274 #define NTXT 16 /* Maximum T Line Values */
275 #define NREL 16 /* Maximum R Line Values */
278 * Internal Definitions
280 #define dot sym[0] /* Dot, current loc */
281 #define dca area[0] /* Dca, default code area */
283 #define hilo sym[3].s_addr /* hilo, byte order flag */
284 #define mls sym[4] /* Mls, Macro local symbol */
287 * The defined type 'a_uint' is used for all address and
288 * unsigned variable value calculations. Its size is
289 * required to be at least 32-bits to allow upto
290 * 32-bit addressing or 32-bit value manipulation.
292 typedef unsigned INT32 a_uint
;
295 * The defined type 'v_sint' is used for address and
296 * variable value calculations requiring a sign.
297 * Its size is required to be at least 32-bits to allow
298 * upto 32-bit addressing or 32-bit value manipulation.
300 typedef signed INT32 v_sint
;
303 * The area structure contains the parameter values for a
304 * specific program or data section. The area structure
305 * is a linked list of areas. The initial default area
306 * is "_CODE" defined in asdata.c, the next area structure
307 * will be linked to this structure through the structure
308 * element 'struct area *a_ap'. The structure contains the
309 * area name, area reference number ("_CODE" is 0) determined
310 * by the order of .area directives, area size determined
311 * from the total code and/or data in an area, area fuzz is
312 * a variable used to track pass to pass changes in the
313 * area size caused by variable length instruction formats,
314 * and area flags which specify the area's relocation type.
318 struct area
*a_ap
; /* Area link */
319 char * a_id
; /* Area Name */
320 int a_ref
; /* Ref. number */
321 a_uint a_size
; /* Area size */
322 a_uint a_fuzz
; /* Area fuzz */
323 int a_flag
; /* Area flags */
325 a_uint a_addr
; /* Area address */
326 /* end sdas specific */
330 * The "A_" area constants define values used in
331 * generating the assembler area output data.
336 * +-----+-----+-----+-----+-----+-----+-----+-----+
337 * | BIT |XDATA|DATA | PAG | ABS | OVR | | |
338 * +-----+-----+-----+-----+-----+-----+-----+-----+
341 #define A_CON 0000 /* Concatenating */
342 #define A_OVR 0004 /* Overlaying */
343 #define A_REL 0000 /* Relocatable */
344 #define A_ABS 0010 /* absolute */
345 #define A_NOPAG 0000 /* Non-Paged */
346 #define A_PAG 0020 /* Paged */
349 /* Additional flags for 8051 address spaces */
350 #define A_DATA 0000 /* data space (default)*/
351 #define A_CODE 0040 /* code space */
352 #define A_XDATA 0100 /* external data space */
353 #define A_BIT 0200 /* bit addressable space */
355 #define A_NOLOAD 0400 /* nonloadable */
356 #define A_LOAD 0000 /* loadable (default) */
357 /* end sdas specific */
360 * The "R_" relocation constants define values used in
361 * generating the assembler relocation output data for
362 * areas, symbols, and code.
367 * +-----+-----+-----+-----+-----+-----+-----+-----+
368 * | MSB | PAGn| PAG0| USGN| BYT2| PCR | SYM | BYT |
369 * +-----+-----+-----+-----+-----+-----+-----+-----+
372 #define R_BYTE 0x01 /* 8 bit */
373 #define R_WORD 0x00 /* 16 bit */
375 #define R_BYT1 0x00 /* Byte count for R_BYTE = 1 */
376 #define R_BYTX 0x08 /* Byte count for R_BYTE = 2 */
377 #define R_HIB 0x200 /* If R_BYTE & R_BYT3 are set, linker
378 * will select byte 3 of the relocated
382 #define R_SGND 0x00 /* Signed Byte */
383 #define R_USGN 0x10 /* Unsigned Byte */
385 #define R_LSB 0x00 /* low byte */
386 #define R_MSB 0x80 /* high byte */
388 #define R_BIT 0x400 /* Linker will convert from byte-addressable
389 * space to bit-addressable space.
393 #define R_AREA 0x00 /* Base type */
397 * Note: The PAGE modes and PCR modes are mutually exclusive !!!
403 #define R_NOPAG 0x0000 /* Page Mode */
404 #define R_PAG0 0x0020 /* Page '0' */
405 #define R_PAGN 0x0040 /* Page 'nnn' */
406 #define R_PAGX 0x0060 /* Page 'x', Extended Relocation Mode */
414 #define R_J11 (R_WORD|R_BYTX) /* JLH: 11 bit JMP and CALL (8051) */
415 #define R_J19 (R_WORD|R_BYTX|R_MSB) /* 19 bit JMP/CALL (DS80C390) */
416 #define R_C24 (R_WORD|R_BYT1|R_MSB) /* 24 bit address (DS80C390) */
417 #define R_J19_MASK (R_BYTE|R_BYTX|R_MSB)
419 #define IS_R_J19(x) (((x) & R_J19_MASK) == R_J19)
420 #define IS_R_J11(x) (((x) & R_J19_MASK) == R_J11)
421 #define IS_C24(x) (((x) & R_J19_MASK) == R_C24)
424 * Basic Relocation Modes
427 #define R_NORM 0x0000 /* No Bit Positioning */
430 * Extended Relocation Modes are defined in
431 * the ___pst.c files.
433 * #define R_0100 0x0100 Extended mode 1
435 * #define R_0F00 0x0F00 Extended mode 15
438 #define R_ESCAPE_MASK 0xf0 /* Used to escape relocation modes
439 * greater than 0xff in the .rel
444 * Listing Control Flags
447 #define R_HIGH 0040000 /* High Byte */
448 #define R_BYT3 0x100 /* if R_BYTE is set, this is a
449 * 3 byte address, of which
450 * the linker must select one byte.
452 #define R_RELOC 0100000 /* Relocation */
454 #define R_DEF 00 /* Global def. */
455 #define R_REF 01 /* Global ref. */
456 #define R_REL 00 /* Relocatable */
457 #define R_ABS 02 /* Absolute */
458 #define R_GBL 00 /* Global */
459 #define R_LCL 04 /* Local */
462 * The mne structure is a linked list of the assembler
463 * mnemonics and directives. The list of mnemonics and
464 * directives contained in the device dependent file
465 * xxxpst.c are hashed and linked into NHASH lists in
466 * module assym.c by syminit(). The structure contains
467 * the mnemonic/directive name, a subtype which directs
468 * the evaluation of this mnemonic/directive, a flag which
469 * is used to detect the end of the mnemonic/directive
470 * list in xxxpst.c, and a value which is normally
471 * associated with the assembler mnemonic base instruction
476 struct mne
*m_mp
; /* Hash link */
477 char *m_id
; /* Mnemonic (JLH) */
478 char m_type
; /* Mnemonic subtype */
479 char m_flag
; /* Mnemonic flags */
480 a_uint m_valu
; /* Value */
484 * The sym structure is a linked list of symbols defined
485 * in the assembler source files. The first symbol is "."
486 * defined in asdata.c. The entry 'struct tsym *s_tsym'
487 * links any temporary symbols following this symbol and
488 * preceeding the next normal symbol. The structure also
489 * contains the symbol's name, type (NEW or USER),
490 * flag (global, assigned, and multiply defined), a pointer
491 * to the area structure defining where the symbol is
492 * located, a reference number assigned by outgsd() in
493 * asout.c, and the symbols address relative to the base
494 * address of the area where the symbol is located.
498 struct sym
*s_sp
; /* Hash link */
499 struct tsym
*s_tsym
; /* Temporary symbol link */
500 char *s_id
; /* Symbol (JLH) */
501 char s_type
; /* Symbol subtype */
502 char s_flag
; /* Symbol flags */
503 struct area
*s_area
; /* Area line, 0 if absolute */
504 int s_ref
; /* Ref. number */
505 a_uint s_addr
; /* Address */
507 a_uint s_org
; /* Start Address if absolute */
508 /* end sdas specific */
511 #define S_EOL 040 /* End mark for ___pst files */
513 #define S_NEW 0 /* New Name (External) */
514 #define S_USER 1 /* User Name (Assigned) */
516 #define S_LCL 001 /* Local Variable */
517 #define S_GBL 002 /* Global Variable */
518 #define S_ASG 004 /* Assigned Value */
519 #define S_MDF 010 /* Multiple Definition */
521 #define S_PAGE 2 /* .page */
522 #define S_HEADER 3 /* .title, .sbttl */
523 #define O_TITLE 0 /* .title */
524 #define O_SBTTL 1 /* .sbttl */
525 #define S_MODUL 4 /* .module */
526 #define S_INCL 5 /* .include, .incbin */
527 #define I_CODE 0 /* .include */
528 #define I_BNRY 1 /* .incbin */
529 #define S_AREA 6 /* .area */
530 #define S_ATYP 7 /* .area type */
531 #define S_ORG 8 /* .org */
532 #define S_RADIX 9 /* .radix */
533 #define S_GLOBL 10 /* .globl */
534 #define S_LOCAL 11 /* .local */
535 #define S_CONDITIONAL 12 /* .if, .iif, .else, .endif, ... */
536 #define O_IF 0 /* .if */
537 #define O_IFF 1 /* .iff */
538 #define O_IFT 2 /* .ift */
539 #define O_IFTF 3 /* .iftf */
540 #define O_IFDEF 4 /* .ifdef */
541 #define O_IFNDEF 5 /* .ifndef */
542 #define O_IFGT 6 /* .ifgt (BGP) */
543 #define O_IFLT 7 /* .iflt (BGP) */
544 #define O_IFGE 8 /* .ifge (BGP) */
545 #define O_IFLE 9 /* .ifle (BGP) */
546 #define O_IFEQ 10 /* .ifeq (BGP) */
547 #define O_IFNE 11 /* .ifne (BGP) */
548 #define O_IFB 12 /* .ifb */
549 #define O_IFNB 13 /* .ifnb */
550 #define O_IFIDN 14 /* .ifidn */
551 #define O_IFDIF 15 /* .ifdif */
552 #define O_IFEND 20 /* end of .if conditionals */
553 #define O_IIF 20 /* .iif */
554 #define O_IIFF 21 /* .iiff */
555 #define O_IIFT 22 /* .iift */
556 #define O_IIFTF 23 /* .iiftf */
557 #define O_IIFDEF 24 /* .iifdef */
558 #define O_IIFNDEF 25 /* .iifndef */
559 #define O_IIFGT 26 /* .iifgt */
560 #define O_IIFLT 27 /* .iiflt */
561 #define O_IIFGE 28 /* .iifge */
562 #define O_IIFLE 29 /* .iifle */
563 #define O_IIFEQ 30 /* .iifeq */
564 #define O_IIFNE 31 /* .iifne */
565 #define O_IIFB 32 /* .iifb */
566 #define O_IIFNB 33 /* .iifnb */
567 #define O_IIFIDN 34 /* .iifidn */
568 #define O_IIFDIF 35 /* .iifdif */
569 #define O_IIFEND 40 /* end of .iif conditionals */
570 #define O_ELSE 40 /* .else */
571 #define O_ENDIF 41 /* .endif */
572 #define S_LISTING 13 /* .nlist, .list */
573 #define O_LIST 0 /* .list */
574 #define O_NLIST 1 /* .nlist */
575 #define S_EQU 14 /* .equ, .gblequ, .lclequ */
576 #define O_EQU 0 /* .equ */
577 #define O_GBLEQU 1 /* .gblequ */
578 #define O_LCLEQU 2 /* .lclequ */
579 #define S_DATA 15 /* .byte, .word, long, .3byte, .4byte, .db, .dw, .dl, .fcb, .fdb */
580 #define O_1BYTE 1 /* .byte, .db, .fcb */
581 #define O_2BYTE 2 /* .word, .dw, .fdb */
582 #define O_3BYTE 3 /* .3byte */
583 #define O_4BYTE 4 /* .4byte, .long, .dl */
584 #define S_BLK 16 /* .blkb, .blkw, .blk3, .blk4, .ds, .rmb, .rs */
585 /* O_1BYTE 1 */ /* .blkb, .ds, .rmb, .rs */
586 /* O_2BYTE 2 */ /* .blkw */
587 /* O_3BYTE 3 */ /* .blk3 */
588 /* O_4BYTE 4 */ /* .blk4 */
589 #define S_ASCIX 17 /* .ascii, .ascis, .asciz, .str, .strs, .strz */
590 #define O_ASCII 0 /* .ascii */
591 #define O_ASCIS 1 /* .ascis */
592 #define O_ASCIZ 2 /* .asciz */
593 #define S_DEFINE 18 /* .define, .undefine */
594 #define O_DEF 0 /* .define */
595 #define O_UNDEF 1 /* .undefine */
596 #define S_BOUNDARY 19 /* .even, .odd */
597 #define O_EVEN 0 /* .even */
598 #define O_ODD 1 /* .odd */
599 #define O_BNDRY 2 /* .bndry */
600 #define S_MSG 20 /* .msg */
601 #define S_ERROR 21 /* .assume, .error */
602 #define O_ASSUME 0 /* .assume */
603 #define O_ERROR 1 /* .error */
604 #define S_BITS 23 /* .8bit, .16bit, .24bit, .32bit */
605 /* O_1BYTE 1 */ /* .8bit */
606 /* O_2BYTE 2 */ /* .16bit */
607 /* O_3BYTE 3 */ /* .24bit */
608 /* O_4BYTE 4 */ /* .32bit */
609 #define S_END 24 /* .end */
610 #define S_MACRO 25 /* .macro, .endm, .mexit, ... */
611 #define O_MACRO 0 /* .macro */
612 #define O_ENDM 1 /* .endm */
613 #define O_MEXIT 2 /* .mexit */
614 #define O_NCHR 3 /* .nchr */
615 #define O_NARG 4 /* .narg */
616 #define O_NTYP 5 /* .ntyp */
617 #define O_IRP 6 /* .irp */
618 #define O_IRPC 7 /* .irpc */
619 #define O_REPT 8 /* .rept */
620 #define O_NVAL 9 /* .nval */
621 #define O_MDEL 10 /* .mdelete */
622 #define O_CHECK 255 /* Building/Exiting a Macro Check */
624 #define S_DIREOL 30 /* Assembler Directive End Of List */
627 #define S_FLOAT 32 /* .df */
628 #define S_ULEB128 33 /* .uleb128 */
629 #define S_SLEB128 34 /* .sleb128 */
630 #define S_OPTSDCC 35 /* .optsdcc */
631 /* end sdas specific */
634 * The tsym structure is a linked list of temporary
635 * symbols defined in the assembler source files following
636 * a normal symbol. The structure contains the temporary
637 * symbols number, a flag (multiply defined), a pointer to the
638 * area structure defining where the temporary structure
639 * is located, and the temporary symbol's address relative
640 * to the base address of the area where the symbol
645 struct tsym
*t_lnk
; /* Link to next */
646 a_uint t_num
; /* 0-65535$ for a 16-bit int */
647 /* 0-4294967295$ for a 32-bit int */
648 int t_flg
; /* flags */
649 struct area
*t_area
; /* Area */
650 a_uint t_addr
; /* Address */
654 * The def structure is used by the .define assembler
655 * directive to define a substitution string for a
656 * single word. The def structure contains the
657 * string being defined, the string to substitute
658 * for the defined string, and a link to the next
659 * def structure. The defined string is a sequence
660 * of characters not containing any white space
661 * (i.e. NO SPACEs or TABs). The substitution string
662 * may contain SPACES and/or TABs.
666 struct def
*d_dp
; /* link to next define */
667 char *d_id
; /* defined string */
668 char *d_define
; /* string to substitute for defined string */
669 int d_dflag
; /* (1) .defined / (0) .undefined */
673 * The mode structure contains the specification of one of the
674 * assemblers' merge modes. Each assembler must specify
675 * at least one merge mode. The merging specification
676 * allows arbitrarily defined active bits and bit positions.
677 * The 32 element arrays are indexed from 0 to 31.
678 * Index 0 corresponds to bit 0, ..., and 31 corresponds to bit 31
679 * of a normal integer value.
681 * The value of the element specifies if the normal integer bit
682 * is active (bit <7> is set, 0x80) and what destination bit
683 * (bits <4:0>, 0 - 31) should be loaded with this normal
686 * The specification for a 32-bit integer:
689 * '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
690 * '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
691 * '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
692 * '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237'
696 * The specification for the 11-bit 8051 addressing mode:
699 * '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
700 * '\215', '\216', '\217', '\013', '\014', '\015', '\016', '\017',
701 * '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
702 * '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037'
706 * *m_def is a pointer to the bit relocation definition.
707 * m_flag indicates that bit position swapping is required.
708 * m_dbits contains the active bit positions for the output.
709 * m_sbits contains the active bit positions for the input.
713 char * m_def
; /* Bit Relocation Definition */
714 a_uint m_flag
; /* Bit Swapping Flag */
715 a_uint m_dbits
; /* Destination Bit Mask */
716 a_uint m_sbits
; /* Source Bit Mask */
720 * Definitions for Character Types
724 #define LETTER '\001'
733 #define DGT2 (DIGIT|RAD16|RAD10|RAD8|RAD2)
734 #define DGT8 (DIGIT|RAD16|RAD10|RAD8)
735 #define DGT10 (DIGIT|RAD16|RAD10)
736 #define LTR16 (LETTER|RAD16)
739 * The expr structure is used to return the evaluation
740 * of an expression. The structure supports three valid
742 * (1) The expression evaluates to a constant,
743 * mode = S_USER, flag = 0, addr contains the
744 * constant, and base = NULL.
745 * (2) The expression evaluates to a defined symbol
746 * plus or minus a constant, mode = S_USER,
747 * flag = 0, addr contains the constant, and
748 * base = pointer to area symbol.
749 * (3) The expression evaluates to a external
750 * global symbol plus or minus a constant,
751 * mode = S_NEW, flag = 1, addr contains the
752 * constant, and base = pointer to symbol.
756 char e_mode
; /* Address mode */
757 char e_flag
; /* Symbol flag */
758 a_uint e_addr
; /* Address */
762 } e_base
; /* Rel. base */
763 int e_rlcf
; /* Rel. flags */
767 * The asmf structure contains the information
768 * pertaining to an assembler source file/macro.
771 * next is a pointer to the next object in the linked list
772 * objtyp specifies the object type - T_ASM, T_INCL, T_MACRO
773 * line is the saved line number of the parent object
774 * flevel is the saved flevel of the parent object
775 * tlevel is the saved tlevel of the parent object
776 * lnlist is the saved lnlist of the parent object
777 * fp is the source FILE handle
778 * afp is the file path length (excludes the files name.ext)
779 * afn[] is the assembler/include file path/name.ext
783 struct asmf
*next
; /* Link to Next Object */
784 int objtyp
; /* Object Type */
785 int line
; /* Saved Line Counter */
786 int flevel
; /* saved flevel */
787 int tlevel
; /* saved tlevel */
788 int lnlist
; /* saved lnlist */
789 FILE * fp
; /* FILE Handle */
790 int afp
; /* File Path Length */
791 char afn
[FILSPC
]; /* File Name */
795 * The macrofp structure masquerades as a FILE Handle
796 * for inclusion in an asmf structure. This structure
797 * contains the reference to the macro to be inserted
798 * into the assembler stream and information to
799 * restore the assembler state at macro completion.
802 * np is a pointer to the macro definition
803 * lstptr is a pointer to the next macro line
804 * rptcnt is the macro repeat counter
805 * rptidx is the current repeat count
806 * flevel is the saved assembler flevel
807 * tlevel is the saved assembler tlevel
808 * lnlist is the saved assembler lnlist
809 * npexit non zero if an .mexit is encountered
812 struct mcrdef
* np
; /* pointer to macro definition */
813 struct strlst
* lstptr
; /* pointer to next line of macro */
814 int rptcnt
; /* repeat counter */
815 int rptidx
; /* repeat index */
816 int flevel
; /* saved flevel */
817 int tlevel
; /* saved tlevel */
818 int lnlist
; /* saved lnlist */
819 int npexit
; /* .mexit called */
823 * The mcrdef structure contains the
824 * information about a macro definition.
826 * When the macro is defined the definition
827 * arguments are packed into a linked list of
828 * strings beginning with bgnarg and ending with
829 * endarg. The number of args is placed in narg.
831 * When the macro is invoked the expansion
832 * argument strings are placed into a linked
833 * list of strings beginning with bgnxrg and
834 * ending with endxrg. The number of expansion
835 * arguments is placed in xarg.
838 * next is a pointer to the next macro definition structure
839 * name is a pointer to the macro name string
840 * bgnlst is a pointer to the first text line of the macro
841 * endlst is a pointer to the last text line of the macro
842 * type is the macro type - .macro, .irp, .irpc, or .rept
843 * rptcnt is the repeat count for the macro
844 * nest is the macro nesting counter
845 * narg is the number of macro definition arguments
846 * bgnarg is a pointer to the first definition argument string
847 * endarg is a pointer to the last definition argument string
848 * xarg is the number of expansion arguments at macro invocation
849 * bgnxrg is a pointer to the first expansion argument string
850 * endxrg is a pointer to the last expansion argument string
853 struct mcrdef
* next
; /* link to next macro definition */
854 char * name
; /* pointer to the macro name */
855 struct strlst
* bgnlst
; /* link to first text line of macro */
856 struct strlst
* endlst
; /* link to last text line of macro */
857 int type
; /* macro type */
858 int rptcnt
; /* repeat counter */
859 int nest
; /* macro nesting counter */
860 int narg
; /* number of macro defintion arguments */
861 struct strlst
* bgnarg
; /* link to first macro defintion argument */
862 struct strlst
* endarg
; /* link to last macro definition argument */
863 int xarg
; /* number of macro expansion arguments */
864 struct strlst
* bgnxrg
; /* link to first macro expansion argument */
865 struct strlst
* endxrg
; /* link to last macro xpansion argument */
869 * The strlst structure is a linked list of strings.
872 * next is a pointer to the next string.
873 * text is a pointer to a text string.
876 struct strlst
* next
; /* pointer to next string */
877 char * text
; /* pointer to string text */
881 * The memlnk structure is a linked list
882 * of memory allocations.
884 * The function new() uses the memlnk structure
885 * to create a linked list of allocated memory
886 * that can be traversed by asfree() to release
887 * the allocated memory.
889 * The function mhunk() uses the memlnk structure
890 * to create a linked list of allocated memory
891 * that can be reused.
894 * next is a pointer to the next memlnk structure.
895 * ptr is a pointer to the allocated memory.
898 struct memlnk
* next
; /* link to next memlnk */
899 VOID
* ptr
; /* pointer to allocated memory */
903 * External Definitions for all Global Variables
906 extern int aserr
; /* ASxxxx error counter
908 extern jmp_buf jump_env
; /* compiler dependent structure
909 * used by setjmp() and longjmp()
911 extern struct asmf
*asmc
; /* Pointer to the current
912 * source input structure
914 extern struct asmf
*asmp
; /* The pointer to the first assembler
915 * source file structure of a linked list
917 extern struct asmf
*asmi
; /* Queued pointer to an include file
918 * source input structure
920 extern struct asmf
*asmq
; /* Queued pointer to a macro
921 * source input structure
923 extern struct mcrdef
* mcrlst
; /* link to list of defined macros
925 extern struct mcrdef
* mcrp
; /* link to list of defined macros
927 extern struct memlnk
* pmcrmem
;/* First Macro Memory Allocation Structure
929 extern struct memlnk
* mcrmem
; /* Macro Memory Allocation Structure
931 extern int mcrblk
; /* Macro data blocks allocated
933 extern int incfil
; /* include file nesting counter
935 extern int maxinc
; /* maximum include file nesting encountered
937 extern int mcrfil
; /* macro nesting counter
939 extern int maxmcr
; /* maximum macro nesting encountered
941 extern int flevel
; /* IF-ELSE-ENDIF flag will be non
942 * zero for false conditional case
944 extern int ftflevel
; /* IIFF-IIFT-IIFTF FLAG
946 extern int tlevel
; /* current conditional level
948 extern int lnlist
; /* LIST-NLIST options
950 extern int ifcnd
[MAXIF
+1]; /* array of IF statement condition
951 * values (0 = FALSE) indexed by tlevel
953 extern int iflvl
[MAXIF
+1]; /* array of IF-ELSE-ENDIF flevel
954 * values indexed by tlevel
956 extern char afn
[FILSPC
]; /* current input file specification
958 extern int afp
; /* current input file path length
960 extern char afntmp
[FILSPC
]; /* temporary input file specification
962 extern int afptmp
; /* temporary input file path length
964 extern int srcline
; /* current source line number
966 extern int asmline
; /* current assembler file line number
968 extern int incline
; /* current include file line number
970 extern int mcrline
; /* current macro line number
972 extern int radix
; /* current number conversion radix:
973 * 2 (binary), 8 (octal), 10 (decimal),
976 extern int line
; /* current assembler source line number
978 extern int page
; /* current page number
980 extern int lop
; /* current line number on page
982 extern time_t curtim
; /* pointer to the current time string
984 extern int pass
; /* assembler pass number
986 extern int aflag
; /* -a, make all symbols global flag
988 extern int bflag
; /* -b(b), listing mode flag
990 extern int cflag
; /* -c, disable cycle counts in listing flag
992 extern int fflag
; /* -f(f), relocations flagged flag
994 extern int gflag
; /* -g, make undefined symbols global flag
997 extern int jflag
; /* -j, enable NoICE Debug Symbols
1001 extern int lflag
; /* -l, generate listing flag
1003 extern int oflag
; /* -o, generate relocatable output flag
1005 extern int nflag
; /* -n, don't resolve global symbols flag
1007 extern int pflag
; /* -p, disable listing pagination
1009 extern int sflag
; /* -s, generate symbol table flag
1011 extern int tflag
; /* -t, output diagnostic parameters from assembler
1013 extern int uflag
; /* -u, disable .list/.nlist processing flag
1015 extern int vflag
; /* -v, enable out of range signed / unsigned errors
1017 extern int wflag
; /* -w, enable wide listing format
1019 extern int xflag
; /* -x, listing radix flag
1023 extern int yflag
; /* -y, enable SDCC Debug Symbols
1027 extern int zflag
; /* -z, disable symbol case sensitivity
1029 extern int waddrmode
; /* WORD Address mode flag
1031 extern int a_bytes
; /* REL file T Line address length
1033 extern a_uint a_mask
; /* Address Mask
1035 extern a_uint s_mask
; /* Sign Mask
1037 extern a_uint v_mask
; /* Value Mask
1039 extern a_uint laddr
; /* address of current assembler line,
1040 * equate, or value of .if argument
1042 extern a_uint fuzz
; /* tracks pass to pass changes in the
1043 * address of symbols caused by
1044 * variable length instruction formats
1046 extern int lmode
; /* listing mode
1048 extern char txt
[NTXT
]; /* T Line Values
1050 extern char rel
[NREL
]; /* R Line Values
1052 extern char *txtp
; /* Pointer to T Line Values
1054 extern char *relp
; /* Pointer to R Line Values
1056 extern struct area
*areap
; /* pointer to an area structure
1058 extern struct area area
[]; /* array of 1 area
1060 extern struct def
*defp
; /* pointer to a def structure
1062 extern struct sym sym
[]; /* array of 1 symbol
1064 extern struct sym
*symp
; /* pointer to a symbol structure
1066 extern struct sym
*symhash
[NHASH
]; /* array of pointers to NHASH
1067 * linked symbol lists
1069 extern struct mne
*mnehash
[NHASH
]; /* array of pointers to NHASH
1070 * linked mnemonic/directive lists
1072 extern char *ep
; /* pointer into error list
1075 extern char eb
[NERR
]; /* array of generated error codes
1077 extern char *ex
[NERR
]; /* array of error string pointers
1079 extern char *ip
; /* pointer into the assembler-source
1082 extern char *ib
; /* assembler-source text line for processing
1084 extern char *ic
; /* assembler-source text line for listing
1086 extern char *cp
; /* pointer to assembler output
1089 extern char cb
[NCODE
]; /* array of assembler output values
1091 extern int *cpt
; /* pointer to assembler relocation type
1092 * output array cbt[]
1094 extern int cbt
[NCODE
]; /* array of assembler relocation types
1095 * describing the data in cb[]
1097 extern int opcycles
; /* opcode execution cycles
1099 extern char tb
[NTITL
]; /* Title string buffer
1101 extern char stb
[NSBTL
]; /* Subtitle string buffer
1103 extern char erb
[NINPUT
+4]; /* Error string buffer
1105 extern char symtbl
[]; /* string "Symbol Table"
1107 extern char aretbl
[]; /* string "Area Table"
1109 extern char module
[NCPS
+2]; /* module name string
1111 extern FILE *lfp
; /* list output file handle
1113 extern FILE *ofp
; /* relocation output file handle
1115 extern FILE *tfp
; /* symbol table output file handle
1117 extern unsigned char ctype
[256]; /* array of character types, one per
1118 * ASCII/OEM character
1120 extern char ccase
[256]; /* an array of characters which
1121 * perform the case translation function
1124 extern int asfatal
; /* ASxxxx fatal error counter
1126 extern int org_cnt
; /* .org directive counter
1128 extern char *optsdcc
; /* sdcc compile options
1130 /*end sdas specific */
1132 /* C Library functions */
1133 /* for reference only
1135 extern int fclose();
1136 extern char * fgets();
1137 extern FILE * fopen();
1138 extern int fprintf();
1140 extern VOID longjmp();
1141 extern VOID * malloc();
1142 extern int printf();
1144 extern int rewind();
1145 extern int setjmp();
1146 extern int strcmp();
1147 extern char * strcpy();
1148 extern int strlen();
1149 extern char * strncpy();
1150 extern char * strrchr();
1153 /* Machine independent functions */
1158 extern FILE * afile(char *fn
, char *ft
, int wf
);
1159 extern VOID
afilex(char *fn
, char *ft
);
1160 extern VOID
asexit(int i
);
1161 extern VOID
asmbl(void);
1162 extern VOID
equate(char *id
,struct expr
*e1
,a_uint equtype
);
1163 extern int fndidx(char *str
);
1164 extern int intsiz(void);
1165 extern VOID
newdot(struct area
*nap
);
1166 extern VOID
phase(struct area
*ap
, a_uint a
);
1167 extern VOID
usage(void);
1170 extern char * fgetm(char *ptr
, int len
, FILE *fp
);
1171 extern VOID
getdarg(struct mcrdef
*np
);
1172 extern VOID
getxarg(struct mcrdef
*np
);
1173 extern VOID
getxstr(char *id
);
1174 extern VOID
macro(struct mcrdef
* np
);
1175 extern VOID
macroscn(struct macrofp
*nfp
);
1176 extern int macrosub(char *id
, struct macrofp
*nfp
);
1177 extern VOID
mcrinit(void);
1178 extern int mcrprc(int code
);
1179 extern VOID
* mhunk(void);
1180 extern char * mstring(char *str
);
1181 extern char * mstruct(int n
);
1182 extern struct mcrdef
* newdef(int code
, char *id
);
1183 extern struct mcrdef
* nlookup(char *id
);
1186 extern VOID
chopcrlf(char *str
);
1187 extern int comma(int flag
);
1188 extern char endline(void);
1189 extern int get(void);
1190 extern int getdlm(void);
1191 extern VOID
getdstr(char *str
, int slen
);
1192 extern VOID
getid(char *id
, int c
);
1193 extern int getmap(int d
);
1194 extern int getnb(void);
1195 extern int getlnm(void);
1196 extern VOID
getst(char *id
, int c
);
1197 extern int more(void);
1198 extern int nxtline(void);
1199 extern int replace(char *id
);
1200 extern VOID
scanline(void);
1201 extern VOID
unget(int c
);
1204 extern VOID
allglob(void);
1205 extern struct area
* alookup(char *id
);
1206 extern struct def
* dlookup(char *id
);
1207 extern int hash(const char *p
, int flag
);
1208 extern struct sym
* lookup(const char *id
);
1209 extern struct mne
* mlookup(char *id
);
1210 extern char * new(unsigned int n
);
1211 extern struct sym
* slookup(char *id
);
1212 extern char * strsto(const char *str
);
1213 extern int symeq(const char *p1
, const char *p2
, int flag
);
1214 extern VOID
syminit(void);
1215 extern VOID
symglob(void);
1218 extern VOID
aerr(void);
1219 extern VOID
diag(void);
1220 extern VOID
err(int c
);
1221 extern VOID
xerr(int c
, char *str
);
1222 extern char * geterr(int c
);
1223 extern VOID
qerr(void);
1224 extern VOID
rerr(void);
1226 extern VOID
warnBanner(void);
1227 /* end sdas specific */
1230 extern VOID
abscheck(struct expr
*esp
);
1231 extern a_uint
absexpr(void);
1232 extern VOID
clrexpr(struct expr
*esp
);
1233 extern int digit(int c
, int r
);
1234 extern VOID
exprmasks(int n
);
1235 extern VOID
expr(struct expr
*esp
, int n
);
1236 extern int is_abs(struct expr
*esp
);
1237 extern int oprio(int c
);
1238 extern a_uint
rngchk(a_uint n
);
1239 extern VOID
term(struct expr
*esp
);
1242 extern char * BaseFileName(struct asmf
*currFile
, int spacesToUnderscores
);
1243 extern VOID
DefineNoICE_Line(void);
1244 extern VOID
DefineSDCC_Line(void);
1247 extern VOID
list(void);
1248 extern VOID
list1(char *wp
, int *wpt
, int nb
, int n
, int f
, int g
);
1249 extern VOID
list2(int t
);
1250 extern VOID
lstsym(FILE *fp
);
1251 extern VOID
slew(FILE *fp
, int flag
);
1254 extern int lobyte(a_uint v
);
1255 extern int hibyte(a_uint v
);
1256 extern int thrdbyte(a_uint v
);
1257 extern int frthbyte(a_uint v
);
1258 extern VOID
out(char *p
, int n
);
1259 extern VOID
outarea(struct area
*ap
);
1260 extern VOID
outdp(struct area
*carea
, struct expr
*esp
, int r
);
1261 extern VOID
outall(void);
1262 extern VOID
outdot(void);
1263 extern VOID
outbuf(char *s
);
1264 extern VOID
outchk(int nt
, int nr
);
1265 extern VOID
outradix(void);
1266 extern VOID
outgsd(void);
1267 extern VOID
outsym(struct sym
*sp
);
1268 extern VOID
outab(a_uint v
);
1269 extern VOID
outaw(a_uint v
);
1270 extern VOID
outa3b(a_uint v
);
1271 extern VOID
outa4b(a_uint v
);
1272 extern VOID
outaxb(int i
, a_uint v
);
1273 extern VOID
outatxb(int i
, a_uint v
);
1274 extern VOID
outrb(struct expr
*esp
, int r
);
1275 extern VOID
outrw(struct expr
*esp
, int r
);
1276 extern VOID
outr3b(struct expr
*esp
, int r
);
1277 extern VOID
outrxb(int i
, struct expr
*esp
, int r
);
1278 extern VOID
outrwm(struct expr
*esp
, int r
, a_uint v
);
1279 extern VOID
outrwp(struct expr
*esp
, a_uint op
, a_uint mask
, int jump
);
1280 extern VOID
outr3bm(struct expr
*esp
, int r
, a_uint v
);
1281 extern VOID
out_lb(a_uint v
, int t
);
1282 extern VOID
out_lw(a_uint v
, int t
);
1283 extern VOID
out_l3b(a_uint v
, int t
);
1284 extern VOID
out_l4b(a_uint v
, int t
);
1285 extern VOID
out_lxb(int i
, a_uint v
, int t
);
1286 extern VOID
out_rw(a_uint v
);
1287 extern VOID
out_txb(int i
, a_uint v
);
1289 /* Machine dependent variables */
1293 extern struct mne mne
[];
1295 /* Machine dependent functions */
1297 extern VOID
machine(struct mne
*mp
);
1298 extern VOID
minit(void);
1303 extern int as_strcmpi(const char *s1
, const char *s2
);
1304 extern int as_strncmpi(const char *s1
, const char *s2
, size_t n
);
1305 /* end sdas specific */
1310 extern FILE * afile();
1311 extern VOID
afilex();
1312 extern VOID
asexit();
1313 extern VOID
asmbl();
1314 extern VOID
equate();
1315 extern int fndidx();
1316 extern int intsiz();
1318 extern VOID
newdot();
1319 extern VOID
phase();
1320 extern VOID
usage();
1323 extern char * fgetm();
1324 extern VOID
getdarg();
1325 extern VOID
getxarg();
1326 extern VOID
getxstr();
1327 extern VOID
macro();
1328 extern VOID
macroscn();
1329 extern int macrosub();
1330 extern VOID
mcrinit();
1331 extern int mcrprc();
1332 extern VOID
* mhunk();
1333 extern char * mstring();
1334 extern char * mstruct();
1335 extern struct mcrdef
* newdef();
1336 extern struct mcrdef
* nlookup();
1339 extern VOID
chopcrlf();
1341 extern char endline();
1343 extern int getdlm();
1344 extern VOID
getdstr();
1345 extern VOID
getid();
1346 extern int getmap();
1348 extern int getlnm();
1349 extern VOID
getst();
1351 extern int nxtline();
1352 extern VOID
unget();
1355 extern VOID
allglob();
1356 extern struct area
* alookup();
1359 extern struct sym
* lookup();
1360 extern struct mne
* mlookup();
1361 extern char * new();
1362 extern char * strsto();
1364 extern VOID
syminit();
1365 extern VOID
symglob();
1371 extern char * geterr();
1375 extern VOID
warnBanner();
1376 /* end sdas specific */
1379 extern VOID
abscheck();
1380 extern a_uint
absexpr();
1381 extern VOID
clrexpr();
1383 extern VOID
exprmasks();
1385 extern int is_abs();
1387 extern a_uint
rngchk();
1391 extern char * BaseFileName();
1392 extern VOID
DefineNoICE_Line();
1393 extern VOID
DefineSDCC_Line();
1397 extern VOID
list1();
1398 extern VOID
list2();
1399 extern VOID
lstsym();
1403 extern int lobyte();
1404 extern int hibyte();
1405 extern int thrdbyte();
1406 extern int frthbyte();
1408 extern VOID
outarea();
1409 extern VOID
outdp();
1410 extern VOID
outall();
1411 extern VOID
outdot();
1412 extern VOID
outbuf();
1413 extern VOID
outchk();
1414 extern VOID
outradix();
1415 extern VOID
outgsd();
1416 extern VOID
outsym();
1417 extern VOID
outab();
1418 extern VOID
outaw();
1419 extern VOID
outa3b();
1420 extern VOID
outa4b();
1421 extern VOID
outaxb();
1422 extern VOID
outatxb();
1423 extern VOID
outrb();
1424 extern VOID
outrw();
1425 extern VOID
outr3b();
1426 extern VOID
outrxb();
1427 extern VOID
outrwm();
1428 extern VOID
outrwp();
1429 extern VOID
outr3bm();
1430 extern VOID
out_lb();
1431 extern VOID
out_lw();
1432 extern VOID
out_rw();
1433 extern VOID
out_tw();
1435 /* Machine dependent variables */
1440 extern struct mne mne
[];
1442 /* Machine dependent functions */
1444 extern VOID
machine();
1445 extern VOID
minit();
1449 extern int as_strcmpi();
1450 extern int as_strncmpi();
1451 /* end sdas specific */