2 * VWIN32 VxD implementation
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
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(vxd
);
32 extern void WINAPI
CallBuiltinHandler( CONTEXT86
*context
, BYTE intnum
); /* from winedos */
34 /* Pop a DWORD from the 32-bit stack */
35 static inline DWORD
stack32_pop( CONTEXT86
*context
)
37 DWORD ret
= *(DWORD
*)context
->Esp
;
38 context
->Esp
+= sizeof(DWORD
);
42 static void DIOCRegs_2_CONTEXT( DIOC_REGISTERS
*pIn
, CONTEXT86
*pCxt
)
44 memset( pCxt
, 0, sizeof(*pCxt
) );
45 /* Note: segment registers == 0 means that CTX_SEG_OFF_TO_LIN
46 will interpret 32-bit register contents as linear pointers */
48 pCxt
->ContextFlags
=CONTEXT86_INTEGER
|CONTEXT86_CONTROL
;
49 pCxt
->Eax
= pIn
->reg_EAX
;
50 pCxt
->Ebx
= pIn
->reg_EBX
;
51 pCxt
->Ecx
= pIn
->reg_ECX
;
52 pCxt
->Edx
= pIn
->reg_EDX
;
53 pCxt
->Esi
= pIn
->reg_ESI
;
54 pCxt
->Edi
= pIn
->reg_EDI
;
56 /* FIXME: Only partial CONTEXT86_CONTROL */
58 pCxt
->EFlags
= pIn
->reg_Flags
& ~0x00020000; /* clear vm86 mode */
61 static void CONTEXT_2_DIOCRegs( CONTEXT86
*pCxt
, DIOC_REGISTERS
*pOut
)
63 memset( pOut
, 0, sizeof(DIOC_REGISTERS
) );
65 pOut
->reg_EAX
= pCxt
->Eax
;
66 pOut
->reg_EBX
= pCxt
->Ebx
;
67 pOut
->reg_ECX
= pCxt
->Ecx
;
68 pOut
->reg_EDX
= pCxt
->Edx
;
69 pOut
->reg_ESI
= pCxt
->Esi
;
70 pOut
->reg_EDI
= pCxt
->Edi
;
72 /* FIXME: Only partial CONTEXT86_CONTROL */
73 pOut
->reg_Flags
= pCxt
->EFlags
;
76 #define DIOC_AH(regs) (((unsigned char*)&((regs)->reg_EAX))[1])
77 #define DIOC_AL(regs) (((unsigned char*)&((regs)->reg_EAX))[0])
78 #define DIOC_BH(regs) (((unsigned char*)&((regs)->reg_EBX))[1])
79 #define DIOC_BL(regs) (((unsigned char*)&((regs)->reg_EBX))[0])
80 #define DIOC_DH(regs) (((unsigned char*)&((regs)->reg_EDX))[1])
81 #define DIOC_DL(regs) (((unsigned char*)&((regs)->reg_EDX))[0])
83 #define DIOC_AX(regs) (((unsigned short*)&((regs)->reg_EAX))[0])
84 #define DIOC_BX(regs) (((unsigned short*)&((regs)->reg_EBX))[0])
85 #define DIOC_CX(regs) (((unsigned short*)&((regs)->reg_ECX))[0])
86 #define DIOC_DX(regs) (((unsigned short*)&((regs)->reg_EDX))[0])
88 #define DIOC_SET_CARRY(regs) (((regs)->reg_Flags)|=0x00000001)
90 /***********************************************************************
91 * DeviceIoControl (VWIN32.VXD.@)
93 BOOL WINAPI
VWIN32_DeviceIoControl(DWORD dwIoControlCode
,
94 LPVOID lpvInBuffer
, DWORD cbInBuffer
,
95 LPVOID lpvOutBuffer
, DWORD cbOutBuffer
,
96 LPDWORD lpcbBytesReturned
, LPOVERLAPPED lpOverlapped
)
98 switch (dwIoControlCode
)
100 case VWIN32_DIOC_DOS_IOCTL
:
101 case 0x10: /* Int 0x21 call, call it VWIN_DIOC_INT21 ? */
102 case VWIN32_DIOC_DOS_INT13
:
103 case VWIN32_DIOC_DOS_INT25
:
104 case VWIN32_DIOC_DOS_INT26
:
105 case 0x29: /* Int 0x31 call, call it VWIN_DIOC_INT31 ? */
106 case VWIN32_DIOC_DOS_DRIVEINFO
:
109 DIOC_REGISTERS
*pIn
= (DIOC_REGISTERS
*)lpvInBuffer
;
110 DIOC_REGISTERS
*pOut
= (DIOC_REGISTERS
*)lpvOutBuffer
;
113 TRACE( "Control '%s': "
114 "eax=0x%08lx, ebx=0x%08lx, ecx=0x%08lx, "
115 "edx=0x%08lx, esi=0x%08lx, edi=0x%08lx \n",
116 (dwIoControlCode
== VWIN32_DIOC_DOS_IOCTL
)? "VWIN32_DIOC_DOS_IOCTL" :
117 (dwIoControlCode
== VWIN32_DIOC_DOS_INT25
)? "VWIN32_DIOC_DOS_INT25" :
118 (dwIoControlCode
== VWIN32_DIOC_DOS_INT26
)? "VWIN32_DIOC_DOS_INT26" :
119 (dwIoControlCode
== VWIN32_DIOC_DOS_DRIVEINFO
)? "VWIN32_DIOC_DOS_DRIVEINFO" : "???",
120 pIn
->reg_EAX
, pIn
->reg_EBX
, pIn
->reg_ECX
,
121 pIn
->reg_EDX
, pIn
->reg_ESI
, pIn
->reg_EDI
);
123 DIOCRegs_2_CONTEXT( pIn
, &cxt
);
125 switch (dwIoControlCode
)
127 case VWIN32_DIOC_DOS_IOCTL
: /* Call int 21h */
128 case 0x10: /* Int 0x21 call, call it VWIN_DIOC_INT21 ? */
129 case VWIN32_DIOC_DOS_DRIVEINFO
: /* Call int 21h 730x */
132 case VWIN32_DIOC_DOS_INT13
:
135 case VWIN32_DIOC_DOS_INT25
:
138 case VWIN32_DIOC_DOS_INT26
:
141 case 0x29: /* Int 0x31 call, call it VWIN_DIOC_INT31 ? */
146 CallBuiltinHandler( &cxt
, intnum
);
147 CONTEXT_2_DIOCRegs( &cxt
, pOut
);
151 case VWIN32_DIOC_SIMCTRLC
:
152 FIXME( "Control VWIN32_DIOC_SIMCTRLC not implemented\n");
156 FIXME( "Unknown Control %ld\n", dwIoControlCode
);
162 /***********************************************************************
163 * VxDCall (VWIN32.VXD.@)
165 * Service numbers taken from page 448 of Pietrek's "Windows 95 System
166 * Programming Secrets". Parameters from experimentation on real Win98.
169 DWORD WINAPI
VWIN32_VxDCall( DWORD service
, CONTEXT86
*context
)
171 switch ( LOWORD(service
) )
173 case 0x0000: /* GetVersion */
175 DWORD vers
= GetVersion();
176 return (LOBYTE(vers
) << 8) | HIBYTE(vers
);
178 case 0x0020: /* Get VMCPD Version */
180 DWORD parm
= stack32_pop(context
);
182 FIXME("Get VMCPD Version(%08lx): partial stub!\n", parm
);
184 /* FIXME: This is what Win98 returns, it may
185 * not be correct in all situations.
186 * It makes Bleem! happy though.
190 case 0x0029: /* Int31/DPMI dispatch */
192 DWORD callnum
= stack32_pop(context
);
193 DWORD parm
= stack32_pop(context
);
195 TRACE("Int31/DPMI dispatch(%08lx)\n", callnum
);
197 context
->Eax
= callnum
;
199 CallBuiltinHandler( context
, 0x31 );
200 return LOWORD(context
->Eax
);
202 case 0x002a: /* Int41 dispatch - parm = int41 service number */
204 DWORD callnum
= stack32_pop(context
);
205 return callnum
; /* FIXME: should really call INT_Int41Handler() */
208 FIXME("Unknown service %08lx\n", service
);