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