[Midnightbsd-cvs] mports: mports/emulators: add development version of kqemu module.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Mar 1 11:36:06 EST 2009


Log Message:
-----------
add development version of kqemu module.

Modified Files:
--------------
    mports/emulators:
        Makefile (r1.23 -> r1.24)

Added Files:
-----------
    mports/emulators/kqemu-kmod-devel:
        Makefile (r1.1)
        distinfo (r1.1)
        pkg-descr (r1.1)
        pkg-message (r1.1)
    mports/emulators/kqemu-kmod-devel/files:
        kqemu.in (r1.1)
        patch-Makefile.freebsd (r1.1)
        patch-common-Makefile (r1.1)
        patch-configure (r1.1)
        patch-fpucontext (r1.1)
        patch-kqemu-freebsd.c (r1.1)
        patch-tssworkaround (r1.1)

-------------- next part --------------
Index: Makefile
===================================================================
RCS file: /home/cvs/mports/emulators/Makefile,v
retrieving revision 1.23
retrieving revision 1.24
diff -L emulators/Makefile -L emulators/Makefile -u -r1.23 -r1.24
--- emulators/Makefile
+++ emulators/Makefile
@@ -12,6 +12,7 @@
     SUBDIR += extract-xiso
     SUBDIR += ia64sim
     SUBDIR += kqemu-kmod
+    SUBDIR += kqemu-kmod-devel
     SUBDIR += linux_base-fc4
     SUBDIR += mtools
     SUBDIR += pearpc
