     1                                  
     2                                  ; Public Domain
     3                                  
     4                                  ; test install command: install; .; inject uninstall
     5                                  ; test run command: ; .; .
     6                                  
     7                                  %include "lmacros3.mac"
     1                              <1> [list -]
    14                              <2> [list -]
    14                              <1> [list -]
     8                                  %include "eld.mac"
     1                              <1> %if 0
     2                              <1> 
     3                              <1> Extensions for lDebug macros
     4                              <1> 
     5                              <1> Copyright (C) 2008-2025 E. C. Masloch
     6                              <1> 
     7                              <1> Usage of the works is permitted provided that this
     8                              <1> instrument is retained with the works, so that any entity
     9                              <1> that uses the works is notified of this instrument.
    10                              <1> 
    11                              <1> DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
    12                              <1> 
    13                              <1> %endif
    14                              <1> 
    15                              <1> %ifndef ELD_MAC
    16                              <1> %define ELD_MAC 1
    17                              <1> 
    18                              <1> %include "lmacros3.mac"
     1                              <2> [list -]
    19                              <1> 
    20                              <1> 		; ELD executable header
    21                              <1> 	struc ELD_HEADER
    22 00000000 ????????            <1> eldhSignature:		resb 4	; "ELD1"
    23 00000004 ??????              <1> 			resb 3	; reserved
    24 00000007 ??                  <1> 			resb 1	; 26 (Ctrl-Z)
    25 00000008 ????????            <1> eldhCodeOffset:		resd 1	; position displacement from eldhSignature
    26 0000000C ????                <1> eldhCodeImageLength:	resw 1	; amount bytes, at least 32
    27 0000000E ????                <1> eldhCodeAllocLength:	resw 1	; amount bytes, added to prior. sum < 64 KiB
    28 00000010 ????????            <1> eldhDataOffset:		resd 1
    29 00000014 ????                <1> eldhDataImageLength:	resw 1	; (zero allowed)
    30 00000016 ????                <1> eldhDataAllocLength:	resw 1	; (zero allowed)
    31 00000018 ????                <1> eldhCodeEntrypoint:	resw 1	; within code section, used as displacement
    32 0000001A ????????            <1> eldhReserved:		resb 4	; reserved
    33 0000001E ????                <1> eldhExtensionSize:	resw 1	; from eldhSignature, -> past eldhx fields in use
    34                              <1> 	endstruc
    35                              <1> 	endarea ELD_HEADER, 1
    36                              <1> 
    37                              <1> 	struc ELD_HEADERX
    38 00000000 <res 20h>           <1> eldhxHeader:		resb ELD_HEADER_size
    39 00000020 ????????            <1> eldhxDescriptionOffset:	resd 1	; zero if none, from eldhxHeader. <= 128 Bytes
    40 00000024 ????????            <1> eldhxHelpOffset:	resd 1	; zero if none, from eldhxHeader
    41 00000028 ????????            <1> eldhxLibTable:		resd 1	; zero if none, from eldhxHeader
    42 0000002C ????????            <1> eldhxDateTimeOffset:	resd 1	; zero if none, from eldhxHeader
    43                              <1> 	alignb 16
    44                              <1> 	endstruc
    45                              <1> 
    46                              <1> 	struc ELD_TRAILER_HEADER
    47 00000000 ????????????????    <1> eldthSignature:		resb 8	; "ELD1TAIL"
    48 00000008 ????????            <1> eldthHeaderOffset:	resd 1	; negative displacement from eldthSignature,
    49                              <1> 				;  add this dword to the seek offset
    50 0000000C ????                <1> eldthReserved:		resw 1	; reserved, must be initialised to zero
    51 0000000E ????                <1> eldthChecksum:		resw 1	; sum of all words in trailer header = 0
    52                              <1> 	endstruc
    53                              <1> 	endarea ELD_TRAILER_HEADER, 1
    54                              <1> 
    55                              <1> 	struc ELD_LIBTABLE
    56 00000000 ????                <1> eldltFormat:		resw 1
    57                              <1> 	; 0 = uncompressed
    58                              <1> 	; 2 = heatshrink compressed
    59                              <1> 	; 3 = lzexedat -4 compressed
    60                              <1> 	; 4 = lzexedat -4 -l compressed
    61 00000002 ????                <1> eldltAmount:		resw 1
    62 00000004 ????????            <1> eldltOffset:		resd 1	; from eldhxHeader
    63                              <1> eldltCompressedLength:		; (dword, only present if format 2, 3, or 4)
    64                              <1> 	endstruc
    65                              <1> 	endarea ELD_LIBTABLE, 1
    66                              <1> 
    67                              <1> 		; ELD instance header
    68                              <1> 	struc ELD_INSTANCE
    69 00000000 ????                <1> eldiStartCode:		resw 1	; -> this structure itself (para aligned)
    70 00000002 ????                <1> eldiEndCode:		resw 1	; -> behind memory used by instance (para aligned)
    71 00000004 ????                <1> eldiStartData:		resw 1	; -> data in data entry section (para aligned), or 0
    72 00000006 ????                <1> eldiEndData:		resw 1	; -> behind data (para aligned), or 0
    73 00000008 ????????????????    <1> eldiIdentifier:		resb 8	; blank-filled text
    74 00000010 ????                <1> eldiFlags:		resw 1	; flags
    75                              <1> eldiListing_size equ 14
    76 00000012 <res Eh>            <1> eldiListing:		resb eldiListing_size
    77                              <1> 				; ASCIZ listing file name
    78                              <1> 	endstruc
    79                              <1> 		; flags for eldiFlags:
    80                              <1> eldifResident:		equ 1
    81                              <1> 
    82                              <1> 		; ELD link info header
    83                              <1> 	struc ELD_LINKINFO
    84 00000000 ????                <1> eldlSignature:		resw 1	; 0E1D1h
    85 00000002 ????????            <1> eldlReserved:		resw 2
    86 00000006 ????                <1> eldlUseLinkHash:	resw 1
    87 00000008 ????                <1> eldlDataAmount:		resw 1
    88 0000000A ????                <1> eldlDataPrefixes:	resw 1
    89 0000000C ????                <1> eldlDataEntries:	resw 1
    90 0000000E ????                <1> eldlDataAddresses:	resw 1
    91 00000010 ????                <1> eldlCodeAmount:		resw 1
    92 00000012 ????                <1> eldlCodePrefixes:	resw 1
    93 00000014 ????                <1> eldlCodeEntries:	resw 1
    94 00000016 ????                <1> eldlCodeAddresses:	resw 1
    95                              <1> 	endstruc
    96                              <1> 
    97                              <1> 	numdef ELD_CODE_VSTART, 9001h
    98                              <1> 	numdef ELD_DATA_VSTART, 8000h
    99                              <1> 	numdef ELD_RELOC_VSTART, 8000h
   100                              <1> 
   101                              <1> 	numdef ELD_RECLAIM_HINT, 0
   102                              <1> 	strdef ELD_LISTING, ""
   103                              <1> 	numdef ELD_DATETIME, 0
   104                              <1> 
   105                              <1> %if _ELD_DATETIME
   106                              <1>  %define PUT_ELDHX_DATETIME_OFFSET at eldhxDateTimeOffset, dd DATAOFFSET + datetime - datastart
   107                              <1>  %macro PUT_ELD_DATETIME 0.nolist
   108                              <1> datetime:	asciz __UTC_DATE__,'T',__UTC_TIME__,'Z'
   109                              <1> 		asciz		; for future extension
   110                              <1>  %endmacro
   111                              <1> %else
   112                              <1>  %define PUT_ELDHX_DATETIME_OFFSET
   113                              <1>  %define PUT_ELD_DATETIME
   114                              <1> %endif
   115                              <1> 
   116                              <1> %endif
     9                                  %include "eldcall.mac"
     1                              <1> %if 0
     2                              <1> 
     3                              <1> Extensions for lDebug call macros
     4                              <1> 
     5                              <1> Copyright (C) 2008-2024 E. C. Masloch
     6                              <1> 
     7                              <1> Usage of the works is permitted provided that this
     8                              <1> instrument is retained with the works, so that any entity
     9                              <1> that uses the works is notified of this instrument.
    10                              <1> 
    11                              <1> DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
    12                              <1> 
    13                              <1> %endif
    14                              <1> 
    15                              <1> %ifndef ELDCALL_MAC
    16                              <1> %define ELDCALL_MAC 1
    17                              <1> 
    18                              <1> %include "lmacros3.mac"
     1                              <2> [list -]
    19                              <1> %include "nasmhash.mac"
     1                              <2> 
     2                              <2> %if 0
     3                              <2> 
     4                              <2> Hashing macros
     5                              <2>  by E. C. Masloch, 2019
     6                              <2> 
     7                              <2> Usage of the works is permitted provided that this
     8                              <2> instrument is retained with the works, so that any entity
     9                              <2> that uses the works is notified of this instrument.
    10                              <2> 
    11                              <2> DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
    12                              <2> 
    13                              <2> %endif
    14                              <2> 
    15                              <2> %ifndef __NASMHASH_MAC__
    16                              <2> %assign __NASMHASH_MAC__ 1
    17                              <2> 
    18                              <2> 
    19                              <2> 	%macro hashdef 2+.nolist
    20                              <2> %ifempty %2
    21                              <2>  %assign _%1 1
    22                              <2> %else
    23                              <2> %ifstr %2
    24                              <2>  %define %%string %2
    25                              <2> %elifid %2
    26                              <2>  %defstr %%string %2
    27                              <2> %elifnum %2
    28                              <2>  %defstr %%string %2
    29                              <2> %eliftok %2
    30                              <2>  %defstr %%string %2
    31                              <2> %else
    32                              <2>  %error Unknown input
    33                              <2> %endif
    34                              <2> %strlen %%length %%string
    35                              <2> %assign %%hash 1
    36                              <2> %assign %%index 1
    37                              <2> %rep %%length
    38                              <2>  %substr %%char %%string %%index
    39                              <2>  %assign %%hash (%%hash * 31 + %%char) & 0FFFFh
    40                              <2>  %assign %%index %%index + 1
    41                              <2> %endrep
    42                              <2> %assign _%1 %%hash
    43                              <2> %endif
    44                              <2> 	%endmacro
    45                              <2> 
    46                              <2> 
    47                              <2> %endif
    20                              <1> %include "elddata.mac"
     1                              <2> %if 0
     2                              <2> 
     3                              <2> Extensions for lDebug data relocation macros
     4                              <2> 
     5                              <2> Copyright (C) 2008-2024 E. C. Masloch
     6                              <2> 
     7                              <2> Usage of the works is permitted provided that this
     8                              <2> instrument is retained with the works, so that any entity
     9                              <2> that uses the works is notified of this instrument.
    10                              <2> 
    11                              <2> DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
    12                              <2> 
    13                              <2> %endif
    14                              <2> 
    15                              <2> %ifndef ELDDATA_MAC
    16                              <2> %define ELDDATA_MAC 1
    17                              <2> 
    18                              <2> %include "lmacros3.mac"
     1                              <3> [list -]
    19                              <2> %include "nasmhash.mac"
     1                              <3> 
     2                              <3> %if 0
     3                              <3> 
     4                              <3> Hashing macros
     5                              <3>  by E. C. Masloch, 2019
     6                              <3> 
     7                              <3> Usage of the works is permitted provided that this
     8                              <3> instrument is retained with the works, so that any entity
     9                              <3> that uses the works is notified of this instrument.
    10                              <3> 
    11                              <3> DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
    12                              <3> 
    13                              <3> %endif
    14                              <3> 
    15                              <3> %ifndef __NASMHASH_MAC__
    16                              <3> %assign __NASMHASH_MAC__ 1
    17                              <3> 
    18                              <3> 
    19                              <3> 	%macro hashdef 2+.nolist
    20                              <3> %ifempty %2
    21                              <3>  %assign _%1 1
    22                              <3> %else
    23                              <3> %ifstr %2
    24                              <3>  %define %%string %2
    25                              <3> %elifid %2
    26                              <3>  %defstr %%string %2
    27                              <3> %elifnum %2
    28                              <3>  %defstr %%string %2
    29                              <3> %eliftok %2
    30                              <3>  %defstr %%string %2
    31                              <3> %else
    32                              <3>  %error Unknown input
    33                              <3> %endif
    34                              <3> %strlen %%length %%string
    35                              <3> %assign %%hash 1
    36                              <3> %assign %%index 1
    37                              <3> %rep %%length
    38                              <3>  %substr %%char %%string %%index
    39                              <3>  %assign %%hash (%%hash * 31 + %%char) & 0FFFFh
    40                              <3>  %assign %%index %%index + 1
    41                              <3> %endrep
    42                              <3> %assign _%1 %%hash
    43                              <3> %endif
    44                              <3> 	%endmacro
    45                              <3> 
    46                              <3> 
    47                              <3> %endif
    20                              <2> %include "eldcheck.mac"
     1                              <3> %if 0
     2                              <3> 
     3                              <3> Extensions for lDebug relocation check macros
     4                              <3> 
     5                              <3> Copyright (C) 2008-2023 E. C. Masloch
     6                              <3> 
     7                              <3> Usage of the works is permitted provided that this
     8                              <3> instrument is retained with the works, so that any entity
     9                              <3> that uses the works is notified of this instrument.
    10                              <3> 
    11                              <3> DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
    12                              <3> 
    13                              <3> %endif
    14                              <3> 
    15                              <3> %ifndef ELDCHECK_MAC
    16                              <3> %define ELDCHECK_MAC 1
    17                              <3> 
    18                              <3> %assign ELDSTRICT 0
    19                              <3> %assign ELDSTRICTCOUNTER 0
    20                              <3> 
    21                              <3> 	%imacro eldstrict 1.nolist
    22                              <3> %ifidni %1, on
    23                              <3>  %assign ELDSTRICT 1
    24                              <3>  [warning +error=reloc-abs]
    25                              <3>  [warning +reloc-abs]
    26                              <3> %elifidni %1, off
    27                              <3>  %assign ELDSTRICT 0
    28                              <3>  [warning -reloc-abs]
    29                              <3> %else
    30                              <3>  %error Unknown keyword
    31                              <3> %endif
    32                              <3> 	%endmacro
    33                              <3> 
    34                              <3> 	%imacro reloc 1+.nolist
    35                              <3> %if ELDSTRICT
    36                              <3>  %if ELDSTRICTCOUNTER
    37                              <3>   %error Missing relocation
    38                              <3>  %endif
    39                              <3>  [warning -reloc-abs]
    40                              <3>  %assign ELDSTRICTCOUNTER 1
    41                              <3> %endif
    42                              <3> %1
    43                              <3> 	%endmacro
    44                              <3> 
    45                              <3> 	%imacro reloc2 1+.nolist
    46                              <3> %if ELDSTRICT
    47                              <3>  %if ELDSTRICTCOUNTER
    48                              <3>   %error Missing relocation
    49                              <3>  %endif
    50                              <3>  [warning -reloc-abs]
    51                              <3>  %assign ELDSTRICTCOUNTER 2
    52                              <3> %endif
    53                              <3> %1
    54                              <3> 	%endmacro
    55                              <3> 
    56                              <3> 	%imacro eldstrictcheck 0.nolist
    57                              <3> %if ELDSTRICT
    58                              <3>  %ifn ELDSTRICTCOUNTER
    59                              <3>   %error Unexpected relocation
    60                              <3>  %else
    61                              <3>   %assign ELDSTRICTCOUNTER ELDSTRICTCOUNTER - 1
    62                              <3>   %ifn ELDSTRICTCOUNTER
    63                              <3>    [warning +reloc-abs]
    64                              <3>   %endif
    65                              <3>  %endif
    66                              <3> %endif
    67                              <3> 	%endmacro
    68                              <3> 
    69                              <3> %endif
    70                              <3> 
    21                              <2> 
    22                              <2> 
    23                              <2> %assign ELDLINKER 0
    24                              <2> 
    25                              <2> %define INTERNAL_CODE_TO_CODE_RELOCATIONS ""
    26                              <2> %define INTERNAL_CODE_TO_DATA_RELOCATIONS ""
    27                              <2> %define INTERNAL_DATA_TO_CODE_RELOCATIONS ""
    28                              <2> %define INTERNAL_DATA_TO_DATA_RELOCATIONS ""
    29                              <2> %define INTERNAL_LINKER_CODE_TO_CODE_RELOCATIONS ""
    30                              <2> %define INTERNAL_LINKER_CODE_TO_DATA_RELOCATIONS ""
    31                              <2> %define INTERNAL_LINKER_DATA_TO_CODE_RELOCATIONS ""
    32                              <2> %define INTERNAL_LINKER_DATA_TO_DATA_RELOCATIONS ""
    33                              <2> %assign ELDDATA_OPTIONAL_STATUS 0		; not any seen yet
    34                              <2> %assign ELDDATA_PMREQUIRED_STATUS 0		; not any seen yet
    35                              <2> %assign ELDDATA_NEXT_STATUS 0			; not any seen yet
    36                              <2> %assign ELDDATA_NEXT_ENTRY -1
    37                              <2> %assign ELDDATA_NEXT_SECTION -1
    38                              <2> %assign ELDDATA_NEXT_OTHER -1
    39                              <2> 
    40                              <2> 	%imacro internalcoderelocation 0-1.nolist -2
    41                              <2> %assign %%entry $ + _CURRENT_SECTION %+ FIXUP + %1
    42                              <2> %if ELDLINKER
    43                              <2>  %ifidni _CURRENT_SECTION_TYPE, DATA
    44                              <2>   %xdefine INTERNAL_LINKER_DATA_TO_CODE_RELOCATIONS INTERNAL_LINKER_DATA_TO_CODE_RELOCATIONS, %%entry
    45                              <2>  %else
    46                              <2>   %xdefine INTERNAL_LINKER_CODE_TO_CODE_RELOCATIONS INTERNAL_LINKER_CODE_TO_CODE_RELOCATIONS, %%entry
    47                              <2>  %endif
    48                              <2> %else
    49                              <2>  %ifidni _CURRENT_SECTION_TYPE, DATA
    50                              <2>   %xdefine INTERNAL_DATA_TO_CODE_RELOCATIONS INTERNAL_DATA_TO_CODE_RELOCATIONS, %%entry
    51                              <2>  %else
    52                              <2>   %xdefine INTERNAL_CODE_TO_CODE_RELOCATIONS INTERNAL_CODE_TO_CODE_RELOCATIONS, %%entry
    53                              <2>  %endif
    54                              <2> %endif
    55                              <2> 	eldstrictcheck
    56                              <2> 	%endmacro
    57                              <2> 
    58                              <2> 	%imacro internaldatarelocation 0-1.nolist -2
    59                              <2> %assign %%entry $ + _CURRENT_SECTION %+ FIXUP + %1
    60                              <2> %if ELDLINKER
    61                              <2>  %ifidni _CURRENT_SECTION_TYPE, DATA
    62                              <2>   %xdefine INTERNAL_LINKER_DATA_TO_DATA_RELOCATIONS INTERNAL_LINKER_DATA_TO_DATA_RELOCATIONS, %%entry
    63                              <2>  %else
    64                              <2>   %xdefine INTERNAL_LINKER_CODE_TO_DATA_RELOCATIONS INTERNAL_LINKER_CODE_TO_DATA_RELOCATIONS, %%entry
    65                              <2>  %endif
    66                              <2> %else
    67                              <2>  %ifidni _CURRENT_SECTION_TYPE, DATA
    68                              <2>   %xdefine INTERNAL_DATA_TO_DATA_RELOCATIONS INTERNAL_DATA_TO_DATA_RELOCATIONS, %%entry
    69                              <2>  %else
    70                              <2>   %xdefine INTERNAL_CODE_TO_DATA_RELOCATIONS INTERNAL_CODE_TO_DATA_RELOCATIONS, %%entry
    71                              <2>  %endif
    72                              <2> %endif
    73                              <2> 	eldstrictcheck
    74                              <2> 	%endmacro
    75                              <2> 
    76                              <2> ; dw INTERNAL_LINKER_CODE_TO_CODE_RELOCATIONS, 0
    77                              <2> ; dw INTERNAL_LINKER_CODE_TO_DATA_RELOCATIONS, 0
    78                              <2> ; dw INTERNAL_LINKER_DATA_TO_CODE_RELOCATIONS, -1
    79                              <2> ; dw INTERNAL_LINKER_DATA_TO_DATA_RELOCATIONS, -1
    80                              <2> ; dw INTERNAL_CODE_TO_CODE_RELOCATIONS, 0
    81                              <2> ; dw INTERNAL_CODE_TO_DATA_RELOCATIONS, 0
    82                              <2> ; dw INTERNAL_DATA_TO_CODE_RELOCATIONS, -1
    83                              <2> ; dw INTERNAL_DATA_TO_DATA_RELOCATIONS, -1
    84                              <2> 
    85                              <2> 
    86                              <2> %define LINK_DATA_RELOCATIONS ""
    87                              <2> %define LINK_LINKER_DATA_RELOCATIONS ""
    88                              <2> %define LINK_DATA_NAMES db ""
    89                              <2> %define LINK_DATA_DETECTION none, none
    90                              <2> 
    91                              <2> %define LINK_OTHER_DATA_RELOCATIONS ""
    92                              <2> %define LINK_OTHER_LINKER_DATA_RELOCATIONS ""
    93                              <2> %define LINK_OTHER_DATA_NAMES db ""
    94                              <2> %define LINK_OTHER_DATA_DETECTION none, none
    95                              <2> 
    96                              <2> %ifndef ELDOTHER
    97                              <2>  %assign ELDOTHER 0
    98                              <2> %endif
    99                              <2> %assign ELDOTHERLINK 0
   100                              <2> 
   101                              <2> 	%imacro otherlinkdatarelocation 1-3.nolist -2, required
   102                              <2> %if ELDOTHER
   103                              <2>  %assign ELDOTHERLINK 1
   104                              <2> %endif
   105                              <2> 	linkdatarelocation %1, %2, %3
   106                              <2> %assign ELDOTHERLINK 0
   107                              <2> 	%endmacro
   108                              <2> 
   109                              <2> 	%imacro linkdatarelocation 1-4.nolist -2, required, single
   110                              <2> %assign %%entry $ + _CURRENT_SECTION %+ FIXUP + %2
   111                              <2> %ifidni %3, required
   112                              <2>  %assign %%optional 0
   113                              <2> %elifidni %3, optional
   114                              <2>  %assign %%optional 100h
   115                              <2>  %if ELDDATA_OPTIONAL_STATUS == 0
   116                              <2>   %assign ELDDATA_OPTIONAL_STATUS 1
   117                              <2>  %elif ELDDATA_OPTIONAL_STATUS == 1
   118                              <2>  %else
   119                              <2>   %error Optional data link not allowed here
   120                              <2>  %endif
   121                              <2> %elifidni %3, PM required
   122                              <2>  %assign %%optional 300h
   123                              <2>  %assign ELDDATA_PMREQUIRED_STATUS 1
   124                              <2>  %if ELDDATA_OPTIONAL_STATUS == 0
   125                              <2>   %assign ELDDATA_OPTIONAL_STATUS 1
   126                              <2>  %elif ELDDATA_OPTIONAL_STATUS == 1
   127                              <2>  %else
   128                              <2>   %error Optional data link not allowed here
   129                              <2>  %endif
   130                              <2> %else
   131                              <2>  %fatal Unknown optional keyword
   132                              <2> %endif
   133                              <2> %ifidni _CURRENT_SECTION_TYPE, DATA
   134                              <2>  %assign %%DATASECTION 1
   135                              <2> %else
   136                              <2>  %assign %%DATASECTION 0
   137                              <2> %endif
   138                              <2> %ifidni %4, single
   139                              <2>  %if ELDDATA_NEXT_STATUS == 1		; after next ?
   140                              <2>   %error Unexpected single data link after next data link
   141                              <2>  %elif ELDDATA_NEXT_STATUS == 2		; after last ?
   142                              <2>   %assign ELDDATA_NEXT_STATUS 3		; note single with next/last present
   143                              <2>  %endif
   144                              <2>  %assign %%next 0
   145                              <2> %elifidni %4, next
   146                              <2>  %if ELDDATA_NEXT_STATUS == 0		; no next/last yet ?
   147                              <2>   %assign ELDDATA_NEXT_STATUS 1		; in next
   148                              <2>  %elif ELDDATA_NEXT_STATUS == 2		; after last ?
   149                              <2>   %assign ELDDATA_NEXT_STATUS 1		; in next
   150                              <2>  %elif ELDDATA_NEXT_STATUS == 3		; after single ?
   151                              <2>   %assign ELDDATA_NEXT_STATUS 1		; in next
   152                              <2>  %elif ELDDATA_NEXT_STATUS == 1		; repeated next ?
   153                              <2>   %if ELDDATA_NEXT_ENTRY != %%entry 	|| ELDDATA_NEXT_SECTION != %%DATASECTION 	|| ELDDATA_NEXT_OTHER != ELDOTHERLINK
   156                              <2>    %error Unexpected next data link
   157                              <2>   %endif
   158                              <2>  %else
   159                              <2>   %error Next data link not allowed here
   160                              <2>  %endif
   161                              <2>  %ifn %%optional
   162                              <2>   %error Next data link only valid as optional or PM required
   163                              <2>  %endif
   164                              <2>  %assign %%next 400h
   165                              <2>  %assign ELDDATA_NEXT_ENTRY %%entry
   166                              <2>  %assign ELDDATA_NEXT_SECTION %%DATASECTION
   167                              <2>  %assign ELDDATA_NEXT_OTHER ELDOTHERLINK
   168                              <2> %elifidni %4, last
   169                              <2>  %if ELDDATA_NEXT_STATUS == 0		; no next/last yet ?
   170                              <2>   %error Next last data link not allowed here
   171                              <2>  %elif ELDDATA_NEXT_STATUS == 2		; after last ?
   172                              <2>   %error Next last data link not allowed here
   173                              <2>  %elif ELDDATA_NEXT_STATUS == 3		; after single ?
   174                              <2>   %error Next last data link not allowed here
   175                              <2>  %elif ELDDATA_NEXT_STATUS == 1		; after next ?
   176                              <2>   %if ELDDATA_NEXT_ENTRY != %%entry 	|| ELDDATA_NEXT_SECTION != %%DATASECTION 	|| ELDDATA_NEXT_OTHER != ELDOTHERLINK
   179                              <2>    %error Unexpected next data link
   180                              <2>   %endif
   181                              <2>   %assign ELDDATA_NEXT_STATUS 2		; note now after last
   182                              <2>  %else
   183                              <2>   %error Next data link not allowed here
   184                              <2>  %endif
   185                              <2>  %assign %%next 800h
   186                              <2>  %assign ELDDATA_NEXT_ENTRY -1
   187                              <2>  %assign ELDDATA_NEXT_SECTION -1
   188                              <2> %else
   189                              <2>  %fatal Unknown next keyword
   190                              <2> %endif
   191                              <2> 	%if ELDOTHERLINK
   192                              <2> %if ELDLINKER
   193                              <2>  %xdefine LINK_OTHER_LINKER_DATA_RELOCATIONS LINK_OTHER_LINKER_DATA_RELOCATIONS, 1 + %%DATASECTION + %%optional + %%next, %%entry, %%name
   194                              <2> %else
   195                              <2>  %xdefine LINK_OTHER_DATA_RELOCATIONS LINK_OTHER_DATA_RELOCATIONS, 1 + %%DATASECTION + %%optional + %%next, %%entry, %%name
   196                              <2> %endif
   197                              <2> 	%else
   198                              <2> %if ELDLINKER
   199                              <2>  %xdefine LINK_LINKER_DATA_RELOCATIONS LINK_LINKER_DATA_RELOCATIONS, 1 + %%DATASECTION + %%optional + %%next, %%entry, %%name
   200                              <2> %else
   201                              <2>  %xdefine LINK_DATA_RELOCATIONS LINK_DATA_RELOCATIONS, 1 + %%DATASECTION + %%optional + %%next, %%entry, %%name
   202                              <2> %endif
   203                              <2> 	%endif
   204                              <2> %defstr %%string %1
   205                              <2> %strlen %%length %%string
   206                              <2> %if %%length > 64
   207                              <2> 	; Could be increased, but mustn't exceed 127 bytes
   208                              <2> 	;  because flag 80h is used to mark optional links
   209                              <2> 	;  that failed to be matched.
   210                              <2>  %error Too long link name: %1
   211                              <2> %endif
   212                              <2> %define LINK_DATA_CHECK %1
   213                              <2> 	%if ELDOTHERLINK
   214                              <2> 	linkdata_detect LINK_OTHER_DATA_DETECTION
   215                              <2> %if LINK_DATA_NEW
   216                              <2>  %xdefine LINK_OTHER_DATA_DETECTION LINK_OTHER_DATA_DETECTION, %1, %%name
   217                              <2> 	hashdef HASH, %%string
   218                              <2>  %xdefine LINK_OTHER_DATA_NAMES 	LINK_OTHER_DATA_NAMES, %%name:, dw _HASH, {counted %%string}
   220                              <2> %else
   221                              <2>  %%name equ LINK_DATA_DUPLICATE
   222                              <2> %endif
   223                              <2> 	%else
   224                              <2> 	linkdata_detect LINK_DATA_DETECTION
   225                              <2> %if LINK_DATA_NEW
   226                              <2>  %xdefine LINK_DATA_DETECTION LINK_DATA_DETECTION, %1, %%name
   227                              <2> 	hashdef HASH, %%string
   228                              <2>  %xdefine LINK_DATA_NAMES 	LINK_DATA_NAMES, %%name:, dw _HASH, {counted %%string}
   230                              <2> %else
   231                              <2>  %%name equ LINK_DATA_DUPLICATE
   232                              <2> %endif
   233                              <2> 	%endif
   234                              <2> 	eldstrictcheck
   235                              <2> 	%endmacro
   236                              <2> 
   237                              <2> 	%imacro linkdata_detect 2-*.nolist
   238                              <2> %assign LINK_DATA_NEW 1
   239                              <2> %rep (%0 - 2) / 2
   240                              <2>  %rotate 2
   241                              <2>  %ifidni %1, LINK_DATA_CHECK
   242                              <2>   %assign LINK_DATA_NEW 0
   243                              <2>   %xdefine LINK_DATA_DUPLICATE %2
   244                              <2>   %exitrep
   245                              <2>  %endif
   246                              <2> %endrep
   247                              <2> 	%endmacro
   248                              <2> 
   249                              <2> 	%imacro link_data_dump_names 1-*.nolist
   250                              <2> %rep %0
   251                              <2> 	%1
   252                              <2>  %rotate 1
   253                              <2> %endrep
   254                              <2> 	%endmacro
   255                              <2> 
   256                              <2> ; dw LINK_LINKER_DATA_RELOCATIONS, 0, 0
   257                              <2> ; dw LINK_DATA_RELOCATIONS, 0, 0
   258                              <2> ; link_data_dump_names ELDCALL_CODE_NAMES
   259                              <2> 
   260                              <2> %endif
    21                              <1> 
    22                              <1> %assign ELDLINKER 0
    23                              <1> 
    24                              <1> [section relocatedzero nobits vstart=0]
    25                              <1> relocatedzero:
    26                              <1> __SECT__
    27                              <1> 
    28                              <1> 	numdef HOUDINI, 1
    29                              <1> 	numdef HOUDINI_CONDITIONAL, 1
    30                              <1> 
    31                              <1> %imacro houdini 0.nolist
    32                              <1> %if _HOUDINI
    33                              <1>  %if _HOUDINI_CONDITIONAL
    34                              <1> reloc	testopt [ss:relocateddata], 100h
    35                              <1> linkdatarelocation options7, -3
    36                              <1> 	jz %%skip
    37                              <1>  %endif
    38                              <1> reloc	testopt [ss:relocateddata], 100h
    39                              <1> linkdatarelocation internalflags6, -3
    40                              <1> 	jz %%skip
    41                              <1> 	int3
    42                              <1> %%skip:
    43                              <1> %endif
    44                              <1> %endmacro
    45                              <1> 
    46                              <1> %define ELDCALL_CODE_RELOCATIONS ""
    47                              <1> %define ELDCALL_LINKER_CODE_RELOCATIONS ""
    48                              <1> %define ELDCALL_CODE_RELOCATIONS_OPTIONAL ""
    49                              <1> %define ELDCALL_LINKER_CODE_RELOCATIONS_OPTIONAL ""
    50                              <1> %define ELDCALL_CODE_NAMES db ""
    51                              <1> %define ELDCALL_CODE_DETECTION none, none
    52                              <1> %assign ELDCALL_OPTIONAL_STATUS 0		; not any seen yet
    53                              <1> %assign ELDCALL_PMREQUIRED_STATUS 0		; not any seen yet
    54                              <1> %assign ELDCALL_NEXT_STATUS 0			; not any seen yet
    55                              <1> %assign ELDCALL_NEXT_ENTRY -1
    56                              <1> 
    57                              <1> 	%imacro extcall 1-3.nolist required, single
    58                              <1> %ifidni _CURRENT_SECTION_TYPE, DATA
    59                              <1>  %error "ELD call cannot be used in ELD data block"
    60                              <1> %endif
    61                              <1> %assign %%entry $ + _CURRENT_SECTION %+ FIXUP
    62                              <1> %ifidni %2, required
    63                              <1>  %assign %%optional 0
    64                              <1> %elifidni %2, optional
    65                              <1>  %assign %%optional 100h
    66                              <1>  %if ELDCALL_OPTIONAL_STATUS == 0
    67                              <1>   %assign ELDCALL_OPTIONAL_STATUS 1
    68                              <1>  %elif ELDCALL_OPTIONAL_STATUS == 1
    69                              <1>  %else
    70                              <1>   %error Optional code link not allowed here
    71                              <1>  %endif
    72                              <1> %elifidni %2, PM required
    73                              <1>  %assign %%optional 300h
    74                              <1>  %assign ELDCALL_PMREQUIRED_STATUS 1
    75                              <1>  %if ELDCALL_OPTIONAL_STATUS == 0
    76                              <1>   %assign ELDCALL_OPTIONAL_STATUS 1
    77                              <1>  %elif ELDCALL_OPTIONAL_STATUS == 1
    78                              <1>  %else
    79                              <1>   %error Optional code link not allowed here
    80                              <1>  %endif
    81                              <1> %else
    82                              <1>  %fatal Unknown optional keyword
    83                              <1> %endif
    84                              <1> %ifidni %3, single
    85                              <1>  %if ELDCALL_NEXT_STATUS == 1		; after next ?
    86                              <1>   %error Unexpected single code link after next code link
    87                              <1>  %elif ELDCALL_NEXT_STATUS == 2		; after last ?
    88                              <1>   %assign ELDCALL_NEXT_STATUS 3		; note single with next/last present
    89                              <1>  %endif
    90                              <1>  %assign %%next 0
    91                              <1> %elifidni %3, next
    92                              <1>  %if ELDCALL_NEXT_STATUS == 0		; no next/last yet ?
    93                              <1>   %assign ELDCALL_NEXT_STATUS 1		; in next
    94                              <1>  %elif ELDCALL_NEXT_STATUS == 2		; after last ?
    95                              <1>   %assign ELDCALL_NEXT_STATUS 1		; in next
    96                              <1>  %elif ELDCALL_NEXT_STATUS == 3		; after single ?
    97                              <1>   %assign ELDCALL_NEXT_STATUS 1		; in next
    98                              <1>  %elif ELDCALL_NEXT_STATUS == 1		; repeated next ?
    99                              <1>   %if ELDCALL_NEXT_ENTRY != %%entry
   100                              <1>    %error Unexpected next code link
   101                              <1>   %endif
   102                              <1>  %else
   103                              <1>   %error Next code link not allowed here
   104                              <1>  %endif
   105                              <1>  %ifn %%optional
   106                              <1>   %error Next code link only valid as optional or PM required
   107                              <1>  %endif
   108                              <1>  %assign %%next 400h
   109                              <1>  %assign ELDCALL_NEXT_ENTRY %%entry
   110                              <1> %elifidni %3, last
   111                              <1>  %if ELDCALL_NEXT_STATUS == 0		; no next/last yet ?
   112                              <1>   %error Next last code link not allowed here
   113                              <1>  %elif ELDCALL_NEXT_STATUS == 2		; after last ?
   114                              <1>   %error Next last code link not allowed here
   115                              <1>  %elif ELDCALL_NEXT_STATUS == 3		; after single ?
   116                              <1>   %error Next last code link not allowed here
   117                              <1>  %elif ELDCALL_NEXT_STATUS == 1		; after next ?
   118                              <1>   %if ELDCALL_NEXT_ENTRY != %%entry
   119                              <1>    %error Unexpected next code link
   120                              <1>   %endif
   121                              <1>   %assign ELDCALL_NEXT_STATUS 2		; note now after last
   122                              <1>  %else
   123                              <1>   %error Next code link not allowed here
   124                              <1>  %endif
   125                              <1>  %assign %%next 800h
   126                              <1>  %assign ELDCALL_NEXT_ENTRY -1
   127                              <1>  %assign ELDCALL_NEXT_SECTION -1
   128                              <1> %else
   129                              <1>  %fatal Unknown next keyword
   130                              <1> %endif
   131                              <1> %if %%next != 400h
   132                              <1> %if 0
   133                              <1> [warning -reloc-rel-word]
   134                              <1> 	call near relocatedzero
   135                              <1> [warning +reloc-rel-word]
   136                              <1> %else
   137                              <1> 	db 0E8h
   138                              <1> reloc	dw relocatedzero
   139                              <1> 	eldstrictcheck
   140                              <1> %endif
   141                              <1> 	jmp strict short %%skipparameter
   142                              <1> 	dw 0
   143                              <1> %%skipparameter:
   144                              <1> %endif
   145                              <1> %if ELDLINKER
   146                              <1>  %xdefine ELDCALL_LINKER_CODE_RELOCATIONS ELDCALL_LINKER_CODE_RELOCATIONS, %%entry, %%name
   147                              <1>  %xdefine ELDCALL_LINKER_CODE_RELOCATIONS_OPTIONAL ELDCALL_LINKER_CODE_RELOCATIONS_OPTIONAL, 1 + %%optional + %%next, %%entry, %%name
   148                              <1> %else
   149                              <1>  %xdefine ELDCALL_CODE_RELOCATIONS ELDCALL_CODE_RELOCATIONS, %%entry, %%name
   150                              <1>  %xdefine ELDCALL_CODE_RELOCATIONS_OPTIONAL ELDCALL_CODE_RELOCATIONS_OPTIONAL, 1 + %%optional + %%next, %%entry, %%name
   151                              <1> %endif
   152                              <1> %defstr %%string %1
   153                              <1> %strlen %%length %%string
   154                              <1> %if %%length > 64
   155                              <1> 	; Could be increased, but mustn't exceed 127 bytes
   156                              <1> 	;  because flag 80h is used to mark optional links
   157                              <1> 	;  that failed to be matched.
   158                              <1>  %error Too long link name: %1
   159                              <1> %endif
   160                              <1> %define ELDCALL_CODE_CHECK %1
   161                              <1> 	linkcode_detect ELDCALL_CODE_DETECTION
   162                              <1> %if ELDCALL_CODE_NEW
   163                              <1>  %xdefine ELDCALL_CODE_DETECTION ELDCALL_CODE_DETECTION, %1, %%name
   164                              <1> 	hashdef HASH, %%string
   165                              <1> %xdefine ELDCALL_CODE_NAMES 	ELDCALL_CODE_NAMES, %%name:, dw _HASH, {counted %%string}
   167                              <1> %else
   168                              <1>  %%name equ ELDCALL_CODE_DUPLICATE
   169                              <1> %endif
   170                              <1> 	%endmacro
   171                              <1> 
   172                              <1> 	%imacro linkcode_detect 2-*.nolist
   173                              <1> %assign ELDCALL_CODE_NEW 1
   174                              <1> %rep (%0 - 2) / 2
   175                              <1>  %rotate 2
   176                              <1>  %ifidni %1, ELDCALL_CODE_CHECK
   177                              <1>   %assign ELDCALL_CODE_NEW 0
   178                              <1>   %xdefine ELDCALL_CODE_DUPLICATE %2
   179                              <1>   %exitrep
   180                              <1>  %endif
   181                              <1> %endrep
   182                              <1> 	%endmacro
   183                              <1> 
   184                              <1> 
   185                              <1> %define ELDCALL_CALLCALL_LIST none
   186                              <1> %define ELDCALL_CALLCALL_PROCESSED_PRIOR ""
   187                              <1> 
   188                              <1> 	%imacro extcallcall 1.nolist
   189                              <1> 	call %1
   190                              <1> %xdefine ELDCALL_CALLCALL_LIST ELDCALL_CALLCALL_LIST, %1
   191                              <1> 	%endmacro
   192                              <1> 
   193                              <1> %assign ELDCALLCALL_DUMPED 0
   194                              <1> 
   195                              <1> 	%imacro eldcall_dump_callcall 1-*.nolist
   196                              <1> %xdefine ELDCALL_CALLCALL_PROCESSED ELDCALL_CALLCALL_PROCESSED_PRIOR
   197                              <1>  %rep %0 - 1
   198                              <1>   %rotate 1
   199                              <1>   %define ELDCALL_CHECK %1
   200                              <1> 	eldcall_callcall_detect ELDCALL_CALLCALL_PROCESSED
   201                              <1>   %if ELDCALL_NEW
   202                              <1>    %xdefine ELDCALL_CALLCALL_PROCESSED ELDCALL_CALLCALL_PROCESSED, %1
   203                              <1> 	align 8, nop
   204                              <1> %1:
   205                              <1> 	extcall %1
   206                              <1> 	retn
   207                              <1>   %endif
   208                              <1>  %endrep
   209                              <1> %assign ELDCALLCALL_DUMPED 1
   210                              <1> %define ELDCALL_CALLCALL_LIST none
   211                              <1> 	%endmacro
   212                              <1> 
   213                              <1> 	%imacro eldcall_new_callcall 0.nolist
   214                              <1> %if ELDCALLCALL_DUMPED
   215                              <1>  %xdefine ELDCALL_CALLCALL_PROCESSED_PRIOR   ELDCALL_CALLCALL_PROCESSED_PRIOR, ELDCALL_CALLCALL_PROCESSED
   217                              <1>  %assign ELDCALLCALL_DUMPED 0
   218                              <1>  %define ELDCALL_CALLCALL_LIST none
   219                              <1> %endif
   220                              <1> 	%endmacro
   221                              <1> 
   222                              <1> 	%imacro eldcall_callcall_detect 1-*.nolist
   223                              <1> %assign ELDCALL_NEW 1
   224                              <1> %rep %0
   225                              <1>  %ifidni %1, ELDCALL_CHECK
   226                              <1>   %assign ELDCALL_NEW 0
   227                              <1>   %exitrep
   228                              <1>  %endif
   229                              <1>  %rotate 1
   230                              <1> %endrep
   231                              <1> 	%endmacro
   232                              <1> 
   233                              <1> 	%imacro eldcall_dump_names 1-*.nolist
   234                              <1> %rep %0
   235                              <1> 	%1
   236                              <1>  %rotate 1
   237                              <1> %endrep
   238                              <1> 	%endmacro
   239                              <1> 
   240                              <1> ; eldcall_dump_callcall ELDCALL_CALLCALL_LIST
   241                              <1> ; if using optional code links:
   242                              <1> ;  dw ELDCALL_LINKER_CODE_RELOCATIONS_OPTIONAL, 0
   243                              <1> ;  dw ELDCALL_CODE_RELOCATIONS_OPTIONAL, 0
   244                              <1> ; if not using optional code links:
   245                              <1> ;  dw ELDCALL_LINKER_CODE_RELOCATIONS, 0, 0
   246                              <1> ;  dw ELDCALL_CODE_RELOCATIONS, 0, 0
   247                              <1> ; eldcall_dump_names ELDCALL_CODE_NAMES
   248                              <1> 
   249                              <1> %endif
    10                                  %include "elddata.mac"
     1                              <1> %if 0
     2                              <1> 
     3                              <1> Extensions for lDebug data relocation macros
     4                              <1> 
     5                              <1> Copyright (C) 2008-2024 E. C. Masloch
     6                              <1> 
     7                              <1> Usage of the works is permitted provided that this
     8                              <1> instrument is retained with the works, so that any entity
     9                              <1> that uses the works is notified of this instrument.
    10                              <1> 
    11                              <1> DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
    12                              <1> 
    13                              <1> %endif
    14                              <1> 
    15                              <1> %ifndef ELDDATA_MAC
    16                              <1> %define ELDDATA_MAC 1
    17                              <1> 
    18                              <1> %include "lmacros3.mac"
    19                              <1> %include "nasmhash.mac"
    20                              <1> %include "eldcheck.mac"
    21                              <1> 
    22                              <1> 
    23                              <1> %assign ELDLINKER 0
    24                              <1> 
    25                              <1> %define INTERNAL_CODE_TO_CODE_RELOCATIONS ""
    26                              <1> %define INTERNAL_CODE_TO_DATA_RELOCATIONS ""
    27                              <1> %define INTERNAL_DATA_TO_CODE_RELOCATIONS ""
    28                              <1> %define INTERNAL_DATA_TO_DATA_RELOCATIONS ""
    29                              <1> %define INTERNAL_LINKER_CODE_TO_CODE_RELOCATIONS ""
    30                              <1> %define INTERNAL_LINKER_CODE_TO_DATA_RELOCATIONS ""
    31                              <1> %define INTERNAL_LINKER_DATA_TO_CODE_RELOCATIONS ""
    32                              <1> %define INTERNAL_LINKER_DATA_TO_DATA_RELOCATIONS ""
    33                              <1> %assign ELDDATA_OPTIONAL_STATUS 0		; not any seen yet
    34                              <1> %assign ELDDATA_PMREQUIRED_STATUS 0		; not any seen yet
    35                              <1> %assign ELDDATA_NEXT_STATUS 0			; not any seen yet
    36                              <1> %assign ELDDATA_NEXT_ENTRY -1
    37                              <1> %assign ELDDATA_NEXT_SECTION -1
    38                              <1> %assign ELDDATA_NEXT_OTHER -1
    39                              <1> 
    40                              <1> 	%imacro internalcoderelocation 0-1.nolist -2
    41                              <1> %assign %%entry $ + _CURRENT_SECTION %+ FIXUP + %1
    42                              <1> %if ELDLINKER
    43                              <1>  %ifidni _CURRENT_SECTION_TYPE, DATA
    44                              <1>   %xdefine INTERNAL_LINKER_DATA_TO_CODE_RELOCATIONS INTERNAL_LINKER_DATA_TO_CODE_RELOCATIONS, %%entry
    45                              <1>  %else
    46                              <1>   %xdefine INTERNAL_LINKER_CODE_TO_CODE_RELOCATIONS INTERNAL_LINKER_CODE_TO_CODE_RELOCATIONS, %%entry
    47                              <1>  %endif
    48                              <1> %else
    49                              <1>  %ifidni _CURRENT_SECTION_TYPE, DATA
    50                              <1>   %xdefine INTERNAL_DATA_TO_CODE_RELOCATIONS INTERNAL_DATA_TO_CODE_RELOCATIONS, %%entry
    51                              <1>  %else
    52                              <1>   %xdefine INTERNAL_CODE_TO_CODE_RELOCATIONS INTERNAL_CODE_TO_CODE_RELOCATIONS, %%entry
    53                              <1>  %endif
    54                              <1> %endif
    55                              <1> 	eldstrictcheck
    56                              <1> 	%endmacro
    57                              <1> 
    58                              <1> 	%imacro internaldatarelocation 0-1.nolist -2
    59                              <1> %assign %%entry $ + _CURRENT_SECTION %+ FIXUP + %1
    60                              <1> %if ELDLINKER
    61                              <1>  %ifidni _CURRENT_SECTION_TYPE, DATA
    62                              <1>   %xdefine INTERNAL_LINKER_DATA_TO_DATA_RELOCATIONS INTERNAL_LINKER_DATA_TO_DATA_RELOCATIONS, %%entry
    63                              <1>  %else
    64                              <1>   %xdefine INTERNAL_LINKER_CODE_TO_DATA_RELOCATIONS INTERNAL_LINKER_CODE_TO_DATA_RELOCATIONS, %%entry
    65                              <1>  %endif
    66                              <1> %else
    67                              <1>  %ifidni _CURRENT_SECTION_TYPE, DATA
    68                              <1>   %xdefine INTERNAL_DATA_TO_DATA_RELOCATIONS INTERNAL_DATA_TO_DATA_RELOCATIONS, %%entry
    69                              <1>  %else
    70                              <1>   %xdefine INTERNAL_CODE_TO_DATA_RELOCATIONS INTERNAL_CODE_TO_DATA_RELOCATIONS, %%entry
    71                              <1>  %endif
    72                              <1> %endif
    73                              <1> 	eldstrictcheck
    74                              <1> 	%endmacro
    75                              <1> 
    76                              <1> ; dw INTERNAL_LINKER_CODE_TO_CODE_RELOCATIONS, 0
    77                              <1> ; dw INTERNAL_LINKER_CODE_TO_DATA_RELOCATIONS, 0
    78                              <1> ; dw INTERNAL_LINKER_DATA_TO_CODE_RELOCATIONS, -1
    79                              <1> ; dw INTERNAL_LINKER_DATA_TO_DATA_RELOCATIONS, -1
    80                              <1> ; dw INTERNAL_CODE_TO_CODE_RELOCATIONS, 0
    81                              <1> ; dw INTERNAL_CODE_TO_DATA_RELOCATIONS, 0
    82                              <1> ; dw INTERNAL_DATA_TO_CODE_RELOCATIONS, -1
    83                              <1> ; dw INTERNAL_DATA_TO_DATA_RELOCATIONS, -1
    84                              <1> 
    85                              <1> 
    86                              <1> %define LINK_DATA_RELOCATIONS ""
    87                              <1> %define LINK_LINKER_DATA_RELOCATIONS ""
    88                              <1> %define LINK_DATA_NAMES db ""
    89                              <1> %define LINK_DATA_DETECTION none, none
    90                              <1> 
    91                              <1> %define LINK_OTHER_DATA_RELOCATIONS ""
    92                              <1> %define LINK_OTHER_LINKER_DATA_RELOCATIONS ""
    93                              <1> %define LINK_OTHER_DATA_NAMES db ""
    94                              <1> %define LINK_OTHER_DATA_DETECTION none, none
    95                              <1> 
    96                              <1> %ifndef ELDOTHER
    97                              <1>  %assign ELDOTHER 0
    98                              <1> %endif
    99                              <1> %assign ELDOTHERLINK 0
   100                              <1> 
   101                              <1> 	%imacro otherlinkdatarelocation 1-3.nolist -2, required
   102                              <1> %if ELDOTHER
   103                              <1>  %assign ELDOTHERLINK 1
   104                              <1> %endif
   105                              <1> 	linkdatarelocation %1, %2, %3
   106                              <1> %assign ELDOTHERLINK 0
   107                              <1> 	%endmacro
   108                              <1> 
   109                              <1> 	%imacro linkdatarelocation 1-4.nolist -2, required, single
   110                              <1> %assign %%entry $ + _CURRENT_SECTION %+ FIXUP + %2
   111                              <1> %ifidni %3, required
   112                              <1>  %assign %%optional 0
   113                              <1> %elifidni %3, optional
   114                              <1>  %assign %%optional 100h
   115                              <1>  %if ELDDATA_OPTIONAL_STATUS == 0
   116                              <1>   %assign ELDDATA_OPTIONAL_STATUS 1
   117                              <1>  %elif ELDDATA_OPTIONAL_STATUS == 1
   118                              <1>  %else
   119                              <1>   %error Optional data link not allowed here
   120                              <1>  %endif
   121                              <1> %elifidni %3, PM required
   122                              <1>  %assign %%optional 300h
   123                              <1>  %assign ELDDATA_PMREQUIRED_STATUS 1
   124                              <1>  %if ELDDATA_OPTIONAL_STATUS == 0
   125                              <1>   %assign ELDDATA_OPTIONAL_STATUS 1
   126                              <1>  %elif ELDDATA_OPTIONAL_STATUS == 1
   127                              <1>  %else
   128                              <1>   %error Optional data link not allowed here
   129                              <1>  %endif
   130                              <1> %else
   131                              <1>  %fatal Unknown optional keyword
   132                              <1> %endif
   133                              <1> %ifidni _CURRENT_SECTION_TYPE, DATA
   134                              <1>  %assign %%DATASECTION 1
   135                              <1> %else
   136                              <1>  %assign %%DATASECTION 0
   137                              <1> %endif
   138                              <1> %ifidni %4, single
   139                              <1>  %if ELDDATA_NEXT_STATUS == 1		; after next ?
   140                              <1>   %error Unexpected single data link after next data link
   141                              <1>  %elif ELDDATA_NEXT_STATUS == 2		; after last ?
   142                              <1>   %assign ELDDATA_NEXT_STATUS 3		; note single with next/last present
   143                              <1>  %endif
   144                              <1>  %assign %%next 0
   145                              <1> %elifidni %4, next
   146                              <1>  %if ELDDATA_NEXT_STATUS == 0		; no next/last yet ?
   147                              <1>   %assign ELDDATA_NEXT_STATUS 1		; in next
   148                              <1>  %elif ELDDATA_NEXT_STATUS == 2		; after last ?
   149                              <1>   %assign ELDDATA_NEXT_STATUS 1		; in next
   150                              <1>  %elif ELDDATA_NEXT_STATUS == 3		; after single ?
   151                              <1>   %assign ELDDATA_NEXT_STATUS 1		; in next
   152                              <1>  %elif ELDDATA_NEXT_STATUS == 1		; repeated next ?
   153                              <1>   %if ELDDATA_NEXT_ENTRY != %%entry 	|| ELDDATA_NEXT_SECTION != %%DATASECTION 	|| ELDDATA_NEXT_OTHER != ELDOTHERLINK
   156                              <1>    %error Unexpected next data link
   157                              <1>   %endif
   158                              <1>  %else
   159                              <1>   %error Next data link not allowed here
   160                              <1>  %endif
   161                              <1>  %ifn %%optional
   162                              <1>   %error Next data link only valid as optional or PM required
   163                              <1>  %endif
   164                              <1>  %assign %%next 400h
   165                              <1>  %assign ELDDATA_NEXT_ENTRY %%entry
   166                              <1>  %assign ELDDATA_NEXT_SECTION %%DATASECTION
   167                              <1>  %assign ELDDATA_NEXT_OTHER ELDOTHERLINK
   168                              <1> %elifidni %4, last
   169                              <1>  %if ELDDATA_NEXT_STATUS == 0		; no next/last yet ?
   170                              <1>   %error Next last data link not allowed here
   171                              <1>  %elif ELDDATA_NEXT_STATUS == 2		; after last ?
   172                              <1>   %error Next last data link not allowed here
   173                              <1>  %elif ELDDATA_NEXT_STATUS == 3		; after single ?
   174                              <1>   %error Next last data link not allowed here
   175                              <1>  %elif ELDDATA_NEXT_STATUS == 1		; after next ?
   176                              <1>   %if ELDDATA_NEXT_ENTRY != %%entry 	|| ELDDATA_NEXT_SECTION != %%DATASECTION 	|| ELDDATA_NEXT_OTHER != ELDOTHERLINK
   179                              <1>    %error Unexpected next data link
   180                              <1>   %endif
   181                              <1>   %assign ELDDATA_NEXT_STATUS 2		; note now after last
   182                              <1>  %else
   183                              <1>   %error Next data link not allowed here
   184                              <1>  %endif
   185                              <1>  %assign %%next 800h
   186                              <1>  %assign ELDDATA_NEXT_ENTRY -1
   187                              <1>  %assign ELDDATA_NEXT_SECTION -1
   188                              <1> %else
   189                              <1>  %fatal Unknown next keyword
   190                              <1> %endif
   191                              <1> 	%if ELDOTHERLINK
   192                              <1> %if ELDLINKER
   193                              <1>  %xdefine LINK_OTHER_LINKER_DATA_RELOCATIONS LINK_OTHER_LINKER_DATA_RELOCATIONS, 1 + %%DATASECTION + %%optional + %%next, %%entry, %%name
   194                              <1> %else
   195                              <1>  %xdefine LINK_OTHER_DATA_RELOCATIONS LINK_OTHER_DATA_RELOCATIONS, 1 + %%DATASECTION + %%optional + %%next, %%entry, %%name
   196                              <1> %endif
   197                              <1> 	%else
   198                              <1> %if ELDLINKER
   199                              <1>  %xdefine LINK_LINKER_DATA_RELOCATIONS LINK_LINKER_DATA_RELOCATIONS, 1 + %%DATASECTION + %%optional + %%next, %%entry, %%name
   200                              <1> %else
   201                              <1>  %xdefine LINK_DATA_RELOCATIONS LINK_DATA_RELOCATIONS, 1 + %%DATASECTION + %%optional + %%next, %%entry, %%name
   202                              <1> %endif
   203                              <1> 	%endif
   204                              <1> %defstr %%string %1
   205                              <1> %strlen %%length %%string
   206                              <1> %if %%length > 64
   207                              <1> 	; Could be increased, but mustn't exceed 127 bytes
   208                              <1> 	;  because flag 80h is used to mark optional links
   209                              <1> 	;  that failed to be matched.
   210                              <1>  %error Too long link name: %1
   211                              <1> %endif
   212                              <1> %define LINK_DATA_CHECK %1
   213                              <1> 	%if ELDOTHERLINK
   214                              <1> 	linkdata_detect LINK_OTHER_DATA_DETECTION
   215                              <1> %if LINK_DATA_NEW
   216                              <1>  %xdefine LINK_OTHER_DATA_DETECTION LINK_OTHER_DATA_DETECTION, %1, %%name
   217                              <1> 	hashdef HASH, %%string
   218                              <1>  %xdefine LINK_OTHER_DATA_NAMES 	LINK_OTHER_DATA_NAMES, %%name:, dw _HASH, {counted %%string}
   220                              <1> %else
   221                              <1>  %%name equ LINK_DATA_DUPLICATE
   222                              <1> %endif
   223                              <1> 	%else
   224                              <1> 	linkdata_detect LINK_DATA_DETECTION
   225                              <1> %if LINK_DATA_NEW
   226                              <1>  %xdefine LINK_DATA_DETECTION LINK_DATA_DETECTION, %1, %%name
   227                              <1> 	hashdef HASH, %%string
   228                              <1>  %xdefine LINK_DATA_NAMES 	LINK_DATA_NAMES, %%name:, dw _HASH, {counted %%string}
   230                              <1> %else
   231                              <1>  %%name equ LINK_DATA_DUPLICATE
   232                              <1> %endif
   233                              <1> 	%endif
   234                              <1> 	eldstrictcheck
   235                              <1> 	%endmacro
   236                              <1> 
   237                              <1> 	%imacro linkdata_detect 2-*.nolist
   238                              <1> %assign LINK_DATA_NEW 1
   239                              <1> %rep (%0 - 2) / 2
   240                              <1>  %rotate 2
   241                              <1>  %ifidni %1, LINK_DATA_CHECK
   242                              <1>   %assign LINK_DATA_NEW 0
   243                              <1>   %xdefine LINK_DATA_DUPLICATE %2
   244                              <1>   %exitrep
   245                              <1>  %endif
   246                              <1> %endrep
   247                              <1> 	%endmacro
   248                              <1> 
   249                              <1> 	%imacro link_data_dump_names 1-*.nolist
   250                              <1> %rep %0
   251                              <1> 	%1
   252                              <1>  %rotate 1
   253                              <1> %endrep
   254                              <1> 	%endmacro
   255                              <1> 
   256                              <1> ; dw LINK_LINKER_DATA_RELOCATIONS, 0, 0
   257                              <1> ; dw LINK_DATA_RELOCATIONS, 0, 0
   258                              <1> ; link_data_dump_names ELDCALL_CODE_NAMES
   259                              <1> 
   260                              <1> %endif
    11                                  
    12                                  	cpu 8086
    13                                  
    14                                  	addsection RELOCATEDDATA, nobits vstart=_ELD_RELOC_VSTART
    15                                  relocateddata:
    16                                  
    17                                  	addsection HEADER, start=0
    18                                  
    19                                  	istruc ELD_HEADERX
    20                                  at eldhxHeader
    21                                  		; ELD executable header
    22                                  	istruc ELD_HEADER
    23 00000000 454C4431                at eldhSignature,	db "ELD1"
    24 00000004 000000                  			db 0,0,0
    25 00000007 1A                      			db 26
    26 00000008 60000000                at eldhCodeOffset,	dd CODEOFFSET
    27 0000000C F009                    at eldhCodeImageLength,	dw code_size
    28 0000000E 0000                    at eldhCodeAllocLength,	dw 0
    29 00000010 500A0000                at eldhDataOffset,	dd DATAOFFSET
    30 00000014 D001                    at eldhDataImageLength,	dw data_size
    31 00000016 0000                    at eldhDataAllocLength,	dw total_data_size - data_size
    32 00000018 9602                    at eldhCodeEntrypoint,	dw linker - code
    33                                  at eldhReserved
    34 0000001A 00<rep 4h>2800          at eldhExtensionSize,	dw header_extension_end - $$
    35                                  	iend
    36 00000020 [30000000]              at eldhxDescriptionOffset,	dd description
    37 00000024 180B0000                at eldhxHelpOffset,		dd DATAOFFSET + msg.help - datastart
    38                                  PUT_ELDHX_DATETIME_OFFSET
    39                                  header_extension_end:
    40 00000028 00<rep 8h>              	iend
    41                                  
    42 00000030 496E6A65637420636F-     description:		asciz "Inject commands to other's AMIS function 43h."
    42 00000039 6D6D616E647320746F-
    42 00000042 206F74686572277320-
    42 0000004B 414D49532066756E63-
    42 00000054 74696F6E203433682E-
    42 0000005D 00                 
    43                                  
    44                                  
    45 0000005E 00<rep 2h>              	align 16, db 0
    46                                  
    47                                  CODEOFFSET equ $ - $$
    48                                  	addsection CODE, follows=HEADER vstart=_ELD_CODE_VSTART
    49                                  %define CODEFIXUP - code + 0
    50                                  code:
    51                                  code_start:
    52                                  		; ELD instance header
    53                                  	istruc ELD_INSTANCE
    54                                  at eldiStartCode
    55 00000000 00<rep 2h>              at eldiEndCode
    56 00000002 00<rep 2h>              at eldiStartData
    57 00000004 00<rep 2h>              at eldiEndData
    58 00000006 00<rep 2h>494E4A45-     at eldiIdentifier,	fill 8, 32, db "INJECT"
    58 0000000C 435420<rep 2h>     
    59 00000010 00<rep 2h>696E6A65-     at eldiListing,		asciz _ELD_LISTING
    59 00000016 63742E6C737400     
    60 0000001D 00<rep 3h>              	iend
    61                                  
    62                                  
    63                                  DATAOFFSET equ CODEOFFSET + code_size
    64                                  	addsection DATA, follows=CODE vstart=_ELD_DATA_VSTART
    65                                  %define DATAFIXUP - datastart + 0
    66                                  datastart:
    67                                  PUT_ELD_DATETIME
    68                                  
    69                                  
    70                                  	usesection CODE
    71                                  
    72                                  command:
    73 00000020 EB08                    	jmp strict short .entry
    74                                  .chain:
    75 00000022 E8[0000]EB020000        	extcall cmd3_not_ext, required	; must NOT be extcallcall
    76 00000029 90                      	times 10 - ($ - command) nop
    77                                  .entry:
    78 0000002A 56                      	push si
    79 0000002B 3C2D                    	cmp al, '-'
    80 0000002D 7503                    	jne @F
    81 0000002F E85E01                  	extcallcall skipcomma
    82                                  @@:
    83 00000032 4E                      	dec si
    84                                  
    85 00000033 BA[2000]                	mov dx, msg.inject
    86                                  internaldatarelocation
    87 00000036 E85F01                  	extcallcall isstring?
    88 00000039 7405                    	je @F
    89                                  .transfer_to_chain:
    90 0000003B 5E                      	pop si
    91 0000003C 4E                      	dec si
    92 0000003D AC                      	lodsb
    93 0000003E EBE2                    	jmp .chain
    94                                  
    95                                  @@:
    96 00000040 E84D01                  	extcallcall skipcomma
    97 00000043 4E                      	dec si
    98 00000044 C706[0000][0000]        reloc2	mov word [relocateddata], relocateddata
    99                                  linkdatarelocation lastcmd, -4
   100                                  linkdatarelocation dmycmd
   101 0000004A BA[0000]                	mov dx, relocateddata
   102                                  linkdatarelocation msg.uninstall
   103 0000004D E84801                  	extcallcall isstring?
   104 00000050 7503E9B700              	je uninstall
   105 00000055 BA[2700]                	mov dx, msg.run
   106                                  internaldatarelocation
   107 00000058 E83D01                  	call isstring?
   108 0000005B E83201                  	extcallcall skipcomma
   109 0000005E E80300                  	call run
   110 00000061 E83C01                  	extcallcall cmd3
   111                                  
   112                                  
   113                                  run:
   114 00000064 4E                      	dec si
   115 00000065 56                      	push si
   116 00000066 B02D                    	mov al, 2Dh
   117 00000068 E83D01                  	extcallcall intchk		; ZR if offset = -1 or segment = 0
   118                                  					; CHG: ax, dx, bx
   119 0000006B 746C                    	jz .no_hint
   120                                  
   121 0000006D BE[0000]                	mov si, msg.debuggeramissig
   122                                  internaldatarelocation
   123                                  
   124 00000070 8A26[0000]              	mov ah, byte [relocateddata]
   125                                  linkdatarelocation try_debugger_amis_multiplex_number
   126 00000074 E86A00                  	call inject_plex_check
   127 00000077 7305                    	jnc @F
   128                                  
   129 00000079 B4FF                    	mov ah, 0FFh		; start with multiplex number 0FFh
   130                                  .loop_hint_debug:
   131 0000007B E86300                  	call inject_plex_check
   132                                  @@:
   133 0000007E 731F                    	jnc .end_hint		; if found --> (NC)
   134 00000080 80EC01                  	sub ah, 1		; search is backward (to find latest installed first), from 0FFh to 00h including
   135 00000083 73F6                    	jnc .loop_hint_debug	; try next if we didn't check all yet -->
   136                                  
   137 00000085 BE[1000]                	mov si, msg.loaderamissig
   138                                  internaldatarelocation
   139                                  
   140 00000088 8A26[0000]              	mov ah, byte [relocateddata]
   141                                  linkdatarelocation try_debugger_amis_multiplex_number
   142 0000008C E85200                  	call inject_plex_check
   143 0000008F 7305                    	jnc @F
   144                                  
   145 00000091 B4FF                    	mov ah, 0FFh		; start with multiplex number 0FFh
   146                                  .loop_hint_loader:
   147 00000093 E84B00                  	call inject_plex_check
   148                                  @@:
   149 00000096 7307                    	jnc .end_hint		; if found --> (NC)
   150 00000098 80EC01                  	sub ah, 1		; search is backward (to find latest installed first), from 0FFh to 00h including
   151 0000009B 73F6                    	jnc .loop_hint_loader	; try next if we didn't check all yet -->
   152                                  
   153 0000009D EB3A                    	jmp .no_hint
   154                                  
   155                                  .end_hint:
   156 0000009F 5E                      	pop si
   157 000000A0 16                      	 push ss
   158 000000A1 07                      	 pop es
   159                                  
   160 000000A2 88E0                    	mov al, ah
   161 000000A4 BF[4900]                	mov di, msg.return.mpx
   162                                  internaldatarelocation
   163 000000A7 E80601                  	extcallcall hexbyte
   164                                  
   165 000000AA BF[0000]                	mov di, relocateddata
   166                                  linkdatarelocation line_out
   167 000000AD 89FB                    	mov bx, di			; bx -> buffer
   168 000000AF 31C9                    	xor cx, cx
   169 000000B1 47                      	inc di
   170                                  .loop:
   171 000000B2 AC                      	lodsb
   172 000000B3 E80201                  	extcallcall iseol?.notsemicolon
   173 000000B6 7404                    	je .end
   174 000000B8 41                      	inc cx
   175 000000B9 AA                      	stosb
   176 000000BA EBF6                    	jmp .loop
   177                                  
   178                                  .end:
   179 000000BC 880F                    	mov byte [bx], cl		; insert the count
   180 000000BE B00D                    	mov al, 13
   181 000000C0 AA                      	stosb				; for good measure add a CR
   182 000000C1 8B16[0000]              	mov dx, word [relocateddata]
   183                                  linkdatarelocation pspdbg		; => buffer
   184 000000C5 31C9                    	xor cx, cx			; flags
   185 000000C7 B043                    	mov al, 43h
   186 000000C9 E8F400                  	extcallcall call_int2D
   187 000000CC BF[5E00]                	mov di, msg.return.code
   188                                  internaldatarelocation
   189 000000CF E8DE00                  	extcallcall hexbyte
   190 000000D2 BA[2B00]                	mov dx, msg.return
   191                                  internaldatarelocation
   192                                  @@:
   193 000000D5 E8F000                  	extcallcall putsz
   194 000000D8 C3                      	retn
   195                                  
   196                                  .no_hint:
   197 000000D9 5E                      	pop si
   198 000000DA 16                      	 push ss
   199 000000DB 07                      	 pop es
   200 000000DC BA[6500]                	mov dx, msg.none
   201                                  internaldatarelocation
   202 000000DF EBF4                    	jmp @B
   203                                  
   204                                  
   205                                  		; INP:	ah = multiplex number to check
   206                                  		;	ss:si -> 16-byte AMIS signature to check
   207                                  		; OUT:	CY if multiplex number unused or no signature match,
   208                                  		;	 bp, ah, ds unmodified
   209                                  		;	NC if match found,
   210                                  		;	 ah = multiplex number (unmodified)
   211                                  		; CHG:	di, es, bx, cx, dx
   212                                  inject_plex_check:
   213 000000E1 16                      	push ss
   214 000000E2 1F                      	pop ds
   215 000000E3 F606[0000]08            	testopt [relocateddata], 8
   216                                  linkdatarelocation internalflags4, -3
   217 000000E8 740B                    	jz @F
   218 000000EA BB[0000]                	mov bx, relocateddata
   219                                  linkdatarelocation amis_multiplex_number, -2, optional
   220 000000ED 85DB                    	test bx, bx
   221 000000EF 7404                    	jz @F
   222 000000F1 3A27                    	cmp ah, byte [bx]
   223 000000F3 7415                    	je .notfound		; do not use our own multiplexer -->
   224                                  @@:
   225 000000F5 B000                    	mov al, 00h		; AMIS installation check
   226 000000F7 E8C600                  	extcallcall call_int2D	; AMIS (or "DOS reserved" = iret if no AMIS present)
   227 000000FA 3CFF                    	cmp al, 0FFh
   228 000000FC 750C                    	jne .notfound
   229                                  	; push cs
   230                                  	; pop ds
   231 000000FE 56                      	push si
   232 000000FF E8CE00                  	extcallcall setes2dx	; es:di -> name strings of AMIS multiplexer that just answered
   233 00000102 B90800                  	mov cx, 8		; Ignore description, only compare vendor and program name
   234 00000105 F3A7                    	repe cmpsw
   235 00000107 5E                      	pop si
   236 00000108 7401                    	je .checkret		; ZR, NC = match -->
   237                                  .notfound:
   238 0000010A F9                      	stc			; CY no match
   239                                  .checkret:
   240 0000010B C3                      	retn
   241                                  
   242                                  
   243                                  uninstall:
   244 0000010C AC                      	lodsb
   245 0000010D E8C800                  	extcallcall chkeol
   246                                  
   247 00000110 8E06[0000]              	mov es, word [relocateddata]
   248                                  linkdatarelocation extdssel
   249 00000114 E8C900                  	extcallcall ispm
   250 00000117 7404                    	jz @F
   251 00000119 8E06[0000]              	mov es, word [relocateddata]
   252                                  linkdatarelocation extseg
   253                                  @@:
   254 0000011D 06                      	push es
   255 0000011E 1F                      	pop ds
   256                                  
   257 0000011F 31DB                    	xor bx, bx		; = 0 (no prior, modify ext_command_handler)
   258 00000121 BF[2000]                	mov di, command		; di -> us
   259                                  internalcoderelocation
   260 00000124 368B36[0000]            	mov si, word [ss:relocateddata]
   261                                  linkdatarelocation ext_command_handler
   262                                  				; si -> first
   263 00000129 85F6                    	test si, si		; none installed ?
   264 0000012B 7450                    	jz .error		; error -->
   265                                  
   266                                  .loop:
   267 0000012D 39F7                    	cmp di, si		; found ?
   268 0000012F 740D                    	je .bx			; yes, use bx -->
   269 00000131 89F3                    	mov bx, si		; bx -> prior handler
   270 00000133 AD                      	lodsw			; skip entrypoint jmp strict short
   271 00000134 AC                      	lodsb			; get first byte of chainer
   272 00000135 3CE9                    	cmp al, 0E9h		; expecting jmp near ?
   273 00000137 7544                    	jne .error		; no, error -->
   274 00000139 AD                      	lodsw			; get rel16 displacement
   275 0000013A 01C6                    	add si, ax		; -> next handler
   276 0000013C EBEF                    	jmp .loop
   277                                  
   278                                  .bx:
   279 0000013E 85DB                    	test bx, bx		; any prior ?
   280 00000140 751A                    	jnz .bxnz		; yes -->
   281 00000142 AF                      	scasw			; skip entrypoint jmp strict short
   282 00000143 803DE8                  	cmp byte [di], 0E8h	; is it a call to cmd3_not_ext ?
   283 00000146 7507                    	jne @F			; no -->
   284                                  				; yes, reset ext_command_handler to zero
   285                                  .setbx:
   286 00000148 36891E[0000]            	mov word [ss:relocateddata], bx
   287                                  linkdatarelocation ext_command_handler
   288 0000014D EB1E                    	jmp .done
   289                                  
   290                                  @@:
   291 0000014F 803DE9                  	cmp byte [di], 0E9h	; validate
   292 00000152 7529                    	jne .error		; failure -->
   293 00000154 47                      	inc di			; -> rel16 displacement
   294 00000155 8B1D                    	mov bx, word [di]	; get displacement
   295 00000157 AF                      	scasw			; -> after jmp near
   296 00000158 01FB                    	add bx, di		; -> next handler
   297 0000015A EBEC                    	jmp .setbx		; set ext_command_handler to next
   298                                  
   299                                  .bxnz:
   300 0000015C 89DE                    	mov si, bx		; -> prior handler with us as downlink
   301 0000015E 87FE                    	xchg di, si		; si -> ours, di -> prior
   302 00000160 A7                      	cmpsw			; skip entrypoint jmp strict short
   303 00000161 A4                      	movsb			; copy 0E8h/0E9h
   304 00000162 AD                      	lodsw			; ax = near rel16 displacement
   305 00000163 01F0                    	add ax, si		; add in our base (= absolute offset)
   306 00000165 29F8                    	sub ax, di
   307 00000167 48                      	dec ax
   308 00000168 48                      	dec ax			; subtract new base (= relative displacement)
   309 00000169 AB                      	stosw			; store new rel16 displacement
   310 0000016A A5                      	movsw			; jmp strict short
   311 0000016B A5                      	movsw			; linkcall target
   312 0000016C A4                      	movsb			; trailer
   313                                  .done:
   314 0000016D 8026[1000]FE            	clropt [code + eldiFlags], eldifResident
   315                                  internalcoderelocation -3	; mark block as free
   316 00000172 BA[8000]                	mov dx, msg.uninstall_done
   317                                  internaldatarelocation
   318                                  @@:
   319 00000175 16                      	push ss
   320 00000176 1F                      	pop ds
   321 00000177 E84E00                  	extcallcall putsz
   322 0000017A E82300                  	extcallcall cmd3	; return
   323                                  
   324                                  .error:
   325 0000017D B8010E                  	mov ax, 0E01h
   326 00000180 E86500                  	extcallcall setrc
   327 00000183 BA[9600]                	mov dx, msg.uninstall_error
   328                                  internaldatarelocation
   329 00000186 EBED                    	jmp @B
   330                                  
   331                                  
   332                                  error:
   333 00000188 E8[0000]EB020000        	extcall error
   334                                  
   335 0000018F 90E8[0000]EB020000-     	eldcall_dump_callcall ELDCALL_CALLCALL_LIST
   335 00000197 C3E8[0000]EB020000-
   335 0000019F C3E8[0000]EB020000-
   335 000001A7 C3E8[0000]EB020000-
   335 000001AF C3E8[0000]EB020000-
   335 000001B7 C3E8[0000]EB020000-
   335 000001BF C3E8[0000]EB020000-
   335 000001C7 C3E8[0000]EB020000-
   335 000001CF C3E8[0000]EB020000-
   335 000001D7 C3E8[0000]EB020000-
   335 000001DF C3E8[0000]EB020000-
   335 000001E7 C3E8[0000]EB020000-
   335 000001EF C3                 
   336                                  
   337                                  endinstalled equ ($ + CODEFIXUP + 15) & ~15
   338                                  
   339                                  
   340                                  start:
   341 000001F0 8CC3                    	mov bx, es
   342 000001F2 16                      	 push ss
   343 000001F3 07                      	 pop es
   344 000001F4 E899FF                  	call skipcomma
   345 000001F7 4E                      	dec si
   346 000001F8 BA[0000]                	mov dx, relocateddata
   347                                  linkdatarelocation msg.install
   348 000001FB E89AFF                  	call isstring?
   349 000001FE 7443                    	je install
   350                                  
   351 00000200 BA[2700]                	mov dx, msg.run
   352                                  internaldatarelocation
   353 00000203 E892FF                  	call isstring?
   354 00000206 7410                    	je .run
   355                                  
   356 00000208 BA[C800]                	mov dx, msg.help
   357                                  internaldatarelocation
   358 0000020B E8[0000]EB020000        	extcall putsz
   359                                  @@:
   360 00000212 E80B00                  	call uninstall_oneshot
   361 00000215 31C0                    	xor ax, ax
   362 00000217 CB                      	retf
   363                                  
   364                                  .run:
   365 00000218 E875FF                  	call skipcomma
   366 0000021B E846FE                  	call run
   367 0000021E EBF2                    	jmp @B
   368                                  
   369                                  
   370                                  uninstall_oneshot:
   371 00000220 36F606[0000]01          	testopt [ss:relocateddata], 1
   372                                  linkdatarelocation options7, -3
   373 00000226 751A                    	jnz @F
   374                                  
   375 00000228 2EA1[0200]              	mov ax, word [cs:code + eldiEndCode]
   376                                  internalcoderelocation
   377 0000022C 2E2B06[0000]            	sub ax, word [cs:code + eldiStartCode]
   378                                  internalcoderelocation
   379 00000231 2906[0000]              	sub word [relocateddata], ax
   380                                  linkdatarelocation extseg_used
   381                                  
   382 00000235 2EA1[0600]              	mov ax, word [cs:code + eldiEndData]
   383                                  internalcoderelocation
   384 00000239 2E2B06[0400]            	sub ax, word [cs:code + eldiStartData]
   385                                  internalcoderelocation
   386 0000023E 2906[0000]              	sub word [relocateddata], ax
   387                                  linkdatarelocation extdata_used
   388                                  @@:
   389 00000242 C3                      	retn
   390                                  
   391                                  
   392                                  	usesection DATA
   393                                  	align 2, db 0
   394                                  
   395                                  msg:
   396                                  .debuggeramissig:
   397 00000000 65636D20<rep 5h>        		fill 8, 32, db "ecm"
   398 00000008 6C446562756720-         		fill 8, 32, db "lDebug"
   398 00000008 <rep 2h>           
   399                                  .loaderamissig:
   400 00000010 65636D20<rep 5h>        		fill 8, 32, db "ecm"
   401 00000018 4C6F6164657220-         		fill 8, 32, db "Loader"
   401 00000018 <rep 2h>           
   402 00000020 494E4A45435400          .inject:		asciz "INJECT"
   403 00000027 52554E00                .run:			asciz "RUN"
   404 0000002B 496E6A656374696E67-     .return:		db "Injecting to multiplex number "
   404 00000034 20746F206D756C7469-
   404 0000003D 706C6578206E756D62-
   404 00000046 657220             
   405 00000049 2D2D682C2072657475-     .return.mpx:		db "--h, return value is "
   405 00000052 726E2076616C756520-
   405 0000005B 697320             
   406 0000005E 2D2D682E0D0A00          .return.code:		asciz "--h.",13,10
   407 00000065 4E6F206D756C746970-     .none:			asciz "No multiplexer detected!",13,10
   407 0000006E 6C6578657220646574-
   407 00000077 6563746564210D0A00 
   408 00000080 494E4A45435420756E-     .uninstall_done:	db "INJECT uninstalled."
   408 00000089 696E7374616C6C6564-
   408 00000092 2E                 
   409                                  %if _ELD_RECLAIM_HINT
   410                                  			db " (Don't forget to use reclaim.eld)"
   411                                  %endif
   412 00000093 0D0A00                  			asciz 13,10
   413 00000096 494E4A45435420756E-     .uninstall_error:	db "INJECT unable to uninstall!"
   413 0000009F 61626C6520746F2075-
   413 000000A8 6E696E7374616C6C21 
   414 000000B1 0D0A00                  .linebreak:		asciz 13,10
   415                                  
   416                                  uinit_data: equ $
   417                                  
   418 000000B4 494E4A45435420696E-     .installed:	asciz "INJECT installed.",13,10
   418 000000BD 7374616C6C65642E0D-
   418 000000C6 0A00               
   419 000000C8 496E7374616C6C2074-     .help:		db "Install this ELD using an INSTALL keyword or run with RUN.",13,10
   419 000000D1 68697320454C442075-
   419 000000DA 73696E6720616E2049-
   419 000000E3 4E5354414C4C206B65-
   419 000000EC 79776F7264206F7220-
   419 000000F5 72756E207769746820-
   419 000000FE 52554E2E0D0A       
   420 00000104 0D0A                    		db 13,10
   421 00000106 53656E647320612063-     		db "Sends a command to other's AMIS function 43h.",13,10
   421 0000010F 6F6D6D616E6420746F-
   421 00000118 206F74686572277320-
   421 00000121 414D49532066756E63-
   421 0000012A 74696F6E203433682E-
   421 00000133 0D0A               
   422 00000135 496E6A656374696F6E-     		db "Injection occurs before the next command in cmd3.",13,10
   422 0000013E 206F63637572732062-
   422 00000147 65666F726520746865-
   422 00000150 206E65787420636F6D-
   422 00000159 6D616E6420696E2063-
   422 00000162 6D64332E0D0A       
   423 00000168 0D0A                    		db 13,10
   424 0000016A 52756E207769746820-     		db "Run with INJECT [RUN] <command> to inject command.",13,10
   424 00000173 494E4A454354205B52-
   424 0000017C 554E5D203C636F6D6D-
   424 00000185 616E643E20746F2069-
   424 0000018E 6E6A65637420636F6D-
   424 00000197 6D616E642E0D0A     
   425 0000019E 52756E207769746820-     		db "Run with INJECT UNINSTALL to uninstall.",13,10
   425 000001A7 494E4A45435420554E-
   425 000001B0 494E5354414C4C2074-
   425 000001B9 6F20756E696E737461-
   425 000001C2 6C6C2E0D0A         
   426 000001C7 00                      		asciz
   427                                  
   428                                  
   429 000001C8 00<rep 8h>              	align 16, db 0
   430                                  init_data_end:
   431                                  data_size equ $ - datastart
   432                                  transient_data_size equ data_size
   433                                  
   434                                  	absolute uinit_data
   435                                  
   436 000000B4 <res Ch>                	alignb 16
   437                                  uinit_data_end:
   438                                  resident_data_end:
   439                                  resident_data_size equ resident_data_end - datastart
   440                                  
   441                                  %if uinit_data_end >= init_data_end
   442                                   total_data_size equ $ - datastart
   443                                  %else
   444                                   total_data_size equ init_data_end - datastart
   445                                  %endif
   446                                  %assign _DATA_SIZE total_data_size
   447                                  
   448                                  
   449                                  	usesection CODE
   450                                  
   451                                  install:
   452 00000243 AC                      	lodsb
   453 00000244 E8[0000]EB020000        	extcall chkeol
   454                                  
   455                                  	houdini
   456 0000024B 8EC3                    	mov es, bx		; => ext seg (writable)
   457                                  
   458 0000024D B8B000                  	mov ax, endresident - endinstalled
   459 00000250 262906[0200]            	sub word [es:code + eldiEndCode], ax
   460                                  internalcoderelocation		; adjust size
   461 00000255 2906[0000]              	sub word [relocateddata], ax
   462                                  linkdatarelocation extseg_used	; adjust size
   463                                  
   464                                  %if (transient_data_size - resident_data_size) > 0
   465 00000259 B81001                  	mov ax, transient_data_size - resident_data_size
   466 0000025C 262906[0600]            	sub word [es:code + eldiEndData], ax
   467                                  internalcoderelocation		; adjust size
   468 00000261 2906[0000]              	sub word [relocateddata], ax
   469                                  linkdatarelocation extdata_used	; adjust size
   470                                  %endif
   471                                  
   472 00000265 8B1E[0000]              	mov bx, word [relocateddata]
   473                                  linkdatarelocation ext_command_handler
   474                                  				; -> prior
   475 00000269 BF[2000]                	mov di, command		; -> our handler
   476                                  internalcoderelocation
   477 0000026C 85DB                    	test bx, bx		; installing as first ?
   478 0000026E 740A                    	jz .only_first		; yes, simple --> (leave as extcall cmd3_not_ext)
   479 00000270 AF                      	scasw			; skip entrypoint jmp strict short
   480 00000271 B0E9                    	mov al, 0E9h		; = jmp near opcode
   481 00000273 AA                      	stosb			; store
   482 00000274 93                      	xchg ax, bx		; ax -> next handler
   483 00000275 29F8                    	sub ax, di
   484 00000277 48                      	dec ax
   485 00000278 48                      	dec ax			; ax = ax - (di + 2)
   486 00000279 AB                      	stosw			; store our downlink as rel16 displacement
   487                                  
   488                                  .only_first:
   489 0000027A 26800E[1000]01          	setopt [es:code + eldiFlags], eldifResident
   490                                  internalcoderelocation -3	; mark block as resident
   491 00000280 C706[0000][2000]        	mov word [relocateddata], command
   492                                  linkdatarelocation ext_command_handler, -4
   493                                  internalcoderelocation		; -> our entrypoint
   494                                  
   495 00000286 F606[0000]04            	testopt [relocateddata], 4
   496                                  linkdatarelocation options7, -3
   497 0000028B 7506                    	jnz @F
   498 0000028D BA[B400]                	mov dx, msg.installed
   499                                  internaldatarelocation
   500 00000290 E835FF                  	call putsz
   501                                  @@:
   502                                  
   503 00000293 31C0                    	xor ax, ax
   504 00000295 CB                      	retf
   505                                  
   506                                  
   507                                  %include "eldlink.asm"
     1                              <1> %if 0
     2                              <1> 
     3                              <1> Extensions for lDebug linker
     4                              <1> 
     5                              <1> Copyright (C) 2008-2025 E. C. Masloch
     6                              <1> 
     7                              <1> Usage of the works is permitted provided that this
     8                              <1> instrument is retained with the works, so that any entity
     9                              <1> that uses the works is notified of this instrument.
    10                              <1> 
    11                              <1> DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
    12                              <1> 
    13                              <1> %endif
    14                              <1> 
    15                              <1> %include "lmacros3.mac"
     1                              <2> [list -]
    16                              <1> %include "eld.mac"
     1                              <2> %if 0
     2                              <2> 
     3                              <2> Extensions for lDebug macros
     4                              <2> 
     5                              <2> Copyright (C) 2008-2025 E. C. Masloch
     6                              <2> 
     7                              <2> Usage of the works is permitted provided that this
     8                              <2> instrument is retained with the works, so that any entity
     9                              <2> that uses the works is notified of this instrument.
    10                              <2> 
    11                              <2> DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
    12                              <2> 
    13                              <2> %endif
    14                              <2> 
    15                              <2> %ifndef ELD_MAC
    16                              <2> %define ELD_MAC 1
    17                              <2> 
    18                              <2> %include "lmacros3.mac"
    19                              <2> 
    20                              <2> 		; ELD executable header
    21                              <2> 	struc ELD_HEADER
    22                              <2> eldhSignature:		resb 4	; "ELD1"
    23                              <2> 			resb 3	; reserved
    24                              <2> 			resb 1	; 26 (Ctrl-Z)
    25                              <2> eldhCodeOffset:		resd 1	; position displacement from eldhSignature
    26                              <2> eldhCodeImageLength:	resw 1	; amount bytes, at least 32
    27                              <2> eldhCodeAllocLength:	resw 1	; amount bytes, added to prior. sum < 64 KiB
    28                              <2> eldhDataOffset:		resd 1
    29                              <2> eldhDataImageLength:	resw 1	; (zero allowed)
    30                              <2> eldhDataAllocLength:	resw 1	; (zero allowed)
    31                              <2> eldhCodeEntrypoint:	resw 1	; within code section, used as displacement
    32                              <2> eldhReserved:		resb 4	; reserved
    33                              <2> eldhExtensionSize:	resw 1	; from eldhSignature, -> past eldhx fields in use
    34                              <2> 	endstruc
    35                              <2> 	endarea ELD_HEADER, 1
    36                              <2> 
    37                              <2> 	struc ELD_HEADERX
    38                              <2> eldhxHeader:		resb ELD_HEADER_size
    39                              <2> eldhxDescriptionOffset:	resd 1	; zero if none, from eldhxHeader. <= 128 Bytes
    40                              <2> eldhxHelpOffset:	resd 1	; zero if none, from eldhxHeader
    41                              <2> eldhxLibTable:		resd 1	; zero if none, from eldhxHeader
    42                              <2> eldhxDateTimeOffset:	resd 1	; zero if none, from eldhxHeader
    43                              <2> 	alignb 16
    44                              <2> 	endstruc
    45                              <2> 
    46                              <2> 	struc ELD_TRAILER_HEADER
    47                              <2> eldthSignature:		resb 8	; "ELD1TAIL"
    48                              <2> eldthHeaderOffset:	resd 1	; negative displacement from eldthSignature,
    49                              <2> 				;  add this dword to the seek offset
    50                              <2> eldthReserved:		resw 1	; reserved, must be initialised to zero
    51                              <2> eldthChecksum:		resw 1	; sum of all words in trailer header = 0
    52                              <2> 	endstruc
    53                              <2> 	endarea ELD_TRAILER_HEADER, 1
    54                              <2> 
    55                              <2> 	struc ELD_LIBTABLE
    56                              <2> eldltFormat:		resw 1
    57                              <2> 	; 0 = uncompressed
    58                              <2> 	; 2 = heatshrink compressed
    59                              <2> 	; 3 = lzexedat -4 compressed
    60                              <2> 	; 4 = lzexedat -4 -l compressed
    61                              <2> eldltAmount:		resw 1
    62                              <2> eldltOffset:		resd 1	; from eldhxHeader
    63                              <2> eldltCompressedLength:		; (dword, only present if format 2, 3, or 4)
    64                              <2> 	endstruc
    65                              <2> 	endarea ELD_LIBTABLE, 1
    66                              <2> 
    67                              <2> 		; ELD instance header
    68                              <2> 	struc ELD_INSTANCE
    69                              <2> eldiStartCode:		resw 1	; -> this structure itself (para aligned)
    70                              <2> eldiEndCode:		resw 1	; -> behind memory used by instance (para aligned)
    71                              <2> eldiStartData:		resw 1	; -> data in data entry section (para aligned), or 0
    72                              <2> eldiEndData:		resw 1	; -> behind data (para aligned), or 0
    73                              <2> eldiIdentifier:		resb 8	; blank-filled text
    74                              <2> eldiFlags:		resw 1	; flags
    75                              <2> eldiListing_size equ 14
    76                              <2> eldiListing:		resb eldiListing_size
    77                              <2> 				; ASCIZ listing file name
    78                              <2> 	endstruc
    79                              <2> 		; flags for eldiFlags:
    80                              <2> eldifResident:		equ 1
    81                              <2> 
    82                              <2> 		; ELD link info header
    83                              <2> 	struc ELD_LINKINFO
    84                              <2> eldlSignature:		resw 1	; 0E1D1h
    85                              <2> eldlReserved:		resw 2
    86                              <2> eldlUseLinkHash:	resw 1
    87                              <2> eldlDataAmount:		resw 1
    88                              <2> eldlDataPrefixes:	resw 1
    89                              <2> eldlDataEntries:	resw 1
    90                              <2> eldlDataAddresses:	resw 1
    91                              <2> eldlCodeAmount:		resw 1
    92                              <2> eldlCodePrefixes:	resw 1
    93                              <2> eldlCodeEntries:	resw 1
    94                              <2> eldlCodeAddresses:	resw 1
    95                              <2> 	endstruc
    96                              <2> 
    97                              <2> 	numdef ELD_CODE_VSTART, 9001h
    98                              <2> 	numdef ELD_DATA_VSTART, 8000h
    99                              <2> 	numdef ELD_RELOC_VSTART, 8000h
   100                              <2> 
   101                              <2> 	numdef ELD_RECLAIM_HINT, 0
   102                              <2> 	strdef ELD_LISTING, ""
   103                              <2> 	numdef ELD_DATETIME, 0
   104                              <2> 
   105                              <2> %if _ELD_DATETIME
   106                              <2>  %define PUT_ELDHX_DATETIME_OFFSET at eldhxDateTimeOffset, dd DATAOFFSET + datetime - datastart
   107                              <2>  %macro PUT_ELD_DATETIME 0.nolist
   108                              <2> datetime:	asciz __UTC_DATE__,'T',__UTC_TIME__,'Z'
   109                              <2> 		asciz		; for future extension
   110                              <2>  %endmacro
   111                              <2> %else
   112                              <2>  %define PUT_ELDHX_DATETIME_OFFSET
   113                              <2>  %define PUT_ELD_DATETIME
   114                              <2> %endif
   115                              <2> 
   116                              <2> %endif
    17                              <1> 
    18                              <1> 	cpu 8086
    19                              <1> 
    20                              <1> %if ELDSTRICT
    21                              <1>  %if ELDSTRICTCOUNTER
    22                              <1>   %error Missing relocation
    23                              <1>  %endif
    24                              <1> %endif
    25                              <1> 	eldstrict off		; linker does some relocations
    26                              <1> 
    27                              <1> %ifn ELDCALLCALL_DUMPED
    28                              <1> 	eldcall_dump_callcall ELDCALL_CALLCALL_LIST
    29                              <1> %endif
    30                              <1> 
    31                              <1> 	numdef ELD_IDENTICALISE, 0
    32                              <1> 	numdef ELD_DEBUG, 0
    33                              <1> 	numdef ELD_LINKER_PASSES, 1
    34                              <1> 	strdef LISTING, _ELD_LISTING
    35                              <1> 	numdef ELDCALL_OPTIONAL, ELDCALL_OPTIONAL_STATUS
    36                              <1> 	numdef ELDDATA_OPTIONAL, ELDDATA_OPTIONAL_STATUS
    37                              <1> 	numdef ELDDATA_NEXT, ELDDATA_NEXT_STATUS
    38                              <1> 	numdef ELDCALL_NEXT, ELDCALL_NEXT_STATUS
    39                              <1> %if _ELD_IDENTICALISE
    40                              <1>  ;%assign _ELDCALL_OPTIONAL 1
    41                              <1> %endif
    42                              <1> %ifn _ELDCALL_OPTIONAL
    43                              <1> %assign ELDCALL_OPTIONAL_STATUS 2		; not allowed
    44                              <1> %endif
    45                              <1> ;%ifn _ELDDATA_OPTIONAL
    46                              <1> ;%assign ELDDATA_OPTIONAL_STATUS 2		; not allowed
    47                              <1> ;%endif
    48                              <1> 	gendef MAP, ""
    49                              <1> 
    50                              <1> %ifnidni _MAP, ""
    51                              <1>  [map all _MAP]
    52                              <1> %endif
    53                              <1> 
    54                              <1> 
    55                              <1> endresident: equ ($ + _CURRENT_SECTION %+ FIXUP + 15) & ~15
    56                              <1> 
    57                              <1> %if _ELD_LINKER_PASSES
    58                              <1> %assign ELDLINKER 1
    59                              <1> 
    60                              <1> 	struc LINKTABLE
    61 00000000 ????????            <1> ltCodeToCode:	resw 2
    62 00000004 ????????            <1> ltCodeToData:	resw 2
    63 00000008 ????????            <1> ltDataToCode:	resw 2
    64 0000000C ????????            <1> ltDataToData:	resw 2
    65 00000010 ????????            <1> ltLinkData:	resw 2
    66 00000014 ????????            <1> ltLinkCode:	resw 2
    67                              <1> 	endstruc
    68                              <1> %endif
    69                              <1> 
    70                              <1> 
    71                              <1> 		; INP:	es:dx -> loaded initial ELD image
    72                              <1> 		;	 ELD instance structure filled
    73                              <1> 		;	es => ELD code area
    74                              <1> 		;	ds:di -> link info
    75                              <1> 		;	ss:bx -> loaded initial data
    76                              <1> 		;	ss:si -> command line tail
    77                              <1> 		;	cs:ip -> entrypoint
    78                              <1> 		;	ss:sp -> far return address for current mode
    79                              <1> 		; STT:	UP, EI
    80                              <1> linker:
    81                              <1> 		; The first 15 Bytes of the linker should be
    82                              <1> 		;  the same regardless of the linker options
    83                              <1> 		;  used (debug, passes, vstart). This allows
    84                              <1> 		;  the eldcomp ELD to match even if up to 15
    85                              <1> 		;  Bytes of the linker are trailing in the
    86                              <1> 		;  resident part of the ELD.
    87                              <1> 	lframe
    88                              <1>  %if ELDOTHER
    89                              <1> 	lvar dword, linkinfo_other
    90                              <1> 	lvar word, use_hash_other
    91                              <1>  %endif
    92 00000296 5589E5              <1> 	lenter
    93                              <1> 	lvar dword, instance
    94 00000299 06                  <1> 	 push es
    95 0000029A 52                  <1> 	 push dx		; -> start of where we're loaded in ELD cs
    96                              <1> 	lvar word, targetsection_low_optional_high
    97 0000029B 50                  <1> 	 push ax		; placeholder
    98                              <1> 	lequ ?targetsection_low_optional_high, targetsection
    99                              <1> 	lequ ?targetsection_low_optional_high + 1, optional
   100                              <1> 	lvar dword, linkinfo
   101 0000029C 1E                  <1> 	 push ds
   102 0000029D 57                  <1> 	 push di		; -> link info (in debugger ss or message seg)
   103                              <1> 	lvar dword, nextreloc
   104 0000029E 06                  <1> 	 push es		; => ELD cs
   105 0000029F 52                  <1> 	 push dx		; placeholder
   106                              <1> 	lvar dword, entry
   107 000002A0 06                  <1> 	 push es		; => ELD cs
   108 000002A1 50                  <1> 	 push ax		; placeholder
   109 000002A2 31C0                <1> 	xor ax, ax
   110 000002A4 813DD1E1            <1> 	cmp word [di + eldlSignature], 0E1D1h
   111                              <1> %if ($ - linker) < 16
   112                              <1>  %error Expected invariant first paragraph of linker
   113                              <1> %endif
   114 000002A8 7403                <1> 	je @F
   115                              <1> .error_j1:
   116 000002AA E91403              <1> 	jmp .error		; signature mismatch -->
   117                              <1> @@:
   118 000002AD 837D0601            <1> 	cmp word [di + eldlUseLinkHash], 1
   119 000002B1 77F7                <1> 	ja .error_j1		; unknown use link hash number -->
   120 000002B3 7201                <1> 	jb @F
   121                              <1> %if _ELDDATA_NEXT || _ELDCALL_NEXT
   122                              <1> 	dec al			; = -1 if hash used
   123                              <1> %else
   124 000002B5 48                  <1> 	dec ax
   125                              <1> %endif
   126                              <1> @@:
   127                              <1> 	lvar word, use_hash_low_skip_last_high
   128 000002B6 50                  <1> 	 push ax		; = -1 if hash used, else 0
   129                              <1> 	lequ ?use_hash_low_skip_last_high, use_hash
   130                              <1> 	lequ ?use_hash_low_skip_last_high + 1, skip_last
   131                              <1> %if _ELD_IDENTICALISE && _ELD_LINKER_PASSES
   132                              <1> 	mov ax, linktable - code
   133                              <1> 	lvar word, lt
   134                              <1> 	 push ax		; -> link tables (a single reference)
   135                              <1> %endif
   136                              <1> %if _ELD_LINKER_PASSES || ELDOTHER || _ELDDATA_OPTIONAL || _ELDCALL_OPTIONAL
   137 000002B7 31C0                <1> 	xor ax, ax
   138                              <1>  %if _ELD_LINKER_PASSES
   139                              <1> 	lvar word, pass
   140 000002B9 50                  <1> 	 push ax		; = 0 for linker itself, = 2 for application
   141                              <1> 	lvar word, amounterrors
   142 000002BA 50                  <1> 	 push ax		; how many distinct errors encountered in pass 2
   143                              <1>  %endif
   144                              <1>  %if _ELD_LINKER_PASSES || _ELDDATA_OPTIONAL || _ELDCALL_OPTIONAL
   145                              <1> 	lvar word, name
   146 000002BB 50                  <1> 	 push ax		; -> name currently being sought (in our table)
   147                              <1>  %endif
   148                              <1>  %if ELDOTHER
   149                              <1> 	lvar word, other
   150                              <1> 	 push ax		; byte: 0 = own data links, -1 = other data links
   151                              <1>  %endif
   152                              <1>  %if _ELDDATA_OPTIONAL || _ELDCALL_OPTIONAL
   153                              <1> 	lvar word, optionalmissing
   154 000002BC 50                  <1> 	 push ax
   155                              <1>  %endif
   156                              <1> %endif
   157 000002BD 56                  <1> 	push si			; -> command line tail
   158 000002BE 53                  <1> 	push bx			; -> data block in ELD data area (segment ss)
   159                              <1> 
   160                              <1> 			; simple: add instance base (dx) to code
   161 000002BF 06                  <1> 	push es
   162 000002C0 1F                  <1> 	pop ds			; ds = es => ELD cs
   163                              <1> %if _ELD_LINKER_PASSES
   164                              <1> .pass:
   165 000002C1 8B5EEA              <1> 	mov bx, word [bp + ?pass]	; 0 or 2
   166 000002C4 01D3                <1> 	add bx, dx		; -> start of the ELD instance in cs, +0 or +2
   167                              <1>  %if _ELD_IDENTICALISE
   168                              <1> 	add bx, word [bp + ?lt]	; add in single reference to linktable
   169                              <1> 	mov si, word [ltCodeToCode + bx]
   170                              <1>  %else
   171 000002C6 8BB76C06            <1> 	mov si, word [linktable - code + ltCodeToCode + bx]
   172                              <1>  %endif
   173                              <1> %else
   174                              <1> 	mov si, internalcodetocoderelocations - code
   175                              <1> %endif		 		; si -> table for code to code (linker or app)
   176 000002CA 01D6                <1> 	add si, dx		; relocate the table pointer itself
   177                              <1> @@:
   178 000002CC AD                  <1> 	lodsw
   179 000002CD 85C0                <1> 	test ax, ax		; was last ?
   180 000002CF 740B                <1> 	jz @F			; yes -->
   181 000002D1 93                  <1> 	xchg bx, ax		; bx = entry
   182 000002D2 01D3                <1> 	add bx, dx		; relocate the entry itself
   183                              <1> %if _ELD_CODE_VSTART
   184 000002D4 812F[0000]          <1> 	sub word [bx], code	; undo adjustment
   185                              <1> %endif
   186 000002D8 0117                <1> 	add word [bx], dx	; relocate word referenced by entry
   187 000002DA EBF0                <1> 	jmp @B
   188                              <1> 
   189                              <1> @@:
   190                              <1> 			; next, add heap data base (on stack) to code
   191                              <1> %if _ELD_LINKER_PASSES
   192 000002DC 8B5EEA              <1> 	mov bx, word [bp + ?pass]	; 0 or 2
   193 000002DF 01D3                <1> 	add bx, dx		; -> start of the ELD instance in cs, +0 or +2
   194                              <1>  %if _ELD_IDENTICALISE
   195                              <1> 	add bx, word [bp + ?lt]	; add in single reference to linktable
   196                              <1> 	mov si, word [ltCodeToData + bx]
   197                              <1>  %else
   198 000002E1 8BB77006            <1> 	mov si, word [linktable - code + ltCodeToData + bx]
   199                              <1>  %endif
   200                              <1> %else
   201                              <1> 	mov si, internalcodetodatarelocations - code
   202                              <1> %endif				; si -> table for code to data (linker or app)
   203 000002E5 01D6                <1> 	add si, dx		; relocate the table pointer itself
   204                              <1> @@:
   205 000002E7 AD                  <1> 	lodsw
   206 000002E8 85C0                <1> 	test ax, ax		; was last ?
   207 000002EA 740C                <1> 	jz @F			; yes -->
   208 000002EC 93                  <1> 	xchg bx, ax		; bx = entry
   209 000002ED 01D3                <1> 	add bx, dx		; relocate the entry itself
   210                              <1> 		; ! access the offset of the data area block, topmost on stack
   211 000002EF 58                  <1> 	pop ax			; ax -> heap data
   212 000002F0 50                  <1> 	push ax
   213                              <1> %if _ELD_DATA_VSTART
   214 000002F1 2D[0000]            <1> 	sub ax, datastart	; undo adjustment
   215                              <1> %endif
   216 000002F4 0107                <1> 	add word [bx], ax	; relocate word referenced by entry
   217 000002F6 EBEF                <1> 	jmp @B
   218                              <1> 
   219                              <1> @@:
   220                              <1> 
   221                              <1> 			; add instance base (dx) to data
   222                              <1> %if _ELD_LINKER_PASSES
   223 000002F8 8B5EEA              <1> 	mov bx, word [bp + ?pass]
   224 000002FB 01D3                <1> 	add bx, dx
   225                              <1>  %if _ELD_IDENTICALISE
   226                              <1> 	add bx, word [bp + ?lt]
   227                              <1> 	mov si, word [ltDataToCode + bx]
   228                              <1>  %else
   229 000002FD 8BB77406            <1> 	mov si, word [linktable - code + ltDataToCode + bx]
   230                              <1>  %endif
   231                              <1> %else
   232                              <1> 	mov si, internaldatatocoderelocations - code
   233                              <1> %endif
   234 00000301 01D6                <1> 	add si, dx
   235                              <1> @@:
   236 00000303 AD                  <1> 	lodsw
   237 00000304 83F8FF              <1> 	cmp ax, -1		; was last ?
   238 00000307 740F                <1> 	je @F			; yes -->
   239 00000309 93                  <1> 	xchg bx, ax		; bx = entry
   240                              <1> 		; ! access the offset of the data area block, topmost on stack
   241 0000030A 58                  <1> 	pop ax
   242 0000030B 50                  <1> 	push ax
   243 0000030C 01C3                <1> 	add bx, ax		; relocate the entry itself
   244                              <1> %if _ELD_CODE_VSTART
   245 0000030E 36812F[0000]        <1> 	sub word [ss:bx], code	; undo adjustment
   246                              <1> %endif
   247 00000313 360117              <1> 	add word [ss:bx], dx	; relocate word referenced by entry
   248 00000316 EBEB                <1> 	jmp @B
   249                              <1> 
   250                              <1> @@:
   251                              <1> 			; next, add heap data base (on stack) to data
   252                              <1> %if _ELD_LINKER_PASSES
   253 00000318 8B5EEA              <1> 	mov bx, word [bp + ?pass]
   254 0000031B 01D3                <1> 	add bx, dx
   255                              <1>  %if _ELD_IDENTICALISE
   256                              <1> 	add bx, word [bp + ?lt]
   257                              <1> 	mov si, word [ltDataToData + bx]
   258                              <1>  %else
   259 0000031D 8BB77806            <1> 	mov si, word [linktable - code + ltDataToData + bx]
   260                              <1>  %endif
   261                              <1> %else
   262                              <1> 	mov si, internaldatatodatarelocations - code
   263                              <1> %endif
   264 00000321 01D6                <1> 	add si, dx
   265                              <1> @@:
   266 00000323 AD                  <1> 	lodsw
   267 00000324 83F8FF              <1> 	cmp ax, -1		; was last ?
   268 00000327 740D                <1> 	je @F			; yes -->
   269 00000329 93                  <1> 	xchg bx, ax		; bx = entry
   270                              <1> 		; ! access the offset of the data area block, topmost on stack
   271 0000032A 58                  <1> 	pop ax			; ax -> heap data
   272 0000032B 50                  <1> 	push ax
   273 0000032C 01C3                <1> 	add bx, ax		; relocate the entry itself
   274                              <1> %if _ELD_DATA_VSTART
   275 0000032E 2D[0000]            <1> 	sub ax, datastart	; undo adjustment
   276                              <1> %endif
   277 00000331 360107              <1> 	add word [ss:bx], ax	; relocate word referenced by entry
   278 00000334 EBED                <1> 	jmp @B
   279                              <1> 
   280                              <1> @@:
   281 00000336 8B56FC              <1> 	mov dx, word [bp + ?instance]
   282                              <1> 				; reset (why??) -> ELD instance in ELD cs
   283                              <1> %if _ELD_LINKER_PASSES
   284 00000339 8B5EEA              <1> 	mov bx, word [bp + ?pass]
   285 0000033C 01D3                <1> 	add bx, dx
   286                              <1>  %if _ELD_IDENTICALISE
   287                              <1> 	add bx, word [bp + ?lt]
   288                              <1> 	add dx, word [ltLinkData + bx]
   289                              <1>  %else
   290 0000033E 03977C06            <1> 	add dx, word [linktable - code + ltLinkData + bx]
   291                              <1>  %endif
   292                              <1> %else
   293                              <1> 	add dx, linkerdatarelocations - code
   294                              <1> %endif
   295                              <1> .otherloop:
   296 00000342 8956F2              <1> 	mov word [bp + ?nextreloc], dx
   297                              <1> 				; -> data link relocation table
   298                              <1> 
   299                              <1> .datarelocloop:		; must be done before further relocs
   300 00000345 C576F2              <1> 	lds si, [bp + ?nextreloc]
   301 00000348 AD                  <1> 	lodsw			; ax = section indicator
   302 00000349 85C0                <1> 	test ax, ax		; end of table ?
   303 0000034B 7503E95101          <1> 	jz .donedatareloc
   304 00000350 48                  <1> 	dec ax			; al = 1 if data, 0 if code (NB ah may != 0)
   305                              <1> 		; ! access the offset of the data area block, topmost on stack
   306 00000351 5B                  <1> 	pop bx
   307 00000352 53                  <1> 	push bx			; bx -> ELD data block
   308 00000353 8946FA              <1> 	mov word [bp + ?targetsection_low_optional_high], ax
   309 00000356 84C0                <1> 	test al, al		; data ?
   310 00000358 AD                  <1> 	lodsw
   311 00000359 7504                <1> 	jnz @F			; yes -->
   312 0000035B 0346FC              <1> 	add ax, word [bp + ?instance]
   313                              <1> 				; relocate entry into code
   314 0000035E A9                  <1> 	db __TEST_IMM16		; (skip add)
   315                              <1> @@:
   316 0000035F 01D8                <1> 	add ax, bx		; relocate entry into data
   317 00000361 8946EE              <1> 	mov word [bp + ?entry], ax
   318                              <1> 				; save away -> where to patch
   319 00000364 AD                  <1> 	lodsw			; get unrelocated -> name
   320 00000365 8976F2              <1> 	mov word [bp + ?nextreloc], si
   321                              <1> 				; update -> behind relocation table entry
   322                              <1> %if _ELDDATA_NEXT
   323                              <1> 	rol byte [bp + ?skip_last], 1	; skipping ?
   324                              <1> 	jnc @F				; no -->
   325                              <1> 	test byte [bp + ?optional], 8	; is it a last relocation ?
   326                              <1> 	jz .datarelocloop		; no, leave skip_last set -->
   327                              <1> 	not byte [bp + ?skip_last]	; disable skip_last
   328                              <1> 	jmp .datarelocloop
   329                              <1> @@:
   330                              <1> %endif
   331 00000368 E8FB00              <1> 	call .build_match	; get ax = scan value, si -> counted string,
   332                              <1> 				;  dl = original value at byte [si]
   333                              <1> 				; NC if symbol already not found before
   334                              <1> 				; CY if to search for the symbol
   335                              <1> %if _ELD_LINKER_PASSES
   336 0000036B 73D8                <1> 	jnc .datarelocloop	; if duplicate of a not found symbol -->
   337                              <1> %endif
   338 0000036D C45EF6              <1> 	les bx, [bp + ?linkinfo]
   339                              <1> %if ELDOTHER
   340                              <1> 	rol byte [bp + ?other], 1
   341                              <1> 	jnc @F
   342                              <1> 	les bx, [bp + ?linkinfo_other]
   343                              <1> @@:
   344                              <1> %endif				; es:bx -> link info table of the ELD host
   345 00000370 268B4F08            <1> 	mov cx, word [es:bx + eldlDataAmount]	; amount data link info
   346 00000374 268B7F0A            <1> 	mov di, word [es:bx + eldlDataPrefixes]	; -> prefixes or hashes
   347                              <1> .datarelocfind:
   348 00000378 83F901              <1> 	cmp cx, 1			; NZ if cx == 0
   349 0000037B F2AF                <1> 	repne scasw			; scan initial
   350                              <1> %if _ELDDATA_OPTIONAL
   351 0000037D 7541                <1> 	jne .datanotfound_may_be_optional
   352                              <1> %else
   353                              <1> 	jne .datanotfound
   354                              <1> %endif
   355 0000037F 57                  <1> 	push di
   356 00000380 51                  <1> 	push cx
   357 00000381 56                  <1> 	push si
   358 00000382 262B7F0A            <1> 	sub di, word [es:bx + eldlDataPrefixes]	; = double index, 1-based
   359 00000386 4F                  <1> 	dec di
   360 00000387 4F                  <1> 	dec di				; 0-based
   361 00000388 26037F0C            <1> 	add di, word [es:bx + eldlDataEntries]	; -> entry
   362 0000038C 268B3D              <1> 	mov di, [es:di]			; -> counted suffix/string
   363 0000038F B500                <1> 	mov ch, 0
   364 00000391 8A0C                <1> 	mov cl, byte [si]		; cx = length
   365 00000393 41                  <1> 	inc cx
   366                              <1> 	; cmp al, al			; ZR if length is zero
   367 00000394 F3A6                <1> 	repe cmpsb			; match ?
   368 00000396 5E                  <1> 	pop si
   369 00000397 59                  <1> 	pop cx
   370 00000398 5F                  <1> 	pop di
   371 00000399 75DD                <1> 	jne .datarelocfind		; if not found this time,
   372                              <1> 					;  scan for next initial -->
   373 0000039B 8814                <1> 	mov byte [si], dl		; restore the original byte at counter
   374 0000039D 262B7F0A            <1> 	sub di, word [es:bx + eldlDataPrefixes]	; = double index, 1-based
   375 000003A1 4F                  <1> 	dec di
   376 000003A2 4F                  <1> 	dec di				; 0-based
   377 000003A3 26037F0E            <1> 	add di, word [es:bx + eldlDataAddresses]	; -> address (offset)
   378 000003A7 268B05              <1> 	mov ax, word [es:di]		; get link data from the table
   379 000003AA E80700              <1> 	call .address_data_reloc
   380                              <1> %if _ELD_RELOC_VSTART
   381 000003AD 2D[0000]            <1> 	sub ax, relocateddata		; *not* a relocation
   382                              <1> %endif
   383 000003B0 0104                <1> 	add word [si], ax		; relocate
   384                              <1> %if _ELDDATA_NEXT
   385                              <1> 	test byte [bp + ?optional], 4	; is it a next relocation ?
   386                              <1> 	jz .datarelocloop
   387                              <1> 	mov byte [bp + ?skip_last], -1	; skip subsequent next/last relocs
   388                              <1> %endif
   389 000003B2 EB91                <1> 	jmp .datarelocloop
   390                              <1> 
   391                              <1> .address_data_reloc:
   392 000003B4 C576EE              <1> 	lds si, [bp + ?entry]		; -> entry if in ELD code instance
   393 000003B7 807EFA00            <1> 	cmp byte [bp + ?targetsection], 0
   394                              <1> 					; relocation in code ?
   395 000003BB 7402                <1> 	je @F				; yes -->
   396 000003BD 16                  <1> 	push ss
   397 000003BE 1F                  <1> 	pop ds				; => our ELD data block
   398                              <1> @@:
   399 000003BF C3                  <1> 	retn
   400                              <1> 
   401                              <1> %if _ELDDATA_OPTIONAL
   402                              <1> .datanotfound_may_be_optional:
   403 000003C0 8814                <1> 	mov byte [si], dl		; restore the original byte at counter
   404                              <1> %if _ELDDATA_NEXT
   405                              <1> 	test byte [bp + ?optional], 3	; is it an optional relocation ?
   406                              <1> %else
   407 000003C2 807EFB00            <1> 	cmp byte [bp + ?optional], 0	; is it an optional relocation ?
   408                              <1> %endif
   409                              <1> %if _ELD_DEBUG
   410                              <1> 	jnz @F
   411                              <1>  %ifn _ELD_LINKER_PASSES
   412                              <1> 	mov si, 0			; (invalid link)
   413                              <1> linkdatarelocation internalflags6
   414                              <1> 	test si, si
   415                              <1> 	jz .datanotfound
   416                              <1> 	mov si, 0			; (invalid link)
   417                              <1> linkdatarelocation options7
   418                              <1> 	test si, si
   419                              <1> 	jz .datanotfound
   420                              <1>  %else
   421                              <1> 	cmp byte [bp + ?pass], 0
   422                              <1> 	je .datanotfound
   423                              <1>  %endif
   424                              <1> 	houdini				; (the above conditions are for this)
   425                              <1> 	jmp .datanotfound
   426                              <1> @@:
   427                              <1> %else
   428 000003C6 742E                <1> 	jz .datanotfound		; no, handle as an error -->
   429                              <1> %endif
   430                              <1> 
   431                              <1> %if ELDDATA_PMREQUIRED_STATUS
   432                              <1> 	mov si, relocateddata
   433                              <1> linkdatarelocation build_option_PM
   434                              <1> 	test si, si			; is it a PM build ?
   435                              <1> 	jz @F				; no --> (treat PM required as optional)
   436                              <1> 	test byte [bp + ?optional], 2	; optional status is PM required ?
   437                              <1> 	jnz .datanotfound		; yes, handle as an error -->
   438                              <1> @@:
   439                              <1> %endif
   440                              <1> 
   441                              <1> %if _ELD_LINKER_PASSES
   442                              <1> %if _ELDDATA_OPTIONAL || _ELDCALL_OPTIONAL
   443 000003C8 D046E4              <1> 	rol byte [bp + ?optionalmissing], 1
   444 000003CB 730B                <1> 	jnc .optionaldatamissingmsg
   445 000003CD 8B76E6              <1> 	mov si, [bp + ?name]
   446 000003D0 800C80              <1> 	or byte [si], 80h
   447 000003D3 F656E4              <1> 	not byte [bp + ?optionalmissing]
   448 000003D6 EB15                <1> 	jmp @F
   449                              <1> .optionaldatamissingmsg:
   450                              <1> %endif
   451 000003D8 36F606[0000]02      <1> 	testopt [ss:relocateddata], 2	; debug optional link ?
   452                              <1> linkdatarelocation options7, -3
   453 000003DE 740D                <1> 	jz @F				; no -->
   454                              <1> %if _ELDDATA_OPTIONAL || _ELDCALL_OPTIONAL
   455 000003E0 C646E5FF            <1> 	mov byte [bp + ?optionalmissing + 1], -1
   456                              <1> %endif
   457 000003E4 BE[8A09]            <1> 	mov si, lmsg.warning_data_optional
   458                              <1> internalcoderelocation
   459 000003E7 E82B00              <1> 	call .notfound			; display a warning
   460                              <1> %if _ELDDATA_OPTIONAL || _ELDCALL_OPTIONAL
   461 000003EA F656E5              <1> 	not byte [bp + ?optionalmissing + 1]
   462                              <1> %endif
   463                              <1> @@:
   464                              <1> %endif
   465                              <1> %if _ELDDATA_NEXT
   466                              <1> 	test byte [bp + ?optional], 4	; is it a next relocation ?
   467                              <1> 	jnz .datarelocloop
   468                              <1> %endif
   469 000003ED E8C4FF              <1> 	call .address_data_reloc
   470 000003F0 832400              <1> 	and word [si], 0		; indicate optional data link failed
   471 000003F3 E94FFF              <1> 	jmp .datarelocloop
   472                              <1> %endif
   473                              <1> 
   474                              <1> 
   475                              <1> %if _ELDCALL_OPTIONAL
   476                              <1> .codenotfound_may_be_optional:
   477                              <1> 	mov byte [si], dl		; restore the original byte at counter
   478                              <1> %if _ELDCALL_NEXT
   479                              <1> 	test byte [bp + ?optional], 3	; is it an optional relocation ?
   480                              <1> %else
   481                              <1> 	cmp byte [bp + ?optional], 0	; is it an optional relocation ?
   482                              <1> %endif
   483                              <1> %if _ELD_DEBUG
   484                              <1> 	jnz @F
   485                              <1>  %ifn _ELD_LINKER_PASSES
   486                              <1> 	mov si, 0			; (invalid link)
   487                              <1> linkdatarelocation internalflags6
   488                              <1> 	test si, si
   489                              <1> 	jz .codenotfound
   490                              <1> 	mov si, 0			; (invalid link)
   491                              <1> linkdatarelocation options7
   492                              <1> 	test si, si
   493                              <1> 	jz .codenotfound
   494                              <1>  %else
   495                              <1> 	cmp byte [bp + ?pass], 0
   496                              <1> 	je .codenotfound
   497                              <1>  %endif
   498                              <1> 	houdini				; (the above conditions are for this)
   499                              <1> 	jmp .codenotfound
   500                              <1> @@:
   501                              <1> %else
   502                              <1> 	jz .codenotfound		; no, handle as an error -->
   503                              <1> %endif
   504                              <1> 
   505                              <1> %if ELDCALL_PMREQUIRED_STATUS
   506                              <1>  %if _ELD_LINKER_PASSES
   507                              <1>   %assign ELDLINKER 0
   508                              <1>  %endif
   509                              <1> 	mov si, relocateddata
   510                              <1> linkdatarelocation build_option_PM
   511                              <1>  %if _ELD_LINKER_PASSES
   512                              <1>   %assign ELDLINKER 1
   513                              <1>  %endif
   514                              <1> 	test si, si			; is it a PM build ?
   515                              <1> 	jz @F				; no --> (treat PM required as optional)
   516                              <1> 	test byte [bp + ?optional], 2	; optional status is PM required ?
   517                              <1> 	jnz .codenotfound		; yes, handle as an error -->
   518                              <1> @@:
   519                              <1> %endif
   520                              <1> 
   521                              <1> %if _ELD_LINKER_PASSES
   522                              <1> %if _ELDDATA_OPTIONAL || _ELDCALL_OPTIONAL
   523                              <1> 	rol byte [bp + ?optionalmissing], 1
   524                              <1> 	jnc .optionalcodemissingmsg
   525                              <1> 	mov si, [bp + ?name]
   526                              <1> 	or byte [si], 80h
   527                              <1> 	not byte [bp + ?optionalmissing]
   528                              <1> 	jmp @F
   529                              <1> .optionalcodemissingmsg:
   530                              <1> %endif
   531                              <1> 	testopt [ss:relocateddata], 2	; debug optional link ?
   532                              <1> linkdatarelocation options7, -3
   533                              <1> 	jz @F				; no -->
   534                              <1> %if _ELDDATA_OPTIONAL || _ELDCALL_OPTIONAL
   535                              <1> 	mov byte [bp + ?optionalmissing + 1], -1
   536                              <1> %endif
   537                              <1> 	mov si, lmsg.warning_code_optional
   538                              <1> internalcoderelocation
   539                              <1> 	call .notfound			; display a warning
   540                              <1> %if _ELDDATA_OPTIONAL || _ELDCALL_OPTIONAL
   541                              <1> 	not byte [bp + ?optionalmissing + 1]
   542                              <1> %endif
   543                              <1> @@:
   544                              <1> %endif
   545                              <1> %if _ELDCALL_NEXT
   546                              <1> 	test byte [bp + ?optional], 4	; is it a next relocation ?
   547                              <1> 	jnz .coderelocloop
   548                              <1> %endif
   549                              <1> 	lds si, [bp + ?entry]		; -> code site (must be in ELD cs)
   550                              <1> 	mov word [si], 9090h
   551                              <1> 	mov byte [si + 2], 90h		; indicate optional code link failed
   552                              <1> 					;  (NOP out the 3-byte call near imm)
   553                              <1> 	jmp .coderelocloop
   554                              <1> %endif
   555                              <1> 
   556                              <1> 
   557                              <1> %if _ELD_LINKER_PASSES
   558                              <1> .datanotfound:
   559 000003F6 BE[AC09]            <1> 	mov si, lmsg.error_data
   560                              <1> internalcoderelocation
   561 000003F9 E81900              <1> 	call .notfound			; display error
   562 000003FC 7306                <1> 	jnc .error_j3			; NC if in pass 0, error out now -->
   563 000003FE FF46E8              <1> 	inc word [bp + ?amounterrors]	; count the amount of errors
   564 00000401 E941FF              <1> 	jmp .datarelocloop		; go to next relocation entry -->
   565                              <1> 
   566                              <1> .error_j3:
   567 00000404 E9BA01              <1> 	jmp .error
   568                              <1> 
   569                              <1> .codenotfound:
   570 00000407 BE[C509]            <1> 	mov si, lmsg.error_code
   571                              <1> internalcoderelocation
   572 0000040A E80800              <1> 	call .notfound			; display error
   573 0000040D 73F5                <1> 	jnc .error_j3			; NC if in pass 0 -->
   574 0000040F FF46E8              <1> 	inc word [bp + ?amounterrors]	; count the amount of errors
   575 00000412 E99B00              <1> 	jmp .coderelocloop		; go to next -->
   576                              <1> 
   577                              <1> .notfound:
   578 00000415 807EEA00            <1> 	cmp byte [bp + ?pass], 0	; pass 0 ?
   579 00000419 7442                <1> 	je .notfound.retn		; yes, do not try displaying --> (NC)
   580 0000041B 16                  <1> 	 push ss
   581 0000041C 07                  <1> 	 pop es
   582 0000041D BF[0000]            <1> 	mov di, relocateddata
   583                              <1> linkdatarelocation line_out		; es:di -> line_out buffer
   584 00000420 E83B00              <1> 	call .copy			; copy prefix message
   585 00000423 8B76E6              <1> 	mov si, word [bp + ?name]
   586 00000426 AD                  <1> 	lodsw				; = hash
   587 00000427 E8[0000]EB020000    <1> 	extcall hexword			; display the hash in hex
   588 0000042E 56                  <1> 	push si
   589 0000042F BE[DE09]            <1> 	mov si, lmsg.error.2
   590                              <1> internalcoderelocation
   591 00000432 E82900              <1> 	call .copy			; display message fragment
   592 00000435 5E                  <1> 	pop si
   593                              <1> %if _ELD_LINKER_PASSES
   594 00000436 56                  <1> 	push si
   595 00000437 E82400              <1> 	call .copy			; copy over the full name
   596 0000043A 5E                  <1> 	pop si
   597                              <1>  %if _ELDDATA_OPTIONAL || _ELDCALL_OPTIONAL
   598 0000043B 800C80              <1> 	or byte [si], 80h		; mark as failed optional link
   599 0000043E D046E5              <1> 	rol byte [bp + ?optionalmissing + 1], 1
   600                              <1> 					; was it optional ?
   601 00000441 7203                <1> 	jc @F				; yes -->
   602                              <1>  %endif
   603 00000443 C60400              <1> 	mov byte [si], 0		; mark as failed (counter byte = 0)
   604                              <1> @@:
   605                              <1> %else
   606                              <1> 	call .copy
   607                              <1> %endif
   608 00000446 B022                <1> 	mov al, '"'
   609 00000448 AA                  <1> 	stosb				; end message with a closing quote mark
   610 00000449 16                  <1> 	 push ss
   611 0000044A 1F                  <1> 	 pop ds
   612 0000044B E8[0000]EB020000    <1> 	extcall putsline_crlf		; display diagnostic line
   613 00000452 B8350E              <1> 	mov ax, 0E35h
   614 00000455 E8[0000]EB020000    <1> 	extcall setrc
   615 0000045C F9                  <1> 	stc				; CY, diagnostic displayed
   616                              <1> .notfound.retn:
   617 0000045D C3                  <1> 	retn
   618                              <1> 
   619                              <1> .copy:		; (cannot use extcallcall here)
   620 0000045E E8[0000]EB020000    <1> 	extcall copy_single_counted_string
   621 00000465 C3                  <1> 	retn
   622                              <1> %else
   623                              <1> .datanotfound: equ .error
   624                              <1> .codenotfound: equ .error
   625                              <1> %endif
   626                              <1> 
   627                              <1> .build_match:
   628                              <1> %if _ELDDATA_OPTIONAL || _ELDCALL_OPTIONAL
   629 00000466 C646E400            <1> 	mov byte [bp + ?optionalmissing], 0
   630                              <1> 		; This is needed for eldtestj.asm with debugoptlink.
   631                              <1> 		;  The optional data link sets flag 80h, then the
   632                              <1> 		;  required data link to the same symbol sets this
   633                              <1> 		;  flag but doesn't reset it. So the first optional
   634                              <1> 		;  code link still had this set. Reset here to fix.
   635                              <1> %endif
   636                              <1> %if _ELD_CODE_VSTART
   637 0000046A 2D[0000]            <1> 	sub ax, code			; revert adjustment (= displacement)
   638                              <1> %endif
   639 0000046D 0346FC              <1> 	add ax, word [bp + ?instance]	; make displacement into -> name string
   640 00000470 96                  <1> 	xchg si, ax			; si -> hash word, counted name string
   641                              <1> %if _ELD_LINKER_PASSES || _ELDDATA_OPTIONAL || _ELDCALL_OPTIONAL
   642 00000471 8976E6              <1> 	mov word [bp + ?name], si	; save away for diagnostics
   643                              <1> %endif
   644 00000474 AD                  <1> 	lodsw			; = hash, si -> counted string
   645 00000475 8A14                <1> 	mov dl, byte [si]	; dl = original start byte of match
   646                              <1> %if _ELD_LINKER_PASSES
   647 00000477 84D2                <1> 	test dl, dl		; marked as already failed ?
   648                              <1> 				;  (80h = optional, 0 = required)
   649 00000479 750A                <1> 	jnz @F			; no -->
   650 0000047B 837EE800            <1> 	cmp word [bp + ?amounterrors], 0
   651                              <1> 				; validate error status
   652 0000047F 7503E9B000          <1> 	je .error_j		; no error known ?! cancel quickly -->
   653 00000484 C3                  <1> 	retn			; (NC)
   654                              <1> 
   655                              <1> @@:
   656                              <1> %else
   657                              <1> 	test dl, dl
   658                              <1> %endif
   659                              <1> %if _ELDDATA_OPTIONAL || _ELDCALL_OPTIONAL
   660 00000485 7909                <1> 	jns @F
   661 00000487 80E27F              <1> 	and dl, 7Fh
   662 0000048A 8814                <1> 	mov byte [si], dl
   663 0000048C C646E4FF            <1> 	mov byte [bp + ?optionalmissing], -1
   664                              <1> @@:
   665                              <1> %endif
   666                              <1> %if ELDOTHER
   667                              <1> 	rol byte [bp + ?other], 1
   668                              <1> 	jnc @F
   669                              <1> 	rol byte [bp + ?use_hash_other], 1
   670                              <1> 	jmp @FF
   671                              <1> 
   672                              <1> @@:
   673                              <1> %endif
   674 00000490 D046EC              <1> 	rol byte [bp + ?use_hash], 1
   675                              <1> @@:
   676                              <1> 		; If to use the hash, then ax = hash and si ->
   677                              <1> 		;  the entire symbol name as a counted string.
   678 00000493 720A                <1> 	jc @F			; if to use hash, return now -->
   679 00000495 AC                  <1> 	lodsb			; al = length
   680 00000496 91                  <1> 	xchg cx, ax		; cl = length
   681 00000497 AD                  <1> 	lodsw			; ax = prefix
   682 00000498 49                  <1> 	dec cx
   683 00000499 49                  <1> 	dec cx			; cl = adjusted length
   684 0000049A 4E                  <1> 	dec si			; -> second byte of prefix
   685 0000049B 8A14                <1> 	mov dl, byte [si]	; dl = original start byte of match
   686 0000049D 880C                <1> 	mov byte [si], cl	; si -> counted string suffix
   687                              <1> 		; (this name entry has been edited to provide the
   688                              <1> 		;  name suffix as a counted string, as required by
   689                              <1> 		;  the old-style non-hash link info tables.
   690                              <1> 		; it will be reset later by writing dl to si -> the
   691                              <1> 		;  first byte of the match string.)
   692                              <1> @@:
   693                              <1> %if _ELD_LINKER_PASSES
   694 0000049F F9                  <1> 	stc			; CY
   695                              <1> %endif
   696 000004A0 C3                  <1> 	retn
   697                              <1> 
   698                              <1> 
   699                              <1> .donedatareloc:
   700                              <1> %if ELDOTHER
   701                              <1> 	rol byte [bp + ?other], 1
   702                              <1> 	jc .otherdone		; other link only has data links,
   703                              <1> 				;  so at this point we're done -->
   704                              <1> %endif
   705                              <1> 
   706 000004A1 8B56FC              <1> 	mov dx, word [bp + ?instance]
   707                              <1> %if _ELD_LINKER_PASSES
   708 000004A4 8B5EEA              <1> 	mov bx, word [bp + ?pass]
   709 000004A7 01D3                <1> 	add bx, dx
   710                              <1>  %if _ELD_IDENTICALISE
   711                              <1> 	add bx, word [bp + ?lt]
   712                              <1> 	add dx, word [ltLinkCode + bx]
   713                              <1>  %else
   714 000004A9 03978006            <1> 	add dx, word [linktable - code + ltLinkCode + bx]
   715                              <1>  %endif
   716                              <1> %else
   717                              <1> 	add dx, linkercoderelocations - code
   718                              <1> %endif
   719 000004AD 8956F2              <1> 	mov word [bp + ?nextreloc], dx
   720                              <1> 
   721                              <1> .coderelocloop:
   722 000004B0 C576F2              <1> 	lds si, [bp + ?nextreloc]
   723 000004B3 AD                  <1> 	lodsw
   724                              <1> %if _ELDCALL_OPTIONAL || _ELDCALL_NEXT
   725                              <1> 	dec ax				; optional word is 1-based, get 0-based
   726                              <1> 	js .donecodereloc
   727                              <1> 	mov word [bp + ?targetsection_low_optional_high], ax
   728                              <1> 	lodsw
   729                              <1> %endif
   730 000004B4 0346FC              <1> 	add ax, word [bp + ?instance]
   731 000004B7 8946EE              <1> 	mov word [bp + ?entry], ax
   732 000004BA AD                  <1> 	lodsw
   733 000004BB 8976F2              <1> 	mov word [bp + ?nextreloc], si
   734                              <1> %ifn _ELDCALL_OPTIONAL || _ELDCALL_NEXT
   735 000004BE 85C0                <1> 	test ax, ax			; if no optional word, check -> match
   736 000004C0 7503E98100          <1> 	jz .donecodereloc
   737                              <1> %endif
   738                              <1> %if _ELDCALL_NEXT
   739                              <1> 	rol byte [bp + ?skip_last], 1	; skipping ?
   740                              <1> 	jnc @F				; no -->
   741                              <1> 	test byte [bp + ?optional], 8	; is it a last relocation ?
   742                              <1> 	jz .coderelocloop		; no, leave skip_last set -->
   743                              <1> 	not byte [bp + ?skip_last]	; disable skip_last
   744                              <1> 	jmp .coderelocloop
   745                              <1> @@:
   746                              <1> %endif
   747 000004C5 E89EFF              <1> 	call .build_match
   748                              <1> %if _ELD_LINKER_PASSES
   749 000004C8 73E6                <1> 	jnc .coderelocloop
   750                              <1> %endif
   751 000004CA C45EF6              <1> 	les bx, [bp + ?linkinfo]
   752 000004CD 268B4F10            <1> 	mov cx, word [es:bx + eldlCodeAmount]	; amount code link info
   753 000004D1 268B7F12            <1> 	mov di, word [es:bx + eldlCodePrefixes]	; -> prefixes or hashes
   754                              <1> .coderelocfind:
   755 000004D5 83F901              <1> 	cmp cx, 1			; NZ if cx == 0
   756 000004D8 F2AF                <1> 	repne scasw			; scan initial
   757                              <1> %if _ELDCALL_OPTIONAL
   758                              <1> 	jne .codenotfound_may_be_optional
   759                              <1> %else
   760                              <1>  %if _ELD_DEBUG
   761                              <1> 	je @F
   762                              <1> 	houdini
   763                              <1> 	jmp .codenotfound
   764                              <1> @@:
   765                              <1>  %else
   766 000004DA 7403E928FF          <1> 	jne .codenotfound
   767                              <1>  %endif
   768                              <1> %endif
   769 000004DF 57                  <1> 	push di
   770 000004E0 51                  <1> 	push cx
   771 000004E1 56                  <1> 	push si
   772 000004E2 262B7F12            <1> 	sub di, word [es:bx + eldlCodePrefixes]	; = double index, 1-based
   773 000004E6 4F                  <1> 	dec di
   774 000004E7 4F                  <1> 	dec di				; 0-based
   775 000004E8 26037F14            <1> 	add di, word [es:bx + eldlCodeEntries]	; -> entry
   776 000004EC 268B3D              <1> 	mov di, [es:di]			; -> counted suffix/string
   777 000004EF B500                <1> 	mov ch, 0
   778 000004F1 8A0C                <1> 	mov cl, byte [si]		; cx = length
   779 000004F3 41                  <1> 	inc cx
   780                              <1> 	; cmp al, al			; ZR if length is zero
   781 000004F4 F3A6                <1> 	repe cmpsb			; match ?
   782 000004F6 5E                  <1> 	pop si
   783 000004F7 59                  <1> 	pop cx
   784 000004F8 5F                  <1> 	pop di
   785 000004F9 75DA                <1> 	jne .coderelocfind
   786 000004FB 8814                <1> 	mov byte [si], dl
   787 000004FD 262B7F12            <1> 	sub di, word [es:bx + eldlCodePrefixes]	; = double index, 1-based
   788 00000501 4F                  <1> 	dec di
   789 00000502 4F                  <1> 	dec di				; 0-based
   790 00000503 01FF                <1> 	add di, di			; quadruple index
   791 00000505 26037F16            <1> 	add di, word [es:bx + eldlCodeAddresses]	; -> address (offset, segment)
   792 00000509 26FF35              <1> 	push word [es:di]
   793 0000050C C576EE              <1> 	lds si, [bp + ?entry]
   794 0000050F 8F4405              <1> 	pop word [si + 3 + 2]		; call near imm (3), jmp short (2)
   795                              <1> 					;  patch the destination address
   796 00000512 803CE8              <1> 	cmp byte [si], 0E8h		; is it as expected ?
   797 00000515 751D                <1> 	jne .error_j
   798 00000517 268B7D02            <1> 	mov di, word [es:di + 2]
   799 0000051B BB[0000]            <1> 	mov bx, relocateddata
   800                              <1> linkdatarelocation linkcall_table	; ss:bx -> link call table
   801 0000051E 36833F01            <1> 	cmp word [ss:bx], 1		; is it initialised to format 1 ?
   802 00000522 7510                <1> 	jne .error_j			; no -->
   803 00000524 368B4F02            <1> 	mov cx, word [ss:bx + 2]	; get amount of segments
   804 00000528 E30A                <1> 	jcxz .error_j			; none -->
   805                              <1> @@:
   806 0000052A 83C304              <1> 	add bx, 4			; -> next segment
   807 0000052D 36393F              <1> 	cmp word [ss:bx], di		; value matches ?
   808 00000530 7405                <1> 	je @F				; yes, found -->
   809 00000532 E2F6                <1> 	loop @B				; try remaining segments
   810                              <1> .error_j:
   811 00000534 E98A00              <1> 	jmp .error
   812                              <1> 
   813                              <1> @@:
   814 00000537 368B5F02            <1> 	mov bx, word [ss:bx + 2]	; -> call destination offset
   815                              <1> 		; si + 3 + delta = bx
   816                              <1> 		; delta = bx - si - 3
   817 0000053B 29F3                <1> 	sub bx, si
   818 0000053D 83EB03              <1> 	sub bx, 3
   819 00000540 895C01              <1> 	mov word [si + 1], bx		; patch the call instruction
   820                              <1> %if _ELDCALL_NEXT
   821                              <1> 	test byte [bp + ?optional], 4	; is it a next relocation ?
   822                              <1> 	jz .coderelocloop
   823                              <1> 	mov byte [bp + ?skip_last], -1	; skip subsequent next/last relocs
   824                              <1> %endif
   825 00000543 E96AFF              <1> 	jmp .coderelocloop
   826                              <1> 
   827                              <1> .donecodereloc:
   828                              <1> %if _ELD_LINKER_PASSES
   829 00000546 8B46E8              <1> 	mov ax, word [bp + ?amounterrors]
   830 00000549 85C0                <1> 	test ax, ax
   831 0000054B 75E7                <1> 	jnz .error_j
   832 0000054D 8B5EEA              <1> 	mov bx, word [bp + ?pass]
   833 00000550 85DB                <1> 	test bx, bx
   834 00000552 750B                <1> 	jnz @F
   835 00000554 43                  <1> 	inc bx
   836 00000555 43                  <1> 	inc bx
   837 00000556 895EEA              <1> 	mov word [bp + ?pass], bx
   838 00000559 8B56FC              <1> 	mov dx, word [bp + ?instance]
   839 0000055C E962FD              <1> 	jmp .pass
   840                              <1> 
   841                              <1> @@:
   842                              <1> %endif
   843                              <1> 
   844                              <1> %ifnidni _LISTING, ""
   845                              <1> %assign ELDLINKER 0
   846                              <1> .hint:
   847 0000055F 16                  <1> 	push ss
   848 00000560 1F                  <1> 	pop ds
   849 00000561 B02D                <1> 	mov al, 2Dh
   850 00000563 E8[0000]EB020000    <1> 	extcall intchk			; ZR if offset = -1 or segment = 0
   851                              <1> 					; CHG: ax, dx, bx
   852 0000056A 7437                <1> 	jz .no_hint
   853                              <1> 
   854                              <1> %if ELDOTHER
   855                              <1> 	mov si, debuggeramissig	; ds:si -> our AMIS name strings
   856                              <1> internalcoderelocation
   857                              <1> %endif
   858                              <1> 
   859 0000056C 8A26[0000]          <1> 	mov ah, byte [relocateddata]
   860                              <1> linkdatarelocation try_debugger_amis_multiplex_number
   861 00000570 E85500              <1> 	call plex_check
   862 00000573 7305                <1> 	jnc @F
   863                              <1> 
   864 00000575 B4FF                <1> 	mov ah, 0FFh		; start with multiplex number 0FFh
   865                              <1> .loop_hint:
   866 00000577 E84E00              <1> 	call plex_check
   867                              <1> @@:
   868 0000057A 7307                <1> 	jnc .end_hint		; if found --> (NC)
   869 0000057C 80EC01              <1> 	sub ah, 1		; search is backward (to find latest installed first), from 0FFh to 00h including
   870 0000057F 73F6                <1> 	jnc .loop_hint		; try next if we didn't check all yet -->
   871 00000581 EB20                <1> 	jmp .no_hint
   872                              <1> 
   873                              <1> .end_hint:
   874 00000583 50                  <1> 	push ax
   875 00000584 C446FC              <1> 	les ax, [bp + ?instance]
   876 00000587 BF[BE07]            <1> 	mov di, listmsg.hint.offset
   877                              <1> internalcoderelocation
   878 0000058A E8[0000]EB020000    <1> 	extcall hexword
   879 00000591 BB[9E07]            <1> 	mov bx, listmsg.hint
   880                              <1> internalcoderelocation
   881 00000594 368B16[0000]        <1> 	mov dx, [ss:relocateddata]
   882                              <1> linkdatarelocation extseg	; must be 86 Mode segment even in PM
   883 00000599 58                  <1> 	pop ax
   884 0000059A B040                <1> 	mov al, 40h		; AMIS message display service
   885 0000059C E8[0000]EB020000    <1> 	extcall call_int2D
   886                              <1> .no_hint:
   887                              <1> %endif
   888                              <1> 
   889                              <1> %if ELDOTHER
   890                              <1> %assign ELDLINKER 0
   891                              <1> 	not byte [bp + ?other]
   892                              <1> 
   893                              <1> 	push ss
   894                              <1> 	pop ds
   895                              <1> 	mov al, 2Dh
   896                              <1> 	extcall intchk			; ZR if offset = -1 or segment = 0
   897                              <1> 					; CHG: ax, dx, bx
   898                              <1> 	jz .no_other
   899                              <1> 
   900                              <1> 	mov si, debuggeramissig	; ds:si -> our AMIS name strings
   901                              <1> internalcoderelocation
   902                              <1> 
   903                              <1> 	mov ah, byte [relocateddata]
   904                              <1> linkdatarelocation try_debugger_amis_multiplex_number
   905                              <1> 	call plex_check
   906                              <1> 	jnc @F
   907                              <1> 
   908                              <1> 	mov ah, 0FFh		; start with multiplex number 0FFh
   909                              <1> .loop_other_debug:
   910                              <1> 	call plex_check
   911                              <1> @@:
   912                              <1> 	jnc .end_other		; if found --> (NC)
   913                              <1> 	sub ah, 1		; search is backward (to find latest installed first), from 0FFh to 00h including
   914                              <1> 	jnc .loop_other_debug	; try next if we didn't check all yet -->
   915                              <1> 
   916                              <1> 	mov si, loaderamissig	; ds:si -> our AMIS name strings
   917                              <1> internalcoderelocation
   918                              <1> 
   919                              <1> 	mov ah, byte [relocateddata]
   920                              <1> linkdatarelocation try_debugger_amis_multiplex_number
   921                              <1> 	call plex_check
   922                              <1> 	jnc @F
   923                              <1> 
   924                              <1> 	mov ah, 0FFh		; start with multiplex number 0FFh
   925                              <1> .loop_other_loader:
   926                              <1> 	call plex_check
   927                              <1> @@:
   928                              <1> 	jnc .end_other		; if found --> (NC)
   929                              <1> 	sub ah, 1		; search is backward (to find latest installed first), from 0FFh to 00h including
   930                              <1> 	jnc .loop_other_loader	; try next if we didn't check all yet -->
   931                              <1> 
   932                              <1> 	jmp .no_other
   933                              <1> 
   934                              <1> .end_other:
   935                              <1> 	mov al, 42h		; AMIS get other link info service
   936                              <1> 	extcall call_int2D
   937                              <1> 	cmp al, 0FFh
   938                              <1> 	jne .no_other
   939                              <1> 
   940                              <1> 	mov ax, si		; selector => PSP
   941                              <1> 	extcall ispm
   942                              <1> 	jz @F
   943                              <1> 	mov ax, dx		; segment => PSP
   944                              <1> @@:
   945                              <1> 	 push ss
   946                              <1> 	 pop ds
   947                              <1> 	mov word [otherds], ax
   948                              <1> internaldatarelocation		; current mode sel/seg
   949                              <1> 	mov word [otherseg], dx
   950                              <1> internaldatarelocation		; remember segment
   951                              <1> 
   952                              <1> 	mov ax, cx		; selector => link info
   953                              <1> 	extcall ispm
   954                              <1> 	jz @F
   955                              <1> 	mov ax, bx		; segment => link info
   956                              <1> @@:
   957                              <1> 	mov word [bp + ?linkinfo_other], di
   958                              <1> 	mov word [bp + ?linkinfo_other + 2], ax
   959                              <1> 
   960                              <1> 	mov ds, ax		; => link info
   961                              <1> 	xor ax, ax
   962                              <1> 	cmp word [di + eldlSignature], 0E1D1h
   963                              <1> 	jne .error_other
   964                              <1> 	cmp word [di + eldlUseLinkHash], 1
   965                              <1> 	ja .error_other
   966                              <1> 	jb @F
   967                              <1> 	dec ax
   968                              <1> @@:
   969                              <1> 	mov word [bp + ?use_hash_other], ax
   970                              <1> 
   971                              <1> 	mov dx, word [bp + ?instance]
   972                              <1> 	add dx, linkerotherdatarelocations - code
   973                              <1> 	jmp .otherloop
   974                              <1> 
   975                              <1> .error_other:
   976                              <1> 	push cs
   977                              <1> 	pop ds
   978                              <1> 	mov ax, 0E33h
   979                              <1> 	extcall setrc
   980                              <1> 	mov dx, lmsg.error_other
   981                              <1> internalcoderelocation
   982                              <1> 	jmp @F
   983                              <1> 
   984                              <1> .no_other:
   985                              <1> 	push cs
   986                              <1> 	pop ds
   987                              <1> 	mov ax, 0E34h
   988                              <1> 	extcall setrc
   989                              <1> 	mov dx, lmsg.no_other
   990                              <1> internalcoderelocation
   991                              <1> @@:
   992                              <1> 	extcall putsz
   993                              <1> .error_j2:
   994                              <1> 	jmp .error
   995                              <1> 
   996                              <1> .otherdone:
   997                              <1>  %if _ELD_LINKER_PASSES
   998                              <1> 	mov ax, word [bp + ?amounterrors]
   999                              <1> 	test ax, ax
  1000                              <1> 	jnz .error_j2
  1001                              <1>  %endif
  1002                              <1> %endif
  1003                              <1> 
  1004 000005A3 5B                  <1> 	pop bx				; -> our heap data
  1005 000005A4 5E                  <1> 	pop si				; -> our command line tail
  1006 000005A5 16                  <1> 	 push ss
  1007 000005A6 1F                  <1> 	 pop ds
  1008 000005A7 C47EFC              <1> 	les di, [bp + ?instance]
  1009 000005AA 268B4502            <1> 	mov ax, word [es:di + eldiEndCode]
  1010                              <1> houdini
  1011 000005AE 2D[A002]            <1> 	sub ax, strict word endresident + code
  1012                              <1> internalcoderelocation
  1013 000005B1 26C74502[A002]      <1> 	mov word [es:di + eldiEndCode], endresident + code
  1014                              <1> internalcoderelocation
  1015 000005B7 2906[0000]          <1> 	sub word [relocateddata], ax
  1016                              <1> linkdatarelocation extseg_used
  1017                              <1> %if _DATA_SIZE == 0
  1018                              <1> 	xor ax, ax
  1019                              <1> 	mov word [es:di + eldiStartData], ax
  1020                              <1> 	mov word [es:di + eldiEndData], ax
  1021                              <1> %endif
  1022 000005BB 89EC5D              <1> 	lleave code
  1023                              <1> 		; INP:	es => ELD code segment
  1024                              <1> 		;	ds:si -> command line tail
  1025                              <1> 		;	ds:bx -> ELD data block
  1026                              <1> 		;	ss:sp -> far return address for current mode
  1027                              <1> 		; STT:	ds = ss, UP, EI
  1028 000005BE E92FFC              <1> 	jmp start
  1029                              <1> 
  1030                              <1> .error:
  1031 000005C1 89EC5D              <1> 	lleave
  1032 000005C4 B8FFFF              <1> 	mov ax, -1
  1033 000005C7 CB                  <1> 	retf
  1034                              <1> 
  1035                              <1> 
  1036                              <1> %ifnidni _LISTING, ""
  1037                              <1>  %assign ELDHINT 1
  1038                              <1> %else
  1039                              <1>  %assign ELDHINT 0
  1040                              <1> %endif
  1041                              <1> 
  1042                              <1> %if ELDOTHER || ELDHINT
  1043                              <1> 		; INP:	ah = multiplex number to check
  1044                              <1> 		;	(if ELDOTHER:)
  1045                              <1> 		;	 cs:si -> 16-byte AMIS signature to check
  1046                              <1> 		; OUT:	CY if multiplex number unused or no signature match,
  1047                              <1> 		;	 bp, ah, ds unmodified
  1048                              <1> 		;	NC if match found,
  1049                              <1> 		;	 ah = multiplex number (unmodified)
  1050                              <1> 		; CHG:	di, es, cx, dx
  1051                              <1> 		;	(if ELDOTHER:) bx
  1052                              <1> 		;	(if not ELDOTHER:) si
  1053                              <1> plex_check:
  1054 000005C8 16                  <1> 	push ss
  1055 000005C9 1F                  <1> 	pop ds
  1056 000005CA F606[0000]08        <1> 	testopt [relocateddata], 8
  1057                              <1> linkdatarelocation internalflags4, -3
  1058 000005CF 740B                <1> 	jz @F
  1059                              <1> %if ELDOTHER
  1060                              <1> 	mov bx, relocateddata
  1061                              <1> linkdatarelocation amis_multiplex_number, -2, optional
  1062                              <1> 	test bx, bx
  1063                              <1> 	jz @F
  1064                              <1> 	cmp ah, byte [bx]
  1065                              <1> 	je .notfound		; do not use our own multiplexer -->
  1066                              <1> %else
  1067 000005D1 BE[0000]            <1> 	mov si, relocateddata
  1068                              <1> linkdatarelocation amis_multiplex_number, -2, optional
  1069 000005D4 85F6                <1> 	test si, si
  1070 000005D6 7404                <1> 	jz @F
  1071 000005D8 3A24                <1> 	cmp ah, byte [si]
  1072 000005DA 7420                <1> 	je .notfound		; do not use our own multiplexer -->
  1073                              <1> %endif
  1074                              <1> @@:
  1075 000005DC B000                <1> 	mov al, 00h		; AMIS installation check
  1076 000005DE E8[0000]EB020000    <1> 	extcall call_int2D	; AMIS (or "DOS reserved" = iret if no AMIS present)
  1077 000005E5 3CFF                <1> 	cmp al, 0FFh
  1078 000005E7 7513                <1> 	jne .notfound
  1079 000005E9 0E                  <1> 	push cs
  1080 000005EA 1F                  <1> 	pop ds
  1081                              <1> %if ELDOTHER
  1082                              <1> 	push si
  1083                              <1> 	extcall setes2dx	; es:di -> name strings of AMIS multiplexer that just answered
  1084                              <1> 	mov cx, 8		; Ignore description, only compare vendor and program name
  1085                              <1> 	repe cmpsw
  1086                              <1> 	pop si
  1087                              <1> %else
  1088 000005EB BE[8E07]            <1> 	mov si, debuggeramissig	; ds:si -> our AMIS name strings
  1089                              <1> internalcoderelocation
  1090 000005EE E8[0000]EB020000    <1> 	extcall setes2dx	; es:di -> name strings of AMIS multiplexer that just answered
  1091 000005F5 B90800              <1> 	mov cx, 8		; Ignore description, only compare vendor and program name
  1092 000005F8 F3A7                <1> 	repe cmpsw
  1093                              <1> %endif
  1094 000005FA 7401                <1> 	je .checkret		; ZR, NC = match -->
  1095                              <1> .notfound:
  1096 000005FC F9                  <1> 	stc			; CY no match
  1097                              <1> .checkret:
  1098 000005FD C3                  <1> 	retn
  1099                              <1> %endif
  1100                              <1> 
  1101                              <1> 
  1102 000005FE 00<rep 2h>          <1> 	align 4, db 0
  1103                              <1> linkercoderelocations:
  1104                              <1> %if _ELDCALL_OPTIONAL || _ELDCALL_NEXT
  1105                              <1> 	dw ELDCALL_CODE_RELOCATIONS_OPTIONAL, 0
  1106                              <1> %else
  1107 00000600 2200[C607]8801-     <1> 	dw ELDCALL_CODE_RELOCATIONS, 0, 0
  1107 00000606 [D507]9001[DD07]98- <1>
  1107 0000060D 01[E907]A001[F507]- <1>
  1107 00000614 A801[FC07]B001-     <1>
  1107 0000061A [0508]B801[0F08]C0- <1>
  1107 00000621 01[2508]C801[3208]- <1>
  1107 00000628 D001[3A08]D801-     <1>
  1107 0000062E [4508]E001[4E08]E8- <1>
  1107 00000635 01[5508]0B02[3208]- <1>
  1107 0000063C 4402[4508]6305-     <1>
  1107 00000642 [FC07]8A05[5D08]9C- <1>
  1107 00000649 05[2508]DE05[2508]- <1>
  1107 00000650 EE05[3A08]00000000  <1>
  1108                              <1> %endif
  1109                              <1> 
  1110                              <1> %if _ELD_LINKER_PASSES
  1111                              <1> linkerlinkercoderelocations:
  1112                              <1> %if _ELDCALL_OPTIONAL || _ELDCALL_NEXT
  1113                              <1> 	dw ELDCALL_LINKER_CODE_RELOCATIONS_OPTIONAL, 0
  1114                              <1> %else
  1115 00000658 2704[5D08]4B04-     <1> 	dw ELDCALL_LINKER_CODE_RELOCATIONS, 0, 0
  1115 0000065E [6708]5504[5508]5E- <1>
  1115 00000665 04[7708]00000000    <1>
  1116                              <1> %endif
  1117                              <1> 
  1118                              <1> 	align 2, db 0
  1119                              <1> linktable:
  1120                              <1> 	istruc LINKTABLE
  1121                              <1> at ltCodeToCode
  1122 0000066C 7E07                <1> 	dw internallinkercodetocoderelocations - code
  1123 0000066E 2807                <1> 	dw internalcodetocoderelocations - code
  1124                              <1> at ltCodeToData
  1125 00000670 8807                <1> 	dw internallinkercodetodatarelocations - code
  1126 00000672 4A07                <1> 	dw internalcodetodatarelocations - code
  1127                              <1> at ltDataToCode
  1128 00000674 8A07                <1> 	dw internallinkerdatatocoderelocations - code
  1129 00000676 6607                <1> 	dw internaldatatocoderelocations - code
  1130                              <1> at ltDataToData
  1131 00000678 8C07                <1> 	dw internallinkerdatatodatarelocations - code
  1132 0000067A 6807                <1> 	dw internaldatatodatarelocations - code
  1133                              <1> at ltLinkData
  1134 0000067C 6A07                <1> 	dw linkerlinkerdatarelocations - code
  1135 0000067E 8406                <1> 	dw linkerdatarelocations - code
  1136                              <1> at ltLinkCode
  1137 00000680 5806                <1> 	dw linkerlinkercoderelocations - code
  1138 00000682 0006                <1> 	dw linkercoderelocations - code
  1139                              <1> 	iend
  1140                              <1> %endif
  1141                              <1> 
  1142                              <1> 	align 2, db 0
  1143                              <1> linkerdatarelocations:
  1144 00000684 01004600[9408]0100- <1> 	dw LINK_DATA_RELOCATIONS, 0
  1144 0000068C 4800[9E08]01004B00- <1>
  1144 00000694 [A708]01007200-     <1>
  1144 0000069A [B708]01008A00-     <1>
  1144 000006A0 [B708]0100AB00-     <1>
  1144 000006A6 [DC08]0100C300-     <1>
  1144 000006AC [E708]0100E500-     <1>
  1144 000006B2 [F008]0101EB00-     <1>
  1144 000006B8 [0109]01001201-     <1>
  1144 000006BE [1909]01001B01-     <1>
  1144 000006C4 [2409]01002701-     <1>
  1144 000006CA [2D09]01004B01-     <1>
  1144 000006D0 [2D09]0100F901-     <1>
  1144 000006D6 [4309]01002302-     <1>
  1144 000006DC [5109]01003302-     <1>
  1144 000006E2 [5C09]01004002-     <1>
  1144 000006E8 [6A09]01005702-     <1>
  1144 000006EE [5C09]01006302-     <1>
  1144 000006F4 [6A09]01006702-     <1>
  1144 000006FA [2D09]01008202-     <1>
  1144 00000700 [2D09]01008802-     <1>
  1144 00000706 [5109]01006E05-     <1>
  1144 0000070C [B708]01009705-     <1>
  1144 00000712 [2409]0100B905-     <1>
  1144 00000718 [5C09]0100CC05-     <1>
  1144 0000071E [F008]0101D205-     <1>
  1144 00000724 [0109]0000          <1>
  1145                              <1> 
  1146                              <1> 	align 2, db 0
  1147                              <1> internalcodetocoderelocations:
  1148 00000728 22016F012A022F0237- <1> 	dw INTERNAL_CODE_TO_CODE_RELOCATIONS, 0
  1148 00000731 023C0253025F026A02- <1>
  1148 0000073A 7D02840288059205AF- <1>
  1148 00000743 05B505EC050000      <1>
  1149                              <1> 
  1150                              <1> 	align 2, db 0
  1151                              <1> internalcodetodatarelocations:
  1152 0000074A 340056006E008600A5- <1> 	dw INTERNAL_CODE_TO_DATA_RELOCATIONS, 0
  1152 00000753 00CD00D300DD007301- <1>
  1152 0000075C 8401010209028E0200- <1>
  1152 00000765 00                  <1>
  1153                              <1> 
  1154                              <1> 	align 2, db 0
  1155                              <1> internaldatatocoderelocations:
  1156 00000766 FFFF                <1> 	dw INTERNAL_DATA_TO_CODE_RELOCATIONS, -1
  1157                              <1> 
  1158                              <1> 	align 2, db 0
  1159                              <1> internaldatatodatarelocations:
  1160 00000768 FFFF                <1> 	dw INTERNAL_DATA_TO_DATA_RELOCATIONS, -1
  1161                              <1> 
  1162                              <1> %if _ELD_LINKER_PASSES
  1163                              <1> 	align 2, db 0
  1164                              <1> linkerlinkerdatarelocations:
  1165 0000076A 0100DB03[5109]0100- <1> 	dw LINK_LINKER_DATA_RELOCATIONS, 0
  1165 00000772 1E04[DC08]01001C05- <1>
  1165 0000077A [7909]0000          <1>
  1166                              <1> 
  1167                              <1> 	align 2, db 0
  1168                              <1> internallinkercodetocoderelocations:
  1169 0000077E E503F7030804300400- <1> 	dw INTERNAL_LINKER_CODE_TO_CODE_RELOCATIONS, 0
  1169 00000787 00                  <1>
  1170                              <1> 
  1171                              <1> 	align 2, db 0
  1172                              <1> internallinkercodetodatarelocations:
  1173 00000788 0000                <1> 	dw INTERNAL_LINKER_CODE_TO_DATA_RELOCATIONS, 0
  1174                              <1> 
  1175                              <1> 	align 2, db 0
  1176                              <1> internallinkerdatatocoderelocations:
  1177 0000078A FFFF                <1> 	dw INTERNAL_LINKER_DATA_TO_CODE_RELOCATIONS, -1
  1178                              <1> 
  1179                              <1> 	align 2, db 0
  1180                              <1> internallinkerdatatodatarelocations:
  1181 0000078C FFFF                <1> 	dw INTERNAL_LINKER_DATA_TO_DATA_RELOCATIONS, -1
  1182                              <1> %endif
  1183                              <1> 
  1184                              <1> %if ELDOTHER
  1185                              <1> 	align 2, db 0
  1186                              <1> linkerotherdatarelocations:
  1187                              <1> 	dw LINK_OTHER_DATA_RELOCATIONS, 0
  1188                              <1> 
  1189                              <1>  %ifnidn LINK_OTHER_LINKER_DATA_RELOCATIONS, ""
  1190                              <1>   %error Other linker data links not supported
  1191                              <1>  %endif
  1192                              <1> %endif
  1193                              <1> 
  1194                              <1> %if ELDOTHER || ELDHINT
  1195                              <1> 	align 2, db 0
  1196                              <1> debuggeramissig:
  1197 0000078E 65636D20<rep 5h>    <1> 		fill 8, 32, db "ecm"
  1198 00000796 6C446562756720-     <1> 		fill 8, 32, db "lDebug"
  1198 00000796 <rep 2h>            <1>
  1199                              <1> %endif
  1200                              <1> 
  1201                              <1> %if ELDOTHER
  1202                              <1> 	align 2, db 0
  1203                              <1> loaderamissig:
  1204                              <1> 		fill 8, 32, db "ecm"
  1205                              <1> 		fill 8, 32, db "Loader"
  1206                              <1> %endif
  1207                              <1> 
  1208                              <1> %ifnidni _LISTING, ""
  1209                              <1> listmsg:
  1210 0000079E 547261634C6973742D- <1> .hint:		db "TracList-add-offset=",_LISTING,"::"
  1210 000007A7 6164642D6F66667365- <1>
  1210 000007B0 743D696E6A6563742E- <1>
  1210 000007B9 6C73743A3A          <1>
  1211 000007BE 2D2D2D2D680D0A00    <1> .hint.offset:	asciz "----h",13,10
  1212                              <1> %endif
  1213                              <1> 
  1214 000007C6 30CD0C636D64335F6E- <1> 	eldcall_dump_names ELDCALL_CODE_NAMES
  1214 000007CF 6F745F657874A7AA05- <1>
  1214 000007D8 6572726F72D5550973- <1>
  1214 000007E1 6B6970636F6D6D6103- <1>
  1214 000007EA C3096973737472696E- <1>
  1214 000007F3 673FBABD04636D6433- <1>
  1214 000007FC 986906696E7463686B- <1>
  1214 00000805 821B07686578627974- <1>
  1214 0000080E 658490136973656F6C- <1>
  1214 00000817 3F2E6E6F7473656D69- <1>
  1214 00000820 636F6C6F6E21300A63- <1>
  1214 00000829 616C6C5F696E743244- <1>
  1214 00000832 551205707574737AB7- <1>
  1214 0000083B 740873657465733264- <1>
  1214 00000844 78DDB90663686B656F- <1>
  1214 0000084D 6C2890046973706DB2- <1>
  1214 00000856 120573657472638481- <1>
  1214 0000085F 07686578776F72646F- <1>
  1214 00000868 A20D707574736C696E- <1>
  1214 00000871 655F63726C66D0BB1A- <1>
  1214 0000087A 636F70795F73696E67- <1>
  1214 00000883 6C655F636F756E7465- <1>
  1214 0000088C 645F737472696E67    <1>
  1215 00000894 C30B076C617374636D- <1> 	link_data_dump_names LINK_DATA_NAMES
  1215 0000089D 646B5D06646D79636D- <1>
  1215 000008A6 6454400D6D73672E75- <1>
  1215 000008AF 6E696E7374616C6CF0- <1>
  1215 000008B8 9E227472795F646562- <1>
  1215 000008C1 75676765725F616D69- <1>
  1215 000008CA 735F6D756C7469706C- <1>
  1215 000008D3 65785F6E756D626572- <1>
  1215 000008DC 84E3086C696E655F6F- <1>
  1215 000008E5 7574FDFC0670737064- <1>
  1215 000008EE 6267CB510E696E7465- <1>
  1215 000008F7 726E616C666C616773- <1>
  1215 00000900 34688C15616D69735F- <1>
  1215 00000909 6D756C7469706C6578- <1>
  1215 00000912 5F6E756D626572EB42- <1>
  1215 0000091B 08657874647373656C- <1>
  1215 00000924 D52D06657874736567- <1>
  1215 0000092D 97B6136578745F636F- <1>
  1215 00000936 6D6D616E645F68616E- <1>
  1215 0000093F 646C65728D710B6D73- <1>
  1215 00000948 672E696E7374616C6C- <1>
  1215 00000951 5ABC086F7074696F6E- <1>
  1215 0000095A 7337E7D30B65787473- <1>
  1215 00000963 65675F75736564B240- <1>
  1215 0000096C 0C657874646174615F- <1>
  1215 00000975 7573656468440E6C69- <1>
  1215 0000097E 6E6B63616C6C5F7461- <1>
  1215 00000987 626C65              <1>
  1216                              <1> %if ELDOTHER
  1217                              <1> 	link_data_dump_names LINK_OTHER_DATA_NAMES
  1218                              <1> %endif
  1219                              <1> 
  1220                              <1> lmsg:
  1221                              <1> %if _ELD_LINKER_PASSES
  1222                              <1> %if _ELDCALL_OPTIONAL
  1223                              <1> .warning_code_optional:		counted "Optional code link missing, hash="
  1224                              <1> %endif
  1225                              <1> %if _ELDDATA_OPTIONAL
  1226 0000098A 214F7074696F6E616C- <1> .warning_data_optional:		counted "Optional data link missing, hash="
  1226 00000993 2064617461206C696E- <1>
  1226 0000099C 6B206D697373696E67- <1>
  1226 000009A5 2C20686173683D      <1>
  1227                              <1> %endif
  1228 000009AC 1844617461206C696E- <1> .error_data:			counted "Data link missing, hash="
  1228 000009B5 6B206D697373696E67- <1>
  1228 000009BE 2C20686173683D      <1>
  1229 000009C5 18436F6465206C696E- <1> .error_code:			counted "Code link missing, hash="
  1229 000009CE 6B206D697373696E67- <1>
  1229 000009D7 2C20686173683D      <1>
  1230 000009DE 0A682C206C6162656C- <1> .error.2:			counted "h, label ",'"'
  1230 000009E7 2022                <1>
  1231                              <1> %endif
  1232                              <1> %if ELDOTHER
  1233                              <1> .no_other:		asciz "ELD linker: No other link info found!",13,10
  1234                              <1> .error_other:		asciz "ELD linker: Other link info unknown format!",13,10
  1235                              <1> %endif
  1236                              <1> 
  1237 000009E9 00<rep 7h>          <1> 	align 16, db 0
   508                                  
   509                                  	align 16
   510                                  code_size equ $ - code
