4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 /* Needed early for CONFIG_BSD etc. */
33 #include "config-host.h"
37 #include <sys/times.h>
41 #include <sys/ioctl.h>
42 #include <sys/resource.h>
43 #include <sys/socket.h>
44 #include <netinet/in.h>
46 #include <arpa/inet.h>
49 #include <sys/select.h>
52 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
54 #include <sys/sysctl.h>
63 #include <linux/ppdev.h>
64 #include <linux/parport.h>
68 #include <sys/ethernet.h>
69 #include <sys/sockio.h>
70 #include <netinet/arp.h>
71 #include <netinet/in_systm.h>
72 #include <netinet/ip.h>
73 #include <netinet/ip_icmp.h> // must come after ip.h
74 #include <netinet/udp.h>
75 #include <netinet/tcp.h>
79 /* See MySQL bug #7156 (http://bugs.mysql.com/bug.php?id=7156) for
80 discussion about Solaris header problems */
81 extern int madvise(caddr_t
, size_t, int);
86 #if defined(__OpenBSD__)
90 #if defined(CONFIG_VDE)
91 #include <libvdeplug.h>
99 #if defined(__APPLE__) || defined(main)
101 int qemu_main(int argc
, char **argv
, char **envp
);
102 int main(int argc
, char **argv
)
104 return qemu_main(argc
, argv
, NULL
);
107 #define main qemu_main
109 #endif /* CONFIG_SDL */
113 #define main qemu_main
114 #endif /* CONFIG_COCOA */
117 #include "hw/boards.h"
119 #include "hw/pcmcia.h"
124 #include "hw/watchdog.h"
125 #include "hw/smbios.h"
128 #include "hw/loader.h"
131 #include "net/slirp.h"
136 #include "qemu-timer.h"
137 #include "qemu-char.h"
138 #include "cache-utils.h"
140 #include "blockdev.h"
141 #include "block-migration.h"
143 #include "audio/audio.h"
144 #include "migration.h"
146 #include "qemu-option.h"
147 #include "qemu-config.h"
148 #include "qemu-objects.h"
149 #include "qemu-options.h"
150 #include "hw/device-assignment.h"
152 #include "fsdev/qemu-fsdev.h"
157 #include "qemu_socket.h"
159 #include "slirp/libslirp.h"
161 #include "qemu-queue.h"
163 #include "arch_init.h"
166 //#define DEBUG_SLIRP
168 #define DEFAULT_RAM_SIZE 128
170 #define MAX_VIRTIO_CONSOLES 1
172 static const char *data_dir
;
173 const char *bios_name
= NULL
;
174 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
175 DisplayType display_type
= DT_DEFAULT
;
176 const char* keyboard_layout
= NULL
;
178 const char *mem_path
= NULL
;
180 int mem_prealloc
= 0; /* force preallocation of physical target memory */
183 NICInfo nd_table
[MAX_NICS
];
186 int incoming_expected
; /* Started with -incoming and waiting for incoming */
187 static int rtc_utc
= 1;
188 static int rtc_date_offset
= -1; /* -1 means no change */
189 QEMUClock
*rtc_clock
;
190 int vga_interface_type
= VGA_NONE
;
191 static int full_screen
= 0;
193 static int no_frame
= 0;
196 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
197 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
198 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
199 int win2k_install_hack
= 0;
203 const char *assigned_devices
[MAX_DEV_ASSIGN_CMDLINE
];
204 int assigned_devices_index
;
209 const char *vnc_display
;
210 int acpi_enabled
= 1;
216 int graphic_rotate
= 0;
217 uint8_t irq0override
= 1;
218 const char *watchdog
;
219 const char *option_rom
[MAX_OPTION_ROMS
];
221 int semihosting_enabled
= 0;
222 int time_drift_fix
= 0;
223 unsigned int kvm_shadow_memory
= 0;
225 const char *qemu_name
;
228 unsigned int nb_prom_envs
= 0;
229 const char *prom_envs
[MAX_PROM_ENVS
];
230 const char *nvram
= NULL
;
234 uint64_t node_mem
[MAX_NODES
];
235 uint64_t node_cpumask
[MAX_NODES
];
237 static QEMUTimer
*nographic_timer
;
239 uint8_t qemu_uuid
[16];
241 static QEMUBootSetHandler
*boot_set_handler
;
242 static void *boot_set_opaque
;
244 static NotifierList exit_notifiers
=
245 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
249 enum xen_mode xen_mode
= XEN_EMULATE
;
251 static int default_serial
= 1;
252 static int default_parallel
= 1;
253 static int default_virtcon
= 1;
254 static int default_monitor
= 1;
255 static int default_vga
= 1;
256 static int default_floppy
= 1;
257 static int default_cdrom
= 1;
258 static int default_sdcard
= 1;
264 { .driver
= "isa-serial", .flag
= &default_serial
},
265 { .driver
= "isa-parallel", .flag
= &default_parallel
},
266 { .driver
= "isa-fdc", .flag
= &default_floppy
},
267 { .driver
= "ide-drive", .flag
= &default_cdrom
},
268 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
269 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
270 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
271 { .driver
= "VGA", .flag
= &default_vga
},
272 { .driver
= "cirrus-vga", .flag
= &default_vga
},
273 { .driver
= "vmware-svga", .flag
= &default_vga
},
276 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
278 const char *driver
= qemu_opt_get(opts
, "driver");
283 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
284 if (strcmp(default_list
[i
].driver
, driver
) != 0)
286 *(default_list
[i
].flag
) = 0;
291 /***********************************************************/
292 /* real time host monotonic timer */
294 /* compute with 96 bit intermediate result: (a*b)/c */
295 uint64_t muldiv64(uint64_t a
, uint32_t b
, uint32_t c
)
300 #ifdef HOST_WORDS_BIGENDIAN
310 rl
= (uint64_t)u
.l
.low
* (uint64_t)b
;
311 rh
= (uint64_t)u
.l
.high
* (uint64_t)b
;
314 res
.l
.low
= (((rh
% c
) << 32) + (rl
& 0xffffffff)) / c
;
318 /***********************************************************/
319 /* host time/date access */
320 void qemu_get_timedate(struct tm
*tm
, int offset
)
327 if (rtc_date_offset
== -1) {
331 ret
= localtime(&ti
);
333 ti
-= rtc_date_offset
;
337 memcpy(tm
, ret
, sizeof(struct tm
));
340 int qemu_timedate_diff(struct tm
*tm
)
344 if (rtc_date_offset
== -1)
346 seconds
= mktimegm(tm
);
348 seconds
= mktime(tm
);
350 seconds
= mktimegm(tm
) + rtc_date_offset
;
352 return seconds
- time(NULL
);
355 void rtc_change_mon_event(struct tm
*tm
)
359 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
360 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
361 qobject_decref(data
);
364 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
366 time_t rtc_start_date
;
369 if (!strcmp(startdate
, "now") && legacy
) {
370 rtc_date_offset
= -1;
372 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
380 } else if (sscanf(startdate
, "%d-%d-%d",
392 rtc_start_date
= mktimegm(&tm
);
393 if (rtc_start_date
== -1) {
395 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
396 "'2006-06-17T16:01:21' or '2006-06-17'\n");
399 rtc_date_offset
= time(NULL
) - rtc_start_date
;
403 static void configure_rtc(QemuOpts
*opts
)
407 value
= qemu_opt_get(opts
, "base");
409 if (!strcmp(value
, "utc")) {
411 } else if (!strcmp(value
, "localtime")) {
414 configure_rtc_date_offset(value
, 0);
417 value
= qemu_opt_get(opts
, "clock");
419 if (!strcmp(value
, "host")) {
420 rtc_clock
= host_clock
;
421 } else if (!strcmp(value
, "vm")) {
422 rtc_clock
= vm_clock
;
424 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
428 value
= qemu_opt_get(opts
, "driftfix");
430 if (!strcmp(value
, "slew")) {
432 } else if (!strcmp(value
, "none")) {
435 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
441 /***********************************************************/
442 /* Bluetooth support */
445 static struct HCIInfo
*hci_table
[MAX_NICS
];
447 static struct bt_vlan_s
{
448 struct bt_scatternet_s net
;
450 struct bt_vlan_s
*next
;
453 /* find or alloc a new bluetooth "VLAN" */
454 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
456 struct bt_vlan_s
**pvlan
, *vlan
;
457 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
461 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
463 pvlan
= &first_bt_vlan
;
464 while (*pvlan
!= NULL
)
465 pvlan
= &(*pvlan
)->next
;
470 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
474 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
479 static struct HCIInfo null_hci
= {
480 .cmd_send
= null_hci_send
,
481 .sco_send
= null_hci_send
,
482 .acl_send
= null_hci_send
,
483 .bdaddr_set
= null_hci_addr_set
,
486 struct HCIInfo
*qemu_next_hci(void)
488 if (cur_hci
== nb_hcis
)
491 return hci_table
[cur_hci
++];
494 static struct HCIInfo
*hci_init(const char *str
)
497 struct bt_scatternet_s
*vlan
= 0;
499 if (!strcmp(str
, "null"))
502 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
504 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
505 else if (!strncmp(str
, "hci", 3)) {
508 if (!strncmp(str
+ 3, ",vlan=", 6)) {
509 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
514 vlan
= qemu_find_bt_vlan(0);
516 return bt_new_hci(vlan
);
519 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
524 static int bt_hci_parse(const char *str
)
529 if (nb_hcis
>= MAX_NICS
) {
530 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
543 bdaddr
.b
[5] = 0x56 + nb_hcis
;
544 hci
->bdaddr_set(hci
, bdaddr
.b
);
546 hci_table
[nb_hcis
++] = hci
;
551 static void bt_vhci_add(int vlan_id
)
553 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
556 fprintf(stderr
, "qemu: warning: adding a VHCI to "
557 "an empty scatternet %i\n", vlan_id
);
559 bt_vhci_init(bt_new_hci(vlan
));
562 static struct bt_device_s
*bt_device_add(const char *opt
)
564 struct bt_scatternet_s
*vlan
;
566 char *endp
= strstr(opt
, ",vlan=");
567 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
570 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
573 vlan_id
= strtol(endp
+ 6, &endp
, 0);
575 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
580 vlan
= qemu_find_bt_vlan(vlan_id
);
583 fprintf(stderr
, "qemu: warning: adding a slave device to "
584 "an empty scatternet %i\n", vlan_id
);
586 if (!strcmp(devname
, "keyboard"))
587 return bt_keyboard_init(vlan
);
589 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
593 static int bt_parse(const char *opt
)
595 const char *endp
, *p
;
598 if (strstart(opt
, "hci", &endp
)) {
599 if (!*endp
|| *endp
== ',') {
601 if (!strstart(endp
, ",vlan=", 0))
604 return bt_hci_parse(opt
);
606 } else if (strstart(opt
, "vhci", &endp
)) {
607 if (!*endp
|| *endp
== ',') {
609 if (strstart(endp
, ",vlan=", &p
)) {
610 vlan
= strtol(p
, (char **) &endp
, 0);
612 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
616 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
625 } else if (strstart(opt
, "device:", &endp
))
626 return !bt_device_add(endp
);
628 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
632 /***********************************************************/
633 /* QEMU Block devices */
635 #define HD_ALIAS "index=%d,media=disk"
636 #define CDROM_ALIAS "index=2,media=cdrom"
637 #define FD_ALIAS "index=%d,if=floppy"
638 #define PFLASH_ALIAS "if=pflash"
639 #define MTD_ALIAS "if=mtd"
640 #define SD_ALIAS "index=0,if=sd"
642 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
644 int *use_scsi
= opaque
;
647 if (drive_init(opts
, *use_scsi
, &fatal_error
) == NULL
) {
654 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
656 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
657 qemu_opt_set(opts
, "snapshot", "on");
662 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
664 boot_set_handler
= func
;
665 boot_set_opaque
= opaque
;
668 int qemu_boot_set(const char *boot_devices
)
670 if (!boot_set_handler
) {
673 return boot_set_handler(boot_set_opaque
, boot_devices
);
676 static void validate_bootdevices(char *devices
)
678 /* We just do some generic consistency checks */
682 for (p
= devices
; *p
!= '\0'; p
++) {
683 /* Allowed boot devices are:
684 * a-b: floppy disk drives
685 * c-f: IDE disk drives
686 * g-m: machine implementation dependant drives
687 * n-p: network devices
688 * It's up to each machine implementation to check if the given boot
689 * devices match the actual hardware implementation and firmware
692 if (*p
< 'a' || *p
> 'p') {
693 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
696 if (bitmap
& (1 << (*p
- 'a'))) {
697 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
700 bitmap
|= 1 << (*p
- 'a');
704 static void restore_boot_devices(void *opaque
)
706 char *standard_boot_devices
= opaque
;
707 static int first
= 1;
709 /* Restore boot order and remove ourselves after the first boot */
715 qemu_boot_set(standard_boot_devices
);
717 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
718 qemu_free(standard_boot_devices
);
721 static void numa_add(const char *optarg
)
725 unsigned long long value
, endvalue
;
728 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
729 if (!strcmp(option
, "node")) {
730 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
731 nodenr
= nb_numa_nodes
;
733 nodenr
= strtoull(option
, NULL
, 10);
736 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
737 node_mem
[nodenr
] = 0;
739 value
= strtoull(option
, &endptr
, 0);
741 case 0: case 'M': case 'm':
748 node_mem
[nodenr
] = value
;
750 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
751 node_cpumask
[nodenr
] = 0;
753 value
= strtoull(option
, &endptr
, 10);
756 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
758 if (*endptr
== '-') {
759 endvalue
= strtoull(endptr
+1, &endptr
, 10);
760 if (endvalue
>= 63) {
763 "only 63 CPUs in NUMA mode supported.\n");
765 value
= (2ULL << endvalue
) - (1ULL << value
);
767 value
= 1ULL << value
;
770 node_cpumask
[nodenr
] = value
;
777 static void smp_parse(const char *optarg
)
779 int smp
, sockets
= 0, threads
= 0, cores
= 0;
783 smp
= strtoul(optarg
, &endptr
, 10);
784 if (endptr
!= optarg
) {
785 if (*endptr
== ',') {
789 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
790 sockets
= strtoull(option
, NULL
, 10);
791 if (get_param_value(option
, 128, "cores", endptr
) != 0)
792 cores
= strtoull(option
, NULL
, 10);
793 if (get_param_value(option
, 128, "threads", endptr
) != 0)
794 threads
= strtoull(option
, NULL
, 10);
795 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
796 max_cpus
= strtoull(option
, NULL
, 10);
798 /* compute missing values, prefer sockets over cores over threads */
799 if (smp
== 0 || sockets
== 0) {
800 sockets
= sockets
> 0 ? sockets
: 1;
801 cores
= cores
> 0 ? cores
: 1;
802 threads
= threads
> 0 ? threads
: 1;
804 smp
= cores
* threads
* sockets
;
808 threads
= threads
> 0 ? threads
: 1;
809 cores
= smp
/ (sockets
* threads
);
811 threads
= smp
/ (cores
* sockets
);
815 smp_cores
= cores
> 0 ? cores
: 1;
816 smp_threads
= threads
> 0 ? threads
: 1;
821 /***********************************************************/
824 static int usb_device_add(const char *devname
)
827 USBDevice
*dev
= NULL
;
832 /* drivers with .usbdevice_name entry in USBDeviceInfo */
833 dev
= usbdevice_create(devname
);
838 if (strstart(devname
, "host:", &p
)) {
839 dev
= usb_host_device_open(p
);
840 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
841 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
842 bt_new_hci(qemu_find_bt_vlan(0)));
853 static int usb_device_del(const char *devname
)
858 if (strstart(devname
, "host:", &p
))
859 return usb_host_device_close(p
);
864 p
= strchr(devname
, '.');
867 bus_num
= strtoul(devname
, NULL
, 0);
868 addr
= strtoul(p
+ 1, NULL
, 0);
870 return usb_device_delete_addr(bus_num
, addr
);
873 static int usb_parse(const char *cmdline
)
876 r
= usb_device_add(cmdline
);
878 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
883 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
885 const char *devname
= qdict_get_str(qdict
, "devname");
886 if (usb_device_add(devname
) < 0) {
887 error_report("could not add USB device '%s'", devname
);
891 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
893 const char *devname
= qdict_get_str(qdict
, "devname");
894 if (usb_device_del(devname
) < 0) {
895 error_report("could not delete USB device '%s'", devname
);
899 /***********************************************************/
902 static struct pcmcia_socket_entry_s
{
903 PCMCIASocket
*socket
;
904 struct pcmcia_socket_entry_s
*next
;
905 } *pcmcia_sockets
= 0;
907 void pcmcia_socket_register(PCMCIASocket
*socket
)
909 struct pcmcia_socket_entry_s
*entry
;
911 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
912 entry
->socket
= socket
;
913 entry
->next
= pcmcia_sockets
;
914 pcmcia_sockets
= entry
;
917 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
919 struct pcmcia_socket_entry_s
*entry
, **ptr
;
921 ptr
= &pcmcia_sockets
;
922 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
923 if (entry
->socket
== socket
) {
929 void pcmcia_info(Monitor
*mon
)
931 struct pcmcia_socket_entry_s
*iter
;
934 monitor_printf(mon
, "No PCMCIA sockets\n");
936 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
937 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
938 iter
->socket
->attached
? iter
->socket
->card_string
:
942 /***********************************************************/
945 typedef struct IOHandlerRecord
{
947 IOCanReadHandler
*fd_read_poll
;
954 QLIST_ENTRY(IOHandlerRecord
) next
;
957 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
958 QLIST_HEAD_INITIALIZER(io_handlers
);
961 /* XXX: fd_read_poll should be suppressed, but an API change is
962 necessary in the character devices to suppress fd_can_read(). */
963 int qemu_set_fd_handler2(int fd
,
964 IOCanReadHandler
*fd_read_poll
,
969 IOHandlerRecord
*ioh
;
971 if (!fd_read
&& !fd_write
) {
972 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
979 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
983 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
984 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
987 ioh
->fd_read_poll
= fd_read_poll
;
988 ioh
->fd_read
= fd_read
;
989 ioh
->fd_write
= fd_write
;
990 ioh
->opaque
= opaque
;
997 int qemu_set_fd_handler(int fd
,
1002 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
1005 /***********************************************************/
1006 /* machine registration */
1008 static QEMUMachine
*first_machine
= NULL
;
1009 QEMUMachine
*current_machine
= NULL
;
1011 int qemu_register_machine(QEMUMachine
*m
)
1014 pm
= &first_machine
;
1022 static QEMUMachine
*find_machine(const char *name
)
1026 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1027 if (!strcmp(m
->name
, name
))
1029 if (m
->alias
&& !strcmp(m
->alias
, name
))
1035 static QEMUMachine
*find_default_machine(void)
1039 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1040 if (m
->is_default
) {
1047 /***********************************************************/
1048 /* main execution loop */
1050 static void gui_update(void *opaque
)
1052 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1053 DisplayState
*ds
= opaque
;
1054 DisplayChangeListener
*dcl
= ds
->listeners
;
1056 qemu_flush_coalesced_mmio_buffer();
1059 while (dcl
!= NULL
) {
1060 if (dcl
->gui_timer_interval
&&
1061 dcl
->gui_timer_interval
< interval
)
1062 interval
= dcl
->gui_timer_interval
;
1065 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1068 static void nographic_update(void *opaque
)
1070 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1072 qemu_flush_coalesced_mmio_buffer();
1073 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1076 struct vm_change_state_entry
{
1077 VMChangeStateHandler
*cb
;
1079 QLIST_ENTRY (vm_change_state_entry
) entries
;
1082 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1084 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1087 VMChangeStateEntry
*e
;
1089 e
= qemu_mallocz(sizeof (*e
));
1093 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1097 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1099 QLIST_REMOVE (e
, entries
);
1103 void vm_state_notify(int running
, int reason
)
1105 VMChangeStateEntry
*e
;
1107 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1108 e
->cb(e
->opaque
, running
, reason
);
1117 vm_state_notify(1, 0);
1119 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1123 /* reset/shutdown handler */
1125 typedef struct QEMUResetEntry
{
1126 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1127 QEMUResetHandler
*func
;
1131 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1132 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1133 static int reset_requested
;
1134 static int shutdown_requested
;
1135 static int powerdown_requested
;
1136 int debug_requested
;
1137 int vmstop_requested
;
1139 int qemu_no_shutdown(void)
1141 int r
= no_shutdown
;
1146 int qemu_shutdown_requested(void)
1148 int r
= shutdown_requested
;
1149 shutdown_requested
= 0;
1153 int qemu_reset_requested(void)
1155 int r
= reset_requested
;
1156 reset_requested
= 0;
1160 int qemu_powerdown_requested(void)
1162 int r
= powerdown_requested
;
1163 powerdown_requested
= 0;
1167 static int qemu_debug_requested(void)
1169 int r
= debug_requested
;
1170 debug_requested
= 0;
1174 static int qemu_vmstop_requested(void)
1176 int r
= vmstop_requested
;
1177 vmstop_requested
= 0;
1181 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1183 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1186 re
->opaque
= opaque
;
1187 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1190 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1194 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1195 if (re
->func
== func
&& re
->opaque
== opaque
) {
1196 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1203 void qemu_system_reset(void)
1205 QEMUResetEntry
*re
, *nre
;
1207 /* reset all devices */
1208 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1209 re
->func(re
->opaque
);
1211 monitor_protocol_event(QEVENT_RESET
, NULL
);
1212 cpu_synchronize_all_post_reset();
1215 void qemu_system_reset_request(void)
1218 shutdown_requested
= 1;
1220 reset_requested
= 1;
1222 if (cpu_single_env
) {
1223 cpu_single_env
->stopped
= 1;
1224 cpu_exit(cpu_single_env
);
1226 qemu_notify_event();
1229 void qemu_system_shutdown_request(void)
1231 shutdown_requested
= 1;
1232 qemu_notify_event();
1235 void qemu_system_powerdown_request(void)
1237 powerdown_requested
= 1;
1238 qemu_notify_event();
1241 void main_loop_wait(int nonblocking
)
1243 IOHandlerRecord
*ioh
;
1244 fd_set rfds
, wfds
, xfds
;
1252 timeout
= qemu_calculate_timeout();
1253 qemu_bh_update_timeout(&timeout
);
1256 os_host_main_loop_wait(&timeout
);
1258 /* poll any events */
1259 /* XXX: separate device handlers from system ones */
1264 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1268 (!ioh
->fd_read_poll
||
1269 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1270 FD_SET(ioh
->fd
, &rfds
);
1274 if (ioh
->fd_write
) {
1275 FD_SET(ioh
->fd
, &wfds
);
1281 tv
.tv_sec
= timeout
/ 1000;
1282 tv
.tv_usec
= (timeout
% 1000) * 1000;
1284 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1286 qemu_mutex_unlock_iothread();
1287 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1288 qemu_mutex_lock_iothread();
1290 IOHandlerRecord
*pioh
;
1292 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1294 QLIST_REMOVE(ioh
, next
);
1298 if (ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1299 ioh
->fd_read(ioh
->opaque
);
1300 if (!(ioh
->fd_read_poll
&& ioh
->fd_read_poll(ioh
->opaque
)))
1301 FD_CLR(ioh
->fd
, &rfds
);
1303 if (ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1304 ioh
->fd_write(ioh
->opaque
);
1309 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1311 qemu_run_all_timers();
1313 /* Check bottom-halves last in case any of the earlier events triggered
1319 static int vm_can_run(void)
1321 if (powerdown_requested
)
1323 if (reset_requested
)
1325 if (shutdown_requested
)
1327 if (debug_requested
)
1332 qemu_irq qemu_system_powerdown
;
1334 static void main_loop(void)
1338 if (kvm_enabled()) {
1340 cpu_disable_ticks();
1344 qemu_main_loop_start();
1348 bool nonblocking
= false;
1349 #ifdef CONFIG_PROFILER
1352 #ifndef CONFIG_IOTHREAD
1353 nonblocking
= cpu_exec_all();
1355 #ifdef CONFIG_PROFILER
1356 ti
= profile_getclock();
1358 main_loop_wait(nonblocking
);
1359 #ifdef CONFIG_PROFILER
1360 dev_time
+= profile_getclock() - ti
;
1362 } while (vm_can_run());
1364 if ((r
= qemu_debug_requested())) {
1367 if (qemu_shutdown_requested()) {
1368 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1375 if (qemu_reset_requested()) {
1377 qemu_system_reset();
1380 if (qemu_powerdown_requested()) {
1381 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1382 qemu_irq_raise(qemu_system_powerdown
);
1384 if ((r
= qemu_vmstop_requested())) {
1392 static void version(void)
1394 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1397 static void help(int exitcode
)
1399 const char *options_help
=
1400 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1402 #define DEFHEADING(text) stringify(text) "\n"
1403 #include "qemu-options.def"
1409 printf("usage: %s [options] [disk_image]\n"
1411 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1414 "During emulation, the following keys are useful:\n"
1415 "ctrl-alt-f toggle full screen\n"
1416 "ctrl-alt-n switch to virtual console 'n'\n"
1417 "ctrl-alt toggle mouse and keyboard grab\n"
1419 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1425 #define HAS_ARG 0x0001
1427 typedef struct QEMUOption
{
1434 static const QEMUOption qemu_options
[] = {
1435 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1436 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1437 { option, opt_arg, opt_enum, arch_mask },
1438 #define DEFHEADING(text)
1439 #include "qemu-options.def"
1445 static void select_vgahw (const char *p
)
1450 vga_interface_type
= VGA_NONE
;
1451 if (strstart(p
, "std", &opts
)) {
1452 vga_interface_type
= VGA_STD
;
1453 } else if (strstart(p
, "cirrus", &opts
)) {
1454 vga_interface_type
= VGA_CIRRUS
;
1455 } else if (strstart(p
, "vmware", &opts
)) {
1456 vga_interface_type
= VGA_VMWARE
;
1457 } else if (strstart(p
, "xenfb", &opts
)) {
1458 vga_interface_type
= VGA_XENFB
;
1459 } else if (!strstart(p
, "none", &opts
)) {
1461 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1465 const char *nextopt
;
1467 if (strstart(opts
, ",retrace=", &nextopt
)) {
1469 if (strstart(opts
, "dumb", &nextopt
))
1470 vga_retrace_method
= VGA_RETRACE_DUMB
;
1471 else if (strstart(opts
, "precise", &nextopt
))
1472 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1473 else goto invalid_vga
;
1474 } else goto invalid_vga
;
1479 static int balloon_parse(const char *arg
)
1483 if (strcmp(arg
, "none") == 0) {
1487 if (!strncmp(arg
, "virtio", 6)) {
1488 if (arg
[6] == ',') {
1489 /* have params -> parse them */
1490 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1494 /* create empty opts */
1495 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1497 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1504 char *qemu_find_file(int type
, const char *name
)
1510 /* If name contains path separators then try it as a straight path. */
1511 if ((strchr(name
, '/') || strchr(name
, '\\'))
1512 && access(name
, R_OK
) == 0) {
1513 return qemu_strdup(name
);
1516 case QEMU_FILE_TYPE_BIOS
:
1519 case QEMU_FILE_TYPE_KEYMAP
:
1520 subdir
= "keymaps/";
1525 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1526 buf
= qemu_mallocz(len
);
1527 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1528 if (access(buf
, R_OK
)) {
1535 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1537 return qdev_device_help(opts
);
1540 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1544 dev
= qdev_device_add(opts
);
1550 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1552 CharDriverState
*chr
;
1554 chr
= qemu_chr_open_opts(opts
, NULL
);
1560 #ifdef CONFIG_VIRTFS
1561 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1564 ret
= qemu_fsdev_add(opts
);
1570 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1572 CharDriverState
*chr
;
1573 const char *chardev
;
1577 mode
= qemu_opt_get(opts
, "mode");
1581 if (strcmp(mode
, "readline") == 0) {
1582 flags
= MONITOR_USE_READLINE
;
1583 } else if (strcmp(mode
, "control") == 0) {
1584 flags
= MONITOR_USE_CONTROL
;
1586 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1590 if (qemu_opt_get_bool(opts
, "default", 0))
1591 flags
|= MONITOR_IS_DEFAULT
;
1593 chardev
= qemu_opt_get(opts
, "chardev");
1594 chr
= qemu_chr_find(chardev
);
1596 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1600 monitor_init(chr
, flags
);
1604 static void monitor_parse(const char *optarg
, const char *mode
)
1606 static int monitor_device_index
= 0;
1612 if (strstart(optarg
, "chardev:", &p
)) {
1613 snprintf(label
, sizeof(label
), "%s", p
);
1615 snprintf(label
, sizeof(label
), "compat_monitor%d",
1616 monitor_device_index
);
1617 if (monitor_device_index
== 0) {
1620 opts
= qemu_chr_parse_compat(label
, optarg
);
1622 fprintf(stderr
, "parse error: %s\n", optarg
);
1627 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1629 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1632 qemu_opt_set(opts
, "mode", mode
);
1633 qemu_opt_set(opts
, "chardev", label
);
1635 qemu_opt_set(opts
, "default", "on");
1636 monitor_device_index
++;
1639 struct device_config
{
1641 DEV_USB
, /* -usbdevice */
1643 DEV_SERIAL
, /* -serial */
1644 DEV_PARALLEL
, /* -parallel */
1645 DEV_VIRTCON
, /* -virtioconsole */
1646 DEV_DEBUGCON
, /* -debugcon */
1648 const char *cmdline
;
1649 QTAILQ_ENTRY(device_config
) next
;
1651 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1653 static void add_device_config(int type
, const char *cmdline
)
1655 struct device_config
*conf
;
1657 conf
= qemu_mallocz(sizeof(*conf
));
1659 conf
->cmdline
= cmdline
;
1660 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1663 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1665 struct device_config
*conf
;
1668 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1669 if (conf
->type
!= type
)
1671 rc
= func(conf
->cmdline
);
1678 static int serial_parse(const char *devname
)
1680 static int index
= 0;
1683 if (strcmp(devname
, "none") == 0)
1685 if (index
== MAX_SERIAL_PORTS
) {
1686 fprintf(stderr
, "qemu: too many serial ports\n");
1689 snprintf(label
, sizeof(label
), "serial%d", index
);
1690 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1691 if (!serial_hds
[index
]) {
1692 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1693 devname
, strerror(errno
));
1700 static int parallel_parse(const char *devname
)
1702 static int index
= 0;
1705 if (strcmp(devname
, "none") == 0)
1707 if (index
== MAX_PARALLEL_PORTS
) {
1708 fprintf(stderr
, "qemu: too many parallel ports\n");
1711 snprintf(label
, sizeof(label
), "parallel%d", index
);
1712 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1713 if (!parallel_hds
[index
]) {
1714 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1715 devname
, strerror(errno
));
1722 static int virtcon_parse(const char *devname
)
1724 QemuOptsList
*device
= qemu_find_opts("device");
1725 static int index
= 0;
1727 QemuOpts
*bus_opts
, *dev_opts
;
1729 if (strcmp(devname
, "none") == 0)
1731 if (index
== MAX_VIRTIO_CONSOLES
) {
1732 fprintf(stderr
, "qemu: too many virtio consoles\n");
1736 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1737 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1739 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1740 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1742 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1743 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1744 if (!virtcon_hds
[index
]) {
1745 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1746 devname
, strerror(errno
));
1749 qemu_opt_set(dev_opts
, "chardev", label
);
1755 static int debugcon_parse(const char *devname
)
1759 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1762 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1764 fprintf(stderr
, "qemu: already have a debugcon device\n");
1767 qemu_opt_set(opts
, "driver", "isa-debugcon");
1768 qemu_opt_set(opts
, "chardev", "debugcon");
1772 void qemu_add_exit_notifier(Notifier
*notify
)
1774 notifier_list_add(&exit_notifiers
, notify
);
1777 void qemu_remove_exit_notifier(Notifier
*notify
)
1779 notifier_list_remove(&exit_notifiers
, notify
);
1782 static void qemu_run_exit_notifiers(void)
1784 notifier_list_notify(&exit_notifiers
);
1787 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1788 const char **poptarg
, int *poptind
)
1790 const QEMUOption
*popt
;
1791 int optind
= *poptind
;
1792 char *r
= argv
[optind
];
1795 loc_set_cmdline(argv
, optind
, 1);
1797 /* Treat --foo the same as -foo. */
1800 popt
= qemu_options
;
1803 error_report("invalid option");
1806 if (!strcmp(popt
->name
, r
+ 1))
1810 if (popt
->flags
& HAS_ARG
) {
1811 if (optind
>= argc
) {
1812 error_report("requires an argument");
1815 optarg
= argv
[optind
++];
1816 loc_set_cmdline(argv
, optind
- 2, 2);
1827 int main(int argc
, char **argv
, char **envp
)
1829 const char *gdbstub_dev
= NULL
;
1831 int snapshot
, linux_boot
;
1832 const char *icount_option
= NULL
;
1833 const char *initrd_filename
;
1834 const char *kernel_filename
, *kernel_cmdline
;
1835 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1837 DisplayChangeListener
*dcl
;
1838 int cyls
, heads
, secs
, translation
;
1839 QemuOpts
*hda_opts
= NULL
, *opts
;
1840 QemuOptsList
*olist
;
1843 const char *loadvm
= NULL
;
1844 QEMUMachine
*machine
;
1845 const char *cpu_model
;
1847 const char *pid_file
= NULL
;
1848 const char *incoming
= NULL
;
1849 int show_vnc_port
= 0;
1852 atexit(qemu_run_exit_notifiers
);
1853 error_set_progname(argv
[0]);
1857 qemu_cache_utils_init(envp
);
1859 QLIST_INIT (&vm_change_state_head
);
1860 os_setup_early_signal_handling();
1862 module_call_init(MODULE_INIT_MACHINE
);
1863 machine
= find_default_machine();
1865 initrd_filename
= NULL
;
1868 kernel_filename
= NULL
;
1869 kernel_cmdline
= "";
1870 cyls
= heads
= secs
= 0;
1871 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1873 for (i
= 0; i
< MAX_NODES
; i
++) {
1875 node_cpumask
[i
] = 0;
1878 assigned_devices_index
= 0;
1886 #ifdef CONFIG_VIRTFS
1887 qemu_add_opts(&qemu_fsdev_opts
);
1888 qemu_add_opts(&qemu_virtfs_opts
);
1891 /* first pass of option parsing */
1893 while (optind
< argc
) {
1894 if (argv
[optind
][0] != '-') {
1899 const QEMUOption
*popt
;
1901 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1902 switch (popt
->index
) {
1903 case QEMU_OPTION_nodefconfig
:
1913 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1914 if (ret
< 0 && ret
!= -ENOENT
) {
1918 ret
= qemu_read_config_file(arch_config_name
);
1919 if (ret
< 0 && ret
!= -ENOENT
) {
1925 /* second pass of option parsing */
1930 if (argv
[optind
][0] != '-') {
1931 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1933 const QEMUOption
*popt
;
1935 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1936 if (!(popt
->arch_mask
& arch_type
)) {
1937 printf("Option %s not supported for this target\n", popt
->name
);
1940 switch(popt
->index
) {
1942 machine
= find_machine(optarg
);
1945 printf("Supported machines are:\n");
1946 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1948 printf("%-10s %s (alias of %s)\n",
1949 m
->alias
, m
->desc
, m
->name
);
1950 printf("%-10s %s%s\n",
1952 m
->is_default
? " (default)" : "");
1954 exit(*optarg
!= '?');
1957 case QEMU_OPTION_cpu
:
1958 /* hw initialization will check this */
1959 if (*optarg
== '?') {
1960 list_cpus(stdout
, &fprintf
, optarg
);
1966 case QEMU_OPTION_initrd
:
1967 initrd_filename
= optarg
;
1969 case QEMU_OPTION_hda
:
1971 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
1973 hda_opts
= drive_add(optarg
, HD_ALIAS
1974 ",cyls=%d,heads=%d,secs=%d%s",
1975 0, cyls
, heads
, secs
,
1976 translation
== BIOS_ATA_TRANSLATION_LBA
?
1978 translation
== BIOS_ATA_TRANSLATION_NONE
?
1979 ",trans=none" : "");
1981 case QEMU_OPTION_hdb
:
1982 case QEMU_OPTION_hdc
:
1983 case QEMU_OPTION_hdd
:
1984 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
1986 case QEMU_OPTION_drive
:
1987 drive_add(NULL
, "%s", optarg
);
1989 case QEMU_OPTION_set
:
1990 if (qemu_set_option(optarg
) != 0)
1993 case QEMU_OPTION_global
:
1994 if (qemu_global_option(optarg
) != 0)
1997 case QEMU_OPTION_mtdblock
:
1998 drive_add(optarg
, MTD_ALIAS
);
2000 case QEMU_OPTION_sd
:
2001 drive_add(optarg
, SD_ALIAS
);
2003 case QEMU_OPTION_pflash
:
2004 drive_add(optarg
, PFLASH_ALIAS
);
2006 case QEMU_OPTION_snapshot
:
2009 case QEMU_OPTION_hdachs
:
2013 cyls
= strtol(p
, (char **)&p
, 0);
2014 if (cyls
< 1 || cyls
> 16383)
2019 heads
= strtol(p
, (char **)&p
, 0);
2020 if (heads
< 1 || heads
> 16)
2025 secs
= strtol(p
, (char **)&p
, 0);
2026 if (secs
< 1 || secs
> 63)
2030 if (!strcmp(p
, "none"))
2031 translation
= BIOS_ATA_TRANSLATION_NONE
;
2032 else if (!strcmp(p
, "lba"))
2033 translation
= BIOS_ATA_TRANSLATION_LBA
;
2034 else if (!strcmp(p
, "auto"))
2035 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2038 } else if (*p
!= '\0') {
2040 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2043 if (hda_opts
!= NULL
) {
2045 snprintf(num
, sizeof(num
), "%d", cyls
);
2046 qemu_opt_set(hda_opts
, "cyls", num
);
2047 snprintf(num
, sizeof(num
), "%d", heads
);
2048 qemu_opt_set(hda_opts
, "heads", num
);
2049 snprintf(num
, sizeof(num
), "%d", secs
);
2050 qemu_opt_set(hda_opts
, "secs", num
);
2051 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2052 qemu_opt_set(hda_opts
, "trans", "lba");
2053 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2054 qemu_opt_set(hda_opts
, "trans", "none");
2058 case QEMU_OPTION_numa
:
2059 if (nb_numa_nodes
>= MAX_NODES
) {
2060 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2065 case QEMU_OPTION_nographic
:
2066 display_type
= DT_NOGRAPHIC
;
2068 #ifdef CONFIG_CURSES
2069 case QEMU_OPTION_curses
:
2070 display_type
= DT_CURSES
;
2073 case QEMU_OPTION_portrait
:
2076 case QEMU_OPTION_kernel
:
2077 kernel_filename
= optarg
;
2079 case QEMU_OPTION_append
:
2080 kernel_cmdline
= optarg
;
2082 case QEMU_OPTION_cdrom
:
2083 drive_add(optarg
, CDROM_ALIAS
);
2085 case QEMU_OPTION_boot
:
2087 static const char * const params
[] = {
2088 "order", "once", "menu", NULL
2090 char buf
[sizeof(boot_devices
)];
2091 char *standard_boot_devices
;
2094 if (!strchr(optarg
, '=')) {
2096 pstrcpy(buf
, sizeof(buf
), optarg
);
2097 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2099 "qemu: unknown boot parameter '%s' in '%s'\n",
2105 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2106 validate_bootdevices(buf
);
2107 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2110 if (get_param_value(buf
, sizeof(buf
),
2112 validate_bootdevices(buf
);
2113 standard_boot_devices
= qemu_strdup(boot_devices
);
2114 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2115 qemu_register_reset(restore_boot_devices
,
2116 standard_boot_devices
);
2118 if (get_param_value(buf
, sizeof(buf
),
2120 if (!strcmp(buf
, "on")) {
2122 } else if (!strcmp(buf
, "off")) {
2126 "qemu: invalid option value '%s'\n",
2134 case QEMU_OPTION_fda
:
2135 case QEMU_OPTION_fdb
:
2136 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2138 case QEMU_OPTION_no_fd_bootchk
:
2141 case QEMU_OPTION_netdev
:
2142 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2146 case QEMU_OPTION_net
:
2147 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2152 case QEMU_OPTION_tftp
:
2153 legacy_tftp_prefix
= optarg
;
2155 case QEMU_OPTION_bootp
:
2156 legacy_bootp_filename
= optarg
;
2158 case QEMU_OPTION_redir
:
2159 if (net_slirp_redir(optarg
) < 0)
2163 case QEMU_OPTION_bt
:
2164 add_device_config(DEV_BT
, optarg
);
2166 case QEMU_OPTION_audio_help
:
2167 if (!(audio_available())) {
2168 printf("Option %s not supported for this target\n", popt
->name
);
2174 case QEMU_OPTION_soundhw
:
2175 if (!(audio_available())) {
2176 printf("Option %s not supported for this target\n", popt
->name
);
2179 select_soundhw (optarg
);
2184 case QEMU_OPTION_version
:
2188 case QEMU_OPTION_m
: {
2192 value
= strtoul(optarg
, &ptr
, 10);
2194 case 0: case 'M': case 'm':
2201 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2205 /* On 32-bit hosts, QEMU is limited by virtual address space */
2206 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2207 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2210 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2211 fprintf(stderr
, "qemu: ram size too large\n");
2217 case QEMU_OPTION_mempath
:
2221 case QEMU_OPTION_mem_prealloc
:
2226 set_cpu_log(optarg
);
2229 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2231 case QEMU_OPTION_gdb
:
2232 gdbstub_dev
= optarg
;
2237 case QEMU_OPTION_bios
:
2240 case QEMU_OPTION_singlestep
:
2247 keyboard_layout
= optarg
;
2249 case QEMU_OPTION_localtime
:
2252 case QEMU_OPTION_vga
:
2253 select_vgahw (optarg
);
2260 w
= strtol(p
, (char **)&p
, 10);
2263 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2269 h
= strtol(p
, (char **)&p
, 10);
2274 depth
= strtol(p
, (char **)&p
, 10);
2275 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2276 depth
!= 24 && depth
!= 32)
2278 } else if (*p
== '\0') {
2279 depth
= graphic_depth
;
2286 graphic_depth
= depth
;
2289 case QEMU_OPTION_echr
:
2292 term_escape_char
= strtol(optarg
, &r
, 0);
2294 printf("Bad argument to echr\n");
2297 case QEMU_OPTION_monitor
:
2298 monitor_parse(optarg
, "readline");
2299 default_monitor
= 0;
2301 case QEMU_OPTION_qmp
:
2302 monitor_parse(optarg
, "control");
2303 default_monitor
= 0;
2305 case QEMU_OPTION_mon
:
2306 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2310 default_monitor
= 0;
2312 case QEMU_OPTION_chardev
:
2313 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2318 case QEMU_OPTION_fsdev
:
2319 olist
= qemu_find_opts("fsdev");
2321 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2324 opts
= qemu_opts_parse(olist
, optarg
, 1);
2326 fprintf(stderr
, "parse error: %s\n", optarg
);
2330 case QEMU_OPTION_virtfs
: {
2331 char *arg_fsdev
= NULL
;
2332 char *arg_9p
= NULL
;
2335 olist
= qemu_find_opts("virtfs");
2337 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2340 opts
= qemu_opts_parse(olist
, optarg
, 1);
2342 fprintf(stderr
, "parse error: %s\n", optarg
);
2346 if (qemu_opt_get(opts
, "fstype") == NULL
||
2347 qemu_opt_get(opts
, "mount_tag") == NULL
||
2348 qemu_opt_get(opts
, "path") == NULL
||
2349 qemu_opt_get(opts
, "security_model") == NULL
) {
2350 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2351 "security_model=[mapped|passthrough],"
2356 len
= strlen(",id=,path=,security_model=");
2357 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2358 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2359 len
+= strlen(qemu_opt_get(opts
, "path"));
2360 len
+= strlen(qemu_opt_get(opts
, "security_model"));
2361 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2363 snprintf(arg_fsdev
, (len
+ 1) * sizeof(*arg_fsdev
),
2364 "%s,id=%s,path=%s,security_model=%s",
2365 qemu_opt_get(opts
, "fstype"),
2366 qemu_opt_get(opts
, "mount_tag"),
2367 qemu_opt_get(opts
, "path"),
2368 qemu_opt_get(opts
, "security_model"));
2370 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2371 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2372 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2374 snprintf(arg_9p
, (len
+ 1) * sizeof(*arg_9p
),
2375 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2376 qemu_opt_get(opts
, "mount_tag"),
2377 qemu_opt_get(opts
, "mount_tag"));
2379 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev
, 1)) {
2380 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2384 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p
, 1)) {
2385 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2389 qemu_free(arg_fsdev
);
2393 case QEMU_OPTION_serial
:
2394 add_device_config(DEV_SERIAL
, optarg
);
2396 if (strncmp(optarg
, "mon:", 4) == 0) {
2397 default_monitor
= 0;
2400 case QEMU_OPTION_watchdog
:
2403 "qemu: only one watchdog option may be given\n");
2408 case QEMU_OPTION_watchdog_action
:
2409 if (select_watchdog_action(optarg
) == -1) {
2410 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2414 case QEMU_OPTION_virtiocon
:
2415 add_device_config(DEV_VIRTCON
, optarg
);
2416 default_virtcon
= 0;
2417 if (strncmp(optarg
, "mon:", 4) == 0) {
2418 default_monitor
= 0;
2421 case QEMU_OPTION_parallel
:
2422 add_device_config(DEV_PARALLEL
, optarg
);
2423 default_parallel
= 0;
2424 if (strncmp(optarg
, "mon:", 4) == 0) {
2425 default_monitor
= 0;
2428 case QEMU_OPTION_debugcon
:
2429 add_device_config(DEV_DEBUGCON
, optarg
);
2431 case QEMU_OPTION_loadvm
:
2434 case QEMU_OPTION_full_screen
:
2438 case QEMU_OPTION_no_frame
:
2441 case QEMU_OPTION_alt_grab
:
2444 case QEMU_OPTION_ctrl_grab
:
2447 case QEMU_OPTION_no_quit
:
2450 case QEMU_OPTION_sdl
:
2451 display_type
= DT_SDL
;
2454 case QEMU_OPTION_pidfile
:
2457 case QEMU_OPTION_win2k_hack
:
2458 win2k_install_hack
= 1;
2460 case QEMU_OPTION_rtc_td_hack
:
2463 case QEMU_OPTION_acpitable
:
2464 do_acpitable_option(optarg
);
2466 case QEMU_OPTION_smbios
:
2467 do_smbios_option(optarg
);
2470 case QEMU_OPTION_enable_kvm
:
2474 case QEMU_OPTION_no_kvm
:
2478 case QEMU_OPTION_no_kvm_irqchip
: {
2483 case QEMU_OPTION_no_kvm_pit
: {
2487 case QEMU_OPTION_no_kvm_pit_reinjection
: {
2488 kvm_pit_reinject
= 0;
2491 case QEMU_OPTION_enable_nesting
: {
2496 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
2497 case QEMU_OPTION_pcidevice
:
2498 if (assigned_devices_index
>= MAX_DEV_ASSIGN_CMDLINE
) {
2499 fprintf(stderr
, "Too many assigned devices\n");
2502 assigned_devices
[assigned_devices_index
] = optarg
;
2503 assigned_devices_index
++;
2506 case QEMU_OPTION_usb
:
2509 case QEMU_OPTION_usbdevice
:
2511 add_device_config(DEV_USB
, optarg
);
2513 case QEMU_OPTION_device
:
2514 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2518 case QEMU_OPTION_smp
:
2521 fprintf(stderr
, "Invalid number of CPUs\n");
2524 if (max_cpus
< smp_cpus
) {
2525 fprintf(stderr
, "maxcpus must be equal to or greater than "
2529 if (max_cpus
> 255) {
2530 fprintf(stderr
, "Unsupported number of maxcpus\n");
2534 case QEMU_OPTION_vnc
:
2535 display_type
= DT_VNC
;
2536 vnc_display
= optarg
;
2538 case QEMU_OPTION_no_acpi
:
2541 case QEMU_OPTION_no_hpet
:
2544 case QEMU_OPTION_balloon
:
2545 if (balloon_parse(optarg
) < 0) {
2546 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2550 case QEMU_OPTION_no_reboot
:
2553 case QEMU_OPTION_no_shutdown
:
2556 case QEMU_OPTION_show_cursor
:
2559 case QEMU_OPTION_uuid
:
2560 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2561 fprintf(stderr
, "Fail to parse UUID string."
2562 " Wrong format.\n");
2566 case QEMU_OPTION_option_rom
:
2567 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2568 fprintf(stderr
, "Too many option ROMs\n");
2571 option_rom
[nb_option_roms
] = optarg
;
2574 case QEMU_OPTION_semihosting
:
2575 semihosting_enabled
= 1;
2577 case QEMU_OPTION_tdf
:
2580 case QEMU_OPTION_kvm_shadow_memory
:
2581 kvm_shadow_memory
= (int64_t)atoi(optarg
) * 1024 * 1024 / 4096;
2583 case QEMU_OPTION_name
:
2584 qemu_name
= qemu_strdup(optarg
);
2586 char *p
= strchr(qemu_name
, ',');
2589 if (strncmp(p
, "process=", 8)) {
2590 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2594 os_set_proc_name(p
);
2598 case QEMU_OPTION_prom_env
:
2599 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2600 fprintf(stderr
, "Too many prom variables\n");
2603 prom_envs
[nb_prom_envs
] = optarg
;
2606 case QEMU_OPTION_old_param
:
2609 case QEMU_OPTION_clock
:
2610 configure_alarms(optarg
);
2612 case QEMU_OPTION_startdate
:
2613 configure_rtc_date_offset(optarg
, 1);
2615 case QEMU_OPTION_rtc
:
2616 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2620 configure_rtc(opts
);
2622 case QEMU_OPTION_tb_size
:
2623 tb_size
= strtol(optarg
, NULL
, 0);
2627 case QEMU_OPTION_icount
:
2628 icount_option
= optarg
;
2630 case QEMU_OPTION_incoming
:
2632 incoming_expected
= true;
2634 case QEMU_OPTION_nodefaults
:
2636 default_parallel
= 0;
2637 default_virtcon
= 0;
2638 default_monitor
= 0;
2646 case QEMU_OPTION_nvram
:
2650 case QEMU_OPTION_xen_domid
:
2651 if (!(xen_available())) {
2652 printf("Option %s not supported for this target\n", popt
->name
);
2655 xen_domid
= atoi(optarg
);
2657 case QEMU_OPTION_xen_create
:
2658 if (!(xen_available())) {
2659 printf("Option %s not supported for this target\n", popt
->name
);
2662 xen_mode
= XEN_CREATE
;
2664 case QEMU_OPTION_xen_attach
:
2665 if (!(xen_available())) {
2666 printf("Option %s not supported for this target\n", popt
->name
);
2669 xen_mode
= XEN_ATTACH
;
2671 case QEMU_OPTION_readconfig
:
2673 int ret
= qemu_read_config_file(optarg
);
2675 fprintf(stderr
, "read config %s: %s\n", optarg
,
2681 case QEMU_OPTION_writeconfig
:
2684 if (strcmp(optarg
, "-") == 0) {
2687 fp
= fopen(optarg
, "w");
2689 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2693 qemu_config_write(fp
);
2698 os_parse_cmd_args(popt
->index
, optarg
);
2704 /* If no data_dir is specified then try to find it relative to the
2707 data_dir
= os_find_datadir(argv
[0]);
2709 /* If all else fails use the install patch specified when building. */
2711 data_dir
= CONFIG_QEMU_DATADIR
;
2715 * Default to max_cpus = smp_cpus, in case the user doesn't
2716 * specify a max_cpus value.
2719 max_cpus
= smp_cpus
;
2721 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2722 if (smp_cpus
> machine
->max_cpus
) {
2723 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2724 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2729 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2730 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2732 if (machine
->no_serial
) {
2735 if (machine
->no_parallel
) {
2736 default_parallel
= 0;
2738 if (!machine
->use_virtcon
) {
2739 default_virtcon
= 0;
2741 if (machine
->no_vga
) {
2744 if (machine
->no_floppy
) {
2747 if (machine
->no_cdrom
) {
2750 if (machine
->no_sdcard
) {
2754 if (display_type
== DT_NOGRAPHIC
) {
2755 if (default_parallel
)
2756 add_device_config(DEV_PARALLEL
, "null");
2757 if (default_serial
&& default_monitor
) {
2758 add_device_config(DEV_SERIAL
, "mon:stdio");
2759 } else if (default_virtcon
&& default_monitor
) {
2760 add_device_config(DEV_VIRTCON
, "mon:stdio");
2763 add_device_config(DEV_SERIAL
, "stdio");
2764 if (default_virtcon
)
2765 add_device_config(DEV_VIRTCON
, "stdio");
2766 if (default_monitor
)
2767 monitor_parse("stdio", "readline");
2771 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2772 if (default_parallel
)
2773 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2774 if (default_monitor
)
2775 monitor_parse("vc:80Cx24C", "readline");
2776 if (default_virtcon
)
2777 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2780 vga_interface_type
= VGA_CIRRUS
;
2784 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
2786 #ifdef CONFIG_VIRTFS
2787 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
2794 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2800 int ret
= kvm_init(smp_cpus
);
2802 #if defined(KVM_UPSTREAM) || defined(CONFIG_NO_CPU_EMULATION)
2803 if (!kvm_available()) {
2804 printf("KVM not supported for this target\n");
2806 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2811 fprintf(stderr
, "Could not initialize KVM, will disable KVM support\n");
2817 if (qemu_init_main_loop()) {
2818 fprintf(stderr
, "qemu_init_main_loop failed\n");
2821 linux_boot
= (kernel_filename
!= NULL
);
2823 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2824 fprintf(stderr
, "-append only allowed with -kernel option\n");
2828 if (!linux_boot
&& initrd_filename
!= NULL
) {
2829 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2833 os_set_line_buffering();
2835 if (init_timer_alarm() < 0) {
2836 fprintf(stderr
, "could not initialize alarm timer\n");
2839 configure_icount(icount_option
);
2841 if (net_init_clients() < 0) {
2845 /* init the bluetooth world */
2846 if (foreach_device_config(DEV_BT
, bt_parse
))
2849 /* init the memory */
2851 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2853 /* init the dynamic translator */
2854 cpu_exec_init_all(tb_size
* 1024 * 1024);
2856 bdrv_init_with_whitelist();
2860 if (default_cdrom
) {
2861 /* we always create the cdrom drive, even if no disk is there */
2862 drive_add(NULL
, CDROM_ALIAS
);
2865 if (default_floppy
) {
2866 /* we always create at least one floppy */
2867 drive_add(NULL
, FD_ALIAS
, 0);
2870 if (default_sdcard
) {
2871 /* we always create one sd slot, even if no card is in it */
2872 drive_add(NULL
, SD_ALIAS
);
2875 /* open the virtual block devices */
2877 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
2878 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
2881 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2884 if (nb_numa_nodes
> 0) {
2887 if (nb_numa_nodes
> smp_cpus
) {
2888 nb_numa_nodes
= smp_cpus
;
2891 /* If no memory size if given for any node, assume the default case
2892 * and distribute the available memory equally across all nodes
2894 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2895 if (node_mem
[i
] != 0)
2898 if (i
== nb_numa_nodes
) {
2899 uint64_t usedmem
= 0;
2901 /* On Linux, the each node's border has to be 8MB aligned,
2902 * the final node gets the rest.
2904 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2905 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2906 usedmem
+= node_mem
[i
];
2908 node_mem
[i
] = ram_size
- usedmem
;
2911 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2912 if (node_cpumask
[i
] != 0)
2915 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2916 * must cope with this anyway, because there are BIOSes out there in
2917 * real machines which also use this scheme.
2919 if (i
== nb_numa_nodes
) {
2920 for (i
= 0; i
< smp_cpus
; i
++) {
2921 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2926 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
2930 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2932 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2934 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2936 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2939 module_call_init(MODULE_INIT_DEVICE
);
2941 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
2945 i
= select_watchdog(watchdog
);
2947 exit (i
== 1 ? 1 : 0);
2950 if (machine
->compat_props
) {
2951 qdev_prop_register_global_list(machine
->compat_props
);
2955 machine
->init(ram_size
, boot_devices
,
2956 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2958 cpu_synchronize_all_post_init();
2960 /* must be after terminal init, SDL library changes signal handlers */
2961 os_setup_signal_handling();
2965 current_machine
= machine
;
2967 /* init USB devices */
2969 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2973 /* init generic devices */
2974 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
2977 net_check_clients();
2979 /* just use the first displaystate for the moment */
2980 ds
= get_displaystate();
2982 if (display_type
== DT_DEFAULT
) {
2983 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
2984 display_type
= DT_SDL
;
2986 display_type
= DT_VNC
;
2987 vnc_display
= "localhost:0,to=99";
2993 switch (display_type
) {
2996 #if defined(CONFIG_CURSES)
2998 curses_display_init(ds
, full_screen
);
3001 #if defined(CONFIG_SDL)
3003 sdl_display_init(ds
, full_screen
, no_frame
);
3005 #elif defined(CONFIG_COCOA)
3007 cocoa_display_init(ds
, full_screen
);
3011 vnc_display_init(ds
);
3012 if (vnc_display_open(ds
, vnc_display
) < 0)
3015 if (show_vnc_port
) {
3016 printf("VNC server running on `%s'\n", vnc_display_local_addr(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
));
3034 if (display_type
== DT_NOGRAPHIC
|| display_type
== DT_VNC
) {
3035 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
3036 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
3039 text_consoles_set_display(ds
);
3041 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3042 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3047 qdev_machine_creation_done();
3049 if (rom_load_all() != 0) {
3050 fprintf(stderr
, "rom loading failed\n");
3054 qemu_system_reset();
3056 if (load_vmstate(loadvm
) < 0) {
3062 int ret
= qemu_start_incoming_migration(incoming
);
3064 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3068 } else if (autostart
) {