x86: Add x86 support. Rebase the change (20906/1) due to a minor conflict.

Change-Id: Ic73cca0fc6c6e5cf74f63daa6080d00aa7c392bb
Signed-off-by: Xiaohui Xin <xiaohui.xin@intel.com>
Signed-off-by: Yunhong Jiang <yunhong.jiang@intel.com>
Signed-off-by: Jun Nakajima <jun.nakajima@intel.com>
diff --git a/Makefile.android b/Makefile.android
index 7ddff81..bec91ba 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -1,6 +1,13 @@
-ifeq ($(TARGET_ARCH),arm)
+ifneq (,$(filter $(TARGET_ARCH),arm x86))
 LOCAL_PATH:= $(call my-dir)
 
+# determine the target cpu
+ifeq ($(TARGET_ARCH),arm)
+EMULATOR_TARGET_CPU := target-arm
+else
+EMULATOR_TARGET_CPU := target-i386
+endif
+
 # determine the host tag to use
 QEMU_HOST_TAG := $(HOST_PREBUILT_TAG)
 ifneq ($(USE_MINGW),)
@@ -37,6 +44,11 @@
 
 MY_CFLAGS += -DCONFIG_MEMCHECK
 
+# prepare config.h for x86
+ifeq ($(TARGET_ARCH),x86)
+MY_CFLAGS += -DARCH_FLAGS_x86
+endif
+
 MY_LDLIBS :=
 
 # this is needed to build the emulator on 64-bit Linux systems
@@ -140,7 +152,7 @@
 TCG_CFLAGS := -I$(LOCAL_PATH)/tcg -I$(LOCAL_PATH)/tcg/$(TCG_TARGET)
 
 LOCAL_CFLAGS += $(TCG_CFLAGS) -DNEED_CPU_H \
-                -I$(LOCAL_PATH)/target-arm \
+                -I$(LOCAL_PATH)/$(EMULATOR_TARGET_CPU) \
                 -I$(LOCAL_PATH)/fpu \
 
 LOCAL_SRC_FILES := \
@@ -161,12 +173,10 @@
 HW_CFLAGS    := -I$(LOCAL_PATH)/hw
 
 LOCAL_CFLAGS := $(MY_CFLAGS) $(LOCAL_CFLAGS) -DNEED_CPU_H
-LOCAL_CFLAGS += -I$(LOCAL_PATH)/target-arm -I$(LOCAL_PATH)/fpu $(HW_CFLAGS)
+LOCAL_CFLAGS += -I$(LOCAL_PATH)/$(EMULATOR_TARGET_CPU) -I$(LOCAL_PATH)/fpu $(HW_CFLAGS)
 LOCAL_CFLAGS += $(ZLIB_CFLAGS) -I$(LOCAL_PATH)/$(ZLIB_DIR)
 
 HW_SOURCES := \
-    android_arm.c \
-    arm_pic.c \
     bt.c \
     bt-hci.c \
     bt-hid.c \
@@ -175,24 +185,18 @@
     cdrom.c \
     dma.c \
     irq.c \
-    goldfish_audio.c \
-    goldfish_battery.c \
     goldfish_device.c \
     goldfish_events_device.c \
     goldfish_fb.c \
-    goldfish_interrupt.c \
+    goldfish_battery.c \
+    goldfish_mmc.c   \
     goldfish_memlog.c \
-    goldfish_mmc.c \
-    goldfish_nand.c  \
-    goldfish_switch.c \
-    goldfish_timer.c \
-    goldfish_trace.c \
+    goldfish_nand.c \
     goldfish_tty.c \
     msmouse.c \
     pci.c \
     qdev.c \
     scsi-disk.c \
-    smc91c111.c \
     sysbus.c \
     usb-hid.c \
     usb-hub.c \
@@ -201,6 +205,34 @@
     usb.c \
     watchdog.c \
 
