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