svn commit: r197019 - in head/sys: conf contrib/x86emu modules modules/x86emu sys

Xin LI delphij at FreeBSD.org
Wed Sep 9 05:53:26 UTC 2009


Author: delphij
Date: Wed Sep  9 05:53:26 2009
New Revision: 197019
URL: http://svn.freebsd.org/changeset/base/197019

Log:
   - Port x86emu to FreeBSD.
   - Connect x86emu to build.
  
  Tested with:	make universe
  Submitted by:	swell.k at gmail com

Added:
  head/sys/modules/x86emu/
  head/sys/modules/x86emu/Makefile   (contents, props changed)
Modified:
  head/sys/conf/NOTES
  head/sys/conf/files
  head/sys/conf/options
  head/sys/contrib/x86emu/x86emu.c   (contents, props changed)
  head/sys/contrib/x86emu/x86emu.h   (contents, props changed)
  head/sys/contrib/x86emu/x86emu_util.c   (contents, props changed)
  head/sys/modules/Makefile
  head/sys/sys/param.h

Modified: head/sys/conf/NOTES
==============================================================================
--- head/sys/conf/NOTES	Wed Sep  9 04:48:41 2009	(r197018)
+++ head/sys/conf/NOTES	Wed Sep  9 05:53:26 2009	(r197019)
@@ -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

Modified: head/sys/conf/files
==============================================================================
--- head/sys/conf/files	Wed Sep  9 04:48:41 2009	(r197018)
+++ head/sys/conf/files	Wed Sep  9 05:53:26 2009	(r197019)
@@ -2826,4 +2826,6 @@ dev/xen/netfront/netfront.c	optional xen
 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
 

Modified: head/sys/conf/options
==============================================================================
--- head/sys/conf/options	Wed Sep  9 04:48:41 2009	(r197018)
+++ head/sys/conf/options	Wed Sep  9 05:53:26 2009	(r197019)
@@ -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

Modified: head/sys/contrib/x86emu/x86emu.c
==============================================================================
--- head/sys/contrib/x86emu/x86emu.c	Wed Sep  9 04:48:41 2009	(r197018)
+++ head/sys/contrib/x86emu/x86emu.c	Wed Sep  9 05:53:26 2009	(r197019)
@@ -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 <dev/x86emu/x86emu.h>
-#include <dev/x86emu/x86emu_regs.h>
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+
+#include <contrib/x86emu/x86emu.h>
+#include <contrib/x86emu/x86emu_regs.h>
 
 static void 	x86emu_intr_raise (struct x86emu *, uint8_t type);
 
@@ -45,7 +50,7 @@ static uint8_t	fetch_byte_imm (struct x8
 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, uin
 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);

Modified: head/sys/contrib/x86emu/x86emu.h
==============================================================================
--- head/sys/contrib/x86emu/x86emu.h	Wed Sep  9 04:48:41 2009	(r197018)
+++ head/sys/contrib/x86emu/x86emu.h	Wed Sep  9 05:53:26 2009	(r197019)
@@ -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 <sys/systm.h>
+#include <machine/setjmp.h>
 #else
 #include <setjmp.h>
 #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
 

Modified: head/sys/contrib/x86emu/x86emu_util.c
==============================================================================
--- head/sys/contrib/x86emu/x86emu_util.c	Wed Sep  9 04:48:41 2009	(r197018)
+++ head/sys/contrib/x86emu/x86emu_util.c	Wed Sep  9 05:53:26 2009	(r197019)
@@ -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 <sys/param.h>
 #include <sys/endian.h>
 
-#include <dev/x86emu/x86emu.h>
-#include <dev/x86emu/x86emu_regs.h>
+#include <contrib/x86emu/x86emu.h>
+#include <contrib/x86emu/x86emu_regs.h>
 
 
 
@@ -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
 }
 

Modified: head/sys/modules/Makefile
==============================================================================
--- head/sys/modules/Makefile	Wed Sep  9 04:48:41 2009	(r197018)
+++ head/sys/modules/Makefile	Wed Sep  9 05:53:26 2009	(r197019)
@@ -298,6 +298,7 @@ SUBDIR=	${_3dfx} \
 	wlan_xauth \
 	${_wpi} \
 	${_wpifw} \
+	x86emu \
 	${_xe} \
 	xfs \
 	xl \

Added: head/sys/modules/x86emu/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/modules/x86emu/Makefile	Wed Sep  9 05:53:26 2009	(r197019)
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+.PATH:	${.CURDIR}/../../contrib/x86emu
+
+KMOD=	x86emu
+SRCS=	x86emu.c x86emu_util.c
+
+.include <bsd.kmod.mk>

Modified: head/sys/sys/param.h
==============================================================================
--- head/sys/sys/param.h	Wed Sep  9 04:48:41 2009	(r197018)
+++ head/sys/sys/param.h	Wed Sep  9 05:53:26 2009	(r197019)
@@ -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 <sys/types.h>


More information about the svn-src-all mailing list