| 1 |
; -*- nasm -*- |
| 2 |
; NASM macro file to allow the `bin' output format to generate |
| 3 |
; simple .EXE files by constructing the EXE header by hand. |
| 4 |
; Adapted from a contribution by Yann Guidon <[email protected]> |
| 5 |
|
| 6 |
%define EXE_stack_size EXE_realstacksize |
| 7 |
|
| 8 |
%macro EXE_begin 0 |
| 9 |
ORG 0E0h |
| 10 |
section .text |
| 11 |
|
| 12 |
header_start: |
| 13 |
db 4Dh,5Ah ; EXE file signature |
| 14 |
dw EXE_allocsize % 512 |
| 15 |
dw (EXE_allocsize + 511) / 512 |
| 16 |
dw 0 ; relocation information: none |
| 17 |
dw (header_end-header_start)/16 ; header size in paragraphs |
| 18 |
dw (EXE_absssize + EXE_realstacksize) / 16 ; min extra mem |
| 19 |
dw (EXE_absssize + EXE_realstacksize) / 16 ; max extra mem |
| 20 |
dw -10h ; Initial SS (before fixup) |
| 21 |
dw EXE_endbss + EXE_realstacksize ; Initial SP (1K DPMI+1K STACK) |
| 22 |
dw 0 ; (no) Checksum |
| 23 |
dw 100h ; Initial IP - start just after the header |
| 24 |
dw -10h ; Initial CS (before fixup) |
| 25 |
dw 0 ; file offset to relocation table: none |
| 26 |
dw 0 ; (no overlay) |
| 27 |
align 16,db 0 |
| 28 |
header_end: |
| 29 |
|
| 30 |
EXE_startcode: |
| 31 |
section .data |
| 32 |
EXE_startdata: |
| 33 |
section .bss |
| 34 |
EXE_startbss: |
| 35 |
%endmacro |
| 36 |
|
| 37 |
%macro EXE_stack 1 |
| 38 |
EXE_realstacksize equ %1 |
| 39 |
%define EXE_stack_size EXE_bogusstacksize ; defeat EQU in EXE_end |
| 40 |
%endmacro |
| 41 |
|
| 42 |
%macro EXE_end 0 |
| 43 |
section .text |
| 44 |
EXE_endcode: |
| 45 |
section .data |
| 46 |
EXE_enddata: |
| 47 |
section .bss |
| 48 |
alignb 4 |
| 49 |
EXE_endbss: |
| 50 |
|
| 51 |
EXE_acodesize equ (EXE_endcode-EXE_startcode+3) & (~3) |
| 52 |
EXE_datasize equ EXE_enddata-EXE_startdata |
| 53 |
EXE_absssize equ (EXE_endbss-EXE_startbss+3) & (~3) |
| 54 |
EXE_allocsize equ EXE_acodesize + EXE_datasize |
| 55 |
|
| 56 |
EXE_stack_size equ 0x800 ; default if nothing else was used |
| 57 |
%endmacro |