+ifeq ($(TARGET_ARCH),arm)
+HW_SOURCES += android_arm.c \
+    arm_pic.c \
+    smc91c111.c \
+    goldfish_audio.c \
+    goldfish_interrupt.c \
+    goldfish_switch.c \
+    goldfish_timer.c \
+    goldfish_trace.c \
+
+endif
+
+ifeq ($(TARGET_ARCH),x86)
+HW_SOURCES += pc.c \
+    apic.c \
+    i8259.c \
+    mc146818rtc.c \
+    piix_pci.c \
+    i8254.c \
+    ne2000.c \
+    pckbd.c \
+    ioapic.c \
+    ps2.c \
+    smbios.c \
+    fw_cfg.c \
+
+endif
+
 LOCAL_SRC_FILES += $(HW_SOURCES:%=hw/%)
 
 include $(BUILD_HOST_STATIC_LIBRARY)
@@ -223,7 +255,7 @@
 ELFF_CFLAGS    := -I$(LOCAL_PATH)/elff
 
 LOCAL_CFLAGS := $(MY_CFLAGS) $(LOCAL_CFLAGS) -fno-exceptions
-LOCAL_CFLAGS += -I$(LOCAL_PATH)/target-arm -I$(LOCAL_PATH)/fpu $(ELFF_CFLAGS)
+LOCAL_CFLAGS += -I$(LOCAL_PATH)/$(EMULATOR_TARGET_CPU) -I$(LOCAL_PATH)/fpu $(ELFF_CFLAGS)
 LOCAL_CFLAGS += $(ZLIB_CFLAGS) -I$(LOCAL_PATH)/$(ZLIB_DIR)
 
 ELFF_SOURCES := \
@@ -258,7 +290,7 @@
 MCHK_CFLAGS    := -I$(LOCAL_PATH)/memcheck -I$(LOCAL_PATH)/elff
 
 LOCAL_CFLAGS := $(MY_CFLAGS) $(LOCAL_CFLAGS) -DNEED_CPU_H
-LOCAL_CFLAGS += -I$(LOCAL_PATH)/target-arm -I$(LOCAL_PATH)/fpu $(MCHK_CFLAGS)
+LOCAL_CFLAGS += -I$(LOCAL_PATH)/$(EMULATOR_TARGET_CPU) -I$(LOCAL_PATH)/fpu $(MCHK_CFLAGS)
 LOCAL_CFLAGS += $(ZLIB_CFLAGS) -I$(LOCAL_PATH)/$(ZLIB_DIR)
 
 MCHK_SOURCES := \
@@ -273,13 +305,21 @@
 include $(BUILD_HOST_STATIC_LIBRARY)
 
 ##############################################################################
-# build the ARM-specific emulation engine sources
+# build the CPU-specific emulation engine sources
 #
 include $(CLEAR_VARS)
 
+ifeq ($(TARGET_ARCH),arm)
+LOCAL_MODULE			:= emulator-arm
+endif
+ifeq ($(TARGET_ARCH),x86)
+LOCAL_MODULE			:= emulator-i386
+LOCAL_MODULE_TAGS		:= optional
+endif
+
 LOCAL_NO_DEFAULT_COMPILER_FLAGS := true
 LOCAL_CC                        := $(MY_CC)
-LOCAL_MODULE                    := emulator-arm
+LOCAL_MODULE                    := $(LOCAL_MODULE)
 LOCAL_LDLIBS                    := $(MY_LDLIBS)
 LOCAL_CFLAGS                    := $(MY_CFLAGS) $(LOCAL_CFLAGS)
 LOCAL_STATIC_LIBRARIES          := emulator-hw
@@ -288,7 +328,7 @@
 LOCAL_CFLAGS := $(MY_CFLAGS) $(LOCAL_CFLAGS)
 
 LOCAL_CFLAGS += -I$(LOCAL_PATH) \
-                -I$(LOCAL_PATH)/target-arm \
+                -I$(LOCAL_PATH)/$(EMULATOR_TARGET_CPU) \
                 -I$(LOCAL_PATH)/fpu \
                 $(TCG_CFLAGS) \
                 $(HW_CFLAGS) \
@@ -298,13 +338,14 @@
     LOCAL_CFLAGS += -D__powerpc__
 endif
 
+ifeq ($(TARGET_ARCH),arm)
 LOCAL_SRC_FILES += exec.c cpu-exec.c  \
-                   target-arm/op_helper.c \
-                   target-arm/iwmmxt_helper.c \
-                   target-arm/neon_helper.c \
-                   target-arm/helper.c \
-                   target-arm/translate.c \
-                   target-arm/machine.c \
+                   $(EMULATOR_TARGET_CPU)/op_helper.c \
+                   $(EMULATOR_TARGET_CPU)/iwmmxt_helper.c \
+                   $(EMULATOR_TARGET_CPU)/neon_helper.c \
+                   $(EMULATOR_TARGET_CPU)/helper.c \
+                   $(EMULATOR_TARGET_CPU)/translate.c \
+                   $(EMULATOR_TARGET_CPU)/machine.c \
                    translate-all.c \
                    hw/armv7m.c \
                    hw/armv7m_nvic.c \
@@ -315,6 +356,22 @@
                    softmmu_outside_jit.c \
 
 LOCAL_SRC_FILES += fpu/softfloat.c
+endif
+
+ifeq ($(TARGET_ARCH), x86)
+LOCAL_SRC_FILES += exec.c cpu-exec.c  \
+                   $(EMULATOR_TARGET_CPU)/op_helper.c \
+                   $(EMULATOR_TARGET_CPU)/helper.c \
+                   $(EMULATOR_TARGET_CPU)/translate.c \
+                   $(EMULATOR_TARGET_CPU)/machine.c \
+                   translate-all.c \
+                   trace.c \
+                   varint.c \
+                   dcache.c \
+                   softmmu_outside_jit.c \
+
+LOCAL_SRC_FILES += fpu/softfloat-native.c
+endif
 
 include $(BUILD_HOST_STATIC_LIBRARY)
 
@@ -450,7 +507,7 @@
   LOCAL_CFLAGS := -Wno-sign-compare \
                   -fno-strict-aliasing -W -Wall -Wno-unused-parameter \
                   -I$(LOCAL_PATH) \
-                  -I$(LOCAL_PATH)/target-arm \
+                  -I$(LOCAL_PATH)/$(EMULATOR_TARGET_CPU) \
                   -I$(LOCAL_PATH)/fpu \
 
   # this is very important, otherwise the generated binaries may
@@ -513,7 +570,7 @@
 
 # Common includes for the emulator
 EMULATOR_CORE_CFLAGS += -I$(LOCAL_PATH)/ \
-                        -I$(LOCAL_PATH)/target-arm \
+                        -I$(LOCAL_PATH)/$(EMULATOR_TARGET_CPU) \
                         -I$(LOCAL_PATH)/fpu \
                         $(TCG_CFLAGS) \
                         $(HW_CFLAGS) \
@@ -632,8 +689,14 @@
 
 # hw sources
 #
+ifeq ($(TARGET_ARCH),arm)
 CORE_HW_SOURCES = hw/arm_boot.c \
                   hw/android_arm.c
+endif
+
+ifeq ($(TARGET_ARCH),x86)
+CORE_HW_SOURCES = hw/pc.c
+endif
 
 # migration sources
 #
@@ -662,7 +725,6 @@
                     qemu-error.c \
                     qerror.c \
                     disas.c \
-                    arm-dis.c \
                     aes.c \
                     d3des.c \
                     vnc-android.c \
@@ -703,6 +765,10 @@
                     android/snapshot.c \
                     android/utils/timezone.c \
 
+ifeq ($(TARGET_ARCH),arm)
+    CORE_MISC_SOURCES += arm-dis.c
+endif
+
 ifeq ($(HOST_ARCH),x86)
     CORE_MISC_SOURCES += i386-dis.c
 endif
@@ -834,7 +900,12 @@
 LOCAL_NO_DEFAULT_COMPILER_FLAGS := true
 LOCAL_CC                        := $(MY_CC)
 LOCAL_MODULE                    := emulator
+ifeq ($(TARGET_ARCH),arm)
 LOCAL_STATIC_LIBRARIES          := emulator-memcheck emulator-hw emulator-arm emulator-tcg
+endif
+ifeq ($(TARGET_ARCH),x86)
+LOCAL_STATIC_LIBRARIES          := emulator-memcheck emulator-hw emulator-i386 emulator-tcg
+endif
 LOCAL_STATIC_LIBRARIES          += emulator-elff
 LOCAL_STATIC_LIBRARIES          += emulator-core emulator-uilib
 LOCAL_LDLIBS                    := $(MY_LDLIBS)
@@ -867,7 +938,7 @@
 
 ifeq ($(HOST_ARCH),x86)
 # enable MMX code for our skin scaler
-LOCAL_CFLAGS += -DUSE_MMX=1 -mmmx
+LOCAL_CFLAGS += -DUSE_MMX=1 -mmmx -DNEED_CPU_H
 endif
 
 # include other sources
@@ -1022,7 +1093,13 @@
 LOCAL_NO_DEFAULT_COMPILER_FLAGS := true
 LOCAL_CC                        := $(MY_CC)
 LOCAL_MODULE                    := qemu-android
+ifeq ($(TARGET_ARCH),arm)
 LOCAL_STATIC_LIBRARIES          := emulator-memcheck emulator-hw emulator-arm emulator-tcg
+endif
+ifeq ($(TARGET_ARCH),x86)
+LOCAL_STATIC_LIBRARIES          := emulator-memcheck emulator-hw emulator-i386 emulator-tcg
+endif
+
 LOCAL_STATIC_LIBRARIES          += emulator-elff
 LOCAL_STATIC_LIBRARIES          += emulator-core
 LOCAL_LDLIBS                    := $(MY_LDLIBS)
@@ -1281,4 +1358,4 @@
 
 include $(BUILD_HOST_EXECUTABLE)
 
-endif  # TARGET_ARCH == arm
+endif  # TARGET_ARCH == arm || TARGET_ARCH == x86
diff --git a/android-configure.sh b/android-configure.sh
index 8b5ea7e..9af5c3a 100755
--- a/android-configure.sh
+++ b/android-configure.sh
@@ -388,7 +388,14 @@
 
 create_config_mk
 echo "" >> $config_mk
+if [ $TARGET_ARCH = arm ] ; then
 echo "TARGET_ARCH       := arm" >> $config_mk
+fi
+
+if [ $TARGET_ARCH = x86 ] ; then
+echo "TARGET_ARCH       := x86" >> $config_mk
+fi
+
 echo "HOST_PREBUILT_TAG := $TARGET_OS" >> $config_mk
 echo "HOST_EXEEXT       := $TARGET_EXEEXT" >> $config_mk
 echo "PREBUILT          := $ANDROID_PREBUILT" >> $config_mk
