-
Notifications
You must be signed in to change notification settings - Fork 48
/
leheader.asm
137 lines (111 loc) · 3.93 KB
/
leheader.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
;
; FASM example of creation of a linear ( exponential soon Very Happy )
; executable ("LE") for running on DOS/32A extender.
;
; Compiles directly from .ASM into .LE , no linker Very Happy
;
; Use "SB" tool to bind it with the extender.
;
; http://board.flatassembler.net/topic.php?t=7122
;
; Limitations:
; - No relocs (crappy anyway)
; - Only one "object" ( no problem, flat rules Very Happy )
;
; Size should be no problem, tested with 2 MiB, should
; support up to 2 Gib Wink
;
format binary as "LE"
use32
org 0
; *** Constants ***
ccstackp = 2 ; Stack size in pages ( 1 page = 4 KiB )
; *** Calculations ***
vvstackb = ccstackp shl 12 ; Pages -> Bytes
vvcodesize = llcodeend - llcode
vvcodep = ( vvcodesize + $0FFF ) shr 12 ; Bytes -> Pages
vvpagestotal = vvcodep + ccstackp
vvpagestotalali = ( vvpagestotal + 3 ) and $000FFFFC ; Align to integer multi of 4
vvcodepad = 2 ; Allign code size to integer multi of $10, and add 2 to make loader / DOS happy
vvtemp1 = vvcodesize and $0F ; Temp, find out used bytes on last 16-Bytes block
if vvtemp1 > 0
vvcodepad = 18 - vvtemp1
end if
; *** LE / [LX] "Module Header" (0,$AC) ***
;org 0
db "LE"
db 0,0 ; Little endian, surprisingly Very Happy
db 0,0,0,0 ; "level" ... of zeroizm
db 2,0 ; 80386
db 1,0 ; "OS/2" Osama's System Very Happy
db 0,0,0,0 ; "module version"
; org $10
dd 0 ; "module type", crap
dd vvpagestotal ; Number of pages total
dd 1,0 ; CS:EIP object number (4 bytes) & offset (4 bytes)
; org $20
dd 2, vvstackb ; SS:ESP object number (4 bytes) & offset (4 bytes)
dd $1000 ; Page size in bytes
dd 0 ; LX: "shift" alignement (4 -> $10 bytes) | LE: bytes on last page | crap Sad
; org $30
dd vvpagestotalali shl 2 , 0
; "fixup" size, chk | "size" may NEVER be 0 !!! Can be skipped in LE, but not empty
dd $30,0 ; "loader" size, chk
; org $40
dd $B0 ; Offset of the "Object table" (relative to "LE")
dd 2 ; Number of entries
dd $E0 ; LX: Offset of the "Object Page Table" | LE: Offset of object "Map" !!!
dd 0 ; Offset of ??? , "iterate" crap
; org $50
dd 0 ; Offset ressource table
dd 0 ; Number of entries
dd 0 ; Offset "resident" crap
dd 0 ; Offset of "entry" crap table Sad
; org $60
dd 0,0 ; "MD" offset & entries, useless junk Very Happy
dd $E0 ; Fixup offset 1, important in LX only !!!
dd $E0 ; Fixup offset 2, useless junk both LE and LX Wink
; org $70
dd 0,0 ; Import offset, count, both junk
dd 0,0 ; 2 more offsets, crap
; org $80
dd llcode ; "Data pages offset" - where the code begins, relative to MZ, not "LE" !!!
; "SB" will care when binding ... just v. 7.1 won't - it has a BUG !!! Sad
dd 0,0,0 ; Some more crap
; org $90
dd 0,0,0,0 ; Useless "chk", "auto", 2 x deBUG
; org $A0
dd 0,0,0 ; Crap / "heap"
; *** Reserved / crap ($AC,4) ***
dd 0
; *** Object table entry #1 ($B0,$18 ) (main) ***
; Flags can be $2045 (R) or $2047 (R&W)
dd vvcodep shl 12 ; Size in bytes (we always align to 4 KiB)
dd 0 ; Base address won't work, let's set it to most funny value of 0
dd $2047 ; Flags: "huge 32-bit" | "preloaded" | "executable" | "writable" | "readable"
dd 1,vvcodep ; "map" index (count from 1 ???) / entries
dd 0 ; Reserved / crap
; *** Object table entry #2 ($C8,$18 ) (stack) ***
; !!! Stack may *** NEVER *** be executable !!!
dd ccstackp shl 12 ; Size in bytes
dd 0 ; Base address won't work
dd $2043 ; Flags: "huge 32-bit" | "preloaded" | "writable" | "readable"
dd 1+vvcodep,ccstackp ; "map" index / entries
dd 0 ; Reserved / crap
; *** Object Page Map ($E0,n*$10 ) | Fixup 1st Table | Fixup 2nd Table ***
dd vvpagestotalali dup (0) ; Crap, one "dd" zero needed per page
macro laddr reg,ofs
{
local thiscall
call thiscall
thiscall:
pop reg
add reg,ofs-thiscall
}
; *** Code, forget about "org", never loads correctly Wink ***
; "org" $F0 minimum, always $10 bytes aligned
llcode:
include 'lemain.asm'
llcodeend:
db vvcodepad dup (0) ; Crap, to prevent unexpected EOF
;end.