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
32 /* Needed early for CONFIG_BSD etc. */
33 #include "config-host.h"
37 #include <sys/times.h>
41 #include <sys/ioctl.h>
42 #include <sys/resource.h>
43 #include <sys/socket.h>
44 #include <netinet/in.h>
46 #include <arpa/inet.h>
49 #include <sys/select.h>
50 #ifdef CONFIG_SIMPLE_TRACE
56 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
58 #include <sys/sysctl.h>
67 #include <linux/ppdev.h>
68 #include <linux/parport.h>
72 #include <sys/ethernet.h>
73 #include <sys/sockio.h>
74 #include <netinet/arp.h>
75 #include <netinet/in_systm.h>
76 #include <netinet/ip.h>
77 #include <netinet/ip_icmp.h> // must come after ip.h
78 #include <netinet/udp.h>
79 #include <netinet/tcp.h>
87 #if defined(__OpenBSD__)
91 #if defined(CONFIG_VDE)
92 #include <libvdeplug.h>
100 #if defined(__APPLE__) || defined(main)
102 int qemu_main(int argc, char **argv, char **envp);
103 int main(int argc, char **argv)
105 return qemu_main(argc, argv, NULL);
108 #define main qemu_main
110 #endif /* CONFIG_SDL */
114 #define main qemu_main
115 #endif /* CONFIG_COCOA */
118 #include "hw/boards.h"
120 #include "hw/pcmcia.h"
125 #include "hw/watchdog.h"
126 #include "hw/smbios.h"
129 #include "hw/loader.h"
132 #include "net/slirp.h"
137 #include "qemu-timer.h"
138 #include "qemu-char.h"
139 #include "cache-utils.h"
141 #include "blockdev.h"
142 #include "block-migration.h"
144 #include "audio/audio.h"
145 #include "migration.h"
147 #include "qemu-option.h"
148 #include "qemu-config.h"
149 #include "qemu-objects.h"
150 #include "qemu-options.h"
152 #include "fsdev/qemu-fsdev.h"
157 #include "qemu_socket.h"
159 #include "slirp/libslirp.h"
162 #include "qemu-queue.h"
164 #include "arch_init.h"
166 #include "ui/qemu-spice.h"
169 //#define DEBUG_SLIRP
171 #define DEFAULT_RAM_SIZE 128
173 #define MAX_VIRTIO_CONSOLES 1
175 static const char *data_dir;
176 const char *bios_name = NULL;
177 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
178 DisplayType display_type = DT_DEFAULT;
179 int display_remote = 0;
180 const char* keyboard_layout = NULL;
182 const char *mem_path = NULL;
184 int mem_prealloc = 0; /* force preallocation of physical target memory */
187 NICInfo nd_table[MAX_NICS];
190 int incoming_expected; /* Started with -incoming and waiting for incoming */
191 static int rtc_utc = 1;
192 static int rtc_date_offset = -1; /* -1 means no change */
193 QEMUClock *rtc_clock;
194 int vga_interface_type = VGA_NONE;
195 static int full_screen = 0;
197 static int no_frame = 0;
200 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
201 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
202 CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
203 int win2k_install_hack = 0;
211 const char *vnc_display;
212 int acpi_enabled = 1;
218 int graphic_rotate = 0;
219 uint8_t irq0override = 1;
220 const char *watchdog;
221 QEMUOptionRom option_rom[MAX_OPTION_ROMS];
223 int semihosting_enabled = 0;
225 const char *qemu_name;
228 unsigned int nb_prom_envs = 0;
229 const char *prom_envs[MAX_PROM_ENVS];
232 typedef struct FWBootEntry FWBootEntry;
235 QTAILQ_ENTRY(FWBootEntry) link;
241 QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order);
244 uint64_t node_mem[MAX_NODES];
245 uint64_t node_cpumask[MAX_NODES];
247 static QEMUTimer *nographic_timer;
249 uint8_t qemu_uuid[16];
251 static QEMUBootSetHandler *boot_set_handler;
252 static void *boot_set_opaque;
254 static NotifierList exit_notifiers =
255 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
257 static NotifierList machine_init_done_notifiers =
258 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
262 enum xen_mode xen_mode = XEN_EMULATE;
264 static int default_serial = 1;
265 static int default_parallel = 1;
266 static int default_virtcon = 1;
267 static int default_monitor = 1;
268 static int default_vga = 1;
269 static int default_floppy = 1;
270 static int default_cdrom = 1;
271 static int default_sdcard = 1;
277 { .driver = "isa-serial", .flag = &default_serial },
278 { .driver = "isa-parallel", .flag = &default_parallel },
279 { .driver = "isa-fdc", .flag = &default_floppy },
280 { .driver = "ide-drive", .flag = &default_cdrom },
281 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
282 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
283 { .driver = "virtio-serial", .flag = &default_virtcon },
284 { .driver = "VGA", .flag = &default_vga },
285 { .driver = "cirrus-vga", .flag = &default_vga },
286 { .driver = "vmware-svga", .flag = &default_vga },
289 static int default_driver_check(QemuOpts *opts, void *opaque)
291 const char *driver = qemu_opt_get(opts, "driver");
296 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
297 if (strcmp(default_list[i].driver, driver) != 0)
299 *(default_list[i].flag) = 0;
304 /***********************************************************/
305 /* real time host monotonic timer */
307 /***********************************************************/
308 /* host time/date access */
309 void qemu_get_timedate(struct tm *tm, int offset)
316 if (rtc_date_offset == -1) {
320 ret = localtime(&ti);
322 ti -= rtc_date_offset;
326 memcpy(tm, ret, sizeof(struct tm));
329 int qemu_timedate_diff(struct tm *tm)
333 if (rtc_date_offset == -1)
335 seconds = mktimegm(tm);
337 seconds = mktime(tm);
339 seconds = mktimegm(tm) + rtc_date_offset;
341 return seconds - time(NULL);
344 void rtc_change_mon_event(struct tm *tm)
348 data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
349 monitor_protocol_event(QEVENT_RTC_CHANGE, data);
350 qobject_decref(data);
353 static void configure_rtc_date_offset(const char *startdate, int legacy)
355 time_t rtc_start_date;
358 if (!strcmp(startdate, "now") && legacy) {
359 rtc_date_offset = -1;
361 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
369 } else if (sscanf(startdate, "%d-%d-%d",
381 rtc_start_date = mktimegm(&tm);
382 if (rtc_start_date == -1) {
384 fprintf(stderr, "Invalid date format. Valid formats are:\n"
385 "'2006-06-17T16:01:21' or '2006-06-17'\n");
388 rtc_date_offset = time(NULL) - rtc_start_date;
392 static void configure_rtc(QemuOpts *opts)
396 value = qemu_opt_get(opts, "base");
398 if (!strcmp(value, "utc")) {
400 } else if (!strcmp(value, "localtime")) {
403 configure_rtc_date_offset(value, 0);
406 value = qemu_opt_get(opts, "clock");
408 if (!strcmp(value, "host")) {
409 rtc_clock = host_clock;
410 } else if (!strcmp(value, "vm")) {
411 rtc_clock = vm_clock;
413 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
417 value = qemu_opt_get(opts, "driftfix");
419 if (!strcmp(value, "slew")) {
421 } else if (!strcmp(value, "none")) {
424 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
430 /***********************************************************/
431 /* Bluetooth support */
434 static struct HCIInfo *hci_table[MAX_NICS];
436 static struct bt_vlan_s {
437 struct bt_scatternet_s net;
439 struct bt_vlan_s *next;
442 /* find or alloc a new bluetooth "VLAN" */
443 static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
445 struct bt_vlan_s **pvlan, *vlan;
446 for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) {
450 vlan = qemu_mallocz(sizeof(struct bt_vlan_s));
452 pvlan = &first_bt_vlan;
453 while (*pvlan != NULL)
454 pvlan = &(*pvlan)->next;
459 static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
463 static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
468 static struct HCIInfo null_hci = {
469 .cmd_send = null_hci_send,
470 .sco_send = null_hci_send,
471 .acl_send = null_hci_send,
472 .bdaddr_set = null_hci_addr_set,
475 struct HCIInfo *qemu_next_hci(void)
477 if (cur_hci == nb_hcis)
480 return hci_table[cur_hci++];
483 static struct HCIInfo *hci_init(const char *str)
486 struct bt_scatternet_s *vlan = 0;
488 if (!strcmp(str, "null"))
491 else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':'))
493 return bt_host_hci(str[4] ? str + 5 : "hci0");
494 else if (!strncmp(str, "hci", 3)) {
497 if (!strncmp(str + 3, ",vlan=", 6)) {
498 vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0));
503 vlan = qemu_find_bt_vlan(0);
505 return bt_new_hci(vlan);
508 fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
513 static int bt_hci_parse(const char *str)
518 if (nb_hcis >= MAX_NICS) {
519 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
532 bdaddr.b[5] = 0x56 + nb_hcis;
533 hci->bdaddr_set(hci, bdaddr.b);
535 hci_table[nb_hcis++] = hci;
540 static void bt_vhci_add(int vlan_id)
542 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
545 fprintf(stderr, "qemu: warning: adding a VHCI to "
546 "an empty scatternet %i\n", vlan_id);
548 bt_vhci_init(bt_new_hci(vlan));
551 static struct bt_device_s *bt_device_add(const char *opt)
553 struct bt_scatternet_s *vlan;
555 char *endp = strstr(opt, ",vlan=");
556 int len = (endp ? endp - opt : strlen(opt)) + 1;
559 pstrcpy(devname, MIN(sizeof(devname), len), opt);
562 vlan_id = strtol(endp + 6, &endp, 0);
564 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
569 vlan = qemu_find_bt_vlan(vlan_id);
572 fprintf(stderr, "qemu: warning: adding a slave device to "
573 "an empty scatternet %i\n", vlan_id);
575 if (!strcmp(devname, "keyboard"))
576 return bt_keyboard_init(vlan);
578 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
582 static int bt_parse(const char *opt)
584 const char *endp, *p;
587 if (strstart(opt, "hci", &endp)) {
588 if (!*endp || *endp == ',') {
590 if (!strstart(endp, ",vlan=", 0))
593 return bt_hci_parse(opt);
595 } else if (strstart(opt, "vhci", &endp)) {
596 if (!*endp || *endp == ',') {
598 if (strstart(endp, ",vlan=", &p)) {
599 vlan = strtol(p, (char **) &endp, 0);
601 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
605 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
614 } else if (strstart(opt, "device:", &endp))
615 return !bt_device_add(endp);
617 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
621 /***********************************************************/
622 /* QEMU Block devices */
624 #define HD_OPTS "media=disk"
625 #define CDROM_OPTS "media=cdrom"
627 #define PFLASH_OPTS ""
631 static int drive_init_func(QemuOpts *opts, void *opaque)
633 int *use_scsi = opaque;
635 return drive_init(opts, *use_scsi) == NULL;
638 static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
640 if (NULL == qemu_opt_get(opts, "snapshot")) {
641 qemu_opt_set(opts, "snapshot", "on");
646 static void default_drive(int enable, int snapshot, int use_scsi,
647 BlockInterfaceType type, int index,
652 if (type == IF_DEFAULT) {
653 type = use_scsi ? IF_SCSI : IF_IDE;
656 if (!enable || drive_get_by_index(type, index)) {
660 opts = drive_add(type, index, NULL, optstr);
662 drive_enable_snapshot(opts, NULL);
664 if (!drive_init(opts, use_scsi)) {
669 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
671 boot_set_handler = func;
672 boot_set_opaque = opaque;
675 int qemu_boot_set(const char *boot_devices)
677 if (!boot_set_handler) {
680 return boot_set_handler(boot_set_opaque, boot_devices);
683 static void validate_bootdevices(char *devices)
685 /* We just do some generic consistency checks */
689 for (p = devices; *p != '\0'; p++) {
690 /* Allowed boot devices are:
691 * a-b: floppy disk drives
692 * c-f: IDE disk drives
693 * g-m: machine implementation dependant drives
694 * n-p: network devices
695 * It's up to each machine implementation to check if the given boot
696 * devices match the actual hardware implementation and firmware
699 if (*p < 'a' || *p > 'p') {
700 fprintf(stderr, "Invalid boot device '%c'\n", *p);
703 if (bitmap & (1 << (*p - 'a'))) {
704 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
707 bitmap |= 1 << (*p - 'a');
711 static void restore_boot_devices(void *opaque)
713 char *standard_boot_devices = opaque;
714 static int first = 1;
716 /* Restore boot order and remove ourselves after the first boot */
722 qemu_boot_set(standard_boot_devices);
724 qemu_unregister_reset(restore_boot_devices, standard_boot_devices);
725 qemu_free(standard_boot_devices);
728 void add_boot_device_path(int32_t bootindex, DeviceState *dev,
731 FWBootEntry *node, *i;
737 assert(dev != NULL || suffix != NULL);
739 node = qemu_mallocz(sizeof(FWBootEntry));
740 node->bootindex = bootindex;
741 node->suffix = strdup(suffix);
744 QTAILQ_FOREACH(i, &fw_boot_order, link) {
745 if (i->bootindex == bootindex) {
746 fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
748 } else if (i->bootindex < bootindex) {
751 QTAILQ_INSERT_BEFORE(i, node, link);
754 QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
758 * This function returns null terminated string that consist of new line
759 * separated device pathes.
761 * memory pointed by "size" is assigned total length of the array in bytes
764 char *get_boot_devices_list(uint32_t *size)
770 QTAILQ_FOREACH(i, &fw_boot_order, link) {
771 char *devpath = NULL, *bootpath;
775 devpath = qdev_get_fw_dev_path(i->dev);
779 if (i->suffix && devpath) {
780 size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
782 bootpath = qemu_malloc(bootpathlen);
783 snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
785 } else if (devpath) {
788 bootpath = strdup(i->suffix);
793 list[total-1] = '\n';
795 len = strlen(bootpath) + 1;
796 list = qemu_realloc(list, total + len);
797 memcpy(&list[total], bootpath, len);
807 static void numa_add(const char *optarg)
811 unsigned long long value, endvalue;
814 optarg = get_opt_name(option, 128, optarg, ',') + 1;
815 if (!strcmp(option, "node")) {
816 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
817 nodenr = nb_numa_nodes;
819 nodenr = strtoull(option, NULL, 10);
822 if (get_param_value(option, 128, "mem", optarg) == 0) {
823 node_mem[nodenr] = 0;
826 sval = strtosz(option, NULL);
828 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
831 node_mem[nodenr] = sval;
833 if (get_param_value(option, 128, "cpus", optarg) == 0) {
834 node_cpumask[nodenr] = 0;
836 value = strtoull(option, &endptr, 10);
839 fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n");
841 if (*endptr == '-') {
842 endvalue = strtoull(endptr+1, &endptr, 10);
843 if (endvalue >= 63) {
846 "only 63 CPUs in NUMA mode supported.\n");
848 value = (2ULL << endvalue) - (1ULL << value);
850 value = 1ULL << value;
853 node_cpumask[nodenr] = value;
860 static void smp_parse(const char *optarg)
862 int smp, sockets = 0, threads = 0, cores = 0;
866 smp = strtoul(optarg, &endptr, 10);
867 if (endptr != optarg) {
868 if (*endptr == ',') {
872 if (get_param_value(option, 128, "sockets", endptr) != 0)
873 sockets = strtoull(option, NULL, 10);
874 if (get_param_value(option, 128, "cores", endptr) != 0)
875 cores = strtoull(option, NULL, 10);
876 if (get_param_value(option, 128, "threads", endptr) != 0)
877 threads = strtoull(option, NULL, 10);
878 if (get_param_value(option, 128, "maxcpus", endptr) != 0)
879 max_cpus = strtoull(option, NULL, 10);
881 /* compute missing values, prefer sockets over cores over threads */
882 if (smp == 0 || sockets == 0) {
883 sockets = sockets > 0 ? sockets : 1;
884 cores = cores > 0 ? cores : 1;
885 threads = threads > 0 ? threads : 1;
887 smp = cores * threads * sockets;
891 threads = threads > 0 ? threads : 1;
892 cores = smp / (sockets * threads);
894 threads = smp / (cores * sockets);
898 smp_cores = cores > 0 ? cores : 1;
899 smp_threads = threads > 0 ? threads : 1;
904 /***********************************************************/
907 static int usb_device_add(const char *devname)
910 USBDevice *dev = NULL;
915 /* drivers with .usbdevice_name entry in USBDeviceInfo */
916 dev = usbdevice_create(devname);
921 if (strstart(devname, "host:", &p)) {
922 dev = usb_host_device_open(p);
923 } else if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
924 dev = usb_bt_init(devname[2] ? hci_init(p) :
925 bt_new_hci(qemu_find_bt_vlan(0)));
936 static int usb_device_del(const char *devname)
941 if (strstart(devname, "host:", &p))
942 return usb_host_device_close(p);
947 p = strchr(devname, '.');
950 bus_num = strtoul(devname, NULL, 0);
951 addr = strtoul(p + 1, NULL, 0);
953 return usb_device_delete_addr(bus_num, addr);
956 static int usb_parse(const char *cmdline)
959 r = usb_device_add(cmdline);
961 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
966 void do_usb_add(Monitor *mon, const QDict *qdict)
968 const char *devname = qdict_get_str(qdict, "devname");
969 if (usb_device_add(devname) < 0) {
970 error_report("could not add USB device '%s'", devname);
974 void do_usb_del(Monitor *mon, const QDict *qdict)
976 const char *devname = qdict_get_str(qdict, "devname");
977 if (usb_device_del(devname) < 0) {
978 error_report("could not delete USB device '%s'", devname);
982 /***********************************************************/
985 static struct pcmcia_socket_entry_s {
986 PCMCIASocket *socket;
987 struct pcmcia_socket_entry_s *next;
988 } *pcmcia_sockets = 0;
990 void pcmcia_socket_register(PCMCIASocket *socket)
992 struct pcmcia_socket_entry_s *entry;
994 entry = qemu_malloc(sizeof(struct pcmcia_socket_entry_s));
995 entry->socket = socket;
996 entry->next = pcmcia_sockets;
997 pcmcia_sockets = entry;
1000 void pcmcia_socket_unregister(PCMCIASocket *socket)
1002 struct pcmcia_socket_entry_s *entry, **ptr;
1004 ptr = &pcmcia_sockets;
1005 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1006 if (entry->socket == socket) {
1012 void pcmcia_info(Monitor *mon)
1014 struct pcmcia_socket_entry_s *iter;
1016 if (!pcmcia_sockets)
1017 monitor_printf(mon, "No PCMCIA sockets\n");
1019 for (iter = pcmcia_sockets; iter; iter = iter->next)
1020 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1021 iter->socket->attached ? iter->socket->card_string :
1025 /***********************************************************/
1028 typedef struct IOHandlerRecord {
1030 IOCanReadHandler *fd_read_poll;
1032 IOHandler *fd_write;
1035 /* temporary data */
1037 QLIST_ENTRY(IOHandlerRecord) next;
1040 static QLIST_HEAD(, IOHandlerRecord) io_handlers =
1041 QLIST_HEAD_INITIALIZER(io_handlers);
1044 /* XXX: fd_read_poll should be suppressed, but an API change is
1045 necessary in the character devices to suppress fd_can_read(). */
1046 int qemu_set_fd_handler2(int fd,
1047 IOCanReadHandler *fd_read_poll,
1049 IOHandler *fd_write,
1052 IOHandlerRecord *ioh;
1054 if (!fd_read && !fd_write) {
1055 QLIST_FOREACH(ioh, &io_handlers, next) {
1056 if (ioh->fd == fd) {
1062 QLIST_FOREACH(ioh, &io_handlers, next) {
1066 ioh = qemu_mallocz(sizeof(IOHandlerRecord));
1067 QLIST_INSERT_HEAD(&io_handlers, ioh, next);
1070 ioh->fd_read_poll = fd_read_poll;
1071 ioh->fd_read = fd_read;
1072 ioh->fd_write = fd_write;
1073 ioh->opaque = opaque;
1079 int qemu_set_fd_handler(int fd,
1081 IOHandler *fd_write,
1084 return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque);
1087 /***********************************************************/
1088 /* machine registration */
1090 static QEMUMachine *first_machine = NULL;
1091 QEMUMachine *current_machine = NULL;
1093 int qemu_register_machine(QEMUMachine *m)
1096 pm = &first_machine;
1104 static QEMUMachine *find_machine(const char *name)
1108 for(m = first_machine; m != NULL; m = m->next) {
1109 if (!strcmp(m->name, name))
1111 if (m->alias && !strcmp(m->alias, name))
1117 static QEMUMachine *find_default_machine(void)
1121 for(m = first_machine; m != NULL; m = m->next) {
1122 if (m->is_default) {
1129 /***********************************************************/
1130 /* main execution loop */
1132 static void gui_update(void *opaque)
1134 uint64_t interval = GUI_REFRESH_INTERVAL;
1135 DisplayState *ds = opaque;
1136 DisplayChangeListener *dcl = ds->listeners;
1138 qemu_flush_coalesced_mmio_buffer();
1141 while (dcl != NULL) {
1142 if (dcl->gui_timer_interval &&
1143 dcl->gui_timer_interval < interval)
1144 interval = dcl->gui_timer_interval;
1147 qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock));
1150 static void nographic_update(void *opaque)
1152 uint64_t interval = GUI_REFRESH_INTERVAL;
1154 qemu_flush_coalesced_mmio_buffer();
1155 qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock));
1158 struct vm_change_state_entry {
1159 VMChangeStateHandler *cb;
1161 QLIST_ENTRY (vm_change_state_entry) entries;
1164 static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
1166 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1169 VMChangeStateEntry *e;
1171 e = qemu_mallocz(sizeof (*e));
1175 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
1179 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1181 QLIST_REMOVE (e, entries);
1185 void vm_state_notify(int running, int reason)
1187 VMChangeStateEntry *e;
1189 trace_vm_state_notify(running, reason);
1191 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
1192 e->cb(e->opaque, running, reason);
1201 vm_state_notify(1, 0);
1203 monitor_protocol_event(QEVENT_RESUME, NULL);
1207 /* reset/shutdown handler */
1209 typedef struct QEMUResetEntry {
1210 QTAILQ_ENTRY(QEMUResetEntry) entry;
1211 QEMUResetHandler *func;
1215 static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1216 QTAILQ_HEAD_INITIALIZER(reset_handlers);
1217 static int reset_requested;
1218 static int shutdown_requested;
1219 static int powerdown_requested;
1220 int debug_requested;
1221 int vmstop_requested;
1223 int qemu_shutdown_requested(void)
1225 int r = shutdown_requested;
1226 shutdown_requested = 0;
1230 int qemu_reset_requested(void)
1232 int r = reset_requested;
1233 reset_requested = 0;
1237 int qemu_powerdown_requested(void)
1239 int r = powerdown_requested;
1240 powerdown_requested = 0;
1244 static int qemu_debug_requested(void)
1246 int r = debug_requested;
1247 debug_requested = 0;
1251 static int qemu_vmstop_requested(void)
1253 int r = vmstop_requested;
1254 vmstop_requested = 0;
1258 void qemu_register_reset(QEMUResetHandler *func, void *opaque)
1260 QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry));
1263 re->opaque = opaque;
1264 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
1267 void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
1271 QTAILQ_FOREACH(re, &reset_handlers, entry) {
1272 if (re->func == func && re->opaque == opaque) {
1273 QTAILQ_REMOVE(&reset_handlers, re, entry);
1280 void qemu_system_reset(void)
1282 QEMUResetEntry *re, *nre;
1284 /* reset all devices */
1285 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
1286 re->func(re->opaque);
1288 monitor_protocol_event(QEVENT_RESET, NULL);
1289 cpu_synchronize_all_post_reset();
1292 void qemu_system_reset_request(void)
1295 shutdown_requested = 1;
1297 reset_requested = 1;
1299 qemu_notify_event();
1302 void qemu_system_shutdown_request(void)
1304 shutdown_requested = 1;
1305 qemu_notify_event();
1308 void qemu_system_powerdown_request(void)
1310 powerdown_requested = 1;
1311 qemu_notify_event();
1314 void main_loop_wait(int nonblocking)
1316 IOHandlerRecord *ioh;
1317 fd_set rfds, wfds, xfds;
1325 timeout = qemu_calculate_timeout();
1326 qemu_bh_update_timeout(&timeout);
1329 os_host_main_loop_wait(&timeout);
1331 /* poll any events */
1332 /* XXX: separate device handlers from system ones */
1337 QLIST_FOREACH(ioh, &io_handlers, next) {
1341 (!ioh->fd_read_poll ||
1342 ioh->fd_read_poll(ioh->opaque) != 0)) {
1343 FD_SET(ioh->fd, &rfds);
1347 if (ioh->fd_write) {
1348 FD_SET(ioh->fd, &wfds);
1354 tv.tv_sec = timeout / 1000;
1355 tv.tv_usec = (timeout % 1000) * 1000;
1357 slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
1359 qemu_mutex_unlock_iothread();
1360 ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
1361 qemu_mutex_lock_iothread();
1363 IOHandlerRecord *pioh;
1365 QLIST_FOREACH_SAFE(ioh, &io_handlers, next, pioh) {
1366 if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {
1367 ioh->fd_read(ioh->opaque);
1369 if (!ioh->deleted && ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) {
1370 ioh->fd_write(ioh->opaque);
1373 /* Do this last in case read/write handlers marked it for deletion */
1375 QLIST_REMOVE(ioh, next);
1381 slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));
1383 qemu_run_all_timers();
1385 /* Check bottom-halves last in case any of the earlier events triggered
1391 static int vm_can_run(void)
1393 if (powerdown_requested)
1395 if (reset_requested)
1397 if (shutdown_requested)
1399 if (debug_requested)
1404 qemu_irq qemu_system_powerdown;
1406 static void main_loop(void)
1410 qemu_main_loop_start();
1414 bool nonblocking = false;
1415 #ifdef CONFIG_PROFILER
1418 #ifndef CONFIG_IOTHREAD
1419 nonblocking = cpu_exec_all();
1421 #ifdef CONFIG_PROFILER
1422 ti = profile_getclock();
1424 main_loop_wait(nonblocking);
1425 #ifdef CONFIG_PROFILER
1426 dev_time += profile_getclock() - ti;
1428 } while (vm_can_run());
1430 if ((r = qemu_debug_requested())) {
1433 if (qemu_shutdown_requested()) {
1434 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
1441 if (qemu_reset_requested()) {
1443 qemu_system_reset();
1446 if (qemu_powerdown_requested()) {
1447 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
1448 qemu_irq_raise(qemu_system_powerdown);
1450 if ((r = qemu_vmstop_requested())) {
1458 static void version(void)
1460 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
1463 static void help(int exitcode)
1465 const char *options_help =
1466 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1468 #define DEFHEADING(text) stringify(text) "\n"
1469 #include "qemu-options.def"
1475 printf("usage: %s [options] [disk_image]\n"
1477 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1480 "During emulation, the following keys are useful:\n"
1481 "ctrl-alt-f toggle full screen\n"
1482 "ctrl-alt-n switch to virtual console 'n'\n"
1483 "ctrl-alt toggle mouse and keyboard grab\n"
1485 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1491 #define HAS_ARG 0x0001
1493 typedef struct QEMUOption {
1500 static const QEMUOption qemu_options[] = {
1501 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1502 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1503 { option, opt_arg, opt_enum, arch_mask },
1504 #define DEFHEADING(text)
1505 #include "qemu-options.def"
1511 static void select_vgahw (const char *p)
1516 vga_interface_type = VGA_NONE;
1517 if (strstart(p, "std", &opts)) {
1518 vga_interface_type = VGA_STD;
1519 } else if (strstart(p, "cirrus", &opts)) {
1520 vga_interface_type = VGA_CIRRUS;
1521 } else if (strstart(p, "vmware", &opts)) {
1522 vga_interface_type = VGA_VMWARE;
1523 } else if (strstart(p, "xenfb", &opts)) {
1524 vga_interface_type = VGA_XENFB;
1525 } else if (strstart(p, "qxl", &opts)) {
1526 vga_interface_type = VGA_QXL;
1527 } else if (!strstart(p, "none", &opts)) {
1529 fprintf(stderr, "Unknown vga type: %s\n", p);
1533 const char *nextopt;
1535 if (strstart(opts, ",retrace=", &nextopt)) {
1537 if (strstart(opts, "dumb", &nextopt))
1538 vga_retrace_method = VGA_RETRACE_DUMB;
1539 else if (strstart(opts, "precise", &nextopt))
1540 vga_retrace_method = VGA_RETRACE_PRECISE;
1541 else goto invalid_vga;
1542 } else goto invalid_vga;
1547 static int balloon_parse(const char *arg)
1551 if (strcmp(arg, "none") == 0) {
1555 if (!strncmp(arg, "virtio", 6)) {
1556 if (arg[6] == ',') {
1557 /* have params -> parse them */
1558 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
1562 /* create empty opts */
1563 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
1565 qemu_opt_set(opts, "driver", "virtio-balloon-pci");
1572 char *qemu_find_file(int type, const char *name)
1578 /* If name contains path separators then try it as a straight path. */
1579 if ((strchr(name, '/') || strchr(name, '\\'))
1580 && access(name, R_OK) == 0) {
1581 return qemu_strdup(name);
1584 case QEMU_FILE_TYPE_BIOS:
1587 case QEMU_FILE_TYPE_KEYMAP:
1588 subdir = "keymaps/";
1593 len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
1594 buf = qemu_mallocz(len);
1595 snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
1596 if (access(buf, R_OK)) {
1603 static int device_help_func(QemuOpts *opts, void *opaque)
1605 return qdev_device_help(opts);
1608 static int device_init_func(QemuOpts *opts, void *opaque)
1612 dev = qdev_device_add(opts);
1618 static int chardev_init_func(QemuOpts *opts, void *opaque)
1620 CharDriverState *chr;
1622 chr = qemu_chr_open_opts(opts, NULL);
1628 #ifdef CONFIG_VIRTFS
1629 static int fsdev_init_func(QemuOpts *opts, void *opaque)
1632 ret = qemu_fsdev_add(opts);
1638 static int mon_init_func(QemuOpts *opts, void *opaque)
1640 CharDriverState *chr;
1641 const char *chardev;
1645 mode = qemu_opt_get(opts, "mode");
1649 if (strcmp(mode, "readline") == 0) {
1650 flags = MONITOR_USE_READLINE;
1651 } else if (strcmp(mode, "control") == 0) {
1652 flags = MONITOR_USE_CONTROL;
1654 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
1658 if (qemu_opt_get_bool(opts, "pretty", 0))
1659 flags |= MONITOR_USE_PRETTY;
1661 if (qemu_opt_get_bool(opts, "default", 0))
1662 flags |= MONITOR_IS_DEFAULT;
1664 chardev = qemu_opt_get(opts, "chardev");
1665 chr = qemu_chr_find(chardev);
1667 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
1671 monitor_init(chr, flags);
1675 static void monitor_parse(const char *optarg, const char *mode)
1677 static int monitor_device_index = 0;
1683 if (strstart(optarg, "chardev:", &p)) {
1684 snprintf(label, sizeof(label), "%s", p);
1686 snprintf(label, sizeof(label), "compat_monitor%d",
1687 monitor_device_index);
1688 if (monitor_device_index == 0) {
1691 opts = qemu_chr_parse_compat(label, optarg);
1693 fprintf(stderr, "parse error: %s\n", optarg);
1698 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1);
1700 fprintf(stderr, "duplicate chardev: %s\n", label);
1703 qemu_opt_set(opts, "mode", mode);
1704 qemu_opt_set(opts, "chardev", label);
1706 qemu_opt_set(opts, "default", "on");
1707 monitor_device_index++;
1710 struct device_config {
1712 DEV_USB, /* -usbdevice */
1714 DEV_SERIAL, /* -serial */
1715 DEV_PARALLEL, /* -parallel */
1716 DEV_VIRTCON, /* -virtioconsole */
1717 DEV_DEBUGCON, /* -debugcon */
1719 const char *cmdline;
1720 QTAILQ_ENTRY(device_config) next;
1722 QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
1724 static void add_device_config(int type, const char *cmdline)
1726 struct device_config *conf;
1728 conf = qemu_mallocz(sizeof(*conf));
1730 conf->cmdline = cmdline;
1731 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
1734 static int foreach_device_config(int type, int (*func)(const char *cmdline))
1736 struct device_config *conf;
1739 QTAILQ_FOREACH(conf, &device_configs, next) {
1740 if (conf->type != type)
1742 rc = func(conf->cmdline);
1749 static int serial_parse(const char *devname)
1751 static int index = 0;
1754 if (strcmp(devname, "none") == 0)
1756 if (index == MAX_SERIAL_PORTS) {
1757 fprintf(stderr, "qemu: too many serial ports\n");
1760 snprintf(label, sizeof(label), "serial%d", index);
1761 serial_hds[index] = qemu_chr_open(label, devname, NULL);
1762 if (!serial_hds[index]) {
1763 fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
1764 devname, strerror(errno));
1771 static int parallel_parse(const char *devname)
1773 static int index = 0;
1776 if (strcmp(devname, "none") == 0)
1778 if (index == MAX_PARALLEL_PORTS) {
1779 fprintf(stderr, "qemu: too many parallel ports\n");
1782 snprintf(label, sizeof(label), "parallel%d", index);
1783 parallel_hds[index] = qemu_chr_open(label, devname, NULL);
1784 if (!parallel_hds[index]) {
1785 fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
1786 devname, strerror(errno));
1793 static int virtcon_parse(const char *devname)
1795 QemuOptsList *device = qemu_find_opts("device");
1796 static int index = 0;
1798 QemuOpts *bus_opts, *dev_opts;
1800 if (strcmp(devname, "none") == 0)
1802 if (index == MAX_VIRTIO_CONSOLES) {
1803 fprintf(stderr, "qemu: too many virtio consoles\n");
1807 bus_opts = qemu_opts_create(device, NULL, 0);
1808 qemu_opt_set(bus_opts, "driver", "virtio-serial");
1810 dev_opts = qemu_opts_create(device, NULL, 0);
1811 qemu_opt_set(dev_opts, "driver", "virtconsole");
1813 snprintf(label, sizeof(label), "virtcon%d", index);
1814 virtcon_hds[index] = qemu_chr_open(label, devname, NULL);
1815 if (!virtcon_hds[index]) {
1816 fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
1817 devname, strerror(errno));
1820 qemu_opt_set(dev_opts, "chardev", label);
1826 static int debugcon_parse(const char *devname)
1830 if (!qemu_chr_open("debugcon", devname, NULL)) {
1833 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1835 fprintf(stderr, "qemu: already have a debugcon device\n");
1838 qemu_opt_set(opts, "driver", "isa-debugcon");
1839 qemu_opt_set(opts, "chardev", "debugcon");
1843 void qemu_add_exit_notifier(Notifier *notify)
1845 notifier_list_add(&exit_notifiers, notify);
1848 void qemu_remove_exit_notifier(Notifier *notify)
1850 notifier_list_remove(&exit_notifiers, notify);
1853 static void qemu_run_exit_notifiers(void)
1855 notifier_list_notify(&exit_notifiers);
1858 void qemu_add_machine_init_done_notifier(Notifier *notify)
1860 notifier_list_add(&machine_init_done_notifiers, notify);
1863 static void qemu_run_machine_init_done_notifiers(void)
1865 notifier_list_notify(&machine_init_done_notifiers);
1868 static const QEMUOption *lookup_opt(int argc, char **argv,
1869 const char **poptarg, int *poptind)
1871 const QEMUOption *popt;
1872 int optind = *poptind;
1873 char *r = argv[optind];
1876 loc_set_cmdline(argv, optind, 1);
1878 /* Treat --foo the same as -foo. */
1881 popt = qemu_options;
1884 error_report("invalid option");
1887 if (!strcmp(popt->name, r + 1))
1891 if (popt->flags & HAS_ARG) {
1892 if (optind >= argc) {
1893 error_report("requires an argument");
1896 optarg = argv[optind++];
1897 loc_set_cmdline(argv, optind - 2, 2);
1908 int main(int argc, char **argv, char **envp)
1910 const char *gdbstub_dev = NULL;
1912 int snapshot, linux_boot;
1913 const char *icount_option = NULL;
1914 const char *initrd_filename;
1915 const char *kernel_filename, *kernel_cmdline;
1916 char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
1918 DisplayChangeListener *dcl;
1919 int cyls, heads, secs, translation;
1920 QemuOpts *hda_opts = NULL, *opts;
1921 QemuOptsList *olist;
1924 const char *loadvm = NULL;
1925 QEMUMachine *machine;
1926 const char *cpu_model;
1928 const char *pid_file = NULL;
1929 const char *incoming = NULL;
1930 int show_vnc_port = 0;
1933 #ifdef CONFIG_SIMPLE_TRACE
1934 const char *trace_file = NULL;
1936 atexit(qemu_run_exit_notifiers);
1937 error_set_progname(argv[0]);
1941 qemu_cache_utils_init(envp);
1943 QLIST_INIT (&vm_change_state_head);
1944 os_setup_early_signal_handling();
1946 module_call_init(MODULE_INIT_MACHINE);
1947 machine = find_default_machine();
1949 initrd_filename = NULL;
1952 kernel_filename = NULL;
1953 kernel_cmdline = "";
1954 cyls = heads = secs = 0;
1955 translation = BIOS_ATA_TRANSLATION_AUTO;
1957 for (i = 0; i < MAX_NODES; i++) {
1959 node_cpumask[i] = 0;
1968 /* first pass of option parsing */
1970 while (optind < argc) {
1971 if (argv[optind][0] != '-') {
1976 const QEMUOption *popt;
1978 popt = lookup_opt(argc, argv, &optarg, &optind);
1979 switch (popt->index) {
1980 case QEMU_OPTION_nodefconfig:
1990 ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
1991 if (ret < 0 && ret != -ENOENT) {
1995 ret = qemu_read_config_file(arch_config_name);
1996 if (ret < 0 && ret != -ENOENT) {
2002 /* second pass of option parsing */
2007 if (argv[optind][0] != '-') {
2008 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
2010 const QEMUOption *popt;
2012 popt = lookup_opt(argc, argv, &optarg, &optind);
2013 if (!(popt->arch_mask & arch_type)) {
2014 printf("Option %s not supported for this target\n", popt->name);
2017 switch(popt->index) {
2019 machine = find_machine(optarg);
2022 printf("Supported machines are:\n");
2023 for(m = first_machine; m != NULL; m = m->next) {
2025 printf("%-10s %s (alias of %s)\n",
2026 m->alias, m->desc, m->name);
2027 printf("%-10s %s%s\n",
2029 m->is_default ? " (default)" : "");
2031 exit(*optarg != '?');
2034 case QEMU_OPTION_cpu:
2035 /* hw initialization will check this */
2036 if (*optarg == '?') {
2037 list_cpus(stdout, &fprintf, optarg);
2043 case QEMU_OPTION_initrd:
2044 initrd_filename = optarg;
2046 case QEMU_OPTION_hda:
2050 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2052 snprintf(buf, sizeof(buf),
2053 "%s,cyls=%d,heads=%d,secs=%d%s",
2054 HD_OPTS , cyls, heads, secs,
2055 translation == BIOS_ATA_TRANSLATION_LBA ?
2057 translation == BIOS_ATA_TRANSLATION_NONE ?
2058 ",trans=none" : "");
2059 drive_add(IF_DEFAULT, 0, optarg, buf);
2062 case QEMU_OPTION_hdb:
2063 case QEMU_OPTION_hdc:
2064 case QEMU_OPTION_hdd:
2065 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2068 case QEMU_OPTION_drive:
2071 case QEMU_OPTION_set:
2072 if (qemu_set_option(optarg) != 0)
2075 case QEMU_OPTION_global:
2076 if (qemu_global_option(optarg) != 0)
2079 case QEMU_OPTION_mtdblock:
2080 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
2082 case QEMU_OPTION_sd:
2083 drive_add(IF_SD, 0, optarg, SD_OPTS);
2085 case QEMU_OPTION_pflash:
2086 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
2088 case QEMU_OPTION_snapshot:
2091 case QEMU_OPTION_hdachs:
2095 cyls = strtol(p, (char **)&p, 0);
2096 if (cyls < 1 || cyls > 16383)
2101 heads = strtol(p, (char **)&p, 0);
2102 if (heads < 1 || heads > 16)
2107 secs = strtol(p, (char **)&p, 0);
2108 if (secs < 1 || secs > 63)
2112 if (!strcmp(p, "none"))
2113 translation = BIOS_ATA_TRANSLATION_NONE;
2114 else if (!strcmp(p, "lba"))
2115 translation = BIOS_ATA_TRANSLATION_LBA;
2116 else if (!strcmp(p, "auto"))
2117 translation = BIOS_ATA_TRANSLATION_AUTO;
2120 } else if (*p != '\0') {
2122 fprintf(stderr, "qemu: invalid physical CHS format\n");
2125 if (hda_opts != NULL) {
2127 snprintf(num, sizeof(num), "%d", cyls);
2128 qemu_opt_set(hda_opts, "cyls", num);
2129 snprintf(num, sizeof(num), "%d", heads);
2130 qemu_opt_set(hda_opts, "heads", num);
2131 snprintf(num, sizeof(num), "%d", secs);
2132 qemu_opt_set(hda_opts, "secs", num);
2133 if (translation == BIOS_ATA_TRANSLATION_LBA)
2134 qemu_opt_set(hda_opts, "trans", "lba");
2135 if (translation == BIOS_ATA_TRANSLATION_NONE)
2136 qemu_opt_set(hda_opts, "trans", "none");
2140 case QEMU_OPTION_numa:
2141 if (nb_numa_nodes >= MAX_NODES) {
2142 fprintf(stderr, "qemu: too many NUMA nodes\n");
2147 case QEMU_OPTION_nographic:
2148 display_type = DT_NOGRAPHIC;
2150 #ifdef CONFIG_CURSES
2151 case QEMU_OPTION_curses:
2152 display_type = DT_CURSES;
2155 case QEMU_OPTION_portrait:
2158 case QEMU_OPTION_kernel:
2159 kernel_filename = optarg;
2161 case QEMU_OPTION_append:
2162 kernel_cmdline = optarg;
2164 case QEMU_OPTION_cdrom:
2165 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
2167 case QEMU_OPTION_boot:
2169 static const char * const params[] = {
2170 "order", "once", "menu", NULL
2172 char buf[sizeof(boot_devices)];
2173 char *standard_boot_devices;
2176 if (!strchr(optarg, '=')) {
2178 pstrcpy(buf, sizeof(buf), optarg);
2179 } else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
2181 "qemu: unknown boot parameter '%s' in '%s'\n",
2187 get_param_value(buf, sizeof(buf), "order", optarg)) {
2188 validate_bootdevices(buf);
2189 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2192 if (get_param_value(buf, sizeof(buf),
2194 validate_bootdevices(buf);
2195 standard_boot_devices = qemu_strdup(boot_devices);
2196 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2197 qemu_register_reset(restore_boot_devices,
2198 standard_boot_devices);
2200 if (get_param_value(buf, sizeof(buf),
2202 if (!strcmp(buf, "on")) {
2204 } else if (!strcmp(buf, "off")) {
2208 "qemu: invalid option value '%s'\n",
2216 case QEMU_OPTION_fda:
2217 case QEMU_OPTION_fdb:
2218 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2221 case QEMU_OPTION_no_fd_bootchk:
2224 case QEMU_OPTION_netdev:
2225 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
2229 case QEMU_OPTION_net:
2230 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
2235 case QEMU_OPTION_tftp:
2236 legacy_tftp_prefix = optarg;
2238 case QEMU_OPTION_bootp:
2239 legacy_bootp_filename = optarg;
2241 case QEMU_OPTION_redir:
2242 if (net_slirp_redir(optarg) < 0)
2246 case QEMU_OPTION_bt:
2247 add_device_config(DEV_BT, optarg);
2249 case QEMU_OPTION_audio_help:
2250 if (!(audio_available())) {
2251 printf("Option %s not supported for this target\n", popt->name);
2257 case QEMU_OPTION_soundhw:
2258 if (!(audio_available())) {
2259 printf("Option %s not supported for this target\n", popt->name);
2262 select_soundhw (optarg);
2267 case QEMU_OPTION_version:
2271 case QEMU_OPTION_m: {
2274 value = strtosz(optarg, NULL);
2276 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
2280 /* On 32-bit hosts, QEMU is limited by virtual address space */
2281 if (value > (2047 << 20) && HOST_LONG_BITS == 32) {
2282 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
2285 if (value != (uint64_t)(ram_addr_t)value) {
2286 fprintf(stderr, "qemu: ram size too large\n");
2292 case QEMU_OPTION_mempath:
2296 case QEMU_OPTION_mem_prealloc:
2301 set_cpu_log(optarg);
2304 gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT;
2306 case QEMU_OPTION_gdb:
2307 gdbstub_dev = optarg;
2312 case QEMU_OPTION_bios:
2315 case QEMU_OPTION_singlestep:
2322 keyboard_layout = optarg;
2324 case QEMU_OPTION_localtime:
2327 case QEMU_OPTION_vga:
2328 select_vgahw (optarg);
2335 w = strtol(p, (char **)&p, 10);
2338 fprintf(stderr, "qemu: invalid resolution or depth\n");
2344 h = strtol(p, (char **)&p, 10);
2349 depth = strtol(p, (char **)&p, 10);
2350 if (depth != 8 && depth != 15 && depth != 16 &&
2351 depth != 24 && depth != 32)
2353 } else if (*p == '\0') {
2354 depth = graphic_depth;
2361 graphic_depth = depth;
2364 case QEMU_OPTION_echr:
2367 term_escape_char = strtol(optarg, &r, 0);
2369 printf("Bad argument to echr\n");
2372 case QEMU_OPTION_monitor:
2373 monitor_parse(optarg, "readline");
2374 default_monitor = 0;
2376 case QEMU_OPTION_qmp:
2377 monitor_parse(optarg, "control");
2378 default_monitor = 0;
2380 case QEMU_OPTION_mon:
2381 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
2385 default_monitor = 0;
2387 case QEMU_OPTION_chardev:
2388 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
2393 case QEMU_OPTION_fsdev:
2394 olist = qemu_find_opts("fsdev");
2396 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
2399 opts = qemu_opts_parse(olist, optarg, 1);
2401 fprintf(stderr, "parse error: %s\n", optarg);
2405 case QEMU_OPTION_virtfs: {
2406 char *arg_fsdev = NULL;
2407 char *arg_9p = NULL;
2410 olist = qemu_find_opts("virtfs");
2412 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
2415 opts = qemu_opts_parse(olist, optarg, 1);
2417 fprintf(stderr, "parse error: %s\n", optarg);
2421 if (qemu_opt_get(opts, "fstype") == NULL ||
2422 qemu_opt_get(opts, "mount_tag") == NULL ||
2423 qemu_opt_get(opts, "path") == NULL ||
2424 qemu_opt_get(opts, "security_model") == NULL) {
2425 fprintf(stderr, "Usage: -virtfs fstype,path=/share_path/,"
2426 "security_model=[mapped|passthrough|none],"
2431 len = strlen(",id=,path=,security_model=");
2432 len += strlen(qemu_opt_get(opts, "fstype"));
2433 len += strlen(qemu_opt_get(opts, "mount_tag"));
2434 len += strlen(qemu_opt_get(opts, "path"));
2435 len += strlen(qemu_opt_get(opts, "security_model"));
2436 arg_fsdev = qemu_malloc((len + 1) * sizeof(*arg_fsdev));
2438 snprintf(arg_fsdev, (len + 1) * sizeof(*arg_fsdev),
2439 "%s,id=%s,path=%s,security_model=%s",
2440 qemu_opt_get(opts, "fstype"),
2441 qemu_opt_get(opts, "mount_tag"),
2442 qemu_opt_get(opts, "path"),
2443 qemu_opt_get(opts, "security_model"));
2445 len = strlen("virtio-9p-pci,fsdev=,mount_tag=");
2446 len += 2*strlen(qemu_opt_get(opts, "mount_tag"));
2447 arg_9p = qemu_malloc((len + 1) * sizeof(*arg_9p));
2449 snprintf(arg_9p, (len + 1) * sizeof(*arg_9p),
2450 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2451 qemu_opt_get(opts, "mount_tag"),
2452 qemu_opt_get(opts, "mount_tag"));
2454 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev, 1)) {
2455 fprintf(stderr, "parse error [fsdev]: %s\n", optarg);
2459 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p, 1)) {
2460 fprintf(stderr, "parse error [device]: %s\n", optarg);
2464 qemu_free(arg_fsdev);
2468 case QEMU_OPTION_serial:
2469 add_device_config(DEV_SERIAL, optarg);
2471 if (strncmp(optarg, "mon:", 4) == 0) {
2472 default_monitor = 0;
2475 case QEMU_OPTION_watchdog:
2478 "qemu: only one watchdog option may be given\n");
2483 case QEMU_OPTION_watchdog_action:
2484 if (select_watchdog_action(optarg) == -1) {
2485 fprintf(stderr, "Unknown -watchdog-action parameter\n");
2489 case QEMU_OPTION_virtiocon:
2490 add_device_config(DEV_VIRTCON, optarg);
2491 default_virtcon = 0;
2492 if (strncmp(optarg, "mon:", 4) == 0) {
2493 default_monitor = 0;
2496 case QEMU_OPTION_parallel:
2497 add_device_config(DEV_PARALLEL, optarg);
2498 default_parallel = 0;
2499 if (strncmp(optarg, "mon:", 4) == 0) {
2500 default_monitor = 0;
2503 case QEMU_OPTION_debugcon:
2504 add_device_config(DEV_DEBUGCON, optarg);
2506 case QEMU_OPTION_loadvm:
2509 case QEMU_OPTION_full_screen:
2513 case QEMU_OPTION_no_frame:
2516 case QEMU_OPTION_alt_grab:
2519 case QEMU_OPTION_ctrl_grab:
2522 case QEMU_OPTION_no_quit:
2525 case QEMU_OPTION_sdl:
2526 display_type = DT_SDL;
2529 case QEMU_OPTION_pidfile:
2532 case QEMU_OPTION_win2k_hack:
2533 win2k_install_hack = 1;
2535 case QEMU_OPTION_rtc_td_hack:
2538 case QEMU_OPTION_acpitable:
2539 do_acpitable_option(optarg);
2541 case QEMU_OPTION_smbios:
2542 do_smbios_option(optarg);
2544 case QEMU_OPTION_enable_kvm:
2547 case QEMU_OPTION_usb:
2550 case QEMU_OPTION_usbdevice:
2552 add_device_config(DEV_USB, optarg);
2554 case QEMU_OPTION_device:
2555 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
2559 case QEMU_OPTION_smp:
2562 fprintf(stderr, "Invalid number of CPUs\n");
2565 if (max_cpus < smp_cpus) {
2566 fprintf(stderr, "maxcpus must be equal to or greater than "
2570 if (max_cpus > 255) {
2571 fprintf(stderr, "Unsupported number of maxcpus\n");
2575 case QEMU_OPTION_vnc:
2577 vnc_display = optarg;
2579 case QEMU_OPTION_no_acpi:
2582 case QEMU_OPTION_no_hpet:
2585 case QEMU_OPTION_balloon:
2586 if (balloon_parse(optarg) < 0) {
2587 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
2591 case QEMU_OPTION_no_reboot:
2594 case QEMU_OPTION_no_shutdown:
2597 case QEMU_OPTION_show_cursor:
2600 case QEMU_OPTION_uuid:
2601 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
2602 fprintf(stderr, "Fail to parse UUID string."
2603 " Wrong format.\n");
2607 case QEMU_OPTION_option_rom:
2608 if (nb_option_roms >= MAX_OPTION_ROMS) {
2609 fprintf(stderr, "Too many option ROMs\n");
2612 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
2613 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
2614 option_rom[nb_option_roms].bootindex =
2615 qemu_opt_get_number(opts, "bootindex", -1);
2616 if (!option_rom[nb_option_roms].name) {
2617 fprintf(stderr, "Option ROM file is not specified\n");
2622 case QEMU_OPTION_semihosting:
2623 semihosting_enabled = 1;
2625 case QEMU_OPTION_name:
2626 qemu_name = qemu_strdup(optarg);
2628 char *p = strchr(qemu_name, ',');
2631 if (strncmp(p, "process=", 8)) {
2632 fprintf(stderr, "Unknown subargument %s to -name\n", p);
2636 os_set_proc_name(p);
2640 case QEMU_OPTION_prom_env:
2641 if (nb_prom_envs >= MAX_PROM_ENVS) {
2642 fprintf(stderr, "Too many prom variables\n");
2645 prom_envs[nb_prom_envs] = optarg;
2648 case QEMU_OPTION_old_param:
2651 case QEMU_OPTION_clock:
2652 configure_alarms(optarg);
2654 case QEMU_OPTION_startdate:
2655 configure_rtc_date_offset(optarg, 1);
2657 case QEMU_OPTION_rtc:
2658 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
2662 configure_rtc(opts);
2664 case QEMU_OPTION_tb_size:
2665 tb_size = strtol(optarg, NULL, 0);
2669 case QEMU_OPTION_icount:
2670 icount_option = optarg;
2672 case QEMU_OPTION_incoming:
2674 incoming_expected = true;
2676 case QEMU_OPTION_nodefaults:
2678 default_parallel = 0;
2679 default_virtcon = 0;
2680 default_monitor = 0;
2687 case QEMU_OPTION_xen_domid:
2688 if (!(xen_available())) {
2689 printf("Option %s not supported for this target\n", popt->name);
2692 xen_domid = atoi(optarg);
2694 case QEMU_OPTION_xen_create:
2695 if (!(xen_available())) {
2696 printf("Option %s not supported for this target\n", popt->name);
2699 xen_mode = XEN_CREATE;
2701 case QEMU_OPTION_xen_attach:
2702 if (!(xen_available())) {
2703 printf("Option %s not supported for this target\n", popt->name);
2706 xen_mode = XEN_ATTACH;
2708 #ifdef CONFIG_SIMPLE_TRACE
2709 case QEMU_OPTION_trace:
2710 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
2712 trace_file = qemu_opt_get(opts, "file");
2716 case QEMU_OPTION_readconfig:
2718 int ret = qemu_read_config_file(optarg);
2720 fprintf(stderr, "read config %s: %s\n", optarg,
2726 case QEMU_OPTION_spice:
2727 olist = qemu_find_opts("spice");
2729 fprintf(stderr, "spice is not supported by this qemu build.\n");
2732 opts = qemu_opts_parse(olist, optarg, 0);
2734 fprintf(stderr, "parse error: %s\n", optarg);
2738 case QEMU_OPTION_writeconfig:
2741 if (strcmp(optarg, "-") == 0) {
2744 fp = fopen(optarg, "w");
2746 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
2750 qemu_config_write(fp);
2755 os_parse_cmd_args(popt->index, optarg);
2761 /* If no data_dir is specified then try to find it relative to the
2764 data_dir = os_find_datadir(argv[0]);
2766 /* If all else fails use the install patch specified when building. */
2768 data_dir = CONFIG_QEMU_DATADIR;
2771 #ifdef CONFIG_SIMPLE_TRACE
2773 * Set the trace file name, if specified.
2775 st_set_trace_file(trace_file);
2778 * Default to max_cpus = smp_cpus, in case the user doesn't
2779 * specify a max_cpus value.
2782 max_cpus = smp_cpus;
2784 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
2785 if (smp_cpus > machine->max_cpus) {
2786 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
2787 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
2792 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
2793 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
2795 if (machine->no_serial) {
2798 if (machine->no_parallel) {
2799 default_parallel = 0;
2801 if (!machine->use_virtcon) {
2802 default_virtcon = 0;
2804 if (machine->no_vga) {
2807 if (machine->no_floppy) {
2810 if (machine->no_cdrom) {
2813 if (machine->no_sdcard) {
2817 if (display_type == DT_NOGRAPHIC) {
2818 if (default_parallel)
2819 add_device_config(DEV_PARALLEL, "null");
2820 if (default_serial && default_monitor) {
2821 add_device_config(DEV_SERIAL, "mon:stdio");
2822 } else if (default_virtcon && default_monitor) {
2823 add_device_config(DEV_VIRTCON, "mon:stdio");
2826 add_device_config(DEV_SERIAL, "stdio");
2827 if (default_virtcon)
2828 add_device_config(DEV_VIRTCON, "stdio");
2829 if (default_monitor)
2830 monitor_parse("stdio", "readline");
2834 add_device_config(DEV_SERIAL, "vc:80Cx24C");
2835 if (default_parallel)
2836 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
2837 if (default_monitor)
2838 monitor_parse("vc:80Cx24C", "readline");
2839 if (default_virtcon)
2840 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
2843 vga_interface_type = VGA_CIRRUS;
2847 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
2849 #ifdef CONFIG_VIRTFS
2850 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
2857 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
2863 int ret = kvm_init();
2865 if (!kvm_available()) {
2866 printf("KVM not supported for this target\n");
2868 fprintf(stderr, "failed to initialize KVM: %s\n", strerror(-ret));
2874 if (qemu_init_main_loop()) {
2875 fprintf(stderr, "qemu_init_main_loop failed\n");
2878 linux_boot = (kernel_filename != NULL);
2880 if (!linux_boot && *kernel_cmdline != '\0') {
2881 fprintf(stderr, "-append only allowed with -kernel option\n");
2885 if (!linux_boot && initrd_filename != NULL) {
2886 fprintf(stderr, "-initrd only allowed with -kernel option\n");
2890 os_set_line_buffering();
2892 if (init_timer_alarm() < 0) {
2893 fprintf(stderr, "could not initialize alarm timer\n");
2896 configure_icount(icount_option);
2898 if (net_init_clients() < 0) {
2902 /* init the bluetooth world */
2903 if (foreach_device_config(DEV_BT, bt_parse))
2906 /* init the memory */
2908 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
2910 /* init the dynamic translator */
2911 cpu_exec_init_all(tb_size * 1024 * 1024);
2913 bdrv_init_with_whitelist();
2917 /* open the virtual block devices */
2919 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
2920 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
2923 default_drive(default_cdrom, snapshot, machine->use_scsi,
2924 IF_DEFAULT, 2, CDROM_OPTS);
2925 default_drive(default_floppy, snapshot, machine->use_scsi,
2926 IF_FLOPPY, 0, FD_OPTS);
2927 default_drive(default_sdcard, snapshot, machine->use_scsi,
2930 register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL,
2933 if (nb_numa_nodes > 0) {
2936 if (nb_numa_nodes > smp_cpus) {
2937 nb_numa_nodes = smp_cpus;
2940 /* If no memory size if given for any node, assume the default case
2941 * and distribute the available memory equally across all nodes
2943 for (i = 0; i < nb_numa_nodes; i++) {
2944 if (node_mem[i] != 0)
2947 if (i == nb_numa_nodes) {
2948 uint64_t usedmem = 0;
2950 /* On Linux, the each node's border has to be 8MB aligned,
2951 * the final node gets the rest.
2953 for (i = 0; i < nb_numa_nodes - 1; i++) {
2954 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
2955 usedmem += node_mem[i];
2957 node_mem[i] = ram_size - usedmem;
2960 for (i = 0; i < nb_numa_nodes; i++) {
2961 if (node_cpumask[i] != 0)
2964 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2965 * must cope with this anyway, because there are BIOSes out there in
2966 * real machines which also use this scheme.
2968 if (i == nb_numa_nodes) {
2969 for (i = 0; i < smp_cpus; i++) {
2970 node_cpumask[i % nb_numa_nodes] |= 1 << i;
2975 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
2979 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
2981 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
2983 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
2985 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
2988 module_call_init(MODULE_INIT_DEVICE);
2990 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0)
2994 i = select_watchdog(watchdog);
2996 exit (i == 1 ? 1 : 0);
2999 if (machine->compat_props) {
3000 qdev_prop_register_global_list(machine->compat_props);
3004 machine->init(ram_size, boot_devices,
3005 kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
3007 cpu_synchronize_all_post_init();
3009 /* must be after terminal init, SDL library changes signal handlers */
3010 os_setup_signal_handling();
3014 current_machine = machine;
3016 /* init USB devices */
3018 if (foreach_device_config(DEV_USB, usb_parse) < 0)
3022 /* init generic devices */
3023 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
3026 net_check_clients();
3028 /* just use the first displaystate for the moment */
3029 ds = get_displaystate();
3033 if (display_type == DT_DEFAULT && !display_remote) {
3034 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3035 display_type = DT_SDL;
3037 vnc_display = "localhost:0,to=99";
3043 /* init local displays */
3044 switch (display_type) {
3047 #if defined(CONFIG_CURSES)
3049 curses_display_init(ds, full_screen);
3052 #if defined(CONFIG_SDL)
3054 sdl_display_init(ds, full_screen, no_frame);
3056 #elif defined(CONFIG_COCOA)
3058 cocoa_display_init(ds, full_screen);
3065 /* init remote displays */
3067 vnc_display_init(ds);
3068 if (vnc_display_open(ds, vnc_display) < 0)
3071 if (show_vnc_port) {
3072 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
3076 if (using_spice && !qxl_enabled) {
3077 qemu_spice_display_init(ds);
3083 dcl = ds->listeners;
3084 while (dcl != NULL) {
3085 if (dcl->dpy_refresh != NULL) {
3086 ds->gui_timer = qemu_new_timer(rt_clock, gui_update, ds);
3087 qemu_mod_timer(ds->gui_timer, qemu_get_clock(rt_clock));
3092 if (ds->gui_timer == NULL) {
3093 nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL);
3094 qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock));
3096 text_consoles_set_display(ds);
3098 if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) {
3099 fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n",
3104 qdev_machine_creation_done();
3106 if (rom_load_all() != 0) {
3107 fprintf(stderr, "rom loading failed\n");
3111 /* TODO: once all bus devices are qdevified, this should be done
3112 * when bus is created by qdev.c */
3113 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
3114 qemu_run_machine_init_done_notifiers();
3116 qemu_system_reset();
3118 if (load_vmstate(loadvm) < 0) {
3124 int ret = qemu_start_incoming_migration(incoming);
3126 fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n",
3130 } else if (autostart) {