Skip to contentSkip to conversation

freebsd qemu port update - kqemu wrapper merge, need testing

Qemu-devel Juergen Lock 2 participants 4 messages Aug 4, 2005 – Aug 5, 2005 Kbuild

lore
Share & tools
lore
#0 lore raw

Okay, I finally got around looking at this a little longer and came up with the port update below. Specifically, I tried to merge the good parts of the old kqemu wrapper:

- device cloning support on 5.x (multiple vms can use kqemu, tested and seems to work)
- 4.x support (untested, I'm not sure if vm_map_user_pageable can be used as a 1-to-1 replacement for vm_map_{un,}wire on 4.x, can anyone here definitely say?)
- max_locked_pages calculation

Also:

- moved debug messages under debug.kqemu_debug sysctl (do `sysctl debug.kqemu_debug=1' to enable)
- fixed a small bug
- added the amd64 ata irq mapping fix

Also untested on amd64.

Removed files: files/BSDmakefile files/kmod_bsd.c New files: files/kqemu-freebsd-patch files/patch-libmath2
files/patch-vl.c patch-hw::ide.c

Index: Makefile
===================================================================
RCS file: /home/ncvs/ports/emulators/qemu/Makefile,v retrieving revision 1.27

Makefile +9 -10
diff -u -r1.27 Makefile
@@ -6,12 +6,12 @@
 #
 
 PORTNAME=	qemu
-PORTVERSION=	0.7.0s.20050717
+PORTVERSION=	0.7.1s.20050803
 CATEGORIES=	emulators
 MASTER_SITES=	http://www.qemu.org/ \
 		http://people.fruitsalad.org/nox/qemu/ \
 		http://dad-answers.com/qemu/
-DISTNAME=	${PORTNAME}-snapshot-2005-07-17_23
+DISTNAME=	${PORTNAME}-snapshot-2005-08-03_23
 EXTRACT_ONLY=	${DISTNAME}${EXTRACT_SUFX}
 
 MAINTAINER=	[email protected]
@@ -23,8 +23,9 @@
 .endif
 
 .if defined(WITH_KQEMU)
-DISTKQEMU=	kqemu-0.6.2-1.tar.gz
+DISTKQEMU=	kqemu-0.7.1-1.tar.gz
 DISTFILES=	${EXTRACT_ONLY} ${DISTKQEMU}
+EXTRA_PATCHES=	${FILESDIR}/kqemu-freebsd-patch
 .endif
 
 HAS_CONFIGURE=	yes
@@ -40,9 +41,11 @@
 ONLY_FOR_ARCHS=	amd64 i386
 .if defined(WITH_KQEMU)
 NO_PACKAGE=	Depends on kernel, and module not redistributable
+CONFIGURE_ARGS+=	--enable-kqemu
 PLIST_SUB=	WITH_KQEMU=""
 PLIST_SUB+=	KMODDIR=${KMODDIR}
 .else
+CONFIGURE_ARGS+=	--disable-kqemu
 PLIST_SUB=	WITH_KQEMU="@comment "
 .endif
 
@@ -52,7 +55,7 @@
 
 .if ${ARCH} == "amd64"
 ARCH=		x86_64
-.if ${OSVERSION} >= 502126
+.if ${OSVERSION} >= 502126 && ${OSVERSION} <= 600029
 BUILD_DEPENDS+=	gcc34:${PORTSDIR}/lang/gcc34
 GCCVERSION=	030402
 CC=		gcc34
@@ -63,16 +66,12 @@
 USE_GCC=	3.4
 .endif
 
-.if defined(WITH_KQEMU) && ${ARCH} != "i386"
-IGNORE=		kqemu only supported on i386
-.endif
-
 .if defined(WITH_KQEMU) && !exists(${SRC_BASE}/sys/Makefile)
 IGNORE=		kqemu requires kernel source to be installed
 .endif
 
 pre-everything::
-.if !defined(WITH_KQEMU) && ${ARCH} == "i386"
+.if !defined(WITH_KQEMU)
 	@${ECHO_MSG} "Notice: you can build qemu with the (alpha!) kqemu accelerator kernel module"
 	@${ECHO_MSG} "by defining WITH_KQEMU."
 .endif
@@ -85,7 +84,7 @@
 .if defined(WITH_KQEMU)
 post-extract:
 	@cd ${WRKSRC} && ${TAR} xfz ${_DISTDIR}/${DISTKQEMU}
-	@${CP} ${FILESDIR}/BSDmakefile ${FILESDIR}/kmod_bsd.c ${WRKSRC}/kqemu
+	@${LN} -s Makefile.freebsd ${WRKSRC}/kqemu/BSDmakefile
 .endif
 
 pre-patch:

Index: distinfo
===================================================================
RCS file: /home/ncvs/ports/emulators/qemu/distinfo,v retrieving revision 1.20

distinfo +4 -4
diff -u -r1.20 distinfo
@@ -1,4 +1,4 @@
-MD5 (qemu-snapshot-2005-07-17_23.tar.bz2) = 5d21295c1f328ea00de19a54715ee7c3
-SIZE (qemu-snapshot-2005-07-17_23.tar.bz2) = 1114748
-MD5 (kqemu-0.6.2-1.tar.gz) = c6bb3b40fb3d526d731eb0f1f9dee7ee
-SIZE (kqemu-0.6.2-1.tar.gz) = 21002
+MD5 (qemu-snapshot-2005-08-03_23.tar.bz2) = 69f7547ef97e02860677dcf926f57e35
+SIZE (qemu-snapshot-2005-08-03_23.tar.bz2) = 1120642
+MD5 (kqemu-0.7.1-1.tar.gz) = 012498dac620eb8c212bf5f622414dd0
+SIZE (kqemu-0.7.1-1.tar.gz) = 76427

Index: files/patch-fbsd
===================================================================
RCS file: /home/ncvs/ports/emulators/qemu/files/patch-fbsd,v retrieving revision 1.2

patch-fbsd +1 -1
diff -u -r1.2 patch-fbsd
@@ -13,7 +13,7 @@
  	$(MAKE) -C kqemu -f Makefile.winnt
  else
 -	$(MAKE) -C kqemu
-+	cd kqemu && $(BSD_MAKE)
++	( cd kqemu && $(BSD_MAKE) )
  endif
  endif
  

Index: files/kqemu-freebsd-patch
@@ -0,0 +1,489 @@
+Index: qemu/kqemu/Makefile.freebsd
+@@ -1,9 +1,13 @@
++# $Id: Makefile.freebsd,v 1.1 2005/04/17 17:21:31 bellard Exp $
+ KMOD= kqemu
+ SRCS= kqemu-freebsd.c
+ .if ${MACHINE_ARCH} == "i386"
+ OBJS= kqemu-mod-i386.o
+ .elif ${MACHINE_ARCH} == "amd64"
+ OBJS= kqemu-mod-x86_64.o
++.endif
++.if ${OSVERSION} >= 500000
++CC= cc
+ .endif
+ WERROR=
+
+Index: qemu/kqemu/kqemu-freebsd.c
+@@ -3,20 +3,33 @@
+ #include <sys/param.h>
+ #include <sys/systm.h>
+ #include <sys/conf.h>
++#include <sys/ctype.h>
++#include <sys/fcntl.h>
+ #include <sys/ioccom.h>
+ #include <sys/malloc.h>
+ #include <sys/module.h>
+ #include <sys/mutex.h>
+ #include <sys/proc.h>
++#include <sys/resourcevar.h>
++#if __FreeBSD_version > 500000
+ #include <sys/sched.h>
++#endif
+ #include <sys/signalvar.h>
+ #include <sys/kernel.h>
++#include <sys/sysctl.h>
++#include <sys/uio.h>
++#if __FreeBSD_version < 500000
++#include <sys/buf.h>
++#endif
++
+ #include <vm/vm.h>
+ #include <vm/vm_param.h>
+ #include <vm/vm_extern.h>
+ #include <vm/pmap.h>
+ #include <vm/vm_map.h>
+ #include <vm/vm_kern.h>
++#include <vm/vm_page.h>
++
+ #include <machine/vmparam.h>
+ #include <machine/stdarg.h>
+
+@@ -27,10 +40,14 @@
+ MALLOC_DECLARE(M_KQEMU);
+ MALLOC_DEFINE(M_KQEMU, "kqemu", "kqemu buffers");
+
++int kqemu_debug;
++SYSCTL_INT(_debug, OID_AUTO, kqemu_debug, CTLFLAG_RW, &kqemu_debug, 0,
++ "kqemu debug flag");
++
+ #define USER_BASE 0x1000
+
+ /* lock the page at virtual address 'user_addr' and return its

+-   physical page index. Return -1 if error */
++   physical page index. Return NULL if error */

+ struct kqemu_user_page *CDECL kqemu_lock_user_page(unsigned long *ppage_index,
+ unsigned long user_addr)
+ {
+@@ -39,14 +56,18 @@

+     vm_paddr_t pa = 0;
+     int ret;
+     pmap_t pmap;

++#if __FreeBSD_version > 500000
+ ret = vm_map_wire(&vm->vm_map, va, va+PAGE_SIZE, VM_MAP_WIRE_USER);
++#else
++ ret = vm_map_user_pageable(&vm->vm_map, va, va+PAGE_SIZE, FALSE);
++#endif
+ if (ret != KERN_SUCCESS) {
+- printf("kqemu_lock_user_page(%08lx) failed, ret=%d\n", user_addr, ret);
++ kqemu_log("kqemu_lock_user_page(%08lx) failed, ret=%d\n", user_addr, ret);
+ return NULL;

+     }
+     pmap = vm_map_pmap(&vm->vm_map);
+     pa = pmap_extract(pmap, va);
+-    // printf("kqemu_lock_user_page(%08lx) va=%08x pa=%08x\n", user_addr, va, pa);
++    // kqemu_log("kqemu_lock_user_page(%08lx) va=%08x pa=%08x\n", user_addr, va, pa);
+     *ppage_index = pa >> PAGE_SHIFT;
+     return (struct kqemu_user_page *)va;
+ }
+@@ -56,12 +77,16 @@
+     struct vmspace *vm = curproc->p_vmspace;
+     vm_offset_t va;
+     int ret;
+-    // printf("kqemu_unlock_user_page(%08lx)\n", page_index);
++    // kqemu_log("kqemu_unlock_user_page(%08lx)\n", page_index);
+     va = (vm_offset_t)page;

++#if __FreeBSD_version > 500000
+ ret = vm_map_unwire(&vm->vm_map, va, va+PAGE_SIZE, VM_MAP_WIRE_USER);
++#else
++ ret = vm_map_user_pageable(&vm->vm_map, va, va+PAGE_SIZE, TRUE);
++#endif
+ #if 0
+ if (ret != KERN_SUCCESS) {
+- printf("kqemu_unlock_user_page(%08lx) failed, ret=%d\n", page_index, ret);
++ kqemu_log("kqemu_unlock_user_page(%08lx) failed, ret=%d\n", page_index, ret);
+ }
+ #endif
+ }
+@@ -78,19 +103,20 @@
+
+ va = kmem_alloc(kernel_map, PAGE_SIZE);
+ if (va == 0) {

+-	printf("kqemu_alloc_zeroed_page: NULL\n");
+-	return -1;
++	kqemu_log("kqemu_alloc_zeroed_page: NULL\n");
++	return NULL;
+     }
+     pmap = vm_map_pmap(kernel_map);
+     pa = pmap_extract(pmap, va);
+-    // printf("kqemu_alloc_zeroed_page: %08x\n", pa);
++    // kqemu_log("kqemu_alloc_zeroed_page: %08x\n", pa);
+     *ppage_index = pa >> PAGE_SHIFT;
+     return (struct kqemu_page *)va;

+ }
+
+ void CDECL kqemu_free_page(struct kqemu_page *page)
+ {

+-    //    printf("kqemu_free_page(%08lx)\n", page_index);
++    if (kqemu_debug > 0)
++    	kqemu_log("kqemu_free_page(%p)\n", page);
+     /* XXX: do it */
+ }
+ 
+@@ -109,22 +135,25 @@
+     vm_offset_t va = USER_BASE;
+     int rv;
+     if (size % PAGE_SIZE != 0) {

+- printf("kqemu_vmalloc(%d) not a multiple of page size\n", size);
++ kqemu_log("kqemu_vmalloc(%d) not a multiple of page size\n", size);
+ return NULL;
+ }
+ rv = vm_map_find(&vm->vm_map, NULL, 0, &va, size, 1,
+ VM_PROT_ALL, VM_PROT_ALL, 0);
+ if (rv != KERN_SUCCESS) {
+- printf("kqemu_vmalloc(%d) failed rv=%d\n", size, rv);
++ kqemu_log("kqemu_vmalloc(%d) failed rv=%d\n", size, rv);
+ return NULL;

+     }
+-    printf("kqemu_vmalloc(%d): %08x\n", size, va);
++    if (kqemu_debug > 0)

++ kqemu_log("kqemu_vmalloc(%d): %08x\n", size, va);
+ return (void *)va;
+ }
+
+ void CDECL kqemu_vfree(void *ptr)
+ {

+-    printf("kqemu_vfree(%p)\n", ptr);
++    if (kqemu_debug > 0)

++ kqemu_log("kqemu_vfree(%p)\n", ptr);
++ /* XXX: do it */
+ }
+
+ /* return the physical page index for a given virtual page */ +@@ -137,10 +166,11 @@

+     pmap = vm_map_pmap(&vm->vm_map);
+     pa = pmap_extract(pmap, (vm_offset_t)vaddr);
+     if (pa == 0) {
+-	printf("kqemu_vmalloc_to_phys(%p)->error\n", vaddr);
++	kqemu_log("kqemu_vmalloc_to_phys(%p)->error\n", vaddr);
+ 	return -1;
+     }
+-    printf("kqemu_vmalloc_to_phys(%p)->%08x\n", vaddr, pa);
++    if (kqemu_debug > 0)

++ kqemu_log("kqemu_vmalloc_to_phys(%p)->%08x\n", vaddr, pa);
+ return pa >> PAGE_SHIFT;
+ }
+
+@@ -156,16 +186,48 @@
+ {
+ }
+
++#if __FreeBSD_version < 500000
++static int
++curpriority_cmp(struct proc *p)
++{
++ int c_class, p_class;
++

++    c_class = RTP_PRIO_BASE(curproc->p_rtprio.type);
++    p_class = RTP_PRIO_BASE(p->p_rtprio.type);
++    if (p_class != c_class)

++ return (p_class - c_class);
++ if (p_class == RTP_PRIO_NORMAL)
++ return (((int)p->p_priority - (int)curpriority) / PPQ);
++ return ((int)p->p_rtprio.prio - (int)curproc->p_rtprio.prio);
++}
++
++/* return TRUE if a signal is pending (i.e. the guest must stop
++ execution) */
++int CDECL kqemu_schedule(void)
++{
++ struct proc *p = curproc;
++ if (curpriority_cmp(p) > 0) {
++ int s = splhigh();
++ p->p_priority = MAXPRI;
++ setrunqueue(p);
++ p->p_stats->p_ru.ru_nvcsw++;
++ mi_switch();
++ splx(s);
++ }
++ return issignal(curproc) != 0;
++}
++#else
+ /* return TRUE if a signal is pending (i.e. the guest must stop
+ execution) */
+ int CDECL kqemu_schedule(void)
+ {

+-    // printf("kqemu_schedule\n");
++    // kqemu_log("kqemu_schedule\n");
+     mtx_lock_spin(&sched_lock);
+     mi_switch(SW_VOL, NULL);
+     mtx_unlock_spin(&sched_lock);
+     return SIGPENDING(curthread);

+ }
++#endif
+
+ static char log_buf[4096];
+
+@@ -178,47 +240,149 @@
+ va_end(ap);
+ }
+
++#define KQEMU_MAX_INSTANCES 4
++
+ struct kqemu_instance {
++#if __FreeBSD_version > 500000
++ TAILQ_ENTRY(kqemu_instance) kqemu_ent;
++ struct cdev *kqemu_dev;
++#endif
+ // struct semaphore sem;
+ struct kqemu_state *state;
+ };
+
++static int kqemu_ref_count = 0;
++static int max_locked_pages;
++
++#if __FreeBSD_version < 500000
++static dev_t kqemu_dev;
++#else
++static struct clonedevs *kqemuclones;
++static TAILQ_HEAD(,kqemu_instance) kqemuhead = TAILQ_HEAD_INITIALIZER(kqemuhead); ++static eventhandler_tag clonetag;
++#endif
++
+ static d_close_t kqemu_close;
+ static d_open_t kqemu_open;
+ static d_ioctl_t kqemu_ioctl;
+
+ static struct cdevsw kqemu_cdevsw = {
++#if __FreeBSD_version < 500000
++ /* open */ kqemu_open,
++ /* close */ kqemu_close,
++ /* read */ noread,
++ /* write */ nowrite,
++ /* ioctl */ kqemu_ioctl,
++ /* poll */ nopoll,
++ /* mmap */ nommap,
++ /* strategy */ nostrategy,
++ /* name */ "kqemu",
++ /* maj */ KQEMU_MAJOR,
++ /* dump */ nodump,
++ /* psize */ nopsize,
++ /* flags */ 0,
++ /* bmaj */ -1
++#else
+ .d_version = D_VERSION,
+ .d_flags = D_NEEDGIANT,
+ .d_open = kqemu_open,
+ .d_ioctl = kqemu_ioctl,
+ .d_close = kqemu_close,
+ .d_name = "kqemu"
++#endif
+ };
+

+-/* For use with make_dev(9)/destroy_dev(9). */
+-static struct cdev *kqemu_dev;

++#if __FreeBSD_version > 500000
++static void
++kqemu_clone(void *arg, char *name, int namelen, struct cdev **dev) ++{
++ int unit, r;
++ if (*dev != NULL)
++ return;
++
++ if (strcmp(name, "kqemu") == 0)
++ unit = -1;
++ else if (dev_stdclone(name, NULL, "kqemu", &unit) != 1)
++ return; /* Bad name */
++ if (unit != -1 && unit > KQEMU_MAX_INSTANCES)
++ return;
++
++ r = clone_create(&kqemuclones, &kqemu_cdevsw, &unit, dev, 0);
++ if (r) {
++ *dev = make_dev(&kqemu_cdevsw, unit2minor(unit),
++ UID_ROOT, GID_WHEEL, 0660, "kqemu%d", unit);
++ if (*dev != NULL) {
++ dev_ref(*dev);
++ (*dev)->si_flags |= SI_CHEAPCLONE;
++ }
++ }
++}
++#endif
++
++static void kqemu_destroy(struct kqemu_instance *ks) ++{
++ struct cdev *dev = ks->kqemu_dev;
++
++ if (ks->state) {
++ kqemu_delete(ks->state);
++ ks->state = NULL;
++ }
++
++ free(ks, M_KQEMU);
++ dev->si_drv1 = NULL;
++#if __FreeBSD_version > 500000
++ TAILQ_REMOVE(&kqemuhead, ks, kqemu_ent);
++ destroy_dev(dev);
++#endif
++ --kqemu_ref_count;
++}
+
+ /* ARGSUSED */
+ static int
++#if __FreeBSD_version < 500000
++kqemu_open(dev_t dev, int flags, int fmt __unused, struct proc *p) ++{
++#else
+ kqemu_open(struct cdev *dev, int flags, int fmt __unused,
+ struct thread *td)
+ {
++ struct proc *p = td->td_proc;
++#endif
+ struct kqemu_instance *ks;
++
++ if (dev->si_drv1 || kqemu_ref_count >= KQEMU_MAX_INSTANCES)
++ return(EBUSY);
++
++ if ((flags & (FREAD|FWRITE)) == FREAD)
++ return(EPERM);
++
+ ks = malloc(sizeof(struct kqemu_instance), M_KQEMU, M_WAITOK);
+ if (ks == NULL) {
+- printf("malloc failed\n");
++ kqemu_log("malloc failed\n");
+ return ENOMEM;

+     }
+-    ks->state = NULL;
++    memset(ks, 0, sizeof *ks);

++#if __FreeBSD_version > 500000
++ ks->kqemu_dev = dev;
++ TAILQ_INSERT_TAIL(&kqemuhead, ks, kqemu_ent);
++#endif
++ kqemu_ref_count++;
++
+ dev->si_drv1 = ks;
++ if (kqemu_debug > 0)
++ kqemu_log("opened by pid=%d\n", p->p_pid);
+ return 0;
+ }
+
+ /* ARGSUSED */
+ static int
++#if __FreeBSD_version < 500000 ++kqemu_ioctl(dev_t dev, u_long cmd, caddr_t addr,
++ int flags __unused, struct proc *p)
++#else
+ kqemu_ioctl(struct cdev *dev, u_long cmd, caddr_t addr,
+ int flags __unused, struct thread *td)
++#endif
+ {
+ int error = 0;
+ int ret;
+@@ -233,8 +397,9 @@
+ break;
+ }
+ d1 = *(struct kqemu_init *)addr;

+-	printf("ram_base=%p ram_size=%ld\n", d1.ram_base, d1.ram_size);
+-	s = kqemu_init(d, 16000);

++ if (kqemu_debug > 0)
++ kqemu_log("ram_base=%p ram_size=%ld\n", d1.ram_base, d1.ram_size);
++ s = kqemu_init(d, max_locked_pages);
+ if (s == NULL) {
+ error = ENOMEM;
+ break;
+@@ -250,9 +415,16 @@
+ }
+ ctx = kqemu_get_cpu_state(s);
+ *ctx = *(struct kqemu_cpu_state *)addr;
++#if __FreeBSD_version > 500000
+ DROP_GIANT();
++#endif
+ ret = kqemu_exec(s);
++#if __FreeBSD_version > 500000
+ PICKUP_GIANT();
++ td->td_retval[0] = ret;
++#else
++ p->p_retval[0] = ret;
++#endif
+ *(struct kqemu_cpu_state *)addr = *ctx;
+ break;
+ }
+@@ -267,10 +439,22 @@
+
+ /* ARGSUSED */
+ static int
++#if __FreeBSD_version < 500000
++kqemu_close(dev_t dev, int flags, int fmt __unused, struct proc *p) ++{
++#else
+ kqemu_close(struct cdev *dev __unused, int flags, int fmt __unused,
+ struct thread *td)
+ {

+-	return 0;
++    struct proc     *p = td->td_proc;

++#endif
++ struct kqemu_instance *ks = (struct kqemu_instance *) dev->si_drv1;
++
++ kqemu_destroy(ks);
++
++ if (kqemu_debug > 0)
++ kqemu_log("closed by pid=%d\n", p->p_pid);
++ return 0;
+ }
+
+ /* ARGSUSED */
+@@ -278,15 +462,55 @@
+ kqemu_modevent(module_t mod __unused, int type, void *data __unused)
+ {
+ int error = 0;
++#if __FreeBSD_version < 500000
++ int rc;
++#else
++ struct kqemu_instance *ks;
++#endif
+
+ switch (type) {
+ case MOD_LOAD:
+ printf("kqemu version 0x%08x\n", KQEMU_VERSION);
++ max_locked_pages = physmem / (2 * KQEMU_MAX_INSTANCES);
++ if (max_locked_pages > 32768)
++ max_locked_pages = 32768;
++#if __FreeBSD_version < 500000
++ if ((rc = cdevsw_add(&kqemu_cdevsw))) {
++ kqemu_log("error registering cdevsw, rc=%d\n", rc);
++ error = ENOENT;
++ break;
++ }
+ kqemu_dev = make_dev(&kqemu_cdevsw, 0,

+-			     UID_ROOT, GID_WHEEL, 0666, "kqemu");
++			     UID_ROOT, GID_WHEEL, 0660, "kqemu");

++#else
++ clone_setup(&kqemuclones);
++ clonetag = EVENTHANDLER_REGISTER(dev_clone, kqemu_clone, 0, 1000);
++ if (!clonetag) {
++ error = ENOMEM;
++ break;
++ }
++#endif
++ kqemu_log("KQEMU installed, max_instances=%d max_locked_mem=%dkB.\n",
++ KQEMU_MAX_INSTANCES, max_locked_pages * 4);
++
++ kqemu_ref_count = 0;
+ break;
+ case MOD_UNLOAD:
++ if (kqemu_ref_count > 0) {
++ error = EBUSY;
++ break;
++ }
++#if __FreeBSD_version < 500000
+ destroy_dev(kqemu_dev);
++ if ((rc = cdevsw_remove(&kqemu_cdevsw)))
++ kqemu_log("error unregistering, rc=%d\n", rc);
++#else
++ EVENTHANDLER_DEREGISTER(dev_clone, clonetag);
++ while ((ks = TAILQ_FIRST(&kqemuhead)) != NULL) {
++ kqemu_destroy(ks);
++ }
++ clone_cleanup(&kqemuclones);
++#endif
+ break;
+ case MOD_SHUTDOWN:
+ break;
Index: files/patch-libmath2
@@ -0,0 +1,67 @@
+Index: qemu/bsd/Makefile
+@@ -16,7 +16,8 @@
+ ${MACHINE_ARCH}/s_rintl.c \
+ ${MACHINE_ARCH}/s_round.c \
+ ${MACHINE_ARCH}/s_sinl.S \
+- ${MACHINE_ARCH}/s_tanl.S
++ ${MACHINE_ARCH}/s_tanl.S \
++ ${MACHINE_ARCH}/s_ldexpl.c
+
+ OBJS= ${SRCS:R:S/$/.o/}
+
+Index: qemu/bsd/i386/s_ldexpl.c
+@@ -0,0 +1,21 @@
++#include <math.h>
++#include <errno.h>
++#include <sysdep.h>
++
++long double __ldexpl(long double x, int expn)
++{
++ long double res;
++ if (!isfinite (x) || x == 0.0L)
++ return x;
++
++ __asm__ ("fscale"
++ : "=t" (res)
++ : "0" (x), "u" ((long double) expn));
++
++ if (!isfinite (res) || res == 0.0L)
++ errno = ERANGE;
++
++ return res;
++}
++
++weak_alias(__ldexpl,ldexpl)
+Index: qemu/bsd/amd64/s_ldexpl.c
+@@ -0,0 +1,21 @@
++#include <math.h>
++#include <errno.h>
++#include <sysdep.h>
++
++long double __ldexpl(long double x, int expn)
++{
++ long double res;
++ if (!isfinite (x) || x == 0.0L)
++ return x;
++
++ __asm__ ("fscale"
++ : "=t" (res)
++ : "0" (x), "u" ((long double) expn));
++
++ if (!isfinite (res) || res == 0.0L)
++ errno = ERANGE;
++
++ return res;
++}
++
++weak_alias(__ldexpl,ldexpl)
+Index: qemu/target-i386/helper.c
+@@ -2886,6 +2886,8 @@
+ ST0 = floatx_round_to_int(ST0, &env->fp_status);
+ }
+
++long double ldexpl(long double, int);
++
+ void helper_fscale(void)
+ {
+ ST0 = ldexp (ST0, (int)(ST1));
Index: files/patch-vl.c
@@ -0,0 +1,21 @@
+Index: qemu/vl.c
+@@ -40,6 +40,10 @@
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <dirent.h>
++#ifdef __FreeBSD__
++#include <sys/types.h>
++#include <libutil.h>
++#endif
+ #ifdef _BSD
+ #include <sys/stat.h>
+ #ifndef __APPLE__
+@@ -1280,7 +1284,7 @@
+ return chr;
+ }
+

+-#if defined(__linux__)
++#if defined(__linux__) || defined(__FreeBSD__)

+ CharDriverState *qemu_chr_open_pty(void)
+ {
+ char slave_name[1024];
Index: files/patch-hw::ide.c
@@ -0,0 +1,9 @@
+Index: qemu/hw/ide.c
+@@ -2330,6 +2330,7 @@

+     pci_conf[0x01] = 0x80;
+     pci_conf[0x02] = 0x10;
+     pci_conf[0x03] = 0x70;
++    pci_conf[0x09] = 0x80; // legacy ATA mode
+     pci_conf[0x0a] = 0x01; // class_sub = PCI_IDE
+     pci_conf[0x0b] = 0x01; // class_base = PCI_mass_storage
+     pci_conf[0x0e] = 0x00; // header_type
#1 lore raw

Hi
Thanks for your work, but... (see below)

Quoted 11 lines · Juergen Lock

Okay, I finally got around looking at this a little longer and came up with the port update below. Specifically, I tried to merge the good parts of the old kqemu wrapper:

- device cloning support on 5.x (multiple vms can use kqemu, tested and seems to work)
- 4.x support (untested, I'm not sure if vm_map_user_pageable can be used as a 1-to-1 replacement for vm_map_{un,}wire on 4.x, can anyone here definitely say?)
- max_locked_pages calculation

Quoted 9 lines

Also:

- moved debug messages under debug.kqemu_debug sysctl (do `sysctl debug.kqemu_debug=1' to enable)
- fixed a small bug
- added the amd64 ata irq mapping fix

Also untested on amd64.

Here it goes:

~> uname -a
FreeBSD kushnir1.kiev.ua 7.0-CURRENT FreeBSD 7.0-CURRENT #10: Thu Aug 4 04:17:5
4 EEST 2005 [email protected]:/usr/obj/usr/src/sys/KUSHNIR amd64

This is Athlon64 3000+ -based box, Asus A8N SLI MB.
qemu itself builds and works like a charm ('sept the sound doesn't work), but as far as kqemu is concerned - it loads perfectly all right but no /dev/kqemu... is created. No warnings, no panics... and no kqemu's speed boost (obviously).

Is there anything I could do?

Regards,
Vladimir

#2 lore raw
Quoted 33 lines · Vladimir Kushnir

Hi
Thanks for your work, but... (see below)

Quoted 11 lines · Juergen Lock

Okay, I finally got around looking at this a little longer and came up with the port update below. Specifically, I tried to merge the good parts of the old kqemu wrapper:

- device cloning support on 5.x (multiple vms can use kqemu, tested and seems to work)
- 4.x support (untested, I'm not sure if vm_map_user_pageable can be used as a 1-to-1 replacement for vm_map_{un,}wire on 4.x, can anyone here definitely say?)
- max_locked_pages calculation

Quoted 9 lines

Also:

- moved debug messages under debug.kqemu_debug sysctl (do `sysctl debug.kqemu_debug=1' to enable)
- fixed a small bug
- added the amd64 ata irq mapping fix

Also untested on amd64.

Here it goes:

~> uname -a
FreeBSD kushnir1.kiev.ua 7.0-CURRENT FreeBSD 7.0-CURRENT #10: Thu Aug 4 04:17:5
4 EEST 2005 [email protected]:/usr/obj/usr/src/sys/KUSHNIR amd64

Quoted 4 lines

This is Athlon64 3000+ -based box, Asus A8N SLI MB.
qemu itself builds and works like a charm ('sept the sound doesn't work), but as far as kqemu is concerned - it loads perfectly all right but no /dev/kqemu... is created.

That's alright, it will appear when open()ed by qemu. (thats device cloning for ya...)

Quoted 1 line

No warnings, no panics...

qemu would print a warning when it cannot open kqemu.

Quoted 3 lines

and no kqemu's speed
boost (obviously).

Hmm. You do use qemu-system-x86_64, since you're on amd64?

Juergen

#3 lore raw
Quoted 5 lines · Juergen Lock
Quoted 1 line

Hmm. You do use qemu-system-x86_64, since you're on amd64?

Juergen

Silly me. Now I did. And it falls with:
EAX=00000000 EBX=00000001 ECX=00000002 EDX=00000003 ESI=00000004 EDI=00000005 EBP=00000000 ESP=0015fd1c
EIP=77fb4d83 EFL=00000202 [-------] CPL=3 II=0 A20=1
ES =0023 00000000 ffffffff 00cff300
CS =001b 00000000 ffffffff 00cffa00
SS =0023 00000000 ffffffff 00cff300
DS =0023 00000000 ffffffff 00cff300
FS =0023 7ffde000 00000fff 7f40f3fd
GS =0023 00000000 00000000 00000000 LDT=0000 00000000 00000000 00008000
TR =0028 80042000 000020ab 80008904
GDT= 8003f000 000003ff
IDT= 8003f400 000007ff
CR0=e001003b CR2=805ba6fd CR3=04631000 CR4=000006d8 Unsupported return value: 0xffffffff

And from dmesg output:

kqemu version 0x00010100
kqemu: KQEMU installed, max_instances=4 max_locked_mem=64536kB.
kqemu: aborting: Unexpected exception 0x0d in monitor space CS:EIP=f180:ffff900000001729

This was with (already made) winxp installation. Almost the same on an attempt to install it.

Regards,
Vladimir