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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
/*****************************************************************************
Copyright (c) 2024 Jaroslav Hensl <emulator@emulace.cz>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*****************************************************************************/
#ifndef VXD32
#error VXD32 not defined!
#endif
#define VXD_MAIN
#include "winhack.h"
#include "vmm.h"
#include "vxd.h"
#include "vxd_lib.h"
#include "3d_accel.h"
#include "vxd_vdd.h"
#ifdef SVGA
# include "svga_all.h"
#endif
#include "version.h"
#include "code32.h"
void VMWS_control();
void VMWS_API_entry();
void Device_Init_proc();
void __stdcall Device_Dynamic_Init_proc(DWORD VM);
void __stdcall Device_Exit_proc(DWORD VM);
/*
VXD structure
this variable must be in first address in code segment.
In other cases VXD isn't loadable (WLINK bug?)
*/
DDB VMWS_DDB = {
NULL, // must be NULL
DDK_VERSION, // DDK_Version
VXD_DEVICE_ID, // Device ID
VXD_MAJOR_VER, // Major Version
VXD_MINOR_VER, // Minor Version
NULL,
"VMWSVXD",
VDD_Init_Order, //Undefined_Init_Order,
(DWORD)VMWS_control,
(DWORD)VMWS_API_entry,
(DWORD)VMWS_API_entry,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL, // DDB_Win32_Service_Table
NULL, // prev
sizeof(DDB)
};
#include "vxd_strings.h"
DWORD *DispatchTable = 0;
DWORD DispatchTableLength = 0;
DWORD ThisVM = 0;
/**
* VDD calls wrapers
**/
void VDD_Get_Mini_Dispatch_Table()
{
VxDCall(VDD, Get_Mini_Dispatch_Table);
_asm mov [DispatchTable],edi
_asm mov [DispatchTableLength],ecx
}
/**
* Control Handles
**/
void Sys_Critical_Init_proc()
{
// nop
}
DWORD __stdcall Device_IO_Control_proc(struct DIOCParams *params);
/*
* 32-bit DeviceIoControl ends here
*
*/
void __declspec(naked) Device_IO_Control_entry()
{
_asm {
push esi /* struct DIOCParams */
call Device_IO_Control_proc
retn
}
}
/*
* service module calls (init, exit, deviceIoControl, ...)
* clear carry if succes (this is always success)
*/
void __declspec(naked) VMWS_control()
{
// eax = 0x00 - Sys Critical Init
// eax = 0x01 - sys dynamic init
// eax = 0x1B - dynamic init
// eax = 0x1C - dynamic exit
// eax = 0x23 - device IO control
_asm {
cmp eax,Sys_Critical_Init
jnz control_1
pushad
call Sys_Critical_Init_proc
popad
clc
ret
control_1:
cmp eax,Device_Init
jnz control_2
call Device_Init_proc
popad
clc
ret
control_2:
cmp eax,0x1B
jnz control_3
pushad
push ebx ; VM handle
call Device_Dynamic_Init_proc
popad
clc
ret
control_3:
cmp eax,W32_DEVICEIOCONTROL
jnz control_4
jmp Device_IO_Control_entry
control_4:
cmp eax,System_Exit
jnz control_5
pushad
push ebx ; VM handle
call Device_Exit_proc
popad
clc
ret
control_5:
clc
ret
};
}
/* process V86/PM16 calls */
WORD __stdcall VMWS_API_Proc(PCRS_32 state)
{
WORD rc = 0xFFFF;
WORD service = state->Client_EDX & 0xFFFF;
switch(service)
{
case VXD_PM16_VERSION:
rc = (VXD_MAJOR_VER << 8) | VXD_MINOR_VER;
break;
case VXD_PM16_VMM_VERSION:
rc = Get_VMM_Version();
break;
case OP_FBHDA_SETUP:
{
DWORD dptr = (DWORD)FBHDA_setup();
if(dptr)
{
state->Client_ECX = dptr;
rc = 1;
}
break;
}
break;
case OP_FBHDA_ACCESS_BEGIN:
FBHDA_access_begin(state->Client_ECX);
rc = 1;
break;
case OP_FBHDA_ACCESS_END:
FBHDA_access_end(state->Client_ECX);
rc = 1;
break;
case OP_FBHDA_SWAP:
{
BOOL rs;
rs = FBHDA_swap(state->Client_ECX);
state->Client_ECX = (DWORD)rs;
rc = 1;
break;
}
case OP_FBHDA_CLEAN:
FBHDA_clean();
rc = 1;
break;
case OP_FBHDA_PALETTE_SET:
FBHDA_palette_set(state->Client_ECX & 0xFF, state->Client_EDI);
rc = 1;
break;
case OP_FBHDA_PALETTE_GET:
{
DWORD color;
color = FBHDA_palette_get(state->Client_ECX & 0xFF);
state->Client_EDI = color;
rc = 1;
break;
}
#ifdef SVGA
case OP_SVGA_VALID:
{
BOOL rs;
rs = SVGA_valid();
state->Client_ECX = (DWORD)rs;
rc = 1;
break;
}
case OP_SVGA_SETMODE:
{
BOOL rs;
rs = SVGA_setmode(state->Client_ESI, state->Client_EDI, state->Client_ECX);
state->Client_ECX = (DWORD)rs;
rc = 1;
break;
}
case OP_SVGA_VALIDMODE:
{
BOOL rs;
rs = SVGA_validmode(state->Client_ESI, state->Client_EDI, state->Client_ECX);
state->Client_ECX = (DWORD)rs;
rc = 1;
break;
}
case OP_SVGA_HW_ENABLE:
SVGA_HW_enable();
rc = 1;
break;
case OP_SVGA_HW_DISABLE:
SVGA_HW_disable();
rc = 1;
break;
#endif
}
if(rc == 0xFFFF)
{
state->Client_EFlags |= 0x1; // set carry
}
else
{
state->Client_EFlags &= 0xFFFFFFFEUL; // clear carry
}
return rc;
}
/*
* Service calls from protected mode (usually 16 bit) and virtual 86 mode
* CPU state before call is already on stack (EBP points it).
* Converts the call to __stdcall and call 'VMWS_API_Proc', result of this
* function is placed to saved AX register.
*
*/
void __declspec(naked) VMWS_API_entry()
{
_asm {
push ebp
call VMWS_API_Proc
mov [ebp+1Ch], ax
retn
}
}
/* generate all entry pro VDD function */
#define VDDFUNC(_fnname, _procname) void __declspec(naked) _procname ## _entry() { \
_asm { push ebp }; \
_asm { call _procname ## _proc }; \
_asm { retn }; \
}
#include "vxd_vdd_list.h"
#undef VDDFUNC
#define VDDFUNC(id, procname) DispatchTable[id] = (DWORD)(procname ## _entry);
/* init device and fill dispatch table */
void Device_Dynamic_Init_proc(DWORD VM)
{
dbg_printf(dbg_Device_Init_proc);
// VMMCall _Allocate_Device_CB_Area
ThisVM = VM;
#ifdef SVGA
SVGA_init_hw();
#endif
/* register miniVDD functions */
VDD_Get_Mini_Dispatch_Table();
if(DispatchTableLength >= 0x31)
{
#include "vxd_vdd_list.h"
}
}
#undef VDDFUNC
/* process user space (PM32, RING-3) call */
DWORD __stdcall Device_IO_Control_proc(struct DIOCParams *params)
{
DWORD *inBuf = (DWORD*)params->lpInBuffer;
DWORD *outBuf = (DWORD*)params->lpOutBuffer;
//dbg_printf(dbg_deviceiocontrol, params->dwIoControlCode);
switch(params->dwIoControlCode)
{
/* DX */
case DIOC_OPEN:
case DIOC_CLOSEHANDLE:
dbg_printf(dbg_dic_system, params->dwIoControlCode);
return 0;
case OP_FBHDA_SETUP:
outBuf[0] = (DWORD)FBHDA_setup();
return 0;
case OP_FBHDA_ACCESS_BEGIN:
FBHDA_access_begin(inBuf[0]);
return 0;
case OP_FBHDA_ACCESS_END:
FBHDA_access_end(inBuf[0]);
return 0;
case OP_FBHDA_SWAP:
outBuf[0] = FBHDA_swap(inBuf[0]);
return 0;
case OP_FBHDA_CLEAN:
FBHDA_clean();
return 0;
case OP_FBHDA_PALETTE_SET:
FBHDA_palette_set(inBuf[0], inBuf[1]);
return 0;
case OP_FBHDA_PALETTE_GET:
outBuf[0] = FBHDA_palette_get(inBuf[0]);
return 0;
#ifdef SVGA
case OP_SVGA_VALID:
outBuf[0] = SVGA_valid();
return 0;
case OP_SVGA_CMB_ALLOC:
outBuf[0] = (DWORD)SVGA_CMB_alloc();
return 0;
case OP_SVGA_CMB_FREE:
SVGA_CMB_free((DWORD*)inBuf[0]);
return 0;
case OP_SVGA_CMB_SUBMIT:
{
SVGA_CMB_submit_io_t *inio = (SVGA_CMB_submit_io_t*)inBuf;
SVGA_CMB_status_t *status = (SVGA_CMB_status_t*)outBuf;
SVGA_CMB_submit(inio->cmb, inio->cmb_size, status, inio->flags, inio->DXCtxId);
return 0;
}
case OP_SVGA_FENCE_GET:
outBuf[0] = SVGA_fence_get();
return 0;
case OP_SVGA_FENCE_QUERY:
SVGA_fence_query(&outBuf[0], &outBuf[1]);
return 0;
case OP_SVGA_FENCE_WAIT:
SVGA_fence_wait(inBuf[0]);
return 0;
case OP_SVGA_REGION_CREATE:
{
SVGA_region_info_t *inio = (SVGA_region_info_t*)inBuf;
SVGA_region_info_t *outio = (SVGA_region_info_t*)outBuf;
if(outio != inio)
{
memcpy(outio, inio, sizeof(SVGA_region_info_t));
}
SVGA_region_create(outio);
return 0;
}
case OP_SVGA_REGION_FREE:
{
SVGA_region_info_t *inio = (SVGA_region_info_t*)inBuf;
SVGA_region_free(inio);
return 0;
}
case OP_SVGA_QUERY:
outBuf[0] = SVGA_query(inBuf[0], inBuf[1]);
return 0;
case OP_SVGA_QUERY_VECTOR:
SVGA_query_vector(inBuf[0], inBuf[1], inBuf[2], outBuf);
return 0;
case OP_SVGA_DB_SETUP:
outBuf[0] = (DWORD)SVGA_DB_setup();
return 0;
case OP_SVGA_OT_SETUP:
outBuf[0] = (DWORD)SVGA_OT_setup();
return 0;
#endif /* SVGA */
}
dbg_printf(dbg_dic_unknown, params->dwIoControlCode);
return 1;
}
void Device_Init_proc()
{
/* nop */
}
/* shutdown procedure */
void Device_Exit_proc(DWORD VM)
{
dbg_printf(dbg_destroy);
#ifdef SVGA
SVGA_HW_disable();
#endif
// TODO: free memory
}
|