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 */
33 #define MAX_DOS_DRIVES 26
35 /* amount of space reserved for relay stack */
36 #define DOSVM_RELAY_DATA_SIZE 4096
38 /* various real-mode code stubs */
51 /* 48-bit segmented pointers for DOS DPMI32 */
55 } SEGPTR48
, FARPROC48
;
57 typedef void (*DOSRELAY
)(CONTEXT
*,void*);
58 typedef void (WINAPI
*RMCBPROC
)(CONTEXT
*);
59 typedef void (WINAPI
*INTPROC
)(CONTEXT
*);
61 extern WORD DOSVM_psp DECLSPEC_HIDDEN
; /* psp of current DOS task */
62 extern WORD DOSVM_retval DECLSPEC_HIDDEN
; /* return value of previous DOS task */
63 extern struct DPMI_segments
*DOSVM_dpmi_segments DECLSPEC_HIDDEN
;
66 * Declare some CONTEXT.EFlags bits.
67 * IF_MASK is only pushed into real mode stack.
69 #define V86_FLAG 0x00020000
70 #define TF_MASK 0x00000100
71 #define IF_MASK 0x00000200
72 #define VIF_MASK 0x00080000
73 #define VIP_MASK 0x00100000
75 #define ADD_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD((DWORD)(dw)+(val)))
77 #define PTR_REAL_TO_LIN(seg,off) ((void*)(((unsigned int)(seg) << 4) + LOWORD(off)))
79 /* NOTE: Interrupts might get called from four modes: real mode, 16-bit,
80 * 32-bit segmented (DPMI32) and 32-bit linear (via DeviceIoControl).
81 * For automatic conversion of pointer
82 * parameters, interrupt handlers should use CTX_SEG_OFF_TO_LIN with
83 * the contents of a segment register as second and the contents of
84 * a *32-bit* general register as third parameter, e.g.
85 * CTX_SEG_OFF_TO_LIN( context, DS_reg(context), EDX_reg(context) )
86 * This will generate a linear pointer in all three cases:
87 * Real-Mode: Seg*16 + LOWORD(Offset)
88 * 16-bit: convert (Seg, LOWORD(Offset)) to linear
89 * 32-bit segmented: convert (Seg, Offset) to linear
90 * 32-bit linear: use Offset as linear address (DeviceIoControl!)
92 * Real-mode is recognized by checking the V86 bit in the flags register,
93 * 32-bit linear mode is recognized by checking whether 'seg' is
94 * a system selector (0 counts also as 32-bit segment) and 32-bit
95 * segmented mode is recognized by checking whether 'seg' is 32-bit
96 * selector which is neither system selector nor zero.
98 #define CTX_SEG_OFF_TO_LIN(context,seg,off) \
99 (ISV86(context) ? PTR_REAL_TO_LIN((seg),(off)) : wine_ldt_get_ptr((seg),(off)))
101 #define INT_BARF(context,num) \
102 ERR( "int%x: unknown/not implemented parameters:\n" \
103 "int%x: AX %04x, BX %04x, CX %04x, DX %04x, " \
104 "SI %04x, DI %04x, DS %04x, ES %04x\n", \
105 (num), (num), LOWORD((context)->Eax), LOWORD((context)->Ebx), \
106 LOWORD((context)->Ecx), LOWORD((context)->Edx), LOWORD((context)->Esi), \
107 LOWORD((context)->Edi), (WORD)(context)->SegDs, (WORD)(context)->SegEs )
109 /* pushing on stack in 16 bit needs segment wrap around */
110 #define PUSH_WORD16(context,val) \
111 *((WORD*)CTX_SEG_OFF_TO_LIN((context), \
112 (context)->SegSs, ADD_LOWORD( context->Esp, -2 ) )) = (val)
114 /* Macros for easier access to i386 context registers */
116 #define AX_reg(context) ((WORD)(context)->Eax)
117 #define BX_reg(context) ((WORD)(context)->Ebx)
118 #define CX_reg(context) ((WORD)(context)->Ecx)
119 #define DX_reg(context) ((WORD)(context)->Edx)
120 #define SI_reg(context) ((WORD)(context)->Esi)
121 #define DI_reg(context) ((WORD)(context)->Edi)
123 #define AL_reg(context) ((BYTE)(context)->Eax)
124 #define AH_reg(context) ((BYTE)((context)->Eax >> 8))
125 #define BL_reg(context) ((BYTE)(context)->Ebx)
126 #define BH_reg(context) ((BYTE)((context)->Ebx >> 8))
127 #define CL_reg(context) ((BYTE)(context)->Ecx)
128 #define CH_reg(context) ((BYTE)((context)->Ecx >> 8))
129 #define DL_reg(context) ((BYTE)(context)->Edx)
130 #define DH_reg(context) ((BYTE)((context)->Edx >> 8))
132 #define SET_CFLAG(context) ((context)->EFlags |= 0x0001)
133 #define RESET_CFLAG(context) ((context)->EFlags &= ~0x0001)
134 #define SET_ZFLAG(context) ((context)->EFlags |= 0x0040)
135 #define RESET_ZFLAG(context) ((context)->EFlags &= ~0x0040)
136 #define ISV86(context) ((context)->EFlags & 0x00020000)
138 #define SET_AX(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xffff) | (WORD)(val)))
139 #define SET_BX(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xffff) | (WORD)(val)))
140 #define SET_CX(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xffff) | (WORD)(val)))
141 #define SET_DX(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xffff) | (WORD)(val)))
142 #define SET_SI(context,val) ((void)((context)->Esi = ((context)->Esi & ~0xffff) | (WORD)(val)))
143 #define SET_DI(context,val) ((void)((context)->Edi = ((context)->Edi & ~0xffff) | (WORD)(val)))
145 #define SET_AL(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xff) | (BYTE)(val)))
146 #define SET_BL(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xff) | (BYTE)(val)))
147 #define SET_CL(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xff) | (BYTE)(val)))
148 #define SET_DL(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xff) | (BYTE)(val)))
150 #define SET_AH(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xff00) | (((BYTE)(val)) << 8)))
151 #define SET_BH(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xff00) | (((BYTE)(val)) << 8)))
152 #define SET_CH(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xff00) | (((BYTE)(val)) << 8)))
153 #define SET_DH(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xff00) | (((BYTE)(val)) << 8)))
155 #include <pshpack1.h>
159 WORD Com1Addr
; /* 00: COM1 I/O address */
160 WORD Com2Addr
; /* 02: COM2 I/O address */
161 WORD Com3Addr
; /* 04: COM3 I/O address */
162 WORD Com4Addr
; /* 06: COM4 I/O address */
163 WORD Lpt1Addr
; /* 08: LPT1 I/O address */
164 WORD Lpt2Addr
; /* 0a: LPT2 I/O address */
165 WORD Lpt3Addr
; /* 0c: LPT3 I/O address */
166 WORD Lpt4Addr
; /* 0e: LPT4 I/O address */
167 WORD InstalledHardware
; /* 10: Installed hardware flags */
168 BYTE POSTstatus
; /* 12: Power-On Self Test status */
169 WORD MemSize
; /* 13: Base memory size in Kb */
170 WORD unused1
; /* 15: Manufacturing test scratch pad */
171 BYTE KbdFlags1
; /* 17: Keyboard flags 1 */
172 BYTE KbdFlags2
; /* 18: Keyboard flags 2 */
173 BYTE unused2
; /* 19: Keyboard driver workspace */
174 WORD NextKbdCharPtr
; /* 1a: Next character in kbd buffer */
175 WORD FirstKbdCharPtr
; /* 1c: First character in kbd buffer */
176 WORD KbdBuffer
[16]; /* 1e: Keyboard buffer */
177 BYTE DisketteStatus1
; /* 3e: Diskette recalibrate status */
178 BYTE DisketteStatus2
; /* 3f: Diskette motor status */
179 BYTE DisketteStatus3
; /* 40: Diskette motor timeout */
180 BYTE DisketteStatus4
; /* 41: Diskette last operation status */
181 BYTE DiskStatus
[7]; /* 42: Disk status/command bytes */
182 BYTE VideoMode
; /* 49: Video mode */
183 WORD VideoColumns
; /* 4a: Number of columns */
184 WORD VideoPageSize
; /* 4c: Video page size in bytes */
185 WORD VideoPageStartAddr
; /* 4e: Video page start address */
186 BYTE VideoCursorPos
[16]; /* 50: Cursor position for 8 pages, column/row order */
187 WORD VideoCursorType
; /* 60: Video cursor type */
188 BYTE VideoCurPage
; /* 62: Video current page */
189 WORD VideoCtrlAddr
; /* 63: Video controller address */
190 BYTE VideoReg1
; /* 65: Video mode select register */
191 BYTE VideoReg2
; /* 66: Video CGA palette register */
192 DWORD ResetEntry
; /* 67: Warm reset entry point */
193 BYTE LastIRQ
; /* 6b: Last unexpected interrupt */
194 DWORD Ticks
; /* 6c: Ticks since midnight */
195 BYTE TicksOverflow
; /* 70: Timer overflow if past midnight */
196 BYTE CtrlBreakFlag
; /* 71: Ctrl-Break flag */
197 WORD ResetFlag
; /* 72: POST Reset flag */
198 BYTE DiskOpStatus
; /* 74: Last hard-disk operation status */
199 BYTE NbHardDisks
; /* 75: Number of hard disks */
200 BYTE DiskCtrlByte
; /* 76: Disk control byte */
201 BYTE DiskIOPort
; /* 77: Disk I/O port offset */
202 BYTE LptTimeout
[4]; /* 78: Timeouts for parallel ports */
203 BYTE ComTimeout
[4]; /* 7c: Timeouts for serial ports */
204 WORD KbdBufferStart
; /* 80: Keyboard buffer start */
205 WORD KbdBufferEnd
; /* 82: Keyboard buffer end */
206 BYTE RowsOnScreenMinus1
; /* 84: EGA only */
207 WORD BytesPerChar
; /* 85: EGA only */
208 BYTE ModeOptions
; /* 87: EGA only */
209 BYTE FeatureBitsSwitches
; /* 88: EGA only */
210 BYTE VGASettings
; /* 89: VGA misc settings */
211 BYTE DisplayCombination
; /* 8A: VGA display combinations */
212 BYTE DiskDataRate
; /* 8B: Last disk data rate selected */
217 /* Device driver header */
219 #include <pshpack1.h>
233 extern void DOSVM_Exit( WORD retval
) DECLSPEC_HIDDEN
;
234 extern LPVOID
DOSVM_AllocDataUMB(DWORD
, WORD
*, WORD
*) DECLSPEC_HIDDEN
;
235 extern void DOSVM_InitSegments(void) DECLSPEC_HIDDEN
;
238 extern int DMA_Transfer(int channel
,int reqlength
,void* buffer
) DECLSPEC_HIDDEN
;
239 extern void DMA_ioport_out( WORD port
, BYTE val
) DECLSPEC_HIDDEN
;
240 extern BYTE
DMA_ioport_in( WORD port
) DECLSPEC_HIDDEN
;
243 extern void DOSVM_ASPIHandler(CONTEXT
*) DECLSPEC_HIDDEN
;
246 extern BIOSDATA
*DOSVM_BiosData( void ) DECLSPEC_HIDDEN
;
247 extern void DOSVM_start_bios_timer(void) DECLSPEC_HIDDEN
;
250 extern void WINAPI
DOSVM_Int34Handler(CONTEXT
*) DECLSPEC_HIDDEN
;
251 extern void WINAPI
DOSVM_Int35Handler(CONTEXT
*) DECLSPEC_HIDDEN
;
252 extern void WINAPI
DOSVM_Int36Handler(CONTEXT
*) DECLSPEC_HIDDEN
;
253 extern void WINAPI
DOSVM_Int37Handler(CONTEXT
*) DECLSPEC_HIDDEN
;
254 extern void WINAPI
DOSVM_Int38Handler(CONTEXT
*) DECLSPEC_HIDDEN
;
255 extern void WINAPI
DOSVM_Int39Handler(CONTEXT
*) DECLSPEC_HIDDEN
;
256 extern void WINAPI
DOSVM_Int3aHandler(CONTEXT
*) DECLSPEC_HIDDEN
;
257 extern void WINAPI
DOSVM_Int3bHandler(CONTEXT
*) DECLSPEC_HIDDEN
;
258 extern void WINAPI
DOSVM_Int3cHandler(CONTEXT
*) DECLSPEC_HIDDEN
;
259 extern void WINAPI
DOSVM_Int3dHandler(CONTEXT
*) DECLSPEC_HIDDEN
;
260 extern void WINAPI
DOSVM_Int3eHandler(CONTEXT
*) DECLSPEC_HIDDEN
;
263 extern void WINAPI
DOSVM_Int13Handler(CONTEXT
*) DECLSPEC_HIDDEN
;
266 extern void WINAPI
DOSVM_Int15Handler(CONTEXT
*) DECLSPEC_HIDDEN
;
269 extern void WINAPI
DOSVM_Int21Handler(CONTEXT
*) DECLSPEC_HIDDEN
;
272 BOOL
DOSVM_RawRead( BYTE
, DWORD
, DWORD
, BYTE
*, BOOL
) DECLSPEC_HIDDEN
;
273 void WINAPI
DOSVM_Int25Handler( CONTEXT
* ) DECLSPEC_HIDDEN
;
276 BOOL
DOSVM_RawWrite( BYTE
, DWORD
, DWORD
, BYTE
*, BOOL
) DECLSPEC_HIDDEN
;
277 void WINAPI
DOSVM_Int26Handler( CONTEXT
* ) DECLSPEC_HIDDEN
;
280 extern void WINAPI
DOSVM_Int2fHandler(CONTEXT
*) DECLSPEC_HIDDEN
;
283 extern void WINAPI
DOSVM_Int31Handler(CONTEXT
*) DECLSPEC_HIDDEN
;
284 extern void WINAPI
DOSVM_RawModeSwitchHandler(CONTEXT
*) DECLSPEC_HIDDEN
;
285 extern BOOL
DOSVM_IsDos32(void) DECLSPEC_HIDDEN
;
286 extern FARPROC16
DPMI_AllocInternalRMCB(RMCBPROC
) DECLSPEC_HIDDEN
;
287 extern int DPMI_CallRMProc(CONTEXT
*,LPWORD
,int,int) DECLSPEC_HIDDEN
;
288 extern BOOL
DOSVM_CheckWrappers(CONTEXT
*) DECLSPEC_HIDDEN
;
291 extern void WINAPI
DOSVM_Int67Handler(CONTEXT
*) DECLSPEC_HIDDEN
;
292 extern void EMS_Ioctl_Handler(CONTEXT
*) DECLSPEC_HIDDEN
;
295 extern void __wine_call_int_handler( CONTEXT
*, BYTE
) DECLSPEC_HIDDEN
;
296 extern void DOSVM_CallBuiltinHandler( CONTEXT
*, BYTE
) DECLSPEC_HIDDEN
;
297 extern BOOL
DOSVM_EmulateInterruptPM( CONTEXT
*, BYTE
) DECLSPEC_HIDDEN
;
298 extern FARPROC16
DOSVM_GetPMHandler16( BYTE
) DECLSPEC_HIDDEN
;
299 extern FARPROC48
DOSVM_GetPMHandler48( BYTE
) DECLSPEC_HIDDEN
;
300 extern FARPROC16
DOSVM_GetRMHandler( BYTE
) DECLSPEC_HIDDEN
;
301 extern void DOSVM_HardwareInterruptPM( CONTEXT
*, BYTE
) DECLSPEC_HIDDEN
;
302 extern void DOSVM_SetPMHandler16( BYTE
, FARPROC16
) DECLSPEC_HIDDEN
;
303 extern void DOSVM_SetPMHandler48( BYTE
, FARPROC48
) DECLSPEC_HIDDEN
;
304 extern void DOSVM_SetRMHandler( BYTE
, FARPROC16
) DECLSPEC_HIDDEN
;
307 extern DWORD
DOSVM_inport( int port
, int size
) DECLSPEC_HIDDEN
;
308 extern void DOSVM_outport( int port
, int size
, DWORD value
) DECLSPEC_HIDDEN
;
311 void DOSVM_RelayHandler( CONTEXT
* ) DECLSPEC_HIDDEN
;
312 void DOSVM_BuildCallFrame( CONTEXT
*, DOSRELAY
, LPVOID
) DECLSPEC_HIDDEN
;
315 extern void SB_ioport_out( WORD port
, BYTE val
) DECLSPEC_HIDDEN
;
316 extern BYTE
SB_ioport_in( WORD port
) DECLSPEC_HIDDEN
;
318 #endif /* __WINE_DOSEXE_H */