coreboot was still using an old set (obsolete since yabel) of x86emu includes
[coreboot.git] / util / x86emu / include / x86emu / x86emu.h
1 /****************************************************************************
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 /* $XFree86: xc/extras/x86emu/include/x86emu.h,v 1.2 2000/11/21 23:10:25 tsi Exp $ */
41
42 #ifndef __X86EMU_X86EMU_H
43 #define __X86EMU_X86EMU_H
44
45 /* FIXME: redefine printk for the moment */
46 #ifdef COREBOOT_V2
47 #include <console/console.h>
48 #undef printk
49 #define printk(x...) do_printk(BIOS_DEBUG, x)
50 #else
51 #define printk printf
52 #endif 
53
54 #ifdef SCITECH
55 #include "scitech.h"
56 #define X86API  _ASMAPI
57 #define X86APIP _ASMAPIP
58 typedef int X86EMU_pioAddr;
59 #else
60 #include "types.h"
61 #define X86API
62 #define X86APIP *
63 #endif
64 #include "regs.h"
65
66 /*---------------------- Macros and type definitions ----------------------*/
67
68 #pragma pack(1)
69
70 /****************************************************************************
71 REMARKS:
72 Data structure containing ponters to programmed I/O functions used by the
73 emulator. This is used so that the user program can hook all programmed
74 I/O for the emulator to handled as necessary by the user program. By
75 default the emulator contains simple functions that do not do access the
76 hardware in any way. To allow the emualtor access the hardware, you will
77 need to override the programmed I/O functions using the X86EMU_setupPioFuncs
78 function.
79
80 HEADER:
81 x86emu.h
82
83 MEMBERS:
84 inb             - Function to read a byte from an I/O port
85 inw             - Function to read a word from an I/O port
86 inl     - Function to read a dword from an I/O port
87 outb    - Function to write a byte to an I/O port
88 outw    - Function to write a word to an I/O port
89 outl    - Function to write a dword to an I/O port
90 ****************************************************************************/
91 typedef struct {
92         u8      (X86APIP inb)(X86EMU_pioAddr addr);
93         u16     (X86APIP inw)(X86EMU_pioAddr addr);
94         u32     (X86APIP inl)(X86EMU_pioAddr addr);
95         void    (X86APIP outb)(X86EMU_pioAddr addr, u8 val);
96         void    (X86APIP outw)(X86EMU_pioAddr addr, u16 val);
97         void    (X86APIP outl)(X86EMU_pioAddr addr, u32 val);
98         } X86EMU_pioFuncs;
99
100 /****************************************************************************
101 REMARKS:
102 Data structure containing ponters to memory access functions used by the
103 emulator. This is used so that the user program can hook all memory
104 access functions as necessary for the emulator. By default the emulator
105 contains simple functions that only access the internal memory of the
106 emulator. If you need specialised functions to handle access to different
107 types of memory (ie: hardware framebuffer accesses and BIOS memory access
108 etc), you will need to override this using the X86EMU_setupMemFuncs
109 function.
110
111 HEADER:
112 x86emu.h
113
114 MEMBERS:
115 rdb             - Function to read a byte from an address
116 rdw             - Function to read a word from an address
117 rdl     - Function to read a dword from an address
118 wrb             - Function to write a byte to an address
119 wrw     - Function to write a word to an address
120 wrl     - Function to write a dword to an address
121 ****************************************************************************/
122 typedef struct {
123         u8      (X86APIP rdb)(u32 addr);
124         u16     (X86APIP rdw)(u32 addr);
125         u32     (X86APIP rdl)(u32 addr);
126         void    (X86APIP wrb)(u32 addr, u8 val);
127         void    (X86APIP wrw)(u32 addr, u16 val);
128         void    (X86APIP wrl)(u32 addr, u32 val);
129         } X86EMU_memFuncs;
130
131 /****************************************************************************
132   Here are the default memory read and write
133   function in case they are needed as fallbacks.
134 ***************************************************************************/
135 extern u8 X86API rdb(u32 addr);
136 extern u16 X86API rdw(u32 addr);
137 extern u32 X86API rdl(u32 addr);
138 extern void X86API wrb(u32 addr, u8 val);
139 extern void X86API wrw(u32 addr, u16 val);
140 extern void X86API wrl(u32 addr, u32 val);
141  
142 #pragma pack()
143
144 /*--------------------- type definitions -----------------------------------*/
145
146 typedef void (X86APIP X86EMU_intrFuncs)(int num);
147 extern X86EMU_intrFuncs _X86EMU_intrTab[256];
148
149 /*-------------------------- Function Prototypes --------------------------*/
150
151 #ifdef  __cplusplus
152 extern "C" {                                    /* Use "C" linkage when in C++ mode */
153 #endif
154
155 void    X86EMU_setupMemFuncs(X86EMU_memFuncs *funcs);
156 void    X86EMU_setupPioFuncs(X86EMU_pioFuncs *funcs);
157 void    X86EMU_setupIntrFuncs(X86EMU_intrFuncs funcs[]);
158 void    X86EMU_prepareForInt(int num);
159
160 //void X86EMU_setMemBase(void *base, size_t size);
161
162 /* decode.c */
163
164 void    X86EMU_exec(void);
165 void    X86EMU_halt_sys(void);
166
167 #ifdef  CONFIG_DEBUG
168 #define HALT_SYS()      \
169         printk("halt_sys: in %s\n", __func__);  \
170         X86EMU_halt_sys();
171 #else
172 #define HALT_SYS()      X86EMU_halt_sys()
173 #endif
174
175 /* Debug options */
176
177 #define DEBUG_DECODE_F          0x000001 /* print decoded instruction  */
178 #define DEBUG_TRACE_F           0x000002 /* dump regs before/after execution */
179 #define DEBUG_STEP_F            0x000004
180 #define DEBUG_DISASSEMBLE_F     0x000008
181 #define DEBUG_BREAK_F           0x000010
182 #define DEBUG_SVC_F             0x000020
183 #define DEBUG_FS_F              0x000080
184 #define DEBUG_PROC_F            0x000100
185 #define DEBUG_SYSINT_F          0x000200 /* bios system interrupts. */
186 #define DEBUG_TRACECALL_F       0x000400
187 #define DEBUG_INSTRUMENT_F      0x000800
188 #define DEBUG_MEM_TRACE_F       0x001000 
189 #define DEBUG_IO_TRACE_F        0x002000 
190 #define DEBUG_TRACECALL_REGS_F  0x004000
191 #define DEBUG_DECODE_NOPRINT_F  0x008000 
192 #define DEBUG_SAVE_IP_CS_F      0x010000
193 #define DEBUG_TRACEJMP_F        0x020000
194 #define DEBUG_TRACEJMP_REGS_F   0x040000
195 #define DEBUG_SYS_F             (DEBUG_SVC_F|DEBUG_FS_F|DEBUG_PROC_F)
196
197 void    X86EMU_trace_regs(void);
198 void    X86EMU_trace_xregs(void);
199 void    X86EMU_dump_memory(u16 seg, u16 off, u32 amt);
200 int     X86EMU_trace_on(void);
201 int     X86EMU_trace_off(void);
202
203 #ifdef  __cplusplus
204 }                                               /* End of "C" linkage for C++           */
205 #endif
206
207 #endif /* __X86EMU_X86EMU_H */