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"
161 #include "qemu-queue.h"
163 #include "arch_init.h"
165 #include "ui/qemu-spice.h"
168 //#define DEBUG_SLIRP
170 #define DEFAULT_RAM_SIZE 128
172 #define MAX_VIRTIO_CONSOLES 1
174 static const char *data_dir
;
175 const char *bios_name
= NULL
;
176 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
177 DisplayType display_type
= DT_DEFAULT
;
178 int display_remote
= 0;
179 const char* keyboard_layout
= NULL
;
181 const char *mem_path
= NULL
;
183 int mem_prealloc
= 0; /* force preallocation of physical target memory */
186 NICInfo nd_table
[MAX_NICS
];
189 int incoming_expected
; /* Started with -incoming and waiting for incoming */
190 static int rtc_utc
= 1;
191 static int rtc_date_offset
= -1; /* -1 means no change */
192 QEMUClock
*rtc_clock
;
193 int vga_interface_type
= VGA_NONE
;
194 static int full_screen
= 0;
196 static int no_frame
= 0;
199 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
200 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
201 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
202 int win2k_install_hack
= 0;
210 const char *vnc_display
;
211 int acpi_enabled
= 1;
217 int graphic_rotate
= 0;
218 uint8_t irq0override
= 1;
219 const char *watchdog
;
220 const char *option_rom
[MAX_OPTION_ROMS
];
222 int semihosting_enabled
= 0;
224 const char *qemu_name
;
227 unsigned int nb_prom_envs
= 0;
228 const char *prom_envs
[MAX_PROM_ENVS
];
232 uint64_t node_mem
[MAX_NODES
];
233 uint64_t node_cpumask
[MAX_NODES
];
235 static QEMUTimer
*nographic_timer
;
237 uint8_t qemu_uuid
[16];
239 static QEMUBootSetHandler
*boot_set_handler
;
240 static void *boot_set_opaque
;
242 static NotifierList exit_notifiers
=
243 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
247 enum xen_mode xen_mode
= XEN_EMULATE
;
249 static int default_serial
= 1;
250 static int default_parallel
= 1;
251 static int default_virtcon
= 1;
252 static int default_monitor
= 1;
253 static int default_vga
= 1;
254 static int default_floppy
= 1;
255 static int default_cdrom
= 1;
256 static int default_sdcard
= 1;
262 { .driver
= "isa-serial", .flag
= &default_serial
},
263 { .driver
= "isa-parallel", .flag
= &default_parallel
},
264 { .driver
= "isa-fdc", .flag
= &default_floppy
},
265 { .driver
= "ide-drive", .flag
= &default_cdrom
},
266 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
267 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
268 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
269 { .driver
= "VGA", .flag
= &default_vga
},
270 { .driver
= "cirrus-vga", .flag
= &default_vga
},
271 { .driver
= "vmware-svga", .flag
= &default_vga
},
274 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
276 const char *driver
= qemu_opt_get(opts
, "driver");
281 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
282 if (strcmp(default_list
[i
].driver
, driver
) != 0)
284 *(default_list
[i
].flag
) = 0;
289 /***********************************************************/
290 /* real time host monotonic timer */
292 /* compute with 96 bit intermediate result: (a*b)/c */
293 uint64_t muldiv64(uint64_t a
, uint32_t b
, uint32_t c
)
298 #ifdef HOST_WORDS_BIGENDIAN
308 rl
= (uint64_t)u
.l
.low
* (uint64_t)b
;
309 rh
= (uint64_t)u
.l
.high
* (uint64_t)b
;
312 res
.l
.low
= (((rh
% c
) << 32) + (rl
& 0xffffffff)) / c
;
316 /***********************************************************/
317 /* host time/date access */
318 void qemu_get_timedate(struct tm
*tm
, int offset
)
325 if (rtc_date_offset
== -1) {
329 ret
= localtime(&ti
);
331 ti
-= rtc_date_offset
;
335 memcpy(tm
, ret
, sizeof(struct tm
));
338 int qemu_timedate_diff(struct tm
*tm
)
342 if (rtc_date_offset
== -1)
344 seconds
= mktimegm(tm
);
346 seconds
= mktime(tm
);
348 seconds
= mktimegm(tm
) + rtc_date_offset
;
350 return seconds
- time(NULL
);
353 void rtc_change_mon_event(struct tm
*tm
)
357 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
358 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
359 qobject_decref(data
);
362 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
364 time_t rtc_start_date
;
367 if (!strcmp(startdate
, "now") && legacy
) {
368 rtc_date_offset
= -1;
370 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
378 } else if (sscanf(startdate
, "%d-%d-%d",
390 rtc_start_date
= mktimegm(&tm
);
391 if (rtc_start_date
== -1) {
393 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
394 "'2006-06-17T16:01:21' or '2006-06-17'\n");
397 rtc_date_offset
= time(NULL
) - rtc_start_date
;
401 static void configure_rtc(QemuOpts
*opts
)
405 value
= qemu_opt_get(opts
, "base");
407 if (!strcmp(value
, "utc")) {
409 } else if (!strcmp(value
, "localtime")) {
412 configure_rtc_date_offset(value
, 0);
415 value
= qemu_opt_get(opts
, "clock");
417 if (!strcmp(value
, "host")) {
418 rtc_clock
= host_clock
;
419 } else if (!strcmp(value
, "vm")) {
420 rtc_clock
= vm_clock
;
422 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
426 value
= qemu_opt_get(opts
, "driftfix");
428 if (!strcmp(value
, "slew")) {
430 } else if (!strcmp(value
, "none")) {
433 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
439 /***********************************************************/
440 /* Bluetooth support */
443 static struct HCIInfo
*hci_table
[MAX_NICS
];
445 static struct bt_vlan_s
{
446 struct bt_scatternet_s net
;
448 struct bt_vlan_s
*next
;
451 /* find or alloc a new bluetooth "VLAN" */
452 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
454 struct bt_vlan_s
**pvlan
, *vlan
;
455 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
459 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
461 pvlan
= &first_bt_vlan
;
462 while (*pvlan
!= NULL
)
463 pvlan
= &(*pvlan
)->next
;
468 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
472 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
477 static struct HCIInfo null_hci
= {
478 .cmd_send
= null_hci_send
,
479 .sco_send
= null_hci_send
,
480 .acl_send
= null_hci_send
,
481 .bdaddr_set
= null_hci_addr_set
,
484 struct HCIInfo
*qemu_next_hci(void)
486 if (cur_hci
== nb_hcis
)
489 return hci_table
[cur_hci
++];
492 static struct HCIInfo
*hci_init(const char *str
)
495 struct bt_scatternet_s
*vlan
= 0;
497 if (!strcmp(str
, "null"))
500 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
502 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
503 else if (!strncmp(str
, "hci", 3)) {
506 if (!strncmp(str
+ 3, ",vlan=", 6)) {
507 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
512 vlan
= qemu_find_bt_vlan(0);
514 return bt_new_hci(vlan
);
517 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
522 static int bt_hci_parse(const char *str
)
527 if (nb_hcis
>= MAX_NICS
) {
528 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
541 bdaddr
.b
[5] = 0x56 + nb_hcis
;
542 hci
->bdaddr_set(hci
, bdaddr
.b
);
544 hci_table
[nb_hcis
++] = hci
;
549 static void bt_vhci_add(int vlan_id
)
551 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
554 fprintf(stderr
, "qemu: warning: adding a VHCI to "
555 "an empty scatternet %i\n", vlan_id
);
557 bt_vhci_init(bt_new_hci(vlan
));
560 static struct bt_device_s
*bt_device_add(const char *opt
)
562 struct bt_scatternet_s
*vlan
;
564 char *endp
= strstr(opt
, ",vlan=");
565 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
568 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
571 vlan_id
= strtol(endp
+ 6, &endp
, 0);
573 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
578 vlan
= qemu_find_bt_vlan(vlan_id
);
581 fprintf(stderr
, "qemu: warning: adding a slave device to "
582 "an empty scatternet %i\n", vlan_id
);
584 if (!strcmp(devname
, "keyboard"))
585 return bt_keyboard_init(vlan
);
587 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
591 static int bt_parse(const char *opt
)
593 const char *endp
, *p
;
596 if (strstart(opt
, "hci", &endp
)) {
597 if (!*endp
|| *endp
== ',') {
599 if (!strstart(endp
, ",vlan=", 0))
602 return bt_hci_parse(opt
);
604 } else if (strstart(opt
, "vhci", &endp
)) {
605 if (!*endp
|| *endp
== ',') {
607 if (strstart(endp
, ",vlan=", &p
)) {
608 vlan
= strtol(p
, (char **) &endp
, 0);
610 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
614 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
623 } else if (strstart(opt
, "device:", &endp
))
624 return !bt_device_add(endp
);
626 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
630 /***********************************************************/
631 /* QEMU Block devices */
633 #define HD_ALIAS "index=%d,media=disk"
634 #define CDROM_ALIAS "index=2,media=cdrom"
635 #define FD_ALIAS "index=%d,if=floppy"
636 #define PFLASH_ALIAS "if=pflash"
637 #define MTD_ALIAS "if=mtd"
638 #define SD_ALIAS "index=0,if=sd"
640 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
642 int *use_scsi
= opaque
;
645 if (drive_init(opts
, *use_scsi
, &fatal_error
) == NULL
) {
652 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
654 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
655 qemu_opt_set(opts
, "snapshot", "on");
660 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
662 boot_set_handler
= func
;
663 boot_set_opaque
= opaque
;
666 int qemu_boot_set(const char *boot_devices
)
668 if (!boot_set_handler
) {
671 return boot_set_handler(boot_set_opaque
, boot_devices
);
674 static void validate_bootdevices(char *devices
)
676 /* We just do some generic consistency checks */
680 for (p
= devices
; *p
!= '\0'; p
++) {
681 /* Allowed boot devices are:
682 * a-b: floppy disk drives
683 * c-f: IDE disk drives
684 * g-m: machine implementation dependant drives
685 * n-p: network devices
686 * It's up to each machine implementation to check if the given boot
687 * devices match the actual hardware implementation and firmware
690 if (*p
< 'a' || *p
> 'p') {
691 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
694 if (bitmap
& (1 << (*p
- 'a'))) {
695 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
698 bitmap
|= 1 << (*p
- 'a');
702 static void restore_boot_devices(void *opaque
)
704 char *standard_boot_devices
= opaque
;
705 static int first
= 1;
707 /* Restore boot order and remove ourselves after the first boot */
713 qemu_boot_set(standard_boot_devices
);
715 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
716 qemu_free(standard_boot_devices
);
719 static void numa_add(const char *optarg
)
723 unsigned long long value
, endvalue
;
726 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
727 if (!strcmp(option
, "node")) {
728 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
729 nodenr
= nb_numa_nodes
;
731 nodenr
= strtoull(option
, NULL
, 10);
734 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
735 node_mem
[nodenr
] = 0;
737 value
= strtoull(option
, &endptr
, 0);
739 case 0: case 'M': case 'm':
746 node_mem
[nodenr
] = value
;
748 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
749 node_cpumask
[nodenr
] = 0;
751 value
= strtoull(option
, &endptr
, 10);
754 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
756 if (*endptr
== '-') {
757 endvalue
= strtoull(endptr
+1, &endptr
, 10);
758 if (endvalue
>= 63) {
761 "only 63 CPUs in NUMA mode supported.\n");
763 value
= (2ULL << endvalue
) - (1ULL << value
);
765 value
= 1ULL << value
;
768 node_cpumask
[nodenr
] = value
;
775 static void smp_parse(const char *optarg
)
777 int smp
, sockets
= 0, threads
= 0, cores
= 0;
781 smp
= strtoul(optarg
, &endptr
, 10);
782 if (endptr
!= optarg
) {
783 if (*endptr
== ',') {
787 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
788 sockets
= strtoull(option
, NULL
, 10);
789 if (get_param_value(option
, 128, "cores", endptr
) != 0)
790 cores
= strtoull(option
, NULL
, 10);
791 if (get_param_value(option
, 128, "threads", endptr
) != 0)
792 threads
= strtoull(option
, NULL
, 10);
793 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
794 max_cpus
= strtoull(option
, NULL
, 10);
796 /* compute missing values, prefer sockets over cores over threads */
797 if (smp
== 0 || sockets
== 0) {
798 sockets
= sockets
> 0 ? sockets
: 1;
799 cores
= cores
> 0 ? cores
: 1;
800 threads
= threads
> 0 ? threads
: 1;
802 smp
= cores
* threads
* sockets
;
806 threads
= threads
> 0 ? threads
: 1;
807 cores
= smp
/ (sockets
* threads
);
809 threads
= smp
/ (cores
* sockets
);
813 smp_cores
= cores
> 0 ? cores
: 1;
814 smp_threads
= threads
> 0 ? threads
: 1;
819 /***********************************************************/
822 static int usb_device_add(const char *devname
)
825 USBDevice
*dev
= NULL
;
830 /* drivers with .usbdevice_name entry in USBDeviceInfo */
831 dev
= usbdevice_create(devname
);
836 if (strstart(devname
, "host:", &p
)) {
837 dev
= usb_host_device_open(p
);
838 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
839 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
840 bt_new_hci(qemu_find_bt_vlan(0)));
851 static int usb_device_del(const char *devname
)
856 if (strstart(devname
, "host:", &p
))
857 return usb_host_device_close(p
);
862 p
= strchr(devname
, '.');
865 bus_num
= strtoul(devname
, NULL
, 0);
866 addr
= strtoul(p
+ 1, NULL
, 0);
868 return usb_device_delete_addr(bus_num
, addr
);
871 static int usb_parse(const char *cmdline
)
874 r
= usb_device_add(cmdline
);
876 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
881 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
883 const char *devname
= qdict_get_str(qdict
, "devname");
884 if (usb_device_add(devname
) < 0) {
885 error_report("could not add USB device '%s'", devname
);
889 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
891 const char *devname
= qdict_get_str(qdict
, "devname");
892 if (usb_device_del(devname
) < 0) {
893 error_report("could not delete USB device '%s'", devname
);
897 /***********************************************************/
900 static struct pcmcia_socket_entry_s
{
901 PCMCIASocket
*socket
;
902 struct pcmcia_socket_entry_s
*next
;
903 } *pcmcia_sockets
= 0;
905 void pcmcia_socket_register(PCMCIASocket
*socket
)
907 struct pcmcia_socket_entry_s
*entry
;
909 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
910 entry
->socket
= socket
;
911 entry
->next
= pcmcia_sockets
;
912 pcmcia_sockets
= entry
;
915 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
917 struct pcmcia_socket_entry_s
*entry
, **ptr
;
919 ptr
= &pcmcia_sockets
;
920 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
921 if (entry
->socket
== socket
) {
927 void pcmcia_info(Monitor
*mon
)
929 struct pcmcia_socket_entry_s
*iter
;
932 monitor_printf(mon
, "No PCMCIA sockets\n");
934 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
935 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
936 iter
->socket
->attached
? iter
->socket
->card_string
:
940 /***********************************************************/
943 typedef struct IOHandlerRecord
{
945 IOCanReadHandler
*fd_read_poll
;
952 QLIST_ENTRY(IOHandlerRecord
) next
;
955 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
956 QLIST_HEAD_INITIALIZER(io_handlers
);
959 /* XXX: fd_read_poll should be suppressed, but an API change is
960 necessary in the character devices to suppress fd_can_read(). */
961 int qemu_set_fd_handler2(int fd
,
962 IOCanReadHandler
*fd_read_poll
,
967 IOHandlerRecord
*ioh
;
969 if (!fd_read
&& !fd_write
) {
970 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
977 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
981 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
982 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
985 ioh
->fd_read_poll
= fd_read_poll
;
986 ioh
->fd_read
= fd_read
;
987 ioh
->fd_write
= fd_write
;
988 ioh
->opaque
= opaque
;
994 int qemu_set_fd_handler(int fd
,
999 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
1002 /***********************************************************/
1003 /* machine registration */
1005 static QEMUMachine
*first_machine
= NULL
;
1006 QEMUMachine
*current_machine
= NULL
;
1008 int qemu_register_machine(QEMUMachine
*m
)
1011 pm
= &first_machine
;
1019 static QEMUMachine
*find_machine(const char *name
)
1023 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1024 if (!strcmp(m
->name
, name
))
1026 if (m
->alias
&& !strcmp(m
->alias
, name
))
1032 static QEMUMachine
*find_default_machine(void)
1036 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1037 if (m
->is_default
) {
1044 /***********************************************************/
1045 /* main execution loop */
1047 static void gui_update(void *opaque
)
1049 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1050 DisplayState
*ds
= opaque
;
1051 DisplayChangeListener
*dcl
= ds
->listeners
;
1053 qemu_flush_coalesced_mmio_buffer();
1056 while (dcl
!= NULL
) {
1057 if (dcl
->gui_timer_interval
&&
1058 dcl
->gui_timer_interval
< interval
)
1059 interval
= dcl
->gui_timer_interval
;
1062 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1065 static void nographic_update(void *opaque
)
1067 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1069 qemu_flush_coalesced_mmio_buffer();
1070 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1073 struct vm_change_state_entry
{
1074 VMChangeStateHandler
*cb
;
1076 QLIST_ENTRY (vm_change_state_entry
) entries
;
1079 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1081 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1084 VMChangeStateEntry
*e
;
1086 e
= qemu_mallocz(sizeof (*e
));
1090 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1094 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1096 QLIST_REMOVE (e
, entries
);
1100 void vm_state_notify(int running
, int reason
)
1102 VMChangeStateEntry
*e
;
1104 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1105 e
->cb(e
->opaque
, running
, reason
);
1114 vm_state_notify(1, 0);
1116 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1120 /* reset/shutdown handler */
1122 typedef struct QEMUResetEntry
{
1123 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1124 QEMUResetHandler
*func
;
1128 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1129 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1130 static int reset_requested
;
1131 static int shutdown_requested
;
1132 static int powerdown_requested
;
1133 int debug_requested
;
1134 int vmstop_requested
;
1136 int qemu_shutdown_requested(void)
1138 int r
= shutdown_requested
;
1139 shutdown_requested
= 0;
1143 int qemu_reset_requested(void)
1145 int r
= reset_requested
;
1146 reset_requested
= 0;
1150 int qemu_powerdown_requested(void)
1152 int r
= powerdown_requested
;
1153 powerdown_requested
= 0;
1157 static int qemu_debug_requested(void)
1159 int r
= debug_requested
;
1160 debug_requested
= 0;
1164 static int qemu_vmstop_requested(void)
1166 int r
= vmstop_requested
;
1167 vmstop_requested
= 0;
1171 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1173 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1176 re
->opaque
= opaque
;
1177 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1180 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1184 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1185 if (re
->func
== func
&& re
->opaque
== opaque
) {
1186 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1193 void qemu_system_reset(void)
1195 QEMUResetEntry
*re
, *nre
;
1197 /* reset all devices */
1198 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1199 re
->func(re
->opaque
);
1201 monitor_protocol_event(QEVENT_RESET
, NULL
);
1202 cpu_synchronize_all_post_reset();
1205 void qemu_system_reset_request(void)
1208 shutdown_requested
= 1;
1210 reset_requested
= 1;
1212 qemu_notify_event();
1215 void qemu_system_shutdown_request(void)
1217 shutdown_requested
= 1;
1218 qemu_notify_event();
1221 void qemu_system_powerdown_request(void)
1223 powerdown_requested
= 1;
1224 qemu_notify_event();
1227 void main_loop_wait(int nonblocking
)
1229 IOHandlerRecord
*ioh
;
1230 fd_set rfds
, wfds
, xfds
;
1238 timeout
= qemu_calculate_timeout();
1239 qemu_bh_update_timeout(&timeout
);
1242 os_host_main_loop_wait(&timeout
);
1244 /* poll any events */
1245 /* XXX: separate device handlers from system ones */
1250 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1254 (!ioh
->fd_read_poll
||
1255 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1256 FD_SET(ioh
->fd
, &rfds
);
1260 if (ioh
->fd_write
) {
1261 FD_SET(ioh
->fd
, &wfds
);
1267 tv
.tv_sec
= timeout
/ 1000;
1268 tv
.tv_usec
= (timeout
% 1000) * 1000;
1270 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1272 qemu_mutex_unlock_iothread();
1273 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1274 qemu_mutex_lock_iothread();
1276 IOHandlerRecord
*pioh
;
1278 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1280 QLIST_REMOVE(ioh
, next
);
1284 if (ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1285 ioh
->fd_read(ioh
->opaque
);
1287 if (ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1288 ioh
->fd_write(ioh
->opaque
);
1293 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1295 qemu_run_all_timers();
1297 /* Check bottom-halves last in case any of the earlier events triggered
1303 static int vm_can_run(void)
1305 if (powerdown_requested
)
1307 if (reset_requested
)
1309 if (shutdown_requested
)
1311 if (debug_requested
)
1316 qemu_irq qemu_system_powerdown
;
1318 static void main_loop(void)
1322 qemu_main_loop_start();
1326 bool nonblocking
= false;
1327 #ifdef CONFIG_PROFILER
1330 #ifndef CONFIG_IOTHREAD
1331 nonblocking
= cpu_exec_all();
1333 #ifdef CONFIG_PROFILER
1334 ti
= profile_getclock();
1336 main_loop_wait(nonblocking
);
1337 #ifdef CONFIG_PROFILER
1338 dev_time
+= profile_getclock() - ti
;
1340 } while (vm_can_run());
1342 if ((r
= qemu_debug_requested())) {
1345 if (qemu_shutdown_requested()) {
1346 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1353 if (qemu_reset_requested()) {
1355 qemu_system_reset();
1358 if (qemu_powerdown_requested()) {
1359 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1360 qemu_irq_raise(qemu_system_powerdown
);
1362 if ((r
= qemu_vmstop_requested())) {
1370 static void version(void)
1372 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1375 static void help(int exitcode
)
1377 const char *options_help
=
1378 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1380 #define DEFHEADING(text) stringify(text) "\n"
1381 #include "qemu-options.def"
1387 printf("usage: %s [options] [disk_image]\n"
1389 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1392 "During emulation, the following keys are useful:\n"
1393 "ctrl-alt-f toggle full screen\n"
1394 "ctrl-alt-n switch to virtual console 'n'\n"
1395 "ctrl-alt toggle mouse and keyboard grab\n"
1397 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1403 #define HAS_ARG 0x0001
1405 typedef struct QEMUOption
{
1412 static const QEMUOption qemu_options
[] = {
1413 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1414 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1415 { option, opt_arg, opt_enum, arch_mask },
1416 #define DEFHEADING(text)
1417 #include "qemu-options.def"
1423 static void select_vgahw (const char *p
)
1428 vga_interface_type
= VGA_NONE
;
1429 if (strstart(p
, "std", &opts
)) {
1430 vga_interface_type
= VGA_STD
;
1431 } else if (strstart(p
, "cirrus", &opts
)) {
1432 vga_interface_type
= VGA_CIRRUS
;
1433 } else if (strstart(p
, "vmware", &opts
)) {
1434 vga_interface_type
= VGA_VMWARE
;
1435 } else if (strstart(p
, "xenfb", &opts
)) {
1436 vga_interface_type
= VGA_XENFB
;
1437 } else if (!strstart(p
, "none", &opts
)) {
1439 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1443 const char *nextopt
;
1445 if (strstart(opts
, ",retrace=", &nextopt
)) {
1447 if (strstart(opts
, "dumb", &nextopt
))
1448 vga_retrace_method
= VGA_RETRACE_DUMB
;
1449 else if (strstart(opts
, "precise", &nextopt
))
1450 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1451 else goto invalid_vga
;
1452 } else goto invalid_vga
;
1457 static int balloon_parse(const char *arg
)
1461 if (strcmp(arg
, "none") == 0) {
1465 if (!strncmp(arg
, "virtio", 6)) {
1466 if (arg
[6] == ',') {
1467 /* have params -> parse them */
1468 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1472 /* create empty opts */
1473 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1475 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1482 char *qemu_find_file(int type
, const char *name
)
1488 /* If name contains path separators then try it as a straight path. */
1489 if ((strchr(name
, '/') || strchr(name
, '\\'))
1490 && access(name
, R_OK
) == 0) {
1491 return qemu_strdup(name
);
1494 case QEMU_FILE_TYPE_BIOS
:
1497 case QEMU_FILE_TYPE_KEYMAP
:
1498 subdir
= "keymaps/";
1503 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1504 buf
= qemu_mallocz(len
);
1505 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1506 if (access(buf
, R_OK
)) {
1513 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1515 return qdev_device_help(opts
);
1518 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1522 dev
= qdev_device_add(opts
);
1528 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1530 CharDriverState
*chr
;
1532 chr
= qemu_chr_open_opts(opts
, NULL
);
1538 #ifdef CONFIG_VIRTFS
1539 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1542 ret
= qemu_fsdev_add(opts
);
1548 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1550 CharDriverState
*chr
;
1551 const char *chardev
;
1555 mode
= qemu_opt_get(opts
, "mode");
1559 if (strcmp(mode
, "readline") == 0) {
1560 flags
= MONITOR_USE_READLINE
;
1561 } else if (strcmp(mode
, "control") == 0) {
1562 flags
= MONITOR_USE_CONTROL
;
1564 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1568 if (qemu_opt_get_bool(opts
, "pretty", 0))
1569 flags
|= MONITOR_USE_PRETTY
;
1571 if (qemu_opt_get_bool(opts
, "default", 0))
1572 flags
|= MONITOR_IS_DEFAULT
;
1574 chardev
= qemu_opt_get(opts
, "chardev");
1575 chr
= qemu_chr_find(chardev
);
1577 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1581 monitor_init(chr
, flags
);
1585 static void monitor_parse(const char *optarg
, const char *mode
)
1587 static int monitor_device_index
= 0;
1593 if (strstart(optarg
, "chardev:", &p
)) {
1594 snprintf(label
, sizeof(label
), "%s", p
);
1596 snprintf(label
, sizeof(label
), "compat_monitor%d",
1597 monitor_device_index
);
1598 if (monitor_device_index
== 0) {
1601 opts
= qemu_chr_parse_compat(label
, optarg
);
1603 fprintf(stderr
, "parse error: %s\n", optarg
);
1608 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1610 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1613 qemu_opt_set(opts
, "mode", mode
);
1614 qemu_opt_set(opts
, "chardev", label
);
1616 qemu_opt_set(opts
, "default", "on");
1617 monitor_device_index
++;
1620 struct device_config
{
1622 DEV_USB
, /* -usbdevice */
1624 DEV_SERIAL
, /* -serial */
1625 DEV_PARALLEL
, /* -parallel */
1626 DEV_VIRTCON
, /* -virtioconsole */
1627 DEV_DEBUGCON
, /* -debugcon */
1629 const char *cmdline
;
1630 QTAILQ_ENTRY(device_config
) next
;
1632 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1634 static void add_device_config(int type
, const char *cmdline
)
1636 struct device_config
*conf
;
1638 conf
= qemu_mallocz(sizeof(*conf
));
1640 conf
->cmdline
= cmdline
;
1641 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1644 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1646 struct device_config
*conf
;
1649 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1650 if (conf
->type
!= type
)
1652 rc
= func(conf
->cmdline
);
1659 static int serial_parse(const char *devname
)
1661 static int index
= 0;
1664 if (strcmp(devname
, "none") == 0)
1666 if (index
== MAX_SERIAL_PORTS
) {
1667 fprintf(stderr
, "qemu: too many serial ports\n");
1670 snprintf(label
, sizeof(label
), "serial%d", index
);
1671 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1672 if (!serial_hds
[index
]) {
1673 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1674 devname
, strerror(errno
));
1681 static int parallel_parse(const char *devname
)
1683 static int index
= 0;
1686 if (strcmp(devname
, "none") == 0)
1688 if (index
== MAX_PARALLEL_PORTS
) {
1689 fprintf(stderr
, "qemu: too many parallel ports\n");
1692 snprintf(label
, sizeof(label
), "parallel%d", index
);
1693 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1694 if (!parallel_hds
[index
]) {
1695 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1696 devname
, strerror(errno
));
1703 static int virtcon_parse(const char *devname
)
1705 QemuOptsList
*device
= qemu_find_opts("device");
1706 static int index
= 0;
1708 QemuOpts
*bus_opts
, *dev_opts
;
1710 if (strcmp(devname
, "none") == 0)
1712 if (index
== MAX_VIRTIO_CONSOLES
) {
1713 fprintf(stderr
, "qemu: too many virtio consoles\n");
1717 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1718 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1720 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1721 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1723 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1724 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1725 if (!virtcon_hds
[index
]) {
1726 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1727 devname
, strerror(errno
));
1730 qemu_opt_set(dev_opts
, "chardev", label
);
1736 static int debugcon_parse(const char *devname
)
1740 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1743 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1745 fprintf(stderr
, "qemu: already have a debugcon device\n");
1748 qemu_opt_set(opts
, "driver", "isa-debugcon");
1749 qemu_opt_set(opts
, "chardev", "debugcon");
1753 void qemu_add_exit_notifier(Notifier
*notify
)
1755 notifier_list_add(&exit_notifiers
, notify
);
1758 void qemu_remove_exit_notifier(Notifier
*notify
)
1760 notifier_list_remove(&exit_notifiers
, notify
);
1763 static void qemu_run_exit_notifiers(void)
1765 notifier_list_notify(&exit_notifiers
);
1768 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1769 const char **poptarg
, int *poptind
)
1771 const QEMUOption
*popt
;
1772 int optind
= *poptind
;
1773 char *r
= argv
[optind
];
1776 loc_set_cmdline(argv
, optind
, 1);
1778 /* Treat --foo the same as -foo. */
1781 popt
= qemu_options
;
1784 error_report("invalid option");
1787 if (!strcmp(popt
->name
, r
+ 1))
1791 if (popt
->flags
& HAS_ARG
) {
1792 if (optind
>= argc
) {
1793 error_report("requires an argument");
1796 optarg
= argv
[optind
++];
1797 loc_set_cmdline(argv
, optind
- 2, 2);
1808 int main(int argc
, char **argv
, char **envp
)
1810 const char *gdbstub_dev
= NULL
;
1812 int snapshot
, linux_boot
;
1813 const char *icount_option
= NULL
;
1814 const char *initrd_filename
;
1815 const char *kernel_filename
, *kernel_cmdline
;
1816 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1818 DisplayChangeListener
*dcl
;
1819 int cyls
, heads
, secs
, translation
;
1820 QemuOpts
*hda_opts
= NULL
, *opts
;
1821 QemuOptsList
*olist
;
1824 const char *loadvm
= NULL
;
1825 QEMUMachine
*machine
;
1826 const char *cpu_model
;
1828 const char *pid_file
= NULL
;
1829 const char *incoming
= NULL
;
1830 int show_vnc_port
= 0;
1833 #ifdef CONFIG_SIMPLE_TRACE
1834 const char *trace_file
= NULL
;
1836 atexit(qemu_run_exit_notifiers
);
1837 error_set_progname(argv
[0]);
1841 qemu_cache_utils_init(envp
);
1843 QLIST_INIT (&vm_change_state_head
);
1844 os_setup_early_signal_handling();
1846 module_call_init(MODULE_INIT_MACHINE
);
1847 machine
= find_default_machine();
1849 initrd_filename
= NULL
;
1852 kernel_filename
= NULL
;
1853 kernel_cmdline
= "";
1854 cyls
= heads
= secs
= 0;
1855 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1857 for (i
= 0; i
< MAX_NODES
; i
++) {
1859 node_cpumask
[i
] = 0;
1868 /* first pass of option parsing */
1870 while (optind
< argc
) {
1871 if (argv
[optind
][0] != '-') {
1876 const QEMUOption
*popt
;
1878 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1879 switch (popt
->index
) {
1880 case QEMU_OPTION_nodefconfig
:
1890 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1891 if (ret
< 0 && ret
!= -ENOENT
) {
1895 ret
= qemu_read_config_file(arch_config_name
);
1896 if (ret
< 0 && ret
!= -ENOENT
) {
1902 /* second pass of option parsing */
1907 if (argv
[optind
][0] != '-') {
1908 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1910 const QEMUOption
*popt
;
1912 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1913 if (!(popt
->arch_mask
& arch_type
)) {
1914 printf("Option %s not supported for this target\n", popt
->name
);
1917 switch(popt
->index
) {
1919 machine
= find_machine(optarg
);
1922 printf("Supported machines are:\n");
1923 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1925 printf("%-10s %s (alias of %s)\n",
1926 m
->alias
, m
->desc
, m
->name
);
1927 printf("%-10s %s%s\n",
1929 m
->is_default
? " (default)" : "");
1931 exit(*optarg
!= '?');
1934 case QEMU_OPTION_cpu
:
1935 /* hw initialization will check this */
1936 if (*optarg
== '?') {
1937 list_cpus(stdout
, &fprintf
, optarg
);
1943 case QEMU_OPTION_initrd
:
1944 initrd_filename
= optarg
;
1946 case QEMU_OPTION_hda
:
1948 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
1950 hda_opts
= drive_add(optarg
, HD_ALIAS
1951 ",cyls=%d,heads=%d,secs=%d%s",
1952 0, cyls
, heads
, secs
,
1953 translation
== BIOS_ATA_TRANSLATION_LBA
?
1955 translation
== BIOS_ATA_TRANSLATION_NONE
?
1956 ",trans=none" : "");
1958 case QEMU_OPTION_hdb
:
1959 case QEMU_OPTION_hdc
:
1960 case QEMU_OPTION_hdd
:
1961 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
1963 case QEMU_OPTION_drive
:
1964 drive_add(NULL
, "%s", optarg
);
1966 case QEMU_OPTION_set
:
1967 if (qemu_set_option(optarg
) != 0)
1970 case QEMU_OPTION_global
:
1971 if (qemu_global_option(optarg
) != 0)
1974 case QEMU_OPTION_mtdblock
:
1975 drive_add(optarg
, MTD_ALIAS
);
1977 case QEMU_OPTION_sd
:
1978 drive_add(optarg
, SD_ALIAS
);
1980 case QEMU_OPTION_pflash
:
1981 drive_add(optarg
, PFLASH_ALIAS
);
1983 case QEMU_OPTION_snapshot
:
1986 case QEMU_OPTION_hdachs
:
1990 cyls
= strtol(p
, (char **)&p
, 0);
1991 if (cyls
< 1 || cyls
> 16383)
1996 heads
= strtol(p
, (char **)&p
, 0);
1997 if (heads
< 1 || heads
> 16)
2002 secs
= strtol(p
, (char **)&p
, 0);
2003 if (secs
< 1 || secs
> 63)
2007 if (!strcmp(p
, "none"))
2008 translation
= BIOS_ATA_TRANSLATION_NONE
;
2009 else if (!strcmp(p
, "lba"))
2010 translation
= BIOS_ATA_TRANSLATION_LBA
;
2011 else if (!strcmp(p
, "auto"))
2012 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2015 } else if (*p
!= '\0') {
2017 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2020 if (hda_opts
!= NULL
) {
2022 snprintf(num
, sizeof(num
), "%d", cyls
);
2023 qemu_opt_set(hda_opts
, "cyls", num
);
2024 snprintf(num
, sizeof(num
), "%d", heads
);
2025 qemu_opt_set(hda_opts
, "heads", num
);
2026 snprintf(num
, sizeof(num
), "%d", secs
);
2027 qemu_opt_set(hda_opts
, "secs", num
);
2028 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2029 qemu_opt_set(hda_opts
, "trans", "lba");
2030 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2031 qemu_opt_set(hda_opts
, "trans", "none");
2035 case QEMU_OPTION_numa
:
2036 if (nb_numa_nodes
>= MAX_NODES
) {
2037 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2042 case QEMU_OPTION_nographic
:
2043 display_type
= DT_NOGRAPHIC
;
2045 #ifdef CONFIG_CURSES
2046 case QEMU_OPTION_curses
:
2047 display_type
= DT_CURSES
;
2050 case QEMU_OPTION_portrait
:
2053 case QEMU_OPTION_kernel
:
2054 kernel_filename
= optarg
;
2056 case QEMU_OPTION_append
:
2057 kernel_cmdline
= optarg
;
2059 case QEMU_OPTION_cdrom
:
2060 drive_add(optarg
, CDROM_ALIAS
);
2062 case QEMU_OPTION_boot
:
2064 static const char * const params
[] = {
2065 "order", "once", "menu", NULL
2067 char buf
[sizeof(boot_devices
)];
2068 char *standard_boot_devices
;
2071 if (!strchr(optarg
, '=')) {
2073 pstrcpy(buf
, sizeof(buf
), optarg
);
2074 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2076 "qemu: unknown boot parameter '%s' in '%s'\n",
2082 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2083 validate_bootdevices(buf
);
2084 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2087 if (get_param_value(buf
, sizeof(buf
),
2089 validate_bootdevices(buf
);
2090 standard_boot_devices
= qemu_strdup(boot_devices
);
2091 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2092 qemu_register_reset(restore_boot_devices
,
2093 standard_boot_devices
);
2095 if (get_param_value(buf
, sizeof(buf
),
2097 if (!strcmp(buf
, "on")) {
2099 } else if (!strcmp(buf
, "off")) {
2103 "qemu: invalid option value '%s'\n",
2111 case QEMU_OPTION_fda
:
2112 case QEMU_OPTION_fdb
:
2113 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2115 case QEMU_OPTION_no_fd_bootchk
:
2118 case QEMU_OPTION_netdev
:
2119 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2123 case QEMU_OPTION_net
:
2124 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2129 case QEMU_OPTION_tftp
:
2130 legacy_tftp_prefix
= optarg
;
2132 case QEMU_OPTION_bootp
:
2133 legacy_bootp_filename
= optarg
;
2135 case QEMU_OPTION_redir
:
2136 if (net_slirp_redir(optarg
) < 0)
2140 case QEMU_OPTION_bt
:
2141 add_device_config(DEV_BT
, optarg
);
2143 case QEMU_OPTION_audio_help
:
2144 if (!(audio_available())) {
2145 printf("Option %s not supported for this target\n", popt
->name
);
2151 case QEMU_OPTION_soundhw
:
2152 if (!(audio_available())) {
2153 printf("Option %s not supported for this target\n", popt
->name
);
2156 select_soundhw (optarg
);
2161 case QEMU_OPTION_version
:
2165 case QEMU_OPTION_m
: {
2169 value
= strtoul(optarg
, &ptr
, 10);
2171 case 0: case 'M': case 'm':
2178 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2182 /* On 32-bit hosts, QEMU is limited by virtual address space */
2183 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2184 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2187 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2188 fprintf(stderr
, "qemu: ram size too large\n");
2194 case QEMU_OPTION_mempath
:
2198 case QEMU_OPTION_mem_prealloc
:
2203 set_cpu_log(optarg
);
2206 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2208 case QEMU_OPTION_gdb
:
2209 gdbstub_dev
= optarg
;
2214 case QEMU_OPTION_bios
:
2217 case QEMU_OPTION_singlestep
:
2224 keyboard_layout
= optarg
;
2226 case QEMU_OPTION_localtime
:
2229 case QEMU_OPTION_vga
:
2230 select_vgahw (optarg
);
2237 w
= strtol(p
, (char **)&p
, 10);
2240 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2246 h
= strtol(p
, (char **)&p
, 10);
2251 depth
= strtol(p
, (char **)&p
, 10);
2252 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2253 depth
!= 24 && depth
!= 32)
2255 } else if (*p
== '\0') {
2256 depth
= graphic_depth
;
2263 graphic_depth
= depth
;
2266 case QEMU_OPTION_echr
:
2269 term_escape_char
= strtol(optarg
, &r
, 0);
2271 printf("Bad argument to echr\n");
2274 case QEMU_OPTION_monitor
:
2275 monitor_parse(optarg
, "readline");
2276 default_monitor
= 0;
2278 case QEMU_OPTION_qmp
:
2279 monitor_parse(optarg
, "control");
2280 default_monitor
= 0;
2282 case QEMU_OPTION_mon
:
2283 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2287 default_monitor
= 0;
2289 case QEMU_OPTION_chardev
:
2290 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2295 case QEMU_OPTION_fsdev
:
2296 olist
= qemu_find_opts("fsdev");
2298 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2301 opts
= qemu_opts_parse(olist
, optarg
, 1);
2303 fprintf(stderr
, "parse error: %s\n", optarg
);
2307 case QEMU_OPTION_virtfs
: {
2308 char *arg_fsdev
= NULL
;
2309 char *arg_9p
= NULL
;
2312 olist
= qemu_find_opts("virtfs");
2314 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2317 opts
= qemu_opts_parse(olist
, optarg
, 1);
2319 fprintf(stderr
, "parse error: %s\n", optarg
);
2323 if (qemu_opt_get(opts
, "fstype") == NULL
||
2324 qemu_opt_get(opts
, "mount_tag") == NULL
||
2325 qemu_opt_get(opts
, "path") == NULL
||
2326 qemu_opt_get(opts
, "security_model") == NULL
) {
2327 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2328 "security_model=[mapped|passthrough|none],"
2333 len
= strlen(",id=,path=,security_model=");
2334 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2335 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2336 len
+= strlen(qemu_opt_get(opts
, "path"));
2337 len
+= strlen(qemu_opt_get(opts
, "security_model"));
2338 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2340 snprintf(arg_fsdev
, (len
+ 1) * sizeof(*arg_fsdev
),
2341 "%s,id=%s,path=%s,security_model=%s",
2342 qemu_opt_get(opts
, "fstype"),
2343 qemu_opt_get(opts
, "mount_tag"),
2344 qemu_opt_get(opts
, "path"),
2345 qemu_opt_get(opts
, "security_model"));
2347 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2348 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2349 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2351 snprintf(arg_9p
, (len
+ 1) * sizeof(*arg_9p
),
2352 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2353 qemu_opt_get(opts
, "mount_tag"),
2354 qemu_opt_get(opts
, "mount_tag"));
2356 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev
, 1)) {
2357 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2361 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p
, 1)) {
2362 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2366 qemu_free(arg_fsdev
);
2370 case QEMU_OPTION_serial
:
2371 add_device_config(DEV_SERIAL
, optarg
);
2373 if (strncmp(optarg
, "mon:", 4) == 0) {
2374 default_monitor
= 0;
2377 case QEMU_OPTION_watchdog
:
2380 "qemu: only one watchdog option may be given\n");
2385 case QEMU_OPTION_watchdog_action
:
2386 if (select_watchdog_action(optarg
) == -1) {
2387 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2391 case QEMU_OPTION_virtiocon
:
2392 add_device_config(DEV_VIRTCON
, optarg
);
2393 default_virtcon
= 0;
2394 if (strncmp(optarg
, "mon:", 4) == 0) {
2395 default_monitor
= 0;
2398 case QEMU_OPTION_parallel
:
2399 add_device_config(DEV_PARALLEL
, optarg
);
2400 default_parallel
= 0;
2401 if (strncmp(optarg
, "mon:", 4) == 0) {
2402 default_monitor
= 0;
2405 case QEMU_OPTION_debugcon
:
2406 add_device_config(DEV_DEBUGCON
, optarg
);
2408 case QEMU_OPTION_loadvm
:
2411 case QEMU_OPTION_full_screen
:
2415 case QEMU_OPTION_no_frame
:
2418 case QEMU_OPTION_alt_grab
:
2421 case QEMU_OPTION_ctrl_grab
:
2424 case QEMU_OPTION_no_quit
:
2427 case QEMU_OPTION_sdl
:
2428 display_type
= DT_SDL
;
2431 case QEMU_OPTION_pidfile
:
2434 case QEMU_OPTION_win2k_hack
:
2435 win2k_install_hack
= 1;
2437 case QEMU_OPTION_rtc_td_hack
:
2440 case QEMU_OPTION_acpitable
:
2441 do_acpitable_option(optarg
);
2443 case QEMU_OPTION_smbios
:
2444 do_smbios_option(optarg
);
2446 case QEMU_OPTION_enable_kvm
:
2449 case QEMU_OPTION_usb
:
2452 case QEMU_OPTION_usbdevice
:
2454 add_device_config(DEV_USB
, optarg
);
2456 case QEMU_OPTION_device
:
2457 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2461 case QEMU_OPTION_smp
:
2464 fprintf(stderr
, "Invalid number of CPUs\n");
2467 if (max_cpus
< smp_cpus
) {
2468 fprintf(stderr
, "maxcpus must be equal to or greater than "
2472 if (max_cpus
> 255) {
2473 fprintf(stderr
, "Unsupported number of maxcpus\n");
2477 case QEMU_OPTION_vnc
:
2479 vnc_display
= optarg
;
2481 case QEMU_OPTION_no_acpi
:
2484 case QEMU_OPTION_no_hpet
:
2487 case QEMU_OPTION_balloon
:
2488 if (balloon_parse(optarg
) < 0) {
2489 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2493 case QEMU_OPTION_no_reboot
:
2496 case QEMU_OPTION_no_shutdown
:
2499 case QEMU_OPTION_show_cursor
:
2502 case QEMU_OPTION_uuid
:
2503 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2504 fprintf(stderr
, "Fail to parse UUID string."
2505 " Wrong format.\n");
2509 case QEMU_OPTION_option_rom
:
2510 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2511 fprintf(stderr
, "Too many option ROMs\n");
2514 option_rom
[nb_option_roms
] = optarg
;
2517 case QEMU_OPTION_semihosting
:
2518 semihosting_enabled
= 1;
2520 case QEMU_OPTION_name
:
2521 qemu_name
= qemu_strdup(optarg
);
2523 char *p
= strchr(qemu_name
, ',');
2526 if (strncmp(p
, "process=", 8)) {
2527 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2531 os_set_proc_name(p
);
2535 case QEMU_OPTION_prom_env
:
2536 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2537 fprintf(stderr
, "Too many prom variables\n");
2540 prom_envs
[nb_prom_envs
] = optarg
;
2543 case QEMU_OPTION_old_param
:
2546 case QEMU_OPTION_clock
:
2547 configure_alarms(optarg
);
2549 case QEMU_OPTION_startdate
:
2550 configure_rtc_date_offset(optarg
, 1);
2552 case QEMU_OPTION_rtc
:
2553 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2557 configure_rtc(opts
);
2559 case QEMU_OPTION_tb_size
:
2560 tb_size
= strtol(optarg
, NULL
, 0);
2564 case QEMU_OPTION_icount
:
2565 icount_option
= optarg
;
2567 case QEMU_OPTION_incoming
:
2569 incoming_expected
= true;
2571 case QEMU_OPTION_nodefaults
:
2573 default_parallel
= 0;
2574 default_virtcon
= 0;
2575 default_monitor
= 0;
2582 case QEMU_OPTION_xen_domid
:
2583 if (!(xen_available())) {
2584 printf("Option %s not supported for this target\n", popt
->name
);
2587 xen_domid
= atoi(optarg
);
2589 case QEMU_OPTION_xen_create
:
2590 if (!(xen_available())) {
2591 printf("Option %s not supported for this target\n", popt
->name
);
2594 xen_mode
= XEN_CREATE
;
2596 case QEMU_OPTION_xen_attach
:
2597 if (!(xen_available())) {
2598 printf("Option %s not supported for this target\n", popt
->name
);
2601 xen_mode
= XEN_ATTACH
;
2603 #ifdef CONFIG_SIMPLE_TRACE
2604 case QEMU_OPTION_trace
:
2605 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2607 trace_file
= qemu_opt_get(opts
, "file");
2611 case QEMU_OPTION_readconfig
:
2613 int ret
= qemu_read_config_file(optarg
);
2615 fprintf(stderr
, "read config %s: %s\n", optarg
,
2621 case QEMU_OPTION_spice
:
2622 olist
= qemu_find_opts("spice");
2624 fprintf(stderr
, "spice is not supported by this qemu build.\n");
2627 opts
= qemu_opts_parse(olist
, optarg
, 0);
2629 fprintf(stderr
, "parse error: %s\n", optarg
);
2633 case QEMU_OPTION_writeconfig
:
2636 if (strcmp(optarg
, "-") == 0) {
2639 fp
= fopen(optarg
, "w");
2641 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2645 qemu_config_write(fp
);
2650 os_parse_cmd_args(popt
->index
, optarg
);
2656 /* If no data_dir is specified then try to find it relative to the
2659 data_dir
= os_find_datadir(argv
[0]);
2661 /* If all else fails use the install patch specified when building. */
2663 data_dir
= CONFIG_QEMU_DATADIR
;
2666 #ifdef CONFIG_SIMPLE_TRACE
2668 * Set the trace file name, if specified.
2670 st_set_trace_file(trace_file
);
2673 * Default to max_cpus = smp_cpus, in case the user doesn't
2674 * specify a max_cpus value.
2677 max_cpus
= smp_cpus
;
2679 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2680 if (smp_cpus
> machine
->max_cpus
) {
2681 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2682 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2687 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2688 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2690 if (machine
->no_serial
) {
2693 if (machine
->no_parallel
) {
2694 default_parallel
= 0;
2696 if (!machine
->use_virtcon
) {
2697 default_virtcon
= 0;
2699 if (machine
->no_vga
) {
2702 if (machine
->no_floppy
) {
2705 if (machine
->no_cdrom
) {
2708 if (machine
->no_sdcard
) {
2712 if (display_type
== DT_NOGRAPHIC
) {
2713 if (default_parallel
)
2714 add_device_config(DEV_PARALLEL
, "null");
2715 if (default_serial
&& default_monitor
) {
2716 add_device_config(DEV_SERIAL
, "mon:stdio");
2717 } else if (default_virtcon
&& default_monitor
) {
2718 add_device_config(DEV_VIRTCON
, "mon:stdio");
2721 add_device_config(DEV_SERIAL
, "stdio");
2722 if (default_virtcon
)
2723 add_device_config(DEV_VIRTCON
, "stdio");
2724 if (default_monitor
)
2725 monitor_parse("stdio", "readline");
2729 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2730 if (default_parallel
)
2731 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2732 if (default_monitor
)
2733 monitor_parse("vc:80Cx24C", "readline");
2734 if (default_virtcon
)
2735 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2738 vga_interface_type
= VGA_CIRRUS
;
2742 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
2744 #ifdef CONFIG_VIRTFS
2745 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
2752 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2758 int ret
= kvm_init(smp_cpus
);
2760 if (!kvm_available()) {
2761 printf("KVM not supported for this target\n");
2763 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2769 if (qemu_init_main_loop()) {
2770 fprintf(stderr
, "qemu_init_main_loop failed\n");
2773 linux_boot
= (kernel_filename
!= NULL
);
2775 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2776 fprintf(stderr
, "-append only allowed with -kernel option\n");
2780 if (!linux_boot
&& initrd_filename
!= NULL
) {
2781 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2785 os_set_line_buffering();
2787 if (init_timer_alarm() < 0) {
2788 fprintf(stderr
, "could not initialize alarm timer\n");
2791 configure_icount(icount_option
);
2793 if (net_init_clients() < 0) {
2797 /* init the bluetooth world */
2798 if (foreach_device_config(DEV_BT
, bt_parse
))
2801 /* init the memory */
2803 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2805 /* init the dynamic translator */
2806 cpu_exec_init_all(tb_size
* 1024 * 1024);
2808 bdrv_init_with_whitelist();
2812 if (default_cdrom
) {
2813 /* we always create the cdrom drive, even if no disk is there */
2814 drive_add(NULL
, CDROM_ALIAS
);
2817 if (default_floppy
) {
2818 /* we always create at least one floppy */
2819 drive_add(NULL
, FD_ALIAS
, 0);
2822 if (default_sdcard
) {
2823 /* we always create one sd slot, even if no card is in it */
2824 drive_add(NULL
, SD_ALIAS
);
2827 /* open the virtual block devices */
2829 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
2830 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
2833 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2836 if (nb_numa_nodes
> 0) {
2839 if (nb_numa_nodes
> smp_cpus
) {
2840 nb_numa_nodes
= smp_cpus
;
2843 /* If no memory size if given for any node, assume the default case
2844 * and distribute the available memory equally across all nodes
2846 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2847 if (node_mem
[i
] != 0)
2850 if (i
== nb_numa_nodes
) {
2851 uint64_t usedmem
= 0;
2853 /* On Linux, the each node's border has to be 8MB aligned,
2854 * the final node gets the rest.
2856 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2857 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2858 usedmem
+= node_mem
[i
];
2860 node_mem
[i
] = ram_size
- usedmem
;
2863 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2864 if (node_cpumask
[i
] != 0)
2867 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2868 * must cope with this anyway, because there are BIOSes out there in
2869 * real machines which also use this scheme.
2871 if (i
== nb_numa_nodes
) {
2872 for (i
= 0; i
< smp_cpus
; i
++) {
2873 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2878 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
2882 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2884 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2886 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2888 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2891 module_call_init(MODULE_INIT_DEVICE
);
2893 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
2897 i
= select_watchdog(watchdog
);
2899 exit (i
== 1 ? 1 : 0);
2902 if (machine
->compat_props
) {
2903 qdev_prop_register_global_list(machine
->compat_props
);
2907 machine
->init(ram_size
, boot_devices
,
2908 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2910 cpu_synchronize_all_post_init();
2912 /* must be after terminal init, SDL library changes signal handlers */
2913 os_setup_signal_handling();
2917 current_machine
= machine
;
2919 /* init USB devices */
2921 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2925 /* init generic devices */
2926 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
2929 net_check_clients();
2931 /* just use the first displaystate for the moment */
2932 ds
= get_displaystate();
2936 if (display_type
== DT_DEFAULT
&& !display_remote
) {
2937 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
2938 display_type
= DT_SDL
;
2940 vnc_display
= "localhost:0,to=99";
2946 /* init local displays */
2947 switch (display_type
) {
2950 #if defined(CONFIG_CURSES)
2952 curses_display_init(ds
, full_screen
);
2955 #if defined(CONFIG_SDL)
2957 sdl_display_init(ds
, full_screen
, no_frame
);
2959 #elif defined(CONFIG_COCOA)
2961 cocoa_display_init(ds
, full_screen
);
2968 /* init remote displays */
2970 vnc_display_init(ds
);
2971 if (vnc_display_open(ds
, vnc_display
) < 0)
2974 if (show_vnc_port
) {
2975 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
2980 qemu_spice_display_init(ds
);
2986 dcl
= ds
->listeners
;
2987 while (dcl
!= NULL
) {
2988 if (dcl
->dpy_refresh
!= NULL
) {
2989 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
2990 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
2995 if (ds
->gui_timer
== NULL
) {
2996 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
2997 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
2999 text_consoles_set_display(ds
);
3001 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3002 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3007 qdev_machine_creation_done();
3009 if (rom_load_all() != 0) {
3010 fprintf(stderr
, "rom loading failed\n");
3014 qemu_system_reset();
3016 if (load_vmstate(loadvm
) < 0) {
3022 int ret
= qemu_start_incoming_migration(incoming
);
3024 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3028 } else if (autostart
) {