x86emu.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /****************************************************************************
  2. *
  3. * Realmode X86 Emulator Library
  4. *
  5. * Copyright (C) 1996-1999 SciTech Software, Inc.
  6. * Copyright (C) David Mosberger-Tang
  7. * Copyright (C) 1999 Egbert Eich
  8. *
  9. * ========================================================================
  10. *
  11. * Permission to use, copy, modify, distribute, and sell this software and
  12. * its documentation for any purpose is hereby granted without fee,
  13. * provided that the above copyright notice appear in all copies and that
  14. * both that copyright notice and this permission notice appear in
  15. * supporting documentation, and that the name of the authors not be used
  16. * in advertising or publicity pertaining to distribution of the software
  17. * without specific, written prior permission. The authors makes no
  18. * representations about the suitability of this software for any purpose.
  19. * It is provided "as is" without express or implied warranty.
  20. *
  21. * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  22. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  23. * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  24. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  25. * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  26. * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  27. * PERFORMANCE OF THIS SOFTWARE.
  28. *
  29. * ========================================================================
  30. *
  31. * Language: ANSI C
  32. * Environment: Any
  33. * Developer: Kendall Bennett
  34. *
  35. * Description: Header file for public specific functions.
  36. * Any application linking against us should only
  37. * include this header
  38. *
  39. ****************************************************************************/
  40. #ifndef __X86EMU_X86EMU_H
  41. #define __X86EMU_X86EMU_H
  42. #include <asm/types.h>
  43. #include <common.h>
  44. #include <pci.h>
  45. #include <asm/io.h>
  46. #define X86API
  47. #define X86APIP *
  48. typedef u16 X86EMU_pioAddr;
  49. #include "x86emu/regs.h"
  50. /*---------------------- Macros and type definitions ----------------------*/
  51. #if defined(CONFIG_ARM)
  52. #define GAS_LINE_COMMENT "@"
  53. #elif defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_X86)
  54. #define GAS_LINE_COMMENT "#"
  55. #elif defined (CONFIG_SH)
  56. #define GAS_LINE_COMMENT "!"
  57. #endif
  58. #define GOT2_TYPE ".got2,\"aw\"\t"GAS_LINE_COMMENT
  59. #pragma pack(1)
  60. /****************************************************************************
  61. REMARKS:
  62. Data structure containing ponters to programmed I/O functions used by the
  63. emulator. This is used so that the user program can hook all programmed
  64. I/O for the emulator to handled as necessary by the user program. By
  65. default the emulator contains simple functions that do not do access the
  66. hardware in any way. To allow the emualtor access the hardware, you will
  67. need to override the programmed I/O functions using the X86EMU_setupPioFuncs
  68. function.
  69. HEADER:
  70. x86emu.h
  71. MEMBERS:
  72. inb - Function to read a byte from an I/O port
  73. inw - Function to read a word from an I/O port
  74. inl - Function to read a dword from an I/O port
  75. outb - Function to write a byte to an I/O port
  76. outw - Function to write a word to an I/O port
  77. outl - Function to write a dword to an I/O port
  78. ****************************************************************************/
  79. typedef struct {
  80. u8(X86APIP inb) (X86EMU_pioAddr addr);
  81. u16(X86APIP inw) (X86EMU_pioAddr addr);
  82. u32(X86APIP inl) (X86EMU_pioAddr addr);
  83. void (X86APIP outb) (X86EMU_pioAddr addr, u8 val);
  84. void (X86APIP outw) (X86EMU_pioAddr addr, u16 val);
  85. void (X86APIP outl) (X86EMU_pioAddr addr, u32 val);
  86. } X86EMU_pioFuncs;
  87. /****************************************************************************
  88. REMARKS:
  89. Data structure containing ponters to memory access functions used by the
  90. emulator. This is used so that the user program can hook all memory
  91. access functions as necessary for the emulator. By default the emulator
  92. contains simple functions that only access the internal memory of the
  93. emulator. If you need specialised functions to handle access to different
  94. types of memory (ie: hardware framebuffer accesses and BIOS memory access
  95. etc), you will need to override this using the X86EMU_setupMemFuncs
  96. function.
  97. HEADER:
  98. x86emu.h
  99. MEMBERS:
  100. rdb - Function to read a byte from an address
  101. rdw - Function to read a word from an address
  102. rdl - Function to read a dword from an address
  103. wrb - Function to write a byte to an address
  104. wrw - Function to write a word to an address
  105. wrl - Function to write a dword to an address
  106. ****************************************************************************/
  107. typedef struct {
  108. u8(X86APIP rdb) (u32 addr);
  109. u16(X86APIP rdw) (u32 addr);
  110. u32(X86APIP rdl) (u32 addr);
  111. void (X86APIP wrb) (u32 addr, u8 val);
  112. void (X86APIP wrw) (u32 addr, u16 val);
  113. void (X86APIP wrl) (u32 addr, u32 val);
  114. } X86EMU_memFuncs;
  115. /****************************************************************************
  116. Here are the default memory read and write
  117. function in case they are needed as fallbacks.
  118. ***************************************************************************/
  119. extern u8 X86API rdb(u32 addr);
  120. extern u16 X86API rdw(u32 addr);
  121. extern u32 X86API rdl(u32 addr);
  122. extern void X86API wrb(u32 addr, u8 val);
  123. extern void X86API wrw(u32 addr, u16 val);
  124. extern void X86API wrl(u32 addr, u32 val);
  125. #pragma pack()
  126. /*--------------------- type definitions -----------------------------------*/
  127. typedef void (X86APIP X86EMU_intrFuncs) (int num);
  128. extern X86EMU_intrFuncs _X86EMU_intrTab[256];
  129. /*-------------------------- Function Prototypes --------------------------*/
  130. #ifdef __cplusplus
  131. extern "C" { /* Use "C" linkage when in C++ mode */
  132. #endif
  133. void X86EMU_setupMemFuncs(X86EMU_memFuncs * funcs);
  134. void X86EMU_setupPioFuncs(X86EMU_pioFuncs * funcs);
  135. void X86EMU_setupIntrFuncs(X86EMU_intrFuncs funcs[]);
  136. void X86EMU_setupIntrFunc(int intnum, X86EMU_intrFuncs func);
  137. void X86EMU_prepareForInt(int num);
  138. /* decode.c */
  139. void X86EMU_exec(void);
  140. void X86EMU_halt_sys(void);
  141. #ifdef CONFIG_X86EMU_DEBUG
  142. #define HALT_SYS() \
  143. printf("halt_sys: file %s, line %d\n", __FILE__, __LINE__), \
  144. X86EMU_halt_sys()
  145. #else
  146. #define HALT_SYS() X86EMU_halt_sys()
  147. #endif
  148. /* Debug options */
  149. #define DEBUG_DECODE_F 0x0001 /* print decoded instruction */
  150. #define DEBUG_TRACE_F 0x0002 /* dump regs before/after execution */
  151. #define DEBUG_STEP_F 0x0004
  152. #define DEBUG_DISASSEMBLE_F 0x0008
  153. #define DEBUG_BREAK_F 0x0010
  154. #define DEBUG_SVC_F 0x0020
  155. #define DEBUG_SAVE_CS_IP 0x0040
  156. #define DEBUG_FS_F 0x0080
  157. #define DEBUG_PROC_F 0x0100
  158. #define DEBUG_SYSINT_F 0x0200 /* bios system interrupts. */
  159. #define DEBUG_TRACECALL_F 0x0400
  160. #define DEBUG_INSTRUMENT_F 0x0800
  161. #define DEBUG_MEM_TRACE_F 0x1000
  162. #define DEBUG_IO_TRACE_F 0x2000
  163. #define DEBUG_TRACECALL_REGS_F 0x4000
  164. #define DEBUG_DECODE_NOPRINT_F 0x8000
  165. #define DEBUG_EXIT 0x10000
  166. #define DEBUG_SYS_F (DEBUG_SVC_F|DEBUG_FS_F|DEBUG_PROC_F)
  167. void X86EMU_trace_regs(void);
  168. void X86EMU_trace_xregs(void);
  169. void X86EMU_dump_memory(u16 seg, u16 off, u32 amt);
  170. int X86EMU_trace_on(void);
  171. int X86EMU_trace_off(void);
  172. #ifdef __cplusplus
  173. } /* End of "C" linkage for C++ */
  174. #endif
  175. #endif /* __X86EMU_X86EMU_H */