%if 0 Big FreeDOS kernel entry and stub by C. Masloch, 2022 Usage of the works is permitted provided that this instrument is retained with the works, so that any entity that uses the works is notified of this instrument. DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY. %endif %include "lmacros3.mac" gendef STACKSEGMENT, (60h + kernel_size_p + stub_size_p) numdef STACKPOINTER, 2048 numdef TRAIL_OFFSET, 48 numdef DEVICE, 0 numdef DEPACKERENTRY, 0 strdef TRAILFILE, "trail.bin" strdef LEADFILE, "lead.bin" cpu 8086 org 0 addsection START kernel: start: jmp strict short entry db "CONFIG" times 32 - ($ - $$) db 0 entry: jmp 60h + kernel_size_p:0 db _TRAIL_OFFSET db trail_size & 15 times _TRAIL_OFFSET - ($ - $$) nop trail: incbin _TRAILFILE endarea trail align 16 endarea kernel addsection STUB, follows=START vstart=0 stub: mov ax, 5Eh mov es, ax ; => help data mov ds, ax xchg ax, bx ; al = unit xor di, di stosw ; store unit, clobber high byte mov si, 22h ; -> our CONFIG block mov cx, words(32 - 2 - 4) rep movsw ; move CONFIG block into help data push bp ; store bp on the stack mov ax, sp stosw ; remember original stack mov ax, ss stosw ; remember original stack ; es:di -> linear 600h (segmented 5Eh:20h) push cs pop ds mov si, replacement mov cl, replacement_size_w rep movsw ; overwrite our start/entry with depacker intro mov ax, _STACKSEGMENT mov ss, ax mov sp, _STACKPOINTER ; set up stack expected by depacker %if _DEVICE mov ax, 60h push ax push word [es:26h] retf %else jmp 60h:_DEPACKERENTRY ; jump to depacker %endif align 2 replacement: incbin _LEADFILE endarea replacement %if replacement_size < (trail - start) %error Too short replacement %elif replacement_size > (trail - start) %warning Too long replacement %endif %if replacement_size & 1 %error Odd replacement size not allowed %endif endarea stub