1 2 ; Public Domain 3 4 %include "lmacros3.mac" 1 <1> [list -] 14 <2> [list -] 14 <1> [list -] 5 6 numdef DOSEXIT, 0 7 numdef DOSENTRY, 0 8 numdef LARGEFILL, 0 9 numdef RELOC, 1 10 numdef BASESEGMENT, 0 11 numdef RELOCEXE, 0 12 13 14 cpu 8086 15 %if _RELOCEXE 16 %assign ORIGIN 0 17 org ORIGIN 18 addsection HEADER, start=0 19 header_start: 20 00000000 4D5A db "MZ" ; exeSignature 21 FILESIZE equ fromparas(header_size_p + BEHINDSEGMENT) 22 00000002 A000 dw FILESIZE % 512 ; exeExtraBytes 23 00000004 8100 dw (FILESIZE + 511) / 512 ; exePages 24 00000006 0400 dw relocationtable.amount ; exeRelocItems 25 00000008 0300 dw header_size_p ; exeHeaderSize 26 0000000A 2000 dw paras(512) ; exeMinAlloc 27 0000000C 2000 dw paras(512) ; exeMaxAlloc 28 0000000E 0710 dw +BEHINDSEGMENT ; exeInitSS 29 00000010 0002 dw 512 ; exeInitSP 30 00000012 0000 dw 0 ; exeChecksum 31 00000014 00000000 dw 0, +0 ; exeInitCSIP 32 00000018 [1C00] dw relocationtable ; exeRelocTable 33 34 addsection FIRST, vstart=0 align=16 follows=HEADER 35 %elif _DOSENTRY 36 %assign ORIGIN 256 37 org ORIGIN 38 addsection FIRST, start=ORIGIN 39 %else 40 %assign ORIGIN 0 41 org ORIGIN 42 addsection FIRST, start=ORIGIN 43 %endif 44 first_start: 45 addsection SECOND, vstart=0 align=16 follows=FIRST 46 second_start: 47 addsection THIRD, vstart=0 align=16 follows=SECOND 48 third_start: 49 50 first_size equ first_end - first_start 51 endarea first, 1 52 second_size equ second_end - second_start 53 endarea second, 1 54 third_size equ third_end - third_start 55 endarea third, 1 56 %if _RELOCEXE 57 header_size equ header_end - header_start 58 endarea header, 1 59 %endif 60 61 FIRSTSEGMENT equ _BASESEGMENT + 0 62 SECONDSEGMENT equ _BASESEGMENT + paras(ORIGIN) + first_size_p 63 THIRDSEGMENT equ _BASESEGMENT + paras(ORIGIN) + first_size_p + second_size_p 64 BEHINDSEGMENT equ _BASESEGMENT + paras(ORIGIN) + first_size_p + second_size_p + third_size_p 65 66 %define RELOCATIONFROMFIRST "" 67 %define RELOCATIONFROMSECOND "" 68 %define RELOCATIONFROMTHIRD "" 69 %imacro relocation 0-1.nolist -2 70 %%reloc equ $ + %1 71 %ifidn _CURRENT_SECTION, FIRST 72 %xdefine RELOCATIONFROMFIRST RELOCATIONFROMFIRST, %%reloc, FIRSTSEGMENT 73 %elifidn _CURRENT_SECTION, SECOND 74 %xdefine RELOCATIONFROMSECOND RELOCATIONFROMSECOND, %%reloc, SECONDSEGMENT 75 %elifidn _CURRENT_SECTION, THIRD 76 %xdefine RELOCATIONFROMTHIRD RELOCATIONFROMTHIRD, %%reloc, THIRDSEGMENT 77 %else 78 %error Unknown section for relocation 79 %endif 80 %endmacro 81 82 usesection FIRST 83 start: 84 00000000 8CCA mov dx, cs 85 00000002 8EDA mov ds, dx 86 %if !_RELOCEXE && _RELOC 87 mov si, relocationtable 88 mov cx, relocationtable.amount 89 jcxz .noreloc 90 @@: 91 lodsw 92 xchg bx, ax 93 lodsw 94 add ax, dx 95 mov es, ax 96 add word [es:bx], dx 97 loop @B 98 .noreloc: 99 %endif 100 101 displayfirst: 102 00000004 BE[2300] mov si, firstmsg 103 00000007 BB0700 mov bx, 7 104 0000000A B40E mov ah, 0Eh 105 0000000C A9 db __TEST_IMM16 ; (skip int 10h) 106 @@: 107 0000000D CD10 int 10h 108 0000000F AC lodsb 109 00000010 84C0 test al, al 110 00000012 75F9 jnz @B 111 112 00000014 9A[1500]0400 call SECONDSEGMENT:secondentry 113 relocation 114 115 exit: 116 %if _DOSEXIT 117 00000019 B8004C mov ax, 4C00h 118 0000001C CD21 int 21h 119 %else 120 xor ax, ax 121 int 16h 122 int 19h 123 %endif 124 125 126 bouncetothird: 127 0000001E EA[1D00]0410 jmp THIRDSEGMENT:bounced 128 relocation 129 130 131 00000023 48656C6C6F2066726F- firstmsg: asciz "Hello from first!",13,10 131 0000002C 6D206669727374210D- 131 00000035 0A00 132 133 134 usesection SECOND 135 136 00000000 48656C6C6F2066726F- secondmsg: asciz "Hello from second!",13,10 136 00000009 6D207365636F6E6421- 136 00000012 0D0A00 137 138 secondentry: 139 displaysecond: 140 00000015 BE[0000] mov si, secondmsg 141 00000018 BB0700 mov bx, 7 142 0000001B B40E mov ah, 0Eh 143 0000001D A9 db __TEST_IMM16 ; (skip int 10h) 144 @@: 145 0000001E CD10 int 10h 146 00000020 2EAC cs lodsb 147 00000022 84C0 test al, al 148 00000024 75F8 jnz @B 149 150 00000026 EA[1800]0410 jmp THIRDSEGMENT:thirdentry 151 relocation 152 153 154 usesection THIRD 155 156 align 2, db 0 157 indirect_to_bounce: 158 00000000 [1E00] dw bouncetothird 159 relocation 0 160 00000002 0000 dw FIRSTSEGMENT 161 162 00000004 48656C6C6F2066726F- thirdmsg: asciz "Hello from third!",13,10 162 0000000D 6D207468697264210D- 162 00000016 0A00 163 164 thirdentry: 165 00000018 2EFF2E[0000] jmp far [cs:indirect_to_bounce] 166 167 bounced: 168 displaythird: 169 0000001D BE[0400] mov si, thirdmsg 170 00000020 BB0700 mov bx, 7 171 00000023 B40E mov ah, 0Eh 172 00000025 A9 db __TEST_IMM16 ; (skip int 10h) 173 @@: 174 00000026 CD10 int 10h 175 00000028 2EAC cs lodsb 176 0000002A 84C0 test al, al 177 0000002C 75F8 jnz @B 178 179 0000002E CB retf 180 181 182 %ifn _RELOCEXE 183 usesection FIRST 184 %else 185 usesection HEADER 186 %endif 187 %if _RELOCEXE || _RELOC 188 0000001A 00 align 4, db 0 189 relocationtable: 190 .: 191 0000001C [1700]0000[2100]00- dw RELOCATIONFROMFIRST 191 00000023 00 192 00000024 [2900]0400 dw RELOCATIONFROMSECOND 193 00000028 [0200]0410 dw RELOCATIONFROMTHIRD 194 .end: 195 .amount: equ (.end - .) / 4 196 %endif 197 %if _RELOCEXE 198 0000002C 90 align 16 199 header_end: 200 %endif 201 202 %if _LARGEFILL 203 usesection SECOND 204 0000002B CC _fill fromkib(64), 0CCh, second_start 205 %endif 206 207 usesection FIRST 208 00000037 90 align 16 209 first_end: 210 usesection SECOND 211 align 16 212 second_end: 213 usesection THIRD 214 0000002F 90 align 16 215 third_end: