Merge upstream QEMU 10.0.50 into the Android source tree.

This change integrates many changes from the upstream QEMU sources.
Its main purpose is to enable correct ARMv6 and ARMv7 support to the
Android emulator. Due to the nature of the upstream code base, this
unfortunately also required changes to many other parts of the source.

Note that to ensure easier integrations in the future, some source files
and directories that have heavy Android-specific customization have been
renamed with an -android suffix. The original files are still there for
easier integration tracking, but *never* compiled. For example:

  net.c        net-android.c
  qemu-char.c  qemu-char-android.c
  slirp/       slirp-android/
  etc...

Tested on linux-x86, darwin-x86 and windows host machines.
diff --git a/Makefile.android b/Makefile.android
index a844a6b..0cc5ed5 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -9,10 +9,12 @@
 
 CONFIG_INCLUDES := $(CONFIG_DIRS:%=-I%)
 
-MY_CFLAGS := $(CONFIG_INCLUDES) -O2 -g \
-             -fno-PIC \
-             -falign-functions=0 \
-             -fomit-frame-pointer \
+MY_OPTIM := -O2 -g -fno-PIC -falign-functions=0 -fomit-frame-pointer
+ifeq ($(BUILD_DEBUG_EMULATOR),true)
+    MY_OPTIM := -O0 -g
+endif
+
+MY_CFLAGS := $(CONFIG_INCLUDES) $(MY_OPTIM)
 
 # Overwrite configuration for debug builds.
 #
@@ -121,7 +123,6 @@
 
 LOCAL_SRC_FILES := \
     tcg/tcg.c \
-    tcg/tcg-dyngen.c \
     tcg/tcg-runtime.c \
 
 include $(BUILD_HOST_STATIC_LIBRARY)
@@ -144,6 +145,11 @@
 HW_SOURCES := \
     android_arm.c \
     arm_pic.c \
+    bt.c \
+    bt-hci.c \
+    bt-hid.c \
+    bt-l2cap.c \
+    bt-sdp.c \
     cdrom.c \
     dma.c \
     irq.c \
@@ -160,14 +166,18 @@
     goldfish_timer.c \
     goldfish_trace.c \
     goldfish_tty.c \
+    msmouse.c \
     pci.c \
+    qdev.c \
     scsi-disk.c \
     smc91c111.c \
+    sysbus.c \
     usb-hid.c \
     usb-hub.c \
     usb-msd.c \
     usb-ohci.c \
     usb.c \
+    watchdog.c \
 
 LOCAL_SRC_FILES += $(HW_SOURCES:%=hw/%)
 
@@ -243,6 +253,7 @@
 
 ifeq ($(HOST_OS),darwin)
   CONFIG_COREAUDIO ?= yes
+  AUDIO_CFLAGS += -DHOST_BSD=1
 endif
 
 ifeq ($(HOST_OS),windows)
@@ -344,9 +355,9 @@
 LOCAL_LDLIBS                    := $(MY_LDLIBS)
 
 # don't remove the -fno-strict-aliasing, or you'll break things
-# (e.g. slirp2/network support)
+# (e.g. slirp-android/network support)
 #
-LOCAL_CFLAGS := -fno-PIC -fomit-frame-pointer -Wno-sign-compare \
+LOCAL_CFLAGS := -fno-PIC -Wno-sign-compare \
                 -fno-strict-aliasing -g -W -Wall -Wno-unused-parameter
 
 LOCAL_CFLAGS := $(MY_CFLAGS) $(LOCAL_CFLAGS)
@@ -370,6 +381,9 @@
                    $(TCG_CFLAGS) \
                    $(HW_CFLAGS) \
 
+# Needed by the upstream code
+LOCAL_CFLAGS += -DNEED_CPU_H
+
 # include telephony stuff
 #
 TELEPHONY_SOURCES := android_modem.c modem_driver.c gsm.c sim_card.c sysdeps_qemu.c sms.c remote_call.c
@@ -392,14 +406,14 @@
 LOCAL_CFLAGS  += $(AUDIO_CFLAGS)
 LOCAL_LDLIBS  += $(AUDIO_LDLIBS)
 
-# include slirp2 code, i.e. the user-level networking stuff
+# include slirp-android code, i.e. the user-level networking stuff
 #
 SLIRP_SOURCES := bootp.c     cksum.c      debug.c  if.c     ip_icmp.c  ip_input.c   ip_output.c  \
                  mbuf.c      misc.c       sbuf.c   slirp.c  socket.c   tcp_input.c  tcp_output.c \
                  tcp_subr.c  tcp_timer.c  tftp.c   udp.c
 
-LOCAL_SRC_FILES += $(SLIRP_SOURCES:%=slirp2/%)
-LOCAL_CFLAGS    += -I$(LOCAL_PATH)/slirp2
+LOCAL_SRC_FILES += $(SLIRP_SOURCES:%=slirp-android/%)
+LOCAL_CFLAGS    += -I$(LOCAL_PATH)/slirp-android
 
 # socket proxy support
 #
@@ -441,16 +455,37 @@
 
 # include other sources
 #
-VL_SOURCES := vl.c osdep.c cutils.c \
+VL_SOURCES := vl-android.c osdep.c cutils.c \
               block.c readline.c monitor.c console.c loader.c sockets.c \
-              block-qcow.c aes.c d3des.c block-cloop.c block-dmg.c block-vvfat.c \
-              block-qcow2.c block-cow.c \
+              aes.c d3des.c \
+              block/qcow.c \
+              block/qcow2.c \
+              block/qcow2-refcount.c \
+              block/qcow2-snapshot.c \
+              block/qcow2-cluster.c \
+              block/cloop.c \
+              block/dmg.c \
+              block/vvfat.c \
+              buffered_file.c \
               cbuffer.c \
