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
24 #include "qemu/osdep.h"
25 #include "qemu/cutils.h"
26 #include "qemu/help_option.h"
29 #include "sysemu/seccomp.h"
32 #if defined(CONFIG_VDE)
33 #include <libvdeplug.h>
37 #if defined(__APPLE__) || defined(main)
40 int qemu_main(int argc, char **argv, char **envp);
41 int main(int argc, char **argv)
43 return qemu_main(argc, argv, NULL);
46 #define main qemu_main
49 #endif /* CONFIG_SDL */
53 #define main qemu_main
54 #endif /* CONFIG_COCOA */
60 int qemu_main(int argc, char **argv, char **envp);
61 #define main qemu_main
66 #include "qemu/error-report.h"
67 #include "qemu/sockets.h"
69 #include "hw/boards.h"
70 #include "sysemu/accel.h"
72 #include "hw/i386/pc.h"
73 #include "hw/isa/isa.h"
75 #include "sysemu/watchdog.h"
76 #include "hw/smbios/smbios.h"
77 #include "hw/xen/xen.h"
79 #include "hw/loader.h"
80 #include "monitor/qdev.h"
81 #include "sysemu/bt.h"
83 #include "net/slirp.h"
84 #include "monitor/monitor.h"
85 #include "ui/console.h"
87 #include "sysemu/sysemu.h"
88 #include "sysemu/numa.h"
89 #include "exec/gdbstub.h"
90 #include "qemu/timer.h"
91 #include "sysemu/char.h"
92 #include "qemu/bitmap.h"
93 #include "sysemu/blockdev.h"
94 #include "hw/block/block.h"
95 #include "migration/block.h"
96 #include "sysemu/tpm.h"
97 #include "sysemu/dma.h"
98 #include "audio/audio.h"
99 #include "migration/migration.h"
100 #include "sysemu/kvm.h"
101 #include "sysemu/hax.h"
102 #include "qapi/qmp/qjson.h"
103 #include "qemu/option.h"
104 #include "qemu/config-file.h"
105 #include "qemu-options.h"
106 #include "qmp-commands.h"
107 #include "qemu/main-loop.h"
109 #include "fsdev/qemu-fsdev.h"
111 #include "sysemu/qtest.h"
113 #include "disas/disas.h"
116 #include "slirp/libslirp.h"
119 #include "trace/control.h"
120 #include "qemu/queue.h"
121 #include "sysemu/cpus.h"
122 #include "sysemu/arch_init.h"
124 #include "ui/qemu-spice.h"
125 #include "qapi/string-input-visitor.h"
126 #include "qapi/opts-visitor.h"
127 #include "qom/object_interfaces.h"
128 #include "qapi-event.h"
129 #include "exec/semihost.h"
130 #include "crypto/init.h"
131 #include "sysemu/replay.h"
132 #include "qapi/qmp/qerror.h"
135 #include "tizen/src/emulator.h"
136 #include "tizen/src/emul_state.h"
137 #include "tizen/src/ui/qt5.h"
138 #include "tizen/src/util/ui_operations.h"
139 #include "tizen/src/ecs/ecs.h"
140 #include "tizen/src/util/error_handler.h"
141 #include "tizen/src/util/exported_strings.h"
143 inline static bool is_maru_machine(MachineClass *mc) {
144 return g_str_has_prefix(mc->name, "maru");
148 #define MAX_VIRTIO_CONSOLES 1
149 #define MAX_SCLP_CONSOLES 1
151 static const char *data_dir[16];
152 static int data_dir_idx;
153 const char *bios_name = NULL;
154 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
155 DisplayType display_type = DT_DEFAULT;
156 int request_opengl = -1;
158 static int display_remote;
159 const char* keyboard_layout = NULL;
161 const char *mem_path = NULL;
162 int mem_prealloc = 0; /* force preallocation of physical target memory */
163 bool enable_mlock = false;
165 NICInfo nd_table[MAX_NICS];
167 static int rtc_utc = 1;
168 static int rtc_date_offset = -1; /* -1 means no change */
169 QEMUClockType rtc_clock;
170 int vga_interface_type = VGA_NONE;
171 static int full_screen = 0;
172 static int no_frame = 0;
175 static bool grab_on_hover;
177 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
178 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
179 CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
180 CharDriverState *sclp_hds[MAX_SCLP_CONSOLES];
181 int win2k_install_hack = 0;
187 int acpi_enabled = 1;
190 static int no_reboot;
193 int graphic_rotate = 0;
194 const char *watchdog;
195 QEMUOptionRom option_rom[MAX_OPTION_ROMS];
198 const char *qemu_name;
201 unsigned int nb_prom_envs = 0;
202 const char *prom_envs[MAX_PROM_ENVS];
205 uint8_t *boot_splash_filedata;
206 size_t boot_splash_filedata_size;
207 uint8_t qemu_extra_params_fw[2];
209 int icount_align_option;
211 /* The bytes in qemu_uuid[] are in the order specified by RFC4122, _not_ in the
212 * little-endian "wire format" described in the SMBIOS 2.6 specification.
214 uint8_t qemu_uuid[16];
217 static NotifierList exit_notifiers =
218 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
220 static NotifierList machine_init_done_notifiers =
221 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
225 enum xen_mode xen_mode = XEN_EMULATE;
227 static int has_defaults = 1;
228 static int default_serial = 1;
229 static int default_parallel = 1;
230 static int default_virtcon = 1;
231 static int default_sclp = 1;
232 static int default_monitor = 1;
233 static int default_floppy = 1;
234 static int default_cdrom = 1;
235 static int default_sdcard = 1;
236 static int default_vga = 1;
242 { .driver = "isa-serial", .flag = &default_serial },
243 { .driver = "isa-parallel", .flag = &default_parallel },
244 { .driver = "isa-fdc", .flag = &default_floppy },
245 { .driver = "ide-cd", .flag = &default_cdrom },
246 { .driver = "ide-hd", .flag = &default_cdrom },
247 { .driver = "ide-drive", .flag = &default_cdrom },
248 { .driver = "scsi-cd", .flag = &default_cdrom },
249 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
250 { .driver = "virtio-serial", .flag = &default_virtcon },
251 { .driver = "VGA", .flag = &default_vga },
252 { .driver = "isa-vga", .flag = &default_vga },
253 { .driver = "cirrus-vga", .flag = &default_vga },
254 { .driver = "isa-cirrus-vga", .flag = &default_vga },
255 { .driver = "vmware-svga", .flag = &default_vga },
256 { .driver = "qxl-vga", .flag = &default_vga },
257 { .driver = "virtio-vga", .flag = &default_vga },
260 static QemuOptsList qemu_rtc_opts = {
262 .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head),
266 .type = QEMU_OPT_STRING,
269 .type = QEMU_OPT_STRING,
272 .type = QEMU_OPT_STRING,
274 { /* end of list */ }
278 static QemuOptsList qemu_sandbox_opts = {
280 .implied_opt_name = "enable",
281 .head = QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts.head),
285 .type = QEMU_OPT_BOOL,
287 { /* end of list */ }
291 static QemuOptsList qemu_trace_opts = {
293 .implied_opt_name = "enable",
294 .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
298 .type = QEMU_OPT_STRING,
302 .type = QEMU_OPT_STRING,
305 .type = QEMU_OPT_STRING,
307 { /* end of list */ }
311 static QemuOptsList qemu_option_rom_opts = {
312 .name = "option-rom",
313 .implied_opt_name = "romfile",
314 .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head),
318 .type = QEMU_OPT_NUMBER,
321 .type = QEMU_OPT_STRING,
323 { /* end of list */ }
327 static QemuOptsList qemu_machine_opts = {
329 .implied_opt_name = "type",
331 .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
334 * no elements => accept any
335 * sanity checking will happen later
336 * when setting machine properties
342 static QemuOptsList qemu_boot_opts = {
344 .implied_opt_name = "order",
346 .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head),
350 .type = QEMU_OPT_STRING,
353 .type = QEMU_OPT_STRING,
356 .type = QEMU_OPT_BOOL,
359 .type = QEMU_OPT_STRING,
361 .name = "splash-time",
362 .type = QEMU_OPT_STRING,
364 .name = "reboot-timeout",
365 .type = QEMU_OPT_STRING,
368 .type = QEMU_OPT_BOOL,
374 static QemuOptsList qemu_add_fd_opts = {
376 .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head),
380 .type = QEMU_OPT_NUMBER,
381 .help = "file descriptor of which a duplicate is added to fd set",
384 .type = QEMU_OPT_NUMBER,
385 .help = "ID of the fd set to add fd to",
388 .type = QEMU_OPT_STRING,
389 .help = "free-form string used to describe fd",
391 { /* end of list */ }
395 static QemuOptsList qemu_object_opts = {
397 .implied_opt_name = "qom-type",
398 .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
404 static QemuOptsList qemu_tpmdev_opts = {
406 .implied_opt_name = "type",
407 .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head),
409 /* options are defined in the TPM backends */
410 { /* end of list */ }
414 static QemuOptsList qemu_realtime_opts = {
416 .head = QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts.head),
420 .type = QEMU_OPT_BOOL,
422 { /* end of list */ }
426 static QemuOptsList qemu_msg_opts = {
428 .head = QTAILQ_HEAD_INITIALIZER(qemu_msg_opts.head),
432 .type = QEMU_OPT_BOOL,
434 { /* end of list */ }
438 static QemuOptsList qemu_name_opts = {
440 .implied_opt_name = "guest",
442 .head = QTAILQ_HEAD_INITIALIZER(qemu_name_opts.head),
446 .type = QEMU_OPT_STRING,
447 .help = "Sets the name of the guest.\n"
448 "This name will be displayed in the SDL window caption.\n"
449 "The name will also be used for the VNC server",
452 .type = QEMU_OPT_STRING,
453 .help = "Sets the name of the QEMU process, as shown in top etc",
455 .name = "debug-threads",
456 .type = QEMU_OPT_BOOL,
457 .help = "When enabled, name the individual threads; defaults off.\n"
458 "NOTE: The thread names are for debugging and not a\n"
461 { /* End of list */ }
465 static QemuOptsList qemu_mem_opts = {
467 .implied_opt_name = "size",
468 .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head),
473 .type = QEMU_OPT_SIZE,
477 .type = QEMU_OPT_NUMBER,
481 .type = QEMU_OPT_SIZE,
483 { /* end of list */ }
487 static QemuOptsList qemu_icount_opts = {
489 .implied_opt_name = "shift",
491 .head = QTAILQ_HEAD_INITIALIZER(qemu_icount_opts.head),
495 .type = QEMU_OPT_STRING,
498 .type = QEMU_OPT_BOOL,
501 .type = QEMU_OPT_BOOL,
504 .type = QEMU_OPT_STRING,
507 .type = QEMU_OPT_STRING,
509 { /* end of list */ }
513 static QemuOptsList qemu_semihosting_config_opts = {
514 .name = "semihosting-config",
515 .implied_opt_name = "enable",
516 .head = QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts.head),
520 .type = QEMU_OPT_BOOL,
523 .type = QEMU_OPT_STRING,
526 .type = QEMU_OPT_STRING,
528 { /* end of list */ }
532 static QemuOptsList qemu_fw_cfg_opts = {
534 .implied_opt_name = "name",
535 .head = QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts.head),
539 .type = QEMU_OPT_STRING,
540 .help = "Sets the fw_cfg name of the blob to be inserted",
543 .type = QEMU_OPT_STRING,
544 .help = "Sets the name of the file from which\n"
545 "the fw_cfg blob will be loaded",
548 .type = QEMU_OPT_STRING,
549 .help = "Sets content of the blob to be inserted from a string",
551 { /* end of list */ }
556 * Get machine options
558 * Returns: machine options (never null).
560 QemuOpts *qemu_get_machine_opts(void)
562 return qemu_find_opts_singleton("machine");
565 const char *qemu_get_vm_name(void)
570 static void res_free(void)
572 g_free(boot_splash_filedata);
573 boot_splash_filedata = NULL;
576 static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp)
578 const char *driver = qemu_opt_get(opts, "driver");
583 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
584 if (strcmp(default_list[i].driver, driver) != 0)
586 *(default_list[i].flag) = 0;
591 /***********************************************************/
594 static RunState current_run_state = RUN_STATE_PRELAUNCH;
596 /* We use RUN_STATE__MAX but any invalid value will do */
597 static RunState vmstop_requested = RUN_STATE__MAX;
598 static QemuMutex vmstop_lock;
603 } RunStateTransition;
605 static const RunStateTransition runstate_transitions_def[] = {
607 { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
608 { RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE },
609 { RUN_STATE_DEBUG, RUN_STATE_PRELAUNCH },
611 { RUN_STATE_INMIGRATE, RUN_STATE_INTERNAL_ERROR },
612 { RUN_STATE_INMIGRATE, RUN_STATE_IO_ERROR },
613 { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED },
614 { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },
615 { RUN_STATE_INMIGRATE, RUN_STATE_SHUTDOWN },
616 { RUN_STATE_INMIGRATE, RUN_STATE_SUSPENDED },
617 { RUN_STATE_INMIGRATE, RUN_STATE_WATCHDOG },
618 { RUN_STATE_INMIGRATE, RUN_STATE_GUEST_PANICKED },
619 { RUN_STATE_INMIGRATE, RUN_STATE_FINISH_MIGRATE },
620 { RUN_STATE_INMIGRATE, RUN_STATE_PRELAUNCH },
621 { RUN_STATE_INMIGRATE, RUN_STATE_POSTMIGRATE },
623 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
624 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
625 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PRELAUNCH },
627 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
628 { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE },
629 { RUN_STATE_IO_ERROR, RUN_STATE_PRELAUNCH },
631 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
632 { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
633 { RUN_STATE_PAUSED, RUN_STATE_PRELAUNCH },
635 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
636 { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
637 { RUN_STATE_POSTMIGRATE, RUN_STATE_PRELAUNCH },
639 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
640 { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
641 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
643 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
644 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
645 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH },
647 { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
648 { RUN_STATE_RESTORE_VM, RUN_STATE_PRELAUNCH },
650 { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
651 { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
652 { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
653 { RUN_STATE_RUNNING, RUN_STATE_PAUSED },
654 { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE },
655 { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM },
656 { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM },
657 { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
658 { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
659 { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED },
661 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
663 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
664 { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
665 { RUN_STATE_SHUTDOWN, RUN_STATE_PRELAUNCH },
667 { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
668 { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
669 { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },
670 { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
671 { RUN_STATE_SUSPENDED, RUN_STATE_PRELAUNCH },
673 { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
674 { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
675 { RUN_STATE_WATCHDOG, RUN_STATE_PRELAUNCH },
677 { RUN_STATE_GUEST_PANICKED, RUN_STATE_RUNNING },
678 { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE },
679 { RUN_STATE_GUEST_PANICKED, RUN_STATE_PRELAUNCH },
681 { RUN_STATE__MAX, RUN_STATE__MAX },
684 static bool runstate_valid_transitions[RUN_STATE__MAX][RUN_STATE__MAX];
686 bool runstate_check(RunState state)
688 return current_run_state == state;
691 bool runstate_store(char *str, size_t size)
693 const char *state = RunState_lookup[current_run_state];
694 size_t len = strlen(state) + 1;
699 memcpy(str, state, len);
703 static void runstate_init(void)
705 const RunStateTransition *p;
707 memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions));
708 for (p = &runstate_transitions_def[0]; p->from != RUN_STATE__MAX; p++) {
709 runstate_valid_transitions[p->from][p->to] = true;
712 qemu_mutex_init(&vmstop_lock);
715 /* This function will abort() on invalid state transitions */
716 void runstate_set(RunState new_state)
718 assert(new_state < RUN_STATE__MAX);
720 if (!runstate_valid_transitions[current_run_state][new_state]) {
721 error_report("invalid runstate transition: '%s' -> '%s'",
722 RunState_lookup[current_run_state],
723 RunState_lookup[new_state]);
726 trace_runstate_set(new_state);
727 current_run_state = new_state;
730 int runstate_is_running(void)
732 return runstate_check(RUN_STATE_RUNNING);
735 bool runstate_needs_reset(void)
737 return runstate_check(RUN_STATE_INTERNAL_ERROR) ||
738 runstate_check(RUN_STATE_SHUTDOWN);
741 StatusInfo *qmp_query_status(Error **errp)
743 StatusInfo *info = g_malloc0(sizeof(*info));
745 info->running = runstate_is_running();
746 info->singlestep = singlestep;
747 info->status = current_run_state;
752 static bool qemu_vmstop_requested(RunState *r)
754 qemu_mutex_lock(&vmstop_lock);
755 *r = vmstop_requested;
756 vmstop_requested = RUN_STATE__MAX;
757 qemu_mutex_unlock(&vmstop_lock);
758 return *r < RUN_STATE__MAX;
761 void qemu_system_vmstop_request_prepare(void)
763 qemu_mutex_lock(&vmstop_lock);
766 void qemu_system_vmstop_request(RunState state)
768 vmstop_requested = state;
769 qemu_mutex_unlock(&vmstop_lock);
777 qemu_vmstop_requested(&requested);
778 if (runstate_is_running() && requested == RUN_STATE__MAX) {
782 /* Ensure that a STOP/RESUME pair of events is emitted if a
783 * vmstop request was pending. The BLOCK_IO_ERROR event, for
784 * example, according to documentation is always followed by
787 if (runstate_is_running()) {
788 qapi_event_send_stop(&error_abort);
791 runstate_set(RUN_STATE_RUNNING);
792 vm_state_notify(1, RUN_STATE_RUNNING);
796 qapi_event_send_resume(&error_abort);
800 /***********************************************************/
801 /* real time host monotonic timer */
803 static time_t qemu_time(void)
805 return qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
808 /***********************************************************/
809 /* host time/date access */
810 void qemu_get_timedate(struct tm *tm, int offset)
812 time_t ti = qemu_time();
815 if (rtc_date_offset == -1) {
819 localtime_r(&ti, tm);
821 ti -= rtc_date_offset;
826 int qemu_timedate_diff(struct tm *tm)
830 if (rtc_date_offset == -1)
832 seconds = mktimegm(tm);
835 tmp.tm_isdst = -1; /* use timezone to figure it out */
836 seconds = mktime(&tmp);
839 seconds = mktimegm(tm) + rtc_date_offset;
841 return seconds - qemu_time();
844 static void configure_rtc_date_offset(const char *startdate, int legacy)
846 time_t rtc_start_date;
849 if (!strcmp(startdate, "now") && legacy) {
850 rtc_date_offset = -1;
852 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
860 } else if (sscanf(startdate, "%d-%d-%d",
872 rtc_start_date = mktimegm(&tm);
873 if (rtc_start_date == -1) {
875 error_report("invalid date format");
876 error_printf("valid formats: "
877 "'2006-06-17T16:01:21' or '2006-06-17'\n");
880 rtc_date_offset = qemu_time() - rtc_start_date;
884 static void configure_rtc(QemuOpts *opts)
888 value = qemu_opt_get(opts, "base");
890 if (!strcmp(value, "utc")) {
892 } else if (!strcmp(value, "localtime")) {
893 Error *blocker = NULL;
895 error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED,
896 "-rtc base=localtime");
897 replay_add_blocker(blocker);
899 configure_rtc_date_offset(value, 0);
902 value = qemu_opt_get(opts, "clock");
904 if (!strcmp(value, "host")) {
905 rtc_clock = QEMU_CLOCK_HOST;
906 } else if (!strcmp(value, "rt")) {
907 rtc_clock = QEMU_CLOCK_REALTIME;
908 } else if (!strcmp(value, "vm")) {
909 rtc_clock = QEMU_CLOCK_VIRTUAL;
911 error_report("invalid option value '%s'", value);
915 value = qemu_opt_get(opts, "driftfix");
917 if (!strcmp(value, "slew")) {
918 static GlobalProperty slew_lost_ticks[] = {
920 .driver = "mc146818rtc",
921 .property = "lost_tick_policy",
924 { /* end of list */ }
927 qdev_prop_register_global_list(slew_lost_ticks);
928 } else if (!strcmp(value, "none")) {
929 /* discard is default */
931 error_report("invalid option value '%s'", value);
937 /***********************************************************/
938 /* Bluetooth support */
941 static struct HCIInfo *hci_table[MAX_NICS];
943 struct HCIInfo *qemu_next_hci(void)
945 if (cur_hci == nb_hcis)
948 return hci_table[cur_hci++];
951 static int bt_hci_parse(const char *str)
956 if (nb_hcis >= MAX_NICS) {
957 error_report("too many bluetooth HCIs (max %i)", MAX_NICS);
970 bdaddr.b[5] = 0x56 + nb_hcis;
971 hci->bdaddr_set(hci, bdaddr.b);
973 hci_table[nb_hcis++] = hci;
978 static void bt_vhci_add(int vlan_id)
980 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
983 error_report("warning: adding a VHCI to an empty scatternet %i",
986 bt_vhci_init(bt_new_hci(vlan));
989 static struct bt_device_s *bt_device_add(const char *opt)
991 struct bt_scatternet_s *vlan;
993 char *endp = strstr(opt, ",vlan=");
994 int len = (endp ? endp - opt : strlen(opt)) + 1;
997 pstrcpy(devname, MIN(sizeof(devname), len), opt);
1000 vlan_id = strtol(endp + 6, &endp, 0);
1002 error_report("unrecognised bluetooth vlan Id");
1007 vlan = qemu_find_bt_vlan(vlan_id);
1010 error_report("warning: adding a slave device to an empty scatternet %i",
1013 if (!strcmp(devname, "keyboard"))
1014 return bt_keyboard_init(vlan);
1016 error_report("unsupported bluetooth device '%s'", devname);
1020 static int bt_parse(const char *opt)
1022 const char *endp, *p;
1025 if (strstart(opt, "hci", &endp)) {
1026 if (!*endp || *endp == ',') {
1028 if (!strstart(endp, ",vlan=", 0))
1031 return bt_hci_parse(opt);
1033 } else if (strstart(opt, "vhci", &endp)) {
1034 if (!*endp || *endp == ',') {
1036 if (strstart(endp, ",vlan=", &p)) {
1037 vlan = strtol(p, (char **) &endp, 0);
1039 error_report("bad scatternet '%s'", p);
1043 error_report("bad parameter '%s'", endp + 1);
1052 } else if (strstart(opt, "device:", &endp))
1053 return !bt_device_add(endp);
1055 error_report("bad bluetooth parameter '%s'", opt);
1059 static int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp)
1061 /* FIXME: change this to true for 1.3 */
1062 if (qemu_opt_get_bool(opts, "enable", false)) {
1063 #ifdef CONFIG_SECCOMP
1064 if (seccomp_start() < 0) {
1065 error_report("failed to install seccomp syscall filter "
1070 error_report("seccomp support is disabled");
1078 static int parse_name(void *opaque, QemuOpts *opts, Error **errp)
1080 const char *proc_name;
1082 if (qemu_opt_get(opts, "debug-threads")) {
1083 qemu_thread_naming(qemu_opt_get_bool(opts, "debug-threads", false));
1085 qemu_name = qemu_opt_get(opts, "guest");
1087 proc_name = qemu_opt_get(opts, "process");
1089 os_set_proc_name(proc_name);
1095 bool defaults_enabled(void)
1097 return has_defaults;
1100 bool usb_enabled(void)
1102 return machine_usb(current_machine);
1106 static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp)
1108 int fd, dupfd, flags;
1110 const char *fd_opaque = NULL;
1113 fd = qemu_opt_get_number(opts, "fd", -1);
1114 fdset_id = qemu_opt_get_number(opts, "set", -1);
1115 fd_opaque = qemu_opt_get(opts, "opaque");
1118 error_report("fd option is required and must be non-negative");
1122 if (fd <= STDERR_FILENO) {
1123 error_report("fd cannot be a standard I/O stream");
1128 * All fds inherited across exec() necessarily have FD_CLOEXEC
1129 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1131 flags = fcntl(fd, F_GETFD);
1132 if (flags == -1 || (flags & FD_CLOEXEC)) {
1133 error_report("fd is not valid or already in use");
1138 error_report("set option is required and must be non-negative");
1142 #ifdef F_DUPFD_CLOEXEC
1143 dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
1147 qemu_set_cloexec(dupfd);
1151 error_report("error duplicating fd: %s", strerror(errno));
1155 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1156 fdinfo = monitor_fdset_add_fd(dupfd, true, fdset_id, !!fd_opaque, fd_opaque,
1163 static int cleanup_add_fd(void *opaque, QemuOpts *opts, Error **errp)
1167 fd = qemu_opt_get_number(opts, "fd", -1);
1174 /***********************************************************/
1175 /* QEMU Block devices */
1177 #define HD_OPTS "media=disk"
1178 #define CDROM_OPTS "media=cdrom"
1180 #define PFLASH_OPTS ""
1184 static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp)
1186 BlockInterfaceType *block_default_type = opaque;
1188 return drive_new(opts, *block_default_type) == NULL;
1191 static int drive_enable_snapshot(void *opaque, QemuOpts *opts, Error **errp)
1193 if (qemu_opt_get(opts, "snapshot") == NULL) {
1194 qemu_opt_set(opts, "snapshot", "on", &error_abort);
1199 static void default_drive(int enable, int snapshot, BlockInterfaceType type,
1200 int index, const char *optstr)
1205 if (!enable || drive_get_by_index(type, index)) {
1209 opts = drive_add(type, index, NULL, optstr);
1211 drive_enable_snapshot(NULL, opts, NULL);
1214 dinfo = drive_new(opts, type);
1218 dinfo->is_default = true;
1222 static QemuOptsList qemu_smp_opts = {
1224 .implied_opt_name = "cpus",
1225 .merge_lists = true,
1226 .head = QTAILQ_HEAD_INITIALIZER(qemu_smp_opts.head),
1230 .type = QEMU_OPT_NUMBER,
1233 .type = QEMU_OPT_NUMBER,
1236 .type = QEMU_OPT_NUMBER,
1239 .type = QEMU_OPT_NUMBER,
1242 .type = QEMU_OPT_NUMBER,
1244 { /*End of list */ }
1248 static void smp_parse(QemuOpts *opts)
1252 unsigned cpus = qemu_opt_get_number(opts, "cpus", 0);
1253 unsigned sockets = qemu_opt_get_number(opts, "sockets", 0);
1254 unsigned cores = qemu_opt_get_number(opts, "cores", 0);
1255 unsigned threads = qemu_opt_get_number(opts, "threads", 0);
1257 /* compute missing values, prefer sockets over cores over threads */
1258 if (cpus == 0 || sockets == 0) {
1259 sockets = sockets > 0 ? sockets : 1;
1260 cores = cores > 0 ? cores : 1;
1261 threads = threads > 0 ? threads : 1;
1263 cpus = cores * threads * sockets;
1265 } else if (cores == 0) {
1266 threads = threads > 0 ? threads : 1;
1267 cores = cpus / (sockets * threads);
1268 } else if (threads == 0) {
1269 threads = cpus / (cores * sockets);
1270 } else if (sockets * cores * threads < cpus) {
1271 error_report("cpu topology: "
1272 "sockets (%u) * cores (%u) * threads (%u) < "
1274 sockets, cores, threads, cpus);
1278 max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
1279 if (sockets * cores * threads > max_cpus) {
1280 error_report("cpu topology: "
1281 "sockets (%u) * cores (%u) * threads (%u) > "
1283 sockets, cores, threads, max_cpus);
1288 smp_cores = cores > 0 ? cores : 1;
1289 smp_threads = threads > 0 ? threads : 1;
1293 if (max_cpus == 0) {
1294 max_cpus = smp_cpus;
1297 if (max_cpus > MAX_CPUMASK_BITS) {
1298 error_report("unsupported number of maxcpus");
1301 if (max_cpus < smp_cpus) {
1302 error_report("maxcpus must be equal to or greater than smp");
1306 if (smp_cpus > 1 || smp_cores > 1 || smp_threads > 1) {
1307 Error *blocker = NULL;
1308 error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp");
1309 replay_add_blocker(blocker);
1313 static void realtime_init(void)
1316 if (os_mlock() < 0) {
1317 error_report("locking memory failed");
1324 static void configure_msg(QemuOpts *opts)
1326 enable_timestamp_msg = qemu_opt_get_bool(opts, "timestamp", true);
1329 /***********************************************************/
1332 typedef struct SemihostingConfig {
1334 SemihostingTarget target;
1337 const char *cmdline; /* concatenated argv */
1338 } SemihostingConfig;
1340 static SemihostingConfig semihosting;
1342 bool semihosting_enabled(void)
1344 return semihosting.enabled;
1347 SemihostingTarget semihosting_get_target(void)
1349 return semihosting.target;
1352 const char *semihosting_get_arg(int i)
1354 if (i >= semihosting.argc) {
1357 return semihosting.argv[i];
1360 int semihosting_get_argc(void)
1362 return semihosting.argc;
1365 const char *semihosting_get_cmdline(void)
1367 if (semihosting.cmdline == NULL && semihosting.argc > 0) {
1368 semihosting.cmdline = g_strjoinv(" ", (gchar **)semihosting.argv);
1370 return semihosting.cmdline;
1373 static int add_semihosting_arg(void *opaque,
1374 const char *name, const char *val,
1377 SemihostingConfig *s = opaque;
1378 if (strcmp(name, "arg") == 0) {
1380 /* one extra element as g_strjoinv() expects NULL-terminated array */
1381 s->argv = g_realloc(s->argv, (s->argc + 1) * sizeof(void *));
1382 s->argv[s->argc - 1] = val;
1383 s->argv[s->argc] = NULL;
1388 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1389 static inline void semihosting_arg_fallback(const char *file, const char *cmd)
1394 add_semihosting_arg(&semihosting, "arg", file, NULL);
1396 /* split -append and initialize argv[1..n] */
1397 cmd_token = strtok(g_strdup(cmd), " ");
1399 add_semihosting_arg(&semihosting, "arg", cmd_token, NULL);
1400 cmd_token = strtok(NULL, " ");
1404 /* Now we still need this for compatibility with XEN. */
1405 bool has_igd_gfx_passthru;
1406 static void igd_gfx_passthru(void)
1408 has_igd_gfx_passthru = current_machine->igd_gfx_passthru;
1411 /***********************************************************/
1414 static int usb_device_add(const char *devname)
1416 USBDevice *dev = NULL;
1417 #ifndef CONFIG_LINUX
1421 if (!usb_enabled()) {
1425 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1426 dev = usbdevice_create(devname);
1430 /* the other ones */
1431 #ifndef CONFIG_LINUX
1432 /* only the linux version is qdev-ified, usb-bsd still needs this */
1433 if (strstart(devname, "host:", &p)) {
1434 dev = usb_host_device_open(usb_bus_find(-1), p);
1444 static int usb_device_del(const char *devname)
1449 if (strstart(devname, "host:", &p)) {
1453 if (!usb_enabled()) {
1457 p = strchr(devname, '.');
1460 bus_num = strtoul(devname, NULL, 0);
1461 addr = strtoul(p + 1, NULL, 0);
1463 return usb_device_delete_addr(bus_num, addr);
1466 static int usb_parse(const char *cmdline)
1469 r = usb_device_add(cmdline);
1471 error_report("could not add USB device '%s'", cmdline);
1476 void hmp_usb_add(Monitor *mon, const QDict *qdict)
1478 const char *devname = qdict_get_str(qdict, "devname");
1479 if (usb_device_add(devname) < 0) {
1480 error_report("could not add USB device '%s'", devname);
1484 void hmp_usb_del(Monitor *mon, const QDict *qdict)
1486 const char *devname = qdict_get_str(qdict, "devname");
1487 if (usb_device_del(devname) < 0) {
1488 error_report("could not delete USB device '%s'", devname);
1492 /***********************************************************/
1493 /* machine registration */
1495 MachineState *current_machine;
1497 static MachineClass *find_machine(const char *name)
1499 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1500 MachineClass *mc = NULL;
1502 for (el = machines; el; el = el->next) {
1503 MachineClass *temp = el->data;
1505 if (!strcmp(temp->name, name)) {
1510 !strcmp(temp->alias, name)) {
1516 g_slist_free(machines);
1520 MachineClass *find_default_machine(void)
1522 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1523 MachineClass *mc = NULL;
1525 for (el = machines; el; el = el->next) {
1526 MachineClass *temp = el->data;
1528 if (temp->is_default) {
1534 g_slist_free(machines);
1538 MachineInfoList *qmp_query_machines(Error **errp)
1540 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
1541 MachineInfoList *mach_list = NULL;
1543 for (el = machines; el; el = el->next) {
1544 MachineClass *mc = el->data;
1545 MachineInfoList *entry;
1548 info = g_malloc0(sizeof(*info));
1549 if (mc->is_default) {
1550 info->has_is_default = true;
1551 info->is_default = true;
1555 info->has_alias = true;
1556 info->alias = g_strdup(mc->alias);
1559 info->name = g_strdup(mc->name);
1560 info->cpu_max = !mc->max_cpus ? 1 : mc->max_cpus;
1562 entry = g_malloc0(sizeof(*entry));
1563 entry->value = info;
1564 entry->next = mach_list;
1568 g_slist_free(machines);
1572 static int machine_help_func(QemuOpts *opts, MachineState *machine)
1574 ObjectProperty *prop;
1575 ObjectPropertyIterator iter;
1577 if (!qemu_opt_has_help_opt(opts)) {
1581 object_property_iter_init(&iter, OBJECT(machine));
1582 while ((prop = object_property_iter_next(&iter))) {
1587 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine)->name,
1588 prop->name, prop->type);
1589 if (prop->description) {
1590 error_printf(" (%s)\n", prop->description);
1599 /***********************************************************/
1600 /* main execution loop */
1602 struct vm_change_state_entry {
1603 VMChangeStateHandler *cb;
1605 QLIST_ENTRY (vm_change_state_entry) entries;
1608 static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
1610 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1613 VMChangeStateEntry *e;
1615 e = g_malloc0(sizeof (*e));
1619 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
1623 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1625 QLIST_REMOVE (e, entries);
1629 void vm_state_notify(int running, RunState state)
1631 VMChangeStateEntry *e, *next;
1633 trace_vm_state_notify(running, state);
1635 QLIST_FOREACH_SAFE(e, &vm_change_state_head, entries, next) {
1636 e->cb(e->opaque, running, state);
1640 /* reset/shutdown handler */
1642 typedef struct QEMUResetEntry {
1643 QTAILQ_ENTRY(QEMUResetEntry) entry;
1644 QEMUResetHandler *func;
1648 static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1649 QTAILQ_HEAD_INITIALIZER(reset_handlers);
1650 static int reset_requested;
1651 static int shutdown_requested, shutdown_signal = -1;
1652 static pid_t shutdown_pid;
1653 static int powerdown_requested;
1654 static int debug_requested;
1655 static int suspend_requested;
1656 static WakeupReason wakeup_reason;
1657 static NotifierList powerdown_notifiers =
1658 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
1659 static NotifierList suspend_notifiers =
1660 NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
1661 static NotifierList wakeup_notifiers =
1662 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
1663 static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE);
1665 int qemu_shutdown_requested_get(void)
1667 return shutdown_requested;
1670 int qemu_reset_requested_get(void)
1672 return reset_requested;
1675 static int qemu_shutdown_requested(void)
1677 return atomic_xchg(&shutdown_requested, 0);
1680 static void qemu_kill_report(void)
1682 if (!qtest_driver() && shutdown_signal != -1) {
1683 if (shutdown_pid == 0) {
1684 /* This happens for eg ^C at the terminal, so it's worth
1685 * avoiding printing an odd message in that case.
1687 error_report("terminating on signal %d", shutdown_signal);
1689 error_report("terminating on signal %d from pid " FMT_pid,
1690 shutdown_signal, shutdown_pid);
1692 shutdown_signal = -1;
1696 static int qemu_reset_requested(void)
1698 int r = reset_requested;
1699 if (r && replay_checkpoint(CHECKPOINT_RESET_REQUESTED)) {
1700 reset_requested = 0;
1706 static int qemu_suspend_requested(void)
1708 int r = suspend_requested;
1709 if (r && replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED)) {
1710 suspend_requested = 0;
1716 static WakeupReason qemu_wakeup_requested(void)
1718 return wakeup_reason;
1721 static int qemu_powerdown_requested(void)
1723 int r = powerdown_requested;
1724 powerdown_requested = 0;
1728 static int qemu_debug_requested(void)
1730 int r = debug_requested;
1731 debug_requested = 0;
1735 void qemu_register_reset(QEMUResetHandler *func, void *opaque)
1737 QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
1740 re->opaque = opaque;
1741 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
1744 void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
1748 QTAILQ_FOREACH(re, &reset_handlers, entry) {
1749 if (re->func == func && re->opaque == opaque) {
1750 QTAILQ_REMOVE(&reset_handlers, re, entry);
1757 void qemu_devices_reset(void)
1759 QEMUResetEntry *re, *nre;
1761 /* reset all devices */
1762 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
1763 re->func(re->opaque);
1767 void qemu_system_reset(bool report)
1771 mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL;
1773 cpu_synchronize_all_states();
1775 if (mc && mc->reset) {
1778 qemu_devices_reset();
1781 qapi_event_send_reset(&error_abort);
1783 cpu_synchronize_all_post_reset();
1786 void qemu_system_guest_panicked(void)
1789 current_cpu->crash_occurred = true;
1791 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE, &error_abort);
1792 vm_stop(RUN_STATE_GUEST_PANICKED);
1795 void qemu_system_reset_request(void)
1798 shutdown_requested = 1;
1800 reset_requested = 1;
1803 qemu_notify_event();
1806 static void qemu_system_suspend(void)
1809 notifier_list_notify(&suspend_notifiers, NULL);
1810 runstate_set(RUN_STATE_SUSPENDED);
1811 qapi_event_send_suspend(&error_abort);
1814 void qemu_system_suspend_request(void)
1816 if (runstate_check(RUN_STATE_SUSPENDED)) {
1819 suspend_requested = 1;
1821 qemu_notify_event();
1824 void qemu_register_suspend_notifier(Notifier *notifier)
1826 notifier_list_add(&suspend_notifiers, notifier);
1829 void qemu_system_wakeup_request(WakeupReason reason)
1831 trace_system_wakeup_request(reason);
1833 if (!runstate_check(RUN_STATE_SUSPENDED)) {
1836 if (!(wakeup_reason_mask & (1 << reason))) {
1839 runstate_set(RUN_STATE_RUNNING);
1840 wakeup_reason = reason;
1841 qemu_notify_event();
1844 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
1847 wakeup_reason_mask |= (1 << reason);
1849 wakeup_reason_mask &= ~(1 << reason);
1853 void qemu_register_wakeup_notifier(Notifier *notifier)
1855 notifier_list_add(&wakeup_notifiers, notifier);
1858 void qemu_system_killed(int signal, pid_t pid)
1860 shutdown_signal = signal;
1865 if (current_machine &&
1866 is_maru_machine(MACHINE_GET_CLASS(current_machine))) {
1867 qemu_system_graceful_shutdown_request(TIMEOUT_FOR_SHUTDOWN);
1870 /* Cannot call qemu_system_shutdown_request directly because
1871 * we are in a signal handler.
1873 shutdown_requested = 1;
1874 qemu_notify_event();
1878 void qemu_system_shutdown_request(void)
1880 trace_qemu_system_shutdown_request();
1881 replay_shutdown_request();
1882 shutdown_requested = 1;
1883 qemu_notify_event();
1886 static void qemu_system_powerdown(void)
1888 qapi_event_send_powerdown(&error_abort);
1889 notifier_list_notify(&powerdown_notifiers, NULL);
1892 void qemu_system_powerdown_request(void)
1894 trace_qemu_system_powerdown_request();
1895 powerdown_requested = 1;
1896 qemu_notify_event();
1899 void qemu_register_powerdown_notifier(Notifier *notifier)
1901 notifier_list_add(&powerdown_notifiers, notifier);
1904 void qemu_system_debug_request(void)
1906 debug_requested = 1;
1907 qemu_notify_event();
1910 static bool main_loop_should_exit(void)
1913 if (qemu_debug_requested()) {
1914 vm_stop(RUN_STATE_DEBUG);
1916 if (qemu_suspend_requested()) {
1917 qemu_system_suspend();
1919 if (qemu_shutdown_requested()) {
1921 qapi_event_send_shutdown(&error_abort);
1923 vm_stop(RUN_STATE_SHUTDOWN);
1928 if (qemu_reset_requested()) {
1930 qemu_system_reset(VMRESET_REPORT);
1932 if (!runstate_check(RUN_STATE_RUNNING) &&
1933 !runstate_check(RUN_STATE_INMIGRATE)) {
1934 runstate_set(RUN_STATE_PRELAUNCH);
1937 if (qemu_wakeup_requested()) {
1939 qemu_system_reset(VMRESET_SILENT);
1940 notifier_list_notify(&wakeup_notifiers, &wakeup_reason);
1941 wakeup_reason = QEMU_WAKEUP_REASON_NONE;
1943 qapi_event_send_wakeup(&error_abort);
1945 if (qemu_powerdown_requested()) {
1946 qemu_system_powerdown();
1948 if (qemu_vmstop_requested(&r)) {
1954 static void main_loop(void)
1958 #ifdef CONFIG_PROFILER
1965 nonblocking = !kvm_enabled() && !xen_enabled() && !hax_enabled() && last_io > 0;
1966 #ifdef CONFIG_PROFILER
1967 ti = profile_getclock();
1969 last_io = main_loop_wait(nonblocking);
1970 #ifdef CONFIG_PROFILER
1971 dev_time += profile_getclock() - ti;
1973 } while (!main_loop_should_exit());
1976 static void version(void)
1978 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
1981 static void help(int exitcode)
1984 printf("usage: %s [options] [disk_image]\n\n"
1985 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1986 error_get_progname());
1988 #define QEMU_OPTIONS_GENERATE_HELP
1989 #include "qemu-options-wrapper.h"
1991 printf("\nDuring emulation, the following keys are useful:\n"
1992 "ctrl-alt-f toggle full screen\n"
1993 "ctrl-alt-n switch to virtual console 'n'\n"
1994 "ctrl-alt toggle mouse and keyboard grab\n"
1996 "When using -nographic, press 'ctrl-a h' to get some help.\n");
2001 #define HAS_ARG 0x0001
2003 typedef struct QEMUOption {
2010 static const QEMUOption qemu_options[] = {
2011 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
2012 #define QEMU_OPTIONS_GENERATE_OPTIONS
2013 #include "qemu-options-wrapper.h"
2017 static bool vga_available(void)
2019 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
2022 static bool cirrus_vga_available(void)
2024 return object_class_by_name("cirrus-vga")
2025 || object_class_by_name("isa-cirrus-vga");
2028 static bool vmware_vga_available(void)
2030 return object_class_by_name("vmware-svga");
2033 static bool qxl_vga_available(void)
2035 return object_class_by_name("qxl-vga");
2038 static bool tcx_vga_available(void)
2040 return object_class_by_name("SUNW,tcx");
2043 static bool cg3_vga_available(void)
2045 return object_class_by_name("cgthree");
2048 static bool virtio_vga_available(void)
2050 return object_class_by_name("virtio-vga");
2053 static void select_vgahw (const char *p)
2057 assert(vga_interface_type == VGA_NONE);
2058 if (strstart(p, "std", &opts)) {
2059 if (vga_available()) {
2060 vga_interface_type = VGA_STD;
2062 error_report("standard VGA not available");
2065 } else if (strstart(p, "cirrus", &opts)) {
2066 if (cirrus_vga_available()) {
2067 vga_interface_type = VGA_CIRRUS;
2069 error_report("Cirrus VGA not available");
2072 } else if (strstart(p, "vmware", &opts)) {
2073 if (vmware_vga_available()) {
2074 vga_interface_type = VGA_VMWARE;
2076 error_report("VMWare SVGA not available");
2079 } else if (strstart(p, "virtio", &opts)) {
2080 if (virtio_vga_available()) {
2081 vga_interface_type = VGA_VIRTIO;
2083 error_report("Virtio VGA not available");
2086 } else if (strstart(p, "xenfb", &opts)) {
2087 vga_interface_type = VGA_XENFB;
2088 } else if (strstart(p, "qxl", &opts)) {
2089 if (qxl_vga_available()) {
2090 vga_interface_type = VGA_QXL;
2092 error_report("QXL VGA not available");
2095 } else if (strstart(p, "tcx", &opts)) {
2096 if (tcx_vga_available()) {
2097 vga_interface_type = VGA_TCX;
2099 error_report("TCX framebuffer not available");
2102 } else if (strstart(p, "cg3", &opts)) {
2103 if (cg3_vga_available()) {
2104 vga_interface_type = VGA_CG3;
2106 error_report("CG3 framebuffer not available");
2109 } else if (!strstart(p, "none", &opts)) {
2111 error_report("unknown vga type: %s", p);
2115 const char *nextopt;
2117 if (strstart(opts, ",retrace=", &nextopt)) {
2119 if (strstart(opts, "dumb", &nextopt))
2120 vga_retrace_method = VGA_RETRACE_DUMB;
2121 else if (strstart(opts, "precise", &nextopt))
2122 vga_retrace_method = VGA_RETRACE_PRECISE;
2123 else goto invalid_vga;
2124 } else goto invalid_vga;
2129 static DisplayType select_display(const char *p)
2132 DisplayType display = DT_DEFAULT;
2134 if (strstart(p, "sdl", &opts)) {
2138 const char *nextopt;
2140 if (strstart(opts, ",frame=", &nextopt)) {
2142 if (strstart(opts, "on", &nextopt)) {
2144 } else if (strstart(opts, "off", &nextopt)) {
2147 goto invalid_sdl_args;
2149 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
2151 if (strstart(opts, "on", &nextopt)) {
2153 } else if (strstart(opts, "off", &nextopt)) {
2156 goto invalid_sdl_args;
2158 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
2160 if (strstart(opts, "on", &nextopt)) {
2162 } else if (strstart(opts, "off", &nextopt)) {
2165 goto invalid_sdl_args;
2167 } else if (strstart(opts, ",window_close=", &nextopt)) {
2169 if (strstart(opts, "on", &nextopt)) {
2171 } else if (strstart(opts, "off", &nextopt)) {
2174 goto invalid_sdl_args;
2176 } else if (strstart(opts, ",gl=", &nextopt)) {
2178 if (strstart(opts, "on", &nextopt)) {
2180 } else if (strstart(opts, "off", &nextopt)) {
2183 goto invalid_sdl_args;
2187 error_report("invalid SDL option string");
2193 error_report("SDL support is disabled");
2196 } else if (strstart(p, "vnc", &opts)) {
2200 if (vnc_parse(opts + 1, &err) == NULL) {
2201 error_report_err(err);
2205 error_report("VNC requires a display argument vnc=<display>");
2209 error_report("VNC support is disabled");
2212 } else if (strstart(p, "curses", &opts)) {
2213 #ifdef CONFIG_CURSES
2214 display = DT_CURSES;
2216 error_report("curses support is disabled");
2219 } else if (strstart(p, "gtk", &opts)) {
2223 const char *nextopt;
2225 if (strstart(opts, ",grab_on_hover=", &nextopt)) {
2227 if (strstart(opts, "on", &nextopt)) {
2228 grab_on_hover = true;
2229 } else if (strstart(opts, "off", &nextopt)) {
2230 grab_on_hover = false;
2232 goto invalid_gtk_args;
2234 } else if (strstart(opts, ",gl=", &nextopt)) {
2236 if (strstart(opts, "on", &nextopt)) {
2238 } else if (strstart(opts, "off", &nextopt)) {
2241 goto invalid_gtk_args;
2245 error_report("invalid GTK option string");
2251 error_report("GTK support is disabled");
2255 } else if (strstart(p, "maru_remote_spice", &opts)) {
2256 # ifdef CONFIG_SPICE
2257 display = DT_MARU_REMOTE_SPICE;
2259 fprintf(stderr, "maru_remote_spice is disabled\n");
2262 } else if (strstart(p, "maru_qt", &opts)) {
2264 display = DT_MARU_QT_ONSCREEN;
2266 const char *nextopt;
2267 if (strstart(opts, ",rendering=", &nextopt)) {
2269 if (strstart(opts, "onscreen", &nextopt)) {
2270 display = DT_MARU_QT_ONSCREEN;
2271 } else if (strstart(opts, "offscreen", &nextopt)) {
2272 display = DT_MARU_QT_OFFSCREEN;
2274 goto invalid_maru_qt_args;
2276 } else if (strstart(opts, ",resolution=", &nextopt)) {
2278 char *endptr = NULL;
2279 // Resolution should be formed "640x480" or "640*480".
2280 int width = (int)g_ascii_strtoll(opts, &endptr, 10);
2281 int height = (int)g_ascii_strtoll(++endptr, &endptr, 10);
2282 if (width <= 0 || height <= 0) {
2283 goto invalid_maru_qt_args;
2285 set_initial_display_resolution(width, height);
2287 } else if (strstart(opts, ",dpi=", &nextopt)) {
2289 char *endptr = NULL;
2290 int dpi = (int)g_ascii_strtoll(opts, &endptr, 10);
2292 goto invalid_maru_qt_args;
2294 set_display_pixel_density(dpi);
2297 invalid_maru_qt_args:
2298 error_report(FAILED_TO_DISPLAY_PARSING);
2304 error_report("maru_qt is disabled.\n");
2308 #endif /* CONFIG_MARU */
2309 } else if (strstart(p, "none", &opts)) {
2312 error_report("unknown display type");
2319 static int balloon_parse(const char *arg)
2323 if (strcmp(arg, "none") == 0) {
2327 if (!strncmp(arg, "virtio", 6)) {
2328 if (arg[6] == ',') {
2329 /* have params -> parse them */
2330 opts = qemu_opts_parse_noisily(qemu_find_opts("device"), arg + 7,
2335 /* create empty opts */
2336 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
2339 qemu_opt_set(opts, "driver", "virtio-balloon", &error_abort);
2346 char *qemu_find_file(int type, const char *name)
2352 /* Try the name as a straight path first */
2353 if (access(name, R_OK) == 0) {
2354 trace_load_file(name, name);
2355 return g_strdup(name);
2359 case QEMU_FILE_TYPE_BIOS:
2362 case QEMU_FILE_TYPE_KEYMAP:
2363 subdir = "keymaps/";
2369 for (i = 0; i < data_dir_idx; i++) {
2370 buf = g_strdup_printf("%s/%s%s", data_dir[i], subdir, name);
2371 if (access(buf, R_OK) == 0) {
2372 trace_load_file(name, buf);
2380 static inline bool nonempty_str(const char *str)
2385 static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)
2389 const char *name, *file, *str;
2390 FWCfgState *fw_cfg = (FWCfgState *) opaque;
2392 if (fw_cfg == NULL) {
2393 error_report("fw_cfg device not available");
2396 name = qemu_opt_get(opts, "name");
2397 file = qemu_opt_get(opts, "file");
2398 str = qemu_opt_get(opts, "string");
2400 /* we need name and either a file or the content string */
2401 if (!(nonempty_str(name) && (nonempty_str(file) || nonempty_str(str)))) {
2402 error_report("invalid argument(s)");
2405 if (nonempty_str(file) && nonempty_str(str)) {
2406 error_report("file and string are mutually exclusive");
2409 if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) {
2410 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH - 1);
2413 if (strncmp(name, "opt/", 4) != 0) {
2414 error_report("warning: externally provided fw_cfg item names "
2415 "should be prefixed with \"opt/\"");
2417 if (nonempty_str(str)) {
2418 size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */
2419 buf = g_memdup(str, size);
2421 if (!g_file_get_contents(file, &buf, &size, NULL)) {
2422 error_report("can't load %s", file);
2426 /* For legacy, keep user files in a specific global order. */
2427 fw_cfg_set_order_override(fw_cfg, FW_CFG_ORDER_OVERRIDE_USER);
2428 fw_cfg_add_file(fw_cfg, name, buf, size);
2429 fw_cfg_reset_order_override(fw_cfg);
2433 static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)
2435 return qdev_device_help(opts);
2438 static int device_init_func(void *opaque, QemuOpts *opts, Error **errp)
2443 dev = qdev_device_add(opts, &err);
2445 error_report_err(err);
2448 object_unref(OBJECT(dev));
2452 static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
2454 Error *local_err = NULL;
2456 qemu_chr_new_from_opts(opts, NULL, &local_err);
2458 error_report_err(local_err);
2464 #ifdef CONFIG_VIRTFS
2465 static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
2468 ret = qemu_fsdev_add(opts);
2474 static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
2476 CharDriverState *chr;
2477 const char *chardev;
2481 mode = qemu_opt_get(opts, "mode");
2485 if (strcmp(mode, "readline") == 0) {
2486 flags = MONITOR_USE_READLINE;
2487 } else if (strcmp(mode, "control") == 0) {
2488 flags = MONITOR_USE_CONTROL;
2490 error_report("unknown monitor mode \"%s\"", mode);
2494 if (qemu_opt_get_bool(opts, "pretty", 0))
2495 flags |= MONITOR_USE_PRETTY;
2497 if (qemu_opt_get_bool(opts, "default", 0))
2498 flags |= MONITOR_IS_DEFAULT;
2500 chardev = qemu_opt_get(opts, "chardev");
2501 chr = qemu_chr_find(chardev);
2503 error_report("chardev \"%s\" not found", chardev);
2507 qemu_chr_fe_claim_no_fail(chr);
2508 monitor_init(chr, flags);
2512 static void monitor_parse(const char *optarg, const char *mode, bool pretty)
2514 static int monitor_device_index = 0;
2515 Error *local_err = NULL;
2521 if (strstart(optarg, "chardev:", &p)) {
2522 snprintf(label, sizeof(label), "%s", p);
2524 snprintf(label, sizeof(label), "compat_monitor%d",
2525 monitor_device_index);
2526 if (monitor_device_index == 0) {
2529 opts = qemu_chr_parse_compat(label, optarg);
2531 error_report("parse error: %s", optarg);
2536 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &local_err);
2538 error_report_err(local_err);
2541 qemu_opt_set(opts, "mode", mode, &error_abort);
2542 qemu_opt_set(opts, "chardev", label, &error_abort);
2543 qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
2545 qemu_opt_set(opts, "default", "on", &error_abort);
2546 monitor_device_index++;
2549 struct device_config {
2551 DEV_USB, /* -usbdevice */
2553 DEV_SERIAL, /* -serial */
2554 DEV_PARALLEL, /* -parallel */
2555 DEV_VIRTCON, /* -virtioconsole */
2556 DEV_DEBUGCON, /* -debugcon */
2557 DEV_GDB, /* -gdb, -s */
2558 DEV_SCLP, /* s390 sclp */
2560 const char *cmdline;
2562 QTAILQ_ENTRY(device_config) next;
2565 static QTAILQ_HEAD(, device_config) device_configs =
2566 QTAILQ_HEAD_INITIALIZER(device_configs);
2568 static void add_device_config(int type, const char *cmdline)
2570 struct device_config *conf;
2572 conf = g_malloc0(sizeof(*conf));
2574 conf->cmdline = cmdline;
2575 loc_save(&conf->loc);
2576 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
2579 static int foreach_device_config(int type, int (*func)(const char *cmdline))
2581 struct device_config *conf;
2584 QTAILQ_FOREACH(conf, &device_configs, next) {
2585 if (conf->type != type)
2587 loc_push_restore(&conf->loc);
2588 rc = func(conf->cmdline);
2589 loc_pop(&conf->loc);
2597 static int serial_parse(const char *devname)
2599 static int index = 0;
2602 if (strcmp(devname, "none") == 0)
2604 if (index == MAX_SERIAL_PORTS) {
2605 error_report("too many serial ports");
2608 snprintf(label, sizeof(label), "serial%d", index);
2609 serial_hds[index] = qemu_chr_new(label, devname, NULL);
2610 if (!serial_hds[index]) {
2611 error_report("could not connect serial device"
2612 " to character backend '%s'", devname);
2619 static int parallel_parse(const char *devname)
2621 static int index = 0;
2624 if (strcmp(devname, "none") == 0)
2626 if (index == MAX_PARALLEL_PORTS) {
2627 error_report("too many parallel ports");
2630 snprintf(label, sizeof(label), "parallel%d", index);
2631 parallel_hds[index] = qemu_chr_new(label, devname, NULL);
2632 if (!parallel_hds[index]) {
2633 error_report("could not connect parallel device"
2634 " to character backend '%s'", devname);
2641 static int virtcon_parse(const char *devname)
2643 QemuOptsList *device = qemu_find_opts("device");
2644 static int index = 0;
2646 QemuOpts *bus_opts, *dev_opts;
2648 if (strcmp(devname, "none") == 0)
2650 if (index == MAX_VIRTIO_CONSOLES) {
2651 error_report("too many virtio consoles");
2655 bus_opts = qemu_opts_create(device, NULL, 0, &error_abort);
2656 qemu_opt_set(bus_opts, "driver", "virtio-serial", &error_abort);
2658 dev_opts = qemu_opts_create(device, NULL, 0, &error_abort);
2659 qemu_opt_set(dev_opts, "driver", "virtconsole", &error_abort);
2661 snprintf(label, sizeof(label), "virtcon%d", index);
2662 virtcon_hds[index] = qemu_chr_new(label, devname, NULL);
2663 if (!virtcon_hds[index]) {
2664 error_report("could not connect virtio console"
2665 " to character backend '%s'", devname);
2668 qemu_opt_set(dev_opts, "chardev", label, &error_abort);
2674 static int sclp_parse(const char *devname)
2676 QemuOptsList *device = qemu_find_opts("device");
2677 static int index = 0;
2681 if (strcmp(devname, "none") == 0) {
2684 if (index == MAX_SCLP_CONSOLES) {
2685 error_report("too many sclp consoles");
2689 assert(arch_type == QEMU_ARCH_S390X);
2691 dev_opts = qemu_opts_create(device, NULL, 0, NULL);
2692 qemu_opt_set(dev_opts, "driver", "sclpconsole", &error_abort);
2694 snprintf(label, sizeof(label), "sclpcon%d", index);
2695 sclp_hds[index] = qemu_chr_new(label, devname, NULL);
2696 if (!sclp_hds[index]) {
2697 error_report("could not connect sclp console"
2698 " to character backend '%s'", devname);
2701 qemu_opt_set(dev_opts, "chardev", label, &error_abort);
2707 static int debugcon_parse(const char *devname)
2711 if (!qemu_chr_new("debugcon", devname, NULL)) {
2714 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL);
2716 error_report("already have a debugcon device");
2719 qemu_opt_set(opts, "driver", "isa-debugcon", &error_abort);
2720 qemu_opt_set(opts, "chardev", "debugcon", &error_abort);
2724 static gint machine_class_cmp(gconstpointer a, gconstpointer b)
2726 const MachineClass *mc1 = a, *mc2 = b;
2729 if (mc1->family == NULL) {
2730 if (mc2->family == NULL) {
2731 /* Compare standalone machine types against each other; they sort
2732 * in increasing order.
2734 return strcmp(object_class_get_name(OBJECT_CLASS(mc1)),
2735 object_class_get_name(OBJECT_CLASS(mc2)));
2738 /* Standalone machine types sort after families. */
2742 if (mc2->family == NULL) {
2743 /* Families sort before standalone machine types. */
2747 /* Families sort between each other alphabetically increasingly. */
2748 res = strcmp(mc1->family, mc2->family);
2753 /* Within the same family, machine types sort in decreasing order. */
2754 return strcmp(object_class_get_name(OBJECT_CLASS(mc2)),
2755 object_class_get_name(OBJECT_CLASS(mc1)));
2758 static MachineClass *machine_parse(const char *name)
2760 MachineClass *mc = NULL;
2761 GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false);
2764 mc = find_machine(name);
2767 g_slist_free(machines);
2770 if (name && !is_help_option(name)) {
2771 error_report("unsupported machine type");
2772 error_printf("Use -machine help to list supported machines\n");
2774 printf("Supported machines are:\n");
2775 machines = g_slist_sort(machines, machine_class_cmp);
2776 for (el = machines; el; el = el->next) {
2777 MachineClass *mc = el->data;
2779 printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name);
2781 printf("%-20s %s%s\n", mc->name, mc->desc,
2782 mc->is_default ? " (default)" : "");
2786 g_slist_free(machines);
2787 exit(!name || !is_help_option(name));
2790 void qemu_add_exit_notifier(Notifier *notify)
2792 notifier_list_add(&exit_notifiers, notify);
2795 void qemu_remove_exit_notifier(Notifier *notify)
2797 notifier_remove(notify);
2800 static void qemu_run_exit_notifiers(void)
2802 notifier_list_notify(&exit_notifiers, NULL);
2805 static bool machine_init_done;
2807 void qemu_add_machine_init_done_notifier(Notifier *notify)
2809 notifier_list_add(&machine_init_done_notifiers, notify);
2810 if (machine_init_done) {
2811 notify->notify(notify, NULL);
2815 static void qemu_run_machine_init_done_notifiers(void)
2817 notifier_list_notify(&machine_init_done_notifiers, NULL);
2818 machine_init_done = true;
2821 static const QEMUOption *lookup_opt(int argc, char **argv,
2822 const char **poptarg, int *poptind)
2824 const QEMUOption *popt;
2825 int optind = *poptind;
2826 char *r = argv[optind];
2829 loc_set_cmdline(argv, optind, 1);
2831 /* Treat --foo the same as -foo. */
2834 popt = qemu_options;
2837 error_report("invalid option");
2840 if (!strcmp(popt->name, r + 1))
2844 if (popt->flags & HAS_ARG) {
2845 if (optind >= argc) {
2846 error_report("requires an argument");
2849 optarg = argv[optind++];
2850 loc_set_cmdline(argv, optind - 2, 2);
2861 static MachineClass *select_machine(void)
2863 MachineClass *machine_class = find_default_machine();
2868 loc_push_none(&loc);
2870 opts = qemu_get_machine_opts();
2871 qemu_opts_loc_restore(opts);
2873 optarg = qemu_opt_get(opts, "type");
2875 machine_class = machine_parse(optarg);
2878 if (!machine_class) {
2879 error_report("No machine specified, and there is no default");
2880 error_printf("Use -machine help to list supported machines\n");
2885 return machine_class;
2888 static int machine_set_property(void *opaque,
2889 const char *name, const char *value,
2892 Object *obj = OBJECT(opaque);
2893 Error *local_err = NULL;
2896 if (strcmp(name, "type") == 0) {
2900 qom_name = g_strdup(name);
2908 object_property_parse(obj, value, qom_name, &local_err);
2912 error_report_err(local_err);
2921 * Initial object creation happens before all other
2922 * QEMU data types are created. The majority of objects
2923 * can be created at this point. The rng-egd object
2924 * cannot be created here, as it depends on the chardev
2927 static bool object_create_initial(const char *type)
2929 if (g_str_equal(type, "rng-egd")) {
2934 * return false for concrete netfilters since
2935 * they depend on netdevs already existing
2937 if (g_str_equal(type, "filter-buffer") ||
2938 g_str_equal(type, "filter-dump") ||
2939 g_str_equal(type, "filter-mirror") ||
2940 g_str_equal(type, "filter-redirector")) {
2949 * The remainder of object creation happens after the
2950 * creation of chardev, fsdev, net clients and device data types.
2952 static bool object_create_delayed(const char *type)
2954 return !object_create_initial(type);
2958 static void set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
2962 const char *mem_str;
2963 const char *maxmem_str, *slots_str;
2964 const ram_addr_t default_ram_size = mc->default_ram_size;
2965 QemuOpts *opts = qemu_find_opts_singleton("memory");
2968 loc_push_none(&loc);
2969 qemu_opts_loc_restore(opts);
2972 mem_str = qemu_opt_get(opts, "size");
2975 error_report("missing 'size' option value");
2979 sz = qemu_opt_get_size(opts, "size", ram_size);
2981 /* Fix up legacy suffix-less format */
2982 if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) {
2983 uint64_t overflow_check = sz;
2986 if ((sz >> 20) != overflow_check) {
2987 error_report("too large 'size' option value");
2993 /* backward compatibility behaviour for case "-m 0" */
2995 sz = default_ram_size;
2998 sz = QEMU_ALIGN_UP(sz, 8192);
3000 if (ram_size != sz) {
3001 error_report("ram size too large");
3005 /* store value for the future use */
3006 qemu_opt_set_number(opts, "size", ram_size, &error_abort);
3007 *maxram_size = ram_size;
3009 maxmem_str = qemu_opt_get(opts, "maxmem");
3010 slots_str = qemu_opt_get(opts, "slots");
3011 if (maxmem_str && slots_str) {
3014 sz = qemu_opt_get_size(opts, "maxmem", 0);
3015 slots = qemu_opt_get_number(opts, "slots", 0);
3016 if (sz < ram_size) {
3017 error_report("invalid value of -m option maxmem: "
3018 "maximum memory size (0x%" PRIx64 ") must be at least "
3019 "the initial memory size (0x" RAM_ADDR_FMT ")",
3022 } else if (sz > ram_size) {
3024 error_report("invalid value of -m option: maxmem was "
3025 "specified, but no hotplug slots were specified");
3029 error_report("invalid value of -m option maxmem: "
3030 "memory slots were specified but maximum memory size "
3031 "(0x%" PRIx64 ") is equal to the initial memory size "
3032 "(0x" RAM_ADDR_FMT ")", sz, ram_size);
3038 } else if ((!maxmem_str && slots_str) ||
3039 (maxmem_str && !slots_str)) {
3040 error_report("invalid -m option value: missing "
3041 "'%s' option", slots_str ? "maxmem" : "slots");
3049 // W/A for preserve larger continuous heap for RAM.
3050 extern void *preallocated_ram_ptr;
3051 extern int preallocated_ram_size;
3053 int main(int argc, char **argv, char **envp)
3056 int snapshot, linux_boot;
3057 const char *initrd_filename;
3058 const char *kernel_filename, *kernel_cmdline;
3059 const char *boot_order = NULL;
3060 const char *boot_once = NULL;
3062 int cyls, heads, secs, translation;
3063 QemuOpts *hda_opts = NULL, *opts, *machine_opts, *icount_opts = NULL;
3064 QemuOptsList *olist;
3067 const char *loadvm = NULL;
3068 MachineClass *machine_class;
3069 const char *cpu_model;
3070 const char *vga_model = NULL;
3071 const char *qtest_chrdev = NULL;
3072 const char *qtest_log = NULL;
3073 const char *pid_file = NULL;
3074 const char *incoming = NULL;
3076 int show_vnc_port = 0;
3078 bool defconfig = true;
3079 bool userconfig = true;
3080 const char *log_mask = NULL;
3081 const char *log_file = NULL;
3082 char *trace_file = NULL;
3083 ram_addr_t maxram_size;
3084 uint64_t ram_slots = 0;
3085 FILE *vmstate_dump_file = NULL;
3086 Error *main_loop_err = NULL;
3089 static bool yagl_enabled = false;
3090 #endif /* CONFIG_YAGL */
3092 static bool vigs_enabled = false;
3093 static char *vigs_backend = NULL;
3094 #endif /* CONFIG_VIGS */
3096 qemu_init_cpu_loop();
3097 qemu_mutex_lock_iothread();
3099 atexit(qemu_run_exit_notifiers);
3100 error_set_progname(argv[0]);
3101 qemu_init_exec_dir(argv[0]);
3103 module_call_init(MODULE_INIT_QOM);
3105 qemu_add_opts(&qemu_drive_opts);
3106 qemu_add_drive_opts(&qemu_legacy_drive_opts);
3107 qemu_add_drive_opts(&qemu_common_drive_opts);
3108 qemu_add_drive_opts(&qemu_drive_opts);
3109 qemu_add_opts(&qemu_chardev_opts);
3110 qemu_add_opts(&qemu_device_opts);
3111 qemu_add_opts(&qemu_netdev_opts);
3112 qemu_add_opts(&qemu_net_opts);
3113 qemu_add_opts(&qemu_rtc_opts);
3114 qemu_add_opts(&qemu_global_opts);
3115 qemu_add_opts(&qemu_mon_opts);
3116 qemu_add_opts(&qemu_trace_opts);
3117 qemu_add_opts(&qemu_option_rom_opts);
3118 qemu_add_opts(&qemu_machine_opts);
3119 qemu_add_opts(&qemu_mem_opts);
3120 qemu_add_opts(&qemu_smp_opts);
3121 qemu_add_opts(&qemu_boot_opts);
3122 qemu_add_opts(&qemu_sandbox_opts);
3123 qemu_add_opts(&qemu_add_fd_opts);
3124 qemu_add_opts(&qemu_object_opts);
3125 qemu_add_opts(&qemu_tpmdev_opts);
3126 qemu_add_opts(&qemu_realtime_opts);
3127 qemu_add_opts(&qemu_msg_opts);
3128 qemu_add_opts(&qemu_name_opts);
3129 qemu_add_opts(&qemu_numa_opts);
3130 qemu_add_opts(&qemu_icount_opts);
3131 qemu_add_opts(&qemu_semihosting_config_opts);
3132 qemu_add_opts(&qemu_fw_cfg_opts);
3133 module_call_init(MODULE_INIT_OPTS);
3137 if (qcrypto_init(&err) < 0) {
3138 error_reportf_err(err, "cannot initialize crypto: ");
3141 rtc_clock = QEMU_CLOCK_HOST;
3143 QLIST_INIT (&vm_change_state_head);
3144 os_setup_early_signal_handling();
3148 cyls = heads = secs = 0;
3149 translation = BIOS_ATA_TRANSLATION_AUTO;
3153 bdrv_init_with_whitelist();
3157 /* first pass of option parsing */
3159 while (optind < argc) {
3160 if (argv[optind][0] != '-') {
3164 const QEMUOption *popt;
3166 popt = lookup_opt(argc, argv, &optarg, &optind);
3167 switch (popt->index) {
3168 case QEMU_OPTION_nodefconfig:
3171 case QEMU_OPTION_nouserconfig:
3180 ret = qemu_read_default_config_files(userconfig);
3186 /* second pass of option parsing */
3191 if (argv[optind][0] != '-') {
3192 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
3194 const QEMUOption *popt;
3196 popt = lookup_opt(argc, argv, &optarg, &optind);
3197 if (!(popt->arch_mask & arch_type)) {
3198 printf("Option %s not supported for this target\n", popt->name);
3201 switch(popt->index) {
3202 case QEMU_OPTION_no_kvm_irqchip: {
3203 olist = qemu_find_opts("machine");
3204 qemu_opts_parse_noisily(olist, "kernel_irqchip=off", false);
3207 case QEMU_OPTION_cpu:
3208 /* hw initialization will check this */
3211 case QEMU_OPTION_hda:
3215 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
3217 snprintf(buf, sizeof(buf),
3218 "%s,cyls=%d,heads=%d,secs=%d%s",
3219 HD_OPTS , cyls, heads, secs,
3220 translation == BIOS_ATA_TRANSLATION_LBA ?
3222 translation == BIOS_ATA_TRANSLATION_NONE ?
3223 ",trans=none" : "");
3224 drive_add(IF_DEFAULT, 0, optarg, buf);
3227 case QEMU_OPTION_hdb:
3228 case QEMU_OPTION_hdc:
3229 case QEMU_OPTION_hdd:
3230 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
3233 case QEMU_OPTION_drive:
3234 if (drive_def(optarg) == NULL) {
3238 case QEMU_OPTION_set:
3239 if (qemu_set_option(optarg) != 0)
3242 case QEMU_OPTION_global:
3243 if (qemu_global_option(optarg) != 0)
3246 case QEMU_OPTION_mtdblock:
3247 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
3249 case QEMU_OPTION_sd:
3250 drive_add(IF_SD, -1, optarg, SD_OPTS);
3252 case QEMU_OPTION_pflash:
3253 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
3255 case QEMU_OPTION_snapshot:
3258 case QEMU_OPTION_hdachs:
3262 cyls = strtol(p, (char **)&p, 0);
3263 if (cyls < 1 || cyls > 16383)
3268 heads = strtol(p, (char **)&p, 0);
3269 if (heads < 1 || heads > 16)
3274 secs = strtol(p, (char **)&p, 0);
3275 if (secs < 1 || secs > 63)
3279 if (!strcmp(p, "large")) {
3280 translation = BIOS_ATA_TRANSLATION_LARGE;
3281 } else if (!strcmp(p, "rechs")) {
3282 translation = BIOS_ATA_TRANSLATION_RECHS;
3283 } else if (!strcmp(p, "none")) {
3284 translation = BIOS_ATA_TRANSLATION_NONE;
3285 } else if (!strcmp(p, "lba")) {
3286 translation = BIOS_ATA_TRANSLATION_LBA;
3287 } else if (!strcmp(p, "auto")) {
3288 translation = BIOS_ATA_TRANSLATION_AUTO;
3292 } else if (*p != '\0') {
3294 error_report("invalid physical CHS format");
3297 if (hda_opts != NULL) {
3298 qemu_opt_set_number(hda_opts, "cyls", cyls,
3300 qemu_opt_set_number(hda_opts, "heads", heads,
3302 qemu_opt_set_number(hda_opts, "secs", secs,
3304 if (translation == BIOS_ATA_TRANSLATION_LARGE) {
3305 qemu_opt_set(hda_opts, "trans", "large",
3307 } else if (translation == BIOS_ATA_TRANSLATION_RECHS) {
3308 qemu_opt_set(hda_opts, "trans", "rechs",
3310 } else if (translation == BIOS_ATA_TRANSLATION_LBA) {
3311 qemu_opt_set(hda_opts, "trans", "lba",
3313 } else if (translation == BIOS_ATA_TRANSLATION_NONE) {
3314 qemu_opt_set(hda_opts, "trans", "none",
3320 case QEMU_OPTION_numa:
3321 opts = qemu_opts_parse_noisily(qemu_find_opts("numa"),
3327 case QEMU_OPTION_display:
3328 display_type = select_display(optarg);
3330 case QEMU_OPTION_nographic:
3331 display_type = DT_NOGRAPHIC;
3333 case QEMU_OPTION_curses:
3334 #ifdef CONFIG_CURSES
3335 display_type = DT_CURSES;
3337 error_report("curses support is disabled");
3341 case QEMU_OPTION_portrait:
3342 graphic_rotate = 90;
3344 case QEMU_OPTION_rotate:
3345 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
3346 if (graphic_rotate != 0 && graphic_rotate != 90 &&
3347 graphic_rotate != 180 && graphic_rotate != 270) {
3348 error_report("only 90, 180, 270 deg rotation is available");
3352 case QEMU_OPTION_kernel:
3353 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg,
3356 case QEMU_OPTION_initrd:
3357 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg,
3360 case QEMU_OPTION_append:
3361 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg,
3364 case QEMU_OPTION_dtb:
3365 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg,
3368 case QEMU_OPTION_cdrom:
3369 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
3371 case QEMU_OPTION_boot:
3372 opts = qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3378 case QEMU_OPTION_fda:
3379 case QEMU_OPTION_fdb:
3380 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
3383 case QEMU_OPTION_no_fd_bootchk:
3386 case QEMU_OPTION_netdev:
3387 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
3391 case QEMU_OPTION_net:
3392 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
3396 #ifdef CONFIG_LIBISCSI
3397 case QEMU_OPTION_iscsi:
3398 opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3406 case QEMU_OPTION_tftp:
3407 error_report("The -tftp option is deprecated. "
3408 "Please use '-netdev user,tftp=...' instead.");
3409 legacy_tftp_prefix = optarg;
3411 case QEMU_OPTION_bootp:
3412 error_report("The -bootp option is deprecated. "
3413 "Please use '-netdev user,bootfile=...' instead.");
3414 legacy_bootp_filename = optarg;
3416 case QEMU_OPTION_redir:
3417 error_report("The -redir option is deprecated. "
3418 "Please use '-netdev user,hostfwd=...' instead.");
3419 if (net_slirp_redir(optarg) < 0)
3423 case QEMU_OPTION_bt:
3424 add_device_config(DEV_BT, optarg);
3426 case QEMU_OPTION_audio_help:
3430 case QEMU_OPTION_soundhw:
3431 select_soundhw (optarg);
3436 case QEMU_OPTION_version:
3441 opts = qemu_opts_parse_noisily(qemu_find_opts("memory"),
3448 case QEMU_OPTION_tpmdev:
3449 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
3454 case QEMU_OPTION_mempath:
3457 case QEMU_OPTION_mem_prealloc:
3466 case QEMU_OPTION_DFILTER:
3467 qemu_set_dfilter_ranges(optarg);
3470 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
3472 case QEMU_OPTION_gdb:
3473 add_device_config(DEV_GDB, optarg);
3476 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
3477 data_dir[data_dir_idx++] = optarg;
3480 case QEMU_OPTION_bios:
3481 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg,
3484 case QEMU_OPTION_singlestep:
3491 keyboard_layout = optarg;
3493 case QEMU_OPTION_localtime:
3496 case QEMU_OPTION_vga:
3505 w = strtol(p, (char **)&p, 10);
3508 error_report("invalid resolution or depth");
3514 h = strtol(p, (char **)&p, 10);
3519 depth = strtol(p, (char **)&p, 10);
3520 if (depth != 8 && depth != 15 && depth != 16 &&
3521 depth != 24 && depth != 32)
3523 } else if (*p == '\0') {
3524 depth = graphic_depth;
3531 graphic_depth = depth;
3534 case QEMU_OPTION_echr:
3537 term_escape_char = strtol(optarg, &r, 0);
3539 printf("Bad argument to echr\n");
3542 case QEMU_OPTION_monitor:
3543 default_monitor = 0;
3544 if (strncmp(optarg, "none", 4)) {
3545 monitor_parse(optarg, "readline", false);
3548 case QEMU_OPTION_qmp:
3549 monitor_parse(optarg, "control", false);
3550 default_monitor = 0;
3552 case QEMU_OPTION_qmp_pretty:
3553 monitor_parse(optarg, "control", true);
3554 default_monitor = 0;
3556 case QEMU_OPTION_mon:
3557 opts = qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg,
3562 default_monitor = 0;
3564 case QEMU_OPTION_chardev:
3565 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3571 case QEMU_OPTION_fsdev:
3572 olist = qemu_find_opts("fsdev");
3574 error_report("fsdev support is disabled");
3577 opts = qemu_opts_parse_noisily(olist, optarg, true);
3582 case QEMU_OPTION_virtfs: {
3585 const char *writeout, *sock_fd, *socket;
3587 olist = qemu_find_opts("virtfs");
3589 error_report("virtfs support is disabled");
3592 opts = qemu_opts_parse_noisily(olist, optarg, true);
3597 if (qemu_opt_get(opts, "fsdriver") == NULL ||
3598 qemu_opt_get(opts, "mount_tag") == NULL) {
3599 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3602 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
3603 qemu_opt_get(opts, "mount_tag"),
3606 error_report("duplicate fsdev id: %s",
3607 qemu_opt_get(opts, "mount_tag"));
3611 writeout = qemu_opt_get(opts, "writeout");
3613 #ifdef CONFIG_SYNC_FILE_RANGE
3614 qemu_opt_set(fsdev, "writeout", writeout, &error_abort);
3616 error_report("writeout=immediate not supported "
3617 "on this platform");
3621 qemu_opt_set(fsdev, "fsdriver",
3622 qemu_opt_get(opts, "fsdriver"), &error_abort);
3623 qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"),
3625 qemu_opt_set(fsdev, "security_model",
3626 qemu_opt_get(opts, "security_model"),
3628 socket = qemu_opt_get(opts, "socket");
3630 qemu_opt_set(fsdev, "socket", socket, &error_abort);
3632 sock_fd = qemu_opt_get(opts, "sock_fd");
3634 qemu_opt_set(fsdev, "sock_fd", sock_fd, &error_abort);
3637 qemu_opt_set_bool(fsdev, "readonly",
3638 qemu_opt_get_bool(opts, "readonly", 0),
3640 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3642 qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort);
3643 qemu_opt_set(device, "fsdev",
3644 qemu_opt_get(opts, "mount_tag"), &error_abort);
3645 qemu_opt_set(device, "mount_tag",
3646 qemu_opt_get(opts, "mount_tag"), &error_abort);
3649 case QEMU_OPTION_virtfs_synth: {
3653 fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3656 error_report("duplicate option: %s", "virtfs_synth");
3659 qemu_opt_set(fsdev, "fsdriver", "synth", &error_abort);
3661 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3663 qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort);
3664 qemu_opt_set(device, "fsdev", "v_synth", &error_abort);
3665 qemu_opt_set(device, "mount_tag", "v_synth", &error_abort);
3668 case QEMU_OPTION_serial:
3669 add_device_config(DEV_SERIAL, optarg);
3671 if (strncmp(optarg, "mon:", 4) == 0) {
3672 default_monitor = 0;
3675 case QEMU_OPTION_watchdog:
3677 error_report("only one watchdog option may be given");
3682 case QEMU_OPTION_watchdog_action:
3683 if (select_watchdog_action(optarg) == -1) {
3684 error_report("unknown -watchdog-action parameter");
3688 case QEMU_OPTION_virtiocon:
3689 add_device_config(DEV_VIRTCON, optarg);
3690 default_virtcon = 0;
3691 if (strncmp(optarg, "mon:", 4) == 0) {
3692 default_monitor = 0;
3695 case QEMU_OPTION_parallel:
3696 add_device_config(DEV_PARALLEL, optarg);
3697 default_parallel = 0;
3698 if (strncmp(optarg, "mon:", 4) == 0) {
3699 default_monitor = 0;
3702 case QEMU_OPTION_debugcon:
3703 add_device_config(DEV_DEBUGCON, optarg);
3705 case QEMU_OPTION_loadvm:
3708 case QEMU_OPTION_full_screen:
3711 case QEMU_OPTION_no_frame:
3714 case QEMU_OPTION_alt_grab:
3717 case QEMU_OPTION_ctrl_grab:
3720 case QEMU_OPTION_no_quit:
3723 case QEMU_OPTION_sdl:
3725 display_type = DT_SDL;
3728 error_report("SDL support is disabled");
3731 case QEMU_OPTION_pidfile:
3734 case QEMU_OPTION_win2k_hack:
3735 win2k_install_hack = 1;
3737 case QEMU_OPTION_rtc_td_hack: {
3738 static GlobalProperty slew_lost_ticks[] = {
3740 .driver = "mc146818rtc",
3741 .property = "lost_tick_policy",
3744 { /* end of list */ }
3747 qdev_prop_register_global_list(slew_lost_ticks);
3750 case QEMU_OPTION_acpitable:
3751 opts = qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3756 do_acpitable_option(opts);
3758 case QEMU_OPTION_smbios:
3759 opts = qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3764 do_smbios_option(opts);
3766 case QEMU_OPTION_fwcfg:
3767 opts = qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3773 case QEMU_OPTION_enable_kvm:
3774 olist = qemu_find_opts("machine");
3775 qemu_opts_parse_noisily(olist, "accel=kvm", false);
3777 case QEMU_OPTION_enable_yagl:
3778 #if defined(CONFIG_YAGL)
3779 yagl_enabled = true;
3781 fprintf(stderr, "YaGL openGLES passthrough support is disabled,"
3782 " ignoring -enable-yagl\n");
3785 case QEMU_OPTION_enable_vigs:
3786 #if defined(CONFIG_VIGS)
3787 vigs_enabled = true;
3789 fprintf(stderr, "VIGS support is disabled,"
3790 " ignoring -enable-vigs\n");
3793 case QEMU_OPTION_vigs_backend:
3794 #if defined(CONFIG_VIGS)
3795 vigs_backend = g_strdup(optarg);
3797 fprintf(stderr, "VIGS support is disabled,"
3798 " ignoring -vigs-backend\n");
3802 case QEMU_OPTION_machine:
3803 olist = qemu_find_opts("machine");
3804 opts = qemu_opts_parse_noisily(olist, optarg, true);
3809 case QEMU_OPTION_no_kvm:
3810 olist = qemu_find_opts("machine");
3811 qemu_opts_parse_noisily(olist, "accel=tcg", false);
3813 case QEMU_OPTION_no_kvm_pit: {
3814 error_report("warning: ignoring deprecated option");
3817 case QEMU_OPTION_no_kvm_pit_reinjection: {
3818 static GlobalProperty kvm_pit_lost_tick_policy[] = {
3820 .driver = "kvm-pit",
3821 .property = "lost_tick_policy",
3824 { /* end of list */ }
3827 error_report("warning: deprecated, replaced by "
3828 "-global kvm-pit.lost_tick_policy=discard");
3829 qdev_prop_register_global_list(kvm_pit_lost_tick_policy);
3832 case QEMU_OPTION_usb:
3833 olist = qemu_find_opts("machine");
3834 qemu_opts_parse_noisily(olist, "usb=on", false);
3836 case QEMU_OPTION_usbdevice:
3837 olist = qemu_find_opts("machine");
3838 qemu_opts_parse_noisily(olist, "usb=on", false);
3839 add_device_config(DEV_USB, optarg);
3841 case QEMU_OPTION_device:
3842 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3847 case QEMU_OPTION_smp:
3848 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3853 case QEMU_OPTION_vnc:
3856 Error *local_err = NULL;
3858 if (vnc_parse(optarg, &local_err) == NULL) {
3859 error_report_err(local_err);
3863 error_report("VNC support is disabled");
3868 case QEMU_OPTION_no_acpi:
3871 case QEMU_OPTION_no_hpet:
3874 case QEMU_OPTION_balloon:
3875 if (balloon_parse(optarg) < 0) {
3876 error_report("unknown -balloon argument %s", optarg);
3880 case QEMU_OPTION_no_reboot:
3883 case QEMU_OPTION_no_shutdown:
3886 case QEMU_OPTION_show_cursor:
3889 case QEMU_OPTION_uuid:
3890 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
3891 error_report("failed to parse UUID string: wrong format");
3894 qemu_uuid_set = true;
3896 case QEMU_OPTION_option_rom:
3897 if (nb_option_roms >= MAX_OPTION_ROMS) {
3898 error_report("too many option ROMs");
3901 opts = qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3906 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
3907 option_rom[nb_option_roms].bootindex =
3908 qemu_opt_get_number(opts, "bootindex", -1);
3909 if (!option_rom[nb_option_roms].name) {
3910 error_report("Option ROM file is not specified");
3915 case QEMU_OPTION_semihosting:
3916 semihosting.enabled = true;
3917 semihosting.target = SEMIHOSTING_TARGET_AUTO;
3919 case QEMU_OPTION_semihosting_config:
3920 semihosting.enabled = true;
3921 opts = qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3924 semihosting.enabled = qemu_opt_get_bool(opts, "enable",
3926 const char *target = qemu_opt_get(opts, "target");
3927 if (target != NULL) {
3928 if (strcmp("native", target) == 0) {
3929 semihosting.target = SEMIHOSTING_TARGET_NATIVE;
3930 } else if (strcmp("gdb", target) == 0) {
3931 semihosting.target = SEMIHOSTING_TARGET_GDB;
3932 } else if (strcmp("auto", target) == 0) {
3933 semihosting.target = SEMIHOSTING_TARGET_AUTO;
3935 error_report("unsupported semihosting-config %s",
3940 semihosting.target = SEMIHOSTING_TARGET_AUTO;
3942 /* Set semihosting argument count and vector */
3943 qemu_opt_foreach(opts, add_semihosting_arg,
3944 &semihosting, NULL);
3946 error_report("unsupported semihosting-config %s", optarg);
3950 case QEMU_OPTION_tdf:
3951 error_report("warning: ignoring deprecated option");
3953 case QEMU_OPTION_name:
3954 opts = qemu_opts_parse_noisily(qemu_find_opts("name"),
3960 case QEMU_OPTION_prom_env:
3961 if (nb_prom_envs >= MAX_PROM_ENVS) {
3962 error_report("too many prom variables");
3965 prom_envs[nb_prom_envs] = optarg;
3968 case QEMU_OPTION_old_param:
3971 case QEMU_OPTION_clock:
3972 /* Clock options no longer exist. Keep this option for
3973 * backward compatibility.
3976 case QEMU_OPTION_startdate:
3977 configure_rtc_date_offset(optarg, 1);
3979 case QEMU_OPTION_rtc:
3980 opts = qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg,
3985 configure_rtc(opts);
3987 case QEMU_OPTION_tb_size:
3988 tcg_tb_size = strtol(optarg, NULL, 0);
3989 if (tcg_tb_size < 0) {
3993 case QEMU_OPTION_icount:
3994 icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"),
4000 case QEMU_OPTION_incoming:
4002 runstate_set(RUN_STATE_INMIGRATE);
4006 case QEMU_OPTION_nodefaults:
4009 case QEMU_OPTION_xen_domid:
4010 if (!(xen_available())) {
4011 printf("Option %s not supported for this target\n", popt->name);
4014 xen_domid = atoi(optarg);
4016 case QEMU_OPTION_xen_create:
4017 if (!(xen_available())) {
4018 printf("Option %s not supported for this target\n", popt->name);
4021 xen_mode = XEN_CREATE;
4023 case QEMU_OPTION_xen_attach:
4024 if (!(xen_available())) {
4025 printf("Option %s not supported for this target\n", popt->name);
4028 xen_mode = XEN_ATTACH;
4030 case QEMU_OPTION_trace:
4032 opts = qemu_opts_parse_noisily(qemu_find_opts("trace"),
4037 if (qemu_opt_get(opts, "enable")) {
4038 trace_enable_events(qemu_opt_get(opts, "enable"));
4040 trace_init_events(qemu_opt_get(opts, "events"));
4044 trace_file = g_strdup(qemu_opt_get(opts, "file"));
4045 qemu_opts_del(opts);
4048 case QEMU_OPTION_readconfig:
4050 int ret = qemu_read_config_file(optarg);
4052 error_report("read config %s: %s", optarg,
4058 case QEMU_OPTION_spice:
4059 olist = qemu_find_opts("spice");
4061 error_report("spice support is disabled");
4064 opts = qemu_opts_parse_noisily(olist, optarg, false);
4070 case QEMU_OPTION_writeconfig:
4073 if (strcmp(optarg, "-") == 0) {
4076 fp = fopen(optarg, "w");
4078 error_report("open %s: %s", optarg,
4083 qemu_config_write(fp);
4089 case QEMU_OPTION_qtest:
4090 qtest_chrdev = optarg;
4092 case QEMU_OPTION_qtest_log:
4095 case QEMU_OPTION_sandbox:
4096 opts = qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4102 case QEMU_OPTION_enable_hax:
4103 olist = qemu_find_opts("machine");
4104 qemu_opts_parse_noisily(olist, "accel=hax", false);
4106 case QEMU_OPTION_add_fd:
4108 opts = qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4114 error_report("File descriptor passing is disabled on this "
4119 #if defined(CONFIG_MARU)
4120 case QEMU_OPTION_enable_suspend:
4121 ecs_set_suspend_state(SUSPEND_UNLOCK);
4124 case QEMU_OPTION_object:
4125 opts = qemu_opts_parse_noisily(qemu_find_opts("object"),
4131 case QEMU_OPTION_realtime:
4132 opts = qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4137 enable_mlock = qemu_opt_get_bool(opts, "mlock", true);
4139 case QEMU_OPTION_msg:
4140 opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg,
4145 configure_msg(opts);
4147 case QEMU_OPTION_dump_vmstate:
4148 if (vmstate_dump_file) {
4149 error_report("only one '-dump-vmstate' "
4150 "option may be given");
4153 vmstate_dump_file = fopen(optarg, "w");
4154 if (vmstate_dump_file == NULL) {
4155 error_report("open %s: %s", optarg, strerror(errno));
4160 os_parse_cmd_args(popt->index, optarg);
4165 * Clear error location left behind by the loop.
4166 * Best done right after the loop. Do not insert code here!
4170 replay_configure(icount_opts);
4172 machine_class = select_machine();
4174 #if defined(CONFIG_MARU)
4175 if (is_maru_machine(machine_class)) {
4176 preallocated_ram_ptr = qemu_anon_ram_alloc(ram_size, NULL);
4177 if (preallocated_ram_ptr) {
4178 preallocated_ram_size = ram_size;
4183 set_memory_options(&ram_slots, &maxram_size, machine_class);
4187 if (qemu_init_main_loop(&main_loop_err)) {
4188 error_report_err(main_loop_err);
4192 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4193 parse_sandbox, NULL, NULL)) {
4197 if (qemu_opts_foreach(qemu_find_opts("name"),
4198 parse_name, NULL, NULL)) {
4203 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4204 parse_add_fd, NULL, NULL)) {
4208 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4209 cleanup_add_fd, NULL, NULL)) {
4214 current_machine = MACHINE(object_new(object_class_get_name(
4215 OBJECT_CLASS(machine_class))));
4216 if (machine_help_func(qemu_get_machine_opts(), current_machine)) {
4219 object_property_add_child(object_get_root(), "machine",
4220 OBJECT(current_machine), &error_abort);
4221 cpu_exec_init_all();
4223 if (machine_class->hw_version) {
4224 qemu_set_hw_version(machine_class->hw_version);
4227 /* Init CPU def lists, based on config
4228 * - Must be called after all the qemu_read_config_file() calls
4229 * - Must be called before list_cpus()
4230 * - Must be called before machine->init()
4234 if (cpu_model && is_help_option(cpu_model)) {
4235 list_cpus(stdout, &fprintf, cpu_model);
4239 if (!trace_init_backends()) {
4242 trace_init_file(trace_file);
4244 /* Open the logfile at this point and set the log mask if necessary.
4247 qemu_set_log_filename(log_file);
4252 mask = qemu_str_to_log_mask(log_mask);
4254 qemu_print_log_usage(stdout);
4262 /* If no data_dir is specified then try to find it relative to the
4264 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
4265 data_dir[data_dir_idx] = os_find_datadir();
4266 if (data_dir[data_dir_idx] != NULL) {
4270 /* If all else fails use the install path specified when building. */
4271 if (data_dir_idx < ARRAY_SIZE(data_dir)) {
4272 data_dir[data_dir_idx++] = CONFIG_QEMU_DATADIR;
4275 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
4277 machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */
4278 if (max_cpus > machine_class->max_cpus) {
4279 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4280 "supported by machine '%s' (%d)", max_cpus,
4281 machine_class->name, machine_class->max_cpus);
4286 * Get the default machine options from the machine if it is not already
4287 * specified either by the configuration file or by the command line.
4289 if (machine_class->default_machine_opts) {
4290 qemu_opts_set_defaults(qemu_find_opts("machine"),
4291 machine_class->default_machine_opts, 0);
4294 qemu_opts_foreach(qemu_find_opts("device"),
4295 default_driver_check, NULL, NULL);
4296 qemu_opts_foreach(qemu_find_opts("global"),
4297 default_driver_check, NULL, NULL);
4299 if (!vga_model && !default_vga) {
4300 vga_interface_type = VGA_DEVICE;
4302 if (!has_defaults || machine_class->no_serial) {
4305 if (!has_defaults || machine_class->no_parallel) {
4306 default_parallel = 0;
4308 if (!has_defaults || !machine_class->use_virtcon) {
4309 default_virtcon = 0;
4311 if (!has_defaults || !machine_class->use_sclp) {
4314 if (!has_defaults || machine_class->no_floppy) {
4317 if (!has_defaults || machine_class->no_cdrom) {
4320 if (!has_defaults || machine_class->no_sdcard) {
4323 if (!has_defaults) {
4324 default_monitor = 0;
4329 if (is_daemonized()) {
4330 /* According to documentation and historically, -nographic redirects
4331 * serial port, parallel port and monitor to stdio, which does not work
4332 * with -daemonize. We can redirect these to null instead, but since
4333 * -nographic is legacy, let's just error out.
4334 * We disallow -nographic only if all other ports are not redirected
4335 * explicitly, to not break existing legacy setups which uses
4336 * -nographic _and_ redirects all ports explicitly - this is valid
4337 * usage, -nographic is just a no-op in this case.
4339 if (display_type == DT_NOGRAPHIC
4340 && (default_parallel || default_serial
4341 || default_monitor || default_virtcon)) {
4342 error_report("-nographic cannot be used with -daemonize");
4345 #ifdef CONFIG_CURSES
4346 if (display_type == DT_CURSES) {
4347 error_report("curses display cannot be used with -daemonize");
4353 if (display_type == DT_NOGRAPHIC) {
4354 if (default_parallel)
4355 add_device_config(DEV_PARALLEL, "null");
4356 if (default_serial && default_monitor) {
4357 add_device_config(DEV_SERIAL, "mon:stdio");
4358 } else if (default_virtcon && default_monitor) {
4359 add_device_config(DEV_VIRTCON, "mon:stdio");
4360 } else if (default_sclp && default_monitor) {
4361 add_device_config(DEV_SCLP, "mon:stdio");
4364 add_device_config(DEV_SERIAL, "stdio");
4365 if (default_virtcon)
4366 add_device_config(DEV_VIRTCON, "stdio");
4368 add_device_config(DEV_SCLP, "stdio");
4370 if (default_monitor)
4371 monitor_parse("stdio", "readline", false);
4375 add_device_config(DEV_SERIAL, "vc:80Cx24C");
4376 if (default_parallel)
4377 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
4378 if (default_monitor)
4379 monitor_parse("vc:80Cx24C", "readline", false);
4380 if (default_virtcon)
4381 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
4383 add_device_config(DEV_SCLP, "vc:80Cx24C");
4387 #if defined(CONFIG_VNC)
4388 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head))) {
4392 if (display_type == DT_DEFAULT && !display_remote) {
4393 #if defined(CONFIG_GTK)
4394 display_type = DT_GTK;
4395 #elif defined(CONFIG_SDL) || defined(CONFIG_COCOA)
4396 display_type = DT_SDL;
4397 #elif defined(CONFIG_VNC)
4398 vnc_parse("localhost:0,to=99,id=default", &error_abort);
4401 display_type = DT_NONE;
4405 if ((no_frame || alt_grab || ctrl_grab) && display_type != DT_SDL) {
4406 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4407 "for SDL, ignoring option");
4409 if (no_quit && (display_type != DT_GTK && display_type != DT_SDL)) {
4410 error_report("-no-quit is only valid for GTK and SDL, "
4414 #if defined(CONFIG_GTK)
4415 if (display_type == DT_GTK) {
4416 early_gtk_display_init(request_opengl);
4419 #if defined(CONFIG_SDL)
4420 if (display_type == DT_SDL) {
4421 sdl_display_early_init(request_opengl);
4424 if (request_opengl == 1 && display_opengl == 0) {
4425 #if defined(CONFIG_OPENGL)
4426 error_report("OpenGL is not supported by the display");
4428 error_report("OpenGL support is disabled");
4434 # if defined(CONFIG_QT)
4435 if (display_type == DT_MARU_QT_ONSCREEN) {
4436 maru_early_qt5_display_init(true);
4437 } else if (display_type == DT_MARU_QT_OFFSCREEN) {
4438 maru_early_qt5_display_init(false);
4446 if (qemu_opts_foreach(qemu_find_opts("object"),
4447 user_creatable_add_opts_foreach,
4448 object_create_initial, NULL)) {
4452 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4453 chardev_init_func, NULL, NULL)) {
4457 #ifdef CONFIG_VIRTFS
4458 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4459 fsdev_init_func, NULL, NULL)) {
4464 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
4465 error_report("could not acquire pid file: %s", strerror(errno));
4469 if (qemu_opts_foreach(qemu_find_opts("device"),
4470 device_help_func, NULL, NULL)) {
4474 machine_opts = qemu_get_machine_opts();
4475 if (qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
4477 object_unref(OBJECT(current_machine));
4482 qtest_init(qtest_chrdev, qtest_log, &error_fatal);
4485 machine_opts = qemu_get_machine_opts();
4486 kernel_filename = qemu_opt_get(machine_opts, "kernel");
4487 initrd_filename = qemu_opt_get(machine_opts, "initrd");
4488 kernel_cmdline = qemu_opt_get(machine_opts, "append");
4489 bios_name = qemu_opt_get(machine_opts, "firmware");
4491 opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
4493 boot_order = qemu_opt_get(opts, "order");
4495 validate_bootdevices(boot_order, &error_fatal);
4498 boot_once = qemu_opt_get(opts, "once");
4500 validate_bootdevices(boot_once, &error_fatal);
4503 boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu);
4504 boot_strict = qemu_opt_get_bool(opts, "strict", false);
4508 boot_order = machine_class->default_boot_order;
4511 if (!kernel_cmdline) {
4512 kernel_cmdline = "";
4513 current_machine->kernel_cmdline = (char *)kernel_cmdline;
4516 linux_boot = (kernel_filename != NULL);
4518 if (!linux_boot && *kernel_cmdline != '\0') {
4519 error_report("-append only allowed with -kernel option");
4523 if (!linux_boot && initrd_filename != NULL) {
4524 error_report("-initrd only allowed with -kernel option");
4528 if (!linux_boot && qemu_opt_get(machine_opts, "dtb")) {
4529 error_report("-dtb only allowed with -kernel option");
4533 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename) {
4534 /* fall back to the -kernel/-append */
4535 semihosting_arg_fallback(kernel_filename, kernel_cmdline);
4538 os_set_line_buffering();
4541 /* spice needs the timers to be initialized by this point */
4547 if (kvm_enabled() || xen_enabled() || hax_enabled()) {
4548 error_report("-icount is not allowed with kvm or xen");
4551 configure_icount(icount_opts, &error_abort);
4552 qemu_opts_del(icount_opts);
4555 /* clean up network at qemu process termination */
4556 atexit(&net_cleanup);
4558 if (net_init_clients() < 0) {
4562 if (qemu_opts_foreach(qemu_find_opts("object"),
4563 user_creatable_add_opts_foreach,
4564 object_create_delayed, NULL)) {
4569 if (tpm_init() < 0) {
4574 /* init the bluetooth world */
4575 if (foreach_device_config(DEV_BT, bt_parse))
4578 if (!xen_enabled()) {
4579 /* On 32-bit hosts, QEMU is limited by virtual address space */
4580 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
4581 error_report("at most 2047 MB RAM can be simulated");
4589 /* If the currently selected machine wishes to override the units-per-bus
4590 * property of its default HBA interface type, do so now. */
4591 if (machine_class->units_per_default_bus) {
4592 override_max_devs(machine_class->block_default_type,
4593 machine_class->units_per_default_bus);
4596 /* open the virtual block devices */
4597 if (snapshot || replay_mode != REPLAY_MODE_NONE) {
4598 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot,
4601 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func,
4602 &machine_class->block_default_type, NULL)) {
4606 default_drive(default_cdrom, snapshot, machine_class->block_default_type, 2,
4608 default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS);
4609 default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS);
4611 parse_numa_opts(machine_class);
4613 if (qemu_opts_foreach(qemu_find_opts("mon"),
4614 mon_init_func, NULL, NULL)) {
4618 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
4620 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
4622 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
4624 if (foreach_device_config(DEV_SCLP, sclp_parse) < 0) {
4627 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
4630 /* If no default VGA is requested, the default is "none". */
4632 if (machine_class->default_display) {
4633 vga_model = machine_class->default_display;
4634 } else if (cirrus_vga_available()) {
4635 vga_model = "cirrus";
4636 } else if (vga_available()) {
4641 select_vgahw(vga_model);
4645 i = select_watchdog(watchdog);
4647 exit (i == 1 ? 1 : 0);
4650 if (machine_class->compat_props) {
4651 qdev_prop_register_global_list(machine_class->compat_props);
4655 /* This checkpoint is required by replay to separate prior clock
4656 reading from the other reads, because timer polling functions query
4657 clock values from the log. */
4658 replay_checkpoint(CHECKPOINT_INIT);
4659 qdev_machine_init();
4661 current_machine->ram_size = ram_size;
4662 current_machine->maxram_size = maxram_size;
4663 current_machine->ram_slots = ram_slots;
4664 current_machine->boot_order = boot_order;
4665 current_machine->cpu_model = cpu_model;
4667 configure_accelerator(current_machine);
4669 #if defined(CONFIG_MARU)
4670 if (is_maru_machine(machine_class)) {
4671 kernel_cmdline = qemu_opt_get(machine_opts, "append");
4672 // Returned variable points different address from input variable.
4673 kernel_cmdline = prepare_maru(kernel_cmdline);
4674 qemu_opt_set(qemu_get_machine_opts(), "append",
4675 kernel_cmdline, &error_abort);
4677 current_machine->kernel_cmdline = (char *)kernel_cmdline;
4681 machine_class->init(current_machine);
4685 // TODO: Check about it...
4688 cpu_synchronize_all_post_init();
4690 numa_post_machine_init();
4692 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4693 parse_fw_cfg, fw_cfg_find(), NULL) != 0) {
4697 if (hax_enabled()) {
4701 /* init USB devices */
4702 if (usb_enabled()) {
4703 if (foreach_device_config(DEV_USB, usb_parse) < 0)
4707 /* Check if IGD GFX passthrough. */
4710 /* init generic devices */
4711 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE);
4712 if (qemu_opts_foreach(qemu_find_opts("device"),
4713 device_init_func, NULL, NULL)) {
4716 rom_reset_order_override();
4718 #if defined(CONFIG_MARU)
4719 if (is_maru_machine(machine_class)) {
4720 prepare_maru_after_device_init();
4724 // To support legacy VIGS options
4726 PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
4727 PCIDevice *pci_dev = pci_create(pci_bus, -1, "vigs");
4729 qdev_prop_set_string(&pci_dev->qdev, "backend", vigs_backend);
4731 qdev_prop_set_string(&pci_dev->qdev, "backend", "gl");
4733 qdev_prop_set_string(&pci_dev->qdev, "wsi", "wsi0");
4734 qdev_init_nofail(&pci_dev->qdev);
4738 // To support legacy YaGL options
4740 PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
4741 PCIDevice *pci_dev = pci_create(pci_bus, -1, "yagl");
4743 qdev_prop_set_string(&pci_dev->qdev, "wsi", "wsi0");
4745 qdev_init_nofail(&pci_dev->qdev);
4749 /* Did we create any drives that we failed to create a device for? */
4750 drive_check_orphaned();
4752 net_check_clients();
4755 qemu_boot_set(boot_once, &error_fatal);
4756 qemu_register_reset(restore_boot_order, g_strdup(boot_order));
4759 ds = init_displaystate();
4761 /* init local displays */
4762 switch (display_type) {
4764 (void)ds; /* avoid warning if no display is configured */
4766 #if defined(CONFIG_CURSES)
4768 curses_display_init(ds, full_screen);
4771 #if defined(CONFIG_SDL)
4773 sdl_display_init(ds, full_screen, no_frame);
4775 #elif defined(CONFIG_COCOA)
4777 cocoa_display_init(ds, full_screen);
4780 #if defined(CONFIG_GTK)
4782 gtk_display_init(ds, full_screen, grab_on_hover);
4785 #if defined(CONFIG_MARU)
4786 #if defined(CONFIG_QT)
4787 case DT_MARU_QT_ONSCREEN:
4788 case DT_MARU_QT_OFFSCREEN:
4789 if (!is_maru_machine(machine_class)) {
4790 error_report("maru_qt can not work"
4791 " without maru machine");
4794 maru_qt5_display_init(ds, full_screen);
4802 /* must be after terminal init, SDL library changes signal handlers */
4803 os_setup_signal_handling();
4806 /* init remote displays */
4807 qemu_opts_foreach(qemu_find_opts("vnc"),
4808 vnc_init_func, NULL, NULL);
4809 if (show_vnc_port) {
4810 char *ret = vnc_display_local_addr("default");
4811 printf("VNC server running on '%s'\n", ret);
4817 qemu_spice_display_init();
4821 if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
4825 qdev_machine_creation_done();
4827 /* TODO: once all bus devices are qdevified, this should be done
4828 * when bus is created by qdev.c */
4829 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
4830 qemu_run_machine_init_done_notifiers();
4832 if (rom_check_and_register_reset() != 0) {
4833 error_report("rom check and register reset failed");
4839 /* This checkpoint is required by replay to separate prior clock
4840 reading from the other reads, because timer polling functions query
4841 clock values from the log. */
4842 replay_checkpoint(CHECKPOINT_RESET);
4843 qemu_system_reset(VMRESET_SILENT);
4844 register_global_state();
4846 if (load_vmstate(loadvm) < 0) {
4851 qdev_prop_check_globals();
4852 if (vmstate_dump_file) {
4854 dump_vmstate_json_to_file(vmstate_dump_file);
4859 Error *local_err = NULL;
4860 qemu_start_incoming_migration(incoming, &local_err);
4862 error_reportf_err(local_err, "-incoming %s: ", incoming);
4865 } else if (autostart) {
4872 enable_print_backtrace_at_normal_exit();
4875 replay_disable_events();