Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Misc. emulation definitions |
| 3 | * |
| 4 | * Copyright 1995 Alexandre Julliard |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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 |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 21 | #ifndef __WINE_MISCEMU_H |
| 22 | #define __WINE_MISCEMU_H |
| 23 | |
Alexandre Julliard | 435e2e6 | 2002-12-10 22:56:43 +0000 | [diff] [blame] | 24 | #include "windef.h" |
Alexandre Julliard | db0747d | 2000-12-13 20:23:41 +0000 | [diff] [blame] | 25 | #include "selectors.h" |
Alexandre Julliard | 83f52d1 | 2000-09-26 22:20:14 +0000 | [diff] [blame] | 26 | #include "wine/windef16.h" |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 27 | |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 28 | /* msdos/dosmem.c */ |
Patrik Stridvall | c7a8dde | 1999-04-25 12:36:53 +0000 | [diff] [blame] | 29 | #include "pshpack1.h" |
Andreas Mohr | f83cf69 | 1999-03-13 18:00:52 +0000 | [diff] [blame] | 30 | |
| 31 | typedef struct |
| 32 | { |
| 33 | WORD Com1Addr; /* 00: COM1 I/O address */ |
| 34 | WORD Com2Addr; /* 02: COM2 I/O address */ |
| 35 | WORD Com3Addr; /* 04: COM3 I/O address */ |
| 36 | WORD Com4Addr; /* 06: COM4 I/O address */ |
| 37 | WORD Lpt1Addr; /* 08: LPT1 I/O address */ |
| 38 | WORD Lpt2Addr; /* 0a: LPT2 I/O address */ |
| 39 | WORD Lpt3Addr; /* 0c: LPT3 I/O address */ |
| 40 | WORD Lpt4Addr; /* 0e: LPT4 I/O address */ |
| 41 | WORD InstalledHardware; /* 10: Installed hardware flags */ |
| 42 | BYTE POSTstatus; /* 12: Power-On Self Test status */ |
| 43 | WORD MemSize WINE_PACKED; /* 13: Base memory size in Kb */ |
| 44 | WORD unused1 WINE_PACKED; /* 15: Manufacturing test scratch pad */ |
| 45 | BYTE KbdFlags1; /* 17: Keyboard flags 1 */ |
| 46 | BYTE KbdFlags2; /* 18: Keyboard flags 2 */ |
| 47 | BYTE unused2; /* 19: Keyboard driver workspace */ |
| 48 | WORD NextKbdCharPtr; /* 1a: Next character in kbd buffer */ |
| 49 | WORD FirstKbdCharPtr; /* 1c: First character in kbd buffer */ |
| 50 | WORD KbdBuffer[16]; /* 1e: Keyboard buffer */ |
| 51 | BYTE DisketteStatus1; /* 3e: Diskette recalibrate status */ |
| 52 | BYTE DisketteStatus2; /* 3f: Diskette motor status */ |
| 53 | BYTE DisketteStatus3; /* 40: Diskette motor timeout */ |
| 54 | BYTE DisketteStatus4; /* 41: Diskette last operation status */ |
| 55 | BYTE DiskStatus[7]; /* 42: Disk status/command bytes */ |
| 56 | BYTE VideoMode; /* 49: Video mode */ |
| 57 | WORD VideoColumns; /* 4a: Number of columns */ |
| 58 | WORD VideoPageSize; /* 4c: Video page size in bytes */ |
| 59 | WORD VideoPageStartAddr; /* 4e: Video page start address */ |
Andreas Mohr | db31151 | 2002-07-01 18:13:52 +0000 | [diff] [blame] | 60 | BYTE VideoCursorPos[16]; /* 50: Cursor position for 8 pages, column/row order */ |
Andreas Mohr | f83cf69 | 1999-03-13 18:00:52 +0000 | [diff] [blame] | 61 | WORD VideoCursorType; /* 60: Video cursor type */ |
| 62 | BYTE VideoCurPage; /* 62: Video current page */ |
| 63 | WORD VideoCtrlAddr WINE_PACKED; /* 63: Video controller address */ |
| 64 | BYTE VideoReg1; /* 65: Video mode select register */ |
| 65 | BYTE VideoReg2; /* 66: Video CGA palette register */ |
| 66 | DWORD ResetEntry WINE_PACKED; /* 67: Warm reset entry point */ |
| 67 | BYTE LastIRQ; /* 6b: Last unexpected interrupt */ |
| 68 | DWORD Ticks; /* 6c: Ticks since midnight */ |
| 69 | BYTE TicksOverflow; /* 70: Timer overflow if past midnight */ |
| 70 | BYTE CtrlBreakFlag; /* 71: Ctrl-Break flag */ |
| 71 | WORD ResetFlag; /* 72: POST Reset flag */ |
| 72 | BYTE DiskOpStatus; /* 74: Last hard-disk operation status */ |
| 73 | BYTE NbHardDisks; /* 75: Number of hard disks */ |
| 74 | BYTE DiskCtrlByte; /* 76: Disk control byte */ |
| 75 | BYTE DiskIOPort; /* 77: Disk I/O port offset */ |
| 76 | BYTE LptTimeout[4]; /* 78: Timeouts for parallel ports */ |
| 77 | BYTE ComTimeout[4]; /* 7c: Timeouts for serial ports */ |
| 78 | WORD KbdBufferStart; /* 80: Keyboard buffer start */ |
| 79 | WORD KbdBufferEnd; /* 82: Keyboard buffer end */ |
| 80 | BYTE RowsOnScreenMinus1; /* 84: EGA only */ |
| 81 | WORD BytesPerChar WINE_PACKED; /* 85: EGA only */ |
| 82 | BYTE ModeOptions; /* 87: EGA only */ |
| 83 | BYTE FeatureBitsSwitches; /* 88: EGA only */ |
| 84 | BYTE VGASettings; /* 89: VGA misc settings */ |
| 85 | BYTE DisplayCombination; /* 8A: VGA display combinations */ |
| 86 | BYTE DiskDataRate; /* 8B: Last disk data rate selected */ |
| 87 | } BIOSDATA; |
| 88 | |
Patrik Stridvall | c7a8dde | 1999-04-25 12:36:53 +0000 | [diff] [blame] | 89 | #include "poppack.h" |
Ove Kaaven | 3f89809 | 1999-03-23 13:45:25 +0000 | [diff] [blame] | 90 | |
Alexandre Julliard | 80fc23a | 2000-10-15 00:37:50 +0000 | [diff] [blame] | 91 | extern WORD DOSMEM_0000H; |
Alexandre Julliard | 83f52d1 | 2000-09-26 22:20:14 +0000 | [diff] [blame] | 92 | extern WORD DOSMEM_BiosDataSeg; |
| 93 | extern WORD DOSMEM_BiosSysSeg; |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 94 | |
Jukka Heinonen | 3546290 | 2002-11-27 20:18:50 +0000 | [diff] [blame] | 95 | /* msdos/dosmem.c */ |
Ove Kaaven | e6d8768 | 2000-07-30 13:32:10 +0000 | [diff] [blame] | 96 | extern BOOL DOSMEM_Init(BOOL); |
Ulrich Weigand | 7b57b24 | 1998-12-10 10:47:26 +0000 | [diff] [blame] | 97 | extern void DOSMEM_Tick(WORD timer); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 98 | extern WORD DOSMEM_AllocSelector(WORD); |
Alexandre Julliard | 83f52d1 | 2000-09-26 22:20:14 +0000 | [diff] [blame] | 99 | extern LPVOID DOSMEM_GetBlock(UINT size, WORD* p); |
Ove Kaaven | 7b49914 | 2000-07-28 22:23:59 +0000 | [diff] [blame] | 100 | extern BOOL DOSMEM_FreeBlock(void* ptr); |
Jukka Heinonen | 54f377c | 2003-02-19 22:11:04 +0000 | [diff] [blame] | 101 | extern UINT DOSMEM_ResizeBlock(void* ptr, UINT size, BOOL exact); |
Ove Kaaven | 7b49914 | 2000-07-28 22:23:59 +0000 | [diff] [blame] | 102 | extern UINT DOSMEM_Available(void); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 103 | extern LPVOID DOSMEM_MapRealToLinear(DWORD); /* real-mode to linear */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 104 | extern LPVOID DOSMEM_MapDosToLinear(UINT); /* linear DOS to Wine */ |
| 105 | extern UINT DOSMEM_MapLinearToDos(LPVOID); /* linear Wine to DOS */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 106 | |
Alexandre Julliard | b375678 | 1999-08-01 12:15:12 +0000 | [diff] [blame] | 107 | /* memory/instr.c */ |
Alexandre Julliard | 0b34697 | 2003-05-14 19:41:16 +0000 | [diff] [blame] | 108 | extern DWORD INSTR_EmulateInstruction( CONTEXT86 *context ); |
Alexandre Julliard | b375678 | 1999-08-01 12:15:12 +0000 | [diff] [blame] | 109 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 110 | /* msdos/ioports.c */ |
| 111 | extern DWORD IO_inport( int port, int count ); |
| 112 | extern void IO_outport( int port, int count, DWORD value ); |
| 113 | |
Ove Kaaven | 7dc3c60 | 1998-10-11 12:15:18 +0000 | [diff] [blame] | 114 | /* msdos/dpmi.c */ |
Ove Kaaven | e5557b3 | 2000-12-26 00:22:45 +0000 | [diff] [blame] | 115 | extern BOOL DPMI_LoadDosSystem(void); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 116 | |
Uwe Bonnes | 6509fa9 | 2001-06-26 21:06:07 +0000 | [diff] [blame] | 117 | /* misc/ppdev.c */ |
Uwe Bonnes | 6509fa9 | 2001-06-26 21:06:07 +0000 | [diff] [blame] | 118 | extern BOOL IO_pp_outp(int port, DWORD* res); |
| 119 | extern int IO_pp_inp(int port, DWORD* res); |
| 120 | extern char IO_pp_init(void); |
| 121 | |
Alexandre Julliard | db0747d | 2000-12-13 20:23:41 +0000 | [diff] [blame] | 122 | #define PTR_REAL_TO_LIN(seg,off) \ |
| 123 | ((void*)(((unsigned int)(seg) << 4) + LOWORD(off))) |
| 124 | |
Jukka Heinonen | eca6182 | 2002-10-23 22:24:10 +0000 | [diff] [blame] | 125 | /* NOTE: Interrupts might get called from four modes: real mode, 16-bit, |
| 126 | * 32-bit segmented (DPMI32) and 32-bit linear (via DeviceIoControl). |
| 127 | * For automatic conversion of pointer |
Ulrich Weigand | 7129d9f | 1998-11-25 10:29:22 +0000 | [diff] [blame] | 128 | * parameters, interrupt handlers should use CTX_SEG_OFF_TO_LIN with |
Andreas Mohr | 217a682 | 2000-08-25 21:56:19 +0000 | [diff] [blame] | 129 | * the contents of a segment register as second and the contents of |
Ulrich Weigand | 7129d9f | 1998-11-25 10:29:22 +0000 | [diff] [blame] | 130 | * a *32-bit* general register as third parameter, e.g. |
| 131 | * CTX_SEG_OFF_TO_LIN( context, DS_reg(context), EDX_reg(context) ) |
| 132 | * This will generate a linear pointer in all three cases: |
Alexandre Julliard | 770eb51 | 2000-09-24 20:47:50 +0000 | [diff] [blame] | 133 | * Real-Mode: Seg*16 + LOWORD(Offset) |
Ulrich Weigand | 7129d9f | 1998-11-25 10:29:22 +0000 | [diff] [blame] | 134 | * 16-bit: convert (Seg, LOWORD(Offset)) to linear |
Jukka Heinonen | eca6182 | 2002-10-23 22:24:10 +0000 | [diff] [blame] | 135 | * 32-bit segmented: convert (Seg, Offset) to linear |
| 136 | * 32-bit linear: use Offset as linear address (DeviceIoControl!) |
Ulrich Weigand | 7129d9f | 1998-11-25 10:29:22 +0000 | [diff] [blame] | 137 | * |
| 138 | * Real-mode is recognized by checking the V86 bit in the flags register, |
Jukka Heinonen | eca6182 | 2002-10-23 22:24:10 +0000 | [diff] [blame] | 139 | * 32-bit linear mode is recognized by checking whether 'seg' is |
| 140 | * a system selector (0 counts also as 32-bit segment) and 32-bit |
| 141 | * segmented mode is recognized by checking whether 'seg' is 32-bit |
| 142 | * selector which is neither system selector nor zero. |
Ulrich Weigand | 7129d9f | 1998-11-25 10:29:22 +0000 | [diff] [blame] | 143 | */ |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 144 | #define CTX_SEG_OFF_TO_LIN(context,seg,off) \ |
Alexandre Julliard | ce13153 | 2003-02-26 20:34:45 +0000 | [diff] [blame] | 145 | (ISV86(context) ? PTR_REAL_TO_LIN((seg),(off)) : wine_ldt_get_ptr((seg),(off))) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 146 | |
Alexandre Julliard | 808cb04 | 1995-08-17 17:11:36 +0000 | [diff] [blame] | 147 | #define INT_BARF(context,num) \ |
Alexandre Julliard | 383da68 | 2000-02-10 22:15:21 +0000 | [diff] [blame] | 148 | ERR( "int%x: unknown/not implemented parameters:\n" \ |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 149 | "int%x: AX %04x, BX %04x, CX %04x, DX %04x, " \ |
| 150 | "SI %04x, DI %04x, DS %04x, ES %04x\n", \ |
Alexandre Julliard | d8fab2e | 2000-09-25 23:53:07 +0000 | [diff] [blame] | 151 | (num), (num), LOWORD((context)->Eax), LOWORD((context)->Ebx), \ |
| 152 | LOWORD((context)->Ecx), LOWORD((context)->Edx), LOWORD((context)->Esi), \ |
| 153 | LOWORD((context)->Edi), (WORD)(context)->SegDs, (WORD)(context)->SegEs ) |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 154 | |
Alexandre Julliard | 3fa613c | 2002-08-31 18:47:00 +0000 | [diff] [blame] | 155 | /* Macros for easier access to i386 context registers */ |
| 156 | |
| 157 | #define AX_reg(context) ((WORD)(context)->Eax) |
| 158 | #define BX_reg(context) ((WORD)(context)->Ebx) |
| 159 | #define CX_reg(context) ((WORD)(context)->Ecx) |
| 160 | #define DX_reg(context) ((WORD)(context)->Edx) |
| 161 | #define SI_reg(context) ((WORD)(context)->Esi) |
| 162 | #define DI_reg(context) ((WORD)(context)->Edi) |
| 163 | |
| 164 | #define AL_reg(context) ((BYTE)(context)->Eax) |
| 165 | #define AH_reg(context) ((BYTE)((context)->Eax >> 8)) |
| 166 | #define BL_reg(context) ((BYTE)(context)->Ebx) |
| 167 | #define BH_reg(context) ((BYTE)((context)->Ebx >> 8)) |
| 168 | #define CL_reg(context) ((BYTE)(context)->Ecx) |
| 169 | #define CH_reg(context) ((BYTE)((context)->Ecx >> 8)) |
| 170 | #define DL_reg(context) ((BYTE)(context)->Edx) |
| 171 | #define DH_reg(context) ((BYTE)((context)->Edx >> 8)) |
| 172 | |
| 173 | #define SET_CFLAG(context) ((context)->EFlags |= 0x0001) |
| 174 | #define RESET_CFLAG(context) ((context)->EFlags &= ~0x0001) |
| 175 | #define SET_ZFLAG(context) ((context)->EFlags |= 0x0040) |
| 176 | #define RESET_ZFLAG(context) ((context)->EFlags &= ~0x0040) |
| 177 | #define ISV86(context) ((context)->EFlags & 0x00020000) |
| 178 | |
Alexandre Julliard | 3dc1f2d | 2003-03-22 21:12:27 +0000 | [diff] [blame] | 179 | #define SET_AX(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xffff) | (WORD)(val))) |
| 180 | #define SET_BX(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xffff) | (WORD)(val))) |
| 181 | #define SET_CX(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xffff) | (WORD)(val))) |
| 182 | #define SET_DX(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xffff) | (WORD)(val))) |
| 183 | #define SET_SI(context,val) ((void)((context)->Esi = ((context)->Esi & ~0xffff) | (WORD)(val))) |
| 184 | #define SET_DI(context,val) ((void)((context)->Edi = ((context)->Edi & ~0xffff) | (WORD)(val))) |
Alexandre Julliard | 3fa613c | 2002-08-31 18:47:00 +0000 | [diff] [blame] | 185 | |
Alexandre Julliard | 3dc1f2d | 2003-03-22 21:12:27 +0000 | [diff] [blame] | 186 | #define SET_AL(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xff) | (BYTE)(val))) |
| 187 | #define SET_BL(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xff) | (BYTE)(val))) |
| 188 | #define SET_CL(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xff) | (BYTE)(val))) |
| 189 | #define SET_DL(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xff) | (BYTE)(val))) |
Alexandre Julliard | 3fa613c | 2002-08-31 18:47:00 +0000 | [diff] [blame] | 190 | |
Alexandre Julliard | 3dc1f2d | 2003-03-22 21:12:27 +0000 | [diff] [blame] | 191 | #define SET_AH(context,val) ((void)((context)->Eax = ((context)->Eax & ~0xff00) | (((BYTE)(val)) << 8))) |
| 192 | #define SET_BH(context,val) ((void)((context)->Ebx = ((context)->Ebx & ~0xff00) | (((BYTE)(val)) << 8))) |
| 193 | #define SET_CH(context,val) ((void)((context)->Ecx = ((context)->Ecx & ~0xff00) | (((BYTE)(val)) << 8))) |
| 194 | #define SET_DH(context,val) ((void)((context)->Edx = ((context)->Edx & ~0xff00) | (((BYTE)(val)) << 8))) |
Alexandre Julliard | 3fa613c | 2002-08-31 18:47:00 +0000 | [diff] [blame] | 195 | |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 196 | #endif /* __WINE_MISCEMU_H */ |