-              gdbstub.c usb-linux.c \
-              vnc.c disas.c arm-dis.c \
+              gdbstub.c \
+              vnc-android.c disas.c arm-dis.c \
               shaper.c charpipe.c loadpng.c \
               framebuffer.c \
               tcpdump.c \
+              qemu-char-android.c \
+              qemu-malloc.c \
+              qemu-option.c \
+              savevm.c \
+              net-android.c \
+              acl.c \
+              aio-android.c \
+              dma-helpers.c \
+              qemu-sockets-android.c \
+              keymaps.c \
+              bt-host.c \
+              bt-vhci.c \
+              module.c \
               android/boot-properties.c \
               android/charmap.c \
               android/cmdline-option.c \
@@ -486,13 +521,23 @@
               hw/android_arm.c \
 
 ifeq ($(HOST_OS),windows)
-  VL_SOURCES += block-raw-win32.c
+  VL_SOURCES += block/raw-win32.c \
+                migration-dummy-android.c \
+                iolooper-select.c
 else
-  VL_SOURCES += block-raw-posix.c
+  VL_SOURCES += block/raw-posix.c \
+                migration.c \
+                migration-exec.c \
+                migration-tcp-android.c \
+                iolooper-select.c
 endif
 
 ifeq ($(HOST_OS),linux)
+    VL_SOURCES += usb-linux.c \
+                  qemu-thread.c
     LOCAL_LDLIBS += -lX11
+else
+    VL_SOURCES += usb-dummy-android.c
 endif
 
 ifeq ($(HOST_ARCH),x86)
@@ -506,7 +551,7 @@
 endif
 
 ifeq ($(HOST_OS),windows)
-  #VL_SOURCES   += tap-win32.c
+  VL_SOURCES   += tap-win32.c
   LOCAL_LDLIBS += -mno-cygwin -mwindows -mconsole
 endif
 
@@ -542,6 +587,65 @@
 LOCAL_PREBUILT_OBJ_FILES += images/$(ANDROID_ICON_OBJ)
 endif
 
+# qemu-options.h is generated from qemu-options.hx with the "hxtool" shell script
+#
+intermediates := $(call intermediates-dir-for,EXECUTABLES,$(LOCAL_MODULE),true)
+
+QEMU_OPTIONS_H := $(intermediates)/qemu-options.h
+$(QEMU_OPTIONS_H): PRIVATE_PATH := $(LOCAL_PATH)
+$(QEMU_OPTIONS_H): PRIVATE_CUSTOM_TOOL = $(PRIVATE_PATH)/hxtool -h < $< > $@
+$(QEMU_OPTIONS_H): $(LOCAL_PATH)/qemu-options.hx $(LOCAL_PATH)/hxtool
+	$(transform-generated-source)
+
+$(intermediates)/vl-android.o: $(QEMU_OPTIONS_H)
+
+LOCAL_GENERATED_SOURCES += $(QEMU_OPTIONS_H)
+
+# qemu-monitor.h is generated from qemu-monitor.hx with the "hxtool" shell script
+#
+intermediates := $(call intermediates-dir-for,EXECUTABLES,$(LOCAL_MODULE),true)
+
+QEMU_MONITOR_H := $(intermediates)/qemu-monitor.h
+$(QEMU_MONITOR_H): PRIVATE_PATH := $(LOCAL_PATH)
+$(QEMU_MONITOR_H): PRIVATE_CUSTOM_TOOL = $(PRIVATE_PATH)/hxtool -h < $< > $@
+$(QEMU_MONITOR_H): $(LOCAL_PATH)/qemu-monitor.hx $(LOCAL_PATH)/hxtool
+	$(transform-generated-source)
+
+$(intermediates)/vl-android.o: $(QEMU_MONITOR_H)
+
+LOCAL_GENERATED_SOURCES += $(QEMU_MONITOR_H)
+
+
+# gdbstub-xml.c contains C-compilable arrays corresponding to the content
+# of $(LOCAL_PATH)/gdb-xml/, and is generated with the 'feature_to_c.sh' script.
+#
+ifeq ($(QEMU_TARGET_XML_SOURCES),)
+    QEMU_TARGET_XML_SOURCES := arm-core arm-neon arm-vfp arm-vfp3
+    QEMU_TARGET_XML_SOURCES := $(QEMU_TARGET_XML_SOURCES:%=$(LOCAL_PATH)/gdb-xml/%.xml)
+endif
+
+QEMU_GDBSTUB_XML_C := $(intermediates)/gdbstub-xml.c
+$(QEMU_GDBSTUB_XML_C): PRIVATE_PATH := $(LOCAL_PATH)
+$(QEMU_GDBSTUB_XML_C): PRIVATE_SOURCES := $(TARGET_XML_SOURCES)
+$(QEMU_GDBSTUB_XML_C): PRIVATE_CUSTOM_TOOL = $(PRIVATE_PATH)/feature_to_c.sh $@ $(QEMU_TARGET_XML_SOURCES)
+$(QEMU_GDBSTUB_XML_C): $(QEMU_TARGET_XML_SOURCES) $(LOCAL_PATH)/feature_to_c.sh
+	$(hide) rm -f $@
+	$(transform-generated-source)
+
+$(intermediates)/vl-android.o: $(QEMU_GDBSTUB_XML_C)
+
+LOCAL_GENERATED_SOURCES += $(QEMU_GDBSTUB_XML_C)
+
+
+# this is already done by the Android build system, but is done for the
+# benefit of the stand-alone one.
+#
+ifeq ($(BUILD_STANDALONE_EMULATOR),true)
+  LOCAL_CFLAGS += -I$(intermediates)
+endif
+
+
+
 # other flags
 LOCAL_CFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
 LOCAL_LDLIBS += -lm -lpthread