direct-io.hg

changeset 15106:d7303c4a9dab

merge with xen-unstable.hg
author Alex Williamson <alex.williamson@hp.com>
date Tue May 08 09:09:17 2007 -0600 (2007-05-08)
parents d1ce60b8070f 3ef0510e44d0
children 8b9637467068
files
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/machine_reboot.c	Mon May 07 13:24:37 2007 -0600
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/machine_reboot.c	Tue May 08 09:09:17 2007 -0600
     1.3 @@ -113,10 +113,18 @@ static void post_suspend(int suspend_can
     1.4  
     1.5  #else /* !(defined(__i386__) || defined(__x86_64__)) */
     1.6  
     1.7 +#ifndef HAVE_XEN_PRE_SUSPEND
     1.8 +#define xen_pre_suspend()	((void)0)
     1.9 +#endif
    1.10 +
    1.11 +#ifndef HAVE_XEN_POST_SUSPEND
    1.12 +#define xen_post_suspend(x)	((void)0)
    1.13 +#endif
    1.14 +
    1.15  #define switch_idle_mm()	((void)0)
    1.16  #define mm_pin_all()		((void)0)
    1.17 -#define pre_suspend()		((void)0)
    1.18 -#define post_suspend(x)		((void)0)
    1.19 +#define pre_suspend()		xen_pre_suspend()
    1.20 +#define post_suspend(x)		xen_post_suspend(x)
    1.21  
    1.22  #endif
    1.23  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/patches/linux-2.6.18/git-5ee7737379b1d7f0c977c0f1661fbaf01a8d4721.patch	Tue May 08 09:09:17 2007 -0600
     2.3 @@ -0,0 +1,28 @@
     2.4 +--- ./arch/ia64/kernel/smp.c.orig	2007-05-02 19:00:01.000000000 +0900
     2.5 ++++ ./arch/ia64/kernel/smp.c	2007-05-02 19:04:32.000000000 +0900
     2.6 +@@ -328,10 +328,14 @@ int
     2.7 + smp_call_function (void (*func) (void *info), void *info, int nonatomic, int wait)
     2.8 + {
     2.9 + 	struct call_data_struct data;
    2.10 +-	int cpus = num_online_cpus()-1;
    2.11 ++	int cpus;
    2.12 + 
    2.13 +-	if (!cpus)
    2.14 ++	spin_lock(&call_lock);
    2.15 ++	cpus = num_online_cpus()-1;
    2.16 ++	if (!cpus) {
    2.17 ++		spin_unlock(&call_lock);
    2.18 + 		return 0;
    2.19 ++	}
    2.20 + 
    2.21 + 	/* Can deadlock when called with interrupts disabled */
    2.22 + 	WARN_ON(irqs_disabled());
    2.23 +@@ -343,8 +347,6 @@ smp_call_function (void (*func) (void *i
    2.24 + 	if (wait)
    2.25 + 		atomic_set(&data.finished, 0);
    2.26 + 
    2.27 +-	spin_lock(&call_lock);
    2.28 +-
    2.29 + 	call_data = &data;
    2.30 + 	mb();	/* ensure store to call_data precedes setting of IPI_CALL_FUNC */
    2.31 + 	send_IPI_allbutself(IPI_CALL_FUNC);
     3.1 --- a/patches/linux-2.6.18/series	Mon May 07 13:24:37 2007 -0600
     3.2 +++ b/patches/linux-2.6.18/series	Tue May 08 09:09:17 2007 -0600
     3.3 @@ -21,3 +21,4 @@ git-c06cb8b1c4d25e5b4d7a2d7c2462619de1e0
     3.4  softlockup-no-idle-hz.patch
     3.5  allow-i386-crash-kernels-to-handle-x86_64-dumps.patch
     3.6  allow-i386-crash-kernels-to-handle-x86_64-dumps-fix.patch
     3.7 +git-5ee7737379b1d7f0c977c0f1661fbaf01a8d4721.patch
     4.1 --- a/tools/blktap/drivers/block-qcow.c	Mon May 07 13:24:37 2007 -0600
     4.2 +++ b/tools/blktap/drivers/block-qcow.c	Tue May 08 09:09:17 2007 -0600
     4.3 @@ -199,7 +199,8 @@ static int init_aio_state(struct disk_dr
     4.4  	}
     4.5  
     4.6          /* A segment (i.e. a page) can span multiple clusters */
     4.7 -        s->max_aio_reqs = (getpagesize() / s->cluster_size) + 1;
     4.8 +        s->max_aio_reqs = ((getpagesize() / s->cluster_size) + 1) *
     4.9 +            MAX_SEGMENTS_PER_REQ * MAX_REQUESTS;
    4.10  
    4.11          /* Initialize AIO */
    4.12          s->iocb_free_count = s->max_aio_reqs;
     5.1 --- a/tools/ioemu/keymaps/modifiers	Mon May 07 13:24:37 2007 -0600
     5.2 +++ b/tools/ioemu/keymaps/modifiers	Tue May 08 09:09:17 2007 -0600
     5.3 @@ -3,7 +3,7 @@ Shift_L 0x2a
     5.4  
     5.5  Alt_R 0xb8
     5.6  Mode_switch 0xb8
     5.7 -ISO_Level3_Switch 0xb8
     5.8 +ISO_Level3_Shift 0xb8
     5.9  Alt_L 0x38
    5.10  
    5.11  Control_R 0x9d
     6.1 --- a/tools/ioemu/patches/acpi-poweroff-support	Mon May 07 13:24:37 2007 -0600
     6.2 +++ b/tools/ioemu/patches/acpi-poweroff-support	Tue May 08 09:09:17 2007 -0600
     6.3 @@ -1,7 +1,7 @@
     6.4  Index: ioemu/hw/piix4acpi.c
     6.5  ===================================================================
     6.6 ---- ioemu.orig/hw/piix4acpi.c	2006-08-17 19:50:05.060576667 +0100
     6.7 -+++ ioemu/hw/piix4acpi.c	2006-08-17 19:50:07.563300039 +0100
     6.8 +--- ioemu.orig/hw/piix4acpi.c	2007-05-02 15:59:27.000000000 +0100
     6.9 ++++ ioemu/hw/piix4acpi.c	2007-05-02 16:02:29.000000000 +0100
    6.10  @@ -45,6 +45,10 @@
    6.11   #define GBL_RLS           (1 << 2)
    6.12   #define SLP_EN            (1 << 13)
    6.13 @@ -13,23 +13,22 @@ Index: ioemu/hw/piix4acpi.c
    6.14   typedef struct AcpiDeviceState AcpiDeviceState;
    6.15   AcpiDeviceState *acpi_device_table;
    6.16   
    6.17 -@@ -190,7 +194,14 @@
    6.18 -     s->pm1_control = (val<<8)||(s->pm1_control);
    6.19 +@@ -81,7 +85,13 @@
    6.20 +     s->pm1_control = (s->pm1_control & 0xff) | (val << 8);
    6.21   /*    printf("acpiPm1ControlP1_writeb \n addr %x val:%x\n", addr, val); */
    6.22   
    6.23  -} 
    6.24  +    // Check for power off request
    6.25 -+
    6.26 ++    val <<= 8;
    6.27  +    if (((val & SLP_EN) != 0) &&
    6.28  +        ((val & SLP_TYP_MASK) == SLP_VAL)) {
    6.29 -+        s->pm1_timer=0x0; //clear ACPI timer
    6.30  +        qemu_system_shutdown_request();
    6.31  +    }
    6.32  +}
    6.33   
    6.34   static uint32_t acpiPm1ControlP1_readb(void *opaque, uint32_t addr)
    6.35   {
    6.36 -@@ -257,7 +268,14 @@
    6.37 +@@ -105,7 +115,14 @@
    6.38       s->pm1_control = val;
    6.39   /*    printf("acpiPm1Control_writew \n addr %x val:%x\n", addr, val); */
    6.40   
     7.1 --- a/tools/ioemu/patches/acpi-support	Mon May 07 13:24:37 2007 -0600
     7.2 +++ b/tools/ioemu/patches/acpi-support	Tue May 08 09:09:17 2007 -0600
     7.3 @@ -1,7 +1,7 @@
     7.4  Index: ioemu/Makefile.target
     7.5  ===================================================================
     7.6 ---- ioemu.orig/Makefile.target	2006-12-08 02:00:40.000000000 +0000
     7.7 -+++ ioemu/Makefile.target	2006-12-08 02:00:40.000000000 +0000
     7.8 +--- ioemu.orig/Makefile.target	2007-05-03 15:06:42.000000000 +0100
     7.9 ++++ ioemu/Makefile.target	2007-05-03 15:07:21.000000000 +0100
    7.10  @@ -358,6 +358,7 @@
    7.11   VL_OBJS+= fdc.o mc146818rtc.o serial.o pc.o
    7.12   VL_OBJS+= cirrus_vga.o mixeng.o parallel.o acpi.o piix_pci.o
    7.13 @@ -12,11 +12,11 @@ Index: ioemu/Makefile.target
    7.14   ifeq ($(TARGET_BASE_ARCH), ppc)
    7.15  Index: ioemu/hw/pc.c
    7.16  ===================================================================
    7.17 ---- ioemu.orig/hw/pc.c	2006-12-08 02:00:40.000000000 +0000
    7.18 -+++ ioemu/hw/pc.c	2006-12-08 02:00:40.000000000 +0000
    7.19 -@@ -874,13 +874,19 @@
    7.20 +--- ioemu.orig/hw/pc.c	2007-05-03 15:06:42.000000000 +0100
    7.21 ++++ ioemu/hw/pc.c	2007-05-03 15:07:21.000000000 +0100
    7.22 +@@ -873,13 +873,19 @@
    7.23   
    7.24 -     cmos_init(ram_size, boot_device, bs_table, timeoffset);
    7.25 +     cmos_init(ram_size, boot_device, bs_table);
    7.26   
    7.27  +    /* using PIIX4 acpi model */
    7.28  +    if (pci_enabled && acpi_enabled)
    7.29 @@ -35,7 +35,7 @@ Index: ioemu/hw/pc.c
    7.30   
    7.31   #if 0
    7.32       /* ??? Need to figure out some way for the user to
    7.33 -@@ -903,8 +909,10 @@
    7.34 +@@ -902,8 +908,10 @@
    7.35       /* XXX: should be done in the Bochs BIOS */
    7.36       if (pci_enabled) {
    7.37           pci_bios_init();
    7.38 @@ -49,8 +49,8 @@ Index: ioemu/hw/pc.c
    7.39  Index: ioemu/hw/piix4acpi.c
    7.40  ===================================================================
    7.41  --- /dev/null	1970-01-01 00:00:00.000000000 +0000
    7.42 -+++ ioemu/hw/piix4acpi.c	2006-12-08 02:00:40.000000000 +0000
    7.43 -@@ -0,0 +1,396 @@
    7.44 ++++ ioemu/hw/piix4acpi.c	2007-05-03 15:07:31.000000000 +0100
    7.45 +@@ -0,0 +1,186 @@
    7.46  +/*
    7.47  + * PIIX4 ACPI controller emulation
    7.48  + *
    7.49 @@ -101,23 +101,11 @@ Index: ioemu/hw/piix4acpi.c
    7.50  +typedef struct AcpiDeviceState AcpiDeviceState;
    7.51  +AcpiDeviceState *acpi_device_table;
    7.52  +
    7.53 -+/* Bits of PM1a register define here  */
    7.54 -+typedef struct PM1Event_BLK {
    7.55 -+    uint16_t pm1_status; /* pm1a_EVT_BLK */
    7.56 -+    uint16_t pm1_enable; /* pm1a_EVT_BLK+2 */
    7.57 -+}PM1Event_BLK;
    7.58 -+
    7.59  +typedef struct PCIAcpiState {
    7.60  +    PCIDevice dev;
    7.61 -+    uint16_t irq;
    7.62 -+    uint16_t pm1_status; /* pm1a_EVT_BLK */
    7.63 -+    uint16_t pm1_enable; /* pm1a_EVT_BLK+2 */
    7.64  +    uint16_t pm1_control; /* pm1a_ECNT_BLK */
    7.65 -+    uint32_t pm1_timer; /* pmtmr_BLK */
    7.66  +} PCIAcpiState;
    7.67  +
    7.68 -+static PCIAcpiState *acpi_state;
    7.69 -+
    7.70  +static inline void acpi_set_irq(PCIAcpiState *s)
    7.71  +{
    7.72  +/* no real SCI event need for now, so comment the following line out */
    7.73 @@ -125,108 +113,11 @@ Index: ioemu/hw/piix4acpi.c
    7.74  +    printf("acpi_set_irq: s->irq %x \n",s->irq);
    7.75  +}
    7.76  +
    7.77 -+static void acpi_reset(PCIAcpiState *s)
    7.78 -+{
    7.79 -+    uint8_t *pci_conf;
    7.80 -+    pci_conf = s->dev.config;
    7.81 -+
    7.82 -+    pci_conf[0x42] = 0x00;
    7.83 -+    pci_conf[0x43] = 0x00;
    7.84 -+    s->irq = 9;
    7.85 -+    s->pm1_status = 0;
    7.86 -+    s->pm1_enable = 0x00;    /* TMROF_EN should cleared */
    7.87 -+    s->pm1_control = SCI_EN; /* SCI_EN */
    7.88 -+    s->pm1_timer = 0;
    7.89 -+}
    7.90 -+
    7.91 -+/*byte access  */
    7.92 -+static void acpiPm1Status_writeb(void *opaque, uint32_t addr, uint32_t val)
    7.93 -+{
    7.94 -+    PCIAcpiState *s = opaque;
    7.95 -+
    7.96 -+    if ((val&TMROF_STS)==TMROF_STS)
    7.97 -+        s->pm1_status = s->pm1_status&!TMROF_STS;
    7.98 -+
    7.99 -+    if ((val&GBL_STS)==GBL_STS)
   7.100 -+        s->pm1_status = s->pm1_status&!GBL_STS;     
   7.101 -+    
   7.102 -+/*     printf("acpiPm1Status_writeb \n addr %x val:%x pm1_status:%x \n", addr, val,s->pm1_status); */
   7.103 -+}
   7.104 -+
   7.105 -+static uint32_t acpiPm1Status_readb(void *opaque, uint32_t addr)
   7.106 -+{
   7.107 -+    PCIAcpiState *s = opaque;
   7.108 -+    uint32_t val;
   7.109 -+
   7.110 -+    val = s->pm1_status;
   7.111 -+/*         printf("acpiPm1Status_readb \n addr %x val:%x\n", addr, val); */
   7.112 -+
   7.113 -+   return val;
   7.114 -+}
   7.115 -+
   7.116 -+static void acpiPm1StatusP1_writeb(void *opaque, uint32_t addr, uint32_t val)
   7.117 -+{
   7.118 -+    PCIAcpiState *s = opaque;
   7.119 -+
   7.120 -+     s->pm1_status = (val<<8)||(s->pm1_status);
   7.121 -+/*     printf("acpiPm1StatusP1_writeb \n addr %x val:%x\n", addr, val); */
   7.122 -+}
   7.123 -+
   7.124 -+static uint32_t acpiPm1StatusP1_readb(void *opaque, uint32_t addr)
   7.125 -+{
   7.126 -+    PCIAcpiState *s = opaque;
   7.127 -+    uint32_t val;
   7.128 -+
   7.129 -+    val = (s->pm1_status)>>8;
   7.130 -+    printf("acpiPm1StatusP1_readb \n addr %x val:%x\n", addr, val);
   7.131 -+
   7.132 -+    return val;
   7.133 -+}
   7.134 -+
   7.135 -+static void acpiPm1Enable_writeb(void *opaque, uint32_t addr, uint32_t val)
   7.136 -+{
   7.137 -+    PCIAcpiState *s = opaque;
   7.138 -+
   7.139 -+    s->pm1_enable = val;
   7.140 -+/*   printf("acpiPm1Enable_writeb \n addr %x val:%x\n", addr, val); */
   7.141 -+}
   7.142 -+
   7.143 -+static uint32_t acpiPm1Enable_readb(void *opaque, uint32_t addr)
   7.144 -+{
   7.145 -+    PCIAcpiState *s = opaque;
   7.146 -+    uint32_t val;
   7.147 -+
   7.148 -+    val = (s->pm1_enable)||0x1;
   7.149 -+/*  printf("acpiPm1Enable_readb \n addr %x val:%x\n", addr, val); */
   7.150 -+
   7.151 -+    return val;
   7.152 -+}
   7.153 -+
   7.154 -+static void acpiPm1EnableP1_writeb(void *opaque, uint32_t addr, uint32_t val)
   7.155 -+{
   7.156 -+    PCIAcpiState *s = opaque;
   7.157 -+
   7.158 -+    s->pm1_enable = (val<<8)||(s->pm1_enable);
   7.159 -+/*    printf("acpiPm1EnableP1_writeb \n addr %x val:%x\n", addr, val); */
   7.160 -+
   7.161 -+}
   7.162 -+
   7.163 -+static uint32_t acpiPm1EnableP1_readb(void *opaque, uint32_t addr)
   7.164 -+{
   7.165 -+    PCIAcpiState *s = opaque;
   7.166 -+    uint32_t val;
   7.167 -+
   7.168 -+    val = (s->pm1_enable)>>8;
   7.169 -+/*  printf("acpiPm1EnableP1_readb \n addr %x val:%x\n", addr, val); */
   7.170 -+
   7.171 -+    return val;
   7.172 -+}
   7.173 -+
   7.174  +static void acpiPm1Control_writeb(void *opaque, uint32_t addr, uint32_t val)
   7.175  +{
   7.176  +    PCIAcpiState *s = opaque;
   7.177  +
   7.178 -+    s->pm1_control = val;
   7.179 ++    s->pm1_control = (s->pm1_control & 0xff00) | (val & 0xff);
   7.180  +/*  printf("acpiPm1Control_writeb \n addr %x val:%x\n", addr, val); */
   7.181  +
   7.182  +}
   7.183 @@ -236,7 +127,8 @@ Index: ioemu/hw/piix4acpi.c
   7.184  +    PCIAcpiState *s = opaque;
   7.185  +    uint32_t val;
   7.186  +
   7.187 -+    val = s->pm1_control;
   7.188 ++    /* Mask out the write-only bits */
   7.189 ++    val = s->pm1_control & ~(GBL_RLS|SLP_EN) & 0xff;
   7.190  +/*    printf("acpiPm1Control_readb \n addr %x val:%x\n", addr, val); */
   7.191  +
   7.192  +    return val;
   7.193 @@ -246,7 +138,7 @@ Index: ioemu/hw/piix4acpi.c
   7.194  +{
   7.195  +    PCIAcpiState *s = opaque;
   7.196  +
   7.197 -+    s->pm1_control = (val<<8)||(s->pm1_control);
   7.198 ++    s->pm1_control = (s->pm1_control & 0xff) | (val << 8);
   7.199  +/*    printf("acpiPm1ControlP1_writeb \n addr %x val:%x\n", addr, val); */
   7.200  +
   7.201  +} 
   7.202 @@ -256,7 +148,8 @@ Index: ioemu/hw/piix4acpi.c
   7.203  +    PCIAcpiState *s = opaque;
   7.204  +    uint32_t val;
   7.205  +
   7.206 -+    val = (s->pm1_control)>>8;
   7.207 ++    /* Mask out the write-only bits */
   7.208 ++    val = (s->pm1_control & ~(GBL_RLS|SLP_EN)) >> 8;
   7.209  +/*    printf("acpiPm1ControlP1_readb \n addr %x val:%x\n", addr, val); */
   7.210  +
   7.211  +    return val;
   7.212 @@ -265,50 +158,6 @@ Index: ioemu/hw/piix4acpi.c
   7.213  +
   7.214  +/* word access   */
   7.215  +
   7.216 -+static void acpiPm1Status_writew(void *opaque, uint32_t addr, uint32_t val)
   7.217 -+{
   7.218 -+    PCIAcpiState *s = opaque;
   7.219 -+
   7.220 -+    if ((val&TMROF_STS)==TMROF_STS)
   7.221 -+        s->pm1_status = s->pm1_status&!TMROF_STS;
   7.222 -+
   7.223 -+    if ((val&GBL_STS)==GBL_STS)
   7.224 -+        s->pm1_status = s->pm1_status&!GBL_STS;     
   7.225 -+
   7.226 -+/*    printf("acpiPm1Status_writew \n addr %x val:%x pm1_status:%x \n", addr, val,s->pm1_status); */
   7.227 -+}
   7.228 -+
   7.229 -+static uint32_t acpiPm1Status_readw(void *opaque, uint32_t addr)
   7.230 -+{
   7.231 -+    PCIAcpiState *s = opaque;
   7.232 -+    uint32_t val;
   7.233 -+
   7.234 -+    val = s->pm1_status;
   7.235 -+/*    printf("acpiPm1Status_readw \n addr %x val:%x\n", addr, val); */
   7.236 -+
   7.237 -+    return val;
   7.238 -+}
   7.239 -+
   7.240 -+static void acpiPm1Enable_writew(void *opaque, uint32_t addr, uint32_t val)
   7.241 -+{
   7.242 -+    PCIAcpiState *s = opaque;
   7.243 -+
   7.244 -+    s->pm1_enable = val;
   7.245 -+/*    printf("acpiPm1Enable_writew \n addr %x val:%x\n", addr, val); */
   7.246 -+
   7.247 -+}
   7.248 -+
   7.249 -+static uint32_t acpiPm1Enable_readw(void *opaque, uint32_t addr)
   7.250 -+{
   7.251 -+    PCIAcpiState *s = opaque;
   7.252 -+    uint32_t val;
   7.253 -+
   7.254 -+    val = s->pm1_enable;
   7.255 -+/*    printf("acpiPm1Enable_readw \n addr %x val:%x\n", addr, val); */
   7.256 -+
   7.257 -+   return val;
   7.258 -+}
   7.259 -+
   7.260  +static void acpiPm1Control_writew(void *opaque, uint32_t addr, uint32_t val)
   7.261  +{
   7.262  +    PCIAcpiState *s = opaque;
   7.263 @@ -323,50 +172,13 @@ Index: ioemu/hw/piix4acpi.c
   7.264  +    PCIAcpiState *s = opaque;
   7.265  +    uint32_t val;
   7.266  +
   7.267 -+    val = s->pm1_control;
   7.268 ++    /* Mask out the write-only bits */
   7.269 ++    val = s->pm1_control & ~(GBL_RLS|SLP_EN);
   7.270  +/*    printf("acpiPm1Control_readw \n addr %x val:%x\n", addr, val);  */
   7.271  +
   7.272  +    return val;
   7.273  +}
   7.274  +
   7.275 -+/* dword access */
   7.276 -+
   7.277 -+static void acpiPm1Event_writel(void *opaque, uint32_t addr, uint32_t val)
   7.278 -+{
   7.279 -+    PCIAcpiState *s = opaque;
   7.280 -+
   7.281 -+    s->pm1_status = val;
   7.282 -+    s->pm1_enable = val>>16;
   7.283 -+/*     printf("acpiPm1Event_writel \n addr %x val:%x \n", addr, val); */
   7.284 -+
   7.285 -+}
   7.286 -+
   7.287 -+static void acpiPm1Event_readl(void *opaque, uint32_t addr)
   7.288 -+{
   7.289 -+    PCIAcpiState *s = opaque;
   7.290 -+    uint32_t val;
   7.291 -+
   7.292 -+    val=s->pm1_status|(s->pm1_enable<<16);
   7.293 -+/*    printf("acpiPm1Event_readl \n addr %x val:%x\n", addr, val);    */
   7.294 -+}
   7.295 -+
   7.296 -+static void acpiPm1Timer_writel(void *opaque, uint32_t addr, uint32_t val)
   7.297 -+{
   7.298 -+    PCIAcpiState *s = opaque;
   7.299 -+
   7.300 -+    s->pm1_timer = val;
   7.301 -+/*    printf("acpiPm1Timer_writel \n addr %x val:%x\n", addr, val); */
   7.302 -+}
   7.303 -+
   7.304 -+static uint32_t acpiPm1Timer_readl(void *opaque, uint32_t addr)
   7.305 -+{
   7.306 -+    PCIAcpiState *s = opaque;
   7.307 -+    uint32_t val;
   7.308 -+
   7.309 -+    val = s->pm1_timer;
   7.310 -+/*    printf("acpiPm1Timer_readl \n addr %x val:%x\n", addr, val); */
   7.311 -+    return val;
   7.312 -+}
   7.313  +
   7.314  +static void acpi_map(PCIDevice *pci_dev, int region_num,
   7.315  +                    uint32_t addr, uint32_t size, int type)
   7.316 @@ -376,39 +188,15 @@ Index: ioemu/hw/piix4acpi.c
   7.317  +    printf("register acpi io \n");
   7.318  +
   7.319  +    /* Byte access */
   7.320 -+    register_ioport_write(addr, 1, 1, acpiPm1Status_writeb, d);
   7.321 -+    register_ioport_read(addr, 1, 1, acpiPm1Status_readb, d);
   7.322 -+    register_ioport_write(addr+1, 1, 1, acpiPm1StatusP1_writeb, d);
   7.323 -+    register_ioport_read(addr+1, 1, 1, acpiPm1StatusP1_readb, d);
   7.324 -+
   7.325 -+    register_ioport_write(addr + 2, 1, 1, acpiPm1Enable_writeb, d);
   7.326 -+    register_ioport_read(addr + 2, 1, 1, acpiPm1Enable_readb, d);
   7.327 -+    register_ioport_write(addr + 2 +1, 1, 1, acpiPm1EnableP1_writeb, d);
   7.328 -+    register_ioport_read(addr + 2 +1, 1, 1, acpiPm1EnableP1_readb, d);
   7.329 -+
   7.330  +    register_ioport_write(addr + 4, 1, 1, acpiPm1Control_writeb, d);
   7.331  +    register_ioport_read(addr + 4, 1, 1, acpiPm1Control_readb, d);
   7.332  +    register_ioport_write(addr + 4 + 1, 1, 1, acpiPm1ControlP1_writeb, d);
   7.333 -+    register_ioport_read(addr + 4 +1, 1, 1, acpiPm1ControlP1_readb, d);	
   7.334 ++    register_ioport_read(addr + 4 +1, 1, 1, acpiPm1ControlP1_readb, d);
   7.335  +
   7.336  +    /* Word access */
   7.337 -+    register_ioport_write(addr, 2, 2, acpiPm1Status_writew, d);
   7.338 -+    register_ioport_read(addr, 2, 2, acpiPm1Status_readw, d);
   7.339 -+
   7.340 -+    register_ioport_write(addr + 2, 2, 2, acpiPm1Enable_writew, d);
   7.341 -+    register_ioport_read(addr + 2, 2, 2, acpiPm1Enable_readw, d); 
   7.342 -+
   7.343  +    register_ioport_write(addr + 4, 2, 2, acpiPm1Control_writew, d);
   7.344  +    register_ioport_read(addr + 4, 2, 2, acpiPm1Control_readw, d);
   7.345 -+
   7.346 -+    /* DWord access */
   7.347 -+    register_ioport_write(addr, 4, 4, acpiPm1Event_writel, d);
   7.348 -+    register_ioport_read(addr, 4, 4, acpiPm1Event_readl, d);
   7.349 -+		
   7.350 -+    register_ioport_write(addr + 8, 4, 4, acpiPm1Timer_writel, d);
   7.351 -+    register_ioport_read(addr + 8, 4, 4, acpiPm1Timer_readl, d);
   7.352  +}
   7.353 -+													
   7.354  +
   7.355  +/* PIIX4 acpi pci configuration space, func 2 */
   7.356  +void pci_piix4_acpi_init(PCIBus *bus, int devfn)
   7.357 @@ -421,7 +209,6 @@ Index: ioemu/hw/piix4acpi.c
   7.358  +        bus, "PIIX4 ACPI", sizeof(PCIAcpiState),
   7.359  +        devfn, NULL, NULL);
   7.360  +
   7.361 -+    acpi_state = d;
   7.362  +    pci_conf = d->dev.config;
   7.363  +    pci_conf[0x00] = 0x86;  /* Intel */
   7.364  +    pci_conf[0x01] = 0x80;
   7.365 @@ -444,14 +231,17 @@ Index: ioemu/hw/piix4acpi.c
   7.366  +     */
   7.367  +    pci_conf[0x40] = 0x41; /* Special device-specific BAR at 0x40 */
   7.368  +    pci_conf[0x41] = 0x1f;
   7.369 ++    pci_conf[0x42] = 0x00;
   7.370 ++    pci_conf[0x43] = 0x00;
   7.371 ++    d->pm1_control = SCI_EN;
   7.372 ++
   7.373  +    acpi_map(d, 0, 0x1f40, 0x10, PCI_ADDRESS_SPACE_IO);
   7.374 -+    acpi_reset(d);
   7.375  +}
   7.376  Index: ioemu/vl.c
   7.377  ===================================================================
   7.378 ---- ioemu.orig/vl.c	2006-12-08 02:00:40.000000000 +0000
   7.379 -+++ ioemu/vl.c	2006-12-08 02:00:40.000000000 +0000
   7.380 -@@ -156,7 +156,7 @@
   7.381 +--- ioemu.orig/vl.c	2007-05-03 15:06:42.000000000 +0100
   7.382 ++++ ioemu/vl.c	2007-05-03 15:07:21.000000000 +0100
   7.383 +@@ -157,7 +157,7 @@
   7.384   #else
   7.385   #define MAX_CPUS 1
   7.386   #endif
   7.387 @@ -460,33 +250,33 @@ Index: ioemu/vl.c
   7.388   int fd_bootchk = 1;
   7.389   
   7.390   extern int vcpus;
   7.391 -@@ -5341,6 +5341,7 @@
   7.392 +@@ -5415,6 +5415,7 @@
   7.393 + #endif
   7.394              "-loadvm file    start right away with a saved state (loadvm in monitor)\n"
   7.395   	   "-vnc display    start a VNC server on display\n"
   7.396 -            "-timeoffset     time offset (in seconds) from local time\n"
   7.397  +           "-acpi           disable or enable ACPI of HVM domain \n"
   7.398              "\n"
   7.399              "During emulation, the following keys are useful:\n"
   7.400              "ctrl-alt-f      toggle full screen\n"
   7.401 -@@ -5426,6 +5427,7 @@
   7.402 +@@ -5499,6 +5500,7 @@
   7.403 + 
   7.404       QEMU_OPTION_d,
   7.405       QEMU_OPTION_vcpus,
   7.406 -     QEMU_OPTION_timeoffset,
   7.407  +    QEMU_OPTION_acpi,
   7.408   };
   7.409   
   7.410   typedef struct QEMUOption {
   7.411 -@@ -5509,6 +5511,7 @@
   7.412 +@@ -5581,6 +5583,7 @@
   7.413 +     
   7.414       { "d", HAS_ARG, QEMU_OPTION_d },
   7.415       { "vcpus", 1, QEMU_OPTION_vcpus },
   7.416 -     { "timeoffset", HAS_ARG, QEMU_OPTION_timeoffset },
   7.417  +    { "acpi", 0, QEMU_OPTION_acpi },
   7.418       { NULL },
   7.419   };
   7.420   
   7.421 -@@ -6240,6 +6243,9 @@
   7.422 -             case QEMU_OPTION_timeoffset:
   7.423 -                 timeoffset = strtol(optarg, NULL, 0);
   7.424 +@@ -6322,6 +6325,9 @@
   7.425 +                 vcpus = atoi(optarg);
   7.426 +                 fprintf(logfile, "qemu: the number of cpus is %d\n", vcpus);
   7.427                   break;
   7.428  +            case QEMU_OPTION_acpi:
   7.429  +                acpi_enabled = 1;
   7.430 @@ -496,8 +286,8 @@ Index: ioemu/vl.c
   7.431       }
   7.432  Index: ioemu/vl.h
   7.433  ===================================================================
   7.434 ---- ioemu.orig/vl.h	2006-12-08 02:00:40.000000000 +0000
   7.435 -+++ ioemu/vl.h	2006-12-08 02:00:40.000000000 +0000
   7.436 +--- ioemu.orig/vl.h	2007-05-03 15:06:42.000000000 +0100
   7.437 ++++ ioemu/vl.h	2007-05-03 15:07:21.000000000 +0100
   7.438  @@ -168,6 +168,7 @@
   7.439   extern int kqemu_allowed;
   7.440   extern int win2k_install_hack;
   7.441 @@ -506,7 +296,7 @@ Index: ioemu/vl.h
   7.442   extern int smp_cpus;
   7.443   
   7.444   /* XXX: make it dynamic */
   7.445 -@@ -923,6 +924,9 @@
   7.446 +@@ -924,6 +925,9 @@
   7.447   void piix4_pm_init(PCIBus *bus, int devfn);
   7.448   void acpi_bios_init(void);
   7.449   
   7.450 @@ -518,8 +308,8 @@ Index: ioemu/vl.h
   7.451   extern QEMUMachine isapc_machine;
   7.452  Index: ioemu/hw/piix_pci.c
   7.453  ===================================================================
   7.454 ---- ioemu.orig/hw/piix_pci.c	2006-12-08 02:00:39.000000000 +0000
   7.455 -+++ ioemu/hw/piix_pci.c	2006-12-08 02:00:40.000000000 +0000
   7.456 +--- ioemu.orig/hw/piix_pci.c	2007-05-03 15:06:42.000000000 +0100
   7.457 ++++ ioemu/hw/piix_pci.c	2007-05-03 15:07:13.000000000 +0100
   7.458  @@ -241,7 +241,7 @@
   7.459   static uint32_t pci_bios_io_addr;
   7.460   static uint32_t pci_bios_mem_addr;
     8.1 --- a/tools/ioemu/patches/acpi-timer-support	Mon May 07 13:24:37 2007 -0600
     8.2 +++ b/tools/ioemu/patches/acpi-timer-support	Tue May 08 09:09:17 2007 -0600
     8.3 @@ -1,8 +1,8 @@
     8.4  Index: ioemu/hw/piix4acpi.c
     8.5  ===================================================================
     8.6 ---- ioemu.orig/hw/piix4acpi.c	2006-12-08 01:35:52.000000000 +0000
     8.7 -+++ ioemu/hw/piix4acpi.c	2006-12-08 01:35:59.000000000 +0000
     8.8 -@@ -24,31 +24,30 @@
     8.9 +--- ioemu.orig/hw/piix4acpi.c	2007-05-02 15:59:22.000000000 +0100
    8.10 ++++ ioemu/hw/piix4acpi.c	2007-05-02 15:59:27.000000000 +0100
    8.11 +@@ -24,26 +24,26 @@
    8.12    */
    8.13   
    8.14   #include "vl.h"
    8.15 @@ -41,20 +41,10 @@ Index: ioemu/hw/piix4acpi.c
    8.16   
    8.17   typedef struct AcpiDeviceState AcpiDeviceState;
    8.18   AcpiDeviceState *acpi_device_table;
    8.19 - 
    8.20 --/* Bits of PM1a register define here  */
    8.21 - typedef struct PM1Event_BLK {
    8.22 -     uint16_t pm1_status; /* pm1a_EVT_BLK */
    8.23 -     uint16_t pm1_enable; /* pm1a_EVT_BLK+2 */
    8.24 -@@ -61,17 +60,11 @@
    8.25 -     uint16_t pm1_enable; /* pm1a_EVT_BLK+2 */
    8.26 +@@ -53,13 +53,6 @@
    8.27       uint16_t pm1_control; /* pm1a_ECNT_BLK */
    8.28 -     uint32_t pm1_timer; /* pmtmr_BLK */
    8.29 -+    uint64_t old_vmck_ticks; /* using vm_clock counter */
    8.30   } PCIAcpiState;
    8.31   
    8.32 - static PCIAcpiState *acpi_state;
    8.33 - 
    8.34  -static inline void acpi_set_irq(PCIAcpiState *s)
    8.35  -{
    8.36  -/* no real SCI event need for now, so comment the following line out */
    8.37 @@ -62,92 +52,10 @@ Index: ioemu/hw/piix4acpi.c
    8.38  -    printf("acpi_set_irq: s->irq %x \n",s->irq);
    8.39  -}
    8.40  -
    8.41 - static void acpi_reset(PCIAcpiState *s)
    8.42 - {
    8.43 -     uint8_t *pci_conf;
    8.44 -@@ -84,6 +77,7 @@
    8.45 -     s->pm1_enable = 0x00;    /* TMROF_EN should cleared */
    8.46 -     s->pm1_control = SCI_EN; /* SCI_EN */
    8.47 -     s->pm1_timer = 0;
    8.48 -+    s->old_vmck_ticks = qemu_get_clock(vm_clock);
    8.49 - }
    8.50 - 
    8.51 - /*byte access  */
    8.52 -@@ -95,8 +89,8 @@
    8.53 -         s->pm1_status = s->pm1_status&!TMROF_STS;
    8.54 - 
    8.55 -     if ((val&GBL_STS)==GBL_STS)
    8.56 --        s->pm1_status = s->pm1_status&!GBL_STS;     
    8.57 --    
    8.58 -+        s->pm1_status = s->pm1_status&!GBL_STS;
    8.59 -+
    8.60 - /*     printf("acpiPm1Status_writeb \n addr %x val:%x pm1_status:%x \n", addr, val,s->pm1_status); */
    8.61 - }
    8.62 - 
    8.63 -@@ -115,7 +109,7 @@
    8.64 + static void acpiPm1Control_writeb(void *opaque, uint32_t addr, uint32_t val)
    8.65   {
    8.66       PCIAcpiState *s = opaque;
    8.67 - 
    8.68 --     s->pm1_status = (val<<8)||(s->pm1_status);
    8.69 -+    s->pm1_status = (val<<8)||(s->pm1_status);
    8.70 - /*     printf("acpiPm1StatusP1_writeb \n addr %x val:%x\n", addr, val); */
    8.71 - }
    8.72 - 
    8.73 -@@ -220,7 +214,7 @@
    8.74 -         s->pm1_status = s->pm1_status&!TMROF_STS;
    8.75 - 
    8.76 -     if ((val&GBL_STS)==GBL_STS)
    8.77 --        s->pm1_status = s->pm1_status&!GBL_STS;     
    8.78 -+        s->pm1_status = s->pm1_status&!GBL_STS;
    8.79 - 
    8.80 - /*    printf("acpiPm1Status_writew \n addr %x val:%x pm1_status:%x \n", addr, val,s->pm1_status); */
    8.81 - }
    8.82 -@@ -288,13 +282,15 @@
    8.83 - 
    8.84 - }
    8.85 - 
    8.86 --static void acpiPm1Event_readl(void *opaque, uint32_t addr)
    8.87 -+static uint32_t acpiPm1Event_readl(void *opaque, uint32_t addr)
    8.88 - {
    8.89 -     PCIAcpiState *s = opaque;
    8.90 -     uint32_t val;
    8.91 - 
    8.92 --    val=s->pm1_status|(s->pm1_enable<<16);
    8.93 -+    val = s->pm1_status|(s->pm1_enable<<16);
    8.94 - /*    printf("acpiPm1Event_readl \n addr %x val:%x\n", addr, val);    */
    8.95 -+
    8.96 -+    return val;
    8.97 - }
    8.98 - 
    8.99 - static void acpiPm1Timer_writel(void *opaque, uint32_t addr, uint32_t val)
   8.100 -@@ -302,17 +298,21 @@
   8.101 -     PCIAcpiState *s = opaque;
   8.102 - 
   8.103 -     s->pm1_timer = val;
   8.104 --/*    printf("acpiPm1Timer_writel \n addr %x val:%x\n", addr, val); */
   8.105 -+    s->old_vmck_ticks = qemu_get_clock(vm_clock) +
   8.106 -+        muldiv64(val, FREQUENCE_PMTIMER, ticks_per_sec);
   8.107 - }
   8.108 - 
   8.109 - static uint32_t acpiPm1Timer_readl(void *opaque, uint32_t addr)
   8.110 - {
   8.111 -     PCIAcpiState *s = opaque;
   8.112 --    uint32_t val;
   8.113 -+    int64_t current_vmck_ticks = qemu_get_clock(vm_clock);
   8.114 -+    int64_t vmck_ticks_delta = current_vmck_ticks - s->old_vmck_ticks;
   8.115 - 
   8.116 --    val = s->pm1_timer;
   8.117 --/*    printf("acpiPm1Timer_readl \n addr %x val:%x\n", addr, val); */
   8.118 --    return val;
   8.119 -+    if (s->old_vmck_ticks)
   8.120 -+        s->pm1_timer += muldiv64(vmck_ticks_delta, FREQUENCE_PMTIMER,
   8.121 -+                                 ticks_per_sec);
   8.122 -+    s->old_vmck_ticks = current_vmck_ticks;
   8.123 -+    return s->pm1_timer;
   8.124 - }
   8.125 - 
   8.126 - static void acpi_map(PCIDevice *pci_dev, int region_num,
   8.127 -@@ -320,7 +320,7 @@
   8.128 +@@ -132,7 +125,7 @@
   8.129   {
   8.130       PCIAcpiState *d = (PCIAcpiState *)pci_dev;
   8.131   
   8.132 @@ -155,34 +63,4 @@ Index: ioemu/hw/piix4acpi.c
   8.133  +    printf("register acpi io\n");
   8.134   
   8.135       /* Byte access */
   8.136 -     register_ioport_write(addr, 1, 1, acpiPm1Status_writeb, d);
   8.137 -@@ -336,14 +336,14 @@
   8.138       register_ioport_write(addr + 4, 1, 1, acpiPm1Control_writeb, d);
   8.139 -     register_ioport_read(addr + 4, 1, 1, acpiPm1Control_readb, d);
   8.140 -     register_ioport_write(addr + 4 + 1, 1, 1, acpiPm1ControlP1_writeb, d);
   8.141 --    register_ioport_read(addr + 4 +1, 1, 1, acpiPm1ControlP1_readb, d);	
   8.142 -+    register_ioport_read(addr + 4 +1, 1, 1, acpiPm1ControlP1_readb, d);
   8.143 - 
   8.144 -     /* Word access */
   8.145 -     register_ioport_write(addr, 2, 2, acpiPm1Status_writew, d);
   8.146 -     register_ioport_read(addr, 2, 2, acpiPm1Status_readw, d);
   8.147 - 
   8.148 -     register_ioport_write(addr + 2, 2, 2, acpiPm1Enable_writew, d);
   8.149 --    register_ioport_read(addr + 2, 2, 2, acpiPm1Enable_readw, d); 
   8.150 -+    register_ioport_read(addr + 2, 2, 2, acpiPm1Enable_readw, d);
   8.151 - 
   8.152 -     register_ioport_write(addr + 4, 2, 2, acpiPm1Control_writew, d);
   8.153 -     register_ioport_read(addr + 4, 2, 2, acpiPm1Control_readw, d);
   8.154 -@@ -351,11 +351,10 @@
   8.155 -     /* DWord access */
   8.156 -     register_ioport_write(addr, 4, 4, acpiPm1Event_writel, d);
   8.157 -     register_ioport_read(addr, 4, 4, acpiPm1Event_readl, d);
   8.158 --		
   8.159 -+
   8.160 -     register_ioport_write(addr + 8, 4, 4, acpiPm1Timer_writel, d);
   8.161 -     register_ioport_read(addr + 8, 4, 4, acpiPm1Timer_readl, d);
   8.162 - }
   8.163 --													
   8.164 - 
   8.165 - /* PIIX4 acpi pci configuration space, func 2 */
   8.166 - void pci_piix4_acpi_init(PCIBus *bus, int devfn)
     9.1 --- a/tools/ioemu/patches/domain-destroy	Mon May 07 13:24:37 2007 -0600
     9.2 +++ b/tools/ioemu/patches/domain-destroy	Tue May 08 09:09:17 2007 -0600
     9.3 @@ -1,7 +1,7 @@
     9.4  Index: ioemu/monitor.c
     9.5  ===================================================================
     9.6 ---- ioemu.orig/monitor.c	2006-12-08 01:26:07.000000000 +0000
     9.7 -+++ ioemu/monitor.c	2006-12-08 01:26:08.000000000 +0000
     9.8 +--- ioemu.orig/monitor.c	2007-05-03 14:54:59.000000000 +0100
     9.9 ++++ ioemu/monitor.c	2007-05-03 14:55:01.000000000 +0100
    9.10  @@ -308,6 +308,7 @@
    9.11   
    9.12   static void do_quit(void)
    9.13 @@ -12,13 +12,14 @@ Index: ioemu/monitor.c
    9.14   
    9.15  Index: ioemu/target-i386-dm/helper2.c
    9.16  ===================================================================
    9.17 ---- ioemu.orig/target-i386-dm/helper2.c	2006-12-08 01:26:08.000000000 +0000
    9.18 -+++ ioemu/target-i386-dm/helper2.c	2006-12-08 01:26:08.000000000 +0000
    9.19 -@@ -507,5 +507,25 @@
    9.20 +--- ioemu.orig/target-i386-dm/helper2.c	2007-05-03 14:55:00.000000000 +0100
    9.21 ++++ ioemu/target-i386-dm/helper2.c	2007-05-03 14:55:01.000000000 +0100
    9.22 +@@ -549,5 +549,26 @@
    9.23           /* Wait up to 10 msec. */
    9.24           main_loop_wait(10);
    9.25 -     }
    9.26 + 
    9.27  +    destroy_hvm_domain();
    9.28 ++
    9.29       return 0;
    9.30   }
    9.31  +
    9.32 @@ -42,8 +43,8 @@ Index: ioemu/target-i386-dm/helper2.c
    9.33  +}
    9.34  Index: ioemu/vl.h
    9.35  ===================================================================
    9.36 ---- ioemu.orig/vl.h	2006-12-08 01:26:08.000000000 +0000
    9.37 -+++ ioemu/vl.h	2006-12-08 01:26:08.000000000 +0000
    9.38 +--- ioemu.orig/vl.h	2007-05-03 14:55:00.000000000 +0100
    9.39 ++++ ioemu/vl.h	2007-05-03 14:55:01.000000000 +0100
    9.40  @@ -1190,4 +1190,7 @@
    9.41   void kqemu_record_dump(void);
    9.42   
    10.1 --- a/tools/ioemu/patches/domain-reset	Mon May 07 13:24:37 2007 -0600
    10.2 +++ b/tools/ioemu/patches/domain-reset	Tue May 08 09:09:17 2007 -0600
    10.3 @@ -1,17 +1,14 @@
    10.4  Index: ioemu/target-i386-dm/helper2.c
    10.5  ===================================================================
    10.6 ---- ioemu.orig/target-i386-dm/helper2.c	2006-12-08 01:26:06.000000000 +0000
    10.7 -+++ ioemu/target-i386-dm/helper2.c	2006-12-08 01:26:08.000000000 +0000
    10.8 -@@ -127,6 +127,25 @@
    10.9 +--- ioemu.orig/target-i386-dm/helper2.c	2007-05-03 14:54:46.000000000 +0100
   10.10 ++++ ioemu/target-i386-dm/helper2.c	2007-05-03 14:55:00.000000000 +0100
   10.11 +@@ -127,6 +127,22 @@
   10.12   /* called from main_cpu_reset */
   10.13   void cpu_reset(CPUX86State *env)
   10.14   {
   10.15  +    int xcHandle;
   10.16  +    int sts;
   10.17  +
   10.18 -+    /* pause domain first, to avoid repeated reboot request*/
   10.19 -+    xc_domain_pause(xc_handle, domid);
   10.20 -+
   10.21  +    xcHandle = xc_interface_open();
   10.22  +    if (xcHandle < 0)
   10.23  +        fprintf(logfile, "Cannot acquire xenctrl handle\n");
   10.24 @@ -28,22 +25,28 @@ Index: ioemu/target-i386-dm/helper2.c
   10.25   }
   10.26   
   10.27   void cpu_x86_close(CPUX86State *env)
   10.28 -@@ -479,6 +498,10 @@
   10.29 -         if (vm_running) {
   10.30 -             if (shutdown_requested)
   10.31 -                 break;
   10.32 -+            if (reset_requested) {
   10.33 -+                qemu_system_reset();
   10.34 -+                reset_requested = 0;
   10.35 -+            }
   10.36 -         }
   10.37 +@@ -529,14 +545,9 @@
   10.38 + 
   10.39 +     qemu_set_fd_handler(evtchn_fd, cpu_handle_ioreq, NULL, env);
   10.40   
   10.41 +-    while (1) {
   10.42 +-        if (vm_running) {
   10.43 +-            if (shutdown_requested)
   10.44 +-                break;
   10.45 +-        }
   10.46 +-
   10.47 ++    while (!(vm_running && suspend_requested))
   10.48           /* Wait up to 10 msec. */
   10.49 +         main_loop_wait(10);
   10.50 +-    }
   10.51 ++
   10.52 +     return 0;
   10.53 + }
   10.54  Index: ioemu/vl.c
   10.55  ===================================================================
   10.56 ---- ioemu.orig/vl.c	2006-12-08 01:26:08.000000000 +0000
   10.57 -+++ ioemu/vl.c	2006-12-08 01:26:08.000000000 +0000
   10.58 -@@ -4948,7 +4948,7 @@
   10.59 +--- ioemu.orig/vl.c	2007-05-03 14:55:00.000000000 +0100
   10.60 ++++ ioemu/vl.c	2007-05-03 14:55:00.000000000 +0100
   10.61 +@@ -4957,7 +4957,7 @@
   10.62   } QEMUResetEntry;
   10.63   
   10.64   static QEMUResetEntry *first_reset_entry;
   10.65 @@ -54,8 +57,8 @@ Index: ioemu/vl.c
   10.66   
   10.67  Index: ioemu/vl.h
   10.68  ===================================================================
   10.69 ---- ioemu.orig/vl.h	2006-12-08 01:26:07.000000000 +0000
   10.70 -+++ ioemu/vl.h	2006-12-08 01:26:08.000000000 +0000
   10.71 +--- ioemu.orig/vl.h	2007-05-03 14:55:00.000000000 +0100
   10.72 ++++ ioemu/vl.h	2007-05-03 14:55:00.000000000 +0100
   10.73  @@ -131,6 +131,7 @@
   10.74   
   10.75   void qemu_register_reset(QEMUResetHandler *func, void *opaque);
    11.1 --- a/tools/ioemu/patches/domain-timeoffset	Mon May 07 13:24:37 2007 -0600
    11.2 +++ b/tools/ioemu/patches/domain-timeoffset	Tue May 08 09:09:17 2007 -0600
    11.3 @@ -1,7 +1,7 @@
    11.4  Index: ioemu/hw/mc146818rtc.c
    11.5  ===================================================================
    11.6 ---- ioemu.orig/hw/mc146818rtc.c	2006-12-20 15:21:33.000000000 +0000
    11.7 -+++ ioemu/hw/mc146818rtc.c	2006-12-20 15:21:50.000000000 +0000
    11.8 +--- ioemu.orig/hw/mc146818rtc.c	2007-05-03 15:38:35.000000000 +0100
    11.9 ++++ ioemu/hw/mc146818rtc.c	2007-05-03 15:38:45.000000000 +0100
   11.10  @@ -178,10 +178,27 @@
   11.11       }
   11.12   }
   11.13 @@ -46,8 +46,8 @@ Index: ioemu/hw/mc146818rtc.c
   11.14   static void rtc_copy_date(RTCState *s)
   11.15  Index: ioemu/hw/pc.c
   11.16  ===================================================================
   11.17 ---- ioemu.orig/hw/pc.c	2006-12-20 15:21:49.000000000 +0000
   11.18 -+++ ioemu/hw/pc.c	2006-12-20 15:21:50.000000000 +0000
   11.19 +--- ioemu.orig/hw/pc.c	2007-05-03 15:38:44.000000000 +0100
   11.20 ++++ ioemu/hw/pc.c	2007-05-03 15:38:45.000000000 +0100
   11.21  @@ -159,7 +159,7 @@
   11.22   }
   11.23   
   11.24 @@ -81,9 +81,9 @@ Index: ioemu/hw/pc.c
   11.25  -    cmos_init(ram_size, boot_device, bs_table);
   11.26  +    cmos_init(ram_size, boot_device, bs_table, timeoffset);
   11.27   
   11.28 -     if (pci_enabled && usb_enabled) {
   11.29 -         usb_uhci_init(pci_bus, piix3_devfn + 2);
   11.30 -@@ -912,12 +913,13 @@
   11.31 +     /* using PIIX4 acpi model */
   11.32 +     if (pci_enabled && acpi_enabled)
   11.33 +@@ -920,12 +921,13 @@
   11.34                           int snapshot, 
   11.35                           const char *kernel_filename, 
   11.36                           const char *kernel_cmdline,
   11.37 @@ -99,7 +99,7 @@ Index: ioemu/hw/pc.c
   11.38   }
   11.39   
   11.40   static void pc_init_isa(uint64_t ram_size, int vga_ram_size, int boot_device,
   11.41 -@@ -925,12 +927,13 @@
   11.42 +@@ -933,12 +935,13 @@
   11.43                           int snapshot, 
   11.44                           const char *kernel_filename, 
   11.45                           const char *kernel_cmdline,
   11.46 @@ -117,9 +117,9 @@ Index: ioemu/hw/pc.c
   11.47   QEMUMachine pc_machine = {
   11.48  Index: ioemu/vl.c
   11.49  ===================================================================
   11.50 ---- ioemu.orig/vl.c	2006-12-20 15:21:49.000000000 +0000
   11.51 -+++ ioemu/vl.c	2006-12-20 15:21:50.000000000 +0000
   11.52 -@@ -163,6 +163,8 @@
   11.53 +--- ioemu.orig/vl.c	2007-05-03 15:38:45.000000000 +0100
   11.54 ++++ ioemu/vl.c	2007-05-03 15:38:45.000000000 +0100
   11.55 +@@ -167,6 +167,8 @@
   11.56   
   11.57   int xc_handle;
   11.58   
   11.59 @@ -128,41 +128,51 @@ Index: ioemu/vl.c
   11.60   char domain_name[1024] = { 'H','V', 'M', 'X', 'E', 'N', '-'};
   11.61   extern int domid;
   11.62   
   11.63 -@@ -5338,6 +5340,7 @@
   11.64 - #endif
   11.65 -            "-loadvm file    start right away with a saved state (loadvm in monitor)\n"
   11.66 - 	   "-vnc display    start a VNC server on display\n"
   11.67 +@@ -5435,6 +5437,7 @@
   11.68 +            "-vncviewer      start a vncviewer process for this domain\n"
   11.69 +            "-vncunused      bind the VNC server to an unused port\n"
   11.70 +            "-vnclisten      bind the VNC server to this address\n"
   11.71  +           "-timeoffset     time offset (in seconds) from local time\n"
   11.72 +            "-acpi           disable or enable ACPI of HVM domain \n"
   11.73              "\n"
   11.74              "During emulation, the following keys are useful:\n"
   11.75 -            "ctrl-alt-f      toggle full screen\n"
   11.76 -@@ -5422,6 +5425,7 @@
   11.77 +@@ -5522,6 +5525,7 @@
   11.78   
   11.79       QEMU_OPTION_d,
   11.80       QEMU_OPTION_vcpus,
   11.81  +    QEMU_OPTION_timeoffset,
   11.82 - };
   11.83 - 
   11.84 - typedef struct QEMUOption {
   11.85 -@@ -5504,6 +5508,7 @@
   11.86 +     QEMU_OPTION_acpi,
   11.87 +     QEMU_OPTION_vncviewer,
   11.88 +     QEMU_OPTION_vncunused,
   11.89 +@@ -5613,6 +5617,7 @@
   11.90       
   11.91       { "d", HAS_ARG, QEMU_OPTION_d },
   11.92       { "vcpus", 1, QEMU_OPTION_vcpus },
   11.93  +    { "timeoffset", HAS_ARG, QEMU_OPTION_timeoffset },
   11.94 +     { "acpi", 0, QEMU_OPTION_acpi },
   11.95       { NULL },
   11.96   };
   11.97 - 
   11.98 -@@ -6232,6 +6237,9 @@
   11.99 +@@ -6377,6 +6382,9 @@
  11.100                   vcpus = atoi(optarg);
  11.101                   fprintf(logfile, "qemu: the number of cpus is %d\n", vcpus);
  11.102                   break;
  11.103  +            case QEMU_OPTION_timeoffset:
  11.104  +                timeoffset = strtol(optarg, NULL, 0);
  11.105  +                break;
  11.106 -             }
  11.107 -         }
  11.108 +             case QEMU_OPTION_acpi:
  11.109 +                 acpi_enabled = 1;
  11.110 +                 break;
  11.111 +@@ -6531,6 +6539,9 @@
  11.112       }
  11.113 -@@ -6484,7 +6492,8 @@
  11.114 +     free(page_array);
  11.115 + #endif
  11.116 ++
  11.117 ++    timeoffset_get();
  11.118 ++
  11.119 + #else  /* !CONFIG_DM */
  11.120 + 
  11.121 +     phys_ram_base = qemu_vmalloc(phys_ram_size);
  11.122 +@@ -6662,7 +6673,8 @@
  11.123   
  11.124       machine->init(ram_size, vga_ram_size, boot_device,
  11.125                     ds, fd_filename, snapshot,
  11.126 @@ -174,9 +184,9 @@ Index: ioemu/vl.c
  11.127       if (usb_enabled) {
  11.128  Index: ioemu/vl.h
  11.129  ===================================================================
  11.130 ---- ioemu.orig/vl.h	2006-12-20 15:21:49.000000000 +0000
  11.131 -+++ ioemu/vl.h	2006-12-20 15:21:50.000000000 +0000
  11.132 -@@ -576,7 +576,7 @@
  11.133 +--- ioemu.orig/vl.h	2007-05-03 15:38:45.000000000 +0100
  11.134 ++++ ioemu/vl.h	2007-05-03 15:38:45.000000000 +0100
  11.135 +@@ -581,7 +581,7 @@
  11.136                                    int boot_device,
  11.137                DisplayState *ds, const char **fd_filename, int snapshot,
  11.138                const char *kernel_filename, const char *kernel_cmdline,
  11.139 @@ -185,3 +195,72 @@ Index: ioemu/vl.h
  11.140   
  11.141   typedef struct QEMUMachine {
  11.142       const char *name;
  11.143 +@@ -1216,6 +1216,10 @@
  11.144 + int xenstore_vm_write(int domid, char *key, char *val);
  11.145 + char *xenstore_vm_read(int domid, char *key, int *len);
  11.146 + 
  11.147 ++/* helper2.c */
  11.148 ++extern long time_offset;
  11.149 ++void timeoffset_get(void);
  11.150 ++
  11.151 + void kqemu_record_dump(void);
  11.152 + 
  11.153 + extern char domain_name[];
  11.154 +Index: ioemu/target-i386-dm/helper2.c
  11.155 +===================================================================
  11.156 +--- ioemu.orig/target-i386-dm/helper2.c	2007-05-03 15:38:44.000000000 +0100
  11.157 ++++ ioemu/target-i386-dm/helper2.c	2007-05-03 15:38:45.000000000 +0100
  11.158 +@@ -74,6 +74,8 @@
  11.159 + 
  11.160 + int xc_handle;
  11.161 + 
  11.162 ++long time_offset = 0;
  11.163 ++
  11.164 + shared_iopage_t *shared_page = NULL;
  11.165 + 
  11.166 + /* the evtchn fd for polling */
  11.167 +@@ -447,6 +449,34 @@
  11.168 +     req->data = tmp1;
  11.169 + }
  11.170 + 
  11.171 ++void timeoffset_get()
  11.172 ++{
  11.173 ++    char *p;
  11.174 ++
  11.175 ++    p = xenstore_vm_read(domid, "rtc/timeoffset", NULL);
  11.176 ++    if (!p)
  11.177 ++	return;
  11.178 ++
  11.179 ++    if (sscanf(p, "%ld", &time_offset) == 1)
  11.180 ++	fprintf(logfile, "Time offset set %ld\n", time_offset);
  11.181 ++    else
  11.182 ++	time_offset = 0;
  11.183 ++
  11.184 ++    xc_domain_set_time_offset(xc_handle, domid, time_offset);
  11.185 ++
  11.186 ++    free(p);
  11.187 ++}
  11.188 ++
  11.189 ++void cpu_ioreq_timeoffset(CPUState *env, ioreq_t *req)
  11.190 ++{
  11.191 ++    char b[64];
  11.192 ++
  11.193 ++    time_offset += (ulong)req->data;
  11.194 ++
  11.195 ++    sprintf(b, "%ld", time_offset);
  11.196 ++    xenstore_vm_write(domid, "rtc/timeoffset", b);
  11.197 ++}
  11.198 ++
  11.199 + void cpu_ioreq_xchg(CPUState *env, ioreq_t *req)
  11.200 + {
  11.201 +     unsigned long tmp1;
  11.202 +@@ -497,6 +527,9 @@
  11.203 +         case IOREQ_TYPE_XCHG:
  11.204 +             cpu_ioreq_xchg(env, req);
  11.205 +             break;
  11.206 ++	case IOREQ_TYPE_TIMEOFFSET:
  11.207 ++            cpu_ioreq_timeoffset(env, req);
  11.208 ++            break;
  11.209 +         default:
  11.210 +             hw_error("Invalid ioreq type 0x%x\n", req->type);
  11.211 +         }
    12.1 --- a/tools/ioemu/patches/hypervisor-pit	Mon May 07 13:24:37 2007 -0600
    12.2 +++ b/tools/ioemu/patches/hypervisor-pit	Tue May 08 09:09:17 2007 -0600
    12.3 @@ -1,7 +1,7 @@
    12.4  Index: ioemu/Makefile.target
    12.5  ===================================================================
    12.6 ---- ioemu.orig/Makefile.target	2006-12-08 01:41:12.000000000 +0000
    12.7 -+++ ioemu/Makefile.target	2006-12-08 01:41:12.000000000 +0000
    12.8 +--- ioemu.orig/Makefile.target	2007-05-03 10:07:52.000000000 +0100
    12.9 ++++ ioemu/Makefile.target	2007-05-03 10:07:53.000000000 +0100
   12.10  @@ -355,7 +355,7 @@
   12.11   ifeq ($(TARGET_BASE_ARCH), i386)
   12.12   # Hardware support
   12.13 @@ -13,8 +13,8 @@ Index: ioemu/Makefile.target
   12.14   DEFINES += -DHAS_AUDIO
   12.15  Index: ioemu/hw/pc.c
   12.16  ===================================================================
   12.17 ---- ioemu.orig/hw/pc.c	2006-12-08 01:41:12.000000000 +0000
   12.18 -+++ ioemu/hw/pc.c	2006-12-08 01:41:12.000000000 +0000
   12.19 +--- ioemu.orig/hw/pc.c	2007-05-03 10:07:52.000000000 +0100
   12.20 ++++ ioemu/hw/pc.c	2007-05-03 10:07:53.000000000 +0100
   12.21  @@ -38,7 +38,9 @@
   12.22   
   12.23   static fdctrl_t *floppy_controller;
   12.24 @@ -38,9 +38,9 @@ Index: ioemu/hw/pc.c
   12.25           pic_set_alt_irq_func(isa_pic, ioapic_set_irq, ioapic);
   12.26  Index: ioemu/vl.c
   12.27  ===================================================================
   12.28 ---- ioemu.orig/vl.c	2006-12-08 01:41:12.000000000 +0000
   12.29 -+++ ioemu/vl.c	2006-12-08 01:41:12.000000000 +0000
   12.30 -@@ -5570,6 +5570,7 @@
   12.31 +--- ioemu.orig/vl.c	2007-05-03 10:07:53.000000000 +0100
   12.32 ++++ ioemu/vl.c	2007-05-03 10:07:53.000000000 +0100
   12.33 +@@ -5622,6 +5622,7 @@
   12.34   
   12.35   #ifdef HAS_AUDIO
   12.36   struct soundhw soundhw[] = {
   12.37 @@ -48,7 +48,7 @@ Index: ioemu/vl.c
   12.38   #ifdef TARGET_I386
   12.39       {
   12.40           "pcspk",
   12.41 -@@ -5579,6 +5580,7 @@
   12.42 +@@ -5631,6 +5632,7 @@
   12.43           { .init_isa = pcspk_audio_init }
   12.44       },
   12.45   #endif
    13.1 --- a/tools/ioemu/patches/ide-cd-dma	Mon May 07 13:24:37 2007 -0600
    13.2 +++ b/tools/ioemu/patches/ide-cd-dma	Tue May 08 09:09:17 2007 -0600
    13.3 @@ -5,9 +5,11 @@
    13.4  [HVM] Enable DMA mode for CD-ROM IDE ATAPI interface.
    13.5  Signed-off-by: Winston Wang <winston.l.wang@intel.com
    13.6  
    13.7 ---- ioemu/hw/ide.c	Wed Oct 18 18:37:18 2006 +0100
    13.8 -+++ ioemu/hw/ide.c	Wed Oct 18 18:41:47 2006 +0100
    13.9 -@@ -557,9 +557,9 @@ static void ide_atapi_identify(IDEState 
   13.10 +Index: ioemu/hw/ide.c
   13.11 +===================================================================
   13.12 +--- ioemu.orig/hw/ide.c	2007-05-03 15:07:16.000000000 +0100
   13.13 ++++ ioemu/hw/ide.c	2007-05-03 15:07:16.000000000 +0100
   13.14 +@@ -713,9 +713,9 @@
   13.15       padstr((uint8_t *)(p + 23), QEMU_VERSION, 8); /* firmware version */
   13.16       padstr((uint8_t *)(p + 27), "QEMU CD-ROM", 40); /* model */
   13.17       put_le16(p + 48, 1); /* dword I/O (XXX: should not be set on CDROM) */
    14.1 --- a/tools/ioemu/patches/ide-error-reporting	Mon May 07 13:24:37 2007 -0600
    14.2 +++ b/tools/ioemu/patches/ide-error-reporting	Tue May 08 09:09:17 2007 -0600
    14.3 @@ -33,9 +33,9 @@ Signed-off-by: Keir Fraser <keir@xensour
    14.4  
    14.5  Index: ioemu/hw/ide.c
    14.6  ===================================================================
    14.7 ---- ioemu.orig/hw/ide.c	2006-12-08 18:21:36.000000000 +0000
    14.8 -+++ ioemu/hw/ide.c	2006-12-08 18:23:18.000000000 +0000
    14.9 -@@ -680,7 +680,7 @@
   14.10 +--- ioemu.orig/hw/ide.c	2007-05-03 15:07:16.000000000 +0100
   14.11 ++++ ioemu/hw/ide.c	2007-05-03 15:07:17.000000000 +0100
   14.12 +@@ -838,7 +838,7 @@
   14.13   static void ide_sector_read(IDEState *s)
   14.14   {
   14.15       int64_t sector_num;
   14.16 @@ -44,7 +44,7 @@ Index: ioemu/hw/ide.c
   14.17   
   14.18       s->status = READY_STAT | SEEK_STAT;
   14.19       s->error = 0; /* not needed by IDE spec, but needed by Windows */
   14.20 -@@ -695,7 +695,11 @@
   14.21 +@@ -853,7 +853,11 @@
   14.22   #endif
   14.23           if (n > s->req_nb_sectors)
   14.24               n = s->req_nb_sectors;
   14.25 @@ -57,7 +57,7 @@ Index: ioemu/hw/ide.c
   14.26           ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_read);
   14.27           ide_set_irq(s);
   14.28           ide_set_sector(s, sector_num + n);
   14.29 -@@ -721,7 +725,11 @@
   14.30 +@@ -879,7 +883,11 @@
   14.31               if (n > MAX_MULT_SECTORS)
   14.32                   n = MAX_MULT_SECTORS;
   14.33               sector_num = ide_get_sector(s);
   14.34 @@ -70,7 +70,7 @@ Index: ioemu/hw/ide.c
   14.35               s->io_buffer_index = 0;
   14.36               s->io_buffer_size = n * 512;
   14.37               len = s->io_buffer_size;
   14.38 -@@ -767,7 +775,7 @@
   14.39 +@@ -925,7 +933,7 @@
   14.40   static void ide_sector_write(IDEState *s)
   14.41   {
   14.42       int64_t sector_num;
   14.43 @@ -79,7 +79,7 @@ Index: ioemu/hw/ide.c
   14.44   
   14.45       s->status = READY_STAT | SEEK_STAT;
   14.46       sector_num = ide_get_sector(s);
   14.47 -@@ -777,7 +785,11 @@
   14.48 +@@ -935,7 +943,11 @@
   14.49       n = s->nsector;
   14.50       if (n > s->req_nb_sectors)
   14.51           n = s->req_nb_sectors;
   14.52 @@ -92,7 +92,7 @@ Index: ioemu/hw/ide.c
   14.53       s->nsector -= n;
   14.54       if (s->nsector == 0) {
   14.55           /* no more sector to write */
   14.56 -@@ -823,8 +835,13 @@
   14.57 +@@ -981,8 +993,13 @@
   14.58           if (len == 0) {
   14.59               n = s->io_buffer_size >> 9;
   14.60               sector_num = ide_get_sector(s);
    15.1 --- a/tools/ioemu/patches/ide-hd-multithread	Mon May 07 13:24:37 2007 -0600
    15.2 +++ b/tools/ioemu/patches/ide-hd-multithread	Tue May 08 09:09:17 2007 -0600
    15.3 @@ -1,7 +1,7 @@
    15.4  Index: ioemu/hw/ide.c
    15.5  ===================================================================
    15.6 ---- ioemu.orig/hw/ide.c	2006-08-17 19:37:36.267534285 +0100
    15.7 -+++ ioemu/hw/ide.c	2006-08-17 19:49:57.830375828 +0100
    15.8 +--- ioemu.orig/hw/ide.c	2007-05-03 15:03:18.000000000 +0100
    15.9 ++++ ioemu/hw/ide.c	2007-05-03 15:06:48.000000000 +0100
   15.10  @@ -22,6 +22,7 @@
   15.11    * THE SOFTWARE.
   15.12    */
   15.13 @@ -10,7 +10,7 @@ Index: ioemu/hw/ide.c
   15.14   
   15.15   /* debug IDE devices */
   15.16   //#define DEBUG_IDE
   15.17 -@@ -390,6 +391,48 @@
   15.18 +@@ -390,6 +391,89 @@
   15.19       int type; /* see IDE_TYPE_xxx */
   15.20   } PCIIDEState;
   15.21   
   15.22 @@ -18,17 +18,41 @@ Index: ioemu/hw/ide.c
   15.23  +
   15.24  +#ifdef DMA_MULTI_THREAD
   15.25  +
   15.26 ++static pthread_t ide_dma_thread;
   15.27  +static int file_pipes[2];
   15.28  +
   15.29  +static void ide_dma_loop(BMDMAState *bm);
   15.30  +static void dma_thread_loop(BMDMAState *bm);
   15.31  +
   15.32 ++extern int suspend_requested;
   15.33  +static void *dma_thread_func(void* opaque)
   15.34  +{
   15.35  +    BMDMAState* req;
   15.36 ++    fd_set fds;
   15.37 ++    int rv, nfds = file_pipes[0] + 1;
   15.38 ++    struct timeval tm;
   15.39  +
   15.40 -+    while (read(file_pipes[0], &req, sizeof(req))) {
   15.41 -+        dma_thread_loop(req);
   15.42 ++    while (1) {
   15.43 ++
   15.44 ++        /* Wait at most a second for the pipe to become readable */
   15.45 ++        FD_ZERO(&fds);
   15.46 ++        FD_SET(file_pipes[0], &fds);
   15.47 ++        tm.tv_sec = 1;
   15.48 ++        tm.tv_usec = 0;
   15.49 ++        rv = select(nfds, &fds, NULL, NULL, &tm);
   15.50 ++        
   15.51 ++        if (rv != 0) {
   15.52 ++            if (read(file_pipes[0], &req, sizeof(req)) == 0)
   15.53 ++                return NULL;
   15.54 ++            dma_thread_loop(req);
   15.55 ++        } else {
   15.56 ++            if (suspend_requested)  {
   15.57 ++                /* Need to tidy up the DMA thread so that we don't end up 
   15.58 ++                 * finishing operations after the domain's ioreqs are 
   15.59 ++                 * drained and its state saved */
   15.60 ++                return NULL;
   15.61 ++            }
   15.62 ++        }
   15.63  +    }
   15.64  +
   15.65  +    return NULL;
   15.66 @@ -36,30 +60,47 @@ Index: ioemu/hw/ide.c
   15.67  +
   15.68  +static void dma_create_thread(void)
   15.69  +{
   15.70 -+    pthread_t tid;
   15.71  +    int rt;
   15.72 ++    pthread_attr_t a;
   15.73  +
   15.74  +    if (pipe(file_pipes) != 0) {
   15.75  +        fprintf(stderr, "create pipe failed\n");
   15.76  +        exit(1);
   15.77  +    }
   15.78  +
   15.79 -+    if ((rt = pthread_create(&tid, NULL, dma_thread_func, NULL))) {
   15.80 ++    if ((rt = pthread_attr_init(&a))
   15.81 ++        || (rt = pthread_attr_setdetachstate(&a, PTHREAD_CREATE_JOINABLE))) {
   15.82 ++        fprintf(stderr, "Oops, dma thread attr setup failed, errno=%d\n", rt);
   15.83 ++        exit(1);
   15.84 ++    }    
   15.85 ++    
   15.86 ++    if ((rt = pthread_create(&ide_dma_thread, &a, dma_thread_func, NULL))) {
   15.87  +        fprintf(stderr, "Oops, dma thread creation failed, errno=%d\n", rt);
   15.88  +        exit(1);
   15.89  +    }
   15.90 ++}
   15.91  +
   15.92 -+    if ((rt = pthread_detach(tid))) {
   15.93 -+        fprintf(stderr, "Oops, dma thread detachment failed, errno=%d\n", rt);
   15.94 -+        exit(1);
   15.95 ++void ide_stop_dma_thread(void)
   15.96 ++{
   15.97 ++    int rc;
   15.98 ++    /* Make sure the IDE DMA thread is stopped */
   15.99 ++    if ( (rc = pthread_join(ide_dma_thread, NULL)) != 0 )
  15.100 ++    {
  15.101 ++        fprintf(stderr, "Oops, error collecting IDE DMA thread (%s)\n", 
  15.102 ++                strerror(rc));
  15.103  +    }
  15.104  +}
  15.105 ++
  15.106 ++#else
  15.107 ++void ide_stop_dma_thread(void)
  15.108 ++{
  15.109 ++}
  15.110  +#endif /* DMA_MULTI_THREAD */
  15.111  +
  15.112   static void ide_dma_start(IDEState *s, IDEDMAFunc *dma_cb);
  15.113   
  15.114   static void padstr(char *str, const char *src, int len)
  15.115 -@@ -695,7 +738,9 @@
  15.116 +@@ -695,7 +779,9 @@
  15.117       }
  15.118       if (s->io_buffer_index >= s->io_buffer_size && s->nsector == 0) {
  15.119           s->status = READY_STAT | SEEK_STAT;
  15.120 @@ -69,7 +110,7 @@ Index: ioemu/hw/ide.c
  15.121   #ifdef DEBUG_IDE_ATAPI
  15.122           printf("dma status=0x%x\n", s->status);
  15.123   #endif
  15.124 -@@ -795,7 +840,11 @@
  15.125 +@@ -795,7 +881,11 @@
  15.126                               qemu_get_clock(vm_clock) + (ticks_per_sec / 1000));
  15.127                   } else 
  15.128   #endif
  15.129 @@ -81,7 +122,7 @@ Index: ioemu/hw/ide.c
  15.130                   return 0;
  15.131               }
  15.132               if (n > MAX_MULT_SECTORS)
  15.133 -@@ -1046,7 +1095,9 @@
  15.134 +@@ -1046,7 +1136,9 @@
  15.135       if (s->packet_transfer_size <= 0) {
  15.136           s->status = READY_STAT;
  15.137           s->nsector = (s->nsector & ~7) | ATAPI_INT_REASON_IO | ATAPI_INT_REASON_CD;
  15.138 @@ -91,7 +132,7 @@ Index: ioemu/hw/ide.c
  15.139   #ifdef DEBUG_IDE_ATAPI
  15.140           printf("dma status=0x%x\n", s->status);
  15.141   #endif
  15.142 -@@ -2103,9 +2154,30 @@
  15.143 +@@ -2103,9 +2195,30 @@
  15.144       }
  15.145   }
  15.146   
  15.147 @@ -122,7 +163,7 @@ Index: ioemu/hw/ide.c
  15.148   {
  15.149       struct {
  15.150           uint32_t addr;
  15.151 -@@ -2141,10 +2213,7 @@
  15.152 +@@ -2141,10 +2254,7 @@
  15.153       }
  15.154       /* end of transfer */
  15.155    the_end:
  15.156 @@ -134,7 +175,7 @@ Index: ioemu/hw/ide.c
  15.157   }
  15.158   
  15.159   static void ide_dma_start(IDEState *s, IDEDMAFunc *dma_cb)
  15.160 -@@ -2370,6 +2439,9 @@
  15.161 +@@ -2370,6 +2480,9 @@
  15.162                 cmd646_set_irq, d, 0);
  15.163       ide_init2(&d->ide_if[2], hd_table[2], hd_table[3],
  15.164                 cmd646_set_irq, d, 1);
  15.165 @@ -143,14 +184,41 @@ Index: ioemu/hw/ide.c
  15.166  +#endif /* DMA_MULTI_THREAD */
  15.167   }
  15.168   
  15.169 - /* hd_table must contain 4 block drivers */
  15.170 -@@ -2405,6 +2477,9 @@
  15.171 -               pic_set_irq_new, isa_pic, 15);
  15.172 -     ide_init_ioport(&d->ide_if[0], 0x1f0, 0x3f6);
  15.173 -     ide_init_ioport(&d->ide_if[2], 0x170, 0x376);
  15.174 + static void pci_ide_save(QEMUFile* f, void *opaque)
  15.175 +@@ -2522,6 +2635,10 @@
  15.176 + 
  15.177 +     register_savevm("ide_pci", 0, 1, generic_pci_save, generic_pci_load, d);
  15.178 +     register_savevm("ide", 0, 1, pci_ide_save, pci_ide_load, d);
  15.179 ++
  15.180  +#ifdef DMA_MULTI_THREAD    
  15.181  +    dma_create_thread();
  15.182  +#endif //DMA_MULTI_THREAD    
  15.183   }
  15.184   
  15.185   /***********************************************************/
  15.186 +Index: ioemu/target-i386-dm/helper2.c
  15.187 +===================================================================
  15.188 +--- ioemu.orig/target-i386-dm/helper2.c	2007-05-03 15:03:18.000000000 +0100
  15.189 ++++ ioemu/target-i386-dm/helper2.c	2007-05-03 15:06:41.000000000 +0100
  15.190 +@@ -556,6 +556,9 @@
  15.191 +     handle_buffered_io(env);
  15.192 +     main_loop_wait(1); /* For the select() on events */
  15.193 + 
  15.194 ++    /* Stop the IDE thread */
  15.195 ++    ide_stop_dma_thread();
  15.196 ++
  15.197 +     /* Save the device state */
  15.198 +     sprintf(qemu_file, "/tmp/xen.qemu-dm.%d", domid);
  15.199 +     if (qemu_savevm(qemu_file) < 0)
  15.200 +Index: ioemu/vl.h
  15.201 +===================================================================
  15.202 +--- ioemu.orig/vl.h	2007-05-03 15:03:18.000000000 +0100
  15.203 ++++ ioemu/vl.h	2007-05-03 15:06:42.000000000 +0100
  15.204 +@@ -797,6 +797,7 @@
  15.205 + void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn);
  15.206 + int pmac_ide_init (BlockDriverState **hd_table,
  15.207 +                    SetIRQFunc *set_irq, void *irq_opaque, int irq);
  15.208 ++void ide_stop_dma_thread(void);
  15.209 + 
  15.210 + /* cdrom.c */
  15.211 + int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/tools/ioemu/patches/ioemu-buffer-pio-ia64	Tue May 08 09:09:17 2007 -0600
    16.3 @@ -0,0 +1,215 @@
    16.4 +Index: ioemu/vl.c
    16.5 +===================================================================
    16.6 +--- ioemu.orig/vl.c	2007-05-03 15:07:15.000000000 +0100
    16.7 ++++ ioemu/vl.c	2007-05-03 15:07:15.000000000 +0100
    16.8 +@@ -5924,6 +5924,7 @@
    16.9 +     unsigned long ioreq_pfn;
   16.10 +     extern void *shared_page;
   16.11 +     extern void *buffered_io_page;
   16.12 ++    extern void *buffered_pio_page;
   16.13 +     unsigned long nr_pages;
   16.14 + 
   16.15 +     char qemu_dm_logfilename[64];
   16.16 +@@ -6530,6 +6531,10 @@
   16.17 +                                        PROT_READ|PROT_WRITE,
   16.18 +                                        BUFFER_IO_PAGE_START >> PAGE_SHIFT);
   16.19 + 
   16.20 ++    buffered_pio_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   16.21 ++                                       PROT_READ|PROT_WRITE,
   16.22 ++                                       BUFFER_PIO_PAGE_START >> PAGE_SHIFT);
   16.23 ++
   16.24 +     for (i = 0; i < nr_pages; i++)
   16.25 +         page_array[i] = i;
   16.26 + 	
   16.27 +Index: ioemu/hw/ide.c
   16.28 +===================================================================
   16.29 +--- ioemu.orig/hw/ide.c	2007-05-03 15:07:15.000000000 +0100
   16.30 ++++ ioemu/hw/ide.c	2007-05-03 15:07:15.000000000 +0100
   16.31 +@@ -474,6 +474,121 @@
   16.32 + }
   16.33 + #endif /* DMA_MULTI_THREAD */
   16.34 + 
   16.35 ++#if defined(__ia64__)
   16.36 ++#include <xen/hvm/ioreq.h>
   16.37 ++
   16.38 ++struct buffered_piopage *buffered_pio_page;
   16.39 ++
   16.40 ++static inline struct pio_buffer *
   16.41 ++piobuf_by_addr(uint32_t addr)
   16.42 ++{
   16.43 ++    if (addr == 0x1F0)
   16.44 ++        return &buffered_pio_page->pio[PIO_BUFFER_IDE_PRIMARY];
   16.45 ++    if (addr == 0x170)
   16.46 ++        return &buffered_pio_page->pio[PIO_BUFFER_IDE_SECONDARY];
   16.47 ++    return NULL;
   16.48 ++}
   16.49 ++
   16.50 ++static void
   16.51 ++buffered_pio_init(void)
   16.52 ++{
   16.53 ++    struct pio_buffer *p1, *p2;
   16.54 ++    uint32_t off1, off2;
   16.55 ++
   16.56 ++    if (!buffered_pio_page)
   16.57 ++        return;
   16.58 ++
   16.59 ++    p1 = &buffered_pio_page->pio[PIO_BUFFER_IDE_PRIMARY];
   16.60 ++    p2 = &buffered_pio_page->pio[PIO_BUFFER_IDE_SECONDARY];
   16.61 ++    off1 = offsetof(struct buffered_piopage, buffer);
   16.62 ++    off2 = (off1 + TARGET_PAGE_SIZE)/2;
   16.63 ++
   16.64 ++    p1->buf_size = off2 - off1;
   16.65 ++    p1->page_offset = off1;
   16.66 ++
   16.67 ++    p2->buf_size = TARGET_PAGE_SIZE - off2;
   16.68 ++    p2->page_offset = off2;
   16.69 ++}
   16.70 ++
   16.71 ++static inline void
   16.72 ++buffered_pio_flush(struct pio_buffer *piobuf)
   16.73 ++{
   16.74 ++    IDEState *s = piobuf->opaque;
   16.75 ++    uint32_t pointer = piobuf->pointer;
   16.76 ++
   16.77 ++    if (s != NULL && pointer > 0) {
   16.78 ++        uint8_t *buf = (uint8_t *)buffered_pio_page + piobuf->page_offset;
   16.79 ++        memcpy(s->data_ptr, buf, pointer);
   16.80 ++        s->data_ptr += pointer;
   16.81 ++    }
   16.82 ++}
   16.83 ++
   16.84 ++static inline void
   16.85 ++buffered_pio_reset(IDEState *s)
   16.86 ++{
   16.87 ++    struct pio_buffer *piobuf;
   16.88 ++
   16.89 ++    if ((unsigned)s->drive_serial - 1 < 2)      /* 1,2 */
   16.90 ++        piobuf = &buffered_pio_page->pio[PIO_BUFFER_IDE_PRIMARY];
   16.91 ++    else if ((unsigned)s->drive_serial - 3 < 2) /* 3,4 */
   16.92 ++        piobuf = &buffered_pio_page->pio[PIO_BUFFER_IDE_SECONDARY];
   16.93 ++    else
   16.94 ++        return;
   16.95 ++    buffered_pio_flush(piobuf);
   16.96 ++    piobuf->pointer = 0;
   16.97 ++    piobuf->data_end = 0;
   16.98 ++    piobuf->opaque = NULL;
   16.99 ++}
  16.100 ++
  16.101 ++static inline void
  16.102 ++buffered_pio_write(IDEState *s, uint32_t addr, int size)
  16.103 ++{
  16.104 ++    struct pio_buffer *piobuf = piobuf_by_addr(addr);
  16.105 ++    int data_end;
  16.106 ++
  16.107 ++    if (!piobuf)
  16.108 ++        return;
  16.109 ++    buffered_pio_flush(piobuf);
  16.110 ++    data_end = s->data_end - s->data_ptr - size;
  16.111 ++    if (data_end <= 0)
  16.112 ++        data_end = 0;
  16.113 ++    else if (data_end > piobuf->buf_size)
  16.114 ++        data_end = piobuf->buf_size;
  16.115 ++    piobuf->pointer = 0;
  16.116 ++    piobuf->data_end = data_end;
  16.117 ++    piobuf->opaque = s;
  16.118 ++}
  16.119 ++
  16.120 ++static inline void
  16.121 ++buffered_pio_read(IDEState *s, uint32_t addr, int size)
  16.122 ++{
  16.123 ++    struct pio_buffer *piobuf = piobuf_by_addr(addr);
  16.124 ++    int data_end;
  16.125 ++
  16.126 ++    if (!piobuf)
  16.127 ++        return;
  16.128 ++    s->data_ptr += piobuf->pointer;
  16.129 ++    data_end = s->data_end - s->data_ptr - size;
  16.130 ++    if (data_end <= 0) {
  16.131 ++        data_end = 0;
  16.132 ++    } else {
  16.133 ++	uint8_t *buf = (uint8_t *)buffered_pio_page + piobuf->page_offset;
  16.134 ++        if (data_end > piobuf->buf_size)
  16.135 ++            data_end = piobuf->buf_size;
  16.136 ++        memcpy(buf, s->data_ptr + size, data_end);
  16.137 ++    }
  16.138 ++    piobuf->pointer = 0;
  16.139 ++    piobuf->data_end = data_end;
  16.140 ++    piobuf->opaque = NULL;
  16.141 ++}
  16.142 ++
  16.143 ++#else /* !__ia64__ */
  16.144 ++#define buffered_pio_init()         do {} while (0)
  16.145 ++#define buffered_pio_reset(I)       do {} while (0)
  16.146 ++#define buffered_pio_write(I,A,S)   do {} while (0)
  16.147 ++#define buffered_pio_read(I,A,S)    do {} while (0)
  16.148 ++#endif
  16.149 ++
  16.150 + static void ide_dma_start(IDEState *s, IDEDMAFunc *dma_cb);
  16.151 + 
  16.152 + static void padstr(char *str, const char *src, int len)
  16.153 +@@ -658,6 +773,7 @@
  16.154 +     s->data_ptr = buf;
  16.155 +     s->data_end = buf + size;
  16.156 +     s->status |= DRQ_STAT;
  16.157 ++    buffered_pio_reset(s);
  16.158 + }
  16.159 + 
  16.160 + static void ide_transfer_stop(IDEState *s)
  16.161 +@@ -666,6 +782,7 @@
  16.162 +     s->data_ptr = s->io_buffer;
  16.163 +     s->data_end = s->io_buffer;
  16.164 +     s->status &= ~DRQ_STAT;
  16.165 ++    buffered_pio_reset(s);
  16.166 + }
  16.167 + 
  16.168 + static int64_t ide_get_sector(IDEState *s)
  16.169 +@@ -1578,6 +1695,7 @@
  16.170 +         ide_if[0].select = (val & ~0x10) | 0xa0;
  16.171 +         ide_if[1].select = (val | 0x10) | 0xa0;
  16.172 +         /* select drive */
  16.173 ++        buffered_pio_reset(ide_if->cur_drive);
  16.174 +         unit = (val >> 4) & 1;
  16.175 +         s = ide_if + unit;
  16.176 +         ide_if->cur_drive = s;
  16.177 +@@ -1936,6 +2054,7 @@
  16.178 +     IDEState *s = ((IDEState *)opaque)->cur_drive;
  16.179 +     uint8_t *p;
  16.180 + 
  16.181 ++    buffered_pio_write(s, addr, 2);
  16.182 +     p = s->data_ptr;
  16.183 +     *(uint16_t *)p = le16_to_cpu(val);
  16.184 +     p += 2;
  16.185 +@@ -1949,6 +2068,8 @@
  16.186 +     IDEState *s = ((IDEState *)opaque)->cur_drive;
  16.187 +     uint8_t *p;
  16.188 +     int ret;
  16.189 ++    
  16.190 ++    buffered_pio_read(s, addr, 2);
  16.191 +     p = s->data_ptr;
  16.192 +     ret = cpu_to_le16(*(uint16_t *)p);
  16.193 +     p += 2;
  16.194 +@@ -1963,6 +2084,7 @@
  16.195 +     IDEState *s = ((IDEState *)opaque)->cur_drive;
  16.196 +     uint8_t *p;
  16.197 + 
  16.198 ++    buffered_pio_write(s, addr, 4);
  16.199 +     p = s->data_ptr;
  16.200 +     *(uint32_t *)p = le32_to_cpu(val);
  16.201 +     p += 4;
  16.202 +@@ -1977,6 +2099,7 @@
  16.203 +     uint8_t *p;
  16.204 +     int ret;
  16.205 +     
  16.206 ++    buffered_pio_read(s, addr, 4);
  16.207 +     p = s->data_ptr;
  16.208 +     ret = cpu_to_le32(*(uint32_t *)p);
  16.209 +     p += 4;
  16.210 +@@ -2634,6 +2757,8 @@
  16.211 +     ide_init_ioport(&d->ide_if[0], 0x1f0, 0x3f6);
  16.212 +     ide_init_ioport(&d->ide_if[2], 0x170, 0x376);
  16.213 + 
  16.214 ++    buffered_pio_init();
  16.215 ++
  16.216 +     register_savevm("ide_pci", 0, 1, generic_pci_save, generic_pci_load, d);
  16.217 +     register_savevm("ide", 0, 1, pci_ide_save, pci_ide_load, d);
  16.218 + 
    17.1 --- a/tools/ioemu/patches/ioemu-ia64	Mon May 07 13:24:37 2007 -0600
    17.2 +++ b/tools/ioemu/patches/ioemu-ia64	Tue May 08 09:09:17 2007 -0600
    17.3 @@ -1,7 +1,7 @@
    17.4  Index: ioemu/hw/iommu.c
    17.5  ===================================================================
    17.6 ---- ioemu.orig/hw/iommu.c	2006-12-20 15:04:54.000000000 +0000
    17.7 -+++ ioemu/hw/iommu.c	2006-12-20 15:04:54.000000000 +0000
    17.8 +--- ioemu.orig/hw/iommu.c	2007-05-03 09:56:32.000000000 +0100
    17.9 ++++ ioemu/hw/iommu.c	2007-05-03 10:05:51.000000000 +0100
   17.10  @@ -82,7 +82,11 @@
   17.11   #define IOPTE_VALID         0x00000002 /* IOPTE is valid */
   17.12   #define IOPTE_WAZ           0x00000001 /* Write as zeros */
   17.13 @@ -16,8 +16,8 @@ Index: ioemu/hw/iommu.c
   17.14   
   17.15  Index: ioemu/cpu-all.h
   17.16  ===================================================================
   17.17 ---- ioemu.orig/cpu-all.h	2006-12-20 15:04:54.000000000 +0000
   17.18 -+++ ioemu/cpu-all.h	2006-12-20 15:04:54.000000000 +0000
   17.19 +--- ioemu.orig/cpu-all.h	2007-05-03 09:56:32.000000000 +0100
   17.20 ++++ ioemu/cpu-all.h	2007-05-03 10:05:51.000000000 +0100
   17.21  @@ -835,6 +835,31 @@
   17.22                   :"=m" (*(volatile long *)addr)
   17.23                   :"dIr" (nr));
   17.24 @@ -52,17 +52,13 @@ Index: ioemu/cpu-all.h
   17.25   /* memory API */
   17.26  Index: ioemu/vl.c
   17.27  ===================================================================
   17.28 ---- ioemu.orig/vl.c	2006-12-20 15:04:54.000000000 +0000
   17.29 -+++ ioemu/vl.c	2006-12-20 15:12:00.000000000 +0000
   17.30 -@@ -6137,6 +6137,15 @@
   17.31 +--- ioemu.orig/vl.c	2007-05-03 10:04:06.000000000 +0100
   17.32 ++++ ioemu/vl.c	2007-05-03 10:25:23.000000000 +0100
   17.33 +@@ -6142,6 +6142,11 @@
   17.34               exit(1);
   17.35       }
   17.36   
   17.37  +#if defined (__ia64__)
   17.38 -+    /* ram_size passed from xend has added on GFW memory,
   17.39 -+       so we must subtract it here */
   17.40 -+    ram_size -= 16 * MEM_M;
   17.41 -+
   17.42  +    if (ram_size > MMIO_START)
   17.43  +        ram_size += 1 * MEM_G; /* skip 3G-4G MMIO, LEGACY_IO_SPACE etc. */
   17.44  +#endif
   17.45 @@ -70,20 +66,20 @@ Index: ioemu/vl.c
   17.46       /* init the memory */
   17.47       phys_ram_size = ram_size + vga_ram_size + bios_size;
   17.48   
   17.49 -@@ -6161,6 +6170,7 @@
   17.50 -         exit(-1);
   17.51 -     }
   17.52 - 
   17.53 -+#if defined(__i386__) || defined(__x86_64__)
   17.54 -     for ( i = 0; i < tmp_nr_pages; i++)
   17.55 -         page_array[i] = i;
   17.56 - 
   17.57 -@@ -6185,6 +6195,36 @@
   17.58 +@@ -6182,6 +6187,44 @@
   17.59   
   17.60       free(page_array);
   17.61   
   17.62  +#elif defined(__ia64__)
   17.63 -+  
   17.64 ++
   17.65 ++    nr_pages = ram_size/PAGE_SIZE;
   17.66 ++
   17.67 ++    page_array = (xen_pfn_t *)malloc(nr_pages * sizeof(xen_pfn_t));
   17.68 ++    if (page_array == NULL) {
   17.69 ++        fprintf(logfile, "malloc returned error %d\n", errno);
   17.70 ++        exit(-1);
   17.71 ++    }
   17.72 ++
   17.73  +    shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   17.74  +                                       PROT_READ|PROT_WRITE,
   17.75  +                                       IO_PAGE_START >> PAGE_SHIFT);
   17.76 @@ -92,7 +88,7 @@ Index: ioemu/vl.c
   17.77  +                                       PROT_READ|PROT_WRITE,
   17.78  +                                       BUFFER_IO_PAGE_START >> PAGE_SHIFT);
   17.79  +
   17.80 -+    for (i = 0; i < tmp_nr_pages; i++)
   17.81 ++    for (i = 0; i < nr_pages; i++)
   17.82  +        page_array[i] = i;
   17.83  +	
   17.84  +    /* VTI will not use memory between 3G~4G, so we just pass a legal pfn
   17.85 @@ -117,8 +113,8 @@ Index: ioemu/vl.c
   17.86       phys_ram_base = qemu_vmalloc(phys_ram_size);
   17.87  Index: ioemu/exec-all.h
   17.88  ===================================================================
   17.89 ---- ioemu.orig/exec-all.h	2006-12-20 15:04:54.000000000 +0000
   17.90 -+++ ioemu/exec-all.h	2006-12-20 15:04:54.000000000 +0000
   17.91 +--- ioemu.orig/exec-all.h	2007-05-03 09:56:32.000000000 +0100
   17.92 ++++ ioemu/exec-all.h	2007-05-03 10:05:51.000000000 +0100
   17.93  @@ -462,12 +462,13 @@
   17.94   }
   17.95   #endif
   17.96 @@ -138,8 +134,8 @@ Index: ioemu/exec-all.h
   17.97   
   17.98  Index: ioemu/target-i386-dm/cpu.h
   17.99  ===================================================================
  17.100 ---- ioemu.orig/target-i386-dm/cpu.h	2006-12-20 15:04:54.000000000 +0000
  17.101 -+++ ioemu/target-i386-dm/cpu.h	2006-12-20 15:10:13.000000000 +0000
  17.102 +--- ioemu.orig/target-i386-dm/cpu.h	2007-05-03 09:56:32.000000000 +0100
  17.103 ++++ ioemu/target-i386-dm/cpu.h	2007-05-03 10:25:13.000000000 +0100
  17.104  @@ -78,7 +78,11 @@
  17.105   /* helper2.c */
  17.106   int main_loop(void);
  17.107 @@ -155,7 +151,7 @@ Index: ioemu/target-i386-dm/cpu.h
  17.108  Index: ioemu/ia64_intrinsic.h
  17.109  ===================================================================
  17.110  --- /dev/null	1970-01-01 00:00:00.000000000 +0000
  17.111 -+++ ioemu/ia64_intrinsic.h	2006-12-20 15:04:54.000000000 +0000
  17.112 ++++ ioemu/ia64_intrinsic.h	2007-05-03 10:05:51.000000000 +0100
  17.113  @@ -0,0 +1,276 @@
  17.114  +#ifndef IA64_INTRINSIC_H
  17.115  +#define IA64_INTRINSIC_H
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/tools/ioemu/patches/ioemu-save-restore	Tue May 08 09:09:17 2007 -0600
    18.3 @@ -0,0 +1,225 @@
    18.4 +Index: ioemu/hw/cirrus_vga.c
    18.5 +===================================================================
    18.6 +--- ioemu.orig/hw/cirrus_vga.c	2007-05-03 15:03:18.000000000 +0100
    18.7 ++++ ioemu/hw/cirrus_vga.c	2007-05-03 15:08:02.000000000 +0100
    18.8 +@@ -3011,11 +3011,42 @@
    18.9 +     cirrus_mmio_writel,
   18.10 + };
   18.11 + 
   18.12 ++void cirrus_stop_acc(CirrusVGAState *s)
   18.13 ++{
   18.14 ++    if (s->map_addr){
   18.15 ++        int error;
   18.16 ++        s->map_addr = 0;
   18.17 ++        error = unset_vram_mapping(s->cirrus_lfb_addr,
   18.18 ++                s->cirrus_lfb_end, s->vram_ptr);
   18.19 ++        fprintf(stderr, "cirrus_stop_acc:unset_vram_mapping.\n");
   18.20 ++    }
   18.21 ++}
   18.22 ++
   18.23 ++void cirrus_restart_acc(CirrusVGAState *s)
   18.24 ++{
   18.25 ++    if (s->cirrus_lfb_addr && s->cirrus_lfb_end) {
   18.26 ++        void *vram_pointer, *old_vram;
   18.27 ++        fprintf(stderr, "cirrus_vga_load:re-enable vga acc.lfb_addr=0x%lx, lfb_end=0x%lx.\n",
   18.28 ++                s->cirrus_lfb_addr, s->cirrus_lfb_end);
   18.29 ++        vram_pointer = set_vram_mapping(s->cirrus_lfb_addr ,s->cirrus_lfb_end);
   18.30 ++        if (!vram_pointer){
   18.31 ++            fprintf(stderr, "cirrus_vga_load:NULL vram_pointer\n");
   18.32 ++        } else {
   18.33 ++            old_vram = vga_update_vram((VGAState *)s, vram_pointer,
   18.34 ++                    VGA_RAM_SIZE);
   18.35 ++            qemu_free(old_vram);
   18.36 ++            s->map_addr = s->cirrus_lfb_addr;
   18.37 ++            s->map_end = s->cirrus_lfb_end;
   18.38 ++        }
   18.39 ++    }
   18.40 ++}
   18.41 ++
   18.42 + /* load/save state */
   18.43 + 
   18.44 + static void cirrus_vga_save(QEMUFile *f, void *opaque)
   18.45 + {
   18.46 +     CirrusVGAState *s = opaque;
   18.47 ++    uint8_t vga_acc;
   18.48 + 
   18.49 +     qemu_put_be32s(f, &s->latch);
   18.50 +     qemu_put_8s(f, &s->sr_index);
   18.51 +@@ -3050,11 +3081,20 @@
   18.52 +     qemu_put_be32s(f, &s->hw_cursor_y);
   18.53 +     /* XXX: we do not save the bitblt state - we assume we do not save
   18.54 +        the state when the blitter is active */
   18.55 ++
   18.56 ++    vga_acc = (!!s->map_addr);
   18.57 ++    qemu_put_8s(f, &vga_acc);
   18.58 ++    qemu_put_be64s(f, (uint64_t*)&s->cirrus_lfb_addr);
   18.59 ++    qemu_put_be64s(f, (uint64_t*)&s->cirrus_lfb_end);
   18.60 ++    qemu_put_buffer(f, s->vram_ptr, VGA_RAM_SIZE); 
   18.61 ++    if (vga_acc)
   18.62 ++        cirrus_stop_acc(s);
   18.63 + }
   18.64 + 
   18.65 + static int cirrus_vga_load(QEMUFile *f, void *opaque, int version_id)
   18.66 + {
   18.67 +     CirrusVGAState *s = opaque;
   18.68 ++    uint8_t vga_acc = 0;
   18.69 + 
   18.70 +     if (version_id != 1)
   18.71 +         return -EINVAL;
   18.72 +@@ -3093,6 +3133,14 @@
   18.73 +     qemu_get_be32s(f, &s->hw_cursor_x);
   18.74 +     qemu_get_be32s(f, &s->hw_cursor_y);
   18.75 + 
   18.76 ++    qemu_get_8s(f, &vga_acc);
   18.77 ++    qemu_get_be64s(f, (uint64_t*)&s->cirrus_lfb_addr);
   18.78 ++    qemu_get_be64s(f, (uint64_t*)&s->cirrus_lfb_end);
   18.79 ++    qemu_get_buffer(f, s->vram_ptr, VGA_RAM_SIZE); 
   18.80 ++    if (vga_acc){
   18.81 ++        cirrus_restart_acc(s);
   18.82 ++    }
   18.83 ++
   18.84 +     /* force refresh */
   18.85 +     s->graphic_mode = -1;
   18.86 +     cirrus_update_bank_ptr(s, 0);
   18.87 +@@ -3298,6 +3346,8 @@
   18.88 +                     ds, vga_ram_base, vga_ram_offset, vga_ram_size);
   18.89 +     cirrus_init_common(s, device_id, 1);
   18.90 + 
   18.91 ++    register_savevm("cirrus_vga_pci", 0, 1, generic_pci_save, generic_pci_load, d);
   18.92 ++
   18.93 +     /* setup memory space */
   18.94 +     /* memory #0 LFB */
   18.95 +     /* memory #1 memory-mapped I/O */
   18.96 +Index: ioemu/vl.c
   18.97 +===================================================================
   18.98 +--- ioemu.orig/vl.c	2007-05-03 15:03:18.000000000 +0100
   18.99 ++++ ioemu/vl.c	2007-05-03 15:08:04.000000000 +0100
  18.100 +@@ -4470,6 +4470,11 @@
  18.101 +         qemu_fseek(f, cur_pos + record_len, SEEK_SET);
  18.102 +     }
  18.103 +     fclose(f);
  18.104 ++
  18.105 ++    /* del tmp file */
  18.106 ++    if (unlink(filename) == -1)
  18.107 ++        fprintf(stderr, "delete tmp qemu state file failed.\n");
  18.108 ++
  18.109 +     ret = 0;
  18.110 +  the_end:
  18.111 +     if (saved_vm_running)
  18.112 +@@ -5056,6 +5061,7 @@
  18.113 + static QEMUResetEntry *first_reset_entry;
  18.114 + int reset_requested;
  18.115 + int shutdown_requested;
  18.116 ++int suspend_requested;
  18.117 + static int powerdown_requested;
  18.118 + 
  18.119 + void qemu_register_reset(QEMUResetHandler *func, void *opaque)
  18.120 +@@ -5816,6 +5822,15 @@
  18.121 +     return 0;
  18.122 + }
  18.123 + 
  18.124 ++void suspend(int sig)
  18.125 ++{
  18.126 ++    fprintf(logfile, "suspend sig handler called with requested=%d!\n",
  18.127 ++            suspend_requested);
  18.128 ++    if (sig != SIGUSR1)
  18.129 ++        fprintf(logfile, "suspend signal dismatch, get sig=%d!\n", sig);
  18.130 ++    suspend_requested = 1;
  18.131 ++}
  18.132 ++
  18.133 + int main(int argc, char **argv)
  18.134 + {
  18.135 + #ifdef CONFIG_GDBSTUB
  18.136 +@@ -6581,6 +6596,26 @@
  18.137 +             vm_start();
  18.138 +         }
  18.139 +     }
  18.140 ++
  18.141 ++    /* register signal for the suspend request when save */
  18.142 ++    {
  18.143 ++        struct sigaction act;
  18.144 ++        sigset_t set;
  18.145 ++        act.sa_handler = suspend;
  18.146 ++        act.sa_flags = SA_RESTART;
  18.147 ++        sigemptyset(&act.sa_mask);
  18.148 ++
  18.149 ++        sigaction(SIGUSR1, &act, NULL);
  18.150 ++
  18.151 ++        /* control panel mask some signals when spawn qemu, need unmask here*/
  18.152 ++        sigemptyset(&set);
  18.153 ++        sigaddset(&set, SIGUSR1);
  18.154 ++        sigaddset(&set, SIGTERM);
  18.155 ++        if (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1)
  18.156 ++            fprintf(stderr, "unblock signal fail, possible issue for HVM save!\n");
  18.157 ++
  18.158 ++    }
  18.159 ++
  18.160 +     main_loop();
  18.161 +     quit_timers();
  18.162 +     return 0;
  18.163 +Index: ioemu/hw/pci.c
  18.164 +===================================================================
  18.165 +--- ioemu.orig/hw/pci.c	2007-05-03 15:03:12.000000000 +0100
  18.166 ++++ ioemu/hw/pci.c	2007-05-03 15:08:02.000000000 +0100
  18.167 +@@ -40,6 +40,8 @@
  18.168 + static int pci_irq_index;
  18.169 + static PCIBus *first_bus;
  18.170 + 
  18.171 ++static void pci_update_mappings(PCIDevice *d);
  18.172 ++
  18.173 + PCIBus *pci_register_bus(pci_set_irq_fn set_irq, void *pic, int devfn_min)
  18.174 + {
  18.175 +     PCIBus *bus;
  18.176 +@@ -71,6 +73,7 @@
  18.177 +         return -EINVAL;
  18.178 + 
  18.179 +     qemu_get_buffer(f, s->config, 256);
  18.180 ++    pci_update_mappings(s);
  18.181 +     return 0;
  18.182 + }
  18.183 + 
  18.184 +Index: ioemu/hw/ide.c
  18.185 +===================================================================
  18.186 +--- ioemu.orig/hw/ide.c	2007-05-03 15:03:12.000000000 +0100
  18.187 ++++ ioemu/hw/ide.c	2007-05-03 15:08:04.000000000 +0100
  18.188 +@@ -2405,6 +2405,8 @@
  18.189 +               pic_set_irq_new, isa_pic, 15);
  18.190 +     ide_init_ioport(&d->ide_if[0], 0x1f0, 0x3f6);
  18.191 +     ide_init_ioport(&d->ide_if[2], 0x170, 0x376);
  18.192 ++
  18.193 ++    register_savevm("ide_pci", 0, 1, generic_pci_save, generic_pci_load, d);
  18.194 + }
  18.195 + 
  18.196 + /***********************************************************/
  18.197 +Index: ioemu/target-i386-dm/helper2.c
  18.198 +===================================================================
  18.199 +--- ioemu.orig/target-i386-dm/helper2.c	2007-05-03 15:03:18.000000000 +0100
  18.200 ++++ ioemu/target-i386-dm/helper2.c	2007-05-03 15:09:10.000000000 +0100
  18.201 +@@ -540,8 +540,10 @@
  18.202 + {
  18.203 +     extern int vm_running;
  18.204 +     extern int shutdown_requested;
  18.205 ++    extern int suspend_requested;
  18.206 +     CPUState *env = cpu_single_env;
  18.207 +     int evtchn_fd = xc_evtchn_fd(xce_handle);
  18.208 ++    char qemu_file[20];
  18.209 + 
  18.210 +     qemu_set_fd_handler(evtchn_fd, cpu_handle_ioreq, NULL, env);
  18.211 + 
  18.212 +@@ -549,7 +551,15 @@
  18.213 +         /* Wait up to 10 msec. */
  18.214 +         main_loop_wait(10);
  18.215 + 
  18.216 +-    destroy_hvm_domain();
  18.217 ++    fprintf(logfile, "device model received suspend signal!\n");
  18.218 ++
  18.219 ++    /* Pull all outstanding ioreqs through the system */
  18.220 ++    main_loop_wait(1); /* For the select() on events */
  18.221 ++
  18.222 ++    /* Save the device state */
  18.223 ++    sprintf(qemu_file, "/tmp/xen.qemu-dm.%d", domid);
  18.224 ++    if (qemu_savevm(qemu_file) < 0)
  18.225 ++        fprintf(stderr, "qemu save fail.\n");
  18.226 + 
  18.227 +     return 0;
  18.228 + }
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/tools/ioemu/patches/ioemu-save-restore-acpi	Tue May 08 09:09:17 2007 -0600
    19.3 @@ -0,0 +1,34 @@
    19.4 +Index: ioemu/hw/piix4acpi.c
    19.5 +===================================================================
    19.6 +--- ioemu.orig/hw/piix4acpi.c	2007-05-03 15:07:43.000000000 +0100
    19.7 ++++ ioemu/hw/piix4acpi.c	2007-05-03 15:07:43.000000000 +0100
    19.8 +@@ -57,6 +57,20 @@
    19.9 +     uint16_t pm1_control; /* pm1a_ECNT_BLK */
   19.10 + } PCIAcpiState;
   19.11 + 
   19.12 ++static void piix4acpi_save(QEMUFile *f, void *opaque)
   19.13 ++{
   19.14 ++    PCIAcpiState *s = opaque;
   19.15 ++    qemu_put_be16s(f, &s->pm1_control);
   19.16 ++}
   19.17 ++
   19.18 ++static int piix4acpi_load(QEMUFile *f, void *opaque, int version_id)
   19.19 ++{
   19.20 ++    PCIAcpiState *s = opaque;
   19.21 ++    if (version_id > 1) 
   19.22 ++        return -EINVAL;
   19.23 ++    qemu_get_be16s(f, &s->pm1_control);
   19.24 ++}
   19.25 ++
   19.26 + static void acpiPm1Control_writeb(void *opaque, uint32_t addr, uint32_t val)
   19.27 + {
   19.28 +     PCIAcpiState *s = opaque;
   19.29 +@@ -193,4 +207,8 @@
   19.30 +     d->pm1_control = SCI_EN;
   19.31 + 
   19.32 +     acpi_map(d, 0, 0x1f40, 0x10, PCI_ADDRESS_SPACE_IO);
   19.33 ++
   19.34 ++    register_savevm("piix4acpi", 0, 1, piix4acpi_save, piix4acpi_load, d);    
   19.35 ++    register_savevm("piix4acpi_pci", 0, 1, generic_pci_save, generic_pci_load, 
   19.36 ++                    &d->dev);
   19.37 + }
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/tools/ioemu/patches/ioemu-save-restore-ide	Tue May 08 09:09:17 2007 -0600
    20.3 @@ -0,0 +1,133 @@
    20.4 +Index: ioemu/hw/ide.c
    20.5 +===================================================================
    20.6 +--- ioemu.orig/hw/ide.c	2007-05-02 14:12:00.000000000 +0100
    20.7 ++++ ioemu/hw/ide.c	2007-05-02 14:12:40.000000000 +0100
    20.8 +@@ -2372,6 +2372,120 @@
    20.9 +               cmd646_set_irq, d, 1);
   20.10 + }
   20.11 + 
   20.12 ++static void pci_ide_save(QEMUFile* f, void *opaque)
   20.13 ++{
   20.14 ++    PCIIDEState *d = opaque;
   20.15 ++    int i;
   20.16 ++
   20.17 ++    for(i = 0; i < 2; i++) {
   20.18 ++        BMDMAState *bm = &d->bmdma[i];
   20.19 ++        qemu_put_8s(f, &bm->cmd);
   20.20 ++        qemu_put_8s(f, &bm->status);
   20.21 ++        qemu_put_be32s(f, &bm->addr);
   20.22 ++        /* XXX: if a transfer is pending, we do not save it yet */
   20.23 ++    }
   20.24 ++
   20.25 ++    /* per IDE interface data */
   20.26 ++    for(i = 0; i < 2; i++) {
   20.27 ++        IDEState *s = &d->ide_if[i * 2];
   20.28 ++        uint8_t drive1_selected;
   20.29 ++        qemu_put_8s(f, &s->cmd);
   20.30 ++        drive1_selected = (s->cur_drive != s);
   20.31 ++        qemu_put_8s(f, &drive1_selected);
   20.32 ++    }
   20.33 ++
   20.34 ++    /* per IDE drive data */
   20.35 ++    for(i = 0; i < 4; i++) {
   20.36 ++        IDEState *s = &d->ide_if[i];
   20.37 ++        qemu_put_be32s(f, &s->mult_sectors);
   20.38 ++        qemu_put_be32s(f, &s->identify_set);
   20.39 ++        if (s->identify_set) {
   20.40 ++            qemu_put_buffer(f, (const uint8_t *)s->identify_data, 512);
   20.41 ++        }
   20.42 ++        qemu_put_8s(f, &s->write_cache);
   20.43 ++        qemu_put_8s(f, &s->feature);
   20.44 ++        qemu_put_8s(f, &s->error);
   20.45 ++        qemu_put_be32s(f, &s->nsector);
   20.46 ++        qemu_put_8s(f, &s->sector);
   20.47 ++        qemu_put_8s(f, &s->lcyl);
   20.48 ++        qemu_put_8s(f, &s->hcyl);
   20.49 ++        qemu_put_8s(f, &s->hob_feature);
   20.50 ++        qemu_put_8s(f, &s->hob_nsector);
   20.51 ++        qemu_put_8s(f, &s->hob_sector);
   20.52 ++        qemu_put_8s(f, &s->hob_lcyl);
   20.53 ++        qemu_put_8s(f, &s->hob_hcyl);
   20.54 ++        qemu_put_8s(f, &s->select);
   20.55 ++        qemu_put_8s(f, &s->status);
   20.56 ++        qemu_put_8s(f, &s->lba48);
   20.57 ++
   20.58 ++        qemu_put_8s(f, &s->sense_key);
   20.59 ++        qemu_put_8s(f, &s->asc);
   20.60 ++        /* XXX: if a transfer is pending, we do not save it yet */
   20.61 ++    }
   20.62 ++}
   20.63 ++
   20.64 ++static int pci_ide_load(QEMUFile* f, void *opaque, int version_id)
   20.65 ++{
   20.66 ++    PCIIDEState *d = opaque;
   20.67 ++    int ret, i;
   20.68 ++
   20.69 ++    if (version_id != 1)
   20.70 ++        return -EINVAL;
   20.71 ++
   20.72 ++    for(i = 0; i < 2; i++) {
   20.73 ++        BMDMAState *bm = &d->bmdma[i];
   20.74 ++        qemu_get_8s(f, &bm->cmd);
   20.75 ++        qemu_get_8s(f, &bm->status);
   20.76 ++        qemu_get_be32s(f, &bm->addr);
   20.77 ++        /* XXX: if a transfer is pending, we do not save it yet */
   20.78 ++    }
   20.79 ++
   20.80 ++    /* per IDE interface data */
   20.81 ++    for(i = 0; i < 2; i++) {
   20.82 ++        IDEState *s = &d->ide_if[i * 2];
   20.83 ++        uint8_t drive1_selected;
   20.84 ++        qemu_get_8s(f, &s->cmd);
   20.85 ++        qemu_get_8s(f, &drive1_selected);
   20.86 ++        s->cur_drive = &d->ide_if[i * 2 + (drive1_selected != 0)];
   20.87 ++    }
   20.88 ++
   20.89 ++    /* per IDE drive data */
   20.90 ++    for(i = 0; i < 4; i++) {
   20.91 ++        IDEState *s = &d->ide_if[i];
   20.92 ++        qemu_get_be32s(f, &s->mult_sectors);
   20.93 ++        qemu_get_be32s(f, &s->identify_set);
   20.94 ++        if (s->identify_set) {
   20.95 ++            qemu_get_buffer(f, (uint8_t *)s->identify_data, 512);
   20.96 ++        }
   20.97 ++        qemu_get_8s(f, &s->write_cache);
   20.98 ++        qemu_get_8s(f, &s->feature);
   20.99 ++        qemu_get_8s(f, &s->error);
  20.100 ++        qemu_get_be32s(f, &s->nsector);
  20.101 ++        qemu_get_8s(f, &s->sector);
  20.102 ++        qemu_get_8s(f, &s->lcyl);
  20.103 ++        qemu_get_8s(f, &s->hcyl);
  20.104 ++        qemu_get_8s(f, &s->hob_feature);
  20.105 ++        qemu_get_8s(f, &s->hob_nsector);
  20.106 ++        qemu_get_8s(f, &s->hob_sector);
  20.107 ++        qemu_get_8s(f, &s->hob_lcyl);
  20.108 ++        qemu_get_8s(f, &s->hob_hcyl);
  20.109 ++        qemu_get_8s(f, &s->select);
  20.110 ++        qemu_get_8s(f, &s->status);
  20.111 ++        qemu_get_8s(f, &s->lba48);
  20.112 ++
  20.113 ++        qemu_get_8s(f, &s->sense_key);
  20.114 ++        qemu_get_8s(f, &s->asc);
  20.115 ++        /* XXX: if a transfer is pending, we do not save it yet */
  20.116 ++        if (s->status & (DRQ_STAT|BUSY_STAT)) {
  20.117 ++            /* Tell the guest that its transfer has gone away */
  20.118 ++            ide_abort_command(s);
  20.119 ++            ide_set_irq(s);
  20.120 ++        }
  20.121 ++    }
  20.122 ++    return 0;
  20.123 ++}
  20.124 ++
  20.125 ++
  20.126 + /* hd_table must contain 4 block drivers */
  20.127 + /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
  20.128 + void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn)
  20.129 +@@ -2407,6 +2521,7 @@
  20.130 +     ide_init_ioport(&d->ide_if[2], 0x170, 0x376);
  20.131 + 
  20.132 +     register_savevm("ide_pci", 0, 1, generic_pci_save, generic_pci_load, d);
  20.133 ++    register_savevm("ide", 0, 1, pci_ide_save, pci_ide_load, d);
  20.134 + }
  20.135 + 
  20.136 + /***********************************************************/
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/tools/ioemu/patches/ioemu-save-restore-logdirty	Tue May 08 09:09:17 2007 -0600
    21.3 @@ -0,0 +1,190 @@
    21.4 +Index: ioemu/xenstore.c
    21.5 +===================================================================
    21.6 +--- ioemu.orig/xenstore.c	2007-05-03 10:42:11.000000000 +0100
    21.7 ++++ ioemu/xenstore.c	2007-05-03 14:17:13.000000000 +0100
    21.8 +@@ -11,6 +11,11 @@
    21.9 + #include "vl.h"
   21.10 + #include "block_int.h"
   21.11 + #include <unistd.h>
   21.12 ++#include <sys/ipc.h>
   21.13 ++#include <sys/shm.h>
   21.14 ++#include <sys/types.h>
   21.15 ++#include <sys/stat.h>
   21.16 ++#include <fcntl.h>
   21.17 + 
   21.18 + static struct xs_handle *xsh = NULL;
   21.19 + static char *media_filename[MAX_DISKS];
   21.20 +@@ -173,6 +178,13 @@
   21.21 + 	}
   21.22 +     }
   21.23 + 
   21.24 ++    /* Set a watch for log-dirty requests from the migration tools */
   21.25 ++    if (pasprintf(&buf, "%s/logdirty/next-active", path) != -1) {
   21.26 ++        xs_watch(xsh, buf, "logdirty");
   21.27 ++        fprintf(logfile, "Watching %s\n", buf);
   21.28 ++    }
   21.29 ++
   21.30 ++
   21.31 +  out:
   21.32 +     free(type);
   21.33 +     free(params);
   21.34 +@@ -191,6 +203,112 @@
   21.35 +     return -1;
   21.36 + }
   21.37 + 
   21.38 ++unsigned long *logdirty_bitmap = NULL;
   21.39 ++unsigned long logdirty_bitmap_size;
   21.40 ++extern int vga_ram_size, bios_size;
   21.41 ++
   21.42 ++void xenstore_process_logdirty_event(void)
   21.43 ++{
   21.44 ++    char *act;
   21.45 ++    static char *active_path = NULL;
   21.46 ++    static char *next_active_path = NULL;
   21.47 ++    static char *seg = NULL;
   21.48 ++    unsigned int len;
   21.49 ++    int i;
   21.50 ++
   21.51 ++    fprintf(logfile, "Triggered log-dirty buffer switch\n");
   21.52 ++
   21.53 ++    if (!seg) {
   21.54 ++        char *path, *p, *key_ascii, key_terminated[17] = {0,};
   21.55 ++        key_t key;
   21.56 ++        int shmid;
   21.57 ++
   21.58 ++        /* Find and map the shared memory segment for log-dirty bitmaps */
   21.59 ++        if (!(path = xs_get_domain_path(xsh, domid))) {            
   21.60 ++            fprintf(logfile, "Log-dirty: can't get domain path in store\n");
   21.61 ++            exit(1);
   21.62 ++        }
   21.63 ++        if (!(path = realloc(path, strlen(path) 
   21.64 ++                             + strlen("/logdirty/next-active") + 1))) {
   21.65 ++            fprintf(logfile, "Log-dirty: out of memory\n");
   21.66 ++            exit(1);
   21.67 ++        }
   21.68 ++        strcat(path, "/logdirty/");
   21.69 ++        p = path + strlen(path);
   21.70 ++        strcpy(p, "key");
   21.71 ++        
   21.72 ++        key_ascii = xs_read(xsh, XBT_NULL, path, &len);
   21.73 ++        if (!key_ascii) {
   21.74 ++            /* No key yet: wait for the next watch */
   21.75 ++            free(path);
   21.76 ++            return;
   21.77 ++        }
   21.78 ++        strncpy(key_terminated, key_ascii, 16);
   21.79 ++        free(key_ascii);
   21.80 ++        key = (key_t) strtoull(key_terminated, NULL, 16);
   21.81 ++
   21.82 ++        /* Figure out how bit the log-dirty bitmaps are */
   21.83 ++        logdirty_bitmap_size = xc_memory_op(xc_handle, 
   21.84 ++                                            XENMEM_maximum_gpfn, &domid) + 1;
   21.85 ++        logdirty_bitmap_size = ((logdirty_bitmap_size + HOST_LONG_BITS - 1)
   21.86 ++                                / HOST_LONG_BITS); /* longs */
   21.87 ++        logdirty_bitmap_size *= sizeof (unsigned long); /* bytes */
   21.88 ++
   21.89 ++        /* Map the shared-memory segment */
   21.90 ++        if ((shmid = shmget(key, 
   21.91 ++                            2 * logdirty_bitmap_size, 
   21.92 ++                            S_IRUSR|S_IWUSR)) == -1 
   21.93 ++            || (seg = shmat(shmid, NULL, 0)) == (void *)-1) {
   21.94 ++            fprintf(logfile, "Log-dirty: can't map segment %16.16llx (%s)\n",
   21.95 ++                    (unsigned long long) key, strerror(errno));
   21.96 ++            exit(1);
   21.97 ++        }
   21.98 ++
   21.99 ++        fprintf(logfile, "Log-dirty: mapped segment at %p\n", seg);
  21.100 ++
  21.101 ++        /* Double-check that the bitmaps are the size we expect */
  21.102 ++        if (logdirty_bitmap_size != *(uint32_t *)seg) {
  21.103 ++            fprintf(logfile, "Log-dirty: got %u, calc %lu\n", 
  21.104 ++                    *(uint32_t *)seg, logdirty_bitmap_size);
  21.105 ++            return;
  21.106 ++        }
  21.107 ++
  21.108 ++        /* Remember the paths for the next-active and active entries */
  21.109 ++        strcpy(p, "active");
  21.110 ++        if (!(active_path = strdup(path))) {
  21.111 ++            fprintf(logfile, "Log-dirty: out of memory\n");
  21.112 ++            exit(1);
  21.113 ++        }
  21.114 ++        strcpy(p, "next-active");
  21.115 ++        if (!(next_active_path = strdup(path))) {
  21.116 ++            fprintf(logfile, "Log-dirty: out of memory\n");
  21.117 ++            exit(1);
  21.118 ++        }
  21.119 ++        free(path);
  21.120 ++    }
  21.121 ++    
  21.122 ++    /* Read the required active buffer from the store */
  21.123 ++    act = xs_read(xsh, XBT_NULL, next_active_path, &len);
  21.124 ++    if (!act) {
  21.125 ++        fprintf(logfile, "Log-dirty: can't read next-active\n");
  21.126 ++        exit(1);
  21.127 ++    }
  21.128 ++
  21.129 ++    /* Switch buffers */
  21.130 ++    i = act[0] - '0';
  21.131 ++    if (i != 0 && i != 1) {
  21.132 ++        fprintf(logfile, "Log-dirty: bad next-active entry: %s\n", act);
  21.133 ++        exit(1);
  21.134 ++    }
  21.135 ++    logdirty_bitmap = (unsigned long *)(seg + i * logdirty_bitmap_size);
  21.136 ++
  21.137 ++    /* Ack that we've switched */
  21.138 ++    xs_write(xsh, XBT_NULL, active_path, act, len);
  21.139 ++    free(act);
  21.140 ++}
  21.141 ++
  21.142 ++
  21.143 ++
  21.144 + void xenstore_process_event(void *opaque)
  21.145 + {
  21.146 +     char **vec, *image = NULL;
  21.147 +@@ -200,6 +318,11 @@
  21.148 +     if (!vec)
  21.149 + 	return;
  21.150 + 
  21.151 ++    if (!strcmp(vec[XS_WATCH_TOKEN], "logdirty")) {
  21.152 ++        xenstore_process_logdirty_event();
  21.153 ++        goto out;
  21.154 ++    }
  21.155 ++
  21.156 +     if (strncmp(vec[XS_WATCH_TOKEN], "hd", 2) ||
  21.157 + 	strlen(vec[XS_WATCH_TOKEN]) != 3)
  21.158 + 	goto out;
  21.159 +Index: ioemu/target-i386-dm/exec-dm.c
  21.160 +===================================================================
  21.161 +--- ioemu.orig/target-i386-dm/exec-dm.c	2007-05-03 14:13:38.000000000 +0100
  21.162 ++++ ioemu/target-i386-dm/exec-dm.c	2007-05-03 14:18:14.000000000 +0100
  21.163 +@@ -431,6 +431,9 @@
  21.164 + #define phys_ram_addr(x) ((addr < ram_size) ? (phys_ram_base + (x)) : NULL)
  21.165 + #endif
  21.166 + 
  21.167 ++extern unsigned long *logdirty_bitmap;
  21.168 ++extern unsigned long logdirty_bitmap_size;
  21.169 ++
  21.170 + void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, 
  21.171 +                             int len, int is_write)
  21.172 + {
  21.173 +@@ -466,8 +469,19 @@
  21.174 +                     l = 1;
  21.175 +                 }
  21.176 +             } else if ((ptr = phys_ram_addr(addr)) != NULL) {
  21.177 +-                /* Reading from RAM */
  21.178 ++                /* Writing to RAM */
  21.179 +                 memcpy(ptr, buf, l);
  21.180 ++                if (logdirty_bitmap != NULL) {
  21.181 ++                    /* Record that we have dirtied this frame */
  21.182 ++                    unsigned long pfn = addr >> TARGET_PAGE_BITS;
  21.183 ++                    if (pfn / 8 >= logdirty_bitmap_size) {
  21.184 ++                        fprintf(logfile, "dirtying pfn %lx >= bitmap "
  21.185 ++                                "size %lx\n", pfn, logdirty_bitmap_size * 8);
  21.186 ++                    } else {
  21.187 ++                        logdirty_bitmap[pfn / HOST_LONG_BITS]
  21.188 ++                            |= 1UL << pfn % HOST_LONG_BITS;
  21.189 ++                    }
  21.190 ++                }
  21.191 + #ifdef __ia64__
  21.192 +                 sync_icache(ptr, l);
  21.193 + #endif 
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/tools/ioemu/patches/ioemu-save-restore-ne2000	Tue May 08 09:09:17 2007 -0600
    22.3 @@ -0,0 +1,34 @@
    22.4 +Index: ioemu/hw/ne2000.c
    22.5 +===================================================================
    22.6 +--- ioemu.orig/hw/ne2000.c	2007-05-02 16:09:35.000000000 +0100
    22.7 ++++ ioemu/hw/ne2000.c	2007-05-02 16:10:03.000000000 +0100
    22.8 +@@ -739,7 +739,7 @@
    22.9 +              s->macaddr[4],
   22.10 +              s->macaddr[5]);
   22.11 +              
   22.12 +-    register_savevm("ne2000", 0, 2, ne2000_save, ne2000_load, s);
   22.13 ++    register_savevm("ne2000", base, 2, ne2000_save, ne2000_load, s);
   22.14 + }
   22.15 + 
   22.16 + /***********************************************************/
   22.17 +@@ -775,6 +775,7 @@
   22.18 +     PCINE2000State *d;
   22.19 +     NE2000State *s;
   22.20 +     uint8_t *pci_conf;
   22.21 ++    int instance;
   22.22 +     
   22.23 +     d = (PCINE2000State *)pci_register_device(bus,
   22.24 +                                               "NE2000", sizeof(PCINE2000State),
   22.25 +@@ -809,8 +810,8 @@
   22.26 +              s->macaddr[4],
   22.27 +              s->macaddr[5]);
   22.28 +              
   22.29 +-    /* XXX: instance number ? */
   22.30 +-    register_savevm("ne2000", 0, 2, ne2000_save, ne2000_load, s);
   22.31 +-    register_savevm("ne2000_pci", 0, 1, generic_pci_save, generic_pci_load, 
   22.32 +-                    &d->dev);
   22.33 ++    instance = pci_bus_num(bus) << 8 | s->pci_dev->devfn;
   22.34 ++    register_savevm("ne2000", instance, 2, ne2000_save, ne2000_load, s);
   22.35 ++    register_savevm("ne2000_pci", instance, 1, generic_pci_save, 
   22.36 ++                    generic_pci_load, &d->dev);
   22.37 + }
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/tools/ioemu/patches/ioemu-save-restore-pcnet	Tue May 08 09:09:17 2007 -0600
    23.3 @@ -0,0 +1,80 @@
    23.4 +Index: ioemu/hw/pcnet.c
    23.5 +===================================================================
    23.6 +--- ioemu.orig/hw/pcnet.c	2007-05-02 16:09:36.000000000 +0100
    23.7 ++++ ioemu/hw/pcnet.c	2007-05-02 16:10:28.000000000 +0100
    23.8 +@@ -1727,10 +1727,63 @@
    23.9 +     cpu_register_physical_memory(addr, PCNET_PNPMMIO_SIZE, d->mmio_io_addr);
   23.10 + }
   23.11 + 
   23.12 ++
   23.13 ++static void pcnet_save(QEMUFile *f, void *opaque)
   23.14 ++{
   23.15 ++    PCNetState *s = opaque;
   23.16 ++    unsigned int i;
   23.17 ++
   23.18 ++    qemu_put_be32s(f, &s->rap);
   23.19 ++    qemu_put_be32s(f, &s->isr);
   23.20 ++    qemu_put_be32s(f, &s->lnkst);
   23.21 ++    qemu_put_be32s(f, &s->rdra);
   23.22 ++    qemu_put_be32s(f, &s->tdra);
   23.23 ++    qemu_put_buffer(f, s->prom, 16);
   23.24 ++    for (i = 0; i < 128; i++)
   23.25 ++        qemu_put_be16s(f, &s->csr[i]);
   23.26 ++    for (i = 0; i < 32; i++)
   23.27 ++        qemu_put_be16s(f, &s->bcr[i]);
   23.28 ++    qemu_put_be64s(f, &s->timer);
   23.29 ++    qemu_put_be32s(f, &s->xmit_pos);
   23.30 ++    qemu_put_be32s(f, &s->recv_pos);
   23.31 ++    qemu_put_buffer(f, s->buffer, 4096);
   23.32 ++    qemu_put_be32s(f, &s->tx_busy);
   23.33 ++    qemu_put_timer(f, s->poll_timer);
   23.34 ++}
   23.35 ++
   23.36 ++static int pcnet_load(QEMUFile *f, void *opaque, int version_id)
   23.37 ++{
   23.38 ++    PCNetState *s = opaque;
   23.39 ++    int i, ret;
   23.40 ++
   23.41 ++    if (version_id != 1)
   23.42 ++        return -EINVAL;
   23.43 ++
   23.44 ++    qemu_get_be32s(f, &s->rap);
   23.45 ++    qemu_get_be32s(f, &s->isr);
   23.46 ++    qemu_get_be32s(f, &s->lnkst);
   23.47 ++    qemu_get_be32s(f, &s->rdra);
   23.48 ++    qemu_get_be32s(f, &s->tdra);
   23.49 ++    qemu_get_buffer(f, s->prom, 16);
   23.50 ++    for (i = 0; i < 128; i++)
   23.51 ++        qemu_get_be16s(f, &s->csr[i]);
   23.52 ++    for (i = 0; i < 32; i++)
   23.53 ++        qemu_get_be16s(f, &s->bcr[i]);
   23.54 ++    qemu_get_be64s(f, &s->timer);
   23.55 ++    qemu_get_be32s(f, &s->xmit_pos);
   23.56 ++    qemu_get_be32s(f, &s->recv_pos);
   23.57 ++    qemu_get_buffer(f, s->buffer, 4096);
   23.58 ++    qemu_get_be32s(f, &s->tx_busy);
   23.59 ++    qemu_get_timer(f, s->poll_timer);
   23.60 ++
   23.61 ++    return 0;
   23.62 ++}
   23.63 ++
   23.64 + void pci_pcnet_init(PCIBus *bus, NICInfo *nd)
   23.65 + {
   23.66 +     PCNetState *d;
   23.67 +     uint8_t *pci_conf;
   23.68 ++    int instance;
   23.69 + 
   23.70 + #if 0
   23.71 +     printf("sizeof(RMD)=%d, sizeof(TMD)=%d\n", 
   23.72 +@@ -1775,6 +1828,11 @@
   23.73 + 
   23.74 +     d->vc = qemu_new_vlan_client(nd->vlan, pcnet_receive, 
   23.75 +                                  pcnet_can_receive, d);
   23.76 ++
   23.77 ++    instance = pci_bus_num(bus) << 8 | d->dev.devfn;
   23.78 ++    register_savevm("pcnet", instance, 1, pcnet_save, pcnet_load, d);
   23.79 ++    register_savevm("pcnet_pci", instance, 1, generic_pci_save,
   23.80 ++                    generic_pci_load, &d->dev);
   23.81 +     
   23.82 +     snprintf(d->vc->info_str, sizeof(d->vc->info_str),
   23.83 +              "pcnet macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/tools/ioemu/patches/ioemu-save-restore-rtl8139	Tue May 08 09:09:17 2007 -0600
    24.3 @@ -0,0 +1,27 @@
    24.4 +Index: ioemu/hw/rtl8139.c
    24.5 +===================================================================
    24.6 +--- ioemu.orig/hw/rtl8139.c	2007-05-02 16:09:35.000000000 +0100
    24.7 ++++ ioemu/hw/rtl8139.c	2007-05-02 16:10:56.000000000 +0100
    24.8 +@@ -3406,6 +3406,7 @@
    24.9 +     PCIRTL8139State *d;
   24.10 +     RTL8139State *s;
   24.11 +     uint8_t *pci_conf;
   24.12 ++    int instance;
   24.13 +     
   24.14 +     d = (PCIRTL8139State *)pci_register_device(bus,
   24.15 +                                               "RTL8139", sizeof(PCIRTL8139State),
   24.16 +@@ -3456,10 +3457,10 @@
   24.17 +     s->cplus_txbuffer_len = 0;
   24.18 +     s->cplus_txbuffer_offset = 0;
   24.19 +              
   24.20 +-    /* XXX: instance number ? */
   24.21 +-    register_savevm("rtl8139", 0, 2, rtl8139_save, rtl8139_load, s);
   24.22 +-    register_savevm("rtl8139_pci", 0, 1, generic_pci_save, generic_pci_load, 
   24.23 +-                    &d->dev);
   24.24 ++    instance = pci_bus_num(bus) << 8 | s->pci_dev->devfn;
   24.25 ++    register_savevm("rtl8139", instance, 2, rtl8139_save, rtl8139_load, s);
   24.26 ++    register_savevm("rtl8139_pci", instance, 1, generic_pci_save, 
   24.27 ++                    generic_pci_load, &d->dev);
   24.28 + 
   24.29 + #if RTL8139_ONBOARD_TIMER
   24.30 +     s->timer = qemu_new_timer(vm_clock, rtl8139_timer, s);
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/tools/ioemu/patches/ioemu-save-restore-timer	Tue May 08 09:09:17 2007 -0600
    25.3 @@ -0,0 +1,27 @@
    25.4 +Index: ioemu/vl.c
    25.5 +===================================================================
    25.6 +--- ioemu.orig/vl.c	2007-05-03 10:07:54.000000000 +0100
    25.7 ++++ ioemu/vl.c	2007-05-03 10:07:54.000000000 +0100
    25.8 +@@ -828,10 +828,22 @@
    25.9 + #ifdef CONFIG_DM
   25.10 + static void timer_save(QEMUFile *f, void *opaque)
   25.11 + {
   25.12 ++    /* need timer for save/restoe qemu_timer in usb_uhci */
   25.13 ++    if (cpu_ticks_enabled) {
   25.14 ++        hw_error("cannot save state if virtual timers are running");
   25.15 ++    }
   25.16 ++    qemu_put_be64s(f, &cpu_clock_offset);
   25.17 + }
   25.18 + 
   25.19 + static int timer_load(QEMUFile *f, void *opaque, int version_id)
   25.20 + {
   25.21 ++    if (version_id != 1)
   25.22 ++        return -EINVAL;
   25.23 ++    if (cpu_ticks_enabled) {
   25.24 ++        return -EINVAL;
   25.25 ++    }
   25.26 ++
   25.27 ++    qemu_get_be64s(f, &cpu_clock_offset);
   25.28 +     return 0;
   25.29 + }
   25.30 + #else  /* !CONFIG_DM */
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/tools/ioemu/patches/ioemu-save-restore-usb	Tue May 08 09:09:17 2007 -0600
    26.3 @@ -0,0 +1,235 @@
    26.4 +Index: ioemu/hw/usb-hid.c
    26.5 +===================================================================
    26.6 +--- ioemu.orig/hw/usb-hid.c	2007-05-03 09:56:32.000000000 +0100
    26.7 ++++ ioemu/hw/usb-hid.c	2007-05-03 10:07:54.000000000 +0100
    26.8 +@@ -508,6 +508,49 @@
    26.9 +     qemu_free(s);
   26.10 + }
   26.11 + 
   26.12 ++void usb_mouse_save(QEMUFile *f, void *opaque)
   26.13 ++{
   26.14 ++    USBMouseState *s = (USBMouseState*)opaque;
   26.15 ++
   26.16 ++    qemu_put_be32s(f, &s->dx);
   26.17 ++    qemu_put_be32s(f, &s->dy);
   26.18 ++    qemu_put_be32s(f, &s->dz);
   26.19 ++    qemu_put_be32s(f, &s->buttons_state);
   26.20 ++    qemu_put_be32s(f, &s->x);
   26.21 ++    qemu_put_be32s(f, &s->y);
   26.22 ++    qemu_put_be32s(f, &s->kind);
   26.23 ++    qemu_put_be32s(f, &s->mouse_grabbed);
   26.24 ++    qemu_put_be32s(f, &s->status_changed);
   26.25 ++
   26.26 ++}
   26.27 ++
   26.28 ++int usb_mouse_load(QEMUFile *f, void *opaque, int version_id)
   26.29 ++{
   26.30 ++    USBMouseState *s = (USBMouseState*)opaque;
   26.31 ++
   26.32 ++    if (version_id != 1)
   26.33 ++        return -EINVAL;
   26.34 ++
   26.35 ++    qemu_get_be32s(f, &s->dx);
   26.36 ++    qemu_get_be32s(f, &s->dy);
   26.37 ++    qemu_get_be32s(f, &s->dz);
   26.38 ++    qemu_get_be32s(f, &s->buttons_state);
   26.39 ++    qemu_get_be32s(f, &s->x);
   26.40 ++    qemu_get_be32s(f, &s->y);
   26.41 ++    qemu_get_be32s(f, &s->kind);
   26.42 ++    qemu_get_be32s(f, &s->mouse_grabbed);
   26.43 ++    qemu_get_be32s(f, &s->status_changed);
   26.44 ++
   26.45 ++    if ( s->kind == USB_TABLET) {
   26.46 ++        fprintf(logfile, "usb_mouse_load:add usb_tablet_event.\n");
   26.47 ++        qemu_add_mouse_event_handler(usb_tablet_event, s, 1);
   26.48 ++    } else if ( s->kind == USB_MOUSE) {
   26.49 ++        fprintf(logfile, "usb_mouse_load:add usb_mouse_event.\n");
   26.50 ++        qemu_add_mouse_event_handler(usb_mouse_event, s, 0);
   26.51 ++    }
   26.52 ++}
   26.53 ++
   26.54 ++
   26.55 + USBDevice *usb_tablet_init(void)
   26.56 + {
   26.57 +     USBMouseState *s;
   26.58 +@@ -526,6 +569,8 @@
   26.59 + 
   26.60 +     pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Tablet");
   26.61 + 
   26.62 ++    register_savevm("USB tablet dev", 0, 1, usb_mouse_save, usb_mouse_load, s);
   26.63 ++
   26.64 +     return (USBDevice *)s;
   26.65 + }
   26.66 + 
   26.67 +@@ -547,5 +592,7 @@
   26.68 + 
   26.69 +     pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Mouse");
   26.70 + 
   26.71 ++    register_savevm("USB mouse dev", 0, 1, usb_mouse_save, usb_mouse_load, s);
   26.72 ++
   26.73 +     return (USBDevice *)s;
   26.74 + }
   26.75 +Index: ioemu/vl.c
   26.76 +===================================================================
   26.77 +--- ioemu.orig/vl.c	2007-05-03 10:07:53.000000000 +0100
   26.78 ++++ ioemu/vl.c	2007-05-03 10:07:54.000000000 +0100
   26.79 +@@ -3878,6 +3878,7 @@
   26.80 +     const char *p;
   26.81 +     USBDevice *dev;
   26.82 +     USBPort *port;
   26.83 ++    char usb_name[256] = "USB ";
   26.84 + 
   26.85 +     if (!free_usb_ports)
   26.86 +         return -1;
   26.87 +@@ -3914,6 +3915,12 @@
   26.88 +     free_usb_ports = port->next;
   26.89 +     port->next = used_usb_ports;
   26.90 +     used_usb_ports = port;
   26.91 ++
   26.92 ++    pstrcpy(usb_name + strlen(usb_name), 
   26.93 ++            sizeof(usb_name) - strlen(usb_name), 
   26.94 ++            devname);
   26.95 ++    register_savevm(usb_name, 0, 1, generic_usb_save, generic_usb_load, dev);
   26.96 ++    
   26.97 +     usb_attach(port, dev);
   26.98 +     return 0;
   26.99 + }
  26.100 +Index: ioemu/hw/usb.c
  26.101 +===================================================================
  26.102 +--- ioemu.orig/hw/usb.c	2007-05-03 09:56:32.000000000 +0100
  26.103 ++++ ioemu/hw/usb.c	2007-05-03 10:07:54.000000000 +0100
  26.104 +@@ -191,3 +191,43 @@
  26.105 +     }
  26.106 +     return q - buf;
  26.107 + }
  26.108 ++
  26.109 ++void generic_usb_save(QEMUFile* f, void *opaque)
  26.110 ++{
  26.111 ++    USBDevice *s = (USBDevice*)opaque;
  26.112 ++
  26.113 ++    qemu_put_be32s(f, &s->speed);
  26.114 ++    qemu_put_8s(f, &s->addr);
  26.115 ++    qemu_put_be32s(f, &s->state);
  26.116 ++
  26.117 ++    qemu_put_buffer(f, s->setup_buf, 8);
  26.118 ++    qemu_put_buffer(f, s->data_buf, 1024);
  26.119 ++
  26.120 ++    qemu_put_be32s(f, &s->remote_wakeup);
  26.121 ++    qemu_put_be32s(f, &s->setup_state);
  26.122 ++    qemu_put_be32s(f, &s->setup_len);
  26.123 ++    qemu_put_be32s(f, &s->setup_index);
  26.124 ++
  26.125 ++}
  26.126 ++
  26.127 ++int generic_usb_load(QEMUFile* f, void *opaque, int version_id)
  26.128 ++{
  26.129 ++    USBDevice *s = (USBDevice*)opaque;
  26.130 ++
  26.131 ++    if (version_id != 1)
  26.132 ++        return -EINVAL;
  26.133 ++
  26.134 ++    qemu_get_be32s(f, &s->speed);
  26.135 ++    qemu_get_8s(f, &s->addr);
  26.136 ++    qemu_get_be32s(f, &s->state);
  26.137 ++
  26.138 ++    qemu_get_buffer(f, s->setup_buf, 8);
  26.139 ++    qemu_get_buffer(f, s->data_buf, 1024);
  26.140 ++
  26.141 ++    qemu_get_be32s(f, &s->remote_wakeup);
  26.142 ++    qemu_get_be32s(f, &s->setup_state);
  26.143 ++    qemu_get_be32s(f, &s->setup_len);
  26.144 ++    qemu_get_be32s(f, &s->setup_index);
  26.145 ++
  26.146 ++    return 0;
  26.147 ++}
  26.148 +Index: ioemu/hw/usb-ohci.c
  26.149 +===================================================================
  26.150 +--- ioemu.orig/hw/usb-ohci.c	2007-05-03 09:56:32.000000000 +0100
  26.151 ++++ ioemu/hw/usb-ohci.c	2007-05-03 10:07:54.000000000 +0100
  26.152 +@@ -1186,5 +1186,7 @@
  26.153 +         qemu_register_usb_port(&ohci->rhport[i].port, ohci, i, ohci_attach);
  26.154 +     }
  26.155 + 
  26.156 ++    register_savevm("OHCI USB", 0, 1, generic_pci_save, generic_pci_load, ohci);
  26.157 ++
  26.158 +     ohci_reset(ohci);
  26.159 + }
  26.160 +Index: ioemu/hw/usb.h
  26.161 +===================================================================
  26.162 +--- ioemu.orig/hw/usb.h	2007-05-03 09:56:32.000000000 +0100
  26.163 ++++ ioemu/hw/usb.h	2007-05-03 10:07:54.000000000 +0100
  26.164 +@@ -176,3 +176,9 @@
  26.165 + 
  26.166 + /* usb-msd.c */
  26.167 + USBDevice *usb_msd_init(const char *filename);
  26.168 ++
  26.169 ++/* usb.c */
  26.170 ++void generic_usb_save(QEMUFile* f, void *opaque);
  26.171 ++int generic_usb_load(QEMUFile* f, void *opaque, int version_id);
  26.172 ++
  26.173 ++
  26.174 +Index: ioemu/hw/usb-uhci.c
  26.175 +===================================================================
  26.176 +--- ioemu.orig/hw/usb-uhci.c	2007-05-03 09:56:32.000000000 +0100
  26.177 ++++ ioemu/hw/usb-uhci.c	2007-05-03 10:07:54.000000000 +0100
  26.178 +@@ -638,6 +638,51 @@
  26.179 +     register_ioport_read(addr, 32, 1, uhci_ioport_readb, s);
  26.180 + }
  26.181 + 
  26.182 ++void uhci_usb_save(QEMUFile *f, void *opaque)
  26.183 ++{
  26.184 ++    int i;
  26.185 ++    UHCIState *s = (UHCIState*)opaque;
  26.186 ++
  26.187 ++    qemu_put_be16s(f, &s->cmd);
  26.188 ++    qemu_put_be16s(f, &s->status);
  26.189 ++    qemu_put_be16s(f, &s->intr);
  26.190 ++    qemu_put_be16s(f, &s->frnum);
  26.191 ++    qemu_put_be32s(f, &s->fl_base_addr);
  26.192 ++    qemu_put_8s(f, &s->sof_timing);
  26.193 ++    qemu_put_8s(f, &s->status2);
  26.194 ++
  26.195 ++    for(i = 0; i < NB_PORTS; i++) {
  26.196 ++        qemu_put_be16s(f, &s->ports[i].ctrl);
  26.197 ++    }
  26.198 ++
  26.199 ++    qemu_put_timer(f, s->frame_timer);
  26.200 ++}
  26.201 ++
  26.202 ++int uhci_usb_load(QEMUFile *f, void *opaque, int version_id)
  26.203 ++{
  26.204 ++    int i;
  26.205 ++    UHCIState *s = (UHCIState*)opaque;
  26.206 ++
  26.207 ++    if (version_id != 1)
  26.208 ++        return -EINVAL;
  26.209 ++
  26.210 ++    qemu_get_be16s(f, &s->cmd);
  26.211 ++    qemu_get_be16s(f, &s->status);
  26.212 ++    qemu_get_be16s(f, &s->intr);
  26.213 ++    qemu_get_be16s(f, &s->frnum);
  26.214 ++    qemu_get_be32s(f, &s->fl_base_addr);
  26.215 ++    qemu_get_8s(f, &s->sof_timing);
  26.216 ++    qemu_get_8s(f, &s->status2);
  26.217 ++
  26.218 ++    for(i = 0; i < NB_PORTS; i++) {
  26.219 ++        qemu_get_be16s(f, &s->ports[i].ctrl);
  26.220 ++    }
  26.221 ++
  26.222 ++    qemu_get_timer(f, s->frame_timer);
  26.223 ++
  26.224 ++    return 0;
  26.225 ++}
  26.226 ++
  26.227 + void usb_uhci_init(PCIBus *bus, int devfn)
  26.228 + {
  26.229 +     UHCIState *s;
  26.230 +@@ -671,4 +716,8 @@
  26.231 +        to rely on this.  */
  26.232 +     pci_register_io_region(&s->dev, 4, 0x20, 
  26.233 +                            PCI_ADDRESS_SPACE_IO, uhci_map);
  26.234 ++
  26.235 ++    register_savevm("UHCI_usb_pci", 0, 1, generic_pci_save, generic_pci_load, s);
  26.236 ++
  26.237 ++    register_savevm("UHCI usb controller", 0, 1, uhci_usb_save, uhci_usb_load, s);
  26.238 + }
    27.1 --- a/tools/ioemu/patches/nodelay-serial-over-tcp	Mon May 07 13:24:37 2007 -0600
    27.2 +++ b/tools/ioemu/patches/nodelay-serial-over-tcp	Tue May 08 09:09:17 2007 -0600
    27.3 @@ -8,9 +8,9 @@ Signed-off-by: Steven Smith <sos22@cam.a
    27.4  
    27.5  Index: ioemu/vl.c
    27.6  ===================================================================
    27.7 ---- ioemu.orig/vl.c	2006-12-08 18:21:56.000000000 +0000
    27.8 -+++ ioemu/vl.c	2006-12-08 18:22:42.000000000 +0000
    27.9 -@@ -2530,6 +2530,7 @@
   27.10 +--- ioemu.orig/vl.c	2007-05-03 10:09:02.000000000 +0100
   27.11 ++++ ioemu/vl.c	2007-05-03 10:09:03.000000000 +0100
   27.12 +@@ -2586,6 +2586,7 @@
   27.13       int is_waitconnect = 1;
   27.14       const char *ptr;
   27.15       struct sockaddr_in saddr;
   27.16 @@ -18,7 +18,7 @@ Index: ioemu/vl.c
   27.17   
   27.18       if (parse_host_port(&saddr, host_str) < 0)
   27.19           goto fail;
   27.20 -@@ -2598,6 +2599,8 @@
   27.21 +@@ -2654,6 +2655,8 @@
   27.22               }
   27.23           }
   27.24           s->fd = fd;
    28.1 --- a/tools/ioemu/patches/qemu-64bit	Mon May 07 13:24:37 2007 -0600
    28.2 +++ b/tools/ioemu/patches/qemu-64bit	Tue May 08 09:09:17 2007 -0600
    28.3 @@ -1,7 +1,7 @@
    28.4  Index: ioemu/cpu-all.h
    28.5  ===================================================================
    28.6 ---- ioemu.orig/cpu-all.h	2006-08-06 02:14:09.796902750 +0100
    28.7 -+++ ioemu/cpu-all.h	2006-08-06 02:15:39.707879423 +0100
    28.8 +--- ioemu.orig/cpu-all.h	2007-05-02 16:04:46.000000000 +0100
    28.9 ++++ ioemu/cpu-all.h	2007-05-02 16:05:50.000000000 +0100
   28.10  @@ -822,7 +822,7 @@
   28.11   
   28.12   /* memory API */
   28.13 @@ -13,8 +13,8 @@ Index: ioemu/cpu-all.h
   28.14   extern uint8_t *phys_ram_dirty;
   28.15  Index: ioemu/hw/pc.c
   28.16  ===================================================================
   28.17 ---- ioemu.orig/hw/pc.c	2006-08-06 02:14:09.797902638 +0100
   28.18 -+++ ioemu/hw/pc.c	2006-08-06 02:15:39.708879311 +0100
   28.19 +--- ioemu.orig/hw/pc.c	2007-05-02 16:04:46.000000000 +0100
   28.20 ++++ ioemu/hw/pc.c	2007-05-02 16:05:50.000000000 +0100
   28.21  @@ -155,7 +155,7 @@
   28.22   }
   28.23   
   28.24 @@ -53,8 +53,8 @@ Index: ioemu/hw/pc.c
   28.25                           const char *kernel_filename, 
   28.26  Index: ioemu/vl.c
   28.27  ===================================================================
   28.28 ---- ioemu.orig/vl.c	2006-08-06 02:15:31.040845624 +0100
   28.29 -+++ ioemu/vl.c	2006-08-06 02:15:39.711878977 +0100
   28.30 +--- ioemu.orig/vl.c	2007-05-02 16:05:50.000000000 +0100
   28.31 ++++ ioemu/vl.c	2007-05-02 16:05:50.000000000 +0100
   28.32  @@ -122,7 +122,7 @@
   28.33   const char* keyboard_layout = NULL;
   28.34   int64_t ticks_per_sec;
   28.35 @@ -64,7 +64,7 @@ Index: ioemu/vl.c
   28.36   int pit_min_timer_count = 0;
   28.37   int nb_nics;
   28.38   NICInfo nd_table[MAX_NICS];
   28.39 -@@ -5895,7 +5895,7 @@
   28.40 +@@ -5899,7 +5899,7 @@
   28.41                   help();
   28.42                   break;
   28.43               case QEMU_OPTION_m:
   28.44 @@ -75,8 +75,8 @@ Index: ioemu/vl.c
   28.45                   if (ram_size > PHYS_RAM_MAX_SIZE) {
   28.46  Index: ioemu/vl.h
   28.47  ===================================================================
   28.48 ---- ioemu.orig/vl.h	2006-08-06 02:15:10.368150219 +0100
   28.49 -+++ ioemu/vl.h	2006-08-06 02:15:39.711878977 +0100
   28.50 +--- ioemu.orig/vl.h	2007-05-02 16:05:50.000000000 +0100
   28.51 ++++ ioemu/vl.h	2007-05-02 16:05:50.000000000 +0100
   28.52  @@ -146,7 +146,7 @@
   28.53   extern int xc_handle;
   28.54   extern int domid;
   28.55 @@ -97,8 +97,8 @@ Index: ioemu/vl.h
   28.56                const char *kernel_filename, const char *kernel_cmdline,
   28.57  Index: ioemu/hw/vga.c
   28.58  ===================================================================
   28.59 ---- ioemu.orig/hw/vga.c	2006-08-06 02:15:10.364150665 +0100
   28.60 -+++ ioemu/hw/vga.c	2006-08-06 02:15:39.712878866 +0100
   28.61 +--- ioemu.orig/hw/vga.c	2007-05-02 16:05:50.000000000 +0100
   28.62 ++++ ioemu/hw/vga.c	2007-05-02 16:05:50.000000000 +0100
   28.63  @@ -1365,7 +1365,8 @@
   28.64   static void vga_draw_graphic(VGAState *s, int full_update)
   28.65   {
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/tools/ioemu/patches/qemu-block-device-bounds-checks	Tue May 08 09:09:17 2007 -0600
    29.3 @@ -0,0 +1,22 @@
    29.4 +Index: ioemu/block.c
    29.5 +===================================================================
    29.6 +--- ioemu.orig/block.c	2007-05-03 14:55:04.000000000 +0100
    29.7 ++++ ioemu/block.c	2007-05-03 14:59:20.000000000 +0100
    29.8 +@@ -420,6 +420,8 @@
    29.9 + 
   29.10 +     if (!bs->inserted)
   29.11 +         return -1;
   29.12 ++    if (sector_num < 0)
   29.13 ++	return -1;
   29.14 + 
   29.15 +     while (nb_sectors > 0) {
   29.16 +         if (sector_num == 0 && bs->boot_sector_enabled) {
   29.17 +@@ -458,6 +460,8 @@
   29.18 +         return -1;
   29.19 +     if (bs->read_only)
   29.20 +         return -1;
   29.21 ++    if (sector_num < 0)
   29.22 ++	return -1;
   29.23 +     if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {
   29.24 +         memcpy(bs->boot_sector_data, buf, 512);   
   29.25 +     }
    30.1 --- a/tools/ioemu/patches/qemu-bootorder	Mon May 07 13:24:37 2007 -0600
    30.2 +++ b/tools/ioemu/patches/qemu-bootorder	Tue May 08 09:09:17 2007 -0600
    30.3 @@ -1,8 +1,8 @@
    30.4  Index: ioemu/vl.c
    30.5  ===================================================================
    30.6 ---- ioemu.orig/vl.c	2006-12-20 15:12:08.000000000 +0000
    30.7 -+++ ioemu/vl.c	2006-12-20 15:21:19.000000000 +0000
    30.8 -@@ -125,7 +125,7 @@
    30.9 +--- ioemu.orig/vl.c	2007-05-03 15:20:35.000000000 +0100
   30.10 ++++ ioemu/vl.c	2007-05-03 15:20:43.000000000 +0100
   30.11 +@@ -126,7 +126,7 @@
   30.12   struct sockaddr_in vnclisten_addr;
   30.13   const char* keyboard_layout = NULL;
   30.14   int64_t ticks_per_sec;
   30.15 @@ -11,7 +11,7 @@ Index: ioemu/vl.c
   30.16   uint64_t ram_size;
   30.17   int pit_min_timer_count = 0;
   30.18   int nb_nics;
   30.19 -@@ -6059,14 +6059,14 @@
   30.20 +@@ -6150,14 +6150,14 @@
   30.21                   break;
   30.22   #endif /* !CONFIG_DM */
   30.23               case QEMU_OPTION_boot:
   30.24 @@ -34,7 +34,7 @@ Index: ioemu/vl.c
   30.25                       exit(1);
   30.26                   }
   30.27                   break;
   30.28 -@@ -6333,6 +6333,7 @@
   30.29 +@@ -6424,6 +6424,7 @@
   30.30           fd_filename[0] == '\0')
   30.31           help();
   30.32       
   30.33 @@ -42,7 +42,7 @@ Index: ioemu/vl.c
   30.34       /* boot to cd by default if no hard disk */
   30.35       if (hd_filename[0] == '\0' && boot_device == 'c') {
   30.36           if (fd_filename[0] != '\0')
   30.37 -@@ -6340,6 +6341,7 @@
   30.38 +@@ -6431,6 +6432,7 @@
   30.39           else
   30.40               boot_device = 'd';
   30.41       }
   30.42 @@ -50,7 +50,7 @@ Index: ioemu/vl.c
   30.43   #endif /* !CONFIG_DM */
   30.44   
   30.45       setvbuf(stdout, NULL, _IOLBF, 0);
   30.46 -@@ -6590,6 +6592,7 @@
   30.47 +@@ -6692,6 +6694,7 @@
   30.48                     ds, fd_filename, snapshot,
   30.49                     kernel_filename, kernel_cmdline, initrd_filename,
   30.50                     timeoffset);
   30.51 @@ -60,8 +60,8 @@ Index: ioemu/vl.c
   30.52       if (usb_enabled) {
   30.53  Index: ioemu/vl.h
   30.54  ===================================================================
   30.55 ---- ioemu.orig/vl.h	2006-12-20 15:12:08.000000000 +0000
   30.56 -+++ ioemu/vl.h	2006-12-20 15:21:14.000000000 +0000
   30.57 +--- ioemu.orig/vl.h	2007-05-03 15:20:39.000000000 +0100
   30.58 ++++ ioemu/vl.h	2007-05-03 15:20:43.000000000 +0100
   30.59  @@ -578,7 +578,7 @@
   30.60   #ifndef QEMU_TOOL
   30.61   
   30.62 @@ -71,7 +71,7 @@ Index: ioemu/vl.h
   30.63                DisplayState *ds, const char **fd_filename, int snapshot,
   30.64                const char *kernel_filename, const char *kernel_cmdline,
   30.65                const char *initrd_filename, time_t timeoffset);
   30.66 -@@ -1023,7 +1023,7 @@
   30.67 +@@ -1024,7 +1024,7 @@
   30.68                       uint32_t start, uint32_t count);
   30.69   int PPC_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size,
   30.70                             const unsigned char *arch,
   30.71 @@ -82,8 +82,8 @@ Index: ioemu/vl.h
   30.72                             uint32_t initrd_image, uint32_t initrd_size,
   30.73  Index: ioemu/hw/pc.c
   30.74  ===================================================================
   30.75 ---- ioemu.orig/hw/pc.c	2006-12-20 15:12:08.000000000 +0000
   30.76 -+++ ioemu/hw/pc.c	2006-12-20 15:21:19.000000000 +0000
   30.77 +--- ioemu.orig/hw/pc.c	2007-05-03 15:20:35.000000000 +0100
   30.78 ++++ ioemu/hw/pc.c	2007-05-03 15:20:43.000000000 +0100
   30.79  @@ -158,8 +158,25 @@
   30.80       rtc_set_memory(s, info_ofs + 8, sectors);
   30.81   }
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/tools/ioemu/patches/qemu-cirrus-bounds-checks	Tue May 08 09:09:17 2007 -0600
    31.3 @@ -0,0 +1,350 @@
    31.4 +Index: ioemu/hw/cirrus_vga.c
    31.5 +===================================================================
    31.6 +--- ioemu.orig/hw/cirrus_vga.c	2007-05-03 14:55:45.000000000 +0100
    31.7 ++++ ioemu/hw/cirrus_vga.c	2007-05-03 14:58:05.000000000 +0100
    31.8 +@@ -601,7 +601,8 @@
    31.9 + 	off_cur_end = off_cur + bytesperline;
   31.10 + 	off_cur &= TARGET_PAGE_MASK;
   31.11 + 	while (off_cur < off_cur_end) {
   31.12 +-	    cpu_physical_memory_set_dirty(s->vram_offset + off_cur);
   31.13 ++	    cpu_physical_memory_set_dirty(s->vram_offset +
   31.14 ++					  (off_cur & s->cirrus_addr_mask));
   31.15 + 	    off_cur += TARGET_PAGE_SIZE;
   31.16 + 	}
   31.17 + 	off_begin += off_pitch;
   31.18 +Index: ioemu/hw/cirrus_vga_rop.h
   31.19 +===================================================================
   31.20 +--- ioemu.orig/hw/cirrus_vga_rop.h	2007-05-02 10:30:05.000000000 +0100
   31.21 ++++ ioemu/hw/cirrus_vga_rop.h	2007-05-03 14:58:22.000000000 +0100
   31.22 +@@ -22,18 +22,36 @@
   31.23 +  * THE SOFTWARE.
   31.24 +  */
   31.25 + 
   31.26 ++#define get_base(p, s, b) do { \
   31.27 ++    if ((p) >= (s)->vram_ptr && (p) < (s)->vram_ptr + (s)->vram_size) \
   31.28 ++	(b) = (s)->vram_ptr; \
   31.29 ++    else if ((p) >= &(s)->cirrus_bltbuf[0] && \
   31.30 ++	     (p) < &(s)->cirrus_bltbuf[CIRRUS_BLTBUFSIZE]) \
   31.31 ++	(b) = &(s)->cirrus_bltbuf[0]; \
   31.32 ++    else \
   31.33 ++	return; \
   31.34 ++} while(0)
   31.35 ++
   31.36 ++#define m(x) ((x) & s->cirrus_addr_mask)
   31.37 ++
   31.38 + static void
   31.39 + glue(cirrus_bitblt_rop_fwd_, ROP_NAME)(CirrusVGAState *s,
   31.40 +-                             uint8_t *dst,const uint8_t *src,
   31.41 ++                             uint8_t *dst_,const uint8_t *src_,
   31.42 +                              int dstpitch,int srcpitch,
   31.43 +                              int bltwidth,int bltheight)
   31.44 + {
   31.45 +     int x,y;
   31.46 ++    uint32_t dst, src;
   31.47 ++    uint8_t *dst_base, *src_base;
   31.48 ++    get_base(dst_, s, dst_base);
   31.49 ++    get_base(src_, s, src_base);
   31.50 ++    dst = dst_ - dst_base;
   31.51 ++    src = src_ - src_base;
   31.52 +     dstpitch -= bltwidth;
   31.53 +     srcpitch -= bltwidth;
   31.54 +     for (y = 0; y < bltheight; y++) {
   31.55 +         for (x = 0; x < bltwidth; x++) {
   31.56 +-            ROP_OP(*dst, *src);
   31.57 ++            ROP_OP(*(dst_base + m(dst)), *(src_base + m(src)));
   31.58 +             dst++;
   31.59 +             src++;
   31.60 +         }
   31.61 +@@ -44,16 +62,22 @@
   31.62 + 
   31.63 + static void
   31.64 + glue(cirrus_bitblt_rop_bkwd_, ROP_NAME)(CirrusVGAState *s,
   31.65 +-                                        uint8_t *dst,const uint8_t *src,
   31.66 ++                                        uint8_t *dst_,const uint8_t *src_,
   31.67 +                                         int dstpitch,int srcpitch,
   31.68 +                                         int bltwidth,int bltheight)
   31.69 + {
   31.70 +     int x,y;
   31.71 ++    uint32_t dst, src;
   31.72 ++    uint8_t *dst_base, *src_base;
   31.73 ++    get_base(dst_, s, dst_base);
   31.74 ++    get_base(src_, s, src_base);
   31.75 ++    dst = dst_ - dst_base;
   31.76 ++    src = src_ - src_base;
   31.77 +     dstpitch += bltwidth;
   31.78 +     srcpitch += bltwidth;
   31.79 +     for (y = 0; y < bltheight; y++) {
   31.80 +         for (x = 0; x < bltwidth; x++) {
   31.81 +-            ROP_OP(*dst, *src);
   31.82 ++            ROP_OP(*(dst_base + m(dst)), *(src_base + m(src)));
   31.83 +             dst--;
   31.84 +             src--;
   31.85 +         }
   31.86 +@@ -76,3 +100,6 @@
   31.87 + 
   31.88 + #undef ROP_NAME
   31.89 + #undef ROP_OP
   31.90 ++
   31.91 ++#undef get_base
   31.92 ++#undef m
   31.93 +Index: ioemu/hw/cirrus_vga_rop2.h
   31.94 +===================================================================
   31.95 +--- ioemu.orig/hw/cirrus_vga_rop2.h	2007-05-02 10:30:05.000000000 +0100
   31.96 ++++ ioemu/hw/cirrus_vga_rop2.h	2007-05-03 14:58:42.000000000 +0100
   31.97 +@@ -23,36 +23,42 @@
   31.98 +  */
   31.99 + 
  31.100 + #if DEPTH == 8
  31.101 +-#define PUTPIXEL()    ROP_OP(d[0], col)
  31.102 ++#define PUTPIXEL()    ROP_OP((dst_base + m(d))[0], col)
  31.103 + #elif DEPTH == 16
  31.104 +-#define PUTPIXEL()    ROP_OP(((uint16_t *)d)[0], col);
  31.105 ++#define PUTPIXEL()    ROP_OP(((uint16_t *)(dst_base + m(d)))[0], col);
  31.106 + #elif DEPTH == 24
  31.107 +-#define PUTPIXEL()    ROP_OP(d[0], col); \
  31.108 +-                      ROP_OP(d[1], (col >> 8)); \
  31.109 +-                      ROP_OP(d[2], (col >> 16))
  31.110 ++#define PUTPIXEL()    ROP_OP((dst_base + m(d))[0], col); \
  31.111 ++                      ROP_OP((dst_base + m(d))[1], (col >> 8)); \
  31.112 ++                      ROP_OP((dst_base + m(d))[2], (col >> 16))
  31.113 + #elif DEPTH == 32
  31.114 +-#define PUTPIXEL()    ROP_OP(((uint32_t *)d)[0], col)
  31.115 ++#define PUTPIXEL()    ROP_OP(((uint32_t *)(dst_base + m(d)))[0], col)
  31.116 + #else
  31.117 + #error unsupported DEPTH
  31.118 + #endif                
  31.119 + 
  31.120 + static void
  31.121 + glue(glue(glue(cirrus_patternfill_, ROP_NAME), _),DEPTH)
  31.122 +-     (CirrusVGAState * s, uint8_t * dst,
  31.123 +-      const uint8_t * src, 
  31.124 ++     (CirrusVGAState * s, uint8_t * dst_,
  31.125 ++      const uint8_t * src_, 
  31.126 +       int dstpitch, int srcpitch, 
  31.127 +       int bltwidth, int bltheight)
  31.128 + {
  31.129 +-    uint8_t *d;
  31.130 ++    uint8_t *dst_base, *src_base;
  31.131 ++    uint32_t src, dst;
  31.132 ++    uint32_t d;
  31.133 +     int x, y, pattern_y, pattern_pitch, pattern_x;
  31.134 +     unsigned int col;
  31.135 +-    const uint8_t *src1;
  31.136 ++    uint32_t src1;
  31.137 + #if DEPTH == 24
  31.138 +     int skipleft = s->gr[0x2f] & 0x1f;
  31.139 + #else
  31.140 +     int skipleft = (s->gr[0x2f] & 0x07) * (DEPTH / 8);
  31.141 + #endif
  31.142 + 
  31.143 ++    get_base(dst_, s, dst_base);
  31.144 ++    get_base(src_, s, src_base);
  31.145 ++    dst = dst_ - dst_base;
  31.146 ++    src = src_ - src_base;
  31.147 + #if DEPTH == 8
  31.148 +     pattern_pitch = 8;
  31.149 + #elif DEPTH == 16
  31.150 +@@ -67,19 +73,19 @@
  31.151 +         src1 = src + pattern_y * pattern_pitch;
  31.152 +         for (x = skipleft; x < bltwidth; x += (DEPTH / 8)) {
  31.153 + #if DEPTH == 8
  31.154 +-            col = src1[pattern_x];
  31.155 ++            col = *(src_base + m(src1 + pattern_x));
  31.156 +             pattern_x = (pattern_x + 1) & 7;
  31.157 + #elif DEPTH == 16
  31.158 +-            col = ((uint16_t *)(src1 + pattern_x))[0];
  31.159 ++            col = *(uint16_t *)(src_base + m(src1 + pattern_x));
  31.160 +             pattern_x = (pattern_x + 2) & 15;
  31.161 + #elif DEPTH == 24
  31.162 +             {
  31.163 +-                const uint8_t *src2 = src1 + pattern_x * 3;
  31.164 ++                const uint8_t *src2 = src_base + m(src1 + pattern_x * 3);
  31.165 +                 col = src2[0] | (src2[1] << 8) | (src2[2] << 16);
  31.166 +                 pattern_x = (pattern_x + 1) & 7;
  31.167 +             }
  31.168 + #else
  31.169 +-            col = ((uint32_t *)(src1 + pattern_x))[0];
  31.170 ++            col = *(uint32_t *)(src_base + m(src1 + pattern_x));
  31.171 +             pattern_x = (pattern_x + 4) & 31;
  31.172 + #endif
  31.173 +             PUTPIXEL();
  31.174 +@@ -93,12 +99,14 @@
  31.175 + /* NOTE: srcpitch is ignored */
  31.176 + static void
  31.177 + glue(glue(glue(cirrus_colorexpand_transp_, ROP_NAME), _),DEPTH)
  31.178 +-     (CirrusVGAState * s, uint8_t * dst,
  31.179 +-      const uint8_t * src, 
  31.180 ++     (CirrusVGAState * s, uint8_t * dst_,
  31.181 ++      const uint8_t * src_, 
  31.182 +       int dstpitch, int srcpitch, 
  31.183 +       int bltwidth, int bltheight)
  31.184 + {
  31.185 +-    uint8_t *d;
  31.186 ++    uint8_t *dst_base, *src_base;
  31.187 ++    uint32_t src, dst;
  31.188 ++    uint32_t d;
  31.189 +     int x, y;
  31.190 +     unsigned bits, bits_xor;
  31.191 +     unsigned int col;
  31.192 +@@ -112,6 +120,10 @@
  31.193 +     int dstskipleft = srcskipleft * (DEPTH / 8);
  31.194 + #endif
  31.195 + 
  31.196 ++    get_base(dst_, s, dst_base);
  31.197 ++    get_base(src_, s, src_base);
  31.198 ++    dst = dst_ - dst_base;
  31.199 ++    src = src_ - src_base;
  31.200 +     if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) {
  31.201 +         bits_xor = 0xff;
  31.202 +         col = s->cirrus_blt_bgcol;
  31.203 +@@ -122,12 +134,12 @@
  31.204 + 
  31.205 +     for(y = 0; y < bltheight; y++) {
  31.206 +         bitmask = 0x80 >> srcskipleft;
  31.207 +-        bits = *src++ ^ bits_xor;
  31.208 ++        bits = *(src_base + m(src++)) ^ bits_xor;
  31.209 +         d = dst + dstskipleft;
  31.210 +         for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
  31.211 +             if ((bitmask & 0xff) == 0) {
  31.212 +                 bitmask = 0x80;
  31.213 +-                bits = *src++ ^ bits_xor;
  31.214 ++                bits = *(src_base + m(src++)) ^ bits_xor;
  31.215 +             }
  31.216 +             index = (bits & bitmask);
  31.217 +             if (index) {
  31.218 +@@ -142,13 +154,15 @@
  31.219 + 
  31.220 + static void
  31.221 + glue(glue(glue(cirrus_colorexpand_, ROP_NAME), _),DEPTH)
  31.222 +-     (CirrusVGAState * s, uint8_t * dst,
  31.223 +-      const uint8_t * src, 
  31.224 ++     (CirrusVGAState * s, uint8_t * dst_,
  31.225 ++      const uint8_t * src_, 
  31.226 +       int dstpitch, int srcpitch, 
  31.227 +       int bltwidth, int bltheight)
  31.228 + {
  31.229 ++    uint8_t *dst_base, *src_base;
  31.230 ++    uint32_t src, dst;
  31.231 +     uint32_t colors[2];
  31.232 +-    uint8_t *d;
  31.233 ++    uint32_t d;
  31.234 +     int x, y;
  31.235 +     unsigned bits;
  31.236 +     unsigned int col;
  31.237 +@@ -156,16 +170,20 @@
  31.238 +     int srcskipleft = s->gr[0x2f] & 0x07;
  31.239 +     int dstskipleft = srcskipleft * (DEPTH / 8);
  31.240 + 
  31.241 ++    get_base(dst_, s, dst_base);
  31.242 ++    get_base(src_, s, src_base);
  31.243 ++    dst = dst_ - dst_base;
  31.244 ++    src = src_ - src_base;
  31.245 +     colors[0] = s->cirrus_blt_bgcol;
  31.246 +     colors[1] = s->cirrus_blt_fgcol;
  31.247 +     for(y = 0; y < bltheight; y++) {
  31.248 +         bitmask = 0x80 >> srcskipleft;
  31.249 +-        bits = *src++;
  31.250 ++        bits = *(src_base + m(src++));
  31.251 +         d = dst + dstskipleft;
  31.252 +         for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
  31.253 +             if ((bitmask & 0xff) == 0) {
  31.254 +                 bitmask = 0x80;
  31.255 +-                bits = *src++;
  31.256 ++                bits = *(src_base + m(src++));
  31.257 +             }
  31.258 +             col = colors[!!(bits & bitmask)];
  31.259 +             PUTPIXEL();
  31.260 +@@ -178,12 +196,14 @@
  31.261 + 
  31.262 + static void
  31.263 + glue(glue(glue(cirrus_colorexpand_pattern_transp_, ROP_NAME), _),DEPTH)
  31.264 +-     (CirrusVGAState * s, uint8_t * dst,
  31.265 +-      const uint8_t * src, 
  31.266 ++     (CirrusVGAState * s, uint8_t * dst_,
  31.267 ++      const uint8_t * src_, 
  31.268 +       int dstpitch, int srcpitch, 
  31.269 +       int bltwidth, int bltheight)
  31.270 + {
  31.271 +-    uint8_t *d;
  31.272 ++    uint8_t *dst_base, *src_base;
  31.273 ++    uint32_t src, dst;
  31.274 ++    uint32_t d;
  31.275 +     int x, y, bitpos, pattern_y;
  31.276 +     unsigned int bits, bits_xor;
  31.277 +     unsigned int col;
  31.278 +@@ -195,6 +215,10 @@
  31.279 +     int dstskipleft = srcskipleft * (DEPTH / 8);
  31.280 + #endif
  31.281 + 
  31.282 ++    get_base(dst_, s, dst_base);
  31.283 ++    get_base(src_, s, src_base);
  31.284 ++    dst = dst_ - dst_base;
  31.285 ++    src = src_ - src_base;
  31.286 +     if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) {
  31.287 +         bits_xor = 0xff;
  31.288 +         col = s->cirrus_blt_bgcol;
  31.289 +@@ -205,7 +229,7 @@
  31.290 +     pattern_y = s->cirrus_blt_srcaddr & 7;
  31.291 + 
  31.292 +     for(y = 0; y < bltheight; y++) {
  31.293 +-        bits = src[pattern_y] ^ bits_xor;
  31.294 ++        bits = *(src_base + m(src + pattern_y)) ^ bits_xor;
  31.295 +         bitpos = 7 - srcskipleft;
  31.296 +         d = dst + dstskipleft;
  31.297 +         for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
  31.298 +@@ -222,25 +246,31 @@
  31.299 + 
  31.300 + static void
  31.301 + glue(glue(glue(cirrus_colorexpand_pattern_, ROP_NAME), _),DEPTH)
  31.302 +-     (CirrusVGAState * s, uint8_t * dst,
  31.303 +-      const uint8_t * src, 
  31.304 ++     (CirrusVGAState * s, uint8_t * dst_,
  31.305 ++      const uint8_t * src_, 
  31.306 +       int dstpitch, int srcpitch, 
  31.307 +       int bltwidth, int bltheight)
  31.308 + {
  31.309 ++    uint8_t *dst_base, *src_base;
  31.310 ++    uint32_t src, dst;
  31.311 +     uint32_t colors[2];
  31.312 +-    uint8_t *d;
  31.313 ++    uint32_t d;
  31.314 +     int x, y, bitpos, pattern_y;
  31.315 +     unsigned int bits;
  31.316 +     unsigned int col;
  31.317 +     int srcskipleft = s->gr[0x2f] & 0x07;
  31.318 +     int dstskipleft = srcskipleft * (DEPTH / 8);
  31.319 + 
  31.320 ++    get_base(dst_, s, dst_base);
  31.321 ++    get_base(src_, s, src_base);
  31.322 ++    dst = dst_ - dst_base;
  31.323 ++    src = src_ - src_base;
  31.324 +     colors[0] = s->cirrus_blt_bgcol;
  31.325 +     colors[1] = s->cirrus_blt_fgcol;
  31.326 +     pattern_y = s->cirrus_blt_srcaddr & 7;
  31.327 + 
  31.328 +     for(y = 0; y < bltheight; y++) {
  31.329 +-        bits = src[pattern_y];
  31.330 ++        bits = *(src_base + m(src + pattern_y));
  31.331 +         bitpos = 7 - srcskipleft;
  31.332 +         d = dst + dstskipleft;
  31.333 +         for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
  31.334 +@@ -257,13 +287,17 @@
  31.335 + static void 
  31.336 + glue(glue(glue(cirrus_fill_, ROP_NAME), _),DEPTH)
  31.337 +      (CirrusVGAState *s,
  31.338 +-      uint8_t *dst, int dst_pitch, 
  31.339 ++      uint8_t *dst_, int dst_pitch, 
  31.340 +       int width, int height)
  31.341 + {
  31.342 +-    uint8_t *d, *d1;
  31.343 ++    uint8_t *dst_base;
  31.344 ++    uint32_t dst;
  31.345 ++    uint32_t d, d1;
  31.346 +     uint32_t col;
  31.347 +     int x, y;
  31.348 + 
  31.349 ++    get_base(dst_, s, dst_base);
  31.350 ++    dst = dst_ - dst_base;
  31.351 +     col = s->cirrus_blt_fgcol;
  31.352 + 
  31.353 +     d1 = dst;
    32.1 --- a/tools/ioemu/patches/qemu-cleanup	Mon May 07 13:24:37 2007 -0600
    32.2 +++ b/tools/ioemu/patches/qemu-cleanup	Tue May 08 09:09:17 2007 -0600
    32.3 @@ -1,7 +1,7 @@
    32.4  Index: ioemu/hw/vga.c
    32.5  ===================================================================
    32.6 ---- ioemu.orig/hw/vga.c	2006-10-24 14:44:03.000000000 +0100
    32.7 -+++ ioemu/hw/vga.c	2006-10-24 14:45:22.000000000 +0100
    32.8 +--- ioemu.orig/hw/vga.c	2007-05-02 16:04:46.000000000 +0100
    32.9 ++++ ioemu/hw/vga.c	2007-05-02 16:05:50.000000000 +0100
   32.10  @@ -1622,7 +1622,9 @@
   32.11   static void vga_save(QEMUFile *f, void *opaque)
   32.12   {
   32.13 @@ -26,8 +26,8 @@ Index: ioemu/hw/vga.c
   32.14           return -EINVAL;
   32.15  Index: ioemu/vl.c
   32.16  ===================================================================
   32.17 ---- ioemu.orig/vl.c	2006-10-24 14:44:08.000000000 +0100
   32.18 -+++ ioemu/vl.c	2006-10-24 14:45:29.000000000 +0100
   32.19 +--- ioemu.orig/vl.c	2007-05-02 16:05:50.000000000 +0100
   32.20 ++++ ioemu/vl.c	2007-05-02 16:05:50.000000000 +0100
   32.21  @@ -39,6 +39,7 @@
   32.22   #include <sys/ioctl.h>
   32.23   #include <sys/socket.h>
   32.24 @@ -74,7 +74,7 @@ Index: ioemu/vl.c
   32.25   #ifdef USE_KQEMU
   32.26       { "no-kqemu", 0, QEMU_OPTION_no_kqemu },
   32.27       { "kernel-kqemu", 0, QEMU_OPTION_kernel_kqemu },
   32.28 -@@ -5849,9 +5854,11 @@
   32.29 +@@ -5853,9 +5858,11 @@
   32.30                   fd_bootchk = 0;
   32.31                   break;
   32.32   #endif
   32.33 @@ -88,8 +88,8 @@ Index: ioemu/vl.c
   32.34                       fprintf(stderr, "qemu: too many network clients\n");
   32.35  Index: ioemu/vl.h
   32.36  ===================================================================
   32.37 ---- ioemu.orig/vl.h	2006-10-24 14:44:08.000000000 +0100
   32.38 -+++ ioemu/vl.h	2006-10-24 14:45:22.000000000 +0100
   32.39 +--- ioemu.orig/vl.h	2007-05-02 16:05:50.000000000 +0100
   32.40 ++++ ioemu/vl.h	2007-05-02 16:05:50.000000000 +0100
   32.41  @@ -957,7 +957,7 @@
   32.42   	       unsigned long vram_offset, int vram_size, int width, int height);
   32.43   
   32.44 @@ -101,8 +101,8 @@ Index: ioemu/vl.h
   32.45   void slavio_irq_info(void *opaque);
   32.46  Index: ioemu/usb-linux.c
   32.47  ===================================================================
   32.48 ---- ioemu.orig/usb-linux.c	2006-10-24 14:44:03.000000000 +0100
   32.49 -+++ ioemu/usb-linux.c	2006-10-24 14:44:08.000000000 +0100
   32.50 +--- ioemu.orig/usb-linux.c	2007-05-02 16:04:46.000000000 +0100
   32.51 ++++ ioemu/usb-linux.c	2007-05-02 16:05:50.000000000 +0100
   32.52  @@ -26,7 +26,9 @@
   32.53   #if defined(__linux__)
   32.54   #include <dirent.h>
    33.1 --- a/tools/ioemu/patches/qemu-daemonize	Mon May 07 13:24:37 2007 -0600
    33.2 +++ b/tools/ioemu/patches/qemu-daemonize	Tue May 08 09:09:17 2007 -0600
    33.3 @@ -2,9 +2,9 @@ Changes required because qemu-dm runs da
    33.4  
    33.5  Index: ioemu/vl.c
    33.6  ===================================================================
    33.7 ---- ioemu.orig/vl.c	2006-12-08 02:00:42.000000000 +0000
    33.8 -+++ ioemu/vl.c	2006-12-08 02:00:42.000000000 +0000
    33.9 -@@ -6038,10 +6038,11 @@
   33.10 +--- ioemu.orig/vl.c	2007-05-03 10:11:05.000000000 +0100
   33.11 ++++ ioemu/vl.c	2007-05-03 10:11:05.000000000 +0100
   33.12 +@@ -6129,10 +6129,11 @@
   33.13                   }
   33.14                   break;
   33.15               case QEMU_OPTION_nographic:
    34.1 --- a/tools/ioemu/patches/qemu-dm	Mon May 07 13:24:37 2007 -0600
    34.2 +++ b/tools/ioemu/patches/qemu-dm	Tue May 08 09:09:17 2007 -0600
    34.3 @@ -1,7 +1,7 @@
    34.4  Index: ioemu/Makefile.target
    34.5  ===================================================================
    34.6 ---- ioemu.orig/Makefile.target	2006-12-08 01:41:05.000000000 +0000
    34.7 -+++ ioemu/Makefile.target	2006-12-08 01:41:10.000000000 +0000
    34.8 +--- ioemu.orig/Makefile.target	2007-05-02 15:48:40.000000000 +0100
    34.9 ++++ ioemu/Makefile.target	2007-05-02 16:04:46.000000000 +0100
   34.10  @@ -303,7 +303,7 @@
   34.11   endif
   34.12   
   34.13 @@ -13,8 +13,8 @@ Index: ioemu/Makefile.target
   34.14   VL_OBJS+=tap-win32.o
   34.15  Index: ioemu/configure
   34.16  ===================================================================
   34.17 ---- ioemu.orig/configure	2006-12-08 01:40:58.000000000 +0000
   34.18 -+++ ioemu/configure	2006-12-08 01:41:10.000000000 +0000
   34.19 +--- ioemu.orig/configure	2007-05-02 15:48:40.000000000 +0100
   34.20 ++++ ioemu/configure	2007-05-02 16:04:46.000000000 +0100
   34.21  @@ -75,8 +75,8 @@
   34.22   bigendian="no"
   34.23   mingw32="no"
   34.24 @@ -37,8 +37,8 @@ Index: ioemu/configure
   34.25     target_user_only="yes"
   34.26  Index: ioemu/cpu-all.h
   34.27  ===================================================================
   34.28 ---- ioemu.orig/cpu-all.h	2006-12-08 01:40:58.000000000 +0000
   34.29 -+++ ioemu/cpu-all.h	2006-12-08 01:41:10.000000000 +0000
   34.30 +--- ioemu.orig/cpu-all.h	2007-05-02 15:48:36.000000000 +0100
   34.31 ++++ ioemu/cpu-all.h	2007-05-02 16:04:46.000000000 +0100
   34.32  @@ -690,7 +690,9 @@
   34.33   void page_set_flags(target_ulong start, target_ulong end, int flags);
   34.34   void page_unprotect_range(target_ulong data, target_ulong data_size);
   34.35 @@ -64,8 +64,8 @@ Index: ioemu/cpu-all.h
   34.36   void cpu_dump_state(CPUState *env, FILE *f, 
   34.37  Index: ioemu/disas.h
   34.38  ===================================================================
   34.39 ---- ioemu.orig/disas.h	2006-12-08 01:40:58.000000000 +0000
   34.40 -+++ ioemu/disas.h	2006-12-08 01:41:10.000000000 +0000
   34.41 +--- ioemu.orig/disas.h	2007-05-02 15:48:36.000000000 +0100
   34.42 ++++ ioemu/disas.h	2007-05-02 15:48:40.000000000 +0100
   34.43  @@ -1,6 +1,7 @@
   34.44   #ifndef _QEMU_DISAS_H
   34.45   #define _QEMU_DISAS_H
   34.46 @@ -83,8 +83,8 @@ Index: ioemu/disas.h
   34.47   #endif /* _QEMU_DISAS_H */
   34.48  Index: ioemu/exec-all.h
   34.49  ===================================================================
   34.50 ---- ioemu.orig/exec-all.h	2006-12-08 01:40:58.000000000 +0000
   34.51 -+++ ioemu/exec-all.h	2006-12-08 01:41:10.000000000 +0000
   34.52 +--- ioemu.orig/exec-all.h	2007-05-02 15:48:36.000000000 +0100
   34.53 ++++ ioemu/exec-all.h	2007-05-02 16:04:45.000000000 +0100
   34.54  @@ -509,7 +509,7 @@
   34.55   
   34.56   extern int tb_invalidated_flag;
   34.57 @@ -105,8 +105,8 @@ Index: ioemu/exec-all.h
   34.58       return addr;
   34.59  Index: ioemu/hw/pc.c
   34.60  ===================================================================
   34.61 ---- ioemu.orig/hw/pc.c	2006-12-08 01:40:58.000000000 +0000
   34.62 -+++ ioemu/hw/pc.c	2006-12-08 01:41:10.000000000 +0000
   34.63 +--- ioemu.orig/hw/pc.c	2007-05-02 15:48:36.000000000 +0100
   34.64 ++++ ioemu/hw/pc.c	2007-05-02 16:04:46.000000000 +0100
   34.65  @@ -73,6 +73,7 @@
   34.66       }
   34.67   }
   34.68 @@ -184,8 +184,8 @@ Index: ioemu/hw/pc.c
   34.69           if (serial_hds[i]) {
   34.70  Index: ioemu/hw/vga_int.h
   34.71  ===================================================================
   34.72 ---- ioemu.orig/hw/vga_int.h	2006-12-08 01:40:58.000000000 +0000
   34.73 -+++ ioemu/hw/vga_int.h	2006-12-08 01:41:10.000000000 +0000
   34.74 +--- ioemu.orig/hw/vga_int.h	2007-05-02 15:48:36.000000000 +0100
   34.75 ++++ ioemu/hw/vga_int.h	2007-05-02 16:04:45.000000000 +0100
   34.76  @@ -28,7 +28,7 @@
   34.77   #define ST01_DISP_ENABLE    0x01
   34.78   
   34.79 @@ -197,8 +197,8 @@ Index: ioemu/hw/vga_int.h
   34.80   #define VBE_DISPI_MAX_YRES              1200
   34.81  Index: ioemu/monitor.c
   34.82  ===================================================================
   34.83 ---- ioemu.orig/monitor.c	2006-12-08 01:40:58.000000000 +0000
   34.84 -+++ ioemu/monitor.c	2006-12-08 01:41:10.000000000 +0000
   34.85 +--- ioemu.orig/monitor.c	2007-05-02 15:48:36.000000000 +0100
   34.86 ++++ ioemu/monitor.c	2007-05-02 16:04:46.000000000 +0100
   34.87  @@ -68,6 +68,12 @@
   34.88   
   34.89   void term_flush(void)
   34.90 @@ -429,8 +429,8 @@ Index: ioemu/monitor.c
   34.91   {
   34.92  Index: ioemu/vl.c
   34.93  ===================================================================
   34.94 ---- ioemu.orig/vl.c	2006-12-08 01:40:58.000000000 +0000
   34.95 -+++ ioemu/vl.c	2006-12-08 01:41:10.000000000 +0000
   34.96 +--- ioemu.orig/vl.c	2007-05-02 15:48:36.000000000 +0100
   34.97 ++++ ioemu/vl.c	2007-05-02 16:05:40.000000000 +0100
   34.98  @@ -422,12 +422,15 @@
   34.99   void hw_error(const char *fmt, ...)
  34.100   {
  34.101 @@ -489,7 +489,31 @@ Index: ioemu/vl.c
  34.102   
  34.103   /***********************************************************/
  34.104   /* machine registration */
  34.105 -@@ -6054,6 +6078,7 @@
  34.106 +@@ -5664,15 +5688,19 @@
  34.107 + #endif
  34.108 +     cyls = heads = secs = 0;
  34.109 +     translation = BIOS_ATA_TRANSLATION_AUTO;
  34.110 +-    pstrcpy(monitor_device, sizeof(monitor_device), "vc");
  34.111 ++    pstrcpy(monitor_device, sizeof(monitor_device), "null");
  34.112 + 
  34.113 +-    pstrcpy(serial_devices[0], sizeof(serial_devices[0]), "vc");
  34.114 +-    for(i = 1; i < MAX_SERIAL_PORTS; i++)
  34.115 ++    for(i = 0; i < MAX_SERIAL_PORTS; i++)
  34.116 +         serial_devices[i][0] = '\0';
  34.117 +     serial_device_index = 0;
  34.118 +-    
  34.119 ++
  34.120 ++#ifndef CONFIG_DM
  34.121 +     pstrcpy(parallel_devices[0], sizeof(parallel_devices[0]), "vc");
  34.122 +     for(i = 1; i < MAX_PARALLEL_PORTS; i++)
  34.123 ++#else
  34.124 ++    /* Xen steals IRQ7 for PCI. Disable LPT1 by default. */
  34.125 ++    for(i = 0; i < MAX_PARALLEL_PORTS; i++)
  34.126 ++#endif
  34.127 +         parallel_devices[i][0] = '\0';
  34.128 +     parallel_device_index = 0;
  34.129 +     
  34.130 +@@ -6054,6 +6082,7 @@
  34.131       socket_init();
  34.132   #endif
  34.133   
  34.134 @@ -497,7 +521,7 @@ Index: ioemu/vl.c
  34.135       /* init network clients */
  34.136       if (nb_net_clients == 0) {
  34.137           /* if no clients, we use a default config */
  34.138 -@@ -6063,6 +6088,7 @@
  34.139 +@@ -6063,6 +6092,7 @@
  34.140                   "user");
  34.141           nb_net_clients = 2;
  34.142       }
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/tools/ioemu/patches/qemu-dma-null-pointer-check	Tue May 08 09:09:17 2007 -0600
    35.3 @@ -0,0 +1,13 @@
    35.4 +Index: ioemu/hw/dma.c
    35.5 +===================================================================
    35.6 +--- ioemu.orig/hw/dma.c	2007-05-02 10:30:05.000000000 +0100
    35.7 ++++ ioemu/hw/dma.c	2007-05-03 14:59:53.000000000 +0100
    35.8 +@@ -340,6 +340,8 @@
    35.9 + #endif
   35.10 + 
   35.11 +     r = dma_controllers[ncont].regs + ichan;
   35.12 ++    if (r->transfer_handler == NULL)
   35.13 ++	return;
   35.14 +     n = r->transfer_handler (r->opaque, ichan + (ncont << 2),
   35.15 +                              r->now[COUNT], (r->base[COUNT] + 1) << ncont);
   35.16 +     r->now[COUNT] = n;
    36.1 --- a/tools/ioemu/patches/qemu-logging	Mon May 07 13:24:37 2007 -0600
    36.2 +++ b/tools/ioemu/patches/qemu-logging	Tue May 08 09:09:17 2007 -0600
    36.3 @@ -1,7 +1,7 @@
    36.4  Index: ioemu/vl.c
    36.5  ===================================================================
    36.6 ---- ioemu.orig/vl.c	2006-10-24 14:36:58.000000000 +0100
    36.7 -+++ ioemu/vl.c	2006-10-24 14:37:03.000000000 +0100
    36.8 +--- ioemu.orig/vl.c	2007-05-02 16:05:51.000000000 +0100
    36.9 ++++ ioemu/vl.c	2007-05-02 16:05:51.000000000 +0100
   36.10  @@ -5234,7 +5234,7 @@
   36.11              "-S              freeze CPU at startup (use 'c' to start execution)\n"
   36.12              "-s              wait gdb connection to port %d\n"
   36.13 @@ -38,7 +38,7 @@ Index: ioemu/vl.c
   36.14       LIST_INIT (&vm_change_state_head);
   36.15   #ifndef _WIN32
   36.16       {
   36.17 -@@ -5715,6 +5717,11 @@
   36.18 +@@ -5719,6 +5721,11 @@
   36.19       nb_nics = 0;
   36.20       /* default mac address of the first network interface */
   36.21       
   36.22 @@ -50,7 +50,7 @@ Index: ioemu/vl.c
   36.23       optind = 1;
   36.24       for(;;) {
   36.25           if (optind >= argc)
   36.26 -@@ -5905,7 +5912,7 @@
   36.27 +@@ -5909,7 +5916,7 @@
   36.28                       exit(1);
   36.29                   }
   36.30                   break;
    37.1 --- a/tools/ioemu/patches/qemu-pci	Mon May 07 13:24:37 2007 -0600
    37.2 +++ b/tools/ioemu/patches/qemu-pci	Tue May 08 09:09:17 2007 -0600
    37.3 @@ -1,8 +1,8 @@
    37.4  Index: ioemu/hw/pci.c
    37.5  ===================================================================
    37.6 ---- ioemu.orig/hw/pci.c	2006-12-08 02:02:05.000000000 +0000
    37.7 -+++ ioemu/hw/pci.c	2006-12-08 18:16:55.000000000 +0000
    37.8 -@@ -286,6 +286,7 @@
    37.9 +--- ioemu.orig/hw/pci.c	2007-05-03 15:20:35.000000000 +0100
   37.10 ++++ ioemu/hw/pci.c	2007-05-03 15:20:43.000000000 +0100
   37.11 +@@ -289,6 +289,7 @@
   37.12               case 0x0b:
   37.13               case 0x0e:
   37.14               case 0x10 ... 0x27: /* base */
   37.15 @@ -10,7 +10,7 @@ Index: ioemu/hw/pci.c
   37.16               case 0x30 ... 0x33: /* rom */
   37.17               case 0x3d:
   37.18                   can_write = 0;
   37.19 -@@ -318,6 +319,18 @@
   37.20 +@@ -321,6 +322,18 @@
   37.21               break;
   37.22           }
   37.23           if (can_write) {
   37.24 @@ -31,9 +31,9 @@ Index: ioemu/hw/pci.c
   37.25           addr++;
   37.26  Index: ioemu/hw/rtl8139.c
   37.27  ===================================================================
   37.28 ---- ioemu.orig/hw/rtl8139.c	2006-12-08 02:02:05.000000000 +0000
   37.29 -+++ ioemu/hw/rtl8139.c	2006-12-08 18:16:47.000000000 +0000
   37.30 -@@ -3423,6 +3423,8 @@
   37.31 +--- ioemu.orig/hw/rtl8139.c	2007-05-03 15:20:35.000000000 +0100
   37.32 ++++ ioemu/hw/rtl8139.c	2007-05-03 15:20:43.000000000 +0100
   37.33 +@@ -3424,6 +3424,8 @@
   37.34       pci_conf[0x0e] = 0x00; /* header_type */
   37.35       pci_conf[0x3d] = 1;    /* interrupt pin 0 */
   37.36       pci_conf[0x34] = 0xdc;
   37.37 @@ -44,9 +44,9 @@ Index: ioemu/hw/rtl8139.c
   37.38   
   37.39  Index: ioemu/hw/usb-uhci.c
   37.40  ===================================================================
   37.41 ---- ioemu.orig/hw/usb-uhci.c	2006-12-08 02:02:05.000000000 +0000
   37.42 -+++ ioemu/hw/usb-uhci.c	2006-12-08 02:02:38.000000000 +0000
   37.43 -@@ -659,6 +659,8 @@
   37.44 +--- ioemu.orig/hw/usb-uhci.c	2007-05-03 15:20:35.000000000 +0100
   37.45 ++++ ioemu/hw/usb-uhci.c	2007-05-03 15:20:43.000000000 +0100
   37.46 +@@ -704,6 +704,8 @@
   37.47       pci_conf[0x0e] = 0x00; // header_type
   37.48       pci_conf[0x3d] = 4; // interrupt pin 3
   37.49       pci_conf[0x60] = 0x10; // release number
   37.50 @@ -57,8 +57,8 @@ Index: ioemu/hw/usb-uhci.c
   37.51           qemu_register_usb_port(&s->ports[i].port, s, i, uhci_attach);
   37.52  Index: ioemu/vl.h
   37.53  ===================================================================
   37.54 ---- ioemu.orig/vl.h	2006-12-08 18:16:47.000000000 +0000
   37.55 -+++ ioemu/vl.h	2006-12-08 18:16:55.000000000 +0000
   37.56 +--- ioemu.orig/vl.h	2007-05-03 15:20:43.000000000 +0100
   37.57 ++++ ioemu/vl.h	2007-05-03 15:20:43.000000000 +0100
   37.58  @@ -650,8 +650,11 @@
   37.59   #define PCI_MAX_LAT		0x3f	/* 8 bits */
   37.60   
    38.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.2 +++ b/tools/ioemu/patches/qemu-pci-vendor-ids	Tue May 08 09:09:17 2007 -0600
    38.3 @@ -0,0 +1,47 @@
    38.4 +Index: ioemu/hw/cirrus_vga.c
    38.5 +===================================================================
    38.6 +--- ioemu.orig/hw/cirrus_vga.c	2007-05-03 15:06:41.000000000 +0100
    38.7 ++++ ioemu/hw/cirrus_vga.c	2007-05-03 15:07:16.000000000 +0100
    38.8 +@@ -3339,6 +3339,10 @@
    38.9 +     pci_conf[0x0a] = PCI_CLASS_SUB_VGA;
   38.10 +     pci_conf[0x0b] = PCI_CLASS_BASE_DISPLAY;
   38.11 +     pci_conf[0x0e] = PCI_CLASS_HEADERTYPE_00h;
   38.12 ++    pci_conf[0x2c] = 0x53; /* subsystem vendor: XenSource */
   38.13 ++    pci_conf[0x2d] = 0x58;
   38.14 ++    pci_conf[0x2e] = 0x01; /* subsystem device */
   38.15 ++    pci_conf[0x2f] = 0x00;
   38.16 + 
   38.17 +     /* setup VGA */
   38.18 +     s = &d->cirrus_vga;
   38.19 +Index: ioemu/hw/rtl8139.c
   38.20 +===================================================================
   38.21 +--- ioemu.orig/hw/rtl8139.c	2007-05-03 15:07:16.000000000 +0100
   38.22 ++++ ioemu/hw/rtl8139.c	2007-05-03 15:07:16.000000000 +0100
   38.23 +@@ -3424,8 +3424,10 @@
   38.24 +     pci_conf[0x0e] = 0x00; /* header_type */
   38.25 +     pci_conf[0x3d] = 1;    /* interrupt pin 0 */
   38.26 +     pci_conf[0x34] = 0xdc;
   38.27 +-    pci_conf[0x2c] = pci_conf[0x00]; // same as Vendor ID
   38.28 +-    pci_conf[0x2d] = pci_conf[0x01];
   38.29 ++    pci_conf[0x2c] = 0x53; /* subsystem vendor: XenSource */
   38.30 ++    pci_conf[0x2d] = 0x58;
   38.31 ++    pci_conf[0x2e] = 0x01; /* subsystem device */
   38.32 ++    pci_conf[0x2f] = 0x00;
   38.33 + 
   38.34 +     s = &d->rtl8139;
   38.35 + 
   38.36 +Index: ioemu/hw/ide.c
   38.37 +===================================================================
   38.38 +--- ioemu.orig/hw/ide.c	2007-05-03 15:07:16.000000000 +0100
   38.39 ++++ ioemu/hw/ide.c	2007-05-03 15:07:16.000000000 +0100
   38.40 +@@ -2763,6 +2763,10 @@
   38.41 +     pci_conf[0x0a] = 0x01; // class_sub = PCI_IDE
   38.42 +     pci_conf[0x0b] = 0x01; // class_base = PCI_mass_storage
   38.43 +     pci_conf[0x0e] = 0x00; // header_type
   38.44 ++    pci_conf[0x2c] = 0x53; /* subsystem vendor: XenSource */
   38.45 ++    pci_conf[0x2d] = 0x58;
   38.46 ++    pci_conf[0x2e] = 0x01; /* subsystem device */
   38.47 ++    pci_conf[0x2f] = 0x00;
   38.48 + 
   38.49 +     pci_register_io_region((PCIDevice *)d, 4, 0x10, 
   38.50 +                            PCI_ADDRESS_SPACE_IO, bmdma_map);
    39.1 --- a/tools/ioemu/patches/qemu-serial-fixes	Mon May 07 13:24:37 2007 -0600
    39.2 +++ b/tools/ioemu/patches/qemu-serial-fixes	Tue May 08 09:09:17 2007 -0600
    39.3 @@ -13,9 +13,9 @@ Signed-off-by: Keir Fraser <keir@xensour
    39.4  
    39.5  Index: ioemu/vl.c
    39.6  ===================================================================
    39.7 ---- ioemu.orig/vl.c	2006-12-08 01:28:59.000000000 +0000
    39.8 -+++ ioemu/vl.c	2006-12-08 01:28:59.000000000 +0000
    39.9 -@@ -1684,7 +1684,7 @@
   39.10 +--- ioemu.orig/vl.c	2007-05-03 10:09:02.000000000 +0100
   39.11 ++++ ioemu/vl.c	2007-05-03 10:09:02.000000000 +0100
   39.12 +@@ -1740,7 +1740,7 @@
   39.13   
   39.14       tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
   39.15                             |INLCR|IGNCR|ICRNL|IXON);
   39.16 @@ -26,8 +26,8 @@ Index: ioemu/vl.c
   39.17       switch(data_bits) {
   39.18  Index: ioemu/hw/serial.c
   39.19  ===================================================================
   39.20 ---- ioemu.orig/hw/serial.c	2006-12-08 01:28:17.000000000 +0000
   39.21 -+++ ioemu/hw/serial.c	2006-12-08 01:29:10.000000000 +0000
   39.22 +--- ioemu.orig/hw/serial.c	2007-05-03 10:09:02.000000000 +0100
   39.23 ++++ ioemu/hw/serial.c	2007-05-03 10:09:02.000000000 +0100
   39.24  @@ -73,6 +73,11 @@
   39.25   #define UART_LSR_OE	0x02	/* Overrun error indicator */
   39.26   #define UART_LSR_DR	0x01	/* Receiver data ready */
    40.1 --- a/tools/ioemu/patches/qemu-smp	Mon May 07 13:24:37 2007 -0600
    40.2 +++ b/tools/ioemu/patches/qemu-smp	Tue May 08 09:09:17 2007 -0600
    40.3 @@ -1,8 +1,8 @@
    40.4  Index: ioemu/vl.c
    40.5  ===================================================================
    40.6 ---- ioemu.orig/vl.c	2006-08-06 02:18:54.847125593 +0100
    40.7 -+++ ioemu/vl.c	2006-08-06 02:19:00.413505070 +0100
    40.8 -@@ -158,6 +158,8 @@
    40.9 +--- ioemu.orig/vl.c	2007-05-03 10:07:47.000000000 +0100
   40.10 ++++ ioemu/vl.c	2007-05-03 10:07:52.000000000 +0100
   40.11 +@@ -159,6 +159,8 @@
   40.12   int acpi_enabled = 1;
   40.13   int fd_bootchk = 1;
   40.14   
   40.15 @@ -11,7 +11,7 @@ Index: ioemu/vl.c
   40.16   int xc_handle;
   40.17   
   40.18   char domain_name[1024] = { 'H','V', 'M', 'X', 'E', 'N', '-'};
   40.19 -@@ -5172,6 +5174,7 @@
   40.20 +@@ -5173,6 +5175,7 @@
   40.21              "-m megs         set virtual RAM size to megs MB [default=%d]\n"
   40.22              "-smp n          set the number of CPUs to 'n' [default=1]\n"
   40.23              "-nographic      disable graphical output and redirect serial I/Os to console\n"
   40.24 @@ -19,7 +19,7 @@ Index: ioemu/vl.c
   40.25   #ifndef _WIN32
   40.26   	   "-k language     use keyboard layout (for example \"fr\" for French)\n"
   40.27   #endif
   40.28 -@@ -5342,6 +5345,7 @@
   40.29 +@@ -5343,6 +5346,7 @@
   40.30       QEMU_OPTION_no_acpi,
   40.31   
   40.32       QEMU_OPTION_d,
   40.33 @@ -27,7 +27,7 @@ Index: ioemu/vl.c
   40.34   };
   40.35   
   40.36   typedef struct QEMUOption {
   40.37 -@@ -5423,6 +5427,7 @@
   40.38 +@@ -5424,6 +5428,7 @@
   40.39       { "no-acpi", 0, QEMU_OPTION_no_acpi },
   40.40       
   40.41       { "d", HAS_ARG, QEMU_OPTION_d },
   40.42 @@ -35,7 +35,7 @@ Index: ioemu/vl.c
   40.43       { NULL },
   40.44   };
   40.45   
   40.46 -@@ -6087,6 +6092,10 @@
   40.47 +@@ -6092,6 +6097,10 @@
   40.48                   domid = atoi(optarg);
   40.49                   fprintf(logfile, "domid: %d\n", domid);
   40.50                   break;
    41.1 --- a/tools/ioemu/patches/qemu-target-i386-dm	Mon May 07 13:24:37 2007 -0600
    41.2 +++ b/tools/ioemu/patches/qemu-target-i386-dm	Tue May 08 09:09:17 2007 -0600
    41.3 @@ -1,7 +1,7 @@
    41.4  Index: ioemu/Makefile.target
    41.5  ===================================================================
    41.6 ---- ioemu.orig/Makefile.target	2006-12-08 01:41:10.000000000 +0000
    41.7 -+++ ioemu/Makefile.target	2006-12-08 01:41:11.000000000 +0000
    41.8 +--- ioemu.orig/Makefile.target	2007-05-03 14:53:03.000000000 +0100
    41.9 ++++ ioemu/Makefile.target	2007-05-03 14:53:58.000000000 +0100
   41.10  @@ -62,6 +62,8 @@
   41.11   QEMU_SYSTEM=qemu-fast
   41.12   endif
   41.13 @@ -32,8 +32,8 @@ Index: ioemu/Makefile.target
   41.14   DEFINES += -DHAS_AUDIO
   41.15  Index: ioemu/configure
   41.16  ===================================================================
   41.17 ---- ioemu.orig/configure	2006-12-08 01:41:10.000000000 +0000
   41.18 -+++ ioemu/configure	2006-12-08 01:41:11.000000000 +0000
   41.19 +--- ioemu.orig/configure	2007-05-03 14:53:03.000000000 +0100
   41.20 ++++ ioemu/configure	2007-05-03 14:53:57.000000000 +0100
   41.21  @@ -373,6 +373,8 @@
   41.22       if [ "$user" = "yes" ] ; then
   41.23           target_list="i386-user arm-user armeb-user sparc-user ppc-user mips-user mipsel-user $target_list"
   41.24 @@ -45,8 +45,8 @@ Index: ioemu/configure
   41.25   fi
   41.26  Index: ioemu/monitor.c
   41.27  ===================================================================
   41.28 ---- ioemu.orig/monitor.c	2006-12-08 01:41:10.000000000 +0000
   41.29 -+++ ioemu/monitor.c	2006-12-08 01:41:11.000000000 +0000
   41.30 +--- ioemu.orig/monitor.c	2007-05-03 14:53:03.000000000 +0100
   41.31 ++++ ioemu/monitor.c	2007-05-03 14:53:58.000000000 +0100
   41.32  @@ -1262,6 +1262,10 @@
   41.33         "", "show profiling information", },
   41.34       { "capture", "", do_info_capture,
   41.35 @@ -60,8 +60,8 @@ Index: ioemu/monitor.c
   41.36   
   41.37  Index: ioemu/vl.c
   41.38  ===================================================================
   41.39 ---- ioemu.orig/vl.c	2006-12-08 01:41:10.000000000 +0000
   41.40 -+++ ioemu/vl.c	2006-12-08 01:41:11.000000000 +0000
   41.41 +--- ioemu.orig/vl.c	2007-05-03 14:53:03.000000000 +0100
   41.42 ++++ ioemu/vl.c	2007-05-03 14:53:59.000000000 +0100
   41.43  @@ -87,7 +87,7 @@
   41.44   
   41.45   #include "exec-all.h"
   41.46 @@ -98,8 +98,8 @@ Index: ioemu/vl.c
   41.47   {
   41.48  Index: ioemu/vl.h
   41.49  ===================================================================
   41.50 ---- ioemu.orig/vl.h	2006-12-08 01:40:58.000000000 +0000
   41.51 -+++ ioemu/vl.h	2006-12-08 01:41:11.000000000 +0000
   41.52 +--- ioemu.orig/vl.h	2007-05-03 14:52:58.000000000 +0100
   41.53 ++++ ioemu/vl.h	2007-05-03 14:53:59.000000000 +0100
   41.54  @@ -37,6 +37,8 @@
   41.55   #include <unistd.h>
   41.56   #include <fcntl.h>
   41.57 @@ -132,7 +132,7 @@ Index: ioemu/vl.h
   41.58  Index: ioemu/target-i386-dm/cpu.h
   41.59  ===================================================================
   41.60  --- /dev/null	1970-01-01 00:00:00.000000000 +0000
   41.61 -+++ ioemu/target-i386-dm/cpu.h	2006-12-08 01:41:11.000000000 +0000
   41.62 ++++ ioemu/target-i386-dm/cpu.h	2007-05-03 14:53:58.000000000 +0100
   41.63  @@ -0,0 +1,84 @@
   41.64  +/*
   41.65  + * i386 virtual CPU header
   41.66 @@ -221,8 +221,8 @@ Index: ioemu/target-i386-dm/cpu.h
   41.67  Index: ioemu/target-i386-dm/exec-dm.c
   41.68  ===================================================================
   41.69  --- /dev/null	1970-01-01 00:00:00.000000000 +0000
   41.70 -+++ ioemu/target-i386-dm/exec-dm.c	2006-12-08 01:41:11.000000000 +0000
   41.71 -@@ -0,0 +1,546 @@
   41.72 ++++ ioemu/target-i386-dm/exec-dm.c	2007-05-03 14:53:56.000000000 +0100
   41.73 +@@ -0,0 +1,540 @@
   41.74  +/*
   41.75  + *  virtual page mapping and translated block handling
   41.76  + * 
   41.77 @@ -638,14 +638,8 @@ Index: ioemu/target-i386-dm/exec-dm.c
   41.78  +{
   41.79  +    /* Is this guest physical address RAM-backed? */
   41.80  +#if defined(CONFIG_DM) && (defined(__i386__) || defined(__x86_64__))
   41.81 -+    if (ram_size <= HVM_BELOW_4G_RAM_END)
   41.82 -+        /* RAM is contiguous */
   41.83 -+        return (addr < ram_size);
   41.84 -+    else
   41.85 -+        /* There is RAM below and above the MMIO hole */
   41.86 -+        return ((addr < HVM_BELOW_4G_MMIO_START) ||
   41.87 -+                ((addr >= HVM_BELOW_4G_MMIO_START + HVM_BELOW_4G_MMIO_LENGTH)
   41.88 -+                 && (addr < ram_size + HVM_BELOW_4G_MMIO_LENGTH)));
   41.89 ++    return ((addr < HVM_BELOW_4G_MMIO_START) ||
   41.90 ++            (addr >= HVM_BELOW_4G_MMIO_START + HVM_BELOW_4G_MMIO_LENGTH));
   41.91  +#else
   41.92  +    return (addr < ram_size);
   41.93  +#endif
   41.94 @@ -772,8 +766,8 @@ Index: ioemu/target-i386-dm/exec-dm.c
   41.95  Index: ioemu/target-i386-dm/helper2.c
   41.96  ===================================================================
   41.97  --- /dev/null	1970-01-01 00:00:00.000000000 +0000
   41.98 -+++ ioemu/target-i386-dm/helper2.c	2006-12-08 01:41:11.000000000 +0000
   41.99 -@@ -0,0 +1,488 @@
  41.100 ++++ ioemu/target-i386-dm/helper2.c	2007-05-03 14:54:46.000000000 +0100
  41.101 +@@ -0,0 +1,542 @@
  41.102  +/*
  41.103  + *  i386 helpers (without register variable usage)
  41.104  + *
  41.105 @@ -1162,6 +1156,21 @@ Index: ioemu/target-i386-dm/helper2.c
  41.106  +    req->data = tmp1;
  41.107  +}
  41.108  +
  41.109 ++void cpu_ioreq_sub(CPUState *env, ioreq_t *req)
  41.110 ++{
  41.111 ++    unsigned long tmp1, tmp2;
  41.112 ++
  41.113 ++    if (req->data_is_ptr != 0)
  41.114 ++        hw_error("expected scalar value");
  41.115 ++
  41.116 ++    read_physical(req->addr, req->size, &tmp1);
  41.117 ++    if (req->dir == IOREQ_WRITE) {
  41.118 ++        tmp2 = tmp1 - (unsigned long) req->data;
  41.119 ++        write_physical(req->addr, req->size, &tmp2);
  41.120 ++    }
  41.121 ++    req->data = tmp1;
  41.122 ++}
  41.123 ++
  41.124  +void cpu_ioreq_or(CPUState *env, ioreq_t *req)
  41.125  +{
  41.126  +    unsigned long tmp1, tmp2;
  41.127 @@ -1192,8 +1201,22 @@ Index: ioemu/target-i386-dm/helper2.c
  41.128  +    req->data = tmp1;
  41.129  +}
  41.130  +
  41.131 ++void cpu_ioreq_xchg(CPUState *env, ioreq_t *req)
  41.132 ++{
  41.133 ++    unsigned long tmp1;
  41.134 ++
  41.135 ++    if (req->data_is_ptr != 0)
  41.136 ++        hw_error("expected scalar value");
  41.137 ++
  41.138 ++    read_physical(req->addr, req->size, &tmp1);
  41.139 ++    write_physical(req->addr, req->size, &req->data);
  41.140 ++    req->data = tmp1;
  41.141 ++}
  41.142 ++
  41.143  +void cpu_handle_ioreq(void *opaque)
  41.144  +{
  41.145 ++    extern int vm_running;
  41.146 ++    extern int shutdown_requested;
  41.147  +    CPUState *env = opaque;
  41.148  +    ioreq_t *req = cpu_get_ioreq();
  41.149  +
  41.150 @@ -1216,12 +1239,18 @@ Index: ioemu/target-i386-dm/helper2.c
  41.151  +        case IOREQ_TYPE_ADD:
  41.152  +            cpu_ioreq_add(env, req);
  41.153  +            break;
  41.154 ++        case IOREQ_TYPE_SUB:
  41.155 ++            cpu_ioreq_sub(env, req);
  41.156 ++            break;
  41.157  +        case IOREQ_TYPE_OR:
  41.158  +            cpu_ioreq_or(env, req);
  41.159  +            break;
  41.160  +        case IOREQ_TYPE_XOR:
  41.161  +            cpu_ioreq_xor(env, req);
  41.162  +            break;
  41.163 ++        case IOREQ_TYPE_XCHG:
  41.164 ++            cpu_ioreq_xchg(env, req);
  41.165 ++            break;
  41.166  +        default:
  41.167  +            hw_error("Invalid ioreq type 0x%x\n", req->type);
  41.168  +        }
  41.169 @@ -1237,6 +1266,25 @@ Index: ioemu/target-i386-dm/helper2.c
  41.170  +        }
  41.171  +
  41.172  +        wmb(); /* Update ioreq contents /then/ update state. */
  41.173 ++
  41.174 ++	/*
  41.175 ++         * We do this before we send the response so that the tools
  41.176 ++         * have the opportunity to pick up on the reset before the
  41.177 ++         * guest resumes and does a hlt with interrupts disabled which
  41.178 ++         * causes Xen to powerdown the domain.
  41.179 ++         */
  41.180 ++        if (vm_running) {
  41.181 ++            if (shutdown_requested) {
  41.182 ++		fprintf(logfile, "shutdown requested in cpu_handle_ioreq\n");
  41.183 ++		destroy_hvm_domain();
  41.184 ++	    }
  41.185 ++	    if (reset_requested) {
  41.186 ++		fprintf(logfile, "reset requested in cpu_handle_ioreq.\n");
  41.187 ++		qemu_system_reset();
  41.188 ++		reset_requested = 0;
  41.189 ++	    }
  41.190 ++	}
  41.191 ++
  41.192  +        req->state = STATE_IORESP_READY;
  41.193  +        xc_evtchn_notify(xce_handle, ioreq_local_port[send_vcpu]);
  41.194  +    }
  41.195 @@ -1265,7 +1313,7 @@ Index: ioemu/target-i386-dm/helper2.c
  41.196  Index: ioemu/target-i386-dm/i8259-dm.c
  41.197  ===================================================================
  41.198  --- /dev/null	1970-01-01 00:00:00.000000000 +0000
  41.199 -+++ ioemu/target-i386-dm/i8259-dm.c	2006-12-08 01:41:11.000000000 +0000
  41.200 ++++ ioemu/target-i386-dm/i8259-dm.c	2007-05-03 14:53:57.000000000 +0100
  41.201  @@ -0,0 +1,67 @@
  41.202  +/* Xen 8259 stub for interrupt controller emulation
  41.203  + * 
  41.204 @@ -1337,7 +1385,7 @@ Index: ioemu/target-i386-dm/i8259-dm.c
  41.205  Index: ioemu/target-i386-dm/qemu-dm.debug
  41.206  ===================================================================
  41.207  --- /dev/null	1970-01-01 00:00:00.000000000 +0000
  41.208 -+++ ioemu/target-i386-dm/qemu-dm.debug	2006-12-08 01:41:11.000000000 +0000
  41.209 ++++ ioemu/target-i386-dm/qemu-dm.debug	2007-05-03 14:53:03.000000000 +0100
  41.210  @@ -0,0 +1,10 @@
  41.211  +#!/bin/sh
  41.212  +
  41.213 @@ -1352,15 +1400,14 @@ Index: ioemu/target-i386-dm/qemu-dm.debu
  41.214  Index: ioemu/target-i386-dm/qemu-ifup
  41.215  ===================================================================
  41.216  --- /dev/null	1970-01-01 00:00:00.000000000 +0000
  41.217 -+++ ioemu/target-i386-dm/qemu-ifup	2006-12-08 01:41:11.000000000 +0000
  41.218 -@@ -0,0 +1,10 @@
  41.219 ++++ ioemu/target-i386-dm/qemu-ifup	2007-05-03 14:53:03.000000000 +0100
  41.220 +@@ -0,0 +1,9 @@
  41.221  +#!/bin/sh
  41.222  +
  41.223  +#. /etc/rc.d/init.d/functions
  41.224  +#ulimit -c unlimited
  41.225  +
  41.226 -+echo -c 'config qemu network with xen bridge for '
  41.227 -+echo $*
  41.228 ++echo 'config qemu network with xen bridge for ' $*
  41.229  +
  41.230  +ifconfig $1 0.0.0.0 up
  41.231  +brctl addif $2 $1
    42.1 --- a/tools/ioemu/patches/qemu-timer	Mon May 07 13:24:37 2007 -0600
    42.2 +++ b/tools/ioemu/patches/qemu-timer	Tue May 08 09:09:17 2007 -0600
    42.3 @@ -1,8 +1,8 @@
    42.4  Index: ioemu/vl.c
    42.5  ===================================================================
    42.6 ---- ioemu.orig/vl.c	2006-08-06 02:22:53.925474246 +0100
    42.7 -+++ ioemu/vl.c	2006-08-06 02:22:56.618174081 +0100
    42.8 -@@ -824,6 +824,16 @@
    42.9 +--- ioemu.orig/vl.c	2007-05-03 10:07:52.000000000 +0100
   42.10 ++++ ioemu/vl.c	2007-05-03 10:07:52.000000000 +0100
   42.11 +@@ -825,6 +825,16 @@
   42.12       }
   42.13   }
   42.14   
   42.15 @@ -19,7 +19,7 @@ Index: ioemu/vl.c
   42.16   static void timer_save(QEMUFile *f, void *opaque)
   42.17   {
   42.18       if (cpu_ticks_enabled) {
   42.19 -@@ -940,6 +950,8 @@
   42.20 +@@ -941,6 +951,8 @@
   42.21   
   42.22   #endif /* !defined(_WIN32) */
   42.23   
   42.24 @@ -28,7 +28,7 @@ Index: ioemu/vl.c
   42.25   static void init_timer_alarm(void)
   42.26   {
   42.27   #ifdef _WIN32
   42.28 -@@ -971,12 +983,15 @@
   42.29 +@@ -972,12 +984,15 @@
   42.30       pit_min_timer_count = ((uint64_t)10000 * PIT_FREQ) / 1000000;
   42.31   #else
   42.32       {
   42.33 @@ -44,7 +44,7 @@ Index: ioemu/vl.c
   42.34           /* timer signal */
   42.35           sigfillset(&act.sa_mask);
   42.36          act.sa_flags = 0;
   42.37 -@@ -1022,6 +1037,7 @@
   42.38 +@@ -1023,6 +1038,7 @@
   42.39               pit_min_timer_count = ((uint64_t)itv.it_interval.tv_usec * 
   42.40                                      PIT_FREQ) / 1000000;
   42.41           }
    43.1 --- a/tools/ioemu/patches/qemu-tunable-ide-write-cache	Mon May 07 13:24:37 2007 -0600
    43.2 +++ b/tools/ioemu/patches/qemu-tunable-ide-write-cache	Tue May 08 09:09:17 2007 -0600
    43.3 @@ -1,7 +1,7 @@
    43.4  Index: ioemu/hw/ide.c
    43.5  ===================================================================
    43.6 ---- ioemu.orig/hw/ide.c	2006-08-20 22:22:36.000000000 +0100
    43.7 -+++ ioemu/hw/ide.c	2006-08-20 23:56:13.000000000 +0100
    43.8 +--- ioemu.orig/hw/ide.c	2007-05-03 15:07:15.000000000 +0100
    43.9 ++++ ioemu/hw/ide.c	2007-05-03 15:07:16.000000000 +0100
   43.10  @@ -305,6 +305,7 @@
   43.11       PCIDevice *pci_dev;
   43.12       struct BMDMAState *bmdma;
   43.13 @@ -10,7 +10,7 @@ Index: ioemu/hw/ide.c
   43.14       /* ide regs */
   43.15       uint8_t feature;
   43.16       uint8_t error;
   43.17 -@@ -789,6 +790,9 @@
   43.18 +@@ -947,6 +948,9 @@
   43.19       }
   43.20       ide_set_sector(s, sector_num + n);
   43.21       
   43.22 @@ -20,7 +20,7 @@ Index: ioemu/hw/ide.c
   43.23   #ifdef TARGET_I386
   43.24       if (win2k_install_hack && ((++s->irq_count % 16) == 0)) {
   43.25           /* It seems there is a bug in the Windows 2000 installer HDD
   43.26 -@@ -863,6 +867,10 @@
   43.27 +@@ -1021,6 +1025,10 @@
   43.28           transfer_size -= len;
   43.29           phys_addr += len;
   43.30       }
   43.31 @@ -31,7 +31,7 @@ Index: ioemu/hw/ide.c
   43.32       return transfer_size1 - transfer_size;
   43.33   }
   43.34   
   43.35 -@@ -1672,7 +1680,15 @@
   43.36 +@@ -1831,7 +1839,15 @@
   43.37               /* XXX: valid for CDROM ? */
   43.38               switch(s->feature) {
   43.39               case 0x02: /* write cache enable */
   43.40 @@ -47,7 +47,7 @@ Index: ioemu/hw/ide.c
   43.41               case 0xaa: /* read look-ahead enable */
   43.42               case 0x55: /* read look-ahead disable */
   43.43                   s->status = READY_STAT | SEEK_STAT;
   43.44 -@@ -2090,6 +2106,7 @@
   43.45 +@@ -2254,6 +2270,7 @@
   43.46           s->irq = irq;
   43.47           s->sector_write_timer = qemu_new_timer(vm_clock, 
   43.48                                                  ide_sector_write_timer_cb, s);
    44.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.2 +++ b/tools/ioemu/patches/scsi	Tue May 08 09:09:17 2007 -0600
    44.3 @@ -0,0 +1,194 @@
    44.4 +Index: ioemu/vl.c
    44.5 +===================================================================
    44.6 +--- ioemu.orig/vl.c	2007-05-03 15:20:45.000000000 +0100
    44.7 ++++ ioemu/vl.c	2007-05-03 15:20:45.000000000 +0100
    44.8 +@@ -116,7 +116,7 @@
    44.9 + void *ioport_opaque[MAX_IOPORTS];
   44.10 + IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS];
   44.11 + IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS];
   44.12 +-BlockDriverState *bs_table[MAX_DISKS], *fd_table[MAX_FD];
   44.13 ++BlockDriverState *bs_table[MAX_DISKS + MAX_SCSI_DISKS], *fd_table[MAX_FD];
   44.14 + int vga_ram_size;
   44.15 + int bios_size;
   44.16 + static DisplayState display_state;
   44.17 +@@ -1396,7 +1396,7 @@
   44.18 +         case 's': 
   44.19 +             {
   44.20 +                 int i;
   44.21 +-                for (i = 0; i < MAX_DISKS; i++) {
   44.22 ++                for (i = 0; i < MAX_DISKS + MAX_SCSI_DISKS; i++) {
   44.23 +                     if (bs_table[i])
   44.24 +                         bdrv_commit(bs_table[i]);
   44.25 +                 }
   44.26 +@@ -6057,7 +6057,7 @@
   44.27 +     int snapshot, linux_boot;
   44.28 +     const char *initrd_filename;
   44.29 + #ifndef CONFIG_DM
   44.30 +-    const char *hd_filename[MAX_DISKS];
   44.31 ++    const char *hd_filename[MAX_DISKS + MAX_SCSI_DISKS];
   44.32 + #endif /* !CONFIG_DM */
   44.33 +     const char *fd_filename[MAX_FD];
   44.34 +     const char *kernel_filename, *kernel_cmdline;
   44.35 +@@ -6126,7 +6126,7 @@
   44.36 +     for(i = 0; i < MAX_FD; i++)
   44.37 +         fd_filename[i] = NULL;
   44.38 + #ifndef CONFIG_DM
   44.39 +-    for(i = 0; i < MAX_DISKS; i++)
   44.40 ++    for(i = 0; i < MAX_DISKS + MAX_SCSI_DISKS; i++)
   44.41 +         hd_filename[i] = NULL;
   44.42 + #endif /* !CONFIG_DM */
   44.43 +     ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
   44.44 +@@ -6724,7 +6724,7 @@
   44.45 +     }
   44.46 + 
   44.47 +     /* open the virtual block devices */
   44.48 +-    for(i = 0; i < MAX_DISKS; i++) {
   44.49 ++    for(i = 0; i < MAX_DISKS + MAX_SCSI_DISKS; i++) {
   44.50 +         if (hd_filename[i]) {
   44.51 +             if (!bs_table[i]) {
   44.52 +                 char buf[64];
   44.53 +Index: ioemu/vl.h
   44.54 +===================================================================
   44.55 +--- ioemu.orig/vl.h	2007-05-03 15:20:45.000000000 +0100
   44.56 ++++ ioemu/vl.h	2007-05-03 15:20:45.000000000 +0100
   44.57 +@@ -818,8 +818,9 @@
   44.58 + 
   44.59 + /* ide.c */
   44.60 + #define MAX_DISKS 4
   44.61 ++#define MAX_SCSI_DISKS 7
   44.62 + 
   44.63 +-extern BlockDriverState *bs_table[MAX_DISKS];
   44.64 ++extern BlockDriverState *bs_table[MAX_DISKS + MAX_SCSI_DISKS];
   44.65 + 
   44.66 + void isa_ide_init(int iobase, int iobase2, int irq,
   44.67 +                   BlockDriverState *hd0, BlockDriverState *hd1);
   44.68 +Index: ioemu/hw/pc.c
   44.69 +===================================================================
   44.70 +--- ioemu.orig/hw/pc.c	2007-05-03 15:20:44.000000000 +0100
   44.71 ++++ ioemu/hw/pc.c	2007-05-03 15:20:45.000000000 +0100
   44.72 +@@ -902,7 +902,6 @@
   44.73 +     if (pci_enabled && acpi_enabled) {
   44.74 +         piix4_pm_init(pci_bus, piix3_devfn + 3);
   44.75 +     }
   44.76 +-#endif /* !CONFIG_DM */
   44.77 + 
   44.78 + #if 0
   44.79 +     /* ??? Need to figure out some way for the user to
   44.80 +@@ -921,6 +920,18 @@
   44.81 +         lsi_scsi_attach(scsi, bdrv, -1);
   44.82 +     }
   44.83 + #endif
   44.84 ++#else
   44.85 ++    if (pci_enabled) {
   44.86 ++        void *scsi = NULL;
   44.87 ++        for (i = 0; i < MAX_SCSI_DISKS ; i++) {
   44.88 ++            if (!bs_table[i + MAX_DISKS])
   44.89 ++                continue;
   44.90 ++            if (!scsi)
   44.91 ++                scsi = lsi_scsi_init(pci_bus, -1);
   44.92 ++            lsi_scsi_attach(scsi, bs_table[i + MAX_DISKS], -1);
   44.93 ++        }
   44.94 ++    }
   44.95 ++#endif /* !CONFIG_DM */
   44.96 +     /* must be done after all PCI devices are instanciated */
   44.97 +     /* XXX: should be done in the Bochs BIOS */
   44.98 +     if (pci_enabled) {
   44.99 +Index: ioemu/xenstore.c
  44.100 +===================================================================
  44.101 +--- ioemu.orig/xenstore.c	2007-05-03 15:20:45.000000000 +0100
  44.102 ++++ ioemu/xenstore.c	2007-05-03 15:20:45.000000000 +0100
  44.103 +@@ -18,7 +18,7 @@
  44.104 + #include <fcntl.h>
  44.105 + 
  44.106 + static struct xs_handle *xsh = NULL;
  44.107 +-static char *media_filename[MAX_DISKS];
  44.108 ++static char *media_filename[MAX_DISKS + MAX_SCSI_DISKS];
  44.109 + static QEMUTimer *insert_timer = NULL;
  44.110 + 
  44.111 + #define UWAIT_MAX (30*1000000) /* thirty seconds */
  44.112 +@@ -44,7 +44,7 @@
  44.113 + {
  44.114 +     int i;
  44.115 + 
  44.116 +-    for (i = 0; i < MAX_DISKS; i++) {
  44.117 ++    for (i = 0; i < MAX_DISKS + MAX_SCSI_DISKS; i++) {
  44.118 +         if (media_filename[i] && bs_table[i]) {
  44.119 +             do_change(bs_table[i]->device_name, media_filename[i]);
  44.120 +             free(media_filename[i]);
  44.121 +@@ -83,10 +83,10 @@
  44.122 +     char *buf = NULL, *path;
  44.123 +     char *fpath = NULL, *bpath = NULL,
  44.124 +         *dev = NULL, *params = NULL, *type = NULL;
  44.125 +-    int i;
  44.126 ++    int i, is_scsi;
  44.127 +     unsigned int len, num, hd_index;
  44.128 + 
  44.129 +-    for(i = 0; i < MAX_DISKS; i++)
  44.130 ++    for(i = 0; i < MAX_DISKS + MAX_SCSI_DISKS; i++)
  44.131 +         media_filename[i] = NULL;
  44.132 + 
  44.133 +     xsh = xs_daemon_open();
  44.134 +@@ -123,10 +123,11 @@
  44.135 +         dev = xs_read(xsh, XBT_NULL, buf, &len);
  44.136 +         if (dev == NULL)
  44.137 +             continue;
  44.138 +-        if (strncmp(dev, "hd", 2) || strlen(dev) != 3)
  44.139 ++        is_scsi = !strncmp(dev, "sd", 2);
  44.140 ++        if ((strncmp(dev, "hd", 2) && !is_scsi) || strlen(dev) != 3 )
  44.141 +             continue;
  44.142 +         hd_index = dev[2] - 'a';
  44.143 +-        if (hd_index >= MAX_DISKS)
  44.144 ++        if (hd_index >= (is_scsi ? MAX_SCSI_DISKS : MAX_DISKS))
  44.145 +             continue;
  44.146 +         /* read the type of the device */
  44.147 +         if (pasprintf(&buf, "%s/device/vbd/%s/device-type", path, e[i]) == -1)
  44.148 +@@ -163,7 +164,7 @@
  44.149 +             }
  44.150 +         }
  44.151 + 
  44.152 +-        bs_table[hd_index] = bdrv_new(dev);
  44.153 ++        bs_table[hd_index + (is_scsi ? MAX_DISKS : 0)] = bdrv_new(dev);
  44.154 +         /* check if it is a cdrom */
  44.155 +         if (type && !strcmp(type, "cdrom")) {
  44.156 +             bdrv_set_type_hint(bs_table[hd_index], BDRV_TYPE_CDROM);
  44.157 +@@ -172,7 +173,8 @@
  44.158 +         }
  44.159 +         /* open device now if media present */
  44.160 +         if (params[0]) {
  44.161 +-            if (bdrv_open(bs_table[hd_index], params, 0 /* snapshot */) < 0)
  44.162 ++            if (bdrv_open(bs_table[hd_index + (is_scsi ? MAX_DISKS : 0)],
  44.163 ++                          params, 0 /* snapshot */) < 0)
  44.164 +                 fprintf(stderr, "qemu: could not open hard disk image '%s'\n",
  44.165 +                         params);
  44.166 +         }
  44.167 +Index: ioemu/monitor.c
  44.168 +===================================================================
  44.169 +--- ioemu.orig/monitor.c	2007-05-03 15:18:43.000000000 +0100
  44.170 ++++ ioemu/monitor.c	2007-05-03 15:20:45.000000000 +0100
  44.171 +@@ -180,7 +180,7 @@
  44.172 + {
  44.173 +     int i;
  44.174 + 
  44.175 +-    for (i = 0; i < MAX_DISKS; i++) {
  44.176 ++    for (i = 0; i < MAX_DISKS + MAX_SCSI_DISKS; i++) {
  44.177 +         if (bs_table[i]) {
  44.178 +             bdrv_commit(bs_table[i]);
  44.179 +         }
  44.180 +Index: ioemu/hw/lsi53c895a.c
  44.181 +===================================================================
  44.182 +--- ioemu.orig/hw/lsi53c895a.c	2007-05-03 15:18:43.000000000 +0100
  44.183 ++++ ioemu/hw/lsi53c895a.c	2007-05-03 15:20:45.000000000 +0100
  44.184 +@@ -1071,8 +1071,13 @@
  44.185 +         shift = (offset & 3) * 8;
  44.186 +         return (s->scratch[n] >> shift) & 0xff;
  44.187 +     }
  44.188 ++#ifndef CONFIG_DM
  44.189 +     BADF("readb 0x%x\n", offset);
  44.190 +     exit(1);
  44.191 ++#else
  44.192 ++    /* XEN: This path can be triggered (e.g. ASPI8DOS.SYS reads 0x8). */
  44.193 ++    return 0;
  44.194 ++#endif
  44.195 + #undef CASE_GET_REG32
  44.196 + }
  44.197 + 
    45.1 --- a/tools/ioemu/patches/serial-non-block	Mon May 07 13:24:37 2007 -0600
    45.2 +++ b/tools/ioemu/patches/serial-non-block	Tue May 08 09:09:17 2007 -0600
    45.3 @@ -1,8 +1,8 @@
    45.4  Index: ioemu/vl.c
    45.5  ===================================================================
    45.6 ---- ioemu.orig/vl.c	2006-08-17 19:49:52.162002356 +0100
    45.7 -+++ ioemu/vl.c	2006-08-17 19:49:56.273547905 +0100
    45.8 -@@ -1175,19 +1175,34 @@
    45.9 +--- ioemu.orig/vl.c	2007-05-03 10:07:53.000000000 +0100
   45.10 ++++ ioemu/vl.c	2007-05-03 10:07:53.000000000 +0100
   45.11 +@@ -1176,19 +1176,34 @@
   45.12   
   45.13   static int unix_write(int fd, const uint8_t *buf, int len1)
   45.14   {
    46.1 --- a/tools/ioemu/patches/series	Mon May 07 13:24:37 2007 -0600
    46.2 +++ b/tools/ioemu/patches/series	Tue May 08 09:09:17 2007 -0600
    46.3 @@ -24,11 +24,18 @@ hypervisor-pit
    46.4  shared-vram
    46.5  shadow-vram
    46.6  serial-non-block
    46.7 +ioemu-save-restore
    46.8 +ioemu-save-restore-ide
    46.9 +ioemu-save-restore-usb
   46.10 +ioemu-save-restore-timer
   46.11 +ioemu-save-restore-rtl8139
   46.12 +ioemu-save-restore-pcnet
   46.13 +ioemu-save-restore-ne2000
   46.14  ide-hd-multithread
   46.15 -domain-timeoffset
   46.16  acpi-support
   46.17  acpi-timer-support
   46.18  acpi-poweroff-support
   46.19 +ioemu-save-restore-acpi
   46.20  fix-vga-scanning-code-overflow
   46.21  vnc-cleanup
   46.22  vnc-fixes
   46.23 @@ -39,16 +46,20 @@ vnc-access-monitor-vt
   46.24  vnc-display-find-unused
   46.25  vnc-listen-specific-interface
   46.26  vnc-backoff-screen-scan
   46.27 +xenstore
   46.28  xenstore-block-device-config
   46.29  xenstore-write-vnc-port
   46.30 +domain-timeoffset
   46.31  qemu-allow-disable-sdl
   46.32  qemu-fix-memset-args
   46.33  xen-support-buffered-ioreqs
   46.34 +ioemu-buffer-pio-ia64
   46.35  qemu-daemonize
   46.36  xen-platform-device
   46.37  qemu-bootorder
   46.38  qemu-tunable-ide-write-cache
   46.39  qemu-pci 
   46.40 +qemu-pci-vendor-ids
   46.41  serial-port-rate-limit
   46.42  hypervisor-rtc
   46.43  ide-cd-dma
   46.44 @@ -67,5 +78,13 @@ usb-uhci-buffer-size
   46.45  vnc-monitor-shift-key-processing
   46.46  ide-error-reporting
   46.47  vnc-numpad-handling
   46.48 +vnc-altgr-keysym
   46.49  xen-mapcache
   46.50 -usb-mouse-tablet-status-check -p3
   46.51 +ioemu-save-restore-logdirty
   46.52 +usb-mouse-tablet-status-check
   46.53 +vnc-fix-signedness
   46.54 +vnc-fix-version-check
   46.55 +scsi
   46.56 +qemu-cirrus-bounds-checks
   46.57 +qemu-block-device-bounds-checks
   46.58 +qemu-dma-null-pointer-check
    47.1 --- a/tools/ioemu/patches/shadow-vram	Mon May 07 13:24:37 2007 -0600
    47.2 +++ b/tools/ioemu/patches/shadow-vram	Tue May 08 09:09:17 2007 -0600
    47.3 @@ -1,7 +1,7 @@
    47.4  Index: ioemu/hw/vga.c
    47.5  ===================================================================
    47.6 ---- ioemu.orig/hw/vga.c	2006-08-17 19:49:52.159002688 +0100
    47.7 -+++ ioemu/hw/vga.c	2006-08-17 19:49:54.575735565 +0100
    47.8 +--- ioemu.orig/hw/vga.c	2007-05-02 10:32:35.000000000 +0100
    47.9 ++++ ioemu/hw/vga.c	2007-05-02 10:35:05.000000000 +0100
   47.10  @@ -1359,6 +1359,105 @@
   47.11       }
   47.12   }
   47.13 @@ -120,10 +120,11 @@ Index: ioemu/hw/vga.c
   47.14       addr1 = (s->start_addr * 4);
   47.15       bwidth = width * 4;
   47.16       y_start = -1;
   47.17 -@@ -1889,6 +1993,14 @@
   47.18 +@@ -1889,7 +1993,18 @@
   47.19   
   47.20       vga_reset(s);
   47.21   
   47.22 +-    s->vram_ptr = qemu_malloc(vga_ram_size);
   47.23  +    check_sse2();
   47.24  +    s->vram_shadow = qemu_malloc(vga_ram_size+TARGET_PAGE_SIZE+1);
   47.25  +    if (s->vram_shadow == NULL)
   47.26 @@ -132,16 +133,43 @@ Index: ioemu/hw/vga.c
   47.27  +    s->vram_shadow = (uint8_t *)((long)(s->vram_shadow + TARGET_PAGE_SIZE - 1)
   47.28  +                                 & ~(TARGET_PAGE_SIZE - 1));
   47.29  +
   47.30 -     s->vram_ptr = qemu_malloc(vga_ram_size);
   47.31 ++    /* Video RAM must be 128-bit aligned for SSE optimizations later */
   47.32 ++    s->vram_alloc = qemu_malloc(vga_ram_size + 15);
   47.33 ++    s->vram_ptr = (uint8_t *)((long)(s->vram_alloc + 15) & ~15L);
   47.34 ++
   47.35       s->vram_offset = vga_ram_offset;
   47.36       s->vram_size = vga_ram_size;
   47.37 +     s->ds = ds;
   47.38 +@@ -2013,7 +2128,7 @@
   47.39 +     }
   47.40 + 
   47.41 +     if (!vga_ram_base) {
   47.42 +-        vga_ram_base = qemu_malloc(vga_ram_size);
   47.43 ++        vga_ram_base = qemu_malloc(vga_ram_size + TARGET_PAGE_SIZE + 1);
   47.44 +         if (!vga_ram_base) {
   47.45 +             fprintf(stderr, "reallocate error\n");
   47.46 +             return NULL;
   47.47 +@@ -2021,8 +2136,10 @@
   47.48 +     }
   47.49 + 
   47.50 +     /* XXX lock needed? */
   47.51 ++    old_pointer = s->vram_alloc;
   47.52 ++    s->vram_alloc = vga_ram_base;
   47.53 ++    vga_ram_base = (uint8_t *)((long)(vga_ram_base + 15) & ~15L);
   47.54 +     memcpy(vga_ram_base, s->vram_ptr, vga_ram_size);
   47.55 +-    old_pointer = s->vram_ptr;
   47.56 +     s->vram_ptr = vga_ram_base;
   47.57 + 
   47.58 +     return old_pointer;
   47.59  Index: ioemu/hw/vga_int.h
   47.60  ===================================================================
   47.61 ---- ioemu.orig/hw/vga_int.h	2006-08-17 19:49:52.159002688 +0100
   47.62 -+++ ioemu/hw/vga_int.h	2006-08-17 19:49:54.575735565 +0100
   47.63 -@@ -79,6 +79,7 @@
   47.64 +--- ioemu.orig/hw/vga_int.h	2007-05-02 10:32:35.000000000 +0100
   47.65 ++++ ioemu/hw/vga_int.h	2007-05-02 10:35:10.000000000 +0100
   47.66 +@@ -78,7 +78,9 @@
   47.67 + #define VGA_MAX_HEIGHT 2048
   47.68   
   47.69   #define VGA_STATE_COMMON                                                \
   47.70 ++    uint8_t *vram_alloc;                                                \
   47.71       uint8_t *vram_ptr;                                                  \
   47.72  +    uint8_t *vram_shadow;                                               \
   47.73       unsigned long vram_offset;                                          \
    48.1 --- a/tools/ioemu/patches/shared-vram	Mon May 07 13:24:37 2007 -0600
    48.2 +++ b/tools/ioemu/patches/shared-vram	Tue May 08 09:09:17 2007 -0600
    48.3 @@ -1,7 +1,7 @@
    48.4  Index: ioemu/hw/cirrus_vga.c
    48.5  ===================================================================
    48.6 ---- ioemu.orig/hw/cirrus_vga.c	2006-12-08 01:57:54.000000000 +0000
    48.7 -+++ ioemu/hw/cirrus_vga.c	2006-12-08 02:00:04.000000000 +0000
    48.8 +--- ioemu.orig/hw/cirrus_vga.c	2007-05-03 09:56:32.000000000 +0100
    48.9 ++++ ioemu/hw/cirrus_vga.c	2007-05-03 10:07:53.000000000 +0100
   48.10  @@ -28,6 +28,9 @@
   48.11    */
   48.12   #include "vl.h"
   48.13 @@ -39,7 +39,7 @@ Index: ioemu/hw/cirrus_vga.c
   48.14   /***************************************
   48.15    *
   48.16    *  prototypes.
   48.17 -@@ -2520,6 +2529,80 @@
   48.18 +@@ -2520,6 +2529,83 @@
   48.19       cirrus_linear_bitblt_writel,
   48.20   };
   48.21   
   48.22 @@ -85,7 +85,8 @@ Index: ioemu/hw/cirrus_vga.c
   48.23  +    return vram_pointer;
   48.24  +}
   48.25  +
   48.26 -+static int unset_vram_mapping(unsigned long begin, unsigned long end)
   48.27 ++static int unset_vram_mapping(unsigned long begin, unsigned long end, 
   48.28 ++                              void *mapping)
   48.29  +{
   48.30  +    xen_pfn_t *extent_start = NULL;
   48.31  +    unsigned long nr_extents;
   48.32 @@ -105,11 +106,13 @@ Index: ioemu/hw/cirrus_vga.c
   48.33  +        return -1;
   48.34  +    }
   48.35  +
   48.36 ++    /* Drop our own references to the vram pages */
   48.37 ++    munmap(mapping, nr_extents * TARGET_PAGE_SIZE);
   48.38 ++
   48.39 ++    /* Now drop the guest's mappings */
   48.40  +    memset(extent_start, 0, sizeof(xen_pfn_t) * nr_extents);
   48.41 -+
   48.42  +    for (i = 0; i < nr_extents; i++)
   48.43  +        extent_start[i] = (begin + (i * TARGET_PAGE_SIZE)) >> TARGET_PAGE_BITS;
   48.44 -+
   48.45  +    unset_mm_mapping(xc_handle, domid, nr_extents, 0, extent_start);
   48.46  +
   48.47  +    free(extent_start);
   48.48 @@ -120,7 +123,7 @@ Index: ioemu/hw/cirrus_vga.c
   48.49   /* Compute the memory access functions */
   48.50   static void cirrus_update_memory_access(CirrusVGAState *s)
   48.51   {
   48.52 -@@ -2538,11 +2621,39 @@
   48.53 +@@ -2538,11 +2624,37 @@
   48.54           
   48.55   	mode = s->gr[0x05] & 0x7;
   48.56   	if (mode < 4 || mode > 5 || ((s->gr[0x0B] & 0x4) == 0)) {
   48.57 @@ -145,22 +148,20 @@ Index: ioemu/hw/cirrus_vga.c
   48.58           } else {
   48.59           generic_io:
   48.60  +            if (s->cirrus_lfb_addr && s->cirrus_lfb_end && s->map_addr) {
   48.61 -+		int error;
   48.62 -+                void *old_vram = NULL;
   48.63 ++                void *old_vram;
   48.64 ++
   48.65 ++                old_vram = vga_update_vram((VGAState *)s, NULL, VGA_RAM_SIZE);
   48.66  +
   48.67 -+		error = unset_vram_mapping(s->cirrus_lfb_addr,
   48.68 -+					   s->cirrus_lfb_end);
   48.69 -+		if (!error)
   48.70 -+		    old_vram = vga_update_vram((VGAState *)s, NULL,
   48.71 -+                                               VGA_RAM_SIZE);
   48.72 -+                if (old_vram)
   48.73 -+                    munmap(old_vram, s->map_addr - s->map_end);
   48.74 ++                unset_vram_mapping(s->cirrus_lfb_addr,
   48.75 ++                                   s->cirrus_lfb_end, 
   48.76 ++                                   old_vram);
   48.77 ++
   48.78  +                s->map_addr = s->map_end = 0;
   48.79  +            }
   48.80               s->cirrus_linear_write[0] = cirrus_linear_writeb;
   48.81               s->cirrus_linear_write[1] = cirrus_linear_writew;
   48.82               s->cirrus_linear_write[2] = cirrus_linear_writel;
   48.83 -@@ -3136,6 +3247,13 @@
   48.84 +@@ -3136,6 +3248,13 @@
   48.85       /* XXX: add byte swapping apertures */
   48.86       cpu_register_physical_memory(addr, s->vram_size,
   48.87   				 s->cirrus_linear_io_addr);
   48.88 @@ -176,8 +177,8 @@ Index: ioemu/hw/cirrus_vga.c
   48.89   }
   48.90  Index: ioemu/hw/pc.c
   48.91  ===================================================================
   48.92 ---- ioemu.orig/hw/pc.c	2006-12-08 02:00:04.000000000 +0000
   48.93 -+++ ioemu/hw/pc.c	2006-12-08 02:00:04.000000000 +0000
   48.94 +--- ioemu.orig/hw/pc.c	2007-05-03 10:07:53.000000000 +0100
   48.95 ++++ ioemu/hw/pc.c	2007-05-03 10:07:53.000000000 +0100
   48.96  @@ -790,14 +790,14 @@
   48.97       if (cirrus_vga_enabled) {
   48.98           if (pci_enabled) {
   48.99 @@ -198,8 +199,8 @@ Index: ioemu/hw/pc.c
  48.100   
  48.101  Index: ioemu/hw/vga.c
  48.102  ===================================================================
  48.103 ---- ioemu.orig/hw/vga.c	2006-12-08 02:00:04.000000000 +0000
  48.104 -+++ ioemu/hw/vga.c	2006-12-08 02:00:04.000000000 +0000
  48.105 +--- ioemu.orig/hw/vga.c	2007-05-03 10:07:52.000000000 +0100
  48.106 ++++ ioemu/hw/vga.c	2007-05-03 10:07:53.000000000 +0100
  48.107  @@ -1858,6 +1858,7 @@
  48.108       /* TODO: add vbe support if enabled */
  48.109   }
  48.110 @@ -251,8 +252,8 @@ Index: ioemu/hw/vga.c
  48.111   
  48.112  Index: ioemu/hw/vga_int.h
  48.113  ===================================================================
  48.114 ---- ioemu.orig/hw/vga_int.h	2006-12-08 01:57:54.000000000 +0000
  48.115 -+++ ioemu/hw/vga_int.h	2006-12-08 02:00:04.000000000 +0000
  48.116 +--- ioemu.orig/hw/vga_int.h	2007-05-03 09:56:32.000000000 +0100
  48.117 ++++ ioemu/hw/vga_int.h	2007-05-03 10:07:53.000000000 +0100
  48.118  @@ -169,5 +169,6 @@
  48.119                                unsigned int color0, unsigned int color1,
  48.120                                unsigned int color_xor);
  48.121 @@ -262,9 +263,9 @@ Index: ioemu/hw/vga_int.h
  48.122   extern const uint8_t gr_mask[16];
  48.123  Index: ioemu/vl.c
  48.124  ===================================================================
  48.125 ---- ioemu.orig/vl.c	2006-12-08 02:00:04.000000000 +0000
  48.126 -+++ ioemu/vl.c	2006-12-08 02:00:27.000000000 +0000
  48.127 -@@ -5693,6 +5693,62 @@
  48.128 +--- ioemu.orig/vl.c	2007-05-03 10:07:53.000000000 +0100
  48.129 ++++ ioemu/vl.c	2007-05-03 10:07:53.000000000 +0100
  48.130 +@@ -5745,6 +5745,62 @@
  48.131   
  48.132   #define MAX_NET_CLIENTS 32
  48.133   
  48.134 @@ -278,17 +279,17 @@ Index: ioemu/vl.c
  48.135  +    int err = 0;
  48.136  +    xc_dominfo_t info;
  48.137  +
  48.138 ++    xc_domain_getinfo(xc_handle, domid, 1, &info);
  48.139 ++    if ((info.nr_pages - nr_pages) <= 0) {
  48.140 ++        fprintf(stderr, "unset_mm_mapping: error nr_pages\n");
  48.141 ++        err = -1;
  48.142 ++    }
  48.143 ++
  48.144  +    err = xc_domain_memory_decrease_reservation(xc_handle, domid,
  48.145  +                                                nr_pages, 0, extent_start);
  48.146  +    if (err)
  48.147  +        fprintf(stderr, "Failed to decrease physmap\n");
  48.148  +
  48.149 -+    xc_domain_getinfo(xc_handle, domid, 1, &info);
  48.150 -+
  48.151 -+    if ((info.nr_pages - nr_pages) <= 0) {
  48.152 -+        fprintf(stderr, "unset_mm_mapping: error nr_pages\n");
  48.153 -+        err = -1;
  48.154 -+    }
  48.155  +
  48.156  +    if (xc_domain_setmaxmem(xc_handle, domid, (info.nr_pages - nr_pages) *
  48.157  +                            PAGE_SIZE/1024) != 0) {
  48.158 @@ -329,8 +330,8 @@ Index: ioemu/vl.c
  48.159   #ifdef CONFIG_GDBSTUB
  48.160  Index: ioemu/vl.h
  48.161  ===================================================================
  48.162 ---- ioemu.orig/vl.h	2006-12-08 02:00:04.000000000 +0000
  48.163 -+++ ioemu/vl.h	2006-12-08 02:00:04.000000000 +0000
  48.164 +--- ioemu.orig/vl.h	2007-05-03 10:07:53.000000000 +0100
  48.165 ++++ ioemu/vl.h	2007-05-03 10:07:53.000000000 +0100
  48.166  @@ -145,6 +145,13 @@
  48.167   
  48.168   void main_loop_wait(int timeout);
    49.1 --- a/tools/ioemu/patches/support-xm-console	Mon May 07 13:24:37 2007 -0600
    49.2 +++ b/tools/ioemu/patches/support-xm-console	Tue May 08 09:09:17 2007 -0600
    49.3 @@ -1,17 +1,56 @@
    49.4  Index: ioemu/vl.c
    49.5  ===================================================================
    49.6 ---- ioemu.orig/vl.c	2006-08-17 19:49:40.119333436 +0100
    49.7 -+++ ioemu/vl.c	2006-08-17 19:49:48.566399780 +0100
    49.8 -@@ -1536,26 +1536,65 @@
    49.9 +--- ioemu.orig/vl.c	2007-05-03 10:24:03.000000000 +0100
   49.10 ++++ ioemu/vl.c	2007-05-03 10:24:04.000000000 +0100
   49.11 +@@ -1537,26 +1537,108 @@
   49.12       return chr;
   49.13   }
   49.14   
   49.15 -+int store_console_dev(int domid, char *pts)
   49.16 ++/*
   49.17 ++ * Create a store entry for a device (e.g., monitor, serial/parallel lines).
   49.18 ++ * The entry is <domain-path><storeString>/tty and the value is the name
   49.19 ++ * of the pty associated with the device.
   49.20 ++ */
   49.21 ++static int store_dev_info(char *devName, int domid,
   49.22 ++                          CharDriverState *cState, char *storeString)
   49.23  +{
   49.24  +    int xc_handle;
   49.25  +    struct xs_handle *xs;
   49.26  +    char *path;
   49.27 ++    char *newpath;
   49.28 ++    FDCharDriver *s;
   49.29 ++    char *pts;
   49.30  +
   49.31 ++    /* Check for valid arguments (at least, prevent segfaults). */
   49.32 ++    if ((devName == NULL) || (cState == NULL) || (storeString == NULL)) {
   49.33 ++        fprintf(logfile, "%s - invalid arguments\n", __FUNCTION__);
   49.34 ++        return EINVAL;
   49.35 ++    }
   49.36 ++
   49.37 ++    /*
   49.38 ++     * Only continue if we're talking to a pty
   49.39 ++     * Actually, the following code works for any CharDriverState using
   49.40 ++     * FDCharDriver, but we really only care about pty's here
   49.41 ++     */
   49.42 ++    if (strcmp(devName, "pty"))
   49.43 ++        return 0;
   49.44 ++
   49.45 ++    s = cState->opaque;
   49.46 ++    if (s == NULL) {
   49.47 ++        fprintf(logfile, "%s - unable to retrieve fd for '%s'/'%s'\n",
   49.48 ++                __FUNCTION__, storeString, devName);
   49.49 ++        return EBADF;
   49.50 ++    }
   49.51 ++
   49.52 ++    pts = ptsname(s->fd_in);
   49.53 ++    if (pts == NULL) {
   49.54 ++        fprintf(logfile, "%s - unable to determine ptsname '%s'/'%s', "
   49.55 ++                "error %d (%s)\n",
   49.56 ++                __FUNCTION__, storeString, devName, errno, strerror(errno));
   49.57 ++        return errno;
   49.58 ++    }
   49.59 ++
   49.60 ++    /* We now have everything we need to set the xenstore entry. */
   49.61  +    xs = xs_daemon_open();
   49.62  +    if (xs == NULL) {
   49.63  +        fprintf(logfile, "Could not contact XenStore\n");
   49.64 @@ -29,14 +68,19 @@ Index: ioemu/vl.c
   49.65  +        fprintf(logfile, "xs_get_domain_path() error\n");
   49.66  +        return -1;
   49.67  +    }
   49.68 -+    path = realloc(path, strlen(path) + strlen("/console/tty") + 1);
   49.69 -+    if (path == NULL) {
   49.70 ++    newpath = realloc(path, (strlen(path) + strlen(storeString) +
   49.71 ++                             strlen("/tty") + 1));
   49.72 ++    if (newpath == NULL) {
   49.73 ++        free(path); /* realloc errors leave old block */
   49.74  +        fprintf(logfile, "realloc error\n");
   49.75  +        return -1;
   49.76  +    }
   49.77 -+    strcat(path, "/console/tty");
   49.78 ++    path = newpath;
   49.79 ++
   49.80 ++    strcat(path, storeString);
   49.81 ++    strcat(path, "/tty");
   49.82  +    if (!xs_write(xs, XBT_NULL, path, pts, strlen(pts))) {
   49.83 -+        fprintf(logfile, "xs_write for console fail");
   49.84 ++        fprintf(logfile, "xs_write for '%s' fail", storeString);
   49.85  +        return -1;
   49.86  +    }
   49.87  +
   49.88 @@ -71,13 +115,12 @@ Index: ioemu/vl.c
   49.89  +    tcsetattr(slave_fd, TCSAFLUSH, &tty);
   49.90  +    
   49.91  +    fprintf(stderr, "char device redirected to %s\n", ptsname(master_fd));
   49.92 -+    store_console_dev(domid, ptsname(master_fd));
   49.93   
   49.94  -    fprintf(stderr, "char device redirected to %s\n", slave_name);
   49.95       return qemu_chr_open_fd(master_fd, master_fd);
   49.96   }
   49.97   
   49.98 -@@ -5868,7 +5907,9 @@
   49.99 +@@ -5881,7 +5963,9 @@
  49.100                   break;
  49.101               case QEMU_OPTION_nographic:
  49.102                   pstrcpy(monitor_device, sizeof(monitor_device), "stdio");
  49.103 @@ -88,3 +131,43 @@ Index: ioemu/vl.c
  49.104                   nographic = 1;
  49.105                   break;
  49.106               case QEMU_OPTION_kernel:
  49.107 +@@ -6348,16 +6432,23 @@
  49.108 +         fprintf(stderr, "qemu: could not open monitor device '%s'\n", monitor_device);
  49.109 +         exit(1);
  49.110 +     }
  49.111 ++    store_dev_info(monitor_device, domid, monitor_hd, "/monitor");
  49.112 +     monitor_init(monitor_hd, !nographic);
  49.113 + 
  49.114 +     for(i = 0; i < MAX_SERIAL_PORTS; i++) {
  49.115 +         if (serial_devices[i][0] != '\0') {
  49.116 ++            char buf[16];
  49.117 +             serial_hds[i] = qemu_chr_open(serial_devices[i]);
  49.118 +             if (!serial_hds[i]) {
  49.119 +                 fprintf(stderr, "qemu: could not open serial device '%s'\n", 
  49.120 +                         serial_devices[i]);
  49.121 +                 exit(1);
  49.122 +             }
  49.123 ++            snprintf(buf, sizeof(buf), "/serial/%d", i);
  49.124 ++            store_dev_info(serial_devices[i], domid, serial_hds[i], buf);
  49.125 ++            if (i == 0) /* serial 0 is also called the console */
  49.126 ++                store_dev_info(serial_devices[i], domid,
  49.127 ++                               serial_hds[i], "/console");
  49.128 +             if (!strcmp(serial_devices[i], "vc"))
  49.129 +                 qemu_chr_printf(serial_hds[i], "serial%d console\r\n", i);
  49.130 +         }
  49.131 +@@ -6365,12 +6456,15 @@
  49.132 + 
  49.133 +     for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
  49.134 +         if (parallel_devices[i][0] != '\0') {
  49.135 ++            char buf[16];
  49.136 +             parallel_hds[i] = qemu_chr_open(parallel_devices[i]);
  49.137 +             if (!parallel_hds[i]) {
  49.138 +                 fprintf(stderr, "qemu: could not open parallel device '%s'\n", 
  49.139 +                         parallel_devices[i]);
  49.140 +                 exit(1);
  49.141 +             }
  49.142 ++            snprintf(buf, sizeof(buf), "/parallel/%d", i);
  49.143 ++            store_dev_info(parallel_devices[i], domid, parallel_hds[i], buf);
  49.144 +             if (!strcmp(parallel_devices[i], "vc"))
  49.145 +                 qemu_chr_printf(parallel_hds[i], "parallel%d console\r\n", i);
  49.146 +         }
    50.1 --- a/tools/ioemu/patches/tpm-tis-device	Mon May 07 13:24:37 2007 -0600
    50.2 +++ b/tools/ioemu/patches/tpm-tis-device	Tue May 08 09:09:17 2007 -0600
    50.3 @@ -22,8 +22,8 @@ Signed-off-by: Stefan Berger <stefanb@us
    50.4  
    50.5  Index: ioemu/Makefile.target
    50.6  ===================================================================
    50.7 ---- ioemu.orig/Makefile.target	2006-12-20 15:21:55.000000000 +0000
    50.8 -+++ ioemu/Makefile.target	2006-12-20 15:21:55.000000000 +0000
    50.9 +--- ioemu.orig/Makefile.target	2007-05-03 15:20:44.000000000 +0100
   50.10 ++++ ioemu/Makefile.target	2007-05-03 15:20:44.000000000 +0100
   50.11  @@ -369,6 +369,7 @@
   50.12   VL_OBJS+= piix4acpi.o
   50.13   VL_OBJS+= xenstore.o
   50.14 @@ -34,8 +34,8 @@ Index: ioemu/Makefile.target
   50.15   ifeq ($(TARGET_BASE_ARCH), ppc)
   50.16  Index: ioemu/hw/pc.c
   50.17  ===================================================================
   50.18 ---- ioemu.orig/hw/pc.c	2006-12-20 15:21:54.000000000 +0000
   50.19 -+++ ioemu/hw/pc.c	2006-12-20 15:21:55.000000000 +0000
   50.20 +--- ioemu.orig/hw/pc.c	2007-05-03 15:20:43.000000000 +0100
   50.21 ++++ ioemu/hw/pc.c	2007-05-03 15:20:44.000000000 +0100
   50.22  @@ -877,6 +877,9 @@
   50.23           }
   50.24       }
   50.25 @@ -49,8 +49,8 @@ Index: ioemu/hw/pc.c
   50.26  Index: ioemu/hw/tpm_tis.c
   50.27  ===================================================================
   50.28  --- /dev/null	1970-01-01 00:00:00.000000000 +0000
   50.29 -+++ ioemu/hw/tpm_tis.c	2006-12-20 15:21:55.000000000 +0000
   50.30 -@@ -0,0 +1,1120 @@
   50.31 ++++ ioemu/hw/tpm_tis.c	2007-05-03 15:20:44.000000000 +0100
   50.32 +@@ -0,0 +1,1128 @@
   50.33  +/*
   50.34  + * tpm_tis.c - QEMU emulator for a 1.2 TPM with TIS interface
   50.35  + *
   50.36 @@ -570,7 +570,7 @@ Index: ioemu/hw/tpm_tis.c
   50.37  +
   50.38  +#ifdef DEBUG_TPM
   50.39  +    fprintf(logfile," read(%08x) = %08x\n",
   50.40 -+            addr,
   50.41 ++            (int)addr,
   50.42  +            val);
   50.43  +#endif
   50.44  +
   50.45 @@ -591,7 +591,7 @@ Index: ioemu/hw/tpm_tis.c
   50.46  +
   50.47  +#ifdef DEBUG_TPM
   50.48  +    fprintf(logfile,"write(%08x) = %08x\n",
   50.49 -+            addr,
   50.50 ++            (int)addr,
   50.51  +            val);
   50.52  +#endif
   50.53  +
   50.54 @@ -810,10 +810,11 @@ Index: ioemu/hw/tpm_tis.c
   50.55  +static void tpm_save(QEMUFile* f,void* opaque)
   50.56  +{
   50.57  +    tpmState* s=(tpmState*)opaque;
   50.58 ++    uint8_t locty = s->active_loc;
   50.59  +    int c;
   50.60  +
   50.61  +    /* need to wait for outstanding requests to complete */
   50.62 -+    if (IS_COMM_WITH_VTPM(s)) {
   50.63 ++    if (s->loc[locty].state == STATE_EXECUTION) {
   50.64  +        int repeats = 30; /* 30 seconds; really should be infty */
   50.65  +        while (repeats > 0 &&
   50.66  +               !(s->loc[s->active_loc].sts & STS_DATA_AVAILABLE)) {
   50.67 @@ -821,6 +822,8 @@ Index: ioemu/hw/tpm_tis.c
   50.68  +            if (n > 0) {
   50.69  +                if (IS_VALID_LOC(s->active_loc)) {
   50.70  +                    s->loc[s->active_loc].sts = STS_VALID | STS_DATA_AVAILABLE;
   50.71 ++                    s->loc[s->active_loc].state = STATE_COMPLETION;
   50.72 ++                    tis_raise_irq(s, s->active_loc, INT_DATA_AVAILABLE);
   50.73  +                }
   50.74  +                /* close the connection with the vTPM for good */
   50.75  +                close_vtpm_channel(s, 1);
   50.76 @@ -830,6 +833,10 @@ Index: ioemu/hw/tpm_tis.c
   50.77  +        }
   50.78  +    }
   50.79  +
   50.80 ++    if (IS_COMM_WITH_VTPM(s)) {
   50.81 ++        close_vtpm_channel(s, 1);
   50.82 ++    }
   50.83 ++
   50.84  +    qemu_put_be32s(f,&s->offset);
   50.85  +    qemu_put_buffer(f, s->buffer.buf, TPM_MAX_PKT);
   50.86  +    qemu_put_8s(f, &s->active_loc);
   50.87 @@ -929,6 +936,7 @@ Index: ioemu/hw/tpm_tis.c
   50.88  +    s->Transmitlayer = -1;
   50.89  +    s->tpmTx.fd[0] = -1;
   50.90  +    s->tpmTx.fd[1] = -1;
   50.91 ++    s->aborting_locty = NO_LOCALITY;
   50.92  +
   50.93  +    tpm_initialize_instance(s, s->vtpm_instance);
   50.94  +    memset(s->buffer.buf,0,sizeof(s->buffer.buf));
   50.95 @@ -1046,7 +1054,7 @@ Index: ioemu/hw/tpm_tis.c
   50.96  +        uint32_t size = tpm_get_size_from_buffer(buffer->buf);
   50.97  +        if (size + sizeof(buffer->instance) != off) {
   50.98  +            fprintf(logfile,"TPM: Packet size is bad! %d != %d\n",
   50.99 -+                    size + sizeof(buffer->instance),
  50.100 ++                    (int)(size + sizeof(buffer->instance)),
  50.101  +                    off);
  50.102  +        } else {
  50.103  +            uint32_t ret;
  50.104 @@ -1173,9 +1181,9 @@ Index: ioemu/hw/tpm_tis.c
  50.105  +}
  50.106  Index: ioemu/vl.h
  50.107  ===================================================================
  50.108 ---- ioemu.orig/vl.h	2006-12-20 15:21:55.000000000 +0000
  50.109 -+++ ioemu/vl.h	2006-12-20 15:21:55.000000000 +0000
  50.110 -@@ -932,6 +932,10 @@
  50.111 +--- ioemu.orig/vl.h	2007-05-03 15:20:44.000000000 +0100
  50.112 ++++ ioemu/vl.h	2007-05-03 15:20:44.000000000 +0100
  50.113 +@@ -933,6 +933,10 @@
  50.114   void piix4_pm_init(PCIBus *bus, int devfn);
  50.115   void acpi_bios_init(void);
  50.116   
    51.1 --- a/tools/ioemu/patches/usb-mouse-tablet-status-check	Mon May 07 13:24:37 2007 -0600
    51.2 +++ b/tools/ioemu/patches/usb-mouse-tablet-status-check	Tue May 08 09:09:17 2007 -0600
    51.3 @@ -16,10 +16,11 @@ This patch make UHC & USB mouse/tablet b
    51.4  
    51.5  Signed-off-by: Xinmei Huang <xinmei.huang@intel.com>
    51.6  
    51.7 -diff -r fb3cb6f52a29 -r 60bbcf799384 tools/ioemu/hw/usb-hid.c
    51.8 ---- a/tools/ioemu/hw/usb-hid.c	Thu Dec 07 11:51:22 2006 +0000
    51.9 -+++ b/tools/ioemu/hw/usb-hid.c	Thu Dec 07 11:52:26 2006 +0000
   51.10 -@@ -39,6 +39,7 @@ typedef struct USBMouseState {
   51.11 +Index: ioemu/hw/usb-hid.c
   51.12 +===================================================================
   51.13 +--- ioemu.orig/hw/usb-hid.c	2007-05-02 14:21:51.000000000 +0100
   51.14 ++++ ioemu/hw/usb-hid.c	2007-05-02 14:23:54.000000000 +0100
   51.15 +@@ -39,6 +39,7 @@
   51.16       int x, y;
   51.17       int kind;
   51.18       int mouse_grabbed;
   51.19 @@ -27,7 +28,7 @@ diff -r fb3cb6f52a29 -r 60bbcf799384 too
   51.20   } USBMouseState;
   51.21   
   51.22   /* mostly the same values as the Bochs USB Mouse device */
   51.23 -@@ -231,6 +232,7 @@ static void usb_mouse_event(void *opaque
   51.24 +@@ -231,6 +232,7 @@
   51.25       s->dy += dy1;
   51.26       s->dz += dz1;
   51.27       s->buttons_state = buttons_state;
   51.28 @@ -35,7 +36,7 @@ diff -r fb3cb6f52a29 -r 60bbcf799384 too
   51.29   }
   51.30   
   51.31   static void usb_tablet_event(void *opaque,
   51.32 -@@ -242,6 +244,7 @@ static void usb_tablet_event(void *opaqu
   51.33 +@@ -242,6 +244,7 @@
   51.34       s->y = y;
   51.35       s->dz += dz;
   51.36       s->buttons_state = buttons_state;
   51.37 @@ -43,7 +44,7 @@ diff -r fb3cb6f52a29 -r 60bbcf799384 too
   51.38   }
   51.39   
   51.40   static inline int int_clamp(int val, int vmin, int vmax)
   51.41 -@@ -483,10 +486,16 @@ static int usb_mouse_handle_data(USBDevi
   51.42 +@@ -483,10 +486,16 @@
   51.43       switch(pid) {
   51.44       case USB_TOKEN_IN:
   51.45           if (devep == 1) {
   51.46 @@ -64,7 +65,7 @@ diff -r fb3cb6f52a29 -r 60bbcf799384 too
   51.47           } else {
   51.48               goto fail;
   51.49           }
   51.50 -@@ -523,6 +532,7 @@ USBDevice *usb_tablet_init(void)
   51.51 +@@ -566,6 +575,7 @@
   51.52       s->dev.handle_data = usb_mouse_handle_data;
   51.53       s->dev.handle_destroy = usb_mouse_handle_destroy;
   51.54       s->kind = USB_TABLET;
   51.55 @@ -72,7 +73,7 @@ diff -r fb3cb6f52a29 -r 60bbcf799384 too
   51.56   
   51.57       pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Tablet");
   51.58   
   51.59 -@@ -544,6 +554,7 @@ USBDevice *usb_mouse_init(void)
   51.60 +@@ -589,6 +599,7 @@
   51.61       s->dev.handle_data = usb_mouse_handle_data;
   51.62       s->dev.handle_destroy = usb_mouse_handle_destroy;
   51.63       s->kind = USB_MOUSE;
   51.64 @@ -80,27 +81,45 @@ diff -r fb3cb6f52a29 -r 60bbcf799384 too
   51.65   
   51.66       pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Mouse");
   51.67   
   51.68 -diff -r fb3cb6f52a29 -r 60bbcf799384 tools/ioemu/hw/usb-uhci.c
   51.69 ---- a/tools/ioemu/hw/usb-uhci.c	Thu Dec 07 11:51:22 2006 +0000
   51.70 -+++ b/tools/ioemu/hw/usb-uhci.c	Thu Dec 07 11:52:26 2006 +0000
   51.71 -@@ -424,12 +424,10 @@ static int uhci_handle_td(UHCIState *s, 
   51.72 +Index: ioemu/hw/usb-uhci.c
   51.73 +===================================================================
   51.74 +--- ioemu.orig/hw/usb-uhci.c	2007-05-02 14:23:54.000000000 +0100
   51.75 ++++ ioemu/hw/usb-uhci.c	2007-05-02 14:23:54.000000000 +0100
   51.76 +@@ -43,9 +43,15 @@
   51.77 + #define TD_CTRL_IOC     (1 << 24)
   51.78 + #define TD_CTRL_ACTIVE  (1 << 23)
   51.79 + #define TD_CTRL_STALL   (1 << 22)
   51.80 ++#define TD_CTRL_BUFFER  (1 << 21)
   51.81 + #define TD_CTRL_BABBLE  (1 << 20)
   51.82 + #define TD_CTRL_NAK     (1 << 19)
   51.83 + #define TD_CTRL_TIMEOUT (1 << 18)
   51.84 ++#define TD_CTRL_BITSTUFF                                 \
   51.85 ++                        (1 << 17)
   51.86 ++#define TD_CTRL_MASK                                     \
   51.87 ++    (TD_CTRL_BITSTUFF | TD_CTRL_TIMEOUT | TD_CTRL_NAK    \
   51.88 ++     | TD_CTRL_BABBLE | TD_CTRL_BUFFER | TD_CTRL_STALL)
   51.89 + 
   51.90 + #define UHCI_PORT_RESET (1 << 9)
   51.91 + #define UHCI_PORT_LSDA  (1 << 8)
   51.92 +@@ -424,12 +430,12 @@
   51.93       uint8_t buf[2048];
   51.94       int len, max_len, err, ret;
   51.95   
   51.96  -    if (td->ctrl & TD_CTRL_IOC) {
   51.97  -        *int_mask |= 0x01;
   51.98 --    }
   51.99 ++    if (!(td->ctrl & TD_CTRL_ACTIVE)){
  51.100 ++        ret = 1;
  51.101 ++        goto out;
  51.102 +     }
  51.103  -    
  51.104  -    if (!(td->ctrl & TD_CTRL_ACTIVE))
  51.105  -        return 1;
  51.106 -+    if (!(td->ctrl & TD_CTRL_ACTIVE)){
  51.107 -+        ret = 1;
  51.108 -+        goto out;
  51.109 -+    }
  51.110 ++    /* Clear TD's status field explicitly */
  51.111 ++    td->ctrl = td->ctrl & (~TD_CTRL_MASK);
  51.112   
  51.113       /* TD is active */
  51.114       max_len = ((td->token >> 21) + 1) & 0x7ff;
  51.115 -@@ -467,7 +465,8 @@ static int uhci_handle_td(UHCIState *s, 
  51.116 +@@ -467,7 +473,8 @@
  51.117           /* invalid pid : frame interrupted */
  51.118           s->status |= UHCI_STS_HCPERR;
  51.119           uhci_update_irq(s);
  51.120 @@ -110,7 +129,7 @@ diff -r fb3cb6f52a29 -r 60bbcf799384 too
  51.121       }
  51.122       if (td->ctrl & TD_CTRL_IOS)
  51.123           td->ctrl &= ~TD_CTRL_ACTIVE;
  51.124 -@@ -479,10 +478,12 @@ static int uhci_handle_td(UHCIState *s, 
  51.125 +@@ -479,10 +486,12 @@
  51.126               len < max_len) {
  51.127               *int_mask |= 0x02;
  51.128               /* short packet: do not update QH */
  51.129 @@ -125,7 +144,7 @@ diff -r fb3cb6f52a29 -r 60bbcf799384 too
  51.130           }
  51.131       } else {
  51.132           switch(ret) {
  51.133 -@@ -501,23 +502,34 @@ static int uhci_handle_td(UHCIState *s, 
  51.134 +@@ -501,23 +510,34 @@
  51.135               }
  51.136               td->ctrl = (td->ctrl & ~(3 << TD_CTRL_ERROR_SHIFT)) | 
  51.137                   (err << TD_CTRL_ERROR_SHIFT);
  51.138 @@ -150,12 +169,10 @@ diff -r fb3cb6f52a29 -r 60bbcf799384 too
  51.139               td->ctrl &= ~TD_CTRL_ACTIVE;
  51.140               /* frame interrupted */
  51.141  -            return -1;
  51.142 --        }
  51.143 --    }
  51.144  +            ret = -1;
  51.145  +            goto out;
  51.146 -+        }
  51.147 -+    }
  51.148 +         }
  51.149 +     }
  51.150  +   
  51.151  +out:
  51.152  +    /* If TD is inactive and IOC bit set to 1 then update int_mask */ 
    52.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.2 +++ b/tools/ioemu/patches/vnc-altgr-keysym	Tue May 08 09:09:17 2007 -0600
    52.3 @@ -0,0 +1,24 @@
    52.4 +Index: ioemu/keymaps/modifiers
    52.5 +===================================================================
    52.6 +--- ioemu.orig/keymaps/modifiers	2007-05-02 10:30:05.000000000 +0100
    52.7 ++++ ioemu/keymaps/modifiers	2007-05-03 15:02:56.000000000 +0100
    52.8 +@@ -3,6 +3,7 @@
    52.9 + 
   52.10 + Alt_R 0xb8
   52.11 + Mode_switch 0xb8
   52.12 ++ISO_Level3_Switch 0xb8
   52.13 + Alt_L 0x38
   52.14 + 
   52.15 + Control_R 0x9d
   52.16 +Index: ioemu/vnc_keysym.h
   52.17 +===================================================================
   52.18 +--- ioemu.orig/vnc_keysym.h	2007-05-03 15:02:10.000000000 +0100
   52.19 ++++ ioemu/vnc_keysym.h	2007-05-03 15:03:03.000000000 +0100
   52.20 +@@ -215,6 +215,7 @@
   52.21 + {"Shift_R", 0xffe2},   /* XK_Shift_R */
   52.22 + {"Super_L", 0xffeb},   /* XK_Super_L */
   52.23 + {"Super_R", 0xffec},   /* XK_Super_R */
   52.24 ++{"ISO_Level3_Shift", 0xfe03}, /* XK_ISO_Level3_Shift */
   52.25 + 
   52.26 +     /* special keys */
   52.27 + {"BackSpace", 0xff08}, /* XK_BackSpace */
    53.1 --- a/tools/ioemu/patches/vnc-backoff-screen-scan	Mon May 07 13:24:37 2007 -0600
    53.2 +++ b/tools/ioemu/patches/vnc-backoff-screen-scan	Tue May 08 09:09:17 2007 -0600
    53.3 @@ -1,7 +1,7 @@
    53.4  Index: ioemu/vnc.c
    53.5  ===================================================================
    53.6 ---- ioemu.orig/vnc.c	2006-12-06 23:46:12.000000000 +0000
    53.7 -+++ ioemu/vnc.c	2006-12-06 23:46:12.000000000 +0000
    53.8 +--- ioemu.orig/vnc.c	2007-05-03 10:07:56.000000000 +0100
    53.9 ++++ ioemu/vnc.c	2007-05-03 10:07:56.000000000 +0100
   53.10  @@ -28,7 +28,19 @@
   53.11   #include "qemu_socket.h"
   53.12   #include <assert.h>
   53.13 @@ -356,9 +356,9 @@ Index: ioemu/vnc.c
   53.14       case 6:
   53.15  Index: ioemu/vl.c
   53.16  ===================================================================
   53.17 ---- ioemu.orig/vl.c	2006-12-06 23:46:12.000000000 +0000
   53.18 -+++ ioemu/vl.c	2006-12-06 23:46:12.000000000 +0000
   53.19 -@@ -726,6 +726,12 @@
   53.20 +--- ioemu.orig/vl.c	2007-05-03 10:07:56.000000000 +0100
   53.21 ++++ ioemu/vl.c	2007-05-03 10:07:56.000000000 +0100
   53.22 +@@ -725,6 +725,12 @@
   53.23       }
   53.24   }
   53.25   
   53.26 @@ -373,8 +373,8 @@ Index: ioemu/vl.c
   53.27   void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
   53.28  Index: ioemu/vl.h
   53.29  ===================================================================
   53.30 ---- ioemu.orig/vl.h	2006-12-06 23:46:12.000000000 +0000
   53.31 -+++ ioemu/vl.h	2006-12-06 23:46:12.000000000 +0000
   53.32 +--- ioemu.orig/vl.h	2007-05-03 10:07:56.000000000 +0100
   53.33 ++++ ioemu/vl.h	2007-05-03 10:07:56.000000000 +0100
   53.34  @@ -407,6 +407,7 @@
   53.35   void qemu_free_timer(QEMUTimer *ts);
   53.36   void qemu_del_timer(QEMUTimer *ts);
    54.1 --- a/tools/ioemu/patches/vnc-cleanup	Mon May 07 13:24:37 2007 -0600
    54.2 +++ b/tools/ioemu/patches/vnc-cleanup	Tue May 08 09:09:17 2007 -0600
    54.3 @@ -1,7 +1,7 @@
    54.4  Index: ioemu/vnc.c
    54.5  ===================================================================
    54.6 ---- ioemu.orig/vnc.c	2006-09-21 18:54:22.000000000 +0100
    54.7 -+++ ioemu/vnc.c	2006-09-21 19:05:39.000000000 +0100
    54.8 +--- ioemu.orig/vnc.c	2007-05-03 09:56:31.000000000 +0100
    54.9 ++++ ioemu/vnc.c	2007-05-03 10:07:55.000000000 +0100
   54.10  @@ -143,13 +143,16 @@
   54.11   static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h)
   54.12   {
   54.13 @@ -90,9 +90,9 @@ Index: ioemu/vnc.c
   54.14   static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
   54.15  Index: ioemu/vl.c
   54.16  ===================================================================
   54.17 ---- ioemu.orig/vl.c	2006-09-21 18:55:38.000000000 +0100
   54.18 -+++ ioemu/vl.c	2006-09-21 19:00:48.000000000 +0100
   54.19 -@@ -5120,10 +5120,10 @@
   54.20 +--- ioemu.orig/vl.c	2007-05-03 10:07:54.000000000 +0100
   54.21 ++++ ioemu/vl.c	2007-05-03 10:07:55.000000000 +0100
   54.22 +@@ -5195,10 +5195,10 @@
   54.23           /* XXX: better handling of removal */
   54.24           for(ioh = first_io_handler; ioh != NULL; ioh = ioh_next) {
   54.25               ioh_next = ioh->next;
    55.1 --- a/tools/ioemu/patches/vnc-display-find-unused	Mon May 07 13:24:37 2007 -0600
    55.2 +++ b/tools/ioemu/patches/vnc-display-find-unused	Tue May 08 09:09:17 2007 -0600
    55.3 @@ -1,7 +1,7 @@
    55.4  Index: ioemu/vnc.c
    55.5  ===================================================================
    55.6 ---- ioemu.orig/vnc.c	2006-12-20 15:21:52.000000000 +0000
    55.7 -+++ ioemu/vnc.c	2006-12-20 15:21:52.000000000 +0000
    55.8 +--- ioemu.orig/vnc.c	2007-05-03 10:24:06.000000000 +0100
    55.9 ++++ ioemu/vnc.c	2007-05-03 10:24:06.000000000 +0100
   55.10  @@ -1197,7 +1197,7 @@
   55.11       }
   55.12   }
   55.13 @@ -50,9 +50,9 @@ Index: ioemu/vnc.c
   55.14   int vnc_start_viewer(int port)
   55.15  Index: ioemu/vl.c
   55.16  ===================================================================
   55.17 ---- ioemu.orig/vl.c	2006-12-20 15:21:51.000000000 +0000
   55.18 -+++ ioemu/vl.c	2006-12-20 15:21:52.000000000 +0000
   55.19 -@@ -121,6 +121,7 @@
   55.20 +--- ioemu.orig/vl.c	2007-05-03 10:24:06.000000000 +0100
   55.21 ++++ ioemu/vl.c	2007-05-03 10:24:06.000000000 +0100
   55.22 +@@ -122,6 +122,7 @@
   55.23   static DisplayState display_state;
   55.24   int nographic;
   55.25   int vncviewer;
   55.26 @@ -60,23 +60,23 @@ Index: ioemu/vl.c
   55.27   const char* keyboard_layout = NULL;
   55.28   int64_t ticks_per_sec;
   55.29   int boot_device = 'c';
   55.30 -@@ -5342,6 +5343,7 @@
   55.31 +@@ -5417,6 +5418,7 @@
   55.32              "-loadvm file    start right away with a saved state (loadvm in monitor)\n"
   55.33   	   "-vnc display    start a VNC server on display\n"
   55.34              "-vncviewer      start a vncviewer process for this domain\n"
   55.35  +           "-vncunused      bind the VNC server to an unused port\n"
   55.36 -            "-timeoffset     time offset (in seconds) from local time\n"
   55.37              "-acpi           disable or enable ACPI of HVM domain \n"
   55.38              "\n"
   55.39 -@@ -5431,6 +5433,7 @@
   55.40 -     QEMU_OPTION_timeoffset,
   55.41 +            "During emulation, the following keys are useful:\n"
   55.42 +@@ -5504,6 +5506,7 @@
   55.43 +     QEMU_OPTION_vcpus,
   55.44       QEMU_OPTION_acpi,
   55.45       QEMU_OPTION_vncviewer,
   55.46  +    QEMU_OPTION_vncunused,
   55.47   };
   55.48   
   55.49   typedef struct QEMUOption {
   55.50 -@@ -5506,6 +5509,7 @@
   55.51 +@@ -5579,6 +5582,7 @@
   55.52       { "smp", HAS_ARG, QEMU_OPTION_smp },
   55.53       { "vnc", HAS_ARG, QEMU_OPTION_vnc },
   55.54       { "vncviewer", 0, QEMU_OPTION_vncviewer },
   55.55 @@ -84,7 +84,7 @@ Index: ioemu/vl.c
   55.56       
   55.57       /* temporary options */
   55.58       { "usb", 0, QEMU_OPTION_usb },
   55.59 -@@ -5857,6 +5861,7 @@
   55.60 +@@ -5938,6 +5942,7 @@
   55.61       snapshot = 0;
   55.62       nographic = 0;
   55.63       vncviewer = 0;
   55.64 @@ -92,7 +92,7 @@ Index: ioemu/vl.c
   55.65       kernel_filename = NULL;
   55.66       kernel_cmdline = "";
   55.67   #ifdef TARGET_PPC
   55.68 -@@ -6254,6 +6259,11 @@
   55.69 +@@ -6336,6 +6341,11 @@
   55.70               case QEMU_OPTION_vncviewer:
   55.71                   vncviewer++;
   55.72                   break;
   55.73 @@ -104,7 +104,7 @@ Index: ioemu/vl.c
   55.74               }
   55.75           }
   55.76       }
   55.77 -@@ -6460,7 +6470,7 @@
   55.78 +@@ -6537,7 +6547,7 @@
   55.79       if (nographic) {
   55.80           dumb_display_init(ds);
   55.81       } else if (vnc_display != -1) {
   55.82 @@ -115,8 +115,8 @@ Index: ioemu/vl.c
   55.83       } else {
   55.84  Index: ioemu/vl.h
   55.85  ===================================================================
   55.86 ---- ioemu.orig/vl.h	2006-12-20 15:21:51.000000000 +0000
   55.87 -+++ ioemu/vl.h	2006-12-20 15:21:52.000000000 +0000
   55.88 +--- ioemu.orig/vl.h	2007-05-03 10:24:06.000000000 +0100
   55.89 ++++ ioemu/vl.h	2007-05-03 10:24:06.000000000 +0100
   55.90  @@ -785,7 +785,7 @@
   55.91   void cocoa_display_init(DisplayState *ds, int full_screen);
   55.92   
    56.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    56.2 +++ b/tools/ioemu/patches/vnc-fix-signedness	Tue May 08 09:09:17 2007 -0600
    56.3 @@ -0,0 +1,222 @@
    56.4 +# HG changeset patch
    56.5 +# User kaf24@localhost.localdomain
    56.6 +# Date 1167325891 0
    56.7 +# Node ID ede2f5280810789c3cb37603cf2e6b34c60982b1
    56.8 +# Parent  a138fabc2120376cfb4bf72596a334a1edf8adb0
    56.9 +[QEMU] Fix a number of signedness issues plus a typo in the version checking in vnc.c.
   56.10 +Signed-off-by:  Anthony Liguori <aliguori@us.ibm.com>
   56.11 +
   56.12 +Index: ioemu/vnc.c
   56.13 +===================================================================
   56.14 +--- ioemu.orig/vnc.c	2007-05-02 14:03:41.000000000 +0100
   56.15 ++++ ioemu/vnc.c	2007-05-02 14:03:42.000000000 +0100
   56.16 +@@ -54,12 +54,12 @@
   56.17 + {
   56.18 +     size_t capacity;
   56.19 +     size_t offset;
   56.20 +-    char *buffer;
   56.21 ++    uint8_t *buffer;
   56.22 + } Buffer;
   56.23 + 
   56.24 + typedef struct VncState VncState;
   56.25 + 
   56.26 +-typedef int VncReadEvent(VncState *vs, char *data, size_t len);
   56.27 ++typedef int VncReadEvent(VncState *vs, uint8_t *data, size_t len);
   56.28 + 
   56.29 + typedef void VncWritePixels(VncState *vs, void *data, int size);
   56.30 + 
   56.31 +@@ -90,7 +90,7 @@
   56.32 +     uint64_t *update_row;	/* outstanding updates */
   56.33 +     int has_update;		/* there's outstanding updates in the
   56.34 + 				 * visible area */
   56.35 +-    char *old_data;
   56.36 ++    uint8_t *old_data;
   56.37 +     int depth; /* internal VNC frame buffer byte per pixel */
   56.38 +     int has_resize;
   56.39 +     int has_hextile;
   56.40 +@@ -140,7 +140,7 @@
   56.41 + static void vnc_update_client(void *opaque);
   56.42 + static void vnc_client_read(void *opaque);
   56.43 + static void framebuffer_set_updated(VncState *vs, int x, int y, int w, int h);
   56.44 +-static int make_challenge(char *random, int size);
   56.45 ++static int make_challenge(unsigned char *random, int size);
   56.46 + static void set_seed(unsigned int *seedp);
   56.47 + static void get_random(int len, unsigned char *buf);
   56.48 + 
   56.49 +@@ -330,7 +330,7 @@
   56.50 + static void send_framebuffer_update_raw(VncState *vs, int x, int y, int w, int h)
   56.51 + {
   56.52 +     int i;
   56.53 +-    char *row;
   56.54 ++    uint8_t *row;
   56.55 + 
   56.56 +     vnc_framebuffer_update(vs, x, y, w, h, 0);
   56.57 + 
   56.58 +@@ -394,9 +394,9 @@
   56.59 + static void vnc_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int dst_y, int w, int h)
   56.60 + {
   56.61 +     int src, dst;
   56.62 +-    char *src_row;
   56.63 +-    char *dst_row;
   56.64 +-    char *old_row;
   56.65 ++    uint8_t *src_row;
   56.66 ++    uint8_t *dst_row;
   56.67 ++    uint8_t *old_row;
   56.68 +     int y = 0;
   56.69 +     int pitch = ds->linesize;
   56.70 +     VncState *vs = ds->opaque;
   56.71 +@@ -465,8 +465,8 @@
   56.72 +     VncState *vs = opaque;
   56.73 +     int64_t now;
   56.74 +     int y;
   56.75 +-    char *row;
   56.76 +-    char *old_row;
   56.77 ++    uint8_t *row;
   56.78 ++    uint8_t *old_row;
   56.79 +     uint64_t width_mask;
   56.80 +     int n_rectangles;
   56.81 +     int saved_offset;
   56.82 +@@ -491,7 +491,7 @@
   56.83 +     for (y = 0; y < vs->ds->height; y++) {
   56.84 + 	if (vs->dirty_row[y] & width_mask) {
   56.85 + 	    int x;
   56.86 +-	    char *ptr, *old_ptr;
   56.87 ++	    uint8_t *ptr, *old_ptr;
   56.88 + 
   56.89 + 	    ptr = row;
   56.90 + 	    old_ptr = old_row;
   56.91 +@@ -654,7 +654,7 @@
   56.92 +     return buffer->offset == 0;
   56.93 + }
   56.94 + 
   56.95 +-static char *buffer_end(Buffer *buffer)
   56.96 ++static uint8_t *buffer_end(Buffer *buffer)
   56.97 + {
   56.98 +     return buffer->buffer + buffer->offset;
   56.99 + }
  56.100 +@@ -778,7 +778,7 @@
  56.101 + 
  56.102 + static void vnc_write_u16(VncState *vs, uint16_t value)
  56.103 + {
  56.104 +-    char buf[2];
  56.105 ++    uint8_t buf[2];
  56.106 + 
  56.107 +     buf[0] = (value >> 8) & 0xFF;
  56.108 +     buf[1] = value & 0xFF;
  56.109 +@@ -788,7 +788,7 @@
  56.110 + 
  56.111 + static void vnc_write_u8(VncState *vs, uint8_t value)
  56.112 + {
  56.113 +-    vnc_write(vs, (char *)&value, 1);
  56.114 ++    vnc_write(vs, &value, 1);
  56.115 + }
  56.116 + 
  56.117 + static void vnc_flush(VncState *vs)
  56.118 +@@ -797,23 +797,23 @@
  56.119 + 	vnc_client_write(vs);
  56.120 + }
  56.121 + 
  56.122 +-static uint8_t read_u8(char *data, size_t offset)
  56.123 ++static uint8_t read_u8(uint8_t *data, size_t offset)
  56.124 + {
  56.125 +     return data[offset];
  56.126 + }
  56.127 + 
  56.128 +-static uint16_t read_u16(char *data, size_t offset)
  56.129 ++static uint16_t read_u16(uint8_t *data, size_t offset)
  56.130 + {
  56.131 +     return ((data[offset] & 0xFF) << 8) | (data[offset + 1] & 0xFF);
  56.132 + }
  56.133 + 
  56.134 +-static int32_t read_s32(char *data, size_t offset)
  56.135 ++static int32_t read_s32(uint8_t *data, size_t offset)
  56.136 + {
  56.137 +     return (int32_t)((data[offset] << 24) | (data[offset + 1] << 16) |
  56.138 + 		     (data[offset + 2] << 8) | data[offset + 3]);
  56.139 + }
  56.140 + 
  56.141 +-static uint32_t read_u32(char *data, size_t offset)
  56.142 ++static uint32_t read_u32(uint8_t *data, size_t offset)
  56.143 + {
  56.144 +     return ((data[offset] << 24) | (data[offset + 1] << 16) |
  56.145 + 	    (data[offset + 2] << 8) | data[offset + 3]);
  56.146 +@@ -1115,11 +1115,10 @@
  56.147 +     vga_hw_update();
  56.148 + }
  56.149 + 
  56.150 +-static int protocol_client_msg(VncState *vs, char *data, size_t len)
  56.151 ++static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len)
  56.152 + {
  56.153 +     int i;
  56.154 +     uint16_t limit;
  56.155 +-    int64_t now;
  56.156 + 
  56.157 +     switch (data[0]) {
  56.158 +     case 0:
  56.159 +@@ -1188,7 +1187,7 @@
  56.160 + 		return 8 + v;
  56.161 + 	}
  56.162 + 
  56.163 +-	client_cut_text(vs, read_u32(data, 4), data + 8);
  56.164 ++	client_cut_text(vs, read_u32(data, 4), (char *)(data + 8));
  56.165 + 	break;
  56.166 +     default:
  56.167 + 	printf("Msg: %d\n", data[0]);
  56.168 +@@ -1200,7 +1199,7 @@
  56.169 +     return 0;
  56.170 + }
  56.171 + 
  56.172 +-static int protocol_client_init(VncState *vs, char *data, size_t len)
  56.173 ++static int protocol_client_init(VncState *vs, uint8_t *data, size_t len)
  56.174 + {
  56.175 +     size_t l;
  56.176 +     char pad[3] = { 0, 0, 0 };
  56.177 +@@ -1261,7 +1260,7 @@
  56.178 +     return 0;
  56.179 + }
  56.180 + 
  56.181 +-static int protocol_response(VncState *vs, char *client_response, size_t len)
  56.182 ++static int protocol_response(VncState *vs, uint8_t *client_response, size_t len)
  56.183 + {
  56.184 +     extern char vncpasswd[64];
  56.185 +     extern unsigned char challenge[AUTHCHALLENGESIZE];
  56.186 +@@ -1299,7 +1298,7 @@
  56.187 +     return 0;
  56.188 + }
  56.189 + 
  56.190 +-static int protocol_version(VncState *vs, char *version, size_t len)
  56.191 ++static int protocol_version(VncState *vs, uint8_t *version, size_t len)
  56.192 + {
  56.193 +     extern char vncpasswd[64];
  56.194 +     extern unsigned char challenge[AUTHCHALLENGESIZE];
  56.195 +@@ -1474,7 +1473,7 @@
  56.196 + 
  56.197 + unsigned int seed;
  56.198 + 
  56.199 +-static int make_challenge(char *random, int size)
  56.200 ++static int make_challenge(unsigned char *random, int size)
  56.201 + {
  56.202 +  
  56.203 +     set_seed(&seed);
  56.204 +Index: ioemu/vnchextile.h
  56.205 +===================================================================
  56.206 +--- ioemu.orig/vnchextile.h	2007-05-02 14:03:13.000000000 +0100
  56.207 ++++ ioemu/vnchextile.h	2007-05-02 14:03:42.000000000 +0100
  56.208 +@@ -13,7 +13,7 @@
  56.209 +                                              uint32_t *last_fg32,
  56.210 +                                              int *has_bg, int *has_fg)
  56.211 + {
  56.212 +-    char *row = (vs->ds->data + y * vs->ds->linesize + x * vs->depth);
  56.213 ++    uint8_t *row = (vs->ds->data + y * vs->ds->linesize + x * vs->depth);
  56.214 +     pixel_t *irow = (pixel_t *)row;
  56.215 +     int j, i;
  56.216 +     pixel_t *last_bg = (pixel_t *)last_bg32;
  56.217 +@@ -119,7 +119,7 @@
  56.218 + 	for (j = 0; j < h; j++) {
  56.219 + 	    int has_color = 0;
  56.220 + 	    int min_x = -1;
  56.221 +-	    pixel_t color;
  56.222 ++	    pixel_t color = 0;
  56.223 + 
  56.224 + 	    for (i = 0; i < w; i++) {
  56.225 + 		if (!has_color) {
    57.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.2 +++ b/tools/ioemu/patches/vnc-fix-version-check	Tue May 08 09:09:17 2007 -0600
    57.3 @@ -0,0 +1,13 @@
    57.4 +Index: ioemu/vnc.c
    57.5 +===================================================================
    57.6 +--- ioemu.orig/vnc.c	2007-05-02 10:47:41.000000000 +0100
    57.7 ++++ ioemu/vnc.c	2007-05-02 10:47:42.000000000 +0100
    57.8 +@@ -1317,7 +1317,7 @@
    57.9 + 
   57.10 + 
   57.11 +     support = 0;
   57.12 +-    if (maj = 3) {
   57.13 ++    if (maj == 3) {
   57.14 + 	if (min == 3 || min ==4) {
   57.15 + 	    support = 1;
   57.16 + 	}
    58.1 --- a/tools/ioemu/patches/vnc-fixes	Mon May 07 13:24:37 2007 -0600
    58.2 +++ b/tools/ioemu/patches/vnc-fixes	Tue May 08 09:09:17 2007 -0600
    58.3 @@ -1,8 +1,8 @@
    58.4  Index: ioemu/vl.c
    58.5  ===================================================================
    58.6 ---- ioemu.orig/vl.c	2006-12-20 15:21:51.000000000 +0000
    58.7 -+++ ioemu/vl.c	2006-12-20 15:21:51.000000000 +0000
    58.8 -@@ -6511,8 +6511,10 @@
    58.9 +--- ioemu.orig/vl.c	2007-05-03 10:24:05.000000000 +0100
   58.10 ++++ ioemu/vl.c	2007-05-03 10:24:05.000000000 +0100
   58.11 +@@ -6597,8 +6597,10 @@
   58.12           }
   58.13       }
   58.14   
   58.15 @@ -17,8 +17,8 @@ Index: ioemu/vl.c
   58.16       if (use_gdbstub) {
   58.17  Index: ioemu/vnc.c
   58.18  ===================================================================
   58.19 ---- ioemu.orig/vnc.c	2006-12-20 15:21:51.000000000 +0000
   58.20 -+++ ioemu/vnc.c	2006-12-20 15:21:51.000000000 +0000
   58.21 +--- ioemu.orig/vnc.c	2007-05-03 10:24:05.000000000 +0100
   58.22 ++++ ioemu/vnc.c	2007-05-03 10:24:05.000000000 +0100
   58.23  @@ -3,6 +3,7 @@
   58.24    * 
   58.25    * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>
   58.26 @@ -531,8 +531,8 @@ Index: ioemu/vnc.c
   58.27   }
   58.28  Index: ioemu/vl.h
   58.29  ===================================================================
   58.30 ---- ioemu.orig/vl.h	2006-12-20 15:21:51.000000000 +0000
   58.31 -+++ ioemu/vl.h	2006-12-20 15:21:51.000000000 +0000
   58.32 +--- ioemu.orig/vl.h	2007-05-03 10:24:05.000000000 +0100
   58.33 ++++ ioemu/vl.h	2007-05-03 10:24:05.000000000 +0100
   58.34  @@ -319,6 +319,7 @@
   58.35   int is_graphic_console(void);
   58.36   CharDriverState *text_console_init(DisplayState *ds);
    59.1 --- a/tools/ioemu/patches/vnc-listen-specific-interface	Mon May 07 13:24:37 2007 -0600
    59.2 +++ b/tools/ioemu/patches/vnc-listen-specific-interface	Tue May 08 09:09:17 2007 -0600
    59.3 @@ -20,9 +20,9 @@ Signed-off-by:  Daniel P. Berrange <berr
    59.4  
    59.5  Index: ioemu/vl.c
    59.6  ===================================================================
    59.7 ---- ioemu.orig/vl.c	2006-12-20 15:21:52.000000000 +0000
    59.8 -+++ ioemu/vl.c	2006-12-20 15:21:52.000000000 +0000
    59.9 -@@ -122,6 +122,7 @@
   59.10 +--- ioemu.orig/vl.c	2007-05-03 10:24:06.000000000 +0100
   59.11 ++++ ioemu/vl.c	2007-05-03 10:24:06.000000000 +0100
   59.12 +@@ -123,6 +123,7 @@
   59.13   int nographic;
   59.14   int vncviewer;
   59.15   int vncunused;
   59.16 @@ -30,7 +30,7 @@ Index: ioemu/vl.c
   59.17   const char* keyboard_layout = NULL;
   59.18   int64_t ticks_per_sec;
   59.19   int boot_device = 'c';
   59.20 -@@ -2777,10 +2778,22 @@
   59.21 +@@ -2831,10 +2832,22 @@
   59.22       return -1;
   59.23   }
   59.24   
   59.25 @@ -54,7 +54,7 @@ Index: ioemu/vl.c
   59.26       const char *p, *r;
   59.27       int port;
   59.28   
   59.29 -@@ -2791,14 +2804,8 @@
   59.30 +@@ -2845,14 +2858,8 @@
   59.31       if (buf[0] == '\0') {
   59.32           saddr->sin_addr.s_addr = 0;
   59.33       } else {
   59.34 @@ -71,15 +71,15 @@ Index: ioemu/vl.c
   59.35       }
   59.36       port = strtol(p, (char **)&r, 0);
   59.37       if (r == p)
   59.38 -@@ -5344,6 +5351,7 @@
   59.39 +@@ -5419,6 +5426,7 @@
   59.40   	   "-vnc display    start a VNC server on display\n"
   59.41              "-vncviewer      start a vncviewer process for this domain\n"
   59.42              "-vncunused      bind the VNC server to an unused port\n"
   59.43  +           "-vnclisten      bind the VNC server to this address\n"
   59.44 -            "-timeoffset     time offset (in seconds) from local time\n"
   59.45              "-acpi           disable or enable ACPI of HVM domain \n"
   59.46              "\n"
   59.47 -@@ -5434,6 +5442,7 @@
   59.48 +            "During emulation, the following keys are useful:\n"
   59.49 +@@ -5507,6 +5515,7 @@
   59.50       QEMU_OPTION_acpi,
   59.51       QEMU_OPTION_vncviewer,
   59.52       QEMU_OPTION_vncunused,
   59.53 @@ -87,7 +87,7 @@ Index: ioemu/vl.c
   59.54   };
   59.55   
   59.56   typedef struct QEMUOption {
   59.57 -@@ -5510,6 +5519,7 @@
   59.58 +@@ -5583,6 +5592,7 @@
   59.59       { "vnc", HAS_ARG, QEMU_OPTION_vnc },
   59.60       { "vncviewer", 0, QEMU_OPTION_vncviewer },
   59.61       { "vncunused", 0, QEMU_OPTION_vncunused },
   59.62 @@ -95,7 +95,7 @@ Index: ioemu/vl.c
   59.63       
   59.64       /* temporary options */
   59.65       { "usb", 0, QEMU_OPTION_usb },
   59.66 -@@ -5889,6 +5899,8 @@
   59.67 +@@ -5974,6 +5984,8 @@
   59.68   
   59.69       nb_nics = 0;
   59.70       /* default mac address of the first network interface */
   59.71 @@ -104,7 +104,7 @@ Index: ioemu/vl.c
   59.72       
   59.73       /* init debug */
   59.74       sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm.%ld.log", (long)getpid());
   59.75 -@@ -6264,6 +6276,9 @@
   59.76 +@@ -6346,6 +6358,9 @@
   59.77                   if (vnc_display == -1)
   59.78                       vnc_display = 0;
   59.79                   break;
   59.80 @@ -114,7 +114,7 @@ Index: ioemu/vl.c
   59.81               }
   59.82           }
   59.83       }
   59.84 -@@ -6470,7 +6485,7 @@
   59.85 +@@ -6547,7 +6562,7 @@
   59.86       if (nographic) {
   59.87           dumb_display_init(ds);
   59.88       } else if (vnc_display != -1) {
   59.89 @@ -125,8 +125,8 @@ Index: ioemu/vl.c
   59.90       } else {
   59.91  Index: ioemu/vl.h
   59.92  ===================================================================
   59.93 ---- ioemu.orig/vl.h	2006-12-20 15:21:52.000000000 +0000
   59.94 -+++ ioemu/vl.h	2006-12-20 15:21:52.000000000 +0000
   59.95 +--- ioemu.orig/vl.h	2007-05-03 10:24:06.000000000 +0100
   59.96 ++++ ioemu/vl.h	2007-05-03 10:24:06.000000000 +0100
   59.97  @@ -37,6 +37,8 @@
   59.98   #include <unistd.h>
   59.99   #include <fcntl.h>
  59.100 @@ -147,8 +147,8 @@ Index: ioemu/vl.h
  59.101   /* ide.c */
  59.102  Index: ioemu/vnc.c
  59.103  ===================================================================
  59.104 ---- ioemu.orig/vnc.c	2006-12-20 15:21:52.000000000 +0000
  59.105 -+++ ioemu/vnc.c	2006-12-20 15:21:52.000000000 +0000
  59.106 +--- ioemu.orig/vnc.c	2007-05-03 10:24:06.000000000 +0100
  59.107 ++++ ioemu/vnc.c	2007-05-03 10:24:06.000000000 +0100
  59.108  @@ -1197,9 +1197,8 @@
  59.109       }
  59.110   }
    60.1 --- a/tools/ioemu/patches/vnc-password	Mon May 07 13:24:37 2007 -0600
    60.2 +++ b/tools/ioemu/patches/vnc-password	Tue May 08 09:09:17 2007 -0600
    60.3 @@ -17,8 +17,8 @@ Signed-off-by: Masami Watanabe <masami.w
    60.4  
    60.5  Index: ioemu/Makefile.target
    60.6  ===================================================================
    60.7 ---- ioemu.orig/Makefile.target	2006-12-20 15:21:55.000000000 +0000
    60.8 -+++ ioemu/Makefile.target	2006-12-20 15:21:55.000000000 +0000
    60.9 +--- ioemu.orig/Makefile.target	2007-05-03 15:23:43.000000000 +0100
   60.10 ++++ ioemu/Makefile.target	2007-05-03 15:23:43.000000000 +0100
   60.11  @@ -407,6 +407,7 @@
   60.12   VL_OBJS+=sdl.o
   60.13   endif
   60.14 @@ -39,9 +39,9 @@ Index: ioemu/Makefile.target
   60.15   
   60.16  Index: ioemu/vl.c
   60.17  ===================================================================
   60.18 ---- ioemu.orig/vl.c	2006-12-20 15:21:54.000000000 +0000
   60.19 -+++ ioemu/vl.c	2006-12-20 15:21:55.000000000 +0000
   60.20 -@@ -171,6 +171,9 @@
   60.21 +--- ioemu.orig/vl.c	2007-05-03 15:23:43.000000000 +0100
   60.22 ++++ ioemu/vl.c	2007-05-03 15:23:43.000000000 +0100
   60.23 +@@ -172,6 +172,9 @@
   60.24   char domain_name[1024] = { 'H','V', 'M', 'X', 'E', 'N', '-'};
   60.25   extern int domid;
   60.26   
   60.27 @@ -51,7 +51,7 @@ Index: ioemu/vl.c
   60.28   /***********************************************************/
   60.29   /* x86 ISA bus support */
   60.30   
   60.31 -@@ -5895,6 +5898,7 @@
   60.32 +@@ -5982,6 +5985,7 @@
   60.33       vncunused = 0;
   60.34       kernel_filename = NULL;
   60.35       kernel_cmdline = "";
   60.36 @@ -59,7 +59,7 @@ Index: ioemu/vl.c
   60.37   #ifndef CONFIG_DM
   60.38   #ifdef TARGET_PPC
   60.39       cdrom_index = 1;
   60.40 -@@ -6535,6 +6539,10 @@
   60.41 +@@ -6627,6 +6631,10 @@
   60.42   
   60.43       init_ioports();
   60.44   
   60.45 @@ -72,17 +72,17 @@ Index: ioemu/vl.c
   60.46           dumb_display_init(ds);
   60.47  Index: ioemu/vl.h
   60.48  ===================================================================
   60.49 ---- ioemu.orig/vl.h	2006-12-20 15:21:54.000000000 +0000
   60.50 -+++ ioemu/vl.h	2006-12-20 15:21:55.000000000 +0000
   60.51 -@@ -1214,6 +1214,7 @@
   60.52 +--- ioemu.orig/vl.h	2007-05-03 15:23:43.000000000 +0100
   60.53 ++++ ioemu/vl.h	2007-05-03 15:23:43.000000000 +0100
   60.54 +@@ -1215,6 +1215,7 @@
   60.55   void xenstore_process_event(void *opaque);
   60.56   void xenstore_check_new_media_present(int timeout);
   60.57   void xenstore_write_vncport(int vnc_display);
   60.58  +int xenstore_read_vncpasswd(int domid);
   60.59   
   60.60 - /* xen_platform.c */
   60.61 - void pci_xen_platform_init(PCIBus *bus);
   60.62 -@@ -1225,4 +1226,7 @@
   60.63 + int xenstore_vm_write(int domid, char *key, char *val);
   60.64 + char *xenstore_vm_read(int domid, char *key, int *len);
   60.65 +@@ -1233,4 +1234,7 @@
   60.66   
   60.67   void destroy_hvm_domain(void);
   60.68   
   60.69 @@ -92,8 +92,8 @@ Index: ioemu/vl.h
   60.70   #endif /* VL_H */
   60.71  Index: ioemu/vnc.c
   60.72  ===================================================================
   60.73 ---- ioemu.orig/vnc.c	2006-12-20 15:21:52.000000000 +0000
   60.74 -+++ ioemu/vnc.c	2006-12-20 15:21:55.000000000 +0000
   60.75 +--- ioemu.orig/vnc.c	2007-05-03 15:22:57.000000000 +0100
   60.76 ++++ ioemu/vnc.c	2007-05-03 15:23:43.000000000 +0100
   60.77  @@ -44,6 +44,7 @@
   60.78   
   60.79   #include "vnc_keysym.h"
   60.80 @@ -209,7 +209,7 @@ Index: ioemu/vnc.c
   60.81   
   60.82       return 0;
   60.83   }
   60.84 -@@ -1344,3 +1417,32 @@
   60.85 +@@ -1350,3 +1423,32 @@
   60.86   	return pid;
   60.87       }
   60.88   }
   60.89 @@ -244,13 +244,12 @@ Index: ioemu/vnc.c
   60.90  +}
   60.91  Index: ioemu/xenstore.c
   60.92  ===================================================================
   60.93 ---- ioemu.orig/xenstore.c	2006-12-20 15:21:54.000000000 +0000
   60.94 -+++ ioemu/xenstore.c	2006-12-20 15:21:55.000000000 +0000
   60.95 -@@ -213,3 +213,54 @@
   60.96 -     free(portstr);
   60.97 +--- ioemu.orig/xenstore.c	2007-05-03 15:23:43.000000000 +0100
   60.98 ++++ ioemu/xenstore.c	2007-05-03 15:24:09.000000000 +0100
   60.99 +@@ -253,6 +253,57 @@
  60.100       free(buf);
  60.101   }
  60.102 -+
  60.103 + 
  60.104  +int xenstore_read_vncpasswd(int domid)
  60.105  +{
  60.106  +    extern char vncpasswd[64];
  60.107 @@ -258,41 +257,41 @@ Index: ioemu/xenstore.c
  60.108  +    unsigned int i, len, rc = 0;
  60.109  +
  60.110  +    if (xsh == NULL) {
  60.111 -+	return -1;
  60.112 ++        return -1;
  60.113  +    }
  60.114  +
  60.115  +    path = xs_get_domain_path(xsh, domid);
  60.116  +    if (path == NULL) {
  60.117 -+	fprintf(logfile, "xs_get_domain_path() error. domid %d.\n", domid);
  60.118 -+	return -1;
  60.119 ++        fprintf(logfile, "xs_get_domain_path() error. domid %d.\n", domid);
  60.120 ++        return -1;
  60.121  +    }
  60.122  +
  60.123  +    pasprintf(&buf, "%s/vm", path);
  60.124  +    uuid = xs_read(xsh, XBT_NULL, buf, &len);
  60.125  +    if (uuid == NULL) {
  60.126 -+	fprintf(logfile, "xs_read(): uuid get error. %s.\n", buf);
  60.127 -+	free(path);
  60.128 -+	return -1;
  60.129 ++        fprintf(logfile, "xs_read(): uuid get error. %s.\n", buf);
  60.130 ++        free(path);
  60.131 ++        return -1;
  60.132  +    }
  60.133  +
  60.134  +    pasprintf(&buf, "%s/vncpasswd", uuid);
  60.135  +    passwd = xs_read(xsh, XBT_NULL, buf, &len);
  60.136  +    if (passwd == NULL) {
  60.137 -+	fprintf(logfile, "xs_read(): vncpasswd get error. %s.\n", buf);
  60.138 -+	free(uuid);
  60.139 -+	free(path);
  60.140 -+	return rc;
  60.141 ++        fprintf(logfile, "xs_read(): vncpasswd get error. %s.\n", buf);
  60.142 ++        free(uuid);
  60.143 ++        free(path);
  60.144 ++        return rc;
  60.145  +    }
  60.146  +
  60.147  +    for (i=0; i<len && i<63; i++) {
  60.148 -+	vncpasswd[i] = passwd[i];
  60.149 -+	passwd[i] = '\0';
  60.150 ++        vncpasswd[i] = passwd[i];
  60.151 ++        passwd[i] = '\0';
  60.152  +    }
  60.153  +    vncpasswd[len] = '\0';
  60.154  +    pasprintf(&buf, "%s/vncpasswd", uuid);
  60.155  +    if (xs_write(xsh, XBT_NULL, buf, passwd, len) == 0) {
  60.156 -+	fprintf(logfile, "xs_write() vncpasswd failed.\n");
  60.157 -+	rc = -1;
  60.158 ++        fprintf(logfile, "xs_write() vncpasswd failed.\n");
  60.159 ++        rc = -1;
  60.160  +    }
  60.161  +
  60.162  +    free(passwd);
  60.163 @@ -301,10 +300,14 @@ Index: ioemu/xenstore.c
  60.164  +
  60.165  +    return rc;
  60.166  +}
  60.167 ++
  60.168 + char *xenstore_vm_read(int domid, char *key, int *len)
  60.169 + {
  60.170 +     char *buf = NULL, *path = NULL, *value = NULL;
  60.171  Index: ioemu/d3des.c
  60.172  ===================================================================
  60.173  --- /dev/null	1970-01-01 00:00:00.000000000 +0000
  60.174 -+++ ioemu/d3des.c	2006-12-20 15:21:55.000000000 +0000
  60.175 ++++ ioemu/d3des.c	2007-05-03 15:23:43.000000000 +0100
  60.176  @@ -0,0 +1,434 @@
  60.177  +/*
  60.178  + * This is D3DES (V5.09) by Richard Outerbridge with the double and
  60.179 @@ -743,7 +746,7 @@ Index: ioemu/d3des.c
  60.180  Index: ioemu/d3des.h
  60.181  ===================================================================
  60.182  --- /dev/null	1970-01-01 00:00:00.000000000 +0000
  60.183 -+++ ioemu/d3des.h	2006-12-20 15:21:55.000000000 +0000
  60.184 ++++ ioemu/d3des.h	2007-05-03 15:23:43.000000000 +0100
  60.185  @@ -0,0 +1,51 @@
  60.186  +/*
  60.187  + * This is D3DES (V5.09) by Richard Outerbridge with the double and
    61.1 --- a/tools/ioemu/patches/vnc-start-vncviewer	Mon May 07 13:24:37 2007 -0600
    61.2 +++ b/tools/ioemu/patches/vnc-start-vncviewer	Tue May 08 09:09:17 2007 -0600
    61.3 @@ -1,15 +1,15 @@
    61.4  Index: ioemu/vnc.c
    61.5  ===================================================================
    61.6 ---- ioemu.orig/vnc.c	2006-12-20 15:21:51.000000000 +0000
    61.7 -+++ ioemu/vnc.c	2006-12-20 15:21:51.000000000 +0000
    61.8 -@@ -1189,3 +1189,25 @@
    61.9 +--- ioemu.orig/vnc.c	2007-05-03 10:24:06.000000000 +0100
   61.10 ++++ ioemu/vnc.c	2007-05-03 10:24:06.000000000 +0100
   61.11 +@@ -1189,3 +1189,31 @@
   61.12   
   61.13       vnc_dpy_resize(vs->ds, 640, 400);
   61.14   }
   61.15  +
   61.16  +int vnc_start_viewer(int port)
   61.17  +{
   61.18 -+    int pid;
   61.19 ++    int pid, i, open_max;
   61.20  +    char s[16];
   61.21  +
   61.22  +    sprintf(s, ":%d", port);
   61.23 @@ -20,6 +20,12 @@ Index: ioemu/vnc.c
   61.24  +	exit(1);
   61.25  +
   61.26  +    case 0:	/* child */
   61.27 ++	open_max = sysconf(_SC_OPEN_MAX);
   61.28 ++	for (i = 0; i < open_max; i++)
   61.29 ++	    if (i != STDIN_FILENO &&
   61.30 ++		i != STDOUT_FILENO &&
   61.31 ++		i != STDERR_FILENO)
   61.32 ++		close(i);
   61.33  +	execlp("vncviewer", "vncviewer", s, NULL);
   61.34  +	fprintf(stderr, "vncviewer execlp failed\n");
   61.35  +	exit(1);
   61.36 @@ -30,9 +36,9 @@ Index: ioemu/vnc.c
   61.37  +}
   61.38  Index: ioemu/vl.c
   61.39  ===================================================================
   61.40 ---- ioemu.orig/vl.c	2006-12-20 15:21:51.000000000 +0000
   61.41 -+++ ioemu/vl.c	2006-12-20 15:21:51.000000000 +0000
   61.42 -@@ -120,6 +120,7 @@
   61.43 +--- ioemu.orig/vl.c	2007-05-03 10:24:05.000000000 +0100
   61.44 ++++ ioemu/vl.c	2007-05-03 10:24:06.000000000 +0100
   61.45 +@@ -121,6 +121,7 @@
   61.46   int bios_size;
   61.47   static DisplayState display_state;
   61.48   int nographic;
   61.49 @@ -40,23 +46,23 @@ Index: ioemu/vl.c
   61.50   const char* keyboard_layout = NULL;
   61.51   int64_t ticks_per_sec;
   61.52   int boot_device = 'c';
   61.53 -@@ -5340,6 +5341,7 @@
   61.54 +@@ -5415,6 +5416,7 @@
   61.55   #endif
   61.56              "-loadvm file    start right away with a saved state (loadvm in monitor)\n"
   61.57   	   "-vnc display    start a VNC server on display\n"
   61.58  +           "-vncviewer      start a vncviewer process for this domain\n"
   61.59 -            "-timeoffset     time offset (in seconds) from local time\n"
   61.60              "-acpi           disable or enable ACPI of HVM domain \n"
   61.61              "\n"
   61.62 -@@ -5428,6 +5430,7 @@
   61.63 +            "During emulation, the following keys are useful:\n"
   61.64 +@@ -5501,6 +5503,7 @@
   61.65 +     QEMU_OPTION_d,
   61.66       QEMU_OPTION_vcpus,
   61.67 -     QEMU_OPTION_timeoffset,
   61.68       QEMU_OPTION_acpi,
   61.69  +    QEMU_OPTION_vncviewer,
   61.70   };
   61.71   
   61.72   typedef struct QEMUOption {
   61.73 -@@ -5502,6 +5505,7 @@
   61.74 +@@ -5575,6 +5578,7 @@
   61.75       { "usbdevice", HAS_ARG, QEMU_OPTION_usbdevice },
   61.76       { "smp", HAS_ARG, QEMU_OPTION_smp },
   61.77       { "vnc", HAS_ARG, QEMU_OPTION_vnc },
   61.78 @@ -64,7 +70,7 @@ Index: ioemu/vl.c
   61.79       
   61.80       /* temporary options */
   61.81       { "usb", 0, QEMU_OPTION_usb },
   61.82 -@@ -5852,6 +5856,7 @@
   61.83 +@@ -5933,6 +5937,7 @@
   61.84   #endif
   61.85       snapshot = 0;
   61.86       nographic = 0;
   61.87 @@ -72,7 +78,7 @@ Index: ioemu/vl.c
   61.88       kernel_filename = NULL;
   61.89       kernel_cmdline = "";
   61.90   #ifdef TARGET_PPC
   61.91 -@@ -6246,6 +6251,9 @@
   61.92 +@@ -6328,6 +6333,9 @@
   61.93               case QEMU_OPTION_acpi:
   61.94                   acpi_enabled = 1;
   61.95                   break;
   61.96 @@ -82,7 +88,7 @@ Index: ioemu/vl.c
   61.97               }
   61.98           }
   61.99       }
  61.100 -@@ -6453,6 +6461,8 @@
  61.101 +@@ -6530,6 +6538,8 @@
  61.102           dumb_display_init(ds);
  61.103       } else if (vnc_display != -1) {
  61.104   	vnc_display_init(ds, vnc_display);
  61.105 @@ -93,8 +99,8 @@ Index: ioemu/vl.c
  61.106           sdl_display_init(ds, full_screen);
  61.107  Index: ioemu/vl.h
  61.108  ===================================================================
  61.109 ---- ioemu.orig/vl.h	2006-12-20 15:21:51.000000000 +0000
  61.110 -+++ ioemu/vl.h	2006-12-20 15:21:51.000000000 +0000
  61.111 +--- ioemu.orig/vl.h	2007-05-03 10:24:05.000000000 +0100
  61.112 ++++ ioemu/vl.h	2007-05-03 10:24:06.000000000 +0100
  61.113  @@ -786,6 +786,7 @@
  61.114   
  61.115   /* vnc.c */
    62.1 --- a/tools/ioemu/patches/xen-build	Mon May 07 13:24:37 2007 -0600
    62.2 +++ b/tools/ioemu/patches/xen-build	Tue May 08 09:09:17 2007 -0600
    62.3 @@ -1,7 +1,7 @@
    62.4  Index: ioemu/Makefile
    62.5  ===================================================================
    62.6 ---- ioemu.orig/Makefile	2006-12-08 01:26:04.000000000 +0000
    62.7 -+++ ioemu/Makefile	2006-12-08 01:26:06.000000000 +0000
    62.8 +--- ioemu.orig/Makefile	2007-05-03 15:38:37.000000000 +0100
    62.9 ++++ ioemu/Makefile	2007-05-03 15:38:39.000000000 +0100
   62.10  @@ -1,11 +1,14 @@
   62.11   # Makefile for QEMU.
   62.12   
   62.13 @@ -41,7 +41,17 @@ Index: ioemu/Makefile
   62.14           done
   62.15   
   62.16   distclean: clean
   62.17 -@@ -68,12 +73,12 @@
   62.18 +@@ -60,24 +65,24 @@
   62.19 + 
   62.20 + install-doc: $(DOCS)
   62.21 + 	mkdir -p "$(DESTDIR)$(docdir)"
   62.22 +-	$(INSTALL) -m 644 qemu-doc.html  qemu-tech.html "$(DESTDIR)$(docdir)"
   62.23 ++	$(INSTALL_DATA) qemu-doc.html  qemu-tech.html "$(DESTDIR)$(docdir)"
   62.24 + ifndef CONFIG_WIN32
   62.25 + 	mkdir -p "$(DESTDIR)$(mandir)/man1"
   62.26 +-	$(INSTALL) qemu.1 qemu-img.1 "$(DESTDIR)$(mandir)/man1"
   62.27 ++	$(INSTALL_DATA) qemu.1 qemu-img.1 "$(DESTDIR)$(mandir)/man1"
   62.28 + endif
   62.29   
   62.30   install: all $(if $(BUILD_DOCS),install-doc)
   62.31   	mkdir -p "$(DESTDIR)$(bindir)"
   62.32 @@ -55,11 +65,16 @@ Index: ioemu/Makefile
   62.33  +#	mkdir -p "$(DESTDIR)$(datadir)"
   62.34  +#	for x in bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \
   62.35  +#			video.x openbios-sparc32 linux_boot.bin; do \
   62.36 -+#		$(INSTALL) -m 644 $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(datadir)"; \
   62.37 ++#		$(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(datadir)"; \
   62.38  +#	done
   62.39   ifndef CONFIG_WIN32
   62.40   	mkdir -p "$(DESTDIR)$(datadir)/keymaps"
   62.41   	for x in $(KEYMAPS); do \
   62.42 +-		$(INSTALL) -m 644 $(SRC_PATH)/keymaps/$$x "$(DESTDIR)$(datadir)/keymaps"; \
   62.43 ++		$(INSTALL_DATA) $(SRC_PATH)/keymaps/$$x "$(DESTDIR)$(datadir)/keymaps"; \
   62.44 + 	done
   62.45 + endif
   62.46 + 	for d in $(TARGET_DIRS); do \
   62.47  @@ -89,7 +94,7 @@
   62.48   	$(MAKE) -C tests $@
   62.49   
   62.50 @@ -85,8 +100,8 @@ Index: ioemu/Makefile
   62.51   info: qemu-doc.info qemu-tech.info
   62.52  Index: ioemu/Makefile.target
   62.53  ===================================================================
   62.54 ---- ioemu.orig/Makefile.target	2006-12-08 01:26:04.000000000 +0000
   62.55 -+++ ioemu/Makefile.target	2006-12-08 01:41:05.000000000 +0000
   62.56 +--- ioemu.orig/Makefile.target	2007-05-03 15:38:37.000000000 +0100
   62.57 ++++ ioemu/Makefile.target	2007-05-03 15:38:39.000000000 +0100
   62.58  @@ -1,5 +1,8 @@
   62.59   include config.mak
   62.60   
   62.61 @@ -163,8 +178,8 @@ Index: ioemu/Makefile.target
   62.62   include .depend
   62.63  Index: ioemu/configure
   62.64  ===================================================================
   62.65 ---- ioemu.orig/configure	2006-12-08 01:26:04.000000000 +0000
   62.66 -+++ ioemu/configure	2006-12-08 01:40:58.000000000 +0000
   62.67 +--- ioemu.orig/configure	2007-05-03 15:38:37.000000000 +0100
   62.68 ++++ ioemu/configure	2007-05-03 15:38:39.000000000 +0100
   62.69  @@ -18,8 +18,8 @@
   62.70   
   62.71   # default parameters
    63.1 --- a/tools/ioemu/patches/xen-domain-name	Mon May 07 13:24:37 2007 -0600
    63.2 +++ b/tools/ioemu/patches/xen-domain-name	Tue May 08 09:09:17 2007 -0600
    63.3 @@ -1,7 +1,7 @@
    63.4  Index: ioemu/sdl.c
    63.5  ===================================================================
    63.6 ---- ioemu.orig/sdl.c	2006-08-06 02:03:48.563137711 +0100
    63.7 -+++ ioemu/sdl.c	2006-08-06 02:17:16.063137816 +0100
    63.8 +--- ioemu.orig/sdl.c	2007-05-02 16:04:45.000000000 +0100
    63.9 ++++ ioemu/sdl.c	2007-05-02 16:05:51.000000000 +0100
   63.10  @@ -273,14 +273,14 @@
   63.11   static void sdl_update_caption(void)
   63.12   {
   63.13 @@ -21,8 +21,8 @@ Index: ioemu/sdl.c
   63.14   static void sdl_hide_cursor(void)
   63.15  Index: ioemu/vl.c
   63.16  ===================================================================
   63.17 ---- ioemu.orig/vl.c	2006-08-06 02:16:31.246133963 +0100
   63.18 -+++ ioemu/vl.c	2006-08-06 02:17:31.428424918 +0100
   63.19 +--- ioemu.orig/vl.c	2007-05-02 16:05:51.000000000 +0100
   63.20 ++++ ioemu/vl.c	2007-05-02 16:05:51.000000000 +0100
   63.21  @@ -158,6 +158,8 @@
   63.22   int acpi_enabled = 1;
   63.23   int fd_bootchk = 1;
   63.24 @@ -56,7 +56,7 @@ Index: ioemu/vl.c
   63.25       { "serial", 1, QEMU_OPTION_serial },
   63.26       { "parallel", 1, QEMU_OPTION_parallel },
   63.27       { "loadvm", HAS_ARG, QEMU_OPTION_loadvm },
   63.28 -@@ -6062,6 +6067,9 @@
   63.29 +@@ -6066,6 +6071,9 @@
   63.30               case QEMU_OPTION_no_acpi:
   63.31                   acpi_enabled = 0;
   63.32                   break;
   63.33 @@ -68,8 +68,8 @@ Index: ioemu/vl.c
   63.34       }
   63.35  Index: ioemu/vl.h
   63.36  ===================================================================
   63.37 ---- ioemu.orig/vl.h	2006-08-06 02:15:39.711878977 +0100
   63.38 -+++ ioemu/vl.h	2006-08-06 02:17:16.068137258 +0100
   63.39 +--- ioemu.orig/vl.h	2007-05-02 16:05:50.000000000 +0100
   63.40 ++++ ioemu/vl.h	2007-05-02 16:05:51.000000000 +0100
   63.41  @@ -1185,4 +1185,5 @@
   63.42   
   63.43   void kqemu_record_dump(void);
    64.1 --- a/tools/ioemu/patches/xen-domid	Mon May 07 13:24:37 2007 -0600
    64.2 +++ b/tools/ioemu/patches/xen-domid	Tue May 08 09:09:17 2007 -0600
    64.3 @@ -1,7 +1,7 @@
    64.4  Index: ioemu/vl.c
    64.5  ===================================================================
    64.6 ---- ioemu.orig/vl.c	2006-08-06 02:17:31.428424918 +0100
    64.7 -+++ ioemu/vl.c	2006-08-06 02:18:12.550840673 +0100
    64.8 +--- ioemu.orig/vl.c	2007-05-02 16:05:51.000000000 +0100
    64.9 ++++ ioemu/vl.c	2007-05-02 16:05:51.000000000 +0100
   64.10  @@ -159,6 +159,7 @@
   64.11   int fd_bootchk = 1;
   64.12   
   64.13 @@ -36,7 +36,7 @@ Index: ioemu/vl.c
   64.14       { NULL },
   64.15   };
   64.16   
   64.17 -@@ -6070,6 +6076,10 @@
   64.18 +@@ -6074,6 +6080,10 @@
   64.19               case QEMU_OPTION_domainname:
   64.20                   strncat(domain_name, optarg, sizeof(domain_name) - 20);
   64.21                   break;
    65.1 --- a/tools/ioemu/patches/xen-mapcache	Mon May 07 13:24:37 2007 -0600
    65.2 +++ b/tools/ioemu/patches/xen-mapcache	Tue May 08 09:09:17 2007 -0600
    65.3 @@ -17,44 +17,116 @@ Signed-off-by: Keir Fraser <keir@xensour
    65.4  
    65.5  Index: ioemu/vl.c
    65.6  ===================================================================
    65.7 ---- ioemu.orig/vl.c	2006-12-20 15:21:55.000000000 +0000
    65.8 -+++ ioemu/vl.c	2006-12-20 15:21:56.000000000 +0000
    65.9 -@@ -5808,6 +5808,91 @@
   65.10 +--- ioemu.orig/vl.c	2007-05-03 15:12:21.000000000 +0100
   65.11 ++++ ioemu/vl.c	2007-05-03 15:12:41.000000000 +0100
   65.12 +@@ -286,7 +286,7 @@
   65.13 +     for(i = start; i < start + length; i += size) {
   65.14 +         ioport_write_table[bsize][i] = func;
   65.15 +         if (ioport_opaque[i] != NULL && ioport_opaque[i] != opaque)
   65.16 +-            hw_error("register_ioport_read: invalid opaque");
   65.17 ++            hw_error("register_ioport_write: invalid opaque");
   65.18 +         ioport_opaque[i] = opaque;
   65.19 +     }
   65.20       return 0;
   65.21 +@@ -5894,6 +5894,157 @@
   65.22 +     suspend_requested = 1;
   65.23   }
   65.24   
   65.25 -+#if defined(__i386__) || defined(__x86_64__)
   65.26 ++#if defined(MAPCACHE)
   65.27 ++
   65.28 ++#if defined(__i386__) 
   65.29 ++#define MAX_MCACHE_SIZE    0x40000000 /* 1GB max for x86 */
   65.30 ++#define MCACHE_BUCKET_SHIFT 16
   65.31 ++#elif defined(__x86_64__)
   65.32 ++#define MAX_MCACHE_SIZE    0x1000000000 /* 64GB max for x86_64 */
   65.33 ++#define MCACHE_BUCKET_SHIFT 20
   65.34 ++#endif
   65.35 ++
   65.36 ++#define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT)
   65.37 ++
   65.38 ++#define BITS_PER_LONG (sizeof(long)*8)
   65.39 ++#define BITS_TO_LONGS(bits) \
   65.40 ++    (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
   65.41 ++#define DECLARE_BITMAP(name,bits) \
   65.42 ++    unsigned long name[BITS_TO_LONGS(bits)]
   65.43 ++#define test_bit(bit,map) \
   65.44 ++    (!!((map)[(bit)/BITS_PER_LONG] & (1UL << ((bit)%BITS_PER_LONG))))
   65.45 ++
   65.46 ++struct map_cache {
   65.47 ++    unsigned long paddr_index;
   65.48 ++    uint8_t      *vaddr_base;
   65.49 ++    DECLARE_BITMAP(valid_mapping, MCACHE_BUCKET_SIZE>>PAGE_SHIFT);
   65.50 ++};
   65.51 ++
   65.52  +static struct map_cache *mapcache_entry;
   65.53  +static unsigned long nr_buckets;
   65.54  +
   65.55 -+static int qemu_map_cache_init(unsigned long nr_pages)
   65.56 -+{
   65.57 -+    unsigned long max_pages = MAX_MCACHE_SIZE >> PAGE_SHIFT;
   65.58 -+    int i;
   65.59 ++/* For most cases (>99.9%), the page address is the same. */
   65.60 ++static unsigned long last_address_index = ~0UL;
   65.61 ++static uint8_t      *last_address_vaddr;
   65.62  +
   65.63 -+    if (nr_pages < max_pages)
   65.64 -+        max_pages = nr_pages;
   65.65 ++static int qemu_map_cache_init(void)
   65.66 ++{
   65.67 ++    unsigned long size;
   65.68  +
   65.69 -+    nr_buckets   = max_pages + (1UL << (MCACHE_BUCKET_SHIFT - PAGE_SHIFT)) - 1;
   65.70 -+    nr_buckets >>= (MCACHE_BUCKET_SHIFT - PAGE_SHIFT);
   65.71 ++    nr_buckets = (((MAX_MCACHE_SIZE >> PAGE_SHIFT) +
   65.72 ++                   (1UL << (MCACHE_BUCKET_SHIFT - PAGE_SHIFT)) - 1) >>
   65.73 ++                  (MCACHE_BUCKET_SHIFT - PAGE_SHIFT));
   65.74  +    fprintf(logfile, "qemu_map_cache_init nr_buckets = %lx\n", nr_buckets);
   65.75  +
   65.76 -+    mapcache_entry = malloc(nr_buckets * sizeof(struct map_cache));
   65.77 -+    if (mapcache_entry == NULL) {
   65.78 ++    /*
   65.79 ++     * Use mmap() directly: lets us allocate a big hash table with no up-front
   65.80 ++     * cost in storage space. The OS will allocate memory only for the buckets
   65.81 ++     * that we actually use. All others will contain all zeroes.
   65.82 ++     */
   65.83 ++    size = nr_buckets * sizeof(struct map_cache);
   65.84 ++    size = (size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
   65.85 ++    mapcache_entry = mmap(NULL, size, PROT_READ|PROT_WRITE,
   65.86 ++                          MAP_SHARED|MAP_ANONYMOUS, 0, 0);
   65.87 ++    if (mapcache_entry == MAP_FAILED) {
   65.88  +        errno = ENOMEM;
   65.89  +        return -1;
   65.90  +    }
   65.91  +
   65.92 -+    memset(mapcache_entry, 0, nr_buckets * sizeof(struct map_cache));
   65.93 ++    return 0;
   65.94 ++}
   65.95 ++
   65.96 ++static void qemu_remap_bucket(struct map_cache *entry,
   65.97 ++                              unsigned long address_index)
   65.98 ++{
   65.99 ++    uint8_t *vaddr_base;
  65.100 ++    unsigned long pfns[MCACHE_BUCKET_SIZE >> PAGE_SHIFT];
  65.101 ++    unsigned int i, j;
  65.102 ++
  65.103 ++    if (entry->vaddr_base != NULL) {
  65.104 ++        errno = munmap(entry->vaddr_base, MCACHE_BUCKET_SIZE);
  65.105 ++        if (errno) {
  65.106 ++            fprintf(logfile, "unmap fails %d\n", errno);
  65.107 ++            exit(-1);
  65.108 ++        }
  65.109 ++    }
  65.110  +
  65.111 -+    /*
  65.112 -+     * To avoid ENOMEM from xc_map_foreign_batch() at runtime, we
  65.113 -+     * pre-fill all the map caches in advance.
  65.114 -+     */
  65.115 -+    for (i = 0; i < nr_buckets; i++)
  65.116 -+       (void)qemu_map_cache(((target_phys_addr_t)i) << MCACHE_BUCKET_SHIFT);
  65.117 ++    for (i = 0; i < MCACHE_BUCKET_SIZE >> PAGE_SHIFT; i++)
  65.118 ++        pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-PAGE_SHIFT)) + i;
  65.119 ++
  65.120 ++    vaddr_base = xc_map_foreign_batch(xc_handle, domid, PROT_READ|PROT_WRITE,
  65.121 ++                                      pfns, MCACHE_BUCKET_SIZE >> PAGE_SHIFT);
  65.122 ++    if (vaddr_base == NULL) {
  65.123 ++        fprintf(logfile, "xc_map_foreign_batch error %d\n", errno);
  65.124 ++        exit(-1);
  65.125 ++    }
  65.126  +
  65.127 -+    return 0;
  65.128 ++    entry->vaddr_base  = vaddr_base;
  65.129 ++    entry->paddr_index = address_index;
  65.130 ++
  65.131 ++    for (i = 0; i < MCACHE_BUCKET_SIZE >> PAGE_SHIFT; i += BITS_PER_LONG) {
  65.132 ++        unsigned long word = 0;
  65.133 ++        j = ((i + BITS_PER_LONG) > (MCACHE_BUCKET_SIZE >> PAGE_SHIFT)) ?
  65.134 ++            (MCACHE_BUCKET_SIZE >> PAGE_SHIFT) % BITS_PER_LONG : BITS_PER_LONG;
  65.135 ++        while (j > 0)
  65.136 ++            word = (word << 1) | !(pfns[i + --j] & 0xF0000000UL);
  65.137 ++        entry->valid_mapping[i / BITS_PER_LONG] = word;
  65.138 ++    }
  65.139  +}
  65.140  +
  65.141  +uint8_t *qemu_map_cache(target_phys_addr_t phys_addr)
  65.142 @@ -63,55 +135,71 @@ Index: ioemu/vl.c
  65.143  +    unsigned long address_index  = phys_addr >> MCACHE_BUCKET_SHIFT;
  65.144  +    unsigned long address_offset = phys_addr & (MCACHE_BUCKET_SIZE-1);
  65.145  +
  65.146 -+    /* For most cases (>99.9%), the page address is the same. */
  65.147 -+    static unsigned long last_address_index = ~0UL;
  65.148 -+    static uint8_t      *last_address_vaddr;
  65.149 -+
  65.150  +    if (address_index == last_address_index)
  65.151  +        return last_address_vaddr + address_offset;
  65.152  +
  65.153  +    entry = &mapcache_entry[address_index % nr_buckets];
  65.154  +
  65.155 -+    if (entry->vaddr_base == NULL || entry->paddr_index != address_index) {
  65.156 -+        /* We need to remap a bucket. */
  65.157 -+        uint8_t *vaddr_base;
  65.158 -+        unsigned long pfns[MCACHE_BUCKET_SIZE >> PAGE_SHIFT];
  65.159 -+        unsigned int i;
  65.160 -+
  65.161 -+        if (entry->vaddr_base != NULL) {
  65.162 -+            errno = munmap(entry->vaddr_base, MCACHE_BUCKET_SIZE);
  65.163 -+            if (errno) {
  65.164 -+                fprintf(logfile, "unmap fails %d\n", errno);
  65.165 -+                exit(-1);
  65.166 -+            }
  65.167 -+        }
  65.168 ++    if (entry->vaddr_base == NULL || entry->paddr_index != address_index ||
  65.169 ++        !test_bit(address_offset>>PAGE_SHIFT, entry->valid_mapping))
  65.170 ++        qemu_remap_bucket(entry, address_index);
  65.171  +
  65.172 -+        for (i = 0; i < MCACHE_BUCKET_SIZE >> PAGE_SHIFT; i++)
  65.173 -+            pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-PAGE_SHIFT)) + i;
  65.174 -+
  65.175 -+        vaddr_base = xc_map_foreign_batch(
  65.176 -+            xc_handle, domid, PROT_READ|PROT_WRITE,
  65.177 -+            pfns, MCACHE_BUCKET_SIZE >> PAGE_SHIFT);
  65.178 -+        if (vaddr_base == NULL) {
  65.179 -+            fprintf(logfile, "xc_map_foreign_batch error %d\n", errno);
  65.180 -+            exit(-1);
  65.181 -+        }
  65.182 -+
  65.183 -+        entry->vaddr_base  = vaddr_base;
  65.184 -+        entry->paddr_index = address_index;;
  65.185 -+    }
  65.186 ++    if (!test_bit(address_offset>>PAGE_SHIFT, entry->valid_mapping))
  65.187 ++        return NULL;
  65.188  +
  65.189  +    last_address_index = address_index;
  65.190  +    last_address_vaddr = entry->vaddr_base;
  65.191  +
  65.192  +    return last_address_vaddr + address_offset;
  65.193  +}
  65.194 -+#endif
  65.195 ++
  65.196 ++void qemu_invalidate_map_cache(void)
  65.197 ++{
  65.198 ++    unsigned long i;
  65.199 ++
  65.200 ++    mapcache_lock();
  65.201 ++
  65.202 ++    for (i = 0; i < nr_buckets; i++) {
  65.203 ++        struct map_cache *entry = &mapcache_entry[i];
  65.204 ++
  65.205 ++        if (entry->vaddr_base == NULL)
  65.206 ++            continue;
  65.207 ++
  65.208 ++        errno = munmap(entry->vaddr_base, MCACHE_BUCKET_SIZE);
  65.209 ++        if (errno) {
  65.210 ++            fprintf(logfile, "unmap fails %d\n", errno);
  65.211 ++            exit(-1);
  65.212 ++        }
  65.213 ++
  65.214 ++        entry->paddr_index = 0;
  65.215 ++        entry->vaddr_base  = NULL;
  65.216 ++    }
  65.217 ++
  65.218 ++    last_address_index =  ~0UL;
  65.219 ++    last_address_vaddr = NULL;
  65.220 ++
  65.221 ++    mapcache_unlock();
  65.222 ++}
  65.223 ++
  65.224 ++#endif /* defined(MAPCACHE) */
  65.225  +
  65.226   int main(int argc, char **argv)
  65.227   {
  65.228   #ifdef CONFIG_GDBSTUB
  65.229 -@@ -6130,6 +6215,7 @@
  65.230 +@@ -5930,8 +6081,11 @@
  65.231 +     unsigned long ioreq_pfn;
  65.232 +     extern void *shared_page;
  65.233 +     extern void *buffered_io_page;
  65.234 +-    extern void *buffered_pio_page;
  65.235 ++#ifdef __ia64__
  65.236 +     unsigned long nr_pages;
  65.237 ++    xen_pfn_t *page_array;
  65.238 ++    extern void *buffered_pio_page;
  65.239 ++#endif
  65.240 + 
  65.241 +     char qemu_dm_logfilename[64];
  65.242 + 
  65.243 +@@ -6221,6 +6375,7 @@
  65.244                   break;
  65.245               case QEMU_OPTION_m:
  65.246                   ram_size = atol(optarg) * 1024 * 1024;
  65.247 @@ -119,75 +207,61 @@ Index: ioemu/vl.c
  65.248                   if (ram_size <= 0)
  65.249                       help();
  65.250   #ifndef CONFIG_DM
  65.251 -@@ -6404,50 +6490,41 @@
  65.252 -         shared_page_nr = nr_pages - 1;
  65.253 - #endif
  65.254 +@@ -6482,30 +6637,15 @@
  65.255 + 
  65.256 + #if defined(__i386__) || defined(__x86_64__)
  65.257   
  65.258 --    page_array = (xen_pfn_t *)malloc(tmp_nr_pages * sizeof(xen_pfn_t));
  65.259 +-    nr_pages = ram_size/PAGE_SIZE;
  65.260 +-
  65.261 +-    page_array = (xen_pfn_t *)malloc(nr_pages * sizeof(xen_pfn_t));
  65.262  -    if (page_array == NULL) {
  65.263  -        fprintf(logfile, "malloc returned error %d\n", errno);
  65.264  -        exit(-1);
  65.265  -    }
  65.266  -
  65.267 - #if defined(__i386__) || defined(__x86_64__)
  65.268 --    for ( i = 0; i < tmp_nr_pages; i++)
  65.269 +-    for ( i = 0; i < nr_pages; i++)
  65.270  -        page_array[i] = i;
  65.271 - 
  65.272 +-
  65.273  -    phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
  65.274  -                                         PROT_READ|PROT_WRITE, page_array,
  65.275 --                                         tmp_nr_pages);
  65.276 +-                                         nr_pages);
  65.277  -    if (phys_ram_base == NULL) {
  65.278  -        fprintf(logfile, "batch map guest memory returned error %d\n", errno);
  65.279 -+    if ( qemu_map_cache_init(tmp_nr_pages) )
  65.280 -+    {
  65.281 ++    if (qemu_map_cache_init()) {
  65.282  +        fprintf(logfile, "qemu_map_cache_init returned: error %d\n", errno);
  65.283           exit(-1);
  65.284       }
  65.285   
  65.286 +     xc_get_hvm_param(xc_handle, domid, HVM_PARAM_IOREQ_PFN, &ioreq_pfn);
  65.287 +     fprintf(logfile, "shared page at pfn %lx\n", ioreq_pfn);
  65.288       shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  65.289  -                                       PROT_READ|PROT_WRITE,
  65.290 --                                       page_array[shared_page_nr]);
  65.291 -+                                       PROT_READ|PROT_WRITE, shared_page_nr);
  65.292 +-                                       page_array[ioreq_pfn]);
  65.293 ++                                       PROT_READ|PROT_WRITE, ioreq_pfn);
  65.294       if (shared_page == NULL) {
  65.295           fprintf(logfile, "map shared IO page returned error %d\n", errno);
  65.296           exit(-1);
  65.297 -     }
  65.298 - 
  65.299 --    fprintf(logfile, "shared page at pfn:%lx, mfn: %"PRIx64"\n",
  65.300 --            shared_page_nr, (uint64_t)(page_array[shared_page_nr]));
  65.301 -+    fprintf(logfile, "shared page at pfn:%lx\n", shared_page_nr);
  65.302 - 
  65.303 +@@ -6514,15 +6654,12 @@
  65.304 +     xc_get_hvm_param(xc_handle, domid, HVM_PARAM_BUFIOREQ_PFN, &ioreq_pfn);
  65.305 +     fprintf(logfile, "buffered io page at pfn %lx\n", ioreq_pfn);
  65.306       buffered_io_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  65.307 -                                             PROT_READ|PROT_WRITE,
  65.308 --                                            page_array[shared_page_nr - 2]);
  65.309 -+                                            shared_page_nr - 2);
  65.310 +-                                            PROT_READ|PROT_WRITE,
  65.311 +-                                            page_array[ioreq_pfn]);
  65.312 ++                                            PROT_READ|PROT_WRITE, ioreq_pfn);
  65.313       if (buffered_io_page == NULL) {
  65.314           fprintf(logfile, "map buffered IO page returned error %d\n", errno);
  65.315           exit(-1);
  65.316       }
  65.317   
  65.318 --    fprintf(logfile, "buffered io page at pfn:%lx, mfn: %"PRIx64"\n",
  65.319 --            shared_page_nr - 2, (uint64_t)(page_array[shared_page_nr - 2]));
  65.320 +-    free(page_array);
  65.321  -
  65.322 --    free(page_array);
  65.323 -+    fprintf(logfile, "buffered io page at pfn:%lx\n", shared_page_nr - 2);
  65.324 - 
  65.325   #elif defined(__ia64__)
  65.326 --  
  65.327 -+
  65.328 -+    page_array = (xen_pfn_t *)malloc(tmp_nr_pages * sizeof(xen_pfn_t));
  65.329 -+    if (page_array == NULL) {
  65.330 -+        fprintf(logfile, "malloc returned error %d\n", errno);
  65.331 -+        exit(-1);
  65.332 -+    }
  65.333 -+
  65.334 -     shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  65.335 -                                        PROT_READ|PROT_WRITE,
  65.336 -                                        IO_PAGE_START >> PAGE_SHIFT);
  65.337 + 
  65.338 +     nr_pages = ram_size/PAGE_SIZE;
  65.339  Index: ioemu/target-i386-dm/exec-dm.c
  65.340  ===================================================================
  65.341 ---- ioemu.orig/target-i386-dm/exec-dm.c	2006-12-20 15:21:42.000000000 +0000
  65.342 -+++ ioemu/target-i386-dm/exec-dm.c	2006-12-21 11:32:29.000000000 +0000
  65.343 +--- ioemu.orig/target-i386-dm/exec-dm.c	2007-05-03 15:10:22.000000000 +0100
  65.344 ++++ ioemu/target-i386-dm/exec-dm.c	2007-05-03 15:12:34.000000000 +0100
  65.345  @@ -36,6 +36,7 @@
  65.346   
  65.347   #include "cpu.h"
  65.348 @@ -196,26 +270,14 @@ Index: ioemu/target-i386-dm/exec-dm.c
  65.349   
  65.350   //#define DEBUG_TB_INVALIDATE
  65.351   //#define DEBUG_FLUSH
  65.352 -@@ -127,10 +128,29 @@
  65.353 +@@ -127,10 +128,17 @@
  65.354   FILE *logfile;
  65.355   int loglevel;
  65.356   
  65.357 -+
  65.358 -+#if defined(__i386__) || defined(__x86_64__)
  65.359 -+#define MAPCACHE
  65.360 ++#ifdef MAPCACHE
  65.361 ++pthread_mutex_t mapcache_mutex;
  65.362  +#endif
  65.363  +
  65.364 -+#ifdef MAPCACHE
  65.365 -+#include <pthread.h>
  65.366 -+static pthread_mutex_t mapcache_mutex;
  65.367 -+#define mapcache_lock() pthread_mutex_lock(&mapcache_mutex)
  65.368 -+#define mapcache_unlock() pthread_mutex_unlock(&mapcache_mutex)
  65.369 -+#else 
  65.370 -+#define mapcache_lock() ( (void)0 )
  65.371 -+#define mapcache_unlock() ( (void)0 )
  65.372 -+#endif
  65.373 -+
  65.374 -+
  65.375   void cpu_exec_init(CPUState *env)
  65.376   {
  65.377       CPUState **penv;
  65.378 @@ -226,7 +288,7 @@ Index: ioemu/target-i386-dm/exec-dm.c
  65.379   
  65.380       env->next_cpu = NULL;
  65.381       penv = &first_cpu;
  65.382 -@@ -144,6 +164,14 @@
  65.383 +@@ -144,6 +152,14 @@
  65.384   
  65.385       /* alloc dirty bits array */
  65.386       phys_ram_dirty = qemu_malloc(phys_ram_size >> TARGET_PAGE_BITS);
  65.387 @@ -241,19 +303,28 @@ Index: ioemu/target-i386-dm/exec-dm.c
  65.388   }
  65.389   
  65.390   /* enable or disable low levels log */
  65.391 -@@ -426,19 +454,27 @@
  65.392 - #endif
  65.393 +@@ -409,16 +425,11 @@
  65.394 +         return 0;
  65.395   }
  65.396   
  65.397 +-static inline int paddr_is_ram(target_phys_addr_t addr)
  65.398 +-{
  65.399 +-    /* Is this guest physical address RAM-backed? */
  65.400 +-#if defined(CONFIG_DM) && (defined(__i386__) || defined(__x86_64__))
  65.401 +-    return ((addr < HVM_BELOW_4G_MMIO_START) ||
  65.402 +-            (addr >= HVM_BELOW_4G_MMIO_START + HVM_BELOW_4G_MMIO_LENGTH));
  65.403 +-#else
  65.404 +-    return (addr < ram_size);
  65.405  +#if defined(__i386__) || defined(__x86_64__)
  65.406  +#define phys_ram_addr(x) (qemu_map_cache(x))
  65.407  +#elif defined(__ia64__)
  65.408 -+#define phys_ram_addr(x) (phys_ram_base + (x))
  65.409 -+#endif
  65.410 -+
  65.411 ++#define phys_ram_addr(x) ((addr < ram_size) ? (phys_ram_base + (x)) : NULL)
  65.412 + #endif
  65.413 +-}
  65.414 + 
  65.415   void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, 
  65.416                               int len, int is_write)
  65.417 - {
  65.418 +@@ -426,13 +437,15 @@
  65.419       int l, io_index;
  65.420       uint8_t *ptr;
  65.421       uint32_t val;
  65.422 @@ -271,12 +342,14 @@ Index: ioemu/target-i386-dm/exec-dm.c
  65.423           io_index = iomem_index(addr);
  65.424           if (is_write) {
  65.425               if (io_index) {
  65.426 -@@ -460,9 +496,10 @@
  65.427 +@@ -452,11 +465,11 @@
  65.428 +                     io_mem_write[io_index][0](io_mem_opaque[io_index], addr, val);
  65.429 +                     l = 1;
  65.430                   }
  65.431 -             } else if (paddr_is_ram(addr)) {
  65.432 +-            } else if (paddr_is_ram(addr)) {
  65.433 ++            } else if ((ptr = phys_ram_addr(addr)) != NULL) {
  65.434                   /* Reading from RAM */
  65.435  -                memcpy(phys_ram_base + addr, buf, l);
  65.436 -+                ptr = phys_ram_addr(addr);
  65.437  +                memcpy(ptr, buf, l);
  65.438   #ifdef __ia64__
  65.439  -                sync_icache((unsigned long)(phys_ram_base + addr), l);
  65.440 @@ -284,17 +357,19 @@ Index: ioemu/target-i386-dm/exec-dm.c
  65.441   #endif 
  65.442               }
  65.443           } else {
  65.444 -@@ -485,7 +522,8 @@
  65.445 +@@ -477,9 +490,9 @@
  65.446 +                     stb_raw(buf, val);
  65.447 +                     l = 1;
  65.448                   }
  65.449 -             } else if (paddr_is_ram(addr)) {
  65.450 +-            } else if (paddr_is_ram(addr)) {
  65.451 ++            } else if ((ptr = phys_ram_addr(addr)) != NULL) {
  65.452                   /* Reading from RAM */
  65.453  -                memcpy(buf, phys_ram_base + addr, l);
  65.454 -+                ptr = phys_ram_addr(addr);
  65.455  +                memcpy(buf, ptr, l);
  65.456               } else {
  65.457                   /* Neither RAM nor known MMIO space */
  65.458                   memset(buf, 0xff, len); 
  65.459 -@@ -495,6 +533,8 @@
  65.460 +@@ -489,6 +502,8 @@
  65.461           buf += l;
  65.462           addr += l;
  65.463       }
  65.464 @@ -305,30 +380,32 @@ Index: ioemu/target-i386-dm/exec-dm.c
  65.465   
  65.466  Index: ioemu/vl.h
  65.467  ===================================================================
  65.468 ---- ioemu.orig/vl.h	2006-12-20 15:21:55.000000000 +0000
  65.469 -+++ ioemu/vl.h	2006-12-20 15:21:56.000000000 +0000
  65.470 -@@ -156,6 +156,26 @@
  65.471 +--- ioemu.orig/vl.h	2007-05-03 15:12:20.000000000 +0100
  65.472 ++++ ioemu/vl.h	2007-05-03 15:12:34.000000000 +0100
  65.473 +@@ -156,6 +156,28 @@
  65.474   
  65.475   extern FILE *logfile;
  65.476   
  65.477  +
  65.478  +#if defined(__i386__) || defined(__x86_64__)
  65.479 -+#if defined(__i386__) 
  65.480 -+#define MAX_MCACHE_SIZE    0x40000000 /* 1GB max for x86 */
  65.481 -+#define MCACHE_BUCKET_SHIFT 16
  65.482 -+#elif defined(__x86_64__)
  65.483 -+#define MAX_MCACHE_SIZE    0x1000000000 /* 64GB max for x86_64 */
  65.484 -+#define MCACHE_BUCKET_SHIFT 20
  65.485 -+#endif
  65.486  +
  65.487 -+#define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT)
  65.488 -+
  65.489 -+struct map_cache {
  65.490 -+    unsigned long paddr_index;
  65.491 -+    uint8_t      *vaddr_base;
  65.492 -+};
  65.493 ++#define MAPCACHE
  65.494  +
  65.495  +uint8_t *qemu_map_cache(target_phys_addr_t phys_addr);
  65.496 ++void     qemu_invalidate_map_cache(void);
  65.497 ++
  65.498 ++#include <pthread.h>
  65.499 ++extern  pthread_mutex_t mapcache_mutex;
  65.500 ++#define mapcache_lock() pthread_mutex_lock(&mapcache_mutex)
  65.501 ++#define mapcache_unlock() pthread_mutex_unlock(&mapcache_mutex)
  65.502 ++
  65.503 ++#else 
  65.504 ++
  65.505 ++#define qemu_invalidate_map_cache() ((void)0)
  65.506 ++
  65.507 ++#define mapcache_lock()   ((void)0)
  65.508 ++#define mapcache_unlock() ((void)0)
  65.509 ++
  65.510  +#endif
  65.511  +
  65.512   extern int xc_handle;
  65.513 @@ -336,8 +413,8 @@ Index: ioemu/vl.h
  65.514   
  65.515  Index: ioemu/target-i386-dm/cpu.h
  65.516  ===================================================================
  65.517 ---- ioemu.orig/target-i386-dm/cpu.h	2006-12-20 15:21:45.000000000 +0000
  65.518 -+++ ioemu/target-i386-dm/cpu.h	2006-12-20 15:21:56.000000000 +0000
  65.519 +--- ioemu.orig/target-i386-dm/cpu.h	2007-05-03 15:10:22.000000000 +0100
  65.520 ++++ ioemu/target-i386-dm/cpu.h	2007-05-03 15:12:21.000000000 +0100
  65.521  @@ -25,7 +25,8 @@
  65.522   #ifdef TARGET_X86_64
  65.523   #define TARGET_LONG_BITS 64
  65.524 @@ -348,3 +425,17 @@ Index: ioemu/target-i386-dm/cpu.h
  65.525   #endif
  65.526   
  65.527   /* target supports implicit self modifying code */
  65.528 +Index: ioemu/target-i386-dm/helper2.c
  65.529 +===================================================================
  65.530 +--- ioemu.orig/target-i386-dm/helper2.c	2007-05-03 15:12:19.000000000 +0100
  65.531 ++++ ioemu/target-i386-dm/helper2.c	2007-05-03 15:12:21.000000000 +0100
  65.532 +@@ -526,6 +526,9 @@
  65.533 +     case IOREQ_TYPE_TIMEOFFSET:
  65.534 +         cpu_ioreq_timeoffset(env, req);
  65.535 +         break;
  65.536 ++    case IOREQ_TYPE_INVALIDATE:
  65.537 ++        qemu_invalidate_map_cache();
  65.538 ++        break;
  65.539 +     default:
  65.540 +         hw_error("Invalid ioreq type 0x%x\n", req->type);
  65.541 +     }
    66.1 --- a/tools/ioemu/patches/xen-mm	Mon May 07 13:24:37 2007 -0600
    66.2 +++ b/tools/ioemu/patches/xen-mm	Tue May 08 09:09:17 2007 -0600
    66.3 @@ -1,7 +1,7 @@
    66.4  Index: ioemu/hw/pc.c
    66.5  ===================================================================
    66.6 ---- ioemu.orig/hw/pc.c	2006-12-08 02:00:38.000000000 +0000
    66.7 -+++ ioemu/hw/pc.c	2006-12-08 02:02:07.000000000 +0000
    66.8 +--- ioemu.orig/hw/pc.c	2007-05-03 09:54:24.000000000 +0100
    66.9 ++++ ioemu/hw/pc.c	2007-05-03 09:56:32.000000000 +0100
   66.10  @@ -646,7 +646,9 @@
   66.11       }
   66.12   
   66.13 @@ -25,9 +25,17 @@ Index: ioemu/hw/pc.c
   66.14       isa_bios_size = bios_size;
   66.15  Index: ioemu/vl.c
   66.16  ===================================================================
   66.17 ---- ioemu.orig/vl.c	2006-12-08 02:00:39.000000000 +0000
   66.18 -+++ ioemu/vl.c	2006-12-08 02:02:28.000000000 +0000
   66.19 -@@ -158,6 +158,8 @@
   66.20 +--- ioemu.orig/vl.c	2007-05-03 09:54:24.000000000 +0100
   66.21 ++++ ioemu/vl.c	2007-05-03 10:04:06.000000000 +0100
   66.22 +@@ -88,6 +88,7 @@
   66.23 + 
   66.24 + #include "exec-all.h"
   66.25 + 
   66.26 ++#include <xen/hvm/params.h>
   66.27 + #define DEFAULT_NETWORK_SCRIPT "/etc/xen/qemu-ifup"
   66.28 + 
   66.29 + //#define DEBUG_UNUSED_IOPORT
   66.30 +@@ -158,6 +159,8 @@
   66.31   int acpi_enabled = 1;
   66.32   int fd_bootchk = 1;
   66.33   
   66.34 @@ -36,17 +44,17 @@ Index: ioemu/vl.c
   66.35   char domain_name[1024] = { 'H','V', 'M', 'X', 'E', 'N', '-'};
   66.36   extern int domid;
   66.37   
   66.38 -@@ -5650,6 +5652,9 @@
   66.39 +@@ -5650,6 +5653,9 @@
   66.40       QEMUMachine *machine;
   66.41       char usb_devices[MAX_USB_CMDLINE][128];
   66.42       int usb_devices_index;
   66.43 -+    unsigned long nr_pages, tmp_nr_pages, shared_page_nr;
   66.44 -+    xen_pfn_t *page_array;
   66.45 ++    unsigned long ioreq_pfn;
   66.46  +    extern void *shared_page;
   66.47 ++    unsigned long nr_pages;
   66.48   
   66.49       char qemu_dm_logfilename[64];
   66.50   
   66.51 -@@ -5917,11 +5922,13 @@
   66.52 +@@ -5921,11 +5927,13 @@
   66.53                   ram_size = atol(optarg) * 1024 * 1024;
   66.54                   if (ram_size <= 0)
   66.55                       help();
   66.56 @@ -60,7 +68,7 @@ Index: ioemu/vl.c
   66.57                   break;
   66.58               case QEMU_OPTION_l:
   66.59                   {
   66.60 -@@ -6133,12 +6140,61 @@
   66.61 +@@ -6137,12 +6145,53 @@
   66.62       /* init the memory */
   66.63       phys_ram_size = ram_size + vga_ram_size + bios_size;
   66.64   
   66.65 @@ -68,45 +76,37 @@ Index: ioemu/vl.c
   66.66  +
   66.67  +    xc_handle = xc_interface_open();
   66.68  +
   66.69 -+    nr_pages = ram_size/PAGE_SIZE;
   66.70 -+    tmp_nr_pages = nr_pages;
   66.71 ++#if defined(__i386__) || defined(__x86_64__)
   66.72  +
   66.73 -+#if defined(__i386__) || defined(__x86_64__)
   66.74 -+    if (ram_size > HVM_BELOW_4G_RAM_END) {
   66.75 -+        tmp_nr_pages += HVM_BELOW_4G_MMIO_LENGTH >> PAGE_SHIFT;
   66.76 -+        shared_page_nr = (HVM_BELOW_4G_RAM_END >> PAGE_SHIFT) - 1;
   66.77 -+    } else
   66.78 -+        shared_page_nr = nr_pages - 1;
   66.79 -+#endif
   66.80 ++    nr_pages = ram_size/PAGE_SIZE;
   66.81  +
   66.82 -+    page_array = (xen_pfn_t *)malloc(tmp_nr_pages * sizeof(xen_pfn_t));
   66.83 ++    page_array = (xen_pfn_t *)malloc(nr_pages * sizeof(xen_pfn_t));
   66.84  +    if (page_array == NULL) {
   66.85  +        fprintf(logfile, "malloc returned error %d\n", errno);
   66.86  +        exit(-1);
   66.87  +    }
   66.88  +
   66.89 -+    for ( i = 0; i < tmp_nr_pages; i++)
   66.90 ++    for ( i = 0; i < nr_pages; i++)
   66.91  +        page_array[i] = i;
   66.92  +
   66.93  +    phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
   66.94  +                                         PROT_READ|PROT_WRITE, page_array,
   66.95 -+                                         tmp_nr_pages);
   66.96 ++                                         nr_pages);
   66.97  +    if (phys_ram_base == NULL) {
   66.98  +        fprintf(logfile, "batch map guest memory returned error %d\n", errno);
   66.99  +        exit(-1);
  66.100  +    }
  66.101  +
  66.102 ++    xc_get_hvm_param(xc_handle, domid, HVM_PARAM_IOREQ_PFN, &ioreq_pfn);
  66.103 ++    fprintf(logfile, "shared page at pfn %lx\n", ioreq_pfn);
  66.104  +    shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
  66.105  +                                       PROT_READ|PROT_WRITE,
  66.106 -+                                       page_array[shared_page_nr]);
  66.107 ++                                       page_array[ioreq_pfn]);
  66.108  +    if (shared_page == NULL) {
  66.109  +        fprintf(logfile, "map shared IO page returned error %d\n", errno);
  66.110  +        exit(-1);
  66.111  +    }
  66.112  +
  66.113 -+    fprintf(logfile, "shared page at pfn:%lx, mfn: %"PRIx64"\n",
  66.114 -+            shared_page_nr, (uint64_t)(page_array[shared_page_nr]));
  66.115 -+
  66.116  +    free(page_array);
  66.117  +
  66.118  +#else  /* !CONFIG_DM */
  66.119 @@ -124,8 +124,8 @@ Index: ioemu/vl.c
  66.120       if (cdrom_index >= 0) {
  66.121  Index: ioemu/hw/piix_pci.c
  66.122  ===================================================================
  66.123 ---- ioemu.orig/hw/piix_pci.c	2006-12-08 02:00:36.000000000 +0000
  66.124 -+++ ioemu/hw/piix_pci.c	2006-12-08 02:02:06.000000000 +0000
  66.125 +--- ioemu.orig/hw/piix_pci.c	2007-05-03 09:54:18.000000000 +0100
  66.126 ++++ ioemu/hw/piix_pci.c	2007-05-03 09:56:32.000000000 +0100
  66.127  @@ -399,7 +399,7 @@
  66.128       uint8_t elcr[2];
  66.129   
  66.130 @@ -137,8 +137,8 @@ Index: ioemu/hw/piix_pci.c
  66.131       elcr[0] = 0x00;
  66.132  Index: ioemu/vl.h
  66.133  ===================================================================
  66.134 ---- ioemu.orig/vl.h	2006-12-08 02:00:39.000000000 +0000
  66.135 -+++ ioemu/vl.h	2006-12-08 02:02:07.000000000 +0000
  66.136 +--- ioemu.orig/vl.h	2007-05-03 09:54:24.000000000 +0100
  66.137 ++++ ioemu/vl.h	2007-05-03 09:56:32.000000000 +0100
  66.138  @@ -39,6 +39,7 @@
  66.139   #include <sys/stat.h>
  66.140   #include "xenctrl.h"
    67.1 --- a/tools/ioemu/patches/xen-network	Mon May 07 13:24:37 2007 -0600
    67.2 +++ b/tools/ioemu/patches/xen-network	Tue May 08 09:09:17 2007 -0600
    67.3 @@ -1,16 +1,16 @@
    67.4  Index: ioemu/vl.c
    67.5  ===================================================================
    67.6 ---- ioemu.orig/vl.c	2006-08-06 02:22:01.556312045 +0100
    67.7 -+++ ioemu/vl.c	2006-08-06 02:22:53.925474246 +0100
    67.8 -@@ -89,6 +89,7 @@
    67.9 - #include "exec-all.h"
   67.10 +--- ioemu.orig/vl.c	2007-05-03 10:07:52.000000000 +0100
   67.11 ++++ ioemu/vl.c	2007-05-03 10:07:52.000000000 +0100
   67.12 +@@ -90,6 +90,7 @@
   67.13   
   67.14 + #include <xen/hvm/params.h>
   67.15   #define DEFAULT_NETWORK_SCRIPT "/etc/xen/qemu-ifup"
   67.16  +#define DEFAULT_BRIDGE "xenbr0"
   67.17   
   67.18   //#define DEBUG_UNUSED_IOPORT
   67.19   //#define DEBUG_IOPORT
   67.20 -@@ -3090,11 +3091,11 @@
   67.21 +@@ -3091,11 +3092,11 @@
   67.22   #endif
   67.23   
   67.24   static int net_tap_init(VLANState *vlan, const char *ifname1,
   67.25 @@ -24,7 +24,18 @@ Index: ioemu/vl.c
   67.26       char **parg;
   67.27       char ifname[128];
   67.28   
   67.29 -@@ -3116,6 +3117,7 @@
   67.30 +@@ -3114,9 +3115,18 @@
   67.31 +         pid = fork();
   67.32 +         if (pid >= 0) {
   67.33 +             if (pid == 0) {
   67.34 ++                int open_max = sysconf(_SC_OPEN_MAX), i;
   67.35 ++                for (i = 0; i < open_max; i++)
   67.36 ++                    if (i != STDIN_FILENO &&
   67.37 ++                        i != STDOUT_FILENO &&
   67.38 ++                        i != STDERR_FILENO &&
   67.39 ++                        i != fd)
   67.40 ++                        close(i);
   67.41 ++
   67.42                   parg = args;
   67.43                   *parg++ = (char *)setup_script;
   67.44                   *parg++ = ifname;
   67.45 @@ -32,7 +43,7 @@ Index: ioemu/vl.c
   67.46                   *parg++ = NULL;
   67.47                   execv(setup_script, args);
   67.48                   _exit(1);
   67.49 -@@ -3671,6 +3673,7 @@
   67.50 +@@ -3672,6 +3682,7 @@
   67.51       if (!strcmp(device, "tap")) {
   67.52           char ifname[64];
   67.53           char setup_script[1024];
   67.54 @@ -40,7 +51,7 @@ Index: ioemu/vl.c
   67.55           int fd;
   67.56           if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {
   67.57               fd = strtol(buf, NULL, 0);
   67.58 -@@ -3683,7 +3686,10 @@
   67.59 +@@ -3684,7 +3695,10 @@
   67.60               if (get_param_value(setup_script, sizeof(setup_script), "script", p) == 0) {
   67.61                   pstrcpy(setup_script, sizeof(setup_script), DEFAULT_NETWORK_SCRIPT);
   67.62               }
   67.63 @@ -52,7 +63,7 @@ Index: ioemu/vl.c
   67.64           }
   67.65       } else
   67.66   #endif
   67.67 -@@ -5208,7 +5214,7 @@
   67.68 +@@ -5209,7 +5223,7 @@
   67.69              "-net tap[,vlan=n],ifname=name\n"
   67.70              "                connect the host TAP network interface to VLAN 'n'\n"
   67.71   #else
    68.1 --- a/tools/ioemu/patches/xen-platform-device	Mon May 07 13:24:37 2007 -0600
    68.2 +++ b/tools/ioemu/patches/xen-platform-device	Tue May 08 09:09:17 2007 -0600
    68.3 @@ -3,8 +3,8 @@ will come later.
    68.4  
    68.5  Index: ioemu/Makefile.target
    68.6  ===================================================================
    68.7 ---- ioemu.orig/Makefile.target	2006-12-08 01:41:14.000000000 +0000
    68.8 -+++ ioemu/Makefile.target	2006-12-08 01:41:15.000000000 +0000
    68.9 +--- ioemu.orig/Makefile.target	2007-05-03 15:16:41.000000000 +0100
   68.10 ++++ ioemu/Makefile.target	2007-05-03 15:20:35.000000000 +0100
   68.11  @@ -360,6 +360,7 @@
   68.12   VL_OBJS+= usb-uhci.o
   68.13   VL_OBJS+= piix4acpi.o
   68.14 @@ -15,8 +15,8 @@ Index: ioemu/Makefile.target
   68.15   ifeq ($(TARGET_BASE_ARCH), ppc)
   68.16  Index: ioemu/hw/pc.c
   68.17  ===================================================================
   68.18 ---- ioemu.orig/hw/pc.c	2006-12-08 01:41:13.000000000 +0000
   68.19 -+++ ioemu/hw/pc.c	2006-12-08 01:41:15.000000000 +0000
   68.20 +--- ioemu.orig/hw/pc.c	2007-05-03 15:18:17.000000000 +0100
   68.21 ++++ ioemu/hw/pc.c	2007-05-03 15:20:35.000000000 +0100
   68.22  @@ -823,6 +823,9 @@
   68.23       }
   68.24   #endif /* !CONFIG_DM */
   68.25 @@ -30,8 +30,8 @@ Index: ioemu/hw/pc.c
   68.26  Index: ioemu/hw/xen_platform.c
   68.27  ===================================================================
   68.28  --- /dev/null	1970-01-01 00:00:00.000000000 +0000
   68.29 -+++ ioemu/hw/xen_platform.c	2006-12-08 01:41:15.000000000 +0000
   68.30 -@@ -0,0 +1,144 @@
   68.31 ++++ ioemu/hw/xen_platform.c	2007-05-03 15:18:17.000000000 +0100
   68.32 +@@ -0,0 +1,133 @@
   68.33  +/*
   68.34  + * XEN platform fake pci device, formerly known as the event channel device
   68.35  + * 
   68.36 @@ -63,21 +63,10 @@ Index: ioemu/hw/xen_platform.c
   68.37  +
   68.38  +extern FILE *logfile;
   68.39  +
   68.40 -+static void platform_ioport_write(void *opaque, uint32_t addr, uint32_t val)
   68.41 -+{
   68.42 -+    return;
   68.43 -+}
   68.44 -+
   68.45 -+static uint32_t platform_ioport_read(void *opaque, uint32_t addr)
   68.46 -+{
   68.47 -+    return 0;
   68.48 -+}
   68.49 -+
   68.50  +static void platform_ioport_map(PCIDevice *pci_dev, int region_num,
   68.51  +                                uint32_t addr, uint32_t size, int type)
   68.52  +{
   68.53 -+    register_ioport_write(addr, 16, 4, platform_ioport_write, NULL);
   68.54 -+    register_ioport_read(addr, 16, 1, platform_ioport_read, NULL);
   68.55 ++    /* nothing yet */
   68.56  +}
   68.57  +
   68.58  +static uint32_t platform_mmio_read(void *opaque, target_phys_addr_t addr)
   68.59 @@ -178,15 +167,16 @@ Index: ioemu/hw/xen_platform.c
   68.60  +}
   68.61  Index: ioemu/vl.h
   68.62  ===================================================================
   68.63 ---- ioemu.orig/vl.h	2006-12-08 01:41:14.000000000 +0000
   68.64 -+++ ioemu/vl.h	2006-12-08 01:41:15.000000000 +0000
   68.65 -@@ -1212,6 +1212,9 @@
   68.66 - void xenstore_check_new_media_present(int timeout);
   68.67 - void xenstore_write_vncport(int vnc_display);
   68.68 +--- ioemu.orig/vl.h	2007-05-03 15:18:17.000000000 +0100
   68.69 ++++ ioemu/vl.h	2007-05-03 15:20:39.000000000 +0100
   68.70 +@@ -1220,6 +1220,10 @@
   68.71 + extern long time_offset;
   68.72 + void timeoffset_get(void);
   68.73   
   68.74  +/* xen_platform.c */
   68.75  +void pci_xen_platform_init(PCIBus *bus);
   68.76  +
   68.77 - 
   68.78 ++
   68.79   void kqemu_record_dump(void);
   68.80   
   68.81 + extern char domain_name[];
    69.1 --- a/tools/ioemu/patches/xen-support-buffered-ioreqs	Mon May 07 13:24:37 2007 -0600
    69.2 +++ b/tools/ioemu/patches/xen-support-buffered-ioreqs	Tue May 08 09:09:17 2007 -0600
    69.3 @@ -1,38 +1,37 @@
    69.4  Index: ioemu/vl.c
    69.5  ===================================================================
    69.6 ---- ioemu.orig/vl.c	2006-12-20 15:21:54.000000000 +0000
    69.7 -+++ ioemu/vl.c	2006-12-20 15:21:54.000000000 +0000
    69.8 -@@ -5838,6 +5838,7 @@
    69.9 -     unsigned long nr_pages, tmp_nr_pages, shared_page_nr;
   69.10 -     xen_pfn_t *page_array;
   69.11 +--- ioemu.orig/vl.c	2007-05-03 15:09:21.000000000 +0100
   69.12 ++++ ioemu/vl.c	2007-05-03 15:09:48.000000000 +0100
   69.13 +@@ -5923,6 +5923,7 @@
   69.14 +     int usb_devices_index;
   69.15 +     unsigned long ioreq_pfn;
   69.16       extern void *shared_page;
   69.17  +    extern void *buffered_io_page;
   69.18 +     unsigned long nr_pages;
   69.19   
   69.20       char qemu_dm_logfilename[64];
   69.21 +@@ -6499,6 +6500,16 @@
   69.22 +         exit(-1);
   69.23 +     }
   69.24   
   69.25 -@@ -6422,6 +6423,17 @@
   69.26 -     fprintf(logfile, "shared page at pfn:%lx, mfn: %"PRIx64"\n",
   69.27 -             shared_page_nr, (uint64_t)(page_array[shared_page_nr]));
   69.28 - 
   69.29 ++    xc_get_hvm_param(xc_handle, domid, HVM_PARAM_BUFIOREQ_PFN, &ioreq_pfn);
   69.30 ++    fprintf(logfile, "buffered io page at pfn %lx\n", ioreq_pfn);
   69.31  +    buffered_io_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   69.32  +                                            PROT_READ|PROT_WRITE,
   69.33 -+                                            page_array[shared_page_nr - 2]);
   69.34 ++                                            page_array[ioreq_pfn]);
   69.35  +    if (buffered_io_page == NULL) {
   69.36  +        fprintf(logfile, "map buffered IO page returned error %d\n", errno);
   69.37  +        exit(-1);
   69.38  +    }
   69.39  +
   69.40 -+    fprintf(logfile, "buffered io page at pfn:%lx, mfn: %"PRIx64"\n",
   69.41 -+            shared_page_nr - 2, (uint64_t)(page_array[shared_page_nr - 2]));
   69.42 -+
   69.43       free(page_array);
   69.44   
   69.45   #elif defined(__ia64__)
   69.46  Index: ioemu/target-i386-dm/helper2.c
   69.47  ===================================================================
   69.48 ---- ioemu.orig/target-i386-dm/helper2.c	2006-12-20 15:21:47.000000000 +0000
   69.49 -+++ ioemu/target-i386-dm/helper2.c	2006-12-20 15:21:54.000000000 +0000
   69.50 -@@ -76,6 +76,10 @@
   69.51 +--- ioemu.orig/target-i386-dm/helper2.c	2007-05-03 15:09:21.000000000 +0100
   69.52 ++++ ioemu/target-i386-dm/helper2.c	2007-05-03 15:10:03.000000000 +0100
   69.53 +@@ -78,6 +78,10 @@
   69.54   
   69.55   shared_iopage_t *shared_page = NULL;
   69.56   
   69.57 @@ -43,7 +42,7 @@ Index: ioemu/target-i386-dm/helper2.c
   69.58   /* the evtchn fd for polling */
   69.59   int xce_handle = -1;
   69.60   
   69.61 -@@ -435,39 +439,71 @@
   69.62 +@@ -489,6 +493,72 @@
   69.63       req->data = tmp1;
   69.64   }
   69.65   
   69.66 @@ -65,12 +64,21 @@ Index: ioemu/target-i386-dm/helper2.c
   69.67  +    case IOREQ_TYPE_ADD:
   69.68  +        cpu_ioreq_add(env, req);
   69.69  +        break;
   69.70 ++    case IOREQ_TYPE_SUB:
   69.71 ++        cpu_ioreq_sub(env, req);
   69.72 ++        break;
   69.73  +    case IOREQ_TYPE_OR:
   69.74  +        cpu_ioreq_or(env, req);
   69.75  +        break;
   69.76  +    case IOREQ_TYPE_XOR:
   69.77  +        cpu_ioreq_xor(env, req);
   69.78  +        break;
   69.79 ++    case IOREQ_TYPE_XCHG:
   69.80 ++        cpu_ioreq_xchg(env, req);
   69.81 ++        break;
   69.82 ++    case IOREQ_TYPE_TIMEOFFSET:
   69.83 ++        cpu_ioreq_timeoffset(env, req);
   69.84 ++        break;
   69.85  +    default:
   69.86  +        hw_error("Invalid ioreq type 0x%x\n", req->type);
   69.87  +    }
   69.88 @@ -106,6 +114,8 @@ Index: ioemu/target-i386-dm/helper2.c
   69.89  +
   69.90   void cpu_handle_ioreq(void *opaque)
   69.91   {
   69.92 +     extern int vm_running;
   69.93 +@@ -496,43 +566,9 @@
   69.94       CPUState *env = opaque;
   69.95       ioreq_t *req = cpu_get_ioreq();
   69.96   
   69.97 @@ -129,12 +139,21 @@ Index: ioemu/target-i386-dm/helper2.c
   69.98  -        case IOREQ_TYPE_ADD:
   69.99  -            cpu_ioreq_add(env, req);
  69.100  -            break;
  69.101 +-        case IOREQ_TYPE_SUB:
  69.102 +-            cpu_ioreq_sub(env, req);
  69.103 +-            break;
  69.104  -        case IOREQ_TYPE_OR:
  69.105  -            cpu_ioreq_or(env, req);
  69.106  -            break;
  69.107  -        case IOREQ_TYPE_XOR:
  69.108  -            cpu_ioreq_xor(env, req);
  69.109  -            break;
  69.110 +-        case IOREQ_TYPE_XCHG:
  69.111 +-            cpu_ioreq_xchg(env, req);
  69.112 +-            break;
  69.113 +-	case IOREQ_TYPE_TIMEOFFSET:
  69.114 +-            cpu_ioreq_timeoffset(env, req);
  69.115 +-            break;
  69.116  -        default:
  69.117  -            hw_error("Invalid ioreq type 0x%x\n", req->type);
  69.118  -        }
  69.119 @@ -142,9 +161,9 @@ Index: ioemu/target-i386-dm/helper2.c
  69.120   
  69.121           if (req->state != STATE_IOREQ_INPROCESS) {
  69.122               fprintf(logfile, "Badness in I/O request ... not in service?!: "
  69.123 -@@ -492,6 +528,10 @@
  69.124 -     CPUState *env = cpu_single_env;
  69.125 +@@ -578,6 +614,10 @@
  69.126       int evtchn_fd = xc_evtchn_fd(xce_handle);
  69.127 +     char qemu_file[20];
  69.128   
  69.129  +    buffered_io_timer = qemu_new_timer(rt_clock, handle_buffered_io,
  69.130  +				       cpu_single_env);
  69.131 @@ -152,4 +171,12 @@ Index: ioemu/target-i386-dm/helper2.c
  69.132  +
  69.133       qemu_set_fd_handler(evtchn_fd, cpu_handle_ioreq, NULL, env);
  69.134   
  69.135 -     while (1) {
  69.136 +     while (!(vm_running && suspend_requested))
  69.137 +@@ -587,6 +627,7 @@
  69.138 +     fprintf(logfile, "device model received suspend signal!\n");
  69.139 + 
  69.140 +     /* Pull all outstanding ioreqs through the system */
  69.141 ++    handle_buffered_io(env);
  69.142 +     main_loop_wait(1); /* For the select() on events */
  69.143 + 
  69.144 +     /* Stop the IDE thread */
    70.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    70.2 +++ b/tools/ioemu/patches/xenstore	Tue May 08 09:09:17 2007 -0600
    70.3 @@ -0,0 +1,197 @@
    70.4 +Index: ioemu/xenstore.c
    70.5 +===================================================================
    70.6 +--- /dev/null	1970-01-01 00:00:00.000000000 +0000
    70.7 ++++ ioemu/xenstore.c	2007-05-03 15:17:52.000000000 +0100
    70.8 +@@ -0,0 +1,139 @@
    70.9 ++/*
   70.10 ++ * This file is subject to the terms and conditions of the GNU General
   70.11 ++ * Public License.  See the file "COPYING" in the main directory of
   70.12 ++ * this archive for more details.
   70.13 ++ *
   70.14 ++ * Copyright (C) 2006 Christian Limpach
   70.15 ++ * Copyright (C) 2006 XenSource Ltd.
   70.16 ++ *
   70.17 ++ */
   70.18 ++
   70.19 ++#include "vl.h"
   70.20 ++
   70.21 ++static struct xs_handle *xsh = NULL;
   70.22 ++
   70.23 ++static int pasprintf(char **buf, const char *fmt, ...)
   70.24 ++{
   70.25 ++    va_list ap;
   70.26 ++    int ret = 0;
   70.27 ++
   70.28 ++    if (*buf)
   70.29 ++        free(*buf);
   70.30 ++    va_start(ap, fmt);
   70.31 ++    if (vasprintf(buf, fmt, ap) == -1) {
   70.32 ++        buf = NULL;
   70.33 ++        ret = -1;
   70.34 ++    }
   70.35 ++    va_end(ap);
   70.36 ++    return ret;
   70.37 ++}
   70.38 ++
   70.39 ++void xenstore_parse_domain_config(int domid)
   70.40 ++{
   70.41 ++    char *path;
   70.42 ++
   70.43 ++    xsh = xs_daemon_open();
   70.44 ++    if (xsh == NULL) {
   70.45 ++        fprintf(logfile, "Could not contact xenstore for domain config\n");
   70.46 ++        return;
   70.47 ++    }
   70.48 ++
   70.49 ++    path = xs_get_domain_path(xsh, domid);
   70.50 ++    if (path == NULL) {
   70.51 ++        fprintf(logfile, "xs_get_domain_path() error\n");
   70.52 ++        goto out;
   70.53 ++    }
   70.54 ++
   70.55 ++ out:
   70.56 ++    free(path);
   70.57 ++    return;
   70.58 ++}
   70.59 ++
   70.60 ++int xenstore_fd(void)
   70.61 ++{
   70.62 ++    if (xsh)
   70.63 ++        return xs_fileno(xsh);
   70.64 ++    return -1;
   70.65 ++}
   70.66 ++
   70.67 ++void xenstore_process_event(void *opaque)
   70.68 ++{
   70.69 ++    char **vec;
   70.70 ++    unsigned int num;
   70.71 ++
   70.72 ++    vec = xs_read_watch(xsh, &num);
   70.73 ++    if (!vec)
   70.74 ++        return;
   70.75 ++
   70.76 ++ out:
   70.77 ++    free(vec);
   70.78 ++}
   70.79 ++
   70.80 ++char *xenstore_vm_read(int domid, char *key, int *len)
   70.81 ++{
   70.82 ++    char *buf = NULL, *path = NULL, *value = NULL;
   70.83 ++
   70.84 ++    if (xsh == NULL)
   70.85 ++        goto out;
   70.86 ++
   70.87 ++    path = xs_get_domain_path(xsh, domid);
   70.88 ++    if (path == NULL) {
   70.89 ++        fprintf(logfile, "xs_get_domain_path(%d): error\n", domid);
   70.90 ++        goto out;
   70.91 ++    }
   70.92 ++
   70.93 ++    pasprintf(&buf, "%s/vm", path);
   70.94 ++    free(path);
   70.95 ++    path = xs_read(xsh, XBT_NULL, buf, NULL);
   70.96 ++    if (path == NULL) {
   70.97 ++        fprintf(logfile, "xs_read(%s): read error\n", buf);
   70.98 ++        goto out;
   70.99 ++    }
  70.100 ++
  70.101 ++    pasprintf(&buf, "%s/%s", path, key);
  70.102 ++    value = xs_read(xsh, XBT_NULL, buf, len);
  70.103 ++    if (value == NULL) {
  70.104 ++        fprintf(logfile, "xs_read(%s): read error\n", buf);
  70.105 ++        goto out;
  70.106 ++    }
  70.107 ++
  70.108 ++ out:
  70.109 ++    free(path);
  70.110 ++    free(buf);
  70.111 ++    return value;
  70.112 ++}
  70.113 ++
  70.114 ++int xenstore_vm_write(int domid, char *key, char *value)
  70.115 ++{
  70.116 ++    char *buf = NULL, *path = NULL;
  70.117 ++    int rc = -1;
  70.118 ++
  70.119 ++    if (xsh == NULL)
  70.120 ++        goto out;
  70.121 ++
  70.122 ++    path = xs_get_domain_path(xsh, domid);
  70.123 ++    if (path == NULL) {
  70.124 ++        fprintf(logfile, "xs_get_domain_path: error\n");
  70.125 ++        goto out;
  70.126 ++    }
  70.127 ++
  70.128 ++    pasprintf(&buf, "%s/vm", path);
  70.129 ++    free(path);
  70.130 ++    path = xs_read(xsh, XBT_NULL, buf, NULL);
  70.131 ++    if (path == NULL) {
  70.132 ++        fprintf(logfile, "xs_read(%s): read error\n", buf);
  70.133 ++        goto out;
  70.134 ++    }
  70.135 ++
  70.136 ++    pasprintf(&buf, "%s/%s", path, key);
  70.137 ++    rc = xs_write(xsh, XBT_NULL, buf, value, strlen(value));
  70.138 ++    if (rc) {
  70.139 ++        fprintf(logfile, "xs_write(%s, %s): write error\n", buf, key);
  70.140 ++        goto out;
  70.141 ++    }
  70.142 ++
  70.143 ++ out:
  70.144 ++    free(path);
  70.145 ++    free(buf);
  70.146 ++    return rc;
  70.147 ++}
  70.148 +Index: ioemu/vl.h
  70.149 +===================================================================
  70.150 +--- ioemu.orig/vl.h	2007-05-03 15:15:40.000000000 +0100
  70.151 ++++ ioemu/vl.h	2007-05-03 15:18:00.000000000 +0100
  70.152 +@@ -1204,6 +1204,12 @@
  70.153 + void readline_start(const char *prompt, int is_password,
  70.154 +                     ReadLineFunc *readline_func, void *opaque);
  70.155 + 
  70.156 ++/* xenstore.c */
  70.157 ++void xenstore_parse_domain_config(int domid);
  70.158 ++
  70.159 ++int xenstore_vm_write(int domid, char *key, char *val);
  70.160 ++char *xenstore_vm_read(int domid, char *key, int *len);
  70.161 ++
  70.162 + void kqemu_record_dump(void);
  70.163 + 
  70.164 + extern char domain_name[];
  70.165 +Index: ioemu/Makefile.target
  70.166 +===================================================================
  70.167 +--- ioemu.orig/Makefile.target	2007-05-03 15:15:39.000000000 +0100
  70.168 ++++ ioemu/Makefile.target	2007-05-03 15:16:41.000000000 +0100
  70.169 +@@ -359,6 +359,7 @@
  70.170 + VL_OBJS+= cirrus_vga.o mixeng.o parallel.o acpi.o piix_pci.o
  70.171 + VL_OBJS+= usb-uhci.o
  70.172 + VL_OBJS+= piix4acpi.o
  70.173 ++VL_OBJS+= xenstore.o
  70.174 + DEFINES += -DHAS_AUDIO
  70.175 + endif
  70.176 + ifeq ($(TARGET_BASE_ARCH), ppc)
  70.177 +Index: ioemu/vl.c
  70.178 +===================================================================
  70.179 +--- ioemu.orig/vl.c	2007-05-03 15:15:40.000000000 +0100
  70.180 ++++ ioemu/vl.c	2007-05-03 15:17:52.000000000 +0100
  70.181 +@@ -6371,6 +6371,10 @@
  70.182 +         }
  70.183 +     }
  70.184 + 
  70.185 ++#ifdef CONFIG_DM
  70.186 ++    xenstore_parse_domain_config(domid);
  70.187 ++#endif /* CONFIG_DM */
  70.188 ++
  70.189 + #ifdef USE_KQEMU
  70.190 +     if (smp_cpus > 1)
  70.191 +         kqemu_allowed = 0;
  70.192 +@@ -6624,6 +6628,8 @@
  70.193 +         }
  70.194 +     }
  70.195 + 
  70.196 ++    qemu_set_fd_handler(xenstore_fd(), xenstore_process_event, NULL, NULL);
  70.197 ++
  70.198 +     machine->init(ram_size, vga_ram_size, boot_device,
  70.199 +                   ds, fd_filename, snapshot,
  70.200 +                   kernel_filename, kernel_cmdline, initrd_filename);
    71.1 --- a/tools/ioemu/patches/xenstore-block-device-config	Mon May 07 13:24:37 2007 -0600
    71.2 +++ b/tools/ioemu/patches/xenstore-block-device-config	Tue May 08 09:09:17 2007 -0600
    71.3 @@ -1,63 +1,37 @@
    71.4 -Index: ioemu/Makefile.target
    71.5 -===================================================================
    71.6 ---- ioemu.orig/Makefile.target	2006-12-20 15:21:51.000000000 +0000
    71.7 -+++ ioemu/Makefile.target	2006-12-20 15:21:53.000000000 +0000
    71.8 -@@ -359,6 +359,7 @@
    71.9 - VL_OBJS+= cirrus_vga.o mixeng.o parallel.o acpi.o piix_pci.o
   71.10 - VL_OBJS+= usb-uhci.o
   71.11 - VL_OBJS+= piix4acpi.o
   71.12 -+VL_OBJS+= xenstore.o
   71.13 - DEFINES += -DHAS_AUDIO
   71.14 - endif
   71.15 - ifeq ($(TARGET_BASE_ARCH), ppc)
   71.16  Index: ioemu/xenstore.c
   71.17  ===================================================================
   71.18 ---- /dev/null	1970-01-01 00:00:00.000000000 +0000
   71.19 -+++ ioemu/xenstore.c	2006-12-20 15:21:53.000000000 +0000
   71.20 -@@ -0,0 +1,187 @@
   71.21 -+/*
   71.22 -+ * This file is subject to the terms and conditions of the GNU General
   71.23 -+ * Public License.  See the file "COPYING" in the main directory of
   71.24 -+ * this archive for more details.
   71.25 -+ *
   71.26 -+ * Copyright (C) 2006 Christian Limpach
   71.27 -+ * Copyright (C) 2006 XenSource Ltd.
   71.28 -+ *
   71.29 -+ */
   71.30 -+
   71.31 -+#include "vl.h"
   71.32 +--- ioemu.orig/xenstore.c	2007-05-03 15:17:52.000000000 +0100
   71.33 ++++ ioemu/xenstore.c	2007-05-03 15:18:05.000000000 +0100
   71.34 +@@ -9,8 +9,15 @@
   71.35 +  */
   71.36 + 
   71.37 + #include "vl.h"
   71.38  +#include "block_int.h"
   71.39 -+
   71.40 -+static struct xs_handle *xsh = NULL;
   71.41 -+static char *hd_filename[MAX_DISKS];
   71.42 ++#include <unistd.h>
   71.43 + 
   71.44 + static struct xs_handle *xsh = NULL;
   71.45 ++static char *media_filename[MAX_DISKS];
   71.46  +static QEMUTimer *insert_timer = NULL;
   71.47  +
   71.48 -+static int pasprintf(char **buf, const char *fmt, ...)
   71.49 -+{
   71.50 -+    va_list ap;
   71.51 -+    int ret = 0;
   71.52 -+
   71.53 -+    if (*buf)
   71.54 -+	free(*buf);
   71.55 -+    va_start(ap, fmt);
   71.56 -+    if (vasprintf(buf, fmt, ap) == -1) {
   71.57 -+	buf = NULL;
   71.58 -+	ret = -1;
   71.59 -+    }
   71.60 -+    va_end(ap);
   71.61 -+    return ret;
   71.62 -+}
   71.63 -+
   71.64 ++#define UWAIT_MAX (30*1000000) /* thirty seconds */
   71.65 ++#define UWAIT     (100000)     /* 1/10th second  */
   71.66 + 
   71.67 + static int pasprintf(char **buf, const char *fmt, ...)
   71.68 + {
   71.69 +@@ -28,9 +35,54 @@
   71.70 +     return ret;
   71.71 + }
   71.72 + 
   71.73  +static void insert_media(void *opaque)
   71.74  +{
   71.75  +    int i;
   71.76  +
   71.77  +    for (i = 0; i < MAX_DISKS; i++) {
   71.78 -+	if (hd_filename[i]) {
   71.79 -+	    do_change(bs_table[i]->device_name, hd_filename[i]);
   71.80 -+	    free(hd_filename[i]);
   71.81 -+	    hd_filename[i] = NULL;
   71.82 -+	}
   71.83 ++        if (media_filename[i] && bs_table[i]) {
   71.84 ++            do_change(bs_table[i]->device_name, media_filename[i]);
   71.85 ++            free(media_filename[i]);
   71.86 ++            media_filename[i] = NULL;
   71.87 ++        }
   71.88  +    }
   71.89  +}
   71.90  +
   71.91 @@ -65,148 +39,176 @@ Index: ioemu/xenstore.c
   71.92  +{
   71.93  +
   71.94  +    if (insert_timer == NULL)
   71.95 -+	insert_timer = qemu_new_timer(rt_clock, insert_media, NULL);
   71.96 ++        insert_timer = qemu_new_timer(rt_clock, insert_media, NULL);
   71.97  +    qemu_mod_timer(insert_timer, qemu_get_clock(rt_clock) + timeout);
   71.98  +}
   71.99  +
  71.100 -+void xenstore_parse_domain_config(int domid)
  71.101 -+{
  71.102 ++static void waitForDevice(char *fn)
  71.103 ++{ 
  71.104 ++    struct stat sbuf;
  71.105 ++    int status;
  71.106 ++    int uwait = UWAIT_MAX;
  71.107 ++
  71.108 ++    do {
  71.109 ++        status = stat(fn, &sbuf);
  71.110 ++        if (!status) break;
  71.111 ++        usleep(UWAIT);
  71.112 ++        uwait -= UWAIT;
  71.113 ++    } while (uwait > 0);
  71.114 ++
  71.115 ++    return;
  71.116 ++}
  71.117 ++
  71.118 + void xenstore_parse_domain_config(int domid)
  71.119 + {
  71.120 +-    char *path;
  71.121  +    char **e = NULL;
  71.122  +    char *buf = NULL, *path;
  71.123 -+    char *bpath = NULL, *dev = NULL, *params = NULL, *type = NULL;
  71.124 ++    char *fpath = NULL, *bpath = NULL,
  71.125 ++        *dev = NULL, *params = NULL, *type = NULL;
  71.126  +    int i;
  71.127  +    unsigned int len, num, hd_index;
  71.128  +
  71.129  +    for(i = 0; i < MAX_DISKS; i++)
  71.130 -+        hd_filename[i] = NULL;
  71.131 -+
  71.132 -+    xsh = xs_daemon_open();
  71.133 -+    if (xsh == NULL) {
  71.134 -+	fprintf(logfile, "Could not contact xenstore for domain config\n");
  71.135 -+	return;
  71.136 -+    }
  71.137 -+
  71.138 -+    path = xs_get_domain_path(xsh, domid);
  71.139 -+    if (path == NULL) {
  71.140 -+        fprintf(logfile, "xs_get_domain_path() error\n");
  71.141 ++        media_filename[i] = NULL;
  71.142 + 
  71.143 +     xsh = xs_daemon_open();
  71.144 +     if (xsh == NULL) {
  71.145 +@@ -44,8 +96,91 @@
  71.146 +         goto out;
  71.147 +     }
  71.148 + 
  71.149 ++    if (pasprintf(&buf, "%s/device/vbd", path) == -1)
  71.150  +        goto out;
  71.151 -+    }
  71.152 -+
  71.153 -+    if (pasprintf(&buf, "%s/device/vbd", path) == -1)
  71.154 -+	goto out;
  71.155  +
  71.156  +    e = xs_directory(xsh, XBT_NULL, buf, &num);
  71.157  +    if (e == NULL)
  71.158 -+	goto out;
  71.159 ++        goto out;
  71.160  +
  71.161  +    for (i = 0; i < num; i++) {
  71.162 -+	/* read the backend path */
  71.163 -+	if (pasprintf(&buf, "%s/device/vbd/%s/backend", path, e[i]) == -1)
  71.164 -+	    continue;
  71.165 -+	free(bpath);
  71.166 ++        /* read the backend path */
  71.167 ++        if (pasprintf(&buf, "%s/device/vbd/%s/backend", path, e[i]) == -1)
  71.168 ++            continue;
  71.169 ++        free(bpath);
  71.170  +        bpath = xs_read(xsh, XBT_NULL, buf, &len);
  71.171 -+	if (bpath == NULL)
  71.172 -+	    continue;
  71.173 -+	/* read the name of the device */
  71.174 -+	if (pasprintf(&buf, "%s/dev", bpath) == -1)
  71.175 -+	    continue;
  71.176 -+	free(dev);
  71.177 -+	dev = xs_read(xsh, XBT_NULL, buf, &len);
  71.178 -+	if (dev == NULL)
  71.179 -+	    continue;
  71.180 -+	if (strncmp(dev, "hd", 2) || strlen(dev) != 3)
  71.181 -+	    continue;
  71.182 -+	hd_index = dev[2] - 'a';
  71.183 -+	if (hd_index >= MAX_DISKS)
  71.184 -+	    continue;
  71.185 -+	/* read the type of the device */
  71.186 -+	if (pasprintf(&buf, "%s/device/vbd/%s/device-type", path, e[i]) == -1)
  71.187 -+	    continue;
  71.188 -+	free(type);
  71.189 -+	type = xs_read(xsh, XBT_NULL, buf, &len);
  71.190 -+	/* read params to get the patch of the image -- read it last
  71.191 -+	 * so that we have its path in buf when setting up the
  71.192 -+	 * watch */
  71.193 -+	if (pasprintf(&buf, "%s/params", bpath) == -1)
  71.194 -+	    continue;
  71.195 -+	free(params);
  71.196 -+	params = xs_read(xsh, XBT_NULL, buf, &len);
  71.197 -+	if (params == NULL)
  71.198 -+	    continue;
  71.199 -+	if (params[0]) {
  71.200 -+	    hd_filename[hd_index] = params;	/* strdup() */
  71.201 -+	    params = NULL;		/* don't free params on re-use */
  71.202 -+	}
  71.203 -+	bs_table[hd_index] = bdrv_new(dev);
  71.204 -+	/* check if it is a cdrom */
  71.205 -+	if (type && !strcmp(type, "cdrom")) {
  71.206 -+	    bdrv_set_type_hint(bs_table[hd_index], BDRV_TYPE_CDROM);
  71.207 -+	    xs_watch(xsh, buf, dev);
  71.208 -+	}
  71.209 -+	if (hd_filename[hd_index]) {
  71.210 -+            if (bdrv_open(bs_table[hd_index], hd_filename[hd_index],
  71.211 -+			  0 /* snapshot */) < 0)
  71.212 ++        if (bpath == NULL)
  71.213 ++            continue;
  71.214 ++        /* read the name of the device */
  71.215 ++        if (pasprintf(&buf, "%s/dev", bpath) == -1)
  71.216 ++            continue;
  71.217 ++        free(dev);
  71.218 ++        dev = xs_read(xsh, XBT_NULL, buf, &len);
  71.219 ++        if (dev == NULL)
  71.220 ++            continue;
  71.221 ++        if (strncmp(dev, "hd", 2) || strlen(dev) != 3)
  71.222 ++            continue;
  71.223 ++        hd_index = dev[2] - 'a';
  71.224 ++        if (hd_index >= MAX_DISKS)
  71.225 ++            continue;
  71.226 ++        /* read the type of the device */
  71.227 ++        if (pasprintf(&buf, "%s/device/vbd/%s/device-type", path, e[i]) == -1)
  71.228 ++            continue;
  71.229 ++        free(type);
  71.230 ++        type = xs_read(xsh, XBT_NULL, buf, &len);
  71.231 ++        if (pasprintf(&buf, "%s/params", bpath) == -1)
  71.232 ++            continue;
  71.233 ++        free(params);
  71.234 ++        params = xs_read(xsh, XBT_NULL, buf, &len);
  71.235 ++        if (params == NULL)
  71.236 ++            continue;
  71.237 ++        /* 
  71.238 ++         * check if device has a phantom vbd; the phantom is hooked
  71.239 ++         * to the frontend device (for ease of cleanup), so lookup 
  71.240 ++         * the frontend device, and see if there is a phantom_vbd
  71.241 ++         * if there is, we will use resolution as the filename
  71.242 ++         */
  71.243 ++        if (pasprintf(&buf, "%s/device/vbd/%s/phantom_vbd", path, e[i]) == -1)
  71.244 ++            continue;
  71.245 ++        free(fpath);
  71.246 ++        fpath = xs_read(xsh, XBT_NULL, buf, &len);
  71.247 ++        if (fpath) {
  71.248 ++            if (pasprintf(&buf, "%s/dev", fpath) == -1)
  71.249 ++                continue;
  71.250 ++            free(params);
  71.251 ++            params = xs_read(xsh, XBT_NULL, buf , &len);
  71.252 ++            if (params) {
  71.253 ++                /* 
  71.254 ++                 * wait for device, on timeout silently fail because we will 
  71.255 ++                 * fail to open below
  71.256 ++                 */
  71.257 ++                waitForDevice(params);
  71.258 ++            }
  71.259 ++        }
  71.260 ++
  71.261 ++        bs_table[hd_index] = bdrv_new(dev);
  71.262 ++        /* check if it is a cdrom */
  71.263 ++        if (type && !strcmp(type, "cdrom")) {
  71.264 ++            bdrv_set_type_hint(bs_table[hd_index], BDRV_TYPE_CDROM);
  71.265 ++            if (pasprintf(&buf, "%s/params", bpath) != -1)
  71.266 ++                xs_watch(xsh, buf, dev);
  71.267 ++        }
  71.268 ++        /* open device now if media present */
  71.269 ++        if (params[0]) {
  71.270 ++            if (bdrv_open(bs_table[hd_index], params, 0 /* snapshot */) < 0)
  71.271  +                fprintf(stderr, "qemu: could not open hard disk image '%s'\n",
  71.272 -+                        hd_filename[hd_index]);
  71.273 -+	}
  71.274 ++                        params);
  71.275 ++        }
  71.276  +    }
  71.277  +
  71.278 -+ out:
  71.279 +  out:
  71.280  +    free(type);
  71.281  +    free(params);
  71.282  +    free(dev);
  71.283  +    free(bpath);
  71.284  +    free(buf);
  71.285 -+    free(path);
  71.286 +     free(path);
  71.287  +    free(e);
  71.288 -+    return;
  71.289 -+}
  71.290 -+
  71.291 -+int xenstore_fd(void)
  71.292 -+{
  71.293 -+    if (xsh)
  71.294 -+	return xs_fileno(xsh);
  71.295 -+    return -1;
  71.296 -+}
  71.297 -+
  71.298 -+void xenstore_process_event(void *opaque)
  71.299 -+{
  71.300 +     return;
  71.301 + }
  71.302 + 
  71.303 +@@ -58,14 +193,35 @@
  71.304 + 
  71.305 + void xenstore_process_event(void *opaque)
  71.306 + {
  71.307 +-    char **vec;
  71.308 +-    unsigned int num;
  71.309  +    char **vec, *image = NULL;
  71.310  +    unsigned int len, num, hd_index;
  71.311 -+
  71.312 -+    vec = xs_read_watch(xsh, &num);
  71.313 -+    if (!vec)
  71.314 -+	return;
  71.315 -+
  71.316 + 
  71.317 +     vec = xs_read_watch(xsh, &num);
  71.318 +     if (!vec)
  71.319 +         return;
  71.320 + 
  71.321  +    if (strncmp(vec[XS_WATCH_TOKEN], "hd", 2) ||
  71.322 -+	strlen(vec[XS_WATCH_TOKEN]) != 3)
  71.323 -+	goto out;
  71.324 ++        strlen(vec[XS_WATCH_TOKEN]) != 3)
  71.325 ++        goto out;
  71.326  +    hd_index = vec[XS_WATCH_TOKEN][2] - 'a';
  71.327  +    image = xs_read(xsh, XBT_NULL, vec[XS_WATCH_PATH], &len);
  71.328  +    if (image == NULL || !strcmp(image, bs_table[hd_index]->filename))
  71.329 -+	goto out;		/* gone or identical */
  71.330 ++        goto out;  /* gone or identical */
  71.331  +
  71.332  +    do_eject(0, vec[XS_WATCH_TOKEN]);
  71.333  +    bs_table[hd_index]->filename[0] = 0;
  71.334 -+    if (hd_filename[hd_index]) {
  71.335 -+	free(hd_filename[hd_index]);
  71.336 -+	hd_filename[hd_index] = NULL;
  71.337 ++    if (media_filename[hd_index]) {
  71.338 ++        free(media_filename[hd_index]);
  71.339 ++        media_filename[hd_index] = NULL;
  71.340  +    }
  71.341  +
  71.342  +    if (image[0]) {
  71.343 -+	hd_filename[hd_index] = strdup(image);
  71.344 -+	xenstore_check_new_media_present(5000);
  71.345 ++        media_filename[hd_index] = strdup(image);
  71.346 ++        xenstore_check_new_media_present(5000);
  71.347  +    }
  71.348  +
  71.349 -+ out:
  71.350 +  out:
  71.351  +    free(image);
  71.352 -+    free(vec);
  71.353 -+}
  71.354 +     free(vec);
  71.355 + }
  71.356 + 
  71.357  Index: ioemu/vl.c
  71.358  ===================================================================
  71.359 ---- ioemu.orig/vl.c	2006-12-20 15:21:52.000000000 +0000
  71.360 -+++ ioemu/vl.c	2006-12-20 15:21:53.000000000 +0000
  71.361 -@@ -5256,9 +5256,11 @@
  71.362 +--- ioemu.orig/vl.c	2007-05-03 15:17:52.000000000 +0100
  71.363 ++++ ioemu/vl.c	2007-05-03 15:18:05.000000000 +0100
  71.364 +@@ -5331,9 +5331,11 @@
  71.365              "Standard options:\n"
  71.366              "-M machine      select emulated machine (-M ? for list)\n"
  71.367              "-fda/-fdb file  use 'file' as floppy disk 0/1 image\n"
  71.368 @@ -218,7 +220,7 @@ Index: ioemu/vl.c
  71.369              "-boot [a|c|d]   boot on floppy (a), hard disk (c) or CD-ROM (d)\n"
  71.370   	   "-snapshot       write to temporary files instead of disk image files\n"
  71.371   #ifdef TARGET_I386
  71.372 -@@ -5386,11 +5388,13 @@
  71.373 +@@ -5460,11 +5462,13 @@
  71.374       QEMU_OPTION_M,
  71.375       QEMU_OPTION_fda,
  71.376       QEMU_OPTION_fdb,
  71.377 @@ -232,7 +234,7 @@ Index: ioemu/vl.c
  71.378       QEMU_OPTION_boot,
  71.379       QEMU_OPTION_snapshot,
  71.380   #ifdef TARGET_I386
  71.381 -@@ -5463,11 +5467,13 @@
  71.382 +@@ -5536,11 +5540,13 @@
  71.383       { "M", HAS_ARG, QEMU_OPTION_M },
  71.384       { "fda", HAS_ARG, QEMU_OPTION_fda },
  71.385       { "fdb", HAS_ARG, QEMU_OPTION_fdb },
  71.386 @@ -246,7 +248,7 @@ Index: ioemu/vl.c
  71.387       { "boot", HAS_ARG, QEMU_OPTION_boot },
  71.388       { "snapshot", 0, QEMU_OPTION_snapshot },
  71.389   #ifdef TARGET_I386
  71.390 -@@ -5801,10 +5807,16 @@
  71.391 +@@ -5882,10 +5888,16 @@
  71.392   #ifdef CONFIG_GDBSTUB
  71.393       int use_gdbstub, gdbstub_port;
  71.394   #endif
  71.395 @@ -265,7 +267,7 @@ Index: ioemu/vl.c
  71.396       const char *kernel_filename, *kernel_cmdline;
  71.397       DisplayState *ds = &display_state;
  71.398       int cyls, heads, secs, translation;
  71.399 -@@ -5865,8 +5877,10 @@
  71.400 +@@ -5946,8 +5958,10 @@
  71.401       initrd_filename = NULL;
  71.402       for(i = 0; i < MAX_FD; i++)
  71.403           fd_filename[i] = NULL;
  71.404 @@ -276,7 +278,7 @@ Index: ioemu/vl.c
  71.405       ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
  71.406       vga_ram_size = VGA_RAM_SIZE;
  71.407       bios_size = BIOS_SIZE;
  71.408 -@@ -5880,11 +5894,13 @@
  71.409 +@@ -5961,11 +5975,13 @@
  71.410       vncunused = 0;
  71.411       kernel_filename = NULL;
  71.412       kernel_cmdline = "";
  71.413 @@ -289,8 +291,8 @@ Index: ioemu/vl.c
  71.414  +#endif /* !CONFIG_DM */
  71.415       cyls = heads = secs = 0;
  71.416       translation = BIOS_ATA_TRANSLATION_AUTO;
  71.417 -     pstrcpy(monitor_device, sizeof(monitor_device), "vc");
  71.418 -@@ -5919,7 +5935,11 @@
  71.419 +     pstrcpy(monitor_device, sizeof(monitor_device), "null");
  71.420 +@@ -6004,7 +6020,11 @@
  71.421               break;
  71.422           r = argv[optind];
  71.423           if (r[0] != '-') {
  71.424 @@ -302,7 +304,7 @@ Index: ioemu/vl.c
  71.425           } else {
  71.426               const QEMUOption *popt;
  71.427   
  71.428 -@@ -5963,6 +5983,7 @@
  71.429 +@@ -6048,6 +6068,7 @@
  71.430               case QEMU_OPTION_initrd:
  71.431                   initrd_filename = optarg;
  71.432                   break;
  71.433 @@ -310,7 +312,7 @@ Index: ioemu/vl.c
  71.434               case QEMU_OPTION_hda:
  71.435               case QEMU_OPTION_hdb:
  71.436               case QEMU_OPTION_hdc:
  71.437 -@@ -5975,6 +5996,7 @@
  71.438 +@@ -6060,6 +6081,7 @@
  71.439                           cdrom_index = -1;
  71.440                   }
  71.441                   break;
  71.442 @@ -318,7 +320,7 @@ Index: ioemu/vl.c
  71.443               case QEMU_OPTION_snapshot:
  71.444                   snapshot = 1;
  71.445                   break;
  71.446 -@@ -6027,11 +6049,13 @@
  71.447 +@@ -6112,11 +6134,13 @@
  71.448               case QEMU_OPTION_append:
  71.449                   kernel_cmdline = optarg;
  71.450                   break;
  71.451 @@ -332,18 +334,15 @@ Index: ioemu/vl.c
  71.452               case QEMU_OPTION_boot:
  71.453                   boot_device = optarg[0];
  71.454                   if (boot_device != 'a' && 
  71.455 -@@ -6289,12 +6313,18 @@
  71.456 -         }
  71.457 +@@ -6372,6 +6396,7 @@
  71.458       }
  71.459   
  71.460 -+#ifdef CONFIG_DM
  71.461 + #ifdef CONFIG_DM
  71.462  +    bdrv_init();
  71.463 -+    xenstore_parse_domain_config(domid);
  71.464 -+#endif /* CONFIG_DM */
  71.465 -+
  71.466 - #ifdef USE_KQEMU
  71.467 -     if (smp_cpus > 1)
  71.468 -         kqemu_allowed = 0;
  71.469 +     xenstore_parse_domain_config(domid);
  71.470 + #endif /* CONFIG_DM */
  71.471 + 
  71.472 +@@ -6381,6 +6406,7 @@
  71.473   #endif
  71.474       linux_boot = (kernel_filename != NULL);
  71.475           
  71.476 @@ -351,7 +350,7 @@ Index: ioemu/vl.c
  71.477       if (!linux_boot && 
  71.478           hd_filename[0] == '\0' && 
  71.479           (cdrom_index >= 0 && hd_filename[cdrom_index] == '\0') &&
  71.480 -@@ -6308,6 +6338,7 @@
  71.481 +@@ -6394,6 +6420,7 @@
  71.482           else
  71.483               boot_device = 'd';
  71.484       }
  71.485 @@ -359,7 +358,7 @@ Index: ioemu/vl.c
  71.486   
  71.487       setvbuf(stdout, NULL, _IOLBF, 0);
  71.488       
  71.489 -@@ -6433,6 +6464,7 @@
  71.490 +@@ -6514,6 +6541,7 @@
  71.491   
  71.492   #endif /* !CONFIG_DM */
  71.493   
  71.494 @@ -367,7 +366,7 @@ Index: ioemu/vl.c
  71.495       /* we always create the cdrom drive, even if no disk is there */
  71.496       bdrv_init();
  71.497       if (cdrom_index >= 0) {
  71.498 -@@ -6459,6 +6491,7 @@
  71.499 +@@ -6540,6 +6568,7 @@
  71.500               }
  71.501           }
  71.502       }
  71.503 @@ -375,19 +374,10 @@ Index: ioemu/vl.c
  71.504   
  71.505       /* we always create at least one floppy disk */
  71.506       fd_table[0] = bdrv_new("fda");
  71.507 -@@ -6537,6 +6570,8 @@
  71.508 -         }
  71.509 -     }
  71.510 - 
  71.511 -+    qemu_set_fd_handler(xenstore_fd(), xenstore_process_event, NULL, NULL);
  71.512 -+
  71.513 -     machine->init(ram_size, vga_ram_size, boot_device,
  71.514 -                   ds, fd_filename, snapshot,
  71.515 -                   kernel_filename, kernel_cmdline, initrd_filename,
  71.516  Index: ioemu/monitor.c
  71.517  ===================================================================
  71.518 ---- ioemu.orig/monitor.c	2006-12-20 15:21:47.000000000 +0000
  71.519 -+++ ioemu/monitor.c	2006-12-20 15:21:53.000000000 +0000
  71.520 +--- ioemu.orig/monitor.c	2007-05-03 15:17:52.000000000 +0100
  71.521 ++++ ioemu/monitor.c	2007-05-03 15:18:05.000000000 +0100
  71.522  @@ -24,6 +24,7 @@
  71.523   #include "vl.h"
  71.524   #include "disas.h"
  71.525 @@ -416,8 +406,8 @@ Index: ioemu/monitor.c
  71.526       int i;
  71.527  Index: ioemu/block.c
  71.528  ===================================================================
  71.529 ---- ioemu.orig/block.c	2006-12-20 15:21:31.000000000 +0000
  71.530 -+++ ioemu/block.c	2006-12-20 15:21:53.000000000 +0000
  71.531 +--- ioemu.orig/block.c	2007-05-03 15:17:52.000000000 +0100
  71.532 ++++ ioemu/block.c	2007-05-03 15:18:05.000000000 +0100
  71.533  @@ -758,6 +758,7 @@
  71.534   static void raw_close(BlockDriverState *bs)
  71.535   {
  71.536 @@ -428,9 +418,9 @@ Index: ioemu/block.c
  71.537   
  71.538  Index: ioemu/vl.h
  71.539  ===================================================================
  71.540 ---- ioemu.orig/vl.h	2006-12-20 15:21:52.000000000 +0000
  71.541 -+++ ioemu/vl.h	2006-12-20 15:21:53.000000000 +0000
  71.542 -@@ -1191,6 +1191,8 @@
  71.543 +--- ioemu.orig/vl.h	2007-05-03 15:18:00.000000000 +0100
  71.544 ++++ ioemu/vl.h	2007-05-03 15:18:05.000000000 +0100
  71.545 +@@ -1192,6 +1192,8 @@
  71.546   void term_print_help(void);
  71.547   void monitor_readline(const char *prompt, int is_password,
  71.548                         char *buf, int buf_size);
  71.549 @@ -439,25 +429,21 @@ Index: ioemu/vl.h
  71.550   
  71.551   /* readline.c */
  71.552   typedef void ReadLineFunc(void *opaque, const char *str);
  71.553 -@@ -1203,6 +1205,13 @@
  71.554 - void readline_start(const char *prompt, int is_password,
  71.555 -                     ReadLineFunc *readline_func, void *opaque);
  71.556 +@@ -1206,6 +1208,9 @@
  71.557   
  71.558 -+/* xenstore.c */
  71.559 -+void xenstore_parse_domain_config(int domid);
  71.560 + /* xenstore.c */
  71.561 + void xenstore_parse_domain_config(int domid);
  71.562  +int xenstore_fd(void);
  71.563  +void xenstore_process_event(void *opaque);
  71.564  +void xenstore_check_new_media_present(int timeout);
  71.565 -+
  71.566 -+
  71.567 - void kqemu_record_dump(void);
  71.568   
  71.569 - extern char domain_name[];
  71.570 + int xenstore_vm_write(int domid, char *key, char *val);
  71.571 + char *xenstore_vm_read(int domid, char *key, int *len);
  71.572  Index: ioemu/hw/ide.c
  71.573  ===================================================================
  71.574 ---- ioemu.orig/hw/ide.c	2006-12-20 15:21:49.000000000 +0000
  71.575 -+++ ioemu/hw/ide.c	2006-12-20 15:21:53.000000000 +0000
  71.576 -@@ -1158,6 +1158,7 @@
  71.577 +--- ioemu.orig/hw/ide.c	2007-05-03 15:17:52.000000000 +0100
  71.578 ++++ ioemu/hw/ide.c	2007-05-03 15:18:05.000000000 +0100
  71.579 +@@ -1199,6 +1199,7 @@
  71.580           } else {
  71.581               ide_atapi_cmd_error(s, SENSE_NOT_READY, 
  71.582                                   ASC_MEDIUM_NOT_PRESENT);
    72.1 --- a/tools/ioemu/patches/xenstore-device-info-functions	Mon May 07 13:24:37 2007 -0600
    72.2 +++ b/tools/ioemu/patches/xenstore-device-info-functions	Tue May 08 09:09:17 2007 -0600
    72.3 @@ -15,13 +15,12 @@ Signed-off-by: Stefan Berger <stefanb@us
    72.4  
    72.5  Index: ioemu/xenstore.c
    72.6  ===================================================================
    72.7 ---- ioemu.orig/xenstore.c	2006-12-08 18:20:53.000000000 +0000
    72.8 -+++ ioemu/xenstore.c	2006-12-08 18:20:53.000000000 +0000
    72.9 -@@ -264,3 +264,140 @@
   72.10 - 
   72.11 +--- ioemu.orig/xenstore.c	2007-05-03 15:21:22.000000000 +0100
   72.12 ++++ ioemu/xenstore.c	2007-05-03 15:22:05.000000000 +0100
   72.13 +@@ -304,6 +304,143 @@
   72.14       return rc;
   72.15   }
   72.16 -+
   72.17 + 
   72.18  +
   72.19  +/*
   72.20  + * get all device instances of a certain type
   72.21 @@ -38,7 +37,7 @@ Index: ioemu/xenstore.c
   72.22  +        goto out;
   72.23  +
   72.24  +    if (pasprintf(&buf, "%s/device/%s", path,devtype) == -1)
   72.25 -+	goto out;
   72.26 ++        goto out;
   72.27  +
   72.28  +    e = xs_directory(handle, XBT_NULL, buf, num);
   72.29  +
   72.30 @@ -91,13 +90,13 @@ Index: ioemu/xenstore.c
   72.31  +
   72.32  +    buf = get_device_variable_path(devtype, inst, var);
   72.33  +    if (NULL == buf)
   72.34 -+	goto out;
   72.35 ++        goto out;
   72.36  +
   72.37  +    value = xs_read(handle, XBT_NULL, buf, &len);
   72.38  +
   72.39  +    free(buf);
   72.40  +
   72.41 -+out:
   72.42 ++ out:
   72.43  +    return value;
   72.44  +}
   72.45  +
   72.46 @@ -158,11 +157,15 @@ Index: ioemu/xenstore.c
   72.47  +
   72.48  +    return rc;
   72.49  +}
   72.50 ++
   72.51 + char *xenstore_vm_read(int domid, char *key, int *len)
   72.52 + {
   72.53 +     char *buf = NULL, *path = NULL, *value = NULL;
   72.54  Index: ioemu/vl.h
   72.55  ===================================================================
   72.56 ---- ioemu.orig/vl.h	2006-12-08 18:20:53.000000000 +0000
   72.57 -+++ ioemu/vl.h	2006-12-08 18:20:53.000000000 +0000
   72.58 -@@ -1216,6 +1216,25 @@
   72.59 +--- ioemu.orig/vl.h	2007-05-03 15:21:09.000000000 +0100
   72.60 ++++ ioemu/vl.h	2007-05-03 15:21:47.000000000 +0100
   72.61 +@@ -1217,6 +1217,24 @@
   72.62   void xenstore_write_vncport(int vnc_display);
   72.63   int xenstore_read_vncpasswd(int domid);
   72.64   
   72.65 @@ -184,7 +187,6 @@ Index: ioemu/vl.h
   72.66  +                                             const char *inst,
   72.67  +                                             const char *token);
   72.68  +
   72.69 -+
   72.70 - /* xen_platform.c */
   72.71 - void pci_xen_platform_init(PCIBus *bus);
   72.72 + int xenstore_vm_write(int domid, char *key, char *val);
   72.73 + char *xenstore_vm_read(int domid, char *key, int *len);
   72.74   
    73.1 --- a/tools/ioemu/patches/xenstore-write-vnc-port	Mon May 07 13:24:37 2007 -0600
    73.2 +++ b/tools/ioemu/patches/xenstore-write-vnc-port	Tue May 08 09:09:17 2007 -0600
    73.3 @@ -1,19 +1,18 @@
    73.4  Index: ioemu/xenstore.c
    73.5  ===================================================================
    73.6 ---- ioemu.orig/xenstore.c	2006-12-20 15:21:53.000000000 +0000
    73.7 -+++ ioemu/xenstore.c	2006-12-20 15:21:54.000000000 +0000
    73.8 -@@ -185,3 +185,31 @@
    73.9 -     free(image);
   73.10 +--- ioemu.orig/xenstore.c	2007-05-03 15:18:05.000000000 +0100
   73.11 ++++ ioemu/xenstore.c	2007-05-03 15:18:17.000000000 +0100
   73.12 +@@ -225,6 +225,34 @@
   73.13       free(vec);
   73.14   }
   73.15 -+
   73.16 + 
   73.17  +void xenstore_write_vncport(int display)
   73.18  +{
   73.19  +    char *buf = NULL, *path;
   73.20  +    char *portstr = NULL;
   73.21  +
   73.22  +    if (xsh == NULL)
   73.23 -+	return;
   73.24 ++        return;
   73.25  +
   73.26  +    path = xs_get_domain_path(xsh, domid);
   73.27  +    if (path == NULL) {
   73.28 @@ -22,10 +21,10 @@ Index: ioemu/xenstore.c
   73.29  +    }
   73.30  +
   73.31  +    if (pasprintf(&buf, "%s/console/vnc-port", path) == -1)
   73.32 -+	goto out;
   73.33 ++        goto out;
   73.34  +
   73.35  +    if (pasprintf(&portstr, "%d", 5900 + display) == -1)
   73.36 -+	goto out;
   73.37 ++        goto out;
   73.38  +
   73.39  +    if (xs_write(xsh, XBT_NULL, buf, portstr, strlen(portstr)) == 0)
   73.40  +        fprintf(logfile, "xs_write() vncport failed\n");
   73.41 @@ -34,11 +33,15 @@ Index: ioemu/xenstore.c
   73.42  +    free(portstr);
   73.43  +    free(buf);
   73.44  +}
   73.45 ++
   73.46 + char *xenstore_vm_read(int domid, char *key, int *len)
   73.47 + {
   73.48 +     char *buf = NULL, *path = NULL, *value = NULL;
   73.49  Index: ioemu/vl.c
   73.50  ===================================================================
   73.51 ---- ioemu.orig/vl.c	2006-12-20 15:21:53.000000000 +0000
   73.52 -+++ ioemu/vl.c	2006-12-20 15:21:54.000000000 +0000
   73.53 -@@ -6527,6 +6527,7 @@
   73.54 +--- ioemu.orig/vl.c	2007-05-03 15:18:05.000000000 +0100
   73.55 ++++ ioemu/vl.c	2007-05-03 15:18:17.000000000 +0100
   73.56 +@@ -6604,6 +6604,7 @@
   73.57   	vnc_display = vnc_display_init(ds, vnc_display, vncunused, &vnclisten_addr);
   73.58   	if (vncviewer)
   73.59   	    vnc_start_viewer(vnc_display);
   73.60 @@ -48,13 +51,13 @@ Index: ioemu/vl.c
   73.61           sdl_display_init(ds, full_screen);
   73.62  Index: ioemu/vl.h
   73.63  ===================================================================
   73.64 ---- ioemu.orig/vl.h	2006-12-20 15:21:53.000000000 +0000
   73.65 -+++ ioemu/vl.h	2006-12-20 15:21:54.000000000 +0000
   73.66 -@@ -1210,6 +1210,7 @@
   73.67 +--- ioemu.orig/vl.h	2007-05-03 15:18:05.000000000 +0100
   73.68 ++++ ioemu/vl.h	2007-05-03 15:18:17.000000000 +0100
   73.69 +@@ -1211,6 +1211,7 @@
   73.70   int xenstore_fd(void);
   73.71   void xenstore_process_event(void *opaque);
   73.72   void xenstore_check_new_media_present(int timeout);
   73.73  +void xenstore_write_vncport(int vnc_display);
   73.74   
   73.75 - 
   73.76 - void kqemu_record_dump(void);
   73.77 + int xenstore_vm_write(int domid, char *key, char *val);
   73.78 + char *xenstore_vm_read(int domid, char *key, int *len);
    74.1 --- a/tools/libxc/xc_hvm_build.c	Mon May 07 13:24:37 2007 -0600
    74.2 +++ b/tools/libxc/xc_hvm_build.c	Tue May 08 09:09:17 2007 -0600
    74.3 @@ -108,43 +108,45 @@ static void build_e820map(void *e820_pag
    74.4      *(((unsigned char *)e820_page) + E820_MAP_NR_OFFSET) = nr_map;
    74.5  }
    74.6  
    74.7 -static int
    74.8 -loadelfimage(struct elf_binary *elf, int xch, uint32_t dom, unsigned long *parray)
    74.9 +static int loadelfimage(
   74.10 +    struct elf_binary *elf, int xch, uint32_t dom, unsigned long *parray)
   74.11  {
   74.12      privcmd_mmap_entry_t *entries = NULL;
   74.13      int pages = (elf->pend - elf->pstart + PAGE_SIZE - 1) >> PAGE_SHIFT;
   74.14      int i, rc = -1;
   74.15  
   74.16 -    /* map hvmloader address space */
   74.17 +    /* Map address space for initial elf image. */
   74.18      entries = malloc(pages * sizeof(privcmd_mmap_entry_t));
   74.19 -    if (NULL == entries)
   74.20 +    if ( entries == NULL )
   74.21          goto err;
   74.22      elf->dest = mmap(NULL, pages << PAGE_SHIFT, PROT_READ | PROT_WRITE,
   74.23                       MAP_SHARED, xch, 0);
   74.24 -    if (MAP_FAILED == elf->dest)
   74.25 +    if ( elf->dest == MAP_FAILED )
   74.26          goto err;
   74.27  
   74.28 -    for (i = 0; i < pages; i++)
   74.29 +    for ( i = 0; i < pages; i++ )
   74.30      {
   74.31          entries[i].va = (uintptr_t)elf->dest + (i << PAGE_SHIFT);
   74.32          entries[i].mfn = parray[(elf->pstart >> PAGE_SHIFT) + i];
   74.33          entries[i].npages = 1;
   74.34      }
   74.35 +
   74.36      rc = xc_map_foreign_ranges(xch, dom, entries, pages);
   74.37 -    if (rc < 0)
   74.38 +    if ( rc < 0 )
   74.39          goto err;
   74.40  
   74.41 -    /* load hvmloader */
   74.42 +    /* Load the initial elf image. */
   74.43      elf_load_binary(elf);
   74.44      rc = 0;
   74.45  
   74.46   err:
   74.47 -    /* cleanup */
   74.48 -    if (elf->dest) {
   74.49 +    if ( elf->dest )
   74.50 +    {
   74.51          munmap(elf->dest, pages << PAGE_SHIFT);
   74.52          elf->dest = NULL;
   74.53      }
   74.54 -    if (entries)
   74.55 +
   74.56 +    if ( entries )
   74.57          free(entries);
   74.58  
   74.59      return rc;
   74.60 @@ -166,13 +168,17 @@ static int setup_guest(int xc_handle,
   74.61      int rc;
   74.62      xen_capabilities_info_t caps;
   74.63  
   74.64 -    if (0 != elf_init(&elf, image, image_size))
   74.65 +    /* An HVM guest must be initialised with at least 2MB memory. */
   74.66 +    if ( memsize < 2 )
   74.67 +        goto error_out;
   74.68 +
   74.69 +    if ( elf_init(&elf, image, image_size) != 0 )
   74.70          goto error_out;
   74.71      elf_parse_binary(&elf);
   74.72      v_start = 0;
   74.73      v_end = (unsigned long long)memsize << 20;
   74.74  
   74.75 -    if (xc_version(xc_handle, XENVER_capabilities, &caps) != 0)
   74.76 +    if ( xc_version(xc_handle, XENVER_capabilities, &caps) != 0 )
   74.77      {
   74.78          PERROR("Could not get Xen capabilities\n");
   74.79          goto error_out;
   74.80 @@ -185,9 +191,9 @@ static int setup_guest(int xc_handle,
   74.81      }
   74.82  
   74.83      IPRINTF("VIRTUAL MEMORY ARRANGEMENT:\n"
   74.84 -            "  Loaded HVM loader:    %016"PRIx64"->%016"PRIx64"\n"
   74.85 -            "  TOTAL:                %016"PRIx64"->%016"PRIx64"\n"
   74.86 -            "  ENTRY ADDRESS:        %016"PRIx64"\n",
   74.87 +            "  Loader:        %016"PRIx64"->%016"PRIx64"\n"
   74.88 +            "  TOTAL:         %016"PRIx64"->%016"PRIx64"\n"
   74.89 +            "  ENTRY ADDRESS: %016"PRIx64"\n",
   74.90              elf.pstart, elf.pend,
   74.91              v_start, v_end,
   74.92              elf_uval(&elf, elf.ehdr, e_entry));
   74.93 @@ -205,9 +211,8 @@ static int setup_guest(int xc_handle,
   74.94  
   74.95      /* Allocate memory for HVM guest, skipping VGA hole 0xA0000-0xC0000. */
   74.96      rc = xc_domain_memory_populate_physmap(
   74.97 -        xc_handle, dom, (nr_pages > 0xa0) ? 0xa0 : nr_pages,
   74.98 -        0, 0, &page_array[0x00]);
   74.99 -    if ( (rc == 0) && (nr_pages > 0xc0) )
  74.100 +        xc_handle, dom, 0xa0, 0, 0, &page_array[0x00]);
  74.101 +    if ( rc == 0 )
  74.102          rc = xc_domain_memory_populate_physmap(
  74.103              xc_handle, dom, nr_pages - 0xc0, 0, 0, &page_array[0xc0]);
  74.104      if ( rc != 0 )
  74.105 @@ -216,7 +221,8 @@ static int setup_guest(int xc_handle,
  74.106          goto error_out;
  74.107      }
  74.108  
  74.109 -    loadelfimage(&elf, xc_handle, dom, page_array);
  74.110 +    if ( loadelfimage(&elf, xc_handle, dom, page_array) != 0 )
  74.111 +        goto error_out;
  74.112  
  74.113      if ( (e820_page = xc_map_foreign_range(
  74.114                xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
  74.115 @@ -328,12 +334,9 @@ static inline int is_loadable_phdr(Elf32
  74.116              ((phdr->p_flags & (PF_W|PF_X)) != 0));
  74.117  }
  74.118  
  74.119 -/* xc_hvm_build
  74.120 - *
  74.121 - * Create a domain for a virtualized Linux, using files/filenames
  74.122 - *
  74.123 +/* xc_hvm_build:
  74.124 + * Create a domain for a virtualized Linux, using files/filenames.
  74.125   */
  74.126 -
  74.127  int xc_hvm_build(int xc_handle,
  74.128                   uint32_t domid,
  74.129                   int memsize,
  74.130 @@ -354,12 +357,9 @@ int xc_hvm_build(int xc_handle,
  74.131      return sts;
  74.132  }
  74.133  
  74.134 -/* xc_hvm_build_mem
  74.135 - *
  74.136 - * Create a domain for a virtualized Linux, using buffers
  74.137 - *
  74.138 +/* xc_hvm_build_mem:
  74.139 + * Create a domain for a virtualized Linux, using memory buffers.
  74.140   */
  74.141 -
  74.142  int xc_hvm_build_mem(int xc_handle,
  74.143                       uint32_t domid,
  74.144                       int memsize,
  74.145 @@ -379,7 +379,7 @@ int xc_hvm_build_mem(int xc_handle,
  74.146      }
  74.147  
  74.148      img = xc_inflate_buffer(image_buffer, image_size, &img_len);
  74.149 -    if (img == NULL)
  74.150 +    if ( img == NULL )
  74.151      {
  74.152          ERROR("unable to inflate ram disk buffer");
  74.153          return -1;
    75.1 --- a/tools/python/xen/xend/XendAPI.py	Mon May 07 13:24:37 2007 -0600
    75.2 +++ b/tools/python/xen/xend/XendAPI.py	Tue May 08 09:09:17 2007 -0600
    75.3 @@ -1009,7 +1009,7 @@ class XendAPI(object):
    75.4                    'cpu_configuration': node.get_cpu_configuration(),
    75.5                    'metrics': node.host_metrics_uuid,
    75.6                    'capabilities': node.get_capabilities(),
    75.7 -                  'supported_bootloaders': 'pygrub',
    75.8 +                  'supported_bootloaders': ['pygrub'],
    75.9                    'sched_policy': node.get_vcpus_policy()}
   75.10          return xen_api_success(record)
   75.11  
    76.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Mon May 07 13:24:37 2007 -0600
    76.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Tue May 08 09:09:17 2007 -0600
    76.3 @@ -867,7 +867,10 @@ class XendDomainInfo:
    76.4  
    76.5          # convert two lists into a python dictionary
    76.6          vm_details = dict(zip(cfg_vm, vm_details))
    76.7 -        
    76.8 +
    76.9 +        if vm_details['rtc/timeoffset'] == None:
   76.10 +            vm_details['rtc/timeoffset'] = "0"
   76.11 +
   76.12          for arg, val in vm_details.items():
   76.13              if arg in XendConfig.LEGACY_CFG_TO_XENAPI_CFG:
   76.14                  xapiarg = XendConfig.LEGACY_CFG_TO_XENAPI_CFG[arg]
    77.1 --- a/tools/python/xen/xend/image.py	Mon May 07 13:24:37 2007 -0600
    77.2 +++ b/tools/python/xen/xend/image.py	Tue May 08 09:09:17 2007 -0600
    77.3 @@ -418,7 +418,7 @@ class HVMImageHandler(ImageHandler):
    77.4              ret.append('-nographic')
    77.5  
    77.6          if int(vmConfig['platform'].get('monitor', 0)) != 0:
    77.7 -            ret.append('-monitor vc')
    77.8 +            ret = ret + ['-monitor', 'vc']
    77.9          return ret
   77.10  
   77.11      def createDeviceModel(self, restore = False):
    78.1 --- a/tools/xenstat/libxenstat/src/xenstat_linux.c	Mon May 07 13:24:37 2007 -0600
    78.2 +++ b/tools/xenstat/libxenstat/src/xenstat_linux.c	Tue May 08 09:09:17 2007 -0600
    78.3 @@ -206,10 +206,8 @@ int xenstat_collect_vbds(xenstat_node * 
    78.4  
    78.5  
    78.6  		ret = sscanf(dp->d_name, "vbd-%u-%u", &domid, &vbd.dev);
    78.7 -		if (ret != 2) {
    78.8 +		if (ret != 2)
    78.9  			continue;
   78.10 -		}
   78.11 -		printf("%s is VBD.\n",dp->d_name);
   78.12  
   78.13  		domain = xenstat_node_domain(node, domid);
   78.14  		if (domain == NULL) {