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
27 #include "wine/library.h"
28 #include "wine/windef16.h"
30 #include "winnt.h" /* for PCONTEXT */
31 #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 TF_MASK 0x00000100
102 #define IF_MASK 0x00000200
103 #define VIF_MASK 0x00080000
104 #define VIP_MASK 0x00100000
106 #define ADD_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD((DWORD)(dw)+(val)))
108 #define PTR_REAL_TO_LIN(seg,off) ((void*)(((unsigned int)(seg) << 4) + LOWORD(off)))
110 /* NOTE: Interrupts might get called from four modes: real mode, 16-bit,
111 * 32-bit segmented (DPMI32) and 32-bit linear (via DeviceIoControl).
112 * For automatic conversion of pointer
113 * parameters, interrupt handlers should use CTX_SEG_OFF_TO_LIN with
114 * the contents of a segment register as second and the contents of
115 * a *32-bit* general register as third parameter, e.g.
116 * CTX_SEG_OFF_TO_LIN( context, DS_reg(context), EDX_reg(context) )
117 * This will generate a linear pointer in all three cases:
118 * Real-Mode: Seg*16 + LOWORD(Offset)
119 * 16-bit: convert (Seg, LOWORD(Offset)) to linear
120 * 32-bit segmented: convert (Seg, Offset) to linear
121 * 32-bit linear: use Offset as linear address (DeviceIoControl!)
123 * Real-mode is recognized by checking the V86 bit in the flags register,
124 * 32-bit linear mode is recognized by checking whether 'seg' is
125 * a system selector (0 counts also as 32-bit segment) and 32-bit
126 * segmented mode is recognized by checking whether 'seg' is 32-bit
127 * selector which is neither system selector nor zero.
129 #define CTX_SEG_OFF_TO_LIN(context,seg,off) \
130 (ISV86(context) ? PTR_REAL_TO_LIN((seg),(off)) : wine_ldt_get_ptr((seg),(off)))
132 #define INT_BARF(context,num) \
133 ERR( "int%x: unknown/not implemented parameters:\n" \
134 "int%x: AX %04x, BX %04x, CX %04x, DX %04x, " \
135 "SI %04x, DI %04x, DS %04x, ES %04x\n", \
136 (num), (num), LOWORD((context)->Eax), LOWORD((context)->Ebx), \
137 LOWORD((context)->Ecx), LOWORD((context)->Edx), LOWORD((context)->Esi), \
138 LOWORD((context)->Edi), (WORD)(context)->SegDs, (WORD)(context)->SegEs )
140 /* pushing on stack in 16 bit needs segment wrap around */
141 #define PUSH_WORD16(context,val) \
142 *((WORD*)CTX_SEG_OFF_TO_LIN((context), \
143 (context)->SegSs, ADD_LOWORD( context->Esp, -2 ) )) = (val)
145 /* Macros for easier access to i386 context registers */
147 #define AX_reg(context) ((WORD)(context)->Eax)
148 #define BX_reg(context) ((WORD)(context)->Ebx)
149 #define CX_reg(context) ((WORD)(context)->Ecx)
150 #define DX_reg(context) ((WORD)(context)->Edx)
151 #define SI_reg(context) ((WORD)(context)->Esi)
152 #define DI_reg(context) ((WORD)(context)->Edi)
154 #define AL_reg(context) ((BYTE)(context)->Eax)
155 #define AH_reg(context) ((BYTE)((context)->Eax >> 8))
156 #define BL_reg(context) ((BYTE)(context)->Ebx)
157 #define BH_reg(context) ((BYTE)((context)->Ebx >> 8))
158 #define CL_reg(context) ((BYTE)(context)->Ecx)
159 #define CH_reg(context) ((BYTE)((context)->Ecx >> 8))
160 #define DL_reg(context) ((BYTE)(context)->Edx)
161 #define DH_reg(context) ((BYTE)((context)->Edx >> 8))
163 #define SET_CFLAG(context) ((context)->EFlags |= 0x0001)
164 #define RESET_CFLAG(context) ((context)->EFlags &= ~0x0001)
165 #define SET_ZFLAG(context) ((context)->EFlags |= 0x0040)
166 #define RESET_ZFLAG(context) ((context)->EFlags &= ~0x0040)
167 #define ISV86(context) ((context)->EFlags & 0x00020000)
169 #define SET_AX(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xffff) | (WORD)(val)))
170 #define SET_BX(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xffff) | (WORD)(val)))
171 #define SET_CX(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xffff) | (WORD)(val)))
172 #define SET_DX(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xffff) | (WORD)(val)))
173 #define SET_SI(context,val) ((void)((context)->Esi = ((context)->Esi & ~0xffff) | (WORD)(val)))
174 #define SET_DI(context,val) ((void)((context)->Edi = ((context)->Edi & ~0xffff) | (WORD)(val)))
176 #define SET_AL(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xff) | (BYTE)(val)))
177 #define SET_BL(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xff) | (BYTE)(val)))
178 #define SET_CL(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xff) | (BYTE)(val)))
179 #define SET_DL(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xff) | (BYTE)(val)))
181 #define SET_AH(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xff00) | (((BYTE)(val)) << 8)))
182 #define SET_BH(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xff00) | (((BYTE)(val)) << 8)))
183 #define SET_CH(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xff00) | (((BYTE)(val)) << 8)))
184 #define SET_DH(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xff00) | (((BYTE)(val)) << 8)))
186 #include <pshpack1.h>
190 WORD Com1Addr
; /* 00: COM1 I/O address */
191 WORD Com2Addr
; /* 02: COM2 I/O address */
192 WORD Com3Addr
; /* 04: COM3 I/O address */
193 WORD Com4Addr
; /* 06: COM4 I/O address */
194 WORD Lpt1Addr
; /* 08: LPT1 I/O address */
195 WORD Lpt2Addr
; /* 0a: LPT2 I/O address */
196 WORD Lpt3Addr
; /* 0c: LPT3 I/O address */
197 WORD Lpt4Addr
; /* 0e: LPT4 I/O address */
198 WORD InstalledHardware
; /* 10: Installed hardware flags */
199 BYTE POSTstatus
; /* 12: Power-On Self Test status */
200 WORD MemSize
; /* 13: Base memory size in Kb */
201 WORD unused1
; /* 15: Manufacturing test scratch pad */
202 BYTE KbdFlags1
; /* 17: Keyboard flags 1 */
203 BYTE KbdFlags2
; /* 18: Keyboard flags 2 */
204 BYTE unused2
; /* 19: Keyboard driver workspace */
205 WORD NextKbdCharPtr
; /* 1a: Next character in kbd buffer */
206 WORD FirstKbdCharPtr
; /* 1c: First character in kbd buffer */
207 WORD KbdBuffer
[16]; /* 1e: Keyboard buffer */
208 BYTE DisketteStatus1
; /* 3e: Diskette recalibrate status */
209 BYTE DisketteStatus2
; /* 3f: Diskette motor status */
210 BYTE DisketteStatus3
; /* 40: Diskette motor timeout */
211 BYTE DisketteStatus4
; /* 41: Diskette last operation status */
212 BYTE DiskStatus
[7]; /* 42: Disk status/command bytes */
213 BYTE VideoMode
; /* 49: Video mode */
214 WORD VideoColumns
; /* 4a: Number of columns */
215 WORD VideoPageSize
; /* 4c: Video page size in bytes */
216 WORD VideoPageStartAddr
; /* 4e: Video page start address */
217 BYTE VideoCursorPos
[16]; /* 50: Cursor position for 8 pages, column/row order */
218 WORD VideoCursorType
; /* 60: Video cursor type */
219 BYTE VideoCurPage
; /* 62: Video current page */
220 WORD VideoCtrlAddr
; /* 63: Video controller address */
221 BYTE VideoReg1
; /* 65: Video mode select register */
222 BYTE VideoReg2
; /* 66: Video CGA palette register */
223 DWORD ResetEntry
; /* 67: Warm reset entry point */
224 BYTE LastIRQ
; /* 6b: Last unexpected interrupt */
225 DWORD Ticks
; /* 6c: Ticks since midnight */
226 BYTE TicksOverflow
; /* 70: Timer overflow if past midnight */
227 BYTE CtrlBreakFlag
; /* 71: Ctrl-Break flag */
228 WORD ResetFlag
; /* 72: POST Reset flag */
229 BYTE DiskOpStatus
; /* 74: Last hard-disk operation status */
230 BYTE NbHardDisks
; /* 75: Number of hard disks */
231 BYTE DiskCtrlByte
; /* 76: Disk control byte */
232 BYTE DiskIOPort
; /* 77: Disk I/O port offset */
233 BYTE LptTimeout
[4]; /* 78: Timeouts for parallel ports */
234 BYTE ComTimeout
[4]; /* 7c: Timeouts for serial ports */
235 WORD KbdBufferStart
; /* 80: Keyboard buffer start */
236 WORD KbdBufferEnd
; /* 82: Keyboard buffer end */
237 BYTE RowsOnScreenMinus1
; /* 84: EGA only */
238 WORD BytesPerChar
; /* 85: EGA only */
239 BYTE ModeOptions
; /* 87: EGA only */
240 BYTE FeatureBitsSwitches
; /* 88: EGA only */
241 BYTE VGASettings
; /* 89: VGA misc settings */
242 BYTE DisplayCombination
; /* 8A: VGA display combinations */
243 BYTE DiskDataRate
; /* 8B: Last disk data rate selected */
248 /* Device driver header */
250 #define NONEXT ((DWORD)-1)
252 #define ATTR_STDIN 0x0001
253 #define ATTR_STDOUT 0x0002
254 #define ATTR_NUL 0x0004
255 #define ATTR_CLOCK 0x0008
256 #define ATTR_FASTCON 0x0010
257 #define ATTR_RAW 0x0020
258 #define ATTR_NOTEOF 0x0040
259 #define ATTR_DEVICE 0x0080
260 #define ATTR_REMOVABLE 0x0800
261 #define ATTR_NONIBM 0x2000 /* block devices */
262 #define ATTR_UNTILBUSY 0x2000 /* char devices */
263 #define ATTR_IOCTL 0x4000
264 #define ATTR_CHAR 0x8000
266 #include <pshpack1.h>
279 /* DOS Device requests */
282 #define CMD_MEDIACHECK 1 /* block devices */
283 #define CMD_BUILDBPB 2 /* block devices */
284 #define CMD_INIOCTL 3
285 #define CMD_INPUT 4 /* read data */
286 #define CMD_SAFEINPUT 5 /* "non-destructive input no wait", char devices */
287 #define CMD_INSTATUS 6 /* char devices */
288 #define CMD_INFLUSH 7 /* char devices */
289 #define CMD_OUTPUT 8 /* write data */
290 #define CMD_SAFEOUTPUT 9 /* write data with verify */
291 #define CMD_OUTSTATUS 10 /* char devices */
292 #define CMD_OUTFLUSH 11 /* char devices */
293 #define CMD_OUTIOCTL 12
294 #define CMD_DEVOPEN 13
295 #define CMD_DEVCLOSE 14
296 #define CMD_REMOVABLE 15 /* block devices */
297 #define CMD_UNTILBUSY 16 /* output until busy */
299 #define STAT_MASK 0x00FF
300 #define STAT_DONE 0x0100
301 #define STAT_BUSY 0x0200
302 #define STAT_ERROR 0x8000
304 #include <pshpack1.h>
307 BYTE size
; /* length of header + data */
308 BYTE unit
; /* unit (block devices only) */
316 BYTE media
; /* media descriptor from BPB */
318 WORD count
; /* byte/sector count */
319 WORD sector
; /* starting sector (block devices) */
320 DWORD volume
; /* volume ID (block devices) */
328 /* WINE device driver thunk from RM */
338 /* Device driver info (used for initialization) */
348 extern void WINAPI
MZ_LoadImage( LPCSTR filename
, HANDLE hFile
);
349 extern BOOL WINAPI
MZ_Exec( CONTEXT86
*context
, LPCSTR filename
, BYTE func
, LPVOID paramblk
);
350 extern void WINAPI
MZ_Exit( CONTEXT86
*context
, BOOL cs_psp
, WORD retval
);
351 extern BOOL WINAPI
MZ_Current( void );
352 extern void WINAPI
MZ_AllocDPMITask( void );
353 extern void WINAPI
MZ_RunInThread( PAPCFUNC proc
, ULONG_PTR arg
);
354 extern BOOL
DOSVM_IsWin16(void);
357 extern void DOSVM_SendQueuedEvents( CONTEXT86
* );
358 extern void WINAPI
DOSVM_AcknowledgeIRQ( CONTEXT86
* );
359 extern INT WINAPI
DOSVM_Enter( CONTEXT86
*context
);
360 extern void WINAPI
DOSVM_Wait( CONTEXT86
* );
361 extern DWORD WINAPI
DOSVM_Loop( HANDLE hThread
);
362 extern void WINAPI
DOSVM_QueueEvent( INT irq
, INT priority
, DOSRELAY relay
, LPVOID data
);
363 extern void WINAPI
DOSVM_PIC_ioport_out( WORD port
, BYTE val
);
364 extern void WINAPI
DOSVM_SetTimer( UINT ticks
);
365 extern UINT WINAPI
DOSVM_GetTimer( void );
368 extern void DOSDEV_InstallDOSDevices(void);
369 extern void DOSDEV_SetupDevice(const WINEDEV
* devinfo
,
370 WORD seg
, WORD off_dev
, WORD off_thunk
);
371 extern void DOSDEV_SetSharingRetry(WORD delay
, WORD count
);
372 extern SEGPTR
DOSDEV_GetLOL(BOOL v86
);
375 extern int DMA_Transfer(int channel
,int reqlength
,void* buffer
);
376 extern void DMA_ioport_out( WORD port
, BYTE val
);
377 extern BYTE
DMA_ioport_in( WORD port
);
380 extern void WINAPI
DOSVM_ASPIHandler(CONTEXT86
*);
383 extern DOSCONF
*DOSCONF_GetConfig( void );
386 extern BOOL
DOSMEM_InitDosMemory(void);
387 extern BOOL
DOSMEM_MapDosLayout(void);
388 extern WORD
DOSMEM_AllocSelector(WORD
); /* FIXME: to be removed */
389 extern LPVOID
DOSMEM_AllocBlock(UINT size
, WORD
* p
);
390 extern BOOL
DOSMEM_FreeBlock(void* ptr
);
391 extern UINT
DOSMEM_ResizeBlock(void* ptr
, UINT size
, BOOL exact
);
392 extern UINT
DOSMEM_Available(void);
393 extern BIOSDATA
*DOSVM_BiosData( void );
396 extern void WINAPI
DOSVM_Int34Handler(CONTEXT86
*);
397 extern void WINAPI
DOSVM_Int35Handler(CONTEXT86
*);
398 extern void WINAPI
DOSVM_Int36Handler(CONTEXT86
*);
399 extern void WINAPI
DOSVM_Int37Handler(CONTEXT86
*);
400 extern void WINAPI
DOSVM_Int38Handler(CONTEXT86
*);
401 extern void WINAPI
DOSVM_Int39Handler(CONTEXT86
*);
402 extern void WINAPI
DOSVM_Int3aHandler(CONTEXT86
*);
403 extern void WINAPI
DOSVM_Int3bHandler(CONTEXT86
*);
404 extern void WINAPI
DOSVM_Int3cHandler(CONTEXT86
*);
405 extern void WINAPI
DOSVM_Int3dHandler(CONTEXT86
*);
406 extern void WINAPI
DOSVM_Int3eHandler(CONTEXT86
*);
409 extern void DOSVM_InitSegments(void);
410 extern LPVOID
DOSVM_AllocDataUMB(DWORD
, WORD
*, WORD
*);
413 extern void WINAPI
DOSVM_Int09Handler(CONTEXT86
*);
414 extern void WINAPI
DOSVM_Int09SendScan(BYTE scan
,BYTE ascii
);
415 extern BYTE WINAPI
DOSVM_Int09ReadScan(BYTE
*ascii
);
418 extern void WINAPI
DOSVM_Int10Handler(CONTEXT86
*);
419 extern void WINAPI
DOSVM_PutChar(BYTE ascii
);
422 extern void WINAPI
DOSVM_Int13Handler(CONTEXT86
*);
425 extern void WINAPI
DOSVM_Int15Handler(CONTEXT86
*);
428 extern void WINAPI
DOSVM_Int16Handler(CONTEXT86
*);
429 extern BOOL WINAPI
DOSVM_Int16ReadChar( BYTE
*, BYTE
*, CONTEXT86
* );
430 extern int WINAPI
DOSVM_Int16AddChar(BYTE ascii
,BYTE scan
);
433 extern void WINAPI
DOSVM_Int21Handler(CONTEXT86
*);
436 BOOL
DOSVM_RawRead( BYTE
, DWORD
, DWORD
, BYTE
*, BOOL
);
437 void WINAPI
DOSVM_Int25Handler( CONTEXT86
* );
440 BOOL
DOSVM_RawWrite( BYTE
, DWORD
, DWORD
, BYTE
*, BOOL
);
441 void WINAPI
DOSVM_Int26Handler( CONTEXT86
* );
444 extern void WINAPI
DOSVM_Int2fHandler(CONTEXT86
*);
445 extern void MSCDEX_InstallCDROM(void);
448 extern void WINAPI
DOSVM_Int31Handler(CONTEXT86
*);
449 extern void WINAPI
DOSVM_RawModeSwitchHandler(CONTEXT86
*);
450 extern BOOL
DOSVM_IsDos32(void);
451 extern FARPROC16 WINAPI
DPMI_AllocInternalRMCB(RMCBPROC
);
452 extern void WINAPI
DPMI_FreeInternalRMCB(FARPROC16
);
453 extern int DPMI_CallRMProc(CONTEXT86
*,LPWORD
,int,int);
454 extern BOOL
DOSVM_CheckWrappers(CONTEXT86
*);
457 extern void WINAPI
DOSVM_Int33Handler(CONTEXT86
*);
458 extern void WINAPI
DOSVM_Int33Message(UINT
,WPARAM
,LPARAM
);
459 extern void WINAPI
DOSVM_Int33Console(MOUSE_EVENT_RECORD
*);
462 extern void WINAPI
DOSVM_Int67Handler(CONTEXT86
*);
463 extern void WINAPI
EMS_Ioctl_Handler(CONTEXT86
*);
466 extern void WINAPI
DOSVM_CallBuiltinHandler( CONTEXT86
*, BYTE
);
467 extern BOOL WINAPI
DOSVM_EmulateInterruptPM( CONTEXT86
*, BYTE
);
468 extern BOOL WINAPI
DOSVM_EmulateInterruptRM( CONTEXT86
*, BYTE
);
469 extern FARPROC16
DOSVM_GetPMHandler16( BYTE
);
470 extern FARPROC48
DOSVM_GetPMHandler48( BYTE
);
471 extern FARPROC16
DOSVM_GetRMHandler( BYTE
);
472 extern void DOSVM_HardwareInterruptPM( CONTEXT86
*, BYTE
);
473 extern void DOSVM_HardwareInterruptRM( CONTEXT86
*, BYTE
);
474 extern void DOSVM_SetPMHandler16( BYTE
, FARPROC16
);
475 extern void DOSVM_SetPMHandler48( BYTE
, FARPROC48
);
476 extern void DOSVM_SetRMHandler( BYTE
, FARPROC16
);
479 void DOSVM_RelayHandler( CONTEXT86
* );
480 void DOSVM_BuildCallFrame( CONTEXT86
*, DOSRELAY
, LPVOID
);
483 extern void SB_ioport_out( WORD port
, BYTE val
);
484 extern BYTE
SB_ioport_in( WORD port
);
487 extern BOOL
IO_pp_outp(int port
, DWORD
* res
);
488 extern int IO_pp_inp(int port
, DWORD
* res
);
489 extern char IO_pp_init(void);
492 extern void WINAPI
DOSVM_Int08Handler(CONTEXT86
*);
495 extern void WINAPI
XMS_Handler(CONTEXT86
*);
497 #endif /* __WINE_DOSEXE_H */