• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <bios_emul.h>
47 
48 #ifdef __KERNEL__
49 #include "x86emu.h"
50 #else
51 #include "x86emu.h"
52 #include "pmapi.h"
53 #include "pcilib.h"
54 #endif
55 
56 /*---------------------- Macros and type definitions ----------------------*/
57 
58 #pragma pack(1)
59 
60 #define CRT_C   24		/* 24  CRT Controller Registers             */
61 #define ATT_C   21		/* 21  Attribute Controller Registers       */
62 #define GRA_C   9		/* 9   Graphics Controller Registers        */
63 #define SEQ_C   5		/* 5   Sequencer Registers                  */
64 #define PAL_C   768		/* 768 Palette Registers                    */
65 
66 /****************************************************************************
67 REMARKS:
68 Data structure used to describe the details for the BIOS emulator system
69 environment as used by the X86 emulator library.
70 
71 HEADER:
72 biosemu.h
73 
74 MEMBERS:
75 vgaInfo         - VGA BIOS information structure
76 biosmem_base    - Base of the BIOS image
77 biosmem_limit   - Limit of the BIOS image
78 busmem_base     - Base of the VGA bus memory
79 timer           - Timer used to emulate PC timer ports
80 timer0          - Latched value for timer 0
81 timer0Latched   - true if timer 0 value was just latched
82 timer2          - Current value for timer 2
83 emulateVGA      - true to emulate VGA I/O and memory accesses
84 ****************************************************************************/
85 
86 typedef struct {
87 	BE_VGAInfo vgaInfo;
88 	ulong biosmem_base;
89 	ulong biosmem_limit;
90 	ulong busmem_base;
91 
92 	u32 timer0;
93 	int timer0Latched;
94 	u32 timer1;
95 	int timer1Latched;
96 	u32 timer2;
97 	int timer2Latched;
98 
99 	int emulateVGA;
100 	u8 emu61;
101 	u8 emu70;
102 	int flipFlop3C0;
103 	u32 configAddress;
104 	u8 emu3C0;
105 	u8 emu3C1[ATT_C];
106 	u8 emu3C2;
107 	u8 emu3C4;
108 	u8 emu3C5[SEQ_C];
109 	u8 emu3C6;
110 	uint emu3C7;
111 	uint emu3C8;
112 	u8 emu3C9[PAL_C];
113 	u8 emu3CE;
114 	u8 emu3CF[GRA_C];
115 	u8 emu3D4;
116 	u8 emu3D5[CRT_C];
117 	u8 emu3DA;
118 
119 } BE_sysEnv;
120 
121 #ifdef __KERNEL__
122 
123 /* Define some types when compiling for the Linux kernel that normally
124  * come from the SciTech PM library.
125  */
126 
127 /****************************************************************************
128 REMARKS:
129 Structure describing the 32-bit extended x86 CPU registers
130 
131 HEADER:
132 pmapi.h
133 
134 MEMBERS:
135 eax     - Value of the EAX register
136 ebx     - Value of the EBX register
137 ecx     - Value of the ECX register
138 edx     - Value of the EDX register
139 esi     - Value of the ESI register
140 edi     - Value of the EDI register
141 cflag   - Value of the carry flag
142 ****************************************************************************/
143 typedef struct {
144 	u32 eax;
145 	u32 ebx;
146 	u32 ecx;
147 	u32 edx;
148 	u32 esi;
149 	u32 edi;
150 	u32 cflag;
151 } RMDWORDREGS;
152 
153 /****************************************************************************
154 REMARKS:
155 Structure describing the 16-bit x86 CPU registers
156 
157 HEADER:
158 pmapi.h
159 
160 MEMBERS:
161 ax      - Value of the AX register
162 bx      - Value of the BX register
163 cx      - Value of the CX register
164 dx      - Value of the DX register
165 si      - Value of the SI register
166 di      - Value of the DI register
167 cflag   - Value of the carry flag
168 ****************************************************************************/
169 #ifdef __BIG_ENDIAN__
170 typedef struct {
171 	u16 ax_hi, ax;
172 	u16 bx_hi, bx;
173 	u16 cx_hi, cx;
174 	u16 dx_hi, dx;
175 	u16 si_hi, si;
176 	u16 di_hi, di;
177 	u16 cflag_hi, cflag;
178 } RMWORDREGS;
179 #else
180 typedef struct {
181 	u16 ax, ax_hi;
182 	u16 bx, bx_hi;
183 	u16 cx, cx_hi;
184 	u16 dx, dx_hi;
185 	u16 si, si_hi;
186 	u16 di, di_hi;
187 	u16 cflag, cflag_hi;
188 } RMWORDREGS;
189 #endif
190 
191 /****************************************************************************
192 REMARKS:
193 Structure describing the 8-bit x86 CPU registers
194 
195 HEADER:
196 pmapi.h
197 
198 MEMBERS:
199 al      - Value of the AL register
200 ah      - Value of the AH register
201 bl      - Value of the BL register
202 bh      - Value of the BH register
203 cl      - Value of the CL register
204 ch      - Value of the CH register
205 dl      - Value of the DL register
206 dh      - Value of the DH register
207 ****************************************************************************/
208 #ifdef __BIG_ENDIAN__
209 typedef struct {
210 	u16 ax_hi;
211 	u8 ah, al;
212 	u16 bx_hi;
213 	u8 bh, bl;
214 	u16 cx_hi;
215 	u8 ch, cl;
216 	u16 dx_hi;
217 	u8 dh, dl;
218 } RMBYTEREGS;
219 #else
220 typedef struct {
221 	u8 al;
222 	u8 ah;
223 	u16 ax_hi;
224 	u8 bl;
225 	u8 bh;
226 	u16 bx_hi;
227 	u8 cl;
228 	u8 ch;
229 	u16 cx_hi;
230 	u8 dl;
231 	u8 dh;
232 	u16 dx_hi;
233 } RMBYTEREGS;
234 #endif
235 
236 /****************************************************************************
237 REMARKS:
238 Structure describing all the x86 CPU registers
239 
240 HEADER:
241 pmapi.h
242 
243 MEMBERS:
244 e   - Member to access registers as 32-bit values
245 x   - Member to access registers as 16-bit values
246 h   - Member to access registers as 8-bit values
247 ****************************************************************************/
248 typedef union {
249 	RMDWORDREGS e;
250 	RMWORDREGS x;
251 	RMBYTEREGS h;
252 } RMREGS;
253 
254 /****************************************************************************
255 REMARKS:
256 Structure describing all the x86 segment registers
257 
258 HEADER:
259 pmapi.h
260 
261 MEMBERS:
262 es  - ES segment register
263 cs  - CS segment register
264 ss  - SS segment register
265 ds  - DS segment register
266 fs  - FS segment register
267 gs  - GS segment register
268 ****************************************************************************/
269 typedef struct {
270 	u16 es;
271 	u16 cs;
272 	u16 ss;
273 	u16 ds;
274 	u16 fs;
275 	u16 gs;
276 } RMSREGS;
277 
278 #endif				/* __KERNEL__ */
279 
280 #ifndef __KERNEL__
281 
282 /****************************************************************************
283 REMARKS:
284 Structure defining all the BIOS Emulator API functions as exported from
285 the Binary Portable DLL.
286 {secret}
287 ****************************************************************************/
288 typedef struct {
289 	ulong dwSize;
290 	 ibool(PMAPIP BE_init) (u32 debugFlags, int memSize, BE_VGAInfo * info);
291 	void (PMAPIP BE_setVGA) (BE_VGAInfo * info);
292 	void (PMAPIP BE_getVGA) (BE_VGAInfo * info);
293 	void *(PMAPIP BE_mapRealPointer) (uint r_seg, uint r_off);
294 	void *(PMAPIP BE_getVESABuf) (uint * len, uint * rseg, uint * roff);
295 	void (PMAPIP BE_callRealMode) (uint seg, uint off, RMREGS * regs,
296 				       RMSREGS * sregs);
297 	int (PMAPIP BE_int86) (int intno, RMREGS * in, RMREGS * out);
298 	int (PMAPIP BE_int86x) (int intno, RMREGS * in, RMREGS * out,
299 				RMSREGS * sregs);
300 	void *reserved1;
301 	void (PMAPIP BE_exit) (void);
302 } BE_exports;
303 
304 /****************************************************************************
305 REMARKS:
306 Function pointer type for the Binary Portable DLL initialisation entry point.
307 {secret}
308 ****************************************************************************/
309 typedef BE_exports *(PMAPIP BE_initLibrary_t) (PM_imports * PMImp);
310 #endif
311 
312 #pragma pack()
313 
314 /*---------------------------- Global variables ---------------------------*/
315 
316 #ifdef  __cplusplus
317 extern "C" {			/* Use "C" linkage when in C++ mode */
318 #endif
319 
320 /* {secret} Global BIOS emulator system environment */
321 	extern BE_sysEnv _BE_env;
322 
323 /*-------------------------- Function Prototypes --------------------------*/
324 
325 /* BIOS emulator library entry points */
326 	int X86API BE_init(u32 debugFlags, int memSize, BE_VGAInfo * info,
327 			   int shared);
328 	void X86API BE_setVGA(BE_VGAInfo * info);
329 	void X86API BE_getVGA(BE_VGAInfo * info);
330 	void X86API BE_setDebugFlags(u32 debugFlags);
331 	void *X86API BE_mapRealPointer(uint r_seg, uint r_off);
332 	void *X86API BE_getVESABuf(uint * len, uint * rseg, uint * roff);
333 	void X86API BE_callRealMode(uint seg, uint off, RMREGS * regs,
334 				    RMSREGS * sregs);
335 	int X86API BE_int86(int intno, RMREGS * in, RMREGS * out);
336 	int X86API BE_int86x(int intno, RMREGS * in, RMREGS * out,
337 			     RMSREGS * sregs);
338 	void X86API BE_exit(void);
339 
340 #ifdef  __cplusplus
341 }				/* End of "C" linkage for C++       */
342 #endif
343 #endif				/* __BIOSEMU_H */
344