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>
53 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
55 #include <sys/sysctl.h>
64 #include <linux/ppdev.h>
65 #include <linux/parport.h>
69 #include <sys/ethernet.h>
70 #include <sys/sockio.h>
71 #include <netinet/arp.h>
72 #include <netinet/in_systm.h>
73 #include <netinet/ip.h>
74 #include <netinet/ip_icmp.h> // must come after ip.h
75 #include <netinet/udp.h>
76 #include <netinet/tcp.h>
84 #if defined(__OpenBSD__)
88 #if defined(CONFIG_VDE)
89 #include <libvdeplug.h>
97 #if defined(__APPLE__) || defined(main)
99 int qemu_main(int argc, char **argv, char **envp);
100 int main(int argc, char **argv)
102 return qemu_main(argc, argv, NULL);
105 #define main qemu_main
107 #endif /* CONFIG_SDL */
111 #define main qemu_main
112 #endif /* CONFIG_COCOA */
115 #include "hw/boards.h"
117 #include "hw/pcmcia.h"
122 #include "hw/watchdog.h"
123 #include "hw/smbios.h"
126 #include "hw/loader.h"
129 #include "net/slirp.h"
134 #include "qemu-timer.h"
135 #include "qemu-char.h"
136 #include "cache-utils.h"
138 #include "blockdev.h"
139 #include "block-migration.h"
141 #include "audio/audio.h"
142 #include "migration.h"
144 #include "qemu-option.h"
145 #include "qemu-config.h"
146 #include "qemu-objects.h"
147 #include "qemu-options.h"
149 #include "fsdev/qemu-fsdev.h"
154 #include "qemu_socket.h"
156 #include "slirp/libslirp.h"
159 #include "simpletrace.h"
160 #include "qemu-queue.h"
162 #include "arch_init.h"
164 #include "ui/qemu-spice.h"
167 //#define DEBUG_SLIRP
169 #define DEFAULT_RAM_SIZE 128
171 #define MAX_VIRTIO_CONSOLES 1
173 static const char *data_dir;
174 const char *bios_name = NULL;
175 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
176 DisplayType display_type = DT_DEFAULT;
177 int display_remote = 0;
178 const char* keyboard_layout = NULL;
180 const char *mem_path = NULL;
182 int mem_prealloc = 0; /* force preallocation of physical target memory */
185 NICInfo nd_table[MAX_NICS];
188 int incoming_expected; /* Started with -incoming and waiting for incoming */
189 static int rtc_utc = 1;
190 static int rtc_date_offset = -1; /* -1 means no change */
191 QEMUClock *rtc_clock;
192 int vga_interface_type = VGA_NONE;
193 static int full_screen = 0;
195 static int no_frame = 0;
198 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
199 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
200 CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
201 int win2k_install_hack = 0;
210 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 = suffix ? qemu_strdup(suffix) : NULL;
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 = qemu_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 /***********************************************************/
1026 /* machine registration */
1028 static QEMUMachine *first_machine = NULL;
1029 QEMUMachine *current_machine = NULL;
1031 int qemu_register_machine(QEMUMachine *m)
1034 pm = &first_machine;
1042 static QEMUMachine *find_machine(const char *name)
1046 for(m = first_machine; m != NULL; m = m->next) {
1047 if (!strcmp(m->name, name))
1049 if (m->alias && !strcmp(m->alias, name))
1055 static QEMUMachine *find_default_machine(void)
1059 for(m = first_machine; m != NULL; m = m->next) {
1060 if (m->is_default) {
1067 /***********************************************************/
1068 /* main execution loop */
1070 static void gui_update(void *opaque)
1072 uint64_t interval = GUI_REFRESH_INTERVAL;
1073 DisplayState *ds = opaque;
1074 DisplayChangeListener *dcl = ds->listeners;
1076 qemu_flush_coalesced_mmio_buffer();
1079 while (dcl != NULL) {
1080 if (dcl->gui_timer_interval &&
1081 dcl->gui_timer_interval < interval)
1082 interval = dcl->gui_timer_interval;
1085 qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock));
1088 static void nographic_update(void *opaque)
1090 uint64_t interval = GUI_REFRESH_INTERVAL;
1092 qemu_flush_coalesced_mmio_buffer();
1093 qemu_mod_timer(nographic_timer, interval + qemu_get_clock_ms(rt_clock));
1096 struct vm_change_state_entry {
1097 VMChangeStateHandler *cb;
1099 QLIST_ENTRY (vm_change_state_entry) entries;
1102 static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
1104 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1107 VMChangeStateEntry *e;
1109 e = qemu_mallocz(sizeof (*e));
1113 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
1117 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1119 QLIST_REMOVE (e, entries);
1123 void vm_state_notify(int running, int reason)
1125 VMChangeStateEntry *e;
1127 trace_vm_state_notify(running, reason);
1129 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
1130 e->cb(e->opaque, running, reason);
1139 vm_state_notify(1, 0);
1141 monitor_protocol_event(QEVENT_RESUME, NULL);
1145 /* reset/shutdown handler */
1147 typedef struct QEMUResetEntry {
1148 QTAILQ_ENTRY(QEMUResetEntry) entry;
1149 QEMUResetHandler *func;
1153 static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1154 QTAILQ_HEAD_INITIALIZER(reset_handlers);
1155 static int reset_requested;
1156 static int shutdown_requested, shutdown_signal = -1;
1157 static pid_t shutdown_pid;
1158 static int powerdown_requested;
1159 static int debug_requested;
1160 static int vmstop_requested;
1162 int qemu_shutdown_requested(void)
1164 int r = shutdown_requested;
1165 shutdown_requested = 0;
1169 void qemu_kill_report(void)
1171 if (shutdown_signal != -1) {
1172 fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal);
1173 if (shutdown_pid == 0) {
1174 /* This happens for eg ^C at the terminal, so it's worth
1175 * avoiding printing an odd message in that case.
1177 fputc('\n', stderr);
1179 fprintf(stderr, " from pid %d\n", shutdown_pid);
1181 shutdown_signal = -1;
1185 int qemu_reset_requested(void)
1187 int r = reset_requested;
1188 reset_requested = 0;
1192 int qemu_powerdown_requested(void)
1194 int r = powerdown_requested;
1195 powerdown_requested = 0;
1199 static int qemu_debug_requested(void)
1201 int r = debug_requested;
1202 debug_requested = 0;
1206 static int qemu_vmstop_requested(void)
1208 int r = vmstop_requested;
1209 vmstop_requested = 0;
1213 void qemu_register_reset(QEMUResetHandler *func, void *opaque)
1215 QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry));
1218 re->opaque = opaque;
1219 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
1222 void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
1226 QTAILQ_FOREACH(re, &reset_handlers, entry) {
1227 if (re->func == func && re->opaque == opaque) {
1228 QTAILQ_REMOVE(&reset_handlers, re, entry);
1235 void qemu_system_reset(void)
1237 QEMUResetEntry *re, *nre;
1239 /* reset all devices */
1240 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
1241 re->func(re->opaque);
1243 monitor_protocol_event(QEVENT_RESET, NULL);
1244 cpu_synchronize_all_post_reset();
1247 void qemu_system_reset_request(void)
1250 shutdown_requested = 1;
1252 reset_requested = 1;
1255 qemu_notify_event();
1258 void qemu_system_killed(int signal, pid_t pid)
1260 shutdown_signal = signal;
1262 qemu_system_shutdown_request();
1265 void qemu_system_shutdown_request(void)
1267 shutdown_requested = 1;
1268 qemu_notify_event();
1271 void qemu_system_powerdown_request(void)
1273 powerdown_requested = 1;
1274 qemu_notify_event();
1277 void qemu_system_debug_request(void)
1279 debug_requested = 1;
1280 qemu_notify_event();
1283 void qemu_system_vmstop_request(int reason)
1285 vmstop_requested = reason;
1286 qemu_notify_event();
1289 void main_loop_wait(int nonblocking)
1291 fd_set rfds, wfds, xfds;
1299 timeout = qemu_calculate_timeout();
1300 qemu_bh_update_timeout(&timeout);
1303 os_host_main_loop_wait(&timeout);
1305 tv.tv_sec = timeout / 1000;
1306 tv.tv_usec = (timeout % 1000) * 1000;
1308 /* poll any events */
1309 /* XXX: separate device handlers from system ones */
1314 qemu_iohandler_fill(&nfds, &rfds, &wfds, &xfds);
1315 slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
1317 qemu_mutex_unlock_iothread();
1318 ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
1319 qemu_mutex_lock_iothread();
1321 qemu_iohandler_poll(&rfds, &wfds, &xfds, ret);
1322 slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));
1324 qemu_run_all_timers();
1326 /* Check bottom-halves last in case any of the earlier events triggered
1332 #ifndef CONFIG_IOTHREAD
1333 static int vm_request_pending(void)
1335 return powerdown_requested ||
1337 shutdown_requested ||
1343 qemu_irq qemu_system_powerdown;
1345 static void main_loop(void)
1347 bool nonblocking = false;
1348 #ifdef CONFIG_PROFILER
1353 qemu_main_loop_start();
1356 #ifndef CONFIG_IOTHREAD
1357 nonblocking = cpu_exec_all();
1358 if (vm_request_pending()) {
1362 #ifdef CONFIG_PROFILER
1363 ti = profile_getclock();
1365 main_loop_wait(nonblocking);
1366 #ifdef CONFIG_PROFILER
1367 dev_time += profile_getclock() - ti;
1370 if (qemu_debug_requested()) {
1371 vm_stop(VMSTOP_DEBUG);
1373 if (qemu_shutdown_requested()) {
1375 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
1377 vm_stop(VMSTOP_SHUTDOWN);
1382 if (qemu_reset_requested()) {
1384 cpu_synchronize_all_states();
1385 qemu_system_reset();
1388 if (qemu_powerdown_requested()) {
1389 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
1390 qemu_irq_raise(qemu_system_powerdown);
1392 if ((r = qemu_vmstop_requested())) {
1400 static void version(void)
1402 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
1405 static void help(int exitcode)
1407 const char *options_help =
1408 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1410 #define DEFHEADING(text) stringify(text) "\n"
1411 #include "qemu-options.def"
1417 printf("usage: %s [options] [disk_image]\n"
1419 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1422 "During emulation, the following keys are useful:\n"
1423 "ctrl-alt-f toggle full screen\n"
1424 "ctrl-alt-n switch to virtual console 'n'\n"
1425 "ctrl-alt toggle mouse and keyboard grab\n"
1427 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1433 #define HAS_ARG 0x0001
1435 typedef struct QEMUOption {
1442 static const QEMUOption qemu_options[] = {
1443 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1444 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1445 { option, opt_arg, opt_enum, arch_mask },
1446 #define DEFHEADING(text)
1447 #include "qemu-options.def"
1453 static void select_vgahw (const char *p)
1458 vga_interface_type = VGA_NONE;
1459 if (strstart(p, "std", &opts)) {
1460 vga_interface_type = VGA_STD;
1461 } else if (strstart(p, "cirrus", &opts)) {
1462 vga_interface_type = VGA_CIRRUS;
1463 } else if (strstart(p, "vmware", &opts)) {
1464 vga_interface_type = VGA_VMWARE;
1465 } else if (strstart(p, "xenfb", &opts)) {
1466 vga_interface_type = VGA_XENFB;
1467 } else if (strstart(p, "qxl", &opts)) {
1468 vga_interface_type = VGA_QXL;
1469 } else if (!strstart(p, "none", &opts)) {
1471 fprintf(stderr, "Unknown vga type: %s\n", p);
1475 const char *nextopt;
1477 if (strstart(opts, ",retrace=", &nextopt)) {
1479 if (strstart(opts, "dumb", &nextopt))
1480 vga_retrace_method = VGA_RETRACE_DUMB;
1481 else if (strstart(opts, "precise", &nextopt))
1482 vga_retrace_method = VGA_RETRACE_PRECISE;
1483 else goto invalid_vga;
1484 } else goto invalid_vga;
1489 static DisplayType select_display(const char *p)
1492 DisplayType display = DT_DEFAULT;
1494 if (strstart(p, "sdl", &opts)) {
1498 const char *nextopt;
1500 if (strstart(opts, ",frame=", &nextopt)) {
1502 if (strstart(opts, "on", &nextopt)) {
1504 } else if (strstart(opts, "off", &nextopt)) {
1507 goto invalid_sdl_args;
1509 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
1511 if (strstart(opts, "on", &nextopt)) {
1513 } else if (strstart(opts, "off", &nextopt)) {
1516 goto invalid_sdl_args;
1518 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
1520 if (strstart(opts, "on", &nextopt)) {
1522 } else if (strstart(opts, "off", &nextopt)) {
1525 goto invalid_sdl_args;
1527 } else if (strstart(opts, ",window_close=", &nextopt)) {
1529 if (strstart(opts, "on", &nextopt)) {
1531 } else if (strstart(opts, "off", &nextopt)) {
1534 goto invalid_sdl_args;
1538 fprintf(stderr, "Invalid SDL option string: %s\n", p);
1544 fprintf(stderr, "SDL support is disabled\n");
1547 } else if (strstart(p, "vnc", &opts)) {
1552 const char *nextopt;
1554 if (strstart(opts, "=", &nextopt)) {
1555 vnc_display = nextopt;
1559 fprintf(stderr, "VNC requires a display argument vnc=<display>\n");
1563 fprintf(stderr, "VNC support is disabled\n");
1566 } else if (strstart(p, "curses", &opts)) {
1567 #ifdef CONFIG_CURSES
1568 display = DT_CURSES;
1570 fprintf(stderr, "Curses support is disabled\n");
1573 } else if (strstart(p, "none", &opts)) {
1576 fprintf(stderr, "Unknown display type: %s\n", p);
1583 static int balloon_parse(const char *arg)
1587 if (strcmp(arg, "none") == 0) {
1591 if (!strncmp(arg, "virtio", 6)) {
1592 if (arg[6] == ',') {
1593 /* have params -> parse them */
1594 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
1598 /* create empty opts */
1599 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
1601 qemu_opt_set(opts, "driver", "virtio-balloon");
1608 char *qemu_find_file(int type, const char *name)
1614 /* If name contains path separators then try it as a straight path. */
1615 if ((strchr(name, '/') || strchr(name, '\\'))
1616 && access(name, R_OK) == 0) {
1617 return qemu_strdup(name);
1620 case QEMU_FILE_TYPE_BIOS:
1623 case QEMU_FILE_TYPE_KEYMAP:
1624 subdir = "keymaps/";
1629 len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
1630 buf = qemu_mallocz(len);
1631 snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
1632 if (access(buf, R_OK)) {
1639 static int device_help_func(QemuOpts *opts, void *opaque)
1641 return qdev_device_help(opts);
1644 static int device_init_func(QemuOpts *opts, void *opaque)
1648 dev = qdev_device_add(opts);
1654 static int chardev_init_func(QemuOpts *opts, void *opaque)
1656 CharDriverState *chr;
1658 chr = qemu_chr_open_opts(opts, NULL);
1664 #ifdef CONFIG_VIRTFS
1665 static int fsdev_init_func(QemuOpts *opts, void *opaque)
1668 ret = qemu_fsdev_add(opts);
1674 static int mon_init_func(QemuOpts *opts, void *opaque)
1676 CharDriverState *chr;
1677 const char *chardev;
1681 mode = qemu_opt_get(opts, "mode");
1685 if (strcmp(mode, "readline") == 0) {
1686 flags = MONITOR_USE_READLINE;
1687 } else if (strcmp(mode, "control") == 0) {
1688 flags = MONITOR_USE_CONTROL;
1690 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
1694 if (qemu_opt_get_bool(opts, "pretty", 0))
1695 flags |= MONITOR_USE_PRETTY;
1697 if (qemu_opt_get_bool(opts, "default", 0))
1698 flags |= MONITOR_IS_DEFAULT;
1700 chardev = qemu_opt_get(opts, "chardev");
1701 chr = qemu_chr_find(chardev);
1703 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
1707 monitor_init(chr, flags);
1711 static void monitor_parse(const char *optarg, const char *mode)
1713 static int monitor_device_index = 0;
1719 if (strstart(optarg, "chardev:", &p)) {
1720 snprintf(label, sizeof(label), "%s", p);
1722 snprintf(label, sizeof(label), "compat_monitor%d",
1723 monitor_device_index);
1724 if (monitor_device_index == 0) {
1727 opts = qemu_chr_parse_compat(label, optarg);
1729 fprintf(stderr, "parse error: %s\n", optarg);
1734 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1);
1736 fprintf(stderr, "duplicate chardev: %s\n", label);
1739 qemu_opt_set(opts, "mode", mode);
1740 qemu_opt_set(opts, "chardev", label);
1742 qemu_opt_set(opts, "default", "on");
1743 monitor_device_index++;
1746 struct device_config {
1748 DEV_USB, /* -usbdevice */
1750 DEV_SERIAL, /* -serial */
1751 DEV_PARALLEL, /* -parallel */
1752 DEV_VIRTCON, /* -virtioconsole */
1753 DEV_DEBUGCON, /* -debugcon */
1755 const char *cmdline;
1756 QTAILQ_ENTRY(device_config) next;
1758 QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
1760 static void add_device_config(int type, const char *cmdline)
1762 struct device_config *conf;
1764 conf = qemu_mallocz(sizeof(*conf));
1766 conf->cmdline = cmdline;
1767 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
1770 static int foreach_device_config(int type, int (*func)(const char *cmdline))
1772 struct device_config *conf;
1775 QTAILQ_FOREACH(conf, &device_configs, next) {
1776 if (conf->type != type)
1778 rc = func(conf->cmdline);
1785 static int serial_parse(const char *devname)
1787 static int index = 0;
1790 if (strcmp(devname, "none") == 0)
1792 if (index == MAX_SERIAL_PORTS) {
1793 fprintf(stderr, "qemu: too many serial ports\n");
1796 snprintf(label, sizeof(label), "serial%d", index);
1797 serial_hds[index] = qemu_chr_open(label, devname, NULL);
1798 if (!serial_hds[index]) {
1799 fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
1800 devname, strerror(errno));
1807 static int parallel_parse(const char *devname)
1809 static int index = 0;
1812 if (strcmp(devname, "none") == 0)
1814 if (index == MAX_PARALLEL_PORTS) {
1815 fprintf(stderr, "qemu: too many parallel ports\n");
1818 snprintf(label, sizeof(label), "parallel%d", index);
1819 parallel_hds[index] = qemu_chr_open(label, devname, NULL);
1820 if (!parallel_hds[index]) {
1821 fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
1822 devname, strerror(errno));
1829 static int virtcon_parse(const char *devname)
1831 QemuOptsList *device = qemu_find_opts("device");
1832 static int index = 0;
1834 QemuOpts *bus_opts, *dev_opts;
1836 if (strcmp(devname, "none") == 0)
1838 if (index == MAX_VIRTIO_CONSOLES) {
1839 fprintf(stderr, "qemu: too many virtio consoles\n");
1843 bus_opts = qemu_opts_create(device, NULL, 0);
1844 qemu_opt_set(bus_opts, "driver", "virtio-serial");
1846 dev_opts = qemu_opts_create(device, NULL, 0);
1847 qemu_opt_set(dev_opts, "driver", "virtconsole");
1849 snprintf(label, sizeof(label), "virtcon%d", index);
1850 virtcon_hds[index] = qemu_chr_open(label, devname, NULL);
1851 if (!virtcon_hds[index]) {
1852 fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
1853 devname, strerror(errno));
1856 qemu_opt_set(dev_opts, "chardev", label);
1862 static int debugcon_parse(const char *devname)
1866 if (!qemu_chr_open("debugcon", devname, NULL)) {
1869 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1871 fprintf(stderr, "qemu: already have a debugcon device\n");
1874 qemu_opt_set(opts, "driver", "isa-debugcon");
1875 qemu_opt_set(opts, "chardev", "debugcon");
1879 void qemu_add_exit_notifier(Notifier *notify)
1881 notifier_list_add(&exit_notifiers, notify);
1884 void qemu_remove_exit_notifier(Notifier *notify)
1886 notifier_list_remove(&exit_notifiers, notify);
1889 static void qemu_run_exit_notifiers(void)
1891 notifier_list_notify(&exit_notifiers);
1894 void qemu_add_machine_init_done_notifier(Notifier *notify)
1896 notifier_list_add(&machine_init_done_notifiers, notify);
1899 static void qemu_run_machine_init_done_notifiers(void)
1901 notifier_list_notify(&machine_init_done_notifiers);
1904 static const QEMUOption *lookup_opt(int argc, char **argv,
1905 const char **poptarg, int *poptind)
1907 const QEMUOption *popt;
1908 int optind = *poptind;
1909 char *r = argv[optind];
1912 loc_set_cmdline(argv, optind, 1);
1914 /* Treat --foo the same as -foo. */
1917 popt = qemu_options;
1920 error_report("invalid option");
1923 if (!strcmp(popt->name, r + 1))
1927 if (popt->flags & HAS_ARG) {
1928 if (optind >= argc) {
1929 error_report("requires an argument");
1932 optarg = argv[optind++];
1933 loc_set_cmdline(argv, optind - 2, 2);
1944 int main(int argc, char **argv, char **envp)
1946 const char *gdbstub_dev = NULL;
1948 int snapshot, linux_boot;
1949 const char *icount_option = NULL;
1950 const char *initrd_filename;
1951 const char *kernel_filename, *kernel_cmdline;
1952 char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
1954 DisplayChangeListener *dcl;
1955 int cyls, heads, secs, translation;
1956 QemuOpts *hda_opts = NULL, *opts;
1957 QemuOptsList *olist;
1960 const char *loadvm = NULL;
1961 QEMUMachine *machine;
1962 const char *cpu_model;
1964 const char *pid_file = NULL;
1965 const char *incoming = NULL;
1967 int show_vnc_port = 0;
1970 const char *trace_file = NULL;
1972 atexit(qemu_run_exit_notifiers);
1973 error_set_progname(argv[0]);
1977 qemu_cache_utils_init(envp);
1979 QLIST_INIT (&vm_change_state_head);
1980 os_setup_early_signal_handling();
1982 module_call_init(MODULE_INIT_MACHINE);
1983 machine = find_default_machine();
1985 initrd_filename = NULL;
1988 kernel_filename = NULL;
1989 kernel_cmdline = "";
1990 cyls = heads = secs = 0;
1991 translation = BIOS_ATA_TRANSLATION_AUTO;
1993 for (i = 0; i < MAX_NODES; i++) {
1995 node_cpumask[i] = 0;
2004 /* first pass of option parsing */
2006 while (optind < argc) {
2007 if (argv[optind][0] != '-') {
2012 const QEMUOption *popt;
2014 popt = lookup_opt(argc, argv, &optarg, &optind);
2015 switch (popt->index) {
2016 case QEMU_OPTION_nodefconfig:
2026 ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
2027 if (ret < 0 && ret != -ENOENT) {
2031 ret = qemu_read_config_file(arch_config_name);
2032 if (ret < 0 && ret != -ENOENT) {
2038 /* second pass of option parsing */
2043 if (argv[optind][0] != '-') {
2044 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
2046 const QEMUOption *popt;
2048 popt = lookup_opt(argc, argv, &optarg, &optind);
2049 if (!(popt->arch_mask & arch_type)) {
2050 printf("Option %s not supported for this target\n", popt->name);
2053 switch(popt->index) {
2055 machine = find_machine(optarg);
2058 printf("Supported machines are:\n");
2059 for(m = first_machine; m != NULL; m = m->next) {
2061 printf("%-10s %s (alias of %s)\n",
2062 m->alias, m->desc, m->name);
2063 printf("%-10s %s%s\n",
2065 m->is_default ? " (default)" : "");
2067 exit(*optarg != '?');
2070 case QEMU_OPTION_cpu:
2071 /* hw initialization will check this */
2072 if (*optarg == '?') {
2073 list_cpus(stdout, &fprintf, optarg);
2079 case QEMU_OPTION_initrd:
2080 initrd_filename = optarg;
2082 case QEMU_OPTION_hda:
2086 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2088 snprintf(buf, sizeof(buf),
2089 "%s,cyls=%d,heads=%d,secs=%d%s",
2090 HD_OPTS , cyls, heads, secs,
2091 translation == BIOS_ATA_TRANSLATION_LBA ?
2093 translation == BIOS_ATA_TRANSLATION_NONE ?
2094 ",trans=none" : "");
2095 drive_add(IF_DEFAULT, 0, optarg, buf);
2098 case QEMU_OPTION_hdb:
2099 case QEMU_OPTION_hdc:
2100 case QEMU_OPTION_hdd:
2101 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2104 case QEMU_OPTION_drive:
2105 if (drive_def(optarg) == NULL) {
2109 case QEMU_OPTION_set:
2110 if (qemu_set_option(optarg) != 0)
2113 case QEMU_OPTION_global:
2114 if (qemu_global_option(optarg) != 0)
2117 case QEMU_OPTION_mtdblock:
2118 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
2120 case QEMU_OPTION_sd:
2121 drive_add(IF_SD, 0, optarg, SD_OPTS);
2123 case QEMU_OPTION_pflash:
2124 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
2126 case QEMU_OPTION_snapshot:
2129 case QEMU_OPTION_hdachs:
2133 cyls = strtol(p, (char **)&p, 0);
2134 if (cyls < 1 || cyls > 16383)
2139 heads = strtol(p, (char **)&p, 0);
2140 if (heads < 1 || heads > 16)
2145 secs = strtol(p, (char **)&p, 0);
2146 if (secs < 1 || secs > 63)
2150 if (!strcmp(p, "none"))
2151 translation = BIOS_ATA_TRANSLATION_NONE;
2152 else if (!strcmp(p, "lba"))
2153 translation = BIOS_ATA_TRANSLATION_LBA;
2154 else if (!strcmp(p, "auto"))
2155 translation = BIOS_ATA_TRANSLATION_AUTO;
2158 } else if (*p != '\0') {
2160 fprintf(stderr, "qemu: invalid physical CHS format\n");
2163 if (hda_opts != NULL) {
2165 snprintf(num, sizeof(num), "%d", cyls);
2166 qemu_opt_set(hda_opts, "cyls", num);
2167 snprintf(num, sizeof(num), "%d", heads);
2168 qemu_opt_set(hda_opts, "heads", num);
2169 snprintf(num, sizeof(num), "%d", secs);
2170 qemu_opt_set(hda_opts, "secs", num);
2171 if (translation == BIOS_ATA_TRANSLATION_LBA)
2172 qemu_opt_set(hda_opts, "trans", "lba");
2173 if (translation == BIOS_ATA_TRANSLATION_NONE)
2174 qemu_opt_set(hda_opts, "trans", "none");
2178 case QEMU_OPTION_numa:
2179 if (nb_numa_nodes >= MAX_NODES) {
2180 fprintf(stderr, "qemu: too many NUMA nodes\n");
2185 case QEMU_OPTION_display:
2186 display_type = select_display(optarg);
2188 case QEMU_OPTION_nographic:
2189 display_type = DT_NOGRAPHIC;
2191 case QEMU_OPTION_curses:
2192 #ifdef CONFIG_CURSES
2193 display_type = DT_CURSES;
2195 fprintf(stderr, "Curses support is disabled\n");
2199 case QEMU_OPTION_portrait:
2202 case QEMU_OPTION_kernel:
2203 kernel_filename = optarg;
2205 case QEMU_OPTION_append:
2206 kernel_cmdline = optarg;
2208 case QEMU_OPTION_cdrom:
2209 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
2211 case QEMU_OPTION_boot:
2213 static const char * const params[] = {
2214 "order", "once", "menu", NULL
2216 char buf[sizeof(boot_devices)];
2217 char *standard_boot_devices;
2220 if (!strchr(optarg, '=')) {
2222 pstrcpy(buf, sizeof(buf), optarg);
2223 } else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
2225 "qemu: unknown boot parameter '%s' in '%s'\n",
2231 get_param_value(buf, sizeof(buf), "order", optarg)) {
2232 validate_bootdevices(buf);
2233 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2236 if (get_param_value(buf, sizeof(buf),
2238 validate_bootdevices(buf);
2239 standard_boot_devices = qemu_strdup(boot_devices);
2240 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2241 qemu_register_reset(restore_boot_devices,
2242 standard_boot_devices);
2244 if (get_param_value(buf, sizeof(buf),
2246 if (!strcmp(buf, "on")) {
2248 } else if (!strcmp(buf, "off")) {
2252 "qemu: invalid option value '%s'\n",
2260 case QEMU_OPTION_fda:
2261 case QEMU_OPTION_fdb:
2262 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2265 case QEMU_OPTION_no_fd_bootchk:
2268 case QEMU_OPTION_netdev:
2269 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
2273 case QEMU_OPTION_net:
2274 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
2279 case QEMU_OPTION_tftp:
2280 legacy_tftp_prefix = optarg;
2282 case QEMU_OPTION_bootp:
2283 legacy_bootp_filename = optarg;
2285 case QEMU_OPTION_redir:
2286 if (net_slirp_redir(optarg) < 0)
2290 case QEMU_OPTION_bt:
2291 add_device_config(DEV_BT, optarg);
2293 case QEMU_OPTION_audio_help:
2294 if (!(audio_available())) {
2295 printf("Option %s not supported for this target\n", popt->name);
2301 case QEMU_OPTION_soundhw:
2302 if (!(audio_available())) {
2303 printf("Option %s not supported for this target\n", popt->name);
2306 select_soundhw (optarg);
2311 case QEMU_OPTION_version:
2315 case QEMU_OPTION_m: {
2318 value = strtosz(optarg, NULL);
2320 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
2324 /* On 32-bit hosts, QEMU is limited by virtual address space */
2325 if (value > (2047 << 20) && HOST_LONG_BITS == 32) {
2326 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
2329 if (value != (uint64_t)(ram_addr_t)value) {
2330 fprintf(stderr, "qemu: ram size too large\n");
2336 case QEMU_OPTION_mempath:
2340 case QEMU_OPTION_mem_prealloc:
2345 set_cpu_log(optarg);
2348 gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT;
2350 case QEMU_OPTION_gdb:
2351 gdbstub_dev = optarg;
2356 case QEMU_OPTION_bios:
2359 case QEMU_OPTION_singlestep:
2366 keyboard_layout = optarg;
2368 case QEMU_OPTION_localtime:
2371 case QEMU_OPTION_vga:
2372 select_vgahw (optarg);
2379 w = strtol(p, (char **)&p, 10);
2382 fprintf(stderr, "qemu: invalid resolution or depth\n");
2388 h = strtol(p, (char **)&p, 10);
2393 depth = strtol(p, (char **)&p, 10);
2394 if (depth != 8 && depth != 15 && depth != 16 &&
2395 depth != 24 && depth != 32)
2397 } else if (*p == '\0') {
2398 depth = graphic_depth;
2405 graphic_depth = depth;
2408 case QEMU_OPTION_echr:
2411 term_escape_char = strtol(optarg, &r, 0);
2413 printf("Bad argument to echr\n");
2416 case QEMU_OPTION_monitor:
2417 monitor_parse(optarg, "readline");
2418 default_monitor = 0;
2420 case QEMU_OPTION_qmp:
2421 monitor_parse(optarg, "control");
2422 default_monitor = 0;
2424 case QEMU_OPTION_mon:
2425 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
2429 default_monitor = 0;
2431 case QEMU_OPTION_chardev:
2432 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
2437 case QEMU_OPTION_fsdev:
2438 olist = qemu_find_opts("fsdev");
2440 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
2443 opts = qemu_opts_parse(olist, optarg, 1);
2445 fprintf(stderr, "parse error: %s\n", optarg);
2449 case QEMU_OPTION_virtfs: {
2450 char *arg_fsdev = NULL;
2451 char *arg_9p = NULL;
2454 olist = qemu_find_opts("virtfs");
2456 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
2459 opts = qemu_opts_parse(olist, optarg, 1);
2461 fprintf(stderr, "parse error: %s\n", optarg);
2465 if (qemu_opt_get(opts, "fstype") == NULL ||
2466 qemu_opt_get(opts, "mount_tag") == NULL ||
2467 qemu_opt_get(opts, "path") == NULL ||
2468 qemu_opt_get(opts, "security_model") == NULL) {
2469 fprintf(stderr, "Usage: -virtfs fstype,path=/share_path/,"
2470 "security_model=[mapped|passthrough|none],"
2475 len = strlen(",id=,path=,security_model=");
2476 len += strlen(qemu_opt_get(opts, "fstype"));
2477 len += strlen(qemu_opt_get(opts, "mount_tag"));
2478 len += strlen(qemu_opt_get(opts, "path"));
2479 len += strlen(qemu_opt_get(opts, "security_model"));
2480 arg_fsdev = qemu_malloc((len + 1) * sizeof(*arg_fsdev));
2482 snprintf(arg_fsdev, (len + 1) * sizeof(*arg_fsdev),
2483 "%s,id=%s,path=%s,security_model=%s",
2484 qemu_opt_get(opts, "fstype"),
2485 qemu_opt_get(opts, "mount_tag"),
2486 qemu_opt_get(opts, "path"),
2487 qemu_opt_get(opts, "security_model"));
2489 len = strlen("virtio-9p,fsdev=,mount_tag=");
2490 len += 2*strlen(qemu_opt_get(opts, "mount_tag"));
2491 arg_9p = qemu_malloc((len + 1) * sizeof(*arg_9p));
2493 snprintf(arg_9p, (len + 1) * sizeof(*arg_9p),
2494 "virtio-9p,fsdev=%s,mount_tag=%s",
2495 qemu_opt_get(opts, "mount_tag"),
2496 qemu_opt_get(opts, "mount_tag"));
2498 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev, 1)) {
2499 fprintf(stderr, "parse error [fsdev]: %s\n", optarg);
2503 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p, 1)) {
2504 fprintf(stderr, "parse error [device]: %s\n", optarg);
2508 qemu_free(arg_fsdev);
2512 case QEMU_OPTION_serial:
2513 add_device_config(DEV_SERIAL, optarg);
2515 if (strncmp(optarg, "mon:", 4) == 0) {
2516 default_monitor = 0;
2519 case QEMU_OPTION_watchdog:
2522 "qemu: only one watchdog option may be given\n");
2527 case QEMU_OPTION_watchdog_action:
2528 if (select_watchdog_action(optarg) == -1) {
2529 fprintf(stderr, "Unknown -watchdog-action parameter\n");
2533 case QEMU_OPTION_virtiocon:
2534 add_device_config(DEV_VIRTCON, optarg);
2535 default_virtcon = 0;
2536 if (strncmp(optarg, "mon:", 4) == 0) {
2537 default_monitor = 0;
2540 case QEMU_OPTION_parallel:
2541 add_device_config(DEV_PARALLEL, optarg);
2542 default_parallel = 0;
2543 if (strncmp(optarg, "mon:", 4) == 0) {
2544 default_monitor = 0;
2547 case QEMU_OPTION_debugcon:
2548 add_device_config(DEV_DEBUGCON, optarg);
2550 case QEMU_OPTION_loadvm:
2553 case QEMU_OPTION_full_screen:
2557 case QEMU_OPTION_no_frame:
2560 case QEMU_OPTION_alt_grab:
2563 case QEMU_OPTION_ctrl_grab:
2566 case QEMU_OPTION_no_quit:
2569 case QEMU_OPTION_sdl:
2570 display_type = DT_SDL;
2573 case QEMU_OPTION_no_frame:
2574 case QEMU_OPTION_alt_grab:
2575 case QEMU_OPTION_ctrl_grab:
2576 case QEMU_OPTION_no_quit:
2577 case QEMU_OPTION_sdl:
2578 fprintf(stderr, "SDL support is disabled\n");
2581 case QEMU_OPTION_pidfile:
2584 case QEMU_OPTION_win2k_hack:
2585 win2k_install_hack = 1;
2587 case QEMU_OPTION_rtc_td_hack:
2590 case QEMU_OPTION_acpitable:
2591 do_acpitable_option(optarg);
2593 case QEMU_OPTION_smbios:
2594 do_smbios_option(optarg);
2596 case QEMU_OPTION_enable_kvm:
2599 case QEMU_OPTION_usb:
2602 case QEMU_OPTION_usbdevice:
2604 add_device_config(DEV_USB, optarg);
2606 case QEMU_OPTION_device:
2607 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
2611 case QEMU_OPTION_smp:
2614 fprintf(stderr, "Invalid number of CPUs\n");
2617 if (max_cpus < smp_cpus) {
2618 fprintf(stderr, "maxcpus must be equal to or greater than "
2622 if (max_cpus > 255) {
2623 fprintf(stderr, "Unsupported number of maxcpus\n");
2627 case QEMU_OPTION_vnc:
2630 vnc_display = optarg;
2632 fprintf(stderr, "VNC support is disabled\n");
2636 case QEMU_OPTION_no_acpi:
2639 case QEMU_OPTION_no_hpet:
2642 case QEMU_OPTION_balloon:
2643 if (balloon_parse(optarg) < 0) {
2644 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
2648 case QEMU_OPTION_no_reboot:
2651 case QEMU_OPTION_no_shutdown:
2654 case QEMU_OPTION_show_cursor:
2657 case QEMU_OPTION_uuid:
2658 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
2659 fprintf(stderr, "Fail to parse UUID string."
2660 " Wrong format.\n");
2664 case QEMU_OPTION_option_rom:
2665 if (nb_option_roms >= MAX_OPTION_ROMS) {
2666 fprintf(stderr, "Too many option ROMs\n");
2669 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
2670 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
2671 option_rom[nb_option_roms].bootindex =
2672 qemu_opt_get_number(opts, "bootindex", -1);
2673 if (!option_rom[nb_option_roms].name) {
2674 fprintf(stderr, "Option ROM file is not specified\n");
2679 case QEMU_OPTION_semihosting:
2680 semihosting_enabled = 1;
2682 case QEMU_OPTION_name:
2683 qemu_name = qemu_strdup(optarg);
2685 char *p = strchr(qemu_name, ',');
2688 if (strncmp(p, "process=", 8)) {
2689 fprintf(stderr, "Unknown subargument %s to -name\n", p);
2693 os_set_proc_name(p);
2697 case QEMU_OPTION_prom_env:
2698 if (nb_prom_envs >= MAX_PROM_ENVS) {
2699 fprintf(stderr, "Too many prom variables\n");
2702 prom_envs[nb_prom_envs] = optarg;
2705 case QEMU_OPTION_old_param:
2708 case QEMU_OPTION_clock:
2709 configure_alarms(optarg);
2711 case QEMU_OPTION_startdate:
2712 configure_rtc_date_offset(optarg, 1);
2714 case QEMU_OPTION_rtc:
2715 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
2719 configure_rtc(opts);
2721 case QEMU_OPTION_tb_size:
2722 tb_size = strtol(optarg, NULL, 0);
2726 case QEMU_OPTION_icount:
2727 icount_option = optarg;
2729 case QEMU_OPTION_incoming:
2731 incoming_expected = true;
2733 case QEMU_OPTION_nodefaults:
2735 default_parallel = 0;
2736 default_virtcon = 0;
2737 default_monitor = 0;
2744 case QEMU_OPTION_xen_domid:
2745 if (!(xen_available())) {
2746 printf("Option %s not supported for this target\n", popt->name);
2749 xen_domid = atoi(optarg);
2751 case QEMU_OPTION_xen_create:
2752 if (!(xen_available())) {
2753 printf("Option %s not supported for this target\n", popt->name);
2756 xen_mode = XEN_CREATE;
2758 case QEMU_OPTION_xen_attach:
2759 if (!(xen_available())) {
2760 printf("Option %s not supported for this target\n", popt->name);
2763 xen_mode = XEN_ATTACH;
2765 #ifdef CONFIG_SIMPLE_TRACE
2766 case QEMU_OPTION_trace:
2767 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
2769 trace_file = qemu_opt_get(opts, "file");
2773 case QEMU_OPTION_readconfig:
2775 int ret = qemu_read_config_file(optarg);
2777 fprintf(stderr, "read config %s: %s\n", optarg,
2783 case QEMU_OPTION_spice:
2784 olist = qemu_find_opts("spice");
2786 fprintf(stderr, "spice is not supported by this qemu build.\n");
2789 opts = qemu_opts_parse(olist, optarg, 0);
2791 fprintf(stderr, "parse error: %s\n", optarg);
2795 case QEMU_OPTION_writeconfig:
2798 if (strcmp(optarg, "-") == 0) {
2801 fp = fopen(optarg, "w");
2803 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
2807 qemu_config_write(fp);
2812 os_parse_cmd_args(popt->index, optarg);
2818 if (!st_init(trace_file)) {
2819 fprintf(stderr, "warning: unable to initialize simple trace backend\n");
2822 /* If no data_dir is specified then try to find it relative to the
2825 data_dir = os_find_datadir(argv[0]);
2827 /* If all else fails use the install patch specified when building. */
2829 data_dir = CONFIG_QEMU_DATADIR;
2833 * Default to max_cpus = smp_cpus, in case the user doesn't
2834 * specify a max_cpus value.
2837 max_cpus = smp_cpus;
2839 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
2840 if (smp_cpus > machine->max_cpus) {
2841 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
2842 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
2847 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
2848 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
2850 if (machine->no_serial) {
2853 if (machine->no_parallel) {
2854 default_parallel = 0;
2856 if (!machine->use_virtcon) {
2857 default_virtcon = 0;
2859 if (machine->no_vga) {
2862 if (machine->no_floppy) {
2865 if (machine->no_cdrom) {
2868 if (machine->no_sdcard) {
2872 if (display_type == DT_NOGRAPHIC) {
2873 if (default_parallel)
2874 add_device_config(DEV_PARALLEL, "null");
2875 if (default_serial && default_monitor) {
2876 add_device_config(DEV_SERIAL, "mon:stdio");
2877 } else if (default_virtcon && default_monitor) {
2878 add_device_config(DEV_VIRTCON, "mon:stdio");
2881 add_device_config(DEV_SERIAL, "stdio");
2882 if (default_virtcon)
2883 add_device_config(DEV_VIRTCON, "stdio");
2884 if (default_monitor)
2885 monitor_parse("stdio", "readline");
2889 add_device_config(DEV_SERIAL, "vc:80Cx24C");
2890 if (default_parallel)
2891 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
2892 if (default_monitor)
2893 monitor_parse("vc:80Cx24C", "readline");
2894 if (default_virtcon)
2895 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
2898 vga_interface_type = VGA_CIRRUS;
2902 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
2904 #ifdef CONFIG_VIRTFS
2905 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
2912 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
2918 int ret = kvm_init();
2920 if (!kvm_available()) {
2921 printf("KVM not supported for this target\n");
2923 fprintf(stderr, "failed to initialize KVM: %s\n", strerror(-ret));
2929 if (qemu_init_main_loop()) {
2930 fprintf(stderr, "qemu_init_main_loop failed\n");
2933 linux_boot = (kernel_filename != NULL);
2935 if (!linux_boot && *kernel_cmdline != '\0') {
2936 fprintf(stderr, "-append only allowed with -kernel option\n");
2940 if (!linux_boot && initrd_filename != NULL) {
2941 fprintf(stderr, "-initrd only allowed with -kernel option\n");
2945 os_set_line_buffering();
2947 if (init_timer_alarm() < 0) {
2948 fprintf(stderr, "could not initialize alarm timer\n");
2951 configure_icount(icount_option);
2953 if (net_init_clients() < 0) {
2957 /* init the bluetooth world */
2958 if (foreach_device_config(DEV_BT, bt_parse))
2961 /* init the memory */
2963 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
2965 /* init the dynamic translator */
2966 cpu_exec_init_all(tb_size * 1024 * 1024);
2968 bdrv_init_with_whitelist();
2972 /* open the virtual block devices */
2974 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
2975 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
2978 default_drive(default_cdrom, snapshot, machine->use_scsi,
2979 IF_DEFAULT, 2, CDROM_OPTS);
2980 default_drive(default_floppy, snapshot, machine->use_scsi,
2981 IF_FLOPPY, 0, FD_OPTS);
2982 default_drive(default_sdcard, snapshot, machine->use_scsi,
2985 register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL,
2988 if (nb_numa_nodes > 0) {
2991 if (nb_numa_nodes > smp_cpus) {
2992 nb_numa_nodes = smp_cpus;
2995 /* If no memory size if given for any node, assume the default case
2996 * and distribute the available memory equally across all nodes
2998 for (i = 0; i < nb_numa_nodes; i++) {
2999 if (node_mem[i] != 0)
3002 if (i == nb_numa_nodes) {
3003 uint64_t usedmem = 0;
3005 /* On Linux, the each node's border has to be 8MB aligned,
3006 * the final node gets the rest.
3008 for (i = 0; i < nb_numa_nodes - 1; i++) {
3009 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
3010 usedmem += node_mem[i];
3012 node_mem[i] = ram_size - usedmem;
3015 for (i = 0; i < nb_numa_nodes; i++) {
3016 if (node_cpumask[i] != 0)
3019 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3020 * must cope with this anyway, because there are BIOSes out there in
3021 * real machines which also use this scheme.
3023 if (i == nb_numa_nodes) {
3024 for (i = 0; i < smp_cpus; i++) {
3025 node_cpumask[i % nb_numa_nodes] |= 1 << i;
3030 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
3034 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
3036 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
3038 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
3040 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
3043 module_call_init(MODULE_INIT_DEVICE);
3045 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0)
3049 i = select_watchdog(watchdog);
3051 exit (i == 1 ? 1 : 0);
3054 if (machine->compat_props) {
3055 qdev_prop_register_global_list(machine->compat_props);
3059 machine->init(ram_size, boot_devices,
3060 kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
3062 cpu_synchronize_all_post_init();
3066 current_machine = machine;
3068 /* init USB devices */
3070 if (foreach_device_config(DEV_USB, usb_parse) < 0)
3074 /* init generic devices */
3075 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
3078 net_check_clients();
3080 /* just use the first displaystate for the moment */
3081 ds = get_displaystate();
3085 if (display_type == DT_DEFAULT && !display_remote) {
3086 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3087 display_type = DT_SDL;
3088 #elif defined(CONFIG_VNC)
3089 vnc_display = "localhost:0,to=99";
3092 display_type = DT_NONE;
3097 /* init local displays */
3098 switch (display_type) {
3101 #if defined(CONFIG_CURSES)
3103 curses_display_init(ds, full_screen);
3106 #if defined(CONFIG_SDL)
3108 sdl_display_init(ds, full_screen, no_frame);
3110 #elif defined(CONFIG_COCOA)
3112 cocoa_display_init(ds, full_screen);
3119 /* must be after terminal init, SDL library changes signal handlers */
3120 os_setup_signal_handling();
3123 /* init remote displays */
3125 vnc_display_init(ds);
3126 if (vnc_display_open(ds, vnc_display) < 0)
3129 if (show_vnc_port) {
3130 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
3135 if (using_spice && !qxl_enabled) {
3136 qemu_spice_display_init(ds);
3142 dcl = ds->listeners;
3143 while (dcl != NULL) {
3144 if (dcl->dpy_refresh != NULL) {
3145 ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds);
3146 qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock));
3151 if (ds->gui_timer == NULL) {
3152 nographic_timer = qemu_new_timer_ms(rt_clock, nographic_update, NULL);
3153 qemu_mod_timer(nographic_timer, qemu_get_clock_ms(rt_clock));
3155 text_consoles_set_display(ds);
3157 if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) {
3158 fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n",
3163 qdev_machine_creation_done();
3165 if (rom_load_all() != 0) {
3166 fprintf(stderr, "rom loading failed\n");
3170 /* TODO: once all bus devices are qdevified, this should be done
3171 * when bus is created by qdev.c */
3172 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
3173 qemu_run_machine_init_done_notifiers();
3175 qemu_system_reset();
3177 if (load_vmstate(loadvm) < 0) {
3183 int ret = qemu_start_incoming_migration(incoming);
3185 fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n",
3189 } else if (autostart) {