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 41 #ifndef __X86EMU_X86EMU_H 42 #define __X86EMU_X86EMU_H 43 44 #include <stddef.h> 45 #if CONFIG(X86EMU_DEBUG) 46 #define DEBUG 47 #endif 48 49 #include "types.h" 50 #define X86API 51 #define X86APIP * 52 #include "regs.h" 53 54 /*---------------------- Macros and type definitions ----------------------*/ 55 56 #pragma pack(1) 57 58 /**************************************************************************** 59 REMARKS: 60 Data structure containing pointers to programmed I/O functions used by the 61 emulator. This is used so that the user program can hook all programmed 62 I/O for the emulator to handled as necessary by the user program. By 63 default the emulator contains simple functions that do not do access the 64 hardware in any way. To allow the emulator access the hardware, you will 65 need to override the programmed I/O functions using the X86EMU_setupPioFuncs 66 function. 67 68 HEADER: 69 x86emu.h 70 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 /**************************************************************************** 89 REMARKS: 90 Data structure containing pointers to memory access functions used by the 91 emulator. This is used so that the user program can hook all memory 92 access functions as necessary for the emulator. By default the emulator 93 contains simple functions that only access the internal memory of the 94 emulator. If you need specialized functions to handle access to different 95 types of memory (ie: hardware framebuffer accesses and BIOS memory access 96 etc), you will need to override this using the X86EMU_setupMemFuncs 97 function. 98 99 HEADER: 100 x86emu.h 101 102 MEMBERS: 103 rdb - Function to read a byte from an address 104 rdw - Function to read a word from an address 105 rdl - Function to read a dword from an address 106 wrb - Function to write a byte to an address 107 wrw - Function to write a word to an address 108 wrl - Function to write a dword to an address 109 ****************************************************************************/ 110 typedef struct { 111 u8 (X86APIP rdb)(u32 addr); 112 u16 (X86APIP rdw)(u32 addr); 113 u32 (X86APIP rdl)(u32 addr); 114 void (X86APIP wrb)(u32 addr, u8 val); 115 void (X86APIP wrw)(u32 addr, u16 val); 116 void (X86APIP wrl)(u32 addr, u32 val); 117 } X86EMU_memFuncs; 118 119 /**************************************************************************** 120 Here are the default memory read and write 121 function in case they are needed as fallbacks. 122 ***************************************************************************/ 123 extern u8 X86API rdb(u32 addr); 124 extern u16 X86API rdw(u32 addr); 125 extern u32 X86API rdl(u32 addr); 126 extern void X86API wrb(u32 addr, u8 val); 127 extern void X86API wrw(u32 addr, u16 val); 128 extern void X86API wrl(u32 addr, u32 val); 129 130 #pragma pack() 131 132 /*--------------------- type definitions -----------------------------------*/ 133 134 typedef void (X86APIP X86EMU_intrFuncs)(int num); 135 extern X86EMU_intrFuncs _X86EMU_intrTab[256]; 136 137 /*-------------------------- Function Prototypes --------------------------*/ 138 139 #ifdef __cplusplus 140 extern "C" { /* Use "C" linkage when in C++ mode */ 141 #endif 142 143 void X86EMU_setupMemFuncs(X86EMU_memFuncs *funcs); 144 void X86EMU_setupPioFuncs(X86EMU_pioFuncs *funcs); 145 void X86EMU_setupIntrFuncs(X86EMU_intrFuncs funcs[]); 146 void X86EMU_prepareForInt(int num); 147 148 void X86EMU_setMemBase(void *base, size_t size); 149 150 /* decode.c */ 151 152 void X86EMU_exec(void); 153 void X86EMU_halt_sys(void); 154 155 #if CONFIG(X86EMU_DEBUG) 156 #define HALT_SYS() \ 157 printf("halt_sys: in %s\n", __func__); \ 158 X86EMU_halt_sys(); 159 #else 160 #define HALT_SYS() X86EMU_halt_sys() 161 #endif 162 163 /* Debug options */ 164 165 #define DEBUG_DECODE_F 0x000001 /* print decoded instruction */ 166 #define DEBUG_TRACE_F 0x000002 /* dump regs before/after execution */ 167 #define DEBUG_STEP_F 0x000004 168 #define DEBUG_DISASSEMBLE_F 0x000008 169 #define DEBUG_BREAK_F 0x000010 170 #define DEBUG_SVC_F 0x000020 171 #define DEBUG_FS_F 0x000080 172 #define DEBUG_PROC_F 0x000100 173 #define DEBUG_SYSINT_F 0x000200 /* BIOS system interrupts. */ 174 #define DEBUG_TRACECALL_F 0x000400 175 #define DEBUG_INSTRUMENT_F 0x000800 176 #define DEBUG_MEM_TRACE_F 0x001000 177 #define DEBUG_IO_TRACE_F 0x002000 178 #define DEBUG_TRACECALL_REGS_F 0x004000 179 #define DEBUG_DECODE_NOPRINT_F 0x008000 180 #define DEBUG_SAVE_IP_CS_F 0x010000 181 #define DEBUG_TRACEJMP_F 0x020000 182 #define DEBUG_TRACEJMP_REGS_F 0x040000 183 #define DEBUG_SYS_F (DEBUG_SVC_F|DEBUG_FS_F|DEBUG_PROC_F) 184 185 void X86EMU_trace_regs(void); 186 void X86EMU_trace_xregs(void); 187 void X86EMU_dump_memory(u16 seg, u16 off, u32 amt); 188 int X86EMU_trace_on(void); 189 int X86EMU_trace_off(void); 190 191 #ifdef __cplusplus 192 } /* End of "C" linkage for C++ */ 193 #endif 194 195 #endif /* __X86EMU_X86EMU_H */ 196