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