2 * Copyright 1999 Egbert Eich
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the authors not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. The authors makes no representations
11 * about the suitability of this software for any purpose. It is provided
12 * "as is" without express or implied warranty.
14 * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
24 #define IF_MASK 0x00000200
25 #define VIF_MASK 0x00080000 /* virtual interrupt flag */
26 #define VIP_MASK 0x00100000 /* virtual interrupt pending */
28 #include </usr/include/unistd.h>
30 #include <asm/unistd.h>
31 /*#include <syscall-list.h> */
41 #include "AsmMacros.h"
48 #define CPU_REG(reg) M.x86.R_##reg
55 if (!Config.PrintPort && !Config.IoStatistics) {
57 #if defined (__i386__)
58 P.inb = (u8(*)(u16))inb;
59 P.inw = (u16(*)(u16))inw;
60 P.outb = (void(*)(u16,u8))outb;
61 P.outw = (void(*)(u16,u16))outw;
68 #if defined (__i386__) && ! defined(NEED_PCI_IO)
69 P.inl = (u32(*)(u16))inl;
70 P.outl = (void(*)(u16,u32))outl;
86 x86emu_do_int(int num)
90 i_printf("int 0x%x received: ax:0x%x",num,CPU_REG(AX));
92 i_printf(" at: 0x%x\n",getIP());
96 /* try to run bios interrupt */
98 /* if not installed fall back */
99 #define COPY(x,y) regs.y = M.x86.x
100 #define COPY_R(x,y) M.x86.x = regs.y
119 if (!(int_handler(num,®s))) {
120 if (!run_bios_int(num,®s))
141 COPY_R(R_EFLG,eflags);
145 fprintf(stderr,"\nUnknown vm86_int: %X\n\n",num);
154 setup_x86emu(unsigned long bios_start, i86biosRegsPtr regs)
159 X86EMU_intrFuncs intFuncs[256];
161 X86EMU_pioFuncs pioFuncs = {
165 (void(*)(u16,u8))P.outb,
166 (void(*)(u16,u16))P.outw,
167 (void(*)(u16,u32))P.outl
170 X86EMU_memFuncs memFuncs = {
174 (void(*)(u32,u8))mem_wb,
175 (void(*)(u32,u16))mem_ww,
176 (void(*)(u32,u32))mem_wl
180 M.mem_size = 1024*1024 + 1024;
181 /* M.x86.debug = DEBUG_DISASSEMBLE_F | DEBUG_TRACE_F | DEBUG_DECODE_F; */
182 /* M.x86.debug |= DEBUG_DECODE_F | DEBUG_TRACE_F; */
184 * For single step tracing compile x86emu with option -DDEBUG
188 M.x86.debug = DEBUG_SAVE_CS_IP;
193 X86EMU_setupPioFuncs(&pioFuncs);
195 X86EMU_setupMemFuncs(&memFuncs);
198 intFuncs[i] = x86emu_do_int;
199 X86EMU_setupIntrFuncs(intFuncs);
201 eip = bios_start & 0xFFFF;
202 cs = (bios_start & 0xFF0000) >> 4;
204 CPU_REG(EAX) = regs->ax;
205 CPU_REG(EBX) = regs->bx;
206 CPU_REG(ECX) = regs->cx;
207 CPU_REG(EDX) = regs->dx;
208 CPU_REG(ESI) = regs->si;
209 CPU_REG(EDI) = regs->di;
214 CPU_REG(SS) = 0x30; /* This is the standard pc bios stack */
215 CPU_REG(ES) = regs->es;
216 CPU_REG(DS) = regs->ds;
219 CPU_REG(EFLG) |= (VIF_MASK | VIP_MASK | IF_MASK | 0x2);
223 collect_bios_regs(i86biosRegsPtr regs)
225 regs->ax = CPU_REG(EAX);
226 regs->bx = CPU_REG(EBX);
227 regs->cx = CPU_REG(ECX);
228 regs->dx = CPU_REG(EDX);
229 regs->es = CPU_REG(ES);
230 regs->ds = CPU_REG(DS);
231 regs->di = CPU_REG(EDI);
232 regs->si = CPU_REG(ESI);
241 static jmp_buf x86_esc;
249 do_x86(unsigned long bios_start, i86biosRegsPtr regs)
251 static void (*org_handler)(int);
253 setup_x86emu(bios_start,regs);
254 if (setjmp(x86_esc) == 0) {
255 org_handler = signal(2,vmexit);
257 signal(2,org_handler);
258 collect_bios_regs(regs);
260 signal(2,org_handler);
261 printf("interrupted at 0x%x\n",((CARD16)CPU_REG(CS)) << 4
262 | (CARD16)CPU_REG(EIP));
267 run_bios_int(int num, struct regs86 *regs)
270 static int firsttime = 1;
272 /* check if bios vector is initialized */
273 if (((CARD16*)0)[(num<<1)+1] == 0x0000) { /* SYS_BIOS_SEG ?*/
275 i_printf("card BIOS not loaded\n");
287 i_printf("calling card BIOS at: ");
288 i_printf("0x%x:%x\n",((CARD16 *) 0)[(num << 1) + 1],
289 (CARD32)((CARD16 *) 0)[num << 1]);
290 X86EMU_prepareForInt(num);
298 return ((CARD32*)0)[num];
302 printk(const char *fmt, ...)
305 va_start(argptr, fmt);
306 vfprintf(stdout, fmt, argptr);
315 return (M.x86.saved_cs << 4) + M.x86.saved_ip;