summaryrefslogtreecommitdiff
path: root/sysutils/xentools3-hvm
diff options
context:
space:
mode:
authorbouyer <bouyer@pkgsrc.org>2007-06-14 19:42:12 +0000
committerbouyer <bouyer@pkgsrc.org>2007-06-14 19:42:12 +0000
commite3c02d59e378e872663389aa65e4becdb0955b6c (patch)
tree21a556bbb7395917b34504b4a25c1d883cd65004 /sysutils/xentools3-hvm
parentf9a2cde35228fa7adefb366eae259ccf6f456438 (diff)
downloadpkgsrc-e3c02d59e378e872663389aa65e4becdb0955b6c.tar.gz
Rename xentools30-hvm to xentools3-hvm to acknowledge that Xen dropped one
digit in version numbers, and upgrade to 3.1.0. Changes since 3.0.4: * XenAPI 1.0 support o XML configuration files for virtual machines; o VM life-cycle management operations; and o Secure on- or off-box XML-RPC with bindings for many languages * Basic save/restore/migrate support for HVM (e.g. Windows) VMs; * Dynamic memory control for HVM guests; * 32-on-64 PV guest support (run PAE PV VMs on a 64-bit Xen!); and * Blktap copy-on-write disk support. It also fixes some HVM bugs. Note that this package contains a backport of the pcnet emulation from xen-unstable, to make it useable. It gives better performances than the default realtek emulation.
Diffstat (limited to 'sysutils/xentools3-hvm')
-rw-r--r--sysutils/xentools3-hvm/DESCR4
-rw-r--r--sysutils/xentools3-hvm/Makefile95
-rw-r--r--sysutils/xentools3-hvm/PLIST43
-rw-r--r--sysutils/xentools3-hvm/distinfo25
-rw-r--r--sysutils/xentools3-hvm/files/NetBSD.mk2
-rw-r--r--sysutils/xentools3-hvm/files/hvm-nbsd68
-rwxr-xr-xsysutils/xentools3-hvm/files/qemu-ifup-nbsd3
-rw-r--r--sysutils/xentools3-hvm/files/xenio.h105
-rw-r--r--sysutils/xentools3-hvm/files/xenio3.h89
-rw-r--r--sysutils/xentools3-hvm/patches/patch-aa61
-rw-r--r--sysutils/xentools3-hvm/patches/patch-an24
-rw-r--r--sysutils/xentools3-hvm/patches/patch-ao23
-rw-r--r--sysutils/xentools3-hvm/patches/patch-ap12
-rw-r--r--sysutils/xentools3-hvm/patches/patch-ar165
-rw-r--r--sysutils/xentools3-hvm/patches/patch-as26
-rw-r--r--sysutils/xentools3-hvm/patches/patch-at13
-rw-r--r--sysutils/xentools3-hvm/patches/patch-au16
-rw-r--r--sysutils/xentools3-hvm/patches/patch-av12
-rw-r--r--sysutils/xentools3-hvm/patches/patch-aw32
-rw-r--r--sysutils/xentools3-hvm/patches/patch-ax14
-rw-r--r--sysutils/xentools3-hvm/patches/patch-ay25
-rw-r--r--sysutils/xentools3-hvm/patches/patch-ba15
-rw-r--r--sysutils/xentools3-hvm/patches/patch-bb19
-rw-r--r--sysutils/xentools3-hvm/patches/patch-bv14
-rw-r--r--sysutils/xentools3-hvm/patches/patch-ci16
-rw-r--r--sysutils/xentools3-hvm/patches/patch-ck9
-rw-r--r--sysutils/xentools3-hvm/patches/patch-cl12
-rw-r--r--sysutils/xentools3-hvm/patches/patch-cp14
-rw-r--r--sysutils/xentools3-hvm/patches/patch-cq757
29 files changed, 1713 insertions, 0 deletions
diff --git a/sysutils/xentools3-hvm/DESCR b/sysutils/xentools3-hvm/DESCR
new file mode 100644
index 00000000000..8b7d41362d4
--- /dev/null
+++ b/sysutils/xentools3-hvm/DESCR
@@ -0,0 +1,4 @@
+The Xen virtual machine monitor allows running several virtual machines
+on a single physical machine. The xentools30-vmx package contains
+additionnal tools to xentools30 to run unmodified guests using the
+Intel VT or AMD VMX extentions.
diff --git a/sysutils/xentools3-hvm/Makefile b/sysutils/xentools3-hvm/Makefile
new file mode 100644
index 00000000000..0fdecb6adc0
--- /dev/null
+++ b/sysutils/xentools3-hvm/Makefile
@@ -0,0 +1,95 @@
+# $NetBSD: Makefile,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+#
+
+VERSION= 3.1.0
+DISTNAME= xen-${VERSION}-src
+PKGNAME= xentools3-hvm-${VERSION}
+CATEGORIES= sysutils
+MASTER_SITES= http://www.cl.cam.ac.uk/research/srg/netos/xen/downloads/ \
+ http://bits.xensource.com/oss-xen/release/${VERSION}/src.tgz/
+EXTRACT_SUFX= .tgz
+
+MAINTAINER= bouyer@NetBSD.org
+HOMEPAGE= http://www.cl.cam.ac.uk/research/srg/netos/xen/
+COMMENT= Tools for Virtual Machine Extensions support in Xen
+
+BUILD_DEPENDS+= dev86-[0-9]*:../../devel/dev86 # needed to build firmware
+
+PKG_SYSCONFSUBDIR= xen
+
+ONLY_FOR_PLATFORM= Linux-2.[46]*-i386 NetBSD-*-i386
+
+CONFLICTS= xentools30-*
+
+WRKSRC= ${WRKDIR}/xen-${VERSION}-src/tools
+CHECK_PORTABILITY_SKIP+= examples/* xm-test/ramdisk/make-release.sh
+
+EGDIR= ${PREFIX}/share/examples/xen
+MESSAGE_SUBST= EGDIR=${EGDIR}
+
+USE_TOOLS+= perl
+USE_TOOLS+= gmake
+MAKE_ENV+= EGDIR=${EGDIR:Q}
+MAKE_ENV+= MV=${MV:Q} PYTHON=${PYTHONBIN:Q} SED=${SED:Q}
+MAKE_ENV+= XEN_TARGET_ARCH="x86_32"
+PYTHON_VERSIONS_ACCEPTED= 24 23
+
+SUBST_CLASSES+= paths
+SUBST_STAGE.paths= pre-configure
+SUBST_FILES.paths= ioemu/vl.c
+SUBST_SED.paths= -e "s|/usr/sbin|${PREFIX}/sbin|g"
+SUBST_MESSAGE.paths= Fixing hardcoded paths.
+
+SUBST_CLASSES+= py
+SUBST_STAGE.py= pre-configure
+SUBST_FILES.py= ../xen/include/public/foreign/Makefile
+SUBST_SED.py= -e "s,python,${PYTHONBIN},g"
+
+SUBST_CLASSES+= conf
+SUBST_STAGE.conf= pre-configure
+SUBST_FILES.conf= ioemu/configure
+SUBST_FILES.conf+= ioemu/vl.c
+SUBST_SED.conf= -e "s,@XENDCONFDIR@,${PKG_SYSCONFDIR},g"
+
+SUBST_CLASSES+= prefix
+SUBST_STAGE.prefix= pre-configure
+SUBST_FILES.prefix= python/xen/util/auxbin.py
+SUBST_FILES.prefix= ioemu/vl.c
+SUBST_SED.prefix= -e "s,@PREFIX@,${PREFIX},g"
+
+.include "../../mk/bsd.prefs.mk"
+
+.if ${OPSYS} == "NetBSD"
+PROCPATH= /kern
+.else
+PROCPATH= /proc
+.endif
+
+pre-build:
+ ${MKDIR} ${WRKSRC}/libxc/xen/NetBSD
+ ${TEST} -f ${WRKSRC}/libxc/xen/NetBSD/xenio.h || ${CP} ${FILESDIR}/xenio.h ${WRKSRC}/libxc/xen/NetBSD
+ ${TEST} -f ${WRKSRC}/libxc/xen/NetBSD/xenio3.h || ${CP} ${FILESDIR}/xenio3.h ${WRKSRC}/libxc/xen/NetBSD
+ ${CP} ${FILESDIR}/NetBSD.mk ${WRKSRC}/../config/
+
+.if ${OPSYS} == "NetBSD"
+post-build:
+ cd ${FILESDIR}; for src in *-nbsd; do \
+ dst="$${src%-nbsd}"; \
+ ${SED} -e "s|@PKG_SYSCONFDIR@|${PKG_SYSCONFDIR}|g" \
+ -e "s|@PREFIX@|${PREFIX}|g" \
+ $$src > ${WRKSRC}/examples/$$dst; \
+ done
+.endif
+
+post-install:
+ for f in hvm; do \
+ ${INSTALL_DATA} ${WRKSRC}/examples/$$f ${EGDIR}/$$f; \
+ done
+
+.include "../../lang/python/application.mk"
+.include "../../lang/python/extension.mk"
+.include "../../devel/ncurses/buildlink3.mk"
+.include "../../devel/SDL/buildlink3.mk"
+.include "../../sysutils/xentools3/buildlink3.mk"
+
+.include "../../mk/bsd.pkg.mk"
diff --git a/sysutils/xentools3-hvm/PLIST b/sysutils/xentools3-hvm/PLIST
new file mode 100644
index 00000000000..011e5e13e61
--- /dev/null
+++ b/sysutils/xentools3-hvm/PLIST
@@ -0,0 +1,43 @@
+@comment $NetBSD: PLIST,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+lib/xen/boot/hvmloader
+libexec/qemu-dm
+share/examples/xen/hvm
+share/xen/qemu/keymaps/ar
+share/xen/qemu/keymaps/common
+share/xen/qemu/keymaps/da
+share/xen/qemu/keymaps/de
+share/xen/qemu/keymaps/de-ch
+share/xen/qemu/keymaps/en-gb
+share/xen/qemu/keymaps/en-us
+share/xen/qemu/keymaps/es
+share/xen/qemu/keymaps/et
+share/xen/qemu/keymaps/fi
+share/xen/qemu/keymaps/fo
+share/xen/qemu/keymaps/fr
+share/xen/qemu/keymaps/fr-be
+share/xen/qemu/keymaps/fr-ca
+share/xen/qemu/keymaps/fr-ch
+share/xen/qemu/keymaps/hr
+share/xen/qemu/keymaps/hu
+share/xen/qemu/keymaps/is
+share/xen/qemu/keymaps/it
+share/xen/qemu/keymaps/ja
+share/xen/qemu/keymaps/lt
+share/xen/qemu/keymaps/lv
+share/xen/qemu/keymaps/mk
+share/xen/qemu/keymaps/modifiers
+share/xen/qemu/keymaps/nl
+share/xen/qemu/keymaps/nl-be
+share/xen/qemu/keymaps/no
+share/xen/qemu/keymaps/pl
+share/xen/qemu/keymaps/pt
+share/xen/qemu/keymaps/pt-br
+share/xen/qemu/keymaps/ru
+share/xen/qemu/keymaps/sl
+share/xen/qemu/keymaps/sv
+share/xen/qemu/keymaps/th
+share/xen/qemu/keymaps/tr
+@dirrm lib/xen/boot
+@dirrm lib/xen
+@dirrm share/xen/qemu/keymaps
+@dirrm share/xen/qemu
diff --git a/sysutils/xentools3-hvm/distinfo b/sysutils/xentools3-hvm/distinfo
new file mode 100644
index 00000000000..6ace99004ae
--- /dev/null
+++ b/sysutils/xentools3-hvm/distinfo
@@ -0,0 +1,25 @@
+$NetBSD: distinfo,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+SHA1 (xen-3.1.0-src.tgz) = fa4b54c36626f2cce9b15dc99cafda0b42c54777
+RMD160 (xen-3.1.0-src.tgz) = 2fd65a3b81e522d0ed2d62fd11e5977167f1ceb3
+Size (xen-3.1.0-src.tgz) = 6831094 bytes
+SHA1 (patch-aa) = 663c798a472501d4c38add5049faded5b7e807aa
+SHA1 (patch-an) = cb6e3a7eac490851f2eacf557f05daf0d6966cce
+SHA1 (patch-ao) = d1250258d09cf9b330a4e9d52e85332a0eef7998
+SHA1 (patch-ap) = 33f2bdbef6df3f2105d4502b8066abb6c952fc6c
+SHA1 (patch-ar) = c8748761267dd82c75deab79d13b71d56bcf2223
+SHA1 (patch-as) = 8850108d0c8f101642f4855184253824f9c214b5
+SHA1 (patch-at) = 2311289176c83fcd3ff18b90bab9c2e5e05a52f1
+SHA1 (patch-au) = beb2eaa8bf832e179e69b1758cfe0fafafdc496b
+SHA1 (patch-av) = be2a1440126908996410f92a04ad479f8a2ca373
+SHA1 (patch-aw) = 2776799b391983ad79af0f28367287a4a865260a
+SHA1 (patch-ax) = 93411fbeff95f76d723fdda993d55a2740d3a713
+SHA1 (patch-ay) = 6c5b1e469d6dfd853f68a3151ee46e7c56d8247c
+SHA1 (patch-ba) = ee151472a9ec28301b67e696e81673c4bf753ed6
+SHA1 (patch-bb) = 19e3d323efab335a50f0410d1197ecbee5b7798b
+SHA1 (patch-bv) = 2ba938aef7a5c9eb417e443577b841bae0e0550a
+SHA1 (patch-ci) = 1338452d7994b3de40e80fb395175ddbe325b577
+SHA1 (patch-ck) = d085b0ced66544963441fff5231e06fd9ac03878
+SHA1 (patch-cl) = ad26eee7b315ec512453c73cdc29253e0fa6266f
+SHA1 (patch-cp) = 1f774a6636ce6646fc83bab304e84ce2d8886db5
+SHA1 (patch-cq) = b2fcddf97e92a49828504777232841c8d5e3df16
diff --git a/sysutils/xentools3-hvm/files/NetBSD.mk b/sysutils/xentools3-hvm/files/NetBSD.mk
new file mode 100644
index 00000000000..39d24996f4e
--- /dev/null
+++ b/sysutils/xentools3-hvm/files/NetBSD.mk
@@ -0,0 +1,2 @@
+# $NetBSD: NetBSD.mk,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+include $(XEN_ROOT)/config/StdGNU.mk
diff --git a/sysutils/xentools3-hvm/files/hvm-nbsd b/sysutils/xentools3-hvm/files/hvm-nbsd
new file mode 100644
index 00000000000..2ff8181f827
--- /dev/null
+++ b/sysutils/xentools3-hvm/files/hvm-nbsd
@@ -0,0 +1,68 @@
+#============================================================================
+# Python configuration setup for 'xm create'.
+# This script sets the parameters used when a domain is created using 'xm create'.
+# You use a separate script for each domain you want to create, or
+# you can set the parameters for the domain on the xm command line.
+#============================================================================
+
+#----------------------------------------------------------------------------
+# Kernel image file.
+kernel = "@PREFIX@/lib/xen/boot/hvmloader"
+
+builder='hvm'
+
+# Initial memory allocation (in megabytes) for the new domain.
+memory = 256
+
+# A name for your domain. All domains must have different names.
+name = "hvm"
+
+#Network interface. By default emules a realtek 8139. For a NetBSD guest you
+# have to disable re(4) and let rtk attach to use it.
+# ne2k_pci emulates a pci ne2000 clone; this his cpu-hungry in dom0
+# pcnet emulates a AMD PCnet-PCI controller; but it corrupts packets with
+# pcn(4) under NetBSD.
+#vif = [ 'mac=00:16:3e:00:00:13, bridge=bridge0, type=ioemu, model=ne2k_pci' ]
+#vif = [ 'mac=00:16:3e:00:00:13, bridge=bridge0, type=ioemu, model=pcnet' ]
+vif = [ 'mac=00:16:3e:00:00:13, bridge=bridge0, type=ioemu' ]
+
+#----------------------------------------------------------------------------
+# device model to use: only qemu-dm available for now
+device_model = '/usr/pkg/libexec/qemu-dm'
+
+# Define the disk devices you want the domain to have access to, and
+# what you want them accessible as.
+# Each disk entry is of the form phy:UNAME,DEV,MODE
+# where UNAME is the device, DEV is the device name the domain will see,
+# and MODE is r for read-only, w for read-write.
+# For hvm domains you can only use hda to hdd. You can set extra types
+# (e.g. cdrom)
+
+disk = [ 'file:/home/domains/vmx,ioemu:hda,w', 'file:/home/domains/i386cd.iso,ioemu:hdc:cdrom,r' ]
+
+# floppy images; this doesn't seem to work currently. Use a iso image instead.
+#fda = '/home/domains/boot1.fs'
+
+# boot device: a = floppy, c= hard drive, d= cdrom (with the disk entry
+# before)
+boot='d'
+
+# By default, 'xm create' will try to open an X window on the current display
+# for the virtal framebuffer. You can have the virtal framebuffer in vnc
+# instead, and connect using a vnc client (using localhost:$vncdisplay)
+# If vncunused is set to 1 (this is the default value), vncdisplay
+# will be set to the first unused port; so it's recommended to
+#vnc = 1
+#vncdisplay = 0
+#vncunused = 0
+
+#Xen emulates a PS/2 mouse, but the pointer in the guest has difficulties
+# tracking the absolute position. Xen can emulate a USB tablet in addition
+# to the mouse which will report the absolute position of the pointer,
+# and make the mouse much easier to use.
+#
+usb=1
+usbdevice='tablet'
+#usbdevice='mouse'
+
+#============================================================================
diff --git a/sysutils/xentools3-hvm/files/qemu-ifup-nbsd b/sysutils/xentools3-hvm/files/qemu-ifup-nbsd
new file mode 100755
index 00000000000..eee78765d67
--- /dev/null
+++ b/sysutils/xentools3-hvm/files/qemu-ifup-nbsd
@@ -0,0 +1,3 @@
+#!/bin/sh
+ifconfig $1 up
+exec /sbin/brconfig $2 add $1
diff --git a/sysutils/xentools3-hvm/files/xenio.h b/sysutils/xentools3-hvm/files/xenio.h
new file mode 100644
index 00000000000..d670b414759
--- /dev/null
+++ b/sysutils/xentools3-hvm/files/xenio.h
@@ -0,0 +1,105 @@
+/* NetBSD: xenio.h,v 1.3 2005/05/24 12:07:12 yamt Exp $ */
+
+/******************************************************************************
+ * privcmd.h
+ *
+ * Copyright (c) 2003-2004, K A Fraser
+ *
+ * This file may be distributed separately from the Linux kernel, or
+ * incorporated into other software packages, subject to the following license:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this source file (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef __NetBSD_PRIVCMD_H__
+#define __NetBSD_PRIVCMD_H__
+
+/* Interface to /proc/xen/privcmd */
+
+typedef struct privcmd_hypercall
+{
+ unsigned long op;
+ unsigned long arg[5];
+} privcmd_hypercall_t;
+
+typedef struct privcmd_mmap_entry {
+ unsigned long va;
+ unsigned long mfn;
+ unsigned long npages;
+} privcmd_mmap_entry_t;
+
+typedef struct privcmd_mmap {
+ int num;
+ domid_t dom; /* target domain */
+ privcmd_mmap_entry_t *entry;
+} privcmd_mmap_t;
+
+typedef struct privcmd_mmapbatch {
+ int num; /* number of pages to populate */
+ domid_t dom; /* target domain */
+ unsigned long addr; /* virtual address */
+ unsigned long *arr; /* array of mfns - top nibble set on err */
+} privcmd_mmapbatch_t;
+
+typedef struct privcmd_blkmsg
+{
+ unsigned long op;
+ void *buf;
+ int buf_size;
+} privcmd_blkmsg_t;
+
+/*
+ * @cmd: IOCTL_PRIVCMD_HYPERCALL
+ * @arg: &privcmd_hypercall_t
+ * Return: Value returned from execution of the specified hypercall.
+ */
+#define IOCTL_PRIVCMD_HYPERCALL \
+ _IOWR('P', 0, privcmd_hypercall_t)
+
+#if defined(_KERNEL)
+/* compat */
+#define IOCTL_PRIVCMD_INITDOMAIN_EVTCHN_OLD \
+ _IO('P', 1)
+#endif /* defined(_KERNEL) */
+
+#define IOCTL_PRIVCMD_MMAP \
+ _IOW('P', 2, privcmd_mmap_t)
+#define IOCTL_PRIVCMD_MMAPBATCH \
+ _IOW('P', 3, privcmd_mmapbatch_t)
+#define IOCTL_PRIVCMD_GET_MACH2PHYS_START_MFN \
+ _IOR('P', 4, unsigned long)
+
+/*
+ * @cmd: IOCTL_PRIVCMD_INITDOMAIN_EVTCHN
+ * @arg: n/a
+ * Return: Port associated with domain-controller end of control event channel
+ * for the initial domain.
+ */
+#define IOCTL_PRIVCMD_INITDOMAIN_EVTCHN \
+ _IOR('P', 5, int)
+
+/* Interface to /dev/xenevt */
+/* EVTCHN_RESET: Clear and reinit the event buffer. Clear error condition. */
+#define EVTCHN_RESET _IO('E', 1)
+/* EVTCHN_BIND: Bind to the specified event-channel port. */
+#define EVTCHN_BIND _IOW('E', 2, unsigned long)
+/* EVTCHN_UNBIND: Unbind from the specified event-channel port. */
+#define EVTCHN_UNBIND _IOW('E', 3, unsigned long)
+
+#endif /* __NetBSD_PRIVCMD_H__ */
diff --git a/sysutils/xentools3-hvm/files/xenio3.h b/sysutils/xentools3-hvm/files/xenio3.h
new file mode 100644
index 00000000000..5ee2a26e20f
--- /dev/null
+++ b/sysutils/xentools3-hvm/files/xenio3.h
@@ -0,0 +1,89 @@
+/* $NetBSD: xenio3.h,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $ */
+/******************************************************************************
+ * evtchn.h
+ *
+ * Interface to /dev/xen/evtchn.
+ *
+ * Copyright (c) 2003-2005, K A Fraser
+ *
+ * This file may be distributed separately from the Linux kernel, or
+ * incorporated into other software packages, subject to the following license:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this source file (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef __NetBSD_XENIO3_H__
+#define __NetBSD_XENIO3_H__
+
+/*
+ * Bind a fresh port to VIRQ @virq.
+ * Return allocated port.
+ */
+#define IOCTL_EVTCHN_BIND_VIRQ \
+ _IOWR('E', 4, struct ioctl_evtchn_bind_virq)
+struct ioctl_evtchn_bind_virq {
+ unsigned int virq;
+ unsigned int port;
+};
+
+/*
+ * Bind a fresh port to remote <@remote_domain, @remote_port>.
+ * Return allocated port.
+ */
+#define IOCTL_EVTCHN_BIND_INTERDOMAIN \
+ _IOWR('E', 5, struct ioctl_evtchn_bind_interdomain)
+struct ioctl_evtchn_bind_interdomain {
+ unsigned int remote_domain, remote_port;
+ unsigned int port;
+};
+
+/*
+ * Allocate a fresh port for binding to @remote_domain.
+ * Return allocated port.
+ */
+#define IOCTL_EVTCHN_BIND_UNBOUND_PORT \
+ _IOWR('E', 6, struct ioctl_evtchn_bind_unbound_port)
+struct ioctl_evtchn_bind_unbound_port {
+ unsigned int remote_domain;
+ unsigned int port;
+};
+
+/*
+ * Unbind previously allocated @port.
+ */
+#define IOCTL_EVTCHN_UNBIND \
+ _IOW('E', 7, struct ioctl_evtchn_unbind)
+struct ioctl_evtchn_unbind {
+ unsigned int port;
+};
+
+/*
+ * Send event to previously allocated @port.
+ */
+#define IOCTL_EVTCHN_NOTIFY \
+ _IOW('E', 8, struct ioctl_evtchn_notify)
+struct ioctl_evtchn_notify {
+ unsigned int port;
+};
+
+/* Clear and reinitialise the event buffer. Clear error condition. */
+#define IOCTL_EVTCHN_RESET \
+ _IO('E', 9)
+
+#endif /* __NetBSD_XENIO3_H__ */
diff --git a/sysutils/xentools3-hvm/patches/patch-aa b/sysutils/xentools3-hvm/patches/patch-aa
new file mode 100644
index 00000000000..7a6a25088f2
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-aa
@@ -0,0 +1,61 @@
+$NetBSD: patch-aa,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- Makefile.orig 2007-05-18 16:45:21.000000000 +0200
++++ Makefile 2007-06-12 22:20:43.000000000 +0200
+@@ -2,34 +2,11 @@
+ include $(XEN_ROOT)/tools/Rules.mk
+
+ SUBDIRS-y :=
+-SUBDIRS-y += libxc
+-SUBDIRS-y += xenstore
+-SUBDIRS-y += misc
+-SUBDIRS-y += examples
+-SUBDIRS-y += xentrace
+-SUBDIRS-$(CONFIG_XCUTILS) += xcutils
+-SUBDIRS-$(CONFIG_X86) += firmware
+-SUBDIRS-y += security
+-SUBDIRS-y += console
+-SUBDIRS-y += xenmon
+-SUBDIRS-y += guest-headers
+-SUBDIRS-$(VTPM_TOOLS) += vtpm_manager
+-SUBDIRS-$(VTPM_TOOLS) += vtpm
+-SUBDIRS-y += xenstat
+-SUBDIRS-y += libaio
+-SUBDIRS-y += blktap
+-SUBDIRS-y += libfsimage
+-SUBDIRS-$(XENFB_TOOLS) += xenfb
+-SUBDIRS-$(LIBXENAPI_BINDINGS) += libxen
+-
+-# These don't cross-compile
+-ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
+-SUBDIRS-$(PYTHON_TOOLS) += python
+-SUBDIRS-$(PYTHON_TOOLS) += pygrub
+-endif
++SUBDIRS-y += firmware
+
+ .PHONY: all
+ all: check
++ (cd libxc ; $(MAKE) mk-symlinks)
+ @set -e; for subdir in $(SUBDIRS-y); do \
+ $(MAKE) -C $$subdir $@; \
+ done
+@@ -56,18 +33,16 @@
+
+ .PHONY: check
+ check:
+- $(MAKE) -C check
+
+ .PHONY: check_clean
+ check_clean:
+- $(MAKE) -C check clean
+
+ .PHONY: ioemu ioemuinstall ioemuclean
+ ifeq ($(CONFIG_IOEMU),y)
+ export IOEMU_DIR ?= ioemu
+ ioemu ioemuinstall:
+ [ -f $(IOEMU_DIR)/config-host.mak ] || \
+- (cd $(IOEMU_DIR) && sh configure --prefix=/usr)
++ (cd $(IOEMU_DIR) && sh configure --prefix=$(PREFIX))
+ $(MAKE) -C $(IOEMU_DIR) $(patsubst ioemu%,%,$@)
+ ioemuclean:
+ $(MAKE) -C $(IOEMU_DIR) distclean
diff --git a/sysutils/xentools3-hvm/patches/patch-an b/sysutils/xentools3-hvm/patches/patch-an
new file mode 100644
index 00000000000..14e97f5919b
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-an
@@ -0,0 +1,24 @@
+$NetBSD: patch-an,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- firmware/Makefile.orig 2007-05-18 16:45:21.000000000 +0200
++++ firmware/Makefile 2007-06-12 22:21:53.000000000 +0200
+@@ -4,7 +4,7 @@
+ # hvmloader is a 32-bit protected mode binary.
+ # It belongs in /usr/lib, not /usr/lib64.
+ TARGET := hvmloader/hvmloader
+-INST_DIR := $(DESTDIR)/usr/lib/xen/boot
++INST_DIR := $(PREFIX)/lib/xen/boot
+
+ SUBDIRS :=
+ SUBDIRS += rombios rombios/32bit
+@@ -28,8 +28,8 @@
+
+ .PHONY: install
+ install: all
+- [ -d $(INST_DIR) ] || $(INSTALL_DIR) $(INST_DIR)
+- [ ! -e $(TARGET) ] || $(INSTALL_DATA) $(TARGET) $(INST_DIR)
++ $(BSD_INSTALL_DATA_DIR) $(INST_DIR)
++ $(BSD_INSTALL_DATA) $(TARGET) $(INST_DIR)
+
+ .PHONY: clean
+ clean:
diff --git a/sysutils/xentools3-hvm/patches/patch-ao b/sysutils/xentools3-hvm/patches/patch-ao
new file mode 100644
index 00000000000..a99fa1d2dd5
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-ao
@@ -0,0 +1,23 @@
+$NetBSD: patch-ao,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- ioemu/configure.orig 2006-10-04 04:28:06.000000000 +0200
++++ ioemu/configure 2006-10-18 17:37:42.000000000 +0200
+@@ -517,7 +517,7 @@
+ datadir="$prefix/share/xen/qemu"
+ docdir="$prefix/share/doc/qemu"
+-bindir="$prefix/$libdir/xen/bin"
++bindir="$prefix/libexec"
+-configdir="/etc/xen"
++configdir="@XENDCONFDIR@"
+ fi
+
+ echo "Install prefix $prefix"
+@@ -653,6 +653,8 @@
+ echo "#define CONFIG_WIN32 1" >> $config_h
+ elif test -f "/usr/include/byteswap.h" ; then
+ echo "#define HAVE_BYTESWAP_H 1" >> $config_h
++elif test -f "/usr/include/machine/bswap.h" ; then
++ echo "#define HAVE_MACHINE_BSWAP_H 1" >> $config_h
+ fi
+ if test "$darwin" = "yes" ; then
+ echo "CONFIG_DARWIN=yes" >> $config_mak
diff --git a/sysutils/xentools3-hvm/patches/patch-ap b/sysutils/xentools3-hvm/patches/patch-ap
new file mode 100644
index 00000000000..efe94d6f8b8
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-ap
@@ -0,0 +1,12 @@
+$NetBSD: patch-ap,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- firmware/hvmloader/mkhex.orig 2006-04-13 19:48:38.000000000 +0200
++++ firmware/hvmloader/mkhex
+@@ -21,6 +21,6 @@
+ #
+
+ echo "unsigned $1[] = {"
+-od -v -t x $2 | sed 's/^[0-9]* /0x/' | sed 's/ /, 0x/g' | sed 's/$/,/'
++od -v -t x $2 | sed 's/^[0-9]* */0x0/' | sed 's/ */, 0x/g' | sed 's/$/,/'
+ echo "};"
+
diff --git a/sysutils/xentools3-hvm/patches/patch-ar b/sysutils/xentools3-hvm/patches/patch-ar
new file mode 100644
index 00000000000..db2c5df827a
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-ar
@@ -0,0 +1,165 @@
+$NetBSD: patch-ar,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- ioemu/vl.c.orig 2007-05-18 16:45:21.000000000 +0200
++++ ioemu/vl.c 2007-06-12 23:59:27.000000000 +0200
+@@ -37,14 +37,17 @@
+ #include <sys/poll.h>
+ #include <sys/mman.h>
+ #include <sys/ioctl.h>
++#include <sys/resource.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
++#include <net/if.h>
++#include <net/if_tap.h>
+ #include <arpa/inet.h>
+ #include <dirent.h>
+ #include <netdb.h>
+ #ifdef _BSD
+ #include <sys/stat.h>
+-#ifndef __APPLE__
++#ifndef _BSD
+ #include <libutil.h>
+ #endif
+ #else
+@@ -89,8 +92,8 @@
+ #include "exec-all.h"
+
+ #include <xen/hvm/params.h>
+-#define DEFAULT_NETWORK_SCRIPT "/etc/xen/qemu-ifup"
+-#define DEFAULT_BRIDGE "xenbr0"
++#define DEFAULT_NETWORK_SCRIPT "@XENDCONFDIR@/scripts/qemu-ifup"
++#define DEFAULT_BRIDGE "bridge0"
+
+ //#define DEBUG_UNUSED_IOPORT
+ //#define DEBUG_IOPORT
+@@ -1663,7 +1666,7 @@
+ return 0;
+ }
+
+-#if defined(__linux__)
++#if defined(__linux__) || defined(__NetBSD__)
+ CharDriverState *qemu_chr_open_pty(void)
+ {
+ struct termios tty;
+@@ -1814,7 +1817,7 @@
+ chr->chr_ioctl = tty_serial_ioctl;
+ return chr;
+ }
+-
++#if defined(__linux__)
+ static int pp_ioctl(CharDriverState *chr, int cmd, void *arg)
+ {
+ int fd = (int)chr->opaque;
+@@ -1877,13 +1880,14 @@
+ chr->chr_ioctl = pp_ioctl;
+ return chr;
+ }
++#endif /* __linux__ */
+
+ #else
+ CharDriverState *qemu_chr_open_pty(void)
+ {
+ return NULL;
+ }
+-#endif
++#endif /* __linux__ || __NetBSD__ */
+
+ #endif /* !defined(_WIN32) */
+
+@@ -3126,7 +3130,7 @@
+ fclose(f);
+ atexit(smb_exit);
+
+- snprintf(smb_cmdline, sizeof(smb_cmdline), "/usr/sbin/smbd -s %s",
++ snprintf(smb_cmdline, sizeof(smb_cmdline), "@PREFIX@/sbin/smbd -s %s",
+ smb_conf);
+
+ slirp_add_exec(0, smb_cmdline, 4, 139);
+@@ -3190,16 +3194,26 @@
+ int fd;
+ char *dev;
+ struct stat s;
++ struct ifreq ifr;
+
+ fd = open("/dev/tap", O_RDWR);
+ if (fd < 0) {
+- fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
++ fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation: %s\n", strerror(errno));
+ return -1;
+ }
+
++#ifdef TAPGIFNAME
++ if (ioctl (fd, TAPGIFNAME, (void*)&ifr) < 0) {
++ fprintf(stderr, "warning: could not open get tap name: %s\n",
++ strerror(errno));
++ return -1;
++ }
++ pstrcpy(ifname, ifname_size, ifr.ifr_name);
++#else
+ fstat(fd, &s);
+ dev = devname(s.st_rdev, S_IFCHR);
+ pstrcpy(ifname, ifname_size, dev);
++#endif
+
+ fcntl(fd, F_SETFL, O_NONBLOCK);
+ return fd;
+@@ -5934,7 +5948,6 @@
+ nr_buckets = (((MAX_MCACHE_SIZE >> PAGE_SHIFT) +
+ (1UL << (MCACHE_BUCKET_SHIFT - PAGE_SHIFT)) - 1) >>
+ (MCACHE_BUCKET_SHIFT - PAGE_SHIFT));
+- fprintf(logfile, "qemu_map_cache_init nr_buckets = %lx\n", nr_buckets);
+
+ /*
+ * Use mmap() directly: lets us allocate a big hash table with no up-front
+@@ -5943,8 +5956,9 @@
+ */
+ size = nr_buckets * sizeof(struct map_cache);
+ size = (size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
++ fprintf(logfile, "qemu_map_cache_init nr_buckets = %lx size %lu\n", nr_buckets, size);
+ mapcache_entry = mmap(NULL, size, PROT_READ|PROT_WRITE,
+- MAP_SHARED|MAP_ANONYMOUS, 0, 0);
++ MAP_SHARED|MAP_ANONYMOUS, -1, 0);
+ if (mapcache_entry == MAP_FAILED) {
+ errno = ENOMEM;
+ return -1;
+@@ -6081,6 +6095,7 @@
+ unsigned long ioreq_pfn;
+ extern void *shared_page;
+ extern void *buffered_io_page;
++ struct rlimit rl;
+ #ifdef __ia64__
+ unsigned long nr_pages;
+ xen_pfn_t *page_array;
+@@ -6089,6 +6104,32 @@
+
+ char qemu_dm_logfilename[64];
+
++ /* XXX required for now */
++ if (setenv("PTHREAD_DIAGASSERT", "A", 1) != 0)
++ perror("setenv");
++ if (getrlimit(RLIMIT_STACK, &rl) != 0) {
++ perror("getrlimit(RLIMIT_STACK)");
++ exit(1);
++ }
++ rl.rlim_cur = rl.rlim_max;
++ if (setrlimit(RLIMIT_STACK, &rl) != 0)
++ perror("setrlimit(RLIMIT_STACK)");
++ if (getrlimit(RLIMIT_DATA, &rl) != 0) {
++ perror("getrlimit(RLIMIT_DATA)");
++ exit(1);
++ }
++ rl.rlim_cur = rl.rlim_max;
++ if (setrlimit(RLIMIT_DATA, &rl) != 0)
++ perror("setrlimit(RLIMIT_DATA)");
++ rl.rlim_cur = RLIM_INFINITY;
++ rl.rlim_max = RLIM_INFINITY;
++ if (setrlimit(RLIMIT_RSS, &rl) != 0)
++ perror("setrlimit(RLIMIT_RSS)");
++ rl.rlim_cur = RLIM_INFINITY;
++ rl.rlim_max = RLIM_INFINITY;
++ if (setrlimit(RLIMIT_MEMLOCK, &rl) != 0)
++ perror("setrlimit(RLIMIT_MEMLOCK)");
++
+ LIST_INIT (&vm_change_state_head);
+ #ifndef _WIN32
+ {
diff --git a/sysutils/xentools3-hvm/patches/patch-as b/sysutils/xentools3-hvm/patches/patch-as
new file mode 100644
index 00000000000..6f5f4c0ca10
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-as
@@ -0,0 +1,26 @@
+$NetBSD: patch-as,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- ioemu/bswap.h.orig 2006-04-13 19:48:38.000000000 +0200
++++ ioemu/bswap.h
+@@ -5,6 +5,12 @@
+
+ #include <inttypes.h>
+
++#ifdef HAVE_MACHINE_BSWAP_H
++#include <sys/endian.h>
++#include <sys/types.h>
++#include <machine/bswap.h>
++#else
++
+ #ifdef HAVE_BYTESWAP_H
+ #include <byteswap.h>
+ #else
+@@ -58,6 +64,8 @@ static inline uint64_t bswap64(uint64_t
+ return bswap_64(x);
+ }
+
++#endif /* ! HAVE_MACHINE_BSWAP_H */
++
+ static inline void bswap16s(uint16_t *s)
+ {
+ *s = bswap16(*s);
diff --git a/sysutils/xentools3-hvm/patches/patch-at b/sysutils/xentools3-hvm/patches/patch-at
new file mode 100644
index 00000000000..26906d436c8
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-at
@@ -0,0 +1,13 @@
+$NetBSD: patch-at,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- ioemu/audio/ossaudio.c.orig 2006-10-04 04:28:03.000000000 +0200
++++ ioemu/audio/ossaudio.c 2006-10-18 17:43:53.000000000 +0200
+@@ -231,7 +231,7 @@
+ goto err;
+ }
+
+- if (ioctl (fd, SNDCTL_DSP_NONBLOCK)) {
++ if (ioctl (fd, SNDCTL_DSP_NONBLOCK, NULL)) {
+ oss_logerr2 (errno, typ, "Failed to set non-blocking mode\n");
+ goto err;
+ }
diff --git a/sysutils/xentools3-hvm/patches/patch-au b/sysutils/xentools3-hvm/patches/patch-au
new file mode 100644
index 00000000000..f479e601274
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-au
@@ -0,0 +1,16 @@
+$NetBSD: patch-au,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- libxc/xc_private.h.orig 2006-10-16 22:15:35.000000000 +0200
++++ libxc/xc_private.h 2006-10-16 22:16:09.000000000 +0200
+@@ -15,7 +15,11 @@
+
+ #include "xenctrl.h"
+
++#ifdef __NetBSD__
++#include <xen/NetBSD/xenio.h>
++#else
+ #include <xen/sys/privcmd.h>
++#endif
+
+ /* valgrind cannot see when a hypercall has filled in some values. For this
+ reason, we must zero the privcmd_hypercall_t or domctl/sysctl instance
diff --git a/sysutils/xentools3-hvm/patches/patch-av b/sysutils/xentools3-hvm/patches/patch-av
new file mode 100644
index 00000000000..323ffdff478
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-av
@@ -0,0 +1,12 @@
+$NetBSD: patch-av,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- libxc/xg_private.h.orig 2006-10-16 22:15:35.000000000 +0200
++++ libxc/xg_private.h 2006-10-16 22:16:19.000000000 +0200
+@@ -15,7 +15,6 @@
+ #include "xenguest.h"
+ #include "xc_private.h"
+
+-#include <xen/sys/privcmd.h>
+ #include <xen/memory.h>
+ #include <xen/elfnote.h>
+
diff --git a/sysutils/xentools3-hvm/patches/patch-aw b/sysutils/xentools3-hvm/patches/patch-aw
new file mode 100644
index 00000000000..0a3a28eb075
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-aw
@@ -0,0 +1,32 @@
+$NetBSD: patch-aw,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- ioemu/audio/mixeng.c.orig 2006-10-04 04:28:03.000000000 +0200
++++ ioemu/audio/mixeng.c 2006-10-18 17:45:57.000000000 +0200
+@@ -102,6 +102,7 @@
+ #undef SHIFT
+
+ t_sample *mixeng_conv[2][2][2][2] = {
++#if !defined(__NetBSD__)
+ {
+ {
+ {
+@@ -146,9 +147,11 @@
+ }
+ }
+ }
++#endif /* !__NetBSD__ */
+ };
+
+ f_sample *mixeng_clip[2][2][2][2] = {
++#if !defined(__NetBSD__)
+ {
+ {
+ {
+@@ -193,6 +196,7 @@
+ }
+ }
+ }
++#endif /* !__NetBSD__ */
+ };
+
+ /*
diff --git a/sysutils/xentools3-hvm/patches/patch-ax b/sysutils/xentools3-hvm/patches/patch-ax
new file mode 100644
index 00000000000..2dc2f96da9c
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-ax
@@ -0,0 +1,14 @@
+$NetBSD: patch-ax,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- ioemu/vnc.c.orig 2006-10-19 22:23:35.000000000 +0200
++++ ioemu/vnc.c 2006-10-19 22:26:50.000000000 +0200
+@@ -24,6 +24,9 @@
+ * THE SOFTWARE.
+ */
+
++#include <sys/stat.h>
++#include <sys/socket.h>
++#include <netinet/in.h>
+ #include "vl.h"
+ #include "qemu_socket.h"
+ #include <assert.h>
diff --git a/sysutils/xentools3-hvm/patches/patch-ay b/sysutils/xentools3-hvm/patches/patch-ay
new file mode 100644
index 00000000000..32471e1af4d
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-ay
@@ -0,0 +1,25 @@
+$NetBSD: patch-ay,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- ioemu/Makefile.orig 2007-05-18 16:45:21.000000000 +0200
++++ ioemu/Makefile 2007-06-12 22:28:21.000000000 +0200
+@@ -72,7 +72,7 @@
+ endif
+
+ install: all $(if $(BUILD_DOCS),install-doc)
+- mkdir -p "$(DESTDIR)$(bindir)"
++ $(BSD_INSTALL_PROGRAM_DIR) "$(bindir)"
+ # $(INSTALL) -m 755 -s $(TOOLS) "$(DESTDIR)$(bindir)"
+ # mkdir -p "$(DESTDIR)$(datadir)"
+ # for x in bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \
+@@ -80,9 +80,9 @@
+ # $(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(datadir)"; \
+ # done
+ ifndef CONFIG_WIN32
+- mkdir -p "$(DESTDIR)$(datadir)/keymaps"
++ $(BSD_INSTALL_DATA_DIR) "$(datadir)/keymaps"
+ for x in $(KEYMAPS); do \
+- $(INSTALL_DATA) $(SRC_PATH)/keymaps/$$x "$(DESTDIR)$(datadir)/keymaps"; \
++ $(BSD_INSTALL_DATA) $(SRC_PATH)/keymaps/$$x "$(DESTDIR)$(datadir)/keymaps"; \
+ done
+ endif
+ for d in $(TARGET_DIRS); do \
diff --git a/sysutils/xentools3-hvm/patches/patch-ba b/sysutils/xentools3-hvm/patches/patch-ba
new file mode 100644
index 00000000000..81215f06030
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-ba
@@ -0,0 +1,15 @@
+$NetBSD: patch-ba,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- ioemu/target-i386-dm/exec-dm.c.orig 2006-10-18 18:19:27.000000000 +0200
++++ ioemu/target-i386-dm/exec-dm.c 2006-10-18 18:19:40.000000000 +0200
+@@ -163,8 +163,8 @@
+ #else
+ setvbuf(logfile, NULL, _IOLBF, 0);
+ #endif
+- stdout = logfile;
+- stderr = logfile;
++ dup2(fileno(logfile), 1);
++ dup2(fileno(logfile), 2);
+ }
+ }
+
diff --git a/sysutils/xentools3-hvm/patches/patch-bb b/sysutils/xentools3-hvm/patches/patch-bb
new file mode 100644
index 00000000000..e58a3131709
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-bb
@@ -0,0 +1,19 @@
+$NetBSD: patch-bb,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- ioemu/Makefile.target.orig 2007-01-08 16:00:48.000000000 +0100
++++ ioemu/Makefile.target 2007-04-26 21:38:21.000000000 +0200
+@@ -567,12 +567,8 @@
+ rm -rf config.mak config.h
+
+ install: all
+- mkdir -p "$(DESTDIR)$(bindir)" "$(DESTDIR)$(configdir)"
+-ifneq ($(PROGS),)
+- $(INSTALL_PROG) $(PROGS) "$(DESTDIR)$(bindir)"
+-endif
+- $(INSTALL_PROG) $(TARGET_PATH)/qemu-dm.debug "$(DESTDIR)$(bindir)"
+- $(INSTALL_PROG) $(TARGET_PATH)/qemu-ifup "$(DESTDIR)$(configdir)"
++ $(BSD_INSTALL_PROGRAM_DIR) "$(bindir)"
++ $(BSD_INSTALL_PROGRAM) $(PROGS) "$(DESTDIR)$(bindir)"
+
+ ifneq ($(wildcard .depend),)
+ include .depend
diff --git a/sysutils/xentools3-hvm/patches/patch-bv b/sysutils/xentools3-hvm/patches/patch-bv
new file mode 100644
index 00000000000..0279eb04d88
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-bv
@@ -0,0 +1,14 @@
+$NetBSD: patch-bv,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- libxc/xenctrl.h.orig 2007-01-08 16:00:49.000000000 +0100
++++ libxc/xenctrl.h 2007-04-26 21:40:23.000000000 +0200
+@@ -16,6 +16,9 @@
+
+ #include <stddef.h>
+ #include <stdint.h>
++#undef uint8_t
++#undef uint16_t
++#undef uint32_t
+ #include <xen/xen.h>
+ #include <xen/domctl.h>
+ #include <xen/sysctl.h>
diff --git a/sysutils/xentools3-hvm/patches/patch-ci b/sysutils/xentools3-hvm/patches/patch-ci
new file mode 100644
index 00000000000..60d4f98ff97
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-ci
@@ -0,0 +1,16 @@
+$NetBSD: patch-ci,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- ../xen/include/public/arch-x86/xen.h.orig 2007-04-25 19:25:41.000000000 +0200
++++ ../xen/include/public/arch-x86/xen.h 2007-04-25 19:25:43.000000000 +0200
+@@ -35,9 +35,10 @@
+ #define __DEFINE_XEN_GUEST_HANDLE(name, type) \
+ typedef type * __guest_handle_ ## name
+ #endif
++#define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name
+
+ #define DEFINE_XEN_GUEST_HANDLE(name) __DEFINE_XEN_GUEST_HANDLE(name, name)
+-#define XEN_GUEST_HANDLE(name) __guest_handle_ ## name
++#define XEN_GUEST_HANDLE(name) __XEN_GUEST_HANDLE(name)
+ #define set_xen_guest_handle(hnd, val) do { (hnd).p = val; } while (0)
+ #ifdef __XEN_TOOLS__
+ #define get_xen_guest_handle(val, hnd) do { val = (hnd).p; } while (0)
diff --git a/sysutils/xentools3-hvm/patches/patch-ck b/sysutils/xentools3-hvm/patches/patch-ck
new file mode 100644
index 00000000000..7532d14a39e
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-ck
@@ -0,0 +1,9 @@
+$NetBSD: patch-ck,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+--- firmware/rombios/32bit/Makefile.orig 2007-06-12 22:41:50.000000000 +0200
++++ firmware/rombios/32bit/Makefile 2007-06-12 22:41:59.000000000 +0200
+@@ -39,4 +39,4 @@
+ nm -u 32bitbios_all.o; \
+ exit 11; \
+ } || :
+- bash mkhex highbios_array 32bitbios_all.o > $@
++ sh mkhex highbios_array 32bitbios_all.o > $@
diff --git a/sysutils/xentools3-hvm/patches/patch-cl b/sysutils/xentools3-hvm/patches/patch-cl
new file mode 100644
index 00000000000..494a255d544
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-cl
@@ -0,0 +1,12 @@
+$NetBSD: patch-cl,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- firmware/rombios/32bit/mkhex.orig 2007-06-12 22:45:56.000000000 +0200
++++ firmware/rombios/32bit/mkhex 2007-06-12 22:46:08.000000000 +0200
+@@ -21,6 +21,6 @@
+ #
+
+ echo "unsigned $1[] = {"
+-od -v -t x $2 | sed 's/^[0-9]* /0x/' | sed 's/ /, 0x/g' | sed 's/$/,/'
++od -v -t x $2 | sed 's/^[0-9]* */0x0/' | sed 's/ */, 0x/g' | sed 's/$/,/' | sed 's/0x,//' | sed 's/^[0-9]*,//'
+ echo "};"
+
diff --git a/sysutils/xentools3-hvm/patches/patch-cp b/sysutils/xentools3-hvm/patches/patch-cp
new file mode 100644
index 00000000000..a55777b0e3f
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-cp
@@ -0,0 +1,14 @@
+$NetBSD: patch-cp,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+
+--- ../xen/include/public/arch-x86/xen-x86_32.h.orig 2007-05-27 15:08:03.000000000 +0200
++++ ../xen/include/public/arch-x86/xen-x86_32.h 2007-05-27 15:08:44.000000000 +0200
+@@ -103,7 +103,8 @@
+ (hnd).p = val; \
+ } while ( 0 )
+ #define uint64_aligned_t uint64_t __attribute__((aligned(8)))
+-#define XEN_GUEST_HANDLE_64(name) __guest_handle_64_ ## name
++#define __XEN_GUEST_HANDLE_64(name) __guest_handle_64_ ## name
++#define XEN_GUEST_HANDLE_64(name) __XEN_GUEST_HANDLE_64(name)
+ #endif
+
+ #ifndef __ASSEMBLY__
diff --git a/sysutils/xentools3-hvm/patches/patch-cq b/sysutils/xentools3-hvm/patches/patch-cq
new file mode 100644
index 00000000000..7016cca7877
--- /dev/null
+++ b/sysutils/xentools3-hvm/patches/patch-cq
@@ -0,0 +1,757 @@
+$NetBSD: patch-cq,v 1.1.1.1 2007/06/14 19:42:12 bouyer Exp $
+This is a backport of bugfixes and changes in xen-unstable to make pcnet
+usable. It gives better performances than the ne2000 or realtek emulations.
+
+--- ioemu/hw/pcnet.c.orig 2007-06-13 19:06:54.000000000 +0200
++++ ioemu/hw/pcnet.c 2007-06-13 19:54:43.000000000 +0200
+@@ -41,25 +41,6 @@
+ #define PCNET_IOPORT_SIZE 0x20
+ #define PCNET_PNPMMIO_SIZE 0x20
+
+-
+-typedef struct PCNetState_st PCNetState;
+-
+-struct PCNetState_st {
+- PCIDevice dev;
+- VLANClientState *vc;
+- NICInfo *nd;
+- QEMUTimer *poll_timer;
+- int mmio_io_addr, rap, isr, lnkst;
+- target_phys_addr_t rdra, tdra;
+- uint8_t prom[16];
+- uint16_t csr[128];
+- uint16_t bcr[32];
+- uint64_t timer;
+- int xmit_pos, recv_pos;
+- uint8_t buffer[4096];
+- int tx_busy;
+-};
+-
+ /* XXX: using bitfields for target memory structures is almost surely
+ not portable, so it should be suppressed ASAP */
+ #ifdef __GNUC__
+@@ -251,6 +232,28 @@
+ (R)->rmd2.rcc, (R)->rmd2.rpc, (R)->rmd2.mcnt, \
+ (R)->rmd2.zeros)
+
++typedef struct PCNetState_st PCNetState;
++
++struct PCNetState_st {
++ PCIDevice dev;
++ VLANClientState *vc;
++ NICInfo *nd;
++ QEMUTimer *poll_timer;
++ int mmio_io_addr, rap, isr, lnkst;
++ target_phys_addr_t rdra, tdra;
++ uint8_t prom[16];
++ uint16_t csr[128];
++ uint16_t bcr[32];
++ uint64_t timer;
++ int recv_pos;
++ uint8_t tx_buffer[2048];
++ uint8_t rx_buffer[2048];
++ struct pcnet_TMD tmd;
++ struct pcnet_RMD crmd;
++ struct pcnet_RMD nrmd;
++ struct pcnet_RMD nnrmd;
++};
++
+ static inline void pcnet_tmd_load(PCNetState *s, struct pcnet_TMD *tmd, target_phys_addr_t addr)
+ {
+ if (!BCR_SWSTYLE(s)) {
+@@ -269,18 +272,17 @@
+ if (BCR_SWSTYLE(s) != 3)
+ cpu_physical_memory_read(addr, (void *)tmd, 16);
+ else {
+- uint32_t xda[4];
+- cpu_physical_memory_read(addr,
+- (void *)&xda[0], sizeof(xda));
+- ((uint32_t *)tmd)[0] = xda[2];
+- ((uint32_t *)tmd)[1] = xda[1];
+- ((uint32_t *)tmd)[2] = xda[0];
+- ((uint32_t *)tmd)[3] = xda[3];
++ uint32_t xda[2];
++ cpu_physical_memory_read(addr+4, (void *)&xda[0], sizeof(xda));
++ ((uint32_t *)tmd)[0] = xda[1];
++ ((uint32_t *)tmd)[1] = xda[0];
++ ((uint32_t *)tmd)[2] = 0;
+ }
+ }
+
+ static inline void pcnet_tmd_store(PCNetState *s, struct pcnet_TMD *tmd, target_phys_addr_t addr)
+ {
++ tmd->tmd1.own = 0;
+ if (!BCR_SWSTYLE(s)) {
+ uint16_t xda[4];
+ xda[0] = ((uint32_t *)tmd)[0] & 0xffff;
+@@ -295,14 +297,12 @@
+ if (BCR_SWSTYLE(s) != 3)
+ cpu_physical_memory_write(addr, (void *)tmd, 16);
+ else {
+- uint32_t xda[4];
++ uint32_t xda[2];
+ xda[0] = ((uint32_t *)tmd)[2];
+ xda[1] = ((uint32_t *)tmd)[1];
+- xda[2] = ((uint32_t *)tmd)[0];
+- xda[3] = ((uint32_t *)tmd)[3];
+- cpu_physical_memory_write(addr,
+- (void *)&xda[0], sizeof(xda));
++ cpu_physical_memory_write(addr, (void *)&xda[0], sizeof(xda));
+ }
++ cpu_physical_memory_set_dirty(addr+15);
+ }
+ }
+
+@@ -320,21 +320,22 @@
+ ((uint32_t *)rmd)[3] = 0;
+ }
+ else
+- if (BCR_SWSTYLE(s) != 3)
++ if (BCR_SWSTYLE(s) != 3) {
++ ((uint32_t *)rmd)[2] = 0;
+ cpu_physical_memory_read(addr, (void *)rmd, 16);
+- else {
+- uint32_t rda[4];
+- cpu_physical_memory_read(addr,
+- (void *)&rda[0], sizeof(rda));
+- ((uint32_t *)rmd)[0] = rda[2];
+- ((uint32_t *)rmd)[1] = rda[1];
+- ((uint32_t *)rmd)[2] = rda[0];
+- ((uint32_t *)rmd)[3] = rda[3];
++ } else {
++ uint32_t rda[2];
++ cpu_physical_memory_read(addr+4, (void *)&rda[0], sizeof(rda));
++ ((uint32_t *)rmd)[0] = rda[1];
++ ((uint32_t *)rmd)[1] = rda[0];
++ ((uint32_t *)rmd)[2] = 0;
+ }
+ }
+
+ static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd, target_phys_addr_t addr)
+ {
++ rmd->rmd1.own = 0;
++ cpu_physical_memory_set_dirty(addr);
+ if (!BCR_SWSTYLE(s)) {
+ uint16_t rda[4]; \
+ rda[0] = ((uint32_t *)rmd)[0] & 0xffff; \
+@@ -349,13 +350,10 @@
+ if (BCR_SWSTYLE(s) != 3)
+ cpu_physical_memory_write(addr, (void *)rmd, 16);
+ else {
+- uint32_t rda[4];
++ uint32_t rda[2];
+ rda[0] = ((uint32_t *)rmd)[2];
+ rda[1] = ((uint32_t *)rmd)[1];
+- rda[2] = ((uint32_t *)rmd)[0];
+- rda[3] = ((uint32_t *)rmd)[3];
+- cpu_physical_memory_write(addr,
+- (void *)&rda[0], sizeof(rda));
++ cpu_physical_memory_write(addr, (void *)&rda[0], sizeof(rda));
+ }
+ }
+ }
+@@ -369,81 +367,16 @@
+
+ #define RMDSTORE(RMD,ADDR) pcnet_rmd_store(s,RMD,ADDR)
+
+-#if 1
+-
+-#define CHECK_RMD(ADDR,RES) do { \
+- struct pcnet_RMD rmd; \
+- RMDLOAD(&rmd,(ADDR)); \
+- (RES) |= (rmd.rmd1.ones != 15) \
+- || (rmd.rmd2.zeros != 0); \
++#define CHECK_RMD(RMD,ADDR,RES) do { \
++ RMDLOAD((RMD),(ADDR)); \
++ (RES) |= ((RMD)->rmd1.ones != 15); \
+ } while (0)
+
+ #define CHECK_TMD(ADDR,RES) do { \
+- struct pcnet_TMD tmd; \
+- TMDLOAD(&tmd,(ADDR)); \
+- (RES) |= (tmd.tmd1.ones != 15); \
++ TMDLOAD(&(s->tmd),(ADDR)); \
++ (RES) |= (s->tmd.tmd1.ones != 15); \
+ } while (0)
+
+-#else
+-
+-#define CHECK_RMD(ADDR,RES) do { \
+- switch (BCR_SWSTYLE(s)) { \
+- case 0x00: \
+- do { \
+- uint16_t rda[4]; \
+- cpu_physical_memory_read((ADDR), \
+- (void *)&rda[0], sizeof(rda)); \
+- (RES) |= (rda[2] & 0xf000)!=0xf000; \
+- (RES) |= (rda[3] & 0xf000)!=0x0000; \
+- } while (0); \
+- break; \
+- case 0x01: \
+- case 0x02: \
+- do { \
+- uint32_t rda[4]; \
+- cpu_physical_memory_read((ADDR), \
+- (void *)&rda[0], sizeof(rda)); \
+- (RES) |= (rda[1] & 0x0000f000L)!=0x0000f000L; \
+- (RES) |= (rda[2] & 0x0000f000L)!=0x00000000L; \
+- } while (0); \
+- break; \
+- case 0x03: \
+- do { \
+- uint32_t rda[4]; \
+- cpu_physical_memory_read((ADDR), \
+- (void *)&rda[0], sizeof(rda)); \
+- (RES) |= (rda[0] & 0x0000f000L)!=0x00000000L; \
+- (RES) |= (rda[1] & 0x0000f000L)!=0x0000f000L; \
+- } while (0); \
+- break; \
+- } \
+-} while (0)
+-
+-#define CHECK_TMD(ADDR,RES) do { \
+- switch (BCR_SWSTYLE(s)) { \
+- case 0x00: \
+- do { \
+- uint16_t xda[4]; \
+- cpu_physical_memory_read((ADDR), \
+- (void *)&xda[0], sizeof(xda)); \
+- (RES) |= (xda[2] & 0xf000)!=0xf000;\
+- } while (0); \
+- break; \
+- case 0x01: \
+- case 0x02: \
+- case 0x03: \
+- do { \
+- uint32_t xda[4]; \
+- cpu_physical_memory_read((ADDR), \
+- (void *)&xda[0], sizeof(xda)); \
+- (RES) |= (xda[1] & 0x0000f000L)!=0x0000f000L; \
+- } while (0); \
+- break; \
+- } \
+-} while (0)
+-
+-#endif
+-
+ #define PRINT_PKTHDR(BUF) do { \
+ struct qemu_ether_header *hdr = (void *)(BUF); \
+ printf("packet dhost=%02x:%02x:%02x:%02x:%02x:%02x, " \
+@@ -662,8 +595,6 @@
+ s->csr[114] = 0x0000;
+ s->csr[122] = 0x0000;
+ s->csr[124] = 0x0000;
+-
+- s->tx_busy = 0;
+ }
+
+ static void pcnet_update_irq(PCNetState *s)
+@@ -737,6 +668,9 @@
+ s->csr[15] = le16_to_cpu(initblk.mode); \
+ CSR_RCVRL(s) = (initblk.rlen < 9) ? (1 << initblk.rlen) : 512; \
+ CSR_XMTRL(s) = (initblk.tlen < 9) ? (1 << initblk.tlen) : 512; \
++ s->crmd.rmd1.own = 0; \
++ s->nrmd.rmd1.own = 0; \
++ s->nnrmd.rmd1.own = 0; \
+ s->csr[ 6] = (initblk.tlen << 12) | (initblk.rlen << 8); \
+ s->csr[ 8] = le16_to_cpu(initblk.ladrf1); \
+ s->csr[ 9] = le16_to_cpu(initblk.ladrf2); \
+@@ -791,6 +725,10 @@
+
+ if (!CSR_DRX(s))
+ s->csr[0] |= 0x0020; /* set RXON */
++ /* flush any cached receive descriptors */
++ s->crmd.rmd1.own = 0;
++ s->nrmd.rmd1.own = 0;
++ s->nnrmd.rmd1.own = 0;
+
+ s->csr[0] &= ~0x0004; /* clear STOP bit */
+ s->csr[0] |= 0x0002;
+@@ -813,29 +751,21 @@
+ s->csr[28] = s->csr[29] = 0;
+ if (s->rdra) {
+ int bad = 0;
+-#if 1
+ target_phys_addr_t crda = pcnet_rdra_addr(s, CSR_RCVRC(s));
+ target_phys_addr_t nrda = pcnet_rdra_addr(s, -1 + CSR_RCVRC(s));
+ target_phys_addr_t nnrd = pcnet_rdra_addr(s, -2 + CSR_RCVRC(s));
+-#else
+- target_phys_addr_t crda = s->rdra +
+- (CSR_RCVRL(s) - CSR_RCVRC(s)) *
+- (BCR_SWSTYLE(s) ? 16 : 8 );
+- int nrdc = CSR_RCVRC(s)<=1 ? CSR_RCVRL(s) : CSR_RCVRC(s)-1;
+- target_phys_addr_t nrda = s->rdra +
+- (CSR_RCVRL(s) - nrdc) *
+- (BCR_SWSTYLE(s) ? 16 : 8 );
+- int nnrc = nrdc<=1 ? CSR_RCVRL(s) : nrdc-1;
+- target_phys_addr_t nnrd = s->rdra +
+- (CSR_RCVRL(s) - nnrc) *
+- (BCR_SWSTYLE(s) ? 16 : 8 );
+-#endif
+
+- CHECK_RMD(PHYSADDR(s,crda), bad);
++ if (!s->crmd.rmd1.own) {
++ CHECK_RMD(&(s->crmd),PHYSADDR(s,crda), bad);
++ }
+ if (!bad) {
+- CHECK_RMD(PHYSADDR(s,nrda), bad);
++ if (s->crmd.rmd1.own && !s->nrmd.rmd1.own) {
++ CHECK_RMD(&(s->nrmd),PHYSADDR(s,nrda), bad);
++ }
+ if (bad || (nrda == crda)) nrda = 0;
+- CHECK_RMD(PHYSADDR(s,nnrd), bad);
++ if (s->crmd.rmd1.own && s->nrmd.rmd1.own && !s->nnrmd.rmd1.own) {
++ CHECK_RMD(&(s->nnrmd),PHYSADDR(s,nnrd), bad);
++ }
+ if (bad || (nnrd == crda)) nnrd = 0;
+
+ s->csr[28] = crda & 0xffff;
+@@ -856,14 +786,12 @@
+ }
+
+ if (CSR_CRDA(s)) {
+- struct pcnet_RMD rmd;
+- RMDLOAD(&rmd, PHYSADDR(s,CSR_CRDA(s)));
+- CSR_CRBC(s) = rmd.rmd1.bcnt;
+- CSR_CRST(s) = ((uint32_t *)&rmd)[1] >> 16;
++ CSR_CRBC(s) = s->crmd.rmd1.bcnt;
++ CSR_CRST(s) = ((uint32_t *)&(s->crmd))[1] >> 16;
+ #ifdef PCNET_DEBUG_RMD_X
+ printf("CRDA=0x%08x CRST=0x%04x RCVRC=%d RMD1=0x%08x RMD2=0x%08x\n",
+ PHYSADDR(s,CSR_CRDA(s)), CSR_CRST(s), CSR_RCVRC(s),
+- ((uint32_t *)&rmd)[1], ((uint32_t *)&rmd)[2]);
++ ((uint32_t *)&(s->crmd))[1], ((uint32_t *)&(s->crmd))[2]);
+ PRINT_RMD(&rmd);
+ #endif
+ } else {
+@@ -871,10 +799,8 @@
+ }
+
+ if (CSR_NRDA(s)) {
+- struct pcnet_RMD rmd;
+- RMDLOAD(&rmd, PHYSADDR(s,CSR_NRDA(s)));
+- CSR_NRBC(s) = rmd.rmd1.bcnt;
+- CSR_NRST(s) = ((uint32_t *)&rmd)[1] >> 16;
++ CSR_NRBC(s) = s->nrmd.rmd1.bcnt;
++ CSR_NRST(s) = ((uint32_t *)&(s->nrmd))[1] >> 16;
+ } else {
+ CSR_NRBC(s) = CSR_NRST(s) = 0;
+ }
+@@ -889,6 +815,7 @@
+ (CSR_XMTRL(s) - CSR_XMTRC(s)) *
+ (BCR_SWSTYLE(s) ? 16 : 8 );
+ int bad = 0;
++ s->csr[0] &= ~0x0008; /* clear TDMD */
+ CHECK_TMD(PHYSADDR(s, cxda),bad);
+ if (!bad) {
+ if (CSR_CXDA(s) != cxda) {
+@@ -907,12 +834,8 @@
+ }
+
+ if (CSR_CXDA(s)) {
+- struct pcnet_TMD tmd;
+-
+- TMDLOAD(&tmd, PHYSADDR(s,CSR_CXDA(s)));
+-
+- CSR_CXBC(s) = tmd.tmd1.bcnt;
+- CSR_CXST(s) = ((uint32_t *)&tmd)[1] >> 16;
++ CSR_CXBC(s) = s->tmd.tmd1.bcnt;
++ CSR_CXST(s) = ((uint32_t *)&(s->tmd))[1] >> 16;
+ } else {
+ CSR_CXBC(s) = CSR_CXST(s) = 0;
+ }
+@@ -925,11 +848,12 @@
+ PCNetState *s = opaque;
+ if (CSR_STOP(s) || CSR_SPND(s))
+ return 0;
+-
+- if (s->recv_pos > 0)
+- return 0;
+
+- return sizeof(s->buffer)-16;
++ if (!(CSR_CRST(s) & 0x8000)) {
++ return 0;
++ }
++
++ return sizeof(s->rx_buffer)-16;
+ }
+
+ #define MIN_BUF_SIZE 60
+@@ -938,7 +862,7 @@
+ {
+ PCNetState *s = opaque;
+ int is_padr = 0, is_bcast = 0, is_ladr = 0;
+- uint8_t buf1[60];
++ int pad;
+
+ if (CSR_DRX(s) || CSR_STOP(s) || CSR_SPND(s) || !size)
+ return;
+@@ -948,12 +872,10 @@
+ #endif
+
+ /* if too small buffer, then expand it */
+- if (size < MIN_BUF_SIZE) {
+- memcpy(buf1, buf, size);
+- memset(buf1 + size, 0, MIN_BUF_SIZE - size);
+- buf = buf1;
+- size = MIN_BUF_SIZE;
+- }
++ if (size < MIN_BUF_SIZE)
++ pad = MIN_BUF_SIZE - size + 4;
++ else
++ pad = 4;
+
+ if (CSR_PROM(s)
+ || (is_padr=padr_match(s, buf, size))
+@@ -962,125 +884,75 @@
+
+ pcnet_rdte_poll(s);
+
+- if (!(CSR_CRST(s) & 0x8000) && s->rdra) {
+- struct pcnet_RMD rmd;
+- int rcvrc = CSR_RCVRC(s)-1,i;
+- target_phys_addr_t nrda;
+- for (i = CSR_RCVRL(s)-1; i > 0; i--, rcvrc--) {
+- if (rcvrc <= 1)
+- rcvrc = CSR_RCVRL(s);
+- nrda = s->rdra +
+- (CSR_RCVRL(s) - rcvrc) *
+- (BCR_SWSTYLE(s) ? 16 : 8 );
+- RMDLOAD(&rmd, PHYSADDR(s,nrda));
+- if (rmd.rmd1.own) {
++ if (size > 2000) {
+ #ifdef PCNET_DEBUG_RMD
+- printf("pcnet - scan buffer: RCVRC=%d PREV_RCVRC=%d\n",
+- rcvrc, CSR_RCVRC(s));
++ printf("pcnet - oversize packet discarded.\n");
+ #endif
+- CSR_RCVRC(s) = rcvrc;
+- pcnet_rdte_poll(s);
+- break;
+- }
+- }
+- }
+-
+- if (!(CSR_CRST(s) & 0x8000)) {
++ } else if (!(CSR_CRST(s) & 0x8000)) {
+ #ifdef PCNET_DEBUG_RMD
+ printf("pcnet - no buffer: RCVRC=%d\n", CSR_RCVRC(s));
+ #endif
+ s->csr[0] |= 0x1000; /* Set MISS flag */
+ CSR_MISSC(s)++;
+ } else {
+- uint8_t *src = &s->buffer[8];
++ uint8_t *src = &s->rx_buffer[8];
+ target_phys_addr_t crda = CSR_CRDA(s);
+- struct pcnet_RMD rmd;
++ target_phys_addr_t nrda = CSR_NRDA(s);
++ target_phys_addr_t nnrda = CSR_NNRD(s);
+ int pktcount = 0;
++ int packet_size = size + pad;
+
+ memcpy(src, buf, size);
+
+-#if 1
+- /* no need to compute the CRC */
+- src[size] = 0;
+- src[size + 1] = 0;
+- src[size + 2] = 0;
+- src[size + 3] = 0;
+- size += 4;
+-#else
+- /* XXX: avoid CRC generation */
+- if (!CSR_ASTRP_RCV(s)) {
+- uint32_t fcs = ~0;
+- uint8_t *p = src;
+-
+- while (size < 46) {
+- src[size++] = 0;
+- }
+-
+- while (p != &src[size]) {
+- CRC(fcs, *p++);
+- }
+- ((uint32_t *)&src[size])[0] = htonl(fcs);
+- size += 4; /* FCS at end of packet */
+- } else size += 4;
+-#endif
++ memset(src + size, 0, pad);
++ size += pad;
+
+ #ifdef PCNET_DEBUG_MATCH
+ PRINT_PKTHDR(buf);
+ #endif
+
+- RMDLOAD(&rmd, PHYSADDR(s,crda));
+- /*if (!CSR_LAPPEN(s))*/
+- rmd.rmd1.stp = 1;
+-
+-#define PCNET_RECV_STORE() do { \
+- int count = MIN(4096 - rmd.rmd1.bcnt,size); \
+- target_phys_addr_t rbadr = PHYSADDR(s, rmd.rmd0.rbadr); \
+- cpu_physical_memory_write(rbadr, src, count); \
+- src += count; size -= count; \
+- rmd.rmd2.mcnt = count; rmd.rmd1.own = 0; \
+- RMDSTORE(&rmd, PHYSADDR(s,crda)); \
+- pktcount++; \
+-} while (0)
+-
+- PCNET_RECV_STORE();
+- if ((size > 0) && CSR_NRDA(s)) {
+- target_phys_addr_t nrda = CSR_NRDA(s);
+- RMDLOAD(&rmd, PHYSADDR(s,nrda));
+- if (rmd.rmd1.own) {
++ s->crmd.rmd1.stp = 1;
++ do {
++ int count = MIN(4096 - s->crmd.rmd1.bcnt,size);
++ target_phys_addr_t rbadr = PHYSADDR(s, s->crmd.rmd0.rbadr);
++ cpu_physical_memory_write(rbadr, src, count);
++ cpu_physical_memory_set_dirty(rbadr);
++ cpu_physical_memory_set_dirty(rbadr+count);
++ src += count; size -= count;
++ if (size > 0 && s->nrmd.rmd1.own) {
++ RMDSTORE(&(s->crmd), PHYSADDR(s,crda));
+ crda = nrda;
+- PCNET_RECV_STORE();
+- if ((size > 0) && (nrda=CSR_NNRD(s))) {
+- RMDLOAD(&rmd, PHYSADDR(s,nrda));
+- if (rmd.rmd1.own) {
+- crda = nrda;
+- PCNET_RECV_STORE();
+- }
+- }
+- }
+- }
+-
+-#undef PCNET_RECV_STORE
++ nrda = nnrda;
++ s->crmd = s->nrmd;
++ s->nrmd = s->nnrmd;
++ s->nnrmd.rmd1.own = 0;
++ }
++ pktcount++;
++ } while (size > 0 && s->crmd.rmd1.own);
+
+- RMDLOAD(&rmd, PHYSADDR(s,crda));
+ if (size == 0) {
+- rmd.rmd1.enp = 1;
+- rmd.rmd1.pam = !CSR_PROM(s) && is_padr;
+- rmd.rmd1.lafm = !CSR_PROM(s) && is_ladr;
+- rmd.rmd1.bam = !CSR_PROM(s) && is_bcast;
++ s->crmd.rmd1.enp = 1;
++ s->crmd.rmd2.mcnt = packet_size;
++ s->crmd.rmd1.pam = !CSR_PROM(s) && is_padr;
++ s->crmd.rmd1.lafm = !CSR_PROM(s) && is_ladr;
++ s->crmd.rmd1.bam = !CSR_PROM(s) && is_bcast;
+ } else {
+- rmd.rmd1.oflo = 1;
+- rmd.rmd1.buff = 1;
+- rmd.rmd1.err = 1;
++ s->crmd.rmd1.oflo = 1;
++ s->crmd.rmd1.buff = 1;
++ s->crmd.rmd1.err = 1;
+ }
+- RMDSTORE(&rmd, PHYSADDR(s,crda));
++ RMDSTORE(&(s->crmd), PHYSADDR(s,crda));
+ s->csr[0] |= 0x0400;
++ s->crmd = s->nrmd;
++ s->nrmd = s->nnrmd;
++ s->nnrmd.rmd1.own = 0;
+
+ #ifdef PCNET_DEBUG
+ printf("RCVRC=%d CRDA=0x%08x BLKS=%d\n",
+ CSR_RCVRC(s), PHYSADDR(s,CSR_CRDA(s)), pktcount);
+ #endif
+ #ifdef PCNET_DEBUG_RMD
+- PRINT_RMD(&rmd);
++ PRINT_RMD(&s->crmd);
+ #endif
+
+ while (pktcount--) {
+@@ -1101,81 +973,86 @@
+
+ static void pcnet_transmit(PCNetState *s)
+ {
+- target_phys_addr_t xmit_cxda = 0;
++ target_phys_addr_t start_addr = 0;
++ struct pcnet_TMD start_tmd;
+ int count = CSR_XMTRL(s)-1;
+- s->xmit_pos = -1;
++ int xmit_pos = 0;
++ int len;
+
+ if (!CSR_TXON(s)) {
+ s->csr[0] &= ~0x0008;
+ return;
+ }
+
+- s->tx_busy = 1;
+-
+- txagain:
+- if (pcnet_tdte_poll(s)) {
+- struct pcnet_TMD tmd;
+-
+- TMDLOAD(&tmd, PHYSADDR(s,CSR_CXDA(s)));
++ while (pcnet_tdte_poll(s)) {
+
+ #ifdef PCNET_DEBUG_TMD
+ printf(" TMDLOAD 0x%08x\n", PHYSADDR(s,CSR_CXDA(s)));
+- PRINT_TMD(&tmd);
++ PRINT_TMD(&(s->tmd));
+ #endif
+- if (tmd.tmd1.stp) {
+- s->xmit_pos = 0;
+- if (!tmd.tmd1.enp) {
+- cpu_physical_memory_read(PHYSADDR(s, tmd.tmd0.tbadr),
+- s->buffer, 4096 - tmd.tmd1.bcnt);
+- s->xmit_pos += 4096 - tmd.tmd1.bcnt;
+- }
+- xmit_cxda = PHYSADDR(s,CSR_CXDA(s));
+- }
+- if (tmd.tmd1.enp && (s->xmit_pos >= 0)) {
+- cpu_physical_memory_read(PHYSADDR(s, tmd.tmd0.tbadr),
+- s->buffer + s->xmit_pos, 4096 - tmd.tmd1.bcnt);
+- s->xmit_pos += 4096 - tmd.tmd1.bcnt;
+-#ifdef PCNET_DEBUG
+- printf("pcnet_transmit size=%d\n", s->xmit_pos);
+-#endif
+- if (CSR_LOOP(s))
+- pcnet_receive(s, s->buffer, s->xmit_pos);
+- else
+- qemu_send_packet(s->vc, s->buffer, s->xmit_pos);
+-
+- s->csr[0] &= ~0x0008; /* clear TDMD */
+- s->csr[4] |= 0x0004; /* set TXSTRT */
+- s->xmit_pos = -1;
+- }
++ len = 4096 - s->tmd.tmd1.bcnt;
++ if (CSR_XMTRC(s) <= 1)
++ CSR_XMTRC(s) = CSR_XMTRL(s);
++ else
++ CSR_XMTRC(s)--;
++ /* handle start followed by start */
++ if (s->tmd.tmd1.stp && start_addr) {
++ TMDSTORE(&start_tmd, start_addr);
++ start_addr = 0;
++ xmit_pos = 0;
++ }
++ if ((xmit_pos + len) < sizeof(s->tx_buffer)) {
++ cpu_physical_memory_read(PHYSADDR(s, s->tmd.tmd0.tbadr),
++ s->tx_buffer + xmit_pos, len);
++ xmit_pos += len;
++ } else {
++ s->tmd.tmd2.buff = s->tmd.tmd2.uflo = s->tmd.tmd1.err = 1;
++ TMDSTORE(&(s->tmd), PHYSADDR(s,CSR_CXDA(s)));
++ if (start_addr == PHYSADDR(s,CSR_CXDA(s)))
++ start_addr = 0; /* don't clear own bit twice */
++ continue;
++ }
++ if (s->tmd.tmd1.stp) {
++ if (s->tmd.tmd1.enp) {
++ if (CSR_LOOP(s))
++ pcnet_receive(s, s->tx_buffer, xmit_pos);
++ else
++ qemu_send_packet(s->vc, s->tx_buffer, xmit_pos);
++
++ s->csr[4] |= 0x0008; /* set TXSTRT */
++ TMDSTORE(&(s->tmd), PHYSADDR(s,CSR_CXDA(s)));
++ xmit_pos = 0;
++ count--;
++ } else {
++ start_tmd = s->tmd;
++ start_addr = PHYSADDR(s,CSR_CXDA(s));
++ }
++ } else if (s->tmd.tmd1.enp) {
++ TMDSTORE(&(s->tmd), PHYSADDR(s,CSR_CXDA(s)));
++ if (start_addr) {
++ TMDSTORE(&start_tmd, start_addr);
++ }
++ start_addr = 0;
++ xmit_pos = 0;
++ count--;
++ } else {
++ TMDSTORE(&(s->tmd), PHYSADDR(s,CSR_CXDA(s)));
++ }
+
+- tmd.tmd1.own = 0;
+- TMDSTORE(&tmd, PHYSADDR(s,CSR_CXDA(s)));
+- if (!CSR_TOKINTD(s) || (CSR_LTINTEN(s) && tmd.tmd1.ltint))
++ if (!CSR_TOKINTD(s) || (CSR_LTINTEN(s) && s->tmd.tmd1.ltint))
+ s->csr[0] |= 0x0200; /* set TINT */
+
+- if (CSR_XMTRC(s)<=1)
+- CSR_XMTRC(s) = CSR_XMTRL(s);
+- else
+- CSR_XMTRC(s)--;
+- if (count--)
+- goto txagain;
+-
+- } else
+- if (s->xmit_pos >= 0) {
+- struct pcnet_TMD tmd;
+- TMDLOAD(&tmd, PHYSADDR(s,xmit_cxda));
+- tmd.tmd2.buff = tmd.tmd2.uflo = tmd.tmd1.err = 1;
+- tmd.tmd1.own = 0;
+- TMDSTORE(&tmd, PHYSADDR(s,xmit_cxda));
+- s->csr[0] |= 0x0200; /* set TINT */
+- if (!CSR_DXSUFLO(s)) {
+- s->csr[0] &= ~0x0010;
+- } else
+- if (count--)
+- goto txagain;
++ if (count <= 0)
++ break;
++ }
++ if (start_addr) {
++ start_tmd.tmd2.buff = start_tmd.tmd2.uflo = start_tmd.tmd1.err = 1;
++ TMDSTORE(&start_tmd, PHYSADDR(s,start_addr));
++ s->csr[0] |= 0x0200; /* set TINT */
++ if (!CSR_DXSUFLO(s)) {
++ s->csr[0] &= ~0x0010;
++ }
+ }
+-
+- s->tx_busy = 0;
+ }
+
+ static void pcnet_poll(PCNetState *s)
+@@ -1186,13 +1063,7 @@
+
+ if (CSR_TDMD(s) ||
+ (CSR_TXON(s) && !CSR_DPOLL(s) && pcnet_tdte_poll(s)))
+- {
+- /* prevent recursion */
+- if (s->tx_busy)
+- return;
+-
+ pcnet_transmit(s);
+- }
+ }
+
+ static void pcnet_poll_timer(void *opaque)
+@@ -1744,10 +1615,9 @@
+ for (i = 0; i < 32; i++)
+ qemu_put_be16s(f, &s->bcr[i]);
+ qemu_put_be64s(f, &s->timer);
+- qemu_put_be32s(f, &s->xmit_pos);
+ qemu_put_be32s(f, &s->recv_pos);
+- qemu_put_buffer(f, s->buffer, 4096);
+- qemu_put_be32s(f, &s->tx_busy);
++ qemu_put_buffer(f, s->tx_buffer, 2048);
++ qemu_put_buffer(f, s->rx_buffer, 2048);
+ qemu_put_timer(f, s->poll_timer);
+ }
+
+@@ -1770,10 +1640,9 @@
+ for (i = 0; i < 32; i++)
+ qemu_get_be16s(f, &s->bcr[i]);
+ qemu_get_be64s(f, &s->timer);
+- qemu_get_be32s(f, &s->xmit_pos);
+ qemu_get_be32s(f, &s->recv_pos);
+- qemu_get_buffer(f, s->buffer, 4096);
+- qemu_get_be32s(f, &s->tx_busy);
++ qemu_get_buffer(f, s->tx_buffer, 2048);
++ qemu_get_buffer(f, s->rx_buffer, 2048);
+ qemu_get_timer(f, s->poll_timer);
+
+ return 0;