error_handler: unify stack walking logic
[sdk/emulator/qemu.git] / vl.c
diff --git a/vl.c b/vl.c
index a455947..cf0f23b 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -37,6 +37,7 @@
 #ifdef CONFIG_SDL
 #if defined(__APPLE__) || defined(main)
 #include <SDL.h>
+#ifndef CONFIG_MARU
 int qemu_main(int argc, char **argv, char **envp);
 int main(int argc, char **argv)
 {
@@ -45,6 +46,7 @@ int main(int argc, char **argv)
 #undef main
 #define main qemu_main
 #endif
+#endif
 #endif /* CONFIG_SDL */
 
 #ifdef CONFIG_COCOA
@@ -52,6 +54,13 @@ int main(int argc, char **argv)
 #define main qemu_main
 #endif /* CONFIG_COCOA */
 
+#ifdef CONFIG_MARU
+#ifdef main
+#undef main
+#endif
+int qemu_main(int argc, char **argv, char **envp);
+#define main qemu_main
+#endif
 
 #include "qemu/error-report.h"
 #include "qemu/sockets.h"
@@ -90,6 +99,7 @@ int main(int argc, char **argv)
 #include "migration/migration.h"
 #include "sysemu/cpus.h"
 #include "sysemu/kvm.h"
+#include "sysemu/hax.h"
 #include "qapi/qmp/qjson.h"
 #include "qemu/option.h"
 #include "qemu/config-file.h"
@@ -122,6 +132,20 @@ int main(int argc, char **argv)
 #include "sysemu/replay.h"
 #include "qapi/qmp/qerror.h"
 
+#ifdef CONFIG_MARU
+#include "tizen/src/emulator.h"
+#include "tizen/src/emul_state.h"
+#include "tizen/src/ui/qt5.h"
+#include "tizen/src/util/ui_operations.h"
+#include "tizen/src/ecs/ecs.h"
+#include "tizen/src/util/error_handler.h"
+#include "tizen/src/util/exported_strings.h"
+
+inline static bool is_maru_machine(MachineClass *mc) {
+   return g_str_has_prefix(mc->name, "maru");
+}
+#endif
+
 #define MAX_VIRTIO_CONSOLES 1
 #define MAX_SCLP_CONSOLES 1
 
@@ -1810,11 +1834,18 @@ void qemu_system_killed(int signal, pid_t pid)
     shutdown_pid = pid;
     no_shutdown = 0;
 
+#ifdef CONFIG_MARU
+    if (current_machine &&
+            is_maru_machine(MACHINE_GET_CLASS(current_machine))) {
+        qemu_system_graceful_shutdown_request(TIMEOUT_FOR_SHUTDOWN);
+    }
+#else
     /* Cannot call qemu_system_shutdown_request directly because
      * we are in a signal handler.
      */
     shutdown_requested = 1;
     qemu_notify_event();
+#endif
 }
 
 void qemu_system_shutdown_request(void)
@@ -1900,8 +1931,11 @@ static void main_loop(void)
 #ifdef CONFIG_PROFILER
     int64_t ti;
 #endif
+
+    hax_sync_vcpus();
+
     do {
-        nonblocking = !kvm_enabled() && !xen_enabled() && last_io > 0;
+        nonblocking = !kvm_enabled() && !xen_enabled() && !hax_enabled() && last_io > 0;
 #ifdef CONFIG_PROFILER
         ti = profile_getclock();
 #endif
@@ -1914,7 +1948,8 @@ static void main_loop(void)
 
 static void version(void)
 {
-    printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
+    printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", "
+           QEMU_COPYRIGHT "\n");
 }
 
 static void help(int exitcode)
@@ -2058,6 +2093,13 @@ typedef enum DisplayType {
     DT_SDL,
     DT_COCOA,
     DT_GTK,
+#ifdef CONFIG_MARU
+    DT_MARU_REMOTE_SPICE,
+# ifdef CONFIG_QT
+    DT_MARU_QT_ONSCREEN,
+    DT_MARU_QT_OFFSCREEN,
+# endif
+#endif
     DT_NONE,
 } DisplayType;
 
