blob: e92e96e82b6876dd1fde3f1c268cbe2b5d1466ed [file] [log] [blame]
Jason Jina63ce952007-07-06 08:34:56 +08001/****************************************************************************
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/****************************************************************************
60REMARKS:
61Data structure used to describe the details specific to a particular VGA
62controller. This information is used to allow the VGA controller to be
63swapped on the fly within the BIOS emulator.
64
65HEADER:
66biosemu.h
67
68MEMBERS:
69pciInfo - PCI device information block for the controller
70BIOSImage - Pointer to a read/write copy of the BIOS image
71BIOSImageLen - Length of the BIOS image
72LowMem - Copy of key low memory areas
73****************************************************************************/
74typedef struct {
75 PCIDeviceInfo *pciInfo;
76 void *BIOSImage;
77 ulong BIOSImageLen;
78 uchar LowMem[1536];
79} BE_VGAInfo;
80#else
81/****************************************************************************
82REMARKS:
83Data structure used to describe the details for the BIOS emulator system
84environment as used by the X86 emulator library.
85
86HEADER:
87biosemu.h
88
89MEMBERS:
90vgaInfo - VGA BIOS information structure
91biosmem_base - Base of the BIOS image
92biosmem_limit - Limit of the BIOS image
93busmem_base - Base of the VGA bus memory
94****************************************************************************/
95typedef 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/****************************************************************************
116REMARKS:
117Data structure used to describe the details for the BIOS emulator system
118environment as used by the X86 emulator library.
119
120HEADER:
121biosemu.h
122
123MEMBERS:
124vgaInfo - VGA BIOS information structure
125biosmem_base - Base of the BIOS image
126biosmem_limit - Limit of the BIOS image
127busmem_base - Base of the VGA bus memory
128timer - Timer used to emulate PC timer ports
129timer0 - Latched value for timer 0
York Sun4a598092013-04-01 11:29:11 -0700130timer0Latched - true if timer 0 value was just latched
Jason Jina63ce952007-07-06 08:34:56 +0800131timer2 - Current value for timer 2
York Sun4a598092013-04-01 11:29:11 -0700132emulateVGA - true to emulate VGA I/O and memory accesses
Jason Jina63ce952007-07-06 08:34:56 +0800133****************************************************************************/
134
135typedef 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/****************************************************************************
177REMARKS:
178Structure describing the 32-bit extended x86 CPU registers
179
180HEADER:
181pmapi.h
182
183MEMBERS:
184eax - Value of the EAX register
185ebx - Value of the EBX register
186ecx - Value of the ECX register
187edx - Value of the EDX register
188esi - Value of the ESI register
189edi - Value of the EDI register
190cflag - Value of the carry flag
191****************************************************************************/
192typedef 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/****************************************************************************
203REMARKS:
204Structure describing the 16-bit x86 CPU registers
205
206HEADER:
207pmapi.h
208
209MEMBERS:
210ax - Value of the AX register
211bx - Value of the BX register
212cx - Value of the CX register
213dx - Value of the DX register
214si - Value of the SI register
215di - Value of the DI register
216cflag - Value of the carry flag
217****************************************************************************/
218#ifdef __BIG_ENDIAN__
219typedef 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
229typedef 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/****************************************************************************
241REMARKS:
242Structure describing the 8-bit x86 CPU registers
243
244HEADER:
245pmapi.h
246
247MEMBERS:
248al - Value of the AL register
249ah - Value of the AH register
250bl - Value of the BL register
251bh - Value of the BH register
252cl - Value of the CL register
253ch - Value of the CH register
254dl - Value of the DL register
255dh - Value of the DH register
256****************************************************************************/
257#ifdef __BIG_ENDIAN__
258typedef 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
269typedef 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/****************************************************************************
286REMARKS:
287Structure describing all the x86 CPU registers
288
289HEADER:
290pmapi.h
291
292MEMBERS:
293e - Member to access registers as 32-bit values
294x - Member to access registers as 16-bit values
295h - Member to access registers as 8-bit values
296****************************************************************************/
297typedef union {
298 RMDWORDREGS e;
299 RMWORDREGS x;
300 RMBYTEREGS h;
301} RMREGS;
302
303/****************************************************************************
304REMARKS:
305Structure describing all the x86 segment registers
306
307HEADER:
308pmapi.h
309
310MEMBERS:
311es - ES segment register
312cs - CS segment register
313ss - SS segment register
314ds - DS segment register
315fs - FS segment register
316gs - GS segment register
317****************************************************************************/
318typedef 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/****************************************************************************
332REMARKS:
333Structure defining all the BIOS Emulator API functions as exported from
334the Binary Portable DLL.
335{secret}
336****************************************************************************/
337typedef 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/****************************************************************************
354REMARKS:
355Function pointer type for the Binary Portable DLL initialisation entry point.
356{secret}
357****************************************************************************/
358typedef BE_exports *(PMAPIP BE_initLibrary_t) (PM_imports * PMImp);
359#endif
360
361#pragma pack()
362
363/*---------------------------- Global variables ---------------------------*/
364
365#ifdef __cplusplus
366extern "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 */