6 #include "v86_x86emu.h"
15 void printk(const char *fmt
, ...)
18 va_start(argptr
, fmt
);
19 vsyslog(LOG_INFO
, fmt
, argptr
);
26 wrw(((u32
) X86_SS
<< 4) + X86_SP
, val
);
29 static void x86emu_do_int(int num
)
34 eflags
= eflags
| X86_IF_MASK
;
36 /* Return address and flags */
40 X86_EFLAGS
= X86_EFLAGS
& ~(X86_VIF_MASK
| X86_TF_MASK
);
42 X86_CS
= rdw((num
<< 2) + 2);
43 X86_IP
= rdw((num
<< 2));
48 X86EMU_intrFuncs intFuncs
[256];
49 X86EMU_pioFuncs pioFuncs
= {
61 stack
= v86_mem_alloc(DEFAULT_STACK_SIZE
);
62 X86_SS
= (u32
)stack
>> 4;
65 halt
= v86_mem_alloc(0x100);
68 /* Setup x86emu I/O functions */
69 X86EMU_setupPioFuncs(&pioFuncs
);
71 /* Setup interrupt handlers */
72 for (i
= 0; i
< 256; i
++) {
73 intFuncs
[i
] = x86emu_do_int
;
75 X86EMU_setupIntrFuncs(intFuncs
);
77 /* Set the default flags */
78 X86_EFLAGS
= X86_IF_MASK
| X86_IOPL_MASK
;
80 /* M is a macro poiting to the global virtual machine state
83 M
.mem_size
= 0x100000;
96 void rconv_v86_to_x86emu(struct v86_regs
*rs
)
106 X86_EFLAGS
= rs
->eflags
;
115 void rconv_x86emu_to_v86(struct v86_regs
*rd
)
125 rd
->eflags
= X86_EFLAGS
;
135 * Perform a simulated interrupt call.
137 int v86_int(int num
, struct v86_regs
*regs
)
139 rconv_v86_to_x86emu(regs
);
142 X86_CS
= get_int_seg(num
);
143 X86_EIP
= get_int_off(num
);
144 X86_SS
= (u32
)stack
>> 4;
146 X86_EFLAGS
= DEFAULT_V86_FLAGS
| X86_IF_MASK
;
147 X86_EFLAGS
&= ~(X86_VIF_MASK
| X86_TF_MASK
| X86_IF_MASK
| X86_NT_MASK
);
149 pushw(DEFAULT_V86_FLAGS
);
150 pushw(((u32
)halt
>> 4));
155 rconv_x86emu_to_v86(regs
);