@@ -2177,6 +2219,64 @@ static DisplayType select_display(const char *p)
         error_report("GTK support is disabled");
         exit(1);
 #endif
+#ifdef CONFIG_MARU
+    } else if (strstart(p, "maru_remote_spice", &opts)) {
+# ifdef CONFIG_SPICE
+        display = DT_MARU_REMOTE_SPICE;
+# else
+        fprintf(stderr, "maru_remote_spice is disabled\n");
+        exit(1);
+# endif
+    } else if (strstart(p, "maru_qt", &opts)) {
+# ifdef CONFIG_QT
+        display = DT_MARU_QT_ONSCREEN;
+        while (*opts) {
+            const char *nextopt;
+            if (strstart(opts, ",rendering=", &nextopt)) {
+                opts = nextopt;
+                if (strstart(opts, "onscreen", &nextopt)) {
+                    display = DT_MARU_QT_ONSCREEN;
+                } else if (strstart(opts, "offscreen", &nextopt)) {
+                    display = DT_MARU_QT_OFFSCREEN;
+                } else {
+                    goto invalid_maru_qt_args;
+                }
+            } else if (strstart(opts, ",resolution=", &nextopt)) {
+                opts = nextopt;
+                char *endptr = NULL;
+                // Resolution should be formed "640x480" or "640*480".
+                int width = (int)g_ascii_strtoll(opts, &endptr, 10);
+                int height = (int)g_ascii_strtoll(++endptr, &endptr, 10);
+                if (width <= 0 || height <= 0) {
+                    goto invalid_maru_qt_args;
+                }
+                set_initial_display_resolution(width, height);
+                nextopt = endptr;
+            } else if (strstart(opts, ",dpi=", &nextopt)) {
+                opts = nextopt;
+                char *endptr = NULL;
+                int dpi = (int)g_ascii_strtoll(opts, &endptr, 10);
+                if (dpi <= 0) {
+                    goto invalid_maru_qt_args;
+                }
+                set_display_pixel_density(dpi);
+                nextopt = endptr;
+            } else if (strstart(opts, ",forcelegacy", &nextopt)) {
+                opts = nextopt;
+                maru_qt5_set_force_legacy(true);
+            } else {
+            invalid_maru_qt_args:
+                error_report(FAILED_TO_DISPLAY_PARSING);
+                exit(1);
+            }
+            opts = nextopt;
+        }
+# else
+        error_report("maru_qt is disabled.\n");
+
+        exit(1);
+# endif
+#endif /* CONFIG_MARU */
     } else if (strstart(p, "none", &opts)) {
         display = DT_NONE;
     } else {
@@ -2922,10 +3022,19 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
     g->user_provided = true;
+    g->errp = &error_fatal;
     qdev_prop_register_global(g);
     return 0;
 }
 
