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