4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 /* Needed early for CONFIG_BSD etc. */
33 #include "config-host.h"
37 #include <sys/times.h>
41 #include <sys/ioctl.h>
42 #include <sys/resource.h>
43 #include <sys/socket.h>
44 #include <netinet/in.h>
46 #include <arpa/inet.h>
49 #include <sys/select.h>
50 #ifdef CONFIG_SIMPLE_TRACE
56 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
58 #include <sys/sysctl.h>
67 #include <linux/ppdev.h>
68 #include <linux/parport.h>
72 #include <sys/ethernet.h>
73 #include <sys/sockio.h>
74 #include <netinet/arp.h>
75 #include <netinet/in_systm.h>
76 #include <netinet/ip.h>
77 #include <netinet/ip_icmp.h> // must come after ip.h
78 #include <netinet/udp.h>
79 #include <netinet/tcp.h>
87 #if defined(__OpenBSD__)
91 #if defined(CONFIG_VDE)
92 #include <libvdeplug.h>
100 #if defined(__APPLE__) || defined(main)
102 int qemu_main(int argc
, char **argv
, char **envp
);
103 int main(int argc
, char **argv
)
105 return qemu_main(argc
, argv
, NULL
);
108 #define main qemu_main
110 #endif /* CONFIG_SDL */
114 #define main qemu_main
115 #endif /* CONFIG_COCOA */
118 #include "hw/boards.h"
120 #include "hw/pcmcia.h"
125 #include "hw/watchdog.h"
126 #include "hw/smbios.h"
129 #include "hw/loader.h"
132 #include "net/slirp.h"
137 #include "qemu-timer.h"
138 #include "qemu-char.h"
139 #include "cache-utils.h"
141 #include "blockdev.h"
142 #include "block-migration.h"
144 #include "audio/audio.h"
145 #include "migration.h"
147 #include "qemu-option.h"
148 #include "qemu-config.h"
149 #include "qemu-objects.h"
150 #include "qemu-options.h"
151 #include "hw/device-assignment.h"
153 #include "fsdev/qemu-fsdev.h"
158 #include "qemu_socket.h"
160 #include "slirp/libslirp.h"
163 #include "qemu-queue.h"
165 #include "arch_init.h"
167 #include "ui/qemu-spice.h"
170 //#define DEBUG_SLIRP
172 #define DEFAULT_RAM_SIZE 128
174 #define MAX_VIRTIO_CONSOLES 1
176 static const char *data_dir
;
177 const char *bios_name
= NULL
;
178 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
179 DisplayType display_type
= DT_DEFAULT
;
180 int display_remote
= 0;
181 const char* keyboard_layout
= NULL
;
183 const char *mem_path
= NULL
;
185 int mem_prealloc
= 0; /* force preallocation of physical target memory */
188 NICInfo nd_table
[MAX_NICS
];
191 int incoming_expected
; /* Started with -incoming and waiting for incoming */
192 static int rtc_utc
= 1;
193 static int rtc_date_offset
= -1; /* -1 means no change */
194 QEMUClock
*rtc_clock
;
195 int vga_interface_type
= VGA_NONE
;
196 static int full_screen
= 0;
198 static int no_frame
= 0;
201 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
202 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
203 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
204 int win2k_install_hack
= 0;
212 const char *vnc_display
;
213 int acpi_enabled
= 1;
219 int graphic_rotate
= 0;
220 uint8_t irq0override
= 1;
221 const char *watchdog
;
222 const char *option_rom
[MAX_OPTION_ROMS
];
224 int semihosting_enabled
= 0;
225 int time_drift_fix
= 0;
226 unsigned int kvm_shadow_memory
= 0;
228 const char *qemu_name
;
231 unsigned int nb_prom_envs
= 0;
232 const char *prom_envs
[MAX_PROM_ENVS
];
233 const char *nvram
= NULL
;
237 uint64_t node_mem
[MAX_NODES
];
238 uint64_t node_cpumask
[MAX_NODES
];
240 static QEMUTimer
*nographic_timer
;
242 uint8_t qemu_uuid
[16];
244 static QEMUBootSetHandler
*boot_set_handler
;
245 static void *boot_set_opaque
;
247 static NotifierList exit_notifiers
=
248 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
252 enum xen_mode xen_mode
= XEN_EMULATE
;
254 static int default_serial
= 1;
255 static int default_parallel
= 1;
256 static int default_virtcon
= 1;
257 static int default_monitor
= 1;
258 static int default_vga
= 1;
259 static int default_floppy
= 1;
260 static int default_cdrom
= 1;
261 static int default_sdcard
= 1;
267 { .driver
= "isa-serial", .flag
= &default_serial
},
268 { .driver
= "isa-parallel", .flag
= &default_parallel
},
269 { .driver
= "isa-fdc", .flag
= &default_floppy
},
270 { .driver
= "ide-drive", .flag
= &default_cdrom
},
271 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
272 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
273 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
274 { .driver
= "VGA", .flag
= &default_vga
},
275 { .driver
= "cirrus-vga", .flag
= &default_vga
},
276 { .driver
= "vmware-svga", .flag
= &default_vga
},
279 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
281 const char *driver
= qemu_opt_get(opts
, "driver");
286 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
287 if (strcmp(default_list
[i
].driver
, driver
) != 0)
289 *(default_list
[i
].flag
) = 0;
294 /***********************************************************/
295 /* real time host monotonic timer */
297 /***********************************************************/
298 /* host time/date access */
299 void qemu_get_timedate(struct tm
*tm
, int offset
)
306 if (rtc_date_offset
== -1) {
310 ret
= localtime(&ti
);
312 ti
-= rtc_date_offset
;
316 memcpy(tm
, ret
, sizeof(struct tm
));
319 int qemu_timedate_diff(struct tm
*tm
)
323 if (rtc_date_offset
== -1)
325 seconds
= mktimegm(tm
);
327 seconds
= mktime(tm
);
329 seconds
= mktimegm(tm
) + rtc_date_offset
;
331 return seconds
- time(NULL
);
334 void rtc_change_mon_event(struct tm
*tm
)
338 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
339 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
340 qobject_decref(data
);
343 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
345 time_t rtc_start_date
;
348 if (!strcmp(startdate
, "now") && legacy
) {
349 rtc_date_offset
= -1;
351 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
359 } else if (sscanf(startdate
, "%d-%d-%d",
371 rtc_start_date
= mktimegm(&tm
);
372 if (rtc_start_date
== -1) {
374 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
375 "'2006-06-17T16:01:21' or '2006-06-17'\n");
378 rtc_date_offset
= time(NULL
) - rtc_start_date
;
382 static void configure_rtc(QemuOpts
*opts
)
386 value
= qemu_opt_get(opts
, "base");
388 if (!strcmp(value
, "utc")) {
390 } else if (!strcmp(value
, "localtime")) {
393 configure_rtc_date_offset(value
, 0);
396 value
= qemu_opt_get(opts
, "clock");
398 if (!strcmp(value
, "host")) {
399 rtc_clock
= host_clock
;
400 } else if (!strcmp(value
, "vm")) {
401 rtc_clock
= vm_clock
;
403 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
407 value
= qemu_opt_get(opts
, "driftfix");
409 if (!strcmp(value
, "slew")) {
411 } else if (!strcmp(value
, "none")) {
414 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
420 /***********************************************************/
421 /* Bluetooth support */
424 static struct HCIInfo
*hci_table
[MAX_NICS
];
426 static struct bt_vlan_s
{
427 struct bt_scatternet_s net
;
429 struct bt_vlan_s
*next
;
432 /* find or alloc a new bluetooth "VLAN" */
433 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
435 struct bt_vlan_s
**pvlan
, *vlan
;
436 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
440 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
442 pvlan
= &first_bt_vlan
;
443 while (*pvlan
!= NULL
)
444 pvlan
= &(*pvlan
)->next
;
449 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
453 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
458 static struct HCIInfo null_hci
= {
459 .cmd_send
= null_hci_send
,
460 .sco_send
= null_hci_send
,
461 .acl_send
= null_hci_send
,
462 .bdaddr_set
= null_hci_addr_set
,
465 struct HCIInfo
*qemu_next_hci(void)
467 if (cur_hci
== nb_hcis
)
470 return hci_table
[cur_hci
++];
473 static struct HCIInfo
*hci_init(const char *str
)
476 struct bt_scatternet_s
*vlan
= 0;
478 if (!strcmp(str
, "null"))
481 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
483 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
484 else if (!strncmp(str
, "hci", 3)) {
487 if (!strncmp(str
+ 3, ",vlan=", 6)) {
488 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
493 vlan
= qemu_find_bt_vlan(0);
495 return bt_new_hci(vlan
);
498 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
503 static int bt_hci_parse(const char *str
)
508 if (nb_hcis
>= MAX_NICS
) {
509 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
522 bdaddr
.b
[5] = 0x56 + nb_hcis
;
523 hci
->bdaddr_set(hci
, bdaddr
.b
);
525 hci_table
[nb_hcis
++] = hci
;
530 static void bt_vhci_add(int vlan_id
)
532 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
535 fprintf(stderr
, "qemu: warning: adding a VHCI to "
536 "an empty scatternet %i\n", vlan_id
);
538 bt_vhci_init(bt_new_hci(vlan
));
541 static struct bt_device_s
*bt_device_add(const char *opt
)
543 struct bt_scatternet_s
*vlan
;
545 char *endp
= strstr(opt
, ",vlan=");
546 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
549 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
552 vlan_id
= strtol(endp
+ 6, &endp
, 0);
554 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
559 vlan
= qemu_find_bt_vlan(vlan_id
);
562 fprintf(stderr
, "qemu: warning: adding a slave device to "
563 "an empty scatternet %i\n", vlan_id
);
565 if (!strcmp(devname
, "keyboard"))
566 return bt_keyboard_init(vlan
);
568 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
572 static int bt_parse(const char *opt
)
574 const char *endp
, *p
;
577 if (strstart(opt
, "hci", &endp
)) {
578 if (!*endp
|| *endp
== ',') {
580 if (!strstart(endp
, ",vlan=", 0))
583 return bt_hci_parse(opt
);
585 } else if (strstart(opt
, "vhci", &endp
)) {
586 if (!*endp
|| *endp
== ',') {
588 if (strstart(endp
, ",vlan=", &p
)) {
589 vlan
= strtol(p
, (char **) &endp
, 0);
591 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
595 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
604 } else if (strstart(opt
, "device:", &endp
))
605 return !bt_device_add(endp
);
607 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
611 /***********************************************************/
612 /* QEMU Block devices */
614 #define HD_ALIAS "index=%d,media=disk"
615 #define CDROM_ALIAS "index=2,media=cdrom"
616 #define FD_ALIAS "index=%d,if=floppy"
617 #define PFLASH_ALIAS "if=pflash"
618 #define MTD_ALIAS "if=mtd"
619 #define SD_ALIAS "index=0,if=sd"
621 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
623 int *use_scsi
= opaque
;
626 if (drive_init(opts
, *use_scsi
, &fatal_error
) == NULL
) {
633 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
635 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
636 qemu_opt_set(opts
, "snapshot", "on");
641 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
643 boot_set_handler
= func
;
644 boot_set_opaque
= opaque
;
647 int qemu_boot_set(const char *boot_devices
)
649 if (!boot_set_handler
) {
652 return boot_set_handler(boot_set_opaque
, boot_devices
);
655 static void validate_bootdevices(char *devices
)
657 /* We just do some generic consistency checks */
661 for (p
= devices
; *p
!= '\0'; p
++) {
662 /* Allowed boot devices are:
663 * a-b: floppy disk drives
664 * c-f: IDE disk drives
665 * g-m: machine implementation dependant drives
666 * n-p: network devices
667 * It's up to each machine implementation to check if the given boot
668 * devices match the actual hardware implementation and firmware
671 if (*p
< 'a' || *p
> 'p') {
672 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
675 if (bitmap
& (1 << (*p
- 'a'))) {
676 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
679 bitmap
|= 1 << (*p
- 'a');
683 static void restore_boot_devices(void *opaque
)
685 char *standard_boot_devices
= opaque
;
686 static int first
= 1;
688 /* Restore boot order and remove ourselves after the first boot */
694 qemu_boot_set(standard_boot_devices
);
696 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
697 qemu_free(standard_boot_devices
);
700 static void numa_add(const char *optarg
)
704 unsigned long long value
, endvalue
;
707 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
708 if (!strcmp(option
, "node")) {
709 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
710 nodenr
= nb_numa_nodes
;
712 nodenr
= strtoull(option
, NULL
, 10);
715 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
716 node_mem
[nodenr
] = 0;
719 sval
= strtosz(option
, NULL
);
721 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
724 node_mem
[nodenr
] = sval
;
726 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
727 node_cpumask
[nodenr
] = 0;
729 value
= strtoull(option
, &endptr
, 10);
732 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
734 if (*endptr
== '-') {
735 endvalue
= strtoull(endptr
+1, &endptr
, 10);
736 if (endvalue
>= 63) {
739 "only 63 CPUs in NUMA mode supported.\n");
741 value
= (2ULL << endvalue
) - (1ULL << value
);
743 value
= 1ULL << value
;
746 node_cpumask
[nodenr
] = value
;
753 static void smp_parse(const char *optarg
)
755 int smp
, sockets
= 0, threads
= 0, cores
= 0;
759 smp
= strtoul(optarg
, &endptr
, 10);
760 if (endptr
!= optarg
) {
761 if (*endptr
== ',') {
765 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
766 sockets
= strtoull(option
, NULL
, 10);
767 if (get_param_value(option
, 128, "cores", endptr
) != 0)
768 cores
= strtoull(option
, NULL
, 10);
769 if (get_param_value(option
, 128, "threads", endptr
) != 0)
770 threads
= strtoull(option
, NULL
, 10);
771 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
772 max_cpus
= strtoull(option
, NULL
, 10);
774 /* compute missing values, prefer sockets over cores over threads */
775 if (smp
== 0 || sockets
== 0) {
776 sockets
= sockets
> 0 ? sockets
: 1;
777 cores
= cores
> 0 ? cores
: 1;
778 threads
= threads
> 0 ? threads
: 1;
780 smp
= cores
* threads
* sockets
;
784 threads
= threads
> 0 ? threads
: 1;
785 cores
= smp
/ (sockets
* threads
);
787 threads
= smp
/ (cores
* sockets
);
791 smp_cores
= cores
> 0 ? cores
: 1;
792 smp_threads
= threads
> 0 ? threads
: 1;
797 /***********************************************************/
800 static int usb_device_add(const char *devname
)
803 USBDevice
*dev
= NULL
;
808 /* drivers with .usbdevice_name entry in USBDeviceInfo */
809 dev
= usbdevice_create(devname
);
814 if (strstart(devname
, "host:", &p
)) {
815 dev
= usb_host_device_open(p
);
816 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
817 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
818 bt_new_hci(qemu_find_bt_vlan(0)));
829 static int usb_device_del(const char *devname
)
834 if (strstart(devname
, "host:", &p
))
835 return usb_host_device_close(p
);
840 p
= strchr(devname
, '.');
843 bus_num
= strtoul(devname
, NULL
, 0);
844 addr
= strtoul(p
+ 1, NULL
, 0);
846 return usb_device_delete_addr(bus_num
, addr
);
849 static int usb_parse(const char *cmdline
)
852 r
= usb_device_add(cmdline
);
854 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
859 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
861 const char *devname
= qdict_get_str(qdict
, "devname");
862 if (usb_device_add(devname
) < 0) {
863 error_report("could not add USB device '%s'", devname
);
867 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
869 const char *devname
= qdict_get_str(qdict
, "devname");
870 if (usb_device_del(devname
) < 0) {
871 error_report("could not delete USB device '%s'", devname
);
875 /***********************************************************/
878 static struct pcmcia_socket_entry_s
{
879 PCMCIASocket
*socket
;
880 struct pcmcia_socket_entry_s
*next
;
881 } *pcmcia_sockets
= 0;
883 void pcmcia_socket_register(PCMCIASocket
*socket
)
885 struct pcmcia_socket_entry_s
*entry
;
887 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
888 entry
->socket
= socket
;
889 entry
->next
= pcmcia_sockets
;
890 pcmcia_sockets
= entry
;
893 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
895 struct pcmcia_socket_entry_s
*entry
, **ptr
;
897 ptr
= &pcmcia_sockets
;
898 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
899 if (entry
->socket
== socket
) {
905 void pcmcia_info(Monitor
*mon
)
907 struct pcmcia_socket_entry_s
*iter
;
910 monitor_printf(mon
, "No PCMCIA sockets\n");
912 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
913 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
914 iter
->socket
->attached
? iter
->socket
->card_string
:
918 /***********************************************************/
921 typedef struct IOHandlerRecord
{
923 IOCanReadHandler
*fd_read_poll
;
930 QLIST_ENTRY(IOHandlerRecord
) next
;
933 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
934 QLIST_HEAD_INITIALIZER(io_handlers
);
937 /* XXX: fd_read_poll should be suppressed, but an API change is
938 necessary in the character devices to suppress fd_can_read(). */
939 int qemu_set_fd_handler2(int fd
,
940 IOCanReadHandler
*fd_read_poll
,
945 IOHandlerRecord
*ioh
;
947 if (!fd_read
&& !fd_write
) {
948 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
955 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
959 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
960 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
963 ioh
->fd_read_poll
= fd_read_poll
;
964 ioh
->fd_read
= fd_read
;
965 ioh
->fd_write
= fd_write
;
966 ioh
->opaque
= opaque
;
973 int qemu_set_fd_handler(int fd
,
978 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
981 /***********************************************************/
982 /* machine registration */
984 static QEMUMachine
*first_machine
= NULL
;
985 QEMUMachine
*current_machine
= NULL
;
987 int qemu_register_machine(QEMUMachine
*m
)
998 static QEMUMachine
*find_machine(const char *name
)
1002 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1003 if (!strcmp(m
->name
, name
))
1005 if (m
->alias
&& !strcmp(m
->alias
, name
))
1011 static QEMUMachine
*find_default_machine(void)
1015 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1016 if (m
->is_default
) {
1023 /***********************************************************/
1024 /* main execution loop */
1026 static void gui_update(void *opaque
)
1028 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1029 DisplayState
*ds
= opaque
;
1030 DisplayChangeListener
*dcl
= ds
->listeners
;
1032 qemu_flush_coalesced_mmio_buffer();
1035 while (dcl
!= NULL
) {
1036 if (dcl
->gui_timer_interval
&&
1037 dcl
->gui_timer_interval
< interval
)
1038 interval
= dcl
->gui_timer_interval
;
1041 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1044 static void nographic_update(void *opaque
)
1046 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1048 qemu_flush_coalesced_mmio_buffer();
1049 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1052 struct vm_change_state_entry
{
1053 VMChangeStateHandler
*cb
;
1055 QLIST_ENTRY (vm_change_state_entry
) entries
;
1058 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1060 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1063 VMChangeStateEntry
*e
;
1065 e
= qemu_mallocz(sizeof (*e
));
1069 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1073 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1075 QLIST_REMOVE (e
, entries
);
1079 void vm_state_notify(int running
, int reason
)
1081 VMChangeStateEntry
*e
;
1083 trace_vm_state_notify(running
, reason
);
1085 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1086 e
->cb(e
->opaque
, running
, reason
);
1095 vm_state_notify(1, 0);
1097 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1101 /* reset/shutdown handler */
1103 typedef struct QEMUResetEntry
{
1104 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1105 QEMUResetHandler
*func
;
1109 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1110 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1111 static int reset_requested
;
1112 static int shutdown_requested
;
1113 static int powerdown_requested
;
1114 int debug_requested
;
1115 int vmstop_requested
;
1117 int qemu_no_shutdown(void)
1119 int r
= no_shutdown
;
1124 int qemu_shutdown_requested(void)
1126 int r
= shutdown_requested
;
1127 shutdown_requested
= 0;
1131 int qemu_reset_requested(void)
1133 int r
= reset_requested
;
1134 reset_requested
= 0;
1138 int qemu_powerdown_requested(void)
1140 int r
= powerdown_requested
;
1141 powerdown_requested
= 0;
1145 static int qemu_debug_requested(void)
1147 int r
= debug_requested
;
1148 debug_requested
= 0;
1152 static int qemu_vmstop_requested(void)
1154 int r
= vmstop_requested
;
1155 vmstop_requested
= 0;
1159 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1161 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1164 re
->opaque
= opaque
;
1165 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1168 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1172 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1173 if (re
->func
== func
&& re
->opaque
== opaque
) {
1174 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1181 void qemu_system_reset(void)
1183 QEMUResetEntry
*re
, *nre
;
1185 /* reset all devices */
1186 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1187 re
->func(re
->opaque
);
1189 monitor_protocol_event(QEVENT_RESET
, NULL
);
1190 cpu_synchronize_all_post_reset();
1193 void qemu_system_reset_request(void)
1196 shutdown_requested
= 1;
1198 reset_requested
= 1;
1200 if (cpu_single_env
) {
1201 cpu_single_env
->stopped
= 1;
1202 cpu_exit(cpu_single_env
);
1204 qemu_notify_event();
1207 void qemu_system_shutdown_request(void)
1209 shutdown_requested
= 1;
1210 qemu_notify_event();
1213 void qemu_system_powerdown_request(void)
1215 powerdown_requested
= 1;
1216 qemu_notify_event();
1219 void main_loop_wait(int nonblocking
)
1221 IOHandlerRecord
*ioh
;
1222 fd_set rfds
, wfds
, xfds
;
1230 timeout
= qemu_calculate_timeout();
1231 qemu_bh_update_timeout(&timeout
);
1234 os_host_main_loop_wait(&timeout
);
1236 /* poll any events */
1237 /* XXX: separate device handlers from system ones */
1242 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1246 (!ioh
->fd_read_poll
||
1247 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1248 FD_SET(ioh
->fd
, &rfds
);
1252 if (ioh
->fd_write
) {
1253 FD_SET(ioh
->fd
, &wfds
);
1259 tv
.tv_sec
= timeout
/ 1000;
1260 tv
.tv_usec
= (timeout
% 1000) * 1000;
1262 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1264 qemu_mutex_unlock_iothread();
1265 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1266 qemu_mutex_lock_iothread();
1268 IOHandlerRecord
*pioh
;
1270 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1271 if (!ioh
->deleted
&& ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1272 ioh
->fd_read(ioh
->opaque
);
1273 if (!(ioh
->fd_read_poll
&& ioh
->fd_read_poll(ioh
->opaque
)))
1274 FD_CLR(ioh
->fd
, &rfds
);
1276 if (!ioh
->deleted
&& ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1277 ioh
->fd_write(ioh
->opaque
);
1280 /* Do this last in case read/write handlers marked it for deletion */
1282 QLIST_REMOVE(ioh
, next
);
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 if (kvm_enabled()) {
1319 cpu_disable_ticks();
1323 qemu_main_loop_start();
1327 bool nonblocking
= false;
1328 #ifdef CONFIG_PROFILER
1331 #ifndef CONFIG_IOTHREAD
1332 nonblocking
= cpu_exec_all();
1334 #ifdef CONFIG_PROFILER
1335 ti
= profile_getclock();
1337 main_loop_wait(nonblocking
);
1338 #ifdef CONFIG_PROFILER
1339 dev_time
+= profile_getclock() - ti
;
1341 } while (vm_can_run());
1343 if ((r
= qemu_debug_requested())) {
1346 if (qemu_shutdown_requested()) {
1347 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1354 if (qemu_reset_requested()) {
1356 qemu_system_reset();
1359 if (qemu_powerdown_requested()) {
1360 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1361 qemu_irq_raise(qemu_system_powerdown
);
1363 if ((r
= qemu_vmstop_requested())) {
1371 static void version(void)
1373 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1376 static void help(int exitcode
)
1378 const char *options_help
=
1379 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1381 #define DEFHEADING(text) stringify(text) "\n"
1382 #include "qemu-options.def"
1388 printf("usage: %s [options] [disk_image]\n"
1390 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1393 "During emulation, the following keys are useful:\n"
1394 "ctrl-alt-f toggle full screen\n"
1395 "ctrl-alt-n switch to virtual console 'n'\n"
1396 "ctrl-alt toggle mouse and keyboard grab\n"
1398 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1404 #define HAS_ARG 0x0001
1406 typedef struct QEMUOption
{
1413 static const QEMUOption qemu_options
[] = {
1414 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1415 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1416 { option, opt_arg, opt_enum, arch_mask },
1417 #define DEFHEADING(text)
1418 #include "qemu-options.def"
1424 static void select_vgahw (const char *p
)
1429 vga_interface_type
= VGA_NONE
;
1430 if (strstart(p
, "std", &opts
)) {
1431 vga_interface_type
= VGA_STD
;
1432 } else if (strstart(p
, "cirrus", &opts
)) {
1433 vga_interface_type
= VGA_CIRRUS
;
1434 } else if (strstart(p
, "vmware", &opts
)) {
1435 vga_interface_type
= VGA_VMWARE
;
1436 } else if (strstart(p
, "xenfb", &opts
)) {
1437 vga_interface_type
= VGA_XENFB
;
1438 } else if (!strstart(p
, "none", &opts
)) {
1440 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1444 const char *nextopt
;
1446 if (strstart(opts
, ",retrace=", &nextopt
)) {
1448 if (strstart(opts
, "dumb", &nextopt
))
1449 vga_retrace_method
= VGA_RETRACE_DUMB
;
1450 else if (strstart(opts
, "precise", &nextopt
))
1451 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1452 else goto invalid_vga
;
1453 } else goto invalid_vga
;
1458 static int balloon_parse(const char *arg
)
1462 if (strcmp(arg
, "none") == 0) {
1466 if (!strncmp(arg
, "virtio", 6)) {
1467 if (arg
[6] == ',') {
1468 /* have params -> parse them */
1469 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1473 /* create empty opts */
1474 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1476 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1483 char *qemu_find_file(int type
, const char *name
)
1489 /* If name contains path separators then try it as a straight path. */
1490 if ((strchr(name
, '/') || strchr(name
, '\\'))
1491 && access(name
, R_OK
) == 0) {
1492 return qemu_strdup(name
);
1495 case QEMU_FILE_TYPE_BIOS
:
1498 case QEMU_FILE_TYPE_KEYMAP
:
1499 subdir
= "keymaps/";
1504 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1505 buf
= qemu_mallocz(len
);
1506 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1507 if (access(buf
, R_OK
)) {
1514 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1516 return qdev_device_help(opts
);
1519 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1523 dev
= qdev_device_add(opts
);
1529 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1531 CharDriverState
*chr
;
1533 chr
= qemu_chr_open_opts(opts
, NULL
);
1539 #ifdef CONFIG_VIRTFS
1540 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1543 ret
= qemu_fsdev_add(opts
);
1549 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1551 CharDriverState
*chr
;
1552 const char *chardev
;
1556 mode
= qemu_opt_get(opts
, "mode");
1560 if (strcmp(mode
, "readline") == 0) {
1561 flags
= MONITOR_USE_READLINE
;
1562 } else if (strcmp(mode
, "control") == 0) {
1563 flags
= MONITOR_USE_CONTROL
;
1565 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1569 if (qemu_opt_get_bool(opts
, "pretty", 0))
1570 flags
|= MONITOR_USE_PRETTY
;
1572 if (qemu_opt_get_bool(opts
, "default", 0))
1573 flags
|= MONITOR_IS_DEFAULT
;
1575 chardev
= qemu_opt_get(opts
, "chardev");
1576 chr
= qemu_chr_find(chardev
);
1578 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1582 monitor_init(chr
, flags
);
1586 static void monitor_parse(const char *optarg
, const char *mode
)
1588 static int monitor_device_index
= 0;
1594 if (strstart(optarg
, "chardev:", &p
)) {
1595 snprintf(label
, sizeof(label
), "%s", p
);
1597 snprintf(label
, sizeof(label
), "compat_monitor%d",
1598 monitor_device_index
);
1599 if (monitor_device_index
== 0) {
1602 opts
= qemu_chr_parse_compat(label
, optarg
);
1604 fprintf(stderr
, "parse error: %s\n", optarg
);
1609 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1611 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1614 qemu_opt_set(opts
, "mode", mode
);
1615 qemu_opt_set(opts
, "chardev", label
);
1617 qemu_opt_set(opts
, "default", "on");
1618 monitor_device_index
++;
1621 struct device_config
{
1623 DEV_USB
, /* -usbdevice */
1625 DEV_SERIAL
, /* -serial */
1626 DEV_PARALLEL
, /* -parallel */
1627 DEV_VIRTCON
, /* -virtioconsole */
1628 DEV_DEBUGCON
, /* -debugcon */
1630 const char *cmdline
;
1631 QTAILQ_ENTRY(device_config
) next
;
1633 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1635 static void add_device_config(int type
, const char *cmdline
)
1637 struct device_config
*conf
;
1639 conf
= qemu_mallocz(sizeof(*conf
));
1641 conf
->cmdline
= cmdline
;
1642 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1645 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1647 struct device_config
*conf
;
1650 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1651 if (conf
->type
!= type
)
1653 rc
= func(conf
->cmdline
);
1660 static int serial_parse(const char *devname
)
1662 static int index
= 0;
1665 if (strcmp(devname
, "none") == 0)
1667 if (index
== MAX_SERIAL_PORTS
) {
1668 fprintf(stderr
, "qemu: too many serial ports\n");
1671 snprintf(label
, sizeof(label
), "serial%d", index
);
1672 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1673 if (!serial_hds
[index
]) {
1674 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1675 devname
, strerror(errno
));
1682 static int parallel_parse(const char *devname
)
1684 static int index
= 0;
1687 if (strcmp(devname
, "none") == 0)
1689 if (index
== MAX_PARALLEL_PORTS
) {
1690 fprintf(stderr
, "qemu: too many parallel ports\n");
1693 snprintf(label
, sizeof(label
), "parallel%d", index
);
1694 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1695 if (!parallel_hds
[index
]) {
1696 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1697 devname
, strerror(errno
));
1704 static int virtcon_parse(const char *devname
)
1706 QemuOptsList
*device
= qemu_find_opts("device");
1707 static int index
= 0;
1709 QemuOpts
*bus_opts
, *dev_opts
;
1711 if (strcmp(devname
, "none") == 0)
1713 if (index
== MAX_VIRTIO_CONSOLES
) {
1714 fprintf(stderr
, "qemu: too many virtio consoles\n");
1718 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1719 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1721 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1722 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1724 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1725 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1726 if (!virtcon_hds
[index
]) {
1727 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1728 devname
, strerror(errno
));
1731 qemu_opt_set(dev_opts
, "chardev", label
);
1737 static int debugcon_parse(const char *devname
)
1741 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1744 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1746 fprintf(stderr
, "qemu: already have a debugcon device\n");
1749 qemu_opt_set(opts
, "driver", "isa-debugcon");
1750 qemu_opt_set(opts
, "chardev", "debugcon");
1754 void qemu_add_exit_notifier(Notifier
*notify
)
1756 notifier_list_add(&exit_notifiers
, notify
);
1759 void qemu_remove_exit_notifier(Notifier
*notify
)
1761 notifier_list_remove(&exit_notifiers
, notify
);
1764 static void qemu_run_exit_notifiers(void)
1766 notifier_list_notify(&exit_notifiers
);
1769 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1770 const char **poptarg
, int *poptind
)
1772 const QEMUOption
*popt
;
1773 int optind
= *poptind
;
1774 char *r
= argv
[optind
];
1777 loc_set_cmdline(argv
, optind
, 1);
1779 /* Treat --foo the same as -foo. */
1782 popt
= qemu_options
;
1785 error_report("invalid option");
1788 if (!strcmp(popt
->name
, r
+ 1))
1792 if (popt
->flags
& HAS_ARG
) {
1793 if (optind
>= argc
) {
1794 error_report("requires an argument");
1797 optarg
= argv
[optind
++];
1798 loc_set_cmdline(argv
, optind
- 2, 2);
1809 int main(int argc
, char **argv
, char **envp
)
1811 const char *gdbstub_dev
= NULL
;
1813 int snapshot
, linux_boot
;
1814 const char *icount_option
= NULL
;
1815 const char *initrd_filename
;
1816 const char *kernel_filename
, *kernel_cmdline
;
1817 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1819 DisplayChangeListener
*dcl
;
1820 int cyls
, heads
, secs
, translation
;
1821 QemuOpts
*hda_opts
= NULL
, *opts
;
1822 QemuOptsList
*olist
;
1825 const char *loadvm
= NULL
;
1826 QEMUMachine
*machine
;
1827 const char *cpu_model
;
1829 const char *pid_file
= NULL
;
1830 const char *incoming
= NULL
;
1831 int show_vnc_port
= 0;
1834 #ifdef CONFIG_SIMPLE_TRACE
1835 const char *trace_file
= NULL
;
1837 atexit(qemu_run_exit_notifiers
);
1838 error_set_progname(argv
[0]);
1842 qemu_cache_utils_init(envp
);
1844 QLIST_INIT (&vm_change_state_head
);
1845 os_setup_early_signal_handling();
1847 module_call_init(MODULE_INIT_MACHINE
);
1848 machine
= find_default_machine();
1850 initrd_filename
= NULL
;
1853 kernel_filename
= NULL
;
1854 kernel_cmdline
= "";
1855 cyls
= heads
= secs
= 0;
1856 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1858 for (i
= 0; i
< MAX_NODES
; i
++) {
1860 node_cpumask
[i
] = 0;
1869 /* first pass of option parsing */
1871 while (optind
< argc
) {
1872 if (argv
[optind
][0] != '-') {
1877 const QEMUOption
*popt
;
1879 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1880 switch (popt
->index
) {
1881 case QEMU_OPTION_nodefconfig
:
1891 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1892 if (ret
< 0 && ret
!= -ENOENT
) {
1896 ret
= qemu_read_config_file(arch_config_name
);
1897 if (ret
< 0 && ret
!= -ENOENT
) {
1903 /* second pass of option parsing */
1908 if (argv
[optind
][0] != '-') {
1909 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1911 const QEMUOption
*popt
;
1913 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1914 if (!(popt
->arch_mask
& arch_type
)) {
1915 printf("Option %s not supported for this target\n", popt
->name
);
1918 switch(popt
->index
) {
1920 machine
= find_machine(optarg
);
1923 printf("Supported machines are:\n");
1924 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1926 printf("%-10s %s (alias of %s)\n",
1927 m
->alias
, m
->desc
, m
->name
);
1928 printf("%-10s %s%s\n",
1930 m
->is_default
? " (default)" : "");
1932 exit(*optarg
!= '?');
1935 case QEMU_OPTION_cpu
:
1936 /* hw initialization will check this */
1937 if (*optarg
== '?') {
1938 list_cpus(stdout
, &fprintf
, optarg
);
1944 case QEMU_OPTION_initrd
:
1945 initrd_filename
= optarg
;
1947 case QEMU_OPTION_hda
:
1949 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
1951 hda_opts
= drive_add(optarg
, HD_ALIAS
1952 ",cyls=%d,heads=%d,secs=%d%s",
1953 0, cyls
, heads
, secs
,
1954 translation
== BIOS_ATA_TRANSLATION_LBA
?
1956 translation
== BIOS_ATA_TRANSLATION_NONE
?
1957 ",trans=none" : "");
1959 case QEMU_OPTION_hdb
:
1960 case QEMU_OPTION_hdc
:
1961 case QEMU_OPTION_hdd
:
1962 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
1964 case QEMU_OPTION_drive
:
1965 drive_add(NULL
, "%s", optarg
);
1967 case QEMU_OPTION_set
:
1968 if (qemu_set_option(optarg
) != 0)
1971 case QEMU_OPTION_global
:
1972 if (qemu_global_option(optarg
) != 0)
1975 case QEMU_OPTION_mtdblock
:
1976 drive_add(optarg
, MTD_ALIAS
);
1978 case QEMU_OPTION_sd
:
1979 drive_add(optarg
, SD_ALIAS
);
1981 case QEMU_OPTION_pflash
:
1982 drive_add(optarg
, PFLASH_ALIAS
);
1984 case QEMU_OPTION_snapshot
:
1987 case QEMU_OPTION_hdachs
:
1991 cyls
= strtol(p
, (char **)&p
, 0);
1992 if (cyls
< 1 || cyls
> 16383)
1997 heads
= strtol(p
, (char **)&p
, 0);
1998 if (heads
< 1 || heads
> 16)
2003 secs
= strtol(p
, (char **)&p
, 0);
2004 if (secs
< 1 || secs
> 63)
2008 if (!strcmp(p
, "none"))
2009 translation
= BIOS_ATA_TRANSLATION_NONE
;
2010 else if (!strcmp(p
, "lba"))
2011 translation
= BIOS_ATA_TRANSLATION_LBA
;
2012 else if (!strcmp(p
, "auto"))
2013 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2016 } else if (*p
!= '\0') {
2018 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2021 if (hda_opts
!= NULL
) {
2023 snprintf(num
, sizeof(num
), "%d", cyls
);
2024 qemu_opt_set(hda_opts
, "cyls", num
);
2025 snprintf(num
, sizeof(num
), "%d", heads
);
2026 qemu_opt_set(hda_opts
, "heads", num
);
2027 snprintf(num
, sizeof(num
), "%d", secs
);
2028 qemu_opt_set(hda_opts
, "secs", num
);
2029 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2030 qemu_opt_set(hda_opts
, "trans", "lba");
2031 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2032 qemu_opt_set(hda_opts
, "trans", "none");
2036 case QEMU_OPTION_numa
:
2037 if (nb_numa_nodes
>= MAX_NODES
) {
2038 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2043 case QEMU_OPTION_nographic
:
2044 display_type
= DT_NOGRAPHIC
;
2046 #ifdef CONFIG_CURSES
2047 case QEMU_OPTION_curses
:
2048 display_type
= DT_CURSES
;
2051 case QEMU_OPTION_portrait
:
2054 case QEMU_OPTION_kernel
:
2055 kernel_filename
= optarg
;
2057 case QEMU_OPTION_append
:
2058 kernel_cmdline
= optarg
;
2060 case QEMU_OPTION_cdrom
:
2061 drive_add(optarg
, CDROM_ALIAS
);
2063 case QEMU_OPTION_boot
:
2065 static const char * const params
[] = {
2066 "order", "once", "menu", NULL
2068 char buf
[sizeof(boot_devices
)];
2069 char *standard_boot_devices
;
2072 if (!strchr(optarg
, '=')) {
2074 pstrcpy(buf
, sizeof(buf
), optarg
);
2075 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2077 "qemu: unknown boot parameter '%s' in '%s'\n",
2083 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2084 validate_bootdevices(buf
);
2085 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2088 if (get_param_value(buf
, sizeof(buf
),
2090 validate_bootdevices(buf
);
2091 standard_boot_devices
= qemu_strdup(boot_devices
);
2092 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2093 qemu_register_reset(restore_boot_devices
,
2094 standard_boot_devices
);
2096 if (get_param_value(buf
, sizeof(buf
),
2098 if (!strcmp(buf
, "on")) {
2100 } else if (!strcmp(buf
, "off")) {
2104 "qemu: invalid option value '%s'\n",
2112 case QEMU_OPTION_fda
:
2113 case QEMU_OPTION_fdb
:
2114 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2116 case QEMU_OPTION_no_fd_bootchk
:
2119 case QEMU_OPTION_netdev
:
2120 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2124 case QEMU_OPTION_net
:
2125 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2130 case QEMU_OPTION_tftp
:
2131 legacy_tftp_prefix
= optarg
;
2133 case QEMU_OPTION_bootp
:
2134 legacy_bootp_filename
= optarg
;
2136 case QEMU_OPTION_redir
:
2137 if (net_slirp_redir(optarg
) < 0)
2141 case QEMU_OPTION_bt
:
2142 add_device_config(DEV_BT
, optarg
);
2144 case QEMU_OPTION_audio_help
:
2145 if (!(audio_available())) {
2146 printf("Option %s not supported for this target\n", popt
->name
);
2152 case QEMU_OPTION_soundhw
:
2153 if (!(audio_available())) {
2154 printf("Option %s not supported for this target\n", popt
->name
);
2157 select_soundhw (optarg
);
2162 case QEMU_OPTION_version
:
2166 case QEMU_OPTION_m
: {
2169 value
= strtosz(optarg
, NULL
);
2171 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2175 /* On 32-bit hosts, QEMU is limited by virtual address space */
2176 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2177 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2180 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2181 fprintf(stderr
, "qemu: ram size too large\n");
2187 case QEMU_OPTION_mempath
:
2191 case QEMU_OPTION_mem_prealloc
:
2196 set_cpu_log(optarg
);
2199 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2201 case QEMU_OPTION_gdb
:
2202 gdbstub_dev
= optarg
;
2207 case QEMU_OPTION_bios
:
2210 case QEMU_OPTION_singlestep
:
2217 keyboard_layout
= optarg
;
2219 case QEMU_OPTION_localtime
:
2222 case QEMU_OPTION_vga
:
2223 select_vgahw (optarg
);
2230 w
= strtol(p
, (char **)&p
, 10);
2233 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2239 h
= strtol(p
, (char **)&p
, 10);
2244 depth
= strtol(p
, (char **)&p
, 10);
2245 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2246 depth
!= 24 && depth
!= 32)
2248 } else if (*p
== '\0') {
2249 depth
= graphic_depth
;
2256 graphic_depth
= depth
;
2259 case QEMU_OPTION_echr
:
2262 term_escape_char
= strtol(optarg
, &r
, 0);
2264 printf("Bad argument to echr\n");
2267 case QEMU_OPTION_monitor
:
2268 monitor_parse(optarg
, "readline");
2269 default_monitor
= 0;
2271 case QEMU_OPTION_qmp
:
2272 monitor_parse(optarg
, "control");
2273 default_monitor
= 0;
2275 case QEMU_OPTION_mon
:
2276 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2280 default_monitor
= 0;
2282 case QEMU_OPTION_chardev
:
2283 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2288 case QEMU_OPTION_fsdev
:
2289 olist
= qemu_find_opts("fsdev");
2291 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2294 opts
= qemu_opts_parse(olist
, optarg
, 1);
2296 fprintf(stderr
, "parse error: %s\n", optarg
);
2300 case QEMU_OPTION_virtfs
: {
2301 char *arg_fsdev
= NULL
;
2302 char *arg_9p
= NULL
;
2305 olist
= qemu_find_opts("virtfs");
2307 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2310 opts
= qemu_opts_parse(olist
, optarg
, 1);
2312 fprintf(stderr
, "parse error: %s\n", optarg
);
2316 if (qemu_opt_get(opts
, "fstype") == NULL
||
2317 qemu_opt_get(opts
, "mount_tag") == NULL
||
2318 qemu_opt_get(opts
, "path") == NULL
||
2319 qemu_opt_get(opts
, "security_model") == NULL
) {
2320 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2321 "security_model=[mapped|passthrough|none],"
2326 len
= strlen(",id=,path=,security_model=");
2327 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2328 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2329 len
+= strlen(qemu_opt_get(opts
, "path"));
2330 len
+= strlen(qemu_opt_get(opts
, "security_model"));
2331 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2333 snprintf(arg_fsdev
, (len
+ 1) * sizeof(*arg_fsdev
),
2334 "%s,id=%s,path=%s,security_model=%s",
2335 qemu_opt_get(opts
, "fstype"),
2336 qemu_opt_get(opts
, "mount_tag"),
2337 qemu_opt_get(opts
, "path"),
2338 qemu_opt_get(opts
, "security_model"));
2340 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2341 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2342 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2344 snprintf(arg_9p
, (len
+ 1) * sizeof(*arg_9p
),
2345 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2346 qemu_opt_get(opts
, "mount_tag"),
2347 qemu_opt_get(opts
, "mount_tag"));
2349 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev
, 1)) {
2350 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2354 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p
, 1)) {
2355 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2359 qemu_free(arg_fsdev
);
2363 case QEMU_OPTION_serial
:
2364 add_device_config(DEV_SERIAL
, optarg
);
2366 if (strncmp(optarg
, "mon:", 4) == 0) {
2367 default_monitor
= 0;
2370 case QEMU_OPTION_watchdog
:
2373 "qemu: only one watchdog option may be given\n");
2378 case QEMU_OPTION_watchdog_action
:
2379 if (select_watchdog_action(optarg
) == -1) {
2380 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2384 case QEMU_OPTION_virtiocon
:
2385 add_device_config(DEV_VIRTCON
, optarg
);
2386 default_virtcon
= 0;
2387 if (strncmp(optarg
, "mon:", 4) == 0) {
2388 default_monitor
= 0;
2391 case QEMU_OPTION_parallel
:
2392 add_device_config(DEV_PARALLEL
, optarg
);
2393 default_parallel
= 0;
2394 if (strncmp(optarg
, "mon:", 4) == 0) {
2395 default_monitor
= 0;
2398 case QEMU_OPTION_debugcon
:
2399 add_device_config(DEV_DEBUGCON
, optarg
);
2401 case QEMU_OPTION_loadvm
:
2404 case QEMU_OPTION_full_screen
:
2408 case QEMU_OPTION_no_frame
:
2411 case QEMU_OPTION_alt_grab
:
2414 case QEMU_OPTION_ctrl_grab
:
2417 case QEMU_OPTION_no_quit
:
2420 case QEMU_OPTION_sdl
:
2421 display_type
= DT_SDL
;
2424 case QEMU_OPTION_pidfile
:
2427 case QEMU_OPTION_win2k_hack
:
2428 win2k_install_hack
= 1;
2430 case QEMU_OPTION_rtc_td_hack
:
2433 case QEMU_OPTION_acpitable
:
2434 do_acpitable_option(optarg
);
2436 case QEMU_OPTION_smbios
:
2437 do_smbios_option(optarg
);
2439 #ifdef OBSOLETE_KVM_IMPL
2440 case QEMU_OPTION_enable_kvm
:
2444 case QEMU_OPTION_no_kvm
:
2446 #ifdef CONFIG_NO_CPU_EMULATION
2447 fprintf(stderr
, "cpu emulation not configured\n");
2452 case QEMU_OPTION_no_kvm_irqchip
: {
2457 case QEMU_OPTION_no_kvm_pit
: {
2461 case QEMU_OPTION_no_kvm_pit_reinjection
: {
2462 kvm_pit_reinject
= 0;
2465 case QEMU_OPTION_enable_nesting
: {
2470 case QEMU_OPTION_usb
:
2473 case QEMU_OPTION_usbdevice
:
2475 add_device_config(DEV_USB
, optarg
);
2477 case QEMU_OPTION_device
:
2478 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2482 case QEMU_OPTION_smp
:
2485 fprintf(stderr
, "Invalid number of CPUs\n");
2488 if (max_cpus
< smp_cpus
) {
2489 fprintf(stderr
, "maxcpus must be equal to or greater than "
2493 if (max_cpus
> 255) {
2494 fprintf(stderr
, "Unsupported number of maxcpus\n");
2498 case QEMU_OPTION_vnc
:
2500 vnc_display
= optarg
;
2502 case QEMU_OPTION_no_acpi
:
2505 case QEMU_OPTION_no_hpet
:
2508 case QEMU_OPTION_balloon
:
2509 if (balloon_parse(optarg
) < 0) {
2510 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2514 case QEMU_OPTION_no_reboot
:
2517 case QEMU_OPTION_no_shutdown
:
2520 case QEMU_OPTION_show_cursor
:
2523 case QEMU_OPTION_uuid
:
2524 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2525 fprintf(stderr
, "Fail to parse UUID string."
2526 " Wrong format.\n");
2530 case QEMU_OPTION_option_rom
:
2531 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2532 fprintf(stderr
, "Too many option ROMs\n");
2535 option_rom
[nb_option_roms
] = optarg
;
2538 case QEMU_OPTION_semihosting
:
2539 semihosting_enabled
= 1;
2541 case QEMU_OPTION_tdf
:
2544 case QEMU_OPTION_kvm_shadow_memory
:
2545 kvm_shadow_memory
= (int64_t)atoi(optarg
) * 1024 * 1024 / 4096;
2547 case QEMU_OPTION_name
:
2548 qemu_name
= qemu_strdup(optarg
);
2550 char *p
= strchr(qemu_name
, ',');
2553 if (strncmp(p
, "process=", 8)) {
2554 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2558 os_set_proc_name(p
);
2562 case QEMU_OPTION_prom_env
:
2563 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2564 fprintf(stderr
, "Too many prom variables\n");
2567 prom_envs
[nb_prom_envs
] = optarg
;
2570 case QEMU_OPTION_old_param
:
2573 case QEMU_OPTION_clock
:
2574 configure_alarms(optarg
);
2576 case QEMU_OPTION_startdate
:
2577 configure_rtc_date_offset(optarg
, 1);
2579 case QEMU_OPTION_rtc
:
2580 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2584 configure_rtc(opts
);
2586 case QEMU_OPTION_tb_size
:
2587 tb_size
= strtol(optarg
, NULL
, 0);
2591 case QEMU_OPTION_icount
:
2592 icount_option
= optarg
;
2594 case QEMU_OPTION_incoming
:
2596 incoming_expected
= true;
2598 case QEMU_OPTION_nodefaults
:
2600 default_parallel
= 0;
2601 default_virtcon
= 0;
2602 default_monitor
= 0;
2610 case QEMU_OPTION_nvram
:
2614 case QEMU_OPTION_xen_domid
:
2615 if (!(xen_available())) {
2616 printf("Option %s not supported for this target\n", popt
->name
);
2619 xen_domid
= atoi(optarg
);
2621 case QEMU_OPTION_xen_create
:
2622 if (!(xen_available())) {
2623 printf("Option %s not supported for this target\n", popt
->name
);
2626 xen_mode
= XEN_CREATE
;
2628 case QEMU_OPTION_xen_attach
:
2629 if (!(xen_available())) {
2630 printf("Option %s not supported for this target\n", popt
->name
);
2633 xen_mode
= XEN_ATTACH
;
2635 #ifdef CONFIG_SIMPLE_TRACE
2636 case QEMU_OPTION_trace
:
2637 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2639 trace_file
= qemu_opt_get(opts
, "file");
2643 case QEMU_OPTION_readconfig
:
2645 int ret
= qemu_read_config_file(optarg
);
2647 fprintf(stderr
, "read config %s: %s\n", optarg
,
2653 case QEMU_OPTION_spice
:
2654 olist
= qemu_find_opts("spice");
2656 fprintf(stderr
, "spice is not supported by this qemu build.\n");
2659 opts
= qemu_opts_parse(olist
, optarg
, 0);
2661 fprintf(stderr
, "parse error: %s\n", optarg
);
2665 case QEMU_OPTION_writeconfig
:
2668 if (strcmp(optarg
, "-") == 0) {
2671 fp
= fopen(optarg
, "w");
2673 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2677 qemu_config_write(fp
);
2682 os_parse_cmd_args(popt
->index
, optarg
);
2688 /* If no data_dir is specified then try to find it relative to the
2691 data_dir
= os_find_datadir(argv
[0]);
2693 /* If all else fails use the install patch specified when building. */
2695 data_dir
= CONFIG_QEMU_DATADIR
;
2698 #ifdef CONFIG_SIMPLE_TRACE
2700 * Set the trace file name, if specified.
2702 st_set_trace_file(trace_file
);
2705 * Default to max_cpus = smp_cpus, in case the user doesn't
2706 * specify a max_cpus value.
2709 max_cpus
= smp_cpus
;
2711 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2712 if (smp_cpus
> machine
->max_cpus
) {
2713 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2714 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2719 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2720 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2722 if (machine
->no_serial
) {
2725 if (machine
->no_parallel
) {
2726 default_parallel
= 0;
2728 if (!machine
->use_virtcon
) {
2729 default_virtcon
= 0;
2731 if (machine
->no_vga
) {
2734 if (machine
->no_floppy
) {
2737 if (machine
->no_cdrom
) {
2740 if (machine
->no_sdcard
) {
2744 if (display_type
== DT_NOGRAPHIC
) {
2745 if (default_parallel
)
2746 add_device_config(DEV_PARALLEL
, "null");
2747 if (default_serial
&& default_monitor
) {
2748 add_device_config(DEV_SERIAL
, "mon:stdio");
2749 } else if (default_virtcon
&& default_monitor
) {
2750 add_device_config(DEV_VIRTCON
, "mon:stdio");
2753 add_device_config(DEV_SERIAL
, "stdio");
2754 if (default_virtcon
)
2755 add_device_config(DEV_VIRTCON
, "stdio");
2756 if (default_monitor
)
2757 monitor_parse("stdio", "readline");
2761 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2762 if (default_parallel
)
2763 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2764 if (default_monitor
)
2765 monitor_parse("vc:80Cx24C", "readline");
2766 if (default_virtcon
)
2767 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2770 vga_interface_type
= VGA_CIRRUS
;
2774 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
2776 #ifdef CONFIG_VIRTFS
2777 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
2784 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2790 int ret
= kvm_init(smp_cpus
);
2792 #if defined(OBSOLETE_KVM_IMPL) || defined(CONFIG_NO_CPU_EMULATION)
2793 if (!kvm_available()) {
2794 printf("KVM not supported for this target\n");
2796 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2801 fprintf(stderr
, "Could not initialize KVM, will disable KVM support\n");
2807 if (qemu_init_main_loop()) {
2808 fprintf(stderr
, "qemu_init_main_loop failed\n");
2811 linux_boot
= (kernel_filename
!= NULL
);
2813 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2814 fprintf(stderr
, "-append only allowed with -kernel option\n");
2818 if (!linux_boot
&& initrd_filename
!= NULL
) {
2819 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2823 os_set_line_buffering();
2825 if (init_timer_alarm() < 0) {
2826 fprintf(stderr
, "could not initialize alarm timer\n");
2829 configure_icount(icount_option
);
2831 if (net_init_clients() < 0) {
2835 /* init the bluetooth world */
2836 if (foreach_device_config(DEV_BT
, bt_parse
))
2839 /* init the memory */
2841 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2843 /* init the dynamic translator */
2844 cpu_exec_init_all(tb_size
* 1024 * 1024);
2846 bdrv_init_with_whitelist();
2850 if (default_cdrom
) {
2851 /* we always create the cdrom drive, even if no disk is there */
2852 drive_add(NULL
, CDROM_ALIAS
);
2855 if (default_floppy
) {
2856 /* we always create at least one floppy */
2857 drive_add(NULL
, FD_ALIAS
, 0);
2860 if (default_sdcard
) {
2861 /* we always create one sd slot, even if no card is in it */
2862 drive_add(NULL
, SD_ALIAS
);
2865 /* open the virtual block devices */
2867 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
2868 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
2871 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2874 if (nb_numa_nodes
> 0) {
2877 if (nb_numa_nodes
> smp_cpus
) {
2878 nb_numa_nodes
= smp_cpus
;
2881 /* If no memory size if given for any node, assume the default case
2882 * and distribute the available memory equally across all nodes
2884 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2885 if (node_mem
[i
] != 0)
2888 if (i
== nb_numa_nodes
) {
2889 uint64_t usedmem
= 0;
2891 /* On Linux, the each node's border has to be 8MB aligned,
2892 * the final node gets the rest.
2894 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2895 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2896 usedmem
+= node_mem
[i
];
2898 node_mem
[i
] = ram_size
- usedmem
;
2901 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2902 if (node_cpumask
[i
] != 0)
2905 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2906 * must cope with this anyway, because there are BIOSes out there in
2907 * real machines which also use this scheme.
2909 if (i
== nb_numa_nodes
) {
2910 for (i
= 0; i
< smp_cpus
; i
++) {
2911 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2916 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
2920 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2922 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2924 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2926 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2929 module_call_init(MODULE_INIT_DEVICE
);
2931 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
2935 i
= select_watchdog(watchdog
);
2937 exit (i
== 1 ? 1 : 0);
2940 if (machine
->compat_props
) {
2941 qdev_prop_register_global_list(machine
->compat_props
);
2945 machine
->init(ram_size
, boot_devices
,
2946 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2948 cpu_synchronize_all_post_init();
2950 /* must be after terminal init, SDL library changes signal handlers */
2951 os_setup_signal_handling();
2955 current_machine
= machine
;
2957 /* init USB devices */
2959 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2963 /* init generic devices */
2964 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
2967 net_check_clients();
2969 /* just use the first displaystate for the moment */
2970 ds
= get_displaystate();
2974 if (display_type
== DT_DEFAULT
&& !display_remote
) {
2975 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
2976 display_type
= DT_SDL
;
2978 vnc_display
= "localhost:0,to=99";
2984 /* init local displays */
2985 switch (display_type
) {
2988 #if defined(CONFIG_CURSES)
2990 curses_display_init(ds
, full_screen
);
2993 #if defined(CONFIG_SDL)
2995 sdl_display_init(ds
, full_screen
, no_frame
);
2997 #elif defined(CONFIG_COCOA)
2999 cocoa_display_init(ds
, full_screen
);
3006 /* init remote displays */
3008 vnc_display_init(ds
);
3009 if (vnc_display_open(ds
, vnc_display
) < 0)
3012 if (show_vnc_port
) {
3013 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3018 qemu_spice_display_init(ds
);
3024 dcl
= ds
->listeners
;
3025 while (dcl
!= NULL
) {
3026 if (dcl
->dpy_refresh
!= NULL
) {
3027 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
3028 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
3033 if (ds
->gui_timer
== NULL
) {
3034 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
3035 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
3037 text_consoles_set_display(ds
);
3039 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3040 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3045 qdev_machine_creation_done();
3047 if (rom_load_all() != 0) {
3048 fprintf(stderr
, "rom loading failed\n");
3052 qemu_system_reset();
3054 if (load_vmstate(loadvm
) < 0) {
3060 int ret
= qemu_start_incoming_migration(incoming
);
3062 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3066 } else if (autostart
) {