Debian Codegraph @

misc/exebin2.mac

raw
1 ; -*- nasm -*-
2
3 ; NASM macro file to allow the `bin' output format to generate
4
5 ; simple .EXE files by constructing the EXE header by hand.
6
7 ; Adapted from a contribution by Yann Guidon <[email protected]>
8
9
10
11 %define EXE_stack_size EXE_realstacksize
12
13
14
15 %macro EXE_begin 0
16
17 ORG 0E0h
18
19 section .text
20
21
22
23 header_start:
24
25 db 4Dh,5Ah ; EXE file signature
26
27 dw EXE_allocsize % 512
28
29 dw (EXE_allocsize + 511) / 512
30
31 dw 0 ; relocation information: none
32
33 dw (header_end-header_start)/16 ; header size in paragraphs
34
35 dw (EXE_absssize + EXE_realstacksize) / 16 ; min extra mem
36
37 dw (EXE_absssize + EXE_realstacksize) / 16 ; max extra mem
38
39 dw -10h ; Initial SS (before fixup)
40
41 dw EXE_endbss + EXE_realstacksize ; Initial SP (1K DPMI+1K STACK)
42
43 dw 0 ; (no) Checksum
44
45 dw 100h ; Initial IP - start just after the header
46
47 dw -10h ; Initial CS (before fixup)
48
49 dw 0 ; file offset to relocation table: none
50
51 dw 0 ; (no overlay)
52
53 align 16,db 0
54
55 header_end:
56
57
58
59 EXE_startcode:
60
61 section .data
62
63 EXE_startdata:
64
65 section .bss
66
67 EXE_startbss:
68
69 %endmacro
70
71
72
73 %macro EXE_stack 1
74
75 EXE_realstacksize equ %1
76
77 %define EXE_stack_size EXE_bogusstacksize ; defeat EQU in EXE_end
78
79 %endmacro
80
81
82
83 %macro EXE_end 0
84
85 section .text
86
87 EXE_endcode:
88
89 section .data
90
91 EXE_enddata:
92
93 section .bss
94
95 alignb 4
96
97 EXE_endbss:
98
99
100
101 EXE_acodesize equ (EXE_endcode-EXE_startcode+3) & (~3)
102
103 EXE_datasize equ EXE_enddata-EXE_startdata
104
105 EXE_absssize equ (EXE_endbss-EXE_startbss+3) & (~3)
106
107 EXE_allocsize equ EXE_acodesize + EXE_datasize
108
109
110
111 EXE_stack_size equ 0x800 ; default if nothing else was used
112
113 %endmacro
114