biosemu.h 11 KB

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