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);
260 static int tcg_allowed = 1;
264 enum xen_mode xen_mode = XEN_EMULATE;
266 static int default_serial = 1;
267 static int default_parallel = 1;
268 static int default_virtcon = 1;
269 static int default_monitor = 1;
270 static int default_vga = 1;
271 static int default_floppy = 1;
272 static int default_cdrom = 1;
273 static int default_sdcard = 1;
279 { .driver = "isa-serial", .flag = &default_serial },
280 { .driver = "isa-parallel", .flag = &default_parallel },
281 { .driver = "isa-fdc", .flag = &default_floppy },
282 { .driver = "ide-cd", .flag = &default_cdrom },
283 { .driver = "ide-hd", .flag = &default_cdrom },
284 { .driver = "ide-drive", .flag = &default_cdrom },
285 { .driver = "scsi-cd", .flag = &default_cdrom },
286 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
287 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
288 { .driver = "virtio-serial", .flag = &default_virtcon },
289 { .driver = "VGA", .flag = &default_vga },
290 { .driver = "cirrus-vga", .flag = &default_vga },
291 { .driver = "vmware-svga", .flag = &default_vga },
292 { .driver = "isa-vga", .flag = &default_vga },
293 { .driver = "qxl-vga", .flag = &default_vga },
296 static int default_driver_check(QemuOpts *opts, void *opaque)
298 const char *driver = qemu_opt_get(opts, "driver");
303 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
304 if (strcmp(default_list[i].driver, driver) != 0)
306 *(default_list[i].flag) = 0;
311 /***********************************************************/
312 /* real time host monotonic timer */
314 /***********************************************************/
315 /* host time/date access */
316 void qemu_get_timedate(struct tm *tm, int offset)
323 if (rtc_date_offset == -1) {
327 ret = localtime(&ti);
329 ti -= rtc_date_offset;
333 memcpy(tm, ret, sizeof(struct tm));
336 int qemu_timedate_diff(struct tm *tm)
340 if (rtc_date_offset == -1)
342 seconds = mktimegm(tm);
344 seconds = mktime(tm);
346 seconds = mktimegm(tm) + rtc_date_offset;
348 return seconds - time(NULL);
351 void rtc_change_mon_event(struct tm *tm)
355 data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
356 monitor_protocol_event(QEVENT_RTC_CHANGE, data);
357 qobject_decref(data);
360 static void configure_rtc_date_offset(const char *startdate, int legacy)
362 time_t rtc_start_date;
365 if (!strcmp(startdate, "now") && legacy) {
366 rtc_date_offset = -1;
368 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
376 } else if (sscanf(startdate, "%d-%d-%d",
388 rtc_start_date = mktimegm(&tm);
389 if (rtc_start_date == -1) {
391 fprintf(stderr, "Invalid date format. Valid formats are:\n"
392 "'2006-06-17T16:01:21' or '2006-06-17'\n");
395 rtc_date_offset = time(NULL) - rtc_start_date;
399 static void configure_rtc(QemuOpts *opts)
403 value = qemu_opt_get(opts, "base");
405 if (!strcmp(value, "utc")) {
407 } else if (!strcmp(value, "localtime")) {
410 configure_rtc_date_offset(value, 0);
413 value = qemu_opt_get(opts, "clock");
415 if (!strcmp(value, "host")) {
416 rtc_clock = host_clock;
417 } else if (!strcmp(value, "vm")) {
418 rtc_clock = vm_clock;
420 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
424 value = qemu_opt_get(opts, "driftfix");
426 if (!strcmp(value, "slew")) {
428 } else if (!strcmp(value, "none")) {
431 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
437 /***********************************************************/
438 /* Bluetooth support */
441 static struct HCIInfo *hci_table[MAX_NICS];
443 static struct bt_vlan_s {
444 struct bt_scatternet_s net;
446 struct bt_vlan_s *next;
449 /* find or alloc a new bluetooth "VLAN" */
450 static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
452 struct bt_vlan_s **pvlan, *vlan;
453 for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) {
457 vlan = qemu_mallocz(sizeof(struct bt_vlan_s));
459 pvlan = &first_bt_vlan;
460 while (*pvlan != NULL)
461 pvlan = &(*pvlan)->next;
466 static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
470 static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
475 static struct HCIInfo null_hci = {
476 .cmd_send = null_hci_send,
477 .sco_send = null_hci_send,
478 .acl_send = null_hci_send,
479 .bdaddr_set = null_hci_addr_set,
482 struct HCIInfo *qemu_next_hci(void)
484 if (cur_hci == nb_hcis)
487 return hci_table[cur_hci++];
490 static struct HCIInfo *hci_init(const char *str)
493 struct bt_scatternet_s *vlan = 0;
495 if (!strcmp(str, "null"))
498 else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':'))
500 return bt_host_hci(str[4] ? str + 5 : "hci0");
501 else if (!strncmp(str, "hci", 3)) {
504 if (!strncmp(str + 3, ",vlan=", 6)) {
505 vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0));
510 vlan = qemu_find_bt_vlan(0);
512 return bt_new_hci(vlan);
515 fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
520 static int bt_hci_parse(const char *str)
525 if (nb_hcis >= MAX_NICS) {
526 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
539 bdaddr.b[5] = 0x56 + nb_hcis;
540 hci->bdaddr_set(hci, bdaddr.b);
542 hci_table[nb_hcis++] = hci;
547 static void bt_vhci_add(int vlan_id)
549 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
552 fprintf(stderr, "qemu: warning: adding a VHCI to "
553 "an empty scatternet %i\n", vlan_id);
555 bt_vhci_init(bt_new_hci(vlan));
558 static struct bt_device_s *bt_device_add(const char *opt)
560 struct bt_scatternet_s *vlan;
562 char *endp = strstr(opt, ",vlan=");
563 int len = (endp ? endp - opt : strlen(opt)) + 1;
566 pstrcpy(devname, MIN(sizeof(devname), len), opt);
569 vlan_id = strtol(endp + 6, &endp, 0);
571 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
576 vlan = qemu_find_bt_vlan(vlan_id);
579 fprintf(stderr, "qemu: warning: adding a slave device to "
580 "an empty scatternet %i\n", vlan_id);
582 if (!strcmp(devname, "keyboard"))
583 return bt_keyboard_init(vlan);
585 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
589 static int bt_parse(const char *opt)
591 const char *endp, *p;
594 if (strstart(opt, "hci", &endp)) {
595 if (!*endp || *endp == ',') {
597 if (!strstart(endp, ",vlan=", 0))
600 return bt_hci_parse(opt);
602 } else if (strstart(opt, "vhci", &endp)) {
603 if (!*endp || *endp == ',') {
605 if (strstart(endp, ",vlan=", &p)) {
606 vlan = strtol(p, (char **) &endp, 0);
608 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
612 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
621 } else if (strstart(opt, "device:", &endp))
622 return !bt_device_add(endp);
624 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
628 /***********************************************************/
629 /* QEMU Block devices */
631 #define HD_OPTS "media=disk"
632 #define CDROM_OPTS "media=cdrom"
634 #define PFLASH_OPTS ""
638 static int drive_init_func(QemuOpts *opts, void *opaque)
640 int *use_scsi = opaque;
642 return drive_init(opts, *use_scsi) == NULL;
645 static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
647 if (NULL == qemu_opt_get(opts, "snapshot")) {
648 qemu_opt_set(opts, "snapshot", "on");
653 static void default_drive(int enable, int snapshot, int use_scsi,
654 BlockInterfaceType type, int index,
659 if (type == IF_DEFAULT) {
660 type = use_scsi ? IF_SCSI : IF_IDE;
663 if (!enable || drive_get_by_index(type, index)) {
667 opts = drive_add(type, index, NULL, optstr);
669 drive_enable_snapshot(opts, NULL);
671 if (!drive_init(opts, use_scsi)) {
676 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
678 boot_set_handler = func;
679 boot_set_opaque = opaque;
682 int qemu_boot_set(const char *boot_devices)
684 if (!boot_set_handler) {
687 return boot_set_handler(boot_set_opaque, boot_devices);
690 static void validate_bootdevices(char *devices)
692 /* We just do some generic consistency checks */
696 for (p = devices; *p != '\0'; p++) {
697 /* Allowed boot devices are:
698 * a-b: floppy disk drives
699 * c-f: IDE disk drives
700 * g-m: machine implementation dependant drives
701 * n-p: network devices
702 * It's up to each machine implementation to check if the given boot
703 * devices match the actual hardware implementation and firmware
706 if (*p < 'a' || *p > 'p') {
707 fprintf(stderr, "Invalid boot device '%c'\n", *p);
710 if (bitmap & (1 << (*p - 'a'))) {
711 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
714 bitmap |= 1 << (*p - 'a');
718 static void restore_boot_devices(void *opaque)
720 char *standard_boot_devices = opaque;
721 static int first = 1;
723 /* Restore boot order and remove ourselves after the first boot */
729 qemu_boot_set(standard_boot_devices);
731 qemu_unregister_reset(restore_boot_devices, standard_boot_devices);
732 qemu_free(standard_boot_devices);
735 void add_boot_device_path(int32_t bootindex, DeviceState *dev,
738 FWBootEntry *node, *i;
744 assert(dev != NULL || suffix != NULL);
746 node = qemu_mallocz(sizeof(FWBootEntry));
747 node->bootindex = bootindex;
748 node->suffix = suffix ? qemu_strdup(suffix) : NULL;
751 QTAILQ_FOREACH(i, &fw_boot_order, link) {
752 if (i->bootindex == bootindex) {
753 fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
755 } else if (i->bootindex < bootindex) {
758 QTAILQ_INSERT_BEFORE(i, node, link);
761 QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
765 * This function returns null terminated string that consist of new line
766 * separated device paths.
768 * memory pointed by "size" is assigned total length of the array in bytes
771 char *get_boot_devices_list(uint32_t *size)
777 QTAILQ_FOREACH(i, &fw_boot_order, link) {
778 char *devpath = NULL, *bootpath;
782 devpath = qdev_get_fw_dev_path(i->dev);
786 if (i->suffix && devpath) {
787 size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
789 bootpath = qemu_malloc(bootpathlen);
790 snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
792 } else if (devpath) {
795 bootpath = qemu_strdup(i->suffix);
800 list[total-1] = '\n';
802 len = strlen(bootpath) + 1;
803 list = qemu_realloc(list, total + len);
804 memcpy(&list[total], bootpath, len);
814 static void numa_add(const char *optarg)
818 unsigned long long value, endvalue;
821 optarg = get_opt_name(option, 128, optarg, ',') + 1;
822 if (!strcmp(option, "node")) {
823 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
824 nodenr = nb_numa_nodes;
826 nodenr = strtoull(option, NULL, 10);
829 if (get_param_value(option, 128, "mem", optarg) == 0) {
830 node_mem[nodenr] = 0;
833 sval = strtosz(option, NULL);
835 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
838 node_mem[nodenr] = sval;
840 if (get_param_value(option, 128, "cpus", optarg) == 0) {
841 node_cpumask[nodenr] = 0;
843 value = strtoull(option, &endptr, 10);
846 fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n");
848 if (*endptr == '-') {
849 endvalue = strtoull(endptr+1, &endptr, 10);
850 if (endvalue >= 63) {
853 "only 63 CPUs in NUMA mode supported.\n");
855 value = (2ULL << endvalue) - (1ULL << value);
857 value = 1ULL << value;
860 node_cpumask[nodenr] = value;
867 static void smp_parse(const char *optarg)
869 int smp, sockets = 0, threads = 0, cores = 0;
873 smp = strtoul(optarg, &endptr, 10);
874 if (endptr != optarg) {
875 if (*endptr == ',') {
879 if (get_param_value(option, 128, "sockets", endptr) != 0)
880 sockets = strtoull(option, NULL, 10);
881 if (get_param_value(option, 128, "cores", endptr) != 0)
882 cores = strtoull(option, NULL, 10);
883 if (get_param_value(option, 128, "threads", endptr) != 0)
884 threads = strtoull(option, NULL, 10);
885 if (get_param_value(option, 128, "maxcpus", endptr) != 0)
886 max_cpus = strtoull(option, NULL, 10);
888 /* compute missing values, prefer sockets over cores over threads */
889 if (smp == 0 || sockets == 0) {
890 sockets = sockets > 0 ? sockets : 1;
891 cores = cores > 0 ? cores : 1;
892 threads = threads > 0 ? threads : 1;
894 smp = cores * threads * sockets;
898 threads = threads > 0 ? threads : 1;
899 cores = smp / (sockets * threads);
901 threads = smp / (cores * sockets);
905 smp_cores = cores > 0 ? cores : 1;
906 smp_threads = threads > 0 ? threads : 1;
911 /***********************************************************/
914 static int usb_device_add(const char *devname)
917 USBDevice *dev = NULL;
922 /* drivers with .usbdevice_name entry in USBDeviceInfo */
923 dev = usbdevice_create(devname);
929 /* only the linux version is qdev-ified, usb-bsd still needs this */
930 if (strstart(devname, "host:", &p)) {
931 dev = usb_host_device_open(p);
934 if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
935 dev = usb_bt_init(devname[2] ? hci_init(p) :
936 bt_new_hci(qemu_find_bt_vlan(0)));
947 static int usb_device_del(const char *devname)
952 if (strstart(devname, "host:", &p))
953 return usb_host_device_close(p);
958 p = strchr(devname, '.');
961 bus_num = strtoul(devname, NULL, 0);
962 addr = strtoul(p + 1, NULL, 0);
964 return usb_device_delete_addr(bus_num, addr);
967 static int usb_parse(const char *cmdline)
970 r = usb_device_add(cmdline);
972 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
977 void do_usb_add(Monitor *mon, const QDict *qdict)
979 const char *devname = qdict_get_str(qdict, "devname");
980 if (usb_device_add(devname) < 0) {
981 error_report("could not add USB device '%s'", devname);
985 void do_usb_del(Monitor *mon, const QDict *qdict)
987 const char *devname = qdict_get_str(qdict, "devname");
988 if (usb_device_del(devname) < 0) {
989 error_report("could not delete USB device '%s'", devname);
993 /***********************************************************/
996 static struct pcmcia_socket_entry_s {
997 PCMCIASocket *socket;
998 struct pcmcia_socket_entry_s *next;
999 } *pcmcia_sockets = 0;
1001 void pcmcia_socket_register(PCMCIASocket *socket)
1003 struct pcmcia_socket_entry_s *entry;
1005 entry = qemu_malloc(sizeof(struct pcmcia_socket_entry_s));
1006 entry->socket = socket;
1007 entry->next = pcmcia_sockets;
1008 pcmcia_sockets = entry;
1011 void pcmcia_socket_unregister(PCMCIASocket *socket)
1013 struct pcmcia_socket_entry_s *entry, **ptr;
1015 ptr = &pcmcia_sockets;
1016 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1017 if (entry->socket == socket) {
1023 void pcmcia_info(Monitor *mon)
1025 struct pcmcia_socket_entry_s *iter;
1027 if (!pcmcia_sockets)
1028 monitor_printf(mon, "No PCMCIA sockets\n");
1030 for (iter = pcmcia_sockets; iter; iter = iter->next)
1031 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1032 iter->socket->attached ? iter->socket->card_string :
1036 /***********************************************************/
1037 /* machine registration */
1039 static QEMUMachine *first_machine = NULL;
1040 QEMUMachine *current_machine = NULL;
1042 int qemu_register_machine(QEMUMachine *m)
1045 pm = &first_machine;
1053 static QEMUMachine *find_machine(const char *name)
1057 for(m = first_machine; m != NULL; m = m->next) {
1058 if (!strcmp(m->name, name))
1060 if (m->alias && !strcmp(m->alias, name))
1066 static QEMUMachine *find_default_machine(void)
1070 for(m = first_machine; m != NULL; m = m->next) {
1071 if (m->is_default) {
1078 /***********************************************************/
1079 /* main execution loop */
1081 static void gui_update(void *opaque)
1083 uint64_t interval = GUI_REFRESH_INTERVAL;
1084 DisplayState *ds = opaque;
1085 DisplayChangeListener *dcl = ds->listeners;
1087 qemu_flush_coalesced_mmio_buffer();
1090 while (dcl != NULL) {
1091 if (dcl->gui_timer_interval &&
1092 dcl->gui_timer_interval < interval)
1093 interval = dcl->gui_timer_interval;
1096 qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock));
1099 static void nographic_update(void *opaque)
1101 uint64_t interval = GUI_REFRESH_INTERVAL;
1103 qemu_flush_coalesced_mmio_buffer();
1104 qemu_mod_timer(nographic_timer, interval + qemu_get_clock_ms(rt_clock));
1107 struct vm_change_state_entry {
1108 VMChangeStateHandler *cb;
1110 QLIST_ENTRY (vm_change_state_entry) entries;
1113 static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
1115 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1118 VMChangeStateEntry *e;
1120 e = qemu_mallocz(sizeof (*e));
1124 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
1128 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1130 QLIST_REMOVE (e, entries);
1134 void vm_state_notify(int running, int reason)
1136 VMChangeStateEntry *e;
1138 trace_vm_state_notify(running, reason);
1140 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
1141 e->cb(e->opaque, running, reason);
1150 vm_state_notify(1, 0);
1152 monitor_protocol_event(QEVENT_RESUME, NULL);
1156 /* reset/shutdown handler */
1158 typedef struct QEMUResetEntry {
1159 QTAILQ_ENTRY(QEMUResetEntry) entry;
1160 QEMUResetHandler *func;
1164 static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1165 QTAILQ_HEAD_INITIALIZER(reset_handlers);
1166 static int reset_requested;
1167 static int shutdown_requested, shutdown_signal = -1;
1168 static pid_t shutdown_pid;
1169 static int powerdown_requested;
1170 static int debug_requested;
1171 static int vmstop_requested;
1173 int qemu_shutdown_requested_get(void)
1175 return shutdown_requested;
1178 int qemu_reset_requested_get(void)
1180 return reset_requested;
1183 int qemu_shutdown_requested(void)
1185 int r = shutdown_requested;
1186 shutdown_requested = 0;
1190 void qemu_kill_report(void)
1192 if (shutdown_signal != -1) {
1193 fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal);
1194 if (shutdown_pid == 0) {
1195 /* This happens for eg ^C at the terminal, so it's worth
1196 * avoiding printing an odd message in that case.
1198 fputc('\n', stderr);
1200 fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid);
1202 shutdown_signal = -1;
1206 int qemu_reset_requested(void)
1208 int r = reset_requested;
1209 reset_requested = 0;
1213 int qemu_powerdown_requested(void)
1215 int r = powerdown_requested;
1216 powerdown_requested = 0;
1220 static int qemu_debug_requested(void)
1222 int r = debug_requested;
1223 debug_requested = 0;
1227 static int qemu_vmstop_requested(void)
1229 int r = vmstop_requested;
1230 vmstop_requested = 0;
1234 void qemu_register_reset(QEMUResetHandler *func, void *opaque)
1236 QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry));
1239 re->opaque = opaque;
1240 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
1243 void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
1247 QTAILQ_FOREACH(re, &reset_handlers, entry) {
1248 if (re->func == func && re->opaque == opaque) {
1249 QTAILQ_REMOVE(&reset_handlers, re, entry);
1256 void qemu_system_reset(void)
1258 QEMUResetEntry *re, *nre;
1260 /* reset all devices */
1261 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
1262 re->func(re->opaque);
1264 monitor_protocol_event(QEVENT_RESET, NULL);
1265 cpu_synchronize_all_post_reset();
1268 void qemu_system_reset_request(void)
1271 shutdown_requested = 1;
1273 reset_requested = 1;
1276 qemu_notify_event();
1279 void qemu_system_killed(int signal, pid_t pid)
1281 shutdown_signal = signal;
1283 qemu_system_shutdown_request();
1286 void qemu_system_shutdown_request(void)
1288 shutdown_requested = 1;
1289 qemu_notify_event();
1292 void qemu_system_powerdown_request(void)
1294 powerdown_requested = 1;
1295 qemu_notify_event();
1298 void qemu_system_debug_request(void)
1300 debug_requested = 1;
1301 qemu_notify_event();
1304 void qemu_system_vmstop_request(int reason)
1306 vmstop_requested = reason;
1307 qemu_notify_event();
1310 void main_loop_wait(int nonblocking)
1312 fd_set rfds, wfds, xfds;
1320 timeout = qemu_calculate_timeout();
1321 qemu_bh_update_timeout(&timeout);
1324 os_host_main_loop_wait(&timeout);
1326 tv.tv_sec = timeout / 1000;
1327 tv.tv_usec = (timeout % 1000) * 1000;
1329 /* poll any events */
1330 /* XXX: separate device handlers from system ones */
1335 qemu_iohandler_fill(&nfds, &rfds, &wfds, &xfds);
1336 slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
1338 qemu_mutex_unlock_iothread();
1339 ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
1340 qemu_mutex_lock_iothread();
1342 qemu_iohandler_poll(&rfds, &wfds, &xfds, ret);
1343 slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));
1345 qemu_run_all_timers();
1347 /* Check bottom-halves last in case any of the earlier events triggered
1353 #ifndef CONFIG_IOTHREAD
1354 static int vm_request_pending(void)
1356 return powerdown_requested ||
1358 shutdown_requested ||
1364 qemu_irq qemu_system_powerdown;
1366 static void main_loop(void)
1368 bool nonblocking = false;
1369 #ifdef CONFIG_PROFILER
1374 qemu_main_loop_start();
1377 #ifndef CONFIG_IOTHREAD
1378 nonblocking = cpu_exec_all();
1379 if (vm_request_pending()) {
1383 #ifdef CONFIG_PROFILER
1384 ti = profile_getclock();
1386 main_loop_wait(nonblocking);
1387 #ifdef CONFIG_PROFILER
1388 dev_time += profile_getclock() - ti;
1391 if (qemu_debug_requested()) {
1392 vm_stop(VMSTOP_DEBUG);
1394 if (qemu_shutdown_requested()) {
1396 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
1398 vm_stop(VMSTOP_SHUTDOWN);
1403 if (qemu_reset_requested()) {
1405 cpu_synchronize_all_states();
1406 qemu_system_reset();
1409 if (qemu_powerdown_requested()) {
1410 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
1411 qemu_irq_raise(qemu_system_powerdown);
1413 if ((r = qemu_vmstop_requested())) {
1421 static void version(void)
1423 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
1426 static void help(int exitcode)
1428 const char *options_help =
1429 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1431 #define DEFHEADING(text) stringify(text) "\n"
1432 #include "qemu-options.def"
1438 printf("usage: %s [options] [disk_image]\n"
1440 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1443 "During emulation, the following keys are useful:\n"
1444 "ctrl-alt-f toggle full screen\n"
1445 "ctrl-alt-n switch to virtual console 'n'\n"
1446 "ctrl-alt toggle mouse and keyboard grab\n"
1448 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1454 #define HAS_ARG 0x0001
1456 typedef struct QEMUOption {
1463 static const QEMUOption qemu_options[] = {
1464 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1465 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1466 { option, opt_arg, opt_enum, arch_mask },
1467 #define DEFHEADING(text)
1468 #include "qemu-options.def"
1474 static void select_vgahw (const char *p)
1479 vga_interface_type = VGA_NONE;
1480 if (strstart(p, "std", &opts)) {
1481 vga_interface_type = VGA_STD;
1482 } else if (strstart(p, "cirrus", &opts)) {
1483 vga_interface_type = VGA_CIRRUS;
1484 } else if (strstart(p, "vmware", &opts)) {
1485 vga_interface_type = VGA_VMWARE;
1486 } else if (strstart(p, "xenfb", &opts)) {
1487 vga_interface_type = VGA_XENFB;
1488 } else if (strstart(p, "qxl", &opts)) {
1489 vga_interface_type = VGA_QXL;
1490 } else if (!strstart(p, "none", &opts)) {
1492 fprintf(stderr, "Unknown vga type: %s\n", p);
1496 const char *nextopt;
1498 if (strstart(opts, ",retrace=", &nextopt)) {
1500 if (strstart(opts, "dumb", &nextopt))
1501 vga_retrace_method = VGA_RETRACE_DUMB;
1502 else if (strstart(opts, "precise", &nextopt))
1503 vga_retrace_method = VGA_RETRACE_PRECISE;
1504 else goto invalid_vga;
1505 } else goto invalid_vga;
1510 static DisplayType select_display(const char *p)
1513 DisplayType display = DT_DEFAULT;
1515 if (strstart(p, "sdl", &opts)) {
1519 const char *nextopt;
1521 if (strstart(opts, ",frame=", &nextopt)) {
1523 if (strstart(opts, "on", &nextopt)) {
1525 } else if (strstart(opts, "off", &nextopt)) {
1528 goto invalid_sdl_args;
1530 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
1532 if (strstart(opts, "on", &nextopt)) {
1534 } else if (strstart(opts, "off", &nextopt)) {
1537 goto invalid_sdl_args;
1539 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
1541 if (strstart(opts, "on", &nextopt)) {
1543 } else if (strstart(opts, "off", &nextopt)) {
1546 goto invalid_sdl_args;
1548 } else if (strstart(opts, ",window_close=", &nextopt)) {
1550 if (strstart(opts, "on", &nextopt)) {
1552 } else if (strstart(opts, "off", &nextopt)) {
1555 goto invalid_sdl_args;
1559 fprintf(stderr, "Invalid SDL option string: %s\n", p);
1565 fprintf(stderr, "SDL support is disabled\n");
1568 } else if (strstart(p, "vnc", &opts)) {
1573 const char *nextopt;
1575 if (strstart(opts, "=", &nextopt)) {
1576 vnc_display = nextopt;
1580 fprintf(stderr, "VNC requires a display argument vnc=<display>\n");
1584 fprintf(stderr, "VNC support is disabled\n");
1587 } else if (strstart(p, "curses", &opts)) {
1588 #ifdef CONFIG_CURSES
1589 display = DT_CURSES;
1591 fprintf(stderr, "Curses support is disabled\n");
1594 } else if (strstart(p, "none", &opts)) {
1597 fprintf(stderr, "Unknown display type: %s\n", p);
1604 static int balloon_parse(const char *arg)
1608 if (strcmp(arg, "none") == 0) {
1612 if (!strncmp(arg, "virtio", 6)) {
1613 if (arg[6] == ',') {
1614 /* have params -> parse them */
1615 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
1619 /* create empty opts */
1620 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
1622 qemu_opt_set(opts, "driver", "virtio-balloon");
1629 char *qemu_find_file(int type, const char *name)
1635 /* If name contains path separators then try it as a straight path. */
1636 if ((strchr(name, '/') || strchr(name, '\\'))
1637 && access(name, R_OK) == 0) {
1638 return qemu_strdup(name);
1641 case QEMU_FILE_TYPE_BIOS:
1644 case QEMU_FILE_TYPE_KEYMAP:
1645 subdir = "keymaps/";
1650 len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
1651 buf = qemu_mallocz(len);
1652 snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
1653 if (access(buf, R_OK)) {
1660 static int device_help_func(QemuOpts *opts, void *opaque)
1662 return qdev_device_help(opts);
1665 static int device_init_func(QemuOpts *opts, void *opaque)
1669 dev = qdev_device_add(opts);
1675 static int chardev_init_func(QemuOpts *opts, void *opaque)
1677 CharDriverState *chr;
1679 chr = qemu_chr_open_opts(opts, NULL);
1685 #ifdef CONFIG_VIRTFS
1686 static int fsdev_init_func(QemuOpts *opts, void *opaque)
1689 ret = qemu_fsdev_add(opts);
1695 static int mon_init_func(QemuOpts *opts, void *opaque)
1697 CharDriverState *chr;
1698 const char *chardev;
1702 mode = qemu_opt_get(opts, "mode");
1706 if (strcmp(mode, "readline") == 0) {
1707 flags = MONITOR_USE_READLINE;
1708 } else if (strcmp(mode, "control") == 0) {
1709 flags = MONITOR_USE_CONTROL;
1711 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
1715 if (qemu_opt_get_bool(opts, "pretty", 0))
1716 flags |= MONITOR_USE_PRETTY;
1718 if (qemu_opt_get_bool(opts, "default", 0))
1719 flags |= MONITOR_IS_DEFAULT;
1721 chardev = qemu_opt_get(opts, "chardev");
1722 chr = qemu_chr_find(chardev);
1724 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
1728 monitor_init(chr, flags);
1732 static void monitor_parse(const char *optarg, const char *mode)
1734 static int monitor_device_index = 0;
1740 if (strstart(optarg, "chardev:", &p)) {
1741 snprintf(label, sizeof(label), "%s", p);
1743 snprintf(label, sizeof(label), "compat_monitor%d",
1744 monitor_device_index);
1745 if (monitor_device_index == 0) {
1748 opts = qemu_chr_parse_compat(label, optarg);
1750 fprintf(stderr, "parse error: %s\n", optarg);
1755 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1);
1757 fprintf(stderr, "duplicate chardev: %s\n", label);
1760 qemu_opt_set(opts, "mode", mode);
1761 qemu_opt_set(opts, "chardev", label);
1763 qemu_opt_set(opts, "default", "on");
1764 monitor_device_index++;
1767 struct device_config {
1769 DEV_USB, /* -usbdevice */
1771 DEV_SERIAL, /* -serial */
1772 DEV_PARALLEL, /* -parallel */
1773 DEV_VIRTCON, /* -virtioconsole */
1774 DEV_DEBUGCON, /* -debugcon */
1776 const char *cmdline;
1777 QTAILQ_ENTRY(device_config) next;
1779 QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
1781 static void add_device_config(int type, const char *cmdline)
1783 struct device_config *conf;
1785 conf = qemu_mallocz(sizeof(*conf));
1787 conf->cmdline = cmdline;
1788 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
1791 static int foreach_device_config(int type, int (*func)(const char *cmdline))
1793 struct device_config *conf;
1796 QTAILQ_FOREACH(conf, &device_configs, next) {
1797 if (conf->type != type)
1799 rc = func(conf->cmdline);
1806 static int serial_parse(const char *devname)
1808 static int index = 0;
1811 if (strcmp(devname, "none") == 0)
1813 if (index == MAX_SERIAL_PORTS) {
1814 fprintf(stderr, "qemu: too many serial ports\n");
1817 snprintf(label, sizeof(label), "serial%d", index);
1818 serial_hds[index] = qemu_chr_open(label, devname, NULL);
1819 if (!serial_hds[index]) {
1820 fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
1821 devname, strerror(errno));
1828 static int parallel_parse(const char *devname)
1830 static int index = 0;
1833 if (strcmp(devname, "none") == 0)
1835 if (index == MAX_PARALLEL_PORTS) {
1836 fprintf(stderr, "qemu: too many parallel ports\n");
1839 snprintf(label, sizeof(label), "parallel%d", index);
1840 parallel_hds[index] = qemu_chr_open(label, devname, NULL);
1841 if (!parallel_hds[index]) {
1842 fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
1843 devname, strerror(errno));
1850 static int virtcon_parse(const char *devname)
1852 QemuOptsList *device = qemu_find_opts("device");
1853 static int index = 0;
1855 QemuOpts *bus_opts, *dev_opts;
1857 if (strcmp(devname, "none") == 0)
1859 if (index == MAX_VIRTIO_CONSOLES) {
1860 fprintf(stderr, "qemu: too many virtio consoles\n");
1864 bus_opts = qemu_opts_create(device, NULL, 0);
1865 qemu_opt_set(bus_opts, "driver", "virtio-serial");
1867 dev_opts = qemu_opts_create(device, NULL, 0);
1868 qemu_opt_set(dev_opts, "driver", "virtconsole");
1870 snprintf(label, sizeof(label), "virtcon%d", index);
1871 virtcon_hds[index] = qemu_chr_open(label, devname, NULL);
1872 if (!virtcon_hds[index]) {
1873 fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
1874 devname, strerror(errno));
1877 qemu_opt_set(dev_opts, "chardev", label);
1883 static int debugcon_parse(const char *devname)
1887 if (!qemu_chr_open("debugcon", devname, NULL)) {
1890 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1892 fprintf(stderr, "qemu: already have a debugcon device\n");
1895 qemu_opt_set(opts, "driver", "isa-debugcon");
1896 qemu_opt_set(opts, "chardev", "debugcon");
1900 static int tcg_init(void)
1906 const char *opt_name;
1908 int (*available)(void);
1912 { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
1913 { "xen", "Xen", xen_available, xen_init, &xen_allowed },
1914 { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
1917 static int configure_accelerator(void)
1919 const char *p = NULL;
1922 bool accel_initalised = 0;
1923 bool init_failed = 0;
1925 QemuOptsList *list = qemu_find_opts("machine");
1926 if (!QTAILQ_EMPTY(&list->head)) {
1927 p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel");
1931 /* Use the default "accelerator", tcg */
1935 while (!accel_initalised && *p != '\0') {
1939 p = get_opt_name(buf, sizeof (buf), p, ':');
1940 for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
1941 if (strcmp(accel_list[i].opt_name, buf) == 0) {
1942 *(accel_list[i].allowed) = 1;
1943 ret = accel_list[i].init();
1946 if (!accel_list[i].available()) {
1947 printf("%s not supported for this target\n",
1948 accel_list[i].name);
1950 fprintf(stderr, "failed to initialize %s: %s\n",
1954 *(accel_list[i].allowed) = 0;
1956 accel_initalised = 1;
1961 if (i == ARRAY_SIZE(accel_list)) {
1962 fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
1966 if (!accel_initalised) {
1967 fprintf(stderr, "No accelerator found!\n");
1972 fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
1975 return !accel_initalised;
1978 void qemu_add_exit_notifier(Notifier *notify)
1980 notifier_list_add(&exit_notifiers, notify);
1983 void qemu_remove_exit_notifier(Notifier *notify)
1985 notifier_list_remove(&exit_notifiers, notify);
1988 static void qemu_run_exit_notifiers(void)
1990 notifier_list_notify(&exit_notifiers);
1993 void qemu_add_machine_init_done_notifier(Notifier *notify)
1995 notifier_list_add(&machine_init_done_notifiers, notify);
1998 static void qemu_run_machine_init_done_notifiers(void)
2000 notifier_list_notify(&machine_init_done_notifiers);
2003 static const QEMUOption *lookup_opt(int argc, char **argv,
2004 const char **poptarg, int *poptind)
2006 const QEMUOption *popt;
2007 int optind = *poptind;
2008 char *r = argv[optind];
2011 loc_set_cmdline(argv, optind, 1);
2013 /* Treat --foo the same as -foo. */
2016 popt = qemu_options;
2019 error_report("invalid option");
2022 if (!strcmp(popt->name, r + 1))
2026 if (popt->flags & HAS_ARG) {
2027 if (optind >= argc) {
2028 error_report("requires an argument");
2031 optarg = argv[optind++];
2032 loc_set_cmdline(argv, optind - 2, 2);
2043 int main(int argc, char **argv, char **envp)
2045 const char *gdbstub_dev = NULL;
2047 int snapshot, linux_boot;
2048 const char *icount_option = NULL;
2049 const char *initrd_filename;
2050 const char *kernel_filename, *kernel_cmdline;
2051 char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
2053 DisplayChangeListener *dcl;
2054 int cyls, heads, secs, translation;
2055 QemuOpts *hda_opts = NULL, *opts;
2056 QemuOptsList *olist;
2059 const char *loadvm = NULL;
2060 QEMUMachine *machine;
2061 const char *cpu_model;
2063 const char *pid_file = NULL;
2064 const char *incoming = NULL;
2066 int show_vnc_port = 0;
2069 const char *trace_file = NULL;
2070 const char *log_mask = NULL;
2071 const char *log_file = NULL;
2073 atexit(qemu_run_exit_notifiers);
2074 error_set_progname(argv[0]);
2078 qemu_cache_utils_init(envp);
2080 QLIST_INIT (&vm_change_state_head);
2081 os_setup_early_signal_handling();
2083 module_call_init(MODULE_INIT_MACHINE);
2084 machine = find_default_machine();
2086 initrd_filename = NULL;
2089 kernel_filename = NULL;
2090 kernel_cmdline = "";
2091 cyls = heads = secs = 0;
2092 translation = BIOS_ATA_TRANSLATION_AUTO;
2094 for (i = 0; i < MAX_NODES; i++) {
2096 node_cpumask[i] = 0;
2105 /* first pass of option parsing */
2107 while (optind < argc) {
2108 if (argv[optind][0] != '-') {
2113 const QEMUOption *popt;
2115 popt = lookup_opt(argc, argv, &optarg, &optind);
2116 switch (popt->index) {
2117 case QEMU_OPTION_nodefconfig:
2127 ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
2128 if (ret < 0 && ret != -ENOENT) {
2132 ret = qemu_read_config_file(arch_config_name);
2133 if (ret < 0 && ret != -ENOENT) {
2139 /* second pass of option parsing */
2144 if (argv[optind][0] != '-') {
2145 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
2147 const QEMUOption *popt;
2149 popt = lookup_opt(argc, argv, &optarg, &optind);
2150 if (!(popt->arch_mask & arch_type)) {
2151 printf("Option %s not supported for this target\n", popt->name);
2154 switch(popt->index) {
2156 machine = find_machine(optarg);
2159 printf("Supported machines are:\n");
2160 for(m = first_machine; m != NULL; m = m->next) {
2162 printf("%-10s %s (alias of %s)\n",
2163 m->alias, m->desc, m->name);
2164 printf("%-10s %s%s\n",
2166 m->is_default ? " (default)" : "");
2168 exit(*optarg != '?');
2171 case QEMU_OPTION_cpu:
2172 /* hw initialization will check this */
2173 if (*optarg == '?') {
2174 list_cpus(stdout, &fprintf, optarg);
2180 case QEMU_OPTION_initrd:
2181 initrd_filename = optarg;
2183 case QEMU_OPTION_hda:
2187 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2189 snprintf(buf, sizeof(buf),
2190 "%s,cyls=%d,heads=%d,secs=%d%s",
2191 HD_OPTS , cyls, heads, secs,
2192 translation == BIOS_ATA_TRANSLATION_LBA ?
2194 translation == BIOS_ATA_TRANSLATION_NONE ?
2195 ",trans=none" : "");
2196 drive_add(IF_DEFAULT, 0, optarg, buf);
2199 case QEMU_OPTION_hdb:
2200 case QEMU_OPTION_hdc:
2201 case QEMU_OPTION_hdd:
2202 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2205 case QEMU_OPTION_drive:
2206 if (drive_def(optarg) == NULL) {
2210 case QEMU_OPTION_set:
2211 if (qemu_set_option(optarg) != 0)
2214 case QEMU_OPTION_global:
2215 if (qemu_global_option(optarg) != 0)
2218 case QEMU_OPTION_mtdblock:
2219 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
2221 case QEMU_OPTION_sd:
2222 drive_add(IF_SD, 0, optarg, SD_OPTS);
2224 case QEMU_OPTION_pflash:
2225 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
2227 case QEMU_OPTION_snapshot:
2230 case QEMU_OPTION_hdachs:
2234 cyls = strtol(p, (char **)&p, 0);
2235 if (cyls < 1 || cyls > 16383)
2240 heads = strtol(p, (char **)&p, 0);
2241 if (heads < 1 || heads > 16)
2246 secs = strtol(p, (char **)&p, 0);
2247 if (secs < 1 || secs > 63)
2251 if (!strcmp(p, "none"))
2252 translation = BIOS_ATA_TRANSLATION_NONE;
2253 else if (!strcmp(p, "lba"))
2254 translation = BIOS_ATA_TRANSLATION_LBA;
2255 else if (!strcmp(p, "auto"))
2256 translation = BIOS_ATA_TRANSLATION_AUTO;
2259 } else if (*p != '\0') {
2261 fprintf(stderr, "qemu: invalid physical CHS format\n");
2264 if (hda_opts != NULL) {
2266 snprintf(num, sizeof(num), "%d", cyls);
2267 qemu_opt_set(hda_opts, "cyls", num);
2268 snprintf(num, sizeof(num), "%d", heads);
2269 qemu_opt_set(hda_opts, "heads", num);
2270 snprintf(num, sizeof(num), "%d", secs);
2271 qemu_opt_set(hda_opts, "secs", num);
2272 if (translation == BIOS_ATA_TRANSLATION_LBA)
2273 qemu_opt_set(hda_opts, "trans", "lba");
2274 if (translation == BIOS_ATA_TRANSLATION_NONE)
2275 qemu_opt_set(hda_opts, "trans", "none");
2279 case QEMU_OPTION_numa:
2280 if (nb_numa_nodes >= MAX_NODES) {
2281 fprintf(stderr, "qemu: too many NUMA nodes\n");
2286 case QEMU_OPTION_display:
2287 display_type = select_display(optarg);
2289 case QEMU_OPTION_nographic:
2290 display_type = DT_NOGRAPHIC;
2292 case QEMU_OPTION_curses:
2293 #ifdef CONFIG_CURSES
2294 display_type = DT_CURSES;
2296 fprintf(stderr, "Curses support is disabled\n");
2300 case QEMU_OPTION_portrait:
2303 case QEMU_OPTION_kernel:
2304 kernel_filename = optarg;
2306 case QEMU_OPTION_append:
2307 kernel_cmdline = optarg;
2309 case QEMU_OPTION_cdrom:
2310 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
2312 case QEMU_OPTION_boot:
2314 static const char * const params[] = {
2315 "order", "once", "menu", NULL
2317 char buf[sizeof(boot_devices)];
2318 char *standard_boot_devices;
2321 if (!strchr(optarg, '=')) {
2323 pstrcpy(buf, sizeof(buf), optarg);
2324 } else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
2326 "qemu: unknown boot parameter '%s' in '%s'\n",
2332 get_param_value(buf, sizeof(buf), "order", optarg)) {
2333 validate_bootdevices(buf);
2334 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2337 if (get_param_value(buf, sizeof(buf),
2339 validate_bootdevices(buf);
2340 standard_boot_devices = qemu_strdup(boot_devices);
2341 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2342 qemu_register_reset(restore_boot_devices,
2343 standard_boot_devices);
2345 if (get_param_value(buf, sizeof(buf),
2347 if (!strcmp(buf, "on")) {
2349 } else if (!strcmp(buf, "off")) {
2353 "qemu: invalid option value '%s'\n",
2361 case QEMU_OPTION_fda:
2362 case QEMU_OPTION_fdb:
2363 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2366 case QEMU_OPTION_no_fd_bootchk:
2369 case QEMU_OPTION_netdev:
2370 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
2374 case QEMU_OPTION_net:
2375 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
2380 case QEMU_OPTION_tftp:
2381 legacy_tftp_prefix = optarg;
2383 case QEMU_OPTION_bootp:
2384 legacy_bootp_filename = optarg;
2386 case QEMU_OPTION_redir:
2387 if (net_slirp_redir(optarg) < 0)
2391 case QEMU_OPTION_bt:
2392 add_device_config(DEV_BT, optarg);
2394 case QEMU_OPTION_audio_help:
2395 if (!(audio_available())) {
2396 printf("Option %s not supported for this target\n", popt->name);
2402 case QEMU_OPTION_soundhw:
2403 if (!(audio_available())) {
2404 printf("Option %s not supported for this target\n", popt->name);
2407 select_soundhw (optarg);
2412 case QEMU_OPTION_version:
2416 case QEMU_OPTION_m: {
2419 value = strtosz(optarg, NULL);
2421 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
2425 /* On 32-bit hosts, QEMU is limited by virtual address space */
2426 if (value > (2047 << 20) && HOST_LONG_BITS == 32) {
2427 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
2430 if (value != (uint64_t)(ram_addr_t)value) {
2431 fprintf(stderr, "qemu: ram size too large\n");
2437 case QEMU_OPTION_mempath:
2441 case QEMU_OPTION_mem_prealloc:
2452 gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT;
2454 case QEMU_OPTION_gdb:
2455 gdbstub_dev = optarg;
2460 case QEMU_OPTION_bios:
2463 case QEMU_OPTION_singlestep:
2470 keyboard_layout = optarg;
2472 case QEMU_OPTION_localtime:
2475 case QEMU_OPTION_vga:
2476 select_vgahw (optarg);
2483 w = strtol(p, (char **)&p, 10);
2486 fprintf(stderr, "qemu: invalid resolution or depth\n");
2492 h = strtol(p, (char **)&p, 10);
2497 depth = strtol(p, (char **)&p, 10);
2498 if (depth != 8 && depth != 15 && depth != 16 &&
2499 depth != 24 && depth != 32)
2501 } else if (*p == '\0') {
2502 depth = graphic_depth;
2509 graphic_depth = depth;
2512 case QEMU_OPTION_echr:
2515 term_escape_char = strtol(optarg, &r, 0);
2517 printf("Bad argument to echr\n");
2520 case QEMU_OPTION_monitor:
2521 monitor_parse(optarg, "readline");
2522 default_monitor = 0;
2524 case QEMU_OPTION_qmp:
2525 monitor_parse(optarg, "control");
2526 default_monitor = 0;
2528 case QEMU_OPTION_mon:
2529 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
2533 default_monitor = 0;
2535 case QEMU_OPTION_chardev:
2536 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
2541 case QEMU_OPTION_fsdev:
2542 olist = qemu_find_opts("fsdev");
2544 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
2547 opts = qemu_opts_parse(olist, optarg, 1);
2549 fprintf(stderr, "parse error: %s\n", optarg);
2553 case QEMU_OPTION_virtfs: {
2557 olist = qemu_find_opts("virtfs");
2559 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
2562 opts = qemu_opts_parse(olist, optarg, 1);
2564 fprintf(stderr, "parse error: %s\n", optarg);
2568 if (qemu_opt_get(opts, "fstype") == NULL ||
2569 qemu_opt_get(opts, "mount_tag") == NULL ||
2570 qemu_opt_get(opts, "path") == NULL ||
2571 qemu_opt_get(opts, "security_model") == NULL) {
2572 fprintf(stderr, "Usage: -virtfs fstype,path=/share_path/,"
2573 "security_model=[mapped|passthrough|none],"
2574 "mount_tag=tag.\n");
2578 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
2579 qemu_opt_get(opts, "mount_tag"), 1);
2581 fprintf(stderr, "duplicate fsdev id: %s\n",
2582 qemu_opt_get(opts, "mount_tag"));
2585 qemu_opt_set(fsdev, "fstype", qemu_opt_get(opts, "fstype"));
2586 qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"));
2587 qemu_opt_set(fsdev, "security_model",
2588 qemu_opt_get(opts, "security_model"));
2590 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
2591 qemu_opt_set(device, "driver", "virtio-9p-pci");
2592 qemu_opt_set(device, "fsdev",
2593 qemu_opt_get(opts, "mount_tag"));
2594 qemu_opt_set(device, "mount_tag",
2595 qemu_opt_get(opts, "mount_tag"));
2598 case QEMU_OPTION_serial:
2599 add_device_config(DEV_SERIAL, optarg);
2601 if (strncmp(optarg, "mon:", 4) == 0) {
2602 default_monitor = 0;
2605 case QEMU_OPTION_watchdog:
2608 "qemu: only one watchdog option may be given\n");
2613 case QEMU_OPTION_watchdog_action:
2614 if (select_watchdog_action(optarg) == -1) {
2615 fprintf(stderr, "Unknown -watchdog-action parameter\n");
2619 case QEMU_OPTION_virtiocon:
2620 add_device_config(DEV_VIRTCON, optarg);
2621 default_virtcon = 0;
2622 if (strncmp(optarg, "mon:", 4) == 0) {
2623 default_monitor = 0;
2626 case QEMU_OPTION_parallel:
2627 add_device_config(DEV_PARALLEL, optarg);
2628 default_parallel = 0;
2629 if (strncmp(optarg, "mon:", 4) == 0) {
2630 default_monitor = 0;
2633 case QEMU_OPTION_debugcon:
2634 add_device_config(DEV_DEBUGCON, optarg);
2636 case QEMU_OPTION_loadvm:
2639 case QEMU_OPTION_full_screen:
2643 case QEMU_OPTION_no_frame:
2646 case QEMU_OPTION_alt_grab:
2649 case QEMU_OPTION_ctrl_grab:
2652 case QEMU_OPTION_no_quit:
2655 case QEMU_OPTION_sdl:
2656 display_type = DT_SDL;
2659 case QEMU_OPTION_no_frame:
2660 case QEMU_OPTION_alt_grab:
2661 case QEMU_OPTION_ctrl_grab:
2662 case QEMU_OPTION_no_quit:
2663 case QEMU_OPTION_sdl:
2664 fprintf(stderr, "SDL support is disabled\n");
2667 case QEMU_OPTION_pidfile:
2670 case QEMU_OPTION_win2k_hack:
2671 win2k_install_hack = 1;
2673 case QEMU_OPTION_rtc_td_hack:
2676 case QEMU_OPTION_acpitable:
2677 do_acpitable_option(optarg);
2679 case QEMU_OPTION_smbios:
2680 do_smbios_option(optarg);
2682 case QEMU_OPTION_enable_kvm:
2683 olist = qemu_find_opts("machine");
2684 qemu_opts_reset(olist);
2685 qemu_opts_parse(olist, "accel=kvm", 0);
2687 case QEMU_OPTION_machine:
2688 olist = qemu_find_opts("machine");
2689 qemu_opts_reset(olist);
2690 opts = qemu_opts_parse(olist, optarg, 0);
2692 fprintf(stderr, "parse error: %s\n", optarg);
2696 case QEMU_OPTION_usb:
2699 case QEMU_OPTION_usbdevice:
2701 add_device_config(DEV_USB, optarg);
2703 case QEMU_OPTION_device:
2704 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
2708 case QEMU_OPTION_smp:
2711 fprintf(stderr, "Invalid number of CPUs\n");
2714 if (max_cpus < smp_cpus) {
2715 fprintf(stderr, "maxcpus must be equal to or greater than "
2719 if (max_cpus > 255) {
2720 fprintf(stderr, "Unsupported number of maxcpus\n");
2724 case QEMU_OPTION_vnc:
2727 vnc_display = optarg;
2729 fprintf(stderr, "VNC support is disabled\n");
2733 case QEMU_OPTION_no_acpi:
2736 case QEMU_OPTION_no_hpet:
2739 case QEMU_OPTION_balloon:
2740 if (balloon_parse(optarg) < 0) {
2741 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
2745 case QEMU_OPTION_no_reboot:
2748 case QEMU_OPTION_no_shutdown:
2751 case QEMU_OPTION_show_cursor:
2754 case QEMU_OPTION_uuid:
2755 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
2756 fprintf(stderr, "Fail to parse UUID string."
2757 " Wrong format.\n");
2761 case QEMU_OPTION_option_rom:
2762 if (nb_option_roms >= MAX_OPTION_ROMS) {
2763 fprintf(stderr, "Too many option ROMs\n");
2766 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
2767 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
2768 option_rom[nb_option_roms].bootindex =
2769 qemu_opt_get_number(opts, "bootindex", -1);
2770 if (!option_rom[nb_option_roms].name) {
2771 fprintf(stderr, "Option ROM file is not specified\n");
2776 case QEMU_OPTION_semihosting:
2777 semihosting_enabled = 1;
2779 case QEMU_OPTION_name:
2780 qemu_name = qemu_strdup(optarg);
2782 char *p = strchr(qemu_name, ',');
2785 if (strncmp(p, "process=", 8)) {
2786 fprintf(stderr, "Unknown subargument %s to -name\n", p);
2790 os_set_proc_name(p);
2794 case QEMU_OPTION_prom_env:
2795 if (nb_prom_envs >= MAX_PROM_ENVS) {
2796 fprintf(stderr, "Too many prom variables\n");
2799 prom_envs[nb_prom_envs] = optarg;
2802 case QEMU_OPTION_old_param:
2805 case QEMU_OPTION_clock:
2806 configure_alarms(optarg);
2808 case QEMU_OPTION_startdate:
2809 configure_rtc_date_offset(optarg, 1);
2811 case QEMU_OPTION_rtc:
2812 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
2816 configure_rtc(opts);
2818 case QEMU_OPTION_tb_size:
2819 tb_size = strtol(optarg, NULL, 0);
2823 case QEMU_OPTION_icount:
2824 icount_option = optarg;
2826 case QEMU_OPTION_incoming:
2828 incoming_expected = true;
2830 case QEMU_OPTION_nodefaults:
2832 default_parallel = 0;
2833 default_virtcon = 0;
2834 default_monitor = 0;
2841 case QEMU_OPTION_xen_domid:
2842 if (!(xen_available())) {
2843 printf("Option %s not supported for this target\n", popt->name);
2846 xen_domid = atoi(optarg);
2848 case QEMU_OPTION_xen_create:
2849 if (!(xen_available())) {
2850 printf("Option %s not supported for this target\n", popt->name);
2853 xen_mode = XEN_CREATE;
2855 case QEMU_OPTION_xen_attach:
2856 if (!(xen_available())) {
2857 printf("Option %s not supported for this target\n", popt->name);
2860 xen_mode = XEN_ATTACH;
2862 #ifdef CONFIG_SIMPLE_TRACE
2863 case QEMU_OPTION_trace:
2864 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
2866 trace_file = qemu_opt_get(opts, "file");
2870 case QEMU_OPTION_readconfig:
2872 int ret = qemu_read_config_file(optarg);
2874 fprintf(stderr, "read config %s: %s\n", optarg,
2880 case QEMU_OPTION_spice:
2881 olist = qemu_find_opts("spice");
2883 fprintf(stderr, "spice is not supported by this qemu build.\n");
2886 opts = qemu_opts_parse(olist, optarg, 0);
2888 fprintf(stderr, "parse error: %s\n", optarg);
2892 case QEMU_OPTION_writeconfig:
2895 if (strcmp(optarg, "-") == 0) {
2898 fp = fopen(optarg, "w");
2900 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
2904 qemu_config_write(fp);
2909 os_parse_cmd_args(popt->index, optarg);
2915 /* Open the logfile at this point, if necessary. We can't open the logfile
2916 * when encountering either of the logging options (-d or -D) because the
2917 * other one may be encountered later on the command line, changing the
2918 * location or level of logging.
2922 set_cpu_log_filename(log_file);
2924 set_cpu_log(log_mask);
2927 if (!st_init(trace_file)) {
2928 fprintf(stderr, "warning: unable to initialize simple trace backend\n");
2931 /* If no data_dir is specified then try to find it relative to the
2934 data_dir = os_find_datadir(argv[0]);
2936 /* If all else fails use the install patch specified when building. */
2938 data_dir = CONFIG_QEMU_DATADIR;
2942 * Default to max_cpus = smp_cpus, in case the user doesn't
2943 * specify a max_cpus value.
2946 max_cpus = smp_cpus;
2948 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
2949 if (smp_cpus > machine->max_cpus) {
2950 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
2951 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
2957 * Get the default machine options from the machine if it is not already
2958 * specified either by the configuration file or by the command line.
2960 if (machine->default_machine_opts) {
2961 QemuOptsList *list = qemu_find_opts("machine");
2962 const char *p = NULL;
2964 if (!QTAILQ_EMPTY(&list->head)) {
2965 p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel");
2968 opts = qemu_opts_parse(qemu_find_opts("machine"),
2969 machine->default_machine_opts, 0);
2971 fprintf(stderr, "parse error for machine %s: %s\n",
2972 machine->name, machine->default_machine_opts);
2978 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
2979 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
2981 if (machine->no_serial) {
2984 if (machine->no_parallel) {
2985 default_parallel = 0;
2987 if (!machine->use_virtcon) {
2988 default_virtcon = 0;
2990 if (machine->no_vga) {
2993 if (machine->no_floppy) {
2996 if (machine->no_cdrom) {
2999 if (machine->no_sdcard) {
3003 if (display_type == DT_NOGRAPHIC) {
3004 if (default_parallel)
3005 add_device_config(DEV_PARALLEL, "null");
3006 if (default_serial && default_monitor) {
3007 add_device_config(DEV_SERIAL, "mon:stdio");
3008 } else if (default_virtcon && default_monitor) {
3009 add_device_config(DEV_VIRTCON, "mon:stdio");
3012 add_device_config(DEV_SERIAL, "stdio");
3013 if (default_virtcon)
3014 add_device_config(DEV_VIRTCON, "stdio");
3015 if (default_monitor)
3016 monitor_parse("stdio", "readline");
3020 add_device_config(DEV_SERIAL, "vc:80Cx24C");
3021 if (default_parallel)
3022 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
3023 if (default_monitor)
3024 monitor_parse("vc:80Cx24C", "readline");
3025 if (default_virtcon)
3026 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
3029 vga_interface_type = VGA_CIRRUS;
3033 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
3035 #ifdef CONFIG_VIRTFS
3036 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
3043 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
3048 configure_accelerator();
3050 if (qemu_init_main_loop()) {
3051 fprintf(stderr, "qemu_init_main_loop failed\n");
3054 linux_boot = (kernel_filename != NULL);
3056 if (!linux_boot && *kernel_cmdline != '\0') {
3057 fprintf(stderr, "-append only allowed with -kernel option\n");
3061 if (!linux_boot && initrd_filename != NULL) {
3062 fprintf(stderr, "-initrd only allowed with -kernel option\n");
3066 os_set_line_buffering();
3068 if (init_timer_alarm() < 0) {
3069 fprintf(stderr, "could not initialize alarm timer\n");
3072 configure_icount(icount_option);
3074 if (net_init_clients() < 0) {
3078 /* init the bluetooth world */
3079 if (foreach_device_config(DEV_BT, bt_parse))
3082 /* init the memory */
3084 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
3086 /* init the dynamic translator */
3087 cpu_exec_init_all(tb_size * 1024 * 1024);
3089 bdrv_init_with_whitelist();
3093 /* open the virtual block devices */
3095 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
3096 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
3099 default_drive(default_cdrom, snapshot, machine->use_scsi,
3100 IF_DEFAULT, 2, CDROM_OPTS);
3101 default_drive(default_floppy, snapshot, machine->use_scsi,
3102 IF_FLOPPY, 0, FD_OPTS);
3103 default_drive(default_sdcard, snapshot, machine->use_scsi,
3106 register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL,
3109 if (nb_numa_nodes > 0) {
3112 if (nb_numa_nodes > smp_cpus) {
3113 nb_numa_nodes = smp_cpus;
3116 /* If no memory size if given for any node, assume the default case
3117 * and distribute the available memory equally across all nodes
3119 for (i = 0; i < nb_numa_nodes; i++) {
3120 if (node_mem[i] != 0)
3123 if (i == nb_numa_nodes) {
3124 uint64_t usedmem = 0;
3126 /* On Linux, the each node's border has to be 8MB aligned,
3127 * the final node gets the rest.
3129 for (i = 0; i < nb_numa_nodes - 1; i++) {
3130 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
3131 usedmem += node_mem[i];
3133 node_mem[i] = ram_size - usedmem;
3136 for (i = 0; i < nb_numa_nodes; i++) {
3137 if (node_cpumask[i] != 0)
3140 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3141 * must cope with this anyway, because there are BIOSes out there in
3142 * real machines which also use this scheme.
3144 if (i == nb_numa_nodes) {
3145 for (i = 0; i < smp_cpus; i++) {
3146 node_cpumask[i % nb_numa_nodes] |= 1 << i;
3151 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
3155 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
3157 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
3159 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
3161 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
3164 module_call_init(MODULE_INIT_DEVICE);
3166 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0)
3170 i = select_watchdog(watchdog);
3172 exit (i == 1 ? 1 : 0);
3175 if (machine->compat_props) {
3176 qdev_prop_register_global_list(machine->compat_props);
3180 machine->init(ram_size, boot_devices,
3181 kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
3183 cpu_synchronize_all_post_init();
3187 current_machine = machine;
3189 /* init USB devices */
3191 if (foreach_device_config(DEV_USB, usb_parse) < 0)
3195 /* init generic devices */
3196 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
3199 net_check_clients();
3201 /* just use the first displaystate for the moment */
3202 ds = get_displaystate();
3206 if (display_type == DT_DEFAULT && !display_remote) {
3207 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3208 display_type = DT_SDL;
3209 #elif defined(CONFIG_VNC)
3210 vnc_display = "localhost:0,to=99";
3213 display_type = DT_NONE;
3218 /* init local displays */
3219 switch (display_type) {
3222 #if defined(CONFIG_CURSES)
3224 curses_display_init(ds, full_screen);
3227 #if defined(CONFIG_SDL)
3229 sdl_display_init(ds, full_screen, no_frame);
3231 #elif defined(CONFIG_COCOA)
3233 cocoa_display_init(ds, full_screen);
3240 /* must be after terminal init, SDL library changes signal handlers */
3241 os_setup_signal_handling();
3244 /* init remote displays */
3246 vnc_display_init(ds);
3247 if (vnc_display_open(ds, vnc_display) < 0)
3250 if (show_vnc_port) {
3251 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
3256 if (using_spice && !qxl_enabled) {
3257 qemu_spice_display_init(ds);
3263 dcl = ds->listeners;
3264 while (dcl != NULL) {
3265 if (dcl->dpy_refresh != NULL) {
3266 ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds);
3267 qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock));
3272 if (ds->gui_timer == NULL) {
3273 nographic_timer = qemu_new_timer_ms(rt_clock, nographic_update, NULL);
3274 qemu_mod_timer(nographic_timer, qemu_get_clock_ms(rt_clock));
3276 text_consoles_set_display(ds);
3278 if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) {
3279 fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n",
3284 qdev_machine_creation_done();
3286 if (rom_load_all() != 0) {
3287 fprintf(stderr, "rom loading failed\n");
3291 /* TODO: once all bus devices are qdevified, this should be done
3292 * when bus is created by qdev.c */
3293 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
3294 qemu_run_machine_init_done_notifiers();
3296 qemu_system_reset();
3298 if (load_vmstate(loadvm) < 0) {
3304 int ret = qemu_start_incoming_migration(incoming);
3306 fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n",
3310 } else if (autostart) {