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 int vga_cga_hacks
= 0;
183 DisplayType display_type
= DT_DEFAULT
;
184 int display_remote
= 0;
185 const char* keyboard_layout
= NULL
;
187 const char *mem_path
= NULL
;
189 int mem_prealloc
= 0; /* force preallocation of physical target memory */
192 NICInfo nd_table
[MAX_NICS
];
194 static int rtc_utc
= 1;
195 static int rtc_date_offset
= -1; /* -1 means no change */
196 QEMUClock
*rtc_clock
;
197 int vga_interface_type
= VGA_NONE
;
198 static int full_screen
= 0;
200 static int no_frame
= 0;
203 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
204 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
205 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
206 int win2k_install_hack
= 0;
214 const char *vnc_display
;
216 int acpi_enabled
= 1;
222 int graphic_rotate
= 0;
223 const char *watchdog
;
224 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
226 int semihosting_enabled
= 0;
228 const char *qemu_name
;
231 unsigned int nb_prom_envs
= 0;
232 const char *prom_envs
[MAX_PROM_ENVS
];
234 uint8_t *boot_splash_filedata
;
235 int boot_splash_filedata_size
;
236 uint8_t qemu_extra_params_fw
[2];
238 typedef struct FWBootEntry FWBootEntry
;
241 QTAILQ_ENTRY(FWBootEntry
) link
;
247 QTAILQ_HEAD(, FWBootEntry
) fw_boot_order
= QTAILQ_HEAD_INITIALIZER(fw_boot_order
);
250 uint64_t node_mem
[MAX_NODES
];
251 unsigned long *node_cpumask
[MAX_NODES
];
253 uint8_t qemu_uuid
[16];
255 static QEMUBootSetHandler
*boot_set_handler
;
256 static void *boot_set_opaque
;
258 static NotifierList exit_notifiers
=
259 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
261 static NotifierList machine_init_done_notifiers
=
262 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
264 static int tcg_allowed
= 1;
268 enum xen_mode xen_mode
= XEN_EMULATE
;
269 static int tcg_tb_size
;
271 static int default_serial
= 1;
272 static int default_parallel
= 1;
273 static int default_virtcon
= 1;
274 static int default_monitor
= 1;
275 static int default_floppy
= 1;
276 static int default_cdrom
= 1;
277 static int default_sdcard
= 1;
278 static int default_vga
= 1;
284 { .driver
= "isa-serial", .flag
= &default_serial
},
285 { .driver
= "isa-parallel", .flag
= &default_parallel
},
286 { .driver
= "isa-fdc", .flag
= &default_floppy
},
287 { .driver
= "ide-cd", .flag
= &default_cdrom
},
288 { .driver
= "ide-hd", .flag
= &default_cdrom
},
289 { .driver
= "ide-drive", .flag
= &default_cdrom
},
290 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
291 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
292 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
293 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
294 { .driver
= "VGA", .flag
= &default_vga
},
295 { .driver
= "isa-vga", .flag
= &default_vga
},
296 { .driver
= "cirrus-vga", .flag
= &default_vga
},
297 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
298 { .driver
= "vmware-svga", .flag
= &default_vga
},
299 { .driver
= "qxl-vga", .flag
= &default_vga
},
302 const char *qemu_get_vm_name(void)
307 static void res_free(void)
309 if (boot_splash_filedata
!= NULL
) {
310 g_free(boot_splash_filedata
);
311 boot_splash_filedata
= NULL
;
315 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
317 const char *driver
= qemu_opt_get(opts
, "driver");
322 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
323 if (strcmp(default_list
[i
].driver
, driver
) != 0)
325 *(default_list
[i
].flag
) = 0;
330 /***********************************************************/
333 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
338 } RunStateTransition
;
340 static const RunStateTransition runstate_transitions_def
[] = {
342 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
344 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
345 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
347 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
348 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
350 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
351 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
353 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
354 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
356 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
357 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
359 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
360 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
361 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
363 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
364 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
366 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
368 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
369 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
370 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
371 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
372 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
373 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
374 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
375 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
376 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
378 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
380 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
381 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
383 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
384 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
385 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
386 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
388 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
389 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
391 { RUN_STATE_MAX
, RUN_STATE_MAX
},
394 static bool runstate_valid_transitions
[RUN_STATE_MAX
][RUN_STATE_MAX
];
396 bool runstate_check(RunState state
)
398 return current_run_state
== state
;
401 void runstate_init(void)
403 const RunStateTransition
*p
;
405 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
407 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE_MAX
; p
++) {
408 runstate_valid_transitions
[p
->from
][p
->to
] = true;
412 /* This function will abort() on invalid state transitions */
413 void runstate_set(RunState new_state
)
415 assert(new_state
< RUN_STATE_MAX
);
417 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
418 fprintf(stderr
, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
419 RunState_lookup
[current_run_state
],
420 RunState_lookup
[new_state
]);
424 current_run_state
= new_state
;
427 int runstate_is_running(void)
429 return runstate_check(RUN_STATE_RUNNING
);
432 StatusInfo
*qmp_query_status(Error
**errp
)
434 StatusInfo
*info
= g_malloc0(sizeof(*info
));
436 info
->running
= runstate_is_running();
437 info
->singlestep
= singlestep
;
438 info
->status
= current_run_state
;
443 /***********************************************************/
444 /* real time host monotonic timer */
446 /***********************************************************/
447 /* host time/date access */
448 void qemu_get_timedate(struct tm
*tm
, int offset
)
455 if (rtc_date_offset
== -1) {
459 ret
= localtime(&ti
);
461 ti
-= rtc_date_offset
;
465 memcpy(tm
, ret
, sizeof(struct tm
));
468 int qemu_timedate_diff(struct tm
*tm
)
472 if (rtc_date_offset
== -1)
474 seconds
= mktimegm(tm
);
477 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
478 seconds
= mktime(&tmp
);
481 seconds
= mktimegm(tm
) + rtc_date_offset
;
483 return seconds
- time(NULL
);
486 void rtc_change_mon_event(struct tm
*tm
)
490 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
491 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
492 qobject_decref(data
);
495 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
497 time_t rtc_start_date
;
500 if (!strcmp(startdate
, "now") && legacy
) {
501 rtc_date_offset
= -1;
503 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
511 } else if (sscanf(startdate
, "%d-%d-%d",
523 rtc_start_date
= mktimegm(&tm
);
524 if (rtc_start_date
== -1) {
526 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
527 "'2006-06-17T16:01:21' or '2006-06-17'\n");
530 rtc_date_offset
= time(NULL
) - rtc_start_date
;
534 static void configure_rtc(QemuOpts
*opts
)
538 value
= qemu_opt_get(opts
, "base");
540 if (!strcmp(value
, "utc")) {
542 } else if (!strcmp(value
, "localtime")) {
545 configure_rtc_date_offset(value
, 0);
548 value
= qemu_opt_get(opts
, "clock");
550 if (!strcmp(value
, "host")) {
551 rtc_clock
= host_clock
;
552 } else if (!strcmp(value
, "rt")) {
553 rtc_clock
= rt_clock
;
554 } else if (!strcmp(value
, "vm")) {
555 rtc_clock
= vm_clock
;
557 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
561 value
= qemu_opt_get(opts
, "driftfix");
563 if (!strcmp(value
, "slew")) {
564 static GlobalProperty slew_lost_ticks
[] = {
566 .driver
= "mc146818rtc",
567 .property
= "lost_tick_policy",
570 { /* end of list */ }
573 qdev_prop_register_global_list(slew_lost_ticks
);
574 } else if (!strcmp(value
, "none")) {
575 /* discard is default */
577 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
583 /***********************************************************/
584 /* Bluetooth support */
587 static struct HCIInfo
*hci_table
[MAX_NICS
];
589 static struct bt_vlan_s
{
590 struct bt_scatternet_s net
;
592 struct bt_vlan_s
*next
;
595 /* find or alloc a new bluetooth "VLAN" */
596 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
598 struct bt_vlan_s
**pvlan
, *vlan
;
599 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
603 vlan
= g_malloc0(sizeof(struct bt_vlan_s
));
605 pvlan
= &first_bt_vlan
;
606 while (*pvlan
!= NULL
)
607 pvlan
= &(*pvlan
)->next
;
612 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
616 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
621 static struct HCIInfo null_hci
= {
622 .cmd_send
= null_hci_send
,
623 .sco_send
= null_hci_send
,
624 .acl_send
= null_hci_send
,
625 .bdaddr_set
= null_hci_addr_set
,
628 struct HCIInfo
*qemu_next_hci(void)
630 if (cur_hci
== nb_hcis
)
633 return hci_table
[cur_hci
++];
636 static struct HCIInfo
*hci_init(const char *str
)
639 struct bt_scatternet_s
*vlan
= 0;
641 if (!strcmp(str
, "null"))
644 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
646 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
647 else if (!strncmp(str
, "hci", 3)) {
650 if (!strncmp(str
+ 3, ",vlan=", 6)) {
651 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
656 vlan
= qemu_find_bt_vlan(0);
658 return bt_new_hci(vlan
);
661 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
666 static int bt_hci_parse(const char *str
)
671 if (nb_hcis
>= MAX_NICS
) {
672 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
685 bdaddr
.b
[5] = 0x56 + nb_hcis
;
686 hci
->bdaddr_set(hci
, bdaddr
.b
);
688 hci_table
[nb_hcis
++] = hci
;
693 static void bt_vhci_add(int vlan_id
)
695 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
698 fprintf(stderr
, "qemu: warning: adding a VHCI to "
699 "an empty scatternet %i\n", vlan_id
);
701 bt_vhci_init(bt_new_hci(vlan
));
704 static struct bt_device_s
*bt_device_add(const char *opt
)
706 struct bt_scatternet_s
*vlan
;
708 char *endp
= strstr(opt
, ",vlan=");
709 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
712 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
715 vlan_id
= strtol(endp
+ 6, &endp
, 0);
717 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
722 vlan
= qemu_find_bt_vlan(vlan_id
);
725 fprintf(stderr
, "qemu: warning: adding a slave device to "
726 "an empty scatternet %i\n", vlan_id
);
728 if (!strcmp(devname
, "keyboard"))
729 return bt_keyboard_init(vlan
);
731 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
735 static int bt_parse(const char *opt
)
737 const char *endp
, *p
;
740 if (strstart(opt
, "hci", &endp
)) {
741 if (!*endp
|| *endp
== ',') {
743 if (!strstart(endp
, ",vlan=", 0))
746 return bt_hci_parse(opt
);
748 } else if (strstart(opt
, "vhci", &endp
)) {
749 if (!*endp
|| *endp
== ',') {
751 if (strstart(endp
, ",vlan=", &p
)) {
752 vlan
= strtol(p
, (char **) &endp
, 0);
754 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
758 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
767 } else if (strstart(opt
, "device:", &endp
))
768 return !bt_device_add(endp
);
770 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
774 static int parse_sandbox(QemuOpts
*opts
, void *opaque
)
776 /* FIXME: change this to true for 1.3 */
777 if (qemu_opt_get_bool(opts
, "enable", false)) {
778 #ifdef CONFIG_SECCOMP
779 if (seccomp_start() < 0) {
780 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
781 "failed to install seccomp syscall filter in the kernel");
785 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
786 "sandboxing request but seccomp is not compiled into this build");
794 /***********************************************************/
795 /* QEMU Block devices */
797 #define HD_OPTS "media=disk"
798 #define CDROM_OPTS "media=cdrom"
800 #define PFLASH_OPTS ""
804 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
806 int *use_scsi
= opaque
;
808 return drive_init(opts
, *use_scsi
) == NULL
;
811 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
813 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
814 qemu_opt_set(opts
, "snapshot", "on");
819 static void default_drive(int enable
, int snapshot
, int use_scsi
,
820 BlockInterfaceType type
, int index
,
825 if (type
== IF_DEFAULT
) {
826 type
= use_scsi
? IF_SCSI
: IF_IDE
;
829 if (!enable
|| drive_get_by_index(type
, index
)) {
833 opts
= drive_add(type
, index
, NULL
, optstr
);
835 drive_enable_snapshot(opts
, NULL
);
837 if (!drive_init(opts
, use_scsi
)) {
842 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
844 boot_set_handler
= func
;
845 boot_set_opaque
= opaque
;
848 int qemu_boot_set(const char *boot_devices
)
850 if (!boot_set_handler
) {
853 return boot_set_handler(boot_set_opaque
, boot_devices
);
856 static void validate_bootdevices(char *devices
)
858 /* We just do some generic consistency checks */
862 for (p
= devices
; *p
!= '\0'; p
++) {
863 /* Allowed boot devices are:
864 * a-b: floppy disk drives
865 * c-f: IDE disk drives
866 * g-m: machine implementation dependent drives
867 * n-p: network devices
868 * It's up to each machine implementation to check if the given boot
869 * devices match the actual hardware implementation and firmware
872 if (*p
< 'a' || *p
> 'p') {
873 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
876 if (bitmap
& (1 << (*p
- 'a'))) {
877 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
880 bitmap
|= 1 << (*p
- 'a');
884 static void restore_boot_devices(void *opaque
)
886 char *standard_boot_devices
= opaque
;
887 static int first
= 1;
889 /* Restore boot order and remove ourselves after the first boot */
895 qemu_boot_set(standard_boot_devices
);
897 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
898 g_free(standard_boot_devices
);
901 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
904 FWBootEntry
*node
, *i
;
910 assert(dev
!= NULL
|| suffix
!= NULL
);
912 node
= g_malloc0(sizeof(FWBootEntry
));
913 node
->bootindex
= bootindex
;
914 node
->suffix
= suffix
? g_strdup(suffix
) : NULL
;
917 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
918 if (i
->bootindex
== bootindex
) {
919 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
921 } else if (i
->bootindex
< bootindex
) {
924 QTAILQ_INSERT_BEFORE(i
, node
, link
);
927 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
931 * This function returns null terminated string that consist of new line
932 * separated device paths.
934 * memory pointed by "size" is assigned total length of the array in bytes
937 char *get_boot_devices_list(uint32_t *size
)
943 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
944 char *devpath
= NULL
, *bootpath
;
948 devpath
= qdev_get_fw_dev_path(i
->dev
);
952 if (i
->suffix
&& devpath
) {
953 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
955 bootpath
= g_malloc(bootpathlen
);
956 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
958 } else if (devpath
) {
962 bootpath
= g_strdup(i
->suffix
);
966 list
[total
-1] = '\n';
968 len
= strlen(bootpath
) + 1;
969 list
= g_realloc(list
, total
+ len
);
970 memcpy(&list
[total
], bootpath
, len
);
980 static void numa_add(const char *optarg
)
984 unsigned long long value
, endvalue
;
987 value
= endvalue
= 0ULL;
989 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
990 if (!strcmp(option
, "node")) {
991 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
992 nodenr
= nb_numa_nodes
;
994 nodenr
= strtoull(option
, NULL
, 10);
997 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
998 node_mem
[nodenr
] = 0;
1001 sval
= strtosz(option
, &endptr
);
1002 if (sval
< 0 || *endptr
) {
1003 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
1006 node_mem
[nodenr
] = sval
;
1008 if (get_param_value(option
, 128, "cpus", optarg
) != 0) {
1009 value
= strtoull(option
, &endptr
, 10);
1010 if (*endptr
== '-') {
1011 endvalue
= strtoull(endptr
+1, &endptr
, 10);
1016 if (!(endvalue
< MAX_CPUMASK_BITS
)) {
1017 endvalue
= MAX_CPUMASK_BITS
- 1;
1019 "A max of %d CPUs are supported in a guest\n",
1023 bitmap_set(node_cpumask
[nodenr
], value
, endvalue
-value
+1);
1030 static void smp_parse(const char *optarg
)
1032 int smp
, sockets
= 0, threads
= 0, cores
= 0;
1036 smp
= strtoul(optarg
, &endptr
, 10);
1037 if (endptr
!= optarg
) {
1038 if (*endptr
== ',') {
1042 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
1043 sockets
= strtoull(option
, NULL
, 10);
1044 if (get_param_value(option
, 128, "cores", endptr
) != 0)
1045 cores
= strtoull(option
, NULL
, 10);
1046 if (get_param_value(option
, 128, "threads", endptr
) != 0)
1047 threads
= strtoull(option
, NULL
, 10);
1048 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
1049 max_cpus
= strtoull(option
, NULL
, 10);
1051 /* compute missing values, prefer sockets over cores over threads */
1052 if (smp
== 0 || sockets
== 0) {
1053 sockets
= sockets
> 0 ? sockets
: 1;
1054 cores
= cores
> 0 ? cores
: 1;
1055 threads
= threads
> 0 ? threads
: 1;
1057 smp
= cores
* threads
* sockets
;
1061 threads
= threads
> 0 ? threads
: 1;
1062 cores
= smp
/ (sockets
* threads
);
1064 threads
= smp
/ (cores
* sockets
);
1068 smp_cores
= cores
> 0 ? cores
: 1;
1069 smp_threads
= threads
> 0 ? threads
: 1;
1071 max_cpus
= smp_cpus
;
1074 /***********************************************************/
1077 static int usb_device_add(const char *devname
)
1080 USBDevice
*dev
= NULL
;
1085 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1086 dev
= usbdevice_create(devname
);
1090 /* the other ones */
1091 #ifndef CONFIG_LINUX
1092 /* only the linux version is qdev-ified, usb-bsd still needs this */
1093 if (strstart(devname
, "host:", &p
)) {
1094 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1097 if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
1098 dev
= usb_bt_init(usb_bus_find(-1),
1099 devname
[2] ? hci_init(p
)
1100 : bt_new_hci(qemu_find_bt_vlan(0)));
1111 static int usb_device_del(const char *devname
)
1116 if (strstart(devname
, "host:", &p
))
1117 return usb_host_device_close(p
);
1122 p
= strchr(devname
, '.');
1125 bus_num
= strtoul(devname
, NULL
, 0);
1126 addr
= strtoul(p
+ 1, NULL
, 0);
1128 return usb_device_delete_addr(bus_num
, addr
);
1131 static int usb_parse(const char *cmdline
)
1134 r
= usb_device_add(cmdline
);
1136 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
1141 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
1143 const char *devname
= qdict_get_str(qdict
, "devname");
1144 if (usb_device_add(devname
) < 0) {
1145 error_report("could not add USB device '%s'", devname
);
1149 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
1151 const char *devname
= qdict_get_str(qdict
, "devname");
1152 if (usb_device_del(devname
) < 0) {
1153 error_report("could not delete USB device '%s'", devname
);
1157 /***********************************************************/
1158 /* PCMCIA/Cardbus */
1160 static struct pcmcia_socket_entry_s
{
1161 PCMCIASocket
*socket
;
1162 struct pcmcia_socket_entry_s
*next
;
1163 } *pcmcia_sockets
= 0;
1165 void pcmcia_socket_register(PCMCIASocket
*socket
)
1167 struct pcmcia_socket_entry_s
*entry
;
1169 entry
= g_malloc(sizeof(struct pcmcia_socket_entry_s
));
1170 entry
->socket
= socket
;
1171 entry
->next
= pcmcia_sockets
;
1172 pcmcia_sockets
= entry
;
1175 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
1177 struct pcmcia_socket_entry_s
*entry
, **ptr
;
1179 ptr
= &pcmcia_sockets
;
1180 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
1181 if (entry
->socket
== socket
) {
1187 void pcmcia_info(Monitor
*mon
)
1189 struct pcmcia_socket_entry_s
*iter
;
1191 if (!pcmcia_sockets
)
1192 monitor_printf(mon
, "No PCMCIA sockets\n");
1194 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1195 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1196 iter
->socket
->attached
? iter
->socket
->card_string
:
1200 /***********************************************************/
1201 /* machine registration */
1203 static QEMUMachine
*first_machine
= NULL
;
1204 QEMUMachine
*current_machine
= NULL
;
1206 int qemu_register_machine(QEMUMachine
*m
)
1209 pm
= &first_machine
;
1217 static QEMUMachine
*find_machine(const char *name
)
1221 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1222 if (!strcmp(m
->name
, name
))
1224 if (m
->alias
&& !strcmp(m
->alias
, name
))
1230 QEMUMachine
*find_default_machine(void)
1234 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1235 if (m
->is_default
) {
1242 MachineInfoList
*qmp_query_machines(Error
**errp
)
1244 MachineInfoList
*mach_list
= NULL
;
1247 for (m
= first_machine
; m
; m
= m
->next
) {
1248 MachineInfoList
*entry
;
1251 info
= g_malloc0(sizeof(*info
));
1252 if (m
->is_default
) {
1253 info
->has_is_default
= true;
1254 info
->is_default
= true;
1258 info
->has_alias
= true;
1259 info
->alias
= g_strdup(m
->alias
);
1262 info
->name
= g_strdup(m
->name
);
1264 entry
= g_malloc0(sizeof(*entry
));
1265 entry
->value
= info
;
1266 entry
->next
= mach_list
;
1273 /***********************************************************/
1274 /* main execution loop */
1276 static void gui_update(void *opaque
)
1278 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1279 DisplayState
*ds
= opaque
;
1280 DisplayChangeListener
*dcl
= ds
->listeners
;
1284 while (dcl
!= NULL
) {
1285 if (dcl
->gui_timer_interval
&&
1286 dcl
->gui_timer_interval
< interval
)
1287 interval
= dcl
->gui_timer_interval
;
1290 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock_ms(rt_clock
));
1293 struct vm_change_state_entry
{
1294 VMChangeStateHandler
*cb
;
1296 QLIST_ENTRY (vm_change_state_entry
) entries
;
1299 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1301 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1304 VMChangeStateEntry
*e
;
1306 e
= g_malloc0(sizeof (*e
));
1310 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1314 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1316 QLIST_REMOVE (e
, entries
);
1320 void vm_state_notify(int running
, RunState state
)
1322 VMChangeStateEntry
*e
;
1324 trace_vm_state_notify(running
, state
);
1326 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1327 e
->cb(e
->opaque
, running
, state
);
1333 if (!runstate_is_running()) {
1335 runstate_set(RUN_STATE_RUNNING
);
1336 vm_state_notify(1, RUN_STATE_RUNNING
);
1338 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1342 /* reset/shutdown handler */
1344 typedef struct QEMUResetEntry
{
1345 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1346 QEMUResetHandler
*func
;
1350 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1351 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1352 static int reset_requested
;
1353 static int shutdown_requested
, shutdown_signal
= -1;
1354 static pid_t shutdown_pid
;
1355 static int powerdown_requested
;
1356 static int debug_requested
;
1357 static int suspend_requested
;
1358 static int wakeup_requested
;
1359 static NotifierList suspend_notifiers
=
1360 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1361 static NotifierList wakeup_notifiers
=
1362 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1363 static uint32_t wakeup_reason_mask
= ~0;
1364 static RunState vmstop_requested
= RUN_STATE_MAX
;
1366 int qemu_shutdown_requested_get(void)
1368 return shutdown_requested
;
1371 int qemu_reset_requested_get(void)
1373 return reset_requested
;
1376 int qemu_shutdown_requested(void)
1378 int r
= shutdown_requested
;
1379 shutdown_requested
= 0;
1383 void qemu_kill_report(void)
1385 if (!qtest_enabled() && shutdown_signal
!= -1) {
1386 fprintf(stderr
, "qemu: terminating on signal %d", shutdown_signal
);
1387 if (shutdown_pid
== 0) {
1388 /* This happens for eg ^C at the terminal, so it's worth
1389 * avoiding printing an odd message in that case.
1391 fputc('\n', stderr
);
1393 fprintf(stderr
, " from pid " FMT_pid
"\n", shutdown_pid
);
1395 shutdown_signal
= -1;
1399 int qemu_reset_requested(void)
1401 int r
= reset_requested
;
1402 reset_requested
= 0;
1406 static int qemu_suspend_requested(void)
1408 int r
= suspend_requested
;
1409 suspend_requested
= 0;
1413 static int qemu_wakeup_requested(void)
1415 int r
= wakeup_requested
;
1416 wakeup_requested
= 0;
1420 int qemu_powerdown_requested(void)
1422 int r
= powerdown_requested
;
1423 powerdown_requested
= 0;
1427 static int qemu_debug_requested(void)
1429 int r
= debug_requested
;
1430 debug_requested
= 0;
1434 /* We use RUN_STATE_MAX but any invalid value will do */
1435 static bool qemu_vmstop_requested(RunState
*r
)
1437 if (vmstop_requested
< RUN_STATE_MAX
) {
1438 *r
= vmstop_requested
;
1439 vmstop_requested
= RUN_STATE_MAX
;
1446 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1448 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1451 re
->opaque
= opaque
;
1452 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1455 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1459 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1460 if (re
->func
== func
&& re
->opaque
== opaque
) {
1461 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1468 void qemu_devices_reset(void)
1470 QEMUResetEntry
*re
, *nre
;
1472 /* reset all devices */
1473 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1474 re
->func(re
->opaque
);
1478 void qemu_system_reset(bool report
)
1480 if (current_machine
&& current_machine
->reset
) {
1481 current_machine
->reset();
1483 qemu_devices_reset();
1486 monitor_protocol_event(QEVENT_RESET
, NULL
);
1488 cpu_synchronize_all_post_reset();
1491 void qemu_system_reset_request(void)
1494 shutdown_requested
= 1;
1496 reset_requested
= 1;
1499 qemu_notify_event();
1502 static void qemu_system_suspend(void)
1505 notifier_list_notify(&suspend_notifiers
, NULL
);
1506 runstate_set(RUN_STATE_SUSPENDED
);
1507 monitor_protocol_event(QEVENT_SUSPEND
, NULL
);
1510 void qemu_system_suspend_request(void)
1512 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1515 suspend_requested
= 1;
1517 qemu_notify_event();
1520 void qemu_register_suspend_notifier(Notifier
*notifier
)
1522 notifier_list_add(&suspend_notifiers
, notifier
);
1525 void qemu_system_wakeup_request(WakeupReason reason
)
1527 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1530 if (!(wakeup_reason_mask
& (1 << reason
))) {
1533 runstate_set(RUN_STATE_RUNNING
);
1534 notifier_list_notify(&wakeup_notifiers
, &reason
);
1535 wakeup_requested
= 1;
1536 qemu_notify_event();
1539 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1542 wakeup_reason_mask
|= (1 << reason
);
1544 wakeup_reason_mask
&= ~(1 << reason
);
1548 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1550 notifier_list_add(&wakeup_notifiers
, notifier
);
1553 void qemu_system_killed(int signal
, pid_t pid
)
1555 shutdown_signal
= signal
;
1558 qemu_system_shutdown_request();
1561 void qemu_system_shutdown_request(void)
1563 shutdown_requested
= 1;
1564 qemu_notify_event();
1567 void qemu_system_powerdown_request(void)
1569 powerdown_requested
= 1;
1570 qemu_notify_event();
1573 void qemu_system_debug_request(void)
1575 debug_requested
= 1;
1576 qemu_notify_event();
1579 void qemu_system_vmstop_request(RunState state
)
1581 vmstop_requested
= state
;
1582 qemu_notify_event();
1585 qemu_irq qemu_system_powerdown
;
1587 static bool main_loop_should_exit(void)
1590 if (qemu_debug_requested()) {
1591 vm_stop(RUN_STATE_DEBUG
);
1593 if (qemu_suspend_requested()) {
1594 qemu_system_suspend();
1596 if (qemu_shutdown_requested()) {
1598 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1600 vm_stop(RUN_STATE_SHUTDOWN
);
1605 if (qemu_reset_requested()) {
1607 cpu_synchronize_all_states();
1608 qemu_system_reset(VMRESET_REPORT
);
1610 if (runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
1611 runstate_check(RUN_STATE_SHUTDOWN
)) {
1612 runstate_set(RUN_STATE_PAUSED
);
1615 if (qemu_wakeup_requested()) {
1617 cpu_synchronize_all_states();
1618 qemu_system_reset(VMRESET_SILENT
);
1620 monitor_protocol_event(QEVENT_WAKEUP
, NULL
);
1622 if (qemu_powerdown_requested()) {
1623 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1624 qemu_irq_raise(qemu_system_powerdown
);
1626 if (qemu_vmstop_requested(&r
)) {
1632 static void main_loop(void)
1636 #ifdef CONFIG_PROFILER
1640 nonblocking
= !kvm_enabled() && last_io
> 0;
1641 #ifdef CONFIG_PROFILER
1642 ti
= profile_getclock();
1644 last_io
= main_loop_wait(nonblocking
);
1645 #ifdef CONFIG_PROFILER
1646 dev_time
+= profile_getclock() - ti
;
1648 } while (!main_loop_should_exit());
1651 static void version(void)
1653 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1656 static void help(int exitcode
)
1659 printf("usage: %s [options] [disk_image]\n\n"
1660 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1661 error_get_progname());
1663 #define QEMU_OPTIONS_GENERATE_HELP
1664 #include "qemu-options-wrapper.h"
1666 printf("\nDuring emulation, the following keys are useful:\n"
1667 "ctrl-alt-f toggle full screen\n"
1668 "ctrl-alt-n switch to virtual console 'n'\n"
1669 "ctrl-alt toggle mouse and keyboard grab\n"
1671 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1676 #define HAS_ARG 0x0001
1678 typedef struct QEMUOption
{
1685 static const QEMUOption qemu_options
[] = {
1686 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1687 #define QEMU_OPTIONS_GENERATE_OPTIONS
1688 #include "qemu-options-wrapper.h"
1692 static bool vga_available(void)
1694 return qdev_exists("VGA") || qdev_exists("isa-vga");
1697 static bool cirrus_vga_available(void)
1699 return qdev_exists("cirrus-vga") || qdev_exists("isa-cirrus-vga");
1702 static bool vmware_vga_available(void)
1704 return qdev_exists("vmware-svga");
1707 static void select_vgahw (const char *p
)
1711 vga_interface_type
= VGA_NONE
;
1712 if (strstart(p
, "std", &opts
)) {
1713 if (vga_available()) {
1714 vga_interface_type
= VGA_STD
;
1716 fprintf(stderr
, "Error: standard VGA not available\n");
1719 } else if (strstart(p
, "cirrus", &opts
)) {
1720 if (cirrus_vga_available()) {
1721 vga_interface_type
= VGA_CIRRUS
;
1723 fprintf(stderr
, "Error: Cirrus VGA not available\n");
1726 } else if (strstart(p
, "vmware", &opts
)) {
1727 if (vmware_vga_available()) {
1728 vga_interface_type
= VGA_VMWARE
;
1730 fprintf(stderr
, "Error: VMWare SVGA not available\n");
1733 } else if (strstart(p
, "xenfb", &opts
)) {
1734 vga_interface_type
= VGA_XENFB
;
1735 } else if (strstart(p
, "qxl", &opts
)) {
1736 vga_interface_type
= VGA_QXL
;
1737 } else if (!strstart(p
, "none", &opts
)) {
1739 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1743 const char *nextopt
;
1745 if (strstart(opts
, ",retrace=", &nextopt
)) {
1747 if (strstart(opts
, "dumb", &nextopt
))
1748 vga_retrace_method
= VGA_RETRACE_DUMB
;
1749 else if (strstart(opts
, "precise", &nextopt
))
1750 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1751 else goto invalid_vga
;
1752 } else if (strstart(opts
, ",cga_hacks=", &nextopt
)) {
1755 if (strstart(opts
, "all", &nextopt
)) {
1757 vga_cga_hacks
|= ~0;
1758 } else if (strstart(opts
, "palette_blanking", &nextopt
)) {
1760 vga_cga_hacks
|= VGA_CGA_HACK_PALETTE_BLANKING
;
1761 } else if (strstart(opts
, "font_height", &nextopt
)) {
1763 vga_cga_hacks
|= VGA_CGA_HACK_FONT_HEIGHT
;
1774 } else goto invalid_vga
;
1779 static DisplayType
select_display(const char *p
)
1782 DisplayType display
= DT_DEFAULT
;
1784 if (strstart(p
, "sdl", &opts
)) {
1788 const char *nextopt
;
1790 if (strstart(opts
, ",frame=", &nextopt
)) {
1792 if (strstart(opts
, "on", &nextopt
)) {
1794 } else if (strstart(opts
, "off", &nextopt
)) {
1797 goto invalid_sdl_args
;
1799 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1801 if (strstart(opts
, "on", &nextopt
)) {
1803 } else if (strstart(opts
, "off", &nextopt
)) {
1806 goto invalid_sdl_args
;
1808 } else if (strstart(opts
, ",ctrl_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
, ",window_close=", &nextopt
)) {
1819 if (strstart(opts
, "on", &nextopt
)) {
1821 } else if (strstart(opts
, "off", &nextopt
)) {
1824 goto invalid_sdl_args
;
1828 fprintf(stderr
, "Invalid SDL option string: %s\n", p
);
1834 fprintf(stderr
, "SDL support is disabled\n");
1837 } else if (strstart(p
, "vnc", &opts
)) {
1842 const char *nextopt
;
1844 if (strstart(opts
, "=", &nextopt
)) {
1845 vnc_display
= nextopt
;
1849 fprintf(stderr
, "VNC requires a display argument vnc=<display>\n");
1853 fprintf(stderr
, "VNC support is disabled\n");
1856 } else if (strstart(p
, "curses", &opts
)) {
1857 #ifdef CONFIG_CURSES
1858 display
= DT_CURSES
;
1860 fprintf(stderr
, "Curses support is disabled\n");
1863 } else if (strstart(p
, "none", &opts
)) {
1866 fprintf(stderr
, "Unknown display type: %s\n", p
);
1873 static int balloon_parse(const char *arg
)
1877 if (strcmp(arg
, "none") == 0) {
1881 if (!strncmp(arg
, "virtio", 6)) {
1882 if (arg
[6] == ',') {
1883 /* have params -> parse them */
1884 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1888 /* create empty opts */
1889 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0, NULL
);
1891 qemu_opt_set(opts
, "driver", "virtio-balloon");
1898 char *qemu_find_file(int type
, const char *name
)
1904 /* Try the name as a straight path first */
1905 if (access(name
, R_OK
) == 0) {
1906 return g_strdup(name
);
1909 case QEMU_FILE_TYPE_BIOS
:
1912 case QEMU_FILE_TYPE_KEYMAP
:
1913 subdir
= "keymaps/";
1918 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1919 buf
= g_malloc0(len
);
1920 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1921 if (access(buf
, R_OK
)) {
1928 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1930 return qdev_device_help(opts
);
1933 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1937 dev
= qdev_device_add(opts
);
1943 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1945 CharDriverState
*chr
;
1947 chr
= qemu_chr_new_from_opts(opts
, NULL
);
1953 #ifdef CONFIG_VIRTFS
1954 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1957 ret
= qemu_fsdev_add(opts
);
1963 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1965 CharDriverState
*chr
;
1966 const char *chardev
;
1970 mode
= qemu_opt_get(opts
, "mode");
1974 if (strcmp(mode
, "readline") == 0) {
1975 flags
= MONITOR_USE_READLINE
;
1976 } else if (strcmp(mode
, "control") == 0) {
1977 flags
= MONITOR_USE_CONTROL
;
1979 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1983 if (qemu_opt_get_bool(opts
, "pretty", 0))
1984 flags
|= MONITOR_USE_PRETTY
;
1986 if (qemu_opt_get_bool(opts
, "default", 0))
1987 flags
|= MONITOR_IS_DEFAULT
;
1989 chardev
= qemu_opt_get(opts
, "chardev");
1990 chr
= qemu_chr_find(chardev
);
1992 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1996 monitor_init(chr
, flags
);
2000 static void monitor_parse(const char *optarg
, const char *mode
)
2002 static int monitor_device_index
= 0;
2008 if (strstart(optarg
, "chardev:", &p
)) {
2009 snprintf(label
, sizeof(label
), "%s", p
);
2011 snprintf(label
, sizeof(label
), "compat_monitor%d",
2012 monitor_device_index
);
2013 if (monitor_device_index
== 0) {
2016 opts
= qemu_chr_parse_compat(label
, optarg
);
2018 fprintf(stderr
, "parse error: %s\n", optarg
);
2023 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, NULL
);
2025 fprintf(stderr
, "duplicate chardev: %s\n", label
);
2028 qemu_opt_set(opts
, "mode", mode
);
2029 qemu_opt_set(opts
, "chardev", label
);
2031 qemu_opt_set(opts
, "default", "on");
2032 monitor_device_index
++;
2035 struct device_config
{
2037 DEV_USB
, /* -usbdevice */
2039 DEV_SERIAL
, /* -serial */
2040 DEV_PARALLEL
, /* -parallel */
2041 DEV_VIRTCON
, /* -virtioconsole */
2042 DEV_DEBUGCON
, /* -debugcon */
2043 DEV_GDB
, /* -gdb, -s */
2045 const char *cmdline
;
2047 QTAILQ_ENTRY(device_config
) next
;
2049 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
2051 static void add_device_config(int type
, const char *cmdline
)
2053 struct device_config
*conf
;
2055 conf
= g_malloc0(sizeof(*conf
));
2057 conf
->cmdline
= cmdline
;
2058 loc_save(&conf
->loc
);
2059 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2062 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2064 struct device_config
*conf
;
2067 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2068 if (conf
->type
!= type
)
2070 loc_push_restore(&conf
->loc
);
2071 rc
= func(conf
->cmdline
);
2072 loc_pop(&conf
->loc
);
2079 static int serial_parse(const char *devname
)
2081 static int index
= 0;
2084 if (strcmp(devname
, "none") == 0)
2086 if (index
== MAX_SERIAL_PORTS
) {
2087 fprintf(stderr
, "qemu: too many serial ports\n");
2090 snprintf(label
, sizeof(label
), "serial%d", index
);
2091 serial_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2092 if (!serial_hds
[index
]) {
2093 fprintf(stderr
, "qemu: could not connect serial device"
2094 " to character backend '%s'\n", devname
);
2101 static int parallel_parse(const char *devname
)
2103 static int index
= 0;
2106 if (strcmp(devname
, "none") == 0)
2108 if (index
== MAX_PARALLEL_PORTS
) {
2109 fprintf(stderr
, "qemu: too many parallel ports\n");
2112 snprintf(label
, sizeof(label
), "parallel%d", index
);
2113 parallel_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2114 if (!parallel_hds
[index
]) {
2115 fprintf(stderr
, "qemu: could not connect parallel device"
2116 " to character backend '%s'\n", devname
);
2123 static int virtcon_parse(const char *devname
)
2125 QemuOptsList
*device
= qemu_find_opts("device");
2126 static int index
= 0;
2128 QemuOpts
*bus_opts
, *dev_opts
;
2130 if (strcmp(devname
, "none") == 0)
2132 if (index
== MAX_VIRTIO_CONSOLES
) {
2133 fprintf(stderr
, "qemu: too many virtio consoles\n");
2137 bus_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2138 if (arch_type
== QEMU_ARCH_S390X
) {
2139 qemu_opt_set(bus_opts
, "driver", "virtio-serial-s390");
2141 qemu_opt_set(bus_opts
, "driver", "virtio-serial-pci");
2144 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2145 qemu_opt_set(dev_opts
, "driver", "virtconsole");
2147 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2148 virtcon_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2149 if (!virtcon_hds
[index
]) {
2150 fprintf(stderr
, "qemu: could not connect virtio console"
2151 " to character backend '%s'\n", devname
);
2154 qemu_opt_set(dev_opts
, "chardev", label
);
2160 static int debugcon_parse(const char *devname
)
2164 if (!qemu_chr_new("debugcon", devname
, NULL
)) {
2167 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2169 fprintf(stderr
, "qemu: already have a debugcon device\n");
2172 qemu_opt_set(opts
, "driver", "isa-debugcon");
2173 qemu_opt_set(opts
, "chardev", "debugcon");
2177 static QEMUMachine
*machine_parse(const char *name
)
2179 QEMUMachine
*m
, *machine
= NULL
;
2182 machine
= find_machine(name
);
2187 printf("Supported machines are:\n");
2188 for (m
= first_machine
; m
!= NULL
; m
= m
->next
) {
2190 printf("%-20s %s (alias of %s)\n", m
->alias
, m
->desc
, m
->name
);
2192 printf("%-20s %s%s\n", m
->name
, m
->desc
,
2193 m
->is_default
? " (default)" : "");
2195 exit(!name
|| !is_help_option(name
));
2198 static int tcg_init(void)
2200 tcg_exec_init(tcg_tb_size
* 1024 * 1024);
2205 const char *opt_name
;
2207 int (*available
)(void);
2211 { "tcg", "tcg", tcg_available
, tcg_init
, &tcg_allowed
},
2212 { "xen", "Xen", xen_available
, xen_init
, &xen_allowed
},
2213 { "kvm", "KVM", kvm_available
, kvm_init
, &kvm_allowed
},
2214 { "qtest", "QTest", qtest_available
, qtest_init
, &qtest_allowed
},
2217 static int configure_accelerator(void)
2219 const char *p
= NULL
;
2222 bool accel_initialised
= 0;
2223 bool init_failed
= 0;
2225 QemuOptsList
*list
= qemu_find_opts("machine");
2226 if (!QTAILQ_EMPTY(&list
->head
)) {
2227 p
= qemu_opt_get(QTAILQ_FIRST(&list
->head
), "accel");
2231 /* Use the default "accelerator", tcg */
2235 while (!accel_initialised
&& *p
!= '\0') {
2239 p
= get_opt_name(buf
, sizeof (buf
), p
, ':');
2240 for (i
= 0; i
< ARRAY_SIZE(accel_list
); i
++) {
2241 if (strcmp(accel_list
[i
].opt_name
, buf
) == 0) {
2242 *(accel_list
[i
].allowed
) = 1;
2243 ret
= accel_list
[i
].init();
2246 if (!accel_list
[i
].available()) {
2247 printf("%s not supported for this target\n",
2248 accel_list
[i
].name
);
2250 fprintf(stderr
, "failed to initialize %s: %s\n",
2254 *(accel_list
[i
].allowed
) = 0;
2256 accel_initialised
= 1;
2261 if (i
== ARRAY_SIZE(accel_list
)) {
2262 fprintf(stderr
, "\"%s\" accelerator does not exist.\n", buf
);
2266 if (!accel_initialised
) {
2267 fprintf(stderr
, "No accelerator found!\n");
2272 fprintf(stderr
, "Back to %s accelerator.\n", accel_list
[i
].name
);
2275 return !accel_initialised
;
2278 void qemu_add_exit_notifier(Notifier
*notify
)
2280 notifier_list_add(&exit_notifiers
, notify
);
2283 void qemu_remove_exit_notifier(Notifier
*notify
)
2285 notifier_remove(notify
);
2288 static void qemu_run_exit_notifiers(void)
2290 notifier_list_notify(&exit_notifiers
, NULL
);
2293 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2295 notifier_list_add(&machine_init_done_notifiers
, notify
);
2298 static void qemu_run_machine_init_done_notifiers(void)
2300 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2303 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2304 const char **poptarg
, int *poptind
)
2306 const QEMUOption
*popt
;
2307 int optind
= *poptind
;
2308 char *r
= argv
[optind
];
2311 loc_set_cmdline(argv
, optind
, 1);
2313 /* Treat --foo the same as -foo. */
2316 popt
= qemu_options
;
2319 error_report("invalid option");
2322 if (!strcmp(popt
->name
, r
+ 1))
2326 if (popt
->flags
& HAS_ARG
) {
2327 if (optind
>= argc
) {
2328 error_report("requires an argument");
2331 optarg
= argv
[optind
++];
2332 loc_set_cmdline(argv
, optind
- 2, 2);
2343 static gpointer
malloc_and_trace(gsize n_bytes
)
2345 void *ptr
= malloc(n_bytes
);
2346 trace_g_malloc(n_bytes
, ptr
);
2350 static gpointer
realloc_and_trace(gpointer mem
, gsize n_bytes
)
2352 void *ptr
= realloc(mem
, n_bytes
);
2353 trace_g_realloc(mem
, n_bytes
, ptr
);
2357 static void free_and_trace(gpointer mem
)
2363 int qemu_init_main_loop(void)
2365 return main_loop_init();
2368 int main(int argc
, char **argv
, char **envp
)
2371 int snapshot
, linux_boot
;
2372 const char *icount_option
= NULL
;
2373 const char *initrd_filename
;
2374 const char *kernel_filename
, *kernel_cmdline
;
2375 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
2377 DisplayChangeListener
*dcl
;
2378 char hdachs_params
[512]; /* save -hdachs to apply to later -hda */
2379 QemuOpts
*hda_opts
= NULL
; /* save -hda to be modified by later -hdachs */
2380 QemuOpts
*opts
, *machine_opts
;
2381 QemuOptsList
*olist
;
2384 const char *loadvm
= NULL
;
2385 QEMUMachine
*machine
;
2386 const char *cpu_model
;
2387 const char *vga_model
= "none";
2388 const char *pid_file
= NULL
;
2389 const char *incoming
= NULL
;
2391 int show_vnc_port
= 0;
2393 bool defconfig
= true;
2394 bool userconfig
= true;
2395 const char *log_mask
= NULL
;
2396 const char *log_file
= NULL
;
2397 GMemVTable mem_trace
= {
2398 .malloc
= malloc_and_trace
,
2399 .realloc
= realloc_and_trace
,
2400 .free
= free_and_trace
,
2402 const char *trace_events
= NULL
;
2403 const char *trace_file
= NULL
;
2405 atexit(qemu_run_exit_notifiers
);
2406 error_set_progname(argv
[0]);
2408 g_mem_set_vtable(&mem_trace
);
2409 if (!g_thread_supported()) {
2410 #if !GLIB_CHECK_VERSION(2, 31, 0)
2411 g_thread_init(NULL
);
2413 fprintf(stderr
, "glib threading failed to initialize.\n");
2418 module_call_init(MODULE_INIT_QOM
);
2423 rtc_clock
= host_clock
;
2425 qemu_cache_utils_init(envp
);
2427 QLIST_INIT (&vm_change_state_head
);
2428 os_setup_early_signal_handling();
2430 module_call_init(MODULE_INIT_MACHINE
);
2431 machine
= find_default_machine();
2435 snprintf(hdachs_params
, sizeof(hdachs_params
), "%s", HD_OPTS
);
2437 for (i
= 0; i
< MAX_NODES
; i
++) {
2439 node_cpumask
[i
] = bitmap_new(MAX_CPUMASK_BITS
);
2447 /* first pass of option parsing */
2449 while (optind
< argc
) {
2450 if (argv
[optind
][0] != '-') {
2455 const QEMUOption
*popt
;
2457 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2458 switch (popt
->index
) {
2459 case QEMU_OPTION_nodefconfig
:
2462 case QEMU_OPTION_nouserconfig
:
2471 ret
= qemu_read_default_config_files(userconfig
);
2477 /* second pass of option parsing */
2482 if (argv
[optind
][0] != '-') {
2483 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], hdachs_params
);
2485 const QEMUOption
*popt
;
2487 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2488 if (!(popt
->arch_mask
& arch_type
)) {
2489 printf("Option %s not supported for this target\n", popt
->name
);
2492 switch(popt
->index
) {
2494 machine
= machine_parse(optarg
);
2496 case QEMU_OPTION_cpu
:
2497 /* hw initialization will check this */
2500 case QEMU_OPTION_hda
:
2501 hda_opts
= drive_add(IF_DEFAULT
, 0, optarg
, hdachs_params
);
2503 case QEMU_OPTION_hdb
:
2504 case QEMU_OPTION_hdc
:
2505 case QEMU_OPTION_hdd
:
2506 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2509 case QEMU_OPTION_drive
:
2510 if (drive_def(optarg
) == NULL
) {
2514 case QEMU_OPTION_set
:
2515 if (qemu_set_option(optarg
) != 0)
2518 case QEMU_OPTION_global
:
2519 if (qemu_global_option(optarg
) != 0)
2522 case QEMU_OPTION_mtdblock
:
2523 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2525 case QEMU_OPTION_sd
:
2526 drive_add(IF_SD
, 0, optarg
, SD_OPTS
);
2528 case QEMU_OPTION_pflash
:
2529 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2531 case QEMU_OPTION_snapshot
:
2534 case QEMU_OPTION_hdachs
:
2536 int cyls
, heads
, secs
, translation
;
2538 cyls
= heads
= secs
= 0;
2539 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2541 cyls
= strtol(p
, (char **)&p
, 0);
2542 if (cyls
< 1 || cyls
> 16383)
2547 heads
= strtol(p
, (char **)&p
, 0);
2548 if (heads
< 1 || heads
> 16)
2553 secs
= strtol(p
, (char **)&p
, 0);
2554 if (secs
< 1 || secs
> 63)
2558 if (!strcmp(p
, "none"))
2559 translation
= BIOS_ATA_TRANSLATION_NONE
;
2560 else if (!strcmp(p
, "lba"))
2561 translation
= BIOS_ATA_TRANSLATION_LBA
;
2562 else if (!strcmp(p
, "auto"))
2563 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2566 } else if (*p
!= '\0') {
2568 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2571 snprintf(hdachs_params
, sizeof(hdachs_params
),
2572 "%s,cyls=%d,heads=%d,secs=%d%s",
2573 HD_OPTS
, cyls
, heads
, secs
,
2574 translation
== BIOS_ATA_TRANSLATION_LBA
?
2576 translation
== BIOS_ATA_TRANSLATION_NONE
?
2577 ",trans=none" : "");
2578 if (hda_opts
!= NULL
) {
2580 snprintf(num
, sizeof(num
), "%d", cyls
);
2581 qemu_opt_set(hda_opts
, "cyls", num
);
2582 snprintf(num
, sizeof(num
), "%d", heads
);
2583 qemu_opt_set(hda_opts
, "heads", num
);
2584 snprintf(num
, sizeof(num
), "%d", secs
);
2585 qemu_opt_set(hda_opts
, "secs", num
);
2586 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2587 qemu_opt_set(hda_opts
, "trans", "lba");
2588 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2589 qemu_opt_set(hda_opts
, "trans", "none");
2593 case QEMU_OPTION_numa
:
2594 if (nb_numa_nodes
>= MAX_NODES
) {
2595 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2600 case QEMU_OPTION_display
:
2601 display_type
= select_display(optarg
);
2603 case QEMU_OPTION_nographic
:
2604 display_type
= DT_NOGRAPHIC
;
2606 case QEMU_OPTION_curses
:
2607 #ifdef CONFIG_CURSES
2608 display_type
= DT_CURSES
;
2610 fprintf(stderr
, "Curses support is disabled\n");
2614 case QEMU_OPTION_portrait
:
2615 graphic_rotate
= 90;
2617 case QEMU_OPTION_rotate
:
2618 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2619 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2620 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2622 "qemu: only 90, 180, 270 deg rotation is available\n");
2626 case QEMU_OPTION_kernel
:
2627 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
);
2629 case QEMU_OPTION_initrd
:
2630 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
);
2632 case QEMU_OPTION_append
:
2633 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
);
2635 case QEMU_OPTION_dtb
:
2636 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
);
2638 case QEMU_OPTION_cdrom
:
2639 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2641 case QEMU_OPTION_boot
:
2643 static const char * const params
[] = {
2644 "order", "once", "menu",
2645 "splash", "splash-time", NULL
2647 char buf
[sizeof(boot_devices
)];
2648 char *standard_boot_devices
;
2651 if (!strchr(optarg
, '=')) {
2653 pstrcpy(buf
, sizeof(buf
), optarg
);
2654 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2656 "qemu: unknown boot parameter '%s' in '%s'\n",
2662 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2663 validate_bootdevices(buf
);
2664 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2667 if (get_param_value(buf
, sizeof(buf
),
2669 validate_bootdevices(buf
);
2670 standard_boot_devices
= g_strdup(boot_devices
);
2671 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2672 qemu_register_reset(restore_boot_devices
,
2673 standard_boot_devices
);
2675 if (get_param_value(buf
, sizeof(buf
),
2677 if (!strcmp(buf
, "on")) {
2679 } else if (!strcmp(buf
, "off")) {
2683 "qemu: invalid option value '%s'\n",
2688 qemu_opts_parse(qemu_find_opts("boot-opts"),
2693 case QEMU_OPTION_fda
:
2694 case QEMU_OPTION_fdb
:
2695 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2698 case QEMU_OPTION_no_fd_bootchk
:
2701 case QEMU_OPTION_netdev
:
2702 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2706 case QEMU_OPTION_net
:
2707 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2711 #ifdef CONFIG_LIBISCSI
2712 case QEMU_OPTION_iscsi
:
2713 opts
= qemu_opts_parse(qemu_find_opts("iscsi"), optarg
, 0);
2720 case QEMU_OPTION_tftp
:
2721 legacy_tftp_prefix
= optarg
;
2723 case QEMU_OPTION_bootp
:
2724 legacy_bootp_filename
= optarg
;
2726 case QEMU_OPTION_redir
:
2727 if (net_slirp_redir(optarg
) < 0)
2731 case QEMU_OPTION_bt
:
2732 add_device_config(DEV_BT
, optarg
);
2734 case QEMU_OPTION_audio_help
:
2735 if (!(audio_available())) {
2736 printf("Option %s not supported for this target\n", popt
->name
);
2742 case QEMU_OPTION_soundhw
:
2743 if (!(audio_available())) {
2744 printf("Option %s not supported for this target\n", popt
->name
);
2747 select_soundhw (optarg
);
2752 case QEMU_OPTION_version
:
2756 case QEMU_OPTION_m
: {
2761 value
= strtosz(optarg
, &end
);
2762 if (value
< 0 || *end
) {
2763 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2766 sz
= QEMU_ALIGN_UP((uint64_t)value
, 8192);
2768 if (ram_size
!= sz
) {
2769 fprintf(stderr
, "qemu: ram size too large\n");
2774 case QEMU_OPTION_mempath
:
2778 case QEMU_OPTION_mem_prealloc
:
2789 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
2791 case QEMU_OPTION_gdb
:
2792 add_device_config(DEV_GDB
, optarg
);
2797 case QEMU_OPTION_bios
:
2800 case QEMU_OPTION_singlestep
:
2807 keyboard_layout
= optarg
;
2809 case QEMU_OPTION_localtime
:
2812 case QEMU_OPTION_vga
:
2821 w
= strtol(p
, (char **)&p
, 10);
2824 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2830 h
= strtol(p
, (char **)&p
, 10);
2835 depth
= strtol(p
, (char **)&p
, 10);
2836 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2837 depth
!= 24 && depth
!= 32)
2839 } else if (*p
== '\0') {
2840 depth
= graphic_depth
;
2847 graphic_depth
= depth
;
2850 case QEMU_OPTION_echr
:
2853 term_escape_char
= strtol(optarg
, &r
, 0);
2855 printf("Bad argument to echr\n");
2858 case QEMU_OPTION_monitor
:
2859 monitor_parse(optarg
, "readline");
2860 default_monitor
= 0;
2862 case QEMU_OPTION_qmp
:
2863 monitor_parse(optarg
, "control");
2864 default_monitor
= 0;
2866 case QEMU_OPTION_mon
:
2867 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2871 default_monitor
= 0;
2873 case QEMU_OPTION_chardev
:
2874 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2879 case QEMU_OPTION_fsdev
:
2880 olist
= qemu_find_opts("fsdev");
2882 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2885 opts
= qemu_opts_parse(olist
, optarg
, 1);
2887 fprintf(stderr
, "parse error: %s\n", optarg
);
2891 case QEMU_OPTION_virtfs
: {
2894 const char *writeout
, *sock_fd
, *socket
;
2896 olist
= qemu_find_opts("virtfs");
2898 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2901 opts
= qemu_opts_parse(olist
, optarg
, 1);
2903 fprintf(stderr
, "parse error: %s\n", optarg
);
2907 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
2908 qemu_opt_get(opts
, "mount_tag") == NULL
) {
2909 fprintf(stderr
, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
2912 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
2913 qemu_opt_get(opts
, "mount_tag"),
2916 fprintf(stderr
, "duplicate fsdev id: %s\n",
2917 qemu_opt_get(opts
, "mount_tag"));
2921 writeout
= qemu_opt_get(opts
, "writeout");
2923 #ifdef CONFIG_SYNC_FILE_RANGE
2924 qemu_opt_set(fsdev
, "writeout", writeout
);
2926 fprintf(stderr
, "writeout=immediate not supported on "
2931 qemu_opt_set(fsdev
, "fsdriver", qemu_opt_get(opts
, "fsdriver"));
2932 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"));
2933 qemu_opt_set(fsdev
, "security_model",
2934 qemu_opt_get(opts
, "security_model"));
2935 socket
= qemu_opt_get(opts
, "socket");
2937 qemu_opt_set(fsdev
, "socket", socket
);
2939 sock_fd
= qemu_opt_get(opts
, "sock_fd");
2941 qemu_opt_set(fsdev
, "sock_fd", sock_fd
);
2944 qemu_opt_set_bool(fsdev
, "readonly",
2945 qemu_opt_get_bool(opts
, "readonly", 0));
2946 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2948 qemu_opt_set(device
, "driver", "virtio-9p-pci");
2949 qemu_opt_set(device
, "fsdev",
2950 qemu_opt_get(opts
, "mount_tag"));
2951 qemu_opt_set(device
, "mount_tag",
2952 qemu_opt_get(opts
, "mount_tag"));
2955 case QEMU_OPTION_virtfs_synth
: {
2959 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
2962 fprintf(stderr
, "duplicate option: %s\n", "virtfs_synth");
2965 qemu_opt_set(fsdev
, "fsdriver", "synth");
2967 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2969 qemu_opt_set(device
, "driver", "virtio-9p-pci");
2970 qemu_opt_set(device
, "fsdev", "v_synth");
2971 qemu_opt_set(device
, "mount_tag", "v_synth");
2974 case QEMU_OPTION_serial
:
2975 add_device_config(DEV_SERIAL
, optarg
);
2977 if (strncmp(optarg
, "mon:", 4) == 0) {
2978 default_monitor
= 0;
2981 case QEMU_OPTION_watchdog
:
2984 "qemu: only one watchdog option may be given\n");
2989 case QEMU_OPTION_watchdog_action
:
2990 if (select_watchdog_action(optarg
) == -1) {
2991 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2995 case QEMU_OPTION_virtiocon
:
2996 add_device_config(DEV_VIRTCON
, optarg
);
2997 default_virtcon
= 0;
2998 if (strncmp(optarg
, "mon:", 4) == 0) {
2999 default_monitor
= 0;
3002 case QEMU_OPTION_parallel
:
3003 add_device_config(DEV_PARALLEL
, optarg
);
3004 default_parallel
= 0;
3005 if (strncmp(optarg
, "mon:", 4) == 0) {
3006 default_monitor
= 0;
3009 case QEMU_OPTION_debugcon
:
3010 add_device_config(DEV_DEBUGCON
, optarg
);
3012 case QEMU_OPTION_loadvm
:
3015 case QEMU_OPTION_full_screen
:
3019 case QEMU_OPTION_no_frame
:
3022 case QEMU_OPTION_alt_grab
:
3025 case QEMU_OPTION_ctrl_grab
:
3028 case QEMU_OPTION_no_quit
:
3031 case QEMU_OPTION_sdl
:
3032 display_type
= DT_SDL
;
3035 case QEMU_OPTION_no_frame
:
3036 case QEMU_OPTION_alt_grab
:
3037 case QEMU_OPTION_ctrl_grab
:
3038 case QEMU_OPTION_no_quit
:
3039 case QEMU_OPTION_sdl
:
3040 fprintf(stderr
, "SDL support is disabled\n");
3043 case QEMU_OPTION_pidfile
:
3046 case QEMU_OPTION_win2k_hack
:
3047 win2k_install_hack
= 1;
3049 case QEMU_OPTION_rtc_td_hack
: {
3050 static GlobalProperty slew_lost_ticks
[] = {
3052 .driver
= "mc146818rtc",
3053 .property
= "lost_tick_policy",
3056 { /* end of list */ }
3059 qdev_prop_register_global_list(slew_lost_ticks
);
3062 case QEMU_OPTION_acpitable
:
3063 do_acpitable_option(optarg
);
3065 case QEMU_OPTION_smbios
:
3066 do_smbios_option(optarg
);
3068 case QEMU_OPTION_enable_kvm
:
3069 olist
= qemu_find_opts("machine");
3070 qemu_opts_parse(olist
, "accel=kvm", 0);
3072 case QEMU_OPTION_machine
:
3073 olist
= qemu_find_opts("machine");
3074 opts
= qemu_opts_parse(olist
, optarg
, 1);
3076 fprintf(stderr
, "parse error: %s\n", optarg
);
3079 optarg
= qemu_opt_get(opts
, "type");
3081 machine
= machine_parse(optarg
);
3084 case QEMU_OPTION_usb
:
3087 case QEMU_OPTION_usbdevice
:
3089 add_device_config(DEV_USB
, optarg
);
3091 case QEMU_OPTION_device
:
3092 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
3096 case QEMU_OPTION_smp
:
3099 fprintf(stderr
, "Invalid number of CPUs\n");
3102 if (max_cpus
< smp_cpus
) {
3103 fprintf(stderr
, "maxcpus must be equal to or greater than "
3107 if (max_cpus
> 255) {
3108 fprintf(stderr
, "Unsupported number of maxcpus\n");
3112 case QEMU_OPTION_vnc
:
3115 vnc_display
= optarg
;
3117 fprintf(stderr
, "VNC support is disabled\n");
3121 case QEMU_OPTION_no_acpi
:
3124 case QEMU_OPTION_no_hpet
:
3127 case QEMU_OPTION_balloon
:
3128 if (balloon_parse(optarg
) < 0) {
3129 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
3133 case QEMU_OPTION_no_reboot
:
3136 case QEMU_OPTION_no_shutdown
:
3139 case QEMU_OPTION_show_cursor
:
3142 case QEMU_OPTION_uuid
:
3143 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
3144 fprintf(stderr
, "Fail to parse UUID string."
3145 " Wrong format.\n");
3149 case QEMU_OPTION_option_rom
:
3150 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3151 fprintf(stderr
, "Too many option ROMs\n");
3154 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
3155 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3156 option_rom
[nb_option_roms
].bootindex
=
3157 qemu_opt_get_number(opts
, "bootindex", -1);
3158 if (!option_rom
[nb_option_roms
].name
) {
3159 fprintf(stderr
, "Option ROM file is not specified\n");
3164 case QEMU_OPTION_semihosting
:
3165 semihosting_enabled
= 1;
3167 case QEMU_OPTION_name
:
3168 qemu_name
= g_strdup(optarg
);
3170 char *p
= strchr(qemu_name
, ',');
3173 if (strncmp(p
, "process=", 8)) {
3174 fprintf(stderr
, "Unknown subargument %s to -name\n", p
);
3178 os_set_proc_name(p
);
3182 case QEMU_OPTION_prom_env
:
3183 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3184 fprintf(stderr
, "Too many prom variables\n");
3187 prom_envs
[nb_prom_envs
] = optarg
;
3190 case QEMU_OPTION_old_param
:
3193 case QEMU_OPTION_clock
:
3194 configure_alarms(optarg
);
3196 case QEMU_OPTION_startdate
:
3197 configure_rtc_date_offset(optarg
, 1);
3199 case QEMU_OPTION_rtc
:
3200 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
3204 configure_rtc(opts
);
3206 case QEMU_OPTION_tb_size
:
3207 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3208 if (tcg_tb_size
< 0) {
3212 case QEMU_OPTION_icount
:
3213 icount_option
= optarg
;
3215 case QEMU_OPTION_incoming
:
3217 runstate_set(RUN_STATE_INMIGRATE
);
3219 case QEMU_OPTION_nodefaults
:
3221 default_parallel
= 0;
3222 default_virtcon
= 0;
3223 default_monitor
= 0;
3230 case QEMU_OPTION_xen_domid
:
3231 if (!(xen_available())) {
3232 printf("Option %s not supported for this target\n", popt
->name
);
3235 xen_domid
= atoi(optarg
);
3237 case QEMU_OPTION_xen_create
:
3238 if (!(xen_available())) {
3239 printf("Option %s not supported for this target\n", popt
->name
);
3242 xen_mode
= XEN_CREATE
;
3244 case QEMU_OPTION_xen_attach
:
3245 if (!(xen_available())) {
3246 printf("Option %s not supported for this target\n", popt
->name
);
3249 xen_mode
= XEN_ATTACH
;
3251 case QEMU_OPTION_trace
:
3253 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
3257 trace_events
= qemu_opt_get(opts
, "events");
3258 trace_file
= qemu_opt_get(opts
, "file");
3261 case QEMU_OPTION_readconfig
:
3263 int ret
= qemu_read_config_file(optarg
);
3265 fprintf(stderr
, "read config %s: %s\n", optarg
,
3271 case QEMU_OPTION_spice
:
3272 olist
= qemu_find_opts("spice");
3274 fprintf(stderr
, "spice is not supported by this qemu build.\n");
3277 opts
= qemu_opts_parse(olist
, optarg
, 0);
3279 fprintf(stderr
, "parse error: %s\n", optarg
);
3283 case QEMU_OPTION_writeconfig
:
3286 if (strcmp(optarg
, "-") == 0) {
3289 fp
= fopen(optarg
, "w");
3291 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
3295 qemu_config_write(fp
);
3299 case QEMU_OPTION_qtest
:
3300 qtest_chrdev
= optarg
;
3302 case QEMU_OPTION_qtest_log
:
3305 case QEMU_OPTION_sandbox
:
3306 opts
= qemu_opts_parse(qemu_find_opts("sandbox"), optarg
, 1);
3312 os_parse_cmd_args(popt
->index
, optarg
);
3318 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox
, NULL
, 0)) {
3322 if (machine
== NULL
) {
3323 fprintf(stderr
, "No machine found.\n");
3327 if (machine
->hw_version
) {
3328 qemu_set_version(machine
->hw_version
);
3331 /* Init CPU def lists, based on config
3332 * - Must be called after all the qemu_read_config_file() calls
3333 * - Must be called before list_cpus()
3334 * - Must be called before machine->init()
3338 if (cpu_model
&& is_help_option(cpu_model
)) {
3339 list_cpus(stdout
, &fprintf
, cpu_model
);
3343 /* Open the logfile at this point, if necessary. We can't open the logfile
3344 * when encountering either of the logging options (-d or -D) because the
3345 * other one may be encountered later on the command line, changing the
3346 * location or level of logging.
3350 set_cpu_log_filename(log_file
);
3352 set_cpu_log(log_mask
);
3355 if (!trace_backend_init(trace_events
, trace_file
)) {
3359 /* If no data_dir is specified then try to find it relative to the
3362 data_dir
= os_find_datadir(argv
[0]);
3364 /* If all else fails use the install path specified when building. */
3366 data_dir
= CONFIG_QEMU_DATADIR
;
3370 * Default to max_cpus = smp_cpus, in case the user doesn't
3371 * specify a max_cpus value.
3374 max_cpus
= smp_cpus
;
3376 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
3377 if (smp_cpus
> machine
->max_cpus
) {
3378 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
3379 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
3385 * Get the default machine options from the machine if it is not already
3386 * specified either by the configuration file or by the command line.
3388 if (machine
->default_machine_opts
) {
3389 qemu_opts_set_defaults(qemu_find_opts("machine"),
3390 machine
->default_machine_opts
, 0);
3393 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
3394 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
3396 if (machine
->no_serial
) {
3399 if (machine
->no_parallel
) {
3400 default_parallel
= 0;
3402 if (!machine
->use_virtcon
) {
3403 default_virtcon
= 0;
3405 if (machine
->no_floppy
) {
3408 if (machine
->no_cdrom
) {
3411 if (machine
->no_sdcard
) {
3415 if (display_type
== DT_NOGRAPHIC
) {
3416 if (default_parallel
)
3417 add_device_config(DEV_PARALLEL
, "null");
3418 if (default_serial
&& default_monitor
) {
3419 add_device_config(DEV_SERIAL
, "mon:stdio");
3420 } else if (default_virtcon
&& default_monitor
) {
3421 add_device_config(DEV_VIRTCON
, "mon:stdio");
3424 add_device_config(DEV_SERIAL
, "stdio");
3425 if (default_virtcon
)
3426 add_device_config(DEV_VIRTCON
, "stdio");
3427 if (default_monitor
)
3428 monitor_parse("stdio", "readline");
3432 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
3433 if (default_parallel
)
3434 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
3435 if (default_monitor
)
3436 monitor_parse("vc:80Cx24C", "readline");
3437 if (default_virtcon
)
3438 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
3443 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
3445 #ifdef CONFIG_VIRTFS
3446 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
3453 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
3458 /* init the memory */
3459 if (ram_size
== 0) {
3460 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
3463 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0)
3468 configure_accelerator();
3470 qemu_init_cpu_loop();
3471 if (qemu_init_main_loop()) {
3472 fprintf(stderr
, "qemu_init_main_loop failed\n");
3476 machine_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
3478 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
3479 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
3480 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
3482 kernel_filename
= initrd_filename
= kernel_cmdline
= NULL
;
3485 if (!kernel_cmdline
) {
3486 kernel_cmdline
= "";
3489 linux_boot
= (kernel_filename
!= NULL
);
3491 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
3492 fprintf(stderr
, "-append only allowed with -kernel option\n");
3496 if (!linux_boot
&& initrd_filename
!= NULL
) {
3497 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
3501 if (!linux_boot
&& machine_opts
&& qemu_opt_get(machine_opts
, "dtb")) {
3502 fprintf(stderr
, "-dtb only allowed with -kernel option\n");
3506 os_set_line_buffering();
3508 if (init_timer_alarm() < 0) {
3509 fprintf(stderr
, "could not initialize alarm timer\n");
3514 /* spice needs the timers to be initialized by this point */
3518 if (icount_option
&& (kvm_enabled() || xen_enabled())) {
3519 fprintf(stderr
, "-icount is not allowed with kvm or xen\n");
3522 configure_icount(icount_option
);
3524 if (net_init_clients() < 0) {
3528 /* init the bluetooth world */
3529 if (foreach_device_config(DEV_BT
, bt_parse
))
3532 if (!xen_enabled()) {
3533 /* On 32-bit hosts, QEMU is limited by virtual address space */
3534 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
3535 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
3540 cpu_exec_init_all();
3542 bdrv_init_with_whitelist();
3546 /* open the virtual block devices */
3548 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
3549 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
3552 default_drive(default_cdrom
, snapshot
, machine
->use_scsi
,
3553 IF_DEFAULT
, 2, CDROM_OPTS
);
3554 default_drive(default_floppy
, snapshot
, machine
->use_scsi
,
3555 IF_FLOPPY
, 0, FD_OPTS
);
3556 default_drive(default_sdcard
, snapshot
, machine
->use_scsi
,
3559 register_savevm_live(NULL
, "ram", 0, 4, &savevm_ram_handlers
, NULL
);
3561 if (nb_numa_nodes
> 0) {
3564 if (nb_numa_nodes
> MAX_NODES
) {
3565 nb_numa_nodes
= MAX_NODES
;
3568 /* If no memory size if given for any node, assume the default case
3569 * and distribute the available memory equally across all nodes
3571 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3572 if (node_mem
[i
] != 0)
3575 if (i
== nb_numa_nodes
) {
3576 uint64_t usedmem
= 0;
3578 /* On Linux, the each node's border has to be 8MB aligned,
3579 * the final node gets the rest.
3581 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
3582 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
3583 usedmem
+= node_mem
[i
];
3585 node_mem
[i
] = ram_size
- usedmem
;
3588 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3589 if (!bitmap_empty(node_cpumask
[i
], MAX_CPUMASK_BITS
)) {
3593 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3594 * must cope with this anyway, because there are BIOSes out there in
3595 * real machines which also use this scheme.
3597 if (i
== nb_numa_nodes
) {
3598 for (i
= 0; i
< max_cpus
; i
++) {
3599 set_bit(i
, node_cpumask
[i
% nb_numa_nodes
]);
3604 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
3608 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
3610 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
3612 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
3614 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
3617 /* If no default VGA is requested, the default is "none". */
3618 if (default_vga
&& cirrus_vga_available()) {
3619 vga_model
= "cirrus";
3621 select_vgahw(vga_model
);
3624 i
= select_watchdog(watchdog
);
3626 exit (i
== 1 ? 1 : 0);
3629 if (machine
->compat_props
) {
3630 qdev_prop_register_global_list(machine
->compat_props
);
3634 qdev_machine_init();
3636 machine
->init(ram_size
, boot_devices
,
3637 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
3639 cpu_synchronize_all_post_init();
3643 current_machine
= machine
;
3645 /* init USB devices */
3647 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
3651 /* init generic devices */
3652 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3655 net_check_clients();
3657 /* just use the first displaystate for the moment */
3658 ds
= get_displaystate();
3662 if (display_type
== DT_DEFAULT
&& !display_remote
) {
3663 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3664 display_type
= DT_SDL
;
3665 #elif defined(CONFIG_VNC)
3666 vnc_display
= "localhost:0,to=99";
3669 display_type
= DT_NONE
;
3674 /* init local displays */
3675 switch (display_type
) {
3678 #if defined(CONFIG_CURSES)
3680 curses_display_init(ds
, full_screen
);
3683 #if defined(CONFIG_SDL)
3685 sdl_display_init(ds
, full_screen
, no_frame
);
3687 #elif defined(CONFIG_COCOA)
3689 cocoa_display_init(ds
, full_screen
);
3696 /* must be after terminal init, SDL library changes signal handlers */
3697 os_setup_signal_handling();
3700 /* init remote displays */
3702 vnc_display_init(ds
);
3703 if (vnc_display_open(ds
, vnc_display
) < 0) {
3704 fprintf(stderr
, "Failed to start VNC server on `%s'\n",
3709 if (show_vnc_port
) {
3710 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3715 if (using_spice
&& !qxl_enabled
) {
3716 qemu_spice_display_init(ds
);
3722 dcl
= ds
->listeners
;
3723 while (dcl
!= NULL
) {
3724 if (dcl
->dpy_refresh
!= NULL
) {
3725 ds
->gui_timer
= qemu_new_timer_ms(rt_clock
, gui_update
, ds
);
3726 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock_ms(rt_clock
));
3731 text_consoles_set_display(ds
);
3733 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
3737 qdev_machine_creation_done();
3739 if (rom_load_all() != 0) {
3740 fprintf(stderr
, "rom loading failed\n");
3744 /* TODO: once all bus devices are qdevified, this should be done
3745 * when bus is created by qdev.c */
3746 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
3747 qemu_run_machine_init_done_notifiers();
3749 qemu_system_reset(VMRESET_SILENT
);
3751 if (load_vmstate(loadvm
) < 0) {
3758 int ret
= qemu_start_incoming_migration(incoming
, &errp
);
3760 if (error_is_set(&errp
)) {
3761 fprintf(stderr
, "Migrate: %s\n", error_get_pretty(errp
));
3764 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3768 } else if (autostart
) {