diff --git a/arch/x64/xen.cc b/arch/x64/xen.cc
index 5354d91bd2ec5f069b850b4e7d53e1dbfbceaedd..5de3f1824d35399e3cf4d64338227d90d6946554 100644
--- a/arch/x64/xen.cc
+++ b/arch/x64/xen.cc
@@ -108,7 +108,11 @@ static bool xen_pci_enabled()
 }
 
 #define HVM_PARAM_CALLBACK_IRQ 0
-extern "C" void evtchn_irq_is_legacy(void);
+}
+
+void evtchn_irq_is_legacy(void);
+
+namespace xen {
 
 static void xen_ack_irq()
 {
diff --git a/arch/x64/xen_intr.cc b/arch/x64/xen_intr.cc
index c51b0c6c413649e1f3a420e587c7d5a8582b2323..49dec6cf68616fd11ecec8b6b922d527192187dc 100644
--- a/arch/x64/xen_intr.cc
+++ b/arch/x64/xen_intr.cc
@@ -11,10 +11,8 @@
 #include <machine/intr_machdep.h>
 #include "bitops.h"
 
-extern "C" {
-    void unmask_evtchn(int vector);
-    int evtchn_from_irq(int irq);
-}
+void unmask_evtchn(int vector);
+int evtchn_from_irq(int irq);
 
 namespace xen {
 
diff --git a/bsd/machine/xen/synch_bitops.h b/bsd/machine/xen/synch_bitops.h
index 746687aa91bdbd0745cae78e64fcc7db6d1a0ab0..9da2c19c70e8abd4d5544fec58a43a8188c143fc 100644
--- a/bsd/machine/xen/synch_bitops.h
+++ b/bsd/machine/xen/synch_bitops.h
@@ -70,35 +70,35 @@ struct __synch_xchg_dummy { unsigned long a[100]; };
 
 static inline unsigned long __synch_cmpxchg(volatile void *ptr,
 					    unsigned long old,
-					    unsigned long new, int size)
+					    unsigned long neww, int size)
 {
 	unsigned long prev;
 	switch (size) {
 	case 1:
 		__asm__ __volatile__("lock; cmpxchgb %b1,%2"
 				     : "=a"(prev)
-				     : "q"(new), "m"(*__synch_xg(ptr)),
+				     : "q"(neww), "m"(*__synch_xg(ptr)),
 				       "0"(old)
 				     : "memory");
 		return prev;
 	case 2:
 		__asm__ __volatile__("lock; cmpxchgw %w1,%2"
 				     : "=a"(prev)
-				     : "q"(new), "m"(*__synch_xg(ptr)),
+				     : "q"(neww), "m"(*__synch_xg(ptr)),
 				       "0"(old)
 				     : "memory");
 		return prev;
 	case 4:
 		__asm__ __volatile__("lock; cmpxchgl %k1,%2"
 				     : "=a"(prev)
-				     : "q"(new), "m"(*__synch_xg(ptr)),
+				     : "q"(neww), "m"(*__synch_xg(ptr)),
 				       "0"(old)
 				     : "memory");
 		return prev;
 	case 8:
 		__asm__ __volatile__("lock; cmpxchgq %1,%2"
 				     : "=a"(prev)
-				     : "q"(new), "m"(*__synch_xg(ptr)),
+				     : "q"(neww), "m"(*__synch_xg(ptr)),
 				       "0"(old)
 				     : "memory");
 		return prev;
diff --git a/bsd/sys/dev/xen/blkfront/blkfront.c b/bsd/sys/dev/xen/blkfront/blkfront.cc
similarity index 97%
rename from bsd/sys/dev/xen/blkfront/blkfront.c
rename to bsd/sys/dev/xen/blkfront/blkfront.cc
index a694951f1e2d179cd20f56e6afc9e54dcf9f11f9..7b3e02b97fafd0dd792684a3e6559b687261fc41 100644
--- a/bsd/sys/dev/xen/blkfront/blkfront.c
+++ b/bsd/sys/dev/xen/blkfront/blkfront.cc
@@ -27,6 +27,8 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#define __STDC_FORMAT_MACROS
+
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
@@ -215,7 +217,7 @@ blkfront_vdevice_to_unit(uint32_t vdevice, int *unit, const char **name)
 
 struct disk *disk_alloc(void)
 {
-    return malloc(sizeof(struct disk) , 0, 0);
+    return (disk *)malloc(sizeof(struct disk) , 0, 0);
 }
 
 int
@@ -260,7 +262,7 @@ xlvbd_add(struct xb_softc *sc, blkif_sector_t sectors,
 static void
 xb_strategy(struct bio *bp)
 {
-	struct xb_softc	*sc = bp->bio_dev->softc;
+	struct xb_softc	*sc = (xb_softc *)bp->bio_dev->softc;
 
 	/* bogus disk? */
 	if (sc == NULL) {
@@ -343,10 +345,10 @@ xb_dump_complete(struct xb_command *cm)
 }
 
 static int
-xb_dump(void *arg, void *virtual, vm_offset_t physical, off_t offset,
+xb_dump(void *arg, void *vvirtual, vm_offset_t physical, off_t offset,
         size_t length)
 {
-	struct	disk   	*dp = arg;
+	struct	disk   	*dp = (disk *)arg;
 	struct xb_softc	*sc = (struct xb_softc *) dp->d_drv1;
 	struct xb_command *cm;
 	size_t		chunk;
@@ -383,7 +385,7 @@ xb_dump(void *arg, void *virtual, vm_offset_t physical, off_t offset,
 
 		chunk = length > sc->max_request_size
 		      ? sc->max_request_size : length;
-		cm->data = virtual;
+		cm->data = vvirtual;
 		cm->datalen = chunk;
 		cm->operation = BLKIF_OP_WRITE;
 		cm->sector_number = offset / dp->d_sectorsize;
@@ -393,7 +395,7 @@ xb_dump(void *arg, void *virtual, vm_offset_t physical, off_t offset,
 
 		length -= chunk;
 		offset += chunk;
-		virtual = (char *) virtual + chunk;
+		vvirtual = (char *) vvirtual + chunk;
 	}
 
 	/* Tell DOM0 to do the I/O */
@@ -505,7 +507,7 @@ blkfront_attach(device_t dev)
 	if (!strcmp(name, "vblk"))
 		device_set_unit(dev, unit);
 
-	sc = device_get_softc(dev);
+	sc = (xb_softc *)device_get_softc(dev);
 	mtx_init(&sc->xb_io_lock, "blkfront i/o lock", NULL, MTX_DEF);
 	xb_initq_free(sc);
 	xb_initq_busy(sc);
@@ -531,7 +533,7 @@ blkfront_attach(device_t dev)
 static int
 blkfront_suspend(device_t dev)
 {
-	struct xb_softc *sc = device_get_softc(dev);
+	struct xb_softc *sc = (xb_softc *)device_get_softc(dev);
 	int retval;
 	int saved_state;
 
@@ -560,7 +562,7 @@ blkfront_suspend(device_t dev)
 static int
 blkfront_resume(device_t dev)
 {
-	struct xb_softc *sc = device_get_softc(dev);
+	struct xb_softc *sc = (xb_softc *)device_get_softc(dev);
 
 	DPRINTK("blkfront_resume: %s\n", xenbus_get_node(dev));
 
@@ -704,7 +706,7 @@ blkfront_initialize(struct xb_softc *sc)
 	}
 
 	/* Per-transaction data allocation. */
-	sc->shadow = malloc(sizeof(*sc->shadow) * sc->max_requests,
+	sc->shadow = (xb_command *)malloc(sizeof(*sc->shadow) * sc->max_requests,
 			    M_XENBLOCKFRONT, M_NOWAIT|M_ZERO);
 	if (sc->shadow == NULL) {
 		bus_dma_tag_destroy(sc->xb_io_dmat);
@@ -717,7 +719,7 @@ blkfront_initialize(struct xb_softc *sc)
 		struct xb_command *cm;
 
 		cm = &sc->shadow[i];
-		cm->sg_refs = malloc(sizeof(grant_ref_t)
+		cm->sg_refs = (grant_ref_t *)malloc(sizeof(grant_ref_t)
 				   * sc->max_request_segments,
 				     M_XENBLOCKFRONT, M_NOWAIT);
 		if (cm->sg_refs == NULL)
@@ -810,7 +812,7 @@ setup_blkring(struct xb_softc *sc)
 	int error;
 	int i;
 
-	sring = malloc(sc->ring_pages * PAGE_SIZE, M_XENBLOCKFRONT,
+	sring = (blkif_sring_t *)malloc(sc->ring_pages * PAGE_SIZE, M_XENBLOCKFRONT,
 		       M_NOWAIT|M_ZERO);
 	if (sring == NULL) {
 		xenbus_dev_fatal(sc->xb_dev, ENOMEM, "allocating shared ring");
@@ -877,7 +879,7 @@ setup_blkring(struct xb_softc *sc)
 static void
 blkfront_backend_changed(device_t dev, XenbusState backend_state)
 {
-	struct xb_softc *sc = device_get_softc(dev);
+	struct xb_softc *sc = (xb_softc *)device_get_softc(dev);
 
 	DPRINTK("backend_state=%d\n", backend_state);
 
@@ -983,7 +985,7 @@ blkfront_connect(struct xb_softc *sc)
 static void
 blkfront_closing(device_t dev)
 {
-	struct xb_softc *sc = device_get_softc(dev);
+	struct xb_softc *sc = (xb_softc *)device_get_softc(dev);
 
 	xenbus_set_state(dev, XenbusStateClosing);
 
@@ -1001,7 +1003,7 @@ blkfront_closing(device_t dev)
 static int
 blkfront_detach(device_t dev)
 {
-	struct xb_softc *sc = device_get_softc(dev);
+	struct xb_softc *sc = (xb_softc *)device_get_softc(dev);
 
 	DPRINTK("blkfront_remove: %s removed\n", xenbus_get_node(dev));
 
@@ -1026,7 +1028,7 @@ flush_requests(struct xb_softc *sc)
 static void
 blkif_restart_queue_callback(void *arg)
 {
-	struct xb_softc *sc = arg;
+	struct xb_softc *sc = (xb_softc *)arg;
 
 	mtx_lock(&sc->xb_io_lock);
 
@@ -1195,7 +1197,7 @@ blkif_queue_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
 	int op;
 	int block_segs;
 
-	cm = arg;
+	cm = (xb_command *)arg;
 	sc = cm->cm_sc;
 
 //printf("%s: Start\n", __func__);
@@ -1333,7 +1335,7 @@ xb_startio(struct xb_softc *sc)
 static void
 blkif_int(void *xsc)
 {
-	struct xb_softc *sc = xsc;
+	struct xb_softc *sc = (xb_softc *)xsc;
 	struct xb_command *cm;
 	blkif_response_t *bret;
 	RING_IDX i, rp;
diff --git a/bsd/sys/dev/xen/netfront/netfront.c b/bsd/sys/dev/xen/netfront/netfront.cc
similarity index 98%
rename from bsd/sys/dev/xen/netfront/netfront.c
rename to bsd/sys/dev/xen/netfront/netfront.cc
index 57517fdea714d61f86eca75ef7e3d85a4c872789..41eed3c8b59d8da58f9014163f09d04907b5324d 100644
--- a/bsd/sys/dev/xen/netfront/netfront.c
+++ b/bsd/sys/dev/xen/netfront/netfront.cc
@@ -496,7 +496,7 @@ netfront_attach(device_t dev)
 static int
 netfront_suspend(device_t dev)
 {
-	struct netfront_info *info = device_get_softc(dev);
+	struct netfront_info *info = (netfront_info *)device_get_softc(dev);
 
 	XN_RX_LOCK(info);
 	XN_TX_LOCK(info);
@@ -515,7 +515,7 @@ netfront_suspend(device_t dev)
 static int
 netfront_resume(device_t dev)
 {
-	struct netfront_info *info = device_get_softc(dev);
+	struct netfront_info *info = (netfront_info *)device_get_softc(dev);
 
 	netif_disconnect_backend(info);
 	return (0);
@@ -693,7 +693,7 @@ netfront_send_fake_arp(device_t dev, struct netfront_info *info)
 static void
 netfront_backend_changed(device_t dev, XenbusState newstate)
 {
-	struct netfront_info *sc = device_get_softc(dev);
+	struct netfront_info *sc = (netfront_info *)device_get_softc(dev);
 		
 	DPRINTK("newstate=%d\n", newstate);
 
@@ -1212,7 +1212,7 @@ xn_txeof(struct netfront_info *np)
 static void
 xn_intr(void *xsc)
 {
-	struct netfront_info *np = xsc;
+	struct netfront_info *np = (netfront_info *)xsc;
 	struct ifnet *ifp = np->xn_ifp;
 
 #if 0
@@ -1240,12 +1240,12 @@ static void
 xennet_move_rx_slot(struct netfront_info *np, struct mbuf *m,
 	grant_ref_t ref)
 {
-	int new = xennet_rxidx(np->rx.req_prod_pvt);
+	int neww = xennet_rxidx(np->rx.req_prod_pvt);
 
-	KASSERT(np->rx_mbufs[new] == NULL, ("rx_mbufs != NULL"));
-	np->rx_mbufs[new] = m;
-	np->grant_rx_ref[new] = ref;
-	RING_GET_REQUEST(&np->rx, np->rx.req_prod_pvt)->id = new;
+	KASSERT(np->rx_mbufs[neww] == NULL, ("rx_mbufs != NULL"));
+	np->rx_mbufs[neww] = m;
+	np->grant_rx_ref[neww] = ref;
+	RING_GET_REQUEST(&np->rx, np->rx.req_prod_pvt)->id = neww;
 	RING_GET_REQUEST(&np->rx, np->rx.req_prod_pvt)->gref = ref;
 	np->rx.req_prod_pvt++;
 }
@@ -1468,7 +1468,7 @@ xn_tick(void *xsc)
 {
 	struct netfront_info *sc;
     
-	sc = xsc;
+	sc = (netfront_info *)xsc;
 	XN_RX_LOCK(sc);
 	xn_tick_locked(sc);
 	XN_RX_UNLOCK(sc);
@@ -1671,7 +1671,7 @@ xn_start_locked(struct ifnet *ifp)
 	struct mbuf *m_head;
 	int notify;
 
-	sc = ifp->if_softc;
+	sc = (netfront_info *)ifp->if_softc;
 
 	if (!netfront_carrier_ok(sc))
 		return;
@@ -1706,7 +1706,7 @@ static void
 xn_start(struct ifnet *ifp)
 {
 	struct netfront_info *sc;
-	sc = ifp->if_softc;
+	sc = (netfront_info *)ifp->if_softc;
 	XN_TX_LOCK(sc);
 	xn_start_locked(ifp);
 	XN_TX_UNLOCK(sc);
@@ -1740,7 +1740,7 @@ xn_ifinit_locked(struct netfront_info *sc)
 static void 
 xn_ifinit(void *xsc)
 {
-	struct netfront_info *sc = xsc;
+	struct netfront_info *sc = (netfront_info *)xsc;
     
 	XN_LOCK(sc);
 	xn_ifinit_locked(sc);
@@ -1750,7 +1750,7 @@ xn_ifinit(void *xsc)
 static int
 xn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
 {
-	struct netfront_info *sc = ifp->if_softc;
+	struct netfront_info *sc = (netfront_info *)ifp->if_softc;
 	struct bsd_ifreq *ifr = (struct bsd_ifreq *) data;
 #ifdef INET
 	struct bsd_ifaddr *ifa = (struct bsd_ifaddr *)data;
@@ -2076,7 +2076,7 @@ create_netdev(device_t dev)
 	int err;
 	struct ifnet *ifp;
 
-	np = device_get_softc(dev);
+	np = (netfront_info *)device_get_softc(dev);
 	
 	np->xbdev         = dev;
     
@@ -2092,10 +2092,10 @@ create_netdev(device_t dev)
 
 	/* Initialise {tx,rx}_skbs to be a free chain containing every entry. */
 	for (i = 0; i <= NET_TX_RING_SIZE; i++) {
-		np->tx_mbufs[i] = (void *) ((u_long) i+1);
+		np->tx_mbufs[i] = (mbuf *) ((u_long) i+1);
 		np->grant_tx_ref[i] = GRANT_REF_INVALID;	
 	}
-	np->tx_mbufs[NET_TX_RING_SIZE] = (void *)0;
+	np->tx_mbufs[NET_TX_RING_SIZE] = (mbuf *)0;
 
 	for (i = 0; i <= NET_RX_RING_SIZE; i++) {
 
@@ -2175,7 +2175,7 @@ netfront_closing(device_t dev)
 static int
 netfront_detach(device_t dev)
 {
-	struct netfront_info *info = device_get_softc(dev);
+	struct netfront_info *info = (netfront_info *)device_get_softc(dev);
 
 	DPRINTK("%s\n", xenbus_get_node(dev));
 
@@ -2214,7 +2214,7 @@ netif_disconnect_backend(struct netfront_info *info)
 static void
 free_ring(grant_ref_t *ref, void *ring_ptr_ref)
 {
-	void **ring_ptr_ptr = ring_ptr_ref;
+	void **ring_ptr_ptr = (void **)ring_ptr_ref;
 
 	if (*ref != GRANT_REF_INVALID) {
 		/* This API frees the associated storage. */
diff --git a/bsd/sys/net/if_media.h b/bsd/sys/net/if_media.h
index cb31dccfc1ebabd8e8a26b71db1ca9b8fe4656c7..f19d9113210f31497b83ec7b3bddbf61c748ff78 100644
--- a/bsd/sys/net/if_media.h
+++ b/bsd/sys/net/if_media.h
@@ -52,6 +52,7 @@
 
 #ifdef _KERNEL
 
+#include <sys/cdefs.h>
 #include <sys/queue.h>
 
 /*
@@ -83,6 +84,8 @@ struct ifmedia {
 	ifm_stat_cb_t	ifm_status;	/* media status driver callback */
 };
 
+__BEGIN_DECLS
+
 /* Initialize an interface's struct if_media field. */
 void	ifmedia_init(struct ifmedia *ifm, int dontcare_mask,
 	    ifm_change_cb_t change_callback, ifm_stat_cb_t status_callback);
@@ -107,6 +110,8 @@ int	ifmedia_ioctl(struct ifnet *ifp, struct bsd_ifreq *ifr,
 /* Compute baudrate for a given media. */
 uint64_t	ifmedia_baudrate(int);
 
+__END_DECLS
+
 #endif /*_KERNEL */
 
 /*
diff --git a/bsd/sys/sys/disk.h b/bsd/sys/sys/disk.h
index 112eed0747b2861471445c38bfb793e2a46ae053..80b00df51bfdc9ceb241646426060b6fd250bd35 100644
--- a/bsd/sys/sys/disk.h
+++ b/bsd/sys/sys/disk.h
@@ -17,12 +17,19 @@
 
 #ifdef _KERNEL
 
+#include <sys/cdefs.h>
+
+
 #ifndef _SYS_CONF_H_
 #include <sys/conf.h>	/* XXX: temporary to avoid breakage */
 #endif
 
+__BEGIN_DECLS
+
 void disk_err(struct bio *bp, const char *what, int blkdone, int nl);
 
+__END_DECLS
+
 #endif
 
 #define	DIOCGSECTORSIZE	_IOR('d', 128, u_int)
diff --git a/bsd/sys/sys/taskqueue.h b/bsd/sys/sys/taskqueue.h
index 810b757f0463cb864e1dfaf1589aea0e374b6adb..2a630760297d9d6011cdcb74f82f9a37fa286fe6 100644
--- a/bsd/sys/sys/taskqueue.h
+++ b/bsd/sys/sys/taskqueue.h
@@ -33,10 +33,14 @@
 #error "no user-servicable parts inside"
 #endif
 
+#include <sys/cdefs.h>
+
 #include <bsd/sys/sys/queue.h>
 #include <bsd/sys/sys/_task.h>
 //#include <sys/_callout.h>
 
+__BEGIN_DECLS
+
 struct taskqueue;
 struct thread;
 
@@ -151,4 +155,6 @@ TASKQUEUE_DEFINE(name, taskqueue_thread_enqueue, &taskqueue_##name,	\
  */
 TASKQUEUE_DECLARE(thread);
 
+__END_DECLS
+
 #endif /* !_SYS_TASKQUEUE_H_ */
diff --git a/bsd/sys/xen/evtchn.c b/bsd/sys/xen/evtchn.cc
similarity index 96%
rename from bsd/sys/xen/evtchn.c
rename to bsd/sys/xen/evtchn.cc
index d011d4b4d42e1fde394544ea703a289052ccfac2..cd8d415168f7e8d2a904abf7bbaeb9fbc29fba5c 100644
--- a/bsd/sys/xen/evtchn.c
+++ b/bsd/sys/xen/evtchn.cc
@@ -480,7 +480,7 @@ bind_caller_port_to_irqhandler(unsigned int caller_port,
 
 	irq = bind_caller_port_to_irq(caller_port, &port);
 	intr_register_source(&xp->xp_pins[irq].xp_intsrc);
-	error = intr_add_handler(devname, irq, NULL, handler, arg, irqflags,
+	error = intr_add_handler(devname, irq, NULL, handler, arg, intr_type(irqflags),
 	    &xp->xp_pins[irq].xp_cookie);
 
 	if (error) {
@@ -507,7 +507,7 @@ bind_listening_port_to_irqhandler(unsigned int remote_domain,
 
 	irq = bind_listening_port_to_irq(remote_domain, &port);
 	intr_register_source(&xp->xp_pins[irq].xp_intsrc);
-	error = intr_add_handler(devname, irq, NULL, handler, arg, irqflags,
+	error = intr_add_handler(devname, irq, NULL, handler, arg, intr_type(irqflags),
 	    &xp->xp_pins[irq].xp_cookie);
 	if (error) {
 		unbind_from_irq(irq);
@@ -534,7 +534,7 @@ bind_interdomain_evtchn_to_irqhandler(unsigned int remote_domain,
 	irq = bind_interdomain_evtchn_to_irq(remote_domain, remote_port, &port);
 	intr_register_source(&xp->xp_pins[irq].xp_intsrc);
 	error = intr_add_handler(devname, irq, NULL, handler, arg,
-	    irqflags, &xp->xp_pins[irq].xp_cookie);
+	    intr_type(irqflags), &xp->xp_pins[irq].xp_cookie);
 	if (error) {
 		unbind_from_irq(irq);
 		return (error);
@@ -559,7 +559,7 @@ bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu,
 	irq = bind_virq_to_irq(virq, cpu, &port);
 	intr_register_source(&xp->xp_pins[irq].xp_intsrc);
 	error = intr_add_handler(devname, irq, filter, handler,
-	    arg, irqflags, &xp->xp_pins[irq].xp_cookie);
+	    arg, intr_type(irqflags), &xp->xp_pins[irq].xp_cookie);
 	if (error) {
 		unbind_from_irq(irq);
 		return (error);
@@ -584,7 +584,7 @@ bind_ipi_to_irqhandler(unsigned int ipi, unsigned int cpu,
 	irq = bind_ipi_to_irq(ipi, cpu, &port);
 	intr_register_source(&xp->xp_pins[irq].xp_intsrc);
 	error = intr_add_handler(devname, irq, filter, NULL,
-	    NULL, irqflags, &xp->xp_pins[irq].xp_cookie);
+	    NULL, intr_type(irqflags), &xp->xp_pins[irq].xp_cookie);
 	if (error) {
 		unbind_from_irq(irq);
 		return (error);
@@ -683,17 +683,17 @@ struct pic xenpic_dynirq_template  =  {
 	.pic_resume		=	xenpic_resume 
 };
 
-struct pic xenpic_pirq_template  =  { 
-	.pic_enable_source	=	xenpic_pirq_enable_source, 
-	.pic_disable_source	=	xenpic_pirq_disable_source,
-	.pic_eoi_source		=	xenpic_pirq_eoi_source, 
-	.pic_enable_intr	=	xenpic_pirq_enable_intr, 
-	.pic_vector		=	xenpic_vector, 
-	.pic_source_pending	=	xenpic_source_pending,
-	.pic_suspend		=	xenpic_suspend, 
-	.pic_resume		=	xenpic_resume,
-	.pic_assign_cpu		=	xenpic_assign_cpu
-};
+struct pic xenpic_pirq_template  = initialize_with([] (pic& x) {
+	x.pic_enable_source	=	xenpic_pirq_enable_source;
+	x.pic_disable_source	=	xenpic_pirq_disable_source;
+	x.pic_eoi_source	=	xenpic_pirq_eoi_source;
+	x.pic_enable_intr	=	xenpic_pirq_enable_intr;
+	x.pic_vector		=	xenpic_vector;
+	x.pic_source_pending	=	xenpic_source_pending;
+	x.pic_suspend		=	xenpic_suspend;
+	x.pic_resume		=	xenpic_resume;
+	x.pic_assign_cpu	=	xenpic_assign_cpu;
+});
 
 
 
@@ -1107,7 +1107,7 @@ evtchn_init(void *dummy __unused)
 	for (i = 0; i < NR_IRQS; i++)
 		irq_info[i] = IRQ_UNBOUND;
 	
-	xp = malloc(sizeof(struct xenpic) + NR_IRQS*sizeof(struct xenpic_intsrc), 
+	xp = (xenpic *)malloc(sizeof(struct xenpic) + NR_IRQS*sizeof(struct xenpic_intsrc),
 		    M_DEVBUF, M_WAITOK);
 
 	xp->xp_dynirq_pic = &xenpic_dynirq_template;
diff --git a/bsd/sys/xen/gnttab.c b/bsd/sys/xen/gnttab.cc
similarity index 98%
rename from bsd/sys/xen/gnttab.c
rename to bsd/sys/xen/gnttab.cc
index ec1fcfc97bd8b634da6a896a60ac9306aa3237fa..5dd838d032b123c6db18e2d386da31793ed86172 100644
--- a/bsd/sys/xen/gnttab.c
+++ b/bsd/sys/xen/gnttab.cc
@@ -596,7 +596,7 @@ gnttab_resume(void)
 		return (ENOSYS);
 
 	if (shared == NULL) {
-		shared = malloc(PAGE_SIZE * max_nr_grant_frames(), 0, 0);
+		shared = (grant_entry_t *)malloc(PAGE_SIZE * max_nr_grant_frames(), 0, 0);
 		if (!shared) {
 			printf("can't allocate VM space for grant table");
 			return (ENOMEM);
@@ -647,7 +647,7 @@ gnttab_init()
 			       GREFS_PER_GRANT_FRAME /
 			       (PAGE_SIZE / sizeof(grant_ref_t)));
 
-	gnttab_list = malloc(max_nr_glist_frames * sizeof(grant_ref_t *),
+	gnttab_list = (grant_ref_t **)malloc(max_nr_glist_frames * sizeof(grant_ref_t *),
 	    M_DEVBUF, M_NOWAIT);
 
 	if (gnttab_list == NULL)
diff --git a/bsd/sys/xen/hypervisor.h b/bsd/sys/xen/hypervisor.h
index 5b554b528d88ebdbbda3cf30c5013bb9025a867d..5e3a1ff891226e1ef9e179a5190865d018e9abad 100644
--- a/bsd/sys/xen/hypervisor.h
+++ b/bsd/sys/xen/hypervisor.h
@@ -28,6 +28,7 @@
 #endif
 
 #include <sys/cdefs.h>
+#include <osv/initialize.hh>
 //#include <sys/systm.h>
 #include <xen/interface/xen.h>
 #include <xen/interface/platform.h>
@@ -118,10 +119,10 @@ HYPERVISOR_poll(
 	evtchn_port_t *ports, unsigned int nr_ports, int ticks)
 {
 	int rc;
-	struct sched_poll sched_poll = {
-		.nr_ports = nr_ports,
-		.timeout = get_system_time(ticks)
-	};
+	struct sched_poll sched_poll = initialize_with([=] (struct sched_poll& x) {
+		x.nr_ports = nr_ports;
+		x.timeout = get_system_time(ticks);
+	});
 	set_xen_guest_handle(sched_poll.ports, ports);
 
 	rc = HYPERVISOR_sched_op(SCHEDOP_poll, &sched_poll);
diff --git a/bsd/sys/xen/xenbus/xenbus.c b/bsd/sys/xen/xenbus/xenbus.cc
similarity index 97%
rename from bsd/sys/xen/xenbus/xenbus.c
rename to bsd/sys/xen/xenbus/xenbus.cc
index 4d0be5dcaebffadb00bb2e211cb141939e5c6930..ec30ba0e97311ed45ef7028ae50310bee6b1410c 100644
--- a/bsd/sys/xen/xenbus/xenbus.c
+++ b/bsd/sys/xen/xenbus/xenbus.cc
@@ -74,7 +74,7 @@ MALLOC_DEFINE(M_XENBUS, "xenbus", "XenBus Support");
 static char *
 error_path(device_t dev)
 {
-	char *path_buffer = malloc(strlen("error/")
+	char *path_buffer = (char *)malloc(strlen("error/")
 	    + strlen(xenbus_get_node(dev)) + 1,M_XENBUS, M_WAITOK);
 
 	strcpy(path_buffer, "error/");
@@ -128,7 +128,7 @@ xenbus_watch_path2(device_t dev, const char *path,
     xs_watch_cb_t *callback, uintptr_t callback_data)
 {
 	int error;
-	char *state = malloc(strlen(path) + 1 + strlen(path2) + 1,
+	char *state = (char *)malloc(strlen(path) + 1 + strlen(path2) + 1,
 	   M_XENBUS, M_WAITOK);
 
 	strcpy(state, path);
@@ -151,7 +151,7 @@ xenbus_dev_verror(device_t dev, int err, const char *fmt, va_list ap)
 	char *printf_buffer = NULL, *path_buffer = NULL;
 
 #define PRINTF_BUFFER_SIZE 4096
-	printf_buffer = malloc(PRINTF_BUFFER_SIZE,M_XENBUS, M_WAITOK);
+	printf_buffer = (char *)malloc(PRINTF_BUFFER_SIZE,M_XENBUS, M_WAITOK);
 
 	len = sprintf(printf_buffer, "%i ", err);
 	ret = vsnprintf(printf_buffer+len, PRINTF_BUFFER_SIZE-len, fmt, ap);
diff --git a/bsd/sys/xen/xenbus/xenbusb.c b/bsd/sys/xen/xenbus/xenbusb.cc
similarity index 95%
rename from bsd/sys/xen/xenbus/xenbusb.c
rename to bsd/sys/xen/xenbus/xenbusb.cc
index 4fd0fe4b369d3b193f5f62d7c6f512f16c76c766..07b1301b6685fc1feef32b276b5066311fdd8ff5 100644
--- a/bsd/sys/xen/xenbus/xenbusb.c
+++ b/bsd/sys/xen/xenbus/xenbusb.cc
@@ -214,7 +214,7 @@ xenbusb_device_exists(device_t dev, const char *node)
 
 	result = NULL;
 	for (i = 0; i < count; i++) {
-		ivars = device_get_ivars(kids[i]);
+		ivars = (xenbus_device_ivars *)device_get_ivars(kids[i]);
 		if (!strcmp(ivars->xd_node, node)) {
 			result = kids[i];
 			break;
@@ -230,7 +230,7 @@ xenbusb_delete_child(device_t dev, device_t child)
 {
 	struct xenbus_device_ivars *ivars;
 
-	ivars = device_get_ivars(child);
+	ivars = (xenbus_device_ivars *)device_get_ivars(child);
 
 	/*
 	 * We no longer care about the otherend of the
@@ -470,7 +470,7 @@ xenbusb_probe_children(device_t dev)
 			 * that can receive otherend state change events,
 			 * hook up a watch for them.
 			 */
-			ivars = device_get_ivars(kids[i]);
+			ivars = (xenbus_device_ivars *)device_get_ivars(kids[i]);
 			xs_register_watch(&ivars->xd_otherend_watch);
 			xs_register_watch(&ivars->xd_local_watch);
 		}
@@ -599,7 +599,7 @@ xenbusb_release_confighook(struct xenbusb_softc *xbs)
 	xbs->xbs_connecting_children--;
 	if (xbs->xbs_connecting_children == 0
 	 && (xbs->xbs_flags & XBS_ATTACH_CH_ACTIVE) != 0) {
-		xbs->xbs_flags &= ~XBS_ATTACH_CH_ACTIVE;
+		xbs->xbs_flags = xenbusb_softc_flag(xbs->xbs_flags & ~XBS_ATTACH_CH_ACTIVE);
 		mtx_unlock(&xbs->xbs_lock);
 		config_intrhook_disestablish(&xbs->xbs_attach_ch);
 	} else {
@@ -628,13 +628,13 @@ xenbusb_add_device(device_t dev, const char *type, const char *id)
 	struct xenbus_device_ivars *ivars;
 	int error;
 
-	xbs = device_get_softc(dev);
+	xbs = (xenbusb_softc *)device_get_softc(dev);
 	devpath_sbuf = sbuf_new_auto();
 	sbuf_printf(devpath_sbuf, "%s/%s/%s", xbs->xbs_node, type, id);
 	sbuf_finish(devpath_sbuf);
 	devpath = sbuf_data(devpath_sbuf);
 
-	ivars = malloc(sizeof(*ivars), M_XENBUS, M_ZERO|M_WAITOK);
+	ivars = (xenbus_device_ivars *)malloc(sizeof(*ivars), M_XENBUS, M_ZERO|M_WAITOK);
 	error = ENXIO;
 
 	if (xs_exists(XST_NIL, devpath, "") != 0) {
@@ -678,7 +678,7 @@ xenbusb_add_device(device_t dev, const char *type, const char *id)
 			goto out;
 		}
 
-		statepath = malloc(ivars->xd_otherend_path_len
+		statepath = (char *)malloc(ivars->xd_otherend_path_len
 		    + strlen("/state") + 1, M_XENBUS, M_WAITOK);
 		sprintf(statepath, "%s/state", ivars->xd_otherend_path);
 		ivars->xd_otherend_watch.node = statepath;
@@ -713,7 +713,7 @@ xenbusb_attach(device_t dev, char *bus_node, u_int id_components)
 {
 	struct xenbusb_softc *xbs;
 
-	xbs = device_get_softc(dev);
+	xbs = (xenbusb_softc *)device_get_softc(dev);
 	mtx_init(&xbs->xbs_lock, "xenbusb softc lock", NULL, MTX_DEF);
 	xbs->xbs_node = bus_node;
 	xbs->xbs_id_components = id_components;
@@ -731,7 +731,7 @@ xenbusb_attach(device_t dev, char *bus_node, u_int id_components)
 	xbs->xbs_attach_ch.ich_func = xenbusb_nop_confighook_cb;
 	xbs->xbs_attach_ch.ich_arg = dev;
 	config_intrhook_establish(&xbs->xbs_attach_ch);
-	xbs->xbs_flags |= XBS_ATTACH_CH_ACTIVE;
+	xbs->xbs_flags = xenbusb_softc_flag(xbs->xbs_flags | XBS_ATTACH_CH_ACTIVE);
 	xbs->xbs_connecting_children = 1;
 
 	/*
@@ -775,7 +775,7 @@ xenbusb_resume(device_t dev)
 			if (device_get_state(kids[i]) == DS_NOTPRESENT)
 				continue;
 
-			ivars = device_get_ivars(kids[i]);
+			ivars = (xenbus_device_ivars *)device_get_ivars(kids[i]);
 
 			xs_unregister_watch(&ivars->xd_otherend_watch);
 			xenbus_set_state(kids[i], XenbusStateInitialising);
@@ -788,7 +788,7 @@ xenbusb_resume(device_t dev)
 			if (error)
 				return (error);
 
-			statepath = malloc(ivars->xd_otherend_path_len
+			statepath = (char *)malloc(ivars->xd_otherend_path_len
 			    + strlen("/state") + 1, M_XENBUS, M_WAITOK);
 			sprintf(statepath, "%s/state", ivars->xd_otherend_path);
 
@@ -822,7 +822,7 @@ xenbusb_resume(device_t dev)
 int
 xenbusb_print_child(device_t dev, device_t child)
 {
-	struct xenbus_device_ivars *ivars = device_get_ivars(child);
+	struct xenbus_device_ivars *ivars = (xenbus_device_ivars *)device_get_ivars(child);
 	int	retval = 0;
 
 	retval += bus_print_child_header(dev, child);
@@ -835,7 +835,7 @@ xenbusb_print_child(device_t dev, device_t child)
 int
 xenbusb_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
 {
-	struct xenbus_device_ivars *ivars = device_get_ivars(child);
+	struct xenbus_device_ivars *ivars = (xenbus_device_ivars *)device_get_ivars(child);
 
 	switch (index) {
 	case XENBUS_IVAR_NODE:
@@ -865,7 +865,7 @@ xenbusb_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
 int
 xenbusb_write_ivar(device_t dev, device_t child, int index, uintptr_t value)
 {
-	struct xenbus_device_ivars *ivars = device_get_ivars(child);
+	struct xenbus_device_ivars *ivars = (xenbus_device_ivars *)device_get_ivars(child);
 	enum xenbus_state newstate;
 	int currstate;
 
@@ -908,8 +908,8 @@ xenbusb_write_ivar(device_t dev, device_t child, int index, uintptr_t value)
 		  || newstate == XenbusStateConnected)) {
 			struct xenbusb_softc *xbs;
 
-			ivars->xd_flags &= ~XDF_CONNECTING;
-			xbs = device_get_softc(dev);
+			ivars->xd_flags = xenbus_dev_flag(ivars->xd_flags & ~XDF_CONNECTING);
+			xbs = (xenbusb_softc *)device_get_softc(dev);
 			xenbusb_release_confighook(xbs);
 		}
 
@@ -945,7 +945,7 @@ xenbusb_localend_changed(device_t bus, device_t child, const char *path)
 	if (strcmp(path, "/state") != 0) {
 		struct xenbus_device_ivars *ivars;
 
-		ivars = device_get_ivars(child);
+		ivars = (xenbus_device_ivars *)device_get_ivars(child);
 		sx_xlock(&ivars->xd_lock);
 		ivars->xd_state = xenbus_read_driver_state(ivars->xd_node);
 		sx_xunlock(&ivars->xd_lock);
diff --git a/bsd/sys/xen/xenbus/xenbusb_front.c b/bsd/sys/xen/xenbus/xenbusb_front.cc
similarity index 99%
rename from bsd/sys/xen/xenbus/xenbusb_front.c
rename to bsd/sys/xen/xenbus/xenbusb_front.cc
index 8e5ee6b54f6c4426c39aba3fe1a8af03dce0a7d6..3677b7ad07ba7acf4e4e1fa1229f926e1c206152 100644
--- a/bsd/sys/xen/xenbus/xenbusb_front.c
+++ b/bsd/sys/xen/xenbus/xenbusb_front.cc
@@ -114,7 +114,7 @@ xenbusb_front_enumerate_type(device_t dev, const char *type)
 	unsigned int i, count;
 	int error;
 
-	xbs = device_get_softc(dev);
+	xbs = (xenbusb_softc *)device_get_softc(dev);
 	error = xs_directory(XST_NIL, xbs->xbs_node, type, &count, &dir);
 	if (error)
 		return (error);
diff --git a/bsd/sys/xen/xenstore/xenstore.c b/bsd/sys/xen/xenstore/xenstore.cc
similarity index 98%
rename from bsd/sys/xen/xenstore/xenstore.c
rename to bsd/sys/xen/xenstore/xenstore.cc
index 31c351cb5e263328707b0f42eb5d8367def46a5a..b5d572b9b036af7f3089d6a8986cb6c0cbc387db 100644
--- a/bsd/sys/xen/xenstore/xenstore.c
+++ b/bsd/sys/xen/xenstore/xenstore.cc
@@ -340,7 +340,7 @@ split(char *strings, u_int len, u_int *num)
 	*num = extract_strings(strings, /*dest*/NULL, len);
 
 	/* Transfer to one big alloc for easy freeing by the caller. */
-	ret = malloc(*num * sizeof(char *) + len, M_XENSTORE, M_WAITOK);
+	ret = (const char **)malloc(*num * sizeof(char *) + len, M_XENSTORE, M_WAITOK);
 	memcpy(&ret[*num], strings, len);
 	free(strings, M_XENSTORE);
 
@@ -599,7 +599,7 @@ xs_read_store(void *tdata, unsigned len)
 			return (EIO);
 		}
 
-		src = xs_get_input_chunk(cons, prod, xen_store->rsp, &avail);
+		src = (const char *)xs_get_input_chunk(cons, prod, xen_store->rsp, &avail);
 		if (avail > len)
 			avail = len;
 
@@ -649,14 +649,14 @@ xs_process_msg(enum xsd_sockmsg_type *type)
 	char *body;
 	int error;
 
-	msg = malloc(sizeof(*msg), M_XENSTORE, M_WAITOK);
+	msg = (xs_stored_msg *)malloc(sizeof(*msg), M_XENSTORE, M_WAITOK);
 	error = xs_read_store(&msg->hdr, sizeof(msg->hdr));
 	if (error) {
 		free(msg, M_XENSTORE);
 		return (error);
 	}
 
-	body = malloc(msg->hdr.len + 1, M_XENSTORE, M_WAITOK);
+	body = (char *)malloc(msg->hdr.len + 1, M_XENSTORE, M_WAITOK);
 	error = xs_read_store(body, msg->hdr.len);
 	if (error) {
 		free(body, M_XENSTORE);
@@ -665,7 +665,7 @@ xs_process_msg(enum xsd_sockmsg_type *type)
 	}
 	body[msg->hdr.len] = '\0';
 
-	*type = msg->hdr.type;
+	*type = (xsd_sockmsg_type)msg->hdr.type;
 	if (msg->hdr.type == XS_WATCH_EVENT) {
 		msg->u.watch.vec = split(body, msg->hdr.len,
 		    &msg->u.watch.vec_size);
@@ -795,7 +795,7 @@ xs_get_error(const char *errorstring)
  *          cause of failure.
  */
 static int
-xs_read_reply(enum xsd_sockmsg_type *type, u_int *len, void **result)
+xs_read_reply(uint32_t *type, u_int *len, void **result)
 {
 	struct xs_stored_msg *msg;
 	char *body;
@@ -814,7 +814,7 @@ xs_read_reply(enum xsd_sockmsg_type *type, u_int *len, void **result)
 	TAILQ_REMOVE(&xs.reply_list, msg, list);
 	mtx_unlock(&xs.reply_lock);
 
-	*type = msg->hdr.type;
+	*type = (xsd_sockmsg_type)msg->hdr.type;
 	if (len)
 		*len = msg->hdr.len;
 	body = msg->u.reply.body;
@@ -918,7 +918,7 @@ error_lock_held:
 		return (error);
 
 	if (msg.type == XS_ERROR) {
-		error = xs_get_error(ret);
+		error = xs_get_error((const char *)ret);
 		free(ret, M_XENSTORE);
 		return (error);
 	}
@@ -1020,7 +1020,7 @@ find_watch(const char *token)
 {
 	struct xs_watch *i, *cmp;
 
-	cmp = (void *)strtoul(token, NULL, 16);
+	cmp = (struct xs_watch *)strtoul(token, NULL, 16);
 
 	LIST_FOREACH(i, &xs.registered_watches, list)
 		if (i == cmp)
@@ -1178,7 +1178,7 @@ xs_attach(device_t dev)
 	if (is_xen_hvm()) {
 		xs.evtchn = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN);
 		xs.gpfn = hvm_get_parameter(HVM_PARAM_STORE_PFN);
-		xen_store = pmap_mapdev(xs.gpfn * PAGE_SIZE, PAGE_SIZE);
+		xen_store = (xenstore_domain_interface *)pmap_mapdev(xs.gpfn * PAGE_SIZE, PAGE_SIZE);
 	} else {
 		printf("implement me\n");
 		abort();
diff --git a/drivers/xenfront-blk.cc b/drivers/xenfront-blk.cc
index 9dc53c35eeb02eb9db736590ac5f275832c93cf0..51534129b629d77b52bc2e6a1bfe9f1706187a06 100644
--- a/drivers/xenfront-blk.cc
+++ b/drivers/xenfront-blk.cc
@@ -11,8 +11,6 @@
 #include <bsd/sys/geom/geom_disk.h>
 #include <osv/bio.h>
 
-extern "C" {
-
 struct xb_softc;
 struct device *blkfront_from_softc(struct xb_softc *s);
 
@@ -70,4 +68,3 @@ void disk_create(struct disk *dp, int version)
     dev->size = dp->d_mediasize;
     dev->max_io_size = dp->d_maxsize;
 }
-};
diff --git a/drivers/xenfront-xenbus.cc b/drivers/xenfront-xenbus.cc
index 51b5783a7dbba6dfe4985012e3ce905616374052..a33ba36a174e1308e2f2619e48be696ab5ebefeb 100644
--- a/drivers/xenfront-xenbus.cc
+++ b/drivers/xenfront-xenbus.cc
@@ -23,18 +23,14 @@
 #include <xen/xenstore/xenstorevar.h>
 #include <xen/xenbus/xenbusb.h>
 
-extern "C" {
+int xs_attach(struct device *);
 
-    int xs_attach(struct device *);
-
-    int xenpci_irq_init(device_t device, struct xenpci_softc *scp);
-    void evtchn_init(void *arg);
-
-    int xenbusb_front_probe(device_t dev);
-    int xenbusb_front_attach(device_t dev);
-    int xenbusb_add_device(device_t dev, const char *type, const char *id);
-};
+int xenpci_irq_init(device_t device, struct xenpci_softc *scp);
+void evtchn_init(void *arg);
 
+int xenbusb_front_probe(device_t dev);
+int xenbusb_front_attach(device_t dev);
+int xenbusb_add_device(device_t dev, const char *type, const char *id);
 
 namespace xenfront {
 
diff --git a/include/osv/bio.h b/include/osv/bio.h
index 16c7f6465eb657dab56b20a4e3a7e500f0b3fda2..b157134a12c7a2b0dcb21fae0e8530bfad397dcc 100644
--- a/include/osv/bio.h
+++ b/include/osv/bio.h
@@ -112,6 +112,9 @@ struct bio *bioq_takefirst(struct bio_queue_head *head);
 struct bio *bioq_first(struct bio_queue_head *head);
 
 void bioq_init(struct bio_queue_head *head);
+void bioq_insert_tail(struct bio_queue_head *head, struct bio *bp);
+void bioq_insert_head(struct bio_queue_head *head, struct bio *bp);
+void bioq_remove(struct bio_queue_head *head, struct bio *bp);
 
 struct bio *	alloc_bio(void);
 void		destroy_bio(struct bio *bio);