4 * Copyright 1998 Ove Kåven
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef __WINE_DOSEXE_H
22 #define __WINE_DOSEXE_H
27 #include "wine/windef16.h"
29 #include "winnt.h" /* for PCONTEXT */
30 #include "wincon.h" /* for MOUSE_EVENT_RECORD */
33 #define MAX_DOS_DRIVES 26
37 /* amount of space reserved for relay stack */
38 #define DOSVM_RELAY_DATA_SIZE 4096
40 /* various real-mode code stubs */
53 /* 48-bit segmented pointers for DOS DPMI32 */
57 } SEGPTR48, FARPROC48;
59 #define DOSCONF_MEM_HIGH 0x0001
60 #define DOSCONF_MEM_UMB 0x0002
61 #define DOSCONF_NUMLOCK 0x0004
62 #define DOSCONF_KEYB_CONV 0x0008
78 typedef void (*DOSRELAY)(CONTEXT86*,void*);
79 typedef void (WINAPI *RMCBPROC)(CONTEXT86*);
80 typedef void (WINAPI *INTPROC)(CONTEXT86*);
82 #define DOS_PRIORITY_REALTIME 0 /* IRQ0 */
83 #define DOS_PRIORITY_KEYBOARD 1 /* IRQ1 */
84 #define DOS_PRIORITY_VGA 2 /* IRQ9 */
85 #define DOS_PRIORITY_MOUSE 5 /* IRQ12 */
86 #define DOS_PRIORITY_SERIAL 10 /* IRQ4 */
88 extern WORD DOSVM_psp; /* psp of current DOS task */
89 extern WORD DOSVM_retval; /* return value of previous DOS task */
90 extern struct DPMI_segments *DOSVM_dpmi_segments;
92 #if defined(linux) && defined(__i386__) && defined(HAVE_SYS_VM86_H)
94 #endif /* linux-i386 */
97 * Declare some CONTEXT86.EFlags bits.
98 * IF_MASK is only pushed into real mode stack.
100 #define V86_FLAG 0x00020000
101 #define IF_MASK 0x00000200
102 #define VIF_MASK 0x00080000
103 #define VIP_MASK 0x00100000
105 #define ADD_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD((DWORD)(dw)+(val)))
107 #define PTR_REAL_TO_LIN(seg,off) ((void*)(((unsigned int)(seg) << 4) + LOWORD(off)))
109 /* NOTE: Interrupts might get called from four modes: real mode, 16-bit,
110 * 32-bit segmented (DPMI32) and 32-bit linear (via DeviceIoControl).
111 * For automatic conversion of pointer
112 * parameters, interrupt handlers should use CTX_SEG_OFF_TO_LIN with
113 * the contents of a segment register as second and the contents of
114 * a *32-bit* general register as third parameter, e.g.
115 * CTX_SEG_OFF_TO_LIN( context, DS_reg(context), EDX_reg(context) )
116 * This will generate a linear pointer in all three cases:
117 * Real-Mode: Seg*16 + LOWORD(Offset)
118 * 16-bit: convert (Seg, LOWORD(Offset)) to linear
119 * 32-bit segmented: convert (Seg, Offset) to linear
120 * 32-bit linear: use Offset as linear address (DeviceIoControl!)
122 * Real-mode is recognized by checking the V86 bit in the flags register,
123 * 32-bit linear mode is recognized by checking whether 'seg' is
124 * a system selector (0 counts also as 32-bit segment) and 32-bit
125 * segmented mode is recognized by checking whether 'seg' is 32-bit
126 * selector which is neither system selector nor zero.
128 #define CTX_SEG_OFF_TO_LIN(context,seg,off) \
129 (ISV86(context) ? PTR_REAL_TO_LIN((seg),(off)) : wine_ldt_get_ptr((seg),(off)))
131 #define INT_BARF(context,num) \
132 ERR( "int%x: unknown/not implemented parameters:\n" \
133 "int%x: AX %04x, BX %04x, CX %04x, DX %04x, " \
134 "SI %04x, DI %04x, DS %04x, ES %04x\n", \
135 (num), (num), LOWORD((context)->Eax), LOWORD((context)->Ebx), \
136 LOWORD((context)->Ecx), LOWORD((context)->Edx), LOWORD((context)->Esi), \
137 LOWORD((context)->Edi), (WORD)(context)->SegDs, (WORD)(context)->SegEs )
139 /* Macros for easier access to i386 context registers */
141 #define AX_reg(context) ((WORD)(context)->Eax)
142 #define BX_reg(context) ((WORD)(context)->Ebx)
143 #define CX_reg(context) ((WORD)(context)->Ecx)
144 #define DX_reg(context) ((WORD)(context)->Edx)
145 #define SI_reg(context) ((WORD)(context)->Esi)
146 #define DI_reg(context) ((WORD)(context)->Edi)
148 #define AL_reg(context) ((BYTE)(context)->Eax)
149 #define AH_reg(context) ((BYTE)((context)->Eax >> 8))
150 #define BL_reg(context) ((BYTE)(context)->Ebx)
151 #define BH_reg(context) ((BYTE)((context)->Ebx >> 8))
152 #define CL_reg(context) ((BYTE)(context)->Ecx)
153 #define CH_reg(context) ((BYTE)((context)->Ecx >> 8))
154 #define DL_reg(context) ((BYTE)(context)->Edx)
155 #define DH_reg(context) ((BYTE)((context)->Edx >> 8))
157 #define SET_CFLAG(context) ((context)->EFlags |= 0x0001)
158 #define RESET_CFLAG(context) ((context)->EFlags &= ~0x0001)
159 #define SET_ZFLAG(context) ((context)->EFlags |= 0x0040)
160 #define RESET_ZFLAG(context) ((context)->EFlags &= ~0x0040)
161 #define ISV86(context) ((context)->EFlags & 0x00020000)
163 #define SET_AX(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xffff) | (WORD)(val)))
164 #define SET_BX(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xffff) | (WORD)(val)))
165 #define SET_CX(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xffff) | (WORD)(val)))
166 #define SET_DX(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xffff) | (WORD)(val)))
167 #define SET_SI(context,val) ((void)((context)->Esi = ((context)->Esi & ~0xffff) | (WORD)(val)))
168 #define SET_DI(context,val) ((void)((context)->Edi = ((context)->Edi & ~0xffff) | (WORD)(val)))
170 #define SET_AL(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xff) | (BYTE)(val)))
171 #define SET_BL(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xff) | (BYTE)(val)))
172 #define SET_CL(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xff) | (BYTE)(val)))
173 #define SET_DL(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xff) | (BYTE)(val)))
175 #define SET_AH(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xff00) | (((BYTE)(val)) << 8)))
176 #define SET_BH(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xff00) | (((BYTE)(val)) << 8)))
177 #define SET_CH(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xff00) | (((BYTE)(val)) << 8)))
178 #define SET_DH(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xff00) | (((BYTE)(val)) << 8)))
181 extern void WINAPI MZ_LoadImage( LPCSTR filename, HANDLE hFile );
182 extern BOOL WINAPI MZ_Exec( CONTEXT86 *context, LPCSTR filename, BYTE func, LPVOID paramblk );
183 extern void WINAPI MZ_Exit( CONTEXT86 *context, BOOL cs_psp, WORD retval );
184 extern BOOL WINAPI MZ_Current( void );
185 extern void WINAPI MZ_AllocDPMITask( void );
186 extern void WINAPI MZ_RunInThread( PAPCFUNC proc, ULONG_PTR arg );
187 extern BOOL DOSVM_IsWin16(void);
190 extern void DOSVM_SendQueuedEvents( CONTEXT86 * );
191 extern void WINAPI DOSVM_AcknowledgeIRQ( CONTEXT86 * );
192 extern INT WINAPI DOSVM_Enter( CONTEXT86 *context );
193 extern void WINAPI DOSVM_Wait( CONTEXT86 * );
194 extern DWORD WINAPI DOSVM_Loop( HANDLE hThread );
195 extern void WINAPI DOSVM_QueueEvent( INT irq, INT priority, DOSRELAY relay, LPVOID data );
196 extern void WINAPI DOSVM_PIC_ioport_out( WORD port, BYTE val );
197 extern void WINAPI DOSVM_SetTimer( UINT ticks );
198 extern UINT WINAPI DOSVM_GetTimer( void );
199 extern BIOSDATA *DOSVM_BiosData( void );
202 extern void DOSDEV_InstallDOSDevices(void);
203 extern DWORD DOSDEV_Console(void);
204 extern DWORD DOSDEV_FindCharDevice(char*name);
205 extern int DOSDEV_Peek(DWORD dev, BYTE*data);
206 extern int DOSDEV_Read(DWORD dev, DWORD buf, int buflen);
207 extern int DOSDEV_Write(DWORD dev, DWORD buf, int buflen, int verify);
208 extern int DOSDEV_IoctlRead(DWORD dev, DWORD buf, int buflen);
209 extern int DOSDEV_IoctlWrite(DWORD dev, DWORD buf, int buflen);
210 extern void DOSDEV_SetSharingRetry(WORD delay, WORD count);
211 extern SEGPTR DOSDEV_GetLOL(BOOL v86);
214 extern int DMA_Transfer(int channel,int reqlength,void* buffer);
215 extern void DMA_ioport_out( WORD port, BYTE val );
216 extern BYTE DMA_ioport_in( WORD port );
219 void WINAPI DOSVM_ASPIHandler(CONTEXT86*);
222 DOSCONF *DOSCONF_GetConfig( void );
225 extern void WINAPI DOSVM_Int34Handler(CONTEXT86*);
226 extern void WINAPI DOSVM_Int35Handler(CONTEXT86*);
227 extern void WINAPI DOSVM_Int36Handler(CONTEXT86*);
228 extern void WINAPI DOSVM_Int37Handler(CONTEXT86*);
229 extern void WINAPI DOSVM_Int38Handler(CONTEXT86*);
230 extern void WINAPI DOSVM_Int39Handler(CONTEXT86*);
231 extern void WINAPI DOSVM_Int3aHandler(CONTEXT86*);
232 extern void WINAPI DOSVM_Int3bHandler(CONTEXT86*);
233 extern void WINAPI DOSVM_Int3cHandler(CONTEXT86*);
234 extern void WINAPI DOSVM_Int3dHandler(CONTEXT86*);
235 extern void WINAPI DOSVM_Int3eHandler(CONTEXT86*);
238 extern void DOSVM_InitSegments(void);
239 extern LPVOID DOSVM_AllocUMB(DWORD);
240 extern LPVOID DOSVM_AllocCodeUMB(DWORD, WORD *, WORD *);
241 extern LPVOID DOSVM_AllocDataUMB(DWORD, WORD *, WORD *);
244 extern void WINAPI DOSVM_Int09Handler(CONTEXT86*);
245 extern void WINAPI DOSVM_Int09SendScan(BYTE scan,BYTE ascii);
246 extern BYTE WINAPI DOSVM_Int09ReadScan(BYTE*ascii);
249 extern void WINAPI DOSVM_Int10Handler(CONTEXT86*);
250 extern void WINAPI DOSVM_PutChar(BYTE ascii);
253 extern void WINAPI DOSVM_Int11Handler(CONTEXT86*);
256 extern void WINAPI DOSVM_Int12Handler(CONTEXT86*);
259 extern void WINAPI DOSVM_Int13Handler(CONTEXT86*);
262 extern void WINAPI DOSVM_Int15Handler(CONTEXT86*);
265 extern void WINAPI DOSVM_Int1aHandler(CONTEXT86*);
268 extern void WINAPI DOSVM_Int16Handler(CONTEXT86*);
269 extern BOOL WINAPI DOSVM_Int16ReadChar( BYTE *, BYTE *, CONTEXT86 * );
270 extern int WINAPI DOSVM_Int16AddChar(BYTE ascii,BYTE scan);
273 extern void WINAPI DOSVM_Int17Handler(CONTEXT86*);
276 extern void WINAPI DOSVM_Int19Handler(CONTEXT86*);
279 extern void WINAPI DOSVM_Int20Handler(CONTEXT86*);
282 extern void WINAPI DOSVM_Int21Handler(CONTEXT86*);
285 BOOL DOSVM_RawRead( BYTE, DWORD, DWORD, BYTE *, BOOL );
286 void WINAPI DOSVM_Int25Handler( CONTEXT86 * );
289 BOOL DOSVM_RawWrite( BYTE, DWORD, DWORD, BYTE *, BOOL );
290 void WINAPI DOSVM_Int26Handler( CONTEXT86 * );
293 extern void WINAPI DOSVM_Int29Handler(CONTEXT86*);
296 extern void WINAPI DOSVM_Int2aHandler(CONTEXT86*);
299 extern void WINAPI DOSVM_Int2fHandler(CONTEXT86*);
302 extern void WINAPI DOSVM_Int31Handler(CONTEXT86*);
303 extern void WINAPI DOSVM_RawModeSwitchHandler(CONTEXT86*);
304 extern BOOL DOSVM_IsDos32(void);
305 extern FARPROC16 WINAPI DPMI_AllocInternalRMCB(RMCBPROC);
306 extern void WINAPI DPMI_FreeInternalRMCB(FARPROC16);
307 extern int DPMI_CallRMProc(CONTEXT86*,LPWORD,int,int);
308 extern BOOL DOSVM_CheckWrappers(CONTEXT86*);
311 extern void WINAPI DOSVM_Int33Handler(CONTEXT86*);
312 extern void WINAPI DOSVM_Int33Message(UINT,WPARAM,LPARAM);
313 extern void WINAPI DOSVM_Int33Console(MOUSE_EVENT_RECORD*);
316 extern void WINAPI DOSVM_Int41Handler(CONTEXT86*);
319 extern void WINAPI DOSVM_Int4bHandler(CONTEXT86*);
322 extern void WINAPI DOSVM_Int5cHandler(CONTEXT86*);
325 extern void WINAPI DOSVM_Int67Handler(CONTEXT86*);
326 extern void WINAPI EMS_Ioctl_Handler(CONTEXT86*);
329 extern void WINAPI DOSVM_CallBuiltinHandler( CONTEXT86 *, BYTE );
330 extern void WINAPI DOSVM_EmulateInterruptPM( CONTEXT86 *, BYTE );
331 extern BOOL WINAPI DOSVM_EmulateInterruptRM( CONTEXT86 *, BYTE );
332 extern FARPROC16 DOSVM_GetPMHandler16( BYTE );
333 extern FARPROC48 DOSVM_GetPMHandler48( BYTE );
334 extern FARPROC16 DOSVM_GetRMHandler( BYTE );
335 extern void DOSVM_HardwareInterruptPM( CONTEXT86 *, BYTE );
336 extern void DOSVM_HardwareInterruptRM( CONTEXT86 *, BYTE );
337 extern void DOSVM_SetPMHandler16( BYTE, FARPROC16 );
338 extern void DOSVM_SetPMHandler48( BYTE, FARPROC48 );
339 extern void DOSVM_SetRMHandler( BYTE, FARPROC16 );
342 void DOSVM_RelayHandler( CONTEXT86 * );
343 void DOSVM_BuildCallFrame( CONTEXT86 *, DOSRELAY, LPVOID );
346 extern void SB_ioport_out( WORD port, BYTE val );
347 extern BYTE SB_ioport_in( WORD port );
350 extern BOOL IO_pp_outp(int port, DWORD* res);
351 extern int IO_pp_inp(int port, DWORD* res);
352 extern char IO_pp_init(void);
355 extern void WINAPI DOSVM_Int08Handler(CONTEXT86*);
358 extern void WINAPI XMS_Handler(CONTEXT86*);
360 #endif /* __WINE_DOSEXE_H */