1 /* $NetBSD: x86emu.h,v 1.1 2007/12/01 20:14:10 joerg Exp $ */
2 /* $OpenBSD: x86emu.h,v 1.3 2009/06/06 03:45:05 matthieu Exp $ */
5 /****************************************************************************
7 * Realmode X86 Emulator Library
9 * Copyright (C) 1996-1999 SciTech Software, Inc.
10 * Copyright (C) David Mosberger-Tang
11 * Copyright (C) 1999 Egbert Eich
12 * Copyright (C) 2007 Joerg Sonnenberger
14 * ========================================================================
16 * Permission to use, copy, modify, distribute, and sell this software and
17 * its documentation for any purpose is hereby granted without fee,
18 * provided that the above copyright notice appear in all copies and that
19 * both that copyright notice and this permission notice appear in
20 * supporting documentation, and that the name of the authors not be used
21 * in advertising or publicity pertaining to distribution of the software
22 * without specific, written prior permission. The authors makes no
23 * representations about the suitability of this software for any purpose.
24 * It is provided "as is" without express or implied warranty.
26 * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
27 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
28 * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
29 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
30 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
31 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
32 * PERFORMANCE OF THIS SOFTWARE.
34 ****************************************************************************/
36 #ifndef __X86EMU_X86EMU_H
37 #define __X86EMU_X86EMU_H
39 #include <sys/types.h>
40 #include <sys/endian.h>
43 #include <sys/systm.h>
44 #include <machine/setjmp.h>
50 * General EAX, EBX, ECX, EDX type registers. Note that for
51 * portability, and speed, the issue of byte swapping is not addressed
52 * in the registers. All registers are stored in the default format
53 * available on the host machine. The only critical issue is that the
54 * registers should line up EXACTLY in the same manner as they do in
60 * etc. The result is that alot of the calculations can then be
61 * done using the native instruction set fully.
66 struct x86emu_register32
{
70 struct x86emu_register16
{
75 struct x86emu_register8
{
76 uint8_t filler0
, filler1
;
80 #else /* !__BIG_ENDIAN__ */
82 struct x86emu_register32
{
86 struct x86emu_register16
{
90 struct x86emu_register8
{
94 #endif /* BIG_ENDIAN */
96 union x86emu_register
{
97 struct x86emu_register32 I32_reg
;
98 struct x86emu_register16 I16_reg
;
99 struct x86emu_register8 I8_reg
;
103 uint16_t register_cs
;
104 uint16_t register_ds
;
105 uint16_t register_es
;
106 uint16_t register_fs
;
107 uint16_t register_gs
;
108 uint16_t register_ss
;
109 uint32_t register_flags
;
110 union x86emu_register register_a
;
111 union x86emu_register register_b
;
112 union x86emu_register register_c
;
113 union x86emu_register register_d
;
115 union x86emu_register register_sp
;
116 union x86emu_register register_bp
;
117 union x86emu_register register_si
;
118 union x86emu_register register_di
;
119 union x86emu_register register_ip
;
122 * MODE contains information on:
123 * REPE prefix 2 bits repe,repne
124 * SEGMENT overrides 5 bits normal,DS,SS,CS,ES
125 * Delayed flag set 3 bits (zero, signed, parity)
127 * interrupt # 8 bits instruction raised interrupt
128 * BIOS video segregs 4 bits
129 * Interrupt Pending 1 bits
130 * Extern interrupt 1 bits
134 volatile int intr
; /* mask of pending interrupts */
143 struct x86emu_regs x86
;
149 unsigned int cur_mod
:2;
150 unsigned int cur_rl
:3;
151 unsigned int cur_rh
:3;
154 uint8_t (*emu_rdb
)(struct x86emu
*, uint32_t addr
);
155 uint16_t (*emu_rdw
)(struct x86emu
*, uint32_t addr
);
156 uint32_t (*emu_rdl
)(struct x86emu
*, uint32_t addr
);
157 void (*emu_wrb
)(struct x86emu
*, uint32_t addr
,uint8_t val
);
158 void (*emu_wrw
)(struct x86emu
*, uint32_t addr
, uint16_t val
);
159 void (*emu_wrl
)(struct x86emu
*, uint32_t addr
, uint32_t val
);
161 uint8_t (*emu_inb
)(struct x86emu
*, uint16_t addr
);
162 uint16_t (*emu_inw
)(struct x86emu
*, uint16_t addr
);
163 uint32_t (*emu_inl
)(struct x86emu
*, uint16_t addr
);
164 void (*emu_outb
)(struct x86emu
*, uint16_t addr
, uint8_t val
);
165 void (*emu_outw
)(struct x86emu
*, uint16_t addr
, uint16_t val
);
166 void (*emu_outl
)(struct x86emu
*, uint16_t addr
, uint32_t val
);
168 void (*_x86emu_intrTab
[256])(struct x86emu
*, int);
173 void x86emu_init_default(struct x86emu
*);
177 void x86emu_exec(struct x86emu
*);
178 void x86emu_exec_call(struct x86emu
*, uint16_t, uint16_t);
179 void x86emu_exec_intr(struct x86emu
*, uint8_t);
180 void x86emu_halt_sys(struct x86emu
*) __dead2
;
184 #endif /* __X86EMU_X86EMU_H */