A few fixes for mingw cross-compilation.
[wine.git] / win32 / device.c
blob2bab50289786cddc0e6a66616f114815161437e1
1 /*
2 * Win32 device functions
4 * Copyright 1998 Marcus Meissner
5 * Copyright 1998 Ulrich Weigand
6 * Copyright 1998 Patrik Stridvall
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "config.h"
24 #include "wine/port.h"
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <sys/types.h>
29 #include <string.h>
30 #include <stdarg.h>
31 #include <time.h>
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winreg.h"
36 #include "winerror.h"
37 #include "file.h"
38 #include "winioctl.h"
39 #include "winnt.h"
40 #include "msdos.h"
41 #include "miscemu.h"
42 #include "stackframe.h"
43 #include "wine/server.h"
44 #include "wine/debug.h"
46 /* int 13 stuff */
47 #ifdef HAVE_SYS_IOCTL_H
48 # include <sys/ioctl.h>
49 #endif
50 #include <fcntl.h>
51 #ifdef linux
52 # include <linux/fd.h>
53 #endif
54 #include "drive.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(file);
59 static BOOL DeviceIo_VTDAPI(DWORD dwIoControlCode,
60 LPVOID lpvInBuffer, DWORD cbInBuffer,
61 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
62 LPDWORD lpcbBytesReturned,
63 LPOVERLAPPED lpOverlapped);
64 static BOOL DeviceIo_MONODEBG(DWORD dwIoControlCode,
65 LPVOID lpvInBuffer, DWORD cbInBuffer,
66 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
67 LPDWORD lpcbBytesReturned,
68 LPOVERLAPPED lpOverlapped);
69 static BOOL DeviceIo_MMDEVLDR(DWORD dwIoControlCode,
70 LPVOID lpvInBuffer, DWORD cbInBuffer,
71 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
72 LPDWORD lpcbBytesReturned,
73 LPOVERLAPPED lpOverlapped);
75 static DWORD VxDCall_VMM( DWORD service, CONTEXT86 *context );
77 static BOOL DeviceIo_IFSMgr(DWORD dwIoControlCode,
78 LPVOID lpvInBuffer, DWORD cbInBuffer,
79 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
80 LPDWORD lpcbBytesReturned,
81 LPOVERLAPPED lpOverlapped);
83 static BOOL DeviceIo_VCD(DWORD dwIoControlCode,
84 LPVOID lpvInBuffer, DWORD cbInBuffer,
85 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
86 LPDWORD lpcbBytesReturned,
87 LPOVERLAPPED lpOverlapped);
89 static DWORD VxDCall_VWin32( DWORD service, CONTEXT86 *context );
91 static BOOL DeviceIo_VWin32(DWORD dwIoControlCode,
92 LPVOID lpvInBuffer, DWORD cbInBuffer,
93 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
94 LPDWORD lpcbBytesReturned,
95 LPOVERLAPPED lpOverlapped);
97 static BOOL DeviceIo_PCCARD (DWORD dwIoControlCode,
98 LPVOID lpvInBuffer, DWORD cbInBuffer,
99 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
100 LPDWORD lpcbBytesReturned,
101 LPOVERLAPPED lpOverlapped);
103 static BOOL DeviceIo_HASP (DWORD dwIoControlCode,
104 LPVOID lpvInBuffer, DWORD cbInBuffer,
105 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
106 LPDWORD lpcbBytesReturned,
107 LPOVERLAPPED lpOverlapped);
109 * VxD names are taken from the Win95 DDK
112 struct VxDInfo
114 LPCSTR name;
115 WORD id;
116 DWORD (*vxdcall)(DWORD, CONTEXT86 *);
117 BOOL (*deviceio)(DWORD, LPVOID, DWORD,
118 LPVOID, DWORD, LPDWORD, LPOVERLAPPED);
121 static const struct VxDInfo VxDList[] =
123 /* Standard VxD IDs */
124 { "VMM", 0x0001, VxDCall_VMM, NULL },
125 { "DEBUG", 0x0002, NULL, NULL },
126 { "VPICD", 0x0003, NULL, NULL },
127 { "VDMAD", 0x0004, NULL, NULL },
128 { "VTD", 0x0005, NULL, NULL },
129 { "V86MMGR", 0x0006, NULL, NULL },
130 { "PAGESWAP", 0x0007, NULL, NULL },
131 { "PARITY", 0x0008, NULL, NULL },
132 { "REBOOT", 0x0009, NULL, NULL },
133 { "VDD", 0x000A, NULL, NULL },
134 { "VSD", 0x000B, NULL, NULL },
135 { "VMD", 0x000C, NULL, NULL },
136 { "VKD", 0x000D, NULL, NULL },
137 { "VCD", 0x000E, NULL, DeviceIo_VCD },
138 { "VPD", 0x000F, NULL, NULL },
139 { "BLOCKDEV", 0x0010, NULL, NULL },
140 { "VMCPD", 0x0011, NULL, NULL },
141 { "EBIOS", 0x0012, NULL, NULL },
142 { "BIOSXLAT", 0x0013, NULL, NULL },
143 { "VNETBIOS", 0x0014, NULL, NULL },
144 { "DOSMGR", 0x0015, NULL, NULL },
145 { "WINLOAD", 0x0016, NULL, NULL },
146 { "SHELL", 0x0017, NULL, NULL },
147 { "VMPOLL", 0x0018, NULL, NULL },
148 { "VPROD", 0x0019, NULL, NULL },
149 { "DOSNET", 0x001A, NULL, NULL },
150 { "VFD", 0x001B, NULL, NULL },
151 { "VDD2", 0x001C, NULL, NULL },
152 { "WINDEBUG", 0x001D, NULL, NULL },
153 { "TSRLOAD", 0x001E, NULL, NULL },
154 { "BIOSHOOK", 0x001F, NULL, NULL },
155 { "INT13", 0x0020, NULL, NULL },
156 { "PAGEFILE", 0x0021, NULL, NULL },
157 { "SCSI", 0x0022, NULL, NULL },
158 { "MCA_POS", 0x0023, NULL, NULL },
159 { "SCSIFD", 0x0024, NULL, NULL },
160 { "VPEND", 0x0025, NULL, NULL },
161 { "VPOWERD", 0x0026, NULL, NULL },
162 { "VXDLDR", 0x0027, NULL, NULL },
163 { "NDIS", 0x0028, NULL, NULL },
164 { "BIOS_EXT", 0x0029, NULL, NULL },
165 { "VWIN32", 0x002A, VxDCall_VWin32, DeviceIo_VWin32 },
166 { "VCOMM", 0x002B, NULL, NULL },
167 { "SPOOLER", 0x002C, NULL, NULL },
168 { "WIN32S", 0x002D, NULL, NULL },
169 { "DEBUGCMD", 0x002E, NULL, NULL },
171 { "VNB", 0x0031, NULL, NULL },
172 { "SERVER", 0x0032, NULL, NULL },
173 { "CONFIGMG", 0x0033, NULL, NULL },
174 { "DWCFGMG", 0x0034, NULL, NULL },
175 { "SCSIPORT", 0x0035, NULL, NULL },
176 { "VFBACKUP", 0x0036, NULL, NULL },
177 { "ENABLE", 0x0037, NULL, NULL },
178 { "VCOND", 0x0038, NULL, NULL },
180 { "EFAX", 0x003A, NULL, NULL },
181 { "DSVXD", 0x003B, NULL, NULL },
182 { "ISAPNP", 0x003C, NULL, NULL },
183 { "BIOS", 0x003D, NULL, NULL },
184 { "WINSOCK", 0x003E, NULL, NULL },
185 { "WSOCK", 0x003E, NULL, NULL },
186 { "WSIPX", 0x003F, NULL, NULL },
187 { "IFSMgr", 0x0040, NULL, DeviceIo_IFSMgr },
188 { "VCDFSD", 0x0041, NULL, NULL },
189 { "MRCI2", 0x0042, NULL, NULL },
190 { "PCI", 0x0043, NULL, NULL },
191 { "PELOADER", 0x0044, NULL, NULL },
192 { "EISA", 0x0045, NULL, NULL },
193 { "DRAGCLI", 0x0046, NULL, NULL },
194 { "DRAGSRV", 0x0047, NULL, NULL },
195 { "PERF", 0x0048, NULL, NULL },
196 { "AWREDIR", 0x0049, NULL, NULL },
198 /* Far East support */
199 { "ETEN", 0x0060, NULL, NULL },
200 { "CHBIOS", 0x0061, NULL, NULL },
201 { "VMSGD", 0x0062, NULL, NULL },
202 { "VPPID", 0x0063, NULL, NULL },
203 { "VIME", 0x0064, NULL, NULL },
204 { "VHBIOSD", 0x0065, NULL, NULL },
206 /* Multimedia OEM IDs */
207 { "VTDAPI", 0x0442, NULL, DeviceIo_VTDAPI },
208 { "MMDEVLDR", 0x044A, NULL, DeviceIo_MMDEVLDR },
210 /* Network Device IDs */
211 { "VNetSup", 0x0480, NULL, NULL },
212 { "VRedir", 0x0481, NULL, NULL },
213 { "VBrowse", 0x0482, NULL, NULL },
214 { "VSHARE", 0x0483, NULL, NULL },
215 { "IFSMgr", 0x0484, NULL, NULL },
216 { "MEMPROBE", 0x0485, NULL, NULL },
217 { "VFAT", 0x0486, NULL, NULL },
218 { "NWLINK", 0x0487, NULL, NULL },
219 { "VNWLINK", 0x0487, NULL, NULL },
220 { "NWSUP", 0x0487, NULL, NULL },
221 { "VTDI", 0x0488, NULL, NULL },
222 { "VIP", 0x0489, NULL, NULL },
223 { "VTCP", 0x048A, NULL, NULL },
224 { "VCache", 0x048B, NULL, NULL },
225 { "VUDP", 0x048C, NULL, NULL },
226 { "VAsync", 0x048D, NULL, NULL },
227 { "NWREDIR", 0x048E, NULL, NULL },
228 { "STAT80", 0x048F, NULL, NULL },
229 { "SCSIPORT", 0x0490, NULL, NULL },
230 { "FILESEC", 0x0491, NULL, NULL },
231 { "NWSERVER", 0x0492, NULL, NULL },
232 { "SECPROV", 0x0493, NULL, NULL },
233 { "NSCL", 0x0494, NULL, NULL },
234 { "WSTCP", 0x0495, NULL, NULL },
235 { "NDIS2SUP", 0x0496, NULL, NULL },
236 { "MSODISUP", 0x0497, NULL, NULL },
237 { "Splitter", 0x0498, NULL, NULL },
238 { "PPP", 0x0499, NULL, NULL },
239 { "VDHCP", 0x049A, NULL, NULL },
240 { "VNBT", 0x049B, NULL, NULL },
241 { "LOGGER", 0x049D, NULL, NULL },
242 { "EFILTER", 0x049E, NULL, NULL },
243 { "FFILTER", 0x049F, NULL, NULL },
244 { "TFILTER", 0x04A0, NULL, NULL },
245 { "AFILTER", 0x04A1, NULL, NULL },
246 { "IRLAMP", 0x04A2, NULL, NULL },
248 { "PCCARD", 0x097C, NULL, DeviceIo_PCCARD },
249 { "HASP95", 0x3721, NULL, DeviceIo_HASP },
251 /* WINE additions, ids unknown */
252 { "MONODEBG.VXD", 0x4242, NULL, DeviceIo_MONODEBG },
254 { NULL, 0, NULL, NULL }
258 * VMM VxDCall service names are (mostly) taken from Stan Mitchell's
259 * "Inside the Windows 95 File System"
262 #define N_VMM_SERVICE 41
264 LPCSTR VMM_Service_Name[N_VMM_SERVICE] =
266 "PageReserve", /* 0x0000 */
267 "PageCommit", /* 0x0001 */
268 "PageDecommit", /* 0x0002 */
269 "PagerRegister", /* 0x0003 */
270 "PagerQuery", /* 0x0004 */
271 "HeapAllocate", /* 0x0005 */
272 "ContextCreate", /* 0x0006 */
273 "ContextDestroy", /* 0x0007 */
274 "PageAttach", /* 0x0008 */
275 "PageFlush", /* 0x0009 */
276 "PageFree", /* 0x000A */
277 "ContextSwitch", /* 0x000B */
278 "HeapReAllocate", /* 0x000C */
279 "PageModifyPermissions", /* 0x000D */
280 "PageQuery", /* 0x000E */
281 "GetCurrentContext", /* 0x000F */
282 "HeapFree", /* 0x0010 */
283 "RegOpenKey", /* 0x0011 */
284 "RegCreateKey", /* 0x0012 */
285 "RegCloseKey", /* 0x0013 */
286 "RegDeleteKey", /* 0x0014 */
287 "RegSetValue", /* 0x0015 */
288 "RegDeleteValue", /* 0x0016 */
289 "RegQueryValue", /* 0x0017 */
290 "RegEnumKey", /* 0x0018 */
291 "RegEnumValue", /* 0x0019 */
292 "RegQueryValueEx", /* 0x001A */
293 "RegSetValueEx", /* 0x001B */
294 "RegFlushKey", /* 0x001C */
295 "RegQueryInfoKey", /* 0x001D */
296 "GetDemandPageInfo", /* 0x001E */
297 "BlockOnID", /* 0x001F */
298 "SignalID", /* 0x0020 */
299 "RegLoadKey", /* 0x0021 */
300 "RegUnLoadKey", /* 0x0022 */
301 "RegSaveKey", /* 0x0023 */
302 "RegRemapPreDefKey", /* 0x0024 */
303 "PageChangePager", /* 0x0025 */
304 "RegQueryMultipleValues", /* 0x0026 */
305 "RegReplaceKey", /* 0x0027 */
306 "<KERNEL32.101>" /* 0x0028 -- What does this do??? */
309 /* PageReserve arena values */
310 #define PR_PRIVATE 0x80000400 /* anywhere in private arena */
311 #define PR_SHARED 0x80060000 /* anywhere in shared arena */
312 #define PR_SYSTEM 0x80080000 /* anywhere in system arena */
314 /* PageReserve flags */
315 #define PR_FIXED 0x00000008 /* don't move during PageReAllocate */
316 #define PR_4MEG 0x00000001 /* allocate on 4mb boundary */
317 #define PR_STATIC 0x00000010 /* see PageReserve documentation */
319 /* PageCommit default pager handle values */
320 #define PD_ZEROINIT 0x00000001 /* swappable zero-initialized pages */
321 #define PD_NOINIT 0x00000002 /* swappable uninitialized pages */
322 #define PD_FIXEDZERO 0x00000003 /* fixed zero-initialized pages */
323 #define PD_FIXED 0x00000004 /* fixed uninitialized pages */
325 /* PageCommit flags */
326 #define PC_FIXED 0x00000008 /* pages are permanently locked */
327 #define PC_LOCKED 0x00000080 /* pages are made present and locked */
328 #define PC_LOCKEDIFDP 0x00000100 /* pages are locked if swap via DOS */
329 #define PC_WRITEABLE 0x00020000 /* make the pages writeable */
330 #define PC_USER 0x00040000 /* make the pages ring 3 accessible */
331 #define PC_INCR 0x40000000 /* increment "pagerdata" each page */
332 #define PC_PRESENT 0x80000000 /* make pages initially present */
333 #define PC_STATIC 0x20000000 /* allow commit in PR_STATIC object */
334 #define PC_DIRTY 0x08000000 /* make pages initially dirty */
335 #define PC_CACHEDIS 0x00100000 /* Allocate uncached pages - new for WDM */
336 #define PC_CACHEWT 0x00080000 /* Allocate write through cache pages - new for WDM */
337 #define PC_PAGEFLUSH 0x00008000 /* Touch device mapped pages on alloc - new for WDM */
339 /* PageCommitContig additional flags */
340 #define PCC_ZEROINIT 0x00000001 /* zero-initialize new pages */
341 #define PCC_NOLIN 0x10000000 /* don't map to any linear address */
345 HANDLE DEVICE_Open( LPCSTR filename, DWORD access, LPSECURITY_ATTRIBUTES sa )
347 const struct VxDInfo *info;
349 for (info = VxDList; info->name; info++)
350 if (!strncasecmp( info->name, filename, strlen(info->name) ))
351 return FILE_CreateDevice( info->id | 0x10000, access, sa );
353 FIXME( "Unknown/unsupported VxD %s. Try --winver nt40 or win31 !\n", filename);
354 SetLastError( ERROR_FILE_NOT_FOUND );
355 return 0;
358 static DWORD DEVICE_GetClientID( HANDLE handle )
360 DWORD ret = 0;
361 SERVER_START_REQ( get_file_info )
363 req->handle = handle;
364 if (!wine_server_call( req ) && (reply->type == FILE_TYPE_UNKNOWN))
365 ret = reply->attr;
367 SERVER_END_REQ;
368 return ret;
371 static const struct VxDInfo *DEVICE_GetInfo( DWORD clientID )
373 const struct VxDInfo *info = NULL;
375 if (clientID & 0x10000)
377 for (info = VxDList; info->name; info++)
378 if (info->id == LOWORD(clientID)) break;
380 return info;
383 /****************************************************************************
384 * DeviceIoControl (KERNEL32.@)
385 * This is one of those big ugly nasty procedure which can do
386 * a million and one things when it comes to devices. It can also be
387 * used for VxD communication.
389 * A return value of FALSE indicates that something has gone wrong which
390 * GetLastError can decipher.
392 BOOL WINAPI DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,
393 LPVOID lpvInBuffer, DWORD cbInBuffer,
394 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
395 LPDWORD lpcbBytesReturned,
396 LPOVERLAPPED lpOverlapped)
398 DWORD clientID;
400 TRACE( "(%d,%ld,%p,%ld,%p,%ld,%p,%p)\n",
401 hDevice,dwIoControlCode,lpvInBuffer,cbInBuffer,
402 lpvOutBuffer,cbOutBuffer,lpcbBytesReturned,lpOverlapped );
404 if (!(clientID = DEVICE_GetClientID( hDevice )))
406 SetLastError( ERROR_INVALID_PARAMETER );
407 return FALSE;
410 /* Check if this is a user defined control code for a VxD */
411 if( HIWORD( dwIoControlCode ) == 0 )
413 const struct VxDInfo *info;
414 if (!(info = DEVICE_GetInfo( clientID )))
416 FIXME( "No device found for id %lx\n", clientID);
418 else if ( info->deviceio )
420 return info->deviceio( dwIoControlCode,
421 lpvInBuffer, cbInBuffer,
422 lpvOutBuffer, cbOutBuffer,
423 lpcbBytesReturned, lpOverlapped );
425 else
427 FIXME( "Unimplemented control %ld for VxD device %s\n",
428 dwIoControlCode, info->name ? info->name : "???" );
429 /* FIXME: this is for invalid calls on W98SE,
430 * but maybe we should use ERROR_CALL_NOT_IMPLEMENTED
431 * instead ? */
432 SetLastError( ERROR_INVALID_FUNCTION );
435 else
437 char str[3];
439 strcpy(str, "A:");
440 str[0] += LOBYTE(clientID);
441 if (GetDriveTypeA(str) == DRIVE_CDROM)
442 return CDROM_DeviceIoControl(clientID, hDevice, dwIoControlCode, lpvInBuffer, cbInBuffer,
443 lpvOutBuffer, cbOutBuffer, lpcbBytesReturned,
444 lpOverlapped);
445 else switch( dwIoControlCode )
447 case FSCTL_DELETE_REPARSE_POINT:
448 case FSCTL_DISMOUNT_VOLUME:
449 case FSCTL_GET_COMPRESSION:
450 case FSCTL_GET_REPARSE_POINT:
451 case FSCTL_LOCK_VOLUME:
452 case FSCTL_QUERY_ALLOCATED_RANGES:
453 case FSCTL_SET_COMPRESSION:
454 case FSCTL_SET_REPARSE_POINT:
455 case FSCTL_SET_SPARSE:
456 case FSCTL_SET_ZERO_DATA:
457 case FSCTL_UNLOCK_VOLUME:
458 case IOCTL_DISK_CHECK_VERIFY:
459 case IOCTL_DISK_EJECT_MEDIA:
460 case IOCTL_DISK_FORMAT_TRACKS:
461 case IOCTL_DISK_GET_DRIVE_GEOMETRY:
462 case IOCTL_DISK_GET_DRIVE_LAYOUT:
463 case IOCTL_DISK_GET_MEDIA_TYPES:
464 case IOCTL_DISK_GET_PARTITION_INFO:
465 case IOCTL_DISK_LOAD_MEDIA:
466 case IOCTL_DISK_MEDIA_REMOVAL:
467 case IOCTL_DISK_PERFORMANCE:
468 case IOCTL_DISK_REASSIGN_BLOCKS:
469 case IOCTL_DISK_SET_DRIVE_LAYOUT:
470 case IOCTL_DISK_SET_PARTITION_INFO:
471 case IOCTL_DISK_VERIFY:
472 case IOCTL_SERIAL_LSRMST_INSERT:
473 case IOCTL_STORAGE_CHECK_VERIFY:
474 case IOCTL_STORAGE_EJECT_MEDIA:
475 case IOCTL_STORAGE_GET_MEDIA_TYPES:
476 case IOCTL_STORAGE_LOAD_MEDIA:
477 case IOCTL_STORAGE_MEDIA_REMOVAL:
478 FIXME( "unimplemented dwIoControlCode=%08lx\n", dwIoControlCode);
479 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
480 return FALSE;
481 break;
482 default:
483 FIXME( "ignored dwIoControlCode=%08lx\n",dwIoControlCode);
484 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
485 return FALSE;
486 break;
489 return FALSE;
492 /***********************************************************************
493 * DeviceIo_VTDAPI
495 static BOOL DeviceIo_VTDAPI(DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer,
496 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
497 LPDWORD lpcbBytesReturned,
498 LPOVERLAPPED lpOverlapped)
500 BOOL retv = TRUE;
502 switch (dwIoControlCode)
504 case 5:
505 if (lpvOutBuffer && (cbOutBuffer>=4))
506 *(DWORD*)lpvOutBuffer = GetTickCount();
508 if (lpcbBytesReturned)
509 *lpcbBytesReturned = 4;
511 break;
513 default:
514 FIXME( "Control %ld not implemented\n", dwIoControlCode);
515 retv = FALSE;
516 break;
519 return retv;
522 /***********************************************************************
523 * VxDCall0 (KERNEL32.1)
524 * VxDCall1 (KERNEL32.2)
525 * VxDCall2 (KERNEL32.3)
526 * VxDCall3 (KERNEL32.4)
527 * VxDCall4 (KERNEL32.5)
528 * VxDCall5 (KERNEL32.6)
529 * VxDCall6 (KERNEL32.7)
530 * VxDCall7 (KERNEL32.8)
531 * VxDCall8 (KERNEL32.9)
533 void VxDCall( DWORD service, CONTEXT86 *context )
535 DWORD ret = 0xffffffff; /* FIXME */
536 int i;
538 TRACE( "(%08lx, ...)\n", service);
540 for (i = 0; VxDList[i].name; i++)
541 if (VxDList[i].id == HIWORD(service))
542 break;
544 if (!VxDList[i].name)
545 FIXME( "Unknown VxD (%08lx)\n", service);
546 else if (!VxDList[i].vxdcall)
547 FIXME( "Unimplemented VxD (%08lx)\n", service);
548 else
549 ret = VxDList[i].vxdcall( service, context );
551 context->Eax = ret;
555 /***********************************************************************
556 * VxDCall_VMM
558 static DWORD VxDCall_VMM( DWORD service, CONTEXT86 *context )
560 switch ( LOWORD(service) )
562 case 0x0011: /* RegOpenKey */
564 HKEY hkey = (HKEY) stack32_pop( context );
565 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
566 LPHKEY retkey = (LPHKEY)stack32_pop( context );
567 return RegOpenKeyA( hkey, lpszSubKey, retkey );
570 case 0x0012: /* RegCreateKey */
572 HKEY hkey = (HKEY) stack32_pop( context );
573 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
574 LPHKEY retkey = (LPHKEY)stack32_pop( context );
575 return RegCreateKeyA( hkey, lpszSubKey, retkey );
578 case 0x0013: /* RegCloseKey */
580 HKEY hkey = (HKEY)stack32_pop( context );
581 return RegCloseKey( hkey );
584 case 0x0014: /* RegDeleteKey */
586 HKEY hkey = (HKEY) stack32_pop( context );
587 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
588 return RegDeleteKeyA( hkey, lpszSubKey );
591 case 0x0015: /* RegSetValue */
593 HKEY hkey = (HKEY) stack32_pop( context );
594 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
595 DWORD dwType = (DWORD) stack32_pop( context );
596 LPCSTR lpszData = (LPCSTR)stack32_pop( context );
597 DWORD cbData = (DWORD) stack32_pop( context );
598 return RegSetValueA( hkey, lpszSubKey, dwType, lpszData, cbData );
601 case 0x0016: /* RegDeleteValue */
603 HKEY hkey = (HKEY) stack32_pop( context );
604 LPSTR lpszValue = (LPSTR)stack32_pop( context );
605 return RegDeleteValueA( hkey, lpszValue );
608 case 0x0017: /* RegQueryValue */
610 HKEY hkey = (HKEY) stack32_pop( context );
611 LPSTR lpszSubKey = (LPSTR) stack32_pop( context );
612 LPSTR lpszData = (LPSTR) stack32_pop( context );
613 LPDWORD lpcbData = (LPDWORD)stack32_pop( context );
614 return RegQueryValueA( hkey, lpszSubKey, lpszData, lpcbData );
617 case 0x0018: /* RegEnumKey */
619 HKEY hkey = (HKEY) stack32_pop( context );
620 DWORD iSubkey = (DWORD)stack32_pop( context );
621 LPSTR lpszName = (LPSTR)stack32_pop( context );
622 DWORD lpcchName = (DWORD)stack32_pop( context );
623 return RegEnumKeyA( hkey, iSubkey, lpszName, lpcchName );
626 case 0x0019: /* RegEnumValue */
628 HKEY hkey = (HKEY) stack32_pop( context );
629 DWORD iValue = (DWORD) stack32_pop( context );
630 LPSTR lpszValue = (LPSTR) stack32_pop( context );
631 LPDWORD lpcchValue = (LPDWORD)stack32_pop( context );
632 LPDWORD lpReserved = (LPDWORD)stack32_pop( context );
633 LPDWORD lpdwType = (LPDWORD)stack32_pop( context );
634 LPBYTE lpbData = (LPBYTE) stack32_pop( context );
635 LPDWORD lpcbData = (LPDWORD)stack32_pop( context );
636 return RegEnumValueA( hkey, iValue, lpszValue, lpcchValue,
637 lpReserved, lpdwType, lpbData, lpcbData );
640 case 0x001A: /* RegQueryValueEx */
642 HKEY hkey = (HKEY) stack32_pop( context );
643 LPSTR lpszValue = (LPSTR) stack32_pop( context );
644 LPDWORD lpReserved = (LPDWORD)stack32_pop( context );
645 LPDWORD lpdwType = (LPDWORD)stack32_pop( context );
646 LPBYTE lpbData = (LPBYTE) stack32_pop( context );
647 LPDWORD lpcbData = (LPDWORD)stack32_pop( context );
648 return RegQueryValueExA( hkey, lpszValue, lpReserved,
649 lpdwType, lpbData, lpcbData );
652 case 0x001B: /* RegSetValueEx */
654 HKEY hkey = (HKEY) stack32_pop( context );
655 LPSTR lpszValue = (LPSTR) stack32_pop( context );
656 DWORD dwReserved = (DWORD) stack32_pop( context );
657 DWORD dwType = (DWORD) stack32_pop( context );
658 LPBYTE lpbData = (LPBYTE)stack32_pop( context );
659 DWORD cbData = (DWORD) stack32_pop( context );
660 return RegSetValueExA( hkey, lpszValue, dwReserved,
661 dwType, lpbData, cbData );
664 case 0x001C: /* RegFlushKey */
666 HKEY hkey = (HKEY)stack32_pop( context );
667 return RegFlushKey( hkey );
670 case 0x001D: /* RegQueryInfoKey */
672 /* NOTE: This VxDCall takes only a subset of the parameters that the
673 corresponding Win32 API call does. The implementation in Win95
674 ADVAPI32 sets all output parameters not mentioned here to zero. */
676 HKEY hkey = (HKEY) stack32_pop( context );
677 LPDWORD lpcSubKeys = (LPDWORD)stack32_pop( context );
678 LPDWORD lpcchMaxSubKey = (LPDWORD)stack32_pop( context );
679 LPDWORD lpcValues = (LPDWORD)stack32_pop( context );
680 LPDWORD lpcchMaxValueName = (LPDWORD)stack32_pop( context );
681 LPDWORD lpcchMaxValueData = (LPDWORD)stack32_pop( context );
682 return RegQueryInfoKeyA( hkey, NULL, NULL, NULL, lpcSubKeys, lpcchMaxSubKey,
683 NULL, lpcValues, lpcchMaxValueName, lpcchMaxValueData,
684 NULL, NULL );
687 case 0x0021: /* RegLoadKey */
689 HKEY hkey = (HKEY) stack32_pop( context );
690 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
691 LPCSTR lpszFile = (LPCSTR)stack32_pop( context );
692 return RegLoadKeyA( hkey, lpszSubKey, lpszFile );
695 case 0x0022: /* RegUnLoadKey */
697 HKEY hkey = (HKEY) stack32_pop( context );
698 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
699 return RegUnLoadKeyA( hkey, lpszSubKey );
702 case 0x0023: /* RegSaveKey */
704 HKEY hkey = (HKEY) stack32_pop( context );
705 LPCSTR lpszFile = (LPCSTR)stack32_pop( context );
706 LPSECURITY_ATTRIBUTES sa = (LPSECURITY_ATTRIBUTES)stack32_pop( context );
707 return RegSaveKeyA( hkey, lpszFile, sa );
710 #if 0 /* Functions are not yet implemented in misc/registry.c */
711 case 0x0024: /* RegRemapPreDefKey */
712 case 0x0026: /* RegQueryMultipleValues */
713 #endif
715 case 0x0027: /* RegReplaceKey */
717 HKEY hkey = (HKEY) stack32_pop( context );
718 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
719 LPCSTR lpszNewFile= (LPCSTR)stack32_pop( context );
720 LPCSTR lpszOldFile= (LPCSTR)stack32_pop( context );
721 return RegReplaceKeyA( hkey, lpszSubKey, lpszNewFile, lpszOldFile );
723 case 0x0000: /* PageReserve */
725 LPVOID address;
726 LPVOID ret;
727 DWORD psize = getpagesize();
728 ULONG page = (ULONG) stack32_pop( context );
729 ULONG npages = (ULONG) stack32_pop( context );
730 ULONG flags = (ULONG) stack32_pop( context );
732 TRACE("PageReserve: page: %08lx, npages: %08lx, flags: %08lx partial stub!\n",
733 page, npages, flags );
735 if ( page == PR_SYSTEM ) {
736 ERR("Can't reserve ring 1 memory\n");
737 return -1;
739 /* FIXME: This has to be handled separately for the separate
740 address-spaces we now have */
741 if ( page == PR_PRIVATE || page == PR_SHARED ) page = 0;
742 /* FIXME: Handle flags in some way */
743 address = (LPVOID )(page * psize);
744 ret = VirtualAlloc ( address, ( npages * psize ), MEM_RESERVE, 0 );
745 TRACE("PageReserve: returning: %08lx\n", (DWORD )ret );
746 if ( ret == NULL )
747 return -1;
748 else
749 return (DWORD )ret;
752 case 0x0001: /* PageCommit */
754 LPVOID address;
755 LPVOID ret;
756 DWORD virt_perm;
757 DWORD psize = getpagesize();
758 ULONG page = (ULONG) stack32_pop( context );
759 ULONG npages = (ULONG) stack32_pop( context );
760 ULONG hpd = (ULONG) stack32_pop( context );
761 ULONG pagerdata = (ULONG) stack32_pop( context );
762 ULONG flags = (ULONG) stack32_pop( context );
764 TRACE("PageCommit: page: %08lx, npages: %08lx, hpd: %08lx pagerdata: "
765 "%08lx, flags: %08lx partial stub\n",
766 page, npages, hpd, pagerdata, flags );
768 if ( flags & PC_USER )
769 if ( flags & PC_WRITEABLE )
770 virt_perm = PAGE_EXECUTE_READWRITE;
771 else
772 virt_perm = PAGE_EXECUTE_READ;
773 else
774 virt_perm = PAGE_NOACCESS;
776 address = (LPVOID )(page * psize);
777 ret = VirtualAlloc ( address, ( npages * psize ), MEM_COMMIT, virt_perm );
778 TRACE("PageCommit: Returning: %08lx\n", (DWORD )ret );
779 return (DWORD )ret;
782 case 0x0002: /* PageDecommit */
784 LPVOID address;
785 BOOL ret;
786 DWORD psize = getpagesize();
787 ULONG page = (ULONG) stack32_pop( context );
788 ULONG npages = (ULONG) stack32_pop( context );
789 ULONG flags = (ULONG) stack32_pop( context );
791 TRACE("PageDecommit: page: %08lx, npages: %08lx, flags: %08lx partial stub\n",
792 page, npages, flags );
793 address = (LPVOID )( page * psize );
794 ret = VirtualFree ( address, ( npages * psize ), MEM_DECOMMIT );
795 TRACE("PageDecommit: Returning: %s\n", ret ? "TRUE" : "FALSE" );
796 return ret;
798 case 0x000d: /* PageModifyPermissions */
800 DWORD pg_old_perm;
801 DWORD pg_new_perm;
802 DWORD virt_old_perm;
803 DWORD virt_new_perm;
804 MEMORY_BASIC_INFORMATION mbi;
805 LPVOID address;
806 DWORD psize = getpagesize();
807 ULONG page = stack32_pop ( context );
808 ULONG npages = stack32_pop ( context );
809 ULONG permand = stack32_pop ( context );
810 ULONG permor = stack32_pop ( context );
812 TRACE("PageModifyPermissions %08lx %08lx %08lx %08lx partial stub\n",
813 page, npages, permand, permor );
814 address = (LPVOID )( page * psize );
816 VirtualQuery ( address, &mbi, sizeof ( MEMORY_BASIC_INFORMATION ));
817 virt_old_perm = mbi.Protect;
819 switch ( virt_old_perm & mbi.Protect ) {
820 case PAGE_READONLY:
821 case PAGE_EXECUTE:
822 case PAGE_EXECUTE_READ:
823 pg_old_perm = PC_USER;
824 break;
825 case PAGE_READWRITE:
826 case PAGE_WRITECOPY:
827 case PAGE_EXECUTE_READWRITE:
828 case PAGE_EXECUTE_WRITECOPY:
829 pg_old_perm = PC_USER | PC_WRITEABLE;
830 break;
831 case PAGE_NOACCESS:
832 default:
833 pg_old_perm = 0;
834 break;
836 pg_new_perm = pg_old_perm;
837 pg_new_perm &= permand & ~PC_STATIC;
838 pg_new_perm |= permor & ~PC_STATIC;
840 virt_new_perm = ( virt_old_perm ) & ~0xff;
841 if ( pg_new_perm & PC_USER )
843 if ( pg_new_perm & PC_WRITEABLE )
844 virt_new_perm |= PAGE_EXECUTE_READWRITE;
845 else
846 virt_new_perm |= PAGE_EXECUTE_READ;
849 if ( ! VirtualProtect ( address, ( npages * psize ), virt_new_perm, &virt_old_perm ) ) {
850 ERR("Can't change page permissions for %08lx\n", (DWORD )address );
851 return 0xffffffff;
853 TRACE("Returning: %08lx\n", pg_old_perm );
854 return pg_old_perm;
856 case 0x000a: /* PageFree */
858 BOOL ret;
859 LPVOID hmem = (LPVOID) stack32_pop( context );
860 DWORD flags = (DWORD ) stack32_pop( context );
862 TRACE("PageFree: hmem: %08lx, flags: %08lx partial stub\n",
863 (DWORD )hmem, flags );
865 ret = VirtualFree ( hmem, 0, MEM_RELEASE );
866 context->Eax = ret;
867 TRACE("Returning: %d\n", ret );
869 return 0;
871 case 0x001e: /* GetDemandPageInfo */
873 DWORD dinfo = (DWORD)stack32_pop( context );
874 DWORD flags = (DWORD)stack32_pop( context );
876 /* GetDemandPageInfo is supposed to fill out the struct at
877 * "dinfo" with various low-level memory management information.
878 * Apps are certainly not supposed to call this, although it's
879 * demoed and documented by Pietrek on pages 441-443 of "Windows
880 * 95 System Programming Secrets" if any program needs a real
881 * implementation of this.
884 FIXME("GetDemandPageInfo(%08lx %08lx): stub!\n", dinfo, flags);
886 return 0;
888 default:
889 if (LOWORD(service) < N_VMM_SERVICE)
890 FIXME( "Unimplemented service %s (%08lx)\n",
891 VMM_Service_Name[LOWORD(service)], service);
892 else
893 FIXME( "Unknown service %08lx\n", service);
894 break;
897 return 0xffffffff; /* FIXME */
900 /***********************************************************************
901 * DeviceIo_IFSMgr
902 * NOTES
903 * These ioctls are used by 'MSNET32.DLL'.
905 * I have been unable to uncover any documentation about the ioctls so
906 * the implementation of the cases IFS_IOCTL_21 and IFS_IOCTL_2F are
907 * based on reasonable guesses on information found in the Windows 95 DDK.
912 * IFSMgr DeviceIO service
915 #define IFS_IOCTL_21 100
916 #define IFS_IOCTL_2F 101
917 #define IFS_IOCTL_GET_RES 102
918 #define IFS_IOCTL_GET_NETPRO_NAME_A 103
920 struct win32apireq {
921 unsigned long ar_proid;
922 unsigned long ar_eax;
923 unsigned long ar_ebx;
924 unsigned long ar_ecx;
925 unsigned long ar_edx;
926 unsigned long ar_esi;
927 unsigned long ar_edi;
928 unsigned long ar_ebp;
929 unsigned short ar_error;
930 unsigned short ar_pad;
933 static void win32apieq_2_CONTEXT(struct win32apireq *pIn,CONTEXT86 *pCxt)
935 memset(pCxt,0,sizeof(*pCxt));
937 pCxt->ContextFlags=CONTEXT86_INTEGER|CONTEXT86_CONTROL;
938 pCxt->Eax = pIn->ar_eax;
939 pCxt->Ebx = pIn->ar_ebx;
940 pCxt->Ecx = pIn->ar_ecx;
941 pCxt->Edx = pIn->ar_edx;
942 pCxt->Esi = pIn->ar_esi;
943 pCxt->Edi = pIn->ar_edi;
945 /* FIXME: Only partial CONTEXT86_CONTROL */
946 pCxt->Ebp = pIn->ar_ebp;
948 /* FIXME: pIn->ar_proid ignored */
949 /* FIXME: pIn->ar_error ignored */
950 /* FIXME: pIn->ar_pad ignored */
953 static void CONTEXT_2_win32apieq(CONTEXT86 *pCxt,struct win32apireq *pOut)
955 memset(pOut,0,sizeof(struct win32apireq));
957 pOut->ar_eax = pCxt->Eax;
958 pOut->ar_ebx = pCxt->Ebx;
959 pOut->ar_ecx = pCxt->Ecx;
960 pOut->ar_edx = pCxt->Edx;
961 pOut->ar_esi = pCxt->Esi;
962 pOut->ar_edi = pCxt->Edi;
964 /* FIXME: Only partial CONTEXT86_CONTROL */
965 pOut->ar_ebp = pCxt->Ebp;
967 /* FIXME: pOut->ar_proid ignored */
968 /* FIXME: pOut->ar_error ignored */
969 /* FIXME: pOut->ar_pad ignored */
972 static BOOL DeviceIo_IFSMgr(DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer,
973 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
974 LPDWORD lpcbBytesReturned,
975 LPOVERLAPPED lpOverlapped)
977 BOOL retv = TRUE;
978 TRACE("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
979 dwIoControlCode,
980 lpvInBuffer,cbInBuffer,
981 lpvOutBuffer,cbOutBuffer,
982 lpcbBytesReturned,
983 lpOverlapped);
985 switch (dwIoControlCode)
987 case IFS_IOCTL_21:
988 case IFS_IOCTL_2F:{
989 CONTEXT86 cxt;
990 struct win32apireq *pIn=(struct win32apireq *) lpvInBuffer;
991 struct win32apireq *pOut=(struct win32apireq *) lpvOutBuffer;
993 TRACE(
994 "Control '%s': "
995 "proid=0x%08lx, eax=0x%08lx, ebx=0x%08lx, ecx=0x%08lx, "
996 "edx=0x%08lx, esi=0x%08lx, edi=0x%08lx, ebp=0x%08lx, "
997 "error=0x%04x, pad=0x%04x\n",
998 (dwIoControlCode==IFS_IOCTL_21)?"IFS_IOCTL_21":"IFS_IOCTL_2F",
999 pIn->ar_proid, pIn->ar_eax, pIn->ar_ebx, pIn->ar_ecx,
1000 pIn->ar_edx, pIn->ar_esi, pIn->ar_edi, pIn->ar_ebp,
1001 pIn->ar_error, pIn->ar_pad
1004 win32apieq_2_CONTEXT(pIn,&cxt);
1006 if(dwIoControlCode==IFS_IOCTL_21)
1008 DOS3Call(&cxt); /* Call int 21h */
1009 } else {
1010 INT_Int2fHandler(&cxt); /* Call int 2Fh */
1013 CONTEXT_2_win32apieq(&cxt,pOut);
1015 retv = TRUE;
1016 } break;
1017 case IFS_IOCTL_GET_RES:{
1018 FIXME( "Control 'IFS_IOCTL_GET_RES' not implemented\n");
1019 retv = FALSE;
1020 } break;
1021 case IFS_IOCTL_GET_NETPRO_NAME_A:{
1022 FIXME( "Control 'IFS_IOCTL_GET_NETPRO_NAME_A' not implemented\n");
1023 retv = FALSE;
1024 } break;
1025 default:
1026 FIXME( "Control %ld not implemented\n", dwIoControlCode);
1027 retv = FALSE;
1030 return retv;
1033 /********************************************************************************
1034 * VxDCall_VWin32
1036 * Service numbers taken from page 448 of Pietrek's "Windows 95 System
1037 * Programming Secrets". Parameters from experimentation on real Win98.
1041 static DWORD VxDCall_VWin32( DWORD service, CONTEXT86 *context )
1043 switch ( LOWORD(service) )
1045 case 0x0000: /* GetVersion */
1047 DWORD vers = GetVersion();
1048 return (LOBYTE(vers) << 8) | HIBYTE(vers);
1050 break;
1052 case 0x0020: /* Get VMCPD Version */
1054 DWORD parm = (DWORD) stack32_pop(context);
1056 FIXME("Get VMCPD Version(%08lx): partial stub!\n", parm);
1058 /* FIXME: This is what Win98 returns, it may
1059 * not be correct in all situations.
1060 * It makes Bleem! happy though.
1063 return 0x0405;
1066 case 0x0029: /* Int31/DPMI dispatch */
1068 DWORD callnum = (DWORD) stack32_pop(context);
1069 DWORD parm = (DWORD) stack32_pop(context);
1071 TRACE("Int31/DPMI dispatch(%08lx)\n", callnum);
1073 AX_reg(context) = callnum;
1074 CX_reg(context) = parm;
1075 INT_Int31Handler(context);
1077 return LOWORD(context->Eax);
1079 break;
1081 case 0x002a: /* Int41 dispatch - parm = int41 service number */
1083 DWORD callnum = (DWORD) stack32_pop(context);
1085 return callnum; /* FIXME: should really call INT_Int41Handler() */
1087 break;
1089 default:
1090 FIXME("Unknown VWin32 service %08lx\n", service);
1091 break;
1094 return 0xffffffff;
1098 /***********************************************************************
1099 * DeviceIo_VCD
1101 static BOOL DeviceIo_VCD(DWORD dwIoControlCode,
1102 LPVOID lpvInBuffer, DWORD cbInBuffer,
1103 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1104 LPDWORD lpcbBytesReturned,
1105 LPOVERLAPPED lpOverlapped)
1107 BOOL retv = TRUE;
1109 switch (dwIoControlCode)
1111 case IOCTL_SERIAL_LSRMST_INSERT:
1113 FIXME( "IOCTL_SERIAL_LSRMST_INSERT NIY !\n");
1114 retv = FALSE;
1116 break;
1118 default:
1119 FIXME( "Unknown Control %ld\n", dwIoControlCode);
1120 retv = FALSE;
1121 break;
1124 return retv;
1128 /***********************************************************************
1129 * DeviceIo_VWin32
1132 static void DIOCRegs_2_CONTEXT( DIOC_REGISTERS *pIn, CONTEXT86 *pCxt )
1134 memset( pCxt, 0, sizeof(*pCxt) );
1135 /* Note: segment registers == 0 means that CTX_SEG_OFF_TO_LIN
1136 will interpret 32-bit register contents as linear pointers */
1138 pCxt->ContextFlags=CONTEXT86_INTEGER|CONTEXT86_CONTROL;
1139 pCxt->Eax = pIn->reg_EAX;
1140 pCxt->Ebx = pIn->reg_EBX;
1141 pCxt->Ecx = pIn->reg_ECX;
1142 pCxt->Edx = pIn->reg_EDX;
1143 pCxt->Esi = pIn->reg_ESI;
1144 pCxt->Edi = pIn->reg_EDI;
1146 /* FIXME: Only partial CONTEXT86_CONTROL */
1147 pCxt->EFlags = pIn->reg_Flags;
1150 static void CONTEXT_2_DIOCRegs( CONTEXT86 *pCxt, DIOC_REGISTERS *pOut )
1152 memset( pOut, 0, sizeof(DIOC_REGISTERS) );
1154 pOut->reg_EAX = pCxt->Eax;
1155 pOut->reg_EBX = pCxt->Ebx;
1156 pOut->reg_ECX = pCxt->Ecx;
1157 pOut->reg_EDX = pCxt->Edx;
1158 pOut->reg_ESI = pCxt->Esi;
1159 pOut->reg_EDI = pCxt->Edi;
1161 /* FIXME: Only partial CONTEXT86_CONTROL */
1162 pOut->reg_Flags = pCxt->EFlags;
1165 #define DIOC_AH(regs) (((unsigned char*)&((regs)->reg_EAX))[1])
1166 #define DIOC_AL(regs) (((unsigned char*)&((regs)->reg_EAX))[0])
1167 #define DIOC_BH(regs) (((unsigned char*)&((regs)->reg_EBX))[1])
1168 #define DIOC_BL(regs) (((unsigned char*)&((regs)->reg_EBX))[0])
1169 #define DIOC_DH(regs) (((unsigned char*)&((regs)->reg_EDX))[1])
1170 #define DIOC_DL(regs) (((unsigned char*)&((regs)->reg_EDX))[0])
1172 #define DIOC_AX(regs) (((unsigned short*)&((regs)->reg_EAX))[0])
1173 #define DIOC_BX(regs) (((unsigned short*)&((regs)->reg_EBX))[0])
1174 #define DIOC_CX(regs) (((unsigned short*)&((regs)->reg_ECX))[0])
1175 #define DIOC_DX(regs) (((unsigned short*)&((regs)->reg_EDX))[0])
1177 #define DIOC_SET_CARRY(regs) (((regs)->reg_Flags)|=0x00000001)
1179 static const DWORD VWIN32_DriveTypeInfo[7]={
1180 0x0000, /* none */
1181 0x2709, /* 360 K */
1182 0x4f0f, /* 1.2 M */
1183 0x4f09, /* 720 K */
1184 0x4f12, /* 1.44 M */
1185 0x4f24, /* 2.88 M */
1186 0x4f24 /* 2.88 M */
1189 static BYTE floppy_params[2][13] =
1191 { 0xaf, 0x02, 0x25, 0x02, 0x12, 0x1b, 0xff, 0x6c, 0xf6, 0x0f, 0x08 },
1192 { 0xaf, 0x02, 0x25, 0x02, 0x12, 0x1b, 0xff, 0x6c, 0xf6, 0x0f, 0x08 }
1195 /**********************************************************************
1196 * VWIN32_ReadFloppyParams
1198 * Handler for int 13h (disk I/O).
1200 static VOID VWIN32_ReadFloppyParams(DIOC_REGISTERS *regs)
1202 #ifdef linux
1203 unsigned int i, nr_of_drives = 0;
1204 BYTE drive_nr = DIOC_DL(regs);
1205 int floppy_fd,r;
1206 struct floppy_drive_params floppy_parm;
1207 char root[] = "A:\\";
1209 TRACE("in [ EDX=%08lx ]\n", regs->reg_EDX );
1211 DIOC_AH(regs) = 0x00; /* success */
1213 for (i = 0; i < MAX_DOS_DRIVES; i++, root[0]++)
1214 if (GetDriveTypeA(root) == DRIVE_REMOVABLE) nr_of_drives++;
1215 DIOC_DL(regs) = nr_of_drives;
1217 if (drive_nr > 1) { /* invalid drive ? */
1218 DIOC_BX(regs) = 0;
1219 DIOC_CX(regs) = 0;
1220 DIOC_DH(regs) = 0;
1221 DIOC_SET_CARRY(regs);
1222 return;
1225 if ( (floppy_fd = DRIVE_OpenDevice( drive_nr, O_NONBLOCK)) == -1)
1227 WARN("Can't determine floppy geometry !\n");
1228 DIOC_BX(regs) = 0;
1229 DIOC_CX(regs) = 0;
1230 DIOC_DH(regs) = 0;
1231 DIOC_SET_CARRY(regs);
1232 return;
1234 r = ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm);
1236 close(floppy_fd);
1238 if(r<0)
1240 DIOC_SET_CARRY(regs);
1241 return;
1244 regs->reg_ECX = 0;
1245 DIOC_AL(regs) = 0;
1246 DIOC_BL(regs) = floppy_parm.cmos;
1248 /* CH = low eight bits of max cyl
1249 CL = max sec nr (bits 5-0),
1250 hi two bits of max cyl (bits 7-6)
1251 DH = max head nr */
1252 if(DIOC_BL(regs) && (DIOC_BL(regs)<7))
1254 DIOC_DH(regs) = 0x01;
1255 DIOC_CX(regs) = VWIN32_DriveTypeInfo[DIOC_BL(regs)];
1257 else
1259 DIOC_CX(regs) = 0x0;
1260 DIOC_DX(regs) = 0x0;
1263 regs->reg_EDI = (DWORD)floppy_params[drive_nr];
1265 if(!regs->reg_EDI)
1267 ERR("Get floppy params failed for drive %d\n",drive_nr);
1268 DIOC_SET_CARRY(regs);
1271 TRACE("out [ EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx EDI=%08lx ]\n",
1272 regs->reg_EAX, regs->reg_EBX, regs->reg_ECX, regs->reg_EDX, regs->reg_EDI);
1274 /* FIXME: Word exits quietly if we return with no error. Why? */
1275 FIXME("Returned ERROR!\n");
1276 DIOC_SET_CARRY(regs);
1278 #else
1279 DIOC_AH(regs) = 0x01;
1280 DIOC_SET_CARRY(regs);
1281 #endif
1284 /**********************************************************************
1285 * VWIN32_Int13Handler
1287 * Handler for VWIN32_DIOC_DOS_INT13 (disk I/O).
1289 static VOID VWIN32_Int13Handler( DIOC_REGISTERS *regs)
1291 TRACE("AH=%02x\n",DIOC_AH(regs));
1292 switch(DIOC_AH(regs)) /* AH */
1294 case 0x00: /* RESET DISK SYSTEM */
1295 break; /* no return ? */
1297 case 0x01: /* STATUS OF DISK SYSTEM */
1298 DIOC_AL(regs) = 0; /* successful completion */
1299 break;
1301 case 0x02: /* READ SECTORS INTO MEMORY */
1302 DIOC_AL(regs) = 0; /* number of sectors read */
1303 DIOC_AH(regs) = 0; /* status */
1304 break;
1306 case 0x03: /* WRITE SECTORS FROM MEMORY */
1307 break; /* no return ? */
1309 case 0x04: /* VERIFY DISK SECTOR(S) */
1310 DIOC_AL(regs) = 0; /* number of sectors verified */
1311 DIOC_AH(regs) = 0;
1312 break;
1314 case 0x05: /* FORMAT TRACK */
1315 case 0x06: /* FORMAT TRACK AND SET BAD SECTOR FLAGS */
1316 case 0x07: /* FORMAT DRIVE STARTING AT GIVEN TRACK */
1317 /* despite what Ralf Brown says, 0x06 and 0x07 seem to
1318 * set CFLAG, too (at least my BIOS does that) */
1319 DIOC_AH(regs) = 0x0c;
1320 DIOC_SET_CARRY(regs);
1321 break;
1323 case 0x08: /* GET DRIVE PARAMETERS */
1324 if (DIOC_DL(regs) & 0x80) { /* hard disk ? */
1325 DIOC_AH(regs) = 0x07;
1326 DIOC_SET_CARRY(regs);
1328 else /* floppy disk */
1329 VWIN32_ReadFloppyParams(regs);
1330 break;
1332 case 0x09: /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */
1333 case 0x0a: /* FIXED DISK - READ LONG (XT,AT,XT286,PS) */
1334 case 0x0b: /* FIXED DISK - WRITE LONG (XT,AT,XT286,PS) */
1335 case 0x0c: /* SEEK TO CYLINDER */
1336 case 0x0d: /* ALTERNATE RESET HARD DISKS */
1337 case 0x10: /* CHECK IF DRIVE READY */
1338 case 0x11: /* RECALIBRATE DRIVE */
1339 case 0x14: /* CONTROLLER INTERNAL DIAGNOSTIC */
1340 DIOC_AH(regs) = 0;
1341 break;
1343 case 0x15: /* GET DISK TYPE (AT,XT2,XT286,CONV,PS) */
1344 if (DIOC_DL(regs) & 0x80) { /* hard disk ? */
1345 DIOC_AH(regs) = 3; /* fixed disk */
1346 DIOC_SET_CARRY(regs);
1348 else { /* floppy disk ? */
1349 DIOC_AH(regs) = 2; /* floppy with change detection */
1350 DIOC_SET_CARRY(regs);
1352 break;
1354 case 0x0e: /* READ SECTOR BUFFER (XT only) */
1355 case 0x0f: /* WRITE SECTOR BUFFER (XT only) */
1356 case 0x12: /* CONTROLLER RAM DIAGNOSTIC (XT,PS) */
1357 case 0x13: /* DRIVE DIAGNOSTIC (XT,PS) */
1358 DIOC_AH(regs) = 0x01;
1359 DIOC_SET_CARRY(regs);
1360 break;
1362 case 0x16: /* FLOPPY - CHANGE OF DISK STATUS */
1363 DIOC_AH(regs) = 0; /* FIXME - no change */
1364 break;
1366 case 0x17: /* SET DISK TYPE FOR FORMAT */
1367 if (DIOC_DL(regs) < 4)
1368 DIOC_AH(regs) = 0x00; /* successful completion */
1369 else
1370 DIOC_AH(regs) = 0x01; /* error */
1371 break;
1373 case 0x18: /* SET MEDIA TYPE FOR FORMAT */
1374 if (DIOC_DL(regs) < 4)
1375 DIOC_AH(regs) = 0x00; /* successful completion */
1376 else
1377 DIOC_AH(regs) = 0x01; /* error */
1378 break;
1380 case 0x19: /* FIXED DISK - PARK HEADS */
1381 break;
1383 default:
1384 FIXME("Unknown VWIN32 INT13 call AX=%04X\n",DIOC_AX(regs));
1388 static BOOL DeviceIo_VWin32(DWORD dwIoControlCode,
1389 LPVOID lpvInBuffer, DWORD cbInBuffer,
1390 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1391 LPDWORD lpcbBytesReturned,
1392 LPOVERLAPPED lpOverlapped)
1394 BOOL retv = TRUE;
1396 switch (dwIoControlCode)
1398 case VWIN32_DIOC_DOS_INT13:
1400 DIOC_REGISTERS *pIn = (DIOC_REGISTERS *)lpvInBuffer;
1401 DIOC_REGISTERS *pOut = (DIOC_REGISTERS *)lpvOutBuffer;
1403 memcpy(pOut, pIn, sizeof (DIOC_REGISTERS));
1404 VWIN32_Int13Handler(pOut);
1405 break;
1408 case VWIN32_DIOC_DOS_IOCTL:
1409 case VWIN32_DIOC_DOS_INT25:
1410 case VWIN32_DIOC_DOS_INT26:
1411 case VWIN32_DIOC_DOS_DRIVEINFO:
1413 CONTEXT86 cxt;
1414 DIOC_REGISTERS *pIn = (DIOC_REGISTERS *)lpvInBuffer;
1415 DIOC_REGISTERS *pOut = (DIOC_REGISTERS *)lpvOutBuffer;
1417 TRACE( "Control '%s': "
1418 "eax=0x%08lx, ebx=0x%08lx, ecx=0x%08lx, "
1419 "edx=0x%08lx, esi=0x%08lx, edi=0x%08lx \n",
1420 (dwIoControlCode == VWIN32_DIOC_DOS_IOCTL)? "VWIN32_DIOC_DOS_IOCTL" :
1421 (dwIoControlCode == VWIN32_DIOC_DOS_INT25)? "VWIN32_DIOC_DOS_INT25" :
1422 (dwIoControlCode == VWIN32_DIOC_DOS_INT26)? "VWIN32_DIOC_DOS_INT26" :
1423 (dwIoControlCode == VWIN32_DIOC_DOS_DRIVEINFO)? "VWIN32_DIOC_DOS_DRIVEINFO" : "???",
1424 pIn->reg_EAX, pIn->reg_EBX, pIn->reg_ECX,
1425 pIn->reg_EDX, pIn->reg_ESI, pIn->reg_EDI );
1427 DIOCRegs_2_CONTEXT( pIn, &cxt );
1429 switch (dwIoControlCode)
1431 case VWIN32_DIOC_DOS_IOCTL: DOS3Call( &cxt ); break; /* Call int 21h */
1432 case VWIN32_DIOC_DOS_INT25: INT_Int25Handler( &cxt ); break;
1433 case VWIN32_DIOC_DOS_INT26: INT_Int26Handler( &cxt ); break;
1434 case VWIN32_DIOC_DOS_DRIVEINFO: DOS3Call( &cxt ); break; /* Call int 21h 730x */
1437 CONTEXT_2_DIOCRegs( &cxt, pOut );
1439 break;
1441 case VWIN32_DIOC_SIMCTRLC:
1442 FIXME( "Control VWIN32_DIOC_SIMCTRLC not implemented\n");
1443 retv = FALSE;
1444 break;
1446 default:
1447 FIXME( "Unknown Control %ld\n", dwIoControlCode);
1448 retv = FALSE;
1449 break;
1452 return retv;
1455 /* this is the main multimedia device loader */
1456 static BOOL DeviceIo_MMDEVLDR(DWORD dwIoControlCode,
1457 LPVOID lpvInBuffer, DWORD cbInBuffer,
1458 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1459 LPDWORD lpcbBytesReturned,
1460 LPOVERLAPPED lpOverlapped)
1462 FIXME("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
1463 dwIoControlCode,
1464 lpvInBuffer,cbInBuffer,
1465 lpvOutBuffer,cbOutBuffer,
1466 lpcbBytesReturned,
1467 lpOverlapped
1469 switch (dwIoControlCode) {
1470 case 5:
1471 /* Hmm. */
1472 *(DWORD*)lpvOutBuffer=0;
1473 *lpcbBytesReturned=4;
1474 return TRUE;
1476 return FALSE;
1478 /* this is used by some Origin games */
1479 static BOOL DeviceIo_MONODEBG(DWORD dwIoControlCode,
1480 LPVOID lpvInBuffer, DWORD cbInBuffer,
1481 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1482 LPDWORD lpcbBytesReturned,
1483 LPOVERLAPPED lpOverlapped)
1485 switch (dwIoControlCode) {
1486 case 1: /* version */
1487 *(LPDWORD)lpvOutBuffer = 0x20004; /* WC SecretOps */
1488 break;
1489 case 9: /* debug output */
1490 ERR("MONODEBG: %s\n",debugstr_a(lpvInBuffer));
1491 break;
1492 default:
1493 FIXME("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
1494 dwIoControlCode,
1495 lpvInBuffer,cbInBuffer,
1496 lpvOutBuffer,cbOutBuffer,
1497 lpcbBytesReturned,
1498 lpOverlapped
1500 break;
1502 return TRUE;
1504 /* pccard */
1505 static BOOL DeviceIo_PCCARD (DWORD dwIoControlCode,
1506 LPVOID lpvInBuffer, DWORD cbInBuffer,
1507 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1508 LPDWORD lpcbBytesReturned,
1509 LPOVERLAPPED lpOverlapped)
1511 switch (dwIoControlCode) {
1512 case 0x0000: /* PCCARD_Get_Version */
1513 case 0x0001: /* PCCARD_Card_Services */
1514 default:
1515 FIXME( "(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
1516 dwIoControlCode,
1517 lpvInBuffer,cbInBuffer,
1518 lpvOutBuffer,cbOutBuffer,
1519 lpcbBytesReturned,
1520 lpOverlapped
1522 break;
1524 return FALSE;
1527 /***********************************************************************
1528 * OpenVxDHandle (KERNEL32.@)
1530 DWORD WINAPI OpenVxDHandle(DWORD pmt)
1532 FIXME( "(0x%08lx) stub!\n", pmt);
1533 return 0;
1536 static BOOL DeviceIo_HASP(DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer,
1537 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1538 LPDWORD lpcbBytesReturned,
1539 LPOVERLAPPED lpOverlapped)
1541 BOOL retv = TRUE;
1542 FIXME("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
1543 dwIoControlCode,
1544 lpvInBuffer,cbInBuffer,
1545 lpvOutBuffer,cbOutBuffer,
1546 lpcbBytesReturned,
1547 lpOverlapped);
1549 return retv;