aboutsummaryrefslogtreecommitdiffstats
path: root/dpmi.h
blob: 4d838fbfe0f70739f08a1897bcfe49d1eabd51f2 (plain) (blame)
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
#ifndef __DPMI_H__INCLUDED__
#define __DPMI_H__INCLUDED__

extern WORD DPMI_AllocLDTDesc( WORD cSelectors );
#pragma aux DPMI_AllocLDTDesc = \
    "xor    ax, ax"             \
    "int    31h"                \
    "jnc    OK"                 \
    "xor    ax, ax"             \
    "OK:"                       \
    parm [cx];

extern DWORD DPMI_GetSegBase( WORD Selector );
#pragma aux DPMI_GetSegBase =   \
    "mov    ax, 6"              \
    "int    31h"                \
    "mov    ax, cx"             \
    "xchg   ax, dx"             \
    parm [bx] modify [cx];

extern void DPMI_SetSegBase( WORD Selector, DWORD Base );
#pragma aux DPMI_SetSegBase =   \
    "mov    ax, 7"              \
    "int    31h"                \
    parm [bx] [cx dx];

extern void DPMI_SetSegLimit( WORD Selector, DWORD Limit );
#pragma aux DPMI_SetSegLimit =   \
    "mov    ax, 8"              \
    "int    31h"                \
    parm [bx] [cx dx];

/* NB: Compiler insists on CX:BX and DI:SI, DPMI needs it word swapped. */
extern DWORD DPMI_MapPhys( DWORD Base, DWORD Size );
#pragma aux DPMI_MapPhys =      \
    "xchg   cx, bx"             \
    "xchg   si, di"             \
    "mov    ax, 800h"           \
    "int    31h"                \
    "jnc    OK"                 \
    "xor    bx, bx"             \
    "xor    cx, cx"             \
    "OK:"                       \
    "mov    dx, bx"             \
    "mov    ax, cx"             \
    parm [cx bx] [di si];

extern DWORD DPMI_AllocMemBlk(DWORD Size);
#pragma aux DPMI_AllocMemBlk =  \
    "xchg   cx, bx"             \
    "mov    ax, 501h"           \
    "int    31h"                \
    "jnc    alloc_ok"           \
    "xor    bx, bx"             \
    "xor    cx, cx"             \
    "alloc_ok:"                 \
    "mov    dx, bx"             \
    "mov    ax, cx"             \
    parm [cx bx] modify [ax di si];

extern WORD DPMI_FreeMemBlk(DWORD ptr);
#pragma aux DPMI_FreeMemBlk =  \
    "xchg   di, si"            \
    "mov    ax, 502h"          \
    "int    31h"               \
    "jc     free_error"        \
    "xor    ax, ax"            \
    "free_error:"              \
    parm [di si] modify [ax];


static DWORD DPMI_AllocLinBlk_LinAddress = 0;
static DWORD DPMI_AllocLinBlk_MHandle = 0;
    
extern WORD DPMI_AllocLinBlk(DWORD size);
#pragma aux DPMI_AllocLinBlk =  \
    ".386"                      \
    "push ebx"                  \
    "push ecx"                  \
    "push esi"                  \
    "push edx"                  \
    "push eax"                  \
    "shl  ecx, 16"              \
    "mov   cx, bx"              \
    "xor  ebx, ebx"             \
    "mov  edx, 1"               \
    "mov  eax, 504h" /* alloc linear address (in EBX, handle in ESI) */ \
    "int  31h"                  \
    "jc alloc_fail"             \
      "mov dword ptr [DPMI_AllocLinBlk_LinAddress], ebx" \
      "mov dword ptr [DPMI_AllocLinBlk_MHandle], esi" \
      "pop eax"                 \
      "mov ax, 0"               \
      "pop edx"                 \
      "pop esi"                 \
      "pop ecx"                 \
      "pop ebx"                 \
      "jmp alloc_end"           \
    "alloc_fail:"               \
      "mov dword ptr [DPMI_AllocLinBlk_LinAddress], ecx" \
      "mov dx, ax"              \
      "pop eax"                 \
      "mov ax, dx"              \
      "pop edx"                 \
      "pop esi"                 \
      "pop ecx"                 \
      "pop ebx"                 \
      "alloc_end:"              \
    parm [cx bx] modify [ax];

extern WORD DPMI_LockRegion(DWORD linAddress, DWORD size);
#pragma aux DPMI_LockRegion = \
    "xchg   cx, bx"           \
    "xchg   si, di"           \
    "mov    ax, 600h"         \
    "int    31h"              \
    "jc lock_fail"            \
    "xor ax, ax"              \
    "lock_fail:"              \
    parm [cx bx] [di si] modify [ax];

extern void DPMI_FreeLDTDesc ( WORD desc);
#pragma aux DPMI_FreeLDTDesc =  \
    "mov    ax, 1"              \
    "int    31h"                \
    parm [bx];


#endif /* __DPMI_H__INCLUDED__ */