5 #include "v86_x86emu.h"
14 void printk(const char *fmt
, ...)
17 va_start(argptr
, fmt
);
18 vsyslog(LOG_INFO
, fmt
, argptr
);
25 v_wrw(((u32
) X86_SS
<< 4) + X86_SP
, val
);
28 static void x86emu_do_int(int num
)
34 /* Return address and flags */
39 X86_EFLAGS
= X86_EFLAGS
& ~(X86_VIF_MASK
| X86_TF_MASK
);
40 X86_CS
= v_rdw((num
<< 2) + 2);
41 X86_IP
= v_rdw((num
<< 2));
46 X86EMU_intrFuncs intFuncs
[256];
47 X86EMU_pioFuncs pioFuncs
= {
56 X86EMU_memFuncs memFuncs
= {
69 stack
= v86_mem_alloc(DEFAULT_STACK_SIZE
);
71 X86_ESP
= DEFAULT_STACK_SIZE
;
73 halt
= v86_mem_alloc(0x100);
76 X86EMU_setupPioFuncs(&pioFuncs
);
77 X86EMU_setupMemFuncs(&memFuncs
);
79 /* Setup interrupt handlers */
80 for (i
= 0; i
< 256; i
++) {
81 intFuncs
[i
] = x86emu_do_int
;
83 X86EMU_setupIntrFuncs(intFuncs
);
85 /* Set the default flags */
86 X86_EFLAGS
= X86_IF_MASK
| X86_IOPL_MASK
;
99 void rconv_v86_to_x86emu(struct v86_regs
*rs
)
109 X86_EFLAGS
= rs
->eflags
;
118 void rconv_x86emu_to_v86(struct v86_regs
*rd
)
128 rd
->eflags
= X86_EFLAGS
;
138 * Perform a simulated interrupt call.
140 int v86_int(int num
, struct v86_regs
*regs
)
142 rconv_v86_to_x86emu(regs
);
147 X86_CS
= v_rdw((num
<< 2) + 2);
148 X86_EIP
= v_rdw((num
<< 2));
150 X86_ESP
= DEFAULT_STACK_SIZE
;
151 X86_EFLAGS
= X86_IF_MASK
| X86_IOPL_MASK
;
159 rconv_x86emu_to_v86(regs
);
166 "EAX=0x%8.8lx, EBX=0x%8.8lx, ECX=0x%8.8lx, EDX=0x%8.8lx\n",
167 (unsigned long)X86_EAX
, (unsigned long)X86_EBX
,
168 (unsigned long)X86_ECX
, (unsigned long)X86_EDX
);
170 "ESP=0x%8.8lx, EBP=0x%8.8lx, ESI=0x%8.8lx, EDI=0x%8.8lx\n",
171 (unsigned long)X86_ESP
, (unsigned long)X86_EBP
,
172 (unsigned long)X86_ESI
, (unsigned long)X86_EDI
);
174 "CS=0x%4.4x, SS=0x%4.4x,"
175 " DS=0x%4.4x, ES=0x%4.4x, FS=0x%4.4x, GS=0x%4.4x\n",
176 X86_CS
, X86_SS
, X86_DS
, X86_ES
, X86_FS
, X86_GS
);
178 "EIP=0x%8.8lx, EFLAGS=0x%8.8lx\n",
179 (unsigned long)X86_EIP
, (unsigned long)X86_EFLAGS
);