4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 /* Needed early for CONFIG_BSD etc. */
33 #include "config-host.h"
37 #include <sys/times.h>
41 #include <sys/ioctl.h>
42 #include <sys/resource.h>
43 #include <sys/socket.h>
44 #include <netinet/in.h>
46 #include <arpa/inet.h>
49 #include <sys/select.h>
50 #ifdef CONFIG_SIMPLE_TRACE
56 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
58 #include <sys/sysctl.h>
67 #include <linux/ppdev.h>
68 #include <linux/parport.h>
72 #include <sys/ethernet.h>
73 #include <sys/sockio.h>
74 #include <netinet/arp.h>
75 #include <netinet/in_systm.h>
76 #include <netinet/ip.h>
77 #include <netinet/ip_icmp.h> // must come after ip.h
78 #include <netinet/udp.h>
79 #include <netinet/tcp.h>
87 #if defined(__OpenBSD__)
91 #if defined(CONFIG_VDE)
92 #include <libvdeplug.h>
100 #if defined(__APPLE__) || defined(main)
102 int qemu_main(int argc
, char **argv
, char **envp
);
103 int main(int argc
, char **argv
)
105 return qemu_main(argc
, argv
, NULL
);
108 #define main qemu_main
110 #endif /* CONFIG_SDL */
114 #define main qemu_main
115 #endif /* CONFIG_COCOA */
118 #include "hw/boards.h"
120 #include "hw/pcmcia.h"
125 #include "hw/watchdog.h"
126 #include "hw/smbios.h"
129 #include "hw/loader.h"
132 #include "net/slirp.h"
137 #include "qemu-timer.h"
138 #include "qemu-char.h"
139 #include "cache-utils.h"
141 #include "blockdev.h"
142 #include "block-migration.h"
144 #include "audio/audio.h"
145 #include "migration.h"
147 #include "qemu-option.h"
148 #include "qemu-config.h"
149 #include "qemu-objects.h"
150 #include "qemu-options.h"
152 #include "fsdev/qemu-fsdev.h"
157 #include "qemu_socket.h"
159 #include "slirp/libslirp.h"
162 #include "qemu-queue.h"
164 #include "arch_init.h"
166 #include "ui/qemu-spice.h"
169 //#define DEBUG_SLIRP
171 #define DEFAULT_RAM_SIZE 128
173 #define MAX_VIRTIO_CONSOLES 1
175 static const char *data_dir
;
176 const char *bios_name
= NULL
;
177 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
178 DisplayType display_type
= DT_DEFAULT
;
179 int display_remote
= 0;
180 const char* keyboard_layout
= NULL
;
182 const char *mem_path
= NULL
;
184 int mem_prealloc
= 0; /* force preallocation of physical target memory */
187 NICInfo nd_table
[MAX_NICS
];
190 int incoming_expected
; /* Started with -incoming and waiting for incoming */
191 static int rtc_utc
= 1;
192 static int rtc_date_offset
= -1; /* -1 means no change */
193 QEMUClock
*rtc_clock
;
194 int vga_interface_type
= VGA_NONE
;
195 static int full_screen
= 0;
197 static int no_frame
= 0;
200 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
201 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
202 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
203 int win2k_install_hack
= 0;
211 const char *vnc_display
;
212 int acpi_enabled
= 1;
218 int graphic_rotate
= 0;
219 uint8_t irq0override
= 1;
220 const char *watchdog
;
221 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
223 int semihosting_enabled
= 0;
225 const char *qemu_name
;
228 unsigned int nb_prom_envs
= 0;
229 const char *prom_envs
[MAX_PROM_ENVS
];
232 typedef struct FWBootEntry FWBootEntry
;
235 QTAILQ_ENTRY(FWBootEntry
) link
;
241 QTAILQ_HEAD(, FWBootEntry
) fw_boot_order
= QTAILQ_HEAD_INITIALIZER(fw_boot_order
);
244 uint64_t node_mem
[MAX_NODES
];
245 uint64_t node_cpumask
[MAX_NODES
];
247 static QEMUTimer
*nographic_timer
;
249 uint8_t qemu_uuid
[16];
251 static QEMUBootSetHandler
*boot_set_handler
;
252 static void *boot_set_opaque
;
254 static NotifierList exit_notifiers
=
255 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
257 static NotifierList machine_init_done_notifiers
=
258 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
262 enum xen_mode xen_mode
= XEN_EMULATE
;
264 static int default_serial
= 1;
265 static int default_parallel
= 1;
266 static int default_virtcon
= 1;
267 static int default_monitor
= 1;
268 static int default_vga
= 1;
269 static int default_floppy
= 1;
270 static int default_cdrom
= 1;
271 static int default_sdcard
= 1;
277 { .driver
= "isa-serial", .flag
= &default_serial
},
278 { .driver
= "isa-parallel", .flag
= &default_parallel
},
279 { .driver
= "isa-fdc", .flag
= &default_floppy
},
280 { .driver
= "ide-drive", .flag
= &default_cdrom
},
281 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
282 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
283 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
284 { .driver
= "VGA", .flag
= &default_vga
},
285 { .driver
= "cirrus-vga", .flag
= &default_vga
},
286 { .driver
= "vmware-svga", .flag
= &default_vga
},
289 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
291 const char *driver
= qemu_opt_get(opts
, "driver");
296 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
297 if (strcmp(default_list
[i
].driver
, driver
) != 0)
299 *(default_list
[i
].flag
) = 0;
304 /***********************************************************/
305 /* real time host monotonic timer */
307 /***********************************************************/
308 /* host time/date access */
309 void qemu_get_timedate(struct tm
*tm
, int offset
)
316 if (rtc_date_offset
== -1) {
320 ret
= localtime(&ti
);
322 ti
-= rtc_date_offset
;
326 memcpy(tm
, ret
, sizeof(struct tm
));
329 int qemu_timedate_diff(struct tm
*tm
)
333 if (rtc_date_offset
== -1)
335 seconds
= mktimegm(tm
);
337 seconds
= mktime(tm
);
339 seconds
= mktimegm(tm
) + rtc_date_offset
;
341 return seconds
- time(NULL
);
344 void rtc_change_mon_event(struct tm
*tm
)
348 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
349 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
350 qobject_decref(data
);
353 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
355 time_t rtc_start_date
;
358 if (!strcmp(startdate
, "now") && legacy
) {
359 rtc_date_offset
= -1;
361 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
369 } else if (sscanf(startdate
, "%d-%d-%d",
381 rtc_start_date
= mktimegm(&tm
);
382 if (rtc_start_date
== -1) {
384 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
385 "'2006-06-17T16:01:21' or '2006-06-17'\n");
388 rtc_date_offset
= time(NULL
) - rtc_start_date
;
392 static void configure_rtc(QemuOpts
*opts
)
396 value
= qemu_opt_get(opts
, "base");
398 if (!strcmp(value
, "utc")) {
400 } else if (!strcmp(value
, "localtime")) {
403 configure_rtc_date_offset(value
, 0);
406 value
= qemu_opt_get(opts
, "clock");
408 if (!strcmp(value
, "host")) {
409 rtc_clock
= host_clock
;
410 } else if (!strcmp(value
, "vm")) {
411 rtc_clock
= vm_clock
;
413 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
417 value
= qemu_opt_get(opts
, "driftfix");
419 if (!strcmp(value
, "slew")) {
421 } else if (!strcmp(value
, "none")) {
424 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
430 /***********************************************************/
431 /* Bluetooth support */
434 static struct HCIInfo
*hci_table
[MAX_NICS
];
436 static struct bt_vlan_s
{
437 struct bt_scatternet_s net
;
439 struct bt_vlan_s
*next
;
442 /* find or alloc a new bluetooth "VLAN" */
443 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
445 struct bt_vlan_s
**pvlan
, *vlan
;
446 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
450 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
452 pvlan
= &first_bt_vlan
;
453 while (*pvlan
!= NULL
)
454 pvlan
= &(*pvlan
)->next
;
459 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
463 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
468 static struct HCIInfo null_hci
= {
469 .cmd_send
= null_hci_send
,
470 .sco_send
= null_hci_send
,
471 .acl_send
= null_hci_send
,
472 .bdaddr_set
= null_hci_addr_set
,
475 struct HCIInfo
*qemu_next_hci(void)
477 if (cur_hci
== nb_hcis
)
480 return hci_table
[cur_hci
++];
483 static struct HCIInfo
*hci_init(const char *str
)
486 struct bt_scatternet_s
*vlan
= 0;
488 if (!strcmp(str
, "null"))
491 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
493 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
494 else if (!strncmp(str
, "hci", 3)) {
497 if (!strncmp(str
+ 3, ",vlan=", 6)) {
498 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
503 vlan
= qemu_find_bt_vlan(0);
505 return bt_new_hci(vlan
);
508 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
513 static int bt_hci_parse(const char *str
)
518 if (nb_hcis
>= MAX_NICS
) {
519 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
532 bdaddr
.b
[5] = 0x56 + nb_hcis
;
533 hci
->bdaddr_set(hci
, bdaddr
.b
);
535 hci_table
[nb_hcis
++] = hci
;
540 static void bt_vhci_add(int vlan_id
)
542 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
545 fprintf(stderr
, "qemu: warning: adding a VHCI to "
546 "an empty scatternet %i\n", vlan_id
);
548 bt_vhci_init(bt_new_hci(vlan
));
551 static struct bt_device_s
*bt_device_add(const char *opt
)
553 struct bt_scatternet_s
*vlan
;
555 char *endp
= strstr(opt
, ",vlan=");
556 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
559 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
562 vlan_id
= strtol(endp
+ 6, &endp
, 0);
564 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
569 vlan
= qemu_find_bt_vlan(vlan_id
);
572 fprintf(stderr
, "qemu: warning: adding a slave device to "
573 "an empty scatternet %i\n", vlan_id
);
575 if (!strcmp(devname
, "keyboard"))
576 return bt_keyboard_init(vlan
);
578 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
582 static int bt_parse(const char *opt
)
584 const char *endp
, *p
;
587 if (strstart(opt
, "hci", &endp
)) {
588 if (!*endp
|| *endp
== ',') {
590 if (!strstart(endp
, ",vlan=", 0))
593 return bt_hci_parse(opt
);
595 } else if (strstart(opt
, "vhci", &endp
)) {
596 if (!*endp
|| *endp
== ',') {
598 if (strstart(endp
, ",vlan=", &p
)) {
599 vlan
= strtol(p
, (char **) &endp
, 0);
601 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
605 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
614 } else if (strstart(opt
, "device:", &endp
))
615 return !bt_device_add(endp
);
617 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
621 /***********************************************************/
622 /* QEMU Block devices */
624 /* Any % in the following strings must be escaped as %% */
625 #define HD_OPTS "media=disk"
626 #define CDROM_OPTS "media=cdrom"
628 #define PFLASH_OPTS ""
632 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
634 int *use_scsi
= opaque
;
637 if (drive_init(opts
, *use_scsi
, &fatal_error
) == NULL
) {
644 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
646 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
647 qemu_opt_set(opts
, "snapshot", "on");
652 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
654 boot_set_handler
= func
;
655 boot_set_opaque
= opaque
;
658 int qemu_boot_set(const char *boot_devices
)
660 if (!boot_set_handler
) {
663 return boot_set_handler(boot_set_opaque
, boot_devices
);
666 static void validate_bootdevices(char *devices
)
668 /* We just do some generic consistency checks */
672 for (p
= devices
; *p
!= '\0'; p
++) {
673 /* Allowed boot devices are:
674 * a-b: floppy disk drives
675 * c-f: IDE disk drives
676 * g-m: machine implementation dependant drives
677 * n-p: network devices
678 * It's up to each machine implementation to check if the given boot
679 * devices match the actual hardware implementation and firmware
682 if (*p
< 'a' || *p
> 'p') {
683 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
686 if (bitmap
& (1 << (*p
- 'a'))) {
687 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
690 bitmap
|= 1 << (*p
- 'a');
694 static void restore_boot_devices(void *opaque
)
696 char *standard_boot_devices
= opaque
;
697 static int first
= 1;
699 /* Restore boot order and remove ourselves after the first boot */
705 qemu_boot_set(standard_boot_devices
);
707 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
708 qemu_free(standard_boot_devices
);
711 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
714 FWBootEntry
*node
, *i
;
720 assert(dev
!= NULL
|| suffix
!= NULL
);
722 node
= qemu_mallocz(sizeof(FWBootEntry
));
723 node
->bootindex
= bootindex
;
724 node
->suffix
= strdup(suffix
);
727 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
728 if (i
->bootindex
== bootindex
) {
729 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
731 } else if (i
->bootindex
< bootindex
) {
734 QTAILQ_INSERT_BEFORE(i
, node
, link
);
737 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
741 * This function returns null terminated string that consist of new line
742 * separated device pathes.
744 * memory pointed by "size" is assigned total length of the array in bytes
747 char *get_boot_devices_list(uint32_t *size
)
753 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
754 char *devpath
= NULL
, *bootpath
;
758 devpath
= qdev_get_fw_dev_path(i
->dev
);
762 if (i
->suffix
&& devpath
) {
763 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
765 bootpath
= qemu_malloc(bootpathlen
);
766 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
768 } else if (devpath
) {
771 bootpath
= strdup(i
->suffix
);
776 list
[total
-1] = '\n';
778 len
= strlen(bootpath
) + 1;
779 list
= qemu_realloc(list
, total
+ len
);
780 memcpy(&list
[total
], bootpath
, len
);
790 static void numa_add(const char *optarg
)
794 unsigned long long value
, endvalue
;
797 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
798 if (!strcmp(option
, "node")) {
799 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
800 nodenr
= nb_numa_nodes
;
802 nodenr
= strtoull(option
, NULL
, 10);
805 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
806 node_mem
[nodenr
] = 0;
809 sval
= strtosz(option
, NULL
);
811 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
814 node_mem
[nodenr
] = sval
;
816 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
817 node_cpumask
[nodenr
] = 0;
819 value
= strtoull(option
, &endptr
, 10);
822 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
824 if (*endptr
== '-') {
825 endvalue
= strtoull(endptr
+1, &endptr
, 10);
826 if (endvalue
>= 63) {
829 "only 63 CPUs in NUMA mode supported.\n");
831 value
= (2ULL << endvalue
) - (1ULL << value
);
833 value
= 1ULL << value
;
836 node_cpumask
[nodenr
] = value
;
843 static void smp_parse(const char *optarg
)
845 int smp
, sockets
= 0, threads
= 0, cores
= 0;
849 smp
= strtoul(optarg
, &endptr
, 10);
850 if (endptr
!= optarg
) {
851 if (*endptr
== ',') {
855 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
856 sockets
= strtoull(option
, NULL
, 10);
857 if (get_param_value(option
, 128, "cores", endptr
) != 0)
858 cores
= strtoull(option
, NULL
, 10);
859 if (get_param_value(option
, 128, "threads", endptr
) != 0)
860 threads
= strtoull(option
, NULL
, 10);
861 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
862 max_cpus
= strtoull(option
, NULL
, 10);
864 /* compute missing values, prefer sockets over cores over threads */
865 if (smp
== 0 || sockets
== 0) {
866 sockets
= sockets
> 0 ? sockets
: 1;
867 cores
= cores
> 0 ? cores
: 1;
868 threads
= threads
> 0 ? threads
: 1;
870 smp
= cores
* threads
* sockets
;
874 threads
= threads
> 0 ? threads
: 1;
875 cores
= smp
/ (sockets
* threads
);
877 threads
= smp
/ (cores
* sockets
);
881 smp_cores
= cores
> 0 ? cores
: 1;
882 smp_threads
= threads
> 0 ? threads
: 1;
887 /***********************************************************/
890 static int usb_device_add(const char *devname
)
893 USBDevice
*dev
= NULL
;
898 /* drivers with .usbdevice_name entry in USBDeviceInfo */
899 dev
= usbdevice_create(devname
);
904 if (strstart(devname
, "host:", &p
)) {
905 dev
= usb_host_device_open(p
);
906 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
907 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
908 bt_new_hci(qemu_find_bt_vlan(0)));
919 static int usb_device_del(const char *devname
)
924 if (strstart(devname
, "host:", &p
))
925 return usb_host_device_close(p
);
930 p
= strchr(devname
, '.');
933 bus_num
= strtoul(devname
, NULL
, 0);
934 addr
= strtoul(p
+ 1, NULL
, 0);
936 return usb_device_delete_addr(bus_num
, addr
);
939 static int usb_parse(const char *cmdline
)
942 r
= usb_device_add(cmdline
);
944 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
949 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
951 const char *devname
= qdict_get_str(qdict
, "devname");
952 if (usb_device_add(devname
) < 0) {
953 error_report("could not add USB device '%s'", devname
);
957 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
959 const char *devname
= qdict_get_str(qdict
, "devname");
960 if (usb_device_del(devname
) < 0) {
961 error_report("could not delete USB device '%s'", devname
);
965 /***********************************************************/
968 static struct pcmcia_socket_entry_s
{
969 PCMCIASocket
*socket
;
970 struct pcmcia_socket_entry_s
*next
;
971 } *pcmcia_sockets
= 0;
973 void pcmcia_socket_register(PCMCIASocket
*socket
)
975 struct pcmcia_socket_entry_s
*entry
;
977 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
978 entry
->socket
= socket
;
979 entry
->next
= pcmcia_sockets
;
980 pcmcia_sockets
= entry
;
983 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
985 struct pcmcia_socket_entry_s
*entry
, **ptr
;
987 ptr
= &pcmcia_sockets
;
988 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
989 if (entry
->socket
== socket
) {
995 void pcmcia_info(Monitor
*mon
)
997 struct pcmcia_socket_entry_s
*iter
;
1000 monitor_printf(mon
, "No PCMCIA sockets\n");
1002 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1003 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1004 iter
->socket
->attached
? iter
->socket
->card_string
:
1008 /***********************************************************/
1011 typedef struct IOHandlerRecord
{
1013 IOCanReadHandler
*fd_read_poll
;
1015 IOHandler
*fd_write
;
1018 /* temporary data */
1020 QLIST_ENTRY(IOHandlerRecord
) next
;
1023 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
1024 QLIST_HEAD_INITIALIZER(io_handlers
);
1027 /* XXX: fd_read_poll should be suppressed, but an API change is
1028 necessary in the character devices to suppress fd_can_read(). */
1029 int qemu_set_fd_handler2(int fd
,
1030 IOCanReadHandler
*fd_read_poll
,
1032 IOHandler
*fd_write
,
1035 IOHandlerRecord
*ioh
;
1037 if (!fd_read
&& !fd_write
) {
1038 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1039 if (ioh
->fd
== fd
) {
1045 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1049 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
1050 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
1053 ioh
->fd_read_poll
= fd_read_poll
;
1054 ioh
->fd_read
= fd_read
;
1055 ioh
->fd_write
= fd_write
;
1056 ioh
->opaque
= opaque
;
1062 int qemu_set_fd_handler(int fd
,
1064 IOHandler
*fd_write
,
1067 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
1070 /***********************************************************/
1071 /* machine registration */
1073 static QEMUMachine
*first_machine
= NULL
;
1074 QEMUMachine
*current_machine
= NULL
;
1076 int qemu_register_machine(QEMUMachine
*m
)
1079 pm
= &first_machine
;
1087 static QEMUMachine
*find_machine(const char *name
)
1091 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1092 if (!strcmp(m
->name
, name
))
1094 if (m
->alias
&& !strcmp(m
->alias
, name
))
1100 static QEMUMachine
*find_default_machine(void)
1104 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1105 if (m
->is_default
) {
1112 /***********************************************************/
1113 /* main execution loop */
1115 static void gui_update(void *opaque
)
1117 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1118 DisplayState
*ds
= opaque
;
1119 DisplayChangeListener
*dcl
= ds
->listeners
;
1121 qemu_flush_coalesced_mmio_buffer();
1124 while (dcl
!= NULL
) {
1125 if (dcl
->gui_timer_interval
&&
1126 dcl
->gui_timer_interval
< interval
)
1127 interval
= dcl
->gui_timer_interval
;
1130 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1133 static void nographic_update(void *opaque
)
1135 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1137 qemu_flush_coalesced_mmio_buffer();
1138 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1141 struct vm_change_state_entry
{
1142 VMChangeStateHandler
*cb
;
1144 QLIST_ENTRY (vm_change_state_entry
) entries
;
1147 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1149 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1152 VMChangeStateEntry
*e
;
1154 e
= qemu_mallocz(sizeof (*e
));
1158 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1162 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1164 QLIST_REMOVE (e
, entries
);
1168 void vm_state_notify(int running
, int reason
)
1170 VMChangeStateEntry
*e
;
1172 trace_vm_state_notify(running
, reason
);
1174 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1175 e
->cb(e
->opaque
, running
, reason
);
1184 vm_state_notify(1, 0);
1186 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1190 /* reset/shutdown handler */
1192 typedef struct QEMUResetEntry
{
1193 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1194 QEMUResetHandler
*func
;
1198 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1199 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1200 static int reset_requested
;
1201 static int shutdown_requested
;
1202 static int powerdown_requested
;
1203 int debug_requested
;
1204 int vmstop_requested
;
1206 int qemu_shutdown_requested(void)
1208 int r
= shutdown_requested
;
1209 shutdown_requested
= 0;
1213 int qemu_reset_requested(void)
1215 int r
= reset_requested
;
1216 reset_requested
= 0;
1220 int qemu_powerdown_requested(void)
1222 int r
= powerdown_requested
;
1223 powerdown_requested
= 0;
1227 static int qemu_debug_requested(void)
1229 int r
= debug_requested
;
1230 debug_requested
= 0;
1234 static int qemu_vmstop_requested(void)
1236 int r
= vmstop_requested
;
1237 vmstop_requested
= 0;
1241 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1243 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1246 re
->opaque
= opaque
;
1247 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1250 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1254 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1255 if (re
->func
== func
&& re
->opaque
== opaque
) {
1256 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1263 void qemu_system_reset(void)
1265 QEMUResetEntry
*re
, *nre
;
1267 /* reset all devices */
1268 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1269 re
->func(re
->opaque
);
1271 monitor_protocol_event(QEVENT_RESET
, NULL
);
1272 cpu_synchronize_all_post_reset();
1275 void qemu_system_reset_request(void)
1278 shutdown_requested
= 1;
1280 reset_requested
= 1;
1282 qemu_notify_event();
1285 void qemu_system_shutdown_request(void)
1287 shutdown_requested
= 1;
1288 qemu_notify_event();
1291 void qemu_system_powerdown_request(void)
1293 powerdown_requested
= 1;
1294 qemu_notify_event();
1297 void main_loop_wait(int nonblocking
)
1299 IOHandlerRecord
*ioh
;
1300 fd_set rfds
, wfds
, xfds
;
1308 timeout
= qemu_calculate_timeout();
1309 qemu_bh_update_timeout(&timeout
);
1312 os_host_main_loop_wait(&timeout
);
1314 /* poll any events */
1315 /* XXX: separate device handlers from system ones */
1320 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1324 (!ioh
->fd_read_poll
||
1325 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1326 FD_SET(ioh
->fd
, &rfds
);
1330 if (ioh
->fd_write
) {
1331 FD_SET(ioh
->fd
, &wfds
);
1337 tv
.tv_sec
= timeout
/ 1000;
1338 tv
.tv_usec
= (timeout
% 1000) * 1000;
1340 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1342 qemu_mutex_unlock_iothread();
1343 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1344 qemu_mutex_lock_iothread();
1346 IOHandlerRecord
*pioh
;
1348 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1349 if (!ioh
->deleted
&& ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1350 ioh
->fd_read(ioh
->opaque
);
1352 if (!ioh
->deleted
&& ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1353 ioh
->fd_write(ioh
->opaque
);
1356 /* Do this last in case read/write handlers marked it for deletion */
1358 QLIST_REMOVE(ioh
, next
);
1364 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1366 qemu_run_all_timers();
1368 /* Check bottom-halves last in case any of the earlier events triggered
1374 static int vm_can_run(void)
1376 if (powerdown_requested
)
1378 if (reset_requested
)
1380 if (shutdown_requested
)
1382 if (debug_requested
)
1387 qemu_irq qemu_system_powerdown
;
1389 static void main_loop(void)
1393 qemu_main_loop_start();
1397 bool nonblocking
= false;
1398 #ifdef CONFIG_PROFILER
1401 #ifndef CONFIG_IOTHREAD
1402 nonblocking
= cpu_exec_all();
1404 #ifdef CONFIG_PROFILER
1405 ti
= profile_getclock();
1407 main_loop_wait(nonblocking
);
1408 #ifdef CONFIG_PROFILER
1409 dev_time
+= profile_getclock() - ti
;
1411 } while (vm_can_run());
1413 if ((r
= qemu_debug_requested())) {
1416 if (qemu_shutdown_requested()) {
1417 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1424 if (qemu_reset_requested()) {
1426 qemu_system_reset();
1429 if (qemu_powerdown_requested()) {
1430 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1431 qemu_irq_raise(qemu_system_powerdown
);
1433 if ((r
= qemu_vmstop_requested())) {
1441 static void version(void)
1443 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1446 static void help(int exitcode
)
1448 const char *options_help
=
1449 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1451 #define DEFHEADING(text) stringify(text) "\n"
1452 #include "qemu-options.def"
1458 printf("usage: %s [options] [disk_image]\n"
1460 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1463 "During emulation, the following keys are useful:\n"
1464 "ctrl-alt-f toggle full screen\n"
1465 "ctrl-alt-n switch to virtual console 'n'\n"
1466 "ctrl-alt toggle mouse and keyboard grab\n"
1468 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1474 #define HAS_ARG 0x0001
1476 typedef struct QEMUOption
{
1483 static const QEMUOption qemu_options
[] = {
1484 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1485 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1486 { option, opt_arg, opt_enum, arch_mask },
1487 #define DEFHEADING(text)
1488 #include "qemu-options.def"
1494 static void select_vgahw (const char *p
)
1499 vga_interface_type
= VGA_NONE
;
1500 if (strstart(p
, "std", &opts
)) {
1501 vga_interface_type
= VGA_STD
;
1502 } else if (strstart(p
, "cirrus", &opts
)) {
1503 vga_interface_type
= VGA_CIRRUS
;
1504 } else if (strstart(p
, "vmware", &opts
)) {
1505 vga_interface_type
= VGA_VMWARE
;
1506 } else if (strstart(p
, "xenfb", &opts
)) {
1507 vga_interface_type
= VGA_XENFB
;
1508 } else if (strstart(p
, "qxl", &opts
)) {
1509 vga_interface_type
= VGA_QXL
;
1510 } else if (!strstart(p
, "none", &opts
)) {
1512 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1516 const char *nextopt
;
1518 if (strstart(opts
, ",retrace=", &nextopt
)) {
1520 if (strstart(opts
, "dumb", &nextopt
))
1521 vga_retrace_method
= VGA_RETRACE_DUMB
;
1522 else if (strstart(opts
, "precise", &nextopt
))
1523 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1524 else goto invalid_vga
;
1525 } else goto invalid_vga
;
1530 static int balloon_parse(const char *arg
)
1534 if (strcmp(arg
, "none") == 0) {
1538 if (!strncmp(arg
, "virtio", 6)) {
1539 if (arg
[6] == ',') {
1540 /* have params -> parse them */
1541 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1545 /* create empty opts */
1546 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1548 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1555 char *qemu_find_file(int type
, const char *name
)
1561 /* If name contains path separators then try it as a straight path. */
1562 if ((strchr(name
, '/') || strchr(name
, '\\'))
1563 && access(name
, R_OK
) == 0) {
1564 return qemu_strdup(name
);
1567 case QEMU_FILE_TYPE_BIOS
:
1570 case QEMU_FILE_TYPE_KEYMAP
:
1571 subdir
= "keymaps/";
1576 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1577 buf
= qemu_mallocz(len
);
1578 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1579 if (access(buf
, R_OK
)) {
1586 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1588 return qdev_device_help(opts
);
1591 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1595 dev
= qdev_device_add(opts
);
1601 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1603 CharDriverState
*chr
;
1605 chr
= qemu_chr_open_opts(opts
, NULL
);
1611 #ifdef CONFIG_VIRTFS
1612 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1615 ret
= qemu_fsdev_add(opts
);
1621 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1623 CharDriverState
*chr
;
1624 const char *chardev
;
1628 mode
= qemu_opt_get(opts
, "mode");
1632 if (strcmp(mode
, "readline") == 0) {
1633 flags
= MONITOR_USE_READLINE
;
1634 } else if (strcmp(mode
, "control") == 0) {
1635 flags
= MONITOR_USE_CONTROL
;
1637 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1641 if (qemu_opt_get_bool(opts
, "pretty", 0))
1642 flags
|= MONITOR_USE_PRETTY
;
1644 if (qemu_opt_get_bool(opts
, "default", 0))
1645 flags
|= MONITOR_IS_DEFAULT
;
1647 chardev
= qemu_opt_get(opts
, "chardev");
1648 chr
= qemu_chr_find(chardev
);
1650 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1654 monitor_init(chr
, flags
);
1658 static void monitor_parse(const char *optarg
, const char *mode
)
1660 static int monitor_device_index
= 0;
1666 if (strstart(optarg
, "chardev:", &p
)) {
1667 snprintf(label
, sizeof(label
), "%s", p
);
1669 snprintf(label
, sizeof(label
), "compat_monitor%d",
1670 monitor_device_index
);
1671 if (monitor_device_index
== 0) {
1674 opts
= qemu_chr_parse_compat(label
, optarg
);
1676 fprintf(stderr
, "parse error: %s\n", optarg
);
1681 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1683 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1686 qemu_opt_set(opts
, "mode", mode
);
1687 qemu_opt_set(opts
, "chardev", label
);
1689 qemu_opt_set(opts
, "default", "on");
1690 monitor_device_index
++;
1693 struct device_config
{
1695 DEV_USB
, /* -usbdevice */
1697 DEV_SERIAL
, /* -serial */
1698 DEV_PARALLEL
, /* -parallel */
1699 DEV_VIRTCON
, /* -virtioconsole */
1700 DEV_DEBUGCON
, /* -debugcon */
1702 const char *cmdline
;
1703 QTAILQ_ENTRY(device_config
) next
;
1705 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1707 static void add_device_config(int type
, const char *cmdline
)
1709 struct device_config
*conf
;
1711 conf
= qemu_mallocz(sizeof(*conf
));
1713 conf
->cmdline
= cmdline
;
1714 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1717 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1719 struct device_config
*conf
;
1722 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1723 if (conf
->type
!= type
)
1725 rc
= func(conf
->cmdline
);
1732 static int serial_parse(const char *devname
)
1734 static int index
= 0;
1737 if (strcmp(devname
, "none") == 0)
1739 if (index
== MAX_SERIAL_PORTS
) {
1740 fprintf(stderr
, "qemu: too many serial ports\n");
1743 snprintf(label
, sizeof(label
), "serial%d", index
);
1744 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1745 if (!serial_hds
[index
]) {
1746 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1747 devname
, strerror(errno
));
1754 static int parallel_parse(const char *devname
)
1756 static int index
= 0;
1759 if (strcmp(devname
, "none") == 0)
1761 if (index
== MAX_PARALLEL_PORTS
) {
1762 fprintf(stderr
, "qemu: too many parallel ports\n");
1765 snprintf(label
, sizeof(label
), "parallel%d", index
);
1766 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1767 if (!parallel_hds
[index
]) {
1768 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1769 devname
, strerror(errno
));
1776 static int virtcon_parse(const char *devname
)
1778 QemuOptsList
*device
= qemu_find_opts("device");
1779 static int index
= 0;
1781 QemuOpts
*bus_opts
, *dev_opts
;
1783 if (strcmp(devname
, "none") == 0)
1785 if (index
== MAX_VIRTIO_CONSOLES
) {
1786 fprintf(stderr
, "qemu: too many virtio consoles\n");
1790 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1791 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1793 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1794 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1796 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1797 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1798 if (!virtcon_hds
[index
]) {
1799 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1800 devname
, strerror(errno
));
1803 qemu_opt_set(dev_opts
, "chardev", label
);
1809 static int debugcon_parse(const char *devname
)
1813 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1816 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1818 fprintf(stderr
, "qemu: already have a debugcon device\n");
1821 qemu_opt_set(opts
, "driver", "isa-debugcon");
1822 qemu_opt_set(opts
, "chardev", "debugcon");
1826 void qemu_add_exit_notifier(Notifier
*notify
)
1828 notifier_list_add(&exit_notifiers
, notify
);
1831 void qemu_remove_exit_notifier(Notifier
*notify
)
1833 notifier_list_remove(&exit_notifiers
, notify
);
1836 static void qemu_run_exit_notifiers(void)
1838 notifier_list_notify(&exit_notifiers
);
1841 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
1843 notifier_list_add(&machine_init_done_notifiers
, notify
);
1846 static void qemu_run_machine_init_done_notifiers(void)
1848 notifier_list_notify(&machine_init_done_notifiers
);
1851 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1852 const char **poptarg
, int *poptind
)
1854 const QEMUOption
*popt
;
1855 int optind
= *poptind
;
1856 char *r
= argv
[optind
];
1859 loc_set_cmdline(argv
, optind
, 1);
1861 /* Treat --foo the same as -foo. */
1864 popt
= qemu_options
;
1867 error_report("invalid option");
1870 if (!strcmp(popt
->name
, r
+ 1))
1874 if (popt
->flags
& HAS_ARG
) {
1875 if (optind
>= argc
) {
1876 error_report("requires an argument");
1879 optarg
= argv
[optind
++];
1880 loc_set_cmdline(argv
, optind
- 2, 2);
1891 int main(int argc
, char **argv
, char **envp
)
1893 const char *gdbstub_dev
= NULL
;
1895 int snapshot
, linux_boot
;
1896 const char *icount_option
= NULL
;
1897 const char *initrd_filename
;
1898 const char *kernel_filename
, *kernel_cmdline
;
1899 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1901 DisplayChangeListener
*dcl
;
1902 int cyls
, heads
, secs
, translation
;
1903 QemuOpts
*hda_opts
= NULL
, *opts
;
1904 QemuOptsList
*olist
;
1907 const char *loadvm
= NULL
;
1908 QEMUMachine
*machine
;
1909 const char *cpu_model
;
1911 const char *pid_file
= NULL
;
1912 const char *incoming
= NULL
;
1913 int show_vnc_port
= 0;
1916 #ifdef CONFIG_SIMPLE_TRACE
1917 const char *trace_file
= NULL
;
1919 atexit(qemu_run_exit_notifiers
);
1920 error_set_progname(argv
[0]);
1924 qemu_cache_utils_init(envp
);
1926 QLIST_INIT (&vm_change_state_head
);
1927 os_setup_early_signal_handling();
1929 module_call_init(MODULE_INIT_MACHINE
);
1930 machine
= find_default_machine();
1932 initrd_filename
= NULL
;
1935 kernel_filename
= NULL
;
1936 kernel_cmdline
= "";
1937 cyls
= heads
= secs
= 0;
1938 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1940 for (i
= 0; i
< MAX_NODES
; i
++) {
1942 node_cpumask
[i
] = 0;
1951 /* first pass of option parsing */
1953 while (optind
< argc
) {
1954 if (argv
[optind
][0] != '-') {
1959 const QEMUOption
*popt
;
1961 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1962 switch (popt
->index
) {
1963 case QEMU_OPTION_nodefconfig
:
1973 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1974 if (ret
< 0 && ret
!= -ENOENT
) {
1978 ret
= qemu_read_config_file(arch_config_name
);
1979 if (ret
< 0 && ret
!= -ENOENT
) {
1985 /* second pass of option parsing */
1990 if (argv
[optind
][0] != '-') {
1991 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
1993 const QEMUOption
*popt
;
1995 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1996 if (!(popt
->arch_mask
& arch_type
)) {
1997 printf("Option %s not supported for this target\n", popt
->name
);
2000 switch(popt
->index
) {
2002 machine
= find_machine(optarg
);
2005 printf("Supported machines are:\n");
2006 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
2008 printf("%-10s %s (alias of %s)\n",
2009 m
->alias
, m
->desc
, m
->name
);
2010 printf("%-10s %s%s\n",
2012 m
->is_default
? " (default)" : "");
2014 exit(*optarg
!= '?');
2017 case QEMU_OPTION_cpu
:
2018 /* hw initialization will check this */
2019 if (*optarg
== '?') {
2020 list_cpus(stdout
, &fprintf
, optarg
);
2026 case QEMU_OPTION_initrd
:
2027 initrd_filename
= optarg
;
2029 case QEMU_OPTION_hda
:
2031 hda_opts
= drive_add(IF_DEFAULT
, 0, optarg
, HD_OPTS
);
2033 hda_opts
= drive_add(IF_DEFAULT
, 0, optarg
, HD_OPTS
2034 ",cyls=%d,heads=%d,secs=%d%s",
2036 translation
== BIOS_ATA_TRANSLATION_LBA
?
2038 translation
== BIOS_ATA_TRANSLATION_NONE
?
2039 ",trans=none" : "");
2041 case QEMU_OPTION_hdb
:
2042 case QEMU_OPTION_hdc
:
2043 case QEMU_OPTION_hdd
:
2044 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2047 case QEMU_OPTION_drive
:
2050 case QEMU_OPTION_set
:
2051 if (qemu_set_option(optarg
) != 0)
2054 case QEMU_OPTION_global
:
2055 if (qemu_global_option(optarg
) != 0)
2058 case QEMU_OPTION_mtdblock
:
2059 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2061 case QEMU_OPTION_sd
:
2062 drive_add(IF_SD
, 0, optarg
, SD_OPTS
);
2064 case QEMU_OPTION_pflash
:
2065 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2067 case QEMU_OPTION_snapshot
:
2070 case QEMU_OPTION_hdachs
:
2074 cyls
= strtol(p
, (char **)&p
, 0);
2075 if (cyls
< 1 || cyls
> 16383)
2080 heads
= strtol(p
, (char **)&p
, 0);
2081 if (heads
< 1 || heads
> 16)
2086 secs
= strtol(p
, (char **)&p
, 0);
2087 if (secs
< 1 || secs
> 63)
2091 if (!strcmp(p
, "none"))
2092 translation
= BIOS_ATA_TRANSLATION_NONE
;
2093 else if (!strcmp(p
, "lba"))
2094 translation
= BIOS_ATA_TRANSLATION_LBA
;
2095 else if (!strcmp(p
, "auto"))
2096 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2099 } else if (*p
!= '\0') {
2101 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2104 if (hda_opts
!= NULL
) {
2106 snprintf(num
, sizeof(num
), "%d", cyls
);
2107 qemu_opt_set(hda_opts
, "cyls", num
);
2108 snprintf(num
, sizeof(num
), "%d", heads
);
2109 qemu_opt_set(hda_opts
, "heads", num
);
2110 snprintf(num
, sizeof(num
), "%d", secs
);
2111 qemu_opt_set(hda_opts
, "secs", num
);
2112 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2113 qemu_opt_set(hda_opts
, "trans", "lba");
2114 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2115 qemu_opt_set(hda_opts
, "trans", "none");
2119 case QEMU_OPTION_numa
:
2120 if (nb_numa_nodes
>= MAX_NODES
) {
2121 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2126 case QEMU_OPTION_nographic
:
2127 display_type
= DT_NOGRAPHIC
;
2129 #ifdef CONFIG_CURSES
2130 case QEMU_OPTION_curses
:
2131 display_type
= DT_CURSES
;
2134 case QEMU_OPTION_portrait
:
2137 case QEMU_OPTION_kernel
:
2138 kernel_filename
= optarg
;
2140 case QEMU_OPTION_append
:
2141 kernel_cmdline
= optarg
;
2143 case QEMU_OPTION_cdrom
:
2144 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2146 case QEMU_OPTION_boot
:
2148 static const char * const params
[] = {
2149 "order", "once", "menu", NULL
2151 char buf
[sizeof(boot_devices
)];
2152 char *standard_boot_devices
;
2155 if (!strchr(optarg
, '=')) {
2157 pstrcpy(buf
, sizeof(buf
), optarg
);
2158 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2160 "qemu: unknown boot parameter '%s' in '%s'\n",
2166 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2167 validate_bootdevices(buf
);
2168 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2171 if (get_param_value(buf
, sizeof(buf
),
2173 validate_bootdevices(buf
);
2174 standard_boot_devices
= qemu_strdup(boot_devices
);
2175 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2176 qemu_register_reset(restore_boot_devices
,
2177 standard_boot_devices
);
2179 if (get_param_value(buf
, sizeof(buf
),
2181 if (!strcmp(buf
, "on")) {
2183 } else if (!strcmp(buf
, "off")) {
2187 "qemu: invalid option value '%s'\n",
2195 case QEMU_OPTION_fda
:
2196 case QEMU_OPTION_fdb
:
2197 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2200 case QEMU_OPTION_no_fd_bootchk
:
2203 case QEMU_OPTION_netdev
:
2204 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2208 case QEMU_OPTION_net
:
2209 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2214 case QEMU_OPTION_tftp
:
2215 legacy_tftp_prefix
= optarg
;
2217 case QEMU_OPTION_bootp
:
2218 legacy_bootp_filename
= optarg
;
2220 case QEMU_OPTION_redir
:
2221 if (net_slirp_redir(optarg
) < 0)
2225 case QEMU_OPTION_bt
:
2226 add_device_config(DEV_BT
, optarg
);
2228 case QEMU_OPTION_audio_help
:
2229 if (!(audio_available())) {
2230 printf("Option %s not supported for this target\n", popt
->name
);
2236 case QEMU_OPTION_soundhw
:
2237 if (!(audio_available())) {
2238 printf("Option %s not supported for this target\n", popt
->name
);
2241 select_soundhw (optarg
);
2246 case QEMU_OPTION_version
:
2250 case QEMU_OPTION_m
: {
2253 value
= strtosz(optarg
, NULL
);
2255 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2259 /* On 32-bit hosts, QEMU is limited by virtual address space */
2260 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2261 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2264 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2265 fprintf(stderr
, "qemu: ram size too large\n");
2271 case QEMU_OPTION_mempath
:
2275 case QEMU_OPTION_mem_prealloc
:
2280 set_cpu_log(optarg
);
2283 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2285 case QEMU_OPTION_gdb
:
2286 gdbstub_dev
= optarg
;
2291 case QEMU_OPTION_bios
:
2294 case QEMU_OPTION_singlestep
:
2301 keyboard_layout
= optarg
;
2303 case QEMU_OPTION_localtime
:
2306 case QEMU_OPTION_vga
:
2307 select_vgahw (optarg
);
2314 w
= strtol(p
, (char **)&p
, 10);
2317 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2323 h
= strtol(p
, (char **)&p
, 10);
2328 depth
= strtol(p
, (char **)&p
, 10);
2329 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2330 depth
!= 24 && depth
!= 32)
2332 } else if (*p
== '\0') {
2333 depth
= graphic_depth
;
2340 graphic_depth
= depth
;
2343 case QEMU_OPTION_echr
:
2346 term_escape_char
= strtol(optarg
, &r
, 0);
2348 printf("Bad argument to echr\n");
2351 case QEMU_OPTION_monitor
:
2352 monitor_parse(optarg
, "readline");
2353 default_monitor
= 0;
2355 case QEMU_OPTION_qmp
:
2356 monitor_parse(optarg
, "control");
2357 default_monitor
= 0;
2359 case QEMU_OPTION_mon
:
2360 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2364 default_monitor
= 0;
2366 case QEMU_OPTION_chardev
:
2367 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2372 case QEMU_OPTION_fsdev
:
2373 olist
= qemu_find_opts("fsdev");
2375 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2378 opts
= qemu_opts_parse(olist
, optarg
, 1);
2380 fprintf(stderr
, "parse error: %s\n", optarg
);
2384 case QEMU_OPTION_virtfs
: {
2385 char *arg_fsdev
= NULL
;
2386 char *arg_9p
= NULL
;
2389 olist
= qemu_find_opts("virtfs");
2391 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2394 opts
= qemu_opts_parse(olist
, optarg
, 1);
2396 fprintf(stderr
, "parse error: %s\n", optarg
);
2400 if (qemu_opt_get(opts
, "fstype") == NULL
||
2401 qemu_opt_get(opts
, "mount_tag") == NULL
||
2402 qemu_opt_get(opts
, "path") == NULL
||
2403 qemu_opt_get(opts
, "security_model") == NULL
) {
2404 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2405 "security_model=[mapped|passthrough|none],"
2410 len
= strlen(",id=,path=,security_model=");
2411 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2412 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2413 len
+= strlen(qemu_opt_get(opts
, "path"));
2414 len
+= strlen(qemu_opt_get(opts
, "security_model"));
2415 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2417 snprintf(arg_fsdev
, (len
+ 1) * sizeof(*arg_fsdev
),
2418 "%s,id=%s,path=%s,security_model=%s",
2419 qemu_opt_get(opts
, "fstype"),
2420 qemu_opt_get(opts
, "mount_tag"),
2421 qemu_opt_get(opts
, "path"),
2422 qemu_opt_get(opts
, "security_model"));
2424 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2425 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2426 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2428 snprintf(arg_9p
, (len
+ 1) * sizeof(*arg_9p
),
2429 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2430 qemu_opt_get(opts
, "mount_tag"),
2431 qemu_opt_get(opts
, "mount_tag"));
2433 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev
, 1)) {
2434 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2438 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p
, 1)) {
2439 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2443 qemu_free(arg_fsdev
);
2447 case QEMU_OPTION_serial
:
2448 add_device_config(DEV_SERIAL
, optarg
);
2450 if (strncmp(optarg
, "mon:", 4) == 0) {
2451 default_monitor
= 0;
2454 case QEMU_OPTION_watchdog
:
2457 "qemu: only one watchdog option may be given\n");
2462 case QEMU_OPTION_watchdog_action
:
2463 if (select_watchdog_action(optarg
) == -1) {
2464 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2468 case QEMU_OPTION_virtiocon
:
2469 add_device_config(DEV_VIRTCON
, optarg
);
2470 default_virtcon
= 0;
2471 if (strncmp(optarg
, "mon:", 4) == 0) {
2472 default_monitor
= 0;
2475 case QEMU_OPTION_parallel
:
2476 add_device_config(DEV_PARALLEL
, optarg
);
2477 default_parallel
= 0;
2478 if (strncmp(optarg
, "mon:", 4) == 0) {
2479 default_monitor
= 0;
2482 case QEMU_OPTION_debugcon
:
2483 add_device_config(DEV_DEBUGCON
, optarg
);
2485 case QEMU_OPTION_loadvm
:
2488 case QEMU_OPTION_full_screen
:
2492 case QEMU_OPTION_no_frame
:
2495 case QEMU_OPTION_alt_grab
:
2498 case QEMU_OPTION_ctrl_grab
:
2501 case QEMU_OPTION_no_quit
:
2504 case QEMU_OPTION_sdl
:
2505 display_type
= DT_SDL
;
2508 case QEMU_OPTION_pidfile
:
2511 case QEMU_OPTION_win2k_hack
:
2512 win2k_install_hack
= 1;
2514 case QEMU_OPTION_rtc_td_hack
:
2517 case QEMU_OPTION_acpitable
:
2518 do_acpitable_option(optarg
);
2520 case QEMU_OPTION_smbios
:
2521 do_smbios_option(optarg
);
2523 case QEMU_OPTION_enable_kvm
:
2526 case QEMU_OPTION_usb
:
2529 case QEMU_OPTION_usbdevice
:
2531 add_device_config(DEV_USB
, optarg
);
2533 case QEMU_OPTION_device
:
2534 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2538 case QEMU_OPTION_smp
:
2541 fprintf(stderr
, "Invalid number of CPUs\n");
2544 if (max_cpus
< smp_cpus
) {
2545 fprintf(stderr
, "maxcpus must be equal to or greater than "
2549 if (max_cpus
> 255) {
2550 fprintf(stderr
, "Unsupported number of maxcpus\n");
2554 case QEMU_OPTION_vnc
:
2556 vnc_display
= optarg
;
2558 case QEMU_OPTION_no_acpi
:
2561 case QEMU_OPTION_no_hpet
:
2564 case QEMU_OPTION_balloon
:
2565 if (balloon_parse(optarg
) < 0) {
2566 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2570 case QEMU_OPTION_no_reboot
:
2573 case QEMU_OPTION_no_shutdown
:
2576 case QEMU_OPTION_show_cursor
:
2579 case QEMU_OPTION_uuid
:
2580 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2581 fprintf(stderr
, "Fail to parse UUID string."
2582 " Wrong format.\n");
2586 case QEMU_OPTION_option_rom
:
2587 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2588 fprintf(stderr
, "Too many option ROMs\n");
2591 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
2592 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
2593 option_rom
[nb_option_roms
].bootindex
=
2594 qemu_opt_get_number(opts
, "bootindex", -1);
2595 if (!option_rom
[nb_option_roms
].name
) {
2596 fprintf(stderr
, "Option ROM file is not specified\n");
2601 case QEMU_OPTION_semihosting
:
2602 semihosting_enabled
= 1;
2604 case QEMU_OPTION_name
:
2605 qemu_name
= qemu_strdup(optarg
);
2607 char *p
= strchr(qemu_name
, ',');
2610 if (strncmp(p
, "process=", 8)) {
2611 fprintf(stderr
, "Unknown subargument %s to -name\n", p
);
2615 os_set_proc_name(p
);
2619 case QEMU_OPTION_prom_env
:
2620 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2621 fprintf(stderr
, "Too many prom variables\n");
2624 prom_envs
[nb_prom_envs
] = optarg
;
2627 case QEMU_OPTION_old_param
:
2630 case QEMU_OPTION_clock
:
2631 configure_alarms(optarg
);
2633 case QEMU_OPTION_startdate
:
2634 configure_rtc_date_offset(optarg
, 1);
2636 case QEMU_OPTION_rtc
:
2637 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2641 configure_rtc(opts
);
2643 case QEMU_OPTION_tb_size
:
2644 tb_size
= strtol(optarg
, NULL
, 0);
2648 case QEMU_OPTION_icount
:
2649 icount_option
= optarg
;
2651 case QEMU_OPTION_incoming
:
2653 incoming_expected
= true;
2655 case QEMU_OPTION_nodefaults
:
2657 default_parallel
= 0;
2658 default_virtcon
= 0;
2659 default_monitor
= 0;
2666 case QEMU_OPTION_xen_domid
:
2667 if (!(xen_available())) {
2668 printf("Option %s not supported for this target\n", popt
->name
);
2671 xen_domid
= atoi(optarg
);
2673 case QEMU_OPTION_xen_create
:
2674 if (!(xen_available())) {
2675 printf("Option %s not supported for this target\n", popt
->name
);
2678 xen_mode
= XEN_CREATE
;
2680 case QEMU_OPTION_xen_attach
:
2681 if (!(xen_available())) {
2682 printf("Option %s not supported for this target\n", popt
->name
);
2685 xen_mode
= XEN_ATTACH
;
2687 #ifdef CONFIG_SIMPLE_TRACE
2688 case QEMU_OPTION_trace
:
2689 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2691 trace_file
= qemu_opt_get(opts
, "file");
2695 case QEMU_OPTION_readconfig
:
2697 int ret
= qemu_read_config_file(optarg
);
2699 fprintf(stderr
, "read config %s: %s\n", optarg
,
2705 case QEMU_OPTION_spice
:
2706 olist
= qemu_find_opts("spice");
2708 fprintf(stderr
, "spice is not supported by this qemu build.\n");
2711 opts
= qemu_opts_parse(olist
, optarg
, 0);
2713 fprintf(stderr
, "parse error: %s\n", optarg
);
2717 case QEMU_OPTION_writeconfig
:
2720 if (strcmp(optarg
, "-") == 0) {
2723 fp
= fopen(optarg
, "w");
2725 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2729 qemu_config_write(fp
);
2734 os_parse_cmd_args(popt
->index
, optarg
);
2740 /* If no data_dir is specified then try to find it relative to the
2743 data_dir
= os_find_datadir(argv
[0]);
2745 /* If all else fails use the install patch specified when building. */
2747 data_dir
= CONFIG_QEMU_DATADIR
;
2750 #ifdef CONFIG_SIMPLE_TRACE
2752 * Set the trace file name, if specified.
2754 st_set_trace_file(trace_file
);
2757 * Default to max_cpus = smp_cpus, in case the user doesn't
2758 * specify a max_cpus value.
2761 max_cpus
= smp_cpus
;
2763 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2764 if (smp_cpus
> machine
->max_cpus
) {
2765 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2766 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2771 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2772 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2774 if (machine
->no_serial
) {
2777 if (machine
->no_parallel
) {
2778 default_parallel
= 0;
2780 if (!machine
->use_virtcon
) {
2781 default_virtcon
= 0;
2783 if (machine
->no_vga
) {
2786 if (machine
->no_floppy
) {
2789 if (machine
->no_cdrom
) {
2792 if (machine
->no_sdcard
) {
2796 if (display_type
== DT_NOGRAPHIC
) {
2797 if (default_parallel
)
2798 add_device_config(DEV_PARALLEL
, "null");
2799 if (default_serial
&& default_monitor
) {
2800 add_device_config(DEV_SERIAL
, "mon:stdio");
2801 } else if (default_virtcon
&& default_monitor
) {
2802 add_device_config(DEV_VIRTCON
, "mon:stdio");
2805 add_device_config(DEV_SERIAL
, "stdio");
2806 if (default_virtcon
)
2807 add_device_config(DEV_VIRTCON
, "stdio");
2808 if (default_monitor
)
2809 monitor_parse("stdio", "readline");
2813 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2814 if (default_parallel
)
2815 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2816 if (default_monitor
)
2817 monitor_parse("vc:80Cx24C", "readline");
2818 if (default_virtcon
)
2819 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2822 vga_interface_type
= VGA_CIRRUS
;
2826 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
2828 #ifdef CONFIG_VIRTFS
2829 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
2836 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2842 int ret
= kvm_init(smp_cpus
);
2844 if (!kvm_available()) {
2845 printf("KVM not supported for this target\n");
2847 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2853 if (qemu_init_main_loop()) {
2854 fprintf(stderr
, "qemu_init_main_loop failed\n");
2857 linux_boot
= (kernel_filename
!= NULL
);
2859 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2860 fprintf(stderr
, "-append only allowed with -kernel option\n");
2864 if (!linux_boot
&& initrd_filename
!= NULL
) {
2865 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2869 os_set_line_buffering();
2871 if (init_timer_alarm() < 0) {
2872 fprintf(stderr
, "could not initialize alarm timer\n");
2875 configure_icount(icount_option
);
2877 if (net_init_clients() < 0) {
2881 /* init the bluetooth world */
2882 if (foreach_device_config(DEV_BT
, bt_parse
))
2885 /* init the memory */
2887 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2889 /* init the dynamic translator */
2890 cpu_exec_init_all(tb_size
* 1024 * 1024);
2892 bdrv_init_with_whitelist();
2896 if (default_cdrom
) {
2897 /* we always create the cdrom drive, even if no disk is there */
2898 drive_add(IF_DEFAULT
, 2, NULL
, CDROM_OPTS
);
2901 if (default_floppy
) {
2902 /* we always create at least one floppy */
2903 drive_add(IF_FLOPPY
, 0, NULL
, FD_OPTS
);
2906 if (default_sdcard
) {
2907 /* we always create one sd slot, even if no card is in it */
2908 drive_add(IF_SD
, 0, NULL
, SD_OPTS
);
2911 /* open the virtual block devices */
2913 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
2914 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
2917 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2920 if (nb_numa_nodes
> 0) {
2923 if (nb_numa_nodes
> smp_cpus
) {
2924 nb_numa_nodes
= smp_cpus
;
2927 /* If no memory size if given for any node, assume the default case
2928 * and distribute the available memory equally across all nodes
2930 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2931 if (node_mem
[i
] != 0)
2934 if (i
== nb_numa_nodes
) {
2935 uint64_t usedmem
= 0;
2937 /* On Linux, the each node's border has to be 8MB aligned,
2938 * the final node gets the rest.
2940 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2941 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2942 usedmem
+= node_mem
[i
];
2944 node_mem
[i
] = ram_size
- usedmem
;
2947 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2948 if (node_cpumask
[i
] != 0)
2951 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2952 * must cope with this anyway, because there are BIOSes out there in
2953 * real machines which also use this scheme.
2955 if (i
== nb_numa_nodes
) {
2956 for (i
= 0; i
< smp_cpus
; i
++) {
2957 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2962 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
2966 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2968 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2970 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2972 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2975 module_call_init(MODULE_INIT_DEVICE
);
2977 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
2981 i
= select_watchdog(watchdog
);
2983 exit (i
== 1 ? 1 : 0);
2986 if (machine
->compat_props
) {
2987 qdev_prop_register_global_list(machine
->compat_props
);
2991 machine
->init(ram_size
, boot_devices
,
2992 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2994 cpu_synchronize_all_post_init();
2996 /* must be after terminal init, SDL library changes signal handlers */
2997 os_setup_signal_handling();
3001 current_machine
= machine
;
3003 /* init USB devices */
3005 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
3009 /* init generic devices */
3010 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3013 net_check_clients();
3015 /* just use the first displaystate for the moment */
3016 ds
= get_displaystate();
3020 if (display_type
== DT_DEFAULT
&& !display_remote
) {
3021 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3022 display_type
= DT_SDL
;
3024 vnc_display
= "localhost:0,to=99";
3030 /* init local displays */
3031 switch (display_type
) {
3034 #if defined(CONFIG_CURSES)
3036 curses_display_init(ds
, full_screen
);
3039 #if defined(CONFIG_SDL)
3041 sdl_display_init(ds
, full_screen
, no_frame
);
3043 #elif defined(CONFIG_COCOA)
3045 cocoa_display_init(ds
, full_screen
);
3052 /* init remote displays */
3054 vnc_display_init(ds
);
3055 if (vnc_display_open(ds
, vnc_display
) < 0)
3058 if (show_vnc_port
) {
3059 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3063 if (using_spice
&& !qxl_enabled
) {
3064 qemu_spice_display_init(ds
);
3070 dcl
= ds
->listeners
;
3071 while (dcl
!= NULL
) {
3072 if (dcl
->dpy_refresh
!= NULL
) {
3073 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
3074 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
3079 if (ds
->gui_timer
== NULL
) {
3080 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
3081 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
3083 text_consoles_set_display(ds
);
3085 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3086 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3091 qdev_machine_creation_done();
3093 if (rom_load_all() != 0) {
3094 fprintf(stderr
, "rom loading failed\n");
3098 /* TODO: once all bus devices are qdevified, this should be done
3099 * when bus is created by qdev.c */
3100 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
3101 qemu_run_machine_init_done_notifiers();
3103 qemu_system_reset();
3105 if (load_vmstate(loadvm
) < 0) {
3111 int ret
= qemu_start_incoming_migration(incoming
);
3113 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3117 } else if (autostart
) {