Index: ioemu/vl.c
===================================================================
--- ioemu.orig/vl.c	2007-05-11 10:04:50.000000000 +0100
+++ ioemu/vl.c	2007-05-11 10:04:50.000000000 +0100
@@ -7530,6 +7530,9 @@
     }
     free(page_array);
 #endif
+
+    timeoffset_get();
+
 #else  /* !CONFIG_DM */
 
     phys_ram_base = qemu_vmalloc(phys_ram_size);
Index: ioemu/vl.h
===================================================================
--- ioemu.orig/vl.h	2007-05-11 10:04:50.000000000 +0100
+++ ioemu/vl.h	2007-05-11 10:04:50.000000000 +0100
@@ -1433,6 +1433,10 @@
 int xenstore_vm_write(int domid, char *key, char *val);
 char *xenstore_vm_read(int domid, char *key, int *len);
 
+/* helper2.c */
+extern long time_offset;
+void timeoffset_get(void);
+
 void kqemu_record_dump(void);
 
 extern char domain_name[];
Index: ioemu/target-i386-dm/helper2.c
===================================================================
--- ioemu.orig/target-i386-dm/helper2.c	2007-05-11 10:04:48.000000000 +0100
+++ ioemu/target-i386-dm/helper2.c	2007-05-11 10:04:50.000000000 +0100
@@ -74,6 +74,8 @@
 
 int xc_handle;
 
+long time_offset = 0;
+
 shared_iopage_t *shared_page = NULL;
 
 /* the evtchn fd for polling */
@@ -447,6 +449,34 @@
     req->data = tmp1;
 }
 
+void timeoffset_get()
+{
+    char *p;
+
+    p = xenstore_vm_read(domid, "rtc/timeoffset", NULL);
+    if (!p)
+	return;
+
+    if (sscanf(p, "%ld", &time_offset) == 1)
+	fprintf(logfile, "Time offset set %ld\n", time_offset);
+    else
+	time_offset = 0;
+
+    xc_domain_set_time_offset(xc_handle, domid, time_offset);
+
+    free(p);
+}
+
+void cpu_ioreq_timeoffset(CPUState *env, ioreq_t *req)
+{
+    char b[64];
+
+    time_offset += (ulong)req->data;
+
+    sprintf(b, "%ld", time_offset);
+    xenstore_vm_write(domid, "rtc/timeoffset", b);
+}
+
 void cpu_ioreq_xchg(CPUState *env, ioreq_t *req)
 {
     unsigned long tmp1;
@@ -497,6 +527,9 @@
         case IOREQ_TYPE_XCHG:
             cpu_ioreq_xchg(env, req);
             break;
+	case IOREQ_TYPE_TIMEOFFSET:
+            cpu_ioreq_timeoffset(env, req);
+            break;
         default:
             hw_error("Invalid ioreq type 0x%x\n", req->type);
         }
