Jason Jin | a63ce95 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * |
| 3 | * BIOS emulator and interface |
| 4 | * to Realmode X86 Emulator Library |
| 5 | * |
| 6 | * Copyright (C) 1996-1999 SciTech Software, Inc. |
| 7 | * |
| 8 | * ======================================================================== |
| 9 | * |
| 10 | * Permission to use, copy, modify, distribute, and sell this software and |
| 11 | * its documentation for any purpose is hereby granted without fee, |
| 12 | * provided that the above copyright notice appear in all copies and that |
| 13 | * both that copyright notice and this permission notice appear in |
| 14 | * supporting documentation, and that the name of the authors not be used |
| 15 | * in advertising or publicity pertaining to distribution of the software |
| 16 | * without specific, written prior permission. The authors makes no |
| 17 | * representations about the suitability of this software for any purpose. |
| 18 | * It is provided "as is" without express or implied warranty. |
| 19 | * |
| 20 | * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 21 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 22 | * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 23 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF |
| 24 | * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
| 25 | * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 26 | * PERFORMANCE OF THIS SOFTWARE. |
| 27 | * |
| 28 | * ======================================================================== |
| 29 | * |
| 30 | * Language: ANSI C |
| 31 | * Environment: Any |
| 32 | * Developer: Kendall Bennett |
| 33 | * |
| 34 | * Description: Header file for the real mode x86 BIOS emulator, which is |
| 35 | * used to warmboot any number of VGA compatible PCI/AGP |
| 36 | * controllers under any OS, on any processor family that |
| 37 | * supports PCI. We also allow the user application to call |
| 38 | * real mode BIOS functions and Int 10h functions (including |
| 39 | * the VESA BIOS). |
| 40 | * |
| 41 | ****************************************************************************/ |
| 42 | |
| 43 | #ifndef __BIOSEMU_H |
| 44 | #define __BIOSEMU_H |
| 45 | |
| 46 | #ifdef __KERNEL__ |
| 47 | #include "x86emu.h" |
| 48 | #else |
| 49 | #include "x86emu.h" |
| 50 | #include "pmapi.h" |
| 51 | #include "pcilib.h" |
| 52 | #endif |
| 53 | |
| 54 | /*---------------------- Macros and type definitions ----------------------*/ |
| 55 | |
| 56 | #pragma pack(1) |
| 57 | |
| 58 | #ifndef __KERNEL__ |
| 59 | /**************************************************************************** |
| 60 | REMARKS: |
| 61 | Data structure used to describe the details specific to a particular VGA |
| 62 | controller. This information is used to allow the VGA controller to be |
| 63 | swapped on the fly within the BIOS emulator. |
| 64 | |
| 65 | HEADER: |
| 66 | biosemu.h |
| 67 | |
| 68 | MEMBERS: |
| 69 | pciInfo - PCI device information block for the controller |
| 70 | BIOSImage - Pointer to a read/write copy of the BIOS image |
| 71 | BIOSImageLen - Length of the BIOS image |
| 72 | LowMem - Copy of key low memory areas |
| 73 | ****************************************************************************/ |
| 74 | typedef struct { |
| 75 | PCIDeviceInfo *pciInfo; |
| 76 | void *BIOSImage; |
| 77 | ulong BIOSImageLen; |
| 78 | uchar LowMem[1536]; |
| 79 | } BE_VGAInfo; |
| 80 | #else |
| 81 | /**************************************************************************** |
| 82 | REMARKS: |
| 83 | Data structure used to describe the details for the BIOS emulator system |
| 84 | environment as used by the X86 emulator library. |
| 85 | |
| 86 | HEADER: |
| 87 | biosemu.h |
| 88 | |
| 89 | MEMBERS: |
| 90 | vgaInfo - VGA BIOS information structure |
| 91 | biosmem_base - Base of the BIOS image |
| 92 | biosmem_limit - Limit of the BIOS image |
| 93 | busmem_base - Base of the VGA bus memory |
| 94 | ****************************************************************************/ |
| 95 | typedef struct { |
| 96 | int function; |
| 97 | int device; |
| 98 | int bus; |
| 99 | u32 VendorID; |
| 100 | u32 DeviceID; |
| 101 | pci_dev_t pcidev; |
| 102 | void *BIOSImage; |
| 103 | u32 BIOSImageLen; |
| 104 | u8 LowMem[1536]; |
| 105 | } BE_VGAInfo; |
| 106 | |
| 107 | #endif /* __KERNEL__ */ |
| 108 | |
| 109 | #define CRT_C 24 /* 24 CRT Controller Registers */ |
| 110 | #define ATT_C 21 /* 21 Attribute Controller Registers */ |
| 111 | #define GRA_C 9 /* 9 Graphics Controller Registers */ |
| 112 | #define SEQ_C 5 /* 5 Sequencer Registers */ |
| 113 | #define PAL_C 768 /* 768 Palette Registers */ |
| 114 | |
| 115 | /**************************************************************************** |
| 116 | REMARKS: |
| 117 | Data structure used to describe the details for the BIOS emulator system |
| 118 | environment as used by the X86 emulator library. |
| 119 | |
| 120 | HEADER: |
| 121 | biosemu.h |
| 122 | |
| 123 | MEMBERS: |
| 124 | vgaInfo - VGA BIOS information structure |
| 125 | biosmem_base - Base of the BIOS image |
| 126 | biosmem_limit - Limit of the BIOS image |
| 127 | busmem_base - Base of the VGA bus memory |
| 128 | timer - Timer used to emulate PC timer ports |
| 129 | timer0 - Latched value for timer 0 |
| 130 | timer0Latched - True if timer 0 value was just latched |
| 131 | timer2 - Current value for timer 2 |
| 132 | emulateVGA - True to emulate VGA I/O and memory accesses |
| 133 | ****************************************************************************/ |
| 134 | |
| 135 | typedef struct { |
| 136 | BE_VGAInfo vgaInfo; |
| 137 | ulong biosmem_base; |
| 138 | ulong biosmem_limit; |
| 139 | ulong busmem_base; |
| 140 | |
| 141 | u32 timer0; |
| 142 | int timer0Latched; |
| 143 | u32 timer1; |
| 144 | int timer1Latched; |
| 145 | u32 timer2; |
| 146 | int timer2Latched; |
| 147 | |
| 148 | int emulateVGA; |
| 149 | u8 emu61; |
| 150 | u8 emu70; |
| 151 | int flipFlop3C0; |
| 152 | u32 configAddress; |
| 153 | u8 emu3C0; |
| 154 | u8 emu3C1[ATT_C]; |
| 155 | u8 emu3C2; |
| 156 | u8 emu3C4; |
| 157 | u8 emu3C5[SEQ_C]; |
| 158 | u8 emu3C6; |
| 159 | uint emu3C7; |
| 160 | uint emu3C8; |
| 161 | u8 emu3C9[PAL_C]; |
| 162 | u8 emu3CE; |
| 163 | u8 emu3CF[GRA_C]; |
| 164 | u8 emu3D4; |
| 165 | u8 emu3D5[CRT_C]; |
| 166 | u8 emu3DA; |
| 167 | |
| 168 | } BE_sysEnv; |
| 169 | |
| 170 | #ifdef __KERNEL__ |
| 171 | |
| 172 | /* Define some types when compiling for the Linux kernel that normally |
| 173 | * come from the SciTech PM library. |
| 174 | */ |
| 175 | |
| 176 | /**************************************************************************** |
| 177 | REMARKS: |
| 178 | Structure describing the 32-bit extended x86 CPU registers |
| 179 | |
| 180 | HEADER: |
| 181 | pmapi.h |
| 182 | |
| 183 | MEMBERS: |
| 184 | eax - Value of the EAX register |
| 185 | ebx - Value of the EBX register |
| 186 | ecx - Value of the ECX register |
| 187 | edx - Value of the EDX register |
| 188 | esi - Value of the ESI register |
| 189 | edi - Value of the EDI register |
| 190 | cflag - Value of the carry flag |
| 191 | ****************************************************************************/ |
| 192 | typedef struct { |
| 193 | u32 eax; |
| 194 | u32 ebx; |
| 195 | u32 ecx; |
| 196 | u32 edx; |
| 197 | u32 esi; |
| 198 | u32 edi; |
| 199 | u32 cflag; |
| 200 | } RMDWORDREGS; |
| 201 | |
| 202 | /**************************************************************************** |
| 203 | REMARKS: |
| 204 | Structure describing the 16-bit x86 CPU registers |
| 205 | |
| 206 | HEADER: |
| 207 | pmapi.h |
| 208 | |
| 209 | MEMBERS: |
| 210 | ax - Value of the AX register |
| 211 | bx - Value of the BX register |
| 212 | cx - Value of the CX register |
| 213 | dx - Value of the DX register |
| 214 | si - Value of the SI register |
| 215 | di - Value of the DI register |
| 216 | cflag - Value of the carry flag |
| 217 | ****************************************************************************/ |
| 218 | #ifdef __BIG_ENDIAN__ |
| 219 | typedef struct { |
| 220 | u16 ax_hi, ax; |
| 221 | u16 bx_hi, bx; |
| 222 | u16 cx_hi, cx; |
| 223 | u16 dx_hi, dx; |
| 224 | u16 si_hi, si; |
| 225 | u16 di_hi, di; |
| 226 | u16 cflag_hi, cflag; |
| 227 | } RMWORDREGS; |
| 228 | #else |
| 229 | typedef struct { |
| 230 | u16 ax, ax_hi; |
| 231 | u16 bx, bx_hi; |
| 232 | u16 cx, cx_hi; |
| 233 | u16 dx, dx_hi; |
| 234 | u16 si, si_hi; |
| 235 | u16 di, di_hi; |
| 236 | u16 cflag, cflag_hi; |
| 237 | } RMWORDREGS; |
| 238 | #endif |
| 239 | |
| 240 | /**************************************************************************** |
| 241 | REMARKS: |
| 242 | Structure describing the 8-bit x86 CPU registers |
| 243 | |
| 244 | HEADER: |
| 245 | pmapi.h |
| 246 | |
| 247 | MEMBERS: |
| 248 | al - Value of the AL register |
| 249 | ah - Value of the AH register |
| 250 | bl - Value of the BL register |
| 251 | bh - Value of the BH register |
| 252 | cl - Value of the CL register |
| 253 | ch - Value of the CH register |
| 254 | dl - Value of the DL register |
| 255 | dh - Value of the DH register |
| 256 | ****************************************************************************/ |
| 257 | #ifdef __BIG_ENDIAN__ |
| 258 | typedef struct { |
| 259 | u16 ax_hi; |
| 260 | u8 ah, al; |
| 261 | u16 bx_hi; |
| 262 | u8 bh, bl; |
| 263 | u16 cx_hi; |
| 264 | u8 ch, cl; |
| 265 | u16 dx_hi; |
| 266 | u8 dh, dl; |
| 267 | } RMBYTEREGS; |
| 268 | #else |
| 269 | typedef struct { |
| 270 | u8 al; |
| 271 | u8 ah; |
| 272 | u16 ax_hi; |
| 273 | u8 bl; |
| 274 | u8 bh; |
| 275 | u16 bx_hi; |
| 276 | u8 cl; |
| 277 | u8 ch; |
| 278 | u16 cx_hi; |
| 279 | u8 dl; |
| 280 | u8 dh; |
| 281 | u16 dx_hi; |
| 282 | } RMBYTEREGS; |
| 283 | #endif |
| 284 | |
| 285 | /**************************************************************************** |
| 286 | REMARKS: |
| 287 | Structure describing all the x86 CPU registers |
| 288 | |
| 289 | HEADER: |
| 290 | pmapi.h |
| 291 | |
| 292 | MEMBERS: |
| 293 | e - Member to access registers as 32-bit values |
| 294 | x - Member to access registers as 16-bit values |
| 295 | h - Member to access registers as 8-bit values |
| 296 | ****************************************************************************/ |
| 297 | typedef union { |
| 298 | RMDWORDREGS e; |
| 299 | RMWORDREGS x; |
| 300 | RMBYTEREGS h; |
| 301 | } RMREGS; |
| 302 | |
| 303 | /**************************************************************************** |
| 304 | REMARKS: |
| 305 | Structure describing all the x86 segment registers |
| 306 | |
| 307 | HEADER: |
| 308 | pmapi.h |
| 309 | |
| 310 | MEMBERS: |
| 311 | es - ES segment register |
| 312 | cs - CS segment register |
| 313 | ss - SS segment register |
| 314 | ds - DS segment register |
| 315 | fs - FS segment register |
| 316 | gs - GS segment register |
| 317 | ****************************************************************************/ |
| 318 | typedef struct { |
| 319 | u16 es; |
| 320 | u16 cs; |
| 321 | u16 ss; |
| 322 | u16 ds; |
| 323 | u16 fs; |
| 324 | u16 gs; |
| 325 | } RMSREGS; |
| 326 | |
| 327 | #endif /* __KERNEL__ */ |
| 328 | |
| 329 | #ifndef __KERNEL__ |
| 330 | |
| 331 | /**************************************************************************** |
| 332 | REMARKS: |
| 333 | Structure defining all the BIOS Emulator API functions as exported from |
| 334 | the Binary Portable DLL. |
| 335 | {secret} |
| 336 | ****************************************************************************/ |
| 337 | typedef struct { |
| 338 | ulong dwSize; |
| 339 | ibool(PMAPIP BE_init) (u32 debugFlags, int memSize, BE_VGAInfo * info); |
| 340 | void (PMAPIP BE_setVGA) (BE_VGAInfo * info); |
| 341 | void (PMAPIP BE_getVGA) (BE_VGAInfo * info); |
| 342 | void *(PMAPIP BE_mapRealPointer) (uint r_seg, uint r_off); |
| 343 | void *(PMAPIP BE_getVESABuf) (uint * len, uint * rseg, uint * roff); |
| 344 | void (PMAPIP BE_callRealMode) (uint seg, uint off, RMREGS * regs, |
| 345 | RMSREGS * sregs); |
| 346 | int (PMAPIP BE_int86) (int intno, RMREGS * in, RMREGS * out); |
| 347 | int (PMAPIP BE_int86x) (int intno, RMREGS * in, RMREGS * out, |
| 348 | RMSREGS * sregs); |
| 349 | void *reserved1; |
| 350 | void (PMAPIP BE_exit) (void); |
| 351 | } BE_exports; |
| 352 | |
| 353 | /**************************************************************************** |
| 354 | REMARKS: |
| 355 | Function pointer type for the Binary Portable DLL initialisation entry point. |
| 356 | {secret} |
| 357 | ****************************************************************************/ |
| 358 | typedef BE_exports *(PMAPIP BE_initLibrary_t) (PM_imports * PMImp); |
| 359 | #endif |
| 360 | |
| 361 | #pragma pack() |
| 362 | |
| 363 | /*---------------------------- Global variables ---------------------------*/ |
| 364 | |
| 365 | #ifdef __cplusplus |
| 366 | extern "C" { /* Use "C" linkage when in C++ mode */ |
| 367 | #endif |
| 368 | |
| 369 | /* {secret} Global BIOS emulator system environment */ |
| 370 | extern BE_sysEnv _BE_env; |
| 371 | |
| 372 | /*-------------------------- Function Prototypes --------------------------*/ |
| 373 | |
| 374 | /* BIOS emulator library entry points */ |
| 375 | int X86API BE_init(u32 debugFlags, int memSize, BE_VGAInfo * info, |
| 376 | int shared); |
| 377 | void X86API BE_setVGA(BE_VGAInfo * info); |
| 378 | void X86API BE_getVGA(BE_VGAInfo * info); |
| 379 | void X86API BE_setDebugFlags(u32 debugFlags); |
| 380 | void *X86API BE_mapRealPointer(uint r_seg, uint r_off); |
| 381 | void *X86API BE_getVESABuf(uint * len, uint * rseg, uint * roff); |
| 382 | void X86API BE_callRealMode(uint seg, uint off, RMREGS * regs, |
| 383 | RMSREGS * sregs); |
| 384 | int X86API BE_int86(int intno, RMREGS * in, RMREGS * out); |
| 385 | int X86API BE_int86x(int intno, RMREGS * in, RMREGS * out, |
| 386 | RMSREGS * sregs); |
| 387 | void X86API BE_exit(void); |
| 388 | |
| 389 | #ifdef __cplusplus |
| 390 | } /* End of "C" linkage for C++ */ |
| 391 | #endif |
| 392 | #endif /* __BIOSEMU_H */ |