-
Notifications
You must be signed in to change notification settings - Fork 893
/
mplib.c
222 lines (175 loc) · 5.36 KB
/
mplib.c
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
/*
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <dpmi.h>
//#include "types.h"
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
//#include "mgenord.h"
#define MGENVXD_REGISTER_ORD 1
#define MGENVXD_GETMEM_ORD 2
#define MGENVXD_DEREGISTER_ORD 3
#define MGENVXD_WAKEUP_ORD 4
#define MGENVXD_MAKEDQS_ORD 5
// Virtual 8086 API Ordinals
#define V86API_GETSELECTOR16_ORD (1)
#define V86API_GETSELECTOR32_ORD (2)
#define V86API_GETFLAT32_ORD (3)
#define V86API_MOVERP_ORD (6)
#define V86API_MOVEPR_ORD (7)
#define V86API_POST_ORD (8)
#define V86API_INIT_ORD (9)
#define V86API_UNINIT_ORD (10)
#define V86API_INSERTKEY_ORD (11)
#define V86API_REMOVEHOTKEY_ORD (12)
#define V86API_INSTALLHOTKEY_ORD (13)
#define V86API_HOOKINT48_ORD (14)
#define V86API_WAKEUPDLL_ORD (15)
#define DPMIAPI_GETFLAT32_ORD (1)
#define DPMIAPI_POST_WINDOWS_ORD (2)
// these are DPMI functions. Make sure they don't clash with the
// other MGENVXD_XXXX functions above, or the DPMI functions!
#define MGENVXD_GETQUEUECTR_ORD 6
#define MGENVXD_MOVENODE_ORD 7
#define MGENVXD_GETNODE_ORD 8
#define MGENVXD_FLUSHNODE_ORD 9
#define MGENVXD_MCOUNT_ORD 10
#define MGENVXD_MASTERNODE_ORD 11
#define MGENVXD_SANITYCHECK_ORD 12
#define MGENVXD_WAKEUPDLL_ORD 13
#define MGENVXD_WAIT_ORD 14
//
#define HWND_OFFSET (0)
#define UMSG_OFFSET (1)
#define SIZEREQUEST_OFFSET (2)
#define HVXD_OFFSET (3)
#define DATUM_OFFSET (4)
#define SLOT_OFFSET (5)
#define SIZEGIVEN_OFFSET (6)
#define SELECTOR32_OFFSET (7)
#define SELECTOR16_OFFSET (8)
//#include "magic.h"
#define MGENVXD_DEVICE_ID 0x18AA
//#include "rtq.h"
#define RTQ_NODE struct rtq_node
RTQ_NODE
{
RTQ_NODE *self; // Ring zero address of this node
RTQ_NODE *left; // Ring zero address of preceding node
RTQ_NODE *right; // Ring zero address of succeding node
BYTE * rtqDatum; // Ring 3 Datum of Buffer (start of preface)
BYTE * rtqInsert; // Ring 3 insertion position
WORD rtqLen; // Length of buffer, excluding preface
WORD rtqUpCtr; // Up Counter of bytes used so far
WORD rtqQCtr; // number of nodes attached
WORD padding; // DWORD alignment
};
#define RTQ_PARAM_MOVENODE struct rtq_param_movenode
RTQ_PARAM_MOVENODE
{
WORD rtqFromDQ;
WORD rtqToDQ;
};
RTQ_NODE* rtq_fetch(RTQ_NODE*, RTQ_NODE*); // To, From
int _int86(int vector, __dpmi_regs *iregs, __dpmi_regs *oregs);
#define CHUNNEL_INT 0x48
#define int386 _int86
#define REGISTERS __dpmi_regs
void
Yield(void)
{
__dpmi_yield();
}
void
PostWindowsMessage(void)
{
REGISTERS regs;
regs.d.eax = DPMIAPI_POST_WINDOWS_ORD << 16 | MGENVXD_DEVICE_ID;
regs.d.ebx = 0;
regs.d.ecx = 0;
int386(CHUNNEL_INT, ®s, ®s);
}
int
MGenWait(void)
{
REGISTERS regs;
regs.d.eax = MGENVXD_WAIT_ORD << 16 | MGENVXD_DEVICE_ID;
int386(CHUNNEL_INT, ®s, ®s);
return regs.d.eax;
}
int MGenGetQueueCtr(int qNo)
{
REGISTERS regs;
regs.d.eax = MGENVXD_GETQUEUECTR_ORD << 16 | MGENVXD_DEVICE_ID;
regs.d.ebx = qNo;
int386(CHUNNEL_INT, ®s, ®s);
return regs.d.eax;
}
RTQ_NODE *MGenMoveTo(int qFrom, int qTo)
{
REGISTERS regs;
regs.d.eax = MGENVXD_MOVENODE_ORD << 16 | MGENVXD_DEVICE_ID;
regs.d.ebx = qFrom;
regs.d.ecx = qTo;
int386(CHUNNEL_INT, ®s, ®s);
return (RTQ_NODE *) regs.d.eax;
}
RTQ_NODE *MGenGetNode(int q)
{
REGISTERS regs;
regs.d.eax = MGENVXD_GETNODE_ORD << 16 | MGENVXD_DEVICE_ID;
regs.d.ebx = q;
int386(CHUNNEL_INT, ®s, ®s);
return (RTQ_NODE *) regs.d.eax;
}
RTQ_NODE *MGenGetMasterNode(unsigned *size)
{
REGISTERS regs;
regs.d.eax = MGENVXD_MASTERNODE_ORD << 16 | MGENVXD_DEVICE_ID;
int386(CHUNNEL_INT, ®s, ®s);
*size = regs.d.ecx;
return (RTQ_NODE *) regs.d.eax;
}
RTQ_NODE *MGenFlushNodes(int qFrom, int qTo)
{
REGISTERS regs;
regs.d.eax = MGENVXD_FLUSHNODE_ORD << 16 | MGENVXD_DEVICE_ID;
regs.d.ebx = qFrom;
regs.d.ecx = qTo;
int386(CHUNNEL_INT, ®s, ®s);
return (RTQ_NODE *) regs.d.eax;
}
int MGenMCount(unsigned lowerOrderBits, unsigned upperOrderBits)
{
REGISTERS regs;
regs.d.eax = MGENVXD_MCOUNT_ORD << 16 | MGENVXD_DEVICE_ID;
regs.d.ebx = lowerOrderBits;
regs.d.ecx = upperOrderBits;
int386(CHUNNEL_INT, ®s, ®s);
return regs.d.eax;
}
int MGenSanityCheck(void)
{
REGISTERS regs;
regs.d.eax = MGENVXD_SANITYCHECK_ORD << 16 | MGENVXD_DEVICE_ID;
int386(CHUNNEL_INT, ®s, ®s);
return regs.d.eax;
}
void MGenWakeupDll(void)
{
REGISTERS regs;
regs.d.eax = MGENVXD_WAKEUPDLL_ORD << 16 | MGENVXD_DEVICE_ID;
int386(CHUNNEL_INT, ®s, ®s);
}