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 static int rtc_utc
= 1;
186 static int rtc_date_offset
= -1; /* -1 means no change */
187 QEMUClock
*rtc_clock
;
188 int vga_interface_type
= VGA_NONE
;
189 static int full_screen
= 0;
191 static int no_frame
= 0;
194 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
195 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
196 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
197 int win2k_install_hack
= 0;
205 const char *vnc_display
;
206 int acpi_enabled
= 1;
212 int graphic_rotate
= 0;
213 uint8_t irq0override
= 1;
214 const char *watchdog
;
215 const char *option_rom
[MAX_OPTION_ROMS
];
217 int semihosting_enabled
= 0;
219 const char *qemu_name
;
222 unsigned int nb_prom_envs
= 0;
223 const char *prom_envs
[MAX_PROM_ENVS
];
227 uint64_t node_mem
[MAX_NODES
];
228 uint64_t node_cpumask
[MAX_NODES
];
230 static QEMUTimer
*nographic_timer
;
232 uint8_t qemu_uuid
[16];
234 static QEMUBootSetHandler
*boot_set_handler
;
235 static void *boot_set_opaque
;
237 static NotifierList exit_notifiers
=
238 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
242 enum xen_mode xen_mode
= XEN_EMULATE
;
244 static int default_serial
= 1;
245 static int default_parallel
= 1;
246 static int default_virtcon
= 1;
247 static int default_monitor
= 1;
248 static int default_vga
= 1;
249 static int default_floppy
= 1;
250 static int default_cdrom
= 1;
251 static int default_sdcard
= 1;
257 { .driver
= "isa-serial", .flag
= &default_serial
},
258 { .driver
= "isa-parallel", .flag
= &default_parallel
},
259 { .driver
= "isa-fdc", .flag
= &default_floppy
},
260 { .driver
= "ide-drive", .flag
= &default_cdrom
},
261 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
262 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
263 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
264 { .driver
= "VGA", .flag
= &default_vga
},
265 { .driver
= "cirrus-vga", .flag
= &default_vga
},
266 { .driver
= "vmware-svga", .flag
= &default_vga
},
269 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
271 const char *driver
= qemu_opt_get(opts
, "driver");
276 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
277 if (strcmp(default_list
[i
].driver
, driver
) != 0)
279 *(default_list
[i
].flag
) = 0;
284 /***********************************************************/
285 /* real time host monotonic timer */
287 /* compute with 96 bit intermediate result: (a*b)/c */
288 uint64_t muldiv64(uint64_t a
, uint32_t b
, uint32_t c
)
293 #ifdef HOST_WORDS_BIGENDIAN
303 rl
= (uint64_t)u
.l
.low
* (uint64_t)b
;
304 rh
= (uint64_t)u
.l
.high
* (uint64_t)b
;
307 res
.l
.low
= (((rh
% c
) << 32) + (rl
& 0xffffffff)) / c
;
311 /***********************************************************/
312 /* host time/date access */
313 void qemu_get_timedate(struct tm
*tm
, int offset
)
320 if (rtc_date_offset
== -1) {
324 ret
= localtime(&ti
);
326 ti
-= rtc_date_offset
;
330 memcpy(tm
, ret
, sizeof(struct tm
));
333 int qemu_timedate_diff(struct tm
*tm
)
337 if (rtc_date_offset
== -1)
339 seconds
= mktimegm(tm
);
341 seconds
= mktime(tm
);
343 seconds
= mktimegm(tm
) + rtc_date_offset
;
345 return seconds
- time(NULL
);
348 void rtc_change_mon_event(struct tm
*tm
)
352 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
353 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
354 qobject_decref(data
);
357 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
359 time_t rtc_start_date
;
362 if (!strcmp(startdate
, "now") && legacy
) {
363 rtc_date_offset
= -1;
365 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
373 } else if (sscanf(startdate
, "%d-%d-%d",
385 rtc_start_date
= mktimegm(&tm
);
386 if (rtc_start_date
== -1) {
388 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
389 "'2006-06-17T16:01:21' or '2006-06-17'\n");
392 rtc_date_offset
= time(NULL
) - rtc_start_date
;
396 static void configure_rtc(QemuOpts
*opts
)
400 value
= qemu_opt_get(opts
, "base");
402 if (!strcmp(value
, "utc")) {
404 } else if (!strcmp(value
, "localtime")) {
407 configure_rtc_date_offset(value
, 0);
410 value
= qemu_opt_get(opts
, "clock");
412 if (!strcmp(value
, "host")) {
413 rtc_clock
= host_clock
;
414 } else if (!strcmp(value
, "vm")) {
415 rtc_clock
= vm_clock
;
417 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
421 value
= qemu_opt_get(opts
, "driftfix");
423 if (!strcmp(value
, "slew")) {
425 } else if (!strcmp(value
, "none")) {
428 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
434 /***********************************************************/
435 /* Bluetooth support */
438 static struct HCIInfo
*hci_table
[MAX_NICS
];
440 static struct bt_vlan_s
{
441 struct bt_scatternet_s net
;
443 struct bt_vlan_s
*next
;
446 /* find or alloc a new bluetooth "VLAN" */
447 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
449 struct bt_vlan_s
**pvlan
, *vlan
;
450 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
454 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
456 pvlan
= &first_bt_vlan
;
457 while (*pvlan
!= NULL
)
458 pvlan
= &(*pvlan
)->next
;
463 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
467 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
472 static struct HCIInfo null_hci
= {
473 .cmd_send
= null_hci_send
,
474 .sco_send
= null_hci_send
,
475 .acl_send
= null_hci_send
,
476 .bdaddr_set
= null_hci_addr_set
,
479 struct HCIInfo
*qemu_next_hci(void)
481 if (cur_hci
== nb_hcis
)
484 return hci_table
[cur_hci
++];
487 static struct HCIInfo
*hci_init(const char *str
)
490 struct bt_scatternet_s
*vlan
= 0;
492 if (!strcmp(str
, "null"))
495 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
497 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
498 else if (!strncmp(str
, "hci", 3)) {
501 if (!strncmp(str
+ 3, ",vlan=", 6)) {
502 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
507 vlan
= qemu_find_bt_vlan(0);
509 return bt_new_hci(vlan
);
512 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
517 static int bt_hci_parse(const char *str
)
522 if (nb_hcis
>= MAX_NICS
) {
523 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
536 bdaddr
.b
[5] = 0x56 + nb_hcis
;
537 hci
->bdaddr_set(hci
, bdaddr
.b
);
539 hci_table
[nb_hcis
++] = hci
;
544 static void bt_vhci_add(int vlan_id
)
546 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
549 fprintf(stderr
, "qemu: warning: adding a VHCI to "
550 "an empty scatternet %i\n", vlan_id
);
552 bt_vhci_init(bt_new_hci(vlan
));
555 static struct bt_device_s
*bt_device_add(const char *opt
)
557 struct bt_scatternet_s
*vlan
;
559 char *endp
= strstr(opt
, ",vlan=");
560 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
563 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
566 vlan_id
= strtol(endp
+ 6, &endp
, 0);
568 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
573 vlan
= qemu_find_bt_vlan(vlan_id
);
576 fprintf(stderr
, "qemu: warning: adding a slave device to "
577 "an empty scatternet %i\n", vlan_id
);
579 if (!strcmp(devname
, "keyboard"))
580 return bt_keyboard_init(vlan
);
582 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
586 static int bt_parse(const char *opt
)
588 const char *endp
, *p
;
591 if (strstart(opt
, "hci", &endp
)) {
592 if (!*endp
|| *endp
== ',') {
594 if (!strstart(endp
, ",vlan=", 0))
597 return bt_hci_parse(opt
);
599 } else if (strstart(opt
, "vhci", &endp
)) {
600 if (!*endp
|| *endp
== ',') {
602 if (strstart(endp
, ",vlan=", &p
)) {
603 vlan
= strtol(p
, (char **) &endp
, 0);
605 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
609 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
618 } else if (strstart(opt
, "device:", &endp
))
619 return !bt_device_add(endp
);
621 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
625 /***********************************************************/
626 /* QEMU Block devices */
628 #define HD_ALIAS "index=%d,media=disk"
629 #define CDROM_ALIAS "index=2,media=cdrom"
630 #define FD_ALIAS "index=%d,if=floppy"
631 #define PFLASH_ALIAS "if=pflash"
632 #define MTD_ALIAS "if=mtd"
633 #define SD_ALIAS "index=0,if=sd"
635 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
637 int *use_scsi
= opaque
;
640 if (drive_init(opts
, *use_scsi
, &fatal_error
) == NULL
) {
647 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
649 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
650 qemu_opt_set(opts
, "snapshot", "on");
655 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
657 boot_set_handler
= func
;
658 boot_set_opaque
= opaque
;
661 int qemu_boot_set(const char *boot_devices
)
663 if (!boot_set_handler
) {
666 return boot_set_handler(boot_set_opaque
, boot_devices
);
669 static void validate_bootdevices(char *devices
)
671 /* We just do some generic consistency checks */
675 for (p
= devices
; *p
!= '\0'; p
++) {
676 /* Allowed boot devices are:
677 * a-b: floppy disk drives
678 * c-f: IDE disk drives
679 * g-m: machine implementation dependant drives
680 * n-p: network devices
681 * It's up to each machine implementation to check if the given boot
682 * devices match the actual hardware implementation and firmware
685 if (*p
< 'a' || *p
> 'p') {
686 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
689 if (bitmap
& (1 << (*p
- 'a'))) {
690 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
693 bitmap
|= 1 << (*p
- 'a');
697 static void restore_boot_devices(void *opaque
)
699 char *standard_boot_devices
= opaque
;
700 static int first
= 1;
702 /* Restore boot order and remove ourselves after the first boot */
708 qemu_boot_set(standard_boot_devices
);
710 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
711 qemu_free(standard_boot_devices
);
714 static void numa_add(const char *optarg
)
718 unsigned long long value
, endvalue
;
721 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
722 if (!strcmp(option
, "node")) {
723 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
724 nodenr
= nb_numa_nodes
;
726 nodenr
= strtoull(option
, NULL
, 10);
729 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
730 node_mem
[nodenr
] = 0;
732 value
= strtoull(option
, &endptr
, 0);
734 case 0: case 'M': case 'm':
741 node_mem
[nodenr
] = value
;
743 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
744 node_cpumask
[nodenr
] = 0;
746 value
= strtoull(option
, &endptr
, 10);
749 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
751 if (*endptr
== '-') {
752 endvalue
= strtoull(endptr
+1, &endptr
, 10);
753 if (endvalue
>= 63) {
756 "only 63 CPUs in NUMA mode supported.\n");
758 value
= (2ULL << endvalue
) - (1ULL << value
);
760 value
= 1ULL << value
;
763 node_cpumask
[nodenr
] = value
;
770 static void smp_parse(const char *optarg
)
772 int smp
, sockets
= 0, threads
= 0, cores
= 0;
776 smp
= strtoul(optarg
, &endptr
, 10);
777 if (endptr
!= optarg
) {
778 if (*endptr
== ',') {
782 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
783 sockets
= strtoull(option
, NULL
, 10);
784 if (get_param_value(option
, 128, "cores", endptr
) != 0)
785 cores
= strtoull(option
, NULL
, 10);
786 if (get_param_value(option
, 128, "threads", endptr
) != 0)
787 threads
= strtoull(option
, NULL
, 10);
788 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
789 max_cpus
= strtoull(option
, NULL
, 10);
791 /* compute missing values, prefer sockets over cores over threads */
792 if (smp
== 0 || sockets
== 0) {
793 sockets
= sockets
> 0 ? sockets
: 1;
794 cores
= cores
> 0 ? cores
: 1;
795 threads
= threads
> 0 ? threads
: 1;
797 smp
= cores
* threads
* sockets
;
801 threads
= threads
> 0 ? threads
: 1;
802 cores
= smp
/ (sockets
* threads
);
804 threads
= smp
/ (cores
* sockets
);
808 smp_cores
= cores
> 0 ? cores
: 1;
809 smp_threads
= threads
> 0 ? threads
: 1;
814 /***********************************************************/
817 static int usb_device_add(const char *devname
)
820 USBDevice
*dev
= NULL
;
825 /* drivers with .usbdevice_name entry in USBDeviceInfo */
826 dev
= usbdevice_create(devname
);
831 if (strstart(devname
, "host:", &p
)) {
832 dev
= usb_host_device_open(p
);
833 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
834 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
835 bt_new_hci(qemu_find_bt_vlan(0)));
846 static int usb_device_del(const char *devname
)
851 if (strstart(devname
, "host:", &p
))
852 return usb_host_device_close(p
);
857 p
= strchr(devname
, '.');
860 bus_num
= strtoul(devname
, NULL
, 0);
861 addr
= strtoul(p
+ 1, NULL
, 0);
863 return usb_device_delete_addr(bus_num
, addr
);
866 static int usb_parse(const char *cmdline
)
869 r
= usb_device_add(cmdline
);
871 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
876 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
878 const char *devname
= qdict_get_str(qdict
, "devname");
879 if (usb_device_add(devname
) < 0) {
880 error_report("could not add USB device '%s'", devname
);
884 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
886 const char *devname
= qdict_get_str(qdict
, "devname");
887 if (usb_device_del(devname
) < 0) {
888 error_report("could not delete USB device '%s'", devname
);
892 /***********************************************************/
895 static struct pcmcia_socket_entry_s
{
896 PCMCIASocket
*socket
;
897 struct pcmcia_socket_entry_s
*next
;
898 } *pcmcia_sockets
= 0;
900 void pcmcia_socket_register(PCMCIASocket
*socket
)
902 struct pcmcia_socket_entry_s
*entry
;
904 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
905 entry
->socket
= socket
;
906 entry
->next
= pcmcia_sockets
;
907 pcmcia_sockets
= entry
;
910 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
912 struct pcmcia_socket_entry_s
*entry
, **ptr
;
914 ptr
= &pcmcia_sockets
;
915 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
916 if (entry
->socket
== socket
) {
922 void pcmcia_info(Monitor
*mon
)
924 struct pcmcia_socket_entry_s
*iter
;
927 monitor_printf(mon
, "No PCMCIA sockets\n");
929 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
930 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
931 iter
->socket
->attached
? iter
->socket
->card_string
:
935 /***********************************************************/
938 typedef struct IOHandlerRecord
{
940 IOCanReadHandler
*fd_read_poll
;
947 QLIST_ENTRY(IOHandlerRecord
) next
;
950 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
951 QLIST_HEAD_INITIALIZER(io_handlers
);
954 /* XXX: fd_read_poll should be suppressed, but an API change is
955 necessary in the character devices to suppress fd_can_read(). */
956 int qemu_set_fd_handler2(int fd
,
957 IOCanReadHandler
*fd_read_poll
,
962 IOHandlerRecord
*ioh
;
964 if (!fd_read
&& !fd_write
) {
965 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
972 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
976 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
977 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
980 ioh
->fd_read_poll
= fd_read_poll
;
981 ioh
->fd_read
= fd_read
;
982 ioh
->fd_write
= fd_write
;
983 ioh
->opaque
= opaque
;
989 int qemu_set_fd_handler(int fd
,
994 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
997 /***********************************************************/
998 /* machine registration */
1000 static QEMUMachine
*first_machine
= NULL
;
1001 QEMUMachine
*current_machine
= NULL
;
1003 int qemu_register_machine(QEMUMachine
*m
)
1006 pm
= &first_machine
;
1014 static QEMUMachine
*find_machine(const char *name
)
1018 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1019 if (!strcmp(m
->name
, name
))
1021 if (m
->alias
&& !strcmp(m
->alias
, name
))
1027 static QEMUMachine
*find_default_machine(void)
1031 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1032 if (m
->is_default
) {
1039 /***********************************************************/
1040 /* main execution loop */
1042 static void gui_update(void *opaque
)
1044 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1045 DisplayState
*ds
= opaque
;
1046 DisplayChangeListener
*dcl
= ds
->listeners
;
1048 qemu_flush_coalesced_mmio_buffer();
1051 while (dcl
!= NULL
) {
1052 if (dcl
->gui_timer_interval
&&
1053 dcl
->gui_timer_interval
< interval
)
1054 interval
= dcl
->gui_timer_interval
;
1057 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1060 static void nographic_update(void *opaque
)
1062 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1064 qemu_flush_coalesced_mmio_buffer();
1065 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1068 struct vm_change_state_entry
{
1069 VMChangeStateHandler
*cb
;
1071 QLIST_ENTRY (vm_change_state_entry
) entries
;
1074 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1076 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1079 VMChangeStateEntry
*e
;
1081 e
= qemu_mallocz(sizeof (*e
));
1085 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1089 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1091 QLIST_REMOVE (e
, entries
);
1095 void vm_state_notify(int running
, int reason
)
1097 VMChangeStateEntry
*e
;
1099 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1100 e
->cb(e
->opaque
, running
, reason
);
1109 vm_state_notify(1, 0);
1111 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1115 /* reset/shutdown handler */
1117 typedef struct QEMUResetEntry
{
1118 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1119 QEMUResetHandler
*func
;
1123 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1124 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1125 static int reset_requested
;
1126 static int shutdown_requested
;
1127 static int powerdown_requested
;
1128 int debug_requested
;
1129 int vmstop_requested
;
1131 int qemu_shutdown_requested(void)
1133 int r
= shutdown_requested
;
1134 shutdown_requested
= 0;
1138 int qemu_reset_requested(void)
1140 int r
= reset_requested
;
1141 reset_requested
= 0;
1145 int qemu_powerdown_requested(void)
1147 int r
= powerdown_requested
;
1148 powerdown_requested
= 0;
1152 static int qemu_debug_requested(void)
1154 int r
= debug_requested
;
1155 debug_requested
= 0;
1159 static int qemu_vmstop_requested(void)
1161 int r
= vmstop_requested
;
1162 vmstop_requested
= 0;
1166 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1168 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1171 re
->opaque
= opaque
;
1172 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1175 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1179 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1180 if (re
->func
== func
&& re
->opaque
== opaque
) {
1181 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1188 void qemu_system_reset(void)
1190 QEMUResetEntry
*re
, *nre
;
1192 /* reset all devices */
1193 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1194 re
->func(re
->opaque
);
1196 monitor_protocol_event(QEVENT_RESET
, NULL
);
1197 cpu_synchronize_all_post_reset();
1200 void qemu_system_reset_request(void)
1203 shutdown_requested
= 1;
1205 reset_requested
= 1;
1207 qemu_notify_event();
1210 void qemu_system_shutdown_request(void)
1212 shutdown_requested
= 1;
1213 qemu_notify_event();
1216 void qemu_system_powerdown_request(void)
1218 powerdown_requested
= 1;
1219 qemu_notify_event();
1222 void main_loop_wait(int nonblocking
)
1224 IOHandlerRecord
*ioh
;
1225 fd_set rfds
, wfds
, xfds
;
1233 timeout
= qemu_calculate_timeout();
1234 qemu_bh_update_timeout(&timeout
);
1237 os_host_main_loop_wait(&timeout
);
1239 /* poll any events */
1240 /* XXX: separate device handlers from system ones */
1245 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1249 (!ioh
->fd_read_poll
||
1250 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1251 FD_SET(ioh
->fd
, &rfds
);
1255 if (ioh
->fd_write
) {
1256 FD_SET(ioh
->fd
, &wfds
);
1262 tv
.tv_sec
= timeout
/ 1000;
1263 tv
.tv_usec
= (timeout
% 1000) * 1000;
1265 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1267 qemu_mutex_unlock_iothread();
1268 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1269 qemu_mutex_lock_iothread();
1271 IOHandlerRecord
*pioh
;
1273 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1275 QLIST_REMOVE(ioh
, next
);
1279 if (ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1280 ioh
->fd_read(ioh
->opaque
);
1282 if (ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1283 ioh
->fd_write(ioh
->opaque
);
1288 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1290 qemu_run_all_timers();
1292 /* Check bottom-halves last in case any of the earlier events triggered
1298 static int vm_can_run(void)
1300 if (powerdown_requested
)
1302 if (reset_requested
)
1304 if (shutdown_requested
)
1306 if (debug_requested
)
1311 qemu_irq qemu_system_powerdown
;
1313 static void main_loop(void)
1317 qemu_main_loop_start();
1321 bool nonblocking
= false;
1322 #ifdef CONFIG_PROFILER
1325 #ifndef CONFIG_IOTHREAD
1326 nonblocking
= cpu_exec_all();
1328 #ifdef CONFIG_PROFILER
1329 ti
= profile_getclock();
1331 main_loop_wait(nonblocking
);
1332 #ifdef CONFIG_PROFILER
1333 dev_time
+= profile_getclock() - ti
;
1335 } while (vm_can_run());
1337 if ((r
= qemu_debug_requested())) {
1340 if (qemu_shutdown_requested()) {
1341 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1348 if (qemu_reset_requested()) {
1350 qemu_system_reset();
1353 if (qemu_powerdown_requested()) {
1354 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1355 qemu_irq_raise(qemu_system_powerdown
);
1357 if ((r
= qemu_vmstop_requested())) {
1365 static void version(void)
1367 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1370 static void help(int exitcode
)
1372 const char *options_help
=
1373 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1375 #define DEFHEADING(text) stringify(text) "\n"
1376 #include "qemu-options.def"
1382 printf("usage: %s [options] [disk_image]\n"
1384 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1387 "During emulation, the following keys are useful:\n"
1388 "ctrl-alt-f toggle full screen\n"
1389 "ctrl-alt-n switch to virtual console 'n'\n"
1390 "ctrl-alt toggle mouse and keyboard grab\n"
1392 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1398 #define HAS_ARG 0x0001
1400 typedef struct QEMUOption
{
1407 static const QEMUOption qemu_options
[] = {
1408 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1409 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1410 { option, opt_arg, opt_enum, arch_mask },
1411 #define DEFHEADING(text)
1412 #include "qemu-options.def"
1418 static void select_vgahw (const char *p
)
1423 vga_interface_type
= VGA_NONE
;
1424 if (strstart(p
, "std", &opts
)) {
1425 vga_interface_type
= VGA_STD
;
1426 } else if (strstart(p
, "cirrus", &opts
)) {
1427 vga_interface_type
= VGA_CIRRUS
;
1428 } else if (strstart(p
, "vmware", &opts
)) {
1429 vga_interface_type
= VGA_VMWARE
;
1430 } else if (strstart(p
, "xenfb", &opts
)) {
1431 vga_interface_type
= VGA_XENFB
;
1432 } else if (!strstart(p
, "none", &opts
)) {
1434 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1438 const char *nextopt
;
1440 if (strstart(opts
, ",retrace=", &nextopt
)) {
1442 if (strstart(opts
, "dumb", &nextopt
))
1443 vga_retrace_method
= VGA_RETRACE_DUMB
;
1444 else if (strstart(opts
, "precise", &nextopt
))
1445 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1446 else goto invalid_vga
;
1447 } else goto invalid_vga
;
1452 static int balloon_parse(const char *arg
)
1456 if (strcmp(arg
, "none") == 0) {
1460 if (!strncmp(arg
, "virtio", 6)) {
1461 if (arg
[6] == ',') {
1462 /* have params -> parse them */
1463 opts
= qemu_opts_parse(&qemu_device_opts
, arg
+7, 0);
1467 /* create empty opts */
1468 opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1470 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1477 char *qemu_find_file(int type
, const char *name
)
1483 /* If name contains path separators then try it as a straight path. */
1484 if ((strchr(name
, '/') || strchr(name
, '\\'))
1485 && access(name
, R_OK
) == 0) {
1486 return qemu_strdup(name
);
1489 case QEMU_FILE_TYPE_BIOS
:
1492 case QEMU_FILE_TYPE_KEYMAP
:
1493 subdir
= "keymaps/";
1498 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1499 buf
= qemu_mallocz(len
);
1500 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1501 if (access(buf
, R_OK
)) {
1508 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1510 return qdev_device_help(opts
);
1513 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1517 dev
= qdev_device_add(opts
);
1523 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1525 CharDriverState
*chr
;
1527 chr
= qemu_chr_open_opts(opts
, NULL
);
1533 #ifdef CONFIG_VIRTFS
1534 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1537 ret
= qemu_fsdev_add(opts
);
1543 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1545 CharDriverState
*chr
;
1546 const char *chardev
;
1550 mode
= qemu_opt_get(opts
, "mode");
1554 if (strcmp(mode
, "readline") == 0) {
1555 flags
= MONITOR_USE_READLINE
;
1556 } else if (strcmp(mode
, "control") == 0) {
1557 flags
= MONITOR_USE_CONTROL
;
1559 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1563 if (qemu_opt_get_bool(opts
, "default", 0))
1564 flags
|= MONITOR_IS_DEFAULT
;
1566 chardev
= qemu_opt_get(opts
, "chardev");
1567 chr
= qemu_chr_find(chardev
);
1569 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1573 monitor_init(chr
, flags
);
1577 static void monitor_parse(const char *optarg
, const char *mode
)
1579 static int monitor_device_index
= 0;
1585 if (strstart(optarg
, "chardev:", &p
)) {
1586 snprintf(label
, sizeof(label
), "%s", p
);
1588 snprintf(label
, sizeof(label
), "compat_monitor%d",
1589 monitor_device_index
);
1590 if (monitor_device_index
== 0) {
1593 opts
= qemu_chr_parse_compat(label
, optarg
);
1595 fprintf(stderr
, "parse error: %s\n", optarg
);
1600 opts
= qemu_opts_create(&qemu_mon_opts
, label
, 1);
1602 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1605 qemu_opt_set(opts
, "mode", mode
);
1606 qemu_opt_set(opts
, "chardev", label
);
1608 qemu_opt_set(opts
, "default", "on");
1609 monitor_device_index
++;
1612 struct device_config
{
1614 DEV_USB
, /* -usbdevice */
1616 DEV_SERIAL
, /* -serial */
1617 DEV_PARALLEL
, /* -parallel */
1618 DEV_VIRTCON
, /* -virtioconsole */
1619 DEV_DEBUGCON
, /* -debugcon */
1621 const char *cmdline
;
1622 QTAILQ_ENTRY(device_config
) next
;
1624 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1626 static void add_device_config(int type
, const char *cmdline
)
1628 struct device_config
*conf
;
1630 conf
= qemu_mallocz(sizeof(*conf
));
1632 conf
->cmdline
= cmdline
;
1633 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1636 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1638 struct device_config
*conf
;
1641 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1642 if (conf
->type
!= type
)
1644 rc
= func(conf
->cmdline
);
1651 static int serial_parse(const char *devname
)
1653 static int index
= 0;
1656 if (strcmp(devname
, "none") == 0)
1658 if (index
== MAX_SERIAL_PORTS
) {
1659 fprintf(stderr
, "qemu: too many serial ports\n");
1662 snprintf(label
, sizeof(label
), "serial%d", index
);
1663 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1664 if (!serial_hds
[index
]) {
1665 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1666 devname
, strerror(errno
));
1673 static int parallel_parse(const char *devname
)
1675 static int index
= 0;
1678 if (strcmp(devname
, "none") == 0)
1680 if (index
== MAX_PARALLEL_PORTS
) {
1681 fprintf(stderr
, "qemu: too many parallel ports\n");
1684 snprintf(label
, sizeof(label
), "parallel%d", index
);
1685 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1686 if (!parallel_hds
[index
]) {
1687 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1688 devname
, strerror(errno
));
1695 static int virtcon_parse(const char *devname
)
1697 static int index
= 0;
1699 QemuOpts
*bus_opts
, *dev_opts
;
1701 if (strcmp(devname
, "none") == 0)
1703 if (index
== MAX_VIRTIO_CONSOLES
) {
1704 fprintf(stderr
, "qemu: too many virtio consoles\n");
1708 bus_opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1709 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1711 dev_opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1712 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1714 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1715 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1716 if (!virtcon_hds
[index
]) {
1717 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1718 devname
, strerror(errno
));
1721 qemu_opt_set(dev_opts
, "chardev", label
);
1727 static int debugcon_parse(const char *devname
)
1731 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1734 opts
= qemu_opts_create(&qemu_device_opts
, "debugcon", 1);
1736 fprintf(stderr
, "qemu: already have a debugcon device\n");
1739 qemu_opt_set(opts
, "driver", "isa-debugcon");
1740 qemu_opt_set(opts
, "chardev", "debugcon");
1744 void qemu_add_exit_notifier(Notifier
*notify
)
1746 notifier_list_add(&exit_notifiers
, notify
);
1749 void qemu_remove_exit_notifier(Notifier
*notify
)
1751 notifier_list_remove(&exit_notifiers
, notify
);
1754 static void qemu_run_exit_notifiers(void)
1756 notifier_list_notify(&exit_notifiers
);
1759 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1760 const char **poptarg
, int *poptind
)
1762 const QEMUOption
*popt
;
1763 int optind
= *poptind
;
1764 char *r
= argv
[optind
];
1767 loc_set_cmdline(argv
, optind
, 1);
1769 /* Treat --foo the same as -foo. */
1772 popt
= qemu_options
;
1775 error_report("invalid option");
1778 if (!strcmp(popt
->name
, r
+ 1))
1782 if (popt
->flags
& HAS_ARG
) {
1783 if (optind
>= argc
) {
1784 error_report("requires an argument");
1787 optarg
= argv
[optind
++];
1788 loc_set_cmdline(argv
, optind
- 2, 2);
1799 int main(int argc
, char **argv
, char **envp
)
1801 const char *gdbstub_dev
= NULL
;
1803 int snapshot
, linux_boot
;
1804 const char *icount_option
= NULL
;
1805 const char *initrd_filename
;
1806 const char *kernel_filename
, *kernel_cmdline
;
1807 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1809 DisplayChangeListener
*dcl
;
1810 int cyls
, heads
, secs
, translation
;
1811 QemuOpts
*hda_opts
= NULL
, *opts
;
1814 const char *loadvm
= NULL
;
1815 QEMUMachine
*machine
;
1816 const char *cpu_model
;
1818 const char *pid_file
= NULL
;
1819 const char *incoming
= NULL
;
1820 int show_vnc_port
= 0;
1823 atexit(qemu_run_exit_notifiers
);
1824 error_set_progname(argv
[0]);
1828 qemu_cache_utils_init(envp
);
1830 QLIST_INIT (&vm_change_state_head
);
1831 os_setup_early_signal_handling();
1833 module_call_init(MODULE_INIT_MACHINE
);
1834 machine
= find_default_machine();
1836 initrd_filename
= NULL
;
1839 kernel_filename
= NULL
;
1840 kernel_cmdline
= "";
1841 cyls
= heads
= secs
= 0;
1842 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1844 for (i
= 0; i
< MAX_NODES
; i
++) {
1846 node_cpumask
[i
] = 0;
1855 /* first pass of option parsing */
1857 while (optind
< argc
) {
1858 if (argv
[optind
][0] != '-') {
1863 const QEMUOption
*popt
;
1865 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1866 switch (popt
->index
) {
1867 case QEMU_OPTION_nodefconfig
:
1877 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1878 if (ret
< 0 && ret
!= -ENOENT
) {
1882 ret
= qemu_read_config_file(arch_config_name
);
1883 if (ret
< 0 && ret
!= -ENOENT
) {
1889 /* second pass of option parsing */
1894 if (argv
[optind
][0] != '-') {
1895 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1897 const QEMUOption
*popt
;
1899 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1900 if (!(popt
->arch_mask
& arch_type
)) {
1901 printf("Option %s not supported for this target\n", popt
->name
);
1904 switch(popt
->index
) {
1906 machine
= find_machine(optarg
);
1909 printf("Supported machines are:\n");
1910 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1912 printf("%-10s %s (alias of %s)\n",
1913 m
->alias
, m
->desc
, m
->name
);
1914 printf("%-10s %s%s\n",
1916 m
->is_default
? " (default)" : "");
1918 exit(*optarg
!= '?');
1921 case QEMU_OPTION_cpu
:
1922 /* hw initialization will check this */
1923 if (*optarg
== '?') {
1924 list_cpus(stdout
, &fprintf
, optarg
);
1930 case QEMU_OPTION_initrd
:
1931 initrd_filename
= optarg
;
1933 case QEMU_OPTION_hda
:
1935 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
1937 hda_opts
= drive_add(optarg
, HD_ALIAS
1938 ",cyls=%d,heads=%d,secs=%d%s",
1939 0, cyls
, heads
, secs
,
1940 translation
== BIOS_ATA_TRANSLATION_LBA
?
1942 translation
== BIOS_ATA_TRANSLATION_NONE
?
1943 ",trans=none" : "");
1945 case QEMU_OPTION_hdb
:
1946 case QEMU_OPTION_hdc
:
1947 case QEMU_OPTION_hdd
:
1948 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
1950 case QEMU_OPTION_drive
:
1951 drive_add(NULL
, "%s", optarg
);
1953 case QEMU_OPTION_set
:
1954 if (qemu_set_option(optarg
) != 0)
1957 case QEMU_OPTION_global
:
1958 if (qemu_global_option(optarg
) != 0)
1961 case QEMU_OPTION_mtdblock
:
1962 drive_add(optarg
, MTD_ALIAS
);
1964 case QEMU_OPTION_sd
:
1965 drive_add(optarg
, SD_ALIAS
);
1967 case QEMU_OPTION_pflash
:
1968 drive_add(optarg
, PFLASH_ALIAS
);
1970 case QEMU_OPTION_snapshot
:
1973 case QEMU_OPTION_hdachs
:
1977 cyls
= strtol(p
, (char **)&p
, 0);
1978 if (cyls
< 1 || cyls
> 16383)
1983 heads
= strtol(p
, (char **)&p
, 0);
1984 if (heads
< 1 || heads
> 16)
1989 secs
= strtol(p
, (char **)&p
, 0);
1990 if (secs
< 1 || secs
> 63)
1994 if (!strcmp(p
, "none"))
1995 translation
= BIOS_ATA_TRANSLATION_NONE
;
1996 else if (!strcmp(p
, "lba"))
1997 translation
= BIOS_ATA_TRANSLATION_LBA
;
1998 else if (!strcmp(p
, "auto"))
1999 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2002 } else if (*p
!= '\0') {
2004 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2007 if (hda_opts
!= NULL
) {
2009 snprintf(num
, sizeof(num
), "%d", cyls
);
2010 qemu_opt_set(hda_opts
, "cyls", num
);
2011 snprintf(num
, sizeof(num
), "%d", heads
);
2012 qemu_opt_set(hda_opts
, "heads", num
);
2013 snprintf(num
, sizeof(num
), "%d", secs
);
2014 qemu_opt_set(hda_opts
, "secs", num
);
2015 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2016 qemu_opt_set(hda_opts
, "trans", "lba");
2017 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2018 qemu_opt_set(hda_opts
, "trans", "none");
2022 case QEMU_OPTION_numa
:
2023 if (nb_numa_nodes
>= MAX_NODES
) {
2024 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2029 case QEMU_OPTION_nographic
:
2030 display_type
= DT_NOGRAPHIC
;
2032 #ifdef CONFIG_CURSES
2033 case QEMU_OPTION_curses
:
2034 display_type
= DT_CURSES
;
2037 case QEMU_OPTION_portrait
:
2040 case QEMU_OPTION_kernel
:
2041 kernel_filename
= optarg
;
2043 case QEMU_OPTION_append
:
2044 kernel_cmdline
= optarg
;
2046 case QEMU_OPTION_cdrom
:
2047 drive_add(optarg
, CDROM_ALIAS
);
2049 case QEMU_OPTION_boot
:
2051 static const char * const params
[] = {
2052 "order", "once", "menu", NULL
2054 char buf
[sizeof(boot_devices
)];
2055 char *standard_boot_devices
;
2058 if (!strchr(optarg
, '=')) {
2060 pstrcpy(buf
, sizeof(buf
), optarg
);
2061 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2063 "qemu: unknown boot parameter '%s' in '%s'\n",
2069 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2070 validate_bootdevices(buf
);
2071 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2074 if (get_param_value(buf
, sizeof(buf
),
2076 validate_bootdevices(buf
);
2077 standard_boot_devices
= qemu_strdup(boot_devices
);
2078 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2079 qemu_register_reset(restore_boot_devices
,
2080 standard_boot_devices
);
2082 if (get_param_value(buf
, sizeof(buf
),
2084 if (!strcmp(buf
, "on")) {
2086 } else if (!strcmp(buf
, "off")) {
2090 "qemu: invalid option value '%s'\n",
2098 case QEMU_OPTION_fda
:
2099 case QEMU_OPTION_fdb
:
2100 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2102 case QEMU_OPTION_no_fd_bootchk
:
2105 case QEMU_OPTION_netdev
:
2106 if (net_client_parse(&qemu_netdev_opts
, optarg
) == -1) {
2110 case QEMU_OPTION_net
:
2111 if (net_client_parse(&qemu_net_opts
, optarg
) == -1) {
2116 case QEMU_OPTION_tftp
:
2117 legacy_tftp_prefix
= optarg
;
2119 case QEMU_OPTION_bootp
:
2120 legacy_bootp_filename
= optarg
;
2122 case QEMU_OPTION_redir
:
2123 if (net_slirp_redir(optarg
) < 0)
2127 case QEMU_OPTION_bt
:
2128 add_device_config(DEV_BT
, optarg
);
2130 case QEMU_OPTION_audio_help
:
2131 if (!(audio_available())) {
2132 printf("Option %s not supported for this target\n", popt
->name
);
2138 case QEMU_OPTION_soundhw
:
2139 if (!(audio_available())) {
2140 printf("Option %s not supported for this target\n", popt
->name
);
2143 select_soundhw (optarg
);
2148 case QEMU_OPTION_version
:
2152 case QEMU_OPTION_m
: {
2156 value
= strtoul(optarg
, &ptr
, 10);
2158 case 0: case 'M': case 'm':
2165 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2169 /* On 32-bit hosts, QEMU is limited by virtual address space */
2170 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2171 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2174 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2175 fprintf(stderr
, "qemu: ram size too large\n");
2181 case QEMU_OPTION_mempath
:
2185 case QEMU_OPTION_mem_prealloc
:
2190 set_cpu_log(optarg
);
2193 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2195 case QEMU_OPTION_gdb
:
2196 gdbstub_dev
= optarg
;
2201 case QEMU_OPTION_bios
:
2204 case QEMU_OPTION_singlestep
:
2211 keyboard_layout
= optarg
;
2213 case QEMU_OPTION_localtime
:
2216 case QEMU_OPTION_vga
:
2217 select_vgahw (optarg
);
2224 w
= strtol(p
, (char **)&p
, 10);
2227 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2233 h
= strtol(p
, (char **)&p
, 10);
2238 depth
= strtol(p
, (char **)&p
, 10);
2239 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2240 depth
!= 24 && depth
!= 32)
2242 } else if (*p
== '\0') {
2243 depth
= graphic_depth
;
2250 graphic_depth
= depth
;
2253 case QEMU_OPTION_echr
:
2256 term_escape_char
= strtol(optarg
, &r
, 0);
2258 printf("Bad argument to echr\n");
2261 case QEMU_OPTION_monitor
:
2262 monitor_parse(optarg
, "readline");
2263 default_monitor
= 0;
2265 case QEMU_OPTION_qmp
:
2266 monitor_parse(optarg
, "control");
2267 default_monitor
= 0;
2269 case QEMU_OPTION_mon
:
2270 opts
= qemu_opts_parse(&qemu_mon_opts
, optarg
, 1);
2274 default_monitor
= 0;
2276 case QEMU_OPTION_chardev
:
2277 opts
= qemu_opts_parse(&qemu_chardev_opts
, optarg
, 1);
2282 #ifdef CONFIG_VIRTFS
2283 case QEMU_OPTION_fsdev
:
2284 opts
= qemu_opts_parse(&qemu_fsdev_opts
, optarg
, 1);
2286 fprintf(stderr
, "parse error: %s\n", optarg
);
2290 case QEMU_OPTION_virtfs
: {
2291 char *arg_fsdev
= NULL
;
2292 char *arg_9p
= NULL
;
2295 opts
= qemu_opts_parse(&qemu_virtfs_opts
, optarg
, 1);
2297 fprintf(stderr
, "parse error: %s\n", optarg
);
2301 if (qemu_opt_get(opts
, "fstype") == NULL
||
2302 qemu_opt_get(opts
, "mount_tag") == NULL
||
2303 qemu_opt_get(opts
, "path") == NULL
||
2304 qemu_opt_get(opts
, "security_model") == NULL
) {
2305 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2306 "security_model=[mapped|passthrough],"
2311 len
= strlen(",id=,path=,security_model=");
2312 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2313 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2314 len
+= strlen(qemu_opt_get(opts
, "path"));
2315 len
+= strlen(qemu_opt_get(opts
, "security_model"));
2316 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2319 fprintf(stderr
, "No memory to parse -fsdev for %s\n",
2324 sprintf(arg_fsdev
, "%s,id=%s,path=%s,security_model=%s",
2325 qemu_opt_get(opts
, "fstype"),
2326 qemu_opt_get(opts
, "mount_tag"),
2327 qemu_opt_get(opts
, "path"),
2328 qemu_opt_get(opts
, "security_model"));
2330 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2331 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2332 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2335 fprintf(stderr
, "No memory to parse -device for %s\n",
2340 sprintf(arg_9p
, "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2341 qemu_opt_get(opts
, "mount_tag"),
2342 qemu_opt_get(opts
, "mount_tag"));
2344 if (!qemu_opts_parse(&qemu_fsdev_opts
, arg_fsdev
, 1)) {
2345 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2349 if (!qemu_opts_parse(&qemu_device_opts
, arg_9p
, 1)) {
2350 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2354 qemu_free(arg_fsdev
);
2359 case QEMU_OPTION_serial
:
2360 add_device_config(DEV_SERIAL
, optarg
);
2362 if (strncmp(optarg
, "mon:", 4) == 0) {
2363 default_monitor
= 0;
2366 case QEMU_OPTION_watchdog
:
2369 "qemu: only one watchdog option may be given\n");
2374 case QEMU_OPTION_watchdog_action
:
2375 if (select_watchdog_action(optarg
) == -1) {
2376 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2380 case QEMU_OPTION_virtiocon
:
2381 add_device_config(DEV_VIRTCON
, optarg
);
2382 default_virtcon
= 0;
2383 if (strncmp(optarg
, "mon:", 4) == 0) {
2384 default_monitor
= 0;
2387 case QEMU_OPTION_parallel
:
2388 add_device_config(DEV_PARALLEL
, optarg
);
2389 default_parallel
= 0;
2390 if (strncmp(optarg
, "mon:", 4) == 0) {
2391 default_monitor
= 0;
2394 case QEMU_OPTION_debugcon
:
2395 add_device_config(DEV_DEBUGCON
, optarg
);
2397 case QEMU_OPTION_loadvm
:
2400 case QEMU_OPTION_full_screen
:
2404 case QEMU_OPTION_no_frame
:
2407 case QEMU_OPTION_alt_grab
:
2410 case QEMU_OPTION_ctrl_grab
:
2413 case QEMU_OPTION_no_quit
:
2416 case QEMU_OPTION_sdl
:
2417 display_type
= DT_SDL
;
2420 case QEMU_OPTION_pidfile
:
2423 case QEMU_OPTION_win2k_hack
:
2424 win2k_install_hack
= 1;
2426 case QEMU_OPTION_rtc_td_hack
:
2429 case QEMU_OPTION_acpitable
:
2430 do_acpitable_option(optarg
);
2432 case QEMU_OPTION_smbios
:
2433 do_smbios_option(optarg
);
2435 case QEMU_OPTION_enable_kvm
:
2438 case QEMU_OPTION_usb
:
2441 case QEMU_OPTION_usbdevice
:
2443 add_device_config(DEV_USB
, optarg
);
2445 case QEMU_OPTION_device
:
2446 if (!qemu_opts_parse(&qemu_device_opts
, optarg
, 1)) {
2450 case QEMU_OPTION_smp
:
2453 fprintf(stderr
, "Invalid number of CPUs\n");
2456 if (max_cpus
< smp_cpus
) {
2457 fprintf(stderr
, "maxcpus must be equal to or greater than "
2461 if (max_cpus
> 255) {
2462 fprintf(stderr
, "Unsupported number of maxcpus\n");
2466 case QEMU_OPTION_vnc
:
2467 display_type
= DT_VNC
;
2468 vnc_display
= optarg
;
2470 case QEMU_OPTION_no_acpi
:
2473 case QEMU_OPTION_no_hpet
:
2476 case QEMU_OPTION_balloon
:
2477 if (balloon_parse(optarg
) < 0) {
2478 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2482 case QEMU_OPTION_no_reboot
:
2485 case QEMU_OPTION_no_shutdown
:
2488 case QEMU_OPTION_show_cursor
:
2491 case QEMU_OPTION_uuid
:
2492 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2493 fprintf(stderr
, "Fail to parse UUID string."
2494 " Wrong format.\n");
2498 case QEMU_OPTION_option_rom
:
2499 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2500 fprintf(stderr
, "Too many option ROMs\n");
2503 option_rom
[nb_option_roms
] = optarg
;
2506 case QEMU_OPTION_semihosting
:
2507 semihosting_enabled
= 1;
2509 case QEMU_OPTION_name
:
2510 qemu_name
= qemu_strdup(optarg
);
2512 char *p
= strchr(qemu_name
, ',');
2515 if (strncmp(p
, "process=", 8)) {
2516 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2520 os_set_proc_name(p
);
2524 case QEMU_OPTION_prom_env
:
2525 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2526 fprintf(stderr
, "Too many prom variables\n");
2529 prom_envs
[nb_prom_envs
] = optarg
;
2532 case QEMU_OPTION_old_param
:
2535 case QEMU_OPTION_clock
:
2536 configure_alarms(optarg
);
2538 case QEMU_OPTION_startdate
:
2539 configure_rtc_date_offset(optarg
, 1);
2541 case QEMU_OPTION_rtc
:
2542 opts
= qemu_opts_parse(&qemu_rtc_opts
, optarg
, 0);
2546 configure_rtc(opts
);
2548 case QEMU_OPTION_tb_size
:
2549 tb_size
= strtol(optarg
, NULL
, 0);
2553 case QEMU_OPTION_icount
:
2554 icount_option
= optarg
;
2556 case QEMU_OPTION_incoming
:
2559 case QEMU_OPTION_nodefaults
:
2561 default_parallel
= 0;
2562 default_virtcon
= 0;
2563 default_monitor
= 0;
2570 case QEMU_OPTION_xen_domid
:
2571 if (!(xen_available())) {
2572 printf("Option %s not supported for this target\n", popt
->name
);
2575 xen_domid
= atoi(optarg
);
2577 case QEMU_OPTION_xen_create
:
2578 if (!(xen_available())) {
2579 printf("Option %s not supported for this target\n", popt
->name
);
2582 xen_mode
= XEN_CREATE
;
2584 case QEMU_OPTION_xen_attach
:
2585 if (!(xen_available())) {
2586 printf("Option %s not supported for this target\n", popt
->name
);
2589 xen_mode
= XEN_ATTACH
;
2591 case QEMU_OPTION_readconfig
:
2593 int ret
= qemu_read_config_file(optarg
);
2595 fprintf(stderr
, "read config %s: %s\n", optarg
,
2601 case QEMU_OPTION_writeconfig
:
2604 if (strcmp(optarg
, "-") == 0) {
2607 fp
= fopen(optarg
, "w");
2609 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2613 qemu_config_write(fp
);
2618 os_parse_cmd_args(popt
->index
, optarg
);
2624 /* If no data_dir is specified then try to find it relative to the
2627 data_dir
= os_find_datadir(argv
[0]);
2629 /* If all else fails use the install patch specified when building. */
2631 data_dir
= CONFIG_QEMU_DATADIR
;
2635 * Default to max_cpus = smp_cpus, in case the user doesn't
2636 * specify a max_cpus value.
2639 max_cpus
= smp_cpus
;
2641 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2642 if (smp_cpus
> machine
->max_cpus
) {
2643 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2644 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2649 qemu_opts_foreach(&qemu_device_opts
, default_driver_check
, NULL
, 0);
2650 qemu_opts_foreach(&qemu_global_opts
, default_driver_check
, NULL
, 0);
2652 if (machine
->no_serial
) {
2655 if (machine
->no_parallel
) {
2656 default_parallel
= 0;
2658 if (!machine
->use_virtcon
) {
2659 default_virtcon
= 0;
2661 if (machine
->no_vga
) {
2664 if (machine
->no_floppy
) {
2667 if (machine
->no_cdrom
) {
2670 if (machine
->no_sdcard
) {
2674 if (display_type
== DT_NOGRAPHIC
) {
2675 if (default_parallel
)
2676 add_device_config(DEV_PARALLEL
, "null");
2677 if (default_serial
&& default_monitor
) {
2678 add_device_config(DEV_SERIAL
, "mon:stdio");
2679 } else if (default_virtcon
&& default_monitor
) {
2680 add_device_config(DEV_VIRTCON
, "mon:stdio");
2683 add_device_config(DEV_SERIAL
, "stdio");
2684 if (default_virtcon
)
2685 add_device_config(DEV_VIRTCON
, "stdio");
2686 if (default_monitor
)
2687 monitor_parse("stdio", "readline");
2691 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2692 if (default_parallel
)
2693 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2694 if (default_monitor
)
2695 monitor_parse("vc:80Cx24C", "readline");
2696 if (default_virtcon
)
2697 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2700 vga_interface_type
= VGA_CIRRUS
;
2704 if (qemu_opts_foreach(&qemu_chardev_opts
, chardev_init_func
, NULL
, 1) != 0)
2706 #ifdef CONFIG_VIRTFS
2707 if (qemu_opts_foreach(&qemu_fsdev_opts
, fsdev_init_func
, NULL
, 1) != 0) {
2714 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2720 int ret
= kvm_init(smp_cpus
);
2722 if (!kvm_available()) {
2723 printf("KVM not supported for this target\n");
2725 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2731 if (qemu_init_main_loop()) {
2732 fprintf(stderr
, "qemu_init_main_loop failed\n");
2735 linux_boot
= (kernel_filename
!= NULL
);
2737 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2738 fprintf(stderr
, "-append only allowed with -kernel option\n");
2742 if (!linux_boot
&& initrd_filename
!= NULL
) {
2743 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2747 os_set_line_buffering();
2749 if (init_timer_alarm() < 0) {
2750 fprintf(stderr
, "could not initialize alarm timer\n");
2753 configure_icount(icount_option
);
2755 if (net_init_clients() < 0) {
2759 /* init the bluetooth world */
2760 if (foreach_device_config(DEV_BT
, bt_parse
))
2763 /* init the memory */
2765 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2767 /* init the dynamic translator */
2768 cpu_exec_init_all(tb_size
* 1024 * 1024);
2770 bdrv_init_with_whitelist();
2774 if (default_cdrom
) {
2775 /* we always create the cdrom drive, even if no disk is there */
2776 drive_add(NULL
, CDROM_ALIAS
);
2779 if (default_floppy
) {
2780 /* we always create at least one floppy */
2781 drive_add(NULL
, FD_ALIAS
, 0);
2784 if (default_sdcard
) {
2785 /* we always create one sd slot, even if no card is in it */
2786 drive_add(NULL
, SD_ALIAS
);
2789 /* open the virtual block devices */
2791 qemu_opts_foreach(&qemu_drive_opts
, drive_enable_snapshot
, NULL
, 0);
2792 if (qemu_opts_foreach(&qemu_drive_opts
, drive_init_func
, &machine
->use_scsi
, 1) != 0)
2795 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2798 if (nb_numa_nodes
> 0) {
2801 if (nb_numa_nodes
> smp_cpus
) {
2802 nb_numa_nodes
= smp_cpus
;
2805 /* If no memory size if given for any node, assume the default case
2806 * and distribute the available memory equally across all nodes
2808 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2809 if (node_mem
[i
] != 0)
2812 if (i
== nb_numa_nodes
) {
2813 uint64_t usedmem
= 0;
2815 /* On Linux, the each node's border has to be 8MB aligned,
2816 * the final node gets the rest.
2818 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2819 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2820 usedmem
+= node_mem
[i
];
2822 node_mem
[i
] = ram_size
- usedmem
;
2825 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2826 if (node_cpumask
[i
] != 0)
2829 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2830 * must cope with this anyway, because there are BIOSes out there in
2831 * real machines which also use this scheme.
2833 if (i
== nb_numa_nodes
) {
2834 for (i
= 0; i
< smp_cpus
; i
++) {
2835 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2840 if (qemu_opts_foreach(&qemu_mon_opts
, mon_init_func
, NULL
, 1) != 0) {
2844 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2846 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2848 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2850 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2853 module_call_init(MODULE_INIT_DEVICE
);
2855 if (qemu_opts_foreach(&qemu_device_opts
, device_help_func
, NULL
, 0) != 0)
2859 i
= select_watchdog(watchdog
);
2861 exit (i
== 1 ? 1 : 0);
2864 if (machine
->compat_props
) {
2865 qdev_prop_register_global_list(machine
->compat_props
);
2869 machine
->init(ram_size
, boot_devices
,
2870 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2872 cpu_synchronize_all_post_init();
2874 /* must be after terminal init, SDL library changes signal handlers */
2875 os_setup_signal_handling();
2879 current_machine
= machine
;
2881 /* init USB devices */
2883 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2887 /* init generic devices */
2888 if (qemu_opts_foreach(&qemu_device_opts
, device_init_func
, NULL
, 1) != 0)
2891 net_check_clients();
2893 /* just use the first displaystate for the moment */
2894 ds
= get_displaystate();
2896 if (display_type
== DT_DEFAULT
) {
2897 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
2898 display_type
= DT_SDL
;
2900 display_type
= DT_VNC
;
2901 vnc_display
= "localhost:0,to=99";
2907 switch (display_type
) {
2910 #if defined(CONFIG_CURSES)
2912 curses_display_init(ds
, full_screen
);
2915 #if defined(CONFIG_SDL)
2917 sdl_display_init(ds
, full_screen
, no_frame
);
2919 #elif defined(CONFIG_COCOA)
2921 cocoa_display_init(ds
, full_screen
);
2925 vnc_display_init(ds
);
2926 if (vnc_display_open(ds
, vnc_display
) < 0)
2929 if (show_vnc_port
) {
2930 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
2938 dcl
= ds
->listeners
;
2939 while (dcl
!= NULL
) {
2940 if (dcl
->dpy_refresh
!= NULL
) {
2941 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
2942 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
2948 if (display_type
== DT_NOGRAPHIC
|| display_type
== DT_VNC
) {
2949 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
2950 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
2953 text_consoles_set_display(ds
);
2955 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
2956 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
2961 qdev_machine_creation_done();
2963 if (rom_load_all() != 0) {
2964 fprintf(stderr
, "rom loading failed\n");
2968 qemu_system_reset();
2970 if (load_vmstate(loadvm
) < 0) {
2976 int ret
= qemu_start_incoming_migration(incoming
);
2978 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
2982 } else if (autostart
) {