Index: ioemu/hw/pc.c
===================================================================
--- ioemu.orig/hw/pc.c	2007-05-03 09:54:24.000000000 +0100
+++ ioemu/hw/pc.c	2007-05-03 09:56:32.000000000 +0100
@@ -646,7 +646,9 @@
     }
 
     /* allocate RAM */
+#ifndef CONFIG_DM		/* HVM domain owns memory */
     cpu_register_physical_memory(0, ram_size, 0);
+#endif
 
     /* BIOS load */
     bios_offset = ram_size + vga_ram_size;
@@ -678,8 +680,10 @@
     ret = load_image(buf, phys_ram_base + vga_bios_offset);
     
     /* setup basic memory access */
+#ifndef CONFIG_DM		/* HVM domain owns memory */
     cpu_register_physical_memory(0xc0000, 0x10000, 
                                  vga_bios_offset | IO_MEM_ROM);
+#endif
 
     /* map the last 128KB of the BIOS in ISA space */
     isa_bios_size = bios_size;
Index: ioemu/vl.c
===================================================================
--- ioemu.orig/vl.c	2007-05-03 09:54:24.000000000 +0100
+++ ioemu/vl.c	2007-05-03 10:04:06.000000000 +0100
@@ -88,6 +88,7 @@
 
 #include "exec-all.h"
 
+#include <xen/hvm/params.h>
 #define DEFAULT_NETWORK_SCRIPT "/etc/xen/qemu-ifup"
 
 //#define DEBUG_UNUSED_IOPORT
@@ -158,6 +159,8 @@
 int acpi_enabled = 1;
 int fd_bootchk = 1;
 
+int xc_handle;
+
 char domain_name[1024] = { 'H','V', 'M', 'X', 'E', 'N', '-'};
 extern int domid;
 
@@ -5650,6 +5653,9 @@
     QEMUMachine *machine;
     char usb_devices[MAX_USB_CMDLINE][128];
     int usb_devices_index;
+    unsigned long ioreq_pfn;
+    extern void *shared_page;
+    unsigned long nr_pages;
 
     char qemu_dm_logfilename[64];
 
@@ -5921,11 +5927,13 @@
                 ram_size = atol(optarg) * 1024 * 1024;
                 if (ram_size <= 0)
                     help();
+#ifndef CONFIG_DM
                 if (ram_size > PHYS_RAM_MAX_SIZE) {
                     fprintf(stderr, "qemu: at most %d MB RAM can be simulated\n",
                             PHYS_RAM_MAX_SIZE / (1024 * 1024));
                     exit(1);
                 }
+#endif /* !CONFIG_DM */
                 break;
             case QEMU_OPTION_l:
                 {
@@ -6137,12 +6145,53 @@
     /* init the memory */
     phys_ram_size = ram_size + vga_ram_size + bios_size;
 
+#ifdef CONFIG_DM
+
+    xc_handle = xc_interface_open();
+
+#if defined(__i386__) || defined(__x86_64__)
+
+    nr_pages = ram_size/PAGE_SIZE;
+
+    page_array = (xen_pfn_t *)malloc(nr_pages * sizeof(xen_pfn_t));
+    if (page_array == NULL) {
+        fprintf(logfile, "malloc returned error %d\n", errno);
+        exit(-1);
+    }
+
+    for ( i = 0; i < nr_pages; i++)
+        page_array[i] = i;
+
+    phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
+                                         PROT_READ|PROT_WRITE, page_array,
+                                         nr_pages);
+    if (phys_ram_base == NULL) {
+        fprintf(logfile, "batch map guest memory returned error %d\n", errno);
+        exit(-1);
+    }
+
+    xc_get_hvm_param(xc_handle, domid, HVM_PARAM_IOREQ_PFN, &ioreq_pfn);
+    fprintf(logfile, "shared page at pfn %lx\n", ioreq_pfn);
+    shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
+                                       PROT_READ|PROT_WRITE,
+                                       page_array[ioreq_pfn]);
+    if (shared_page == NULL) {
+        fprintf(logfile, "map shared IO page returned error %d\n", errno);
+        exit(-1);
+    }
+
+    free(page_array);
+
+#else  /* !CONFIG_DM */
+
     phys_ram_base = qemu_vmalloc(phys_ram_size);
     if (!phys_ram_base) {
         fprintf(stderr, "Could not allocate physical memory\n");
         exit(1);
     }
 
+#endif /* !CONFIG_DM */
+
     /* we always create the cdrom drive, even if no disk is there */
     bdrv_init();
     if (cdrom_index >= 0) {
Index: ioemu/hw/piix_pci.c
===================================================================
--- ioemu.orig/hw/piix_pci.c	2007-05-03 09:54:18.000000000 +0100
+++ ioemu/hw/piix_pci.c	2007-05-03 09:56:32.000000000 +0100
@@ -399,7 +399,7 @@
     uint8_t elcr[2];
 
     pci_bios_io_addr = 0xc000;
-    pci_bios_mem_addr = 0xf0000000;
+    pci_bios_mem_addr = HVM_BELOW_4G_MMIO_START;
 
     /* activate IRQ mappings */
     elcr[0] = 0x00;
Index: ioemu/vl.h
===================================================================
--- ioemu.orig/vl.h	2007-05-03 09:54:24.000000000 +0100
+++ ioemu/vl.h	2007-05-03 09:56:32.000000000 +0100
@@ -39,6 +39,7 @@
 #include <sys/stat.h>
 #include "xenctrl.h"
 #include "xs.h"
+#include <xen/hvm/e820.h>
 
 #ifndef O_LARGEFILE
 #define O_LARGEFILE 0
