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/maru_common.h"
185 #include "tizen/src/maru_display.h"
186 #include "tizen/src/option.h"
187 #include "tizen/src/emul_state.h"
188 #include "tizen/src/skin/maruskin_operation.h"
189 #include "tizen/src/maru_err_table.h"
193 //#define DEBUG_SLIRP
195 #define DEFAULT_RAM_SIZE 128
197 #define MAX_VIRTIO_CONSOLES 1
200 #define MARUCAM_DEV_NAME "maru_camera_pci"
201 extern int tizen_base_port;
202 int skin_disabled = 0;
205 static const char *data_dir;
206 const char *bios_name = NULL;
207 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
208 DisplayType display_type = DT_DEFAULT;
209 int display_remote = 0;
210 const char* keyboard_layout = NULL;
212 const char *mem_path = NULL;
214 int mem_prealloc = 0; /* force preallocation of physical target memory */
217 NICInfo nd_table[MAX_NICS];
219 static int rtc_utc = 1;
220 static int rtc_date_offset = -1; /* -1 means no change */
221 QEMUClock *rtc_clock;
222 int vga_interface_type = VGA_NONE;
223 static int full_screen = 0;
225 static int no_frame = 0;
228 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
229 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
230 CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
231 int win2k_install_hack = 0;
239 const char *vnc_display;
241 int acpi_enabled = 1;
247 int graphic_rotate = 0;
248 const char *watchdog;
249 QEMUOptionRom option_rom[MAX_OPTION_ROMS];
251 int semihosting_enabled = 0;
253 const char *qemu_name;
256 unsigned int nb_prom_envs = 0;
257 const char *prom_envs[MAX_PROM_ENVS];
259 uint8_t *boot_splash_filedata;
260 int boot_splash_filedata_size;
261 uint8_t qemu_extra_params_fw[2];
264 #define VIRTIOGL_DEV_NAME "virtio-gl-pci"
265 #if defined(CONFIG_MARU) && (!defined(CONFIG_DARWIN))
266 extern int gl_acceleration_capability_check(void);
268 int capability_check_gl = 0;
270 #if defined(CONFIG_MARU) && (!defined(CONFIG_DARWIN))
271 #define WEBCAM_INFO_IGNORE 0x00
272 #define WEBCAM_INFO_WRITE 0x04
273 extern int marucam_device_check(int log_flag);
274 int is_webcam_enabled = 0;
278 typedef struct FWBootEntry FWBootEntry;
281 QTAILQ_ENTRY(FWBootEntry) link;
287 QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order);
290 uint64_t node_mem[MAX_NODES];
291 unsigned long *node_cpumask[MAX_NODES];
293 uint8_t qemu_uuid[16];
295 static QEMUBootSetHandler *boot_set_handler;
296 static void *boot_set_opaque;
298 static NotifierList exit_notifiers =
299 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
301 static NotifierList machine_init_done_notifiers =
302 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
304 static int tcg_allowed = 1;
309 enum xen_mode xen_mode = XEN_EMULATE;
310 static int tcg_tb_size;
312 #ifdef CONFIG_OPENGLES
313 int gles2_quality = 100;
315 static int default_serial = 1;
316 static int default_parallel = 1;
317 static int default_virtcon = 1;
318 static int default_monitor = 1;
319 static int default_floppy = 1;
320 static int default_cdrom = 1;
321 static int default_sdcard = 1;
322 static int default_vga = 1;
328 { .driver = "isa-serial", .flag = &default_serial },
329 { .driver = "isa-parallel", .flag = &default_parallel },
330 { .driver = "isa-fdc", .flag = &default_floppy },
331 { .driver = "ide-cd", .flag = &default_cdrom },
332 { .driver = "ide-hd", .flag = &default_cdrom },
333 { .driver = "ide-drive", .flag = &default_cdrom },
334 { .driver = "scsi-cd", .flag = &default_cdrom },
335 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
336 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
337 { .driver = "virtio-serial", .flag = &default_virtcon },
338 { .driver = "VGA", .flag = &default_vga },
339 { .driver = "isa-vga", .flag = &default_vga },
340 { .driver = "cirrus-vga", .flag = &default_vga },
341 { .driver = "isa-cirrus-vga", .flag = &default_vga },
342 { .driver = "vmware-svga", .flag = &default_vga },
343 { .driver = "qxl-vga", .flag = &default_vga },
346 const char *qemu_get_vm_name(void)
351 static void res_free(void)
353 if (boot_splash_filedata != NULL) {
354 g_free(boot_splash_filedata);
355 boot_splash_filedata = NULL;
359 static int default_driver_check(QemuOpts *opts, void *opaque)
361 const char *driver = qemu_opt_get(opts, "driver");
366 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
367 if (strcmp(default_list[i].driver, driver) != 0)
369 *(default_list[i].flag) = 0;
374 /***********************************************************/
377 static RunState current_run_state = RUN_STATE_PRELAUNCH;
382 } RunStateTransition;
384 static const RunStateTransition runstate_transitions_def[] = {
386 { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
388 { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },
389 { RUN_STATE_INMIGRATE, RUN_STATE_PRELAUNCH },
391 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
392 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
394 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
395 { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE },
397 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
398 { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
400 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
401 { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
403 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
404 { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
405 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
407 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
408 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
410 { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
412 { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
413 { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
414 { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
415 { RUN_STATE_RUNNING, RUN_STATE_PAUSED },
416 { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE },
417 { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM },
418 { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM },
419 { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
420 { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
422 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
424 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
425 { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
427 { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
428 { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
429 { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },
430 { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
432 { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
433 { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
435 { RUN_STATE_MAX, RUN_STATE_MAX },
438 static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX];
440 bool runstate_check(RunState state)
442 return current_run_state == state;
445 void runstate_init(void)
447 const RunStateTransition *p;
449 memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions));
451 for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) {
452 runstate_valid_transitions[p->from][p->to] = true;
456 /* This function will abort() on invalid state transitions */
457 void runstate_set(RunState new_state)
459 assert(new_state < RUN_STATE_MAX);
461 if (!runstate_valid_transitions[current_run_state][new_state]) {
462 fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
463 RunState_lookup[current_run_state],
464 RunState_lookup[new_state]);
468 current_run_state = new_state;
471 int runstate_is_running(void)
473 return runstate_check(RUN_STATE_RUNNING);
476 StatusInfo *qmp_query_status(Error **errp)
478 StatusInfo *info = g_malloc0(sizeof(*info));
480 info->running = runstate_is_running();
481 info->singlestep = singlestep;
482 info->status = current_run_state;
487 /***********************************************************/
488 /* real time host monotonic timer */
490 /***********************************************************/
491 /* host time/date access */
492 void qemu_get_timedate(struct tm *tm, int offset)
499 if (rtc_date_offset == -1) {
503 ret = localtime(&ti);
505 ti -= rtc_date_offset;
509 memcpy(tm, ret, sizeof(struct tm));
512 int qemu_timedate_diff(struct tm *tm)
516 if (rtc_date_offset == -1)
518 seconds = mktimegm(tm);
521 tmp.tm_isdst = -1; /* use timezone to figure it out */
522 seconds = mktime(&tmp);
525 seconds = mktimegm(tm) + rtc_date_offset;
527 return seconds - time(NULL);
530 void rtc_change_mon_event(struct tm *tm)
534 data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
535 monitor_protocol_event(QEVENT_RTC_CHANGE, data);
536 qobject_decref(data);
539 static void configure_rtc_date_offset(const char *startdate, int legacy)
541 time_t rtc_start_date;
544 if (!strcmp(startdate, "now") && legacy) {
545 rtc_date_offset = -1;
547 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
555 } else if (sscanf(startdate, "%d-%d-%d",
567 rtc_start_date = mktimegm(&tm);
568 if (rtc_start_date == -1) {
570 fprintf(stderr, "Invalid date format. Valid formats are:\n"
571 "'2006-06-17T16:01:21' or '2006-06-17'\n");
574 rtc_date_offset = time(NULL) - rtc_start_date;
578 static void configure_rtc(QemuOpts *opts)
582 value = qemu_opt_get(opts, "base");
584 if (!strcmp(value, "utc")) {
586 } else if (!strcmp(value, "localtime")) {
589 configure_rtc_date_offset(value, 0);
592 value = qemu_opt_get(opts, "clock");
594 if (!strcmp(value, "host")) {
595 rtc_clock = host_clock;
596 } else if (!strcmp(value, "rt")) {
597 rtc_clock = rt_clock;
598 } else if (!strcmp(value, "vm")) {
599 rtc_clock = vm_clock;
601 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
605 value = qemu_opt_get(opts, "driftfix");
607 if (!strcmp(value, "slew")) {
608 static GlobalProperty slew_lost_ticks[] = {
610 .driver = "mc146818rtc",
611 .property = "lost_tick_policy",
614 { /* end of list */ }
617 qdev_prop_register_global_list(slew_lost_ticks);
618 } else if (!strcmp(value, "none")) {
619 /* discard is default */
621 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
627 /***********************************************************/
628 /* Bluetooth support */
631 static struct HCIInfo *hci_table[MAX_NICS];
633 static struct bt_vlan_s {
634 struct bt_scatternet_s net;
636 struct bt_vlan_s *next;
639 /* find or alloc a new bluetooth "VLAN" */
640 static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
642 struct bt_vlan_s **pvlan, *vlan;
643 for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) {
647 vlan = g_malloc0(sizeof(struct bt_vlan_s));
649 pvlan = &first_bt_vlan;
650 while (*pvlan != NULL)
651 pvlan = &(*pvlan)->next;
656 static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
660 static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
665 static struct HCIInfo null_hci = {
666 .cmd_send = null_hci_send,
667 .sco_send = null_hci_send,
668 .acl_send = null_hci_send,
669 .bdaddr_set = null_hci_addr_set,
672 struct HCIInfo *qemu_next_hci(void)
674 if (cur_hci == nb_hcis)
677 return hci_table[cur_hci++];
680 static struct HCIInfo *hci_init(const char *str)
683 struct bt_scatternet_s *vlan = 0;
685 if (!strcmp(str, "null"))
688 else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':'))
690 return bt_host_hci(str[4] ? str + 5 : "hci0");
691 else if (!strncmp(str, "hci", 3)) {
694 if (!strncmp(str + 3, ",vlan=", 6)) {
695 vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0));
700 vlan = qemu_find_bt_vlan(0);
702 return bt_new_hci(vlan);
705 fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
710 static int bt_hci_parse(const char *str)
715 if (nb_hcis >= MAX_NICS) {
716 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
729 bdaddr.b[5] = 0x56 + nb_hcis;
730 hci->bdaddr_set(hci, bdaddr.b);
732 hci_table[nb_hcis++] = hci;
737 static void bt_vhci_add(int vlan_id)
739 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
742 fprintf(stderr, "qemu: warning: adding a VHCI to "
743 "an empty scatternet %i\n", vlan_id);
745 bt_vhci_init(bt_new_hci(vlan));
748 static struct bt_device_s *bt_device_add(const char *opt)
750 struct bt_scatternet_s *vlan;
752 char *endp = strstr(opt, ",vlan=");
753 int len = (endp ? endp - opt : strlen(opt)) + 1;
756 pstrcpy(devname, MIN(sizeof(devname), len), opt);
759 vlan_id = strtol(endp + 6, &endp, 0);
761 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
766 vlan = qemu_find_bt_vlan(vlan_id);
769 fprintf(stderr, "qemu: warning: adding a slave device to "
770 "an empty scatternet %i\n", vlan_id);
772 if (!strcmp(devname, "keyboard"))
773 return bt_keyboard_init(vlan);
775 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
779 static int bt_parse(const char *opt)
781 const char *endp, *p;
784 if (strstart(opt, "hci", &endp)) {
785 if (!*endp || *endp == ',') {
787 if (!strstart(endp, ",vlan=", 0))
790 return bt_hci_parse(opt);
792 } else if (strstart(opt, "vhci", &endp)) {
793 if (!*endp || *endp == ',') {
795 if (strstart(endp, ",vlan=", &p)) {
796 vlan = strtol(p, (char **) &endp, 0);
798 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
802 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
811 } else if (strstart(opt, "device:", &endp))
812 return !bt_device_add(endp);
814 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
818 static int parse_sandbox(QemuOpts *opts, void *opaque)
820 /* FIXME: change this to true for 1.3 */
821 if (qemu_opt_get_bool(opts, "enable", false)) {
822 #ifdef CONFIG_SECCOMP
823 if (seccomp_start() < 0) {
824 qerror_report(ERROR_CLASS_GENERIC_ERROR,
825 "failed to install seccomp syscall filter in the kernel");
829 qerror_report(ERROR_CLASS_GENERIC_ERROR,
830 "sandboxing request but seccomp is not compiled into this build");
838 /***********************************************************/
839 /* QEMU Block devices */
841 #define HD_OPTS "media=disk"
842 #define CDROM_OPTS "media=cdrom"
844 #define PFLASH_OPTS ""
848 static int drive_init_func(QemuOpts *opts, void *opaque)
850 int *use_scsi = opaque;
852 return drive_init(opts, *use_scsi) == NULL;
855 static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
857 if (NULL == qemu_opt_get(opts, "snapshot")) {
858 qemu_opt_set(opts, "snapshot", "on");
863 static void default_drive(int enable, int snapshot, int use_scsi,
864 BlockInterfaceType type, int index,
869 if (type == IF_DEFAULT) {
870 type = use_scsi ? IF_SCSI : IF_IDE;
873 if (!enable || drive_get_by_index(type, index)) {
877 opts = drive_add(type, index, NULL, optstr);
879 drive_enable_snapshot(opts, NULL);
881 if (!drive_init(opts, use_scsi)) {
886 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
888 boot_set_handler = func;
889 boot_set_opaque = opaque;
892 int qemu_boot_set(const char *boot_devices)
894 if (!boot_set_handler) {
897 return boot_set_handler(boot_set_opaque, boot_devices);
900 static void validate_bootdevices(char *devices)
902 /* We just do some generic consistency checks */
906 for (p = devices; *p != '\0'; p++) {
907 /* Allowed boot devices are:
908 * a-b: floppy disk drives
909 * c-f: IDE disk drives
910 * g-m: machine implementation dependent drives
911 * n-p: network devices
912 * It's up to each machine implementation to check if the given boot
913 * devices match the actual hardware implementation and firmware
916 if (*p < 'a' || *p > 'p') {
917 fprintf(stderr, "Invalid boot device '%c'\n", *p);
920 if (bitmap & (1 << (*p - 'a'))) {
921 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
924 bitmap |= 1 << (*p - 'a');
928 static void restore_boot_devices(void *opaque)
930 char *standard_boot_devices = opaque;
931 static int first = 1;
933 /* Restore boot order and remove ourselves after the first boot */
939 qemu_boot_set(standard_boot_devices);
941 qemu_unregister_reset(restore_boot_devices, standard_boot_devices);
942 g_free(standard_boot_devices);
945 void add_boot_device_path(int32_t bootindex, DeviceState *dev,
948 FWBootEntry *node, *i;
954 assert(dev != NULL || suffix != NULL);
956 node = g_malloc0(sizeof(FWBootEntry));
957 node->bootindex = bootindex;
958 node->suffix = suffix ? g_strdup(suffix) : NULL;
961 QTAILQ_FOREACH(i, &fw_boot_order, link) {
962 if (i->bootindex == bootindex) {
963 fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
965 } else if (i->bootindex < bootindex) {
968 QTAILQ_INSERT_BEFORE(i, node, link);
971 QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
975 * This function returns null terminated string that consist of new line
976 * separated device paths.
978 * memory pointed by "size" is assigned total length of the array in bytes
981 char *get_boot_devices_list(uint32_t *size)
987 QTAILQ_FOREACH(i, &fw_boot_order, link) {
988 char *devpath = NULL, *bootpath;
992 devpath = qdev_get_fw_dev_path(i->dev);
996 if (i->suffix && devpath) {
997 size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
999 bootpath = g_malloc(bootpathlen);
1000 snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
1002 } else if (devpath) {
1006 bootpath = g_strdup(i->suffix);
1010 list[total-1] = '\n';
1012 len = strlen(bootpath) + 1;
1013 list = g_realloc(list, total + len);
1014 memcpy(&list[total], bootpath, len);
1024 static void numa_add(const char *optarg)
1028 unsigned long long value, endvalue;
1031 value = endvalue = 0ULL;
1033 optarg = get_opt_name(option, 128, optarg, ',') + 1;
1034 if (!strcmp(option, "node")) {
1035 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
1036 nodenr = nb_numa_nodes;
1038 nodenr = strtoull(option, NULL, 10);
1041 if (get_param_value(option, 128, "mem", optarg) == 0) {
1042 node_mem[nodenr] = 0;
1045 sval = strtosz(option, &endptr);
1046 if (sval < 0 || *endptr) {
1047 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
1050 node_mem[nodenr] = sval;
1052 if (get_param_value(option, 128, "cpus", optarg) != 0) {
1053 value = strtoull(option, &endptr, 10);
1054 if (*endptr == '-') {
1055 endvalue = strtoull(endptr+1, &endptr, 10);
1060 if (!(endvalue < MAX_CPUMASK_BITS)) {
1061 endvalue = MAX_CPUMASK_BITS - 1;
1063 "A max of %d CPUs are supported in a guest\n",
1067 bitmap_set(node_cpumask[nodenr], value, endvalue-value+1);
1074 static void smp_parse(const char *optarg)
1076 int smp, sockets = 0, threads = 0, cores = 0;
1080 smp = strtoul(optarg, &endptr, 10);
1081 if (endptr != optarg) {
1082 if (*endptr == ',') {
1086 if (get_param_value(option, 128, "sockets", endptr) != 0)
1087 sockets = strtoull(option, NULL, 10);
1088 if (get_param_value(option, 128, "cores", endptr) != 0)
1089 cores = strtoull(option, NULL, 10);
1090 if (get_param_value(option, 128, "threads", endptr) != 0)
1091 threads = strtoull(option, NULL, 10);
1092 if (get_param_value(option, 128, "maxcpus", endptr) != 0)
1093 max_cpus = strtoull(option, NULL, 10);
1095 /* compute missing values, prefer sockets over cores over threads */
1096 if (smp == 0 || sockets == 0) {
1097 sockets = sockets > 0 ? sockets : 1;
1098 cores = cores > 0 ? cores : 1;
1099 threads = threads > 0 ? threads : 1;
1101 smp = cores * threads * sockets;
1105 threads = threads > 0 ? threads : 1;
1106 cores = smp / (sockets * threads);
1108 threads = smp / (cores * sockets);
1112 smp_cores = cores > 0 ? cores : 1;
1113 smp_threads = threads > 0 ? threads : 1;
1115 max_cpus = smp_cpus;
1118 /***********************************************************/
1121 static int usb_device_add(const char *devname)
1124 USBDevice *dev = NULL;
1129 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1130 dev = usbdevice_create(devname);
1134 /* the other ones */
1135 #ifndef CONFIG_LINUX
1136 /* only the linux version is qdev-ified, usb-bsd still needs this */
1137 if (strstart(devname, "host:", &p)) {
1138 dev = usb_host_device_open(usb_bus_find(-1), p);
1141 if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
1142 dev = usb_bt_init(usb_bus_find(-1),
1143 devname[2] ? hci_init(p)
1144 : bt_new_hci(qemu_find_bt_vlan(0)));
1155 static int usb_device_del(const char *devname)
1160 if (strstart(devname, "host:", &p))
1161 return usb_host_device_close(p);
1166 p = strchr(devname, '.');
1169 bus_num = strtoul(devname, NULL, 0);
1170 addr = strtoul(p + 1, NULL, 0);
1172 return usb_device_delete_addr(bus_num, addr);
1175 static int usb_parse(const char *cmdline)
1178 r = usb_device_add(cmdline);
1180 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
1185 void do_usb_add(Monitor *mon, const QDict *qdict)
1187 const char *devname = qdict_get_str(qdict, "devname");
1188 if (usb_device_add(devname) < 0) {
1189 error_report("could not add USB device '%s'", devname);
1193 void do_usb_del(Monitor *mon, const QDict *qdict)
1195 const char *devname = qdict_get_str(qdict, "devname");
1196 if (usb_device_del(devname) < 0) {
1197 error_report("could not delete USB device '%s'", devname);
1201 /***********************************************************/
1202 /* PCMCIA/Cardbus */
1204 static struct pcmcia_socket_entry_s {
1205 PCMCIASocket *socket;
1206 struct pcmcia_socket_entry_s *next;
1207 } *pcmcia_sockets = 0;
1209 void pcmcia_socket_register(PCMCIASocket *socket)
1211 struct pcmcia_socket_entry_s *entry;
1213 entry = g_malloc(sizeof(struct pcmcia_socket_entry_s));
1214 entry->socket = socket;
1215 entry->next = pcmcia_sockets;
1216 pcmcia_sockets = entry;
1219 void pcmcia_socket_unregister(PCMCIASocket *socket)
1221 struct pcmcia_socket_entry_s *entry, **ptr;
1223 ptr = &pcmcia_sockets;
1224 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1225 if (entry->socket == socket) {
1231 void pcmcia_info(Monitor *mon)
1233 struct pcmcia_socket_entry_s *iter;
1235 if (!pcmcia_sockets)
1236 monitor_printf(mon, "No PCMCIA sockets\n");
1238 for (iter = pcmcia_sockets; iter; iter = iter->next)
1239 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1240 iter->socket->attached ? iter->socket->card_string :
1244 /***********************************************************/
1245 /* machine registration */
1247 static QEMUMachine *first_machine = NULL;
1248 QEMUMachine *current_machine = NULL;
1250 int qemu_register_machine(QEMUMachine *m)
1253 pm = &first_machine;
1261 static QEMUMachine *find_machine(const char *name)
1265 for(m = first_machine; m != NULL; m = m->next) {
1266 if (!strcmp(m->name, name))
1268 if (m->alias && !strcmp(m->alias, name))
1274 QEMUMachine *find_default_machine(void)
1278 for(m = first_machine; m != NULL; m = m->next) {
1279 if (m->is_default) {
1286 MachineInfoList *qmp_query_machines(Error **errp)
1288 MachineInfoList *mach_list = NULL;
1291 for (m = first_machine; m; m = m->next) {
1292 MachineInfoList *entry;
1295 info = g_malloc0(sizeof(*info));
1296 if (m->is_default) {
1297 info->has_is_default = true;
1298 info->is_default = true;
1302 info->has_alias = true;
1303 info->alias = g_strdup(m->alias);
1306 info->name = g_strdup(m->name);
1308 entry = g_malloc0(sizeof(*entry));
1309 entry->value = info;
1310 entry->next = mach_list;
1317 /***********************************************************/
1318 /* main execution loop */
1320 static void gui_update(void *opaque)
1322 uint64_t interval = GUI_REFRESH_INTERVAL;
1323 DisplayState *ds = opaque;
1324 DisplayChangeListener *dcl = ds->listeners;
1328 while (dcl != NULL) {
1329 if (dcl->gui_timer_interval &&
1330 dcl->gui_timer_interval < interval)
1331 interval = dcl->gui_timer_interval;
1334 qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock));
1337 struct vm_change_state_entry {
1338 VMChangeStateHandler *cb;
1340 QLIST_ENTRY (vm_change_state_entry) entries;
1343 static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
1345 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1348 VMChangeStateEntry *e;
1350 e = g_malloc0(sizeof (*e));
1354 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
1358 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1360 QLIST_REMOVE (e, entries);
1364 void vm_state_notify(int running, RunState state)
1366 VMChangeStateEntry *e;
1368 trace_vm_state_notify(running, state);
1370 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
1371 e->cb(e->opaque, running, state);
1377 if (!runstate_is_running()) {
1379 runstate_set(RUN_STATE_RUNNING);
1380 vm_state_notify(1, RUN_STATE_RUNNING);
1382 monitor_protocol_event(QEVENT_RESUME, NULL);
1386 /* reset/shutdown handler */
1388 typedef struct QEMUResetEntry {
1389 QTAILQ_ENTRY(QEMUResetEntry) entry;
1390 QEMUResetHandler *func;
1394 static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1395 QTAILQ_HEAD_INITIALIZER(reset_handlers);
1396 static int reset_requested;
1397 static int shutdown_requested, shutdown_signal = -1;
1398 static pid_t shutdown_pid;
1399 static int powerdown_requested;
1400 static int debug_requested;
1401 static int suspend_requested;
1402 static int wakeup_requested;
1403 static NotifierList suspend_notifiers =
1404 NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
1405 static NotifierList wakeup_notifiers =
1406 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
1407 static uint32_t wakeup_reason_mask = ~0;
1408 static RunState vmstop_requested = RUN_STATE_MAX;
1410 int qemu_shutdown_requested_get(void)
1412 return shutdown_requested;
1415 int qemu_reset_requested_get(void)
1417 return reset_requested;
1420 int qemu_shutdown_requested(void)
1422 int r = shutdown_requested;
1423 shutdown_requested = 0;
1427 void qemu_kill_report(void)
1429 if (!qtest_enabled() && shutdown_signal != -1) {
1430 fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal);
1431 if (shutdown_pid == 0) {
1432 /* This happens for eg ^C at the terminal, so it's worth
1433 * avoiding printing an odd message in that case.
1435 fputc('\n', stderr);
1437 fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid);
1439 shutdown_signal = -1;
1443 int qemu_reset_requested(void)
1445 int r = reset_requested;
1446 reset_requested = 0;
1450 static int qemu_suspend_requested(void)
1452 int r = suspend_requested;
1453 suspend_requested = 0;
1457 static int qemu_wakeup_requested(void)
1459 int r = wakeup_requested;
1460 wakeup_requested = 0;
1464 int qemu_powerdown_requested(void)
1466 int r = powerdown_requested;
1467 powerdown_requested = 0;
1471 static int qemu_debug_requested(void)
1473 int r = debug_requested;
1474 debug_requested = 0;
1478 /* We use RUN_STATE_MAX but any invalid value will do */
1479 static bool qemu_vmstop_requested(RunState *r)
1481 if (vmstop_requested < RUN_STATE_MAX) {
1482 *r = vmstop_requested;
1483 vmstop_requested = RUN_STATE_MAX;
1490 void qemu_register_reset(QEMUResetHandler *func, void *opaque)
1492 QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
1495 re->opaque = opaque;
1496 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
1499 void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
1503 QTAILQ_FOREACH(re, &reset_handlers, entry) {
1504 if (re->func == func && re->opaque == opaque) {
1505 QTAILQ_REMOVE(&reset_handlers, re, entry);
1512 void qemu_devices_reset(void)
1514 QEMUResetEntry *re, *nre;
1516 /* reset all devices */
1517 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
1518 re->func(re->opaque);
1522 void qemu_system_reset(bool report)
1524 if (current_machine && current_machine->reset) {
1525 current_machine->reset();
1527 qemu_devices_reset();
1530 monitor_protocol_event(QEVENT_RESET, NULL);
1532 cpu_synchronize_all_post_reset();
1535 void qemu_system_reset_request(void)
1538 shutdown_requested = 1;
1540 reset_requested = 1;
1543 qemu_notify_event();
1546 static void qemu_system_suspend(void)
1549 notifier_list_notify(&suspend_notifiers, NULL);
1550 runstate_set(RUN_STATE_SUSPENDED);
1551 monitor_protocol_event(QEVENT_SUSPEND, NULL);
1554 void qemu_system_suspend_request(void)
1556 if (runstate_check(RUN_STATE_SUSPENDED)) {
1559 suspend_requested = 1;
1561 qemu_notify_event();
1564 void qemu_register_suspend_notifier(Notifier *notifier)
1566 notifier_list_add(&suspend_notifiers, notifier);
1569 void qemu_system_wakeup_request(WakeupReason reason)
1571 if (!runstate_check(RUN_STATE_SUSPENDED)) {
1574 if (!(wakeup_reason_mask & (1 << reason))) {
1577 runstate_set(RUN_STATE_RUNNING);
1578 notifier_list_notify(&wakeup_notifiers, &reason);
1579 wakeup_requested = 1;
1580 qemu_notify_event();
1583 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
1586 wakeup_reason_mask |= (1 << reason);
1588 wakeup_reason_mask &= ~(1 << reason);
1592 void qemu_register_wakeup_notifier(Notifier *notifier)
1594 notifier_list_add(&wakeup_notifiers, notifier);
1597 void qemu_system_killed(int signal, pid_t pid)
1599 shutdown_signal = signal;
1604 shutdown_qemu_gracefully();
1606 qemu_system_shutdown_request();
1610 void qemu_system_shutdown_request(void)
1612 shutdown_requested = 1;
1613 qemu_notify_event();
1616 void qemu_system_powerdown_request(void)
1618 powerdown_requested = 1;
1619 qemu_notify_event();
1622 void qemu_system_debug_request(void)
1624 debug_requested = 1;
1625 qemu_notify_event();
1628 void qemu_system_vmstop_request(RunState state)
1630 vmstop_requested = state;
1631 qemu_notify_event();
1634 qemu_irq qemu_system_powerdown;
1636 static bool main_loop_should_exit(void)
1639 if (qemu_debug_requested()) {
1640 vm_stop(RUN_STATE_DEBUG);
1642 if (qemu_suspend_requested()) {
1643 qemu_system_suspend();
1645 if (qemu_shutdown_requested()) {
1647 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
1649 vm_stop(RUN_STATE_SHUTDOWN);
1654 if (qemu_reset_requested()) {
1656 cpu_synchronize_all_states();
1657 qemu_system_reset(VMRESET_REPORT);
1659 if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
1660 runstate_check(RUN_STATE_SHUTDOWN)) {
1661 runstate_set(RUN_STATE_PAUSED);
1664 if (qemu_wakeup_requested()) {
1666 cpu_synchronize_all_states();
1667 qemu_system_reset(VMRESET_SILENT);
1669 monitor_protocol_event(QEVENT_WAKEUP, NULL);
1671 if (qemu_powerdown_requested()) {
1672 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
1673 qemu_irq_raise(qemu_system_powerdown);
1675 if (qemu_vmstop_requested(&r)) {
1681 static void main_loop(void)
1685 #ifdef CONFIG_PROFILER
1692 nonblocking = !(kvm_enabled()|| hax_enabled()) && last_io > 0;
1693 #ifdef CONFIG_PROFILER
1694 ti = profile_getclock();
1696 last_io = main_loop_wait(nonblocking);
1697 #ifdef CONFIG_PROFILER
1698 dev_time += profile_getclock() - ti;
1700 } while (!main_loop_should_exit());
1703 static void version(void)
1705 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
1708 static void help(int exitcode)
1711 printf("usage: %s [options] [disk_image]\n\n"
1712 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1713 error_get_progname());
1715 #define QEMU_OPTIONS_GENERATE_HELP
1716 #include "qemu-options-wrapper.h"
1718 printf("\nDuring emulation, the following keys are useful:\n"
1719 "ctrl-alt-f toggle full screen\n"
1720 "ctrl-alt-n switch to virtual console 'n'\n"
1721 "ctrl-alt toggle mouse and keyboard grab\n"
1723 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1728 #define HAS_ARG 0x0001
1730 typedef struct QEMUOption {
1737 static const QEMUOption qemu_options[] = {
1738 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1739 #define QEMU_OPTIONS_GENERATE_OPTIONS
1740 #include "qemu-options-wrapper.h"
1744 static bool vga_available(void)
1746 return qdev_exists("VGA") || qdev_exists("isa-vga");
1749 static bool cirrus_vga_available(void)
1751 return qdev_exists("cirrus-vga") || qdev_exists("isa-cirrus-vga");
1754 static bool vmware_vga_available(void)
1756 return qdev_exists("vmware-svga");
1759 static void select_vgahw (const char *p)
1763 vga_interface_type = VGA_NONE;
1764 if (strstart(p, "std", &opts)) {
1765 if (vga_available()) {
1766 vga_interface_type = VGA_STD;
1768 fprintf(stderr, "Error: standard VGA not available\n");
1771 } else if (strstart(p, "cirrus", &opts)) {
1772 if (cirrus_vga_available()) {
1773 vga_interface_type = VGA_CIRRUS;
1775 fprintf(stderr, "Error: Cirrus VGA not available\n");
1778 } else if (strstart(p, "vmware", &opts)) {
1779 if (vmware_vga_available()) {
1780 vga_interface_type = VGA_VMWARE;
1782 fprintf(stderr, "Error: VMWare SVGA not available\n");
1785 } else if (strstart(p, "xenfb", &opts)) {
1786 vga_interface_type = VGA_XENFB;
1787 } else if (strstart(p, "qxl", &opts)) {
1788 vga_interface_type = VGA_QXL;
1790 } else if (strstart(p, "maru", &opts)) {
1791 vga_interface_type = VGA_MARU;
1793 } else if (!strstart(p, "none", &opts)) {
1795 fprintf(stderr, "Unknown vga type: %s\n", p);
1799 const char *nextopt;
1801 if (strstart(opts, ",retrace=", &nextopt)) {
1803 if (strstart(opts, "dumb", &nextopt))
1804 vga_retrace_method = VGA_RETRACE_DUMB;
1805 else if (strstart(opts, "precise", &nextopt))
1806 vga_retrace_method = VGA_RETRACE_PRECISE;
1807 else goto invalid_vga;
1808 } else goto invalid_vga;
1813 static DisplayType select_display(const char *p)
1816 DisplayType display = DT_DEFAULT;
1818 if (strstart(p, "sdl", &opts)) {
1822 const char *nextopt;
1824 if (strstart(opts, ",frame=", &nextopt)) {
1826 if (strstart(opts, "on", &nextopt)) {
1828 } else if (strstart(opts, "off", &nextopt)) {
1831 goto invalid_sdl_args;
1833 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
1835 if (strstart(opts, "on", &nextopt)) {
1837 } else if (strstart(opts, "off", &nextopt)) {
1840 goto invalid_sdl_args;
1842 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
1844 if (strstart(opts, "on", &nextopt)) {
1846 } else if (strstart(opts, "off", &nextopt)) {
1849 goto invalid_sdl_args;
1851 } else if (strstart(opts, ",window_close=", &nextopt)) {
1853 if (strstart(opts, "on", &nextopt)) {
1855 } else if (strstart(opts, "off", &nextopt)) {
1858 goto invalid_sdl_args;
1862 fprintf(stderr, "Invalid SDL option string: %s\n", p);
1868 fprintf(stderr, "SDL support is disabled\n");
1871 } else if (strstart(p, "vnc", &opts)) {
1876 const char *nextopt;
1878 if (strstart(opts, "=", &nextopt)) {
1879 vnc_display = nextopt;
1883 fprintf(stderr, "VNC requires a display argument vnc=<display>\n");
1887 fprintf(stderr, "VNC support is disabled\n");
1890 } else if (strstart(p, "curses", &opts)) {
1891 #ifdef CONFIG_CURSES
1892 display = DT_CURSES;
1894 fprintf(stderr, "Curses support is disabled\n");
1897 } else if (strstart(p, "none", &opts)) {
1900 fprintf(stderr, "Unknown display type: %s\n", p);
1907 static int balloon_parse(const char *arg)
1911 if (strcmp(arg, "none") == 0) {
1915 if (!strncmp(arg, "virtio", 6)) {
1916 if (arg[6] == ',') {
1917 /* have params -> parse them */
1918 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
1922 /* create empty opts */
1923 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, NULL);
1925 qemu_opt_set(opts, "driver", "virtio-balloon");
1932 char *qemu_find_file(int type, const char *name)
1938 /* Try the name as a straight path first */
1939 if (access(name, R_OK) == 0) {
1940 return g_strdup(name);
1943 case QEMU_FILE_TYPE_BIOS:
1946 case QEMU_FILE_TYPE_KEYMAP:
1947 subdir = "keymaps/";
1952 len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
1953 buf = g_malloc0(len);
1954 snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
1955 if (access(buf, R_OK)) {
1963 const char *qemu_get_data_dir(void);
1965 const char *qemu_get_data_dir(void)
1971 static int device_help_func(QemuOpts *opts, void *opaque)
1973 return qdev_device_help(opts);
1976 static int device_init_func(QemuOpts *opts, void *opaque)
1980 #ifdef CONFIG_GL_BACKEND
1981 #if defined(CONFIG_MARU) && (!defined(CONFIG_DARWIN))
1982 // virtio-gl pci device
1984 // ignore virtio-gl-pci device, even if users set it in option.
1985 const char *driver = qemu_opt_get(opts, "driver");
1986 if (driver && (strcmp (driver, VIRTIOGL_DEV_NAME) == 0)) {
1992 #if defined(CONFIG_MARU) && (!defined(CONFIG_DARWIN))
1993 if (!is_webcam_enabled) {
1994 const char *driver = qemu_opt_get(opts, "driver");
1995 if (driver && (strcmp (driver, MARUCAM_DEV_NAME) == 0)) {
2001 dev = qdev_device_add(opts);
2007 static int chardev_init_func(QemuOpts *opts, void *opaque)
2009 CharDriverState *chr;
2011 chr = qemu_chr_new_from_opts(opts, NULL);
2017 #ifdef CONFIG_VIRTFS
2018 static int fsdev_init_func(QemuOpts *opts, void *opaque)
2021 ret = qemu_fsdev_add(opts);
2027 static int mon_init_func(QemuOpts *opts, void *opaque)
2029 CharDriverState *chr;
2030 const char *chardev;
2034 mode = qemu_opt_get(opts, "mode");
2038 if (strcmp(mode, "readline") == 0) {
2039 flags = MONITOR_USE_READLINE;
2040 } else if (strcmp(mode, "control") == 0) {
2041 flags = MONITOR_USE_CONTROL;
2043 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
2047 if (qemu_opt_get_bool(opts, "pretty", 0))
2048 flags |= MONITOR_USE_PRETTY;
2050 if (qemu_opt_get_bool(opts, "default", 0))
2051 flags |= MONITOR_IS_DEFAULT;
2053 chardev = qemu_opt_get(opts, "chardev");
2054 chr = qemu_chr_find(chardev);
2056 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
2060 monitor_init(chr, flags);
2064 static void monitor_parse(const char *optarg, const char *mode)
2066 static int monitor_device_index = 0;
2072 if (strstart(optarg, "chardev:", &p)) {
2073 snprintf(label, sizeof(label), "%s", p);
2075 snprintf(label, sizeof(label), "compat_monitor%d",
2076 monitor_device_index);
2077 if (monitor_device_index == 0) {
2080 opts = qemu_chr_parse_compat(label, optarg);
2082 fprintf(stderr, "parse error: %s\n", optarg);
2087 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, NULL);
2089 fprintf(stderr, "duplicate chardev: %s\n", label);
2092 qemu_opt_set(opts, "mode", mode);
2093 qemu_opt_set(opts, "chardev", label);
2095 qemu_opt_set(opts, "default", "on");
2096 monitor_device_index++;
2099 struct device_config {
2101 DEV_USB, /* -usbdevice */
2103 DEV_SERIAL, /* -serial */
2104 DEV_PARALLEL, /* -parallel */
2105 DEV_VIRTCON, /* -virtioconsole */
2106 DEV_DEBUGCON, /* -debugcon */
2107 DEV_GDB, /* -gdb, -s */
2109 const char *cmdline;
2111 QTAILQ_ENTRY(device_config) next;
2113 QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
2115 static void add_device_config(int type, const char *cmdline)
2117 struct device_config *conf;
2119 conf = g_malloc0(sizeof(*conf));
2121 conf->cmdline = cmdline;
2122 loc_save(&conf->loc);
2123 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
2126 static int foreach_device_config(int type, int (*func)(const char *cmdline))
2128 struct device_config *conf;
2131 QTAILQ_FOREACH(conf, &device_configs, next) {
2132 if (conf->type != type)
2134 loc_push_restore(&conf->loc);
2135 rc = func(conf->cmdline);
2136 loc_pop(&conf->loc);
2143 static int serial_parse(const char *devname)
2145 static int index = 0;
2148 if (strcmp(devname, "none") == 0)
2150 if (index == MAX_SERIAL_PORTS) {
2151 fprintf(stderr, "qemu: too many serial ports\n");
2154 snprintf(label, sizeof(label), "serial%d", index);
2155 serial_hds[index] = qemu_chr_new(label, devname, NULL);
2156 if (!serial_hds[index]) {
2157 fprintf(stderr, "qemu: could not connect serial device"
2158 " to character backend '%s'\n", devname);
2165 static int parallel_parse(const char *devname)
2167 static int index = 0;
2170 if (strcmp(devname, "none") == 0)
2172 if (index == MAX_PARALLEL_PORTS) {
2173 fprintf(stderr, "qemu: too many parallel ports\n");
2176 snprintf(label, sizeof(label), "parallel%d", index);
2177 parallel_hds[index] = qemu_chr_new(label, devname, NULL);
2178 if (!parallel_hds[index]) {
2179 fprintf(stderr, "qemu: could not connect parallel device"
2180 " to character backend '%s'\n", devname);
2187 static int virtcon_parse(const char *devname)
2189 QemuOptsList *device = qemu_find_opts("device");
2190 static int index = 0;
2192 QemuOpts *bus_opts, *dev_opts;
2194 if (strcmp(devname, "none") == 0)
2196 if (index == MAX_VIRTIO_CONSOLES) {
2197 fprintf(stderr, "qemu: too many virtio consoles\n");
2201 bus_opts = qemu_opts_create(device, NULL, 0, NULL);
2202 if (arch_type == QEMU_ARCH_S390X) {
2203 qemu_opt_set(bus_opts, "driver", "virtio-serial-s390");
2205 qemu_opt_set(bus_opts, "driver", "virtio-serial-pci");
2208 dev_opts = qemu_opts_create(device, NULL, 0, NULL);
2209 qemu_opt_set(dev_opts, "driver", "virtconsole");
2211 snprintf(label, sizeof(label), "virtcon%d", index);
2212 virtcon_hds[index] = qemu_chr_new(label, devname, NULL);
2213 if (!virtcon_hds[index]) {
2214 fprintf(stderr, "qemu: could not connect virtio console"
2215 " to character backend '%s'\n", devname);
2218 qemu_opt_set(dev_opts, "chardev", label);
2224 static int debugcon_parse(const char *devname)
2228 if (!qemu_chr_new("debugcon", devname, NULL)) {
2231 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL);
2233 fprintf(stderr, "qemu: already have a debugcon device\n");
2236 qemu_opt_set(opts, "driver", "isa-debugcon");
2237 qemu_opt_set(opts, "chardev", "debugcon");
2241 static QEMUMachine *machine_parse(const char *name)
2243 QEMUMachine *m, *machine = NULL;
2246 machine = find_machine(name);
2251 printf("Supported machines are:\n");
2252 for (m = first_machine; m != NULL; m = m->next) {
2254 printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name);
2256 printf("%-20s %s%s\n", m->name, m->desc,
2257 m->is_default ? " (default)" : "");
2259 exit(!name || !is_help_option(name));
2262 static int tcg_init(void)
2265 tcg_exec_init(tcg_tb_size * 1024 * 1024);
2266 ret = hax_accel_init();
2271 const char *opt_name;
2273 int (*available)(void);
2277 { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
2278 { "xen", "Xen", xen_available, xen_init, &xen_allowed },
2279 { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
2280 { "qtest", "QTest", qtest_available, qtest_init, &qtest_allowed },
2283 static int configure_accelerator(void)
2285 const char *p = NULL;
2288 bool accel_initialised = 0;
2289 bool init_failed = 0;
2291 QemuOptsList *list = qemu_find_opts("machine");
2292 if (!QTAILQ_EMPTY(&list->head)) {
2293 p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel");
2297 /* Use the default "accelerator", tcg */
2301 while (!accel_initialised && *p != '\0') {
2305 p = get_opt_name(buf, sizeof (buf), p, ':');
2306 for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
2307 if (strcmp(accel_list[i].opt_name, buf) == 0) {
2308 *(accel_list[i].allowed) = 1;
2309 ret = accel_list[i].init();
2312 if (!accel_list[i].available()) {
2313 printf("%s not supported for this target\n",
2314 accel_list[i].name);
2316 fprintf(stderr, "failed to initialize %s: %s\n",
2320 *(accel_list[i].allowed) = 0;
2322 accel_initialised = 1;
2327 if (i == ARRAY_SIZE(accel_list)) {
2328 fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
2332 if (!accel_initialised) {
2333 fprintf(stderr, "No accelerator found!\n");
2335 maru_register_exit_msg(MARU_EXIT_UNKNOWN, "No accelerator found.");
2341 fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
2344 return !accel_initialised;
2347 void qemu_add_exit_notifier(Notifier *notify)
2349 notifier_list_add(&exit_notifiers, notify);
2352 void qemu_remove_exit_notifier(Notifier *notify)
2354 notifier_remove(notify);
2357 static void qemu_run_exit_notifiers(void)
2359 notifier_list_notify(&exit_notifiers, NULL);
2362 void qemu_add_machine_init_done_notifier(Notifier *notify)
2364 notifier_list_add(&machine_init_done_notifiers, notify);
2367 static void qemu_run_machine_init_done_notifiers(void)
2369 notifier_list_notify(&machine_init_done_notifiers, NULL);
2372 static const QEMUOption *lookup_opt(int argc, char **argv,
2373 const char **poptarg, int *poptind)
2375 const QEMUOption *popt;
2376 int optind = *poptind;
2377 char *r = argv[optind];
2380 loc_set_cmdline(argv, optind, 1);
2382 /* Treat --foo the same as -foo. */
2385 popt = qemu_options;
2388 error_report("invalid option");
2390 maru_register_exit_msg(MARU_EXIT_UNKNOWN, "invalid option.");
2394 if (!strcmp(popt->name, r + 1))
2398 if (popt->flags & HAS_ARG) {
2399 if (optind >= argc) {
2400 error_report("requires an argument");
2402 maru_register_exit_msg(MARU_EXIT_UNKNOWN, "requires an argument.");
2406 optarg = argv[optind++];
2407 loc_set_cmdline(argv, optind - 2, 2);
2418 static gpointer malloc_and_trace(gsize n_bytes)
2420 void *ptr = malloc(n_bytes);
2421 trace_g_malloc(n_bytes, ptr);
2425 static gpointer realloc_and_trace(gpointer mem, gsize n_bytes)
2427 void *ptr = realloc(mem, n_bytes);
2428 trace_g_realloc(mem, n_bytes, ptr);
2432 static void free_and_trace(gpointer mem)
2438 // virtio-gl pci device lookup
2440 const char *device_name;
2442 } device_opt_finding_t;
2444 static int find_device_opt (QemuOpts *opts, void *opaque)
2446 device_opt_finding_t *devp = (device_opt_finding_t *) opaque;
2447 if (devp->found == 1) {
2451 const char *str = qemu_opt_get (opts, "driver");
2452 if (strcmp (str, devp->device_name) == 0) {
2458 int use_qemu_display = 0; //0:use tizen qemu sdl, 1:use original qemu sdl
2460 int qemu_init_main_loop(void)
2462 return main_loop_init();
2466 // W/A for preserve larger continuous heap for RAM.
2467 void *preallocated_ptr = 0;
2470 int main(int argc, char **argv, char **envp)
2473 int snapshot, linux_boot;
2474 const char *icount_option = NULL;
2475 const char *initrd_filename;
2476 const char *kernel_filename, *kernel_cmdline;
2477 char* tmp_cmdline = NULL;
2478 char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
2480 DisplayChangeListener *dcl;
2481 int cyls, heads, secs, translation;
2482 QemuOpts *hda_opts = NULL, *opts, *machine_opts;
2483 QemuOptsList *olist;
2486 const char *loadvm = NULL;
2487 QEMUMachine *machine;
2488 const char *cpu_model;
2489 const char *vga_model = "none";
2490 const char *pid_file = NULL;
2491 const char *incoming = NULL;
2493 int show_vnc_port = 0;
2495 bool defconfig = true;
2496 bool userconfig = true;
2497 const char *log_mask = NULL;
2498 const char *log_file = NULL;
2499 GMemVTable mem_trace = {
2500 .malloc = malloc_and_trace,
2501 .realloc = realloc_and_trace,
2502 .free = free_and_trace,
2504 const char *trace_events = NULL;
2505 const char *trace_file = NULL;
2509 char http_proxy[MIDBUF] ={0},https_proxy[MIDBUF] = {0,},
2510 ftp_proxy[MIDBUF] = {0,}, socks_proxy[MIDBUF] = {0,},
2511 dns1[MIDBUF] = {0}, dns2[MIDBUF] = {0};
2514 atexit(qemu_run_exit_notifiers);
2515 error_set_progname(argv[0]);
2517 g_mem_set_vtable(&mem_trace);
2518 if (!g_thread_supported()) {
2519 #if !GLIB_CHECK_VERSION(2, 31, 0)
2520 g_thread_init(NULL);
2522 fprintf(stderr, "glib threading failed to initialize.\n");
2527 module_call_init(MODULE_INIT_QOM);
2532 rtc_clock = host_clock;
2534 qemu_cache_utils_init(envp);
2536 QLIST_INIT (&vm_change_state_head);
2537 os_setup_early_signal_handling();
2539 module_call_init(MODULE_INIT_MACHINE);
2540 machine = find_default_machine();
2544 cyls = heads = secs = 0;
2545 translation = BIOS_ATA_TRANSLATION_AUTO;
2547 for (i = 0; i < MAX_NODES; i++) {
2549 node_cpumask[i] = bitmap_new(MAX_CPUMASK_BITS);
2557 /* first pass of option parsing */
2559 while (optind < argc) {
2560 if (argv[optind][0] != '-') {
2565 const QEMUOption *popt;
2567 popt = lookup_opt(argc, argv, &optarg, &optind);
2568 switch (popt->index) {
2569 case QEMU_OPTION_nodefconfig:
2572 case QEMU_OPTION_nouserconfig:
2581 ret = qemu_read_default_config_files(userconfig);
2587 /* second pass of option parsing */
2592 if (argv[optind][0] != '-') {
2593 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
2595 const QEMUOption *popt;
2597 popt = lookup_opt(argc, argv, &optarg, &optind);
2598 if (!(popt->arch_mask & arch_type)) {
2599 printf("Option %s not supported for this target\n", popt->name);
2602 switch(popt->index) {
2604 machine = machine_parse(optarg);
2606 case QEMU_OPTION_cpu:
2607 /* hw initialization will check this */
2610 case QEMU_OPTION_hda:
2614 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2616 snprintf(buf, sizeof(buf),
2617 "%s,cyls=%d,heads=%d,secs=%d%s",
2618 HD_OPTS , cyls, heads, secs,
2619 translation == BIOS_ATA_TRANSLATION_LBA ?
2621 translation == BIOS_ATA_TRANSLATION_NONE ?
2622 ",trans=none" : "");
2623 drive_add(IF_DEFAULT, 0, optarg, buf);
2626 case QEMU_OPTION_hdb:
2627 case QEMU_OPTION_hdc:
2628 case QEMU_OPTION_hdd:
2629 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2632 case QEMU_OPTION_drive:
2633 if (drive_def(optarg) == NULL) {
2637 case QEMU_OPTION_set:
2638 if (qemu_set_option(optarg) != 0)
2641 case QEMU_OPTION_global:
2642 if (qemu_global_option(optarg) != 0)
2645 case QEMU_OPTION_mtdblock:
2646 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
2648 case QEMU_OPTION_sd:
2649 drive_add(IF_SD, 0, optarg, SD_OPTS);
2651 case QEMU_OPTION_pflash:
2652 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
2654 case QEMU_OPTION_snapshot:
2657 case QEMU_OPTION_hdachs:
2661 cyls = strtol(p, (char **)&p, 0);
2662 if (cyls < 1 || cyls > 16383)
2667 heads = strtol(p, (char **)&p, 0);
2668 if (heads < 1 || heads > 16)
2673 secs = strtol(p, (char **)&p, 0);
2674 if (secs < 1 || secs > 63)
2678 if (!strcmp(p, "none"))
2679 translation = BIOS_ATA_TRANSLATION_NONE;
2680 else if (!strcmp(p, "lba"))
2681 translation = BIOS_ATA_TRANSLATION_LBA;
2682 else if (!strcmp(p, "auto"))
2683 translation = BIOS_ATA_TRANSLATION_AUTO;
2686 } else if (*p != '\0') {
2688 fprintf(stderr, "qemu: invalid physical CHS format\n");
2691 if (hda_opts != NULL) {
2693 snprintf(num, sizeof(num), "%d", cyls);
2694 qemu_opt_set(hda_opts, "cyls", num);
2695 snprintf(num, sizeof(num), "%d", heads);
2696 qemu_opt_set(hda_opts, "heads", num);
2697 snprintf(num, sizeof(num), "%d", secs);
2698 qemu_opt_set(hda_opts, "secs", num);
2699 if (translation == BIOS_ATA_TRANSLATION_LBA)
2700 qemu_opt_set(hda_opts, "trans", "lba");
2701 if (translation == BIOS_ATA_TRANSLATION_NONE)
2702 qemu_opt_set(hda_opts, "trans", "none");
2706 case QEMU_OPTION_numa:
2707 if (nb_numa_nodes >= MAX_NODES) {
2708 fprintf(stderr, "qemu: too many NUMA nodes\n");
2713 case QEMU_OPTION_display:
2714 display_type = select_display(optarg);
2716 case QEMU_OPTION_nographic:
2717 display_type = DT_NOGRAPHIC;
2719 case QEMU_OPTION_curses:
2720 #ifdef CONFIG_CURSES
2721 display_type = DT_CURSES;
2723 fprintf(stderr, "Curses support is disabled\n");
2727 case QEMU_OPTION_portrait:
2728 graphic_rotate = 90;
2730 case QEMU_OPTION_rotate:
2731 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
2732 if (graphic_rotate != 0 && graphic_rotate != 90 &&
2733 graphic_rotate != 180 && graphic_rotate != 270) {
2735 "qemu: only 90, 180, 270 deg rotation is available\n");
2739 case QEMU_OPTION_kernel:
2740 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg);
2742 case QEMU_OPTION_initrd:
2743 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg);
2745 case QEMU_OPTION_append:
2747 gethostproxy(http_proxy, https_proxy, ftp_proxy, socks_proxy);
2748 gethostDNS(dns1, dns2);
2749 tmp_cmdline = g_strdup_printf("%s sdb_port=%d,"
2750 " http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s"
2751 " dns1=%s dns2=%s", optarg, tizen_base_port,
2752 http_proxy, https_proxy, ftp_proxy, socks_proxy,
2754 qemu_opts_set(qemu_find_opts("machine"), 0, "append",
2756 fprintf(stdout, "kernel command : %s\n", tmp_cmdline);
2758 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg);
2761 case QEMU_OPTION_dtb:
2762 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg);
2764 case QEMU_OPTION_cdrom:
2765 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
2767 case QEMU_OPTION_boot:
2769 static const char * const params[] = {
2770 "order", "once", "menu",
2771 "splash", "splash-time", NULL
2773 char buf[sizeof(boot_devices)];
2774 char *standard_boot_devices;
2777 if (!strchr(optarg, '=')) {
2779 pstrcpy(buf, sizeof(buf), optarg);
2780 } else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
2782 "qemu: unknown boot parameter '%s' in '%s'\n",
2788 get_param_value(buf, sizeof(buf), "order", optarg)) {
2789 validate_bootdevices(buf);
2790 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2793 if (get_param_value(buf, sizeof(buf),
2795 validate_bootdevices(buf);
2796 standard_boot_devices = g_strdup(boot_devices);
2797 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2798 qemu_register_reset(restore_boot_devices,
2799 standard_boot_devices);
2801 if (get_param_value(buf, sizeof(buf),
2803 if (!strcmp(buf, "on")) {
2805 } else if (!strcmp(buf, "off")) {
2809 "qemu: invalid option value '%s'\n",
2814 qemu_opts_parse(qemu_find_opts("boot-opts"),
2819 case QEMU_OPTION_fda:
2820 case QEMU_OPTION_fdb:
2821 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2824 case QEMU_OPTION_no_fd_bootchk:
2827 case QEMU_OPTION_netdev:
2828 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
2832 case QEMU_OPTION_net:
2833 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
2837 #ifdef CONFIG_LIBISCSI
2838 case QEMU_OPTION_iscsi:
2839 opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0);
2846 case QEMU_OPTION_tftp:
2847 legacy_tftp_prefix = optarg;
2849 case QEMU_OPTION_bootp:
2850 legacy_bootp_filename = optarg;
2852 case QEMU_OPTION_redir:
2853 if (net_slirp_redir(optarg) < 0)
2857 case QEMU_OPTION_bt:
2858 add_device_config(DEV_BT, optarg);
2860 case QEMU_OPTION_audio_help:
2861 if (!(audio_available())) {
2862 printf("Option %s not supported for this target\n", popt->name);
2868 case QEMU_OPTION_soundhw:
2869 if (!(audio_available())) {
2870 printf("Option %s not supported for this target\n", popt->name);
2873 select_soundhw (optarg);
2878 case QEMU_OPTION_version:
2882 case QEMU_OPTION_m: {
2887 value = strtosz(optarg, &end);
2888 if (value < 0 || *end) {
2889 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
2892 sz = QEMU_ALIGN_UP((uint64_t)value, 8192);
2894 if (ram_size != sz) {
2895 fprintf(stderr, "qemu: ram size too large\n");
2900 case QEMU_OPTION_mempath:
2904 case QEMU_OPTION_mem_prealloc:
2915 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
2917 case QEMU_OPTION_gdb:
2918 add_device_config(DEV_GDB, optarg);
2923 case QEMU_OPTION_bios:
2926 case QEMU_OPTION_singlestep:
2933 keyboard_layout = optarg;
2935 case QEMU_OPTION_localtime:
2938 case QEMU_OPTION_vga:
2947 w = strtol(p, (char **)&p, 10);
2950 fprintf(stderr, "qemu: invalid resolution or depth\n");
2956 h = strtol(p, (char **)&p, 10);
2961 depth = strtol(p, (char **)&p, 10);
2962 if (depth != 8 && depth != 15 && depth != 16 &&
2963 depth != 24 && depth != 32)
2965 } else if (*p == '\0') {
2966 depth = graphic_depth;
2973 graphic_depth = depth;
2976 case QEMU_OPTION_echr:
2979 term_escape_char = strtol(optarg, &r, 0);
2981 printf("Bad argument to echr\n");
2984 case QEMU_OPTION_monitor:
2985 monitor_parse(optarg, "readline");
2986 default_monitor = 0;
2988 case QEMU_OPTION_qmp:
2989 monitor_parse(optarg, "control");
2990 default_monitor = 0;
2992 case QEMU_OPTION_mon:
2993 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
2997 default_monitor = 0;
2999 case QEMU_OPTION_chardev:
3000 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
3005 case QEMU_OPTION_fsdev:
3006 olist = qemu_find_opts("fsdev");
3008 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
3011 opts = qemu_opts_parse(olist, optarg, 1);
3013 fprintf(stderr, "parse error: %s\n", optarg);
3017 case QEMU_OPTION_virtfs: {
3020 const char *writeout, *sock_fd, *socket;
3022 olist = qemu_find_opts("virtfs");
3024 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
3027 opts = qemu_opts_parse(olist, optarg, 1);
3029 fprintf(stderr, "parse error: %s\n", optarg);
3033 if (qemu_opt_get(opts, "fsdriver") == NULL ||
3034 qemu_opt_get(opts, "mount_tag") == NULL) {
3035 fprintf(stderr, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
3038 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
3039 qemu_opt_get(opts, "mount_tag"),
3042 fprintf(stderr, "duplicate fsdev id: %s\n",
3043 qemu_opt_get(opts, "mount_tag"));
3047 writeout = qemu_opt_get(opts, "writeout");
3049 #ifdef CONFIG_SYNC_FILE_RANGE
3050 qemu_opt_set(fsdev, "writeout", writeout);
3052 fprintf(stderr, "writeout=immediate not supported on "
3057 qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver"));
3058 qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"));
3059 qemu_opt_set(fsdev, "security_model",
3060 qemu_opt_get(opts, "security_model"));
3061 socket = qemu_opt_get(opts, "socket");
3063 qemu_opt_set(fsdev, "socket", socket);
3065 sock_fd = qemu_opt_get(opts, "sock_fd");
3067 qemu_opt_set(fsdev, "sock_fd", sock_fd);
3070 qemu_opt_set_bool(fsdev, "readonly",
3071 qemu_opt_get_bool(opts, "readonly", 0));
3072 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3074 qemu_opt_set(device, "driver", "virtio-9p-pci");
3075 qemu_opt_set(device, "fsdev",
3076 qemu_opt_get(opts, "mount_tag"));
3077 qemu_opt_set(device, "mount_tag",
3078 qemu_opt_get(opts, "mount_tag"));
3081 case QEMU_OPTION_virtfs_synth: {
3085 fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3088 fprintf(stderr, "duplicate option: %s\n", "virtfs_synth");
3091 qemu_opt_set(fsdev, "fsdriver", "synth");
3093 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3095 qemu_opt_set(device, "driver", "virtio-9p-pci");
3096 qemu_opt_set(device, "fsdev", "v_synth");
3097 qemu_opt_set(device, "mount_tag", "v_synth");
3100 case QEMU_OPTION_serial:
3101 add_device_config(DEV_SERIAL, optarg);
3103 if (strncmp(optarg, "mon:", 4) == 0) {
3104 default_monitor = 0;
3107 case QEMU_OPTION_watchdog:
3110 "qemu: only one watchdog option may be given\n");
3115 case QEMU_OPTION_watchdog_action:
3116 if (select_watchdog_action(optarg) == -1) {
3117 fprintf(stderr, "Unknown -watchdog-action parameter\n");
3121 case QEMU_OPTION_virtiocon:
3122 add_device_config(DEV_VIRTCON, optarg);
3123 default_virtcon = 0;
3124 if (strncmp(optarg, "mon:", 4) == 0) {
3125 default_monitor = 0;
3128 case QEMU_OPTION_parallel:
3129 add_device_config(DEV_PARALLEL, optarg);
3130 default_parallel = 0;
3131 if (strncmp(optarg, "mon:", 4) == 0) {
3132 default_monitor = 0;
3135 case QEMU_OPTION_debugcon:
3136 add_device_config(DEV_DEBUGCON, optarg);
3138 case QEMU_OPTION_loadvm:
3141 case QEMU_OPTION_full_screen:
3145 case QEMU_OPTION_no_frame:
3148 case QEMU_OPTION_alt_grab:
3151 case QEMU_OPTION_ctrl_grab:
3154 case QEMU_OPTION_no_quit:
3157 case QEMU_OPTION_sdl:
3158 display_type = DT_SDL;
3161 case QEMU_OPTION_no_frame:
3162 case QEMU_OPTION_alt_grab:
3163 case QEMU_OPTION_ctrl_grab:
3164 case QEMU_OPTION_no_quit:
3165 case QEMU_OPTION_sdl:
3166 fprintf(stderr, "SDL support is disabled\n");
3169 case QEMU_OPTION_pidfile:
3172 case QEMU_OPTION_win2k_hack:
3173 win2k_install_hack = 1;
3175 case QEMU_OPTION_rtc_td_hack: {
3176 static GlobalProperty slew_lost_ticks[] = {
3178 .driver = "mc146818rtc",
3179 .property = "lost_tick_policy",
3182 { /* end of list */ }
3185 qdev_prop_register_global_list(slew_lost_ticks);
3188 case QEMU_OPTION_acpitable:
3189 do_acpitable_option(optarg);
3191 case QEMU_OPTION_smbios:
3192 do_smbios_option(optarg);
3194 #ifdef CONFIG_OPENGLES
3195 case QEMU_OPTION_gles2_quality:
3196 gles2_quality = strtoul(optarg, NULL, 10);
3199 case QEMU_OPTION_enable_kvm:
3200 olist = qemu_find_opts("machine");
3201 qemu_opts_parse(olist, "accel=kvm", 0);
3203 case QEMU_OPTION_enable_gl:
3204 #ifdef CONFIG_GL_BACKEND
3205 #if defined(CONFIG_MARU) && (!defined(CONFIG_DARWIN))
3209 fprintf(stderr, "Virtio GL support is disabled, ignoring -enable-gl\n");
3212 case QEMU_OPTION_machine:
3213 olist = qemu_find_opts("machine");
3214 opts = qemu_opts_parse(olist, optarg, 1);
3216 fprintf(stderr, "parse error: %s\n", optarg);
3219 optarg = qemu_opt_get(opts, "type");
3221 machine = machine_parse(optarg);
3224 case QEMU_OPTION_usb:
3227 case QEMU_OPTION_usbdevice:
3229 add_device_config(DEV_USB, optarg);
3231 case QEMU_OPTION_device:
3232 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
3236 case QEMU_OPTION_smp:
3239 fprintf(stderr, "Invalid number of CPUs\n");
3242 if (max_cpus < smp_cpus) {
3243 fprintf(stderr, "maxcpus must be equal to or greater than "
3247 if (max_cpus > 255) {
3248 fprintf(stderr, "Unsupported number of maxcpus\n");
3252 case QEMU_OPTION_vnc:
3255 vnc_display = optarg;
3257 fprintf(stderr, "VNC support is disabled\n");
3261 case QEMU_OPTION_no_acpi:
3264 case QEMU_OPTION_no_hpet:
3267 case QEMU_OPTION_balloon:
3268 if (balloon_parse(optarg) < 0) {
3269 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
3273 case QEMU_OPTION_no_reboot:
3276 case QEMU_OPTION_no_shutdown:
3279 case QEMU_OPTION_show_cursor:
3282 case QEMU_OPTION_uuid:
3283 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
3284 fprintf(stderr, "Fail to parse UUID string."
3285 " Wrong format.\n");
3289 case QEMU_OPTION_option_rom:
3290 if (nb_option_roms >= MAX_OPTION_ROMS) {
3291 fprintf(stderr, "Too many option ROMs\n");
3294 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
3295 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
3296 option_rom[nb_option_roms].bootindex =
3297 qemu_opt_get_number(opts, "bootindex", -1);
3298 if (!option_rom[nb_option_roms].name) {
3299 fprintf(stderr, "Option ROM file is not specified\n");
3304 case QEMU_OPTION_semihosting:
3305 semihosting_enabled = 1;
3307 case QEMU_OPTION_name:
3308 qemu_name = g_strdup(optarg);
3310 char *p = strchr(qemu_name, ',');
3313 if (strncmp(p, "process=", 8)) {
3314 fprintf(stderr, "Unknown subargument %s to -name\n", p);
3318 os_set_proc_name(p);
3322 case QEMU_OPTION_prom_env:
3323 if (nb_prom_envs >= MAX_PROM_ENVS) {
3324 fprintf(stderr, "Too many prom variables\n");
3327 prom_envs[nb_prom_envs] = optarg;
3330 case QEMU_OPTION_old_param:
3333 case QEMU_OPTION_clock:
3334 configure_alarms(optarg);
3336 case QEMU_OPTION_startdate:
3337 configure_rtc_date_offset(optarg, 1);
3339 case QEMU_OPTION_rtc:
3340 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
3344 configure_rtc(opts);
3346 case QEMU_OPTION_tb_size:
3347 tcg_tb_size = strtol(optarg, NULL, 0);
3348 if (tcg_tb_size < 0) {
3352 case QEMU_OPTION_icount:
3353 icount_option = optarg;
3355 case QEMU_OPTION_incoming:
3357 runstate_set(RUN_STATE_INMIGRATE);
3359 case QEMU_OPTION_nodefaults:
3361 default_parallel = 0;
3362 default_virtcon = 0;
3363 default_monitor = 0;
3370 case QEMU_OPTION_xen_domid:
3371 if (!(xen_available())) {
3372 printf("Option %s not supported for this target\n", popt->name);
3375 xen_domid = atoi(optarg);
3377 case QEMU_OPTION_xen_create:
3378 if (!(xen_available())) {
3379 printf("Option %s not supported for this target\n", popt->name);
3382 xen_mode = XEN_CREATE;
3384 case QEMU_OPTION_xen_attach:
3385 if (!(xen_available())) {
3386 printf("Option %s not supported for this target\n", popt->name);
3389 xen_mode = XEN_ATTACH;
3391 case QEMU_OPTION_trace:
3393 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
3397 trace_events = qemu_opt_get(opts, "events");
3398 trace_file = qemu_opt_get(opts, "file");
3401 case QEMU_OPTION_readconfig:
3403 int ret = qemu_read_config_file(optarg);
3405 fprintf(stderr, "read config %s: %s\n", optarg,
3411 case QEMU_OPTION_spice:
3412 olist = qemu_find_opts("spice");
3414 fprintf(stderr, "spice is not supported by this qemu build.\n");
3417 opts = qemu_opts_parse(olist, optarg, 0);
3419 fprintf(stderr, "parse error: %s\n", optarg);
3423 case QEMU_OPTION_writeconfig:
3426 if (strcmp(optarg, "-") == 0) {
3429 fp = fopen(optarg, "w");
3431 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
3435 qemu_config_write(fp);
3439 case QEMU_OPTION_qtest:
3440 qtest_chrdev = optarg;
3442 case QEMU_OPTION_qtest_log:
3445 case QEMU_OPTION_sandbox:
3446 opts = qemu_opts_parse(qemu_find_opts("sandbox"), optarg, 1);
3451 case QEMU_OPTION_enable_hax:
3452 #ifdef CONFIG_HAX_BACKEND
3453 olist = qemu_find_opts("machine");
3454 //qemu_opts_reset(olist);
3456 //qemu_opts_parse(olist, "accel=hax", 0);
3459 "HAX support is disabled, ignoring -enable-hax\n");
3463 case QEMU_OPTION_max_touch_point:
3465 int cnt = atoi(optarg);
3466 fprintf(stderr, "maxTouchPoint:%d\n", cnt);
3467 set_emul_max_touch_point(cnt);
3470 case QEMU_OPTION_disable_skin:
3475 os_parse_cmd_args(popt->index, optarg);
3481 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 0)) {
3485 if (machine == NULL) {
3486 fprintf(stderr, "No machine found.\n");
3490 if (machine->hw_version) {
3491 qemu_set_version(machine->hw_version);
3494 /* Init CPU def lists, based on config
3495 * - Must be called after all the qemu_read_config_file() calls
3496 * - Must be called before list_cpus()
3497 * - Must be called before machine->init()
3501 if (cpu_model && is_help_option(cpu_model)) {
3502 list_cpus(stdout, &fprintf, cpu_model);
3506 #ifdef CONFIG_GL_BACKEND
3507 #if defined(CONFIG_MARU) && (!defined(CONFIG_DARWIN))
3509 capability_check_gl = gl_acceleration_capability_check();
3511 if (capability_check_gl != 0) {
3513 fprintf (stderr, "Warn: GL acceleration was disabled due to the fail of GL check!\n");
3516 // To check host gl driver capability and notify to guest.
3517 gchar *tmp = tmp_cmdline;
3518 tmp_cmdline = g_strdup_printf("%s gles=%d", tmp, enable_gl);
3519 qemu_opts_set(qemu_find_opts("machine"), 0, "append", tmp_cmdline);
3520 fprintf(stdout, "kernel command : %s\n", tmp_cmdline);
3524 device_opt_finding_t devp = {VIRTIOGL_DEV_NAME, 0};
3525 qemu_opts_foreach(qemu_find_opts("device"), find_device_opt, &devp, 0);
3526 if (devp.found == 0) {
3527 if (!qemu_opts_parse(qemu_find_opts("device"), VIRTIOGL_DEV_NAME, "driver")) {
3536 /* Open the logfile at this point, if necessary. We can't open the logfile
3537 * when encountering either of the logging options (-d or -D) because the
3538 * other one may be encountered later on the command line, changing the
3539 * location or level of logging.
3543 set_cpu_log_filename(log_file);
3545 set_cpu_log(log_mask);
3548 if (!trace_backend_init(trace_events, trace_file)) {
3552 /* If no data_dir is specified then try to find it relative to the
3555 data_dir = os_find_datadir(argv[0]);
3557 /* If all else fails use the install path specified when building. */
3559 data_dir = CONFIG_QEMU_DATADIR;
3563 * Default to max_cpus = smp_cpus, in case the user doesn't
3564 * specify a max_cpus value.
3567 max_cpus = smp_cpus;
3569 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
3570 if (smp_cpus > machine->max_cpus) {
3571 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
3572 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
3578 * Get the default machine options from the machine if it is not already
3579 * specified either by the configuration file or by the command line.
3581 if (machine->default_machine_opts) {
3582 qemu_opts_set_defaults(qemu_find_opts("machine"),
3583 machine->default_machine_opts, 0);
3586 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
3587 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
3589 if (machine->no_serial) {
3592 if (machine->no_parallel) {
3593 default_parallel = 0;
3595 if (!machine->use_virtcon) {
3596 default_virtcon = 0;
3598 if (machine->no_floppy) {
3601 if (machine->no_cdrom) {
3604 if (machine->no_sdcard) {
3608 if (display_type == DT_NOGRAPHIC) {
3609 if (default_parallel)
3610 add_device_config(DEV_PARALLEL, "null");
3611 if (default_serial && default_monitor) {
3612 add_device_config(DEV_SERIAL, "mon:stdio");
3613 } else if (default_virtcon && default_monitor) {
3614 add_device_config(DEV_VIRTCON, "mon:stdio");
3617 add_device_config(DEV_SERIAL, "stdio");
3618 if (default_virtcon)
3619 add_device_config(DEV_VIRTCON, "stdio");
3620 if (default_monitor)
3621 monitor_parse("stdio", "readline");
3625 add_device_config(DEV_SERIAL, "vc:80Cx24C");
3626 if (default_parallel)
3627 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
3628 if (default_monitor)
3629 monitor_parse("vc:80Cx24C", "readline");
3630 if (default_virtcon)
3631 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
3636 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
3638 #ifdef CONFIG_VIRTFS
3639 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
3646 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
3651 /* init the memory */
3652 if (ram_size == 0) {
3653 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
3656 // W/A for preserve larger continuous heap for RAM.
3657 preallocated_ptr = qemu_vmalloc(ram_size);
3660 hax_pre_init(ram_size);
3662 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0)
3667 configure_accelerator();
3669 qemu_init_cpu_loop();
3670 if (qemu_init_main_loop()) {
3671 fprintf(stderr, "qemu_init_main_loop failed\n");
3675 machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
3677 kernel_filename = qemu_opt_get(machine_opts, "kernel");
3678 initrd_filename = qemu_opt_get(machine_opts, "initrd");
3679 kernel_cmdline = qemu_opt_get(machine_opts, "append");
3681 kernel_filename = initrd_filename = kernel_cmdline = NULL;
3684 if (!kernel_cmdline) {
3685 kernel_cmdline = "";
3688 #if defined(CONFIG_MARU) && (!defined(CONFIG_DARWIN))
3689 is_webcam_enabled = marucam_device_check(WEBCAM_INFO_WRITE);
3690 if (!is_webcam_enabled) {
3691 fprintf (stderr, "[Webcam] <WARNING> Webcam support was disabled "
3692 "due to the fail of webcam capability check!\n");
3695 gchar *tmp_cam_kcmd = kernel_cmdline;
3696 kernel_cmdline = g_strdup_printf("%s enable_cam=%d", tmp_cam_kcmd, is_webcam_enabled);
3697 g_free(tmp_cam_kcmd);
3699 if (is_webcam_enabled) {
3700 device_opt_finding_t devp = {MARUCAM_DEV_NAME, 0};
3701 qemu_opts_foreach(qemu_find_opts("device"), find_device_opt, &devp, 0);
3702 if (devp.found == 0) {
3703 if (!qemu_opts_parse(qemu_find_opts("device"), MARUCAM_DEV_NAME, 1)) {
3704 fprintf(stderr, "Failed to initialize the marucam device.\n");
3708 fprintf(stdout, "[Webcam] Webcam support was enabled.\n");
3712 linux_boot = (kernel_filename != NULL);
3714 if (!linux_boot && *kernel_cmdline != '\0') {
3715 fprintf(stderr, "-append only allowed with -kernel option\n");
3719 if (!linux_boot && initrd_filename != NULL) {
3720 fprintf(stderr, "-initrd only allowed with -kernel option\n");
3724 if (!linux_boot && machine_opts && qemu_opt_get(machine_opts, "dtb")) {
3725 fprintf(stderr, "-dtb only allowed with -kernel option\n");
3729 os_set_line_buffering();
3731 if (init_timer_alarm() < 0) {
3732 fprintf(stderr, "could not initialize alarm timer\n");
3737 /* spice needs the timers to be initialized by this point */
3741 if (icount_option && (kvm_enabled() || xen_enabled() || hax_enabled())) {
3742 fprintf(stderr, "-icount is not allowed with kvm or xen\n");
3745 configure_icount(icount_option);
3747 if (net_init_clients() < 0) {
3751 /* init the bluetooth world */
3752 if (foreach_device_config(DEV_BT, bt_parse))
3755 if (!xen_enabled()) {
3756 /* On 32-bit hosts, QEMU is limited by virtual address space */
3757 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
3758 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
3763 cpu_exec_init_all();
3765 bdrv_init_with_whitelist();
3769 /* open the virtual block devices */
3771 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
3772 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
3775 default_drive(default_cdrom, snapshot, machine->use_scsi,
3776 IF_DEFAULT, 2, CDROM_OPTS);
3777 default_drive(default_floppy, snapshot, machine->use_scsi,
3778 IF_FLOPPY, 0, FD_OPTS);
3779 default_drive(default_sdcard, snapshot, machine->use_scsi,
3782 register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL);
3784 if (nb_numa_nodes > 0) {
3787 if (nb_numa_nodes > MAX_NODES) {
3788 nb_numa_nodes = MAX_NODES;
3791 /* If no memory size if given for any node, assume the default case
3792 * and distribute the available memory equally across all nodes
3794 for (i = 0; i < nb_numa_nodes; i++) {
3795 if (node_mem[i] != 0)
3798 if (i == nb_numa_nodes) {
3799 uint64_t usedmem = 0;
3801 /* On Linux, the each node's border has to be 8MB aligned,
3802 * the final node gets the rest.
3804 for (i = 0; i < nb_numa_nodes - 1; i++) {
3805 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
3806 usedmem += node_mem[i];
3808 node_mem[i] = ram_size - usedmem;
3811 for (i = 0; i < nb_numa_nodes; i++) {
3812 if (!bitmap_empty(node_cpumask[i], MAX_CPUMASK_BITS)) {
3816 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3817 * must cope with this anyway, because there are BIOSes out there in
3818 * real machines which also use this scheme.
3820 if (i == nb_numa_nodes) {
3821 for (i = 0; i < max_cpus; i++) {
3822 set_bit(i, node_cpumask[i % nb_numa_nodes]);
3827 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
3831 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
3833 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
3835 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
3837 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
3840 /* If no default VGA is requested, the default is "none". */
3841 if (default_vga && cirrus_vga_available()) {
3842 vga_model = "cirrus";
3844 select_vgahw(vga_model);
3847 i = select_watchdog(watchdog);
3849 exit (i == 1 ? 1 : 0);
3852 if (machine->compat_props) {
3853 qdev_prop_register_global_list(machine->compat_props);
3857 qdev_machine_init();
3859 machine->init(ram_size, boot_devices,
3860 kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
3862 g_free((gchar *)tmp_cmdline);
3865 cpu_synchronize_all_post_init();
3869 current_machine = machine;
3874 /* init USB devices */
3876 if (foreach_device_config(DEV_USB, usb_parse) < 0)
3880 /* init generic devices */
3881 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
3884 net_check_clients();
3886 /* just use the first displaystate for the moment */
3887 ds = get_displaystate();
3891 if (display_type == DT_DEFAULT && !display_remote) {
3892 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3893 display_type = DT_SDL;
3894 #elif defined(CONFIG_VNC)
3895 vnc_display = "localhost:0,to=99";
3897 #elif defined(CONFIG_MARU) && defined (__APPLE__)
3898 display_type = DT_MARU;
3900 display_type = DT_NONE;
3905 /* init local displays */
3906 switch (display_type) {
3909 #if defined(CONFIG_CURSES)
3911 curses_display_init(ds, full_screen);
3914 #if defined(CONFIG_SDL)
3916 #if defined(CONFIG_MARU)
3917 /* use tizen qemu sdl */
3918 maru_display_init(ds);
3920 if (skin_disabled == 1) {
3921 //do not start skin client process
3922 set_emul_skin_enable(0);
3924 set_emul_skin_enable(1);
3927 sdl_display_init(ds, full_screen, no_frame);
3930 #elif defined(CONFIG_COCOA)
3932 cocoa_display_init(ds, full_screen);
3935 #if defined(CONFIG_MARU) && defined(__APPLE__)
3937 maru_display_init(ds);
3938 if (skin_disabled == 1) {
3939 //do not start skin client process
3940 set_emul_skin_enable(0);
3942 set_emul_skin_enable(1);
3950 /* must be after terminal init, SDL library changes signal handlers */
3951 os_setup_signal_handling();
3954 /* init remote displays */
3956 vnc_display_init(ds);
3957 if (vnc_display_open(ds, vnc_display) < 0) {
3958 fprintf(stderr, "Failed to start VNC server on `%s'\n",
3963 if (show_vnc_port) {
3964 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
3969 if (using_spice && !qxl_enabled) {
3970 qemu_spice_display_init(ds);
3976 dcl = ds->listeners;
3977 while (dcl != NULL) {
3978 if (dcl->dpy_refresh != NULL) {
3979 ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds);
3980 qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock));
3985 text_consoles_set_display(ds);
3987 if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
3991 qdev_machine_creation_done();
3993 if (rom_load_all() != 0) {
3994 fprintf(stderr, "rom loading failed\n");
3998 /* TODO: once all bus devices are qdevified, this should be done
3999 * when bus is created by qdev.c */
4000 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
4001 qemu_run_machine_init_done_notifiers();
4003 qemu_system_reset(VMRESET_SILENT);
4005 if (load_vmstate(loadvm) < 0) {
4012 int ret = qemu_start_incoming_migration(incoming, &errp);
4014 if (error_is_set(&errp)) {
4015 fprintf(stderr, "Migrate: %s\n", error_get_pretty(errp));
4018 fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n",
4022 } else if (autostart) {