-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgi.asm
384 lines (357 loc) · 7.23 KB
/
gi.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
; /**/
; /*
; filename : GI.ASM
; created by : Ben Castricum
; created on : ?
; purpose : all functions used to process fixups are in here
; last update : 8-Apr-1995
; status : completed
; comments : Items are stored in memory using a linked list; stucture
; follows.
;
; 0 word segment of next block
; 2 word number of items stored in this block
; 4+ first fixup stored as:
; word offset
; word segment
;
; revision history :
; 31-May-1994 : Added -F switch
; 08-Apr-1995 : Added common GI signature
; */
; /**/
;---------------------------------------------------------------------------;
.code
BreakGI: ASSUME ds:NOTHING, es:NOTHING
push ds
mov ds,SegData
ASSUME ds:DGROUP
pop RegDS
mov RegAX,ax
mov RegBX,bx
mov RegCX,cx
mov RegDX,dx
mov RegSI,si
mov RegDI,di
mov RegES,es
xor ax,ax
xchg InProgram,al
mov InProgramStatus,al
call [SetFixupRegs]
mov ax,SegItemCur
mov es,ax
ASSUME es:NOTHING
or ax,ax ; first item ?
jne GIResolve
call GetNewItemBlck
mov SegItemCur,es
mov SegItemStart,es
mov word ptr es:[0],0
mov word ptr es:[2],0
GIResolve:
mov si,es:[2] ; store item
shl si,2
mov bx,FixupOfs
mov dx,FixupSeg
sub dx,SegProgram
cmp SwitchF,FALSE
je GIStore
xchg ax,dx
mul ParSize
add bx,ax
adc dx,0
mov cl,12
shl dx,cl
mov FixupSeg,dx
cmp bx,0FFFFh ; segment wrap?
jne GIStore
inc dx
sub bx,10h
GIStore:
mov es:[si+4],bx
mov es:[si+6],dx
inc word ptr es:[2]
push es ; get block size
mov ax,es
dec ax
mov es,ax
ASSUME es:NOTHING
mov cx,es:[3]
shl cx,4
pop es
ASSUME es:NOTHING
mov ax,es:[2]
inc ax
shl ax,2
cmp ax,cx ; block full?
jne EndGI
push es
call GetNewItemBlck
mov SegItemCur,es
mov word ptr es:[0],0
mov word ptr es:[2],0
mov ax,es
pop es
ASSUME es:NOTHING
mov es:[0],ax
EndGI:
inc NrRelocFound
mov al,InProgramStatus
mov InProgram,al
mov ax,RegAX
mov bx,RegBX
mov cx,RegCX
mov dx,RegDX
mov si,RegSI
mov di,RegDI
mov es,RegES
mov ds,RegDS
iret
GetNewItemBlck:
mov bx,1
mov si,offset ME_Fixups
call AllocateMem
mov bx,65535/16
mov es,ax
call ResizeMem
call ResizeMem
ret
GI_DSBX: ASSUME ds:DGROUP, es:NOTHING
mov ax,RegDS
mov FixupSeg,ax
mov FixupOfs,bx
ret
GI_DSDI: ASSUME ds:DGROUP, es:NOTHING
mov ax,RegDS
mov FixupSeg,ax
mov FixupOfs,di
ret
GI_ESDIxchgr: ASSUME ds:DGROUP, es:NOTHING
mov FixupSeg,es
mov al,byte ptr RelItemOfs
cbw
add di,ax
mov FixupOfs,di
mov ax,RegBX
sub ax,SegProgram
xchg es:[di],ax
mov RegBX,ax
ret
GI_ESDIxchg: ASSUME ds:DGROUP, es:NOTHING
mov ax,RegAX
sub ax,SegProgram
xchg es:[di],ax
mov RegAX,ax
GI_ESDI: ASSUME ds:DGROUP, es:NOTHING
mov FixupSeg,es
mov FixupOfs,di
ret
GI_ESSI: ASSUME ds:DGROUP, es:NOTHING
mov FixupSeg,es
mov FixupOfs,si
ret
GI_ESDIr: ASSUME ds:DGROUP, es:NOTHING
mov FixupSeg,es
add di,RelItemOfs
mov FixupOfs,di
ret
GI_ESa: ASSUME ds:DGROUP, es:NOTHING
mov FixupSeg,es
mov ax,RelItemOfs
mov FixupOfs,ax
ret
GI_ESBX: ASSUME ds:DGROUP, es:NOTHING
mov FixupSeg,es
mov FixupOfs,bx
ret
GI_STOSW: ASSUME ds:DGROUP, es:NOTHING
mov FixupSeg,es
mov FixupOfs,di
add FixupOfs,0E4h
mov ax,es:[di] ; mov dx,es:[di]
mov RegDX,ax
mov ax,RegAX ; stosw
sub ax,SegProgram
stosw
mov RegDI,di
ret
;---------------------------------------------------------------------------;
SetFixups: ASSUME ds:NOTHING, es:NOTHING
push ds
push es
mov ds,SegData
ASSUME ds:DGROUP
mov bx,SegProgram
xor ax,ax
mov SegItemCur,ax
mov NrRelocFound,ax
xchg SegItemStart,ax
SetBlckFixup:
or ax,ax
je EndSetFixups
mov ds,ax
mov cx,ds:[2]
jcxz FreeItemMem
mov si,4
Set1Fixup:
lodsw
mov di,ax
lodsw
add ax,bx
mov es,ax
add es:[di],bx
loop Set1Fixup
FreeItemMem:
push es ; free memory block
push ds
pop es
call FreeMem
pop es
mov ax,ds:[0]
jmp SetBlckFixup
EndSetFixups:
pop es
pop ds
ret
;---------------------------------------------------------------------------;
WriteItems: ASSUME ds:NOTHING, es:NOTHING
push ds
push es
push dx
mov es,SegData
ASSUME es:DGROUP
mov ax,SegItemStart
WriteItemBlck:
or ax,ax ; no items ?
je EndWriteItems
mov ds,ax
mov cx,ds:[2]
shl cx,2
mov dx,4
call WriteFile
push es
push ds
pop es
call FreeMem
pop es
mov ax,ds:[0]
jmp WriteItemBlck
EndWriteItems:
pop dx
pop es
pop ds
ret
SetGI: ASSUME ds:NOTHING, es:NOTHING
push ax
push bx
push cx
push es
mov es,SegData
ASSUME es:DGROUP
mov ax,INTGI*100h + 0CDh
mov cl,ds:[bx]
cmp cl,26h
je GIES
xchg ds:[bx],ax
mov si,offset GI_DSBX
cmp ax,0F01h ; add [bx],cx
je SetGIRegs
cmp ax,0701h ; add [bx],ax
je SetGIRegs
mov si,offset GI_DSDI
cmp ax,1501h ; add [di],dx
je SetGIRegs
GIES:
mov byte ptr ds:[bx],90h ; nop
inc bx
xchg ds:[bx],ax
mov si,offset GI_ESDIxchg
cmp ax,0587h ; xchg [di],ax (pgmpak)
je SetGIRegs
mov si,offset GI_ESDI
cmp ax,0501h ; add [di],ax
je SetGIRegs
cmp ax,1D01h ; add [di],bx (exepack)
je SetGIRegs
cmp ax,0D01h ; add [di],cx (UCEXE)
je SetGIRegs
cmp ax,1501h ; add [di],dx
je SetGIRegs
cmp ax,2D01h ; add [di],bp
je SetGIRegs
mov si,offset GI_ESSI
cmp ax,1489h ; mov [si],dx (compressor)
je SetGIRegs
mov si,offset GI_ESBX
cmp ax,0701h ; add [bx],ax
je SetGIRegs
cmp ax,0F01h ; add [bx],cx (tinyprog v3.6)
je SetGIRegs
cmp ax,1701h ; add [bx],dx
je SetGIRegs
cmp ax,3F01h ; add [bx],di (compack v4.4)
je SetGIRegs
cmp ax,2F01h ; add [bx],bp (diet v1.45f)
je SetGIRegs
mov si,offset GI_ESDIxchgr
mov cl,90h
xchg ds:[bx+2],cl
mov byte ptr RelItemOfs,cl
cmp ax,5D87h ; xchg [di+XX],bx (optlink)
je SetGIRegs
mov si,offset GI_STOSW ; spacemaker
cmp ax,158Bh ; mov dx,es:[di]
je SetGIRegs ; cl should be 0ABH (stosw)
mov si,offset GI_ESDIr
mov ch,90h
xchg ds:[bx+3],ch
mov byte ptr [RelItemOfs+1],ch
cmp ax,0AD01h ; add [di+XXXX],bp
je SetGIRegs
mov si,offset GI_ESa
cmp ax,0601h ; add [XXXX],ax (protect 5.0)
je SetGIRegs
mov si,offset ERR_reloc
call Error
jmp Continue
SetGIRegs:
mov SetFixupRegs,si
pop es
pop cx
pop bx
pop ax
ret
;---------------------------------------------------------------------------;
GIShrink: ASSUME ds:NOTHING, es:NOTHING
push es
push ds
mov ds,SegData
ASSUME ds:DGROUP
mov ax,SegItemCur
mov es,ax
ASSUME es:NOTHING
or ax,ax ; first item ?
je GI_NoShrink
mov ax,es:[2]
inc ax ; +4 bytes for info field
shl ax,2
mov bx,ax
shr bx,4
and ax,0Fh
cmp ah,al
adc bx,0
call ResizeMem
GI_NoShrink:
pop ds
pop es
ret
;---------------------------------------------------------------------------;
.data
; common signatures
GI_ESDIBX label
add es:[di],bx
GI_ESDIBXSz equ $ - GI_ESDIBX
FixupSeg dw 0
FixupOfs dw 0
RelItemOfs dw 0
SetFixupRegs dw 0