diff --git a/sys/conf/NOTES b/sys/conf/NOTES index ee0b2202367f..69a80a5ea577 100644 --- a/sys/conf/NOTES +++ b/sys/conf/NOTES @@ -2756,3 +2756,6 @@ options AAC_DEBUG # Debugging levels: ##options BKTR_ALLOC_PAGES=(217*4+1) options BROOKTREE_ALLOC_PAGES=(217*4+1) options MAXFILES=999 + +# x86 real mode emulator +options X86EMU diff --git a/sys/conf/files b/sys/conf/files index 41a34b15d6f5..9b2158576207 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -2826,4 +2826,6 @@ dev/xen/netfront/netfront.c optional xen | xenhvm dev/xen/xenpci/xenpci.c optional xenpci dev/xen/xenpci/evtchn.c optional xenpci dev/xen/xenpci/machine_reboot.c optional xenpci +contrib/x86emu/x86emu.c optional x86emu +contrib/x86emu/x86emu_util.c optional x86emu diff --git a/sys/conf/options b/sys/conf/options index 22484e34ab02..2c2344b6a1b8 100644 --- a/sys/conf/options +++ b/sys/conf/options @@ -836,3 +836,5 @@ SND_FEEDER_FULL_MULTIFORMAT opt_snd.h SND_FEEDER_RATE_HP opt_snd.h SND_PCM_64 opt_snd.h SND_OLDSTEREO opt_snd.h + +X86EMU diff --git a/sys/contrib/x86emu/x86emu.c b/sys/contrib/x86emu/x86emu.c index d99367e8acdc..a26044a3167b 100644 --- a/sys/contrib/x86emu/x86emu.c +++ b/sys/contrib/x86emu/x86emu.c @@ -1,5 +1,6 @@ /* $OpenBSD: x86emu.c,v 1.4 2009/06/18 14:19:21 pirofti Exp $ */ /* $NetBSD: x86emu.c,v 1.7 2009/02/03 19:26:29 joerg Exp $ */ +/* $FreeBSD$ */ /* * @@ -32,8 +33,12 @@ * */ -#include -#include +#include +#include +#include + +#include +#include static void x86emu_intr_raise (struct x86emu *, uint8_t type); @@ -45,7 +50,7 @@ static uint8_t fetch_byte_imm (struct x86emu *); static uint16_t fetch_word_imm (struct x86emu *); static uint32_t fetch_long_imm (struct x86emu *); static uint8_t fetch_data_byte (struct x86emu *, uint32_t offset); -static uint8_t fetch_byte (struct x86emu *, uint segment, uint32_t offset); +static uint8_t fetch_byte (struct x86emu *, u_int segment, uint32_t offset); static uint16_t fetch_data_word (struct x86emu *, uint32_t offset); static uint16_t fetch_word (struct x86emu *, uint32_t segment, uint32_t offset); static uint32_t fetch_data_long (struct x86emu *, uint32_t offset); @@ -227,13 +232,8 @@ x86emu_exec(struct x86emu *emu) { emu->x86.intr = 0; -#ifdef _KERNEL - if (setjmp(&emu->exec_state)) - return; -#else if (setjmp(emu->exec_state)) return; -#endif for (;;) { if (emu->x86.intr) { @@ -282,11 +282,7 @@ x86emu_exec_intr(struct x86emu *emu, uint8_t intr) void x86emu_halt_sys(struct x86emu *emu) { -#ifdef _KERNEL - longjmp(&emu->exec_state); -#else longjmp(emu->exec_state, 1); -#endif } /* @@ -8339,3 +8335,32 @@ pop_long(struct x86emu *emu) emu->x86.R_SP += 4; return res; } + +static int +x86emu_modevent(module_t mod __unused, int type, void *data __unused) +{ + int err = 0; + + switch (type) { + case MOD_LOAD: + break; + + case MOD_UNLOAD: + break; + + default: + err = ENOTSUP; + break; + + } + return (err); +} + +static moduledata_t x86emu_mod = { + "x86emu", + x86emu_modevent, + NULL, +}; + +DECLARE_MODULE(x86emu, x86emu_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST); +MODULE_VERSION(x86emu, 1); diff --git a/sys/contrib/x86emu/x86emu.h b/sys/contrib/x86emu/x86emu.h index 4fd0f8a393fe..f25a95ba6c7b 100644 --- a/sys/contrib/x86emu/x86emu.h +++ b/sys/contrib/x86emu/x86emu.h @@ -1,5 +1,6 @@ /* $NetBSD: x86emu.h,v 1.1 2007/12/01 20:14:10 joerg Exp $ */ /* $OpenBSD: x86emu.h,v 1.3 2009/06/06 03:45:05 matthieu Exp $ */ +/* $FreeBSD$ */ /**************************************************************************** * @@ -40,6 +41,7 @@ #ifdef _KERNEL #include +#include #else #include #endif @@ -140,11 +142,7 @@ struct x86emu { void *sys_private; struct x86emu_regs x86; -#ifdef _KERNEL - label_t exec_state; -#else jmp_buf exec_state; -#endif uint64_t cur_cycles; @@ -179,7 +177,7 @@ void x86emu_init_default(struct x86emu *); void x86emu_exec(struct x86emu *); void x86emu_exec_call(struct x86emu *, uint16_t, uint16_t); void x86emu_exec_intr(struct x86emu *, uint8_t); -void x86emu_halt_sys(struct x86emu *) __dead; +void x86emu_halt_sys(struct x86emu *) __dead2; __END_DECLS diff --git a/sys/contrib/x86emu/x86emu_util.c b/sys/contrib/x86emu/x86emu_util.c index e96efc24a423..41a9f72d1423 100644 --- a/sys/contrib/x86emu/x86emu_util.c +++ b/sys/contrib/x86emu/x86emu_util.c @@ -1,5 +1,6 @@ /* $OpenBSD: x86emu_util.c,v 1.5 2009/06/18 14:19:21 pirofti Exp $ */ /* $NetBSD: x86emu_util.c,v 1.2 2007/12/04 17:32:22 joerg Exp $ */ +/* $FreeBSD$ */ /* * @@ -35,8 +36,8 @@ #include #include -#include -#include +#include +#include @@ -82,9 +83,9 @@ rdw(struct x86emu *emu, uint32_t addr) ((*(a + 1) << 8) & 0xff00); return r; } else - return letoh32(*(u_int32_t *)(emu->mem_base + addr)); + return le32toh(*(u_int32_t *)(emu->mem_base + addr)); #else - return letoh16(*(u_int16_t *)(emu->mem_base + addr)); + return le16toh(*(u_int16_t *)(emu->mem_base + addr)); #endif } @@ -113,9 +114,9 @@ rdl(struct x86emu *emu, uint32_t addr) ((*(a + 3) << 24) & 0xff000000); return r; } else - return letoh32(*(u_int32_t *)(emu->mem_base + addr)); + return le32toh(*(u_int32_t *)(emu->mem_base + addr)); #else - return letoh32(*(u_int32_t *)(emu->mem_base + addr)); + return le32toh(*(u_int32_t *)(emu->mem_base + addr)); #endif } diff --git a/sys/modules/Makefile b/sys/modules/Makefile index 51408b3b6bb3..9f5dbea2d3ad 100644 --- a/sys/modules/Makefile +++ b/sys/modules/Makefile @@ -298,6 +298,7 @@ SUBDIR= ${_3dfx} \ wlan_xauth \ ${_wpi} \ ${_wpifw} \ + x86emu \ ${_xe} \ xfs \ xl \ diff --git a/sys/modules/x86emu/Makefile b/sys/modules/x86emu/Makefile new file mode 100644 index 000000000000..3991d6c70d05 --- /dev/null +++ b/sys/modules/x86emu/Makefile @@ -0,0 +1,8 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../contrib/x86emu + +KMOD= x86emu +SRCS= x86emu.c x86emu_util.c + +.include diff --git a/sys/sys/param.h b/sys/sys/param.h index 46d016bf3478..0fb65b09c8d2 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -58,7 +58,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 900000 /* Master, propagated to newvers */ +#define __FreeBSD_version 900001 /* Master, propagated to newvers */ #ifndef LOCORE #include