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