Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

emu_x86emu.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 *
00003 *                                               Realmode X86 Emulator Library
00004 *
00005 *               Copyright (C) 1996-1999 SciTech Software, Inc.
00006 *                                    Copyright (C) David Mosberger-Tang
00007 *                                          Copyright (C) 1999 Egbert Eich
00008 *
00009 *  ========================================================================
00010 *
00011 *  Permission to use, copy, modify, distribute, and sell this software and
00012 *  its documentation for any purpose is hereby granted without fee,
00013 *  provided that the above copyright notice appear in all copies and that
00014 *  both that copyright notice and this permission notice appear in
00015 *  supporting documentation, and that the name of the authors not be used
00016 *  in advertising or publicity pertaining to distribution of the software
00017 *  without specific, written prior permission.  The authors makes no
00018 *  representations about the suitability of this software for any purpose.
00019 *  It is provided "as is" without express or implied warranty.
00020 *
00021 *  THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00022 *  INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
00023 *  EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
00024 *  CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
00025 *  USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
00026 *  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00027 *  PERFORMANCE OF THIS SOFTWARE.
00028 *
00029 *  ========================================================================
00030 *
00031 * Language:             ANSI C
00032 * Environment:  Any
00033 * Developer:    Kendall Bennett
00034 *
00035 * Description:  Header file for public specific functions.
00036 *               Any application linking against us should only
00037 *               include this header
00038 *
00039 ****************************************************************************/
00040 /* $XFree86: xc/extras/x86emu/include/x86emu.h,v 1.2 2000/11/21 23:10:25 tsi Exp $ */
00041 
00042 #ifndef __X86EMU_X86EMU_H
00043 #define __X86EMU_X86EMU_H
00044 
00045 #include "emu_types.h"
00046 #define X86API
00047 #define X86APIP *
00048 #include "emu_regs.h"
00049 
00050 /*---------------------- Macros and type definitions ----------------------*/
00051 
00052 #pragma pack(1)
00053 
00054 /****************************************************************************
00055 REMARKS:
00056 Data structure containing ponters to programmed I/O functions used by the
00057 emulator. This is used so that the user program can hook all programmed
00058 I/O for the emulator to handled as necessary by the user program. By
00059 default the emulator contains simple functions that do not do access the
00060 hardware in any way. To allow the emualtor access the hardware, you will
00061 need to override the programmed I/O functions using the X86EMU_setupPioFuncs
00062 function.
00063 
00064 HEADER:
00065 x86emu.h
00066 
00067 MEMBERS:
00068 inb             - Function to read a byte from an I/O port
00069 inw             - Function to read a word from an I/O port
00070 inl     - Function to read a dword from an I/O port
00071 outb    - Function to write a byte to an I/O port
00072 outw    - Function to write a word to an I/O port
00073 outl    - Function to write a dword to an I/O port
00074 ****************************************************************************/
00075 typedef struct {
00076         u8      (X86APIP inb)(X86EMU_pioAddr addr);
00077         u16     (X86APIP inw)(X86EMU_pioAddr addr);
00078         u32     (X86APIP inl)(X86EMU_pioAddr addr);
00079         void    (X86APIP outb)(X86EMU_pioAddr addr, u8 val);
00080         void    (X86APIP outw)(X86EMU_pioAddr addr, u16 val);
00081         void    (X86APIP outl)(X86EMU_pioAddr addr, u32 val);
00082         } X86EMU_pioFuncs;
00083 
00084 /****************************************************************************
00085 REMARKS:
00086 Data structure containing ponters to memory access functions used by the
00087 emulator. This is used so that the user program can hook all memory
00088 access functions as necessary for the emulator. By default the emulator
00089 contains simple functions that only access the internal memory of the
00090 emulator. If you need specialised functions to handle access to different
00091 types of memory (ie: hardware framebuffer accesses and BIOS memory access
00092 etc), you will need to override this using the X86EMU_setupMemFuncs
00093 function.
00094 
00095 HEADER:
00096 x86emu.h
00097 
00098 MEMBERS:
00099 rdb             - Function to read a byte from an address
00100 rdw             - Function to read a word from an address
00101 rdl     - Function to read a dword from an address
00102 wrb             - Function to write a byte to an address
00103 wrw     - Function to write a word to an address
00104 wrl     - Function to write a dword to an address
00105 ****************************************************************************/
00106 typedef struct {
00107         u8      (X86APIP rdb)(u32 addr);
00108         u16     (X86APIP rdw)(u32 addr);
00109         u32     (X86APIP rdl)(u32 addr);
00110         void    (X86APIP wrb)(u32 addr, u8 val);
00111         void    (X86APIP wrw)(u32 addr, u16 val);
00112         void    (X86APIP wrl)(u32 addr, u32 val);
00113         } X86EMU_memFuncs;
00114 
00115 /****************************************************************************
00116   Here are the default memory read and write
00117   function in case they are needed as fallbacks.
00118 ***************************************************************************/
00119 extern u8 X86API rdb(u32 addr);
00120 extern u16 X86API rdw(u32 addr);
00121 extern u32 X86API rdl(u32 addr);
00122 extern void X86API wrb(u32 addr, u8 val);
00123 extern void X86API wrw(u32 addr, u16 val);
00124 extern void X86API wrl(u32 addr, u32 val);
00125  
00126 #pragma pack()
00127 
00128 /*--------------------- type definitions -----------------------------------*/
00129 
00130 typedef void (X86APIP X86EMU_intrFuncs)(int num);
00131 extern X86EMU_intrFuncs _X86EMU_intrTab[256];
00132 
00133 /*-------------------------- Function Prototypes --------------------------*/
00134 
00135 void    X86EMU_setupMemFuncs(X86EMU_memFuncs *funcs);
00136 void    X86EMU_setupPioFuncs(X86EMU_pioFuncs *funcs);
00137 void    X86EMU_setupIntrFuncs(X86EMU_intrFuncs funcs[]);
00138 void    X86EMU_prepareForInt(int num);
00139 
00140 /* decode.c */
00141 
00142 void    X86EMU_exec(void);
00143 void    X86EMU_halt_sys(void);
00144 
00145 #ifdef  DEBUG
00146 #define HALT_SYS()      \
00147         printk("halt_sys: file %s, line %d\n", __FILE__, __LINE__), \
00148         X86EMU_halt_sys()
00149 #else
00150 #define HALT_SYS()      X86EMU_halt_sys()
00151 #endif
00152 
00153 /* Debug options */
00154 
00155 #define DEBUG_DECODE_F          0x000001 /* print decoded instruction  */
00156 #define DEBUG_TRACE_F           0x000002 /* dump regs before/after execution */
00157 #define DEBUG_STEP_F            0x000004
00158 #define DEBUG_DISASSEMBLE_F     0x000008
00159 #define DEBUG_BREAK_F           0x000010
00160 #define DEBUG_SVC_F             0x000020
00161 #define DEBUG_FS_F              0x000080
00162 #define DEBUG_PROC_F            0x000100
00163 #define DEBUG_SYSINT_F          0x000200 /* bios system interrupts. */
00164 #define DEBUG_TRACECALL_F       0x000400
00165 #define DEBUG_INSTRUMENT_F      0x000800
00166 #define DEBUG_MEM_TRACE_F       0x001000 
00167 #define DEBUG_IO_TRACE_F        0x002000 
00168 #define DEBUG_TRACECALL_REGS_F  0x004000
00169 #define DEBUG_DECODE_NOPRINT_F  0x008000 
00170 #define DEBUG_SAVE_IP_CS_F      0x010000
00171 #define DEBUG_SYS_F             (DEBUG_SVC_F|DEBUG_FS_F|DEBUG_PROC_F)
00172 
00173 void    X86EMU_trace_regs(void);
00174 void    X86EMU_trace_xregs(void);
00175 void    X86EMU_dump_memory(u16 seg, u16 off, u32 amt);
00176 int     X86EMU_trace_on(void);
00177 int     X86EMU_trace_off(void);
00178 
00179 #endif /* __X86EMU_X86EMU_H */