]>
Commit | Line | Data |
---|---|---|
ece92f85 JJ |
1 | /**************************************************************************** |
2 | * | |
3 | * Realmode X86 Emulator Library | |
4 | * | |
5 | * Copyright (C) 1991-2004 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: This file includes subroutines which are related to | |
36 | * programmed I/O and memory access. Included in this module | |
37 | * are default functions that do nothing. For real uses these | |
62a3b7dd | 38 | * functions will have to be overridden by the user library. |
ece92f85 JJ |
39 | * |
40 | ****************************************************************************/ | |
41 | ||
d678a59d | 42 | #include <common.h> |
1e94b46f | 43 | #include <linux/printk.h> |
5b4de930 MS |
44 | #include "x86emu/x86emui.h" |
45 | ||
ece92f85 JJ |
46 | /*------------------------- Global Variables ------------------------------*/ |
47 | ||
70f2030f | 48 | /* Note: bios.c defines this if the emulator is not enabled */ |
ece92f85 JJ |
49 | X86EMU_sysEnv _X86EMU_env; /* Global emulator machine state */ |
50 | X86EMU_intrFuncs _X86EMU_intrTab[256]; | |
51 | ||
52 | int debug_intr; | |
53 | ||
54 | /*----------------------------- Implementation ----------------------------*/ | |
55 | ||
56 | /**************************************************************************** | |
57 | PARAMETERS: | |
58 | addr - Emulator memory address to read | |
59 | ||
60 | RETURNS: | |
61 | Byte value read from emulator memory. | |
62 | ||
63 | REMARKS: | |
64 | Reads a byte value from the emulator memory. | |
65 | ****************************************************************************/ | |
66 | u8 X86API rdb(u32 addr) | |
67 | { | |
68 | return 0; | |
69 | } | |
70 | ||
71 | /**************************************************************************** | |
72 | PARAMETERS: | |
73 | addr - Emulator memory address to read | |
74 | ||
75 | RETURNS: | |
76 | Word value read from emulator memory. | |
77 | ||
78 | REMARKS: | |
79 | Reads a word value from the emulator memory. | |
80 | ****************************************************************************/ | |
81 | u16 X86API rdw(u32 addr) | |
82 | { | |
83 | return 0; | |
84 | } | |
85 | ||
86 | /**************************************************************************** | |
87 | PARAMETERS: | |
88 | addr - Emulator memory address to read | |
89 | ||
90 | RETURNS: | |
91 | Long value read from emulator memory. | |
92 | REMARKS: | |
93 | Reads a long value from the emulator memory. | |
94 | ****************************************************************************/ | |
95 | u32 X86API rdl(u32 addr) | |
96 | { | |
97 | return 0; | |
98 | } | |
99 | ||
100 | /**************************************************************************** | |
101 | PARAMETERS: | |
102 | addr - Emulator memory address to read | |
103 | val - Value to store | |
104 | ||
105 | REMARKS: | |
106 | Writes a byte value to emulator memory. | |
107 | ****************************************************************************/ | |
108 | void X86API wrb(u32 addr, u8 val) | |
109 | { | |
110 | } | |
111 | ||
112 | /**************************************************************************** | |
113 | PARAMETERS: | |
114 | addr - Emulator memory address to read | |
115 | val - Value to store | |
116 | ||
117 | REMARKS: | |
118 | Writes a word value to emulator memory. | |
119 | ****************************************************************************/ | |
120 | void X86API wrw(u32 addr, u16 val) | |
121 | { | |
122 | } | |
123 | ||
124 | /**************************************************************************** | |
125 | PARAMETERS: | |
126 | addr - Emulator memory address to read | |
127 | val - Value to store | |
128 | ||
129 | REMARKS: | |
130 | Writes a long value to emulator memory. | |
131 | ****************************************************************************/ | |
132 | void X86API wrl(u32 addr, u32 val) | |
133 | { | |
134 | } | |
135 | ||
136 | /**************************************************************************** | |
137 | PARAMETERS: | |
138 | addr - PIO address to read | |
139 | RETURN: | |
140 | 0 | |
141 | REMARKS: | |
142 | Default PIO byte read function. Doesn't perform real inb. | |
143 | ****************************************************************************/ | |
144 | static u8 X86API p_inb(X86EMU_pioAddr addr) | |
145 | { | |
146 | DB(if (DEBUG_IO_TRACE()) | |
147 | printk("inb %#04x \n", addr);) | |
148 | return 0; | |
149 | } | |
150 | ||
151 | /**************************************************************************** | |
152 | PARAMETERS: | |
153 | addr - PIO address to read | |
154 | RETURN: | |
155 | 0 | |
156 | REMARKS: | |
157 | Default PIO word read function. Doesn't perform real inw. | |
158 | ****************************************************************************/ | |
159 | static u16 X86API p_inw(X86EMU_pioAddr addr) | |
160 | { | |
161 | DB(if (DEBUG_IO_TRACE()) | |
162 | printk("inw %#04x \n", addr);) | |
163 | return 0; | |
164 | } | |
165 | ||
166 | /**************************************************************************** | |
167 | PARAMETERS: | |
168 | addr - PIO address to read | |
169 | RETURN: | |
170 | 0 | |
171 | REMARKS: | |
172 | Default PIO long read function. Doesn't perform real inl. | |
173 | ****************************************************************************/ | |
174 | static u32 X86API p_inl(X86EMU_pioAddr addr) | |
175 | { | |
176 | DB(if (DEBUG_IO_TRACE()) | |
177 | printk("inl %#04x \n", addr);) | |
178 | return 0; | |
179 | } | |
180 | ||
181 | /**************************************************************************** | |
182 | PARAMETERS: | |
183 | addr - PIO address to write | |
184 | val - Value to store | |
185 | REMARKS: | |
186 | Default PIO byte write function. Doesn't perform real outb. | |
187 | ****************************************************************************/ | |
188 | static void X86API p_outb(X86EMU_pioAddr addr, u8 val) | |
189 | { | |
190 | DB(if (DEBUG_IO_TRACE()) | |
191 | printk("outb %#02x -> %#04x \n", val, addr);) | |
192 | return; | |
193 | } | |
194 | ||
195 | /**************************************************************************** | |
196 | PARAMETERS: | |
197 | addr - PIO address to write | |
198 | val - Value to store | |
199 | REMARKS: | |
200 | Default PIO word write function. Doesn't perform real outw. | |
201 | ****************************************************************************/ | |
202 | static void X86API p_outw(X86EMU_pioAddr addr, u16 val) | |
203 | { | |
204 | DB(if (DEBUG_IO_TRACE()) | |
205 | printk("outw %#04x -> %#04x \n", val, addr);) | |
206 | return; | |
207 | } | |
208 | ||
209 | /**************************************************************************** | |
210 | PARAMETERS: | |
211 | addr - PIO address to write | |
212 | val - Value to store | |
213 | REMARKS: | |
214 | Default PIO ;ong write function. Doesn't perform real outl. | |
215 | ****************************************************************************/ | |
216 | static void X86API p_outl(X86EMU_pioAddr addr, u32 val) | |
217 | { | |
218 | DB(if (DEBUG_IO_TRACE()) | |
219 | printk("outl %#08x -> %#04x \n", val, addr);) | |
220 | return; | |
221 | } | |
222 | ||
223 | /*------------------------- Global Variables ------------------------------*/ | |
224 | ||
225 | u8(X86APIP sys_rdb) (u32 addr) = rdb; | |
226 | u16(X86APIP sys_rdw) (u32 addr) = rdw; | |
227 | u32(X86APIP sys_rdl) (u32 addr) = rdl; | |
228 | void (X86APIP sys_wrb) (u32 addr, u8 val) = wrb; | |
229 | void (X86APIP sys_wrw) (u32 addr, u16 val) = wrw; | |
230 | void (X86APIP sys_wrl) (u32 addr, u32 val) = wrl; | |
231 | u8(X86APIP sys_inb) (X86EMU_pioAddr addr) = p_inb; | |
232 | u16(X86APIP sys_inw) (X86EMU_pioAddr addr) = p_inw; | |
233 | u32(X86APIP sys_inl) (X86EMU_pioAddr addr) = p_inl; | |
234 | void (X86APIP sys_outb) (X86EMU_pioAddr addr, u8 val) = p_outb; | |
235 | void (X86APIP sys_outw) (X86EMU_pioAddr addr, u16 val) = p_outw; | |
236 | void (X86APIP sys_outl) (X86EMU_pioAddr addr, u32 val) = p_outl; | |
237 | ||
238 | /*----------------------------- Setup -------------------------------------*/ | |
239 | ||
240 | /**************************************************************************** | |
241 | PARAMETERS: | |
242 | funcs - New memory function pointers to make active | |
243 | ||
244 | REMARKS: | |
245 | This function is used to set the pointers to functions which access | |
246 | memory space, allowing the user application to override these functions | |
247 | and hook them out as necessary for their application. | |
248 | ****************************************************************************/ | |
249 | void X86EMU_setupMemFuncs(X86EMU_memFuncs * funcs) | |
250 | { | |
251 | sys_rdb = funcs->rdb; | |
252 | sys_rdw = funcs->rdw; | |
253 | sys_rdl = funcs->rdl; | |
254 | sys_wrb = funcs->wrb; | |
255 | sys_wrw = funcs->wrw; | |
256 | sys_wrl = funcs->wrl; | |
257 | } | |
258 | ||
259 | /**************************************************************************** | |
260 | PARAMETERS: | |
261 | funcs - New programmed I/O function pointers to make active | |
262 | ||
263 | REMARKS: | |
264 | This function is used to set the pointers to functions which access | |
265 | I/O space, allowing the user application to override these functions | |
266 | and hook them out as necessary for their application. | |
267 | ****************************************************************************/ | |
268 | void X86EMU_setupPioFuncs(X86EMU_pioFuncs * funcs) | |
269 | { | |
270 | sys_inb = funcs->inb; | |
271 | sys_inw = funcs->inw; | |
272 | sys_inl = funcs->inl; | |
273 | sys_outb = funcs->outb; | |
274 | sys_outw = funcs->outw; | |
275 | sys_outl = funcs->outl; | |
276 | } | |
277 | ||
a3c700ec SG |
278 | void X86EMU_setupIntrFunc(int intnum, X86EMU_intrFuncs func) |
279 | { | |
280 | _X86EMU_intrTab[intnum] = func; | |
281 | } | |
282 | ||
ece92f85 JJ |
283 | /**************************************************************************** |
284 | PARAMETERS: | |
285 | funcs - New interrupt vector table to make active | |
286 | ||
287 | REMARKS: | |
288 | This function is used to set the pointers to functions which handle | |
289 | interrupt processing in the emulator, allowing the user application to | |
290 | hook interrupts as necessary for their application. Any interrupts that | |
291 | are not hooked by the user application, and reflected and handled internally | |
292 | in the emulator via the interrupt vector table. This allows the application | |
293 | to get control when the code being emulated executes specific software | |
294 | interrupts. | |
295 | ****************************************************************************/ | |
296 | void X86EMU_setupIntrFuncs(X86EMU_intrFuncs funcs[]) | |
297 | { | |
298 | int i; | |
299 | ||
300 | for (i = 0; i < 256; i++) | |
301 | _X86EMU_intrTab[i] = NULL; | |
302 | if (funcs) { | |
303 | for (i = 0; i < 256; i++) | |
304 | _X86EMU_intrTab[i] = funcs[i]; | |
305 | } | |
306 | } | |
307 | ||
308 | /**************************************************************************** | |
309 | PARAMETERS: | |
310 | int - New software interrupt to prepare for | |
311 | ||
312 | REMARKS: | |
313 | This function is used to set up the emulator state to exceute a software | |
314 | interrupt. This can be used by the user application code to allow an | |
315 | interrupt to be hooked, examined and then reflected back to the emulator | |
316 | so that the code in the emulator will continue processing the software | |
317 | interrupt as per normal. This essentially allows system code to actively | |
318 | hook and handle certain software interrupts as necessary. | |
319 | ****************************************************************************/ | |
320 | void X86EMU_prepareForInt(int num) | |
321 | { | |
322 | push_word((u16) M.x86.R_FLG); | |
323 | CLEAR_FLAG(F_IF); | |
324 | CLEAR_FLAG(F_TF); | |
325 | push_word(M.x86.R_CS); | |
326 | M.x86.R_CS = mem_access_word(num * 4 + 2); | |
327 | push_word(M.x86.R_IP); | |
328 | M.x86.R_IP = mem_access_word(num * 4); | |
329 | M.x86.intr = 0; | |
330 | } |