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