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 /***********************************************************/
293 /* host time/date access */
294 void qemu_get_timedate(struct tm
*tm
, int offset
)
301 if (rtc_date_offset
== -1) {
305 ret
= localtime(&ti
);
307 ti
-= rtc_date_offset
;
311 memcpy(tm
, ret
, sizeof(struct tm
));
314 int qemu_timedate_diff(struct tm
*tm
)
318 if (rtc_date_offset
== -1)
320 seconds
= mktimegm(tm
);
322 seconds
= mktime(tm
);
324 seconds
= mktimegm(tm
) + rtc_date_offset
;
326 return seconds
- time(NULL
);
329 void rtc_change_mon_event(struct tm
*tm
)
333 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
334 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
335 qobject_decref(data
);
338 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
340 time_t rtc_start_date
;
343 if (!strcmp(startdate
, "now") && legacy
) {
344 rtc_date_offset
= -1;
346 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
354 } else if (sscanf(startdate
, "%d-%d-%d",
366 rtc_start_date
= mktimegm(&tm
);
367 if (rtc_start_date
== -1) {
369 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
370 "'2006-06-17T16:01:21' or '2006-06-17'\n");
373 rtc_date_offset
= time(NULL
) - rtc_start_date
;
377 static void configure_rtc(QemuOpts
*opts
)
381 value
= qemu_opt_get(opts
, "base");
383 if (!strcmp(value
, "utc")) {
385 } else if (!strcmp(value
, "localtime")) {
388 configure_rtc_date_offset(value
, 0);
391 value
= qemu_opt_get(opts
, "clock");
393 if (!strcmp(value
, "host")) {
394 rtc_clock
= host_clock
;
395 } else if (!strcmp(value
, "vm")) {
396 rtc_clock
= vm_clock
;
398 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
402 value
= qemu_opt_get(opts
, "driftfix");
404 if (!strcmp(value
, "slew")) {
406 } else if (!strcmp(value
, "none")) {
409 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
415 /***********************************************************/
416 /* Bluetooth support */
419 static struct HCIInfo
*hci_table
[MAX_NICS
];
421 static struct bt_vlan_s
{
422 struct bt_scatternet_s net
;
424 struct bt_vlan_s
*next
;
427 /* find or alloc a new bluetooth "VLAN" */
428 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
430 struct bt_vlan_s
**pvlan
, *vlan
;
431 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
435 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
437 pvlan
= &first_bt_vlan
;
438 while (*pvlan
!= NULL
)
439 pvlan
= &(*pvlan
)->next
;
444 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
448 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
453 static struct HCIInfo null_hci
= {
454 .cmd_send
= null_hci_send
,
455 .sco_send
= null_hci_send
,
456 .acl_send
= null_hci_send
,
457 .bdaddr_set
= null_hci_addr_set
,
460 struct HCIInfo
*qemu_next_hci(void)
462 if (cur_hci
== nb_hcis
)
465 return hci_table
[cur_hci
++];
468 static struct HCIInfo
*hci_init(const char *str
)
471 struct bt_scatternet_s
*vlan
= 0;
473 if (!strcmp(str
, "null"))
476 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
478 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
479 else if (!strncmp(str
, "hci", 3)) {
482 if (!strncmp(str
+ 3, ",vlan=", 6)) {
483 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
488 vlan
= qemu_find_bt_vlan(0);
490 return bt_new_hci(vlan
);
493 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
498 static int bt_hci_parse(const char *str
)
503 if (nb_hcis
>= MAX_NICS
) {
504 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
517 bdaddr
.b
[5] = 0x56 + nb_hcis
;
518 hci
->bdaddr_set(hci
, bdaddr
.b
);
520 hci_table
[nb_hcis
++] = hci
;
525 static void bt_vhci_add(int vlan_id
)
527 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
530 fprintf(stderr
, "qemu: warning: adding a VHCI to "
531 "an empty scatternet %i\n", vlan_id
);
533 bt_vhci_init(bt_new_hci(vlan
));
536 static struct bt_device_s
*bt_device_add(const char *opt
)
538 struct bt_scatternet_s
*vlan
;
540 char *endp
= strstr(opt
, ",vlan=");
541 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
544 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
547 vlan_id
= strtol(endp
+ 6, &endp
, 0);
549 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
554 vlan
= qemu_find_bt_vlan(vlan_id
);
557 fprintf(stderr
, "qemu: warning: adding a slave device to "
558 "an empty scatternet %i\n", vlan_id
);
560 if (!strcmp(devname
, "keyboard"))
561 return bt_keyboard_init(vlan
);
563 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
567 static int bt_parse(const char *opt
)
569 const char *endp
, *p
;
572 if (strstart(opt
, "hci", &endp
)) {
573 if (!*endp
|| *endp
== ',') {
575 if (!strstart(endp
, ",vlan=", 0))
578 return bt_hci_parse(opt
);
580 } else if (strstart(opt
, "vhci", &endp
)) {
581 if (!*endp
|| *endp
== ',') {
583 if (strstart(endp
, ",vlan=", &p
)) {
584 vlan
= strtol(p
, (char **) &endp
, 0);
586 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
590 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
599 } else if (strstart(opt
, "device:", &endp
))
600 return !bt_device_add(endp
);
602 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
606 /***********************************************************/
607 /* QEMU Block devices */
609 #define HD_ALIAS "index=%d,media=disk"
610 #define CDROM_ALIAS "index=2,media=cdrom"
611 #define FD_ALIAS "index=%d,if=floppy"
612 #define PFLASH_ALIAS "if=pflash"
613 #define MTD_ALIAS "if=mtd"
614 #define SD_ALIAS "index=0,if=sd"
616 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
618 int *use_scsi
= opaque
;
621 if (drive_init(opts
, *use_scsi
, &fatal_error
) == NULL
) {
628 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
630 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
631 qemu_opt_set(opts
, "snapshot", "on");
636 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
638 boot_set_handler
= func
;
639 boot_set_opaque
= opaque
;
642 int qemu_boot_set(const char *boot_devices
)
644 if (!boot_set_handler
) {
647 return boot_set_handler(boot_set_opaque
, boot_devices
);
650 static void validate_bootdevices(char *devices
)
652 /* We just do some generic consistency checks */
656 for (p
= devices
; *p
!= '\0'; p
++) {
657 /* Allowed boot devices are:
658 * a-b: floppy disk drives
659 * c-f: IDE disk drives
660 * g-m: machine implementation dependant drives
661 * n-p: network devices
662 * It's up to each machine implementation to check if the given boot
663 * devices match the actual hardware implementation and firmware
666 if (*p
< 'a' || *p
> 'p') {
667 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
670 if (bitmap
& (1 << (*p
- 'a'))) {
671 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
674 bitmap
|= 1 << (*p
- 'a');
678 static void restore_boot_devices(void *opaque
)
680 char *standard_boot_devices
= opaque
;
681 static int first
= 1;
683 /* Restore boot order and remove ourselves after the first boot */
689 qemu_boot_set(standard_boot_devices
);
691 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
692 qemu_free(standard_boot_devices
);
695 static void numa_add(const char *optarg
)
699 unsigned long long value
, endvalue
;
702 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
703 if (!strcmp(option
, "node")) {
704 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
705 nodenr
= nb_numa_nodes
;
707 nodenr
= strtoull(option
, NULL
, 10);
710 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
711 node_mem
[nodenr
] = 0;
714 sval
= strtosz(option
, NULL
);
716 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
719 node_mem
[nodenr
] = sval
;
721 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
722 node_cpumask
[nodenr
] = 0;
724 value
= strtoull(option
, &endptr
, 10);
727 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
729 if (*endptr
== '-') {
730 endvalue
= strtoull(endptr
+1, &endptr
, 10);
731 if (endvalue
>= 63) {
734 "only 63 CPUs in NUMA mode supported.\n");
736 value
= (2ULL << endvalue
) - (1ULL << value
);
738 value
= 1ULL << value
;
741 node_cpumask
[nodenr
] = value
;
748 static void smp_parse(const char *optarg
)
750 int smp
, sockets
= 0, threads
= 0, cores
= 0;
754 smp
= strtoul(optarg
, &endptr
, 10);
755 if (endptr
!= optarg
) {
756 if (*endptr
== ',') {
760 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
761 sockets
= strtoull(option
, NULL
, 10);
762 if (get_param_value(option
, 128, "cores", endptr
) != 0)
763 cores
= strtoull(option
, NULL
, 10);
764 if (get_param_value(option
, 128, "threads", endptr
) != 0)
765 threads
= strtoull(option
, NULL
, 10);
766 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
767 max_cpus
= strtoull(option
, NULL
, 10);
769 /* compute missing values, prefer sockets over cores over threads */
770 if (smp
== 0 || sockets
== 0) {
771 sockets
= sockets
> 0 ? sockets
: 1;
772 cores
= cores
> 0 ? cores
: 1;
773 threads
= threads
> 0 ? threads
: 1;
775 smp
= cores
* threads
* sockets
;
779 threads
= threads
> 0 ? threads
: 1;
780 cores
= smp
/ (sockets
* threads
);
782 threads
= smp
/ (cores
* sockets
);
786 smp_cores
= cores
> 0 ? cores
: 1;
787 smp_threads
= threads
> 0 ? threads
: 1;
792 /***********************************************************/
795 static int usb_device_add(const char *devname
)
798 USBDevice
*dev
= NULL
;
803 /* drivers with .usbdevice_name entry in USBDeviceInfo */
804 dev
= usbdevice_create(devname
);
809 if (strstart(devname
, "host:", &p
)) {
810 dev
= usb_host_device_open(p
);
811 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
812 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
813 bt_new_hci(qemu_find_bt_vlan(0)));
824 static int usb_device_del(const char *devname
)
829 if (strstart(devname
, "host:", &p
))
830 return usb_host_device_close(p
);
835 p
= strchr(devname
, '.');
838 bus_num
= strtoul(devname
, NULL
, 0);
839 addr
= strtoul(p
+ 1, NULL
, 0);
841 return usb_device_delete_addr(bus_num
, addr
);
844 static int usb_parse(const char *cmdline
)
847 r
= usb_device_add(cmdline
);
849 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
854 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
856 const char *devname
= qdict_get_str(qdict
, "devname");
857 if (usb_device_add(devname
) < 0) {
858 error_report("could not add USB device '%s'", devname
);
862 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
864 const char *devname
= qdict_get_str(qdict
, "devname");
865 if (usb_device_del(devname
) < 0) {
866 error_report("could not delete USB device '%s'", devname
);
870 /***********************************************************/
873 static struct pcmcia_socket_entry_s
{
874 PCMCIASocket
*socket
;
875 struct pcmcia_socket_entry_s
*next
;
876 } *pcmcia_sockets
= 0;
878 void pcmcia_socket_register(PCMCIASocket
*socket
)
880 struct pcmcia_socket_entry_s
*entry
;
882 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
883 entry
->socket
= socket
;
884 entry
->next
= pcmcia_sockets
;
885 pcmcia_sockets
= entry
;
888 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
890 struct pcmcia_socket_entry_s
*entry
, **ptr
;
892 ptr
= &pcmcia_sockets
;
893 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
894 if (entry
->socket
== socket
) {
900 void pcmcia_info(Monitor
*mon
)
902 struct pcmcia_socket_entry_s
*iter
;
905 monitor_printf(mon
, "No PCMCIA sockets\n");
907 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
908 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
909 iter
->socket
->attached
? iter
->socket
->card_string
:
913 /***********************************************************/
916 typedef struct IOHandlerRecord
{
918 IOCanReadHandler
*fd_read_poll
;
925 QLIST_ENTRY(IOHandlerRecord
) next
;
928 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
929 QLIST_HEAD_INITIALIZER(io_handlers
);
932 /* XXX: fd_read_poll should be suppressed, but an API change is
933 necessary in the character devices to suppress fd_can_read(). */
934 int qemu_set_fd_handler2(int fd
,
935 IOCanReadHandler
*fd_read_poll
,
940 IOHandlerRecord
*ioh
;
942 if (!fd_read
&& !fd_write
) {
943 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
950 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
954 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
955 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
958 ioh
->fd_read_poll
= fd_read_poll
;
959 ioh
->fd_read
= fd_read
;
960 ioh
->fd_write
= fd_write
;
961 ioh
->opaque
= opaque
;
967 int qemu_set_fd_handler(int fd
,
972 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
975 /***********************************************************/
976 /* machine registration */
978 static QEMUMachine
*first_machine
= NULL
;
979 QEMUMachine
*current_machine
= NULL
;
981 int qemu_register_machine(QEMUMachine
*m
)
992 static QEMUMachine
*find_machine(const char *name
)
996 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
997 if (!strcmp(m
->name
, name
))
999 if (m
->alias
&& !strcmp(m
->alias
, name
))
1005 static QEMUMachine
*find_default_machine(void)
1009 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1010 if (m
->is_default
) {
1017 /***********************************************************/
1018 /* main execution loop */
1020 static void gui_update(void *opaque
)
1022 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1023 DisplayState
*ds
= opaque
;
1024 DisplayChangeListener
*dcl
= ds
->listeners
;
1026 qemu_flush_coalesced_mmio_buffer();
1029 while (dcl
!= NULL
) {
1030 if (dcl
->gui_timer_interval
&&
1031 dcl
->gui_timer_interval
< interval
)
1032 interval
= dcl
->gui_timer_interval
;
1035 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1038 static void nographic_update(void *opaque
)
1040 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1042 qemu_flush_coalesced_mmio_buffer();
1043 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1046 struct vm_change_state_entry
{
1047 VMChangeStateHandler
*cb
;
1049 QLIST_ENTRY (vm_change_state_entry
) entries
;
1052 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1054 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1057 VMChangeStateEntry
*e
;
1059 e
= qemu_mallocz(sizeof (*e
));
1063 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1067 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1069 QLIST_REMOVE (e
, entries
);
1073 void vm_state_notify(int running
, int reason
)
1075 VMChangeStateEntry
*e
;
1077 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1078 e
->cb(e
->opaque
, running
, reason
);
1087 vm_state_notify(1, 0);
1089 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1093 /* reset/shutdown handler */
1095 typedef struct QEMUResetEntry
{
1096 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1097 QEMUResetHandler
*func
;
1101 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1102 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1103 static int reset_requested
;
1104 static int shutdown_requested
;
1105 static int powerdown_requested
;
1106 int debug_requested
;
1107 int vmstop_requested
;
1109 int qemu_shutdown_requested(void)
1111 int r
= shutdown_requested
;
1112 shutdown_requested
= 0;
1116 int qemu_reset_requested(void)
1118 int r
= reset_requested
;
1119 reset_requested
= 0;
1123 int qemu_powerdown_requested(void)
1125 int r
= powerdown_requested
;
1126 powerdown_requested
= 0;
1130 static int qemu_debug_requested(void)
1132 int r
= debug_requested
;
1133 debug_requested
= 0;
1137 static int qemu_vmstop_requested(void)
1139 int r
= vmstop_requested
;
1140 vmstop_requested
= 0;
1144 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1146 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1149 re
->opaque
= opaque
;
1150 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1153 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1157 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1158 if (re
->func
== func
&& re
->opaque
== opaque
) {
1159 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1166 void qemu_system_reset(void)
1168 QEMUResetEntry
*re
, *nre
;
1170 /* reset all devices */
1171 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1172 re
->func(re
->opaque
);
1174 monitor_protocol_event(QEVENT_RESET
, NULL
);
1175 cpu_synchronize_all_post_reset();
1178 void qemu_system_reset_request(void)
1181 shutdown_requested
= 1;
1183 reset_requested
= 1;
1185 qemu_notify_event();
1188 void qemu_system_shutdown_request(void)
1190 shutdown_requested
= 1;
1191 qemu_notify_event();
1194 void qemu_system_powerdown_request(void)
1196 powerdown_requested
= 1;
1197 qemu_notify_event();
1200 void main_loop_wait(int nonblocking
)
1202 IOHandlerRecord
*ioh
;
1203 fd_set rfds
, wfds
, xfds
;
1211 timeout
= qemu_calculate_timeout();
1212 qemu_bh_update_timeout(&timeout
);
1215 os_host_main_loop_wait(&timeout
);
1217 /* poll any events */
1218 /* XXX: separate device handlers from system ones */
1223 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1227 (!ioh
->fd_read_poll
||
1228 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1229 FD_SET(ioh
->fd
, &rfds
);
1233 if (ioh
->fd_write
) {
1234 FD_SET(ioh
->fd
, &wfds
);
1240 tv
.tv_sec
= timeout
/ 1000;
1241 tv
.tv_usec
= (timeout
% 1000) * 1000;
1243 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1245 qemu_mutex_unlock_iothread();
1246 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1247 qemu_mutex_lock_iothread();
1249 IOHandlerRecord
*pioh
;
1251 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1252 if (!ioh
->deleted
&& ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1253 ioh
->fd_read(ioh
->opaque
);
1255 if (!ioh
->deleted
&& ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1256 ioh
->fd_write(ioh
->opaque
);
1259 /* Do this last in case read/write handlers marked it for deletion */
1261 QLIST_REMOVE(ioh
, next
);
1267 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1269 qemu_run_all_timers();
1271 /* Check bottom-halves last in case any of the earlier events triggered
1277 static int vm_can_run(void)
1279 if (powerdown_requested
)
1281 if (reset_requested
)
1283 if (shutdown_requested
)
1285 if (debug_requested
)
1290 qemu_irq qemu_system_powerdown
;
1292 static void main_loop(void)
1296 qemu_main_loop_start();
1300 bool nonblocking
= false;
1301 #ifdef CONFIG_PROFILER
1304 #ifndef CONFIG_IOTHREAD
1305 nonblocking
= cpu_exec_all();
1307 #ifdef CONFIG_PROFILER
1308 ti
= profile_getclock();
1310 main_loop_wait(nonblocking
);
1311 #ifdef CONFIG_PROFILER
1312 dev_time
+= profile_getclock() - ti
;
1314 } while (vm_can_run());
1316 if ((r
= qemu_debug_requested())) {
1319 if (qemu_shutdown_requested()) {
1320 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1327 if (qemu_reset_requested()) {
1329 qemu_system_reset();
1332 if (qemu_powerdown_requested()) {
1333 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1334 qemu_irq_raise(qemu_system_powerdown
);
1336 if ((r
= qemu_vmstop_requested())) {
1344 static void version(void)
1346 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1349 static void help(int exitcode
)
1351 const char *options_help
=
1352 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1354 #define DEFHEADING(text) stringify(text) "\n"
1355 #include "qemu-options.def"
1361 printf("usage: %s [options] [disk_image]\n"
1363 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1366 "During emulation, the following keys are useful:\n"
1367 "ctrl-alt-f toggle full screen\n"
1368 "ctrl-alt-n switch to virtual console 'n'\n"
1369 "ctrl-alt toggle mouse and keyboard grab\n"
1371 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1377 #define HAS_ARG 0x0001
1379 typedef struct QEMUOption
{
1386 static const QEMUOption qemu_options
[] = {
1387 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1388 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1389 { option, opt_arg, opt_enum, arch_mask },
1390 #define DEFHEADING(text)
1391 #include "qemu-options.def"
1397 static void select_vgahw (const char *p
)
1402 vga_interface_type
= VGA_NONE
;
1403 if (strstart(p
, "std", &opts
)) {
1404 vga_interface_type
= VGA_STD
;
1405 } else if (strstart(p
, "cirrus", &opts
)) {
1406 vga_interface_type
= VGA_CIRRUS
;
1407 } else if (strstart(p
, "vmware", &opts
)) {
1408 vga_interface_type
= VGA_VMWARE
;
1409 } else if (strstart(p
, "xenfb", &opts
)) {
1410 vga_interface_type
= VGA_XENFB
;
1411 } else if (!strstart(p
, "none", &opts
)) {
1413 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1417 const char *nextopt
;
1419 if (strstart(opts
, ",retrace=", &nextopt
)) {
1421 if (strstart(opts
, "dumb", &nextopt
))
1422 vga_retrace_method
= VGA_RETRACE_DUMB
;
1423 else if (strstart(opts
, "precise", &nextopt
))
1424 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1425 else goto invalid_vga
;
1426 } else goto invalid_vga
;
1431 static int balloon_parse(const char *arg
)
1435 if (strcmp(arg
, "none") == 0) {
1439 if (!strncmp(arg
, "virtio", 6)) {
1440 if (arg
[6] == ',') {
1441 /* have params -> parse them */
1442 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1446 /* create empty opts */
1447 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1449 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1456 char *qemu_find_file(int type
, const char *name
)
1462 /* If name contains path separators then try it as a straight path. */
1463 if ((strchr(name
, '/') || strchr(name
, '\\'))
1464 && access(name
, R_OK
) == 0) {
1465 return qemu_strdup(name
);
1468 case QEMU_FILE_TYPE_BIOS
:
1471 case QEMU_FILE_TYPE_KEYMAP
:
1472 subdir
= "keymaps/";
1477 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1478 buf
= qemu_mallocz(len
);
1479 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1480 if (access(buf
, R_OK
)) {
1487 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1489 return qdev_device_help(opts
);
1492 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1496 dev
= qdev_device_add(opts
);
1502 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1504 CharDriverState
*chr
;
1506 chr
= qemu_chr_open_opts(opts
, NULL
);
1512 #ifdef CONFIG_VIRTFS
1513 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1516 ret
= qemu_fsdev_add(opts
);
1522 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1524 CharDriverState
*chr
;
1525 const char *chardev
;
1529 mode
= qemu_opt_get(opts
, "mode");
1533 if (strcmp(mode
, "readline") == 0) {
1534 flags
= MONITOR_USE_READLINE
;
1535 } else if (strcmp(mode
, "control") == 0) {
1536 flags
= MONITOR_USE_CONTROL
;
1538 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1542 if (qemu_opt_get_bool(opts
, "pretty", 0))
1543 flags
|= MONITOR_USE_PRETTY
;
1545 if (qemu_opt_get_bool(opts
, "default", 0))
1546 flags
|= MONITOR_IS_DEFAULT
;
1548 chardev
= qemu_opt_get(opts
, "chardev");
1549 chr
= qemu_chr_find(chardev
);
1551 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1555 monitor_init(chr
, flags
);
1559 static void monitor_parse(const char *optarg
, const char *mode
)
1561 static int monitor_device_index
= 0;
1567 if (strstart(optarg
, "chardev:", &p
)) {
1568 snprintf(label
, sizeof(label
), "%s", p
);
1570 snprintf(label
, sizeof(label
), "compat_monitor%d",
1571 monitor_device_index
);
1572 if (monitor_device_index
== 0) {
1575 opts
= qemu_chr_parse_compat(label
, optarg
);
1577 fprintf(stderr
, "parse error: %s\n", optarg
);
1582 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1584 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1587 qemu_opt_set(opts
, "mode", mode
);
1588 qemu_opt_set(opts
, "chardev", label
);
1590 qemu_opt_set(opts
, "default", "on");
1591 monitor_device_index
++;
1594 struct device_config
{
1596 DEV_USB
, /* -usbdevice */
1598 DEV_SERIAL
, /* -serial */
1599 DEV_PARALLEL
, /* -parallel */
1600 DEV_VIRTCON
, /* -virtioconsole */
1601 DEV_DEBUGCON
, /* -debugcon */
1603 const char *cmdline
;
1604 QTAILQ_ENTRY(device_config
) next
;
1606 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1608 static void add_device_config(int type
, const char *cmdline
)
1610 struct device_config
*conf
;
1612 conf
= qemu_mallocz(sizeof(*conf
));
1614 conf
->cmdline
= cmdline
;
1615 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1618 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1620 struct device_config
*conf
;
1623 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1624 if (conf
->type
!= type
)
1626 rc
= func(conf
->cmdline
);
1633 static int serial_parse(const char *devname
)
1635 static int index
= 0;
1638 if (strcmp(devname
, "none") == 0)
1640 if (index
== MAX_SERIAL_PORTS
) {
1641 fprintf(stderr
, "qemu: too many serial ports\n");
1644 snprintf(label
, sizeof(label
), "serial%d", index
);
1645 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1646 if (!serial_hds
[index
]) {
1647 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1648 devname
, strerror(errno
));
1655 static int parallel_parse(const char *devname
)
1657 static int index
= 0;
1660 if (strcmp(devname
, "none") == 0)
1662 if (index
== MAX_PARALLEL_PORTS
) {
1663 fprintf(stderr
, "qemu: too many parallel ports\n");
1666 snprintf(label
, sizeof(label
), "parallel%d", index
);
1667 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1668 if (!parallel_hds
[index
]) {
1669 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1670 devname
, strerror(errno
));
1677 static int virtcon_parse(const char *devname
)
1679 QemuOptsList
*device
= qemu_find_opts("device");
1680 static int index
= 0;
1682 QemuOpts
*bus_opts
, *dev_opts
;
1684 if (strcmp(devname
, "none") == 0)
1686 if (index
== MAX_VIRTIO_CONSOLES
) {
1687 fprintf(stderr
, "qemu: too many virtio consoles\n");
1691 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1692 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1694 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1695 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1697 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1698 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1699 if (!virtcon_hds
[index
]) {
1700 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1701 devname
, strerror(errno
));
1704 qemu_opt_set(dev_opts
, "chardev", label
);
1710 static int debugcon_parse(const char *devname
)
1714 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1717 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1719 fprintf(stderr
, "qemu: already have a debugcon device\n");
1722 qemu_opt_set(opts
, "driver", "isa-debugcon");
1723 qemu_opt_set(opts
, "chardev", "debugcon");
1727 void qemu_add_exit_notifier(Notifier
*notify
)
1729 notifier_list_add(&exit_notifiers
, notify
);
1732 void qemu_remove_exit_notifier(Notifier
*notify
)
1734 notifier_list_remove(&exit_notifiers
, notify
);
1737 static void qemu_run_exit_notifiers(void)
1739 notifier_list_notify(&exit_notifiers
);
1742 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1743 const char **poptarg
, int *poptind
)
1745 const QEMUOption
*popt
;
1746 int optind
= *poptind
;
1747 char *r
= argv
[optind
];
1750 loc_set_cmdline(argv
, optind
, 1);
1752 /* Treat --foo the same as -foo. */
1755 popt
= qemu_options
;
1758 error_report("invalid option");
1761 if (!strcmp(popt
->name
, r
+ 1))
1765 if (popt
->flags
& HAS_ARG
) {
1766 if (optind
>= argc
) {
1767 error_report("requires an argument");
1770 optarg
= argv
[optind
++];
1771 loc_set_cmdline(argv
, optind
- 2, 2);
1782 int main(int argc
, char **argv
, char **envp
)
1784 const char *gdbstub_dev
= NULL
;
1786 int snapshot
, linux_boot
;
1787 const char *icount_option
= NULL
;
1788 const char *initrd_filename
;
1789 const char *kernel_filename
, *kernel_cmdline
;
1790 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1792 DisplayChangeListener
*dcl
;
1793 int cyls
, heads
, secs
, translation
;
1794 QemuOpts
*hda_opts
= NULL
, *opts
;
1795 QemuOptsList
*olist
;
1798 const char *loadvm
= NULL
;
1799 QEMUMachine
*machine
;
1800 const char *cpu_model
;
1802 const char *pid_file
= NULL
;
1803 const char *incoming
= NULL
;
1804 int show_vnc_port
= 0;
1807 #ifdef CONFIG_SIMPLE_TRACE
1808 const char *trace_file
= NULL
;
1810 atexit(qemu_run_exit_notifiers
);
1811 error_set_progname(argv
[0]);
1815 qemu_cache_utils_init(envp
);
1817 QLIST_INIT (&vm_change_state_head
);
1818 os_setup_early_signal_handling();
1820 module_call_init(MODULE_INIT_MACHINE
);
1821 machine
= find_default_machine();
1823 initrd_filename
= NULL
;
1826 kernel_filename
= NULL
;
1827 kernel_cmdline
= "";
1828 cyls
= heads
= secs
= 0;
1829 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1831 for (i
= 0; i
< MAX_NODES
; i
++) {
1833 node_cpumask
[i
] = 0;
1842 /* first pass of option parsing */
1844 while (optind
< argc
) {
1845 if (argv
[optind
][0] != '-') {
1850 const QEMUOption
*popt
;
1852 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1853 switch (popt
->index
) {
1854 case QEMU_OPTION_nodefconfig
:
1864 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1865 if (ret
< 0 && ret
!= -ENOENT
) {
1869 ret
= qemu_read_config_file(arch_config_name
);
1870 if (ret
< 0 && ret
!= -ENOENT
) {
1876 /* second pass of option parsing */
1881 if (argv
[optind
][0] != '-') {
1882 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1884 const QEMUOption
*popt
;
1886 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1887 if (!(popt
->arch_mask
& arch_type
)) {
1888 printf("Option %s not supported for this target\n", popt
->name
);
1891 switch(popt
->index
) {
1893 machine
= find_machine(optarg
);
1896 printf("Supported machines are:\n");
1897 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1899 printf("%-10s %s (alias of %s)\n",
1900 m
->alias
, m
->desc
, m
->name
);
1901 printf("%-10s %s%s\n",
1903 m
->is_default
? " (default)" : "");
1905 exit(*optarg
!= '?');
1908 case QEMU_OPTION_cpu
:
1909 /* hw initialization will check this */
1910 if (*optarg
== '?') {
1911 list_cpus(stdout
, &fprintf
, optarg
);
1917 case QEMU_OPTION_initrd
:
1918 initrd_filename
= optarg
;
1920 case QEMU_OPTION_hda
:
1922 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
1924 hda_opts
= drive_add(optarg
, HD_ALIAS
1925 ",cyls=%d,heads=%d,secs=%d%s",
1926 0, cyls
, heads
, secs
,
1927 translation
== BIOS_ATA_TRANSLATION_LBA
?
1929 translation
== BIOS_ATA_TRANSLATION_NONE
?
1930 ",trans=none" : "");
1932 case QEMU_OPTION_hdb
:
1933 case QEMU_OPTION_hdc
:
1934 case QEMU_OPTION_hdd
:
1935 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
1937 case QEMU_OPTION_drive
:
1938 drive_add(NULL
, "%s", optarg
);
1940 case QEMU_OPTION_set
:
1941 if (qemu_set_option(optarg
) != 0)
1944 case QEMU_OPTION_global
:
1945 if (qemu_global_option(optarg
) != 0)
1948 case QEMU_OPTION_mtdblock
:
1949 drive_add(optarg
, MTD_ALIAS
);
1951 case QEMU_OPTION_sd
:
1952 drive_add(optarg
, SD_ALIAS
);
1954 case QEMU_OPTION_pflash
:
1955 drive_add(optarg
, PFLASH_ALIAS
);
1957 case QEMU_OPTION_snapshot
:
1960 case QEMU_OPTION_hdachs
:
1964 cyls
= strtol(p
, (char **)&p
, 0);
1965 if (cyls
< 1 || cyls
> 16383)
1970 heads
= strtol(p
, (char **)&p
, 0);
1971 if (heads
< 1 || heads
> 16)
1976 secs
= strtol(p
, (char **)&p
, 0);
1977 if (secs
< 1 || secs
> 63)
1981 if (!strcmp(p
, "none"))
1982 translation
= BIOS_ATA_TRANSLATION_NONE
;
1983 else if (!strcmp(p
, "lba"))
1984 translation
= BIOS_ATA_TRANSLATION_LBA
;
1985 else if (!strcmp(p
, "auto"))
1986 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1989 } else if (*p
!= '\0') {
1991 fprintf(stderr
, "qemu: invalid physical CHS format\n");
1994 if (hda_opts
!= NULL
) {
1996 snprintf(num
, sizeof(num
), "%d", cyls
);
1997 qemu_opt_set(hda_opts
, "cyls", num
);
1998 snprintf(num
, sizeof(num
), "%d", heads
);
1999 qemu_opt_set(hda_opts
, "heads", num
);
2000 snprintf(num
, sizeof(num
), "%d", secs
);
2001 qemu_opt_set(hda_opts
, "secs", num
);
2002 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2003 qemu_opt_set(hda_opts
, "trans", "lba");
2004 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2005 qemu_opt_set(hda_opts
, "trans", "none");
2009 case QEMU_OPTION_numa
:
2010 if (nb_numa_nodes
>= MAX_NODES
) {
2011 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2016 case QEMU_OPTION_nographic
:
2017 display_type
= DT_NOGRAPHIC
;
2019 #ifdef CONFIG_CURSES
2020 case QEMU_OPTION_curses
:
2021 display_type
= DT_CURSES
;
2024 case QEMU_OPTION_portrait
:
2027 case QEMU_OPTION_kernel
:
2028 kernel_filename
= optarg
;
2030 case QEMU_OPTION_append
:
2031 kernel_cmdline
= optarg
;
2033 case QEMU_OPTION_cdrom
:
2034 drive_add(optarg
, CDROM_ALIAS
);
2036 case QEMU_OPTION_boot
:
2038 static const char * const params
[] = {
2039 "order", "once", "menu", NULL
2041 char buf
[sizeof(boot_devices
)];
2042 char *standard_boot_devices
;
2045 if (!strchr(optarg
, '=')) {
2047 pstrcpy(buf
, sizeof(buf
), optarg
);
2048 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2050 "qemu: unknown boot parameter '%s' in '%s'\n",
2056 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2057 validate_bootdevices(buf
);
2058 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2061 if (get_param_value(buf
, sizeof(buf
),
2063 validate_bootdevices(buf
);
2064 standard_boot_devices
= qemu_strdup(boot_devices
);
2065 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2066 qemu_register_reset(restore_boot_devices
,
2067 standard_boot_devices
);
2069 if (get_param_value(buf
, sizeof(buf
),
2071 if (!strcmp(buf
, "on")) {
2073 } else if (!strcmp(buf
, "off")) {
2077 "qemu: invalid option value '%s'\n",
2085 case QEMU_OPTION_fda
:
2086 case QEMU_OPTION_fdb
:
2087 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2089 case QEMU_OPTION_no_fd_bootchk
:
2092 case QEMU_OPTION_netdev
:
2093 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2097 case QEMU_OPTION_net
:
2098 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2103 case QEMU_OPTION_tftp
:
2104 legacy_tftp_prefix
= optarg
;
2106 case QEMU_OPTION_bootp
:
2107 legacy_bootp_filename
= optarg
;
2109 case QEMU_OPTION_redir
:
2110 if (net_slirp_redir(optarg
) < 0)
2114 case QEMU_OPTION_bt
:
2115 add_device_config(DEV_BT
, optarg
);
2117 case QEMU_OPTION_audio_help
:
2118 if (!(audio_available())) {
2119 printf("Option %s not supported for this target\n", popt
->name
);
2125 case QEMU_OPTION_soundhw
:
2126 if (!(audio_available())) {
2127 printf("Option %s not supported for this target\n", popt
->name
);
2130 select_soundhw (optarg
);
2135 case QEMU_OPTION_version
:
2139 case QEMU_OPTION_m
: {
2142 value
= strtosz(optarg
, NULL
);
2144 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2148 /* On 32-bit hosts, QEMU is limited by virtual address space */
2149 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2150 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2153 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2154 fprintf(stderr
, "qemu: ram size too large\n");
2160 case QEMU_OPTION_mempath
:
2164 case QEMU_OPTION_mem_prealloc
:
2169 set_cpu_log(optarg
);
2172 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2174 case QEMU_OPTION_gdb
:
2175 gdbstub_dev
= optarg
;
2180 case QEMU_OPTION_bios
:
2183 case QEMU_OPTION_singlestep
:
2190 keyboard_layout
= optarg
;
2192 case QEMU_OPTION_localtime
:
2195 case QEMU_OPTION_vga
:
2196 select_vgahw (optarg
);
2203 w
= strtol(p
, (char **)&p
, 10);
2206 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2212 h
= strtol(p
, (char **)&p
, 10);
2217 depth
= strtol(p
, (char **)&p
, 10);
2218 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2219 depth
!= 24 && depth
!= 32)
2221 } else if (*p
== '\0') {
2222 depth
= graphic_depth
;
2229 graphic_depth
= depth
;
2232 case QEMU_OPTION_echr
:
2235 term_escape_char
= strtol(optarg
, &r
, 0);
2237 printf("Bad argument to echr\n");
2240 case QEMU_OPTION_monitor
:
2241 monitor_parse(optarg
, "readline");
2242 default_monitor
= 0;
2244 case QEMU_OPTION_qmp
:
2245 monitor_parse(optarg
, "control");
2246 default_monitor
= 0;
2248 case QEMU_OPTION_mon
:
2249 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2253 default_monitor
= 0;
2255 case QEMU_OPTION_chardev
:
2256 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2261 case QEMU_OPTION_fsdev
:
2262 olist
= qemu_find_opts("fsdev");
2264 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2267 opts
= qemu_opts_parse(olist
, optarg
, 1);
2269 fprintf(stderr
, "parse error: %s\n", optarg
);
2273 case QEMU_OPTION_virtfs
: {
2274 char *arg_fsdev
= NULL
;
2275 char *arg_9p
= NULL
;
2278 olist
= qemu_find_opts("virtfs");
2280 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2283 opts
= qemu_opts_parse(olist
, optarg
, 1);
2285 fprintf(stderr
, "parse error: %s\n", optarg
);
2289 if (qemu_opt_get(opts
, "fstype") == NULL
||
2290 qemu_opt_get(opts
, "mount_tag") == NULL
||
2291 qemu_opt_get(opts
, "path") == NULL
||
2292 qemu_opt_get(opts
, "security_model") == NULL
) {
2293 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2294 "security_model=[mapped|passthrough|none],"
2299 len
= strlen(",id=,path=,security_model=");
2300 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2301 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2302 len
+= strlen(qemu_opt_get(opts
, "path"));
2303 len
+= strlen(qemu_opt_get(opts
, "security_model"));
2304 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2306 snprintf(arg_fsdev
, (len
+ 1) * sizeof(*arg_fsdev
),
2307 "%s,id=%s,path=%s,security_model=%s",
2308 qemu_opt_get(opts
, "fstype"),
2309 qemu_opt_get(opts
, "mount_tag"),
2310 qemu_opt_get(opts
, "path"),
2311 qemu_opt_get(opts
, "security_model"));
2313 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2314 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2315 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2317 snprintf(arg_9p
, (len
+ 1) * sizeof(*arg_9p
),
2318 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2319 qemu_opt_get(opts
, "mount_tag"),
2320 qemu_opt_get(opts
, "mount_tag"));
2322 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev
, 1)) {
2323 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2327 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p
, 1)) {
2328 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2332 qemu_free(arg_fsdev
);
2336 case QEMU_OPTION_serial
:
2337 add_device_config(DEV_SERIAL
, optarg
);
2339 if (strncmp(optarg
, "mon:", 4) == 0) {
2340 default_monitor
= 0;
2343 case QEMU_OPTION_watchdog
:
2346 "qemu: only one watchdog option may be given\n");
2351 case QEMU_OPTION_watchdog_action
:
2352 if (select_watchdog_action(optarg
) == -1) {
2353 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2357 case QEMU_OPTION_virtiocon
:
2358 add_device_config(DEV_VIRTCON
, optarg
);
2359 default_virtcon
= 0;
2360 if (strncmp(optarg
, "mon:", 4) == 0) {
2361 default_monitor
= 0;
2364 case QEMU_OPTION_parallel
:
2365 add_device_config(DEV_PARALLEL
, optarg
);
2366 default_parallel
= 0;
2367 if (strncmp(optarg
, "mon:", 4) == 0) {
2368 default_monitor
= 0;
2371 case QEMU_OPTION_debugcon
:
2372 add_device_config(DEV_DEBUGCON
, optarg
);
2374 case QEMU_OPTION_loadvm
:
2377 case QEMU_OPTION_full_screen
:
2381 case QEMU_OPTION_no_frame
:
2384 case QEMU_OPTION_alt_grab
:
2387 case QEMU_OPTION_ctrl_grab
:
2390 case QEMU_OPTION_no_quit
:
2393 case QEMU_OPTION_sdl
:
2394 display_type
= DT_SDL
;
2397 case QEMU_OPTION_pidfile
:
2400 case QEMU_OPTION_win2k_hack
:
2401 win2k_install_hack
= 1;
2403 case QEMU_OPTION_rtc_td_hack
:
2406 case QEMU_OPTION_acpitable
:
2407 do_acpitable_option(optarg
);
2409 case QEMU_OPTION_smbios
:
2410 do_smbios_option(optarg
);
2412 case QEMU_OPTION_enable_kvm
:
2415 case QEMU_OPTION_usb
:
2418 case QEMU_OPTION_usbdevice
:
2420 add_device_config(DEV_USB
, optarg
);
2422 case QEMU_OPTION_device
:
2423 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2427 case QEMU_OPTION_smp
:
2430 fprintf(stderr
, "Invalid number of CPUs\n");
2433 if (max_cpus
< smp_cpus
) {
2434 fprintf(stderr
, "maxcpus must be equal to or greater than "
2438 if (max_cpus
> 255) {
2439 fprintf(stderr
, "Unsupported number of maxcpus\n");
2443 case QEMU_OPTION_vnc
:
2445 vnc_display
= optarg
;
2447 case QEMU_OPTION_no_acpi
:
2450 case QEMU_OPTION_no_hpet
:
2453 case QEMU_OPTION_balloon
:
2454 if (balloon_parse(optarg
) < 0) {
2455 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2459 case QEMU_OPTION_no_reboot
:
2462 case QEMU_OPTION_no_shutdown
:
2465 case QEMU_OPTION_show_cursor
:
2468 case QEMU_OPTION_uuid
:
2469 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2470 fprintf(stderr
, "Fail to parse UUID string."
2471 " Wrong format.\n");
2475 case QEMU_OPTION_option_rom
:
2476 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2477 fprintf(stderr
, "Too many option ROMs\n");
2480 option_rom
[nb_option_roms
] = optarg
;
2483 case QEMU_OPTION_semihosting
:
2484 semihosting_enabled
= 1;
2486 case QEMU_OPTION_name
:
2487 qemu_name
= qemu_strdup(optarg
);
2489 char *p
= strchr(qemu_name
, ',');
2492 if (strncmp(p
, "process=", 8)) {
2493 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2497 os_set_proc_name(p
);
2501 case QEMU_OPTION_prom_env
:
2502 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2503 fprintf(stderr
, "Too many prom variables\n");
2506 prom_envs
[nb_prom_envs
] = optarg
;
2509 case QEMU_OPTION_old_param
:
2512 case QEMU_OPTION_clock
:
2513 configure_alarms(optarg
);
2515 case QEMU_OPTION_startdate
:
2516 configure_rtc_date_offset(optarg
, 1);
2518 case QEMU_OPTION_rtc
:
2519 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2523 configure_rtc(opts
);
2525 case QEMU_OPTION_tb_size
:
2526 tb_size
= strtol(optarg
, NULL
, 0);
2530 case QEMU_OPTION_icount
:
2531 icount_option
= optarg
;
2533 case QEMU_OPTION_incoming
:
2535 incoming_expected
= true;
2537 case QEMU_OPTION_nodefaults
:
2539 default_parallel
= 0;
2540 default_virtcon
= 0;
2541 default_monitor
= 0;
2548 case QEMU_OPTION_xen_domid
:
2549 if (!(xen_available())) {
2550 printf("Option %s not supported for this target\n", popt
->name
);
2553 xen_domid
= atoi(optarg
);
2555 case QEMU_OPTION_xen_create
:
2556 if (!(xen_available())) {
2557 printf("Option %s not supported for this target\n", popt
->name
);
2560 xen_mode
= XEN_CREATE
;
2562 case QEMU_OPTION_xen_attach
:
2563 if (!(xen_available())) {
2564 printf("Option %s not supported for this target\n", popt
->name
);
2567 xen_mode
= XEN_ATTACH
;
2569 #ifdef CONFIG_SIMPLE_TRACE
2570 case QEMU_OPTION_trace
:
2571 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2573 trace_file
= qemu_opt_get(opts
, "file");
2577 case QEMU_OPTION_readconfig
:
2579 int ret
= qemu_read_config_file(optarg
);
2581 fprintf(stderr
, "read config %s: %s\n", optarg
,
2587 case QEMU_OPTION_spice
:
2588 olist
= qemu_find_opts("spice");
2590 fprintf(stderr
, "spice is not supported by this qemu build.\n");
2593 opts
= qemu_opts_parse(olist
, optarg
, 0);
2595 fprintf(stderr
, "parse error: %s\n", optarg
);
2599 case QEMU_OPTION_writeconfig
:
2602 if (strcmp(optarg
, "-") == 0) {
2605 fp
= fopen(optarg
, "w");
2607 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2611 qemu_config_write(fp
);
2616 os_parse_cmd_args(popt
->index
, optarg
);
2622 /* If no data_dir is specified then try to find it relative to the
2625 data_dir
= os_find_datadir(argv
[0]);
2627 /* If all else fails use the install patch specified when building. */
2629 data_dir
= CONFIG_QEMU_DATADIR
;
2632 #ifdef CONFIG_SIMPLE_TRACE
2634 * Set the trace file name, if specified.
2636 st_set_trace_file(trace_file
);
2639 * Default to max_cpus = smp_cpus, in case the user doesn't
2640 * specify a max_cpus value.
2643 max_cpus
= smp_cpus
;
2645 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2646 if (smp_cpus
> machine
->max_cpus
) {
2647 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2648 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2653 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2654 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2656 if (machine
->no_serial
) {
2659 if (machine
->no_parallel
) {
2660 default_parallel
= 0;
2662 if (!machine
->use_virtcon
) {
2663 default_virtcon
= 0;
2665 if (machine
->no_vga
) {
2668 if (machine
->no_floppy
) {
2671 if (machine
->no_cdrom
) {
2674 if (machine
->no_sdcard
) {
2678 if (display_type
== DT_NOGRAPHIC
) {
2679 if (default_parallel
)
2680 add_device_config(DEV_PARALLEL
, "null");
2681 if (default_serial
&& default_monitor
) {
2682 add_device_config(DEV_SERIAL
, "mon:stdio");
2683 } else if (default_virtcon
&& default_monitor
) {
2684 add_device_config(DEV_VIRTCON
, "mon:stdio");
2687 add_device_config(DEV_SERIAL
, "stdio");
2688 if (default_virtcon
)
2689 add_device_config(DEV_VIRTCON
, "stdio");
2690 if (default_monitor
)
2691 monitor_parse("stdio", "readline");
2695 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2696 if (default_parallel
)
2697 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2698 if (default_monitor
)
2699 monitor_parse("vc:80Cx24C", "readline");
2700 if (default_virtcon
)
2701 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2704 vga_interface_type
= VGA_CIRRUS
;
2708 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
2710 #ifdef CONFIG_VIRTFS
2711 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
2718 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2724 int ret
= kvm_init(smp_cpus
);
2726 if (!kvm_available()) {
2727 printf("KVM not supported for this target\n");
2729 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2735 if (qemu_init_main_loop()) {
2736 fprintf(stderr
, "qemu_init_main_loop failed\n");
2739 linux_boot
= (kernel_filename
!= NULL
);
2741 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2742 fprintf(stderr
, "-append only allowed with -kernel option\n");
2746 if (!linux_boot
&& initrd_filename
!= NULL
) {
2747 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2751 os_set_line_buffering();
2753 if (init_timer_alarm() < 0) {
2754 fprintf(stderr
, "could not initialize alarm timer\n");
2757 configure_icount(icount_option
);
2759 if (net_init_clients() < 0) {
2763 /* init the bluetooth world */
2764 if (foreach_device_config(DEV_BT
, bt_parse
))
2767 /* init the memory */
2769 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2771 /* init the dynamic translator */
2772 cpu_exec_init_all(tb_size
* 1024 * 1024);
2774 bdrv_init_with_whitelist();
2778 if (default_cdrom
) {
2779 /* we always create the cdrom drive, even if no disk is there */
2780 drive_add(NULL
, CDROM_ALIAS
);
2783 if (default_floppy
) {
2784 /* we always create at least one floppy */
2785 drive_add(NULL
, FD_ALIAS
, 0);
2788 if (default_sdcard
) {
2789 /* we always create one sd slot, even if no card is in it */
2790 drive_add(NULL
, SD_ALIAS
);
2793 /* open the virtual block devices */
2795 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
2796 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
2799 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2802 if (nb_numa_nodes
> 0) {
2805 if (nb_numa_nodes
> smp_cpus
) {
2806 nb_numa_nodes
= smp_cpus
;
2809 /* If no memory size if given for any node, assume the default case
2810 * and distribute the available memory equally across all nodes
2812 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2813 if (node_mem
[i
] != 0)
2816 if (i
== nb_numa_nodes
) {
2817 uint64_t usedmem
= 0;
2819 /* On Linux, the each node's border has to be 8MB aligned,
2820 * the final node gets the rest.
2822 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2823 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2824 usedmem
+= node_mem
[i
];
2826 node_mem
[i
] = ram_size
- usedmem
;
2829 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2830 if (node_cpumask
[i
] != 0)
2833 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2834 * must cope with this anyway, because there are BIOSes out there in
2835 * real machines which also use this scheme.
2837 if (i
== nb_numa_nodes
) {
2838 for (i
= 0; i
< smp_cpus
; i
++) {
2839 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2844 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
2848 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2850 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2852 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2854 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2857 module_call_init(MODULE_INIT_DEVICE
);
2859 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
2863 i
= select_watchdog(watchdog
);
2865 exit (i
== 1 ? 1 : 0);
2868 if (machine
->compat_props
) {
2869 qdev_prop_register_global_list(machine
->compat_props
);
2873 machine
->init(ram_size
, boot_devices
,
2874 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2876 cpu_synchronize_all_post_init();
2878 /* must be after terminal init, SDL library changes signal handlers */
2879 os_setup_signal_handling();
2883 current_machine
= machine
;
2885 /* init USB devices */
2887 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2891 /* init generic devices */
2892 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
2895 net_check_clients();
2897 /* just use the first displaystate for the moment */
2898 ds
= get_displaystate();
2902 if (display_type
== DT_DEFAULT
&& !display_remote
) {
2903 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
2904 display_type
= DT_SDL
;
2906 vnc_display
= "localhost:0,to=99";
2912 /* init local displays */
2913 switch (display_type
) {
2916 #if defined(CONFIG_CURSES)
2918 curses_display_init(ds
, full_screen
);
2921 #if defined(CONFIG_SDL)
2923 sdl_display_init(ds
, full_screen
, no_frame
);
2925 #elif defined(CONFIG_COCOA)
2927 cocoa_display_init(ds
, full_screen
);
2934 /* init remote displays */
2936 vnc_display_init(ds
);
2937 if (vnc_display_open(ds
, vnc_display
) < 0)
2940 if (show_vnc_port
) {
2941 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
2946 qemu_spice_display_init(ds
);
2952 dcl
= ds
->listeners
;
2953 while (dcl
!= NULL
) {
2954 if (dcl
->dpy_refresh
!= NULL
) {
2955 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
2956 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
2961 if (ds
->gui_timer
== NULL
) {
2962 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
2963 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
2965 text_consoles_set_display(ds
);
2967 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
2968 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
2973 qdev_machine_creation_done();
2975 if (rom_load_all() != 0) {
2976 fprintf(stderr
, "rom loading failed\n");
2980 qemu_system_reset();
2982 if (load_vmstate(loadvm
) < 0) {
2988 int ret
= qemu_start_incoming_migration(incoming
);
2990 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
2994 } else if (autostart
) {