exebin2.mac 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 <whygee_corp@hol.fr>
  5. %define EXE_stack_size EXE_realstacksize
  6. %macro EXE_begin 0
  7. ORG 0E0h
  8. section .text
  9. header_start:
  10. db 4Dh,5Ah ; EXE file signature
  11. dw EXE_allocsize % 512
  12. dw (EXE_allocsize + 511) / 512
  13. dw 0 ; relocation information: none
  14. dw (header_end-header_start)/16 ; header size in paragraphs
  15. dw (EXE_absssize + EXE_realstacksize) / 16 ; min extra mem
  16. dw (EXE_absssize + EXE_realstacksize) / 16 ; max extra mem
  17. dw -10h ; Initial SS (before fixup)
  18. dw EXE_endbss + EXE_realstacksize ; Initial SP (1K DPMI+1K STACK)
  19. dw 0 ; (no) Checksum
  20. dw 100h ; Initial IP - start just after the header
  21. dw -10h ; Initial CS (before fixup)
  22. dw 0 ; file offset to relocation table: none
  23. dw 0 ; (no overlay)
  24. align 16,db 0
  25. header_end:
  26. EXE_startcode:
  27. section .data
  28. EXE_startdata:
  29. section .bss
  30. EXE_startbss:
  31. %endmacro
  32. %macro EXE_stack 1
  33. EXE_realstacksize equ %1
  34. %define EXE_stack_size EXE_bogusstacksize ; defeat EQU in EXE_end
  35. %endmacro
  36. %macro EXE_end 0
  37. section .text
  38. EXE_endcode:
  39. section .data
  40. EXE_enddata:
  41. section .bss
  42. alignb 4
  43. EXE_endbss:
  44. EXE_acodesize equ (EXE_endcode-EXE_startcode+3) & (~3)
  45. EXE_datasize equ EXE_enddata-EXE_startdata
  46. EXE_absssize equ (EXE_endbss-EXE_startbss+3) & (~3)
  47. EXE_allocsize equ EXE_acodesize + EXE_datasize
  48. EXE_stack_size equ 0x800 ; default if nothing else was used
  49. %endmacro