--- /dev/null
+++ emulators/kqemu-kmod-devel/pkg-message
@@ -0,0 +1,5 @@
+Notice:
+If you installed this from a package and your kernel configuration
+differs from the one on the package build machine (or your kernel source
+is newer than the package), then the kld may not work, or even panic.
+Consider building it from ports in that case.
--- /dev/null
+++ emulators/kqemu-kmod-devel/pkg-descr
@@ -0,0 +1,3 @@
+KQEMU is a qemu accelerator kernel module on x86/amd64.
+
+WWW: http://fabrice.bellard.free.fr/qemu/
--- /dev/null
+++ emulators/kqemu-kmod-devel/Makefile
@@ -0,0 +1,69 @@
+# $MidnightBSD: mports/emulators/kqemu-kmod-devel/Makefile,v 1.1 2009/03/01 16:36:03 laffer1 Exp $
+
+PORTNAME=	kqemu
+PORTVERSION=	1.4.0.p1
+CATEGORIES=	emulators kld
+MASTER_SITES=	http://bellard.org/qemu/ \
+		http://qemu.org/ \
+		${MASTER_SITE_FREEBSD_LOCAL}
+MASTER_SITE_SUBDIR=	nox
+PKGNAMESUFFIX=	-kmod-devel
+DISTNAME=	${PORTNAME}-${PORTVERSION:C/.p/pre/}
+DIST_SUBDIR=	kqemu
+
+MAINTAINER=	ports at MidnightBSD.org
+COMMENT=	Kernel Accelerator for QEMU CPU Emulator (development version)
+LICENSE=	gpl2
+
+ONLY_FOR_ARCHS=	i386 amd64
+HAS_CONFIGURE=	yes
+USE_GMAKE=	yes
+CONFIGURE_ARGS+=	--prefix=${PREFIX} --cc=${CC}
+CONFLICTS=	kqemu-kmod-[0-9]*
+
+USE_RC_SUBR=	kqemu
+
+.include <bsd.port.pre.mk>
+
+PORTDOCS=	kqemu-doc.html kqemu-tech.html
+PLIST_FILES=	"include/kqemu/kqemu.h"
+PLIST_FILES+=	"@dirrm include/kqemu"
+PLIST_FILES+=	"@cwd /"
+PLIST_FILES+=	${KMODDIR:C,^/,,}/kqemu.ko
+PLIST_FILES+=	"@unexec kldxref ${KMODDIR}"
+
+MAKEFILE=	Makefile.freebsd
+
+.if ${ARCH} == "amd64"
+MAKE_ARGS+=	ARCH=x86_64
+.endif
+
+# install where x11/nvidia-driver does also:
+KMODDIR=	/boot/modules
+
+MAKE_ENV+=	KMODDIR="${KMODDIR}"
+
+.if !exists(${SRC_BASE}/sys/Makefile)
+IGNORE=		requires kernel source to be installed
+.endif
+
+CFLAGS+=       ${DEBUG_FLAGS}
+
+do-build:
+	@(cd ${BUILD_WRKSRC}/common; ${SETENV} ${MAKE_ENV} ${GMAKE} ${MAKE_FLAGS} Makefile ${MAKE_ARGS} ${ALL_TARGET})
+	@(cd ${BUILD_WRKSRC}; ${SETENV} ${MAKE_ENV} ${MAKE} ${MAKE_FLAGS} ${MAKEFILE} ${ALL_TARGET})
+
+pre-install:
+	${MKDIR} ${KMODDIR}
+
+do-install:
+	@(cd ${INSTALL_WRKSRC} && ${SETENV} ${MAKE_ENV} ${MAKE} ${MAKE_FLAGS} ${MAKEFILE} ${INSTALL_TARGET})
+	${MKDIR} ${PREFIX}/include/kqemu
+	${INSTALL_DATA} ${WRKSRC}/kqemu.h ${PREFIX}/include/kqemu
+.if !defined(NOPORTDOCS)
+	${MKDIR} ${DOCSDIR}
+	${INSTALL_DATA} ${WRKSRC}/kqemu-doc.html ${WRKSRC}/kqemu-tech.html \
+		${DOCSDIR}
+.endif
+
+.include <bsd.port.post.mk>
--- /dev/null
+++ emulators/kqemu-kmod-devel/distinfo
@@ -0,0 +1,3 @@
+MD5 (kqemu/kqemu-1.4.0pre1.tar.gz) = d738d8ca7332211ab716ec3213d82ee1
+SHA256 (kqemu/kqemu-1.4.0pre1.tar.gz) = bac3e84eae1c867b06cd06ed2bcf563ba8304bd4e5a900880c2abe61b9aab491
+SIZE (kqemu/kqemu-1.4.0pre1.tar.gz) = 168249
--- /dev/null
+++ emulators/kqemu-kmod-devel/files/patch-tssworkaround
@@ -0,0 +1,112 @@
+Index: kqemu-freebsd.c
+@@ -38,6 +38,14 @@
+ #else
+ #include <machine/npx.h>
+ #endif
++#ifdef __x86_64__
++#include <sys/smp.h>
++#include <sys/pcpu.h>
++#include <machine/pcb.h>
++#include <machine/specialreg.h>
++#include <machine/segments.h>
++#include <machine/tss.h>
++#endif
+ 
+ #include "kqemu-kernel.h"
+ 
+@@ -248,6 +256,57 @@
+     va_end(ap);
+ }
+ 
++#ifdef __x86_64__
++int kqemu_cpu0gdtfixed;
++int kqemu_gdts_used;
++struct user_segment_descriptor *kqemu_gdts;
++struct region_descriptor kqemu_r_newgdt;
++extern  struct pcpu __pcpu[];
++
++/* called with interrupts disabled */
++void CDECL kqemu_tss_fixup(unsigned long kerngdtbase)
++{
++    int gsel_tss = GSEL(GPROC0_SEL, SEL_KPL);
++    unsigned cpuid = PCPU_GET(cpuid);
++    struct user_segment_descriptor *newgdt = gdt;
++
++    if (mp_ncpus <= 1 || kerngdtbase != (unsigned long)gdt)
++	/* UP host or gdt already moved, nothing to do */
++	return;
++    if (cpuid) {
++	/* move gdts of all but first cpu */
++	if (!kqemu_gdts)
++	    /*
++	     * XXX gdt is allocated as
++	     *	struct user_segment_descriptor gdt[NGDT * MAXCPU];
++	     * so it has room for the moved copies; need to allocate at
++	     * kldload (and only free if kqemu_gdts_used is zero) should this
++	     * change in the future
++	     */
++	    kqemu_gdts = &gdt[NGDT];
++	++kqemu_gdts_used;
++	newgdt = &kqemu_gdts[NGDT * (cpuid - 1)];
++	bcopy(gdt, newgdt, NGDT * sizeof(gdt[0]));
++	kqemu_r_newgdt.rd_limit = NGDT * sizeof(gdt[0]) - 1;
++	kqemu_r_newgdt.rd_base = (long) newgdt;
++    } else {
++	if (kqemu_cpu0gdtfixed)
++	    return;
++	++kqemu_cpu0gdtfixed;
++    }
++    gdt_segs[GPROC0_SEL].ssd_base = (long) &common_tss[cpuid];
++    ssdtosyssd(&gdt_segs[GPROC0_SEL],
++       (struct system_segment_descriptor *)&newgdt[GPROC0_SEL]);
++    if (cpuid) {
++	lgdt(&kqemu_r_newgdt);
++	wrmsr(MSR_GSBASE, (u_int64_t)&__pcpu[cpuid]);
++	wrmsr(MSR_KGSBASE, curthread->td_pcb->pcb_gsbase);
++	wrmsr(MSR_FSBASE, curthread->td_pcb->pcb_fsbase);
++    }
++    ltr(gsel_tss);
++}
++#endif
++
+ struct kqemu_instance { 
+ #if __FreeBSD_version >= 500000
+     TAILQ_ENTRY(kqemu_instance) kqemu_ent;
+Index: common/kernel.c
+@@ -1025,6 +1025,9 @@
+ #ifdef __x86_64__
+     uint16_t saved_ds, saved_es;
+     unsigned long fs_base, gs_base;
++#ifdef __FreeBSD__
++    struct kqemu_global_state *g = s->global_state;
++#endif
+ #endif
+     
+ #ifdef PROFILE
+@@ -1096,6 +1099,14 @@
+             apic_nmi_mask = apic_save_and_disable_nmi(s);
+         }
+ 
++#ifdef __FreeBSD__
++#ifdef __x86_64__
++        spin_lock(&g->lock);
++        asm volatile ("sgdt %0" : : "m" (s->kernel_gdt));
++        kqemu_tss_fixup(s->kernel_gdt.base);
++        spin_unlock(&g->lock);
++#endif
++#endif
+         /* load breakpoint registers and avoid setting them if in the
+            monitor address space. We suppose that no breakpoints are
+            set by the host OS for this process */
+Index: kqemu-kernel.h
+@@ -48,4 +48,10 @@
+ 
+ void CDECL kqemu_log(const char *fmt, ...);
+ 
++#ifdef __FreeBSD__
++#ifdef __x86_64__
++void CDECL kqemu_tss_fixup(unsigned long kerngdtbase);
++#endif
++#endif
++
+ #endif /* KQEMU_KERNEL_H */
--- /dev/null
+++ emulators/kqemu-kmod-devel/files/patch-common-Makefile
@@ -0,0 +1,22 @@
+Index: common/Makefile
+@@ -47,9 +47,9 @@
+ ifeq ($(ARCH), x86_64)
+ COMMON_CFLAGS+=-mno-red-zone
+ endif
+-CFLAGS=$(COMMON_CFLAGS)
++CFLAGS=$(COMMON_CFLAGS) ${DEBUG_FLAGS}
+ MON_CFLAGS=$(COMMON_CFLAGS)
+-KERNEL_CFLAGS=$(COMMON_CFLAGS)
++KERNEL_CFLAGS=$(COMMON_CFLAGS) ${DEBUG_FLAGS}
+ 
+ # Disable SSP if GCC supports it
+ MON_CFLAGS+=$(call cc-option,$(MON_CC),-fno-stack-protector,)
+@@ -119,7 +119,7 @@
+ 	$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -c -o $@ $<
+ 
+ %.o: %.S
+-	$(CC) $(DEFINES) $(INCLUDES) -D__ASSEMBLY__ -c -o $@ $<
++	$(CC) ${DEBUG_FLAGS} $(DEFINES) $(INCLUDES) -D__ASSEMBLY__ -c -o $@ $<
+ 
+ clean:
+ 	rm -f *.o *~ monitor-image.h genoffsets genmon monitor_def.h \
--- /dev/null
+++ emulators/kqemu-kmod-devel/files/kqemu.in
@@ -0,0 +1,53 @@
+#!/bin/sh
+# $MidnightBSD: mports/emulators/kqemu-kmod-devel/files/kqemu.in,v 1.1 2009/03/01 16:36:03 laffer1 Exp $
+#
+# PROVIDE: kqemu
+# KEYWORD: nojail
+#
+# Add the following line to /etc/rc.conf[.local] to enable kqemu
+#
+# kqemu_enable="YES"
+#
+
+. /etc/rc.subr
+
+name="kqemu"
+rcvar=${name}_enable
+
+load_rc_config $name
+
+: ${kqemu_enable="NO"}
+
+start_cmd=kqemu_start
+stop_cmd=kqemu_stop
+
+kqemu_start()
+{
+	# load aio if needed
+	if ! kldstat -qm aio; then
+		if kldload aio; then
+			info 'aio module loaded.'
+		else
+			warn 'aio module failed to load.'
+			return 1
+		fi
+	fi
+	if ! kldstat -qm kqemu; then
+		if kldload kqemu; then
+			echo 'kqemu module loaded.'
+		else
+			warn 'kqemu module failed to load.'
+			return 1
+		fi
+	fi
+	return 0
+}
+
+kqemu_stop()
+{
+	if kldstat -qm kqemu && kldunload kqemu; then
+		echo 'kqemu module unloaded.'
+	fi
+}
+
+run_rc_command "$1"
--- /dev/null
+++ emulators/kqemu-kmod-devel/files/patch-fpucontext
@@ -0,0 +1,78 @@
+Index: common/kernel.c
+@@ -1240,6 +1240,11 @@
+             case MON_REQ_EXCEPTION:
+                 exec_exception(s->arg0);
+                 break;
++#ifdef __FreeBSD__
++            case MON_REQ_LOADFPUCONTEXT:
++                kqemu_loadfpucontext(s->arg0);
++                break;
++#endif
+             default:
+                 kqemu_log("invalid mon request: %d\n", s->mon_req);
+                 break;
+Index: common/kqemu_int.h
+@@ -523,6 +523,7 @@
+     MON_REQ_LOCK_USER_PAGE,
+     MON_REQ_UNLOCK_USER_PAGE,
+     MON_REQ_EXCEPTION,
++    MON_REQ_LOADFPUCONTEXT,
+ } MonitorRequest;
+ 
+ #define INTERRUPT_ENTRY_SIZE 16
+Index: common/monitor.c
+@@ -1995,8 +1995,13 @@
+         raise_exception_err(s, EXCP07_PREX, 0);
+     } else {
+         /* the host needs to restore the FPU state for us */
++#ifndef __FreeBSD__
+         s->mon_req = MON_REQ_EXCEPTION;
+         s->arg0 = 0x07;
++#else
++        s->mon_req = MON_REQ_LOADFPUCONTEXT;
++        s->arg0 = (unsigned long)s->cpu_state.cpl;
++#endif
+         monitor2kernel1(s);
+     }
+ }
+Index: kqemu-freebsd.c
+@@ -33,6 +33,11 @@
+ 
+ #include <machine/vmparam.h>
+ #include <machine/stdarg.h>
++#ifdef __x86_64__
++#include <machine/fpu.h>
++#else
++#include <machine/npx.h>
++#endif
+ 
+ #include "kqemu-kernel.h"
+ 
+@@ -172,6 +177,15 @@
+ {
+ }
+ 
++void CDECL kqemu_loadfpucontext(unsigned long cpl)
++{
++#ifdef __x86_64__
++    fpudna();
++#else
++    npxdna();
++#endif
++}
++
+ #if __FreeBSD_version < 500000
+ static int
+ curpriority_cmp(struct proc *p)
+Index: kqemu-kernel.h
+@@ -40,6 +40,10 @@
+ void * CDECL kqemu_io_map(unsigned long page_index, unsigned int size);
+ void CDECL kqemu_io_unmap(void *ptr, unsigned int size);
+ 
++#ifdef __FreeBSD__
++void CDECL kqemu_loadfpucontext(unsigned long cpl);
++#endif
++
+ int CDECL kqemu_schedule(void);
+ 
+ void CDECL kqemu_log(const char *fmt, ...);
--- /dev/null
+++ emulators/kqemu-kmod-devel/files/patch-configure
@@ -0,0 +1,11 @@
+--- configure.orig	2009-03-01 11:33:36 -0500
++++ configure	2009-03-01 11:33:52 -0500
+@@ -89,7 +89,7 @@
+ check_gcc="yes"
+ 
+ # OS specific
+-targetos=`uname -s`
++targetos="FreeBSD"
+ case $targetos in
+ CYGWIN*)
+ mingw32="yes"
--- /dev/null
+++ emulators/kqemu-kmod-devel/files/patch-kqemu-freebsd.c
@@ -0,0 +1,89 @@
+Index: kqemu-freebsd.c
+@@ -222,9 +222,17 @@
+ int CDECL kqemu_schedule(void)
+ {
+     /* kqemu_log("kqemu_schedule\n"); */
++#if __FreeBSD_version < 700044
+     mtx_lock_spin(&sched_lock);
+     mi_switch(SW_VOL, NULL);
+     mtx_unlock_spin(&sched_lock);
++#else
++    /* -current no longer uses sched_lock */
++    struct thread *td = curthread;
++    thread_lock(td);
++    mi_switch(SW_VOL, NULL);
++    thread_unlock(td);
++#endif
+     return SIGPENDING(curthread);
+ }
+ #endif
+@@ -258,6 +266,10 @@
+ static struct clonedevs *kqemuclones;
+ static TAILQ_HEAD(,kqemu_instance) kqemuhead = TAILQ_HEAD_INITIALIZER(kqemuhead);
+ static eventhandler_tag clonetag;
++#ifndef D_NEEDMINOR
++/* see http://svn.freebsd.org/viewvc/base?view=revision&revision=179726 */
++#define D_NEEDMINOR 0
++#endif
+ #endif
+ 
+ static d_close_t kqemu_close;
+@@ -282,7 +294,7 @@
+ 	/* bmaj */	-1
+ #else
+ 	.d_version =	D_VERSION,
+-	.d_flags =	D_NEEDGIANT,
++	.d_flags =	D_NEEDGIANT | D_NEEDMINOR,
+ 	.d_open =	kqemu_open,
+ 	.d_ioctl =	kqemu_ioctl,
+ 	.d_close =	kqemu_close,
+@@ -334,8 +346,15 @@
+ #if __FreeBSD_version >= 500000
+     dev->si_drv1 = NULL;
+     TAILQ_REMOVE(&kqemuhead, ks, kqemu_ent);
++#if __FreeBSD_version >= 700051
++    destroy_dev_sched(dev);
++#else
++#if __FreeBSD_version >= 700024
++    dev_relthread(dev); 
++#endif
+     destroy_dev(dev);
+ #endif
++#endif
+     free(ks, M_KQEMU);
+     --kqemu_ref_count;
+ }
+@@ -412,6 +431,19 @@
+ 	ks->state = s;
+ 	break;
+     }
++    case KQEMU_SET_PHYS_MEM: {
++	struct kqemu_phys_mem kphys_mem;
++	if (!s) {
++	    ret = -EIO;
++	    break;
++	}
++	kphys_mem = *(struct kqemu_phys_mem *)addr;
++	ret = kqemu_set_phys_mem(s, &kphys_mem);
++	if (ret != 0) {
++	    ret = -EINVAL;
++	}
++	break;
++    }
+     case KQEMU_EXEC: {
+ 	struct kqemu_cpu_state *ctx;
+ 	if (s == NULL) {
+@@ -514,7 +546,13 @@
+ 	while ((ks = TAILQ_FIRST(&kqemuhead)) != NULL) {
+ 	    kqemu_destroy(ks);
+ 	}
++#if __FreeBSD_version >= 700051
++	drain_dev_clone_events();
++#endif
+ 	clone_cleanup(&kqemuclones);
++#if __FreeBSD_version >= 700051
++	destroy_dev_drain(&kqemu_cdevsw);
++#endif
+ #endif
+         kqemu_global_delete(kqemu_gs);
+         kqemu_gs = NULL;
--- /dev/null
+++ emulators/kqemu-kmod-devel/files/patch-Makefile.freebsd
@@ -0,0 +1,10 @@
+--- Makefile.freebsd.orig	Fri Jul 29 06:37:06 2005
++++ Makefile.freebsd	Tue Oct 25 21:08:43 2005
+@@ -5,6 +5,7 @@
+ .elif ${MACHINE_ARCH} == "amd64"
+ OBJS=	kqemu-mod-x86_64.o
+ .endif
++CC=	cc
+ WERROR=
+ 
+ .include <bsd.kmod.mk>


More information about the Midnightbsd-cvs mailing list