4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 /* Needed early for CONFIG_BSD etc. */
33 #include "config-host.h"
37 #include <sys/times.h>
41 #include <sys/ioctl.h>
42 #include <sys/resource.h>
43 #include <sys/socket.h>
44 #include <netinet/in.h>
46 #include <arpa/inet.h>
49 #include <sys/select.h>
50 #ifdef CONFIG_SIMPLE_TRACE
56 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
58 #include <sys/sysctl.h>
67 #include <linux/ppdev.h>
68 #include <linux/parport.h>
72 #include <sys/ethernet.h>
73 #include <sys/sockio.h>
74 #include <netinet/arp.h>
75 #include <netinet/in_systm.h>
76 #include <netinet/ip.h>
77 #include <netinet/ip_icmp.h> // must come after ip.h
78 #include <netinet/udp.h>
79 #include <netinet/tcp.h>
87 #if defined(__OpenBSD__)
91 #if defined(CONFIG_VDE)
92 #include <libvdeplug.h>
100 #if defined(__APPLE__) || defined(main)
102 int qemu_main(int argc
, char **argv
, char **envp
);
103 int main(int argc
, char **argv
)
105 return qemu_main(argc
, argv
, NULL
);
108 #define main qemu_main
110 #endif /* CONFIG_SDL */
114 #define main qemu_main
115 #endif /* CONFIG_COCOA */
118 #include "hw/boards.h"
120 #include "hw/pcmcia.h"
125 #include "hw/watchdog.h"
126 #include "hw/smbios.h"
129 #include "hw/loader.h"
132 #include "net/slirp.h"
137 #include "qemu-timer.h"
138 #include "qemu-char.h"
139 #include "cache-utils.h"
141 #include "blockdev.h"
142 #include "block-migration.h"
144 #include "audio/audio.h"
145 #include "migration.h"
147 #include "qemu-option.h"
148 #include "qemu-config.h"
149 #include "qemu-objects.h"
150 #include "qemu-options.h"
152 #include "fsdev/qemu-fsdev.h"
157 #include "qemu_socket.h"
159 #include "slirp/libslirp.h"
162 #include "qemu-queue.h"
164 #include "arch_init.h"
166 #include "ui/qemu-spice.h"
169 //#define DEBUG_SLIRP
171 #define DEFAULT_RAM_SIZE 128
173 #define MAX_VIRTIO_CONSOLES 1
175 static const char *data_dir
;
176 const char *bios_name
= NULL
;
177 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
178 DisplayType display_type
= DT_DEFAULT
;
179 int display_remote
= 0;
180 const char* keyboard_layout
= NULL
;
182 const char *mem_path
= NULL
;
184 int mem_prealloc
= 0; /* force preallocation of physical target memory */
187 NICInfo nd_table
[MAX_NICS
];
190 int incoming_expected
; /* Started with -incoming and waiting for incoming */
191 static int rtc_utc
= 1;
192 static int rtc_date_offset
= -1; /* -1 means no change */
193 QEMUClock
*rtc_clock
;
194 int vga_interface_type
= VGA_NONE
;
195 static int full_screen
= 0;
197 static int no_frame
= 0;
200 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
201 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
202 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
203 int win2k_install_hack
= 0;
211 const char *vnc_display
;
212 int acpi_enabled
= 1;
218 int graphic_rotate
= 0;
219 uint8_t irq0override
= 1;
220 const char *watchdog
;
221 const char *option_rom
[MAX_OPTION_ROMS
];
223 int semihosting_enabled
= 0;
225 const char *qemu_name
;
228 unsigned int nb_prom_envs
= 0;
229 const char *prom_envs
[MAX_PROM_ENVS
];
233 uint64_t node_mem
[MAX_NODES
];
234 uint64_t node_cpumask
[MAX_NODES
];
236 static QEMUTimer
*nographic_timer
;
238 uint8_t qemu_uuid
[16];
240 static QEMUBootSetHandler
*boot_set_handler
;
241 static void *boot_set_opaque
;
243 static NotifierList exit_notifiers
=
244 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
248 enum xen_mode xen_mode
= XEN_EMULATE
;
250 static int default_serial
= 1;
251 static int default_parallel
= 1;
252 static int default_virtcon
= 1;
253 static int default_monitor
= 1;
254 static int default_vga
= 1;
255 static int default_floppy
= 1;
256 static int default_cdrom
= 1;
257 static int default_sdcard
= 1;
263 { .driver
= "isa-serial", .flag
= &default_serial
},
264 { .driver
= "isa-parallel", .flag
= &default_parallel
},
265 { .driver
= "isa-fdc", .flag
= &default_floppy
},
266 { .driver
= "ide-drive", .flag
= &default_cdrom
},
267 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
268 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
269 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
270 { .driver
= "VGA", .flag
= &default_vga
},
271 { .driver
= "cirrus-vga", .flag
= &default_vga
},
272 { .driver
= "vmware-svga", .flag
= &default_vga
},
275 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
277 const char *driver
= qemu_opt_get(opts
, "driver");
282 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
283 if (strcmp(default_list
[i
].driver
, driver
) != 0)
285 *(default_list
[i
].flag
) = 0;
290 /***********************************************************/
291 /* real time host monotonic timer */
293 /***********************************************************/
294 /* host time/date access */
295 void qemu_get_timedate(struct tm
*tm
, int offset
)
302 if (rtc_date_offset
== -1) {
306 ret
= localtime(&ti
);
308 ti
-= rtc_date_offset
;
312 memcpy(tm
, ret
, sizeof(struct tm
));
315 int qemu_timedate_diff(struct tm
*tm
)
319 if (rtc_date_offset
== -1)
321 seconds
= mktimegm(tm
);
323 seconds
= mktime(tm
);
325 seconds
= mktimegm(tm
) + rtc_date_offset
;
327 return seconds
- time(NULL
);
330 void rtc_change_mon_event(struct tm
*tm
)
334 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
335 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
336 qobject_decref(data
);
339 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
341 time_t rtc_start_date
;
344 if (!strcmp(startdate
, "now") && legacy
) {
345 rtc_date_offset
= -1;
347 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
355 } else if (sscanf(startdate
, "%d-%d-%d",
367 rtc_start_date
= mktimegm(&tm
);
368 if (rtc_start_date
== -1) {
370 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
371 "'2006-06-17T16:01:21' or '2006-06-17'\n");
374 rtc_date_offset
= time(NULL
) - rtc_start_date
;
378 static void configure_rtc(QemuOpts
*opts
)
382 value
= qemu_opt_get(opts
, "base");
384 if (!strcmp(value
, "utc")) {
386 } else if (!strcmp(value
, "localtime")) {
389 configure_rtc_date_offset(value
, 0);
392 value
= qemu_opt_get(opts
, "clock");
394 if (!strcmp(value
, "host")) {
395 rtc_clock
= host_clock
;
396 } else if (!strcmp(value
, "vm")) {
397 rtc_clock
= vm_clock
;
399 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
403 value
= qemu_opt_get(opts
, "driftfix");
405 if (!strcmp(value
, "slew")) {
407 } else if (!strcmp(value
, "none")) {
410 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
416 /***********************************************************/
417 /* Bluetooth support */
420 static struct HCIInfo
*hci_table
[MAX_NICS
];
422 static struct bt_vlan_s
{
423 struct bt_scatternet_s net
;
425 struct bt_vlan_s
*next
;
428 /* find or alloc a new bluetooth "VLAN" */
429 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
431 struct bt_vlan_s
**pvlan
, *vlan
;
432 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
436 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
438 pvlan
= &first_bt_vlan
;
439 while (*pvlan
!= NULL
)
440 pvlan
= &(*pvlan
)->next
;
445 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
449 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
454 static struct HCIInfo null_hci
= {
455 .cmd_send
= null_hci_send
,
456 .sco_send
= null_hci_send
,
457 .acl_send
= null_hci_send
,
458 .bdaddr_set
= null_hci_addr_set
,
461 struct HCIInfo
*qemu_next_hci(void)
463 if (cur_hci
== nb_hcis
)
466 return hci_table
[cur_hci
++];
469 static struct HCIInfo
*hci_init(const char *str
)
472 struct bt_scatternet_s
*vlan
= 0;
474 if (!strcmp(str
, "null"))
477 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
479 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
480 else if (!strncmp(str
, "hci", 3)) {
483 if (!strncmp(str
+ 3, ",vlan=", 6)) {
484 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
489 vlan
= qemu_find_bt_vlan(0);
491 return bt_new_hci(vlan
);
494 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
499 static int bt_hci_parse(const char *str
)
504 if (nb_hcis
>= MAX_NICS
) {
505 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
518 bdaddr
.b
[5] = 0x56 + nb_hcis
;
519 hci
->bdaddr_set(hci
, bdaddr
.b
);
521 hci_table
[nb_hcis
++] = hci
;
526 static void bt_vhci_add(int vlan_id
)
528 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
531 fprintf(stderr
, "qemu: warning: adding a VHCI to "
532 "an empty scatternet %i\n", vlan_id
);
534 bt_vhci_init(bt_new_hci(vlan
));
537 static struct bt_device_s
*bt_device_add(const char *opt
)
539 struct bt_scatternet_s
*vlan
;
541 char *endp
= strstr(opt
, ",vlan=");
542 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
545 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
548 vlan_id
= strtol(endp
+ 6, &endp
, 0);
550 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
555 vlan
= qemu_find_bt_vlan(vlan_id
);
558 fprintf(stderr
, "qemu: warning: adding a slave device to "
559 "an empty scatternet %i\n", vlan_id
);
561 if (!strcmp(devname
, "keyboard"))
562 return bt_keyboard_init(vlan
);
564 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
568 static int bt_parse(const char *opt
)
570 const char *endp
, *p
;
573 if (strstart(opt
, "hci", &endp
)) {
574 if (!*endp
|| *endp
== ',') {
576 if (!strstart(endp
, ",vlan=", 0))
579 return bt_hci_parse(opt
);
581 } else if (strstart(opt
, "vhci", &endp
)) {
582 if (!*endp
|| *endp
== ',') {
584 if (strstart(endp
, ",vlan=", &p
)) {
585 vlan
= strtol(p
, (char **) &endp
, 0);
587 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
591 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
600 } else if (strstart(opt
, "device:", &endp
))
601 return !bt_device_add(endp
);
603 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
607 /***********************************************************/
608 /* QEMU Block devices */
610 #define HD_ALIAS "index=%d,media=disk"
611 #define CDROM_ALIAS "index=2,media=cdrom"
612 #define FD_ALIAS "index=%d,if=floppy"
613 #define PFLASH_ALIAS "if=pflash"
614 #define MTD_ALIAS "if=mtd"
615 #define SD_ALIAS "index=0,if=sd"
617 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
619 int *use_scsi
= opaque
;
622 if (drive_init(opts
, *use_scsi
, &fatal_error
) == NULL
) {
629 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
631 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
632 qemu_opt_set(opts
, "snapshot", "on");
637 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
639 boot_set_handler
= func
;
640 boot_set_opaque
= opaque
;
643 int qemu_boot_set(const char *boot_devices
)
645 if (!boot_set_handler
) {
648 return boot_set_handler(boot_set_opaque
, boot_devices
);
651 static void validate_bootdevices(char *devices
)
653 /* We just do some generic consistency checks */
657 for (p
= devices
; *p
!= '\0'; p
++) {
658 /* Allowed boot devices are:
659 * a-b: floppy disk drives
660 * c-f: IDE disk drives
661 * g-m: machine implementation dependant drives
662 * n-p: network devices
663 * It's up to each machine implementation to check if the given boot
664 * devices match the actual hardware implementation and firmware
667 if (*p
< 'a' || *p
> 'p') {
668 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
671 if (bitmap
& (1 << (*p
- 'a'))) {
672 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
675 bitmap
|= 1 << (*p
- 'a');
679 static void restore_boot_devices(void *opaque
)
681 char *standard_boot_devices
= opaque
;
682 static int first
= 1;
684 /* Restore boot order and remove ourselves after the first boot */
690 qemu_boot_set(standard_boot_devices
);
692 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
693 qemu_free(standard_boot_devices
);
696 static void numa_add(const char *optarg
)
700 unsigned long long value
, endvalue
;
703 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
704 if (!strcmp(option
, "node")) {
705 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
706 nodenr
= nb_numa_nodes
;
708 nodenr
= strtoull(option
, NULL
, 10);
711 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
712 node_mem
[nodenr
] = 0;
715 sval
= strtosz(option
, NULL
);
717 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
720 node_mem
[nodenr
] = sval
;
722 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
723 node_cpumask
[nodenr
] = 0;
725 value
= strtoull(option
, &endptr
, 10);
728 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
730 if (*endptr
== '-') {
731 endvalue
= strtoull(endptr
+1, &endptr
, 10);
732 if (endvalue
>= 63) {
735 "only 63 CPUs in NUMA mode supported.\n");
737 value
= (2ULL << endvalue
) - (1ULL << value
);
739 value
= 1ULL << value
;
742 node_cpumask
[nodenr
] = value
;
749 static void smp_parse(const char *optarg
)
751 int smp
, sockets
= 0, threads
= 0, cores
= 0;
755 smp
= strtoul(optarg
, &endptr
, 10);
756 if (endptr
!= optarg
) {
757 if (*endptr
== ',') {
761 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
762 sockets
= strtoull(option
, NULL
, 10);
763 if (get_param_value(option
, 128, "cores", endptr
) != 0)
764 cores
= strtoull(option
, NULL
, 10);
765 if (get_param_value(option
, 128, "threads", endptr
) != 0)
766 threads
= strtoull(option
, NULL
, 10);
767 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
768 max_cpus
= strtoull(option
, NULL
, 10);
770 /* compute missing values, prefer sockets over cores over threads */
771 if (smp
== 0 || sockets
== 0) {
772 sockets
= sockets
> 0 ? sockets
: 1;
773 cores
= cores
> 0 ? cores
: 1;
774 threads
= threads
> 0 ? threads
: 1;
776 smp
= cores
* threads
* sockets
;
780 threads
= threads
> 0 ? threads
: 1;
781 cores
= smp
/ (sockets
* threads
);
783 threads
= smp
/ (cores
* sockets
);
787 smp_cores
= cores
> 0 ? cores
: 1;
788 smp_threads
= threads
> 0 ? threads
: 1;
793 /***********************************************************/
796 static int usb_device_add(const char *devname
)
799 USBDevice
*dev
= NULL
;
804 /* drivers with .usbdevice_name entry in USBDeviceInfo */
805 dev
= usbdevice_create(devname
);
810 if (strstart(devname
, "host:", &p
)) {
811 dev
= usb_host_device_open(p
);
812 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
813 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
814 bt_new_hci(qemu_find_bt_vlan(0)));
825 static int usb_device_del(const char *devname
)
830 if (strstart(devname
, "host:", &p
))
831 return usb_host_device_close(p
);
836 p
= strchr(devname
, '.');
839 bus_num
= strtoul(devname
, NULL
, 0);
840 addr
= strtoul(p
+ 1, NULL
, 0);
842 return usb_device_delete_addr(bus_num
, addr
);
845 static int usb_parse(const char *cmdline
)
848 r
= usb_device_add(cmdline
);
850 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
855 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
857 const char *devname
= qdict_get_str(qdict
, "devname");
858 if (usb_device_add(devname
) < 0) {
859 error_report("could not add USB device '%s'", devname
);
863 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
865 const char *devname
= qdict_get_str(qdict
, "devname");
866 if (usb_device_del(devname
) < 0) {
867 error_report("could not delete USB device '%s'", devname
);
871 /***********************************************************/
874 static struct pcmcia_socket_entry_s
{
875 PCMCIASocket
*socket
;
876 struct pcmcia_socket_entry_s
*next
;
877 } *pcmcia_sockets
= 0;
879 void pcmcia_socket_register(PCMCIASocket
*socket
)
881 struct pcmcia_socket_entry_s
*entry
;
883 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
884 entry
->socket
= socket
;
885 entry
->next
= pcmcia_sockets
;
886 pcmcia_sockets
= entry
;
889 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
891 struct pcmcia_socket_entry_s
*entry
, **ptr
;
893 ptr
= &pcmcia_sockets
;
894 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
895 if (entry
->socket
== socket
) {
901 void pcmcia_info(Monitor
*mon
)
903 struct pcmcia_socket_entry_s
*iter
;
906 monitor_printf(mon
, "No PCMCIA sockets\n");
908 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
909 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
910 iter
->socket
->attached
? iter
->socket
->card_string
:
914 /***********************************************************/
917 typedef struct IOHandlerRecord
{
919 IOCanReadHandler
*fd_read_poll
;
926 QLIST_ENTRY(IOHandlerRecord
) next
;
929 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
930 QLIST_HEAD_INITIALIZER(io_handlers
);
933 /* XXX: fd_read_poll should be suppressed, but an API change is
934 necessary in the character devices to suppress fd_can_read(). */
935 int qemu_set_fd_handler2(int fd
,
936 IOCanReadHandler
*fd_read_poll
,
941 IOHandlerRecord
*ioh
;
943 if (!fd_read
&& !fd_write
) {
944 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
951 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
955 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
956 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
959 ioh
->fd_read_poll
= fd_read_poll
;
960 ioh
->fd_read
= fd_read
;
961 ioh
->fd_write
= fd_write
;
962 ioh
->opaque
= opaque
;
968 int qemu_set_fd_handler(int fd
,
973 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
976 /***********************************************************/
977 /* machine registration */
979 static QEMUMachine
*first_machine
= NULL
;
980 QEMUMachine
*current_machine
= NULL
;
982 int qemu_register_machine(QEMUMachine
*m
)
993 static QEMUMachine
*find_machine(const char *name
)
997 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
998 if (!strcmp(m
->name
, name
))
1000 if (m
->alias
&& !strcmp(m
->alias
, name
))
1006 static QEMUMachine
*find_default_machine(void)
1010 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1011 if (m
->is_default
) {
1018 /***********************************************************/
1019 /* main execution loop */
1021 static void gui_update(void *opaque
)
1023 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1024 DisplayState
*ds
= opaque
;
1025 DisplayChangeListener
*dcl
= ds
->listeners
;
1027 qemu_flush_coalesced_mmio_buffer();
1030 while (dcl
!= NULL
) {
1031 if (dcl
->gui_timer_interval
&&
1032 dcl
->gui_timer_interval
< interval
)
1033 interval
= dcl
->gui_timer_interval
;
1036 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1039 static void nographic_update(void *opaque
)
1041 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1043 qemu_flush_coalesced_mmio_buffer();
1044 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1047 struct vm_change_state_entry
{
1048 VMChangeStateHandler
*cb
;
1050 QLIST_ENTRY (vm_change_state_entry
) entries
;
1053 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1055 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1058 VMChangeStateEntry
*e
;
1060 e
= qemu_mallocz(sizeof (*e
));
1064 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1068 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1070 QLIST_REMOVE (e
, entries
);
1074 void vm_state_notify(int running
, int reason
)
1076 VMChangeStateEntry
*e
;
1078 trace_vm_state_notify(running
, reason
);
1080 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1081 e
->cb(e
->opaque
, running
, reason
);
1090 vm_state_notify(1, 0);
1092 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1096 /* reset/shutdown handler */
1098 typedef struct QEMUResetEntry
{
1099 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1100 QEMUResetHandler
*func
;
1104 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1105 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1106 static int reset_requested
;
1107 static int shutdown_requested
;
1108 static int powerdown_requested
;
1109 int debug_requested
;
1110 int vmstop_requested
;
1112 int qemu_shutdown_requested(void)
1114 int r
= shutdown_requested
;
1115 shutdown_requested
= 0;
1119 int qemu_reset_requested(void)
1121 int r
= reset_requested
;
1122 reset_requested
= 0;
1126 int qemu_powerdown_requested(void)
1128 int r
= powerdown_requested
;
1129 powerdown_requested
= 0;
1133 static int qemu_debug_requested(void)
1135 int r
= debug_requested
;
1136 debug_requested
= 0;
1140 static int qemu_vmstop_requested(void)
1142 int r
= vmstop_requested
;
1143 vmstop_requested
= 0;
1147 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1149 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1152 re
->opaque
= opaque
;
1153 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1156 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1160 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1161 if (re
->func
== func
&& re
->opaque
== opaque
) {
1162 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1169 void qemu_system_reset(void)
1171 QEMUResetEntry
*re
, *nre
;
1173 /* reset all devices */
1174 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1175 re
->func(re
->opaque
);
1177 monitor_protocol_event(QEVENT_RESET
, NULL
);
1178 cpu_synchronize_all_post_reset();
1181 void qemu_system_reset_request(void)
1184 shutdown_requested
= 1;
1186 reset_requested
= 1;
1188 qemu_notify_event();
1191 void qemu_system_shutdown_request(void)
1193 shutdown_requested
= 1;
1194 qemu_notify_event();
1197 void qemu_system_powerdown_request(void)
1199 powerdown_requested
= 1;
1200 qemu_notify_event();
1203 void main_loop_wait(int nonblocking
)
1205 IOHandlerRecord
*ioh
;
1206 fd_set rfds
, wfds
, xfds
;
1214 timeout
= qemu_calculate_timeout();
1215 qemu_bh_update_timeout(&timeout
);
1218 os_host_main_loop_wait(&timeout
);
1220 /* poll any events */
1221 /* XXX: separate device handlers from system ones */
1226 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1230 (!ioh
->fd_read_poll
||
1231 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1232 FD_SET(ioh
->fd
, &rfds
);
1236 if (ioh
->fd_write
) {
1237 FD_SET(ioh
->fd
, &wfds
);
1243 tv
.tv_sec
= timeout
/ 1000;
1244 tv
.tv_usec
= (timeout
% 1000) * 1000;
1246 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1248 qemu_mutex_unlock_iothread();
1249 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1250 qemu_mutex_lock_iothread();
1252 IOHandlerRecord
*pioh
;
1254 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1255 if (!ioh
->deleted
&& ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1256 ioh
->fd_read(ioh
->opaque
);
1258 if (!ioh
->deleted
&& ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1259 ioh
->fd_write(ioh
->opaque
);
1262 /* Do this last in case read/write handlers marked it for deletion */
1264 QLIST_REMOVE(ioh
, next
);
1270 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1272 qemu_run_all_timers();
1274 /* Check bottom-halves last in case any of the earlier events triggered
1280 static int vm_can_run(void)
1282 if (powerdown_requested
)
1284 if (reset_requested
)
1286 if (shutdown_requested
)
1288 if (debug_requested
)
1293 qemu_irq qemu_system_powerdown
;
1295 static void main_loop(void)
1299 qemu_main_loop_start();
1303 bool nonblocking
= false;
1304 #ifdef CONFIG_PROFILER
1307 #ifndef CONFIG_IOTHREAD
1308 nonblocking
= cpu_exec_all();
1310 #ifdef CONFIG_PROFILER
1311 ti
= profile_getclock();
1313 main_loop_wait(nonblocking
);
1314 #ifdef CONFIG_PROFILER
1315 dev_time
+= profile_getclock() - ti
;
1317 } while (vm_can_run());
1319 if ((r
= qemu_debug_requested())) {
1322 if (qemu_shutdown_requested()) {
1323 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1330 if (qemu_reset_requested()) {
1332 qemu_system_reset();
1335 if (qemu_powerdown_requested()) {
1336 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1337 qemu_irq_raise(qemu_system_powerdown
);
1339 if ((r
= qemu_vmstop_requested())) {
1347 static void version(void)
1349 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1352 static void help(int exitcode
)
1354 const char *options_help
=
1355 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1357 #define DEFHEADING(text) stringify(text) "\n"
1358 #include "qemu-options.def"
1364 printf("usage: %s [options] [disk_image]\n"
1366 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1369 "During emulation, the following keys are useful:\n"
1370 "ctrl-alt-f toggle full screen\n"
1371 "ctrl-alt-n switch to virtual console 'n'\n"
1372 "ctrl-alt toggle mouse and keyboard grab\n"
1374 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1380 #define HAS_ARG 0x0001
1382 typedef struct QEMUOption
{
1389 static const QEMUOption qemu_options
[] = {
1390 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1391 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1392 { option, opt_arg, opt_enum, arch_mask },
1393 #define DEFHEADING(text)
1394 #include "qemu-options.def"
1400 static void select_vgahw (const char *p
)
1405 vga_interface_type
= VGA_NONE
;
1406 if (strstart(p
, "std", &opts
)) {
1407 vga_interface_type
= VGA_STD
;
1408 } else if (strstart(p
, "cirrus", &opts
)) {
1409 vga_interface_type
= VGA_CIRRUS
;
1410 } else if (strstart(p
, "vmware", &opts
)) {
1411 vga_interface_type
= VGA_VMWARE
;
1412 } else if (strstart(p
, "xenfb", &opts
)) {
1413 vga_interface_type
= VGA_XENFB
;
1414 } else if (strstart(p
, "qxl", &opts
)) {
1415 vga_interface_type
= VGA_QXL
;
1416 } else if (!strstart(p
, "none", &opts
)) {
1418 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1422 const char *nextopt
;
1424 if (strstart(opts
, ",retrace=", &nextopt
)) {
1426 if (strstart(opts
, "dumb", &nextopt
))
1427 vga_retrace_method
= VGA_RETRACE_DUMB
;
1428 else if (strstart(opts
, "precise", &nextopt
))
1429 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1430 else goto invalid_vga
;
1431 } else goto invalid_vga
;
1436 static int balloon_parse(const char *arg
)
1440 if (strcmp(arg
, "none") == 0) {
1444 if (!strncmp(arg
, "virtio", 6)) {
1445 if (arg
[6] == ',') {
1446 /* have params -> parse them */
1447 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1451 /* create empty opts */
1452 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1454 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1461 char *qemu_find_file(int type
, const char *name
)
1467 /* If name contains path separators then try it as a straight path. */
1468 if ((strchr(name
, '/') || strchr(name
, '\\'))
1469 && access(name
, R_OK
) == 0) {
1470 return qemu_strdup(name
);
1473 case QEMU_FILE_TYPE_BIOS
:
1476 case QEMU_FILE_TYPE_KEYMAP
:
1477 subdir
= "keymaps/";
1482 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1483 buf
= qemu_mallocz(len
);
1484 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1485 if (access(buf
, R_OK
)) {
1492 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1494 return qdev_device_help(opts
);
1497 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1501 dev
= qdev_device_add(opts
);
1507 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1509 CharDriverState
*chr
;
1511 chr
= qemu_chr_open_opts(opts
, NULL
);
1517 #ifdef CONFIG_VIRTFS
1518 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1521 ret
= qemu_fsdev_add(opts
);
1527 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1529 CharDriverState
*chr
;
1530 const char *chardev
;
1534 mode
= qemu_opt_get(opts
, "mode");
1538 if (strcmp(mode
, "readline") == 0) {
1539 flags
= MONITOR_USE_READLINE
;
1540 } else if (strcmp(mode
, "control") == 0) {
1541 flags
= MONITOR_USE_CONTROL
;
1543 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1547 if (qemu_opt_get_bool(opts
, "pretty", 0))
1548 flags
|= MONITOR_USE_PRETTY
;
1550 if (qemu_opt_get_bool(opts
, "default", 0))
1551 flags
|= MONITOR_IS_DEFAULT
;
1553 chardev
= qemu_opt_get(opts
, "chardev");
1554 chr
= qemu_chr_find(chardev
);
1556 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1560 monitor_init(chr
, flags
);
1564 static void monitor_parse(const char *optarg
, const char *mode
)
1566 static int monitor_device_index
= 0;
1572 if (strstart(optarg
, "chardev:", &p
)) {
1573 snprintf(label
, sizeof(label
), "%s", p
);
1575 snprintf(label
, sizeof(label
), "compat_monitor%d",
1576 monitor_device_index
);
1577 if (monitor_device_index
== 0) {
1580 opts
= qemu_chr_parse_compat(label
, optarg
);
1582 fprintf(stderr
, "parse error: %s\n", optarg
);
1587 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1589 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1592 qemu_opt_set(opts
, "mode", mode
);
1593 qemu_opt_set(opts
, "chardev", label
);
1595 qemu_opt_set(opts
, "default", "on");
1596 monitor_device_index
++;
1599 struct device_config
{
1601 DEV_USB
, /* -usbdevice */
1603 DEV_SERIAL
, /* -serial */
1604 DEV_PARALLEL
, /* -parallel */
1605 DEV_VIRTCON
, /* -virtioconsole */
1606 DEV_DEBUGCON
, /* -debugcon */
1608 const char *cmdline
;
1609 QTAILQ_ENTRY(device_config
) next
;
1611 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1613 static void add_device_config(int type
, const char *cmdline
)
1615 struct device_config
*conf
;
1617 conf
= qemu_mallocz(sizeof(*conf
));
1619 conf
->cmdline
= cmdline
;
1620 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1623 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1625 struct device_config
*conf
;
1628 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1629 if (conf
->type
!= type
)
1631 rc
= func(conf
->cmdline
);
1638 static int serial_parse(const char *devname
)
1640 static int index
= 0;
1643 if (strcmp(devname
, "none") == 0)
1645 if (index
== MAX_SERIAL_PORTS
) {
1646 fprintf(stderr
, "qemu: too many serial ports\n");
1649 snprintf(label
, sizeof(label
), "serial%d", index
);
1650 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1651 if (!serial_hds
[index
]) {
1652 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1653 devname
, strerror(errno
));
1660 static int parallel_parse(const char *devname
)
1662 static int index
= 0;
1665 if (strcmp(devname
, "none") == 0)
1667 if (index
== MAX_PARALLEL_PORTS
) {
1668 fprintf(stderr
, "qemu: too many parallel ports\n");
1671 snprintf(label
, sizeof(label
), "parallel%d", index
);
1672 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1673 if (!parallel_hds
[index
]) {
1674 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1675 devname
, strerror(errno
));
1682 static int virtcon_parse(const char *devname
)
1684 QemuOptsList
*device
= qemu_find_opts("device");
1685 static int index
= 0;
1687 QemuOpts
*bus_opts
, *dev_opts
;
1689 if (strcmp(devname
, "none") == 0)
1691 if (index
== MAX_VIRTIO_CONSOLES
) {
1692 fprintf(stderr
, "qemu: too many virtio consoles\n");
1696 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1697 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1699 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1700 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1702 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1703 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1704 if (!virtcon_hds
[index
]) {
1705 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1706 devname
, strerror(errno
));
1709 qemu_opt_set(dev_opts
, "chardev", label
);
1715 static int debugcon_parse(const char *devname
)
1719 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1722 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1724 fprintf(stderr
, "qemu: already have a debugcon device\n");
1727 qemu_opt_set(opts
, "driver", "isa-debugcon");
1728 qemu_opt_set(opts
, "chardev", "debugcon");
1732 void qemu_add_exit_notifier(Notifier
*notify
)
1734 notifier_list_add(&exit_notifiers
, notify
);
1737 void qemu_remove_exit_notifier(Notifier
*notify
)
1739 notifier_list_remove(&exit_notifiers
, notify
);
1742 static void qemu_run_exit_notifiers(void)
1744 notifier_list_notify(&exit_notifiers
);
1747 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1748 const char **poptarg
, int *poptind
)
1750 const QEMUOption
*popt
;
1751 int optind
= *poptind
;
1752 char *r
= argv
[optind
];
1755 loc_set_cmdline(argv
, optind
, 1);
1757 /* Treat --foo the same as -foo. */
1760 popt
= qemu_options
;
1763 error_report("invalid option");
1766 if (!strcmp(popt
->name
, r
+ 1))
1770 if (popt
->flags
& HAS_ARG
) {
1771 if (optind
>= argc
) {
1772 error_report("requires an argument");
1775 optarg
= argv
[optind
++];
1776 loc_set_cmdline(argv
, optind
- 2, 2);
1787 int main(int argc
, char **argv
, char **envp
)
1789 const char *gdbstub_dev
= NULL
;
1791 int snapshot
, linux_boot
;
1792 const char *icount_option
= NULL
;
1793 const char *initrd_filename
;
1794 const char *kernel_filename
, *kernel_cmdline
;
1795 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1797 DisplayChangeListener
*dcl
;
1798 int cyls
, heads
, secs
, translation
;
1799 QemuOpts
*hda_opts
= NULL
, *opts
;
1800 QemuOptsList
*olist
;
1803 const char *loadvm
= NULL
;
1804 QEMUMachine
*machine
;
1805 const char *cpu_model
;
1807 const char *pid_file
= NULL
;
1808 const char *incoming
= NULL
;
1809 int show_vnc_port
= 0;
1812 #ifdef CONFIG_SIMPLE_TRACE
1813 const char *trace_file
= NULL
;
1815 atexit(qemu_run_exit_notifiers
);
1816 error_set_progname(argv
[0]);
1820 qemu_cache_utils_init(envp
);
1822 QLIST_INIT (&vm_change_state_head
);
1823 os_setup_early_signal_handling();
1825 module_call_init(MODULE_INIT_MACHINE
);
1826 machine
= find_default_machine();
1828 initrd_filename
= NULL
;
1831 kernel_filename
= NULL
;
1832 kernel_cmdline
= "";
1833 cyls
= heads
= secs
= 0;
1834 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1836 for (i
= 0; i
< MAX_NODES
; i
++) {
1838 node_cpumask
[i
] = 0;
1847 /* first pass of option parsing */
1849 while (optind
< argc
) {
1850 if (argv
[optind
][0] != '-') {
1855 const QEMUOption
*popt
;
1857 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1858 switch (popt
->index
) {
1859 case QEMU_OPTION_nodefconfig
:
1869 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1870 if (ret
< 0 && ret
!= -ENOENT
) {
1874 ret
= qemu_read_config_file(arch_config_name
);
1875 if (ret
< 0 && ret
!= -ENOENT
) {
1881 /* second pass of option parsing */
1886 if (argv
[optind
][0] != '-') {
1887 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1889 const QEMUOption
*popt
;
1891 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1892 if (!(popt
->arch_mask
& arch_type
)) {
1893 printf("Option %s not supported for this target\n", popt
->name
);
1896 switch(popt
->index
) {
1898 machine
= find_machine(optarg
);
1901 printf("Supported machines are:\n");
1902 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1904 printf("%-10s %s (alias of %s)\n",
1905 m
->alias
, m
->desc
, m
->name
);
1906 printf("%-10s %s%s\n",
1908 m
->is_default
? " (default)" : "");
1910 exit(*optarg
!= '?');
1913 case QEMU_OPTION_cpu
:
1914 /* hw initialization will check this */
1915 if (*optarg
== '?') {
1916 list_cpus(stdout
, &fprintf
, optarg
);
1922 case QEMU_OPTION_initrd
:
1923 initrd_filename
= optarg
;
1925 case QEMU_OPTION_hda
:
1927 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
1929 hda_opts
= drive_add(optarg
, HD_ALIAS
1930 ",cyls=%d,heads=%d,secs=%d%s",
1931 0, cyls
, heads
, secs
,
1932 translation
== BIOS_ATA_TRANSLATION_LBA
?
1934 translation
== BIOS_ATA_TRANSLATION_NONE
?
1935 ",trans=none" : "");
1937 case QEMU_OPTION_hdb
:
1938 case QEMU_OPTION_hdc
:
1939 case QEMU_OPTION_hdd
:
1940 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
1942 case QEMU_OPTION_drive
:
1943 drive_add(NULL
, "%s", optarg
);
1945 case QEMU_OPTION_set
:
1946 if (qemu_set_option(optarg
) != 0)
1949 case QEMU_OPTION_global
:
1950 if (qemu_global_option(optarg
) != 0)
1953 case QEMU_OPTION_mtdblock
:
1954 drive_add(optarg
, MTD_ALIAS
);
1956 case QEMU_OPTION_sd
:
1957 drive_add(optarg
, SD_ALIAS
);
1959 case QEMU_OPTION_pflash
:
1960 drive_add(optarg
, PFLASH_ALIAS
);
1962 case QEMU_OPTION_snapshot
:
1965 case QEMU_OPTION_hdachs
:
1969 cyls
= strtol(p
, (char **)&p
, 0);
1970 if (cyls
< 1 || cyls
> 16383)
1975 heads
= strtol(p
, (char **)&p
, 0);
1976 if (heads
< 1 || heads
> 16)
1981 secs
= strtol(p
, (char **)&p
, 0);
1982 if (secs
< 1 || secs
> 63)
1986 if (!strcmp(p
, "none"))
1987 translation
= BIOS_ATA_TRANSLATION_NONE
;
1988 else if (!strcmp(p
, "lba"))
1989 translation
= BIOS_ATA_TRANSLATION_LBA
;
1990 else if (!strcmp(p
, "auto"))
1991 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1994 } else if (*p
!= '\0') {
1996 fprintf(stderr
, "qemu: invalid physical CHS format\n");
1999 if (hda_opts
!= NULL
) {
2001 snprintf(num
, sizeof(num
), "%d", cyls
);
2002 qemu_opt_set(hda_opts
, "cyls", num
);
2003 snprintf(num
, sizeof(num
), "%d", heads
);
2004 qemu_opt_set(hda_opts
, "heads", num
);
2005 snprintf(num
, sizeof(num
), "%d", secs
);
2006 qemu_opt_set(hda_opts
, "secs", num
);
2007 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2008 qemu_opt_set(hda_opts
, "trans", "lba");
2009 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2010 qemu_opt_set(hda_opts
, "trans", "none");
2014 case QEMU_OPTION_numa
:
2015 if (nb_numa_nodes
>= MAX_NODES
) {
2016 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2021 case QEMU_OPTION_nographic
:
2022 display_type
= DT_NOGRAPHIC
;
2024 #ifdef CONFIG_CURSES
2025 case QEMU_OPTION_curses
:
2026 display_type
= DT_CURSES
;
2029 case QEMU_OPTION_portrait
:
2032 case QEMU_OPTION_kernel
:
2033 kernel_filename
= optarg
;
2035 case QEMU_OPTION_append
:
2036 kernel_cmdline
= optarg
;
2038 case QEMU_OPTION_cdrom
:
2039 drive_add(optarg
, CDROM_ALIAS
);
2041 case QEMU_OPTION_boot
:
2043 static const char * const params
[] = {
2044 "order", "once", "menu", NULL
2046 char buf
[sizeof(boot_devices
)];
2047 char *standard_boot_devices
;
2050 if (!strchr(optarg
, '=')) {
2052 pstrcpy(buf
, sizeof(buf
), optarg
);
2053 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2055 "qemu: unknown boot parameter '%s' in '%s'\n",
2061 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2062 validate_bootdevices(buf
);
2063 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2066 if (get_param_value(buf
, sizeof(buf
),
2068 validate_bootdevices(buf
);
2069 standard_boot_devices
= qemu_strdup(boot_devices
);
2070 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2071 qemu_register_reset(restore_boot_devices
,
2072 standard_boot_devices
);
2074 if (get_param_value(buf
, sizeof(buf
),
2076 if (!strcmp(buf
, "on")) {
2078 } else if (!strcmp(buf
, "off")) {
2082 "qemu: invalid option value '%s'\n",
2090 case QEMU_OPTION_fda
:
2091 case QEMU_OPTION_fdb
:
2092 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2094 case QEMU_OPTION_no_fd_bootchk
:
2097 case QEMU_OPTION_netdev
:
2098 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2102 case QEMU_OPTION_net
:
2103 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2108 case QEMU_OPTION_tftp
:
2109 legacy_tftp_prefix
= optarg
;
2111 case QEMU_OPTION_bootp
:
2112 legacy_bootp_filename
= optarg
;
2114 case QEMU_OPTION_redir
:
2115 if (net_slirp_redir(optarg
) < 0)
2119 case QEMU_OPTION_bt
:
2120 add_device_config(DEV_BT
, optarg
);
2122 case QEMU_OPTION_audio_help
:
2123 if (!(audio_available())) {
2124 printf("Option %s not supported for this target\n", popt
->name
);
2130 case QEMU_OPTION_soundhw
:
2131 if (!(audio_available())) {
2132 printf("Option %s not supported for this target\n", popt
->name
);
2135 select_soundhw (optarg
);
2140 case QEMU_OPTION_version
:
2144 case QEMU_OPTION_m
: {
2147 value
= strtosz(optarg
, NULL
);
2149 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2153 /* On 32-bit hosts, QEMU is limited by virtual address space */
2154 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2155 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2158 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2159 fprintf(stderr
, "qemu: ram size too large\n");
2165 case QEMU_OPTION_mempath
:
2169 case QEMU_OPTION_mem_prealloc
:
2174 set_cpu_log(optarg
);
2177 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2179 case QEMU_OPTION_gdb
:
2180 gdbstub_dev
= optarg
;
2185 case QEMU_OPTION_bios
:
2188 case QEMU_OPTION_singlestep
:
2195 keyboard_layout
= optarg
;
2197 case QEMU_OPTION_localtime
:
2200 case QEMU_OPTION_vga
:
2201 select_vgahw (optarg
);
2208 w
= strtol(p
, (char **)&p
, 10);
2211 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2217 h
= strtol(p
, (char **)&p
, 10);
2222 depth
= strtol(p
, (char **)&p
, 10);
2223 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2224 depth
!= 24 && depth
!= 32)
2226 } else if (*p
== '\0') {
2227 depth
= graphic_depth
;
2234 graphic_depth
= depth
;
2237 case QEMU_OPTION_echr
:
2240 term_escape_char
= strtol(optarg
, &r
, 0);
2242 printf("Bad argument to echr\n");
2245 case QEMU_OPTION_monitor
:
2246 monitor_parse(optarg
, "readline");
2247 default_monitor
= 0;
2249 case QEMU_OPTION_qmp
:
2250 monitor_parse(optarg
, "control");
2251 default_monitor
= 0;
2253 case QEMU_OPTION_mon
:
2254 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2258 default_monitor
= 0;
2260 case QEMU_OPTION_chardev
:
2261 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2266 case QEMU_OPTION_fsdev
:
2267 olist
= qemu_find_opts("fsdev");
2269 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2272 opts
= qemu_opts_parse(olist
, optarg
, 1);
2274 fprintf(stderr
, "parse error: %s\n", optarg
);
2278 case QEMU_OPTION_virtfs
: {
2279 char *arg_fsdev
= NULL
;
2280 char *arg_9p
= NULL
;
2283 olist
= qemu_find_opts("virtfs");
2285 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2288 opts
= qemu_opts_parse(olist
, optarg
, 1);
2290 fprintf(stderr
, "parse error: %s\n", optarg
);
2294 if (qemu_opt_get(opts
, "fstype") == NULL
||
2295 qemu_opt_get(opts
, "mount_tag") == NULL
||
2296 qemu_opt_get(opts
, "path") == NULL
||
2297 qemu_opt_get(opts
, "security_model") == NULL
) {
2298 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2299 "security_model=[mapped|passthrough|none],"
2304 len
= strlen(",id=,path=,security_model=");
2305 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2306 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2307 len
+= strlen(qemu_opt_get(opts
, "path"));
2308 len
+= strlen(qemu_opt_get(opts
, "security_model"));
2309 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2311 snprintf(arg_fsdev
, (len
+ 1) * sizeof(*arg_fsdev
),
2312 "%s,id=%s,path=%s,security_model=%s",
2313 qemu_opt_get(opts
, "fstype"),
2314 qemu_opt_get(opts
, "mount_tag"),
2315 qemu_opt_get(opts
, "path"),
2316 qemu_opt_get(opts
, "security_model"));
2318 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2319 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2320 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2322 snprintf(arg_9p
, (len
+ 1) * sizeof(*arg_9p
),
2323 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2324 qemu_opt_get(opts
, "mount_tag"),
2325 qemu_opt_get(opts
, "mount_tag"));
2327 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev
, 1)) {
2328 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2332 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p
, 1)) {
2333 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2337 qemu_free(arg_fsdev
);
2341 case QEMU_OPTION_serial
:
2342 add_device_config(DEV_SERIAL
, optarg
);
2344 if (strncmp(optarg
, "mon:", 4) == 0) {
2345 default_monitor
= 0;
2348 case QEMU_OPTION_watchdog
:
2351 "qemu: only one watchdog option may be given\n");
2356 case QEMU_OPTION_watchdog_action
:
2357 if (select_watchdog_action(optarg
) == -1) {
2358 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2362 case QEMU_OPTION_virtiocon
:
2363 add_device_config(DEV_VIRTCON
, optarg
);
2364 default_virtcon
= 0;
2365 if (strncmp(optarg
, "mon:", 4) == 0) {
2366 default_monitor
= 0;
2369 case QEMU_OPTION_parallel
:
2370 add_device_config(DEV_PARALLEL
, optarg
);
2371 default_parallel
= 0;
2372 if (strncmp(optarg
, "mon:", 4) == 0) {
2373 default_monitor
= 0;
2376 case QEMU_OPTION_debugcon
:
2377 add_device_config(DEV_DEBUGCON
, optarg
);
2379 case QEMU_OPTION_loadvm
:
2382 case QEMU_OPTION_full_screen
:
2386 case QEMU_OPTION_no_frame
:
2389 case QEMU_OPTION_alt_grab
:
2392 case QEMU_OPTION_ctrl_grab
:
2395 case QEMU_OPTION_no_quit
:
2398 case QEMU_OPTION_sdl
:
2399 display_type
= DT_SDL
;
2402 case QEMU_OPTION_pidfile
:
2405 case QEMU_OPTION_win2k_hack
:
2406 win2k_install_hack
= 1;
2408 case QEMU_OPTION_rtc_td_hack
:
2411 case QEMU_OPTION_acpitable
:
2412 do_acpitable_option(optarg
);
2414 case QEMU_OPTION_smbios
:
2415 do_smbios_option(optarg
);
2417 case QEMU_OPTION_enable_kvm
:
2420 case QEMU_OPTION_usb
:
2423 case QEMU_OPTION_usbdevice
:
2425 add_device_config(DEV_USB
, optarg
);
2427 case QEMU_OPTION_device
:
2428 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2432 case QEMU_OPTION_smp
:
2435 fprintf(stderr
, "Invalid number of CPUs\n");
2438 if (max_cpus
< smp_cpus
) {
2439 fprintf(stderr
, "maxcpus must be equal to or greater than "
2443 if (max_cpus
> 255) {
2444 fprintf(stderr
, "Unsupported number of maxcpus\n");
2448 case QEMU_OPTION_vnc
:
2450 vnc_display
= optarg
;
2452 case QEMU_OPTION_no_acpi
:
2455 case QEMU_OPTION_no_hpet
:
2458 case QEMU_OPTION_balloon
:
2459 if (balloon_parse(optarg
) < 0) {
2460 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2464 case QEMU_OPTION_no_reboot
:
2467 case QEMU_OPTION_no_shutdown
:
2470 case QEMU_OPTION_show_cursor
:
2473 case QEMU_OPTION_uuid
:
2474 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2475 fprintf(stderr
, "Fail to parse UUID string."
2476 " Wrong format.\n");
2480 case QEMU_OPTION_option_rom
:
2481 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2482 fprintf(stderr
, "Too many option ROMs\n");
2485 option_rom
[nb_option_roms
] = optarg
;
2488 case QEMU_OPTION_semihosting
:
2489 semihosting_enabled
= 1;
2491 case QEMU_OPTION_name
:
2492 qemu_name
= qemu_strdup(optarg
);
2494 char *p
= strchr(qemu_name
, ',');
2497 if (strncmp(p
, "process=", 8)) {
2498 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2502 os_set_proc_name(p
);
2506 case QEMU_OPTION_prom_env
:
2507 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2508 fprintf(stderr
, "Too many prom variables\n");
2511 prom_envs
[nb_prom_envs
] = optarg
;
2514 case QEMU_OPTION_old_param
:
2517 case QEMU_OPTION_clock
:
2518 configure_alarms(optarg
);
2520 case QEMU_OPTION_startdate
:
2521 configure_rtc_date_offset(optarg
, 1);
2523 case QEMU_OPTION_rtc
:
2524 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2528 configure_rtc(opts
);
2530 case QEMU_OPTION_tb_size
:
2531 tb_size
= strtol(optarg
, NULL
, 0);
2535 case QEMU_OPTION_icount
:
2536 icount_option
= optarg
;
2538 case QEMU_OPTION_incoming
:
2540 incoming_expected
= true;
2542 case QEMU_OPTION_nodefaults
:
2544 default_parallel
= 0;
2545 default_virtcon
= 0;
2546 default_monitor
= 0;
2553 case QEMU_OPTION_xen_domid
:
2554 if (!(xen_available())) {
2555 printf("Option %s not supported for this target\n", popt
->name
);
2558 xen_domid
= atoi(optarg
);
2560 case QEMU_OPTION_xen_create
:
2561 if (!(xen_available())) {
2562 printf("Option %s not supported for this target\n", popt
->name
);
2565 xen_mode
= XEN_CREATE
;
2567 case QEMU_OPTION_xen_attach
:
2568 if (!(xen_available())) {
2569 printf("Option %s not supported for this target\n", popt
->name
);
2572 xen_mode
= XEN_ATTACH
;
2574 #ifdef CONFIG_SIMPLE_TRACE
2575 case QEMU_OPTION_trace
:
2576 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2578 trace_file
= qemu_opt_get(opts
, "file");
2582 case QEMU_OPTION_readconfig
:
2584 int ret
= qemu_read_config_file(optarg
);
2586 fprintf(stderr
, "read config %s: %s\n", optarg
,
2592 case QEMU_OPTION_spice
:
2593 olist
= qemu_find_opts("spice");
2595 fprintf(stderr
, "spice is not supported by this qemu build.\n");
2598 opts
= qemu_opts_parse(olist
, optarg
, 0);
2600 fprintf(stderr
, "parse error: %s\n", optarg
);
2604 case QEMU_OPTION_writeconfig
:
2607 if (strcmp(optarg
, "-") == 0) {
2610 fp
= fopen(optarg
, "w");
2612 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2616 qemu_config_write(fp
);
2621 os_parse_cmd_args(popt
->index
, optarg
);
2627 /* If no data_dir is specified then try to find it relative to the
2630 data_dir
= os_find_datadir(argv
[0]);
2632 /* If all else fails use the install patch specified when building. */
2634 data_dir
= CONFIG_QEMU_DATADIR
;
2637 #ifdef CONFIG_SIMPLE_TRACE
2639 * Set the trace file name, if specified.
2641 st_set_trace_file(trace_file
);
2644 * Default to max_cpus = smp_cpus, in case the user doesn't
2645 * specify a max_cpus value.
2648 max_cpus
= smp_cpus
;
2650 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2651 if (smp_cpus
> machine
->max_cpus
) {
2652 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2653 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2658 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2659 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2661 if (machine
->no_serial
) {
2664 if (machine
->no_parallel
) {
2665 default_parallel
= 0;
2667 if (!machine
->use_virtcon
) {
2668 default_virtcon
= 0;
2670 if (machine
->no_vga
) {
2673 if (machine
->no_floppy
) {
2676 if (machine
->no_cdrom
) {
2679 if (machine
->no_sdcard
) {
2683 if (display_type
== DT_NOGRAPHIC
) {
2684 if (default_parallel
)
2685 add_device_config(DEV_PARALLEL
, "null");
2686 if (default_serial
&& default_monitor
) {
2687 add_device_config(DEV_SERIAL
, "mon:stdio");
2688 } else if (default_virtcon
&& default_monitor
) {
2689 add_device_config(DEV_VIRTCON
, "mon:stdio");
2692 add_device_config(DEV_SERIAL
, "stdio");
2693 if (default_virtcon
)
2694 add_device_config(DEV_VIRTCON
, "stdio");
2695 if (default_monitor
)
2696 monitor_parse("stdio", "readline");
2700 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2701 if (default_parallel
)
2702 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2703 if (default_monitor
)
2704 monitor_parse("vc:80Cx24C", "readline");
2705 if (default_virtcon
)
2706 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2709 vga_interface_type
= VGA_CIRRUS
;
2713 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
2715 #ifdef CONFIG_VIRTFS
2716 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
2723 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2729 int ret
= kvm_init(smp_cpus
);
2731 if (!kvm_available()) {
2732 printf("KVM not supported for this target\n");
2734 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2740 if (qemu_init_main_loop()) {
2741 fprintf(stderr
, "qemu_init_main_loop failed\n");
2744 linux_boot
= (kernel_filename
!= NULL
);
2746 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2747 fprintf(stderr
, "-append only allowed with -kernel option\n");
2751 if (!linux_boot
&& initrd_filename
!= NULL
) {
2752 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2756 os_set_line_buffering();
2758 if (init_timer_alarm() < 0) {
2759 fprintf(stderr
, "could not initialize alarm timer\n");
2762 configure_icount(icount_option
);
2764 if (net_init_clients() < 0) {
2768 /* init the bluetooth world */
2769 if (foreach_device_config(DEV_BT
, bt_parse
))
2772 /* init the memory */
2774 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2776 /* init the dynamic translator */
2777 cpu_exec_init_all(tb_size
* 1024 * 1024);
2779 bdrv_init_with_whitelist();
2783 if (default_cdrom
) {
2784 /* we always create the cdrom drive, even if no disk is there */
2785 drive_add(NULL
, CDROM_ALIAS
);
2788 if (default_floppy
) {
2789 /* we always create at least one floppy */
2790 drive_add(NULL
, FD_ALIAS
, 0);
2793 if (default_sdcard
) {
2794 /* we always create one sd slot, even if no card is in it */
2795 drive_add(NULL
, SD_ALIAS
);
2798 /* open the virtual block devices */
2800 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
2801 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
2804 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2807 if (nb_numa_nodes
> 0) {
2810 if (nb_numa_nodes
> smp_cpus
) {
2811 nb_numa_nodes
= smp_cpus
;
2814 /* If no memory size if given for any node, assume the default case
2815 * and distribute the available memory equally across all nodes
2817 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2818 if (node_mem
[i
] != 0)
2821 if (i
== nb_numa_nodes
) {
2822 uint64_t usedmem
= 0;
2824 /* On Linux, the each node's border has to be 8MB aligned,
2825 * the final node gets the rest.
2827 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2828 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2829 usedmem
+= node_mem
[i
];
2831 node_mem
[i
] = ram_size
- usedmem
;
2834 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2835 if (node_cpumask
[i
] != 0)
2838 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2839 * must cope with this anyway, because there are BIOSes out there in
2840 * real machines which also use this scheme.
2842 if (i
== nb_numa_nodes
) {
2843 for (i
= 0; i
< smp_cpus
; i
++) {
2844 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2849 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
2853 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2855 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2857 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2859 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2862 module_call_init(MODULE_INIT_DEVICE
);
2864 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
2868 i
= select_watchdog(watchdog
);
2870 exit (i
== 1 ? 1 : 0);
2873 if (machine
->compat_props
) {
2874 qdev_prop_register_global_list(machine
->compat_props
);
2878 machine
->init(ram_size
, boot_devices
,
2879 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2881 cpu_synchronize_all_post_init();
2883 /* must be after terminal init, SDL library changes signal handlers */
2884 os_setup_signal_handling();
2888 current_machine
= machine
;
2890 /* init USB devices */
2892 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2896 /* init generic devices */
2897 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
2900 net_check_clients();
2902 /* just use the first displaystate for the moment */
2903 ds
= get_displaystate();
2907 if (display_type
== DT_DEFAULT
&& !display_remote
) {
2908 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
2909 display_type
= DT_SDL
;
2911 vnc_display
= "localhost:0,to=99";
2917 /* init local displays */
2918 switch (display_type
) {
2921 #if defined(CONFIG_CURSES)
2923 curses_display_init(ds
, full_screen
);
2926 #if defined(CONFIG_SDL)
2928 sdl_display_init(ds
, full_screen
, no_frame
);
2930 #elif defined(CONFIG_COCOA)
2932 cocoa_display_init(ds
, full_screen
);
2939 /* init remote displays */
2941 vnc_display_init(ds
);
2942 if (vnc_display_open(ds
, vnc_display
) < 0)
2945 if (show_vnc_port
) {
2946 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
2950 if (using_spice
&& !qxl_enabled
) {
2951 qemu_spice_display_init(ds
);
2957 dcl
= ds
->listeners
;
2958 while (dcl
!= NULL
) {
2959 if (dcl
->dpy_refresh
!= NULL
) {
2960 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
2961 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
2966 if (ds
->gui_timer
== NULL
) {
2967 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
2968 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
2970 text_consoles_set_display(ds
);
2972 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
2973 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
2978 qdev_machine_creation_done();
2980 if (rom_load_all() != 0) {
2981 fprintf(stderr
, "rom loading failed\n");
2985 qemu_register_reset((void *)qbus_reset_all
, sysbus_get_default());
2986 qemu_system_reset();
2988 if (load_vmstate(loadvm
) < 0) {
2994 int ret
= qemu_start_incoming_migration(incoming
);
2996 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3000 } else if (autostart
) {