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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef __WINE_DOSEXE_H
22 #define __WINE_DOSEXE_H
25 #include <sys/types.h>
28 #include "wine/library.h"
29 #include "wine/windef16.h"
31 #include "winnt.h" /* for PCONTEXT */
32 #include "wincon.h" /* for MOUSE_EVENT_RECORD */
34 #define MAX_DOS_DRIVES 26
43 extern pid_t dosvm_pid;
45 /* amount of space reserved for relay stack */
46 #define DOSVM_RELAY_DATA_SIZE 4096
48 /* various real-mode code stubs */
61 /* 48-bit segmented pointers for DOS DPMI32 */
65 } SEGPTR48, FARPROC48;
67 typedef void (*DOSRELAY)(CONTEXT*,void*);
68 typedef void (WINAPI *RMCBPROC)(CONTEXT*);
69 typedef void (WINAPI *INTPROC)(CONTEXT*);
71 #define DOS_PRIORITY_REALTIME 0 /* IRQ0 */
72 #define DOS_PRIORITY_KEYBOARD 1 /* IRQ1 */
73 #define DOS_PRIORITY_VGA 2 /* IRQ9 */
74 #define DOS_PRIORITY_MOUSE 5 /* IRQ12 */
75 #define DOS_PRIORITY_SERIAL 10 /* IRQ4 */
77 extern WORD DOSVM_psp; /* psp of current DOS task */
78 extern WORD DOSVM_retval; /* return value of previous DOS task */
79 extern struct DPMI_segments *DOSVM_dpmi_segments;
81 #if defined(linux) && defined(__i386__) && defined(HAVE_SYS_VM86_H)
83 #endif /* linux-i386 */
86 * Declare some CONTEXT.EFlags bits.
87 * IF_MASK is only pushed into real mode stack.
89 #define V86_FLAG 0x00020000
90 #define TF_MASK 0x00000100
91 #define IF_MASK 0x00000200
92 #define VIF_MASK 0x00080000
93 #define VIP_MASK 0x00100000
95 #define ADD_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD((DWORD)(dw)+(val)))
97 #define PTR_REAL_TO_LIN(seg,off) ((void*)(((unsigned int)(seg) << 4) + LOWORD(off)))
99 /* NOTE: Interrupts might get called from four modes: real mode, 16-bit,
100 * 32-bit segmented (DPMI32) and 32-bit linear (via DeviceIoControl).
101 * For automatic conversion of pointer
102 * parameters, interrupt handlers should use CTX_SEG_OFF_TO_LIN with
103 * the contents of a segment register as second and the contents of
104 * a *32-bit* general register as third parameter, e.g.
105 * CTX_SEG_OFF_TO_LIN( context, DS_reg(context), EDX_reg(context) )
106 * This will generate a linear pointer in all three cases:
107 * Real-Mode: Seg*16 + LOWORD(Offset)
108 * 16-bit: convert (Seg, LOWORD(Offset)) to linear
109 * 32-bit segmented: convert (Seg, Offset) to linear
110 * 32-bit linear: use Offset as linear address (DeviceIoControl!)
112 * Real-mode is recognized by checking the V86 bit in the flags register,
113 * 32-bit linear mode is recognized by checking whether 'seg' is
114 * a system selector (0 counts also as 32-bit segment) and 32-bit
115 * segmented mode is recognized by checking whether 'seg' is 32-bit
116 * selector which is neither system selector nor zero.
118 #define CTX_SEG_OFF_TO_LIN(context,seg,off) \
119 (ISV86(context) ? PTR_REAL_TO_LIN((seg),(off)) : wine_ldt_get_ptr((seg),(off)))
121 #define INT_BARF(context,num) \
122 ERR( "int%x: unknown/not implemented parameters:\n" \
123 "int%x: AX %04x, BX %04x, CX %04x, DX %04x, " \
124 "SI %04x, DI %04x, DS %04x, ES %04x\n", \
125 (num), (num), LOWORD((context)->Eax), LOWORD((context)->Ebx), \
126 LOWORD((context)->Ecx), LOWORD((context)->Edx), LOWORD((context)->Esi), \
127 LOWORD((context)->Edi), (WORD)(context)->SegDs, (WORD)(context)->SegEs )
129 /* pushing on stack in 16 bit needs segment wrap around */
130 #define PUSH_WORD16(context,val) \
131 *((WORD*)CTX_SEG_OFF_TO_LIN((context), \
132 (context)->SegSs, ADD_LOWORD( context->Esp, -2 ) )) = (val)
134 /* Macros for easier access to i386 context registers */
136 #define AX_reg(context) ((WORD)(context)->Eax)
137 #define BX_reg(context) ((WORD)(context)->Ebx)
138 #define CX_reg(context) ((WORD)(context)->Ecx)
139 #define DX_reg(context) ((WORD)(context)->Edx)
140 #define SI_reg(context) ((WORD)(context)->Esi)
141 #define DI_reg(context) ((WORD)(context)->Edi)
143 #define AL_reg(context) ((BYTE)(context)->Eax)
144 #define AH_reg(context) ((BYTE)((context)->Eax >> 8))
145 #define BL_reg(context) ((BYTE)(context)->Ebx)
146 #define BH_reg(context) ((BYTE)((context)->Ebx >> 8))
147 #define CL_reg(context) ((BYTE)(context)->Ecx)
148 #define CH_reg(context) ((BYTE)((context)->Ecx >> 8))
149 #define DL_reg(context) ((BYTE)(context)->Edx)
150 #define DH_reg(context) ((BYTE)((context)->Edx >> 8))
152 #define SET_CFLAG(context) ((context)->EFlags |= 0x0001)
153 #define RESET_CFLAG(context) ((context)->EFlags &= ~0x0001)
154 #define SET_ZFLAG(context) ((context)->EFlags |= 0x0040)
155 #define RESET_ZFLAG(context) ((context)->EFlags &= ~0x0040)
156 #define ISV86(context) ((context)->EFlags & 0x00020000)
158 #define SET_AX(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xffff) | (WORD)(val)))
159 #define SET_BX(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xffff) | (WORD)(val)))
160 #define SET_CX(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xffff) | (WORD)(val)))
161 #define SET_DX(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xffff) | (WORD)(val)))
162 #define SET_SI(context,val) ((void)((context)->Esi = ((context)->Esi & ~0xffff) | (WORD)(val)))
163 #define SET_DI(context,val) ((void)((context)->Edi = ((context)->Edi & ~0xffff) | (WORD)(val)))
165 #define SET_AL(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xff) | (BYTE)(val)))
166 #define SET_BL(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xff) | (BYTE)(val)))
167 #define SET_CL(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xff) | (BYTE)(val)))
168 #define SET_DL(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xff) | (BYTE)(val)))
170 #define SET_AH(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xff00) | (((BYTE)(val)) << 8)))
171 #define SET_BH(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xff00) | (((BYTE)(val)) << 8)))
172 #define SET_CH(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xff00) | (((BYTE)(val)) << 8)))
173 #define SET_DH(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xff00) | (((BYTE)(val)) << 8)))
175 #include <pshpack1.h>
179 WORD Com1Addr; /* 00: COM1 I/O address */
180 WORD Com2Addr; /* 02: COM2 I/O address */
181 WORD Com3Addr; /* 04: COM3 I/O address */
182 WORD Com4Addr; /* 06: COM4 I/O address */
183 WORD Lpt1Addr; /* 08: LPT1 I/O address */
184 WORD Lpt2Addr; /* 0a: LPT2 I/O address */
185 WORD Lpt3Addr; /* 0c: LPT3 I/O address */
186 WORD Lpt4Addr; /* 0e: LPT4 I/O address */
187 WORD InstalledHardware; /* 10: Installed hardware flags */
188 BYTE POSTstatus; /* 12: Power-On Self Test status */
189 WORD MemSize; /* 13: Base memory size in Kb */
190 WORD unused1; /* 15: Manufacturing test scratch pad */
191 BYTE KbdFlags1; /* 17: Keyboard flags 1 */
192 BYTE KbdFlags2; /* 18: Keyboard flags 2 */
193 BYTE unused2; /* 19: Keyboard driver workspace */
194 WORD NextKbdCharPtr; /* 1a: Next character in kbd buffer */
195 WORD FirstKbdCharPtr; /* 1c: First character in kbd buffer */
196 WORD KbdBuffer[16]; /* 1e: Keyboard buffer */
197 BYTE DisketteStatus1; /* 3e: Diskette recalibrate status */
198 BYTE DisketteStatus2; /* 3f: Diskette motor status */
199 BYTE DisketteStatus3; /* 40: Diskette motor timeout */
200 BYTE DisketteStatus4; /* 41: Diskette last operation status */
201 BYTE DiskStatus[7]; /* 42: Disk status/command bytes */
202 BYTE VideoMode; /* 49: Video mode */
203 WORD VideoColumns; /* 4a: Number of columns */
204 WORD VideoPageSize; /* 4c: Video page size in bytes */
205 WORD VideoPageStartAddr; /* 4e: Video page start address */
206 BYTE VideoCursorPos[16]; /* 50: Cursor position for 8 pages, column/row order */
207 WORD VideoCursorType; /* 60: Video cursor type */
208 BYTE VideoCurPage; /* 62: Video current page */
209 WORD VideoCtrlAddr; /* 63: Video controller address */
210 BYTE VideoReg1; /* 65: Video mode select register */
211 BYTE VideoReg2; /* 66: Video CGA palette register */
212 DWORD ResetEntry; /* 67: Warm reset entry point */
213 BYTE LastIRQ; /* 6b: Last unexpected interrupt */
214 DWORD Ticks; /* 6c: Ticks since midnight */
215 BYTE TicksOverflow; /* 70: Timer overflow if past midnight */
216 BYTE CtrlBreakFlag; /* 71: Ctrl-Break flag */
217 WORD ResetFlag; /* 72: POST Reset flag */
218 BYTE DiskOpStatus; /* 74: Last hard-disk operation status */
219 BYTE NbHardDisks; /* 75: Number of hard disks */
220 BYTE DiskCtrlByte; /* 76: Disk control byte */
221 BYTE DiskIOPort; /* 77: Disk I/O port offset */
222 BYTE LptTimeout[4]; /* 78: Timeouts for parallel ports */
223 BYTE ComTimeout[4]; /* 7c: Timeouts for serial ports */
224 WORD KbdBufferStart; /* 80: Keyboard buffer start */
225 WORD KbdBufferEnd; /* 82: Keyboard buffer end */
226 BYTE RowsOnScreenMinus1; /* 84: EGA only */
227 WORD BytesPerChar; /* 85: EGA only */
228 BYTE ModeOptions; /* 87: EGA only */
229 BYTE FeatureBitsSwitches; /* 88: EGA only */
230 BYTE VGASettings; /* 89: VGA misc settings */
231 BYTE DisplayCombination; /* 8A: VGA display combinations */
232 BYTE DiskDataRate; /* 8B: Last disk data rate selected */
237 /* Device driver header */
239 #define NONEXT ((DWORD)-1)
241 #define ATTR_STDIN 0x0001
242 #define ATTR_STDOUT 0x0002
243 #define ATTR_NUL 0x0004
244 #define ATTR_CLOCK 0x0008
245 #define ATTR_FASTCON 0x0010
246 #define ATTR_RAW 0x0020
247 #define ATTR_NOTEOF 0x0040
248 #define ATTR_DEVICE 0x0080
249 #define ATTR_REMOVABLE 0x0800
250 #define ATTR_NONIBM 0x2000 /* block devices */
251 #define ATTR_UNTILBUSY 0x2000 /* char devices */
252 #define ATTR_IOCTL 0x4000
253 #define ATTR_CHAR 0x8000
255 #include <pshpack1.h>
268 /* DOS Device requests */
271 #define CMD_MEDIACHECK 1 /* block devices */
272 #define CMD_BUILDBPB 2 /* block devices */
273 #define CMD_INIOCTL 3
274 #define CMD_INPUT 4 /* read data */
275 #define CMD_SAFEINPUT 5 /* "non-destructive input no wait", char devices */
276 #define CMD_INSTATUS 6 /* char devices */
277 #define CMD_INFLUSH 7 /* char devices */
278 #define CMD_OUTPUT 8 /* write data */
279 #define CMD_SAFEOUTPUT 9 /* write data with verify */
280 #define CMD_OUTSTATUS 10 /* char devices */
281 #define CMD_OUTFLUSH 11 /* char devices */
282 #define CMD_OUTIOCTL 12
283 #define CMD_DEVOPEN 13
284 #define CMD_DEVCLOSE 14
285 #define CMD_REMOVABLE 15 /* block devices */
286 #define CMD_UNTILBUSY 16 /* output until busy */
288 #define STAT_MASK 0x00FF
289 #define STAT_DONE 0x0100
290 #define STAT_BUSY 0x0200
291 #define STAT_ERROR 0x8000
293 #include <pshpack1.h>
296 BYTE size; /* length of header + data */
297 BYTE unit; /* unit (block devices only) */
305 BYTE media; /* media descriptor from BPB */
307 WORD count; /* byte/sector count */
308 WORD sector; /* starting sector (block devices) */
309 DWORD volume; /* volume ID (block devices) */
317 /* WINE device driver thunk from RM */
327 /* Device driver info (used for initialization) */
337 extern BOOL MZ_Exec( CONTEXT *context, LPCSTR filename, BYTE func, LPVOID paramblk );
338 extern void MZ_Exit( CONTEXT *context, BOOL cs_psp, WORD retval );
339 extern BOOL MZ_Current( void );
340 extern void MZ_AllocDPMITask( void );
341 extern void MZ_RunInThread( PAPCFUNC proc, ULONG_PTR arg );
342 extern BOOL DOSVM_IsWin16(void);
343 extern void DOSVM_Exit( WORD retval );
346 extern void DOSVM_SendQueuedEvents( CONTEXT * );
347 extern void WINAPI DOSVM_AcknowledgeIRQ( CONTEXT * );
348 extern INT DOSVM_Enter( CONTEXT *context );
349 extern void DOSVM_Wait( CONTEXT * );
350 extern DWORD DOSVM_Loop( HANDLE hThread );
351 extern void DOSVM_QueueEvent( INT irq, INT priority, DOSRELAY relay, LPVOID data );
352 extern void DOSVM_PIC_ioport_out( WORD port, BYTE val );
353 extern void DOSVM_SetTimer( UINT ticks );
354 extern LPVOID DOSVM_AllocDataUMB(DWORD, WORD *, WORD *);
355 extern void DOSVM_InitSegments(void);
358 extern void DOSDEV_InstallDOSDevices(void);
359 extern void DOSDEV_SetupDevice(const WINEDEV * devinfo,
360 WORD seg, WORD off_dev, WORD off_thunk);
361 extern void DOSDEV_SetSharingRetry(WORD delay, WORD count);
362 extern SEGPTR DOSDEV_GetLOL(BOOL v86);
365 extern int DMA_Transfer(int channel,int reqlength,void* buffer);
366 extern void DMA_ioport_out( WORD port, BYTE val );
367 extern BYTE DMA_ioport_in( WORD port );
370 extern void DOSVM_ASPIHandler(CONTEXT*);
373 extern BIOSDATA *DOSVM_BiosData( void );
374 extern void DOSVM_start_bios_timer(void);
377 extern void WINAPI DOSVM_Int34Handler(CONTEXT*);
378 extern void WINAPI DOSVM_Int35Handler(CONTEXT*);
379 extern void WINAPI DOSVM_Int36Handler(CONTEXT*);
380 extern void WINAPI DOSVM_Int37Handler(CONTEXT*);
381 extern void WINAPI DOSVM_Int38Handler(CONTEXT*);
382 extern void WINAPI DOSVM_Int39Handler(CONTEXT*);
383 extern void WINAPI DOSVM_Int3aHandler(CONTEXT*);
384 extern void WINAPI DOSVM_Int3bHandler(CONTEXT*);
385 extern void WINAPI DOSVM_Int3cHandler(CONTEXT*);
386 extern void WINAPI DOSVM_Int3dHandler(CONTEXT*);
387 extern void WINAPI DOSVM_Int3eHandler(CONTEXT*);
390 extern void WINAPI DOSVM_Int09Handler(CONTEXT*);
391 extern void DOSVM_Int09SendScan(BYTE scan,BYTE ascii);
392 extern BYTE DOSVM_Int09ReadScan(BYTE*ascii);
395 extern void WINAPI DOSVM_Int10Handler(CONTEXT*);
396 extern void DOSVM_PutChar(BYTE ascii);
399 extern void WINAPI DOSVM_Int13Handler(CONTEXT*);
402 extern void WINAPI DOSVM_Int15Handler(CONTEXT*);
405 extern void WINAPI DOSVM_Int16Handler(CONTEXT*);
406 extern BOOL DOSVM_Int16ReadChar( BYTE *, BYTE *, CONTEXT * );
407 extern int DOSVM_Int16AddChar(BYTE ascii,BYTE scan);
410 extern void WINAPI DOSVM_Int21Handler(CONTEXT*);
413 BOOL DOSVM_RawRead( BYTE, DWORD, DWORD, BYTE *, BOOL );
414 void WINAPI DOSVM_Int25Handler( CONTEXT * );
417 BOOL DOSVM_RawWrite( BYTE, DWORD, DWORD, BYTE *, BOOL );
418 void WINAPI DOSVM_Int26Handler( CONTEXT * );
421 extern void WINAPI DOSVM_Int2fHandler(CONTEXT*);
422 extern void MSCDEX_InstallCDROM(void);
425 extern void WINAPI DOSVM_Int31Handler(CONTEXT*);
426 extern void WINAPI DOSVM_RawModeSwitchHandler(CONTEXT*);
427 extern BOOL DOSVM_IsDos32(void);
428 extern FARPROC16 DPMI_AllocInternalRMCB(RMCBPROC);
429 extern int DPMI_CallRMProc(CONTEXT*,LPWORD,int,int);
430 extern BOOL DOSVM_CheckWrappers(CONTEXT*);
433 extern void WINAPI DOSVM_Int33Handler(CONTEXT*);
434 extern void DOSVM_Int33Message(UINT,WPARAM,LPARAM);
435 extern void DOSVM_Int33Console(MOUSE_EVENT_RECORD*);
438 extern void WINAPI DOSVM_Int67Handler(CONTEXT*);
439 extern void EMS_Ioctl_Handler(CONTEXT*);
442 extern void __wine_call_int_handler( CONTEXT *, BYTE );
443 extern void DOSVM_CallBuiltinHandler( CONTEXT *, BYTE );
444 extern BOOL DOSVM_EmulateInterruptPM( CONTEXT *, BYTE );
445 extern BOOL DOSVM_EmulateInterruptRM( CONTEXT *, BYTE );
446 extern FARPROC16 DOSVM_GetPMHandler16( BYTE );
447 extern FARPROC48 DOSVM_GetPMHandler48( BYTE );
448 extern FARPROC16 DOSVM_GetRMHandler( BYTE );
449 extern void DOSVM_HardwareInterruptPM( CONTEXT *, BYTE );
450 extern void DOSVM_HardwareInterruptRM( CONTEXT *, BYTE );
451 extern void DOSVM_SetPMHandler16( BYTE, FARPROC16 );
452 extern void DOSVM_SetPMHandler48( BYTE, FARPROC48 );
453 extern void DOSVM_SetRMHandler( BYTE, FARPROC16 );
456 extern DWORD DOSVM_inport( int port, int size );
457 extern void DOSVM_outport( int port, int size, DWORD value );
460 void DOSVM_RelayHandler( CONTEXT * );
461 void DOSVM_BuildCallFrame( CONTEXT *, DOSRELAY, LPVOID );
464 extern void SB_ioport_out( WORD port, BYTE val );
465 extern BYTE SB_ioport_in( WORD port );
468 extern void WINAPI DOSVM_Int08Handler(CONTEXT*);
470 #endif /* __WINE_DOSEXE_H */