diff --git a/android/avd/info.c b/android/avd/info.c
index d620b83..3d91a30 100644
--- a/android/avd/info.c
+++ b/android/avd/info.c
@@ -1190,7 +1190,12 @@
     if ( !imageLoader_load( l, IMAGE_OPTIONAL |
                                IMAGE_DONT_LOCK ) )
     {
+#ifdef TARGET_ARM
 #define  PREBUILT_KERNEL_PATH   "prebuilt/android-arm/kernel/kernel-qemu"
+#endif
+#ifdef TARGET_I386
+#define  PREBUILT_KERNEL_PATH   "prebuilt/android-x86/kernel/kernel-qemu"
+#endif
         p = bufprint(temp, end, "%s/%s", i->androidBuildRoot,
                         PREBUILT_KERNEL_PATH);
         if (p >= end || !path_exists(temp)) {
diff --git a/android/build/common.sh b/android/build/common.sh
index b053b97..2f44d70 100644
--- a/android/build/common.sh
+++ b/android/build/common.sh
@@ -553,7 +553,12 @@
 add_android_config_mk ()
 {
     echo "" >> $config_mk
+    if [ $TARGET_ARCH = arm ] ; then
     echo "TARGET_ARCH       := arm" >> $config_mk
+    fi
+    if [ $TARGET_ARCH = x86 ] ; then
+    echo "TARGET_ARCH       := x86" >> $config_mk
+    fi
     echo "HOST_PREBUILT_TAG := $HOST_TAG" >> $config_mk
     echo "PREBUILT          := $ANDROID_PREBUILT" >> $config_mk
 }
diff --git a/android/config/config.h b/android/config/config.h
index 7ceac69..fdfbe31 100644
--- a/android/config/config.h
+++ b/android/config/config.h
@@ -1,16 +1,23 @@
 /* Automatically generated by configure - do not modify */
 #include "config-host.h"
-#define CONFIG_QEMU_PREFIX "/usr/gnemul/qemu-arm"
-#define TARGET_ARCH "arm"
-#define TARGET_ARM 1
+
 #define TARGET_PHYS_ADDR_BITS  32
 #define CONFIG_TRACE 1
 #define CONFIG_NAND 1
 #define CONFIG_SHAPER 1
 #define CONFIG_SOFTMMU 1
-#define CONFIG_SOFTFLOAT 1
 #define CONFIG_SDL 1
 #ifndef _WIN32
 #define CONFIG_NAND_LIMITS 1
 #endif
 #define CONFIG_ANDROID_SNAPSHOTS 1
+
+#ifdef ARCH_FLAGS_x86
+#define TARGET_ARCH "x86"
+#define TARGET_I386 1
+#else
+#define TARGET_ARCH "arm"
+#define TARGET_ARM 1
+#define CONFIG_SOFTFLOAT 1
+#endif
+
diff --git a/android/hw-qemud.c b/android/hw-qemud.c
index 8f92bcd..e1cd119 100644
--- a/android/hw-qemud.c
+++ b/android/hw-qemud.c
@@ -50,8 +50,12 @@
  * talking to a legacy qemud daemon. See docs/ANDROID-QEMUD.TXT
  * for details.
  */
+#ifdef TARGET_ARM
 #define  SUPPORT_LEGACY_QEMUD  1
-
+#endif
+#ifdef TARGET_I386
+#define  SUPPORT_LEGACY_QEMUD  0 /* no legacy support */
+#endif
 #if SUPPORT_LEGACY_QEMUD
 #include "telephony/android_modem.h"
 #include "telephony/modem_driver.h"
diff --git a/android/main.c b/android/main.c
index e38c0e3..32f4143 100644
--- a/android/main.c
+++ b/android/main.c
@@ -56,6 +56,11 @@
 #include "android/framebuffer.h"
 #include "iolooper.h"
 
+#ifdef TARGET_I386
+nand_threshold android_nand_read_threshold;
+nand_threshold android_nand_write_threshold;
+#endif
+
 AndroidRotation  android_framebuffer_rotation;
 
 #define  STRINGIFY(x)   _STRINGIFY(x)
@@ -1119,6 +1124,9 @@
         char        *p = params, *end = p + sizeof(params);
 
         p = bufprint(p, end, "qemu=1 console=ttyS0" );
+#ifdef TARGET_I386
+        p = bufprint(p, end, " androidboot.hardware=goldfish");
+#endif
 
         if (opts->shell || opts->logcat) {
             p = bufprint(p, end, " androidboot.console=ttyS%d", shell_serial );
diff --git a/cpu-all.h b/cpu-all.h
index 22a068d..01e6838 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -762,7 +762,6 @@
 int page_check_range(target_ulong start, target_ulong len, int flags);
 #endif
 
-void cpu_exec_init_all(unsigned long tb_size);
 CPUState *cpu_copy(CPUState *env);
 CPUState *qemu_get_cpu(int cpu);
 
diff --git a/hw/goldfish_events_device.c b/hw/goldfish_events_device.c
index 549fe4b..afc1724 100644
--- a/hw/goldfish_events_device.c
+++ b/hw/goldfish_events_device.c
@@ -149,7 +149,23 @@
     if(s->first == s->last) {
         qemu_irq_lower(s->irq);
     }
-
+#ifdef TARGET_I386
+    /*
+     * Adding the logic to handle edge-triggered interrupts for x86
+     * because the exisiting goldfish events device basically provides
+     * level-trigger interrupts only.
+     *
+     * Logic: When an event (including the type/code/value) is fetched
+     * by the driver, if there is still another event in the event
+     * queue, the goldfish event device will re-assert the IRQ so that
+     * the driver can be notified to fetch the event again.
+     */
+    else if (((s->first + 2) & (MAX_EVENTS - 1)) < s->last ||
+               (s->first & (MAX_EVENTS - 1)) > s->last) { /* if there still is an event */
+        qemu_irq_lower(s->irq);
+        qemu_irq_raise(s->irq);
+    }
+#endif
     return n;
 }
 
diff --git a/hw/isa.h b/hw/isa.h
index 09b32a1..2f527c0 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -6,6 +6,8 @@
 #include "ioport.h"
 #include "qdev.h"
 
+extern target_phys_addr_t isa_mem_base;
+
 void isa_mmio_init(target_phys_addr_t base, target_phys_addr_t size);
 
 /* dma.c */
diff --git a/hw/pci_host.h b/hw/pci_host.h
index 757b0e2..0465e02 100644
--- a/hw/pci_host.h
+++ b/hw/pci_host.h
@@ -34,11 +34,10 @@
 #else
 #define PCI_DPRINTF(fmt, ...)
 #endif
-
-typedef struct {
+struct PCIHostState {
     uint32_t config_reg;
     PCIBus *bus;
-} PCIHostState;
+};
 
 static void pci_host_data_writeb(void* opaque, pci_addr_t addr, uint32_t val)
 {
diff --git a/monitor.c b/monitor.c
index f211032..2d0a071 100644
--- a/monitor.c
+++ b/monitor.c
@@ -90,6 +90,28 @@
 
 static QLIST_HEAD(mon_list, Monitor) mon_list;
 
+#if defined(TARGET_I386)
+static void do_inject_mce(Monitor *mon,
+                          int cpu_index, int bank,
+                          unsigned status_hi, unsigned status_lo,
+                          unsigned mcg_status_hi, unsigned mcg_status_lo,
+                          unsigned addr_hi, unsigned addr_lo,
+                          unsigned misc_hi, unsigned misc_lo)
+{
+    CPUState *cenv;
+    uint64_t status = ((uint64_t)status_hi << 32) | status_lo;
+    uint64_t mcg_status = ((uint64_t)mcg_status_hi << 32) | mcg_status_lo;
+    uint64_t addr = ((uint64_t)addr_hi << 32) | addr_lo;
+    uint64_t misc = ((uint64_t)misc_hi << 32) | misc_lo;
+
+    for (cenv = first_cpu; cenv != NULL; cenv = cenv->next_cpu)
+        if (cenv->cpu_index == cpu_index && cenv->mcg_cap) {
+            cpu_inject_x86_mce(cenv, bank, status, mcg_status, addr, misc);
+            break;
+        }
+}
+#endif
+
 static const mon_cmd_t mon_cmds[];
 static const mon_cmd_t info_cmds[];
 
@@ -2403,7 +2425,15 @@
                       void *arg3, void *arg4, void *arg5);
     void (*handler_7)(Monitor *mon, void *arg0, void *arg1, void *arg2,
                       void *arg3, void *arg4, void *arg5, void *arg6);
-
+    void (*handler_8)(Monitor *mon, void *arg0, void *arg1, void *arg2,
+                      void *arg3, void *arg4, void *arg5, void *arg6,
+                      void *arg7);
+    void (*handler_9)(Monitor *mon, void *arg0, void *arg1, void *arg2,
+                      void *arg3, void *arg4, void *arg5, void *arg6,
+                      void *arg7, void *arg8);
+    void (*handler_10)(Monitor *mon, void *arg0, void *arg1, void *arg2,
+                       void *arg3, void *arg4, void *arg5, void *arg6,
+                       void *arg7, void *arg8, void *arg9);
 #ifdef DEBUG
     monitor_printf(mon, "command='%s'\n", cmdline);
 #endif
@@ -2691,6 +2721,21 @@
         handler_7(mon, args[0], args[1], args[2], args[3], args[4], args[5],
                   args[6]);
         break;
+    case 8:
+        handler_8 = cmd->handler;
+        handler_8(mon, args[0], args[1], args[2], args[3], args[4], args[5],
+                  args[6], args[7]);
+        break;
+    case 9:
+        handler_9 = cmd->handler;
+        handler_9(mon, args[0], args[1], args[2], args[3], args[4], args[5],
+                  args[6], args[7], args[8]);
+        break;
+    case 10:
+        handler_10 = cmd->handler;
+        handler_10(mon, args[0], args[1], args[2], args[3], args[4], args[5],
+                   args[6], args[7], args[8], args[9]);
+        break;
     default:
         monitor_printf(mon, "unsupported number of arguments: %d\n", nb_args);
         goto fail;
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index fa48527..fd158ea 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -491,7 +491,7 @@
 @item migrate_set_downtime @var{second}
 Set maximum tolerated downtime (in seconds) for migration.
 ETEXI
-
+#ifndef CONFIG_ANDROID
 #if defined(TARGET_I386)
     { "drive_add", "ss", drive_hot_add, "pci_addr=[[<domain>:]<bus>:]<slot>\n"
                                          "[file=file][,if=type][,bus=n]\n"
@@ -500,22 +500,28 @@
                                         "[snapshot=on|off][,cache=on|off]",
                                         "add drive to PCI storage controller" },
 #endif
+#endif
 STEXI
 @item drive_add
 Add drive to PCI storage controller.
 ETEXI
 
+#ifndef CONFIG_ANDROID
 #if defined(TARGET_I386)
     { "pci_add", "sss", pci_device_hot_add, "pci_addr=auto|[[<domain>:]<bus>:]<slot> nic|storage [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]...", "hot-add PCI device" },
 #endif
+#endif
+
 STEXI
 @item pci_add
 Hot-add PCI device.
 ETEXI
 
+#ifndef CONFIG_ANDROID
 #if defined(TARGET_I386)
     { "pci_del", "s", pci_device_hot_remove, "pci_addr=[[<domain>:]<bus>:]<slot>", "hot remove PCI device" },
 #endif
+#endif
 STEXI
 @item pci_del
 Hot remove PCI device.
@@ -611,6 +617,14 @@
 @end table
 ETEXI
 
+#if defined(TARGET_I386)
+    { "mce", "iillll", do_inject_mce, "cpu bank status mcgstatus addr misc", "inject a MCE on the given CPU"},
+#endif
+STEXI
+@item mce @var{cpu} @var{bank} @var{status} @var{mcgstatus} @var{addr} @var{misc}
+Inject an MCE on the given CPU (x86 only).
+ETEXI
+
 STEXI
 @end table
 ETEXI
diff --git a/sysemu.h b/sysemu.h
index 66414a3..0180dc0 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -52,7 +52,7 @@
 int qemu_reset_requested(void);
 int qemu_powerdown_requested(void);
 #ifdef NEED_CPU_H
-#if !defined(TARGET_SPARC) && !defined(TARGET_I386)
+#if !defined(TARGET_SPARC)
 // Please implement a power failure function to signal the OS
 #define qemu_system_powerdown() do{}while(0)
 #else
@@ -216,12 +216,14 @@
 void destroy_nic(dev_match_fn *match_fn, void *arg);
 void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
 
+#ifndef CONFIG_ANDROID
 /* pci-hotplug */
 void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
                         const char *opts);
 void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts);
 void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
 void pci_device_hot_remove_success(int pcibus, int slot);
+#endif
 
 /* serial ports */
 
diff --git a/vl-android.c b/vl-android.c
index 60c3a01..caef03d 100644
--- a/vl-android.c
+++ b/vl-android.c
@@ -4267,11 +4267,13 @@
             case QEMU_OPTION_rtc_td_hack:
                 rtc_td_hack = 1;
                 break;
+#ifndef CONFIG_ANDROID
             case QEMU_OPTION_acpitable:
                 if(acpi_table_add(optarg) < 0) {
                     PANIC("Wrong acpi table provided");
                 }
                 break;
+#endif
             case QEMU_OPTION_smbios:
                 if(smbios_entry_add(optarg) < 0) {
                     PANIC("Wrong smbios provided");