4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
33 /* Needed early for CONFIG_BSD etc. */
34 #include "config-host.h"
38 #include <sys/times.h>
42 #include <sys/ioctl.h>
43 #include <sys/resource.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
47 #include <arpa/inet.h>
50 #include <sys/select.h>
54 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
55 #include <sys/sysctl.h>
63 #include <linux/ppdev.h>
64 #include <linux/parport.h>
68 #include "qemu-seccomp.h"
73 #include <sys/ethernet.h>
74 #include <sys/sockio.h>
75 #include <netinet/arp.h>
76 #include <netinet/in_systm.h>
77 #include <netinet/ip.h>
78 #include <netinet/ip_icmp.h> // must come after ip.h
79 #include <netinet/udp.h>
80 #include <netinet/tcp.h>
88 #if defined(CONFIG_VDE)
89 #include <libvdeplug.h>
97 #if defined(__APPLE__) || defined(main)
100 int qemu_main(int argc, char **argv, char **envp);
101 int main(int argc, char **argv)
103 return qemu_main(argc, argv, NULL);
106 #define main qemu_main
109 #endif /* CONFIG_SDL */
113 #define main qemu_main
114 #endif /* CONFIG_COCOA */
120 int qemu_main(int argc, char **argv, char **envp);
121 #define main qemu_main
127 #include "hw/boards.h"
129 #include "hw/pcmcia.h"
134 #include "hw/watchdog.h"
135 #include "hw/smbios.h"
138 #include "hw/loader.h"
141 #include "net/slirp.h"
146 #include "qemu-timer.h"
147 #include "qemu-char.h"
148 #include "cache-utils.h"
149 #include "blockdev.h"
150 #include "hw/block-common.h"
151 #include "block-migration.h"
153 #include "audio/audio.h"
154 #include "migration.h"
158 #include "qemu-option.h"
159 #include "qemu-config.h"
160 #include "qemu-options.h"
161 #include "qmp-commands.h"
162 #include "main-loop.h"
164 #include "fsdev/qemu-fsdev.h"
170 #include "qemu_socket.h"
172 #include "slirp/libslirp.h"
175 #include "trace/control.h"
176 #include "qemu-queue.h"
178 #include "arch_init.h"
181 #include "ui/qemu-spice.h"
184 #include "tizen/src/emulator.h"
185 #include "tizen/src/maru_common.h"
186 #include "tizen/src/maru_display.h"
187 #include "tizen/src/option.h"
188 #include "tizen/src/sdb.h"
189 #include "tizen/src/emul_state.h"
190 #include "tizen/src/skin/maruskin_operation.h"
191 #include "tizen/src/maru_err_table.h"
195 //#define DEBUG_SLIRP
197 #define DEFAULT_RAM_SIZE 128
199 #define MAX_VIRTIO_CONSOLES 1
202 #define MARUCAM_DEV_NAME "maru_camera_pci"
203 int skin_disabled = 0;
206 static const char *data_dir;
207 const char *bios_name = NULL;
208 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
209 DisplayType display_type = DT_DEFAULT;
210 int display_remote = 0;
211 const char* keyboard_layout = NULL;
213 const char *mem_path = NULL;
215 int mem_prealloc = 0; /* force preallocation of physical target memory */
218 NICInfo nd_table[MAX_NICS];
220 static int rtc_utc = 1;
221 static int rtc_date_offset = -1; /* -1 means no change */
222 QEMUClock *rtc_clock;
223 int vga_interface_type = VGA_NONE;
224 static int full_screen = 0;
226 static int no_frame = 0;
229 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
230 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
231 CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
232 int win2k_install_hack = 0;
240 const char *vnc_display;
242 int acpi_enabled = 1;
248 int graphic_rotate = 0;
249 const char *watchdog;
250 QEMUOptionRom option_rom[MAX_OPTION_ROMS];
252 int semihosting_enabled = 0;
254 const char *qemu_name;
257 unsigned int nb_prom_envs = 0;
258 const char *prom_envs[MAX_PROM_ENVS];
260 uint8_t *boot_splash_filedata;
261 int boot_splash_filedata_size;
262 uint8_t qemu_extra_params_fw[2];
265 #define VIRTIOGL_DEV_NAME "virtio-gl-pci"
266 #if defined(CONFIG_MARU)
267 extern int gl_acceleration_capability_check(void);
269 int capability_check_gl = 0;
271 #if defined(CONFIG_MARU)
272 #define WEBCAM_INFO_IGNORE 0x00
273 #define WEBCAM_INFO_WRITE 0x04
274 extern int marucam_device_check(int log_flag);
275 int is_webcam_enabled = 0;
279 typedef struct FWBootEntry FWBootEntry;
282 QTAILQ_ENTRY(FWBootEntry) link;
288 QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order);
291 uint64_t node_mem[MAX_NODES];
292 unsigned long *node_cpumask[MAX_NODES];
294 uint8_t qemu_uuid[16];
296 static QEMUBootSetHandler *boot_set_handler;
297 static void *boot_set_opaque;
299 static NotifierList exit_notifiers =
300 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
302 static NotifierList machine_init_done_notifiers =
303 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
305 static int tcg_allowed = 1;
310 enum xen_mode xen_mode = XEN_EMULATE;
311 static int tcg_tb_size;
313 #ifdef CONFIG_OPENGLES
314 int gles2_quality = 100;
316 static int default_serial = 1;
317 static int default_parallel = 1;
318 static int default_virtcon = 1;
319 static int default_monitor = 1;
320 static int default_floppy = 1;
321 static int default_cdrom = 1;
322 static int default_sdcard = 1;
323 static int default_vga = 1;
329 { .driver = "isa-serial", .flag = &default_serial },
330 { .driver = "isa-parallel", .flag = &default_parallel },
331 { .driver = "isa-fdc", .flag = &default_floppy },
332 { .driver = "ide-cd", .flag = &default_cdrom },
333 { .driver = "ide-hd", .flag = &default_cdrom },
334 { .driver = "ide-drive", .flag = &default_cdrom },
335 { .driver = "scsi-cd", .flag = &default_cdrom },
336 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
337 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
338 { .driver = "virtio-serial", .flag = &default_virtcon },
339 { .driver = "VGA", .flag = &default_vga },
340 { .driver = "isa-vga", .flag = &default_vga },
341 { .driver = "cirrus-vga", .flag = &default_vga },
342 { .driver = "isa-cirrus-vga", .flag = &default_vga },
343 { .driver = "vmware-svga", .flag = &default_vga },
344 { .driver = "qxl-vga", .flag = &default_vga },
347 const char *qemu_get_vm_name(void)
352 static void res_free(void)
354 if (boot_splash_filedata != NULL) {
355 g_free(boot_splash_filedata);
356 boot_splash_filedata = NULL;
360 static int default_driver_check(QemuOpts *opts, void *opaque)
362 const char *driver = qemu_opt_get(opts, "driver");
367 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
368 if (strcmp(default_list[i].driver, driver) != 0)
370 *(default_list[i].flag) = 0;
375 /***********************************************************/
378 static RunState current_run_state = RUN_STATE_PRELAUNCH;
383 } RunStateTransition;
385 static const RunStateTransition runstate_transitions_def[] = {
387 { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
389 { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },
390 { RUN_STATE_INMIGRATE, RUN_STATE_PRELAUNCH },
392 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
393 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
395 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
396 { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE },
398 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
399 { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
401 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
402 { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
404 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
405 { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
406 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
408 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
409 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
411 { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
413 { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
414 { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
415 { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
416 { RUN_STATE_RUNNING, RUN_STATE_PAUSED },
417 { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE },
418 { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM },
419 { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM },
420 { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
421 { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
423 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
425 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
426 { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
428 { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
429 { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
430 { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },
431 { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
433 { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
434 { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
436 { RUN_STATE_MAX, RUN_STATE_MAX },
439 static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX];
441 bool runstate_check(RunState state)
443 return current_run_state == state;
446 void runstate_init(void)
448 const RunStateTransition *p;
450 memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions));
452 for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) {
453 runstate_valid_transitions[p->from][p->to] = true;
457 /* This function will abort() on invalid state transitions */
458 void runstate_set(RunState new_state)
460 assert(new_state < RUN_STATE_MAX);
462 if (!runstate_valid_transitions[current_run_state][new_state]) {
463 fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
464 RunState_lookup[current_run_state],
465 RunState_lookup[new_state]);
469 current_run_state = new_state;
472 int runstate_is_running(void)
474 return runstate_check(RUN_STATE_RUNNING);
477 StatusInfo *qmp_query_status(Error **errp)
479 StatusInfo *info = g_malloc0(sizeof(*info));
481 info->running = runstate_is_running();
482 info->singlestep = singlestep;
483 info->status = current_run_state;
488 /***********************************************************/
489 /* real time host monotonic timer */
491 /***********************************************************/
492 /* host time/date access */
493 void qemu_get_timedate(struct tm *tm, int offset)
500 if (rtc_date_offset == -1) {
504 ret = localtime(&ti);
506 ti -= rtc_date_offset;
510 memcpy(tm, ret, sizeof(struct tm));
513 int qemu_timedate_diff(struct tm *tm)
517 if (rtc_date_offset == -1)
519 seconds = mktimegm(tm);
522 tmp.tm_isdst = -1; /* use timezone to figure it out */
523 seconds = mktime(&tmp);
526 seconds = mktimegm(tm) + rtc_date_offset;
528 return seconds - time(NULL);
531 void rtc_change_mon_event(struct tm *tm)
535 data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
536 monitor_protocol_event(QEVENT_RTC_CHANGE, data);
537 qobject_decref(data);
540 static void configure_rtc_date_offset(const char *startdate, int legacy)
542 time_t rtc_start_date;
545 if (!strcmp(startdate, "now") && legacy) {
546 rtc_date_offset = -1;
548 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
556 } else if (sscanf(startdate, "%d-%d-%d",
568 rtc_start_date = mktimegm(&tm);
569 if (rtc_start_date == -1) {
571 fprintf(stderr, "Invalid date format. Valid formats are:\n"
572 "'2006-06-17T16:01:21' or '2006-06-17'\n");
575 rtc_date_offset = time(NULL) - rtc_start_date;
579 static void configure_rtc(QemuOpts *opts)
583 value = qemu_opt_get(opts, "base");
585 if (!strcmp(value, "utc")) {
587 } else if (!strcmp(value, "localtime")) {
590 configure_rtc_date_offset(value, 0);
593 value = qemu_opt_get(opts, "clock");
595 if (!strcmp(value, "host")) {
596 rtc_clock = host_clock;
597 } else if (!strcmp(value, "rt")) {
598 rtc_clock = rt_clock;
599 } else if (!strcmp(value, "vm")) {
600 rtc_clock = vm_clock;
602 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
606 value = qemu_opt_get(opts, "driftfix");
608 if (!strcmp(value, "slew")) {
609 static GlobalProperty slew_lost_ticks[] = {
611 .driver = "mc146818rtc",
612 .property = "lost_tick_policy",
615 { /* end of list */ }
618 qdev_prop_register_global_list(slew_lost_ticks);
619 } else if (!strcmp(value, "none")) {
620 /* discard is default */
622 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
628 /***********************************************************/
629 /* Bluetooth support */
632 static struct HCIInfo *hci_table[MAX_NICS];
634 static struct bt_vlan_s {
635 struct bt_scatternet_s net;
637 struct bt_vlan_s *next;
640 /* find or alloc a new bluetooth "VLAN" */
641 static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
643 struct bt_vlan_s **pvlan, *vlan;
644 for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) {
648 vlan = g_malloc0(sizeof(struct bt_vlan_s));
650 pvlan = &first_bt_vlan;
651 while (*pvlan != NULL)
652 pvlan = &(*pvlan)->next;
657 static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
661 static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
666 static struct HCIInfo null_hci = {
667 .cmd_send = null_hci_send,
668 .sco_send = null_hci_send,
669 .acl_send = null_hci_send,
670 .bdaddr_set = null_hci_addr_set,
673 struct HCIInfo *qemu_next_hci(void)
675 if (cur_hci == nb_hcis)
678 return hci_table[cur_hci++];
681 static struct HCIInfo *hci_init(const char *str)
684 struct bt_scatternet_s *vlan = 0;
686 if (!strcmp(str, "null"))
689 else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':'))
691 return bt_host_hci(str[4] ? str + 5 : "hci0");
692 else if (!strncmp(str, "hci", 3)) {
695 if (!strncmp(str + 3, ",vlan=", 6)) {
696 vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0));
701 vlan = qemu_find_bt_vlan(0);
703 return bt_new_hci(vlan);
706 fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
711 static int bt_hci_parse(const char *str)
716 if (nb_hcis >= MAX_NICS) {
717 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
730 bdaddr.b[5] = 0x56 + nb_hcis;
731 hci->bdaddr_set(hci, bdaddr.b);
733 hci_table[nb_hcis++] = hci;
738 static void bt_vhci_add(int vlan_id)
740 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
743 fprintf(stderr, "qemu: warning: adding a VHCI to "
744 "an empty scatternet %i\n", vlan_id);
746 bt_vhci_init(bt_new_hci(vlan));
749 static struct bt_device_s *bt_device_add(const char *opt)
751 struct bt_scatternet_s *vlan;
753 char *endp = strstr(opt, ",vlan=");
754 int len = (endp ? endp - opt : strlen(opt)) + 1;
757 pstrcpy(devname, MIN(sizeof(devname), len), opt);
760 vlan_id = strtol(endp + 6, &endp, 0);
762 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
767 vlan = qemu_find_bt_vlan(vlan_id);
770 fprintf(stderr, "qemu: warning: adding a slave device to "
771 "an empty scatternet %i\n", vlan_id);
773 if (!strcmp(devname, "keyboard"))
774 return bt_keyboard_init(vlan);
776 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
780 static int bt_parse(const char *opt)
782 const char *endp, *p;
785 if (strstart(opt, "hci", &endp)) {
786 if (!*endp || *endp == ',') {
788 if (!strstart(endp, ",vlan=", 0))
791 return bt_hci_parse(opt);
793 } else if (strstart(opt, "vhci", &endp)) {
794 if (!*endp || *endp == ',') {
796 if (strstart(endp, ",vlan=", &p)) {
797 vlan = strtol(p, (char **) &endp, 0);
799 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
803 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
812 } else if (strstart(opt, "device:", &endp))
813 return !bt_device_add(endp);
815 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
819 static int parse_sandbox(QemuOpts *opts, void *opaque)
821 /* FIXME: change this to true for 1.3 */
822 if (qemu_opt_get_bool(opts, "enable", false)) {
823 #ifdef CONFIG_SECCOMP
824 if (seccomp_start() < 0) {
825 qerror_report(ERROR_CLASS_GENERIC_ERROR,
826 "failed to install seccomp syscall filter in the kernel");
830 qerror_report(ERROR_CLASS_GENERIC_ERROR,
831 "sandboxing request but seccomp is not compiled into this build");
839 /***********************************************************/
840 /* QEMU Block devices */
842 #define HD_OPTS "media=disk"
843 #define CDROM_OPTS "media=cdrom"
845 #define PFLASH_OPTS ""
849 static int drive_init_func(QemuOpts *opts, void *opaque)
851 int *use_scsi = opaque;
853 return drive_init(opts, *use_scsi) == NULL;
856 static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
858 if (NULL == qemu_opt_get(opts, "snapshot")) {
859 qemu_opt_set(opts, "snapshot", "on");
864 static void default_drive(int enable, int snapshot, int use_scsi,
865 BlockInterfaceType type, int index,
870 if (type == IF_DEFAULT) {
871 type = use_scsi ? IF_SCSI : IF_IDE;
874 if (!enable || drive_get_by_index(type, index)) {
878 opts = drive_add(type, index, NULL, optstr);
880 drive_enable_snapshot(opts, NULL);
882 if (!drive_init(opts, use_scsi)) {
887 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
889 boot_set_handler = func;
890 boot_set_opaque = opaque;
893 int qemu_boot_set(const char *boot_devices)
895 if (!boot_set_handler) {
898 return boot_set_handler(boot_set_opaque, boot_devices);
901 static void validate_bootdevices(char *devices)
903 /* We just do some generic consistency checks */
907 for (p = devices; *p != '\0'; p++) {
908 /* Allowed boot devices are:
909 * a-b: floppy disk drives
910 * c-f: IDE disk drives
911 * g-m: machine implementation dependent drives
912 * n-p: network devices
913 * It's up to each machine implementation to check if the given boot
914 * devices match the actual hardware implementation and firmware
917 if (*p < 'a' || *p > 'p') {
918 fprintf(stderr, "Invalid boot device '%c'\n", *p);
921 if (bitmap & (1 << (*p - 'a'))) {
922 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
925 bitmap |= 1 << (*p - 'a');
929 static void restore_boot_devices(void *opaque)
931 char *standard_boot_devices = opaque;
932 static int first = 1;
934 /* Restore boot order and remove ourselves after the first boot */
940 qemu_boot_set(standard_boot_devices);
942 qemu_unregister_reset(restore_boot_devices, standard_boot_devices);
943 g_free(standard_boot_devices);
946 void add_boot_device_path(int32_t bootindex, DeviceState *dev,
949 FWBootEntry *node, *i;
955 assert(dev != NULL || suffix != NULL);
957 node = g_malloc0(sizeof(FWBootEntry));
958 node->bootindex = bootindex;
959 node->suffix = suffix ? g_strdup(suffix) : NULL;
962 QTAILQ_FOREACH(i, &fw_boot_order, link) {
963 if (i->bootindex == bootindex) {
964 fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
966 } else if (i->bootindex < bootindex) {
969 QTAILQ_INSERT_BEFORE(i, node, link);
972 QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
976 * This function returns null terminated string that consist of new line
977 * separated device paths.
979 * memory pointed by "size" is assigned total length of the array in bytes
982 char *get_boot_devices_list(uint32_t *size)
988 QTAILQ_FOREACH(i, &fw_boot_order, link) {
989 char *devpath = NULL, *bootpath;
993 devpath = qdev_get_fw_dev_path(i->dev);
997 if (i->suffix && devpath) {
998 size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
1000 bootpath = g_malloc(bootpathlen);
1001 snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
1003 } else if (devpath) {
1007 bootpath = g_strdup(i->suffix);
1011 list[total-1] = '\n';
1013 len = strlen(bootpath) + 1;
1014 list = g_realloc(list, total + len);
1015 memcpy(&list[total], bootpath, len);
1025 static void numa_add(const char *optarg)
1029 unsigned long long value, endvalue;
1032 value = endvalue = 0ULL;
1034 optarg = get_opt_name(option, 128, optarg, ',') + 1;
1035 if (!strcmp(option, "node")) {
1036 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
1037 nodenr = nb_numa_nodes;
1039 nodenr = strtoull(option, NULL, 10);
1042 if (get_param_value(option, 128, "mem", optarg) == 0) {
1043 node_mem[nodenr] = 0;
1046 sval = strtosz(option, &endptr);
1047 if (sval < 0 || *endptr) {
1048 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
1051 node_mem[nodenr] = sval;
1053 if (get_param_value(option, 128, "cpus", optarg) != 0) {
1054 value = strtoull(option, &endptr, 10);
1055 if (*endptr == '-') {
1056 endvalue = strtoull(endptr+1, &endptr, 10);
1061 if (!(endvalue < MAX_CPUMASK_BITS)) {
1062 endvalue = MAX_CPUMASK_BITS - 1;
1064 "A max of %d CPUs are supported in a guest\n",
1068 bitmap_set(node_cpumask[nodenr], value, endvalue-value+1);
1075 static void smp_parse(const char *optarg)
1077 int smp, sockets = 0, threads = 0, cores = 0;
1081 smp = strtoul(optarg, &endptr, 10);
1082 if (endptr != optarg) {
1083 if (*endptr == ',') {
1087 if (get_param_value(option, 128, "sockets", endptr) != 0)
1088 sockets = strtoull(option, NULL, 10);
1089 if (get_param_value(option, 128, "cores", endptr) != 0)
1090 cores = strtoull(option, NULL, 10);
1091 if (get_param_value(option, 128, "threads", endptr) != 0)
1092 threads = strtoull(option, NULL, 10);
1093 if (get_param_value(option, 128, "maxcpus", endptr) != 0)
1094 max_cpus = strtoull(option, NULL, 10);
1096 /* compute missing values, prefer sockets over cores over threads */
1097 if (smp == 0 || sockets == 0) {
1098 sockets = sockets > 0 ? sockets : 1;
1099 cores = cores > 0 ? cores : 1;
1100 threads = threads > 0 ? threads : 1;
1102 smp = cores * threads * sockets;
1106 threads = threads > 0 ? threads : 1;
1107 cores = smp / (sockets * threads);
1109 threads = smp / (cores * sockets);
1113 smp_cores = cores > 0 ? cores : 1;
1114 smp_threads = threads > 0 ? threads : 1;
1116 max_cpus = smp_cpus;
1119 /***********************************************************/
1122 static int usb_device_add(const char *devname)
1125 USBDevice *dev = NULL;
1130 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1131 dev = usbdevice_create(devname);
1135 /* the other ones */
1136 #ifndef CONFIG_LINUX
1137 /* only the linux version is qdev-ified, usb-bsd still needs this */
1138 if (strstart(devname, "host:", &p)) {
1139 dev = usb_host_device_open(usb_bus_find(-1), p);
1142 if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
1143 dev = usb_bt_init(usb_bus_find(-1),
1144 devname[2] ? hci_init(p)
1145 : bt_new_hci(qemu_find_bt_vlan(0)));
1156 static int usb_device_del(const char *devname)
1161 if (strstart(devname, "host:", &p))
1162 return usb_host_device_close(p);
1167 p = strchr(devname, '.');
1170 bus_num = strtoul(devname, NULL, 0);
1171 addr = strtoul(p + 1, NULL, 0);
1173 return usb_device_delete_addr(bus_num, addr);
1176 static int usb_parse(const char *cmdline)
1179 r = usb_device_add(cmdline);
1181 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
1186 void do_usb_add(Monitor *mon, const QDict *qdict)
1188 const char *devname = qdict_get_str(qdict, "devname");
1189 if (usb_device_add(devname) < 0) {
1190 error_report("could not add USB device '%s'", devname);
1194 void do_usb_del(Monitor *mon, const QDict *qdict)
1196 const char *devname = qdict_get_str(qdict, "devname");
1197 if (usb_device_del(devname) < 0) {
1198 error_report("could not delete USB device '%s'", devname);
1202 /***********************************************************/
1203 /* PCMCIA/Cardbus */
1205 static struct pcmcia_socket_entry_s {
1206 PCMCIASocket *socket;
1207 struct pcmcia_socket_entry_s *next;
1208 } *pcmcia_sockets = 0;
1210 void pcmcia_socket_register(PCMCIASocket *socket)
1212 struct pcmcia_socket_entry_s *entry;
1214 entry = g_malloc(sizeof(struct pcmcia_socket_entry_s));
1215 entry->socket = socket;
1216 entry->next = pcmcia_sockets;
1217 pcmcia_sockets = entry;
1220 void pcmcia_socket_unregister(PCMCIASocket *socket)
1222 struct pcmcia_socket_entry_s *entry, **ptr;
1224 ptr = &pcmcia_sockets;
1225 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1226 if (entry->socket == socket) {
1232 void pcmcia_info(Monitor *mon)
1234 struct pcmcia_socket_entry_s *iter;
1236 if (!pcmcia_sockets)
1237 monitor_printf(mon, "No PCMCIA sockets\n");
1239 for (iter = pcmcia_sockets; iter; iter = iter->next)
1240 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1241 iter->socket->attached ? iter->socket->card_string :
1245 /***********************************************************/
1246 /* machine registration */
1248 static QEMUMachine *first_machine = NULL;
1249 QEMUMachine *current_machine = NULL;
1251 int qemu_register_machine(QEMUMachine *m)
1254 pm = &first_machine;
1262 static QEMUMachine *find_machine(const char *name)
1266 for(m = first_machine; m != NULL; m = m->next) {
1267 if (!strcmp(m->name, name))
1269 if (m->alias && !strcmp(m->alias, name))
1275 QEMUMachine *find_default_machine(void)
1279 for(m = first_machine; m != NULL; m = m->next) {
1280 if (m->is_default) {
1287 MachineInfoList *qmp_query_machines(Error **errp)
1289 MachineInfoList *mach_list = NULL;
1292 for (m = first_machine; m; m = m->next) {
1293 MachineInfoList *entry;
1296 info = g_malloc0(sizeof(*info));
1297 if (m->is_default) {
1298 info->has_is_default = true;
1299 info->is_default = true;
1303 info->has_alias = true;
1304 info->alias = g_strdup(m->alias);
1307 info->name = g_strdup(m->name);
1309 entry = g_malloc0(sizeof(*entry));
1310 entry->value = info;
1311 entry->next = mach_list;
1318 /***********************************************************/
1319 /* main execution loop */
1321 static void gui_update(void *opaque)
1323 uint64_t interval = GUI_REFRESH_INTERVAL;
1324 DisplayState *ds = opaque;
1325 DisplayChangeListener *dcl = ds->listeners;
1329 while (dcl != NULL) {
1330 if (dcl->gui_timer_interval &&
1331 dcl->gui_timer_interval < interval)
1332 interval = dcl->gui_timer_interval;
1335 qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock));
1338 struct vm_change_state_entry {
1339 VMChangeStateHandler *cb;
1341 QLIST_ENTRY (vm_change_state_entry) entries;
1344 static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
1346 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1349 VMChangeStateEntry *e;
1351 e = g_malloc0(sizeof (*e));
1355 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
1359 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1361 QLIST_REMOVE (e, entries);
1365 void vm_state_notify(int running, RunState state)
1367 VMChangeStateEntry *e;
1369 trace_vm_state_notify(running, state);
1371 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
1372 e->cb(e->opaque, running, state);
1378 if (!runstate_is_running()) {
1380 runstate_set(RUN_STATE_RUNNING);
1381 vm_state_notify(1, RUN_STATE_RUNNING);
1383 monitor_protocol_event(QEVENT_RESUME, NULL);
1387 /* reset/shutdown handler */
1389 typedef struct QEMUResetEntry {
1390 QTAILQ_ENTRY(QEMUResetEntry) entry;
1391 QEMUResetHandler *func;
1395 static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1396 QTAILQ_HEAD_INITIALIZER(reset_handlers);
1397 static int reset_requested;
1398 static int shutdown_requested, shutdown_signal = -1;
1399 static pid_t shutdown_pid;
1400 static int powerdown_requested;
1401 static int debug_requested;
1402 static int suspend_requested;
1403 static int wakeup_requested;
1404 static NotifierList suspend_notifiers =
1405 NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
1406 static NotifierList wakeup_notifiers =
1407 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
1408 static uint32_t wakeup_reason_mask = ~0;
1409 static RunState vmstop_requested = RUN_STATE_MAX;
1411 int qemu_shutdown_requested_get(void)
1413 return shutdown_requested;
1416 int qemu_reset_requested_get(void)
1418 return reset_requested;
1421 int qemu_shutdown_requested(void)
1423 int r = shutdown_requested;
1424 shutdown_requested = 0;
1428 void qemu_kill_report(void)
1430 if (!qtest_enabled() && shutdown_signal != -1) {
1431 fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal);
1432 if (shutdown_pid == 0) {
1433 /* This happens for eg ^C at the terminal, so it's worth
1434 * avoiding printing an odd message in that case.
1436 fputc('\n', stderr);
1438 fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid);
1440 shutdown_signal = -1;
1444 int qemu_reset_requested(void)
1446 int r = reset_requested;
1447 reset_requested = 0;
1451 static int qemu_suspend_requested(void)
1453 int r = suspend_requested;
1454 suspend_requested = 0;
1458 static int qemu_wakeup_requested(void)
1460 int r = wakeup_requested;
1461 wakeup_requested = 0;
1465 int qemu_powerdown_requested(void)
1467 int r = powerdown_requested;
1468 powerdown_requested = 0;
1472 static int qemu_debug_requested(void)
1474 int r = debug_requested;
1475 debug_requested = 0;
1479 /* We use RUN_STATE_MAX but any invalid value will do */
1480 static bool qemu_vmstop_requested(RunState *r)
1482 if (vmstop_requested < RUN_STATE_MAX) {
1483 *r = vmstop_requested;
1484 vmstop_requested = RUN_STATE_MAX;
1491 void qemu_register_reset(QEMUResetHandler *func, void *opaque)
1493 QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
1496 re->opaque = opaque;
1497 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
1500 void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
1504 QTAILQ_FOREACH(re, &reset_handlers, entry) {
1505 if (re->func == func && re->opaque == opaque) {
1506 QTAILQ_REMOVE(&reset_handlers, re, entry);
1513 void qemu_devices_reset(void)
1515 QEMUResetEntry *re, *nre;
1517 /* reset all devices */
1518 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
1519 re->func(re->opaque);
1523 void qemu_system_reset(bool report)
1525 if (current_machine && current_machine->reset) {
1526 current_machine->reset();
1528 qemu_devices_reset();
1531 monitor_protocol_event(QEVENT_RESET, NULL);
1533 cpu_synchronize_all_post_reset();
1536 void qemu_system_reset_request(void)
1539 shutdown_requested = 1;
1541 reset_requested = 1;
1544 qemu_notify_event();
1547 static void qemu_system_suspend(void)
1550 notifier_list_notify(&suspend_notifiers, NULL);
1551 runstate_set(RUN_STATE_SUSPENDED);
1552 monitor_protocol_event(QEVENT_SUSPEND, NULL);
1555 void qemu_system_suspend_request(void)
1557 if (runstate_check(RUN_STATE_SUSPENDED)) {
1560 suspend_requested = 1;
1562 qemu_notify_event();
1565 void qemu_register_suspend_notifier(Notifier *notifier)
1567 notifier_list_add(&suspend_notifiers, notifier);
1570 void qemu_system_wakeup_request(WakeupReason reason)
1572 if (!runstate_check(RUN_STATE_SUSPENDED)) {
1575 if (!(wakeup_reason_mask & (1 << reason))) {
1578 runstate_set(RUN_STATE_RUNNING);
1579 notifier_list_notify(&wakeup_notifiers, &reason);
1580 wakeup_requested = 1;
1581 qemu_notify_event();
1584 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
1587 wakeup_reason_mask |= (1 << reason);
1589 wakeup_reason_mask &= ~(1 << reason);
1593 void qemu_register_wakeup_notifier(Notifier *notifier)
1595 notifier_list_add(&wakeup_notifiers, notifier);
1598 void qemu_system_killed(int signal, pid_t pid)
1600 shutdown_signal = signal;
1605 shutdown_qemu_gracefully();
1607 qemu_system_shutdown_request();
1611 void qemu_system_shutdown_request(void)
1613 shutdown_requested = 1;
1614 qemu_notify_event();
1617 void qemu_system_powerdown_request(void)
1619 powerdown_requested = 1;
1620 qemu_notify_event();
1623 void qemu_system_debug_request(void)
1625 debug_requested = 1;
1626 qemu_notify_event();
1629 void qemu_system_vmstop_request(RunState state)
1631 vmstop_requested = state;
1632 qemu_notify_event();
1635 qemu_irq qemu_system_powerdown;
1637 static bool main_loop_should_exit(void)
1640 if (qemu_debug_requested()) {
1641 vm_stop(RUN_STATE_DEBUG);
1643 if (qemu_suspend_requested()) {
1644 qemu_system_suspend();
1646 if (qemu_shutdown_requested()) {
1648 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
1650 vm_stop(RUN_STATE_SHUTDOWN);
1655 if (qemu_reset_requested()) {
1657 cpu_synchronize_all_states();
1658 qemu_system_reset(VMRESET_REPORT);
1660 if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
1661 runstate_check(RUN_STATE_SHUTDOWN)) {
1662 runstate_set(RUN_STATE_PAUSED);
1665 if (qemu_wakeup_requested()) {
1667 cpu_synchronize_all_states();
1668 qemu_system_reset(VMRESET_SILENT);
1670 monitor_protocol_event(QEVENT_WAKEUP, NULL);
1672 if (qemu_powerdown_requested()) {
1673 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
1674 qemu_irq_raise(qemu_system_powerdown);
1676 if (qemu_vmstop_requested(&r)) {
1682 static void main_loop(void)
1686 #ifdef CONFIG_PROFILER
1693 nonblocking = !(kvm_enabled()|| hax_enabled()) && last_io > 0;
1694 #ifdef CONFIG_PROFILER
1695 ti = profile_getclock();
1697 last_io = main_loop_wait(nonblocking);
1698 #ifdef CONFIG_PROFILER
1699 dev_time += profile_getclock() - ti;
1701 } while (!main_loop_should_exit());
1704 static void version(void)
1706 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
1709 static void help(int exitcode)
1712 printf("usage: %s [options] [disk_image]\n\n"
1713 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1714 error_get_progname());
1716 #define QEMU_OPTIONS_GENERATE_HELP
1717 #include "qemu-options-wrapper.h"
1719 printf("\nDuring emulation, the following keys are useful:\n"
1720 "ctrl-alt-f toggle full screen\n"
1721 "ctrl-alt-n switch to virtual console 'n'\n"
1722 "ctrl-alt toggle mouse and keyboard grab\n"
1724 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1729 #define HAS_ARG 0x0001
1731 typedef struct QEMUOption {
1738 static const QEMUOption qemu_options[] = {
1739 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1740 #define QEMU_OPTIONS_GENERATE_OPTIONS
1741 #include "qemu-options-wrapper.h"
1745 static bool vga_available(void)
1747 return qdev_exists("VGA") || qdev_exists("isa-vga");
1750 static bool cirrus_vga_available(void)
1752 return qdev_exists("cirrus-vga") || qdev_exists("isa-cirrus-vga");
1755 static bool vmware_vga_available(void)
1757 return qdev_exists("vmware-svga");
1760 static void select_vgahw (const char *p)
1764 vga_interface_type = VGA_NONE;
1765 if (strstart(p, "std", &opts)) {
1766 if (vga_available()) {
1767 vga_interface_type = VGA_STD;
1769 fprintf(stderr, "Error: standard VGA not available\n");
1772 } else if (strstart(p, "cirrus", &opts)) {
1773 if (cirrus_vga_available()) {
1774 vga_interface_type = VGA_CIRRUS;
1776 fprintf(stderr, "Error: Cirrus VGA not available\n");
1779 } else if (strstart(p, "vmware", &opts)) {
1780 if (vmware_vga_available()) {
1781 vga_interface_type = VGA_VMWARE;
1783 fprintf(stderr, "Error: VMWare SVGA not available\n");
1786 } else if (strstart(p, "xenfb", &opts)) {
1787 vga_interface_type = VGA_XENFB;
1788 } else if (strstart(p, "qxl", &opts)) {
1789 vga_interface_type = VGA_QXL;
1791 } else if (strstart(p, "maru", &opts)) {
1792 vga_interface_type = VGA_MARU;
1794 } else if (!strstart(p, "none", &opts)) {
1796 fprintf(stderr, "Unknown vga type: %s\n", p);
1800 const char *nextopt;
1802 if (strstart(opts, ",retrace=", &nextopt)) {
1804 if (strstart(opts, "dumb", &nextopt))
1805 vga_retrace_method = VGA_RETRACE_DUMB;
1806 else if (strstart(opts, "precise", &nextopt))
1807 vga_retrace_method = VGA_RETRACE_PRECISE;
1808 else goto invalid_vga;
1809 } else goto invalid_vga;
1814 static DisplayType select_display(const char *p)
1817 DisplayType display = DT_DEFAULT;
1819 if (strstart(p, "sdl", &opts)) {
1823 const char *nextopt;
1825 if (strstart(opts, ",frame=", &nextopt)) {
1827 if (strstart(opts, "on", &nextopt)) {
1829 } else if (strstart(opts, "off", &nextopt)) {
1832 goto invalid_sdl_args;
1834 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
1836 if (strstart(opts, "on", &nextopt)) {
1838 } else if (strstart(opts, "off", &nextopt)) {
1841 goto invalid_sdl_args;
1843 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
1845 if (strstart(opts, "on", &nextopt)) {
1847 } else if (strstart(opts, "off", &nextopt)) {
1850 goto invalid_sdl_args;
1852 } else if (strstart(opts, ",window_close=", &nextopt)) {
1854 if (strstart(opts, "on", &nextopt)) {
1856 } else if (strstart(opts, "off", &nextopt)) {
1859 goto invalid_sdl_args;
1863 fprintf(stderr, "Invalid SDL option string: %s\n", p);
1869 fprintf(stderr, "SDL support is disabled\n");
1872 } else if (strstart(p, "vnc", &opts)) {
1877 const char *nextopt;
1879 if (strstart(opts, "=", &nextopt)) {
1880 vnc_display = nextopt;
1884 fprintf(stderr, "VNC requires a display argument vnc=<display>\n");
1888 fprintf(stderr, "VNC support is disabled\n");
1891 } else if (strstart(p, "curses", &opts)) {
1892 #ifdef CONFIG_CURSES
1893 display = DT_CURSES;
1895 fprintf(stderr, "Curses support is disabled\n");
1898 } else if (strstart(p, "none", &opts)) {
1901 fprintf(stderr, "Unknown display type: %s\n", p);
1908 static int balloon_parse(const char *arg)
1912 if (strcmp(arg, "none") == 0) {
1916 if (!strncmp(arg, "virtio", 6)) {
1917 if (arg[6] == ',') {
1918 /* have params -> parse them */
1919 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
1923 /* create empty opts */
1924 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, NULL);
1926 qemu_opt_set(opts, "driver", "virtio-balloon");
1933 char *qemu_find_file(int type, const char *name)
1939 /* Try the name as a straight path first */
1940 if (access(name, R_OK) == 0) {
1941 return g_strdup(name);
1944 case QEMU_FILE_TYPE_BIOS:
1947 case QEMU_FILE_TYPE_KEYMAP:
1948 subdir = "keymaps/";
1953 len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
1954 buf = g_malloc0(len);
1955 snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
1956 if (access(buf, R_OK)) {
1964 const char *qemu_get_data_dir(void);
1966 const char *qemu_get_data_dir(void)
1972 static int device_help_func(QemuOpts *opts, void *opaque)
1974 return qdev_device_help(opts);
1977 static int device_init_func(QemuOpts *opts, void *opaque)
1981 #ifdef CONFIG_GL_BACKEND
1982 #if defined(CONFIG_MARU)
1983 // virtio-gl pci device
1985 // ignore virtio-gl-pci device, even if users set it in option.
1986 const char *driver = qemu_opt_get(opts, "driver");
1987 if (driver && (strcmp (driver, VIRTIOGL_DEV_NAME) == 0)) {
1993 #if defined(CONFIG_MARU)
1994 if (!is_webcam_enabled) {
1995 const char *driver = qemu_opt_get(opts, "driver");
1996 if (driver && (strcmp (driver, MARUCAM_DEV_NAME) == 0)) {
2002 dev = qdev_device_add(opts);
2008 static int chardev_init_func(QemuOpts *opts, void *opaque)
2010 CharDriverState *chr;
2012 chr = qemu_chr_new_from_opts(opts, NULL);
2018 #ifdef CONFIG_VIRTFS
2019 static int fsdev_init_func(QemuOpts *opts, void *opaque)
2022 ret = qemu_fsdev_add(opts);
2028 static int mon_init_func(QemuOpts *opts, void *opaque)
2030 CharDriverState *chr;
2031 const char *chardev;
2035 mode = qemu_opt_get(opts, "mode");
2039 if (strcmp(mode, "readline") == 0) {
2040 flags = MONITOR_USE_READLINE;
2041 } else if (strcmp(mode, "control") == 0) {
2042 flags = MONITOR_USE_CONTROL;
2044 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
2048 if (qemu_opt_get_bool(opts, "pretty", 0))
2049 flags |= MONITOR_USE_PRETTY;
2051 if (qemu_opt_get_bool(opts, "default", 0))
2052 flags |= MONITOR_IS_DEFAULT;
2054 chardev = qemu_opt_get(opts, "chardev");
2055 chr = qemu_chr_find(chardev);
2057 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
2061 monitor_init(chr, flags);
2065 static void monitor_parse(const char *optarg, const char *mode)
2067 static int monitor_device_index = 0;
2073 if (strstart(optarg, "chardev:", &p)) {
2074 snprintf(label, sizeof(label), "%s", p);
2076 snprintf(label, sizeof(label), "compat_monitor%d",
2077 monitor_device_index);
2078 if (monitor_device_index == 0) {
2081 opts = qemu_chr_parse_compat(label, optarg);
2083 fprintf(stderr, "parse error: %s\n", optarg);
2088 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, NULL);
2090 fprintf(stderr, "duplicate chardev: %s\n", label);
2093 qemu_opt_set(opts, "mode", mode);
2094 qemu_opt_set(opts, "chardev", label);
2096 qemu_opt_set(opts, "default", "on");
2097 monitor_device_index++;
2100 struct device_config {
2102 DEV_USB, /* -usbdevice */
2104 DEV_SERIAL, /* -serial */
2105 DEV_PARALLEL, /* -parallel */
2106 DEV_VIRTCON, /* -virtioconsole */
2107 DEV_DEBUGCON, /* -debugcon */
2108 DEV_GDB, /* -gdb, -s */
2110 const char *cmdline;
2112 QTAILQ_ENTRY(device_config) next;
2114 QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
2116 static void add_device_config(int type, const char *cmdline)
2118 struct device_config *conf;
2120 conf = g_malloc0(sizeof(*conf));
2122 conf->cmdline = cmdline;
2123 loc_save(&conf->loc);
2124 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
2127 static int foreach_device_config(int type, int (*func)(const char *cmdline))
2129 struct device_config *conf;
2132 QTAILQ_FOREACH(conf, &device_configs, next) {
2133 if (conf->type != type)
2135 loc_push_restore(&conf->loc);
2136 rc = func(conf->cmdline);
2137 loc_pop(&conf->loc);
2144 static int serial_parse(const char *devname)
2146 static int index = 0;
2149 if (strcmp(devname, "none") == 0)
2151 if (index == MAX_SERIAL_PORTS) {
2152 fprintf(stderr, "qemu: too many serial ports\n");
2155 snprintf(label, sizeof(label), "serial%d", index);
2156 serial_hds[index] = qemu_chr_new(label, devname, NULL);
2157 if (!serial_hds[index]) {
2158 fprintf(stderr, "qemu: could not connect serial device"
2159 " to character backend '%s'\n", devname);
2166 static int parallel_parse(const char *devname)
2168 static int index = 0;
2171 if (strcmp(devname, "none") == 0)
2173 if (index == MAX_PARALLEL_PORTS) {
2174 fprintf(stderr, "qemu: too many parallel ports\n");
2177 snprintf(label, sizeof(label), "parallel%d", index);
2178 parallel_hds[index] = qemu_chr_new(label, devname, NULL);
2179 if (!parallel_hds[index]) {
2180 fprintf(stderr, "qemu: could not connect parallel device"
2181 " to character backend '%s'\n", devname);
2188 static int virtcon_parse(const char *devname)
2190 QemuOptsList *device = qemu_find_opts("device");
2191 static int index = 0;
2193 QemuOpts *bus_opts, *dev_opts;
2195 if (strcmp(devname, "none") == 0)
2197 if (index == MAX_VIRTIO_CONSOLES) {
2198 fprintf(stderr, "qemu: too many virtio consoles\n");
2202 bus_opts = qemu_opts_create(device, NULL, 0, NULL);
2203 if (arch_type == QEMU_ARCH_S390X) {
2204 qemu_opt_set(bus_opts, "driver", "virtio-serial-s390");
2206 qemu_opt_set(bus_opts, "driver", "virtio-serial-pci");
2209 dev_opts = qemu_opts_create(device, NULL, 0, NULL);
2210 qemu_opt_set(dev_opts, "driver", "virtconsole");
2212 snprintf(label, sizeof(label), "virtcon%d", index);
2213 virtcon_hds[index] = qemu_chr_new(label, devname, NULL);
2214 if (!virtcon_hds[index]) {
2215 fprintf(stderr, "qemu: could not connect virtio console"
2216 " to character backend '%s'\n", devname);
2219 qemu_opt_set(dev_opts, "chardev", label);
2225 static int debugcon_parse(const char *devname)
2229 if (!qemu_chr_new("debugcon", devname, NULL)) {
2232 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL);
2234 fprintf(stderr, "qemu: already have a debugcon device\n");
2237 qemu_opt_set(opts, "driver", "isa-debugcon");
2238 qemu_opt_set(opts, "chardev", "debugcon");
2242 static QEMUMachine *machine_parse(const char *name)
2244 QEMUMachine *m, *machine = NULL;
2247 machine = find_machine(name);
2252 printf("Supported machines are:\n");
2253 for (m = first_machine; m != NULL; m = m->next) {
2255 printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name);
2257 printf("%-20s %s%s\n", m->name, m->desc,
2258 m->is_default ? " (default)" : "");
2260 exit(!name || !is_help_option(name));
2263 static int tcg_init(void)
2266 tcg_exec_init(tcg_tb_size * 1024 * 1024);
2267 ret = hax_accel_init();
2272 const char *opt_name;
2274 int (*available)(void);
2278 { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
2279 { "xen", "Xen", xen_available, xen_init, &xen_allowed },
2280 { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
2281 { "qtest", "QTest", qtest_available, qtest_init, &qtest_allowed },
2284 static int configure_accelerator(void)
2286 const char *p = NULL;
2289 bool accel_initialised = 0;
2290 bool init_failed = 0;
2292 QemuOptsList *list = qemu_find_opts("machine");
2293 if (!QTAILQ_EMPTY(&list->head)) {
2294 p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel");
2298 /* Use the default "accelerator", tcg */
2302 while (!accel_initialised && *p != '\0') {
2306 p = get_opt_name(buf, sizeof (buf), p, ':');
2307 for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
2308 if (strcmp(accel_list[i].opt_name, buf) == 0) {
2309 *(accel_list[i].allowed) = 1;
2310 ret = accel_list[i].init();
2313 if (!accel_list[i].available()) {
2314 printf("%s not supported for this target\n",
2315 accel_list[i].name);
2317 fprintf(stderr, "failed to initialize %s: %s\n",
2321 *(accel_list[i].allowed) = 0;
2323 accel_initialised = 1;
2328 if (i == ARRAY_SIZE(accel_list)) {
2329 fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
2333 if (!accel_initialised) {
2334 fprintf(stderr, "No accelerator found!\n");
2336 maru_register_exit_msg(MARU_EXIT_UNKNOWN, "No accelerator found.");
2342 fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
2345 return !accel_initialised;
2348 void qemu_add_exit_notifier(Notifier *notify)
2350 notifier_list_add(&exit_notifiers, notify);
2353 void qemu_remove_exit_notifier(Notifier *notify)
2355 notifier_remove(notify);
2358 static void qemu_run_exit_notifiers(void)
2360 notifier_list_notify(&exit_notifiers, NULL);
2363 void qemu_add_machine_init_done_notifier(Notifier *notify)
2365 notifier_list_add(&machine_init_done_notifiers, notify);
2368 static void qemu_run_machine_init_done_notifiers(void)
2370 notifier_list_notify(&machine_init_done_notifiers, NULL);
2373 static const QEMUOption *lookup_opt(int argc, char **argv,
2374 const char **poptarg, int *poptind)
2376 const QEMUOption *popt;
2377 int optind = *poptind;
2378 char *r = argv[optind];
2381 loc_set_cmdline(argv, optind, 1);
2383 /* Treat --foo the same as -foo. */
2386 popt = qemu_options;
2389 error_report("invalid option");
2391 maru_register_exit_msg(MARU_EXIT_UNKNOWN, "invalid option.");
2395 if (!strcmp(popt->name, r + 1))
2399 if (popt->flags & HAS_ARG) {
2400 if (optind >= argc) {
2401 error_report("requires an argument");
2403 maru_register_exit_msg(MARU_EXIT_UNKNOWN, "requires an argument.");
2407 optarg = argv[optind++];
2408 loc_set_cmdline(argv, optind - 2, 2);
2419 static gpointer malloc_and_trace(gsize n_bytes)
2421 void *ptr = malloc(n_bytes);
2422 trace_g_malloc(n_bytes, ptr);
2426 static gpointer realloc_and_trace(gpointer mem, gsize n_bytes)
2428 void *ptr = realloc(mem, n_bytes);
2429 trace_g_realloc(mem, n_bytes, ptr);
2433 static void free_and_trace(gpointer mem)
2439 // virtio-gl pci device lookup
2441 const char *device_name;
2443 } device_opt_finding_t;
2445 static int find_device_opt (QemuOpts *opts, void *opaque)
2447 device_opt_finding_t *devp = (device_opt_finding_t *) opaque;
2448 if (devp->found == 1) {
2452 const char *str = qemu_opt_get (opts, "driver");
2453 if (strcmp (str, devp->device_name) == 0) {
2459 int use_qemu_display = 0; //0:use tizen qemu sdl, 1:use original qemu sdl
2461 int qemu_init_main_loop(void)
2463 return main_loop_init();
2467 // W/A for preserve larger continuous heap for RAM.
2468 void *preallocated_ptr = 0;
2471 int main(int argc, char **argv, char **envp)
2474 int snapshot, linux_boot;
2475 const char *icount_option = NULL;
2476 const char *initrd_filename;
2477 const char *kernel_filename, *kernel_cmdline;
2478 char* tmp_cmdline = NULL;
2479 char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
2481 DisplayChangeListener *dcl;
2482 int cyls, heads, secs, translation;
2483 QemuOpts *hda_opts = NULL, *opts, *machine_opts;
2484 QemuOptsList *olist;
2487 const char *loadvm = NULL;
2488 QEMUMachine *machine;
2489 const char *cpu_model;
2490 const char *vga_model = "none";
2491 const char *pid_file = NULL;
2492 const char *incoming = NULL;
2494 int show_vnc_port = 0;
2496 bool defconfig = true;
2497 bool userconfig = true;
2498 const char *log_mask = NULL;
2499 const char *log_file = NULL;
2500 GMemVTable mem_trace = {
2501 .malloc = malloc_and_trace,
2502 .realloc = realloc_and_trace,
2503 .free = free_and_trace,
2505 const char *trace_events = NULL;
2506 const char *trace_file = NULL;
2510 char http_proxy[MIDBUF] ={0},https_proxy[MIDBUF] = {0,},
2511 ftp_proxy[MIDBUF] = {0,}, socks_proxy[MIDBUF] = {0,},
2512 dns1[MIDBUF] = {0}, dns2[MIDBUF] = {0};
2515 atexit(qemu_run_exit_notifiers);
2516 error_set_progname(argv[0]);
2518 g_mem_set_vtable(&mem_trace);
2519 if (!g_thread_supported()) {
2520 #if !GLIB_CHECK_VERSION(2, 31, 0)
2521 g_thread_init(NULL);
2523 fprintf(stderr, "glib threading failed to initialize.\n");
2528 module_call_init(MODULE_INIT_QOM);
2533 rtc_clock = host_clock;
2535 qemu_cache_utils_init(envp);
2537 QLIST_INIT (&vm_change_state_head);
2538 os_setup_early_signal_handling();
2540 module_call_init(MODULE_INIT_MACHINE);
2541 machine = find_default_machine();
2545 cyls = heads = secs = 0;
2546 translation = BIOS_ATA_TRANSLATION_AUTO;
2548 for (i = 0; i < MAX_NODES; i++) {
2550 node_cpumask[i] = bitmap_new(MAX_CPUMASK_BITS);
2558 /* first pass of option parsing */
2560 while (optind < argc) {
2561 if (argv[optind][0] != '-') {
2566 const QEMUOption *popt;
2568 popt = lookup_opt(argc, argv, &optarg, &optind);
2569 switch (popt->index) {
2570 case QEMU_OPTION_nodefconfig:
2573 case QEMU_OPTION_nouserconfig:
2582 ret = qemu_read_default_config_files(userconfig);
2588 /* second pass of option parsing */
2593 if (argv[optind][0] != '-') {
2594 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
2596 const QEMUOption *popt;
2598 popt = lookup_opt(argc, argv, &optarg, &optind);
2599 if (!(popt->arch_mask & arch_type)) {
2600 printf("Option %s not supported for this target\n", popt->name);
2603 switch(popt->index) {
2605 machine = machine_parse(optarg);
2607 case QEMU_OPTION_cpu:
2608 /* hw initialization will check this */
2611 case QEMU_OPTION_hda:
2615 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2617 snprintf(buf, sizeof(buf),
2618 "%s,cyls=%d,heads=%d,secs=%d%s",
2619 HD_OPTS , cyls, heads, secs,
2620 translation == BIOS_ATA_TRANSLATION_LBA ?
2622 translation == BIOS_ATA_TRANSLATION_NONE ?
2623 ",trans=none" : "");
2624 drive_add(IF_DEFAULT, 0, optarg, buf);
2627 case QEMU_OPTION_hdb:
2628 case QEMU_OPTION_hdc:
2629 case QEMU_OPTION_hdd:
2630 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2633 case QEMU_OPTION_drive:
2634 if (drive_def(optarg) == NULL) {
2638 case QEMU_OPTION_set:
2639 if (qemu_set_option(optarg) != 0)
2642 case QEMU_OPTION_global:
2643 if (qemu_global_option(optarg) != 0)
2646 case QEMU_OPTION_mtdblock:
2647 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
2649 case QEMU_OPTION_sd:
2650 drive_add(IF_SD, 0, optarg, SD_OPTS);
2652 case QEMU_OPTION_pflash:
2653 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
2655 case QEMU_OPTION_snapshot:
2658 case QEMU_OPTION_hdachs:
2662 cyls = strtol(p, (char **)&p, 0);
2663 if (cyls < 1 || cyls > 16383)
2668 heads = strtol(p, (char **)&p, 0);
2669 if (heads < 1 || heads > 16)
2674 secs = strtol(p, (char **)&p, 0);
2675 if (secs < 1 || secs > 63)
2679 if (!strcmp(p, "none"))
2680 translation = BIOS_ATA_TRANSLATION_NONE;
2681 else if (!strcmp(p, "lba"))
2682 translation = BIOS_ATA_TRANSLATION_LBA;
2683 else if (!strcmp(p, "auto"))
2684 translation = BIOS_ATA_TRANSLATION_AUTO;
2687 } else if (*p != '\0') {
2689 fprintf(stderr, "qemu: invalid physical CHS format\n");
2692 if (hda_opts != NULL) {
2694 snprintf(num, sizeof(num), "%d", cyls);
2695 qemu_opt_set(hda_opts, "cyls", num);
2696 snprintf(num, sizeof(num), "%d", heads);
2697 qemu_opt_set(hda_opts, "heads", num);
2698 snprintf(num, sizeof(num), "%d", secs);
2699 qemu_opt_set(hda_opts, "secs", num);
2700 if (translation == BIOS_ATA_TRANSLATION_LBA)
2701 qemu_opt_set(hda_opts, "trans", "lba");
2702 if (translation == BIOS_ATA_TRANSLATION_NONE)
2703 qemu_opt_set(hda_opts, "trans", "none");
2707 case QEMU_OPTION_numa:
2708 if (nb_numa_nodes >= MAX_NODES) {
2709 fprintf(stderr, "qemu: too many NUMA nodes\n");
2714 case QEMU_OPTION_display:
2715 display_type = select_display(optarg);
2717 case QEMU_OPTION_nographic:
2718 display_type = DT_NOGRAPHIC;
2720 case QEMU_OPTION_curses:
2721 #ifdef CONFIG_CURSES
2722 display_type = DT_CURSES;
2724 fprintf(stderr, "Curses support is disabled\n");
2728 case QEMU_OPTION_portrait:
2729 graphic_rotate = 90;
2731 case QEMU_OPTION_rotate:
2732 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
2733 if (graphic_rotate != 0 && graphic_rotate != 90 &&
2734 graphic_rotate != 180 && graphic_rotate != 270) {
2736 "qemu: only 90, 180, 270 deg rotation is available\n");
2740 case QEMU_OPTION_kernel:
2741 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg);
2743 case QEMU_OPTION_initrd:
2744 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg);
2746 case QEMU_OPTION_append:
2748 gethostproxy(http_proxy, https_proxy, ftp_proxy, socks_proxy);
2749 gethostDNS(dns1, dns2);
2753 tizen_base_port = get_sdb_base_port();
2758 tmp_cmdline = g_strdup_printf("%s sdb_port=%d,"
2759 " http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s"
2760 " dns1=%s dns2=%s", optarg, tizen_base_port,
2761 http_proxy, https_proxy, ftp_proxy, socks_proxy,
2763 qemu_opts_set(qemu_find_opts("machine"), 0, "append",
2765 fprintf(stdout, "kernel command : %s\n", tmp_cmdline);
2767 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg);
2770 case QEMU_OPTION_dtb:
2771 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg);
2773 case QEMU_OPTION_cdrom:
2774 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
2776 case QEMU_OPTION_boot:
2778 static const char * const params[] = {
2779 "order", "once", "menu",
2780 "splash", "splash-time", NULL
2782 char buf[sizeof(boot_devices)];
2783 char *standard_boot_devices;
2786 if (!strchr(optarg, '=')) {
2788 pstrcpy(buf, sizeof(buf), optarg);
2789 } else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
2791 "qemu: unknown boot parameter '%s' in '%s'\n",
2797 get_param_value(buf, sizeof(buf), "order", optarg)) {
2798 validate_bootdevices(buf);
2799 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2802 if (get_param_value(buf, sizeof(buf),
2804 validate_bootdevices(buf);
2805 standard_boot_devices = g_strdup(boot_devices);
2806 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2807 qemu_register_reset(restore_boot_devices,
2808 standard_boot_devices);
2810 if (get_param_value(buf, sizeof(buf),
2812 if (!strcmp(buf, "on")) {
2814 } else if (!strcmp(buf, "off")) {
2818 "qemu: invalid option value '%s'\n",
2823 qemu_opts_parse(qemu_find_opts("boot-opts"),
2828 case QEMU_OPTION_fda:
2829 case QEMU_OPTION_fdb:
2830 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2833 case QEMU_OPTION_no_fd_bootchk:
2836 case QEMU_OPTION_netdev:
2837 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
2841 case QEMU_OPTION_net:
2842 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
2846 #ifdef CONFIG_LIBISCSI
2847 case QEMU_OPTION_iscsi:
2848 opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0);
2855 case QEMU_OPTION_tftp:
2856 legacy_tftp_prefix = optarg;
2858 case QEMU_OPTION_bootp:
2859 legacy_bootp_filename = optarg;
2861 case QEMU_OPTION_redir:
2862 if (net_slirp_redir(optarg) < 0)
2866 case QEMU_OPTION_bt:
2867 add_device_config(DEV_BT, optarg);
2869 case QEMU_OPTION_audio_help:
2870 if (!(audio_available())) {
2871 printf("Option %s not supported for this target\n", popt->name);
2877 case QEMU_OPTION_soundhw:
2878 if (!(audio_available())) {
2879 printf("Option %s not supported for this target\n", popt->name);
2882 select_soundhw (optarg);
2887 case QEMU_OPTION_version:
2891 case QEMU_OPTION_m: {
2896 value = strtosz(optarg, &end);
2897 if (value < 0 || *end) {
2898 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
2901 sz = QEMU_ALIGN_UP((uint64_t)value, 8192);
2903 if (ram_size != sz) {
2904 fprintf(stderr, "qemu: ram size too large\n");
2909 case QEMU_OPTION_mempath:
2913 case QEMU_OPTION_mem_prealloc:
2924 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
2926 case QEMU_OPTION_gdb:
2927 add_device_config(DEV_GDB, optarg);
2932 case QEMU_OPTION_bios:
2935 case QEMU_OPTION_singlestep:
2942 keyboard_layout = optarg;
2944 case QEMU_OPTION_localtime:
2947 case QEMU_OPTION_vga:
2956 w = strtol(p, (char **)&p, 10);
2959 fprintf(stderr, "qemu: invalid resolution or depth\n");
2965 h = strtol(p, (char **)&p, 10);
2970 depth = strtol(p, (char **)&p, 10);
2971 if (depth != 8 && depth != 15 && depth != 16 &&
2972 depth != 24 && depth != 32)
2974 } else if (*p == '\0') {
2975 depth = graphic_depth;
2982 graphic_depth = depth;
2985 case QEMU_OPTION_echr:
2988 term_escape_char = strtol(optarg, &r, 0);
2990 printf("Bad argument to echr\n");
2993 case QEMU_OPTION_monitor:
2994 monitor_parse(optarg, "readline");
2995 default_monitor = 0;
2997 case QEMU_OPTION_qmp:
2998 monitor_parse(optarg, "control");
2999 default_monitor = 0;
3001 case QEMU_OPTION_mon:
3002 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
3006 default_monitor = 0;
3008 case QEMU_OPTION_chardev:
3009 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
3014 case QEMU_OPTION_fsdev:
3015 olist = qemu_find_opts("fsdev");
3017 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
3020 opts = qemu_opts_parse(olist, optarg, 1);
3022 fprintf(stderr, "parse error: %s\n", optarg);
3026 case QEMU_OPTION_virtfs: {
3029 const char *writeout, *sock_fd, *socket;
3031 olist = qemu_find_opts("virtfs");
3033 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
3036 opts = qemu_opts_parse(olist, optarg, 1);
3038 fprintf(stderr, "parse error: %s\n", optarg);
3042 if (qemu_opt_get(opts, "fsdriver") == NULL ||
3043 qemu_opt_get(opts, "mount_tag") == NULL) {
3044 fprintf(stderr, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
3047 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
3048 qemu_opt_get(opts, "mount_tag"),
3051 fprintf(stderr, "duplicate fsdev id: %s\n",
3052 qemu_opt_get(opts, "mount_tag"));
3056 writeout = qemu_opt_get(opts, "writeout");
3058 #ifdef CONFIG_SYNC_FILE_RANGE
3059 qemu_opt_set(fsdev, "writeout", writeout);
3061 fprintf(stderr, "writeout=immediate not supported on "
3066 qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver"));
3067 qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"));
3068 qemu_opt_set(fsdev, "security_model",
3069 qemu_opt_get(opts, "security_model"));
3070 socket = qemu_opt_get(opts, "socket");
3072 qemu_opt_set(fsdev, "socket", socket);
3074 sock_fd = qemu_opt_get(opts, "sock_fd");
3076 qemu_opt_set(fsdev, "sock_fd", sock_fd);
3079 qemu_opt_set_bool(fsdev, "readonly",
3080 qemu_opt_get_bool(opts, "readonly", 0));
3081 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3083 qemu_opt_set(device, "driver", "virtio-9p-pci");
3084 qemu_opt_set(device, "fsdev",
3085 qemu_opt_get(opts, "mount_tag"));
3086 qemu_opt_set(device, "mount_tag",
3087 qemu_opt_get(opts, "mount_tag"));
3090 case QEMU_OPTION_virtfs_synth: {
3094 fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3097 fprintf(stderr, "duplicate option: %s\n", "virtfs_synth");
3100 qemu_opt_set(fsdev, "fsdriver", "synth");
3102 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3104 qemu_opt_set(device, "driver", "virtio-9p-pci");
3105 qemu_opt_set(device, "fsdev", "v_synth");
3106 qemu_opt_set(device, "mount_tag", "v_synth");
3109 case QEMU_OPTION_serial:
3110 add_device_config(DEV_SERIAL, optarg);
3112 if (strncmp(optarg, "mon:", 4) == 0) {
3113 default_monitor = 0;
3116 case QEMU_OPTION_watchdog:
3119 "qemu: only one watchdog option may be given\n");
3124 case QEMU_OPTION_watchdog_action:
3125 if (select_watchdog_action(optarg) == -1) {
3126 fprintf(stderr, "Unknown -watchdog-action parameter\n");
3130 case QEMU_OPTION_virtiocon:
3131 add_device_config(DEV_VIRTCON, optarg);
3132 default_virtcon = 0;
3133 if (strncmp(optarg, "mon:", 4) == 0) {
3134 default_monitor = 0;
3137 case QEMU_OPTION_parallel:
3138 add_device_config(DEV_PARALLEL, optarg);
3139 default_parallel = 0;
3140 if (strncmp(optarg, "mon:", 4) == 0) {
3141 default_monitor = 0;
3144 case QEMU_OPTION_debugcon:
3145 add_device_config(DEV_DEBUGCON, optarg);
3147 case QEMU_OPTION_loadvm:
3150 case QEMU_OPTION_full_screen:
3154 case QEMU_OPTION_no_frame:
3157 case QEMU_OPTION_alt_grab:
3160 case QEMU_OPTION_ctrl_grab:
3163 case QEMU_OPTION_no_quit:
3166 case QEMU_OPTION_sdl:
3167 display_type = DT_SDL;
3170 case QEMU_OPTION_no_frame:
3171 case QEMU_OPTION_alt_grab:
3172 case QEMU_OPTION_ctrl_grab:
3173 case QEMU_OPTION_no_quit:
3174 case QEMU_OPTION_sdl:
3175 fprintf(stderr, "SDL support is disabled\n");
3178 case QEMU_OPTION_pidfile:
3181 case QEMU_OPTION_win2k_hack:
3182 win2k_install_hack = 1;
3184 case QEMU_OPTION_rtc_td_hack: {
3185 static GlobalProperty slew_lost_ticks[] = {
3187 .driver = "mc146818rtc",
3188 .property = "lost_tick_policy",
3191 { /* end of list */ }
3194 qdev_prop_register_global_list(slew_lost_ticks);
3197 case QEMU_OPTION_acpitable:
3198 do_acpitable_option(optarg);
3200 case QEMU_OPTION_smbios:
3201 do_smbios_option(optarg);
3203 #ifdef CONFIG_OPENGLES
3204 case QEMU_OPTION_gles2_quality:
3205 gles2_quality = strtoul(optarg, NULL, 10);
3208 case QEMU_OPTION_enable_kvm:
3209 olist = qemu_find_opts("machine");
3210 qemu_opts_parse(olist, "accel=kvm", 0);
3212 case QEMU_OPTION_enable_gl:
3213 #ifdef CONFIG_GL_BACKEND
3214 #if defined(CONFIG_MARU)
3218 fprintf(stderr, "Virtio GL support is disabled, ignoring -enable-gl\n");
3221 case QEMU_OPTION_machine:
3222 olist = qemu_find_opts("machine");
3223 opts = qemu_opts_parse(olist, optarg, 1);
3225 fprintf(stderr, "parse error: %s\n", optarg);
3228 optarg = qemu_opt_get(opts, "type");
3230 machine = machine_parse(optarg);
3233 case QEMU_OPTION_usb:
3236 case QEMU_OPTION_usbdevice:
3238 add_device_config(DEV_USB, optarg);
3240 case QEMU_OPTION_device:
3241 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
3245 case QEMU_OPTION_smp:
3248 fprintf(stderr, "Invalid number of CPUs\n");
3251 if (max_cpus < smp_cpus) {
3252 fprintf(stderr, "maxcpus must be equal to or greater than "
3256 if (max_cpus > 255) {
3257 fprintf(stderr, "Unsupported number of maxcpus\n");
3261 case QEMU_OPTION_vnc:
3264 vnc_display = optarg;
3266 fprintf(stderr, "VNC support is disabled\n");
3270 case QEMU_OPTION_no_acpi:
3273 case QEMU_OPTION_no_hpet:
3276 case QEMU_OPTION_balloon:
3277 if (balloon_parse(optarg) < 0) {
3278 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
3282 case QEMU_OPTION_no_reboot:
3285 case QEMU_OPTION_no_shutdown:
3288 case QEMU_OPTION_show_cursor:
3291 case QEMU_OPTION_uuid:
3292 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
3293 fprintf(stderr, "Fail to parse UUID string."
3294 " Wrong format.\n");
3298 case QEMU_OPTION_option_rom:
3299 if (nb_option_roms >= MAX_OPTION_ROMS) {
3300 fprintf(stderr, "Too many option ROMs\n");
3303 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
3304 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
3305 option_rom[nb_option_roms].bootindex =
3306 qemu_opt_get_number(opts, "bootindex", -1);
3307 if (!option_rom[nb_option_roms].name) {
3308 fprintf(stderr, "Option ROM file is not specified\n");
3313 case QEMU_OPTION_semihosting:
3314 semihosting_enabled = 1;
3316 case QEMU_OPTION_name:
3317 qemu_name = g_strdup(optarg);
3319 char *p = strchr(qemu_name, ',');
3322 if (strncmp(p, "process=", 8)) {
3323 fprintf(stderr, "Unknown subargument %s to -name\n", p);
3327 os_set_proc_name(p);
3331 case QEMU_OPTION_prom_env:
3332 if (nb_prom_envs >= MAX_PROM_ENVS) {
3333 fprintf(stderr, "Too many prom variables\n");
3336 prom_envs[nb_prom_envs] = optarg;
3339 case QEMU_OPTION_old_param:
3342 case QEMU_OPTION_clock:
3343 configure_alarms(optarg);
3345 case QEMU_OPTION_startdate:
3346 configure_rtc_date_offset(optarg, 1);
3348 case QEMU_OPTION_rtc:
3349 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
3353 configure_rtc(opts);
3355 case QEMU_OPTION_tb_size:
3356 tcg_tb_size = strtol(optarg, NULL, 0);
3357 if (tcg_tb_size < 0) {
3361 case QEMU_OPTION_icount:
3362 icount_option = optarg;
3364 case QEMU_OPTION_incoming:
3366 runstate_set(RUN_STATE_INMIGRATE);
3368 case QEMU_OPTION_nodefaults:
3370 default_parallel = 0;
3371 default_virtcon = 0;
3372 default_monitor = 0;
3379 case QEMU_OPTION_xen_domid:
3380 if (!(xen_available())) {
3381 printf("Option %s not supported for this target\n", popt->name);
3384 xen_domid = atoi(optarg);
3386 case QEMU_OPTION_xen_create:
3387 if (!(xen_available())) {
3388 printf("Option %s not supported for this target\n", popt->name);
3391 xen_mode = XEN_CREATE;
3393 case QEMU_OPTION_xen_attach:
3394 if (!(xen_available())) {
3395 printf("Option %s not supported for this target\n", popt->name);
3398 xen_mode = XEN_ATTACH;
3400 case QEMU_OPTION_trace:
3402 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
3406 trace_events = qemu_opt_get(opts, "events");
3407 trace_file = qemu_opt_get(opts, "file");
3410 case QEMU_OPTION_readconfig:
3412 int ret = qemu_read_config_file(optarg);
3414 fprintf(stderr, "read config %s: %s\n", optarg,
3420 case QEMU_OPTION_spice:
3421 olist = qemu_find_opts("spice");
3423 fprintf(stderr, "spice is not supported by this qemu build.\n");
3426 opts = qemu_opts_parse(olist, optarg, 0);
3428 fprintf(stderr, "parse error: %s\n", optarg);
3432 case QEMU_OPTION_writeconfig:
3435 if (strcmp(optarg, "-") == 0) {
3438 fp = fopen(optarg, "w");
3440 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
3444 qemu_config_write(fp);
3448 case QEMU_OPTION_qtest:
3449 qtest_chrdev = optarg;
3451 case QEMU_OPTION_qtest_log:
3454 case QEMU_OPTION_sandbox:
3455 opts = qemu_opts_parse(qemu_find_opts("sandbox"), optarg, 1);
3460 case QEMU_OPTION_enable_hax:
3461 #ifdef CONFIG_HAX_BACKEND
3462 olist = qemu_find_opts("machine");
3463 //qemu_opts_reset(olist);
3465 //qemu_opts_parse(olist, "accel=hax", 0);
3468 "HAX support is disabled, ignoring -enable-hax\n");
3472 case QEMU_OPTION_max_touch_point:
3474 int cnt = atoi(optarg);
3475 fprintf(stderr, "maxTouchPoint:%d\n", cnt);
3476 set_emul_max_touch_point(cnt);
3479 case QEMU_OPTION_disable_skin:
3484 os_parse_cmd_args(popt->index, optarg);
3490 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 0)) {
3494 if (machine == NULL) {
3495 fprintf(stderr, "No machine found.\n");
3499 if (machine->hw_version) {
3500 qemu_set_version(machine->hw_version);
3503 /* Init CPU def lists, based on config
3504 * - Must be called after all the qemu_read_config_file() calls
3505 * - Must be called before list_cpus()
3506 * - Must be called before machine->init()
3510 if (cpu_model && is_help_option(cpu_model)) {
3511 list_cpus(stdout, &fprintf, cpu_model);
3515 #ifdef CONFIG_GL_BACKEND
3516 #if defined(CONFIG_MARU)
3518 capability_check_gl = gl_acceleration_capability_check();
3520 if (capability_check_gl != 0) {
3522 fprintf (stderr, "Warn: GL acceleration was disabled due to the fail of GL check!\n");
3526 device_opt_finding_t devp = {VIRTIOGL_DEV_NAME, 0};
3527 qemu_opts_foreach(qemu_find_opts("device"), find_device_opt, &devp, 0);
3528 if (devp.found == 0) {
3529 if (!qemu_opts_parse(qemu_find_opts("device"), VIRTIOGL_DEV_NAME, 1)) {
3536 // To check host gl driver capability and notify to guest.
3537 gchar *tmp = tmp_cmdline;
3538 tmp_cmdline = g_strdup_printf("%s gles=%d", tmp, enable_gl);
3539 qemu_opts_set(qemu_find_opts("machine"), 0, "append", tmp_cmdline);
3540 fprintf(stdout, "kernel command : %s\n", tmp_cmdline);
3546 /* Open the logfile at this point, if necessary. We can't open the logfile
3547 * when encountering either of the logging options (-d or -D) because the
3548 * other one may be encountered later on the command line, changing the
3549 * location or level of logging.
3553 set_cpu_log_filename(log_file);
3555 set_cpu_log(log_mask);
3558 if (!trace_backend_init(trace_events, trace_file)) {
3562 /* If no data_dir is specified then try to find it relative to the
3565 data_dir = os_find_datadir(argv[0]);
3567 /* If all else fails use the install path specified when building. */
3569 data_dir = CONFIG_QEMU_DATADIR;
3573 * Default to max_cpus = smp_cpus, in case the user doesn't
3574 * specify a max_cpus value.
3577 max_cpus = smp_cpus;
3579 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
3580 if (smp_cpus > machine->max_cpus) {
3581 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
3582 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
3588 * Get the default machine options from the machine if it is not already
3589 * specified either by the configuration file or by the command line.
3591 if (machine->default_machine_opts) {
3592 qemu_opts_set_defaults(qemu_find_opts("machine"),
3593 machine->default_machine_opts, 0);
3596 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
3597 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
3599 if (machine->no_serial) {
3602 if (machine->no_parallel) {
3603 default_parallel = 0;
3605 if (!machine->use_virtcon) {
3606 default_virtcon = 0;
3608 if (machine->no_floppy) {
3611 if (machine->no_cdrom) {
3614 if (machine->no_sdcard) {
3618 if (display_type == DT_NOGRAPHIC) {
3619 if (default_parallel)
3620 add_device_config(DEV_PARALLEL, "null");
3621 if (default_serial && default_monitor) {
3622 add_device_config(DEV_SERIAL, "mon:stdio");
3623 } else if (default_virtcon && default_monitor) {
3624 add_device_config(DEV_VIRTCON, "mon:stdio");
3627 add_device_config(DEV_SERIAL, "stdio");
3628 if (default_virtcon)
3629 add_device_config(DEV_VIRTCON, "stdio");
3630 if (default_monitor)
3631 monitor_parse("stdio", "readline");
3635 add_device_config(DEV_SERIAL, "vc:80Cx24C");
3636 if (default_parallel)
3637 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
3638 if (default_monitor)
3639 monitor_parse("vc:80Cx24C", "readline");
3640 if (default_virtcon)
3641 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
3645 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
3647 #ifdef CONFIG_VIRTFS
3648 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
3655 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
3660 /* init the memory */
3661 if (ram_size == 0) {
3662 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
3665 // W/A for preserve larger continuous heap for RAM.
3666 preallocated_ptr = qemu_vmalloc(ram_size);
3669 hax_pre_init(ram_size);
3671 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0)
3676 configure_accelerator();
3678 qemu_init_cpu_loop();
3679 if (qemu_init_main_loop()) {
3680 fprintf(stderr, "qemu_init_main_loop failed\n");
3684 machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
3686 kernel_filename = qemu_opt_get(machine_opts, "kernel");
3687 initrd_filename = qemu_opt_get(machine_opts, "initrd");
3688 kernel_cmdline = qemu_opt_get(machine_opts, "append");
3690 kernel_filename = initrd_filename = kernel_cmdline = NULL;
3693 if (!kernel_cmdline) {
3694 kernel_cmdline = "";
3697 #if defined(CONFIG_MARU)
3698 is_webcam_enabled = marucam_device_check(WEBCAM_INFO_WRITE);
3699 if (!is_webcam_enabled) {
3700 fprintf (stderr, "[Webcam] <WARNING> Webcam support was disabled "
3701 "due to the fail of webcam capability check!\n");
3704 gchar const *tmp_cam_kcmd = kernel_cmdline;
3705 kernel_cmdline = g_strdup_printf("%s enable_cam=%d", tmp_cam_kcmd, is_webcam_enabled);
3706 // g_free(tmp_cam_kcmd);
3708 if (is_webcam_enabled) {
3709 device_opt_finding_t devp = {MARUCAM_DEV_NAME, 0};
3710 qemu_opts_foreach(qemu_find_opts("device"), find_device_opt, &devp, 0);
3711 if (devp.found == 0) {
3712 if (!qemu_opts_parse(qemu_find_opts("device"), MARUCAM_DEV_NAME, 1)) {
3713 fprintf(stderr, "Failed to initialize the marucam device.\n");
3717 fprintf(stdout, "[Webcam] Webcam support was enabled.\n");
3721 linux_boot = (kernel_filename != NULL);
3723 if (!linux_boot && *kernel_cmdline != '\0') {
3724 fprintf(stderr, "-append only allowed with -kernel option\n");
3728 if (!linux_boot && initrd_filename != NULL) {
3729 fprintf(stderr, "-initrd only allowed with -kernel option\n");
3733 if (!linux_boot && machine_opts && qemu_opt_get(machine_opts, "dtb")) {
3734 fprintf(stderr, "-dtb only allowed with -kernel option\n");
3738 os_set_line_buffering();
3740 if (init_timer_alarm() < 0) {
3741 fprintf(stderr, "could not initialize alarm timer\n");
3746 /* spice needs the timers to be initialized by this point */
3750 if (icount_option && (kvm_enabled() || xen_enabled() || hax_enabled())) {
3751 fprintf(stderr, "-icount is not allowed with kvm or xen\n");
3754 configure_icount(icount_option);
3756 if (net_init_clients() < 0) {
3760 /* init the bluetooth world */
3761 if (foreach_device_config(DEV_BT, bt_parse))
3764 if (!xen_enabled()) {
3765 /* On 32-bit hosts, QEMU is limited by virtual address space */
3766 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
3767 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
3772 cpu_exec_init_all();
3774 bdrv_init_with_whitelist();
3778 /* open the virtual block devices */
3780 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
3781 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
3784 default_drive(default_cdrom, snapshot, machine->use_scsi,
3785 IF_DEFAULT, 2, CDROM_OPTS);
3786 default_drive(default_floppy, snapshot, machine->use_scsi,
3787 IF_FLOPPY, 0, FD_OPTS);
3788 default_drive(default_sdcard, snapshot, machine->use_scsi,
3791 register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL);
3793 if (nb_numa_nodes > 0) {
3796 if (nb_numa_nodes > MAX_NODES) {
3797 nb_numa_nodes = MAX_NODES;
3800 /* If no memory size if given for any node, assume the default case
3801 * and distribute the available memory equally across all nodes
3803 for (i = 0; i < nb_numa_nodes; i++) {
3804 if (node_mem[i] != 0)
3807 if (i == nb_numa_nodes) {
3808 uint64_t usedmem = 0;
3810 /* On Linux, the each node's border has to be 8MB aligned,
3811 * the final node gets the rest.
3813 for (i = 0; i < nb_numa_nodes - 1; i++) {
3814 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
3815 usedmem += node_mem[i];
3817 node_mem[i] = ram_size - usedmem;
3820 for (i = 0; i < nb_numa_nodes; i++) {
3821 if (!bitmap_empty(node_cpumask[i], MAX_CPUMASK_BITS)) {
3825 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3826 * must cope with this anyway, because there are BIOSes out there in
3827 * real machines which also use this scheme.
3829 if (i == nb_numa_nodes) {
3830 for (i = 0; i < max_cpus; i++) {
3831 set_bit(i, node_cpumask[i % nb_numa_nodes]);
3836 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
3840 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
3842 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
3844 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
3846 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
3849 /* If no default VGA is requested, the default is "none". */
3850 if (default_vga && cirrus_vga_available()) {
3851 vga_model = "cirrus";
3853 select_vgahw(vga_model);
3856 i = select_watchdog(watchdog);
3858 exit (i == 1 ? 1 : 0);
3861 if (machine->compat_props) {
3862 qdev_prop_register_global_list(machine->compat_props);
3866 qdev_machine_init();
3868 machine->init(ram_size, boot_devices,
3869 kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
3871 g_free((gchar *)tmp_cmdline);
3874 cpu_synchronize_all_post_init();
3878 current_machine = machine;
3880 if (hax_enabled()) {
3884 /* init USB devices */
3886 if (foreach_device_config(DEV_USB, usb_parse) < 0)
3890 /* init generic devices */
3891 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
3894 net_check_clients();
3896 /* just use the first displaystate for the moment */
3897 ds = get_displaystate();
3901 if (display_type == DT_DEFAULT && !display_remote) {
3902 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3903 display_type = DT_SDL;
3904 #elif defined(CONFIG_VNC)
3905 vnc_display = "localhost:0,to=99";
3907 #elif defined(CONFIG_MARU) && defined (__APPLE__)
3908 display_type = DT_MARU;
3910 display_type = DT_NONE;
3915 /* init local displays */
3916 switch (display_type) {
3919 #if defined(CONFIG_CURSES)
3921 curses_display_init(ds, full_screen);
3924 #if defined(CONFIG_SDL)
3926 #if defined(CONFIG_MARU)
3927 /* use tizen qemu sdl */
3928 maru_display_init(ds);
3930 if (skin_disabled == 1) {
3931 //do not start skin client process
3932 set_emul_skin_enable(0);
3934 set_emul_skin_enable(1);
3937 sdl_display_init(ds, full_screen, no_frame);
3940 #elif defined(CONFIG_COCOA)
3942 cocoa_display_init(ds, full_screen);
3945 #if defined(CONFIG_MARU) && defined(__APPLE__)
3947 maru_display_init(ds);
3948 if (skin_disabled == 1) {
3949 //do not start skin client process
3950 set_emul_skin_enable(0);
3952 set_emul_skin_enable(1);
3960 /* must be after terminal init, SDL library changes signal handlers */
3961 os_setup_signal_handling();
3964 /* init remote displays */
3966 vnc_display_init(ds);
3967 if (vnc_display_open(ds, vnc_display) < 0) {
3968 fprintf(stderr, "Failed to start VNC server on `%s'\n",
3973 if (show_vnc_port) {
3974 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
3979 if (using_spice && !qxl_enabled) {
3980 qemu_spice_display_init(ds);
3986 dcl = ds->listeners;
3987 while (dcl != NULL) {
3988 if (dcl->dpy_refresh != NULL) {
3989 ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds);
3990 qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock));
3995 text_consoles_set_display(ds);
3997 if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
4001 qdev_machine_creation_done();
4003 if (rom_load_all() != 0) {
4004 fprintf(stderr, "rom loading failed\n");
4008 /* TODO: once all bus devices are qdevified, this should be done
4009 * when bus is created by qdev.c */
4010 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
4011 qemu_run_machine_init_done_notifiers();
4013 qemu_system_reset(VMRESET_SILENT);
4015 if (load_vmstate(loadvm) < 0) {
4022 int ret = qemu_start_incoming_migration(incoming, &errp);
4024 if (error_is_set(&errp)) {
4025 fprintf(stderr, "Migrate: %s\n", error_get_pretty(errp));
4028 fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n",
4032 } else if (autostart) {