Added YUV routines needed for v4l driver, and in the future possibly
[wine/gsoc-2012-control.git] / dlls / winedos / dosexe.h
blob1aba8891951f9ee6fec675479378bbe4f26cb64a
1 /*
2 * DOS EXE loader
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
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "wine/library.h"
28 #include "wine/windef16.h"
29 #include "winbase.h"
30 #include "winnt.h" /* for PCONTEXT */
31 #include "wincon.h" /* for MOUSE_EVENT_RECORD */
33 #define MAX_DOS_DRIVES 26
35 struct _DOSEVENT;
37 /* amount of space reserved for relay stack */
38 #define DOSVM_RELAY_DATA_SIZE 4096
40 /* various real-mode code stubs */
41 struct DPMI_segments
43 WORD wrap_seg;
44 WORD xms_seg;
45 WORD dpmi_seg;
46 WORD dpmi_sel;
47 WORD int48_sel;
48 WORD int16_sel;
49 WORD relay_code_sel;
50 WORD relay_data_sel;
53 /* 48-bit segmented pointers for DOS DPMI32 */
54 typedef struct {
55 WORD selector;
56 DWORD offset;
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
64 typedef struct {
65 char lastdrive;
66 int brk_flag;
67 int files;
68 int stacks_nr;
69 int stacks_sz;
70 int buf;
71 int buf2;
72 int fcbs;
73 int flags;
74 char *shell;
75 char *country;
76 } DOSCONF;
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)
93 # define MZ_SUPPORTED
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 /* pushing on stack in 16 bit needs segment wrap around */
140 #define PUSH_WORD16(context,val) \
141 *((WORD*)CTX_SEG_OFF_TO_LIN((context), \
142 (context)->SegSs, ADD_LOWORD( context->Esp, -2 ) )) = (val)
144 /* Macros for easier access to i386 context registers */
146 #define AX_reg(context) ((WORD)(context)->Eax)
147 #define BX_reg(context) ((WORD)(context)->Ebx)
148 #define CX_reg(context) ((WORD)(context)->Ecx)
149 #define DX_reg(context) ((WORD)(context)->Edx)
150 #define SI_reg(context) ((WORD)(context)->Esi)
151 #define DI_reg(context) ((WORD)(context)->Edi)
153 #define AL_reg(context) ((BYTE)(context)->Eax)
154 #define AH_reg(context) ((BYTE)((context)->Eax >> 8))
155 #define BL_reg(context) ((BYTE)(context)->Ebx)
156 #define BH_reg(context) ((BYTE)((context)->Ebx >> 8))
157 #define CL_reg(context) ((BYTE)(context)->Ecx)
158 #define CH_reg(context) ((BYTE)((context)->Ecx >> 8))
159 #define DL_reg(context) ((BYTE)(context)->Edx)
160 #define DH_reg(context) ((BYTE)((context)->Edx >> 8))
162 #define SET_CFLAG(context) ((context)->EFlags |= 0x0001)
163 #define RESET_CFLAG(context) ((context)->EFlags &= ~0x0001)
164 #define SET_ZFLAG(context) ((context)->EFlags |= 0x0040)
165 #define RESET_ZFLAG(context) ((context)->EFlags &= ~0x0040)
166 #define ISV86(context) ((context)->EFlags & 0x00020000)
168 #define SET_AX(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xffff) | (WORD)(val)))
169 #define SET_BX(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xffff) | (WORD)(val)))
170 #define SET_CX(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xffff) | (WORD)(val)))
171 #define SET_DX(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xffff) | (WORD)(val)))
172 #define SET_SI(context,val) ((void)((context)->Esi = ((context)->Esi & ~0xffff) | (WORD)(val)))
173 #define SET_DI(context,val) ((void)((context)->Edi = ((context)->Edi & ~0xffff) | (WORD)(val)))
175 #define SET_AL(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xff) | (BYTE)(val)))
176 #define SET_BL(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xff) | (BYTE)(val)))
177 #define SET_CL(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xff) | (BYTE)(val)))
178 #define SET_DL(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xff) | (BYTE)(val)))
180 #define SET_AH(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xff00) | (((BYTE)(val)) << 8)))
181 #define SET_BH(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xff00) | (((BYTE)(val)) << 8)))
182 #define SET_CH(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xff00) | (((BYTE)(val)) << 8)))
183 #define SET_DH(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xff00) | (((BYTE)(val)) << 8)))
185 #include <pshpack1.h>
187 typedef struct
189 WORD Com1Addr; /* 00: COM1 I/O address */
190 WORD Com2Addr; /* 02: COM2 I/O address */
191 WORD Com3Addr; /* 04: COM3 I/O address */
192 WORD Com4Addr; /* 06: COM4 I/O address */
193 WORD Lpt1Addr; /* 08: LPT1 I/O address */
194 WORD Lpt2Addr; /* 0a: LPT2 I/O address */
195 WORD Lpt3Addr; /* 0c: LPT3 I/O address */
196 WORD Lpt4Addr; /* 0e: LPT4 I/O address */
197 WORD InstalledHardware; /* 10: Installed hardware flags */
198 BYTE POSTstatus; /* 12: Power-On Self Test status */
199 WORD MemSize; /* 13: Base memory size in Kb */
200 WORD unused1; /* 15: Manufacturing test scratch pad */
201 BYTE KbdFlags1; /* 17: Keyboard flags 1 */
202 BYTE KbdFlags2; /* 18: Keyboard flags 2 */
203 BYTE unused2; /* 19: Keyboard driver workspace */
204 WORD NextKbdCharPtr; /* 1a: Next character in kbd buffer */
205 WORD FirstKbdCharPtr; /* 1c: First character in kbd buffer */
206 WORD KbdBuffer[16]; /* 1e: Keyboard buffer */
207 BYTE DisketteStatus1; /* 3e: Diskette recalibrate status */
208 BYTE DisketteStatus2; /* 3f: Diskette motor status */
209 BYTE DisketteStatus3; /* 40: Diskette motor timeout */
210 BYTE DisketteStatus4; /* 41: Diskette last operation status */
211 BYTE DiskStatus[7]; /* 42: Disk status/command bytes */
212 BYTE VideoMode; /* 49: Video mode */
213 WORD VideoColumns; /* 4a: Number of columns */
214 WORD VideoPageSize; /* 4c: Video page size in bytes */
215 WORD VideoPageStartAddr; /* 4e: Video page start address */
216 BYTE VideoCursorPos[16]; /* 50: Cursor position for 8 pages, column/row order */
217 WORD VideoCursorType; /* 60: Video cursor type */
218 BYTE VideoCurPage; /* 62: Video current page */
219 WORD VideoCtrlAddr; /* 63: Video controller address */
220 BYTE VideoReg1; /* 65: Video mode select register */
221 BYTE VideoReg2; /* 66: Video CGA palette register */
222 DWORD ResetEntry; /* 67: Warm reset entry point */
223 BYTE LastIRQ; /* 6b: Last unexpected interrupt */
224 DWORD Ticks; /* 6c: Ticks since midnight */
225 BYTE TicksOverflow; /* 70: Timer overflow if past midnight */
226 BYTE CtrlBreakFlag; /* 71: Ctrl-Break flag */
227 WORD ResetFlag; /* 72: POST Reset flag */
228 BYTE DiskOpStatus; /* 74: Last hard-disk operation status */
229 BYTE NbHardDisks; /* 75: Number of hard disks */
230 BYTE DiskCtrlByte; /* 76: Disk control byte */
231 BYTE DiskIOPort; /* 77: Disk I/O port offset */
232 BYTE LptTimeout[4]; /* 78: Timeouts for parallel ports */
233 BYTE ComTimeout[4]; /* 7c: Timeouts for serial ports */
234 WORD KbdBufferStart; /* 80: Keyboard buffer start */
235 WORD KbdBufferEnd; /* 82: Keyboard buffer end */
236 BYTE RowsOnScreenMinus1; /* 84: EGA only */
237 WORD BytesPerChar; /* 85: EGA only */
238 BYTE ModeOptions; /* 87: EGA only */
239 BYTE FeatureBitsSwitches; /* 88: EGA only */
240 BYTE VGASettings; /* 89: VGA misc settings */
241 BYTE DisplayCombination; /* 8A: VGA display combinations */
242 BYTE DiskDataRate; /* 8B: Last disk data rate selected */
243 } BIOSDATA;
245 #include <poppack.h>
247 /* module.c */
248 extern void WINAPI MZ_LoadImage( LPCSTR filename, HANDLE hFile );
249 extern BOOL WINAPI MZ_Exec( CONTEXT86 *context, LPCSTR filename, BYTE func, LPVOID paramblk );
250 extern void WINAPI MZ_Exit( CONTEXT86 *context, BOOL cs_psp, WORD retval );
251 extern BOOL WINAPI MZ_Current( void );
252 extern void WINAPI MZ_AllocDPMITask( void );
253 extern void WINAPI MZ_RunInThread( PAPCFUNC proc, ULONG_PTR arg );
254 extern BOOL DOSVM_IsWin16(void);
256 /* dosvm.c */
257 extern void DOSVM_SendQueuedEvents( CONTEXT86 * );
258 extern void WINAPI DOSVM_AcknowledgeIRQ( CONTEXT86 * );
259 extern INT WINAPI DOSVM_Enter( CONTEXT86 *context );
260 extern void WINAPI DOSVM_Wait( CONTEXT86 * );
261 extern DWORD WINAPI DOSVM_Loop( HANDLE hThread );
262 extern void WINAPI DOSVM_QueueEvent( INT irq, INT priority, DOSRELAY relay, LPVOID data );
263 extern void WINAPI DOSVM_PIC_ioport_out( WORD port, BYTE val );
264 extern void WINAPI DOSVM_SetTimer( UINT ticks );
265 extern UINT WINAPI DOSVM_GetTimer( void );
267 /* devices.c */
268 extern void DOSDEV_InstallDOSDevices(void);
269 extern DWORD DOSDEV_Console(void);
270 extern DWORD DOSDEV_FindCharDevice(char*name);
271 extern int DOSDEV_Peek(DWORD dev, BYTE*data);
272 extern int DOSDEV_Read(DWORD dev, DWORD buf, int buflen);
273 extern int DOSDEV_Write(DWORD dev, DWORD buf, int buflen, int verify);
274 extern int DOSDEV_IoctlRead(DWORD dev, DWORD buf, int buflen);
275 extern int DOSDEV_IoctlWrite(DWORD dev, DWORD buf, int buflen);
276 extern void DOSDEV_SetSharingRetry(WORD delay, WORD count);
277 extern SEGPTR DOSDEV_GetLOL(BOOL v86);
279 /* dma.c */
280 extern int DMA_Transfer(int channel,int reqlength,void* buffer);
281 extern void DMA_ioport_out( WORD port, BYTE val );
282 extern BYTE DMA_ioport_in( WORD port );
284 /* dosaspi.c */
285 extern void WINAPI DOSVM_ASPIHandler(CONTEXT86*);
287 /* dosconf.c */
288 extern DOSCONF *DOSCONF_GetConfig( void );
290 /* dosmem.c */
291 extern BOOL DOSMEM_InitDosMemory(void);
292 extern BOOL DOSMEM_MapDosLayout(void);
293 extern WORD DOSMEM_AllocSelector(WORD); /* FIXME: to be removed */
294 extern LPVOID DOSMEM_AllocBlock(UINT size, WORD* p);
295 extern BOOL DOSMEM_FreeBlock(void* ptr);
296 extern UINT DOSMEM_ResizeBlock(void* ptr, UINT size, BOOL exact);
297 extern UINT DOSMEM_Available(void);
298 extern BIOSDATA *DOSVM_BiosData( void );
300 /* fpu.c */
301 extern void WINAPI DOSVM_Int34Handler(CONTEXT86*);
302 extern void WINAPI DOSVM_Int35Handler(CONTEXT86*);
303 extern void WINAPI DOSVM_Int36Handler(CONTEXT86*);
304 extern void WINAPI DOSVM_Int37Handler(CONTEXT86*);
305 extern void WINAPI DOSVM_Int38Handler(CONTEXT86*);
306 extern void WINAPI DOSVM_Int39Handler(CONTEXT86*);
307 extern void WINAPI DOSVM_Int3aHandler(CONTEXT86*);
308 extern void WINAPI DOSVM_Int3bHandler(CONTEXT86*);
309 extern void WINAPI DOSVM_Int3cHandler(CONTEXT86*);
310 extern void WINAPI DOSVM_Int3dHandler(CONTEXT86*);
311 extern void WINAPI DOSVM_Int3eHandler(CONTEXT86*);
313 /* himem.c */
314 extern void DOSVM_InitSegments(void);
315 extern LPVOID DOSVM_AllocUMB(DWORD);
316 extern LPVOID DOSVM_AllocCodeUMB(DWORD, WORD *, WORD *);
317 extern LPVOID DOSVM_AllocDataUMB(DWORD, WORD *, WORD *);
319 /* int09.c */
320 extern void WINAPI DOSVM_Int09Handler(CONTEXT86*);
321 extern void WINAPI DOSVM_Int09SendScan(BYTE scan,BYTE ascii);
322 extern BYTE WINAPI DOSVM_Int09ReadScan(BYTE*ascii);
324 /* int10.c */
325 extern void WINAPI DOSVM_Int10Handler(CONTEXT86*);
326 extern void WINAPI DOSVM_PutChar(BYTE ascii);
328 /* int11.c */
329 extern void WINAPI DOSVM_Int11Handler(CONTEXT86*);
331 /* int12.c */
332 extern void WINAPI DOSVM_Int12Handler(CONTEXT86*);
334 /* int13.c */
335 extern void WINAPI DOSVM_Int13Handler(CONTEXT86*);
337 /* int15.c */
338 extern void WINAPI DOSVM_Int15Handler(CONTEXT86*);
340 /* int1a.c */
341 extern void WINAPI DOSVM_Int1aHandler(CONTEXT86*);
343 /* int16.c */
344 extern void WINAPI DOSVM_Int16Handler(CONTEXT86*);
345 extern BOOL WINAPI DOSVM_Int16ReadChar( BYTE *, BYTE *, CONTEXT86 * );
346 extern int WINAPI DOSVM_Int16AddChar(BYTE ascii,BYTE scan);
348 /* int17.c */
349 extern void WINAPI DOSVM_Int17Handler(CONTEXT86*);
351 /* int19.c */
352 extern void WINAPI DOSVM_Int19Handler(CONTEXT86*);
354 /* int20.c */
355 extern void WINAPI DOSVM_Int20Handler(CONTEXT86*);
357 /* int21.c */
358 extern void WINAPI DOSVM_Int21Handler(CONTEXT86*);
360 /* int25.c */
361 BOOL DOSVM_RawRead( BYTE, DWORD, DWORD, BYTE *, BOOL );
362 void WINAPI DOSVM_Int25Handler( CONTEXT86 * );
364 /* int26.c */
365 BOOL DOSVM_RawWrite( BYTE, DWORD, DWORD, BYTE *, BOOL );
366 void WINAPI DOSVM_Int26Handler( CONTEXT86 * );
368 /* int29.c */
369 extern void WINAPI DOSVM_Int29Handler(CONTEXT86*);
371 /* int2a.c */
372 extern void WINAPI DOSVM_Int2aHandler(CONTEXT86*);
374 /* int2f.c */
375 extern void WINAPI DOSVM_Int2fHandler(CONTEXT86*);
377 /* int31.c */
378 extern void WINAPI DOSVM_Int31Handler(CONTEXT86*);
379 extern void WINAPI DOSVM_RawModeSwitchHandler(CONTEXT86*);
380 extern BOOL DOSVM_IsDos32(void);
381 extern FARPROC16 WINAPI DPMI_AllocInternalRMCB(RMCBPROC);
382 extern void WINAPI DPMI_FreeInternalRMCB(FARPROC16);
383 extern int DPMI_CallRMProc(CONTEXT86*,LPWORD,int,int);
384 extern BOOL DOSVM_CheckWrappers(CONTEXT86*);
386 /* int33.c */
387 extern void WINAPI DOSVM_Int33Handler(CONTEXT86*);
388 extern void WINAPI DOSVM_Int33Message(UINT,WPARAM,LPARAM);
389 extern void WINAPI DOSVM_Int33Console(MOUSE_EVENT_RECORD*);
391 /* int41.c */
392 extern void WINAPI DOSVM_Int41Handler(CONTEXT86*);
394 /* int4b.c */
395 extern void WINAPI DOSVM_Int4bHandler(CONTEXT86*);
397 /* int5c.c */
398 extern void WINAPI DOSVM_Int5cHandler(CONTEXT86*);
400 /* int67.c */
401 extern void WINAPI DOSVM_Int67Handler(CONTEXT86*);
402 extern void WINAPI EMS_Ioctl_Handler(CONTEXT86*);
404 /* interrupts.c */
405 extern void WINAPI DOSVM_CallBuiltinHandler( CONTEXT86 *, BYTE );
406 extern void WINAPI DOSVM_EmulateInterruptPM( CONTEXT86 *, BYTE );
407 extern BOOL WINAPI DOSVM_EmulateInterruptRM( CONTEXT86 *, BYTE );
408 extern FARPROC16 DOSVM_GetPMHandler16( BYTE );
409 extern FARPROC48 DOSVM_GetPMHandler48( BYTE );
410 extern FARPROC16 DOSVM_GetRMHandler( BYTE );
411 extern void DOSVM_HardwareInterruptPM( CONTEXT86 *, BYTE );
412 extern void DOSVM_HardwareInterruptRM( CONTEXT86 *, BYTE );
413 extern void DOSVM_SetPMHandler16( BYTE, FARPROC16 );
414 extern void DOSVM_SetPMHandler48( BYTE, FARPROC48 );
415 extern void DOSVM_SetRMHandler( BYTE, FARPROC16 );
417 /* relay.c */
418 void DOSVM_RelayHandler( CONTEXT86 * );
419 void DOSVM_BuildCallFrame( CONTEXT86 *, DOSRELAY, LPVOID );
421 /* soundblaster.c */
422 extern void SB_ioport_out( WORD port, BYTE val );
423 extern BYTE SB_ioport_in( WORD port );
425 /* ppdev.c */
426 extern BOOL IO_pp_outp(int port, DWORD* res);
427 extern int IO_pp_inp(int port, DWORD* res);
428 extern char IO_pp_init(void);
430 /* timer.c */
431 extern void WINAPI DOSVM_Int08Handler(CONTEXT86*);
433 /* xms.c */
434 extern void WINAPI XMS_Handler(CONTEXT86*);
436 #endif /* __WINE_DOSEXE_H */