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>
52 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
54 #include <sys/sysctl.h>
63 #include <linux/ppdev.h>
64 #include <linux/parport.h>
68 #include <sys/ethernet.h>
69 #include <sys/sockio.h>
70 #include <netinet/arp.h>
71 #include <netinet/in_systm.h>
72 #include <netinet/ip.h>
73 #include <netinet/ip_icmp.h> // must come after ip.h
74 #include <netinet/udp.h>
75 #include <netinet/tcp.h>
79 /* See MySQL bug #7156 (http://bugs.mysql.com/bug.php?id=7156) for
80 discussion about Solaris header problems */
81 extern int madvise(caddr_t
, size_t, int);
86 #if defined(__OpenBSD__)
90 #if defined(CONFIG_VDE)
91 #include <libvdeplug.h>
99 #if defined(__APPLE__) || defined(main)
101 int qemu_main(int argc
, char **argv
, char **envp
);
102 int main(int argc
, char **argv
)
104 return qemu_main(argc
, argv
, NULL
);
107 #define main qemu_main
109 #endif /* CONFIG_SDL */
113 #define main qemu_main
114 #endif /* CONFIG_COCOA */
117 #include "hw/boards.h"
119 #include "hw/pcmcia.h"
124 #include "hw/watchdog.h"
125 #include "hw/smbios.h"
128 #include "hw/loader.h"
131 #include "net/slirp.h"
136 #include "qemu-timer.h"
137 #include "qemu-char.h"
138 #include "cache-utils.h"
140 #include "blockdev.h"
141 #include "block-migration.h"
143 #include "audio/audio.h"
144 #include "migration.h"
146 #include "qemu-option.h"
147 #include "qemu-config.h"
148 #include "qemu-objects.h"
149 #include "qemu-options.h"
150 #include "hw/device-assignment.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"
166 //#define DEBUG_SLIRP
168 #define DEFAULT_RAM_SIZE 128
170 #define MAX_VIRTIO_CONSOLES 1
172 static const char *data_dir
;
173 const char *bios_name
= NULL
;
174 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
175 DisplayType display_type
= DT_DEFAULT
;
176 const char* keyboard_layout
= NULL
;
178 const char *mem_path
= NULL
;
180 int mem_prealloc
= 0; /* force preallocation of physical target memory */
183 NICInfo nd_table
[MAX_NICS
];
186 static int rtc_utc
= 1;
187 static int rtc_date_offset
= -1; /* -1 means no change */
188 QEMUClock
*rtc_clock
;
189 int vga_interface_type
= VGA_NONE
;
190 static int full_screen
= 0;
192 static int no_frame
= 0;
195 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
196 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
197 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
198 int win2k_install_hack
= 0;
202 const char *assigned_devices
[MAX_DEV_ASSIGN_CMDLINE
];
203 int assigned_devices_index
;
208 const char *vnc_display
;
209 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;
223 int time_drift_fix
= 0;
224 unsigned int kvm_shadow_memory
= 0;
226 const char *qemu_name
;
229 unsigned int nb_prom_envs
= 0;
230 const char *prom_envs
[MAX_PROM_ENVS
];
231 const char *nvram
= NULL
;
235 uint64_t node_mem
[MAX_NODES
];
236 uint64_t node_cpumask
[MAX_NODES
];
238 static QEMUTimer
*nographic_timer
;
240 uint8_t qemu_uuid
[16];
242 static QEMUBootSetHandler
*boot_set_handler
;
243 static void *boot_set_opaque
;
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
);
810 threads
= smp
/ (cores
* sockets
);
815 smp_cores
= cores
> 0 ? cores
: 1;
816 smp_threads
= threads
> 0 ? threads
: 1;
821 /***********************************************************/
824 static int usb_device_add(const char *devname
)
827 USBDevice
*dev
= NULL
;
832 /* drivers with .usbdevice_name entry in USBDeviceInfo */
833 dev
= usbdevice_create(devname
);
838 if (strstart(devname
, "host:", &p
)) {
839 dev
= usb_host_device_open(p
);
840 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
841 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
842 bt_new_hci(qemu_find_bt_vlan(0)));
853 static int usb_device_del(const char *devname
)
858 if (strstart(devname
, "host:", &p
))
859 return usb_host_device_close(p
);
864 p
= strchr(devname
, '.');
867 bus_num
= strtoul(devname
, NULL
, 0);
868 addr
= strtoul(p
+ 1, NULL
, 0);
870 return usb_device_delete_addr(bus_num
, addr
);
873 static int usb_parse(const char *cmdline
)
876 r
= usb_device_add(cmdline
);
878 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
883 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
885 const char *devname
= qdict_get_str(qdict
, "devname");
886 if (usb_device_add(devname
) < 0) {
887 error_report("could not add USB device '%s'", devname
);
891 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
893 const char *devname
= qdict_get_str(qdict
, "devname");
894 if (usb_device_del(devname
) < 0) {
895 error_report("could not delete USB device '%s'", devname
);
899 /***********************************************************/
902 static struct pcmcia_socket_entry_s
{
903 PCMCIASocket
*socket
;
904 struct pcmcia_socket_entry_s
*next
;
905 } *pcmcia_sockets
= 0;
907 void pcmcia_socket_register(PCMCIASocket
*socket
)
909 struct pcmcia_socket_entry_s
*entry
;
911 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
912 entry
->socket
= socket
;
913 entry
->next
= pcmcia_sockets
;
914 pcmcia_sockets
= entry
;
917 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
919 struct pcmcia_socket_entry_s
*entry
, **ptr
;
921 ptr
= &pcmcia_sockets
;
922 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
923 if (entry
->socket
== socket
) {
929 void pcmcia_info(Monitor
*mon
)
931 struct pcmcia_socket_entry_s
*iter
;
934 monitor_printf(mon
, "No PCMCIA sockets\n");
936 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
937 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
938 iter
->socket
->attached
? iter
->socket
->card_string
:
942 /***********************************************************/
945 typedef struct IOHandlerRecord
{
947 IOCanReadHandler
*fd_read_poll
;
954 QLIST_ENTRY(IOHandlerRecord
) next
;
957 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
958 QLIST_HEAD_INITIALIZER(io_handlers
);
961 /* XXX: fd_read_poll should be suppressed, but an API change is
962 necessary in the character devices to suppress fd_can_read(). */
963 int qemu_set_fd_handler2(int fd
,
964 IOCanReadHandler
*fd_read_poll
,
969 IOHandlerRecord
*ioh
;
971 if (!fd_read
&& !fd_write
) {
972 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
979 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
983 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
984 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
987 ioh
->fd_read_poll
= fd_read_poll
;
988 ioh
->fd_read
= fd_read
;
989 ioh
->fd_write
= fd_write
;
990 ioh
->opaque
= opaque
;
997 int qemu_set_fd_handler(int fd
,
1002 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
1005 /***********************************************************/
1006 /* machine registration */
1008 static QEMUMachine
*first_machine
= NULL
;
1009 QEMUMachine
*current_machine
= NULL
;
1011 int qemu_register_machine(QEMUMachine
*m
)
1014 pm
= &first_machine
;
1022 static QEMUMachine
*find_machine(const char *name
)
1026 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1027 if (!strcmp(m
->name
, name
))
1029 if (m
->alias
&& !strcmp(m
->alias
, name
))
1035 static QEMUMachine
*find_default_machine(void)
1039 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1040 if (m
->is_default
) {
1047 /***********************************************************/
1048 /* main execution loop */
1050 static void gui_update(void *opaque
)
1052 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1053 DisplayState
*ds
= opaque
;
1054 DisplayChangeListener
*dcl
= ds
->listeners
;
1056 qemu_flush_coalesced_mmio_buffer();
1059 while (dcl
!= NULL
) {
1060 if (dcl
->gui_timer_interval
&&
1061 dcl
->gui_timer_interval
< interval
)
1062 interval
= dcl
->gui_timer_interval
;
1065 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1068 static void nographic_update(void *opaque
)
1070 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1072 qemu_flush_coalesced_mmio_buffer();
1073 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1076 struct vm_change_state_entry
{
1077 VMChangeStateHandler
*cb
;
1079 QLIST_ENTRY (vm_change_state_entry
) entries
;
1082 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1084 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1087 VMChangeStateEntry
*e
;
1089 e
= qemu_mallocz(sizeof (*e
));
1093 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1097 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1099 QLIST_REMOVE (e
, entries
);
1103 void vm_state_notify(int running
, int reason
)
1105 VMChangeStateEntry
*e
;
1107 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1108 e
->cb(e
->opaque
, running
, reason
);
1117 vm_state_notify(1, 0);
1119 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1123 /* reset/shutdown handler */
1125 typedef struct QEMUResetEntry
{
1126 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1127 QEMUResetHandler
*func
;
1131 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1132 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1133 static int reset_requested
;
1134 static int shutdown_requested
;
1135 static int powerdown_requested
;
1136 int debug_requested
;
1137 int vmstop_requested
;
1139 int qemu_no_shutdown(void)
1141 int r
= no_shutdown
;
1146 int qemu_shutdown_requested(void)
1148 int r
= shutdown_requested
;
1149 shutdown_requested
= 0;
1153 int qemu_reset_requested(void)
1155 int r
= reset_requested
;
1156 reset_requested
= 0;
1160 int qemu_powerdown_requested(void)
1162 int r
= powerdown_requested
;
1163 powerdown_requested
= 0;
1167 static int qemu_debug_requested(void)
1169 int r
= debug_requested
;
1170 debug_requested
= 0;
1174 static int qemu_vmstop_requested(void)
1176 int r
= vmstop_requested
;
1177 vmstop_requested
= 0;
1181 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1183 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1186 re
->opaque
= opaque
;
1187 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1190 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1194 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1195 if (re
->func
== func
&& re
->opaque
== opaque
) {
1196 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1203 void qemu_system_reset(void)
1205 QEMUResetEntry
*re
, *nre
;
1207 /* reset all devices */
1208 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1209 re
->func(re
->opaque
);
1211 monitor_protocol_event(QEVENT_RESET
, NULL
);
1212 cpu_synchronize_all_post_reset();
1215 void qemu_system_reset_request(void)
1218 shutdown_requested
= 1;
1220 reset_requested
= 1;
1222 if (cpu_single_env
) {
1223 cpu_single_env
->stopped
= 1;
1225 qemu_notify_event();
1228 void qemu_system_shutdown_request(void)
1230 shutdown_requested
= 1;
1231 qemu_notify_event();
1234 void qemu_system_powerdown_request(void)
1236 powerdown_requested
= 1;
1237 qemu_notify_event();
1240 void main_loop_wait(int nonblocking
)
1242 IOHandlerRecord
*ioh
;
1243 fd_set rfds
, wfds
, xfds
;
1251 timeout
= qemu_calculate_timeout();
1252 qemu_bh_update_timeout(&timeout
);
1255 os_host_main_loop_wait(&timeout
);
1257 /* poll any events */
1258 /* XXX: separate device handlers from system ones */
1263 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1267 (!ioh
->fd_read_poll
||
1268 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1269 FD_SET(ioh
->fd
, &rfds
);
1273 if (ioh
->fd_write
) {
1274 FD_SET(ioh
->fd
, &wfds
);
1280 tv
.tv_sec
= timeout
/ 1000;
1281 tv
.tv_usec
= (timeout
% 1000) * 1000;
1283 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1285 qemu_mutex_unlock_iothread();
1286 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1287 qemu_mutex_lock_iothread();
1289 IOHandlerRecord
*pioh
;
1291 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1293 QLIST_REMOVE(ioh
, next
);
1297 if (ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1298 ioh
->fd_read(ioh
->opaque
);
1299 if (!(ioh
->fd_read_poll
&& ioh
->fd_read_poll(ioh
->opaque
)))
1300 FD_CLR(ioh
->fd
, &rfds
);
1302 if (ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1303 ioh
->fd_write(ioh
->opaque
);
1308 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1310 qemu_run_all_timers();
1312 /* Check bottom-halves last in case any of the earlier events triggered
1318 static int vm_can_run(void)
1320 if (powerdown_requested
)
1322 if (reset_requested
)
1324 if (shutdown_requested
)
1326 if (debug_requested
)
1331 qemu_irq qemu_system_powerdown
;
1333 static void main_loop(void)
1337 if (kvm_enabled()) {
1339 cpu_disable_ticks();
1343 qemu_main_loop_start();
1347 bool nonblocking
= false;
1348 #ifdef CONFIG_PROFILER
1351 #ifndef CONFIG_IOTHREAD
1352 nonblocking
= tcg_cpu_exec();
1354 #ifdef CONFIG_PROFILER
1355 ti
= profile_getclock();
1357 main_loop_wait(nonblocking
);
1358 #ifdef CONFIG_PROFILER
1359 dev_time
+= profile_getclock() - ti
;
1361 } while (vm_can_run());
1363 if ((r
= qemu_debug_requested())) {
1366 if (qemu_shutdown_requested()) {
1367 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1374 if (qemu_reset_requested()) {
1376 qemu_system_reset();
1379 if (qemu_powerdown_requested()) {
1380 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1381 qemu_irq_raise(qemu_system_powerdown
);
1383 if ((r
= qemu_vmstop_requested())) {
1391 static void version(void)
1393 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1396 static void help(int exitcode
)
1398 const char *options_help
=
1399 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1401 #define DEFHEADING(text) stringify(text) "\n"
1402 #include "qemu-options.def"
1408 printf("usage: %s [options] [disk_image]\n"
1410 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1413 "During emulation, the following keys are useful:\n"
1414 "ctrl-alt-f toggle full screen\n"
1415 "ctrl-alt-n switch to virtual console 'n'\n"
1416 "ctrl-alt toggle mouse and keyboard grab\n"
1418 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1424 #define HAS_ARG 0x0001
1426 typedef struct QEMUOption
{
1433 static const QEMUOption qemu_options
[] = {
1434 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1435 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1436 { option, opt_arg, opt_enum, arch_mask },
1437 #define DEFHEADING(text)
1438 #include "qemu-options.def"
1444 static void select_vgahw (const char *p
)
1449 vga_interface_type
= VGA_NONE
;
1450 if (strstart(p
, "std", &opts
)) {
1451 vga_interface_type
= VGA_STD
;
1452 } else if (strstart(p
, "cirrus", &opts
)) {
1453 vga_interface_type
= VGA_CIRRUS
;
1454 } else if (strstart(p
, "vmware", &opts
)) {
1455 vga_interface_type
= VGA_VMWARE
;
1456 } else if (strstart(p
, "xenfb", &opts
)) {
1457 vga_interface_type
= VGA_XENFB
;
1458 } else if (!strstart(p
, "none", &opts
)) {
1460 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1464 const char *nextopt
;
1466 if (strstart(opts
, ",retrace=", &nextopt
)) {
1468 if (strstart(opts
, "dumb", &nextopt
))
1469 vga_retrace_method
= VGA_RETRACE_DUMB
;
1470 else if (strstart(opts
, "precise", &nextopt
))
1471 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1472 else goto invalid_vga
;
1473 } else goto invalid_vga
;
1478 static int balloon_parse(const char *arg
)
1482 if (strcmp(arg
, "none") == 0) {
1486 if (!strncmp(arg
, "virtio", 6)) {
1487 if (arg
[6] == ',') {
1488 /* have params -> parse them */
1489 opts
= qemu_opts_parse(&qemu_device_opts
, arg
+7, 0);
1493 /* create empty opts */
1494 opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1496 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1503 char *qemu_find_file(int type
, const char *name
)
1509 /* If name contains path separators then try it as a straight path. */
1510 if ((strchr(name
, '/') || strchr(name
, '\\'))
1511 && access(name
, R_OK
) == 0) {
1512 return qemu_strdup(name
);
1515 case QEMU_FILE_TYPE_BIOS
:
1518 case QEMU_FILE_TYPE_KEYMAP
:
1519 subdir
= "keymaps/";
1524 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1525 buf
= qemu_mallocz(len
);
1526 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1527 if (access(buf
, R_OK
)) {
1534 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1536 return qdev_device_help(opts
);
1539 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1543 dev
= qdev_device_add(opts
);
1549 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1551 CharDriverState
*chr
;
1553 chr
= qemu_chr_open_opts(opts
, NULL
);
1560 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1563 ret
= qemu_fsdev_add(opts
);
1569 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1571 CharDriverState
*chr
;
1572 const char *chardev
;
1576 mode
= qemu_opt_get(opts
, "mode");
1580 if (strcmp(mode
, "readline") == 0) {
1581 flags
= MONITOR_USE_READLINE
;
1582 } else if (strcmp(mode
, "control") == 0) {
1583 flags
= MONITOR_USE_CONTROL
;
1585 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1589 if (qemu_opt_get_bool(opts
, "default", 0))
1590 flags
|= MONITOR_IS_DEFAULT
;
1592 chardev
= qemu_opt_get(opts
, "chardev");
1593 chr
= qemu_chr_find(chardev
);
1595 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1599 monitor_init(chr
, flags
);
1603 static void monitor_parse(const char *optarg
, const char *mode
)
1605 static int monitor_device_index
= 0;
1611 if (strstart(optarg
, "chardev:", &p
)) {
1612 snprintf(label
, sizeof(label
), "%s", p
);
1614 snprintf(label
, sizeof(label
), "compat_monitor%d",
1615 monitor_device_index
);
1616 if (monitor_device_index
== 0) {
1619 opts
= qemu_chr_parse_compat(label
, optarg
);
1621 fprintf(stderr
, "parse error: %s\n", optarg
);
1626 opts
= qemu_opts_create(&qemu_mon_opts
, label
, 1);
1628 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1631 qemu_opt_set(opts
, "mode", mode
);
1632 qemu_opt_set(opts
, "chardev", label
);
1634 qemu_opt_set(opts
, "default", "on");
1635 monitor_device_index
++;
1638 struct device_config
{
1640 DEV_USB
, /* -usbdevice */
1642 DEV_SERIAL
, /* -serial */
1643 DEV_PARALLEL
, /* -parallel */
1644 DEV_VIRTCON
, /* -virtioconsole */
1645 DEV_DEBUGCON
, /* -debugcon */
1647 const char *cmdline
;
1648 QTAILQ_ENTRY(device_config
) next
;
1650 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1652 static void add_device_config(int type
, const char *cmdline
)
1654 struct device_config
*conf
;
1656 conf
= qemu_mallocz(sizeof(*conf
));
1658 conf
->cmdline
= cmdline
;
1659 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1662 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1664 struct device_config
*conf
;
1667 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1668 if (conf
->type
!= type
)
1670 rc
= func(conf
->cmdline
);
1677 static int serial_parse(const char *devname
)
1679 static int index
= 0;
1682 if (strcmp(devname
, "none") == 0)
1684 if (index
== MAX_SERIAL_PORTS
) {
1685 fprintf(stderr
, "qemu: too many serial ports\n");
1688 snprintf(label
, sizeof(label
), "serial%d", index
);
1689 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1690 if (!serial_hds
[index
]) {
1691 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1692 devname
, strerror(errno
));
1699 static int parallel_parse(const char *devname
)
1701 static int index
= 0;
1704 if (strcmp(devname
, "none") == 0)
1706 if (index
== MAX_PARALLEL_PORTS
) {
1707 fprintf(stderr
, "qemu: too many parallel ports\n");
1710 snprintf(label
, sizeof(label
), "parallel%d", index
);
1711 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1712 if (!parallel_hds
[index
]) {
1713 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1714 devname
, strerror(errno
));
1721 static int virtcon_parse(const char *devname
)
1723 static int index
= 0;
1725 QemuOpts
*bus_opts
, *dev_opts
;
1727 if (strcmp(devname
, "none") == 0)
1729 if (index
== MAX_VIRTIO_CONSOLES
) {
1730 fprintf(stderr
, "qemu: too many virtio consoles\n");
1734 bus_opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1735 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1737 dev_opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1738 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1740 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1741 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1742 if (!virtcon_hds
[index
]) {
1743 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1744 devname
, strerror(errno
));
1747 qemu_opt_set(dev_opts
, "chardev", label
);
1753 static int debugcon_parse(const char *devname
)
1757 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1760 opts
= qemu_opts_create(&qemu_device_opts
, "debugcon", 1);
1762 fprintf(stderr
, "qemu: already have a debugcon device\n");
1765 qemu_opt_set(opts
, "driver", "isa-debugcon");
1766 qemu_opt_set(opts
, "chardev", "debugcon");
1770 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1771 const char **poptarg
, int *poptind
)
1773 const QEMUOption
*popt
;
1774 int optind
= *poptind
;
1775 char *r
= argv
[optind
];
1778 loc_set_cmdline(argv
, optind
, 1);
1780 /* Treat --foo the same as -foo. */
1783 popt
= qemu_options
;
1786 error_report("invalid option");
1789 if (!strcmp(popt
->name
, r
+ 1))
1793 if (popt
->flags
& HAS_ARG
) {
1794 if (optind
>= argc
) {
1795 error_report("requires an argument");
1798 optarg
= argv
[optind
++];
1799 loc_set_cmdline(argv
, optind
- 2, 2);
1810 int main(int argc
, char **argv
, char **envp
)
1812 const char *gdbstub_dev
= NULL
;
1814 int snapshot
, linux_boot
;
1815 const char *icount_option
= NULL
;
1816 const char *initrd_filename
;
1817 const char *kernel_filename
, *kernel_cmdline
;
1818 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1820 DisplayChangeListener
*dcl
;
1821 int cyls
, heads
, secs
, translation
;
1822 QemuOpts
*hda_opts
= NULL
, *opts
;
1825 const char *loadvm
= NULL
;
1826 QEMUMachine
*machine
;
1827 const char *cpu_model
;
1829 const char *pid_file
= NULL
;
1830 const char *incoming
= NULL
;
1831 int show_vnc_port
= 0;
1834 error_set_progname(argv
[0]);
1838 qemu_cache_utils_init(envp
);
1840 QLIST_INIT (&vm_change_state_head
);
1841 os_setup_early_signal_handling();
1843 module_call_init(MODULE_INIT_MACHINE
);
1844 machine
= find_default_machine();
1846 initrd_filename
= NULL
;
1849 kernel_filename
= NULL
;
1850 kernel_cmdline
= "";
1851 cyls
= heads
= secs
= 0;
1852 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1854 for (i
= 0; i
< MAX_NODES
; i
++) {
1856 node_cpumask
[i
] = 0;
1859 assigned_devices_index
= 0;
1867 /* first pass of option parsing */
1869 while (optind
< argc
) {
1870 if (argv
[optind
][0] != '-') {
1875 const QEMUOption
*popt
;
1877 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1878 switch (popt
->index
) {
1879 case QEMU_OPTION_nodefconfig
:
1889 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1890 if (ret
< 0 && ret
!= -ENOENT
) {
1894 ret
= qemu_read_config_file(arch_config_name
);
1895 if (ret
< 0 && ret
!= -ENOENT
) {
1901 /* second pass of option parsing */
1906 if (argv
[optind
][0] != '-') {
1907 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1909 const QEMUOption
*popt
;
1911 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1912 if (!(popt
->arch_mask
& arch_type
)) {
1913 printf("Option %s not supported for this target\n", popt
->name
);
1916 switch(popt
->index
) {
1918 machine
= find_machine(optarg
);
1921 printf("Supported machines are:\n");
1922 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1924 printf("%-10s %s (alias of %s)\n",
1925 m
->alias
, m
->desc
, m
->name
);
1926 printf("%-10s %s%s\n",
1928 m
->is_default
? " (default)" : "");
1930 exit(*optarg
!= '?');
1933 case QEMU_OPTION_cpu
:
1934 /* hw initialization will check this */
1935 if (*optarg
== '?') {
1936 list_cpus(stdout
, &fprintf
, optarg
);
1942 case QEMU_OPTION_initrd
:
1943 initrd_filename
= optarg
;
1945 case QEMU_OPTION_hda
:
1947 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
1949 hda_opts
= drive_add(optarg
, HD_ALIAS
1950 ",cyls=%d,heads=%d,secs=%d%s",
1951 0, cyls
, heads
, secs
,
1952 translation
== BIOS_ATA_TRANSLATION_LBA
?
1954 translation
== BIOS_ATA_TRANSLATION_NONE
?
1955 ",trans=none" : "");
1957 case QEMU_OPTION_hdb
:
1958 case QEMU_OPTION_hdc
:
1959 case QEMU_OPTION_hdd
:
1960 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
1962 case QEMU_OPTION_drive
:
1963 drive_add(NULL
, "%s", optarg
);
1965 case QEMU_OPTION_set
:
1966 if (qemu_set_option(optarg
) != 0)
1969 case QEMU_OPTION_global
:
1970 if (qemu_global_option(optarg
) != 0)
1973 case QEMU_OPTION_mtdblock
:
1974 drive_add(optarg
, MTD_ALIAS
);
1976 case QEMU_OPTION_sd
:
1977 drive_add(optarg
, SD_ALIAS
);
1979 case QEMU_OPTION_pflash
:
1980 drive_add(optarg
, PFLASH_ALIAS
);
1982 case QEMU_OPTION_snapshot
:
1985 case QEMU_OPTION_hdachs
:
1989 cyls
= strtol(p
, (char **)&p
, 0);
1990 if (cyls
< 1 || cyls
> 16383)
1995 heads
= strtol(p
, (char **)&p
, 0);
1996 if (heads
< 1 || heads
> 16)
2001 secs
= strtol(p
, (char **)&p
, 0);
2002 if (secs
< 1 || secs
> 63)
2006 if (!strcmp(p
, "none"))
2007 translation
= BIOS_ATA_TRANSLATION_NONE
;
2008 else if (!strcmp(p
, "lba"))
2009 translation
= BIOS_ATA_TRANSLATION_LBA
;
2010 else if (!strcmp(p
, "auto"))
2011 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2014 } else if (*p
!= '\0') {
2016 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2019 if (hda_opts
!= NULL
) {
2021 snprintf(num
, sizeof(num
), "%d", cyls
);
2022 qemu_opt_set(hda_opts
, "cyls", num
);
2023 snprintf(num
, sizeof(num
), "%d", heads
);
2024 qemu_opt_set(hda_opts
, "heads", num
);
2025 snprintf(num
, sizeof(num
), "%d", secs
);
2026 qemu_opt_set(hda_opts
, "secs", num
);
2027 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2028 qemu_opt_set(hda_opts
, "trans", "lba");
2029 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2030 qemu_opt_set(hda_opts
, "trans", "none");
2034 case QEMU_OPTION_numa
:
2035 if (nb_numa_nodes
>= MAX_NODES
) {
2036 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2041 case QEMU_OPTION_nographic
:
2042 display_type
= DT_NOGRAPHIC
;
2044 #ifdef CONFIG_CURSES
2045 case QEMU_OPTION_curses
:
2046 display_type
= DT_CURSES
;
2049 case QEMU_OPTION_portrait
:
2052 case QEMU_OPTION_kernel
:
2053 kernel_filename
= optarg
;
2055 case QEMU_OPTION_append
:
2056 kernel_cmdline
= optarg
;
2058 case QEMU_OPTION_cdrom
:
2059 drive_add(optarg
, CDROM_ALIAS
);
2061 case QEMU_OPTION_boot
:
2063 static const char * const params
[] = {
2064 "order", "once", "menu", NULL
2066 char buf
[sizeof(boot_devices
)];
2067 char *standard_boot_devices
;
2070 if (!strchr(optarg
, '=')) {
2072 pstrcpy(buf
, sizeof(buf
), optarg
);
2073 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2075 "qemu: unknown boot parameter '%s' in '%s'\n",
2081 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2082 validate_bootdevices(buf
);
2083 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2086 if (get_param_value(buf
, sizeof(buf
),
2088 validate_bootdevices(buf
);
2089 standard_boot_devices
= qemu_strdup(boot_devices
);
2090 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2091 qemu_register_reset(restore_boot_devices
,
2092 standard_boot_devices
);
2094 if (get_param_value(buf
, sizeof(buf
),
2096 if (!strcmp(buf
, "on")) {
2098 } else if (!strcmp(buf
, "off")) {
2102 "qemu: invalid option value '%s'\n",
2110 case QEMU_OPTION_fda
:
2111 case QEMU_OPTION_fdb
:
2112 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2114 case QEMU_OPTION_no_fd_bootchk
:
2117 case QEMU_OPTION_netdev
:
2118 if (net_client_parse(&qemu_netdev_opts
, optarg
) == -1) {
2122 case QEMU_OPTION_net
:
2123 if (net_client_parse(&qemu_net_opts
, optarg
) == -1) {
2128 case QEMU_OPTION_tftp
:
2129 legacy_tftp_prefix
= optarg
;
2131 case QEMU_OPTION_bootp
:
2132 legacy_bootp_filename
= optarg
;
2134 case QEMU_OPTION_redir
:
2135 if (net_slirp_redir(optarg
) < 0)
2139 case QEMU_OPTION_bt
:
2140 add_device_config(DEV_BT
, optarg
);
2142 case QEMU_OPTION_audio_help
:
2143 if (!(audio_available())) {
2144 printf("Option %s not supported for this target\n", popt
->name
);
2150 case QEMU_OPTION_soundhw
:
2151 if (!(audio_available())) {
2152 printf("Option %s not supported for this target\n", popt
->name
);
2155 select_soundhw (optarg
);
2160 case QEMU_OPTION_version
:
2164 case QEMU_OPTION_m
: {
2168 value
= strtoul(optarg
, &ptr
, 10);
2170 case 0: case 'M': case 'm':
2177 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2181 /* On 32-bit hosts, QEMU is limited by virtual address space */
2182 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2183 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2186 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2187 fprintf(stderr
, "qemu: ram size too large\n");
2193 case QEMU_OPTION_mempath
:
2197 case QEMU_OPTION_mem_prealloc
:
2202 set_cpu_log(optarg
);
2205 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2207 case QEMU_OPTION_gdb
:
2208 gdbstub_dev
= optarg
;
2213 case QEMU_OPTION_bios
:
2216 case QEMU_OPTION_singlestep
:
2223 keyboard_layout
= optarg
;
2225 case QEMU_OPTION_localtime
:
2228 case QEMU_OPTION_vga
:
2229 select_vgahw (optarg
);
2236 w
= strtol(p
, (char **)&p
, 10);
2239 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2245 h
= strtol(p
, (char **)&p
, 10);
2250 depth
= strtol(p
, (char **)&p
, 10);
2251 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2252 depth
!= 24 && depth
!= 32)
2254 } else if (*p
== '\0') {
2255 depth
= graphic_depth
;
2262 graphic_depth
= depth
;
2265 case QEMU_OPTION_echr
:
2268 term_escape_char
= strtol(optarg
, &r
, 0);
2270 printf("Bad argument to echr\n");
2273 case QEMU_OPTION_monitor
:
2274 monitor_parse(optarg
, "readline");
2275 default_monitor
= 0;
2277 case QEMU_OPTION_qmp
:
2278 monitor_parse(optarg
, "control");
2279 default_monitor
= 0;
2281 case QEMU_OPTION_mon
:
2282 opts
= qemu_opts_parse(&qemu_mon_opts
, optarg
, 1);
2286 default_monitor
= 0;
2288 case QEMU_OPTION_chardev
:
2289 opts
= qemu_opts_parse(&qemu_chardev_opts
, optarg
, 1);
2295 case QEMU_OPTION_fsdev
:
2296 opts
= qemu_opts_parse(&qemu_fsdev_opts
, optarg
, 1);
2298 fprintf(stderr
, "parse error: %s\n", optarg
);
2302 case QEMU_OPTION_virtfs
: {
2303 char *arg_fsdev
= NULL
;
2304 char *arg_9p
= NULL
;
2307 opts
= qemu_opts_parse(&qemu_virtfs_opts
, optarg
, 1);
2309 fprintf(stderr
, "parse error: %s\n", optarg
);
2313 len
= strlen(",id=,path=");
2314 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2315 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2316 len
+= strlen(qemu_opt_get(opts
, "path"));
2317 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2320 fprintf(stderr
, "No memory to parse -fsdev for %s\n",
2325 sprintf(arg_fsdev
, "%s,id=%s,path=%s",
2326 qemu_opt_get(opts
, "fstype"),
2327 qemu_opt_get(opts
, "mount_tag"),
2328 qemu_opt_get(opts
, "path"));
2330 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2331 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2332 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2335 fprintf(stderr
, "No memory to parse -device for %s\n",
2340 sprintf(arg_9p
, "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2341 qemu_opt_get(opts
, "mount_tag"),
2342 qemu_opt_get(opts
, "mount_tag"));
2344 if (!qemu_opts_parse(&qemu_fsdev_opts
, arg_fsdev
, 1)) {
2345 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2349 if (!qemu_opts_parse(&qemu_device_opts
, arg_9p
, 1)) {
2350 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2354 qemu_free(arg_fsdev
);
2359 case QEMU_OPTION_serial
:
2360 add_device_config(DEV_SERIAL
, optarg
);
2362 if (strncmp(optarg
, "mon:", 4) == 0) {
2363 default_monitor
= 0;
2366 case QEMU_OPTION_watchdog
:
2369 "qemu: only one watchdog option may be given\n");
2374 case QEMU_OPTION_watchdog_action
:
2375 if (select_watchdog_action(optarg
) == -1) {
2376 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2380 case QEMU_OPTION_virtiocon
:
2381 add_device_config(DEV_VIRTCON
, optarg
);
2382 default_virtcon
= 0;
2383 if (strncmp(optarg
, "mon:", 4) == 0) {
2384 default_monitor
= 0;
2387 case QEMU_OPTION_parallel
:
2388 add_device_config(DEV_PARALLEL
, optarg
);
2389 default_parallel
= 0;
2390 if (strncmp(optarg
, "mon:", 4) == 0) {
2391 default_monitor
= 0;
2394 case QEMU_OPTION_debugcon
:
2395 add_device_config(DEV_DEBUGCON
, optarg
);
2397 case QEMU_OPTION_loadvm
:
2400 case QEMU_OPTION_full_screen
:
2404 case QEMU_OPTION_no_frame
:
2407 case QEMU_OPTION_alt_grab
:
2410 case QEMU_OPTION_ctrl_grab
:
2413 case QEMU_OPTION_no_quit
:
2416 case QEMU_OPTION_sdl
:
2417 display_type
= DT_SDL
;
2420 case QEMU_OPTION_pidfile
:
2423 case QEMU_OPTION_win2k_hack
:
2424 win2k_install_hack
= 1;
2426 case QEMU_OPTION_rtc_td_hack
:
2429 case QEMU_OPTION_acpitable
:
2430 do_acpitable_option(optarg
);
2432 case QEMU_OPTION_smbios
:
2433 do_smbios_option(optarg
);
2436 case QEMU_OPTION_enable_kvm
:
2440 case QEMU_OPTION_no_kvm
:
2443 case QEMU_OPTION_no_kvm_irqchip
: {
2448 case QEMU_OPTION_no_kvm_pit
: {
2452 case QEMU_OPTION_no_kvm_pit_reinjection
: {
2453 kvm_pit_reinject
= 0;
2456 case QEMU_OPTION_enable_nesting
: {
2460 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
2461 case QEMU_OPTION_pcidevice
:
2462 if (assigned_devices_index
>= MAX_DEV_ASSIGN_CMDLINE
) {
2463 fprintf(stderr
, "Too many assigned devices\n");
2466 assigned_devices
[assigned_devices_index
] = optarg
;
2467 assigned_devices_index
++;
2470 case QEMU_OPTION_usb
:
2473 case QEMU_OPTION_usbdevice
:
2475 add_device_config(DEV_USB
, optarg
);
2477 case QEMU_OPTION_device
:
2478 if (!qemu_opts_parse(&qemu_device_opts
, optarg
, 1)) {
2482 case QEMU_OPTION_smp
:
2485 fprintf(stderr
, "Invalid number of CPUs\n");
2488 if (max_cpus
< smp_cpus
) {
2489 fprintf(stderr
, "maxcpus must be equal to or greater than "
2493 if (max_cpus
> 255) {
2494 fprintf(stderr
, "Unsupported number of maxcpus\n");
2498 case QEMU_OPTION_vnc
:
2499 display_type
= DT_VNC
;
2500 vnc_display
= optarg
;
2502 case QEMU_OPTION_no_acpi
:
2505 case QEMU_OPTION_no_hpet
:
2508 case QEMU_OPTION_balloon
:
2509 if (balloon_parse(optarg
) < 0) {
2510 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2514 case QEMU_OPTION_no_reboot
:
2517 case QEMU_OPTION_no_shutdown
:
2520 case QEMU_OPTION_show_cursor
:
2523 case QEMU_OPTION_uuid
:
2524 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2525 fprintf(stderr
, "Fail to parse UUID string."
2526 " Wrong format.\n");
2530 case QEMU_OPTION_option_rom
:
2531 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2532 fprintf(stderr
, "Too many option ROMs\n");
2535 option_rom
[nb_option_roms
] = optarg
;
2538 case QEMU_OPTION_semihosting
:
2539 semihosting_enabled
= 1;
2541 case QEMU_OPTION_tdf
:
2544 case QEMU_OPTION_kvm_shadow_memory
:
2545 kvm_shadow_memory
= (int64_t)atoi(optarg
) * 1024 * 1024 / 4096;
2547 case QEMU_OPTION_name
:
2548 qemu_name
= qemu_strdup(optarg
);
2550 char *p
= strchr(qemu_name
, ',');
2553 if (strncmp(p
, "process=", 8)) {
2554 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2558 os_set_proc_name(p
);
2562 case QEMU_OPTION_prom_env
:
2563 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2564 fprintf(stderr
, "Too many prom variables\n");
2567 prom_envs
[nb_prom_envs
] = optarg
;
2570 case QEMU_OPTION_old_param
:
2573 case QEMU_OPTION_clock
:
2574 configure_alarms(optarg
);
2576 case QEMU_OPTION_startdate
:
2577 configure_rtc_date_offset(optarg
, 1);
2579 case QEMU_OPTION_rtc
:
2580 opts
= qemu_opts_parse(&qemu_rtc_opts
, optarg
, 0);
2584 configure_rtc(opts
);
2586 case QEMU_OPTION_tb_size
:
2587 tb_size
= strtol(optarg
, NULL
, 0);
2591 case QEMU_OPTION_icount
:
2592 icount_option
= optarg
;
2594 case QEMU_OPTION_incoming
:
2597 case QEMU_OPTION_nodefaults
:
2599 default_parallel
= 0;
2600 default_virtcon
= 0;
2601 default_monitor
= 0;
2609 case QEMU_OPTION_nvram
:
2613 case QEMU_OPTION_xen_domid
:
2614 if (!(xen_available())) {
2615 printf("Option %s not supported for this target\n", popt
->name
);
2618 xen_domid
= atoi(optarg
);
2620 case QEMU_OPTION_xen_create
:
2621 if (!(xen_available())) {
2622 printf("Option %s not supported for this target\n", popt
->name
);
2625 xen_mode
= XEN_CREATE
;
2627 case QEMU_OPTION_xen_attach
:
2628 if (!(xen_available())) {
2629 printf("Option %s not supported for this target\n", popt
->name
);
2632 xen_mode
= XEN_ATTACH
;
2634 case QEMU_OPTION_readconfig
:
2636 int ret
= qemu_read_config_file(optarg
);
2638 fprintf(stderr
, "read config %s: %s\n", optarg
,
2644 case QEMU_OPTION_writeconfig
:
2647 if (strcmp(optarg
, "-") == 0) {
2650 fp
= fopen(optarg
, "w");
2652 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2656 qemu_config_write(fp
);
2661 os_parse_cmd_args(popt
->index
, optarg
);
2667 /* If no data_dir is specified then try to find it relative to the
2670 data_dir
= os_find_datadir(argv
[0]);
2672 /* If all else fails use the install patch specified when building. */
2674 data_dir
= CONFIG_QEMU_DATADIR
;
2678 * Default to max_cpus = smp_cpus, in case the user doesn't
2679 * specify a max_cpus value.
2682 max_cpus
= smp_cpus
;
2684 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2685 if (smp_cpus
> machine
->max_cpus
) {
2686 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2687 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2692 qemu_opts_foreach(&qemu_device_opts
, default_driver_check
, NULL
, 0);
2693 qemu_opts_foreach(&qemu_global_opts
, default_driver_check
, NULL
, 0);
2695 if (machine
->no_serial
) {
2698 if (machine
->no_parallel
) {
2699 default_parallel
= 0;
2701 if (!machine
->use_virtcon
) {
2702 default_virtcon
= 0;
2704 if (machine
->no_vga
) {
2707 if (machine
->no_floppy
) {
2710 if (machine
->no_cdrom
) {
2713 if (machine
->no_sdcard
) {
2717 if (display_type
== DT_NOGRAPHIC
) {
2718 if (default_parallel
)
2719 add_device_config(DEV_PARALLEL
, "null");
2720 if (default_serial
&& default_monitor
) {
2721 add_device_config(DEV_SERIAL
, "mon:stdio");
2722 } else if (default_virtcon
&& default_monitor
) {
2723 add_device_config(DEV_VIRTCON
, "mon:stdio");
2726 add_device_config(DEV_SERIAL
, "stdio");
2727 if (default_virtcon
)
2728 add_device_config(DEV_VIRTCON
, "stdio");
2729 if (default_monitor
)
2730 monitor_parse("stdio", "readline");
2734 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2735 if (default_parallel
)
2736 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2737 if (default_monitor
)
2738 monitor_parse("vc:80Cx24C", "readline");
2739 if (default_virtcon
)
2740 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2743 vga_interface_type
= VGA_CIRRUS
;
2747 if (qemu_opts_foreach(&qemu_chardev_opts
, chardev_init_func
, NULL
, 1) != 0)
2750 if (qemu_opts_foreach(&qemu_fsdev_opts
, fsdev_init_func
, NULL
, 1) != 0) {
2757 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2763 int ret
= kvm_init(smp_cpus
);
2765 #if defined(KVM_UPSTREAM) || defined(CONFIG_NO_CPU_EMULATION)
2766 if (!kvm_available()) {
2767 printf("KVM not supported for this target\n");
2769 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2774 fprintf(stderr
, "Could not initialize KVM, will disable KVM support\n");
2780 if (qemu_init_main_loop()) {
2781 fprintf(stderr
, "qemu_init_main_loop failed\n");
2784 linux_boot
= (kernel_filename
!= NULL
);
2786 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2787 fprintf(stderr
, "-append only allowed with -kernel option\n");
2791 if (!linux_boot
&& initrd_filename
!= NULL
) {
2792 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2796 os_set_line_buffering();
2798 if (init_timer_alarm() < 0) {
2799 fprintf(stderr
, "could not initialize alarm timer\n");
2802 configure_icount(icount_option
);
2804 if (net_init_clients() < 0) {
2808 /* init the bluetooth world */
2809 if (foreach_device_config(DEV_BT
, bt_parse
))
2812 /* init the memory */
2814 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2816 /* init the dynamic translator */
2817 cpu_exec_init_all(tb_size
* 1024 * 1024);
2819 bdrv_init_with_whitelist();
2823 if (default_cdrom
) {
2824 /* we always create the cdrom drive, even if no disk is there */
2825 drive_add(NULL
, CDROM_ALIAS
);
2828 if (default_floppy
) {
2829 /* we always create at least one floppy */
2830 drive_add(NULL
, FD_ALIAS
, 0);
2833 if (default_sdcard
) {
2834 /* we always create one sd slot, even if no card is in it */
2835 drive_add(NULL
, SD_ALIAS
);
2838 /* open the virtual block devices */
2840 qemu_opts_foreach(&qemu_drive_opts
, drive_enable_snapshot
, NULL
, 0);
2841 if (qemu_opts_foreach(&qemu_drive_opts
, drive_init_func
, &machine
->use_scsi
, 1) != 0)
2844 register_savevm_live("ram", 0, 3, NULL
, ram_save_live
, NULL
,
2847 if (nb_numa_nodes
> 0) {
2850 if (nb_numa_nodes
> smp_cpus
) {
2851 nb_numa_nodes
= smp_cpus
;
2854 /* If no memory size if given for any node, assume the default case
2855 * and distribute the available memory equally across all nodes
2857 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2858 if (node_mem
[i
] != 0)
2861 if (i
== nb_numa_nodes
) {
2862 uint64_t usedmem
= 0;
2864 /* On Linux, the each node's border has to be 8MB aligned,
2865 * the final node gets the rest.
2867 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2868 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2869 usedmem
+= node_mem
[i
];
2871 node_mem
[i
] = ram_size
- usedmem
;
2874 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2875 if (node_cpumask
[i
] != 0)
2878 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2879 * must cope with this anyway, because there are BIOSes out there in
2880 * real machines which also use this scheme.
2882 if (i
== nb_numa_nodes
) {
2883 for (i
= 0; i
< smp_cpus
; i
++) {
2884 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2889 if (qemu_opts_foreach(&qemu_mon_opts
, mon_init_func
, NULL
, 1) != 0) {
2893 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2895 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2897 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2899 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2902 module_call_init(MODULE_INIT_DEVICE
);
2904 if (qemu_opts_foreach(&qemu_device_opts
, device_help_func
, NULL
, 0) != 0)
2908 i
= select_watchdog(watchdog
);
2910 exit (i
== 1 ? 1 : 0);
2913 if (machine
->compat_props
) {
2914 qdev_prop_register_global_list(machine
->compat_props
);
2918 machine
->init(ram_size
, boot_devices
,
2919 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2921 cpu_synchronize_all_post_init();
2923 /* must be after terminal init, SDL library changes signal handlers */
2924 os_setup_signal_handling();
2928 current_machine
= machine
;
2930 /* init USB devices */
2932 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2936 /* init generic devices */
2937 if (qemu_opts_foreach(&qemu_device_opts
, device_init_func
, NULL
, 1) != 0)
2940 net_check_clients();
2942 /* just use the first displaystate for the moment */
2943 ds
= get_displaystate();
2945 if (display_type
== DT_DEFAULT
) {
2946 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
2947 display_type
= DT_SDL
;
2949 display_type
= DT_VNC
;
2950 vnc_display
= "localhost:0,to=99";
2956 switch (display_type
) {
2959 #if defined(CONFIG_CURSES)
2961 curses_display_init(ds
, full_screen
);
2964 #if defined(CONFIG_SDL)
2966 sdl_display_init(ds
, full_screen
, no_frame
);
2968 #elif defined(CONFIG_COCOA)
2970 cocoa_display_init(ds
, full_screen
);
2974 vnc_display_init(ds
);
2975 if (vnc_display_open(ds
, vnc_display
) < 0)
2978 if (show_vnc_port
) {
2979 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
2987 dcl
= ds
->listeners
;
2988 while (dcl
!= NULL
) {
2989 if (dcl
->dpy_refresh
!= NULL
) {
2990 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
2991 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
2997 if (display_type
== DT_NOGRAPHIC
|| display_type
== DT_VNC
) {
2998 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
2999 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
3002 text_consoles_set_display(ds
);
3004 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3005 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3010 qdev_machine_creation_done();
3012 if (rom_load_all() != 0) {
3013 fprintf(stderr
, "rom loading failed\n");
3017 qemu_system_reset();
3019 if (load_vmstate(loadvm
) < 0) {
3025 qemu_start_incoming_migration(incoming
);
3026 } else if (autostart
) {