xref: /OK3568_Linux_fs/u-boot/drivers/bios_emulator/include/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 #include <asm/types.h>
45*4882a593Smuzhiyun #include <common.h>
46*4882a593Smuzhiyun #include <pci.h>
47*4882a593Smuzhiyun #include <asm/io.h>
48*4882a593Smuzhiyun #define X86API
49*4882a593Smuzhiyun #define X86APIP *
50*4882a593Smuzhiyun typedef u16 X86EMU_pioAddr;
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun #include "x86emu/regs.h"
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /*---------------------- Macros and type definitions ----------------------*/
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun #if defined(CONFIG_ARM)
57*4882a593Smuzhiyun #define GAS_LINE_COMMENT	"@"
58*4882a593Smuzhiyun #elif defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_X86)
59*4882a593Smuzhiyun #define GAS_LINE_COMMENT	"#"
60*4882a593Smuzhiyun #elif defined (CONFIG_SH)
61*4882a593Smuzhiyun #define GAS_LINE_COMMENT	"!"
62*4882a593Smuzhiyun #endif
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun #define GOT2_TYPE	".got2,\"aw\"\t"GAS_LINE_COMMENT
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun #pragma pack(1)
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun /****************************************************************************
69*4882a593Smuzhiyun REMARKS:
70*4882a593Smuzhiyun Data structure containing ponters to programmed I/O functions used by the
71*4882a593Smuzhiyun emulator. This is used so that the user program can hook all programmed
72*4882a593Smuzhiyun I/O for the emulator to handled as necessary by the user program. By
73*4882a593Smuzhiyun default the emulator contains simple functions that do not do access the
74*4882a593Smuzhiyun hardware in any way. To allow the emualtor access the hardware, you will
75*4882a593Smuzhiyun need to override the programmed I/O functions using the X86EMU_setupPioFuncs
76*4882a593Smuzhiyun function.
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun HEADER:
79*4882a593Smuzhiyun x86emu.h
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun MEMBERS:
82*4882a593Smuzhiyun inb     - Function to read a byte from an I/O port
83*4882a593Smuzhiyun inw     - Function to read a word from an I/O port
84*4882a593Smuzhiyun inl     - Function to read a dword from an I/O port
85*4882a593Smuzhiyun outb    - Function to write a byte to an I/O port
86*4882a593Smuzhiyun outw    - Function to write a word to an I/O port
87*4882a593Smuzhiyun outl    - Function to write a dword to an I/O port
88*4882a593Smuzhiyun ****************************************************************************/
89*4882a593Smuzhiyun typedef struct {
90*4882a593Smuzhiyun 	u8(X86APIP inb) (X86EMU_pioAddr addr);
91*4882a593Smuzhiyun 	u16(X86APIP inw) (X86EMU_pioAddr addr);
92*4882a593Smuzhiyun 	u32(X86APIP inl) (X86EMU_pioAddr addr);
93*4882a593Smuzhiyun 	void (X86APIP outb) (X86EMU_pioAddr addr, u8 val);
94*4882a593Smuzhiyun 	void (X86APIP outw) (X86EMU_pioAddr addr, u16 val);
95*4882a593Smuzhiyun 	void (X86APIP outl) (X86EMU_pioAddr addr, u32 val);
96*4882a593Smuzhiyun } X86EMU_pioFuncs;
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun /****************************************************************************
99*4882a593Smuzhiyun REMARKS:
100*4882a593Smuzhiyun Data structure containing ponters to memory access functions used by the
101*4882a593Smuzhiyun emulator. This is used so that the user program can hook all memory
102*4882a593Smuzhiyun access functions as necessary for the emulator. By default the emulator
103*4882a593Smuzhiyun contains simple functions that only access the internal memory of the
104*4882a593Smuzhiyun emulator. If you need specialised functions to handle access to different
105*4882a593Smuzhiyun types of memory (ie: hardware framebuffer accesses and BIOS memory access
106*4882a593Smuzhiyun etc), you will need to override this using the X86EMU_setupMemFuncs
107*4882a593Smuzhiyun function.
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun HEADER:
110*4882a593Smuzhiyun x86emu.h
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun MEMBERS:
113*4882a593Smuzhiyun rdb     - Function to read a byte from an address
114*4882a593Smuzhiyun rdw     - Function to read a word from an address
115*4882a593Smuzhiyun rdl     - Function to read a dword from an address
116*4882a593Smuzhiyun wrb     - Function to write a byte to an address
117*4882a593Smuzhiyun wrw     - Function to write a word to an address
118*4882a593Smuzhiyun wrl     - Function to write a dword to an address
119*4882a593Smuzhiyun ****************************************************************************/
120*4882a593Smuzhiyun typedef struct {
121*4882a593Smuzhiyun 	u8(X86APIP rdb) (u32 addr);
122*4882a593Smuzhiyun 	u16(X86APIP rdw) (u32 addr);
123*4882a593Smuzhiyun 	u32(X86APIP rdl) (u32 addr);
124*4882a593Smuzhiyun 	void (X86APIP wrb) (u32 addr, u8 val);
125*4882a593Smuzhiyun 	void (X86APIP wrw) (u32 addr, u16 val);
126*4882a593Smuzhiyun 	void (X86APIP wrl) (u32 addr, u32 val);
127*4882a593Smuzhiyun } X86EMU_memFuncs;
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun /****************************************************************************
130*4882a593Smuzhiyun   Here are the default memory read and write
131*4882a593Smuzhiyun   function in case they are needed as fallbacks.
132*4882a593Smuzhiyun ***************************************************************************/
133*4882a593Smuzhiyun extern u8 X86API rdb(u32 addr);
134*4882a593Smuzhiyun extern u16 X86API rdw(u32 addr);
135*4882a593Smuzhiyun extern u32 X86API rdl(u32 addr);
136*4882a593Smuzhiyun extern void X86API wrb(u32 addr, u8 val);
137*4882a593Smuzhiyun extern void X86API wrw(u32 addr, u16 val);
138*4882a593Smuzhiyun extern void X86API wrl(u32 addr, u32 val);
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun #pragma pack()
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun /*--------------------- type definitions -----------------------------------*/
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun typedef void (X86APIP X86EMU_intrFuncs) (int num);
145*4882a593Smuzhiyun extern X86EMU_intrFuncs _X86EMU_intrTab[256];
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun /*-------------------------- Function Prototypes --------------------------*/
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun #ifdef  __cplusplus
150*4882a593Smuzhiyun extern "C" {			/* Use "C" linkage when in C++ mode */
151*4882a593Smuzhiyun #endif
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun 	void X86EMU_setupMemFuncs(X86EMU_memFuncs * funcs);
154*4882a593Smuzhiyun 	void X86EMU_setupPioFuncs(X86EMU_pioFuncs * funcs);
155*4882a593Smuzhiyun 	void X86EMU_setupIntrFuncs(X86EMU_intrFuncs funcs[]);
156*4882a593Smuzhiyun 	void X86EMU_setupIntrFunc(int intnum, X86EMU_intrFuncs func);
157*4882a593Smuzhiyun 	void X86EMU_prepareForInt(int num);
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun /* decode.c */
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun 	void X86EMU_exec(void);
162*4882a593Smuzhiyun 	void X86EMU_halt_sys(void);
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun #ifdef CONFIG_X86EMU_DEBUG
165*4882a593Smuzhiyun #define HALT_SYS()  \
166*4882a593Smuzhiyun     printf("halt_sys: file %s, line %d\n", __FILE__, __LINE__), \
167*4882a593Smuzhiyun     X86EMU_halt_sys()
168*4882a593Smuzhiyun #else
169*4882a593Smuzhiyun #define HALT_SYS()  X86EMU_halt_sys()
170*4882a593Smuzhiyun #endif
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun /* Debug options */
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun #define DEBUG_DECODE_F          0x0001	/* print decoded instruction  */
175*4882a593Smuzhiyun #define DEBUG_TRACE_F           0x0002	/* dump regs before/after execution */
176*4882a593Smuzhiyun #define DEBUG_STEP_F            0x0004
177*4882a593Smuzhiyun #define DEBUG_DISASSEMBLE_F     0x0008
178*4882a593Smuzhiyun #define DEBUG_BREAK_F           0x0010
179*4882a593Smuzhiyun #define DEBUG_SVC_F             0x0020
180*4882a593Smuzhiyun #define DEBUG_SAVE_CS_IP        0x0040
181*4882a593Smuzhiyun #define DEBUG_FS_F              0x0080
182*4882a593Smuzhiyun #define DEBUG_PROC_F            0x0100
183*4882a593Smuzhiyun #define DEBUG_SYSINT_F          0x0200	/* bios system interrupts. */
184*4882a593Smuzhiyun #define DEBUG_TRACECALL_F       0x0400
185*4882a593Smuzhiyun #define DEBUG_INSTRUMENT_F      0x0800
186*4882a593Smuzhiyun #define DEBUG_MEM_TRACE_F       0x1000
187*4882a593Smuzhiyun #define DEBUG_IO_TRACE_F        0x2000
188*4882a593Smuzhiyun #define DEBUG_TRACECALL_REGS_F  0x4000
189*4882a593Smuzhiyun #define DEBUG_DECODE_NOPRINT_F  0x8000
190*4882a593Smuzhiyun #define DEBUG_EXIT              0x10000
191*4882a593Smuzhiyun #define DEBUG_SYS_F             (DEBUG_SVC_F|DEBUG_FS_F|DEBUG_PROC_F)
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun 	void X86EMU_trace_regs(void);
194*4882a593Smuzhiyun 	void X86EMU_trace_xregs(void);
195*4882a593Smuzhiyun 	void X86EMU_dump_memory(u16 seg, u16 off, u32 amt);
196*4882a593Smuzhiyun 	int X86EMU_trace_on(void);
197*4882a593Smuzhiyun 	int X86EMU_trace_off(void);
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun #ifdef  __cplusplus
200*4882a593Smuzhiyun }				/* End of "C" linkage for C++       */
201*4882a593Smuzhiyun #endif
202*4882a593Smuzhiyun #endif				/* __X86EMU_X86EMU_H */
203