-
Notifications
You must be signed in to change notification settings - Fork 0
/
dpmi.inc
396 lines (345 loc) · 8.71 KB
/
dpmi.inc
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
385
386
387
388
389
390
391
392
393
394
395
396
;/*!
; @file
;
; @brief DPMI Macro Library
;
; @author
;
; This is macros adopted from HX-DOS package
;
; Documentation: http://osfree.org/doku/en:docs:macrolib
;
;*/
ifndef DPMI_DEFINED
DPMI_DEFINED equ 1
;*** definitions DOS Protected Mode Interface ***
RMCS struct ;real mode call structure
union
rEDI dd ? ;+0
rDI dw ?
ends
union
rESI dd ? ;+4
rSI dw ?
ends
union
rEBP dd ? ;+8
rBP dw ?
ends
RESERVE dd ? ;+12
union
rEBX dd ? ;+16
rBX dw ?
ends
union
rEDX dd ? ;+20
rDX dw ?
ends
union
rECX dd ? ;+24
rCX dw ?
ends
union
rEAX dd ? ;+28
rAX dw ?
ends
rFlags dw ? ;+32
rES dw ? ;+34
rDS dw ? ;+36
rFS dw ? ;+38
rGS dw ? ;+40
union
rCSIP dd ? ;+42
struct
rIP dw ?
rCS dw ?
ends
ends
union
rSSSP dd ? ;+46
struct
rSP dw ?
rSS dw ?
ends
ends
RMCS ends
MEMINFO struct
maxBlock dd ? ;0 ;in bytes
freeUnlocked dd ? ;4 ;pages (max unlocked allocation)
maxLockable dd ? ;8 ;pages (max locked allocation)
totalAdrSpace dd ? ;12
unlocked dd ? ;16 ;total unlocked (=virtual)
freePhys dd ? ;20
totalPhys dd ? ;24
freeAdrSpace dd ? ;28
swapFile dd ? ;32
res db 12 dup (?)
MEMINFO ends
EXCFRAME struct
_dpmieip dd ?
_dpmics dd ?
errorcode dd ?
_eip dd ?
_cs dd ?
_eflags dd ?
_esp dd ?
_ss dd ?
EXCFRAME ends
EXCFRAME16 struct
_dpmieip dw ?
_dpmics dw ?
errorcode dw ?
_eip dw ?
_cs dw ?
_eflags dw ?
_esp dw ?
_ss dw ?
EXCFRAME16 ends
DPMI_AllocDesc equ 0
DPMI_FreeDesc equ 1
DPMI_GetBase equ 6
DPMI_SetBase equ 7
DPMI_SetLimit equ 8
DPMI_SetAccRights equ 9
@DpmiCall macro xx
ifnb <xx>
mov ax,xx
endif
int 31h
endm
@DPMI_AllocDesc macro xx ;allocate descriptor
ifnb <xx>
ifdifi <xx>, <cx>
mov cx,xx
endif
else
mov cx,1
endif
@DpmiCall DPMI_AllocDesc
endm
@DPMI_FreeDesc macro xx ;free descriptor
ifnb <xx>
ifdifi <xx>, <bx>
mov bx,xx
endif
endif
@DpmiCall DPMI_FreeDesc
endm
@DPMI_Seg2Desc macro segment_ ;segment to descriptor
ifnb <segment_>
move bx,segment_
endif
@DpmiCall 0002h
endm
@DPMI_GetIncValue macro
@DpmiCall 0003h
endm
@DPMI_LockSel macro xx ;undocumented: lock selector region
mov bx,xx
@DpmiCall 0004h
endm
@DPMI_UnlockSel macro xx ;undocumented: unlock selector region
mov bx,xx
@DpmiCall 0005h
endm
@DPMI_GetBase macro selector ;get base address in CX:DX
ifnb <selector>
mov bx,word ptr selector
endif
@DpmiCall DPMI_GetBase
endm
@DPMI_SetBase macro selector ;set base address in CX:DX
ifnb <selector>
mov bx,word ptr selector
endif
@DpmiCall DPMI_SetBase
endm
@DPMI_SetLimit macro selector ;set limit in CX:DX
ifnb <selector>
mov bx,word ptr selector
endif
@DpmiCall DPMI_SetLimit
endm
@DPMI_SetAccRights macro selector,rights ;set access rights in CX
ifnb <rights>
mov cx,rights
endif
ifnb <selector>
mov bx,selector
endif
@DpmiCall DPMI_SetAccRights
endm
@DPMI_CreateCSAlias macro selector ;create code segment alias descriptor
ifnb <selector>
mov bx,selector
endif
@DpmiCall 000Ah
endm
@DPMI_GetDescriptor macro selector,puffer ;get 8 byte descriptor in ES:DI
ifnb <selector>
mov bx,selector
endif
ifnb <puffer>
les di,puffer
endif
@DpmiCall 000Bh
endm
@DPMI_SetDescriptor macro selector,puffer ;set descriptor ES:DI
ifnb <selector>
mov bx,selector
endif
ifnb <puffer>
les di,puffer
endif
@DpmiCall 000Ch
endm
@DPMI_DOSALLOC macro length ;allocate DOS memory block
mov bx,length
@DpmiCall 0100h
endm
@DPMI_DOSFREE macro selektor ;free DOS memory block
ifnb <selector>
mov dx,selektor
endif
@DpmiCall 0101h
endm
@DPMI_DOSSIZE macro selektor,parag ;resize DOS memory block
ifnb <selektor>
mov dx, selektor
endif
ifnb <parag>
mov bx, parag
endif
@DpmiCall 0102h
endm
@DPMI_GetRMIntVec macro xx ;get realmode interrupt vector in CX:DX
ifnb <xx>
mov bl,xx
endif
@DpmiCall 0200h
endm
@DPMI_SetRMIntVec macro xx ;set realmode interrupt vector CX:DX
ifnb <xx>
mov bl,xx
endif
@DpmiCall 0201h
endm
@DPMI_GetExcVec macro xx ;get exception vector in CX:DX
ifnb <xx>
mov bl,xx
endif
@DpmiCall 0202h
endm
@DPMI_SetExcVec macro xx ;set exception vector in CX:DX
ifnb <xx>
mov bl,xx
endif
@DpmiCall 0203h
endm
@DPMI_GetPMIntVec macro xx ;get PM interrupt vector into CX:DX
ifnb <xx>
mov bl,xx
endif
@DpmiCall 0204h
endm
@DPMI_SetPMIntVec macro xx ;set PM interrupt vector in CX:DX
ifnb <xx>
mov bl,xx
endif
@DpmiCall 0205h
endm
@DPMI_SimRMInt macro xx,yy ;simulate real mode interrupt
mov bx,xx ;ES:DI->RMCS
ifnb <yy>
mov cx,yy ;CX = words to copy to RM stack
endif
@DpmiCall 0300h
endm
@DPMI_CallRMFarProc macro ;call real mode far proc
mov bh,00 ;ES:DI->RMCS
@DpmiCall 0301h ;CX = words to copy to RM stack
endm
@DPMI_CallRMIRProc macro ;call real mode far proc with iret frame
mov bh,00 ;
@DpmiCall 0302h ;CX = words to copy to RM stack
endm
@DPMI_AllocRMCallback macro ;allocate real mode callback
@DpmiCall 0303h ;DS:SI protected mode proc to call
endm ;ES:DI RMCS to use
@DPMI_FreeRMCallback macro ;free real mode callback in CX:DX
@DpmiCall 0304h
endm
@DPMI_GETRMSA macro ;get raw mode switch address
@DpmiCall 0306h
endm
@DPMI_GETVERSION macro ;get version
@DpmiCall 0400h
endm
@DPMI_GETFREEMEMINFO macro ;get free memory information
@DpmiCall 0500h
endm
@DPMI_ALLOCMEM macro ;alloc memory (bytes in BX:CX)
@DpmiCall 0501h ;returns handle in SI:DI, address in BX:CX
endm
@DPMI_FREEMEM macro ;free memory handle in SI:DI
@DpmiCall 0502h
endm
@DPMI_SIZE macro ;refree memory handle in SI:DI
@DpmiCall 0502h
endm
@DPMI_GETPAGESIZE macro ;get page size
@DpmiCall 0604h
endm
@DPMI_MAPPHYS macro addr_,size_
mov di,size_+0
mov si,size_+2
mov cx,addr_+0
mov bx,addr_+2
@DpmiCall 0800h
endm
@DPMI_DisableInt macro
@DpmiCall 0900h
endm
;INT 2F - DOS Protected-Mode Interface - INSTALLATION CHECK
;
; AX = 1687h
;Return: AX = 0000h if installed
; BX = flags
; bit 0: 32-bit programs supported
; CL = processor type (02h=80286, 03h=80386, 04h=80486)
; DH = DPMI major version
; DL = two-digit DPMI minor version (binary)
; SI = number of paragraphs of DOS extender private data
; ES:DI -> DPMI mode-switch entry point (see #02718)
; AX nonzero if not installed
;SeeAlso: AX=1686h,AX=43E0h,AX=DE01h/BX=4450h,AX=FB42h/BX=0001h
;SeeAlso: INT 31/AX=0400h,INT 31/AX=5702h,INT D4/AH=10h
;
@DPMI_SwitchEntry macro
mov ax, 1687h
int 2fh
endm
;INT 2F - DPMI 0.9+ - GET VENDOR-SPECIFIC API ENTRY POINT
;
; AX = 168Ah
; DS:(E)SI = selector:offset of ASCIZ vendor name (see #02719)
;Return: AL = status
; 00h successful
; ES:(E)DI -> extended API entry point
; 8Ah unsuccessful
;Notes: the vendor name is used to determine which entry point to return; it is
; case-sensitive
; available in protected mode only
; 32-bit applications use ESI and EDI, 16-bit applications use SI and DI
; this call is present but not documented for DPMI 0.9
; the Borland C++ 3.1 DPMILOAD does not handle requests for entry points
; other than the MS-DOS one gracefully, producing an unhandled
; exception report; this has been fixed in the Borland Pascal 7 version
;SeeAlso: AX=1687h,INT 31/AX=0A00h,INT 31/AH=57h
@DPMI_VendorEntry macro vendor
mov si,offset vendor
mov ax, 168ah
int 2fh
endm
; popcontext listing
endif