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
33 /* Needed early for CONFIG_BSD etc. */
34 #include "config-host.h"
38 #include <sys/times.h>
42 #include <sys/ioctl.h>
43 #include <sys/resource.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
47 #include <arpa/inet.h>
50 #include <sys/select.h>
54 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
55 #include <sys/sysctl.h>
63 #include <linux/ppdev.h>
64 #include <linux/parport.h>
68 #include "qemu-seccomp.h"
73 #include <sys/ethernet.h>
74 #include <sys/sockio.h>
75 #include <netinet/arp.h>
76 #include <netinet/in_systm.h>
77 #include <netinet/ip.h>
78 #include <netinet/ip_icmp.h> // must come after ip.h
79 #include <netinet/udp.h>
80 #include <netinet/tcp.h>
88 #if defined(CONFIG_VDE)
89 #include <libvdeplug.h>
97 #if defined(__APPLE__) || defined(main)
99 int qemu_main(int argc
, char **argv
, char **envp
);
100 int main(int argc
, char **argv
)
102 return qemu_main(argc
, argv
, NULL
);
105 #define main qemu_main
107 #endif /* CONFIG_SDL */
111 #define main qemu_main
112 #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"
139 #include "blockdev.h"
140 #include "hw/block-common.h"
141 #include "block-migration.h"
143 #include "audio/audio.h"
144 #include "migration.h"
147 #include "qemu-option.h"
148 #include "qemu-config.h"
149 #include "qemu-options.h"
150 #include "qmp-commands.h"
151 #include "main-loop.h"
153 #include "fsdev/qemu-fsdev.h"
159 #include "qemu_socket.h"
161 #include "slirp/libslirp.h"
164 #include "trace/control.h"
165 #include "qemu-queue.h"
167 #include "arch_init.h"
170 #include "ui/qemu-spice.h"
173 //#define DEBUG_SLIRP
175 #define DEFAULT_RAM_SIZE 128
177 #define MAX_VIRTIO_CONSOLES 1
179 static const char *data_dir
;
180 const char *bios_name
= NULL
;
181 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
182 DisplayType display_type
= DT_DEFAULT
;
183 int display_remote
= 0;
184 const char* keyboard_layout
= NULL
;
186 const char *mem_path
= NULL
;
188 int mem_prealloc
= 0; /* force preallocation of physical target memory */
191 NICInfo nd_table
[MAX_NICS
];
193 static int rtc_utc
= 1;
194 static int rtc_date_offset
= -1; /* -1 means no change */
195 QEMUClock
*rtc_clock
;
196 int vga_interface_type
= VGA_NONE
;
197 static int full_screen
= 0;
199 static int no_frame
= 0;
202 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
203 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
204 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
205 int win2k_install_hack
= 0;
212 const char *vnc_display
;
214 int acpi_enabled
= 1;
220 int graphic_rotate
= 0;
221 const char *watchdog
;
222 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
224 int semihosting_enabled
= 0;
226 const char *qemu_name
;
229 unsigned int nb_prom_envs
= 0;
230 const char *prom_envs
[MAX_PROM_ENVS
];
232 uint8_t *boot_splash_filedata
;
233 int boot_splash_filedata_size
;
234 uint8_t qemu_extra_params_fw
[2];
236 typedef struct FWBootEntry FWBootEntry
;
239 QTAILQ_ENTRY(FWBootEntry
) link
;
245 QTAILQ_HEAD(, FWBootEntry
) fw_boot_order
= QTAILQ_HEAD_INITIALIZER(fw_boot_order
);
248 uint64_t node_mem
[MAX_NODES
];
249 unsigned long *node_cpumask
[MAX_NODES
];
251 uint8_t qemu_uuid
[16];
253 static QEMUBootSetHandler
*boot_set_handler
;
254 static void *boot_set_opaque
;
256 static NotifierList exit_notifiers
=
257 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
259 static NotifierList machine_init_done_notifiers
=
260 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
262 static int tcg_allowed
= 1;
266 enum xen_mode xen_mode
= XEN_EMULATE
;
267 static int tcg_tb_size
;
269 static int default_serial
= 1;
270 static int default_parallel
= 1;
271 static int default_virtcon
= 1;
272 static int default_monitor
= 1;
273 static int default_floppy
= 1;
274 static int default_cdrom
= 1;
275 static int default_sdcard
= 1;
276 static int default_vga
= 1;
282 { .driver
= "isa-serial", .flag
= &default_serial
},
283 { .driver
= "isa-parallel", .flag
= &default_parallel
},
284 { .driver
= "isa-fdc", .flag
= &default_floppy
},
285 { .driver
= "ide-cd", .flag
= &default_cdrom
},
286 { .driver
= "ide-hd", .flag
= &default_cdrom
},
287 { .driver
= "ide-drive", .flag
= &default_cdrom
},
288 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
289 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
290 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
291 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
292 { .driver
= "VGA", .flag
= &default_vga
},
293 { .driver
= "isa-vga", .flag
= &default_vga
},
294 { .driver
= "cirrus-vga", .flag
= &default_vga
},
295 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
296 { .driver
= "vmware-svga", .flag
= &default_vga
},
297 { .driver
= "qxl-vga", .flag
= &default_vga
},
300 const char *qemu_get_vm_name(void)
305 static void res_free(void)
307 if (boot_splash_filedata
!= NULL
) {
308 g_free(boot_splash_filedata
);
309 boot_splash_filedata
= NULL
;
313 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
315 const char *driver
= qemu_opt_get(opts
, "driver");
320 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
321 if (strcmp(default_list
[i
].driver
, driver
) != 0)
323 *(default_list
[i
].flag
) = 0;
328 /***********************************************************/
331 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
336 } RunStateTransition
;
338 static const RunStateTransition runstate_transitions_def
[] = {
340 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
342 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
343 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
345 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
346 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
348 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
349 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
351 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
352 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
354 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
355 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
357 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
358 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
359 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
361 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
362 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
364 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
366 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
367 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
368 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
369 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
370 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
371 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
372 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
373 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
374 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
376 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
378 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
379 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
381 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
382 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
383 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
384 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
386 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
387 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
389 { RUN_STATE_MAX
, RUN_STATE_MAX
},
392 static bool runstate_valid_transitions
[RUN_STATE_MAX
][RUN_STATE_MAX
];
394 bool runstate_check(RunState state
)
396 return current_run_state
== state
;
399 void runstate_init(void)
401 const RunStateTransition
*p
;
403 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
405 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE_MAX
; p
++) {
406 runstate_valid_transitions
[p
->from
][p
->to
] = true;
410 /* This function will abort() on invalid state transitions */
411 void runstate_set(RunState new_state
)
413 assert(new_state
< RUN_STATE_MAX
);
415 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
416 fprintf(stderr
, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
417 RunState_lookup
[current_run_state
],
418 RunState_lookup
[new_state
]);
422 current_run_state
= new_state
;
425 int runstate_is_running(void)
427 return runstate_check(RUN_STATE_RUNNING
);
430 StatusInfo
*qmp_query_status(Error
**errp
)
432 StatusInfo
*info
= g_malloc0(sizeof(*info
));
434 info
->running
= runstate_is_running();
435 info
->singlestep
= singlestep
;
436 info
->status
= current_run_state
;
441 /***********************************************************/
442 /* real time host monotonic timer */
444 /***********************************************************/
445 /* host time/date access */
446 void qemu_get_timedate(struct tm
*tm
, int offset
)
453 if (rtc_date_offset
== -1) {
457 ret
= localtime(&ti
);
459 ti
-= rtc_date_offset
;
463 memcpy(tm
, ret
, sizeof(struct tm
));
466 int qemu_timedate_diff(struct tm
*tm
)
470 if (rtc_date_offset
== -1)
472 seconds
= mktimegm(tm
);
475 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
476 seconds
= mktime(&tmp
);
479 seconds
= mktimegm(tm
) + rtc_date_offset
;
481 return seconds
- time(NULL
);
484 void rtc_change_mon_event(struct tm
*tm
)
488 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
489 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
490 qobject_decref(data
);
493 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
495 time_t rtc_start_date
;
498 if (!strcmp(startdate
, "now") && legacy
) {
499 rtc_date_offset
= -1;
501 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
509 } else if (sscanf(startdate
, "%d-%d-%d",
521 rtc_start_date
= mktimegm(&tm
);
522 if (rtc_start_date
== -1) {
524 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
525 "'2006-06-17T16:01:21' or '2006-06-17'\n");
528 rtc_date_offset
= time(NULL
) - rtc_start_date
;
532 static void configure_rtc(QemuOpts
*opts
)
536 value
= qemu_opt_get(opts
, "base");
538 if (!strcmp(value
, "utc")) {
540 } else if (!strcmp(value
, "localtime")) {
543 configure_rtc_date_offset(value
, 0);
546 value
= qemu_opt_get(opts
, "clock");
548 if (!strcmp(value
, "host")) {
549 rtc_clock
= host_clock
;
550 } else if (!strcmp(value
, "rt")) {
551 rtc_clock
= rt_clock
;
552 } else if (!strcmp(value
, "vm")) {
553 rtc_clock
= vm_clock
;
555 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
559 value
= qemu_opt_get(opts
, "driftfix");
561 if (!strcmp(value
, "slew")) {
562 static GlobalProperty slew_lost_ticks
[] = {
564 .driver
= "mc146818rtc",
565 .property
= "lost_tick_policy",
568 { /* end of list */ }
571 qdev_prop_register_global_list(slew_lost_ticks
);
572 } else if (!strcmp(value
, "none")) {
573 /* discard is default */
575 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
581 /***********************************************************/
582 /* Bluetooth support */
585 static struct HCIInfo
*hci_table
[MAX_NICS
];
587 static struct bt_vlan_s
{
588 struct bt_scatternet_s net
;
590 struct bt_vlan_s
*next
;
593 /* find or alloc a new bluetooth "VLAN" */
594 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
596 struct bt_vlan_s
**pvlan
, *vlan
;
597 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
601 vlan
= g_malloc0(sizeof(struct bt_vlan_s
));
603 pvlan
= &first_bt_vlan
;
604 while (*pvlan
!= NULL
)
605 pvlan
= &(*pvlan
)->next
;
610 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
614 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
619 static struct HCIInfo null_hci
= {
620 .cmd_send
= null_hci_send
,
621 .sco_send
= null_hci_send
,
622 .acl_send
= null_hci_send
,
623 .bdaddr_set
= null_hci_addr_set
,
626 struct HCIInfo
*qemu_next_hci(void)
628 if (cur_hci
== nb_hcis
)
631 return hci_table
[cur_hci
++];
634 static struct HCIInfo
*hci_init(const char *str
)
637 struct bt_scatternet_s
*vlan
= 0;
639 if (!strcmp(str
, "null"))
642 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
644 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
645 else if (!strncmp(str
, "hci", 3)) {
648 if (!strncmp(str
+ 3, ",vlan=", 6)) {
649 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
654 vlan
= qemu_find_bt_vlan(0);
656 return bt_new_hci(vlan
);
659 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
664 static int bt_hci_parse(const char *str
)
669 if (nb_hcis
>= MAX_NICS
) {
670 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
683 bdaddr
.b
[5] = 0x56 + nb_hcis
;
684 hci
->bdaddr_set(hci
, bdaddr
.b
);
686 hci_table
[nb_hcis
++] = hci
;
691 static void bt_vhci_add(int vlan_id
)
693 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
696 fprintf(stderr
, "qemu: warning: adding a VHCI to "
697 "an empty scatternet %i\n", vlan_id
);
699 bt_vhci_init(bt_new_hci(vlan
));
702 static struct bt_device_s
*bt_device_add(const char *opt
)
704 struct bt_scatternet_s
*vlan
;
706 char *endp
= strstr(opt
, ",vlan=");
707 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
710 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
713 vlan_id
= strtol(endp
+ 6, &endp
, 0);
715 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
720 vlan
= qemu_find_bt_vlan(vlan_id
);
723 fprintf(stderr
, "qemu: warning: adding a slave device to "
724 "an empty scatternet %i\n", vlan_id
);
726 if (!strcmp(devname
, "keyboard"))
727 return bt_keyboard_init(vlan
);
729 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
733 static int bt_parse(const char *opt
)
735 const char *endp
, *p
;
738 if (strstart(opt
, "hci", &endp
)) {
739 if (!*endp
|| *endp
== ',') {
741 if (!strstart(endp
, ",vlan=", 0))
744 return bt_hci_parse(opt
);
746 } else if (strstart(opt
, "vhci", &endp
)) {
747 if (!*endp
|| *endp
== ',') {
749 if (strstart(endp
, ",vlan=", &p
)) {
750 vlan
= strtol(p
, (char **) &endp
, 0);
752 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
756 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
765 } else if (strstart(opt
, "device:", &endp
))
766 return !bt_device_add(endp
);
768 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
772 static int parse_sandbox(QemuOpts
*opts
, void *opaque
)
774 /* FIXME: change this to true for 1.3 */
775 if (qemu_opt_get_bool(opts
, "enable", false)) {
776 #ifdef CONFIG_SECCOMP
777 if (seccomp_start() < 0) {
778 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
779 "failed to install seccomp syscall filter in the kernel");
783 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
784 "sandboxing request but seccomp is not compiled into this build");
792 /*********QEMU USB setting******/
793 bool usb_enabled(bool default_usb
)
796 mach_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
798 return qemu_opt_get_bool(mach_opts
, "usb", default_usb
);
803 /***********************************************************/
804 /* QEMU Block devices */
806 #define HD_OPTS "media=disk"
807 #define CDROM_OPTS "media=cdrom"
809 #define PFLASH_OPTS ""
813 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
815 int *use_scsi
= opaque
;
817 return drive_init(opts
, *use_scsi
) == NULL
;
820 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
822 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
823 qemu_opt_set(opts
, "snapshot", "on");
828 static void default_drive(int enable
, int snapshot
, int use_scsi
,
829 BlockInterfaceType type
, int index
,
834 if (type
== IF_DEFAULT
) {
835 type
= use_scsi
? IF_SCSI
: IF_IDE
;
838 if (!enable
|| drive_get_by_index(type
, index
)) {
842 opts
= drive_add(type
, index
, NULL
, optstr
);
844 drive_enable_snapshot(opts
, NULL
);
846 if (!drive_init(opts
, use_scsi
)) {
851 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
853 boot_set_handler
= func
;
854 boot_set_opaque
= opaque
;
857 int qemu_boot_set(const char *boot_devices
)
859 if (!boot_set_handler
) {
862 return boot_set_handler(boot_set_opaque
, boot_devices
);
865 static void validate_bootdevices(char *devices
)
867 /* We just do some generic consistency checks */
871 for (p
= devices
; *p
!= '\0'; p
++) {
872 /* Allowed boot devices are:
873 * a-b: floppy disk drives
874 * c-f: IDE disk drives
875 * g-m: machine implementation dependent drives
876 * n-p: network devices
877 * It's up to each machine implementation to check if the given boot
878 * devices match the actual hardware implementation and firmware
881 if (*p
< 'a' || *p
> 'p') {
882 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
885 if (bitmap
& (1 << (*p
- 'a'))) {
886 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
889 bitmap
|= 1 << (*p
- 'a');
893 static void restore_boot_devices(void *opaque
)
895 char *standard_boot_devices
= opaque
;
896 static int first
= 1;
898 /* Restore boot order and remove ourselves after the first boot */
904 qemu_boot_set(standard_boot_devices
);
906 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
907 g_free(standard_boot_devices
);
910 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
913 FWBootEntry
*node
, *i
;
919 assert(dev
!= NULL
|| suffix
!= NULL
);
921 node
= g_malloc0(sizeof(FWBootEntry
));
922 node
->bootindex
= bootindex
;
923 node
->suffix
= suffix
? g_strdup(suffix
) : NULL
;
926 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
927 if (i
->bootindex
== bootindex
) {
928 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
930 } else if (i
->bootindex
< bootindex
) {
933 QTAILQ_INSERT_BEFORE(i
, node
, link
);
936 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
940 * This function returns null terminated string that consist of new line
941 * separated device paths.
943 * memory pointed by "size" is assigned total length of the array in bytes
946 char *get_boot_devices_list(uint32_t *size
)
952 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
953 char *devpath
= NULL
, *bootpath
;
957 devpath
= qdev_get_fw_dev_path(i
->dev
);
961 if (i
->suffix
&& devpath
) {
962 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
964 bootpath
= g_malloc(bootpathlen
);
965 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
967 } else if (devpath
) {
971 bootpath
= g_strdup(i
->suffix
);
975 list
[total
-1] = '\n';
977 len
= strlen(bootpath
) + 1;
978 list
= g_realloc(list
, total
+ len
);
979 memcpy(&list
[total
], bootpath
, len
);
989 static void numa_add(const char *optarg
)
993 unsigned long long value
, endvalue
;
996 value
= endvalue
= 0ULL;
998 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
999 if (!strcmp(option
, "node")) {
1000 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
1001 nodenr
= nb_numa_nodes
;
1003 nodenr
= strtoull(option
, NULL
, 10);
1006 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
1007 node_mem
[nodenr
] = 0;
1010 sval
= strtosz(option
, &endptr
);
1011 if (sval
< 0 || *endptr
) {
1012 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
1015 node_mem
[nodenr
] = sval
;
1017 if (get_param_value(option
, 128, "cpus", optarg
) != 0) {
1018 value
= strtoull(option
, &endptr
, 10);
1019 if (*endptr
== '-') {
1020 endvalue
= strtoull(endptr
+1, &endptr
, 10);
1025 if (!(endvalue
< MAX_CPUMASK_BITS
)) {
1026 endvalue
= MAX_CPUMASK_BITS
- 1;
1028 "A max of %d CPUs are supported in a guest\n",
1032 bitmap_set(node_cpumask
[nodenr
], value
, endvalue
-value
+1);
1038 static void smp_parse(const char *optarg
)
1040 int smp
, sockets
= 0, threads
= 0, cores
= 0;
1044 smp
= strtoul(optarg
, &endptr
, 10);
1045 if (endptr
!= optarg
) {
1046 if (*endptr
== ',') {
1050 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
1051 sockets
= strtoull(option
, NULL
, 10);
1052 if (get_param_value(option
, 128, "cores", endptr
) != 0)
1053 cores
= strtoull(option
, NULL
, 10);
1054 if (get_param_value(option
, 128, "threads", endptr
) != 0)
1055 threads
= strtoull(option
, NULL
, 10);
1056 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
1057 max_cpus
= strtoull(option
, NULL
, 10);
1059 /* compute missing values, prefer sockets over cores over threads */
1060 if (smp
== 0 || sockets
== 0) {
1061 sockets
= sockets
> 0 ? sockets
: 1;
1062 cores
= cores
> 0 ? cores
: 1;
1063 threads
= threads
> 0 ? threads
: 1;
1065 smp
= cores
* threads
* sockets
;
1069 threads
= threads
> 0 ? threads
: 1;
1070 cores
= smp
/ (sockets
* threads
);
1072 threads
= smp
/ (cores
* sockets
);
1076 smp_cores
= cores
> 0 ? cores
: 1;
1077 smp_threads
= threads
> 0 ? threads
: 1;
1079 max_cpus
= smp_cpus
;
1082 /***********************************************************/
1085 static int usb_device_add(const char *devname
)
1088 USBDevice
*dev
= NULL
;
1090 if (!usb_enabled(false)) {
1094 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1095 dev
= usbdevice_create(devname
);
1099 /* the other ones */
1100 #ifndef CONFIG_LINUX
1101 /* only the linux version is qdev-ified, usb-bsd still needs this */
1102 if (strstart(devname
, "host:", &p
)) {
1103 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1106 if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
1107 dev
= usb_bt_init(usb_bus_find(-1),
1108 devname
[2] ? hci_init(p
)
1109 : bt_new_hci(qemu_find_bt_vlan(0)));
1120 static int usb_device_del(const char *devname
)
1125 if (strstart(devname
, "host:", &p
))
1126 return usb_host_device_close(p
);
1128 if (!usb_enabled(false)) {
1132 p
= strchr(devname
, '.');
1135 bus_num
= strtoul(devname
, NULL
, 0);
1136 addr
= strtoul(p
+ 1, NULL
, 0);
1138 return usb_device_delete_addr(bus_num
, addr
);
1141 static int usb_parse(const char *cmdline
)
1144 r
= usb_device_add(cmdline
);
1146 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
1151 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
1153 const char *devname
= qdict_get_str(qdict
, "devname");
1154 if (usb_device_add(devname
) < 0) {
1155 error_report("could not add USB device '%s'", devname
);
1159 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
1161 const char *devname
= qdict_get_str(qdict
, "devname");
1162 if (usb_device_del(devname
) < 0) {
1163 error_report("could not delete USB device '%s'", devname
);
1167 /***********************************************************/
1168 /* PCMCIA/Cardbus */
1170 static struct pcmcia_socket_entry_s
{
1171 PCMCIASocket
*socket
;
1172 struct pcmcia_socket_entry_s
*next
;
1173 } *pcmcia_sockets
= 0;
1175 void pcmcia_socket_register(PCMCIASocket
*socket
)
1177 struct pcmcia_socket_entry_s
*entry
;
1179 entry
= g_malloc(sizeof(struct pcmcia_socket_entry_s
));
1180 entry
->socket
= socket
;
1181 entry
->next
= pcmcia_sockets
;
1182 pcmcia_sockets
= entry
;
1185 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
1187 struct pcmcia_socket_entry_s
*entry
, **ptr
;
1189 ptr
= &pcmcia_sockets
;
1190 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
1191 if (entry
->socket
== socket
) {
1197 void pcmcia_info(Monitor
*mon
)
1199 struct pcmcia_socket_entry_s
*iter
;
1201 if (!pcmcia_sockets
)
1202 monitor_printf(mon
, "No PCMCIA sockets\n");
1204 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1205 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1206 iter
->socket
->attached
? iter
->socket
->card_string
:
1210 /***********************************************************/
1211 /* machine registration */
1213 static QEMUMachine
*first_machine
= NULL
;
1214 QEMUMachine
*current_machine
= NULL
;
1216 int qemu_register_machine(QEMUMachine
*m
)
1219 pm
= &first_machine
;
1227 static QEMUMachine
*find_machine(const char *name
)
1231 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1232 if (!strcmp(m
->name
, name
))
1234 if (m
->alias
&& !strcmp(m
->alias
, name
))
1240 QEMUMachine
*find_default_machine(void)
1244 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1245 if (m
->is_default
) {
1252 MachineInfoList
*qmp_query_machines(Error
**errp
)
1254 MachineInfoList
*mach_list
= NULL
;
1257 for (m
= first_machine
; m
; m
= m
->next
) {
1258 MachineInfoList
*entry
;
1261 info
= g_malloc0(sizeof(*info
));
1262 if (m
->is_default
) {
1263 info
->has_is_default
= true;
1264 info
->is_default
= true;
1268 info
->has_alias
= true;
1269 info
->alias
= g_strdup(m
->alias
);
1272 info
->name
= g_strdup(m
->name
);
1274 entry
= g_malloc0(sizeof(*entry
));
1275 entry
->value
= info
;
1276 entry
->next
= mach_list
;
1283 /***********************************************************/
1284 /* main execution loop */
1286 static void gui_update(void *opaque
)
1288 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1289 DisplayState
*ds
= opaque
;
1290 DisplayChangeListener
*dcl
= ds
->listeners
;
1294 while (dcl
!= NULL
) {
1295 if (dcl
->gui_timer_interval
&&
1296 dcl
->gui_timer_interval
< interval
)
1297 interval
= dcl
->gui_timer_interval
;
1300 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock_ms(rt_clock
));
1303 struct vm_change_state_entry
{
1304 VMChangeStateHandler
*cb
;
1306 QLIST_ENTRY (vm_change_state_entry
) entries
;
1309 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1311 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1314 VMChangeStateEntry
*e
;
1316 e
= g_malloc0(sizeof (*e
));
1320 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1324 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1326 QLIST_REMOVE (e
, entries
);
1330 void vm_state_notify(int running
, RunState state
)
1332 VMChangeStateEntry
*e
;
1334 trace_vm_state_notify(running
, state
);
1336 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1337 e
->cb(e
->opaque
, running
, state
);
1343 if (!runstate_is_running()) {
1345 runstate_set(RUN_STATE_RUNNING
);
1346 vm_state_notify(1, RUN_STATE_RUNNING
);
1348 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1352 /* reset/shutdown handler */
1354 typedef struct QEMUResetEntry
{
1355 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1356 QEMUResetHandler
*func
;
1360 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1361 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1362 static int reset_requested
;
1363 static int shutdown_requested
, shutdown_signal
= -1;
1364 static pid_t shutdown_pid
;
1365 static int powerdown_requested
;
1366 static int debug_requested
;
1367 static int suspend_requested
;
1368 static int wakeup_requested
;
1369 static NotifierList powerdown_notifiers
=
1370 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1371 static NotifierList suspend_notifiers
=
1372 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1373 static NotifierList wakeup_notifiers
=
1374 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1375 static uint32_t wakeup_reason_mask
= ~0;
1376 static RunState vmstop_requested
= RUN_STATE_MAX
;
1378 int qemu_shutdown_requested_get(void)
1380 return shutdown_requested
;
1383 int qemu_reset_requested_get(void)
1385 return reset_requested
;
1388 int qemu_shutdown_requested(void)
1390 int r
= shutdown_requested
;
1391 shutdown_requested
= 0;
1395 void qemu_kill_report(void)
1397 if (!qtest_enabled() && shutdown_signal
!= -1) {
1398 fprintf(stderr
, "qemu: terminating on signal %d", shutdown_signal
);
1399 if (shutdown_pid
== 0) {
1400 /* This happens for eg ^C at the terminal, so it's worth
1401 * avoiding printing an odd message in that case.
1403 fputc('\n', stderr
);
1405 fprintf(stderr
, " from pid " FMT_pid
"\n", shutdown_pid
);
1407 shutdown_signal
= -1;
1411 int qemu_reset_requested(void)
1413 int r
= reset_requested
;
1414 reset_requested
= 0;
1418 static int qemu_suspend_requested(void)
1420 int r
= suspend_requested
;
1421 suspend_requested
= 0;
1425 static int qemu_wakeup_requested(void)
1427 int r
= wakeup_requested
;
1428 wakeup_requested
= 0;
1432 int qemu_powerdown_requested(void)
1434 int r
= powerdown_requested
;
1435 powerdown_requested
= 0;
1439 static int qemu_debug_requested(void)
1441 int r
= debug_requested
;
1442 debug_requested
= 0;
1446 /* We use RUN_STATE_MAX but any invalid value will do */
1447 static bool qemu_vmstop_requested(RunState
*r
)
1449 if (vmstop_requested
< RUN_STATE_MAX
) {
1450 *r
= vmstop_requested
;
1451 vmstop_requested
= RUN_STATE_MAX
;
1458 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1460 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1463 re
->opaque
= opaque
;
1464 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1467 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1471 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1472 if (re
->func
== func
&& re
->opaque
== opaque
) {
1473 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1480 void qemu_devices_reset(void)
1482 QEMUResetEntry
*re
, *nre
;
1484 /* reset all devices */
1485 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1486 re
->func(re
->opaque
);
1490 void qemu_system_reset(bool report
)
1492 if (current_machine
&& current_machine
->reset
) {
1493 current_machine
->reset();
1495 qemu_devices_reset();
1498 monitor_protocol_event(QEVENT_RESET
, NULL
);
1500 cpu_synchronize_all_post_reset();
1503 void qemu_system_reset_request(void)
1506 shutdown_requested
= 1;
1508 reset_requested
= 1;
1511 qemu_notify_event();
1514 static void qemu_system_suspend(void)
1517 notifier_list_notify(&suspend_notifiers
, NULL
);
1518 runstate_set(RUN_STATE_SUSPENDED
);
1519 monitor_protocol_event(QEVENT_SUSPEND
, NULL
);
1522 void qemu_system_suspend_request(void)
1524 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1527 suspend_requested
= 1;
1529 qemu_notify_event();
1532 void qemu_register_suspend_notifier(Notifier
*notifier
)
1534 notifier_list_add(&suspend_notifiers
, notifier
);
1537 void qemu_system_wakeup_request(WakeupReason reason
)
1539 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1542 if (!(wakeup_reason_mask
& (1 << reason
))) {
1545 runstate_set(RUN_STATE_RUNNING
);
1546 notifier_list_notify(&wakeup_notifiers
, &reason
);
1547 wakeup_requested
= 1;
1548 qemu_notify_event();
1551 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1554 wakeup_reason_mask
|= (1 << reason
);
1556 wakeup_reason_mask
&= ~(1 << reason
);
1560 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1562 notifier_list_add(&wakeup_notifiers
, notifier
);
1565 void qemu_system_killed(int signal
, pid_t pid
)
1567 shutdown_signal
= signal
;
1570 qemu_system_shutdown_request();
1573 void qemu_system_shutdown_request(void)
1575 shutdown_requested
= 1;
1576 qemu_notify_event();
1579 static void qemu_system_powerdown(void)
1581 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1582 notifier_list_notify(&powerdown_notifiers
, NULL
);
1585 void qemu_system_powerdown_request(void)
1587 powerdown_requested
= 1;
1588 qemu_notify_event();
1591 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1593 notifier_list_add(&powerdown_notifiers
, notifier
);
1596 void qemu_system_debug_request(void)
1598 debug_requested
= 1;
1599 qemu_notify_event();
1602 void qemu_system_vmstop_request(RunState state
)
1604 vmstop_requested
= state
;
1605 qemu_notify_event();
1608 static bool main_loop_should_exit(void)
1611 if (qemu_debug_requested()) {
1612 vm_stop(RUN_STATE_DEBUG
);
1614 if (qemu_suspend_requested()) {
1615 qemu_system_suspend();
1617 if (qemu_shutdown_requested()) {
1619 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1621 vm_stop(RUN_STATE_SHUTDOWN
);
1626 if (qemu_reset_requested()) {
1628 cpu_synchronize_all_states();
1629 qemu_system_reset(VMRESET_REPORT
);
1631 if (runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
1632 runstate_check(RUN_STATE_SHUTDOWN
)) {
1633 runstate_set(RUN_STATE_PAUSED
);
1636 if (qemu_wakeup_requested()) {
1638 cpu_synchronize_all_states();
1639 qemu_system_reset(VMRESET_SILENT
);
1641 monitor_protocol_event(QEVENT_WAKEUP
, NULL
);
1643 if (qemu_powerdown_requested()) {
1644 qemu_system_powerdown();
1646 if (qemu_vmstop_requested(&r
)) {
1652 static void main_loop(void)
1656 #ifdef CONFIG_PROFILER
1660 nonblocking
= !kvm_enabled() && last_io
> 0;
1661 #ifdef CONFIG_PROFILER
1662 ti
= profile_getclock();
1664 last_io
= main_loop_wait(nonblocking
);
1665 #ifdef CONFIG_PROFILER
1666 dev_time
+= profile_getclock() - ti
;
1668 } while (!main_loop_should_exit());
1671 static void version(void)
1673 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1676 static void help(int exitcode
)
1679 printf("usage: %s [options] [disk_image]\n\n"
1680 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1681 error_get_progname());
1683 #define QEMU_OPTIONS_GENERATE_HELP
1684 #include "qemu-options-wrapper.h"
1686 printf("\nDuring emulation, the following keys are useful:\n"
1687 "ctrl-alt-f toggle full screen\n"
1688 "ctrl-alt-n switch to virtual console 'n'\n"
1689 "ctrl-alt toggle mouse and keyboard grab\n"
1691 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1696 #define HAS_ARG 0x0001
1698 typedef struct QEMUOption
{
1705 static const QEMUOption qemu_options
[] = {
1706 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1707 #define QEMU_OPTIONS_GENERATE_OPTIONS
1708 #include "qemu-options-wrapper.h"
1712 static bool vga_available(void)
1714 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
1717 static bool cirrus_vga_available(void)
1719 return object_class_by_name("cirrus-vga")
1720 || object_class_by_name("isa-cirrus-vga");
1723 static bool vmware_vga_available(void)
1725 return object_class_by_name("vmware-svga");
1728 static bool qxl_vga_available(void)
1730 return object_class_by_name("qxl-vga");
1733 static void select_vgahw (const char *p
)
1737 vga_interface_type
= VGA_NONE
;
1738 if (strstart(p
, "std", &opts
)) {
1739 if (vga_available()) {
1740 vga_interface_type
= VGA_STD
;
1742 fprintf(stderr
, "Error: standard VGA not available\n");
1745 } else if (strstart(p
, "cirrus", &opts
)) {
1746 if (cirrus_vga_available()) {
1747 vga_interface_type
= VGA_CIRRUS
;
1749 fprintf(stderr
, "Error: Cirrus VGA not available\n");
1752 } else if (strstart(p
, "vmware", &opts
)) {
1753 if (vmware_vga_available()) {
1754 vga_interface_type
= VGA_VMWARE
;
1756 fprintf(stderr
, "Error: VMWare SVGA not available\n");
1759 } else if (strstart(p
, "xenfb", &opts
)) {
1760 vga_interface_type
= VGA_XENFB
;
1761 } else if (strstart(p
, "qxl", &opts
)) {
1762 if (qxl_vga_available()) {
1763 vga_interface_type
= VGA_QXL
;
1765 fprintf(stderr
, "Error: QXL VGA not available\n");
1768 } else if (!strstart(p
, "none", &opts
)) {
1770 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1774 const char *nextopt
;
1776 if (strstart(opts
, ",retrace=", &nextopt
)) {
1778 if (strstart(opts
, "dumb", &nextopt
))
1779 vga_retrace_method
= VGA_RETRACE_DUMB
;
1780 else if (strstart(opts
, "precise", &nextopt
))
1781 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1782 else goto invalid_vga
;
1783 } else goto invalid_vga
;
1788 static DisplayType
select_display(const char *p
)
1791 DisplayType display
= DT_DEFAULT
;
1793 if (strstart(p
, "sdl", &opts
)) {
1797 const char *nextopt
;
1799 if (strstart(opts
, ",frame=", &nextopt
)) {
1801 if (strstart(opts
, "on", &nextopt
)) {
1803 } else if (strstart(opts
, "off", &nextopt
)) {
1806 goto invalid_sdl_args
;
1808 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1810 if (strstart(opts
, "on", &nextopt
)) {
1812 } else if (strstart(opts
, "off", &nextopt
)) {
1815 goto invalid_sdl_args
;
1817 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1819 if (strstart(opts
, "on", &nextopt
)) {
1821 } else if (strstart(opts
, "off", &nextopt
)) {
1824 goto invalid_sdl_args
;
1826 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
1828 if (strstart(opts
, "on", &nextopt
)) {
1830 } else if (strstart(opts
, "off", &nextopt
)) {
1833 goto invalid_sdl_args
;
1837 fprintf(stderr
, "Invalid SDL option string: %s\n", p
);
1843 fprintf(stderr
, "SDL support is disabled\n");
1846 } else if (strstart(p
, "vnc", &opts
)) {
1851 const char *nextopt
;
1853 if (strstart(opts
, "=", &nextopt
)) {
1854 vnc_display
= nextopt
;
1858 fprintf(stderr
, "VNC requires a display argument vnc=<display>\n");
1862 fprintf(stderr
, "VNC support is disabled\n");
1865 } else if (strstart(p
, "curses", &opts
)) {
1866 #ifdef CONFIG_CURSES
1867 display
= DT_CURSES
;
1869 fprintf(stderr
, "Curses support is disabled\n");
1872 } else if (strstart(p
, "none", &opts
)) {
1875 fprintf(stderr
, "Unknown display type: %s\n", p
);
1882 static int balloon_parse(const char *arg
)
1886 if (strcmp(arg
, "none") == 0) {
1890 if (!strncmp(arg
, "virtio", 6)) {
1891 if (arg
[6] == ',') {
1892 /* have params -> parse them */
1893 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1897 /* create empty opts */
1898 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0, NULL
);
1900 qemu_opt_set(opts
, "driver", "virtio-balloon");
1907 char *qemu_find_file(int type
, const char *name
)
1913 /* Try the name as a straight path first */
1914 if (access(name
, R_OK
) == 0) {
1915 return g_strdup(name
);
1918 case QEMU_FILE_TYPE_BIOS
:
1921 case QEMU_FILE_TYPE_KEYMAP
:
1922 subdir
= "keymaps/";
1927 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1928 buf
= g_malloc0(len
);
1929 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1930 if (access(buf
, R_OK
)) {
1937 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1939 return qdev_device_help(opts
);
1942 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1946 dev
= qdev_device_add(opts
);
1952 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1954 CharDriverState
*chr
;
1956 chr
= qemu_chr_new_from_opts(opts
, NULL
);
1962 #ifdef CONFIG_VIRTFS
1963 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1966 ret
= qemu_fsdev_add(opts
);
1972 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1974 CharDriverState
*chr
;
1975 const char *chardev
;
1979 mode
= qemu_opt_get(opts
, "mode");
1983 if (strcmp(mode
, "readline") == 0) {
1984 flags
= MONITOR_USE_READLINE
;
1985 } else if (strcmp(mode
, "control") == 0) {
1986 flags
= MONITOR_USE_CONTROL
;
1988 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1992 if (qemu_opt_get_bool(opts
, "pretty", 0))
1993 flags
|= MONITOR_USE_PRETTY
;
1995 if (qemu_opt_get_bool(opts
, "default", 0))
1996 flags
|= MONITOR_IS_DEFAULT
;
1998 chardev
= qemu_opt_get(opts
, "chardev");
1999 chr
= qemu_chr_find(chardev
);
2001 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
2005 monitor_init(chr
, flags
);
2009 static void monitor_parse(const char *optarg
, const char *mode
)
2011 static int monitor_device_index
= 0;
2017 if (strstart(optarg
, "chardev:", &p
)) {
2018 snprintf(label
, sizeof(label
), "%s", p
);
2020 snprintf(label
, sizeof(label
), "compat_monitor%d",
2021 monitor_device_index
);
2022 if (monitor_device_index
== 0) {
2025 opts
= qemu_chr_parse_compat(label
, optarg
);
2027 fprintf(stderr
, "parse error: %s\n", optarg
);
2032 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, NULL
);
2034 fprintf(stderr
, "duplicate chardev: %s\n", label
);
2037 qemu_opt_set(opts
, "mode", mode
);
2038 qemu_opt_set(opts
, "chardev", label
);
2040 qemu_opt_set(opts
, "default", "on");
2041 monitor_device_index
++;
2044 struct device_config
{
2046 DEV_USB
, /* -usbdevice */
2048 DEV_SERIAL
, /* -serial */
2049 DEV_PARALLEL
, /* -parallel */
2050 DEV_VIRTCON
, /* -virtioconsole */
2051 DEV_DEBUGCON
, /* -debugcon */
2052 DEV_GDB
, /* -gdb, -s */
2054 const char *cmdline
;
2056 QTAILQ_ENTRY(device_config
) next
;
2058 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
2060 static void add_device_config(int type
, const char *cmdline
)
2062 struct device_config
*conf
;
2064 conf
= g_malloc0(sizeof(*conf
));
2066 conf
->cmdline
= cmdline
;
2067 loc_save(&conf
->loc
);
2068 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2071 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2073 struct device_config
*conf
;
2076 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2077 if (conf
->type
!= type
)
2079 loc_push_restore(&conf
->loc
);
2080 rc
= func(conf
->cmdline
);
2081 loc_pop(&conf
->loc
);
2088 static int serial_parse(const char *devname
)
2090 static int index
= 0;
2093 if (strcmp(devname
, "none") == 0)
2095 if (index
== MAX_SERIAL_PORTS
) {
2096 fprintf(stderr
, "qemu: too many serial ports\n");
2099 snprintf(label
, sizeof(label
), "serial%d", index
);
2100 serial_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2101 if (!serial_hds
[index
]) {
2102 fprintf(stderr
, "qemu: could not connect serial device"
2103 " to character backend '%s'\n", devname
);
2110 static int parallel_parse(const char *devname
)
2112 static int index
= 0;
2115 if (strcmp(devname
, "none") == 0)
2117 if (index
== MAX_PARALLEL_PORTS
) {
2118 fprintf(stderr
, "qemu: too many parallel ports\n");
2121 snprintf(label
, sizeof(label
), "parallel%d", index
);
2122 parallel_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2123 if (!parallel_hds
[index
]) {
2124 fprintf(stderr
, "qemu: could not connect parallel device"
2125 " to character backend '%s'\n", devname
);
2132 static int virtcon_parse(const char *devname
)
2134 QemuOptsList
*device
= qemu_find_opts("device");
2135 static int index
= 0;
2137 QemuOpts
*bus_opts
, *dev_opts
;
2139 if (strcmp(devname
, "none") == 0)
2141 if (index
== MAX_VIRTIO_CONSOLES
) {
2142 fprintf(stderr
, "qemu: too many virtio consoles\n");
2146 bus_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2147 if (arch_type
== QEMU_ARCH_S390X
) {
2148 qemu_opt_set(bus_opts
, "driver", "virtio-serial-s390");
2150 qemu_opt_set(bus_opts
, "driver", "virtio-serial-pci");
2153 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2154 qemu_opt_set(dev_opts
, "driver", "virtconsole");
2156 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2157 virtcon_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2158 if (!virtcon_hds
[index
]) {
2159 fprintf(stderr
, "qemu: could not connect virtio console"
2160 " to character backend '%s'\n", devname
);
2163 qemu_opt_set(dev_opts
, "chardev", label
);
2169 static int debugcon_parse(const char *devname
)
2173 if (!qemu_chr_new("debugcon", devname
, NULL
)) {
2176 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2178 fprintf(stderr
, "qemu: already have a debugcon device\n");
2181 qemu_opt_set(opts
, "driver", "isa-debugcon");
2182 qemu_opt_set(opts
, "chardev", "debugcon");
2186 static QEMUMachine
*machine_parse(const char *name
)
2188 QEMUMachine
*m
, *machine
= NULL
;
2191 machine
= find_machine(name
);
2196 printf("Supported machines are:\n");
2197 for (m
= first_machine
; m
!= NULL
; m
= m
->next
) {
2199 printf("%-20s %s (alias of %s)\n", m
->alias
, m
->desc
, m
->name
);
2201 printf("%-20s %s%s\n", m
->name
, m
->desc
,
2202 m
->is_default
? " (default)" : "");
2204 exit(!name
|| !is_help_option(name
));
2207 static int tcg_init(void)
2209 tcg_exec_init(tcg_tb_size
* 1024 * 1024);
2214 const char *opt_name
;
2216 int (*available
)(void);
2220 { "tcg", "tcg", tcg_available
, tcg_init
, &tcg_allowed
},
2221 { "xen", "Xen", xen_available
, xen_init
, &xen_allowed
},
2222 { "kvm", "KVM", kvm_available
, kvm_init
, &kvm_allowed
},
2223 { "qtest", "QTest", qtest_available
, qtest_init
, &qtest_allowed
},
2226 static int configure_accelerator(void)
2228 const char *p
= NULL
;
2231 bool accel_initialised
= 0;
2232 bool init_failed
= 0;
2234 QemuOptsList
*list
= qemu_find_opts("machine");
2235 if (!QTAILQ_EMPTY(&list
->head
)) {
2236 p
= qemu_opt_get(QTAILQ_FIRST(&list
->head
), "accel");
2240 /* Use the default "accelerator", tcg */
2244 while (!accel_initialised
&& *p
!= '\0') {
2248 p
= get_opt_name(buf
, sizeof (buf
), p
, ':');
2249 for (i
= 0; i
< ARRAY_SIZE(accel_list
); i
++) {
2250 if (strcmp(accel_list
[i
].opt_name
, buf
) == 0) {
2251 *(accel_list
[i
].allowed
) = 1;
2252 ret
= accel_list
[i
].init();
2255 if (!accel_list
[i
].available()) {
2256 printf("%s not supported for this target\n",
2257 accel_list
[i
].name
);
2259 fprintf(stderr
, "failed to initialize %s: %s\n",
2263 *(accel_list
[i
].allowed
) = 0;
2265 accel_initialised
= 1;
2270 if (i
== ARRAY_SIZE(accel_list
)) {
2271 fprintf(stderr
, "\"%s\" accelerator does not exist.\n", buf
);
2275 if (!accel_initialised
) {
2276 fprintf(stderr
, "No accelerator found!\n");
2281 fprintf(stderr
, "Back to %s accelerator.\n", accel_list
[i
].name
);
2284 return !accel_initialised
;
2287 void qemu_add_exit_notifier(Notifier
*notify
)
2289 notifier_list_add(&exit_notifiers
, notify
);
2292 void qemu_remove_exit_notifier(Notifier
*notify
)
2294 notifier_remove(notify
);
2297 static void qemu_run_exit_notifiers(void)
2299 notifier_list_notify(&exit_notifiers
, NULL
);
2302 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2304 notifier_list_add(&machine_init_done_notifiers
, notify
);
2307 static void qemu_run_machine_init_done_notifiers(void)
2309 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2312 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2313 const char **poptarg
, int *poptind
)
2315 const QEMUOption
*popt
;
2316 int optind
= *poptind
;
2317 char *r
= argv
[optind
];
2320 loc_set_cmdline(argv
, optind
, 1);
2322 /* Treat --foo the same as -foo. */
2325 popt
= qemu_options
;
2328 error_report("invalid option");
2331 if (!strcmp(popt
->name
, r
+ 1))
2335 if (popt
->flags
& HAS_ARG
) {
2336 if (optind
>= argc
) {
2337 error_report("requires an argument");
2340 optarg
= argv
[optind
++];
2341 loc_set_cmdline(argv
, optind
- 2, 2);
2352 static gpointer
malloc_and_trace(gsize n_bytes
)
2354 void *ptr
= malloc(n_bytes
);
2355 trace_g_malloc(n_bytes
, ptr
);
2359 static gpointer
realloc_and_trace(gpointer mem
, gsize n_bytes
)
2361 void *ptr
= realloc(mem
, n_bytes
);
2362 trace_g_realloc(mem
, n_bytes
, ptr
);
2366 static void free_and_trace(gpointer mem
)
2372 int qemu_init_main_loop(void)
2374 return main_loop_init();
2377 int main(int argc
, char **argv
, char **envp
)
2380 int snapshot
, linux_boot
;
2381 const char *icount_option
= NULL
;
2382 const char *initrd_filename
;
2383 const char *kernel_filename
, *kernel_cmdline
;
2384 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
2386 DisplayChangeListener
*dcl
;
2387 int cyls
, heads
, secs
, translation
;
2388 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
;
2389 QemuOptsList
*olist
;
2392 const char *loadvm
= NULL
;
2393 QEMUMachine
*machine
;
2394 const char *cpu_model
;
2395 const char *vga_model
= "none";
2396 const char *pid_file
= NULL
;
2397 const char *incoming
= NULL
;
2399 int show_vnc_port
= 0;
2401 bool defconfig
= true;
2402 bool userconfig
= true;
2403 const char *log_mask
= NULL
;
2404 const char *log_file
= NULL
;
2405 GMemVTable mem_trace
= {
2406 .malloc
= malloc_and_trace
,
2407 .realloc
= realloc_and_trace
,
2408 .free
= free_and_trace
,
2410 const char *trace_events
= NULL
;
2411 const char *trace_file
= NULL
;
2413 atexit(qemu_run_exit_notifiers
);
2414 error_set_progname(argv
[0]);
2416 g_mem_set_vtable(&mem_trace
);
2417 if (!g_thread_supported()) {
2418 #if !GLIB_CHECK_VERSION(2, 31, 0)
2419 g_thread_init(NULL
);
2421 fprintf(stderr
, "glib threading failed to initialize.\n");
2426 module_call_init(MODULE_INIT_QOM
);
2431 rtc_clock
= host_clock
;
2433 qemu_cache_utils_init(envp
);
2435 QLIST_INIT (&vm_change_state_head
);
2436 os_setup_early_signal_handling();
2438 module_call_init(MODULE_INIT_MACHINE
);
2439 machine
= find_default_machine();
2443 cyls
= heads
= secs
= 0;
2444 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2446 for (i
= 0; i
< MAX_NODES
; i
++) {
2448 node_cpumask
[i
] = bitmap_new(MAX_CPUMASK_BITS
);
2456 /* first pass of option parsing */
2458 while (optind
< argc
) {
2459 if (argv
[optind
][0] != '-') {
2464 const QEMUOption
*popt
;
2466 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2467 switch (popt
->index
) {
2468 case QEMU_OPTION_nodefconfig
:
2471 case QEMU_OPTION_nouserconfig
:
2480 ret
= qemu_read_default_config_files(userconfig
);
2486 /* second pass of option parsing */
2491 if (argv
[optind
][0] != '-') {
2492 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2494 const QEMUOption
*popt
;
2496 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2497 if (!(popt
->arch_mask
& arch_type
)) {
2498 printf("Option %s not supported for this target\n", popt
->name
);
2501 switch(popt
->index
) {
2503 machine
= machine_parse(optarg
);
2505 case QEMU_OPTION_cpu
:
2506 /* hw initialization will check this */
2509 case QEMU_OPTION_hda
:
2513 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
2515 snprintf(buf
, sizeof(buf
),
2516 "%s,cyls=%d,heads=%d,secs=%d%s",
2517 HD_OPTS
, cyls
, heads
, secs
,
2518 translation
== BIOS_ATA_TRANSLATION_LBA
?
2520 translation
== BIOS_ATA_TRANSLATION_NONE
?
2521 ",trans=none" : "");
2522 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
2525 case QEMU_OPTION_hdb
:
2526 case QEMU_OPTION_hdc
:
2527 case QEMU_OPTION_hdd
:
2528 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2531 case QEMU_OPTION_drive
:
2532 if (drive_def(optarg
) == NULL
) {
2536 case QEMU_OPTION_set
:
2537 if (qemu_set_option(optarg
) != 0)
2540 case QEMU_OPTION_global
:
2541 if (qemu_global_option(optarg
) != 0)
2544 case QEMU_OPTION_mtdblock
:
2545 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2547 case QEMU_OPTION_sd
:
2548 drive_add(IF_SD
, 0, optarg
, SD_OPTS
);
2550 case QEMU_OPTION_pflash
:
2551 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2553 case QEMU_OPTION_snapshot
:
2556 case QEMU_OPTION_hdachs
:
2560 cyls
= strtol(p
, (char **)&p
, 0);
2561 if (cyls
< 1 || cyls
> 16383)
2566 heads
= strtol(p
, (char **)&p
, 0);
2567 if (heads
< 1 || heads
> 16)
2572 secs
= strtol(p
, (char **)&p
, 0);
2573 if (secs
< 1 || secs
> 63)
2577 if (!strcmp(p
, "none"))
2578 translation
= BIOS_ATA_TRANSLATION_NONE
;
2579 else if (!strcmp(p
, "lba"))
2580 translation
= BIOS_ATA_TRANSLATION_LBA
;
2581 else if (!strcmp(p
, "auto"))
2582 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2585 } else if (*p
!= '\0') {
2587 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2590 if (hda_opts
!= NULL
) {
2592 snprintf(num
, sizeof(num
), "%d", cyls
);
2593 qemu_opt_set(hda_opts
, "cyls", num
);
2594 snprintf(num
, sizeof(num
), "%d", heads
);
2595 qemu_opt_set(hda_opts
, "heads", num
);
2596 snprintf(num
, sizeof(num
), "%d", secs
);
2597 qemu_opt_set(hda_opts
, "secs", num
);
2598 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2599 qemu_opt_set(hda_opts
, "trans", "lba");
2600 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2601 qemu_opt_set(hda_opts
, "trans", "none");
2605 case QEMU_OPTION_numa
:
2606 if (nb_numa_nodes
>= MAX_NODES
) {
2607 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2612 case QEMU_OPTION_display
:
2613 display_type
= select_display(optarg
);
2615 case QEMU_OPTION_nographic
:
2616 display_type
= DT_NOGRAPHIC
;
2618 case QEMU_OPTION_curses
:
2619 #ifdef CONFIG_CURSES
2620 display_type
= DT_CURSES
;
2622 fprintf(stderr
, "Curses support is disabled\n");
2626 case QEMU_OPTION_portrait
:
2627 graphic_rotate
= 90;
2629 case QEMU_OPTION_rotate
:
2630 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2631 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2632 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2634 "qemu: only 90, 180, 270 deg rotation is available\n");
2638 case QEMU_OPTION_kernel
:
2639 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
);
2641 case QEMU_OPTION_initrd
:
2642 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
);
2644 case QEMU_OPTION_append
:
2645 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
);
2647 case QEMU_OPTION_dtb
:
2648 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
);
2650 case QEMU_OPTION_cdrom
:
2651 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2653 case QEMU_OPTION_boot
:
2655 static const char * const params
[] = {
2656 "order", "once", "menu",
2657 "splash", "splash-time",
2658 "reboot-timeout", NULL
2660 char buf
[sizeof(boot_devices
)];
2661 char *standard_boot_devices
;
2664 if (!strchr(optarg
, '=')) {
2666 pstrcpy(buf
, sizeof(buf
), optarg
);
2667 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2669 "qemu: unknown boot parameter '%s' in '%s'\n",
2675 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2676 validate_bootdevices(buf
);
2677 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2680 if (get_param_value(buf
, sizeof(buf
),
2682 validate_bootdevices(buf
);
2683 standard_boot_devices
= g_strdup(boot_devices
);
2684 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2685 qemu_register_reset(restore_boot_devices
,
2686 standard_boot_devices
);
2688 if (get_param_value(buf
, sizeof(buf
),
2690 if (!strcmp(buf
, "on")) {
2692 } else if (!strcmp(buf
, "off")) {
2696 "qemu: invalid option value '%s'\n",
2701 qemu_opts_parse(qemu_find_opts("boot-opts"),
2706 case QEMU_OPTION_fda
:
2707 case QEMU_OPTION_fdb
:
2708 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2711 case QEMU_OPTION_no_fd_bootchk
:
2714 case QEMU_OPTION_netdev
:
2715 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2719 case QEMU_OPTION_net
:
2720 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2724 #ifdef CONFIG_LIBISCSI
2725 case QEMU_OPTION_iscsi
:
2726 opts
= qemu_opts_parse(qemu_find_opts("iscsi"), optarg
, 0);
2733 case QEMU_OPTION_tftp
:
2734 legacy_tftp_prefix
= optarg
;
2736 case QEMU_OPTION_bootp
:
2737 legacy_bootp_filename
= optarg
;
2739 case QEMU_OPTION_redir
:
2740 if (net_slirp_redir(optarg
) < 0)
2744 case QEMU_OPTION_bt
:
2745 add_device_config(DEV_BT
, optarg
);
2747 case QEMU_OPTION_audio_help
:
2748 if (!(audio_available())) {
2749 printf("Option %s not supported for this target\n", popt
->name
);
2755 case QEMU_OPTION_soundhw
:
2756 if (!(audio_available())) {
2757 printf("Option %s not supported for this target\n", popt
->name
);
2760 select_soundhw (optarg
);
2765 case QEMU_OPTION_version
:
2769 case QEMU_OPTION_m
: {
2774 value
= strtosz(optarg
, &end
);
2775 if (value
< 0 || *end
) {
2776 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2779 sz
= QEMU_ALIGN_UP((uint64_t)value
, 8192);
2781 if (ram_size
!= sz
) {
2782 fprintf(stderr
, "qemu: ram size too large\n");
2787 case QEMU_OPTION_mempath
:
2791 case QEMU_OPTION_mem_prealloc
:
2802 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
2804 case QEMU_OPTION_gdb
:
2805 add_device_config(DEV_GDB
, optarg
);
2810 case QEMU_OPTION_bios
:
2813 case QEMU_OPTION_singlestep
:
2820 keyboard_layout
= optarg
;
2822 case QEMU_OPTION_localtime
:
2825 case QEMU_OPTION_vga
:
2834 w
= strtol(p
, (char **)&p
, 10);
2837 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2843 h
= strtol(p
, (char **)&p
, 10);
2848 depth
= strtol(p
, (char **)&p
, 10);
2849 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2850 depth
!= 24 && depth
!= 32)
2852 } else if (*p
== '\0') {
2853 depth
= graphic_depth
;
2860 graphic_depth
= depth
;
2863 case QEMU_OPTION_echr
:
2866 term_escape_char
= strtol(optarg
, &r
, 0);
2868 printf("Bad argument to echr\n");
2871 case QEMU_OPTION_monitor
:
2872 monitor_parse(optarg
, "readline");
2873 default_monitor
= 0;
2875 case QEMU_OPTION_qmp
:
2876 monitor_parse(optarg
, "control");
2877 default_monitor
= 0;
2879 case QEMU_OPTION_mon
:
2880 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2884 default_monitor
= 0;
2886 case QEMU_OPTION_chardev
:
2887 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2892 case QEMU_OPTION_fsdev
:
2893 olist
= qemu_find_opts("fsdev");
2895 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2898 opts
= qemu_opts_parse(olist
, optarg
, 1);
2900 fprintf(stderr
, "parse error: %s\n", optarg
);
2904 case QEMU_OPTION_virtfs
: {
2907 const char *writeout
, *sock_fd
, *socket
;
2909 olist
= qemu_find_opts("virtfs");
2911 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2914 opts
= qemu_opts_parse(olist
, optarg
, 1);
2916 fprintf(stderr
, "parse error: %s\n", optarg
);
2920 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
2921 qemu_opt_get(opts
, "mount_tag") == NULL
) {
2922 fprintf(stderr
, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
2925 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
2926 qemu_opt_get(opts
, "mount_tag"),
2929 fprintf(stderr
, "duplicate fsdev id: %s\n",
2930 qemu_opt_get(opts
, "mount_tag"));
2934 writeout
= qemu_opt_get(opts
, "writeout");
2936 #ifdef CONFIG_SYNC_FILE_RANGE
2937 qemu_opt_set(fsdev
, "writeout", writeout
);
2939 fprintf(stderr
, "writeout=immediate not supported on "
2944 qemu_opt_set(fsdev
, "fsdriver", qemu_opt_get(opts
, "fsdriver"));
2945 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"));
2946 qemu_opt_set(fsdev
, "security_model",
2947 qemu_opt_get(opts
, "security_model"));
2948 socket
= qemu_opt_get(opts
, "socket");
2950 qemu_opt_set(fsdev
, "socket", socket
);
2952 sock_fd
= qemu_opt_get(opts
, "sock_fd");
2954 qemu_opt_set(fsdev
, "sock_fd", sock_fd
);
2957 qemu_opt_set_bool(fsdev
, "readonly",
2958 qemu_opt_get_bool(opts
, "readonly", 0));
2959 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2961 qemu_opt_set(device
, "driver", "virtio-9p-pci");
2962 qemu_opt_set(device
, "fsdev",
2963 qemu_opt_get(opts
, "mount_tag"));
2964 qemu_opt_set(device
, "mount_tag",
2965 qemu_opt_get(opts
, "mount_tag"));
2968 case QEMU_OPTION_virtfs_synth
: {
2972 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
2975 fprintf(stderr
, "duplicate option: %s\n", "virtfs_synth");
2978 qemu_opt_set(fsdev
, "fsdriver", "synth");
2980 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2982 qemu_opt_set(device
, "driver", "virtio-9p-pci");
2983 qemu_opt_set(device
, "fsdev", "v_synth");
2984 qemu_opt_set(device
, "mount_tag", "v_synth");
2987 case QEMU_OPTION_serial
:
2988 add_device_config(DEV_SERIAL
, optarg
);
2990 if (strncmp(optarg
, "mon:", 4) == 0) {
2991 default_monitor
= 0;
2994 case QEMU_OPTION_watchdog
:
2997 "qemu: only one watchdog option may be given\n");
3002 case QEMU_OPTION_watchdog_action
:
3003 if (select_watchdog_action(optarg
) == -1) {
3004 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
3008 case QEMU_OPTION_virtiocon
:
3009 add_device_config(DEV_VIRTCON
, optarg
);
3010 default_virtcon
= 0;
3011 if (strncmp(optarg
, "mon:", 4) == 0) {
3012 default_monitor
= 0;
3015 case QEMU_OPTION_parallel
:
3016 add_device_config(DEV_PARALLEL
, optarg
);
3017 default_parallel
= 0;
3018 if (strncmp(optarg
, "mon:", 4) == 0) {
3019 default_monitor
= 0;
3022 case QEMU_OPTION_debugcon
:
3023 add_device_config(DEV_DEBUGCON
, optarg
);
3025 case QEMU_OPTION_loadvm
:
3028 case QEMU_OPTION_full_screen
:
3032 case QEMU_OPTION_no_frame
:
3035 case QEMU_OPTION_alt_grab
:
3038 case QEMU_OPTION_ctrl_grab
:
3041 case QEMU_OPTION_no_quit
:
3044 case QEMU_OPTION_sdl
:
3045 display_type
= DT_SDL
;
3048 case QEMU_OPTION_no_frame
:
3049 case QEMU_OPTION_alt_grab
:
3050 case QEMU_OPTION_ctrl_grab
:
3051 case QEMU_OPTION_no_quit
:
3052 case QEMU_OPTION_sdl
:
3053 fprintf(stderr
, "SDL support is disabled\n");
3056 case QEMU_OPTION_pidfile
:
3059 case QEMU_OPTION_win2k_hack
:
3060 win2k_install_hack
= 1;
3062 case QEMU_OPTION_rtc_td_hack
: {
3063 static GlobalProperty slew_lost_ticks
[] = {
3065 .driver
= "mc146818rtc",
3066 .property
= "lost_tick_policy",
3069 { /* end of list */ }
3072 qdev_prop_register_global_list(slew_lost_ticks
);
3075 case QEMU_OPTION_acpitable
:
3076 do_acpitable_option(optarg
);
3078 case QEMU_OPTION_smbios
:
3079 do_smbios_option(optarg
);
3081 case QEMU_OPTION_enable_kvm
:
3082 olist
= qemu_find_opts("machine");
3083 qemu_opts_parse(olist
, "accel=kvm", 0);
3085 case QEMU_OPTION_machine
:
3086 olist
= qemu_find_opts("machine");
3087 opts
= qemu_opts_parse(olist
, optarg
, 1);
3089 fprintf(stderr
, "parse error: %s\n", optarg
);
3092 optarg
= qemu_opt_get(opts
, "type");
3094 machine
= machine_parse(optarg
);
3097 case QEMU_OPTION_usb
:
3098 machine_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
3100 qemu_opt_set_bool(machine_opts
, "usb", true);
3103 case QEMU_OPTION_usbdevice
:
3104 machine_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
3106 qemu_opt_set_bool(machine_opts
, "usb", true);
3108 add_device_config(DEV_USB
, optarg
);
3110 case QEMU_OPTION_device
:
3111 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
3115 case QEMU_OPTION_smp
:
3118 fprintf(stderr
, "Invalid number of CPUs\n");
3121 if (max_cpus
< smp_cpus
) {
3122 fprintf(stderr
, "maxcpus must be equal to or greater than "
3126 if (max_cpus
> 255) {
3127 fprintf(stderr
, "Unsupported number of maxcpus\n");
3131 case QEMU_OPTION_vnc
:
3134 vnc_display
= optarg
;
3136 fprintf(stderr
, "VNC support is disabled\n");
3140 case QEMU_OPTION_no_acpi
:
3143 case QEMU_OPTION_no_hpet
:
3146 case QEMU_OPTION_balloon
:
3147 if (balloon_parse(optarg
) < 0) {
3148 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
3152 case QEMU_OPTION_no_reboot
:
3155 case QEMU_OPTION_no_shutdown
:
3158 case QEMU_OPTION_show_cursor
:
3161 case QEMU_OPTION_uuid
:
3162 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
3163 fprintf(stderr
, "Fail to parse UUID string."
3164 " Wrong format.\n");
3168 case QEMU_OPTION_option_rom
:
3169 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3170 fprintf(stderr
, "Too many option ROMs\n");
3173 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
3174 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3175 option_rom
[nb_option_roms
].bootindex
=
3176 qemu_opt_get_number(opts
, "bootindex", -1);
3177 if (!option_rom
[nb_option_roms
].name
) {
3178 fprintf(stderr
, "Option ROM file is not specified\n");
3183 case QEMU_OPTION_semihosting
:
3184 semihosting_enabled
= 1;
3186 case QEMU_OPTION_name
:
3187 qemu_name
= g_strdup(optarg
);
3189 char *p
= strchr(qemu_name
, ',');
3192 if (strncmp(p
, "process=", 8)) {
3193 fprintf(stderr
, "Unknown subargument %s to -name\n", p
);
3197 os_set_proc_name(p
);
3201 case QEMU_OPTION_prom_env
:
3202 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3203 fprintf(stderr
, "Too many prom variables\n");
3206 prom_envs
[nb_prom_envs
] = optarg
;
3209 case QEMU_OPTION_old_param
:
3212 case QEMU_OPTION_clock
:
3213 configure_alarms(optarg
);
3215 case QEMU_OPTION_startdate
:
3216 configure_rtc_date_offset(optarg
, 1);
3218 case QEMU_OPTION_rtc
:
3219 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
3223 configure_rtc(opts
);
3225 case QEMU_OPTION_tb_size
:
3226 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3227 if (tcg_tb_size
< 0) {
3231 case QEMU_OPTION_icount
:
3232 icount_option
= optarg
;
3234 case QEMU_OPTION_incoming
:
3236 runstate_set(RUN_STATE_INMIGRATE
);
3238 case QEMU_OPTION_nodefaults
:
3240 default_parallel
= 0;
3241 default_virtcon
= 0;
3242 default_monitor
= 0;
3249 case QEMU_OPTION_xen_domid
:
3250 if (!(xen_available())) {
3251 printf("Option %s not supported for this target\n", popt
->name
);
3254 xen_domid
= atoi(optarg
);
3256 case QEMU_OPTION_xen_create
:
3257 if (!(xen_available())) {
3258 printf("Option %s not supported for this target\n", popt
->name
);
3261 xen_mode
= XEN_CREATE
;
3263 case QEMU_OPTION_xen_attach
:
3264 if (!(xen_available())) {
3265 printf("Option %s not supported for this target\n", popt
->name
);
3268 xen_mode
= XEN_ATTACH
;
3270 case QEMU_OPTION_trace
:
3272 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
3276 trace_events
= qemu_opt_get(opts
, "events");
3277 trace_file
= qemu_opt_get(opts
, "file");
3280 case QEMU_OPTION_readconfig
:
3282 int ret
= qemu_read_config_file(optarg
);
3284 fprintf(stderr
, "read config %s: %s\n", optarg
,
3290 case QEMU_OPTION_spice
:
3291 olist
= qemu_find_opts("spice");
3293 fprintf(stderr
, "spice is not supported by this qemu build.\n");
3296 opts
= qemu_opts_parse(olist
, optarg
, 0);
3298 fprintf(stderr
, "parse error: %s\n", optarg
);
3302 case QEMU_OPTION_writeconfig
:
3305 if (strcmp(optarg
, "-") == 0) {
3308 fp
= fopen(optarg
, "w");
3310 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
3314 qemu_config_write(fp
);
3318 case QEMU_OPTION_qtest
:
3319 qtest_chrdev
= optarg
;
3321 case QEMU_OPTION_qtest_log
:
3324 case QEMU_OPTION_sandbox
:
3325 opts
= qemu_opts_parse(qemu_find_opts("sandbox"), optarg
, 1);
3331 os_parse_cmd_args(popt
->index
, optarg
);
3337 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox
, NULL
, 0)) {
3341 if (machine
== NULL
) {
3342 fprintf(stderr
, "No machine found.\n");
3346 if (machine
->hw_version
) {
3347 qemu_set_version(machine
->hw_version
);
3350 /* Init CPU def lists, based on config
3351 * - Must be called after all the qemu_read_config_file() calls
3352 * - Must be called before list_cpus()
3353 * - Must be called before machine->init()
3357 if (cpu_model
&& is_help_option(cpu_model
)) {
3358 list_cpus(stdout
, &fprintf
, cpu_model
);
3362 /* Open the logfile at this point, if necessary. We can't open the logfile
3363 * when encountering either of the logging options (-d or -D) because the
3364 * other one may be encountered later on the command line, changing the
3365 * location or level of logging.
3369 set_cpu_log_filename(log_file
);
3371 set_cpu_log(log_mask
);
3374 if (!trace_backend_init(trace_events
, trace_file
)) {
3378 /* If no data_dir is specified then try to find it relative to the
3381 data_dir
= os_find_datadir(argv
[0]);
3383 /* If all else fails use the install path specified when building. */
3385 data_dir
= CONFIG_QEMU_DATADIR
;
3389 * Default to max_cpus = smp_cpus, in case the user doesn't
3390 * specify a max_cpus value.
3393 max_cpus
= smp_cpus
;
3395 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
3396 if (smp_cpus
> machine
->max_cpus
) {
3397 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
3398 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
3404 * Get the default machine options from the machine if it is not already
3405 * specified either by the configuration file or by the command line.
3407 if (machine
->default_machine_opts
) {
3408 qemu_opts_set_defaults(qemu_find_opts("machine"),
3409 machine
->default_machine_opts
, 0);
3412 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
3413 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
3415 if (machine
->no_serial
) {
3418 if (machine
->no_parallel
) {
3419 default_parallel
= 0;
3421 if (!machine
->use_virtcon
) {
3422 default_virtcon
= 0;
3424 if (machine
->no_floppy
) {
3427 if (machine
->no_cdrom
) {
3430 if (machine
->no_sdcard
) {
3434 if (display_type
== DT_NOGRAPHIC
) {
3435 if (default_parallel
)
3436 add_device_config(DEV_PARALLEL
, "null");
3437 if (default_serial
&& default_monitor
) {
3438 add_device_config(DEV_SERIAL
, "mon:stdio");
3439 } else if (default_virtcon
&& default_monitor
) {
3440 add_device_config(DEV_VIRTCON
, "mon:stdio");
3443 add_device_config(DEV_SERIAL
, "stdio");
3444 if (default_virtcon
)
3445 add_device_config(DEV_VIRTCON
, "stdio");
3446 if (default_monitor
)
3447 monitor_parse("stdio", "readline");
3451 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
3452 if (default_parallel
)
3453 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
3454 if (default_monitor
)
3455 monitor_parse("vc:80Cx24C", "readline");
3456 if (default_virtcon
)
3457 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
3462 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
3464 #ifdef CONFIG_VIRTFS
3465 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
3472 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
3477 /* init the memory */
3478 if (ram_size
== 0) {
3479 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
3482 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0)
3487 configure_accelerator();
3489 qemu_init_cpu_loop();
3490 if (qemu_init_main_loop()) {
3491 fprintf(stderr
, "qemu_init_main_loop failed\n");
3495 machine_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
3497 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
3498 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
3499 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
3501 kernel_filename
= initrd_filename
= kernel_cmdline
= NULL
;
3504 if (!kernel_cmdline
) {
3505 kernel_cmdline
= "";
3508 linux_boot
= (kernel_filename
!= NULL
);
3510 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
3511 fprintf(stderr
, "-append only allowed with -kernel option\n");
3515 if (!linux_boot
&& initrd_filename
!= NULL
) {
3516 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
3520 if (!linux_boot
&& machine_opts
&& qemu_opt_get(machine_opts
, "dtb")) {
3521 fprintf(stderr
, "-dtb only allowed with -kernel option\n");
3525 os_set_line_buffering();
3527 if (init_timer_alarm() < 0) {
3528 fprintf(stderr
, "could not initialize alarm timer\n");
3533 /* spice needs the timers to be initialized by this point */
3537 if (icount_option
&& (kvm_enabled() || xen_enabled())) {
3538 fprintf(stderr
, "-icount is not allowed with kvm or xen\n");
3541 configure_icount(icount_option
);
3543 if (net_init_clients() < 0) {
3547 /* init the bluetooth world */
3548 if (foreach_device_config(DEV_BT
, bt_parse
))
3551 if (!xen_enabled()) {
3552 /* On 32-bit hosts, QEMU is limited by virtual address space */
3553 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
3554 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
3559 cpu_exec_init_all();
3561 bdrv_init_with_whitelist();
3565 /* open the virtual block devices */
3567 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
3568 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
3571 default_drive(default_cdrom
, snapshot
, machine
->use_scsi
,
3572 IF_DEFAULT
, 2, CDROM_OPTS
);
3573 default_drive(default_floppy
, snapshot
, machine
->use_scsi
,
3574 IF_FLOPPY
, 0, FD_OPTS
);
3575 default_drive(default_sdcard
, snapshot
, machine
->use_scsi
,
3578 register_savevm_live(NULL
, "ram", 0, 4, &savevm_ram_handlers
, NULL
);
3580 if (nb_numa_nodes
> 0) {
3583 if (nb_numa_nodes
> MAX_NODES
) {
3584 nb_numa_nodes
= MAX_NODES
;
3587 /* If no memory size if given for any node, assume the default case
3588 * and distribute the available memory equally across all nodes
3590 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3591 if (node_mem
[i
] != 0)
3594 if (i
== nb_numa_nodes
) {
3595 uint64_t usedmem
= 0;
3597 /* On Linux, the each node's border has to be 8MB aligned,
3598 * the final node gets the rest.
3600 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
3601 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
3602 usedmem
+= node_mem
[i
];
3604 node_mem
[i
] = ram_size
- usedmem
;
3607 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3608 if (!bitmap_empty(node_cpumask
[i
], MAX_CPUMASK_BITS
)) {
3612 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3613 * must cope with this anyway, because there are BIOSes out there in
3614 * real machines which also use this scheme.
3616 if (i
== nb_numa_nodes
) {
3617 for (i
= 0; i
< max_cpus
; i
++) {
3618 set_bit(i
, node_cpumask
[i
% nb_numa_nodes
]);
3623 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
3627 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
3629 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
3631 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
3633 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
3636 /* If no default VGA is requested, the default is "none". */
3638 if (cirrus_vga_available()) {
3639 vga_model
= "cirrus";
3640 } else if (vga_available()) {
3644 select_vgahw(vga_model
);
3647 i
= select_watchdog(watchdog
);
3649 exit (i
== 1 ? 1 : 0);
3652 if (machine
->compat_props
) {
3653 qdev_prop_register_global_list(machine
->compat_props
);
3657 qdev_machine_init();
3659 QEMUMachineInitArgs args
= { .ram_size
= ram_size
,
3660 .boot_device
= boot_devices
,
3661 .kernel_filename
= kernel_filename
,
3662 .kernel_cmdline
= kernel_cmdline
,
3663 .initrd_filename
= initrd_filename
,
3664 .cpu_model
= cpu_model
};
3665 machine
->init(&args
);
3667 cpu_synchronize_all_post_init();
3671 current_machine
= machine
;
3673 /* init USB devices */
3674 if (usb_enabled(false)) {
3675 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
3679 /* init generic devices */
3680 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3683 net_check_clients();
3685 /* just use the first displaystate for the moment */
3686 ds
= get_displaystate();
3690 if (display_type
== DT_DEFAULT
&& !display_remote
) {
3691 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3692 display_type
= DT_SDL
;
3693 #elif defined(CONFIG_VNC)
3694 vnc_display
= "localhost:0,to=99";
3697 display_type
= DT_NONE
;
3702 /* init local displays */
3703 switch (display_type
) {
3706 #if defined(CONFIG_CURSES)
3708 if (!is_daemonized()) {
3709 curses_display_init(ds
, full_screen
);
3713 #if defined(CONFIG_SDL)
3715 sdl_display_init(ds
, full_screen
, no_frame
);
3717 #elif defined(CONFIG_COCOA)
3719 cocoa_display_init(ds
, full_screen
);
3726 /* must be after terminal init, SDL library changes signal handlers */
3727 os_setup_signal_handling();
3730 /* init remote displays */
3732 Error
*local_err
= NULL
;
3733 vnc_display_init(ds
);
3734 vnc_display_open(ds
, vnc_display
, &local_err
);
3735 if (local_err
!= NULL
) {
3736 fprintf(stderr
, "Failed to start VNC server on `%s': %s\n",
3737 vnc_display
, error_get_pretty(local_err
));
3738 error_free(local_err
);
3742 if (show_vnc_port
) {
3743 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3748 if (using_spice
&& !qxl_enabled
) {
3749 qemu_spice_display_init(ds
);
3755 dcl
= ds
->listeners
;
3756 while (dcl
!= NULL
) {
3757 if (dcl
->dpy_refresh
!= NULL
) {
3758 ds
->gui_timer
= qemu_new_timer_ms(rt_clock
, gui_update
, ds
);
3759 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock_ms(rt_clock
));
3764 text_consoles_set_display(ds
);
3766 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
3770 qdev_machine_creation_done();
3772 if (rom_load_all() != 0) {
3773 fprintf(stderr
, "rom loading failed\n");
3777 /* TODO: once all bus devices are qdevified, this should be done
3778 * when bus is created by qdev.c */
3779 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
3780 qemu_run_machine_init_done_notifiers();
3782 qemu_system_reset(VMRESET_SILENT
);
3784 if (load_vmstate(loadvm
) < 0) {
3790 Error
*local_err
= NULL
;
3791 qemu_start_incoming_migration(incoming
, &local_err
);
3793 fprintf(stderr
, "-incoming %s: %s\n", incoming
, error_get_pretty(local_err
));
3794 error_free(local_err
);
3797 } else if (autostart
) {