+#ifdef CONFIG_MARU
+// W/A for preserve larger continuous heap for RAM.
+extern void *preallocated_ram_ptr;
+extern int preallocated_ram_size;
+// FIXME
+extern bool nodisplay;
+#endif
+
 int main(int argc, char **argv, char **envp)
 {
     int i;
@@ -2962,6 +3071,13 @@ int main(int argc, char **argv, char **envp)
     Error *main_loop_err = NULL;
     Error *err = NULL;
     bool list_data_dirs = false;
+#ifdef CONFIG_YAGL
+    static bool yagl_enabled = false;
+#endif /* CONFIG_YAGL */
+#ifdef CONFIG_VIGS
+    static bool vigs_enabled = false;
+    static char *vigs_backend = NULL;
+#endif /* CONFIG_VIGS */
 
     qemu_init_cpu_loop();
     qemu_mutex_lock_iothread();
@@ -3648,6 +3764,30 @@ int main(int argc, char **argv, char **envp)
                 olist = qemu_find_opts("machine");
                 qemu_opts_parse_noisily(olist, "accel=kvm", false);
                 break;
+           case QEMU_OPTION_enable_yagl:
+#if defined(CONFIG_YAGL)
+                yagl_enabled = true;
+#else
+                fprintf(stderr, "YaGL openGLES passthrough support is disabled,"
+                    " ignoring -enable-yagl\n");
+#endif
+                break;
+           case QEMU_OPTION_enable_vigs:
+#if defined(CONFIG_VIGS)
+                vigs_enabled = true;
+#else
+                fprintf(stderr, "VIGS support is disabled,"
+                    " ignoring -enable-vigs\n");
+#endif
+                break;
+           case QEMU_OPTION_vigs_backend:
+#if defined(CONFIG_VIGS)
+                vigs_backend = g_strdup(optarg);
+#else
+                fprintf(stderr, "VIGS support is disabled,"
+                    " ignoring -vigs-backend\n");
+#endif
+                break;
             case QEMU_OPTION_M:
             case QEMU_OPTION_machine:
                 olist = qemu_find_opts("machine");
@@ -3920,6 +4060,10 @@ int main(int argc, char **argv, char **envp)
                     exit(1);
                 }
                 break;
+            case QEMU_OPTION_enable_hax:
+                olist = qemu_find_opts("machine");
+                qemu_opts_parse_noisily(olist, "accel=hax", false);
+                break;
             case QEMU_OPTION_add_fd:
 #ifndef _WIN32
                 opts = qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
@@ -3933,6 +4077,11 @@ int main(int argc, char **argv, char **envp)
                 exit(1);
 #endif
                 break;
+#if defined(CONFIG_MARU)
+            case QEMU_OPTION_enable_suspend:
+                ecs_set_suspend_state(SUSPEND_UNLOCK);
+                break;
+#endif
             case QEMU_OPTION_object:
                 opts = qemu_opts_parse_noisily(qemu_find_opts("object"),
                                                optarg, true);
@@ -3983,6 +4132,15 @@ int main(int argc, char **argv, char **envp)
 
     machine_class = select_machine();
 
+#if defined(CONFIG_MARU)
+    if (is_maru_machine(machine_class)) {
+        preallocated_ram_ptr = qemu_anon_ram_alloc(ram_size, NULL);
+        if (preallocated_ram_ptr) {
+            preallocated_ram_size = ram_size;
+        }
+    }
+#endif
+
     set_memory_options(&ram_slots, &maxram_size, machine_class);
 
     os_daemonize();
@@ -4233,6 +4391,16 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
+#ifdef CONFIG_MARU
+# if defined(CONFIG_QT)
+    if (display_type == DT_MARU_QT_ONSCREEN) {
+        maru_early_qt5_display_init(true);
+    } else if (display_type == DT_MARU_QT_OFFSCREEN) {
+        maru_early_qt5_display_init(false);
+    }
+# endif
+#endif
+
     page_size_init();
     socket_init();
 
@@ -4271,8 +4439,6 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
-    configure_accelerator(current_machine);
-
     if (qtest_chrdev) {
         qtest_init(qtest_chrdev, qtest_log, &error_fatal);
     }
