+diff --git a/hw/piix4acpi.c b/hw/piix4acpi.c
+index 06b0bfa..3e48413 100644
+--- a/hw/piix4acpi.c
++++ b/hw/piix4acpi.c
+@@ -32,6 +32,8 @@
+ #include "xen_acpi_wmi.h"
+ #include "thermal_mgmt.h"
+
++#include "switcher.h"
++
+ #include <xen/hvm/ioreq.h>
+ #include <xen/hvm/params.h>
+
+@@ -144,14 +146,17 @@ static void acpi_shutdown(uint32_t val)
+ cmos_set_s3_resume();
+ xc_set_hvm_param(xc_handle, domid, HVM_PARAM_ACPI_S_STATE, 3);
+ xenstore_guest_pm_notification(GUEST_STATE_SLEEP);
++ switcher_shutdown(SWITCHER_SHUTDOWN_S3);
+ break;
+ case SLP_TYP_S4:
+ qemu_system_shutdown_request();
+ xenstore_guest_pm_notification(GUEST_STATE_HIBERNATE);
++ switcher_shutdown(SWITCHER_SHUTDOWN_S4);
+ break;
+ case SLP_TYP_S5:
+ qemu_system_shutdown_request();
+ xenstore_guest_pm_notification(GUEST_STATE_SHUTDOWN);
++ switcher_shutdown(SWITCHER_SHUTDOWN_S5);
+ break;
+ default:
+ break;
+diff --git a/i386-dm/helper2.c b/i386-dm/helper2.c
+index 681bd86..53c500d 100644
+--- a/i386-dm/helper2.c
++++ b/i386-dm/helper2.c
+@@ -60,6 +60,8 @@
+ #include "sysemu.h"
+ #include "qemu-xen.h"
+
++#include "switcher.h"
++
+ //#define DEBUG_MMU
+
+ #ifdef USE_CODE_COPY
+@@ -174,6 +176,7 @@ void cpu_reset(CPUX86State *env)
+ else
+ fprintf(logfile, "Issued domain %d reboot\n", domid);
+ xc_interface_close(xcHandle);
++ switcher_shutdown(SWITCHER_SHUTDOWN_REBOOT);
+ }
+ }
+
diff --git a/qemu-xen.h b/qemu-xen.h
-index 7883718..0b6214c 100644
+index 0daf4c4..5ad40a8 100644
--- a/qemu-xen.h
+++ b/qemu-xen.h
-@@ -148,4 +148,6 @@ int has_tpm_device_danger(void);
+@@ -149,4 +149,6 @@ int has_tpm_device_danger(void);
static void vga_dirty_log_start(void *s) { }
static void vga_dirty_log_stop(void *s) { }
#endif /*QEMU_XEN_H*/
diff --git a/switcher.c b/switcher.c
new file mode 100644
-index 0000000..b89ac33
+index 0000000..b89f206
--- /dev/null
+++ b/switcher.c
-@@ -0,0 +1,288 @@
+@@ -0,0 +1,306 @@
+/*
+ * QEMU dom0_driver
+ *
+#include "qemu-timer.h"
+#include "qemu-xen.h"
+
++#include "switcher.h"
++
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#define DOM0_INPUT_DONE 'D'
+#define DOM0_INPUT_DOMID 'I'
+#define DOM0_INPUT_OPT 'O'
++#define DOM0_INPUT_SHUTDOWN 'S'
+
+#define DOM0_INPUT_SOCKET "/tmp/input.socket"
+
+ send(switcher_socket, buff, strlen(buff), 0);
+}
+
++void switcher_shutdown(int reason)
++{
++ switch (reason)
++ {
++ case SWITCHER_SHUTDOWN_REBOOT:
++ case SWITCHER_SHUTDOWN_S3:
++ case SWITCHER_SHUTDOWN_S4:
++ case SWITCHER_SHUTDOWN_S5:
++ switcher_send("%c%d", DOM0_INPUT_SHUTDOWN, reason);
++ break;
++ default:
++ break;
++ }
++}
++
+static void switcher_connect(void *opaque)
+{
+ struct stat st;
+ xenstore_dom_write(domid, "switcher/slot", str_slot);
+ switcher_connect(NULL);
+}
+diff --git a/switcher.h b/switcher.h
+new file mode 100644
+index 0000000..3a89d55
+--- /dev/null
++++ b/switcher.h
+@@ -0,0 +1,35 @@
++/*
++ * QEMU switcher.h
++ *
++ * Copyright (c) 2009 Citrix Systems
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
++ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
++ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
++ * THE SOFTWARE.
++ */
++
++#ifndef SWITCHER_H_
++# define SWITCHER_H_
++
++#define SWITCHER_SHUTDOWN_REBOOT 0
++#define SWITCHER_SHUTDOWN_S3 3
++#define SWITCHER_SHUTDOWN_S4 4
++#define SWITCHER_SHUTDOWN_S5 5
++
++void switcher_shutdown(int reason);
++
++#endif
diff --git a/vl.c b/vl.c
index 93e401c..e5c0447 100644
--- a/vl.c