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"
151 #include "fsdev/qemu-fsdev.h"
156 #include "qemu_socket.h"
158 #include "slirp/libslirp.h"
160 #include "qemu-queue.h"
162 #include "arch_init.h"
165 //#define DEBUG_SLIRP
167 #define DEFAULT_RAM_SIZE 128
169 #define MAX_VIRTIO_CONSOLES 1
171 static const char *data_dir
;
172 const char *bios_name
= NULL
;
173 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
174 DisplayType display_type
= DT_DEFAULT
;
175 const char* keyboard_layout
= NULL
;
177 const char *mem_path
= NULL
;
179 int mem_prealloc
= 0; /* force preallocation of physical target memory */
182 NICInfo nd_table
[MAX_NICS
];
185 int incoming_expected
; /* Started with -incoming and waiting for incoming */
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;
206 const char *vnc_display
;
207 int acpi_enabled
= 1;
213 int graphic_rotate
= 0;
214 uint8_t irq0override
= 1;
215 const char *watchdog
;
216 const char *option_rom
[MAX_OPTION_ROMS
];
218 int semihosting_enabled
= 0;
220 const char *qemu_name
;
223 unsigned int nb_prom_envs
= 0;
224 const char *prom_envs
[MAX_PROM_ENVS
];
228 uint64_t node_mem
[MAX_NODES
];
229 uint64_t node_cpumask
[MAX_NODES
];
231 static QEMUTimer
*nographic_timer
;
233 uint8_t qemu_uuid
[16];
235 static QEMUBootSetHandler
*boot_set_handler
;
236 static void *boot_set_opaque
;
238 static NotifierList exit_notifiers
=
239 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
243 enum xen_mode xen_mode
= XEN_EMULATE
;
245 static int default_serial
= 1;
246 static int default_parallel
= 1;
247 static int default_virtcon
= 1;
248 static int default_monitor
= 1;
249 static int default_vga
= 1;
250 static int default_floppy
= 1;
251 static int default_cdrom
= 1;
252 static int default_sdcard
= 1;
258 { .driver
= "isa-serial", .flag
= &default_serial
},
259 { .driver
= "isa-parallel", .flag
= &default_parallel
},
260 { .driver
= "isa-fdc", .flag
= &default_floppy
},
261 { .driver
= "ide-drive", .flag
= &default_cdrom
},
262 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
263 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
264 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
265 { .driver
= "VGA", .flag
= &default_vga
},
266 { .driver
= "cirrus-vga", .flag
= &default_vga
},
267 { .driver
= "vmware-svga", .flag
= &default_vga
},
270 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
272 const char *driver
= qemu_opt_get(opts
, "driver");
277 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
278 if (strcmp(default_list
[i
].driver
, driver
) != 0)
280 *(default_list
[i
].flag
) = 0;
285 /***********************************************************/
286 /* real time host monotonic timer */
288 /* compute with 96 bit intermediate result: (a*b)/c */
289 uint64_t muldiv64(uint64_t a
, uint32_t b
, uint32_t c
)
294 #ifdef HOST_WORDS_BIGENDIAN
304 rl
= (uint64_t)u
.l
.low
* (uint64_t)b
;
305 rh
= (uint64_t)u
.l
.high
* (uint64_t)b
;
308 res
.l
.low
= (((rh
% c
) << 32) + (rl
& 0xffffffff)) / c
;
312 /***********************************************************/
313 /* host time/date access */
314 void qemu_get_timedate(struct tm
*tm
, int offset
)
321 if (rtc_date_offset
== -1) {
325 ret
= localtime(&ti
);
327 ti
-= rtc_date_offset
;
331 memcpy(tm
, ret
, sizeof(struct tm
));
334 int qemu_timedate_diff(struct tm
*tm
)
338 if (rtc_date_offset
== -1)
340 seconds
= mktimegm(tm
);
342 seconds
= mktime(tm
);
344 seconds
= mktimegm(tm
) + rtc_date_offset
;
346 return seconds
- time(NULL
);
349 void rtc_change_mon_event(struct tm
*tm
)
353 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
354 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
355 qobject_decref(data
);
358 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
360 time_t rtc_start_date
;
363 if (!strcmp(startdate
, "now") && legacy
) {
364 rtc_date_offset
= -1;
366 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
374 } else if (sscanf(startdate
, "%d-%d-%d",
386 rtc_start_date
= mktimegm(&tm
);
387 if (rtc_start_date
== -1) {
389 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
390 "'2006-06-17T16:01:21' or '2006-06-17'\n");
393 rtc_date_offset
= time(NULL
) - rtc_start_date
;
397 static void configure_rtc(QemuOpts
*opts
)
401 value
= qemu_opt_get(opts
, "base");
403 if (!strcmp(value
, "utc")) {
405 } else if (!strcmp(value
, "localtime")) {
408 configure_rtc_date_offset(value
, 0);
411 value
= qemu_opt_get(opts
, "clock");
413 if (!strcmp(value
, "host")) {
414 rtc_clock
= host_clock
;
415 } else if (!strcmp(value
, "vm")) {
416 rtc_clock
= vm_clock
;
418 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
422 value
= qemu_opt_get(opts
, "driftfix");
424 if (!strcmp(value
, "slew")) {
426 } else if (!strcmp(value
, "none")) {
429 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
435 /***********************************************************/
436 /* Bluetooth support */
439 static struct HCIInfo
*hci_table
[MAX_NICS
];
441 static struct bt_vlan_s
{
442 struct bt_scatternet_s net
;
444 struct bt_vlan_s
*next
;
447 /* find or alloc a new bluetooth "VLAN" */
448 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
450 struct bt_vlan_s
**pvlan
, *vlan
;
451 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
455 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
457 pvlan
= &first_bt_vlan
;
458 while (*pvlan
!= NULL
)
459 pvlan
= &(*pvlan
)->next
;
464 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
468 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
473 static struct HCIInfo null_hci
= {
474 .cmd_send
= null_hci_send
,
475 .sco_send
= null_hci_send
,
476 .acl_send
= null_hci_send
,
477 .bdaddr_set
= null_hci_addr_set
,
480 struct HCIInfo
*qemu_next_hci(void)
482 if (cur_hci
== nb_hcis
)
485 return hci_table
[cur_hci
++];
488 static struct HCIInfo
*hci_init(const char *str
)
491 struct bt_scatternet_s
*vlan
= 0;
493 if (!strcmp(str
, "null"))
496 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
498 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
499 else if (!strncmp(str
, "hci", 3)) {
502 if (!strncmp(str
+ 3, ",vlan=", 6)) {
503 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
508 vlan
= qemu_find_bt_vlan(0);
510 return bt_new_hci(vlan
);
513 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
518 static int bt_hci_parse(const char *str
)
523 if (nb_hcis
>= MAX_NICS
) {
524 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
537 bdaddr
.b
[5] = 0x56 + nb_hcis
;
538 hci
->bdaddr_set(hci
, bdaddr
.b
);
540 hci_table
[nb_hcis
++] = hci
;
545 static void bt_vhci_add(int vlan_id
)
547 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
550 fprintf(stderr
, "qemu: warning: adding a VHCI to "
551 "an empty scatternet %i\n", vlan_id
);
553 bt_vhci_init(bt_new_hci(vlan
));
556 static struct bt_device_s
*bt_device_add(const char *opt
)
558 struct bt_scatternet_s
*vlan
;
560 char *endp
= strstr(opt
, ",vlan=");
561 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
564 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
567 vlan_id
= strtol(endp
+ 6, &endp
, 0);
569 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
574 vlan
= qemu_find_bt_vlan(vlan_id
);
577 fprintf(stderr
, "qemu: warning: adding a slave device to "
578 "an empty scatternet %i\n", vlan_id
);
580 if (!strcmp(devname
, "keyboard"))
581 return bt_keyboard_init(vlan
);
583 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
587 static int bt_parse(const char *opt
)
589 const char *endp
, *p
;
592 if (strstart(opt
, "hci", &endp
)) {
593 if (!*endp
|| *endp
== ',') {
595 if (!strstart(endp
, ",vlan=", 0))
598 return bt_hci_parse(opt
);
600 } else if (strstart(opt
, "vhci", &endp
)) {
601 if (!*endp
|| *endp
== ',') {
603 if (strstart(endp
, ",vlan=", &p
)) {
604 vlan
= strtol(p
, (char **) &endp
, 0);
606 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
610 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
619 } else if (strstart(opt
, "device:", &endp
))
620 return !bt_device_add(endp
);
622 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
626 /***********************************************************/
627 /* QEMU Block devices */
629 #define HD_ALIAS "index=%d,media=disk"
630 #define CDROM_ALIAS "index=2,media=cdrom"
631 #define FD_ALIAS "index=%d,if=floppy"
632 #define PFLASH_ALIAS "if=pflash"
633 #define MTD_ALIAS "if=mtd"
634 #define SD_ALIAS "index=0,if=sd"
636 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
638 int *use_scsi
= opaque
;
641 if (drive_init(opts
, *use_scsi
, &fatal_error
) == NULL
) {
648 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
650 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
651 qemu_opt_set(opts
, "snapshot", "on");
656 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
658 boot_set_handler
= func
;
659 boot_set_opaque
= opaque
;
662 int qemu_boot_set(const char *boot_devices
)
664 if (!boot_set_handler
) {
667 return boot_set_handler(boot_set_opaque
, boot_devices
);
670 static void validate_bootdevices(char *devices
)
672 /* We just do some generic consistency checks */
676 for (p
= devices
; *p
!= '\0'; p
++) {
677 /* Allowed boot devices are:
678 * a-b: floppy disk drives
679 * c-f: IDE disk drives
680 * g-m: machine implementation dependant drives
681 * n-p: network devices
682 * It's up to each machine implementation to check if the given boot
683 * devices match the actual hardware implementation and firmware
686 if (*p
< 'a' || *p
> 'p') {
687 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
690 if (bitmap
& (1 << (*p
- 'a'))) {
691 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
694 bitmap
|= 1 << (*p
- 'a');
698 static void restore_boot_devices(void *opaque
)
700 char *standard_boot_devices
= opaque
;
701 static int first
= 1;
703 /* Restore boot order and remove ourselves after the first boot */
709 qemu_boot_set(standard_boot_devices
);
711 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
712 qemu_free(standard_boot_devices
);
715 static void numa_add(const char *optarg
)
719 unsigned long long value
, endvalue
;
722 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
723 if (!strcmp(option
, "node")) {
724 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
725 nodenr
= nb_numa_nodes
;
727 nodenr
= strtoull(option
, NULL
, 10);
730 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
731 node_mem
[nodenr
] = 0;
733 value
= strtoull(option
, &endptr
, 0);
735 case 0: case 'M': case 'm':
742 node_mem
[nodenr
] = value
;
744 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
745 node_cpumask
[nodenr
] = 0;
747 value
= strtoull(option
, &endptr
, 10);
750 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
752 if (*endptr
== '-') {
753 endvalue
= strtoull(endptr
+1, &endptr
, 10);
754 if (endvalue
>= 63) {
757 "only 63 CPUs in NUMA mode supported.\n");
759 value
= (2ULL << endvalue
) - (1ULL << value
);
761 value
= 1ULL << value
;
764 node_cpumask
[nodenr
] = value
;
771 static void smp_parse(const char *optarg
)
773 int smp
, sockets
= 0, threads
= 0, cores
= 0;
777 smp
= strtoul(optarg
, &endptr
, 10);
778 if (endptr
!= optarg
) {
779 if (*endptr
== ',') {
783 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
784 sockets
= strtoull(option
, NULL
, 10);
785 if (get_param_value(option
, 128, "cores", endptr
) != 0)
786 cores
= strtoull(option
, NULL
, 10);
787 if (get_param_value(option
, 128, "threads", endptr
) != 0)
788 threads
= strtoull(option
, NULL
, 10);
789 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
790 max_cpus
= strtoull(option
, NULL
, 10);
792 /* compute missing values, prefer sockets over cores over threads */
793 if (smp
== 0 || sockets
== 0) {
794 sockets
= sockets
> 0 ? sockets
: 1;
795 cores
= cores
> 0 ? cores
: 1;
796 threads
= threads
> 0 ? threads
: 1;
798 smp
= cores
* threads
* sockets
;
802 threads
= threads
> 0 ? threads
: 1;
803 cores
= smp
/ (sockets
* threads
);
805 threads
= smp
/ (cores
* sockets
);
809 smp_cores
= cores
> 0 ? cores
: 1;
810 smp_threads
= threads
> 0 ? threads
: 1;
815 /***********************************************************/
818 static int usb_device_add(const char *devname
)
821 USBDevice
*dev
= NULL
;
826 /* drivers with .usbdevice_name entry in USBDeviceInfo */
827 dev
= usbdevice_create(devname
);
832 if (strstart(devname
, "host:", &p
)) {
833 dev
= usb_host_device_open(p
);
834 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
835 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
836 bt_new_hci(qemu_find_bt_vlan(0)));
847 static int usb_device_del(const char *devname
)
852 if (strstart(devname
, "host:", &p
))
853 return usb_host_device_close(p
);
858 p
= strchr(devname
, '.');
861 bus_num
= strtoul(devname
, NULL
, 0);
862 addr
= strtoul(p
+ 1, NULL
, 0);
864 return usb_device_delete_addr(bus_num
, addr
);
867 static int usb_parse(const char *cmdline
)
870 r
= usb_device_add(cmdline
);
872 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
877 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
879 const char *devname
= qdict_get_str(qdict
, "devname");
880 if (usb_device_add(devname
) < 0) {
881 error_report("could not add USB device '%s'", devname
);
885 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
887 const char *devname
= qdict_get_str(qdict
, "devname");
888 if (usb_device_del(devname
) < 0) {
889 error_report("could not delete USB device '%s'", devname
);
893 /***********************************************************/
896 static struct pcmcia_socket_entry_s
{
897 PCMCIASocket
*socket
;
898 struct pcmcia_socket_entry_s
*next
;
899 } *pcmcia_sockets
= 0;
901 void pcmcia_socket_register(PCMCIASocket
*socket
)
903 struct pcmcia_socket_entry_s
*entry
;
905 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
906 entry
->socket
= socket
;
907 entry
->next
= pcmcia_sockets
;
908 pcmcia_sockets
= entry
;
911 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
913 struct pcmcia_socket_entry_s
*entry
, **ptr
;
915 ptr
= &pcmcia_sockets
;
916 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
917 if (entry
->socket
== socket
) {
923 void pcmcia_info(Monitor
*mon
)
925 struct pcmcia_socket_entry_s
*iter
;
928 monitor_printf(mon
, "No PCMCIA sockets\n");
930 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
931 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
932 iter
->socket
->attached
? iter
->socket
->card_string
:
936 /***********************************************************/
939 typedef struct IOHandlerRecord
{
941 IOCanReadHandler
*fd_read_poll
;
948 QLIST_ENTRY(IOHandlerRecord
) next
;
951 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
952 QLIST_HEAD_INITIALIZER(io_handlers
);
955 /* XXX: fd_read_poll should be suppressed, but an API change is
956 necessary in the character devices to suppress fd_can_read(). */
957 int qemu_set_fd_handler2(int fd
,
958 IOCanReadHandler
*fd_read_poll
,
963 IOHandlerRecord
*ioh
;
965 if (!fd_read
&& !fd_write
) {
966 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
973 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
977 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
978 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
981 ioh
->fd_read_poll
= fd_read_poll
;
982 ioh
->fd_read
= fd_read
;
983 ioh
->fd_write
= fd_write
;
984 ioh
->opaque
= opaque
;
990 int qemu_set_fd_handler(int fd
,
995 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
998 /***********************************************************/
999 /* machine registration */
1001 static QEMUMachine
*first_machine
= NULL
;
1002 QEMUMachine
*current_machine
= NULL
;
1004 int qemu_register_machine(QEMUMachine
*m
)
1007 pm
= &first_machine
;
1015 static QEMUMachine
*find_machine(const char *name
)
1019 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1020 if (!strcmp(m
->name
, name
))
1022 if (m
->alias
&& !strcmp(m
->alias
, name
))
1028 static QEMUMachine
*find_default_machine(void)
1032 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1033 if (m
->is_default
) {
1040 /***********************************************************/
1041 /* main execution loop */
1043 static void gui_update(void *opaque
)
1045 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1046 DisplayState
*ds
= opaque
;
1047 DisplayChangeListener
*dcl
= ds
->listeners
;
1049 qemu_flush_coalesced_mmio_buffer();
1052 while (dcl
!= NULL
) {
1053 if (dcl
->gui_timer_interval
&&
1054 dcl
->gui_timer_interval
< interval
)
1055 interval
= dcl
->gui_timer_interval
;
1058 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1061 static void nographic_update(void *opaque
)
1063 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1065 qemu_flush_coalesced_mmio_buffer();
1066 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1069 struct vm_change_state_entry
{
1070 VMChangeStateHandler
*cb
;
1072 QLIST_ENTRY (vm_change_state_entry
) entries
;
1075 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1077 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1080 VMChangeStateEntry
*e
;
1082 e
= qemu_mallocz(sizeof (*e
));
1086 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1090 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1092 QLIST_REMOVE (e
, entries
);
1096 void vm_state_notify(int running
, int reason
)
1098 VMChangeStateEntry
*e
;
1100 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1101 e
->cb(e
->opaque
, running
, reason
);
1110 vm_state_notify(1, 0);
1112 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1116 /* reset/shutdown handler */
1118 typedef struct QEMUResetEntry
{
1119 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1120 QEMUResetHandler
*func
;
1124 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1125 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1126 static int reset_requested
;
1127 static int shutdown_requested
;
1128 static int powerdown_requested
;
1129 int debug_requested
;
1130 int vmstop_requested
;
1132 int qemu_shutdown_requested(void)
1134 int r
= shutdown_requested
;
1135 shutdown_requested
= 0;
1139 int qemu_reset_requested(void)
1141 int r
= reset_requested
;
1142 reset_requested
= 0;
1146 int qemu_powerdown_requested(void)
1148 int r
= powerdown_requested
;
1149 powerdown_requested
= 0;
1153 static int qemu_debug_requested(void)
1155 int r
= debug_requested
;
1156 debug_requested
= 0;
1160 static int qemu_vmstop_requested(void)
1162 int r
= vmstop_requested
;
1163 vmstop_requested
= 0;
1167 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1169 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1172 re
->opaque
= opaque
;
1173 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1176 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1180 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1181 if (re
->func
== func
&& re
->opaque
== opaque
) {
1182 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1189 void qemu_system_reset(void)
1191 QEMUResetEntry
*re
, *nre
;
1193 /* reset all devices */
1194 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1195 re
->func(re
->opaque
);
1197 monitor_protocol_event(QEVENT_RESET
, NULL
);
1198 cpu_synchronize_all_post_reset();
1201 void qemu_system_reset_request(void)
1204 shutdown_requested
= 1;
1206 reset_requested
= 1;
1208 qemu_notify_event();
1211 void qemu_system_shutdown_request(void)
1213 shutdown_requested
= 1;
1214 qemu_notify_event();
1217 void qemu_system_powerdown_request(void)
1219 powerdown_requested
= 1;
1220 qemu_notify_event();
1223 void main_loop_wait(int nonblocking
)
1225 IOHandlerRecord
*ioh
;
1226 fd_set rfds
, wfds
, xfds
;
1234 timeout
= qemu_calculate_timeout();
1235 qemu_bh_update_timeout(&timeout
);
1238 os_host_main_loop_wait(&timeout
);
1240 /* poll any events */
1241 /* XXX: separate device handlers from system ones */
1246 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1250 (!ioh
->fd_read_poll
||
1251 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1252 FD_SET(ioh
->fd
, &rfds
);
1256 if (ioh
->fd_write
) {
1257 FD_SET(ioh
->fd
, &wfds
);
1263 tv
.tv_sec
= timeout
/ 1000;
1264 tv
.tv_usec
= (timeout
% 1000) * 1000;
1266 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1268 qemu_mutex_unlock_iothread();
1269 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1270 qemu_mutex_lock_iothread();
1272 IOHandlerRecord
*pioh
;
1274 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1276 QLIST_REMOVE(ioh
, next
);
1280 if (ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1281 ioh
->fd_read(ioh
->opaque
);
1283 if (ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1284 ioh
->fd_write(ioh
->opaque
);
1289 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1291 qemu_run_all_timers();
1293 /* Check bottom-halves last in case any of the earlier events triggered
1299 static int vm_can_run(void)
1301 if (powerdown_requested
)
1303 if (reset_requested
)
1305 if (shutdown_requested
)
1307 if (debug_requested
)
1312 qemu_irq qemu_system_powerdown
;
1314 static void main_loop(void)
1318 qemu_main_loop_start();
1322 bool nonblocking
= false;
1323 #ifdef CONFIG_PROFILER
1326 #ifndef CONFIG_IOTHREAD
1327 nonblocking
= cpu_exec_all();
1329 #ifdef CONFIG_PROFILER
1330 ti
= profile_getclock();
1332 main_loop_wait(nonblocking
);
1333 #ifdef CONFIG_PROFILER
1334 dev_time
+= profile_getclock() - ti
;
1336 } while (vm_can_run());
1338 if ((r
= qemu_debug_requested())) {
1341 if (qemu_shutdown_requested()) {
1342 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1349 if (qemu_reset_requested()) {
1351 qemu_system_reset();
1354 if (qemu_powerdown_requested()) {
1355 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1356 qemu_irq_raise(qemu_system_powerdown
);
1358 if ((r
= qemu_vmstop_requested())) {
1366 static void version(void)
1368 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1371 static void help(int exitcode
)
1373 const char *options_help
=
1374 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1376 #define DEFHEADING(text) stringify(text) "\n"
1377 #include "qemu-options.def"
1383 printf("usage: %s [options] [disk_image]\n"
1385 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1388 "During emulation, the following keys are useful:\n"
1389 "ctrl-alt-f toggle full screen\n"
1390 "ctrl-alt-n switch to virtual console 'n'\n"
1391 "ctrl-alt toggle mouse and keyboard grab\n"
1393 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1399 #define HAS_ARG 0x0001
1401 typedef struct QEMUOption
{
1408 static const QEMUOption qemu_options
[] = {
1409 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1410 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1411 { option, opt_arg, opt_enum, arch_mask },
1412 #define DEFHEADING(text)
1413 #include "qemu-options.def"
1419 static void select_vgahw (const char *p
)
1424 vga_interface_type
= VGA_NONE
;
1425 if (strstart(p
, "std", &opts
)) {
1426 vga_interface_type
= VGA_STD
;
1427 } else if (strstart(p
, "cirrus", &opts
)) {
1428 vga_interface_type
= VGA_CIRRUS
;
1429 } else if (strstart(p
, "vmware", &opts
)) {
1430 vga_interface_type
= VGA_VMWARE
;
1431 } else if (strstart(p
, "xenfb", &opts
)) {
1432 vga_interface_type
= VGA_XENFB
;
1433 } else if (!strstart(p
, "none", &opts
)) {
1435 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1439 const char *nextopt
;
1441 if (strstart(opts
, ",retrace=", &nextopt
)) {
1443 if (strstart(opts
, "dumb", &nextopt
))
1444 vga_retrace_method
= VGA_RETRACE_DUMB
;
1445 else if (strstart(opts
, "precise", &nextopt
))
1446 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1447 else goto invalid_vga
;
1448 } else goto invalid_vga
;
1453 static int balloon_parse(const char *arg
)
1457 if (strcmp(arg
, "none") == 0) {
1461 if (!strncmp(arg
, "virtio", 6)) {
1462 if (arg
[6] == ',') {
1463 /* have params -> parse them */
1464 opts
= qemu_opts_parse(&qemu_device_opts
, arg
+7, 0);
1468 /* create empty opts */
1469 opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1471 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1478 char *qemu_find_file(int type
, const char *name
)
1484 /* If name contains path separators then try it as a straight path. */
1485 if ((strchr(name
, '/') || strchr(name
, '\\'))
1486 && access(name
, R_OK
) == 0) {
1487 return qemu_strdup(name
);
1490 case QEMU_FILE_TYPE_BIOS
:
1493 case QEMU_FILE_TYPE_KEYMAP
:
1494 subdir
= "keymaps/";
1499 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1500 buf
= qemu_mallocz(len
);
1501 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1502 if (access(buf
, R_OK
)) {
1509 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1511 return qdev_device_help(opts
);
1514 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1518 dev
= qdev_device_add(opts
);
1524 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1526 CharDriverState
*chr
;
1528 chr
= qemu_chr_open_opts(opts
, NULL
);
1534 #ifdef CONFIG_VIRTFS
1535 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1538 ret
= qemu_fsdev_add(opts
);
1544 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1546 CharDriverState
*chr
;
1547 const char *chardev
;
1551 mode
= qemu_opt_get(opts
, "mode");
1555 if (strcmp(mode
, "readline") == 0) {
1556 flags
= MONITOR_USE_READLINE
;
1557 } else if (strcmp(mode
, "control") == 0) {
1558 flags
= MONITOR_USE_CONTROL
;
1560 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1564 if (qemu_opt_get_bool(opts
, "default", 0))
1565 flags
|= MONITOR_IS_DEFAULT
;
1567 chardev
= qemu_opt_get(opts
, "chardev");
1568 chr
= qemu_chr_find(chardev
);
1570 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1574 monitor_init(chr
, flags
);
1578 static void monitor_parse(const char *optarg
, const char *mode
)
1580 static int monitor_device_index
= 0;
1586 if (strstart(optarg
, "chardev:", &p
)) {
1587 snprintf(label
, sizeof(label
), "%s", p
);
1589 snprintf(label
, sizeof(label
), "compat_monitor%d",
1590 monitor_device_index
);
1591 if (monitor_device_index
== 0) {
1594 opts
= qemu_chr_parse_compat(label
, optarg
);
1596 fprintf(stderr
, "parse error: %s\n", optarg
);
1601 opts
= qemu_opts_create(&qemu_mon_opts
, label
, 1);
1603 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1606 qemu_opt_set(opts
, "mode", mode
);
1607 qemu_opt_set(opts
, "chardev", label
);
1609 qemu_opt_set(opts
, "default", "on");
1610 monitor_device_index
++;
1613 struct device_config
{
1615 DEV_USB
, /* -usbdevice */
1617 DEV_SERIAL
, /* -serial */
1618 DEV_PARALLEL
, /* -parallel */
1619 DEV_VIRTCON
, /* -virtioconsole */
1620 DEV_DEBUGCON
, /* -debugcon */
1622 const char *cmdline
;
1623 QTAILQ_ENTRY(device_config
) next
;
1625 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1627 static void add_device_config(int type
, const char *cmdline
)
1629 struct device_config
*conf
;
1631 conf
= qemu_mallocz(sizeof(*conf
));
1633 conf
->cmdline
= cmdline
;
1634 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1637 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1639 struct device_config
*conf
;
1642 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1643 if (conf
->type
!= type
)
1645 rc
= func(conf
->cmdline
);
1652 static int serial_parse(const char *devname
)
1654 static int index
= 0;
1657 if (strcmp(devname
, "none") == 0)
1659 if (index
== MAX_SERIAL_PORTS
) {
1660 fprintf(stderr
, "qemu: too many serial ports\n");
1663 snprintf(label
, sizeof(label
), "serial%d", index
);
1664 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1665 if (!serial_hds
[index
]) {
1666 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1667 devname
, strerror(errno
));
1674 static int parallel_parse(const char *devname
)
1676 static int index
= 0;
1679 if (strcmp(devname
, "none") == 0)
1681 if (index
== MAX_PARALLEL_PORTS
) {
1682 fprintf(stderr
, "qemu: too many parallel ports\n");
1685 snprintf(label
, sizeof(label
), "parallel%d", index
);
1686 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1687 if (!parallel_hds
[index
]) {
1688 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1689 devname
, strerror(errno
));
1696 static int virtcon_parse(const char *devname
)
1698 static int index
= 0;
1700 QemuOpts
*bus_opts
, *dev_opts
;
1702 if (strcmp(devname
, "none") == 0)
1704 if (index
== MAX_VIRTIO_CONSOLES
) {
1705 fprintf(stderr
, "qemu: too many virtio consoles\n");
1709 bus_opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1710 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1712 dev_opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1713 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1715 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1716 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1717 if (!virtcon_hds
[index
]) {
1718 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1719 devname
, strerror(errno
));
1722 qemu_opt_set(dev_opts
, "chardev", label
);
1728 static int debugcon_parse(const char *devname
)
1732 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1735 opts
= qemu_opts_create(&qemu_device_opts
, "debugcon", 1);
1737 fprintf(stderr
, "qemu: already have a debugcon device\n");
1740 qemu_opt_set(opts
, "driver", "isa-debugcon");
1741 qemu_opt_set(opts
, "chardev", "debugcon");
1745 void qemu_add_exit_notifier(Notifier
*notify
)
1747 notifier_list_add(&exit_notifiers
, notify
);
1750 void qemu_remove_exit_notifier(Notifier
*notify
)
1752 notifier_list_remove(&exit_notifiers
, notify
);
1755 static void qemu_run_exit_notifiers(void)
1757 notifier_list_notify(&exit_notifiers
);
1760 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1761 const char **poptarg
, int *poptind
)
1763 const QEMUOption
*popt
;
1764 int optind
= *poptind
;
1765 char *r
= argv
[optind
];
1768 loc_set_cmdline(argv
, optind
, 1);
1770 /* Treat --foo the same as -foo. */
1773 popt
= qemu_options
;
1776 error_report("invalid option");
1779 if (!strcmp(popt
->name
, r
+ 1))
1783 if (popt
->flags
& HAS_ARG
) {
1784 if (optind
>= argc
) {
1785 error_report("requires an argument");
1788 optarg
= argv
[optind
++];
1789 loc_set_cmdline(argv
, optind
- 2, 2);
1800 int main(int argc
, char **argv
, char **envp
)
1802 const char *gdbstub_dev
= NULL
;
1804 int snapshot
, linux_boot
;
1805 const char *icount_option
= NULL
;
1806 const char *initrd_filename
;
1807 const char *kernel_filename
, *kernel_cmdline
;
1808 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1810 DisplayChangeListener
*dcl
;
1811 int cyls
, heads
, secs
, translation
;
1812 QemuOpts
*hda_opts
= NULL
, *opts
;
1815 const char *loadvm
= NULL
;
1816 QEMUMachine
*machine
;
1817 const char *cpu_model
;
1819 const char *pid_file
= NULL
;
1820 const char *incoming
= NULL
;
1821 int show_vnc_port
= 0;
1824 atexit(qemu_run_exit_notifiers
);
1825 error_set_progname(argv
[0]);
1829 qemu_cache_utils_init(envp
);
1831 QLIST_INIT (&vm_change_state_head
);
1832 os_setup_early_signal_handling();
1834 module_call_init(MODULE_INIT_MACHINE
);
1835 machine
= find_default_machine();
1837 initrd_filename
= NULL
;
1840 kernel_filename
= NULL
;
1841 kernel_cmdline
= "";
1842 cyls
= heads
= secs
= 0;
1843 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1845 for (i
= 0; i
< MAX_NODES
; i
++) {
1847 node_cpumask
[i
] = 0;
1856 /* first pass of option parsing */
1858 while (optind
< argc
) {
1859 if (argv
[optind
][0] != '-') {
1864 const QEMUOption
*popt
;
1866 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1867 switch (popt
->index
) {
1868 case QEMU_OPTION_nodefconfig
:
1878 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1879 if (ret
< 0 && ret
!= -ENOENT
) {
1883 ret
= qemu_read_config_file(arch_config_name
);
1884 if (ret
< 0 && ret
!= -ENOENT
) {
1890 /* second pass of option parsing */
1895 if (argv
[optind
][0] != '-') {
1896 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1898 const QEMUOption
*popt
;
1900 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1901 if (!(popt
->arch_mask
& arch_type
)) {
1902 printf("Option %s not supported for this target\n", popt
->name
);
1905 switch(popt
->index
) {
1907 machine
= find_machine(optarg
);
1910 printf("Supported machines are:\n");
1911 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1913 printf("%-10s %s (alias of %s)\n",
1914 m
->alias
, m
->desc
, m
->name
);
1915 printf("%-10s %s%s\n",
1917 m
->is_default
? " (default)" : "");
1919 exit(*optarg
!= '?');
1922 case QEMU_OPTION_cpu
:
1923 /* hw initialization will check this */
1924 if (*optarg
== '?') {
1925 list_cpus(stdout
, &fprintf
, optarg
);
1931 case QEMU_OPTION_initrd
:
1932 initrd_filename
= optarg
;
1934 case QEMU_OPTION_hda
:
1936 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
1938 hda_opts
= drive_add(optarg
, HD_ALIAS
1939 ",cyls=%d,heads=%d,secs=%d%s",
1940 0, cyls
, heads
, secs
,
1941 translation
== BIOS_ATA_TRANSLATION_LBA
?
1943 translation
== BIOS_ATA_TRANSLATION_NONE
?
1944 ",trans=none" : "");
1946 case QEMU_OPTION_hdb
:
1947 case QEMU_OPTION_hdc
:
1948 case QEMU_OPTION_hdd
:
1949 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
1951 case QEMU_OPTION_drive
:
1952 drive_add(NULL
, "%s", optarg
);
1954 case QEMU_OPTION_set
:
1955 if (qemu_set_option(optarg
) != 0)
1958 case QEMU_OPTION_global
:
1959 if (qemu_global_option(optarg
) != 0)
1962 case QEMU_OPTION_mtdblock
:
1963 drive_add(optarg
, MTD_ALIAS
);
1965 case QEMU_OPTION_sd
:
1966 drive_add(optarg
, SD_ALIAS
);
1968 case QEMU_OPTION_pflash
:
1969 drive_add(optarg
, PFLASH_ALIAS
);
1971 case QEMU_OPTION_snapshot
:
1974 case QEMU_OPTION_hdachs
:
1978 cyls
= strtol(p
, (char **)&p
, 0);
1979 if (cyls
< 1 || cyls
> 16383)
1984 heads
= strtol(p
, (char **)&p
, 0);
1985 if (heads
< 1 || heads
> 16)
1990 secs
= strtol(p
, (char **)&p
, 0);
1991 if (secs
< 1 || secs
> 63)
1995 if (!strcmp(p
, "none"))
1996 translation
= BIOS_ATA_TRANSLATION_NONE
;
1997 else if (!strcmp(p
, "lba"))
1998 translation
= BIOS_ATA_TRANSLATION_LBA
;
1999 else if (!strcmp(p
, "auto"))
2000 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2003 } else if (*p
!= '\0') {
2005 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2008 if (hda_opts
!= NULL
) {
2010 snprintf(num
, sizeof(num
), "%d", cyls
);
2011 qemu_opt_set(hda_opts
, "cyls", num
);
2012 snprintf(num
, sizeof(num
), "%d", heads
);
2013 qemu_opt_set(hda_opts
, "heads", num
);
2014 snprintf(num
, sizeof(num
), "%d", secs
);
2015 qemu_opt_set(hda_opts
, "secs", num
);
2016 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2017 qemu_opt_set(hda_opts
, "trans", "lba");
2018 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2019 qemu_opt_set(hda_opts
, "trans", "none");
2023 case QEMU_OPTION_numa
:
2024 if (nb_numa_nodes
>= MAX_NODES
) {
2025 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2030 case QEMU_OPTION_nographic
:
2031 display_type
= DT_NOGRAPHIC
;
2033 #ifdef CONFIG_CURSES
2034 case QEMU_OPTION_curses
:
2035 display_type
= DT_CURSES
;
2038 case QEMU_OPTION_portrait
:
2041 case QEMU_OPTION_kernel
:
2042 kernel_filename
= optarg
;
2044 case QEMU_OPTION_append
:
2045 kernel_cmdline
= optarg
;
2047 case QEMU_OPTION_cdrom
:
2048 drive_add(optarg
, CDROM_ALIAS
);
2050 case QEMU_OPTION_boot
:
2052 static const char * const params
[] = {
2053 "order", "once", "menu", NULL
2055 char buf
[sizeof(boot_devices
)];
2056 char *standard_boot_devices
;
2059 if (!strchr(optarg
, '=')) {
2061 pstrcpy(buf
, sizeof(buf
), optarg
);
2062 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2064 "qemu: unknown boot parameter '%s' in '%s'\n",
2070 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2071 validate_bootdevices(buf
);
2072 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2075 if (get_param_value(buf
, sizeof(buf
),
2077 validate_bootdevices(buf
);
2078 standard_boot_devices
= qemu_strdup(boot_devices
);
2079 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2080 qemu_register_reset(restore_boot_devices
,
2081 standard_boot_devices
);
2083 if (get_param_value(buf
, sizeof(buf
),
2085 if (!strcmp(buf
, "on")) {
2087 } else if (!strcmp(buf
, "off")) {
2091 "qemu: invalid option value '%s'\n",
2099 case QEMU_OPTION_fda
:
2100 case QEMU_OPTION_fdb
:
2101 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2103 case QEMU_OPTION_no_fd_bootchk
:
2106 case QEMU_OPTION_netdev
:
2107 if (net_client_parse(&qemu_netdev_opts
, optarg
) == -1) {
2111 case QEMU_OPTION_net
:
2112 if (net_client_parse(&qemu_net_opts
, optarg
) == -1) {
2117 case QEMU_OPTION_tftp
:
2118 legacy_tftp_prefix
= optarg
;
2120 case QEMU_OPTION_bootp
:
2121 legacy_bootp_filename
= optarg
;
2123 case QEMU_OPTION_redir
:
2124 if (net_slirp_redir(optarg
) < 0)
2128 case QEMU_OPTION_bt
:
2129 add_device_config(DEV_BT
, optarg
);
2131 case QEMU_OPTION_audio_help
:
2132 if (!(audio_available())) {
2133 printf("Option %s not supported for this target\n", popt
->name
);
2139 case QEMU_OPTION_soundhw
:
2140 if (!(audio_available())) {
2141 printf("Option %s not supported for this target\n", popt
->name
);
2144 select_soundhw (optarg
);
2149 case QEMU_OPTION_version
:
2153 case QEMU_OPTION_m
: {
2157 value
= strtoul(optarg
, &ptr
, 10);
2159 case 0: case 'M': case 'm':
2166 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2170 /* On 32-bit hosts, QEMU is limited by virtual address space */
2171 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2172 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2175 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2176 fprintf(stderr
, "qemu: ram size too large\n");
2182 case QEMU_OPTION_mempath
:
2186 case QEMU_OPTION_mem_prealloc
:
2191 set_cpu_log(optarg
);
2194 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2196 case QEMU_OPTION_gdb
:
2197 gdbstub_dev
= optarg
;
2202 case QEMU_OPTION_bios
:
2205 case QEMU_OPTION_singlestep
:
2212 keyboard_layout
= optarg
;
2214 case QEMU_OPTION_localtime
:
2217 case QEMU_OPTION_vga
:
2218 select_vgahw (optarg
);
2225 w
= strtol(p
, (char **)&p
, 10);
2228 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2234 h
= strtol(p
, (char **)&p
, 10);
2239 depth
= strtol(p
, (char **)&p
, 10);
2240 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2241 depth
!= 24 && depth
!= 32)
2243 } else if (*p
== '\0') {
2244 depth
= graphic_depth
;
2251 graphic_depth
= depth
;
2254 case QEMU_OPTION_echr
:
2257 term_escape_char
= strtol(optarg
, &r
, 0);
2259 printf("Bad argument to echr\n");
2262 case QEMU_OPTION_monitor
:
2263 monitor_parse(optarg
, "readline");
2264 default_monitor
= 0;
2266 case QEMU_OPTION_qmp
:
2267 monitor_parse(optarg
, "control");
2268 default_monitor
= 0;
2270 case QEMU_OPTION_mon
:
2271 opts
= qemu_opts_parse(&qemu_mon_opts
, optarg
, 1);
2275 default_monitor
= 0;
2277 case QEMU_OPTION_chardev
:
2278 opts
= qemu_opts_parse(&qemu_chardev_opts
, optarg
, 1);
2283 #ifdef CONFIG_VIRTFS
2284 case QEMU_OPTION_fsdev
:
2285 opts
= qemu_opts_parse(&qemu_fsdev_opts
, optarg
, 1);
2287 fprintf(stderr
, "parse error: %s\n", optarg
);
2291 case QEMU_OPTION_virtfs
: {
2292 char *arg_fsdev
= NULL
;
2293 char *arg_9p
= NULL
;
2296 opts
= qemu_opts_parse(&qemu_virtfs_opts
, optarg
, 1);
2298 fprintf(stderr
, "parse error: %s\n", optarg
);
2302 if (qemu_opt_get(opts
, "fstype") == NULL
||
2303 qemu_opt_get(opts
, "mount_tag") == NULL
||
2304 qemu_opt_get(opts
, "path") == NULL
||
2305 qemu_opt_get(opts
, "security_model") == NULL
) {
2306 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2307 "security_model=[mapped|passthrough],"
2312 len
= strlen(",id=,path=,security_model=");
2313 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2314 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2315 len
+= strlen(qemu_opt_get(opts
, "path"));
2316 len
+= strlen(qemu_opt_get(opts
, "security_model"));
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,security_model=%s",
2326 qemu_opt_get(opts
, "fstype"),
2327 qemu_opt_get(opts
, "mount_tag"),
2328 qemu_opt_get(opts
, "path"),
2329 qemu_opt_get(opts
, "security_model"));
2331 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2332 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2333 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2336 fprintf(stderr
, "No memory to parse -device for %s\n",
2341 sprintf(arg_9p
, "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2342 qemu_opt_get(opts
, "mount_tag"),
2343 qemu_opt_get(opts
, "mount_tag"));
2345 if (!qemu_opts_parse(&qemu_fsdev_opts
, arg_fsdev
, 1)) {
2346 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2350 if (!qemu_opts_parse(&qemu_device_opts
, arg_9p
, 1)) {
2351 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2355 qemu_free(arg_fsdev
);
2360 case QEMU_OPTION_serial
:
2361 add_device_config(DEV_SERIAL
, optarg
);
2363 if (strncmp(optarg
, "mon:", 4) == 0) {
2364 default_monitor
= 0;
2367 case QEMU_OPTION_watchdog
:
2370 "qemu: only one watchdog option may be given\n");
2375 case QEMU_OPTION_watchdog_action
:
2376 if (select_watchdog_action(optarg
) == -1) {
2377 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2381 case QEMU_OPTION_virtiocon
:
2382 add_device_config(DEV_VIRTCON
, optarg
);
2383 default_virtcon
= 0;
2384 if (strncmp(optarg
, "mon:", 4) == 0) {
2385 default_monitor
= 0;
2388 case QEMU_OPTION_parallel
:
2389 add_device_config(DEV_PARALLEL
, optarg
);
2390 default_parallel
= 0;
2391 if (strncmp(optarg
, "mon:", 4) == 0) {
2392 default_monitor
= 0;
2395 case QEMU_OPTION_debugcon
:
2396 add_device_config(DEV_DEBUGCON
, optarg
);
2398 case QEMU_OPTION_loadvm
:
2401 case QEMU_OPTION_full_screen
:
2405 case QEMU_OPTION_no_frame
:
2408 case QEMU_OPTION_alt_grab
:
2411 case QEMU_OPTION_ctrl_grab
:
2414 case QEMU_OPTION_no_quit
:
2417 case QEMU_OPTION_sdl
:
2418 display_type
= DT_SDL
;
2421 case QEMU_OPTION_pidfile
:
2424 case QEMU_OPTION_win2k_hack
:
2425 win2k_install_hack
= 1;
2427 case QEMU_OPTION_rtc_td_hack
:
2430 case QEMU_OPTION_acpitable
:
2431 do_acpitable_option(optarg
);
2433 case QEMU_OPTION_smbios
:
2434 do_smbios_option(optarg
);
2436 case QEMU_OPTION_enable_kvm
:
2439 case QEMU_OPTION_usb
:
2442 case QEMU_OPTION_usbdevice
:
2444 add_device_config(DEV_USB
, optarg
);
2446 case QEMU_OPTION_device
:
2447 if (!qemu_opts_parse(&qemu_device_opts
, optarg
, 1)) {
2451 case QEMU_OPTION_smp
:
2454 fprintf(stderr
, "Invalid number of CPUs\n");
2457 if (max_cpus
< smp_cpus
) {
2458 fprintf(stderr
, "maxcpus must be equal to or greater than "
2462 if (max_cpus
> 255) {
2463 fprintf(stderr
, "Unsupported number of maxcpus\n");
2467 case QEMU_OPTION_vnc
:
2468 display_type
= DT_VNC
;
2469 vnc_display
= optarg
;
2471 case QEMU_OPTION_no_acpi
:
2474 case QEMU_OPTION_no_hpet
:
2477 case QEMU_OPTION_balloon
:
2478 if (balloon_parse(optarg
) < 0) {
2479 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2483 case QEMU_OPTION_no_reboot
:
2486 case QEMU_OPTION_no_shutdown
:
2489 case QEMU_OPTION_show_cursor
:
2492 case QEMU_OPTION_uuid
:
2493 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2494 fprintf(stderr
, "Fail to parse UUID string."
2495 " Wrong format.\n");
2499 case QEMU_OPTION_option_rom
:
2500 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2501 fprintf(stderr
, "Too many option ROMs\n");
2504 option_rom
[nb_option_roms
] = optarg
;
2507 case QEMU_OPTION_semihosting
:
2508 semihosting_enabled
= 1;
2510 case QEMU_OPTION_name
:
2511 qemu_name
= qemu_strdup(optarg
);
2513 char *p
= strchr(qemu_name
, ',');
2516 if (strncmp(p
, "process=", 8)) {
2517 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2521 os_set_proc_name(p
);
2525 case QEMU_OPTION_prom_env
:
2526 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2527 fprintf(stderr
, "Too many prom variables\n");
2530 prom_envs
[nb_prom_envs
] = optarg
;
2533 case QEMU_OPTION_old_param
:
2536 case QEMU_OPTION_clock
:
2537 configure_alarms(optarg
);
2539 case QEMU_OPTION_startdate
:
2540 configure_rtc_date_offset(optarg
, 1);
2542 case QEMU_OPTION_rtc
:
2543 opts
= qemu_opts_parse(&qemu_rtc_opts
, optarg
, 0);
2547 configure_rtc(opts
);
2549 case QEMU_OPTION_tb_size
:
2550 tb_size
= strtol(optarg
, NULL
, 0);
2554 case QEMU_OPTION_icount
:
2555 icount_option
= optarg
;
2557 case QEMU_OPTION_incoming
:
2559 incoming_expected
= true;
2561 case QEMU_OPTION_nodefaults
:
2563 default_parallel
= 0;
2564 default_virtcon
= 0;
2565 default_monitor
= 0;
2572 case QEMU_OPTION_xen_domid
:
2573 if (!(xen_available())) {
2574 printf("Option %s not supported for this target\n", popt
->name
);
2577 xen_domid
= atoi(optarg
);
2579 case QEMU_OPTION_xen_create
:
2580 if (!(xen_available())) {
2581 printf("Option %s not supported for this target\n", popt
->name
);
2584 xen_mode
= XEN_CREATE
;
2586 case QEMU_OPTION_xen_attach
:
2587 if (!(xen_available())) {
2588 printf("Option %s not supported for this target\n", popt
->name
);
2591 xen_mode
= XEN_ATTACH
;
2593 case QEMU_OPTION_readconfig
:
2595 int ret
= qemu_read_config_file(optarg
);
2597 fprintf(stderr
, "read config %s: %s\n", optarg
,
2603 case QEMU_OPTION_writeconfig
:
2606 if (strcmp(optarg
, "-") == 0) {
2609 fp
= fopen(optarg
, "w");
2611 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2615 qemu_config_write(fp
);
2620 os_parse_cmd_args(popt
->index
, optarg
);
2626 /* If no data_dir is specified then try to find it relative to the
2629 data_dir
= os_find_datadir(argv
[0]);
2631 /* If all else fails use the install patch specified when building. */
2633 data_dir
= CONFIG_QEMU_DATADIR
;
2637 * Default to max_cpus = smp_cpus, in case the user doesn't
2638 * specify a max_cpus value.
2641 max_cpus
= smp_cpus
;
2643 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2644 if (smp_cpus
> machine
->max_cpus
) {
2645 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2646 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2651 qemu_opts_foreach(&qemu_device_opts
, default_driver_check
, NULL
, 0);
2652 qemu_opts_foreach(&qemu_global_opts
, default_driver_check
, NULL
, 0);
2654 if (machine
->no_serial
) {
2657 if (machine
->no_parallel
) {
2658 default_parallel
= 0;
2660 if (!machine
->use_virtcon
) {
2661 default_virtcon
= 0;
2663 if (machine
->no_vga
) {
2666 if (machine
->no_floppy
) {
2669 if (machine
->no_cdrom
) {
2672 if (machine
->no_sdcard
) {
2676 if (display_type
== DT_NOGRAPHIC
) {
2677 if (default_parallel
)
2678 add_device_config(DEV_PARALLEL
, "null");
2679 if (default_serial
&& default_monitor
) {
2680 add_device_config(DEV_SERIAL
, "mon:stdio");
2681 } else if (default_virtcon
&& default_monitor
) {
2682 add_device_config(DEV_VIRTCON
, "mon:stdio");
2685 add_device_config(DEV_SERIAL
, "stdio");
2686 if (default_virtcon
)
2687 add_device_config(DEV_VIRTCON
, "stdio");
2688 if (default_monitor
)
2689 monitor_parse("stdio", "readline");
2693 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2694 if (default_parallel
)
2695 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2696 if (default_monitor
)
2697 monitor_parse("vc:80Cx24C", "readline");
2698 if (default_virtcon
)
2699 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2702 vga_interface_type
= VGA_CIRRUS
;
2706 if (qemu_opts_foreach(&qemu_chardev_opts
, chardev_init_func
, NULL
, 1) != 0)
2708 #ifdef CONFIG_VIRTFS
2709 if (qemu_opts_foreach(&qemu_fsdev_opts
, fsdev_init_func
, NULL
, 1) != 0) {
2716 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2722 int ret
= kvm_init(smp_cpus
);
2724 if (!kvm_available()) {
2725 printf("KVM not supported for this target\n");
2727 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2733 if (qemu_init_main_loop()) {
2734 fprintf(stderr
, "qemu_init_main_loop failed\n");
2737 linux_boot
= (kernel_filename
!= NULL
);
2739 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2740 fprintf(stderr
, "-append only allowed with -kernel option\n");
2744 if (!linux_boot
&& initrd_filename
!= NULL
) {
2745 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2749 os_set_line_buffering();
2751 if (init_timer_alarm() < 0) {
2752 fprintf(stderr
, "could not initialize alarm timer\n");
2755 configure_icount(icount_option
);
2757 if (net_init_clients() < 0) {
2761 /* init the bluetooth world */
2762 if (foreach_device_config(DEV_BT
, bt_parse
))
2765 /* init the memory */
2767 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2769 /* init the dynamic translator */
2770 cpu_exec_init_all(tb_size
* 1024 * 1024);
2772 bdrv_init_with_whitelist();
2776 if (default_cdrom
) {
2777 /* we always create the cdrom drive, even if no disk is there */
2778 drive_add(NULL
, CDROM_ALIAS
);
2781 if (default_floppy
) {
2782 /* we always create at least one floppy */
2783 drive_add(NULL
, FD_ALIAS
, 0);
2786 if (default_sdcard
) {
2787 /* we always create one sd slot, even if no card is in it */
2788 drive_add(NULL
, SD_ALIAS
);
2791 /* open the virtual block devices */
2793 qemu_opts_foreach(&qemu_drive_opts
, drive_enable_snapshot
, NULL
, 0);
2794 if (qemu_opts_foreach(&qemu_drive_opts
, drive_init_func
, &machine
->use_scsi
, 1) != 0)
2797 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2800 if (nb_numa_nodes
> 0) {
2803 if (nb_numa_nodes
> smp_cpus
) {
2804 nb_numa_nodes
= smp_cpus
;
2807 /* If no memory size if given for any node, assume the default case
2808 * and distribute the available memory equally across all nodes
2810 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2811 if (node_mem
[i
] != 0)
2814 if (i
== nb_numa_nodes
) {
2815 uint64_t usedmem
= 0;
2817 /* On Linux, the each node's border has to be 8MB aligned,
2818 * the final node gets the rest.
2820 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2821 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2822 usedmem
+= node_mem
[i
];
2824 node_mem
[i
] = ram_size
- usedmem
;
2827 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2828 if (node_cpumask
[i
] != 0)
2831 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2832 * must cope with this anyway, because there are BIOSes out there in
2833 * real machines which also use this scheme.
2835 if (i
== nb_numa_nodes
) {
2836 for (i
= 0; i
< smp_cpus
; i
++) {
2837 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2842 if (qemu_opts_foreach(&qemu_mon_opts
, mon_init_func
, NULL
, 1) != 0) {
2846 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2848 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2850 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2852 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2855 module_call_init(MODULE_INIT_DEVICE
);
2857 if (qemu_opts_foreach(&qemu_device_opts
, device_help_func
, NULL
, 0) != 0)
2861 i
= select_watchdog(watchdog
);
2863 exit (i
== 1 ? 1 : 0);
2866 if (machine
->compat_props
) {
2867 qdev_prop_register_global_list(machine
->compat_props
);
2871 machine
->init(ram_size
, boot_devices
,
2872 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2874 cpu_synchronize_all_post_init();
2876 /* must be after terminal init, SDL library changes signal handlers */
2877 os_setup_signal_handling();
2881 current_machine
= machine
;
2883 /* init USB devices */
2885 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2889 /* init generic devices */
2890 if (qemu_opts_foreach(&qemu_device_opts
, device_init_func
, NULL
, 1) != 0)
2893 net_check_clients();
2895 /* just use the first displaystate for the moment */
2896 ds
= get_displaystate();
2898 if (display_type
== DT_DEFAULT
) {
2899 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
2900 display_type
= DT_SDL
;
2902 display_type
= DT_VNC
;
2903 vnc_display
= "localhost:0,to=99";
2909 switch (display_type
) {
2912 #if defined(CONFIG_CURSES)
2914 curses_display_init(ds
, full_screen
);
2917 #if defined(CONFIG_SDL)
2919 sdl_display_init(ds
, full_screen
, no_frame
);
2921 #elif defined(CONFIG_COCOA)
2923 cocoa_display_init(ds
, full_screen
);
2927 vnc_display_init(ds
);
2928 if (vnc_display_open(ds
, vnc_display
) < 0)
2931 if (show_vnc_port
) {
2932 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
2940 dcl
= ds
->listeners
;
2941 while (dcl
!= NULL
) {
2942 if (dcl
->dpy_refresh
!= NULL
) {
2943 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
2944 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
2950 if (display_type
== DT_NOGRAPHIC
|| display_type
== DT_VNC
) {
2951 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
2952 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
2955 text_consoles_set_display(ds
);
2957 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
2958 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
2963 qdev_machine_creation_done();
2965 if (rom_load_all() != 0) {
2966 fprintf(stderr
, "rom loading failed\n");
2970 qemu_system_reset();
2972 if (load_vmstate(loadvm
) < 0) {
2978 int ret
= qemu_start_incoming_migration(incoming
);
2980 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
2984 } else if (autostart
) {