@@ -4337,7 +4503,7 @@ int main(int argc, char **argv, char **envp)
 
     cpu_ticks_init();
     if (icount_opts) {
-        if (kvm_enabled() || xen_enabled()) {
+        if (kvm_enabled() || xen_enabled() || hax_enabled()) {
             error_report("-icount is not allowed with kvm or xen");
             exit(1);
         }
@@ -4462,10 +4628,28 @@ int main(int argc, char **argv, char **envp)
     current_machine->boot_order = boot_order;
     current_machine->cpu_model = cpu_model;
 
+    configure_accelerator(current_machine);
+
+#if defined(CONFIG_MARU)
+    if (is_maru_machine(machine_class)) {
+        kernel_cmdline = qemu_opt_get(machine_opts, "append");
+        // Returned variable points different address from input variable.
+        kernel_cmdline = prepare_maru(kernel_cmdline);
+        qemu_opt_set(qemu_get_machine_opts(), "append",
+                kernel_cmdline, &error_abort);
+
+        current_machine->kernel_cmdline = (char *)kernel_cmdline;
+        if (display_type == DT_NONE) {
+            nodisplay = true;
+        }
+    }
+#endif
+
     machine_class->init(current_machine);
 
     realtime_init();
 
+    // TODO: Check about it...
     audio_init();
 
     cpu_synchronize_all_post_init();
@@ -4477,6 +4661,10 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
+    if (hax_enabled()) {
+        hax_sync_vcpus();
+    }
+
     /* init USB devices */
     if (machine_usb(current_machine)) {
         if (foreach_device_config(DEV_USB, usb_parse) < 0)
@@ -4494,6 +4682,37 @@ int main(int argc, char **argv, char **envp)
     }
     rom_reset_order_override();
 
+#if defined(CONFIG_MARU)
+    if (is_maru_machine(machine_class)) {
+        prepare_maru_after_device_init();
+    }
+#endif
+#ifdef CONFIG_VIGS
+    // To support legacy VIGS options
+    if (vigs_enabled) {
+        PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
+        PCIDevice *pci_dev = pci_create(pci_bus, -1, "vigs");
+        if (vigs_backend) {
+            qdev_prop_set_string(&pci_dev->qdev, "backend", vigs_backend);
+        } else {
+            qdev_prop_set_string(&pci_dev->qdev, "backend", "gl");
+        }
+        qdev_prop_set_string(&pci_dev->qdev, "wsi", "wsi0");
+        qdev_init_nofail(&pci_dev->qdev);
+    }
+#endif
+#ifdef CONFIG_YAGL
+    // To support legacy YaGL options
+    if (yagl_enabled) {
+        PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
+        PCIDevice *pci_dev = pci_create(pci_bus, -1, "yagl");
+        if (vigs_enabled) {
+            qdev_prop_set_string(&pci_dev->qdev, "wsi", "wsi0");
+        }
+        qdev_init_nofail(&pci_dev->qdev);
+    }
+#endif
+
     /* Did we create any drives that we failed to create a device for? */
     drive_check_orphaned();
 
@@ -4531,6 +4750,19 @@ int main(int argc, char **argv, char **envp)
     case DT_GTK:
         gtk_display_init(ds, full_screen, grab_on_hover);
         break;
+#if defined(CONFIG_MARU)
+ #if defined(CONFIG_QT)
+    case DT_MARU_QT_ONSCREEN:
+    case DT_MARU_QT_OFFSCREEN:
+        if (!is_maru_machine(machine_class)) {
+            error_report("maru_qt can not work"
+                    " without maru machine");
+            exit(1);
+        }
+        maru_qt5_display_init(ds, full_screen);
+        break;
+ #endif
+#endif
     default:
         break;
     }
@@ -4598,6 +4830,9 @@ int main(int argc, char **argv, char **envp)
 
     os_setup_post();
 
+#ifdef CONFIG_MARU
+    enable_print_backtrace_at_normal_exit();
+#endif
     trace_init_vcpu_events();
     main_loop();
     replay_disable_events();
@@ -4611,7 +4846,20 @@ int main(int argc, char **argv, char **envp)
 
     /* vhost-user must be cleaned up before chardevs.  */
     net_cleanup();
+    audio_cleanup();
+    monitor_cleanup();
     qemu_chr_cleanup();
 
+#if defined(CONFIG_MARU) && defined(CONFIG_QT)
+    switch (display_type) {
+    case DT_MARU_QT_ONSCREEN:
+    case DT_MARU_QT_OFFSCREEN:
+        maru_qt5_display_fini();
+        break;
+    default:
+        break;
+    }
+#endif
+
     return 0;
 }