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
25 #include "qemu/osdep.h"
26 #include "qemu/units.h"
27 #include "qapi/error.h"
28 #include "qemu-version.h"
29 #include "qemu/cutils.h"
30 #include "qemu/help_option.h"
31 #include "qemu/uuid.h"
32 #include "sysemu/seccomp.h"
35 #if defined(__APPLE__) || defined(main)
37 int qemu_main(int argc
, char **argv
, char **envp
);
38 int main(int argc
, char **argv
)
40 return qemu_main(argc
, argv
, NULL
);
43 #define main qemu_main
45 #endif /* CONFIG_SDL */
49 #define main qemu_main
50 #endif /* CONFIG_COCOA */
53 #include "qemu/error-report.h"
54 #include "qemu/sockets.h"
56 #include "hw/boards.h"
57 #include "sysemu/accel.h"
59 #include "hw/isa/isa.h"
60 #include "hw/scsi/scsi.h"
61 #include "hw/display/vga.h"
63 #include "sysemu/watchdog.h"
64 #include "hw/firmware/smbios.h"
65 #include "hw/acpi/acpi.h"
66 #include "hw/xen/xen.h"
68 #include "hw/loader.h"
69 #include "monitor/qdev.h"
70 #include "sysemu/bt.h"
72 #include "net/slirp.h"
73 #include "monitor/monitor.h"
74 #include "ui/console.h"
76 #include "sysemu/sysemu.h"
77 #include "sysemu/numa.h"
78 #include "exec/gdbstub.h"
79 #include "qemu/timer.h"
80 #include "chardev/char.h"
81 #include "qemu/bitmap.h"
83 #include "sysemu/blockdev.h"
84 #include "hw/block/block.h"
85 #include "migration/misc.h"
86 #include "migration/snapshot.h"
87 #include "migration/global_state.h"
88 #include "sysemu/tpm.h"
89 #include "sysemu/dma.h"
90 #include "hw/audio/soundhw.h"
91 #include "audio/audio.h"
92 #include "sysemu/cpus.h"
93 #include "migration/colo.h"
94 #include "migration/postcopy-ram.h"
95 #include "sysemu/kvm.h"
96 #include "sysemu/hax.h"
97 #include "qapi/qobject-input-visitor.h"
98 #include "qemu/option.h"
99 #include "qemu/config-file.h"
100 #include "qemu-options.h"
101 #include "qemu/main-loop.h"
103 #include "fsdev/qemu-fsdev.h"
105 #include "sysemu/qtest.h"
107 #include "disas/disas.h"
109 #include "trace-root.h"
110 #include "trace/control.h"
111 #include "qemu/queue.h"
112 #include "sysemu/arch_init.h"
114 #include "ui/qemu-spice.h"
115 #include "qapi/string-input-visitor.h"
116 #include "qapi/opts-visitor.h"
117 #include "qapi/clone-visitor.h"
118 #include "qom/object_interfaces.h"
119 #include "hw/semihosting/semihost.h"
120 #include "crypto/init.h"
121 #include "sysemu/replay.h"
122 #include "qapi/qapi-events-run-state.h"
123 #include "qapi/qapi-visit-block-core.h"
124 #include "qapi/qapi-visit-ui.h"
125 #include "qapi/qapi-commands-block-core.h"
126 #include "qapi/qapi-commands-misc.h"
127 #include "qapi/qapi-commands-run-state.h"
128 #include "qapi/qapi-commands-ui.h"
129 #include "qapi/qmp/qerror.h"
130 #include "sysemu/iothread.h"
131 #include "qemu/guest-random.h"
133 #define MAX_VIRTIO_CONSOLES 1
135 static const char *data_dir
[16];
136 static int data_dir_idx
;
137 const char *bios_name
= NULL
;
138 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
140 const char* keyboard_layout
= NULL
;
142 const char *mem_path
= NULL
;
143 int mem_prealloc
= 0; /* force preallocation of physical target memory */
144 bool enable_mlock
= false;
145 bool enable_cpu_pm
= false;
147 NICInfo nd_table
[MAX_NICS
];
153 } rtc_base_type
= RTC_BASE_UTC
;
154 static time_t rtc_ref_start_datetime
;
155 static int rtc_realtime_clock_offset
; /* used only with QEMU_CLOCK_REALTIME */
156 static int rtc_host_datetime_offset
= -1; /* valid & used only with
158 QEMUClockType rtc_clock
;
159 int vga_interface_type
= VGA_NONE
;
160 static DisplayOptions dpy
;
161 static int num_serial_hds
;
162 static Chardev
**serial_hds
;
163 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
164 int win2k_install_hack
= 0;
167 unsigned int max_cpus
;
170 int acpi_enabled
= 1;
173 static int no_reboot
;
176 int graphic_rotate
= 0;
177 const char *watchdog
;
178 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
181 const char *qemu_name
;
184 unsigned int nb_prom_envs
= 0;
185 const char *prom_envs
[MAX_PROM_ENVS
];
188 uint8_t *boot_splash_filedata
;
189 int only_migratable
; /* turn it off unless user states otherwise */
190 bool wakeup_suspend_enabled
;
192 int icount_align_option
;
194 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
195 * little-endian "wire format" described in the SMBIOS 2.6 specification.
200 static NotifierList exit_notifiers
=
201 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
203 static NotifierList machine_init_done_notifiers
=
204 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
208 enum xen_mode xen_mode
= XEN_EMULATE
;
209 bool xen_domid_restrict
;
211 static int has_defaults
= 1;
212 static int default_serial
= 1;
213 static int default_parallel
= 1;
214 static int default_monitor
= 1;
215 static int default_floppy
= 1;
216 static int default_cdrom
= 1;
217 static int default_sdcard
= 1;
218 static int default_vga
= 1;
219 static int default_net
= 1;
225 { .driver
= "isa-serial", .flag
= &default_serial
},
226 { .driver
= "isa-parallel", .flag
= &default_parallel
},
227 { .driver
= "isa-fdc", .flag
= &default_floppy
},
228 { .driver
= "floppy", .flag
= &default_floppy
},
229 { .driver
= "ide-cd", .flag
= &default_cdrom
},
230 { .driver
= "ide-hd", .flag
= &default_cdrom
},
231 { .driver
= "ide-drive", .flag
= &default_cdrom
},
232 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
233 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
234 { .driver
= "VGA", .flag
= &default_vga
},
235 { .driver
= "isa-vga", .flag
= &default_vga
},
236 { .driver
= "cirrus-vga", .flag
= &default_vga
},
237 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
238 { .driver
= "vmware-svga", .flag
= &default_vga
},
239 { .driver
= "qxl-vga", .flag
= &default_vga
},
240 { .driver
= "virtio-vga", .flag
= &default_vga
},
241 { .driver
= "ati-vga", .flag
= &default_vga
},
244 static QemuOptsList qemu_rtc_opts
= {
246 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
251 .type
= QEMU_OPT_STRING
,
254 .type
= QEMU_OPT_STRING
,
257 .type
= QEMU_OPT_STRING
,
259 { /* end of list */ }
263 static QemuOptsList qemu_option_rom_opts
= {
264 .name
= "option-rom",
265 .implied_opt_name
= "romfile",
266 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
270 .type
= QEMU_OPT_NUMBER
,
273 .type
= QEMU_OPT_STRING
,
275 { /* end of list */ }
279 static QemuOptsList qemu_machine_opts
= {
281 .implied_opt_name
= "type",
283 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
286 * no elements => accept any
287 * sanity checking will happen later
288 * when setting machine properties
294 static QemuOptsList qemu_accel_opts
= {
296 .implied_opt_name
= "accel",
297 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
302 .type
= QEMU_OPT_STRING
,
303 .help
= "Select the type of accelerator",
307 .type
= QEMU_OPT_STRING
,
308 .help
= "Enable/disable multi-threaded TCG",
310 { /* end of list */ }
314 static QemuOptsList qemu_boot_opts
= {
316 .implied_opt_name
= "order",
318 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
322 .type
= QEMU_OPT_STRING
,
325 .type
= QEMU_OPT_STRING
,
328 .type
= QEMU_OPT_BOOL
,
331 .type
= QEMU_OPT_STRING
,
333 .name
= "splash-time",
334 .type
= QEMU_OPT_NUMBER
,
336 .name
= "reboot-timeout",
337 .type
= QEMU_OPT_NUMBER
,
340 .type
= QEMU_OPT_BOOL
,
346 static QemuOptsList qemu_add_fd_opts
= {
348 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
352 .type
= QEMU_OPT_NUMBER
,
353 .help
= "file descriptor of which a duplicate is added to fd set",
356 .type
= QEMU_OPT_NUMBER
,
357 .help
= "ID of the fd set to add fd to",
360 .type
= QEMU_OPT_STRING
,
361 .help
= "free-form string used to describe fd",
363 { /* end of list */ }
367 static QemuOptsList qemu_object_opts
= {
369 .implied_opt_name
= "qom-type",
370 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
376 static QemuOptsList qemu_tpmdev_opts
= {
378 .implied_opt_name
= "type",
379 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
381 /* options are defined in the TPM backends */
382 { /* end of list */ }
386 static QemuOptsList qemu_realtime_opts
= {
388 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
392 .type
= QEMU_OPT_BOOL
,
394 { /* end of list */ }
398 static QemuOptsList qemu_overcommit_opts
= {
399 .name
= "overcommit",
400 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
404 .type
= QEMU_OPT_BOOL
,
408 .type
= QEMU_OPT_BOOL
,
410 { /* end of list */ }
414 static QemuOptsList qemu_msg_opts
= {
416 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
420 .type
= QEMU_OPT_BOOL
,
422 { /* end of list */ }
426 static QemuOptsList qemu_name_opts
= {
428 .implied_opt_name
= "guest",
430 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
434 .type
= QEMU_OPT_STRING
,
435 .help
= "Sets the name of the guest.\n"
436 "This name will be displayed in the SDL window caption.\n"
437 "The name will also be used for the VNC server",
440 .type
= QEMU_OPT_STRING
,
441 .help
= "Sets the name of the QEMU process, as shown in top etc",
443 .name
= "debug-threads",
444 .type
= QEMU_OPT_BOOL
,
445 .help
= "When enabled, name the individual threads; defaults off.\n"
446 "NOTE: The thread names are for debugging and not a\n"
449 { /* End of list */ }
453 static QemuOptsList qemu_mem_opts
= {
455 .implied_opt_name
= "size",
456 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
461 .type
= QEMU_OPT_SIZE
,
465 .type
= QEMU_OPT_NUMBER
,
469 .type
= QEMU_OPT_SIZE
,
471 { /* end of list */ }
475 static QemuOptsList qemu_icount_opts
= {
477 .implied_opt_name
= "shift",
479 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
483 .type
= QEMU_OPT_STRING
,
486 .type
= QEMU_OPT_BOOL
,
489 .type
= QEMU_OPT_BOOL
,
492 .type
= QEMU_OPT_STRING
,
495 .type
= QEMU_OPT_STRING
,
497 .name
= "rrsnapshot",
498 .type
= QEMU_OPT_STRING
,
500 { /* end of list */ }
504 static QemuOptsList qemu_fw_cfg_opts
= {
506 .implied_opt_name
= "name",
507 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
511 .type
= QEMU_OPT_STRING
,
512 .help
= "Sets the fw_cfg name of the blob to be inserted",
515 .type
= QEMU_OPT_STRING
,
516 .help
= "Sets the name of the file from which "
517 "the fw_cfg blob will be loaded",
520 .type
= QEMU_OPT_STRING
,
521 .help
= "Sets content of the blob to be inserted from a string",
523 { /* end of list */ }
528 * Get machine options
530 * Returns: machine options (never null).
532 QemuOpts
*qemu_get_machine_opts(void)
534 return qemu_find_opts_singleton("machine");
537 const char *qemu_get_vm_name(void)
542 static void res_free(void)
544 g_free(boot_splash_filedata
);
545 boot_splash_filedata
= NULL
;
548 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
550 const char *driver
= qemu_opt_get(opts
, "driver");
555 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
556 if (strcmp(default_list
[i
].driver
, driver
) != 0)
558 *(default_list
[i
].flag
) = 0;
563 /***********************************************************/
566 static RunState current_run_state
= RUN_STATE_PRECONFIG
;
568 /* We use RUN_STATE__MAX but any invalid value will do */
569 static RunState vmstop_requested
= RUN_STATE__MAX
;
570 static QemuMutex vmstop_lock
;
575 } RunStateTransition
;
577 static const RunStateTransition runstate_transitions_def
[] = {
579 { RUN_STATE_PRECONFIG
, RUN_STATE_PRELAUNCH
},
580 /* Early switch to inmigrate state to allow -incoming CLI option work
581 * as it used to. TODO: delay actual switching to inmigrate state to
582 * the point after machine is built and remove this hack.
584 { RUN_STATE_PRECONFIG
, RUN_STATE_INMIGRATE
},
586 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
587 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
588 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
590 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
591 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
592 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
593 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
594 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
595 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
596 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
597 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
598 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
599 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
600 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
601 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
603 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
604 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
605 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
607 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
608 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
609 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
611 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
612 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
613 { RUN_STATE_PAUSED
, RUN_STATE_POSTMIGRATE
},
614 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
615 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
617 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
618 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
619 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
621 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
622 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
623 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
625 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
626 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PAUSED
},
627 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
628 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
629 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
631 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
632 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
634 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
636 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
637 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
638 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
639 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
640 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
641 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
642 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
643 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
644 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
645 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
646 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
648 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
650 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
651 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
652 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
654 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
655 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
656 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
657 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
658 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
659 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
661 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
662 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
663 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
664 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
666 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
667 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
668 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
670 { RUN_STATE__MAX
, RUN_STATE__MAX
},
673 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
675 bool runstate_check(RunState state
)
677 return current_run_state
== state
;
680 bool runstate_store(char *str
, size_t size
)
682 const char *state
= RunState_str(current_run_state
);
683 size_t len
= strlen(state
) + 1;
688 memcpy(str
, state
, len
);
692 static void runstate_init(void)
694 const RunStateTransition
*p
;
696 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
697 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
698 runstate_valid_transitions
[p
->from
][p
->to
] = true;
701 qemu_mutex_init(&vmstop_lock
);
704 /* This function will abort() on invalid state transitions */
705 void runstate_set(RunState new_state
)
707 assert(new_state
< RUN_STATE__MAX
);
709 trace_runstate_set(current_run_state
, RunState_str(current_run_state
),
710 new_state
, RunState_str(new_state
));
712 if (current_run_state
== new_state
) {
716 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
717 error_report("invalid runstate transition: '%s' -> '%s'",
718 RunState_str(current_run_state
),
719 RunState_str(new_state
));
723 current_run_state
= new_state
;
726 int runstate_is_running(void)
728 return runstate_check(RUN_STATE_RUNNING
);
731 bool runstate_needs_reset(void)
733 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
734 runstate_check(RUN_STATE_SHUTDOWN
);
737 StatusInfo
*qmp_query_status(Error
**errp
)
739 StatusInfo
*info
= g_malloc0(sizeof(*info
));
741 info
->running
= runstate_is_running();
742 info
->singlestep
= singlestep
;
743 info
->status
= current_run_state
;
748 bool qemu_vmstop_requested(RunState
*r
)
750 qemu_mutex_lock(&vmstop_lock
);
751 *r
= vmstop_requested
;
752 vmstop_requested
= RUN_STATE__MAX
;
753 qemu_mutex_unlock(&vmstop_lock
);
754 return *r
< RUN_STATE__MAX
;
757 void qemu_system_vmstop_request_prepare(void)
759 qemu_mutex_lock(&vmstop_lock
);
762 void qemu_system_vmstop_request(RunState state
)
764 vmstop_requested
= state
;
765 qemu_mutex_unlock(&vmstop_lock
);
769 /***********************************************************/
770 /* RTC reference time/date access */
771 static time_t qemu_ref_timedate(QEMUClockType clock
)
773 time_t value
= qemu_clock_get_ms(clock
) / 1000;
775 case QEMU_CLOCK_REALTIME
:
776 value
-= rtc_realtime_clock_offset
;
778 case QEMU_CLOCK_VIRTUAL
:
779 value
+= rtc_ref_start_datetime
;
781 case QEMU_CLOCK_HOST
:
782 if (rtc_base_type
== RTC_BASE_DATETIME
) {
783 value
-= rtc_host_datetime_offset
;
792 void qemu_get_timedate(struct tm
*tm
, int offset
)
794 time_t ti
= qemu_ref_timedate(rtc_clock
);
798 switch (rtc_base_type
) {
799 case RTC_BASE_DATETIME
:
803 case RTC_BASE_LOCALTIME
:
804 localtime_r(&ti
, tm
);
809 int qemu_timedate_diff(struct tm
*tm
)
813 switch (rtc_base_type
) {
814 case RTC_BASE_DATETIME
:
816 seconds
= mktimegm(tm
);
818 case RTC_BASE_LOCALTIME
:
821 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
822 seconds
= mktime(&tmp
);
829 return seconds
- qemu_ref_timedate(QEMU_CLOCK_HOST
);
832 static void configure_rtc_base_datetime(const char *startdate
)
834 time_t rtc_start_datetime
;
837 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d", &tm
.tm_year
, &tm
.tm_mon
,
838 &tm
.tm_mday
, &tm
.tm_hour
, &tm
.tm_min
, &tm
.tm_sec
) == 6) {
840 } else if (sscanf(startdate
, "%d-%d-%d",
841 &tm
.tm_year
, &tm
.tm_mon
, &tm
.tm_mday
) == 3) {
850 rtc_start_datetime
= mktimegm(&tm
);
851 if (rtc_start_datetime
== -1) {
853 error_report("invalid datetime format");
854 error_printf("valid formats: "
855 "'2006-06-17T16:01:21' or '2006-06-17'\n");
858 rtc_host_datetime_offset
= rtc_ref_start_datetime
- rtc_start_datetime
;
859 rtc_ref_start_datetime
= rtc_start_datetime
;
862 static void configure_rtc(QemuOpts
*opts
)
867 rtc_clock
= QEMU_CLOCK_HOST
;
868 rtc_ref_start_datetime
= qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
869 rtc_realtime_clock_offset
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) / 1000;
871 value
= qemu_opt_get(opts
, "base");
873 if (!strcmp(value
, "utc")) {
874 rtc_base_type
= RTC_BASE_UTC
;
875 } else if (!strcmp(value
, "localtime")) {
876 Error
*blocker
= NULL
;
877 rtc_base_type
= RTC_BASE_LOCALTIME
;
878 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
879 "-rtc base=localtime");
880 replay_add_blocker(blocker
);
882 rtc_base_type
= RTC_BASE_DATETIME
;
883 configure_rtc_base_datetime(value
);
886 value
= qemu_opt_get(opts
, "clock");
888 if (!strcmp(value
, "host")) {
889 rtc_clock
= QEMU_CLOCK_HOST
;
890 } else if (!strcmp(value
, "rt")) {
891 rtc_clock
= QEMU_CLOCK_REALTIME
;
892 } else if (!strcmp(value
, "vm")) {
893 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
895 error_report("invalid option value '%s'", value
);
899 value
= qemu_opt_get(opts
, "driftfix");
901 if (!strcmp(value
, "slew")) {
902 static GlobalProperty slew_lost_ticks
= {
903 .driver
= "mc146818rtc",
904 .property
= "lost_tick_policy",
908 qdev_prop_register_global(&slew_lost_ticks
);
909 } else if (!strcmp(value
, "none")) {
910 /* discard is default */
912 error_report("invalid option value '%s'", value
);
918 /***********************************************************/
919 /* Bluetooth support */
922 static struct HCIInfo
*hci_table
[MAX_NICS
];
924 struct HCIInfo
*qemu_next_hci(void)
926 if (cur_hci
== nb_hcis
)
929 return hci_table
[cur_hci
++];
932 static int bt_hci_parse(const char *str
)
937 if (nb_hcis
>= MAX_NICS
) {
938 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
951 bdaddr
.b
[5] = 0x56 + nb_hcis
;
952 hci
->bdaddr_set(hci
, bdaddr
.b
);
954 hci_table
[nb_hcis
++] = hci
;
959 static void bt_vhci_add(int vlan_id
)
961 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
964 warn_report("adding a VHCI to an empty scatternet %i",
967 bt_vhci_init(bt_new_hci(vlan
));
970 static struct bt_device_s
*bt_device_add(const char *opt
)
972 struct bt_scatternet_s
*vlan
;
974 char *endp
= strstr(opt
, ",vlan=");
975 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
978 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
981 vlan_id
= strtol(endp
+ 6, &endp
, 0);
983 error_report("unrecognised bluetooth vlan Id");
988 vlan
= qemu_find_bt_vlan(vlan_id
);
991 warn_report("adding a slave device to an empty scatternet %i",
994 if (!strcmp(devname
, "keyboard"))
995 return bt_keyboard_init(vlan
);
997 error_report("unsupported bluetooth device '%s'", devname
);
1001 static int bt_parse(const char *opt
)
1003 const char *endp
, *p
;
1006 if (strstart(opt
, "hci", &endp
)) {
1007 if (!*endp
|| *endp
== ',') {
1009 if (!strstart(endp
, ",vlan=", 0))
1012 return bt_hci_parse(opt
);
1014 } else if (strstart(opt
, "vhci", &endp
)) {
1015 if (!*endp
|| *endp
== ',') {
1017 if (strstart(endp
, ",vlan=", &p
)) {
1018 vlan
= strtol(p
, (char **) &endp
, 0);
1020 error_report("bad scatternet '%s'", p
);
1024 error_report("bad parameter '%s'", endp
+ 1);
1033 } else if (strstart(opt
, "device:", &endp
))
1034 return !bt_device_add(endp
);
1036 error_report("bad bluetooth parameter '%s'", opt
);
1040 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1042 const char *proc_name
;
1044 if (qemu_opt_get(opts
, "debug-threads")) {
1045 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1047 qemu_name
= qemu_opt_get(opts
, "guest");
1049 proc_name
= qemu_opt_get(opts
, "process");
1051 os_set_proc_name(proc_name
);
1057 bool defaults_enabled(void)
1059 return has_defaults
;
1063 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1065 int fd
, dupfd
, flags
;
1067 const char *fd_opaque
= NULL
;
1070 fd
= qemu_opt_get_number(opts
, "fd", -1);
1071 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1072 fd_opaque
= qemu_opt_get(opts
, "opaque");
1075 error_setg(errp
, "fd option is required and must be non-negative");
1079 if (fd
<= STDERR_FILENO
) {
1080 error_setg(errp
, "fd cannot be a standard I/O stream");
1085 * All fds inherited across exec() necessarily have FD_CLOEXEC
1086 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1088 flags
= fcntl(fd
, F_GETFD
);
1089 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1090 error_setg(errp
, "fd is not valid or already in use");
1095 error_setg(errp
, "set option is required and must be non-negative");
1099 #ifdef F_DUPFD_CLOEXEC
1100 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1104 qemu_set_cloexec(dupfd
);
1108 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
1112 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1113 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1120 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1124 fd
= qemu_opt_get_number(opts
, "fd", -1);
1131 /***********************************************************/
1132 /* QEMU Block devices */
1134 #define HD_OPTS "media=disk"
1135 #define CDROM_OPTS "media=cdrom"
1137 #define PFLASH_OPTS ""
1141 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1143 BlockInterfaceType
*block_default_type
= opaque
;
1145 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
1148 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1150 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1151 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1156 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1157 int index
, const char *optstr
)
1162 if (!enable
|| drive_get_by_index(type
, index
)) {
1166 opts
= drive_add(type
, index
, NULL
, optstr
);
1168 drive_enable_snapshot(NULL
, opts
, NULL
);
1171 dinfo
= drive_new(opts
, type
, &error_abort
);
1172 dinfo
->is_default
= true;
1176 typedef struct BlockdevOptionsQueueEntry
{
1177 BlockdevOptions
*bdo
;
1179 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
1180 } BlockdevOptionsQueueEntry
;
1182 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
1184 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
1185 MachineClass
*machine_class
, int snapshot
)
1188 * If the currently selected machine wishes to override the
1189 * units-per-bus property of its default HBA interface type, do so
1192 if (machine_class
->units_per_default_bus
) {
1193 override_max_devs(machine_class
->block_default_type
,
1194 machine_class
->units_per_default_bus
);
1197 /* open the virtual block devices */
1198 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
1199 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
1201 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
1202 loc_push_restore(&bdo
->loc
);
1203 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
1205 qapi_free_BlockdevOptions(bdo
->bdo
);
1208 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
1209 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
1212 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
1213 &machine_class
->block_default_type
, &error_fatal
)) {
1214 /* We printed help */
1218 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
1220 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
1221 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
1225 static QemuOptsList qemu_smp_opts
= {
1227 .implied_opt_name
= "cpus",
1228 .merge_lists
= true,
1229 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1233 .type
= QEMU_OPT_NUMBER
,
1236 .type
= QEMU_OPT_NUMBER
,
1239 .type
= QEMU_OPT_NUMBER
,
1242 .type
= QEMU_OPT_NUMBER
,
1245 .type
= QEMU_OPT_NUMBER
,
1247 { /*End of list */ }
1251 static void smp_parse(QemuOpts
*opts
)
1254 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1255 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1256 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1257 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1259 /* compute missing values, prefer sockets over cores over threads */
1260 if (cpus
== 0 || sockets
== 0) {
1261 cores
= cores
> 0 ? cores
: 1;
1262 threads
= threads
> 0 ? threads
: 1;
1264 sockets
= sockets
> 0 ? sockets
: 1;
1265 cpus
= cores
* threads
* sockets
;
1267 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1268 sockets
= max_cpus
/ (cores
* threads
);
1270 } else if (cores
== 0) {
1271 threads
= threads
> 0 ? threads
: 1;
1272 cores
= cpus
/ (sockets
* threads
);
1273 cores
= cores
> 0 ? cores
: 1;
1274 } else if (threads
== 0) {
1275 threads
= cpus
/ (cores
* sockets
);
1276 threads
= threads
> 0 ? threads
: 1;
1277 } else if (sockets
* cores
* threads
< cpus
) {
1278 error_report("cpu topology: "
1279 "sockets (%u) * cores (%u) * threads (%u) < "
1281 sockets
, cores
, threads
, cpus
);
1285 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1287 if (max_cpus
< cpus
) {
1288 error_report("maxcpus must be equal to or greater than smp");
1292 if (sockets
* cores
* threads
> max_cpus
) {
1293 error_report("cpu topology: "
1294 "sockets (%u) * cores (%u) * threads (%u) > "
1296 sockets
, cores
, threads
, max_cpus
);
1300 if (sockets
* cores
* threads
!= max_cpus
) {
1301 warn_report("Invalid CPU topology deprecated: "
1302 "sockets (%u) * cores (%u) * threads (%u) "
1304 sockets
, cores
, threads
, max_cpus
);
1309 smp_threads
= threads
;
1313 Error
*blocker
= NULL
;
1314 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1315 replay_add_blocker(blocker
);
1319 static void realtime_init(void)
1322 if (os_mlock() < 0) {
1323 error_report("locking memory failed");
1330 static void configure_msg(QemuOpts
*opts
)
1332 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1336 /* Now we still need this for compatibility with XEN. */
1337 bool has_igd_gfx_passthru
;
1338 static void igd_gfx_passthru(void)
1340 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1343 /***********************************************************/
1346 static int usb_device_add(const char *devname
)
1348 USBDevice
*dev
= NULL
;
1350 if (!machine_usb(current_machine
)) {
1354 dev
= usbdevice_create(devname
);
1361 static int usb_parse(const char *cmdline
)
1364 r
= usb_device_add(cmdline
);
1366 error_report("could not add USB device '%s'", cmdline
);
1371 /***********************************************************/
1372 /* machine registration */
1374 MachineState
*current_machine
;
1376 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
1380 for (el
= machines
; el
; el
= el
->next
) {
1381 MachineClass
*mc
= el
->data
;
1383 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
1391 static MachineClass
*find_default_machine(GSList
*machines
)
1395 for (el
= machines
; el
; el
= el
->next
) {
1396 MachineClass
*mc
= el
->data
;
1398 if (mc
->is_default
) {
1406 MachineInfoList
*qmp_query_machines(Error
**errp
)
1408 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1409 MachineInfoList
*mach_list
= NULL
;
1411 for (el
= machines
; el
; el
= el
->next
) {
1412 MachineClass
*mc
= el
->data
;
1413 MachineInfoList
*entry
;
1416 info
= g_malloc0(sizeof(*info
));
1417 if (mc
->is_default
) {
1418 info
->has_is_default
= true;
1419 info
->is_default
= true;
1423 info
->has_alias
= true;
1424 info
->alias
= g_strdup(mc
->alias
);
1427 info
->name
= g_strdup(mc
->name
);
1428 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1429 info
->hotpluggable_cpus
= mc
->has_hotpluggable_cpus
;
1431 entry
= g_malloc0(sizeof(*entry
));
1432 entry
->value
= info
;
1433 entry
->next
= mach_list
;
1437 g_slist_free(machines
);
1441 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1443 ObjectProperty
*prop
;
1444 ObjectPropertyIterator iter
;
1446 if (!qemu_opt_has_help_opt(opts
)) {
1450 object_property_iter_init(&iter
, OBJECT(machine
));
1451 while ((prop
= object_property_iter_next(&iter
))) {
1456 printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1457 prop
->name
, prop
->type
);
1458 if (prop
->description
) {
1459 printf(" (%s)\n", prop
->description
);
1468 struct vm_change_state_entry
{
1469 VMChangeStateHandler
*cb
;
1471 QLIST_ENTRY (vm_change_state_entry
) entries
;
1474 static QLIST_HEAD(, vm_change_state_entry
) vm_change_state_head
;
1476 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1479 VMChangeStateEntry
*e
;
1481 e
= g_malloc0(sizeof (*e
));
1485 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1489 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1491 QLIST_REMOVE (e
, entries
);
1495 void vm_state_notify(int running
, RunState state
)
1497 VMChangeStateEntry
*e
, *next
;
1499 trace_vm_state_notify(running
, state
, RunState_str(state
));
1501 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1502 e
->cb(e
->opaque
, running
, state
);
1506 static ShutdownCause reset_requested
;
1507 static ShutdownCause shutdown_requested
;
1508 static int shutdown_signal
;
1509 static pid_t shutdown_pid
;
1510 static int powerdown_requested
;
1511 static int debug_requested
;
1512 static int suspend_requested
;
1513 static bool preconfig_exit_requested
= true;
1514 static WakeupReason wakeup_reason
;
1515 static NotifierList powerdown_notifiers
=
1516 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1517 static NotifierList suspend_notifiers
=
1518 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1519 static NotifierList wakeup_notifiers
=
1520 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1521 static NotifierList shutdown_notifiers
=
1522 NOTIFIER_LIST_INITIALIZER(shutdown_notifiers
);
1523 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1525 ShutdownCause
qemu_shutdown_requested_get(void)
1527 return shutdown_requested
;
1530 ShutdownCause
qemu_reset_requested_get(void)
1532 return reset_requested
;
1535 static int qemu_shutdown_requested(void)
1537 return atomic_xchg(&shutdown_requested
, SHUTDOWN_CAUSE_NONE
);
1540 static void qemu_kill_report(void)
1542 if (!qtest_driver() && shutdown_signal
) {
1543 if (shutdown_pid
== 0) {
1544 /* This happens for eg ^C at the terminal, so it's worth
1545 * avoiding printing an odd message in that case.
1547 error_report("terminating on signal %d", shutdown_signal
);
1549 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1551 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1552 shutdown_signal
, shutdown_pid
,
1553 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1554 g_free(shutdown_cmd
);
1556 shutdown_signal
= 0;
1560 static ShutdownCause
qemu_reset_requested(void)
1562 ShutdownCause r
= reset_requested
;
1564 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1565 reset_requested
= SHUTDOWN_CAUSE_NONE
;
1568 return SHUTDOWN_CAUSE_NONE
;
1571 static int qemu_suspend_requested(void)
1573 int r
= suspend_requested
;
1574 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1575 suspend_requested
= 0;
1581 static WakeupReason
qemu_wakeup_requested(void)
1583 return wakeup_reason
;
1586 static int qemu_powerdown_requested(void)
1588 int r
= powerdown_requested
;
1589 powerdown_requested
= 0;
1593 static int qemu_debug_requested(void)
1595 int r
= debug_requested
;
1596 debug_requested
= 0;
1600 void qemu_exit_preconfig_request(void)
1602 preconfig_exit_requested
= true;
1606 * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE.
1608 void qemu_system_reset(ShutdownCause reason
)
1612 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1614 cpu_synchronize_all_states();
1616 if (mc
&& mc
->reset
) {
1619 qemu_devices_reset();
1621 if (reason
!= SHUTDOWN_CAUSE_SUBSYSTEM_RESET
) {
1622 qapi_event_send_reset(shutdown_caused_by_guest(reason
), reason
);
1624 cpu_synchronize_all_post_reset();
1627 void qemu_system_guest_panicked(GuestPanicInformation
*info
)
1629 qemu_log_mask(LOG_GUEST_ERROR
, "Guest crashed");
1632 current_cpu
->crash_occurred
= true;
1634 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
,
1636 vm_stop(RUN_STATE_GUEST_PANICKED
);
1638 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1640 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC
);
1644 if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_HYPER_V
) {
1645 qemu_log_mask(LOG_GUEST_ERROR
, "\nHV crash parameters: (%#"PRIx64
1646 " %#"PRIx64
" %#"PRIx64
" %#"PRIx64
" %#"PRIx64
")\n",
1647 info
->u
.hyper_v
.arg1
,
1648 info
->u
.hyper_v
.arg2
,
1649 info
->u
.hyper_v
.arg3
,
1650 info
->u
.hyper_v
.arg4
,
1651 info
->u
.hyper_v
.arg5
);
1652 } else if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_S390
) {
1653 qemu_log_mask(LOG_GUEST_ERROR
, " on cpu %d: %s\n"
1654 "PSW: 0x%016" PRIx64
" 0x%016" PRIx64
"\n",
1656 S390CrashReason_str(info
->u
.s390
.reason
),
1657 info
->u
.s390
.psw_mask
,
1658 info
->u
.s390
.psw_addr
);
1660 qapi_free_GuestPanicInformation(info
);
1664 void qemu_system_reset_request(ShutdownCause reason
)
1666 if (no_reboot
&& reason
!= SHUTDOWN_CAUSE_SUBSYSTEM_RESET
) {
1667 shutdown_requested
= reason
;
1669 reset_requested
= reason
;
1672 qemu_notify_event();
1675 static void qemu_system_suspend(void)
1678 notifier_list_notify(&suspend_notifiers
, NULL
);
1679 runstate_set(RUN_STATE_SUSPENDED
);
1680 qapi_event_send_suspend();
1683 void qemu_system_suspend_request(void)
1685 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1688 suspend_requested
= 1;
1690 qemu_notify_event();
1693 void qemu_register_suspend_notifier(Notifier
*notifier
)
1695 notifier_list_add(&suspend_notifiers
, notifier
);
1698 void qemu_system_wakeup_request(WakeupReason reason
, Error
**errp
)
1700 trace_system_wakeup_request(reason
);
1702 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1704 "Unable to wake up: guest is not in suspended state");
1707 if (!(wakeup_reason_mask
& (1 << reason
))) {
1710 runstate_set(RUN_STATE_RUNNING
);
1711 wakeup_reason
= reason
;
1712 qemu_notify_event();
1715 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1718 wakeup_reason_mask
|= (1 << reason
);
1720 wakeup_reason_mask
&= ~(1 << reason
);
1724 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1726 notifier_list_add(&wakeup_notifiers
, notifier
);
1729 void qemu_register_wakeup_support(void)
1731 wakeup_suspend_enabled
= true;
1734 bool qemu_wakeup_suspend_enabled(void)
1736 return wakeup_suspend_enabled
;
1739 CurrentMachineParams
*qmp_query_current_machine(Error
**errp
)
1741 CurrentMachineParams
*params
= g_malloc0(sizeof(*params
));
1742 params
->wakeup_suspend_support
= qemu_wakeup_suspend_enabled();
1747 void qemu_system_killed(int signal
, pid_t pid
)
1749 shutdown_signal
= signal
;
1753 /* Cannot call qemu_system_shutdown_request directly because
1754 * we are in a signal handler.
1756 shutdown_requested
= SHUTDOWN_CAUSE_HOST_SIGNAL
;
1757 qemu_notify_event();
1760 void qemu_system_shutdown_request(ShutdownCause reason
)
1762 trace_qemu_system_shutdown_request(reason
);
1763 replay_shutdown_request(reason
);
1764 shutdown_requested
= reason
;
1765 qemu_notify_event();
1768 static void qemu_system_powerdown(void)
1770 qapi_event_send_powerdown();
1771 notifier_list_notify(&powerdown_notifiers
, NULL
);
1774 static void qemu_system_shutdown(ShutdownCause cause
)
1776 qapi_event_send_shutdown(shutdown_caused_by_guest(cause
), cause
);
1777 notifier_list_notify(&shutdown_notifiers
, &cause
);
1780 void qemu_system_powerdown_request(void)
1782 trace_qemu_system_powerdown_request();
1783 powerdown_requested
= 1;
1784 qemu_notify_event();
1787 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1789 notifier_list_add(&powerdown_notifiers
, notifier
);
1792 void qemu_register_shutdown_notifier(Notifier
*notifier
)
1794 notifier_list_add(&shutdown_notifiers
, notifier
);
1797 void qemu_system_debug_request(void)
1799 debug_requested
= 1;
1800 qemu_notify_event();
1803 static bool main_loop_should_exit(void)
1806 ShutdownCause request
;
1808 if (preconfig_exit_requested
) {
1809 if (runstate_check(RUN_STATE_PRECONFIG
)) {
1810 runstate_set(RUN_STATE_PRELAUNCH
);
1812 preconfig_exit_requested
= false;
1815 if (qemu_debug_requested()) {
1816 vm_stop(RUN_STATE_DEBUG
);
1818 if (qemu_suspend_requested()) {
1819 qemu_system_suspend();
1821 request
= qemu_shutdown_requested();
1824 qemu_system_shutdown(request
);
1826 vm_stop(RUN_STATE_SHUTDOWN
);
1831 request
= qemu_reset_requested();
1834 qemu_system_reset(request
);
1836 if (!runstate_check(RUN_STATE_RUNNING
) &&
1837 !runstate_check(RUN_STATE_INMIGRATE
)) {
1838 runstate_set(RUN_STATE_PRELAUNCH
);
1841 if (qemu_wakeup_requested()) {
1843 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
1844 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1845 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1847 qapi_event_send_wakeup();
1849 if (qemu_powerdown_requested()) {
1850 qemu_system_powerdown();
1852 if (qemu_vmstop_requested(&r
)) {
1858 static void main_loop(void)
1860 #ifdef CONFIG_PROFILER
1863 while (!main_loop_should_exit()) {
1864 #ifdef CONFIG_PROFILER
1865 ti
= profile_getclock();
1867 main_loop_wait(false);
1868 #ifdef CONFIG_PROFILER
1869 dev_time
+= profile_getclock() - ti
;
1874 static void version(void)
1876 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
1877 QEMU_COPYRIGHT
"\n");
1880 static void help(int exitcode
)
1883 printf("usage: %s [options] [disk_image]\n\n"
1884 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1885 error_get_progname());
1887 #define QEMU_OPTIONS_GENERATE_HELP
1888 #include "qemu-options-wrapper.h"
1890 printf("\nDuring emulation, the following keys are useful:\n"
1891 "ctrl-alt-f toggle full screen\n"
1892 "ctrl-alt-n switch to virtual console 'n'\n"
1893 "ctrl-alt toggle mouse and keyboard grab\n"
1895 "When using -nographic, press 'ctrl-a h' to get some help.\n"
1897 QEMU_HELP_BOTTOM
"\n");
1902 #define HAS_ARG 0x0001
1904 typedef struct QEMUOption
{
1911 static const QEMUOption qemu_options
[] = {
1912 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1913 #define QEMU_OPTIONS_GENERATE_OPTIONS
1914 #include "qemu-options-wrapper.h"
1918 typedef struct VGAInterfaceInfo
{
1919 const char *opt_name
; /* option name */
1920 const char *name
; /* human-readable name */
1921 /* Class names indicating that support is available.
1922 * If no class is specified, the interface is always available */
1923 const char *class_names
[2];
1926 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1929 .name
= "no graphic card",
1933 .name
= "standard VGA",
1934 .class_names
= { "VGA", "isa-vga" },
1937 .opt_name
= "cirrus",
1938 .name
= "Cirrus VGA",
1939 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1942 .opt_name
= "vmware",
1943 .name
= "VMWare SVGA",
1944 .class_names
= { "vmware-svga" },
1947 .opt_name
= "virtio",
1948 .name
= "Virtio VGA",
1949 .class_names
= { "virtio-vga" },
1954 .class_names
= { "qxl-vga" },
1958 .name
= "TCX framebuffer",
1959 .class_names
= { "SUNW,tcx" },
1963 .name
= "CG3 framebuffer",
1964 .class_names
= { "cgthree" },
1967 .opt_name
= "xenfb",
1968 .name
= "Xen paravirtualized framebuffer",
1972 static bool vga_interface_available(VGAInterfaceType t
)
1974 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
1976 assert(t
< VGA_TYPE_MAX
);
1977 return !ti
->class_names
[0] ||
1978 object_class_by_name(ti
->class_names
[0]) ||
1979 object_class_by_name(ti
->class_names
[1]);
1983 get_default_vga_model(const MachineClass
*machine_class
)
1985 if (machine_class
->default_display
) {
1986 return machine_class
->default_display
;
1987 } else if (vga_interface_available(VGA_CIRRUS
)) {
1989 } else if (vga_interface_available(VGA_STD
)) {
1996 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
2001 if (g_str_equal(p
, "help")) {
2002 const char *def
= get_default_vga_model(machine_class
);
2004 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2005 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2007 if (vga_interface_available(t
) && ti
->opt_name
) {
2008 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
2009 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
2015 assert(vga_interface_type
== VGA_NONE
);
2016 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2017 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2018 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2019 if (!vga_interface_available(t
)) {
2020 error_report("%s not available", ti
->name
);
2023 vga_interface_type
= t
;
2027 if (t
== VGA_TYPE_MAX
) {
2029 error_report("unknown vga type: %s", p
);
2033 const char *nextopt
;
2035 if (strstart(opts
, ",retrace=", &nextopt
)) {
2037 if (strstart(opts
, "dumb", &nextopt
))
2038 vga_retrace_method
= VGA_RETRACE_DUMB
;
2039 else if (strstart(opts
, "precise", &nextopt
))
2040 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2041 else goto invalid_vga
;
2042 } else goto invalid_vga
;
2047 static void parse_display_qapi(const char *optarg
)
2049 DisplayOptions
*opts
;
2052 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
2054 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
2055 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
2057 qapi_free_DisplayOptions(opts
);
2061 DisplayOptions
*qmp_query_display_options(Error
**errp
)
2063 return QAPI_CLONE(DisplayOptions
, &dpy
);
2066 static void parse_display(const char *p
)
2070 if (strstart(p
, "sdl", &opts
)) {
2072 * sdl DisplayType needs hand-crafted parser instead of
2073 * parse_display_qapi() due to some options not in
2074 * DisplayOptions, specifically:
2076 * Already deprecated.
2077 * - ctrl_grab + alt_grab
2078 * Not clear yet what happens to them long-term. Should
2079 * replaced by something better or deprecated and dropped.
2081 dpy
.type
= DISPLAY_TYPE_SDL
;
2083 const char *nextopt
;
2085 if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2087 if (strstart(opts
, "on", &nextopt
)) {
2089 } else if (strstart(opts
, "off", &nextopt
)) {
2092 goto invalid_sdl_args
;
2094 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2096 if (strstart(opts
, "on", &nextopt
)) {
2098 } else if (strstart(opts
, "off", &nextopt
)) {
2101 goto invalid_sdl_args
;
2103 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2105 dpy
.has_window_close
= true;
2106 if (strstart(opts
, "on", &nextopt
)) {
2107 dpy
.window_close
= true;
2108 } else if (strstart(opts
, "off", &nextopt
)) {
2109 dpy
.window_close
= false;
2111 goto invalid_sdl_args
;
2113 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2116 if (strstart(opts
, "on", &nextopt
)) {
2117 dpy
.gl
= DISPLAYGL_MODE_ON
;
2118 } else if (strstart(opts
, "core", &nextopt
)) {
2119 dpy
.gl
= DISPLAYGL_MODE_CORE
;
2120 } else if (strstart(opts
, "es", &nextopt
)) {
2121 dpy
.gl
= DISPLAYGL_MODE_ES
;
2122 } else if (strstart(opts
, "off", &nextopt
)) {
2123 dpy
.gl
= DISPLAYGL_MODE_OFF
;
2125 goto invalid_sdl_args
;
2129 error_report("invalid SDL option string");
2134 } else if (strstart(p
, "vnc", &opts
)) {
2136 * vnc isn't a (local) DisplayType but a protocol for remote
2140 vnc_parse(opts
+ 1, &error_fatal
);
2142 error_report("VNC requires a display argument vnc=<display>");
2146 parse_display_qapi(p
);
2150 char *qemu_find_file(int type
, const char *name
)
2156 /* Try the name as a straight path first */
2157 if (access(name
, R_OK
) == 0) {
2158 trace_load_file(name
, name
);
2159 return g_strdup(name
);
2163 case QEMU_FILE_TYPE_BIOS
:
2166 case QEMU_FILE_TYPE_KEYMAP
:
2167 subdir
= "keymaps/";
2173 for (i
= 0; i
< data_dir_idx
; i
++) {
2174 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2175 if (access(buf
, R_OK
) == 0) {
2176 trace_load_file(name
, buf
);
2184 static void qemu_add_data_dir(const char *path
)
2191 if (data_dir_idx
== ARRAY_SIZE(data_dir
)) {
2194 for (i
= 0; i
< data_dir_idx
; i
++) {
2195 if (strcmp(data_dir
[i
], path
) == 0) {
2196 return; /* duplicate */
2199 data_dir
[data_dir_idx
++] = g_strdup(path
);
2202 static inline bool nonempty_str(const char *str
)
2207 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2211 const char *name
, *file
, *str
;
2212 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2214 if (fw_cfg
== NULL
) {
2215 error_setg(errp
, "fw_cfg device not available");
2218 name
= qemu_opt_get(opts
, "name");
2219 file
= qemu_opt_get(opts
, "file");
2220 str
= qemu_opt_get(opts
, "string");
2222 /* we need name and either a file or the content string */
2223 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2224 error_setg(errp
, "invalid argument(s)");
2227 if (nonempty_str(file
) && nonempty_str(str
)) {
2228 error_setg(errp
, "file and string are mutually exclusive");
2231 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2232 error_setg(errp
, "name too long (max. %d char)",
2233 FW_CFG_MAX_FILE_PATH
- 1);
2236 if (strncmp(name
, "opt/", 4) != 0) {
2237 warn_report("externally provided fw_cfg item names "
2238 "should be prefixed with \"opt/\"");
2240 if (nonempty_str(str
)) {
2241 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2242 buf
= g_memdup(str
, size
);
2245 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
2246 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
2251 /* For legacy, keep user files in a specific global order. */
2252 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2253 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2254 fw_cfg_reset_order_override(fw_cfg
);
2258 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2260 return qdev_device_help(opts
);
2263 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2267 dev
= qdev_device_add(opts
, errp
);
2271 object_unref(OBJECT(dev
));
2275 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2277 Error
*local_err
= NULL
;
2279 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
2281 error_propagate(errp
, local_err
);
2289 #ifdef CONFIG_VIRTFS
2290 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2292 return qemu_fsdev_add(opts
, errp
);
2296 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2299 const char *chardev
;
2303 mode
= qemu_opt_get(opts
, "mode");
2307 if (strcmp(mode
, "readline") == 0) {
2308 flags
= MONITOR_USE_READLINE
;
2309 } else if (strcmp(mode
, "control") == 0) {
2310 flags
= MONITOR_USE_CONTROL
;
2312 error_setg(errp
, "unknown monitor mode \"%s\"", mode
);
2316 if (qemu_opt_get_bool(opts
, "pretty", 0))
2317 flags
|= MONITOR_USE_PRETTY
;
2319 chardev
= qemu_opt_get(opts
, "chardev");
2321 error_report("chardev is required");
2324 chr
= qemu_chr_find(chardev
);
2326 error_setg(errp
, "chardev \"%s\" not found", chardev
);
2330 monitor_init(chr
, flags
);
2334 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2336 static int monitor_device_index
= 0;
2341 if (strstart(optarg
, "chardev:", &p
)) {
2342 snprintf(label
, sizeof(label
), "%s", p
);
2344 snprintf(label
, sizeof(label
), "compat_monitor%d",
2345 monitor_device_index
);
2346 opts
= qemu_chr_parse_compat(label
, optarg
, true);
2348 error_report("parse error: %s", optarg
);
2353 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2354 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2355 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2356 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2357 monitor_device_index
++;
2360 struct device_config
{
2362 DEV_USB
, /* -usbdevice */
2364 DEV_SERIAL
, /* -serial */
2365 DEV_PARALLEL
, /* -parallel */
2366 DEV_DEBUGCON
, /* -debugcon */
2367 DEV_GDB
, /* -gdb, -s */
2368 DEV_SCLP
, /* s390 sclp */
2370 const char *cmdline
;
2372 QTAILQ_ENTRY(device_config
) next
;
2375 static QTAILQ_HEAD(, device_config
) device_configs
=
2376 QTAILQ_HEAD_INITIALIZER(device_configs
);
2378 static void add_device_config(int type
, const char *cmdline
)
2380 struct device_config
*conf
;
2382 conf
= g_malloc0(sizeof(*conf
));
2384 conf
->cmdline
= cmdline
;
2385 loc_save(&conf
->loc
);
2386 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2389 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2391 struct device_config
*conf
;
2394 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2395 if (conf
->type
!= type
)
2397 loc_push_restore(&conf
->loc
);
2398 rc
= func(conf
->cmdline
);
2399 loc_pop(&conf
->loc
);
2407 static int serial_parse(const char *devname
)
2409 int index
= num_serial_hds
;
2412 if (strcmp(devname
, "none") == 0)
2414 snprintf(label
, sizeof(label
), "serial%d", index
);
2415 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
2417 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
2418 if (!serial_hds
[index
]) {
2419 error_report("could not connect serial device"
2420 " to character backend '%s'", devname
);
2427 Chardev
*serial_hd(int i
)
2430 if (i
< num_serial_hds
) {
2431 return serial_hds
[i
];
2436 int serial_max_hds(void)
2438 return num_serial_hds
;
2441 static int parallel_parse(const char *devname
)
2443 static int index
= 0;
2446 if (strcmp(devname
, "none") == 0)
2448 if (index
== MAX_PARALLEL_PORTS
) {
2449 error_report("too many parallel ports");
2452 snprintf(label
, sizeof(label
), "parallel%d", index
);
2453 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
2454 if (!parallel_hds
[index
]) {
2455 error_report("could not connect parallel device"
2456 " to character backend '%s'", devname
);
2463 static int debugcon_parse(const char *devname
)
2467 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
2468 error_report("invalid character backend '%s'", devname
);
2471 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2473 error_report("already have a debugcon device");
2476 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2477 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2481 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2483 const MachineClass
*mc1
= a
, *mc2
= b
;
2486 if (mc1
->family
== NULL
) {
2487 if (mc2
->family
== NULL
) {
2488 /* Compare standalone machine types against each other; they sort
2489 * in increasing order.
2491 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2492 object_class_get_name(OBJECT_CLASS(mc2
)));
2495 /* Standalone machine types sort after families. */
2499 if (mc2
->family
== NULL
) {
2500 /* Families sort before standalone machine types. */
2504 /* Families sort between each other alphabetically increasingly. */
2505 res
= strcmp(mc1
->family
, mc2
->family
);
2510 /* Within the same family, machine types sort in decreasing order. */
2511 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2512 object_class_get_name(OBJECT_CLASS(mc1
)));
2515 static MachineClass
*machine_parse(const char *name
, GSList
*machines
)
2520 if (is_help_option(name
)) {
2521 printf("Supported machines are:\n");
2522 machines
= g_slist_sort(machines
, machine_class_cmp
);
2523 for (el
= machines
; el
; el
= el
->next
) {
2524 MachineClass
*mc
= el
->data
;
2526 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2528 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
2529 mc
->is_default
? " (default)" : "",
2530 mc
->deprecation_reason
? " (deprecated)" : "");
2535 mc
= find_machine(name
, machines
);
2537 error_report("unsupported machine type");
2538 error_printf("Use -machine help to list supported machines\n");
2544 void qemu_add_exit_notifier(Notifier
*notify
)
2546 notifier_list_add(&exit_notifiers
, notify
);
2549 void qemu_remove_exit_notifier(Notifier
*notify
)
2551 notifier_remove(notify
);
2554 static void qemu_run_exit_notifiers(void)
2556 notifier_list_notify(&exit_notifiers
, NULL
);
2559 static const char *pid_file
;
2560 static Notifier qemu_unlink_pidfile_notifier
;
2562 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
2569 bool machine_init_done
;
2571 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2573 notifier_list_add(&machine_init_done_notifiers
, notify
);
2574 if (machine_init_done
) {
2575 notify
->notify(notify
, NULL
);
2579 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2581 notifier_remove(notify
);
2584 static void qemu_run_machine_init_done_notifiers(void)
2586 machine_init_done
= true;
2587 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2590 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2591 const char **poptarg
, int *poptind
)
2593 const QEMUOption
*popt
;
2594 int optind
= *poptind
;
2595 char *r
= argv
[optind
];
2598 loc_set_cmdline(argv
, optind
, 1);
2600 /* Treat --foo the same as -foo. */
2603 popt
= qemu_options
;
2606 error_report("invalid option");
2609 if (!strcmp(popt
->name
, r
+ 1))
2613 if (popt
->flags
& HAS_ARG
) {
2614 if (optind
>= argc
) {
2615 error_report("requires an argument");
2618 optarg
= argv
[optind
++];
2619 loc_set_cmdline(argv
, optind
- 2, 2);
2630 static MachineClass
*select_machine(void)
2632 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
2633 MachineClass
*machine_class
= find_default_machine(machines
);
2638 loc_push_none(&loc
);
2640 opts
= qemu_get_machine_opts();
2641 qemu_opts_loc_restore(opts
);
2643 optarg
= qemu_opt_get(opts
, "type");
2645 machine_class
= machine_parse(optarg
, machines
);
2648 if (!machine_class
) {
2649 error_report("No machine specified, and there is no default");
2650 error_printf("Use -machine help to list supported machines\n");
2655 g_slist_free(machines
);
2656 return machine_class
;
2659 static int machine_set_property(void *opaque
,
2660 const char *name
, const char *value
,
2663 Object
*obj
= OBJECT(opaque
);
2664 Error
*local_err
= NULL
;
2667 if (strcmp(name
, "type") == 0) {
2671 qom_name
= g_strdup(name
);
2672 for (p
= qom_name
; *p
; p
++) {
2678 object_property_parse(obj
, value
, qom_name
, &local_err
);
2682 error_propagate(errp
, local_err
);
2691 * Initial object creation happens before all other
2692 * QEMU data types are created. The majority of objects
2693 * can be created at this point. The rng-egd object
2694 * cannot be created here, as it depends on the chardev
2697 static bool object_create_initial(const char *type
, QemuOpts
*opts
)
2701 if (is_help_option(type
)) {
2704 printf("List of user creatable objects:\n");
2705 list
= object_class_get_list_sorted(TYPE_USER_CREATABLE
, false);
2706 for (l
= list
; l
!= NULL
; l
= l
->next
) {
2707 ObjectClass
*oc
= OBJECT_CLASS(l
->data
);
2708 printf(" %s\n", object_class_get_name(oc
));
2714 klass
= object_class_by_name(type
);
2715 if (klass
&& qemu_opt_has_help_opt(opts
)) {
2716 ObjectPropertyIterator iter
;
2717 ObjectProperty
*prop
;
2718 GPtrArray
*array
= g_ptr_array_new();
2721 object_class_property_iter_init(&iter
, klass
);
2722 while ((prop
= object_property_iter_next(&iter
))) {
2729 str
= g_string_new(NULL
);
2730 g_string_append_printf(str
, " %s=<%s>", prop
->name
, prop
->type
);
2731 if (prop
->description
) {
2732 if (str
->len
< 24) {
2733 g_string_append_printf(str
, "%*s", 24 - (int)str
->len
, "");
2735 g_string_append_printf(str
, " - %s", prop
->description
);
2737 g_ptr_array_add(array
, g_string_free(str
, false));
2739 g_ptr_array_sort(array
, (GCompareFunc
)qemu_pstrcmp0
);
2740 if (array
->len
> 0) {
2741 printf("%s options:\n", type
);
2743 printf("There are no options for %s.\n", type
);
2745 for (i
= 0; i
< array
->len
; i
++) {
2746 printf("%s\n", (char *)array
->pdata
[i
]);
2748 g_ptr_array_set_free_func(array
, g_free
);
2749 g_ptr_array_free(array
, true);
2753 if (g_str_equal(type
, "rng-egd") ||
2754 g_str_has_prefix(type
, "pr-manager-")) {
2758 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
2759 if (g_str_equal(type
, "cryptodev-vhost-user")) {
2765 * return false for concrete netfilters since
2766 * they depend on netdevs already existing
2768 if (g_str_equal(type
, "filter-buffer") ||
2769 g_str_equal(type
, "filter-dump") ||
2770 g_str_equal(type
, "filter-mirror") ||
2771 g_str_equal(type
, "filter-redirector") ||
2772 g_str_equal(type
, "colo-compare") ||
2773 g_str_equal(type
, "filter-rewriter") ||
2774 g_str_equal(type
, "filter-replay")) {
2778 /* Memory allocation by backends needs to be done
2779 * after configure_accelerator() (due to the tcg_enabled()
2780 * checks at memory_region_init_*()).
2782 * Also, allocation of large amounts of memory may delay
2783 * chardev initialization for too long, and trigger timeouts
2784 * on software that waits for a monitor socket to be created
2787 if (g_str_has_prefix(type
, "memory-backend-")) {
2796 * The remainder of object creation happens after the
2797 * creation of chardev, fsdev, net clients and device data types.
2799 static bool object_create_delayed(const char *type
, QemuOpts
*opts
)
2801 return !object_create_initial(type
, opts
);
2805 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2809 const char *mem_str
;
2810 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2811 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2814 loc_push_none(&loc
);
2815 qemu_opts_loc_restore(opts
);
2818 mem_str
= qemu_opt_get(opts
, "size");
2821 error_report("missing 'size' option value");
2825 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2827 /* Fix up legacy suffix-less format */
2828 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2829 uint64_t overflow_check
= sz
;
2832 if (sz
/ MiB
!= overflow_check
) {
2833 error_report("too large 'size' option value");
2839 /* backward compatibility behaviour for case "-m 0" */
2841 sz
= default_ram_size
;
2844 sz
= QEMU_ALIGN_UP(sz
, 8192);
2846 if (ram_size
!= sz
) {
2847 error_report("ram size too large");
2851 /* store value for the future use */
2852 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2853 *maxram_size
= ram_size
;
2855 if (qemu_opt_get(opts
, "maxmem")) {
2858 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2859 slots
= qemu_opt_get_number(opts
, "slots", 0);
2860 if (sz
< ram_size
) {
2861 error_report("invalid value of -m option maxmem: "
2862 "maximum memory size (0x%" PRIx64
") must be at least "
2863 "the initial memory size (0x" RAM_ADDR_FMT
")",
2866 } else if (slots
&& sz
== ram_size
) {
2867 error_report("invalid value of -m option maxmem: "
2868 "memory slots were specified but maximum memory size "
2869 "(0x%" PRIx64
") is equal to the initial memory size "
2870 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2876 } else if (qemu_opt_get(opts
, "slots")) {
2877 error_report("invalid -m option value: missing 'maxmem' option");
2884 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2888 g
= g_malloc0(sizeof(*g
));
2889 g
->driver
= qemu_opt_get(opts
, "driver");
2890 g
->property
= qemu_opt_get(opts
, "property");
2891 g
->value
= qemu_opt_get(opts
, "value");
2892 qdev_prop_register_global(g
);
2896 static int qemu_read_default_config_file(void)
2900 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2901 if (ret
< 0 && ret
!= -ENOENT
) {
2908 static void user_register_global_props(void)
2910 qemu_opts_foreach(qemu_find_opts("global"),
2911 global_init_func
, NULL
, NULL
);
2914 int main(int argc
, char **argv
, char **envp
)
2917 int snapshot
, linux_boot
;
2918 const char *initrd_filename
;
2919 const char *kernel_filename
, *kernel_cmdline
;
2920 const char *boot_order
= NULL
;
2921 const char *boot_once
= NULL
;
2923 QemuOpts
*opts
, *machine_opts
;
2924 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2925 QemuOptsList
*olist
;
2928 const char *loadvm
= NULL
;
2929 MachineClass
*machine_class
;
2930 const char *cpu_option
;
2931 const char *vga_model
= NULL
;
2932 const char *qtest_chrdev
= NULL
;
2933 const char *qtest_log
= NULL
;
2934 const char *incoming
= NULL
;
2935 bool userconfig
= true;
2936 bool nographic
= false;
2937 int display_remote
= 0;
2938 const char *log_mask
= NULL
;
2939 const char *log_file
= NULL
;
2940 char *trace_file
= NULL
;
2941 ram_addr_t maxram_size
;
2942 uint64_t ram_slots
= 0;
2943 FILE *vmstate_dump_file
= NULL
;
2944 Error
*main_loop_err
= NULL
;
2946 bool list_data_dirs
= false;
2948 BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
2950 error_init(argv
[0]);
2951 module_call_init(MODULE_INIT_TRACE
);
2953 qemu_init_cpu_list();
2954 qemu_init_cpu_loop();
2956 qemu_mutex_lock_iothread();
2958 atexit(qemu_run_exit_notifiers
);
2959 qemu_init_exec_dir(argv
[0]);
2961 module_call_init(MODULE_INIT_QOM
);
2963 qemu_add_opts(&qemu_drive_opts
);
2964 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2965 qemu_add_drive_opts(&qemu_common_drive_opts
);
2966 qemu_add_drive_opts(&qemu_drive_opts
);
2967 qemu_add_drive_opts(&bdrv_runtime_opts
);
2968 qemu_add_opts(&qemu_chardev_opts
);
2969 qemu_add_opts(&qemu_device_opts
);
2970 qemu_add_opts(&qemu_netdev_opts
);
2971 qemu_add_opts(&qemu_nic_opts
);
2972 qemu_add_opts(&qemu_net_opts
);
2973 qemu_add_opts(&qemu_rtc_opts
);
2974 qemu_add_opts(&qemu_global_opts
);
2975 qemu_add_opts(&qemu_mon_opts
);
2976 qemu_add_opts(&qemu_trace_opts
);
2977 qemu_add_opts(&qemu_option_rom_opts
);
2978 qemu_add_opts(&qemu_machine_opts
);
2979 qemu_add_opts(&qemu_accel_opts
);
2980 qemu_add_opts(&qemu_mem_opts
);
2981 qemu_add_opts(&qemu_smp_opts
);
2982 qemu_add_opts(&qemu_boot_opts
);
2983 qemu_add_opts(&qemu_add_fd_opts
);
2984 qemu_add_opts(&qemu_object_opts
);
2985 qemu_add_opts(&qemu_tpmdev_opts
);
2986 qemu_add_opts(&qemu_realtime_opts
);
2987 qemu_add_opts(&qemu_overcommit_opts
);
2988 qemu_add_opts(&qemu_msg_opts
);
2989 qemu_add_opts(&qemu_name_opts
);
2990 qemu_add_opts(&qemu_numa_opts
);
2991 qemu_add_opts(&qemu_icount_opts
);
2992 qemu_add_opts(&qemu_semihosting_config_opts
);
2993 qemu_add_opts(&qemu_fw_cfg_opts
);
2994 module_call_init(MODULE_INIT_OPTS
);
2997 precopy_infrastructure_init();
2998 postcopy_infrastructure_init();
2999 monitor_init_globals();
3001 if (qcrypto_init(&err
) < 0) {
3002 error_reportf_err(err
, "cannot initialize crypto: ");
3006 QLIST_INIT (&vm_change_state_head
);
3007 os_setup_early_signal_handling();
3014 bdrv_init_with_whitelist();
3018 /* first pass of option parsing */
3020 while (optind
< argc
) {
3021 if (argv
[optind
][0] != '-') {
3025 const QEMUOption
*popt
;
3027 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3028 switch (popt
->index
) {
3029 case QEMU_OPTION_nouserconfig
:
3037 if (qemu_read_default_config_file() < 0) {
3042 /* second pass of option parsing */
3047 if (argv
[optind
][0] != '-') {
3048 loc_set_cmdline(argv
, optind
, 1);
3049 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3051 const QEMUOption
*popt
;
3053 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3054 if (!(popt
->arch_mask
& arch_type
)) {
3055 error_report("Option not supported for this target");
3058 switch(popt
->index
) {
3059 case QEMU_OPTION_cpu
:
3060 /* hw initialization will check this */
3061 cpu_option
= optarg
;
3063 case QEMU_OPTION_hda
:
3064 case QEMU_OPTION_hdb
:
3065 case QEMU_OPTION_hdc
:
3066 case QEMU_OPTION_hdd
:
3067 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3070 case QEMU_OPTION_blockdev
:
3073 BlockdevOptionsQueueEntry
*bdo
;
3075 v
= qobject_input_visitor_new_str(optarg
, "driver",
3078 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
3079 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
3082 loc_save(&bdo
->loc
);
3083 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
3086 case QEMU_OPTION_drive
:
3087 if (drive_def(optarg
) == NULL
) {
3091 case QEMU_OPTION_set
:
3092 if (qemu_set_option(optarg
) != 0)
3095 case QEMU_OPTION_global
:
3096 if (qemu_global_option(optarg
) != 0)
3099 case QEMU_OPTION_mtdblock
:
3100 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3102 case QEMU_OPTION_sd
:
3103 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3105 case QEMU_OPTION_pflash
:
3106 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3108 case QEMU_OPTION_snapshot
:
3111 case QEMU_OPTION_numa
:
3112 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3118 case QEMU_OPTION_display
:
3119 parse_display(optarg
);
3121 case QEMU_OPTION_nographic
:
3122 olist
= qemu_find_opts("machine");
3123 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3125 dpy
.type
= DISPLAY_TYPE_NONE
;
3127 case QEMU_OPTION_curses
:
3128 #ifdef CONFIG_CURSES
3129 dpy
.type
= DISPLAY_TYPE_CURSES
;
3131 error_report("curses or iconv support is disabled");
3135 case QEMU_OPTION_portrait
:
3136 graphic_rotate
= 90;
3138 case QEMU_OPTION_rotate
:
3139 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3140 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3141 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3142 error_report("only 90, 180, 270 deg rotation is available");
3146 case QEMU_OPTION_kernel
:
3147 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3150 case QEMU_OPTION_initrd
:
3151 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3154 case QEMU_OPTION_append
:
3155 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3158 case QEMU_OPTION_dtb
:
3159 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3162 case QEMU_OPTION_cdrom
:
3163 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3165 case QEMU_OPTION_boot
:
3166 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3172 case QEMU_OPTION_fda
:
3173 case QEMU_OPTION_fdb
:
3174 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3177 case QEMU_OPTION_no_fd_bootchk
:
3180 case QEMU_OPTION_netdev
:
3182 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3186 case QEMU_OPTION_nic
:
3188 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
3192 case QEMU_OPTION_net
:
3194 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3198 #ifdef CONFIG_LIBISCSI
3199 case QEMU_OPTION_iscsi
:
3200 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3207 case QEMU_OPTION_bt
:
3208 warn_report("The bluetooth subsystem is deprecated and will "
3209 "be removed soon. If the bluetooth subsystem is "
3210 "still useful for you, please send a mail to "
3211 "qemu-devel@nongnu.org with your usecase.");
3212 add_device_config(DEV_BT
, optarg
);
3214 case QEMU_OPTION_audio_help
:
3215 audio_legacy_help();
3218 case QEMU_OPTION_audiodev
:
3219 audio_parse_option(optarg
);
3221 case QEMU_OPTION_soundhw
:
3222 select_soundhw (optarg
);
3227 case QEMU_OPTION_version
:
3232 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3239 case QEMU_OPTION_tpmdev
:
3240 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3245 case QEMU_OPTION_mempath
:
3248 case QEMU_OPTION_mem_prealloc
:
3257 case QEMU_OPTION_DFILTER
:
3258 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3260 case QEMU_OPTION_seed
:
3261 qemu_guest_random_seed_main(optarg
, &error_fatal
);
3264 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3266 case QEMU_OPTION_gdb
:
3267 add_device_config(DEV_GDB
, optarg
);
3270 if (is_help_option(optarg
)) {
3271 list_data_dirs
= true;
3273 qemu_add_data_dir(optarg
);
3276 case QEMU_OPTION_bios
:
3277 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3280 case QEMU_OPTION_singlestep
:
3287 keyboard_layout
= optarg
;
3289 case QEMU_OPTION_vga
:
3298 w
= strtol(p
, (char **)&p
, 10);
3301 error_report("invalid resolution or depth");
3307 h
= strtol(p
, (char **)&p
, 10);
3312 depth
= strtol(p
, (char **)&p
, 10);
3313 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3314 depth
!= 24 && depth
!= 32)
3316 } else if (*p
== '\0') {
3317 depth
= graphic_depth
;
3324 graphic_depth
= depth
;
3327 case QEMU_OPTION_echr
:
3330 term_escape_char
= strtol(optarg
, &r
, 0);
3332 printf("Bad argument to echr\n");
3335 case QEMU_OPTION_monitor
:
3336 default_monitor
= 0;
3337 if (strncmp(optarg
, "none", 4)) {
3338 monitor_parse(optarg
, "readline", false);
3341 case QEMU_OPTION_qmp
:
3342 monitor_parse(optarg
, "control", false);
3343 default_monitor
= 0;
3345 case QEMU_OPTION_qmp_pretty
:
3346 monitor_parse(optarg
, "control", true);
3347 default_monitor
= 0;
3349 case QEMU_OPTION_mon
:
3350 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3355 default_monitor
= 0;
3357 case QEMU_OPTION_chardev
:
3358 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3364 case QEMU_OPTION_fsdev
:
3365 olist
= qemu_find_opts("fsdev");
3367 error_report("fsdev support is disabled");
3370 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3375 case QEMU_OPTION_virtfs
: {
3378 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
;
3380 olist
= qemu_find_opts("virtfs");
3382 error_report("virtfs support is disabled");
3385 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3390 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3391 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3392 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3395 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3396 qemu_opts_id(opts
) ?:
3397 qemu_opt_get(opts
, "mount_tag"),
3400 error_report("duplicate or invalid fsdev id: %s",
3401 qemu_opt_get(opts
, "mount_tag"));
3405 writeout
= qemu_opt_get(opts
, "writeout");
3407 #ifdef CONFIG_SYNC_FILE_RANGE
3408 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3410 error_report("writeout=immediate not supported "
3411 "on this platform");
3415 qemu_opt_set(fsdev
, "fsdriver",
3416 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3417 path
= qemu_opt_get(opts
, "path");
3419 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3421 security_model
= qemu_opt_get(opts
, "security_model");
3422 if (security_model
) {
3423 qemu_opt_set(fsdev
, "security_model", security_model
,
3426 socket
= qemu_opt_get(opts
, "socket");
3428 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3430 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3432 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3435 qemu_opt_set_bool(fsdev
, "readonly",
3436 qemu_opt_get_bool(opts
, "readonly", 0),
3438 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3440 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3441 qemu_opt_set(device
, "fsdev",
3442 qemu_opts_id(fsdev
), &error_abort
);
3443 qemu_opt_set(device
, "mount_tag",
3444 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3447 case QEMU_OPTION_virtfs_synth
: {
3451 warn_report("'-virtfs_synth' is deprecated, please use "
3452 "'-fsdev synth' and '-device virtio-9p-...' "
3455 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3458 error_report("duplicate option: %s", "virtfs_synth");
3461 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3463 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3465 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3466 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3467 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3470 case QEMU_OPTION_serial
:
3471 add_device_config(DEV_SERIAL
, optarg
);
3473 if (strncmp(optarg
, "mon:", 4) == 0) {
3474 default_monitor
= 0;
3477 case QEMU_OPTION_watchdog
:
3479 error_report("only one watchdog option may be given");
3484 case QEMU_OPTION_watchdog_action
:
3485 if (select_watchdog_action(optarg
) == -1) {
3486 error_report("unknown -watchdog-action parameter");
3490 case QEMU_OPTION_parallel
:
3491 add_device_config(DEV_PARALLEL
, optarg
);
3492 default_parallel
= 0;
3493 if (strncmp(optarg
, "mon:", 4) == 0) {
3494 default_monitor
= 0;
3497 case QEMU_OPTION_debugcon
:
3498 add_device_config(DEV_DEBUGCON
, optarg
);
3500 case QEMU_OPTION_loadvm
:
3503 case QEMU_OPTION_full_screen
:
3504 dpy
.has_full_screen
= true;
3505 dpy
.full_screen
= true;
3507 case QEMU_OPTION_alt_grab
:
3510 case QEMU_OPTION_ctrl_grab
:
3513 case QEMU_OPTION_no_quit
:
3514 dpy
.has_window_close
= true;
3515 dpy
.window_close
= false;
3517 case QEMU_OPTION_sdl
:
3519 dpy
.type
= DISPLAY_TYPE_SDL
;
3522 error_report("SDL support is disabled");
3525 case QEMU_OPTION_pidfile
:
3528 case QEMU_OPTION_win2k_hack
:
3529 win2k_install_hack
= 1;
3531 case QEMU_OPTION_acpitable
:
3532 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3537 acpi_table_add(opts
, &error_fatal
);
3539 case QEMU_OPTION_smbios
:
3540 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3545 smbios_entry_add(opts
, &error_fatal
);
3547 case QEMU_OPTION_fwcfg
:
3548 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3554 case QEMU_OPTION_preconfig
:
3555 preconfig_exit_requested
= false;
3557 case QEMU_OPTION_enable_kvm
:
3558 olist
= qemu_find_opts("machine");
3559 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3562 case QEMU_OPTION_machine
:
3563 olist
= qemu_find_opts("machine");
3564 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3569 case QEMU_OPTION_no_kvm
:
3570 olist
= qemu_find_opts("machine");
3571 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3573 case QEMU_OPTION_accel
:
3574 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3576 optarg
= qemu_opt_get(accel_opts
, "accel");
3577 if (!optarg
|| is_help_option(optarg
)) {
3578 printf("Possible accelerators: kvm, xen, hax, tcg\n");
3581 opts
= qemu_opts_create(qemu_find_opts("machine"), NULL
,
3582 false, &error_abort
);
3583 qemu_opt_set(opts
, "accel", optarg
, &error_abort
);
3585 case QEMU_OPTION_usb
:
3586 olist
= qemu_find_opts("machine");
3587 qemu_opts_parse_noisily(olist
, "usb=on", false);
3589 case QEMU_OPTION_usbdevice
:
3590 error_report("'-usbdevice' is deprecated, please use "
3591 "'-device usb-...' instead");
3592 olist
= qemu_find_opts("machine");
3593 qemu_opts_parse_noisily(olist
, "usb=on", false);
3594 add_device_config(DEV_USB
, optarg
);
3596 case QEMU_OPTION_device
:
3597 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3602 case QEMU_OPTION_smp
:
3603 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3608 case QEMU_OPTION_vnc
:
3609 vnc_parse(optarg
, &error_fatal
);
3611 case QEMU_OPTION_no_acpi
:
3614 case QEMU_OPTION_no_hpet
:
3617 case QEMU_OPTION_no_reboot
:
3620 case QEMU_OPTION_no_shutdown
:
3623 case QEMU_OPTION_show_cursor
:
3626 case QEMU_OPTION_uuid
:
3627 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3628 error_report("failed to parse UUID string: wrong format");
3631 qemu_uuid_set
= true;
3633 case QEMU_OPTION_option_rom
:
3634 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3635 error_report("too many option ROMs");
3638 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3643 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3644 option_rom
[nb_option_roms
].bootindex
=
3645 qemu_opt_get_number(opts
, "bootindex", -1);
3646 if (!option_rom
[nb_option_roms
].name
) {
3647 error_report("Option ROM file is not specified");
3652 case QEMU_OPTION_semihosting
:
3653 qemu_semihosting_enable();
3655 case QEMU_OPTION_semihosting_config
:
3656 if (qemu_semihosting_config_options(optarg
) != 0) {
3660 case QEMU_OPTION_name
:
3661 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3667 case QEMU_OPTION_prom_env
:
3668 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3669 error_report("too many prom variables");
3672 prom_envs
[nb_prom_envs
] = optarg
;
3675 case QEMU_OPTION_old_param
:
3678 case QEMU_OPTION_rtc
:
3679 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3685 case QEMU_OPTION_tb_size
:
3687 error_report("TCG is disabled");
3690 if (qemu_strtoul(optarg
, NULL
, 0, &tcg_tb_size
) < 0) {
3691 error_report("Invalid argument to -tb-size");
3695 case QEMU_OPTION_icount
:
3696 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3702 case QEMU_OPTION_incoming
:
3704 runstate_set(RUN_STATE_INMIGRATE
);
3708 case QEMU_OPTION_only_migratable
:
3709 only_migratable
= 1;
3711 case QEMU_OPTION_nodefaults
:
3714 case QEMU_OPTION_xen_domid
:
3715 if (!(xen_available())) {
3716 error_report("Option not supported for this target");
3719 xen_domid
= atoi(optarg
);
3721 case QEMU_OPTION_xen_attach
:
3722 if (!(xen_available())) {
3723 error_report("Option not supported for this target");
3726 xen_mode
= XEN_ATTACH
;
3728 case QEMU_OPTION_xen_domid_restrict
:
3729 if (!(xen_available())) {
3730 error_report("Option not supported for this target");
3733 xen_domid_restrict
= true;
3735 case QEMU_OPTION_trace
:
3737 trace_file
= trace_opt_parse(optarg
);
3739 case QEMU_OPTION_readconfig
:
3741 int ret
= qemu_read_config_file(optarg
);
3743 error_report("read config %s: %s", optarg
,
3749 case QEMU_OPTION_spice
:
3750 olist
= qemu_find_opts("spice");
3752 error_report("spice support is disabled");
3755 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3761 case QEMU_OPTION_writeconfig
:
3764 if (strcmp(optarg
, "-") == 0) {
3767 fp
= fopen(optarg
, "w");
3769 error_report("open %s: %s", optarg
,
3774 qemu_config_write(fp
);
3780 case QEMU_OPTION_qtest
:
3781 qtest_chrdev
= optarg
;
3783 case QEMU_OPTION_qtest_log
:
3786 case QEMU_OPTION_sandbox
:
3787 olist
= qemu_find_opts("sandbox");
3789 #ifndef CONFIG_SECCOMP
3790 error_report("-sandbox support is not enabled "
3791 "in this QEMU binary");
3796 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3801 case QEMU_OPTION_add_fd
:
3803 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3809 error_report("File descriptor passing is disabled on this "
3814 case QEMU_OPTION_object
:
3815 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
3821 case QEMU_OPTION_realtime
:
3822 warn_report("'-realtime mlock=...' is deprecated, please use "
3823 "'-overcommit mem-lock=...' instead");
3824 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
3829 /* Don't override the -overcommit option if set */
3830 enable_mlock
= enable_mlock
||
3831 qemu_opt_get_bool(opts
, "mlock", true);
3833 case QEMU_OPTION_overcommit
:
3834 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3839 /* Don't override the -realtime option if set */
3840 enable_mlock
= enable_mlock
||
3841 qemu_opt_get_bool(opts
, "mem-lock", false);
3842 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3844 case QEMU_OPTION_msg
:
3845 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3850 configure_msg(opts
);
3852 case QEMU_OPTION_dump_vmstate
:
3853 if (vmstate_dump_file
) {
3854 error_report("only one '-dump-vmstate' "
3855 "option may be given");
3858 vmstate_dump_file
= fopen(optarg
, "w");
3859 if (vmstate_dump_file
== NULL
) {
3860 error_report("open %s: %s", optarg
, strerror(errno
));
3864 case QEMU_OPTION_enable_sync_profile
:
3867 case QEMU_OPTION_nouserconfig
:
3868 /* Nothing to be parsed here. Especially, do not error out below. */
3871 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3872 error_report("Option not supported in this build");
3879 * Clear error location left behind by the loop.
3880 * Best done right after the loop. Do not insert code here!
3884 user_register_global_props();
3886 replay_configure(icount_opts
);
3888 if (incoming
&& !preconfig_exit_requested
) {
3889 error_report("'preconfig' and 'incoming' options are "
3890 "mutually exclusive");
3894 configure_rtc(qemu_find_opts_singleton("rtc"));
3896 machine_class
= select_machine();
3897 object_set_machine_compat_props(machine_class
->compat_props
);
3899 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
3902 rcu_disable_atfork();
3904 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
3905 error_reportf_err(err
, "cannot create PID file: ");
3909 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
3910 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
3912 if (qemu_init_main_loop(&main_loop_err
)) {
3913 error_report_err(main_loop_err
);
3917 #ifdef CONFIG_SECCOMP
3918 olist
= qemu_find_opts_err("sandbox", NULL
);
3920 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
3924 qemu_opts_foreach(qemu_find_opts("name"),
3925 parse_name
, NULL
, &error_fatal
);
3928 qemu_opts_foreach(qemu_find_opts("add-fd"),
3929 parse_add_fd
, NULL
, &error_fatal
);
3931 qemu_opts_foreach(qemu_find_opts("add-fd"),
3932 cleanup_add_fd
, NULL
, &error_fatal
);
3935 current_machine
= MACHINE(object_new(object_class_get_name(
3936 OBJECT_CLASS(machine_class
))));
3937 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
3940 object_property_add_child(object_get_root(), "machine",
3941 OBJECT(current_machine
), &error_abort
);
3942 object_property_add_child(container_get(OBJECT(current_machine
),
3944 "sysbus", OBJECT(sysbus_get_default()),
3947 if (machine_class
->minimum_page_bits
) {
3948 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
3949 /* This would be a board error: specifying a minimum smaller than
3950 * a target's compile-time fixed setting.
3952 g_assert_not_reached();
3956 cpu_exec_init_all();
3958 if (machine_class
->hw_version
) {
3959 qemu_set_hw_version(machine_class
->hw_version
);
3962 if (cpu_option
&& is_help_option(cpu_option
)) {
3963 list_cpus(cpu_option
);
3967 if (!trace_init_backends()) {
3970 trace_init_file(trace_file
);
3972 /* Open the logfile at this point and set the log mask if necessary.
3975 qemu_set_log_filename(log_file
, &error_fatal
);
3980 mask
= qemu_str_to_log_mask(log_mask
);
3982 qemu_print_log_usage(stdout
);
3990 /* add configured firmware directories */
3991 dirs
= g_strsplit(CONFIG_QEMU_FIRMWAREPATH
, G_SEARCHPATH_SEPARATOR_S
, 0);
3992 for (i
= 0; dirs
[i
] != NULL
; i
++) {
3993 qemu_add_data_dir(dirs
[i
]);
3997 /* try to find datadir relative to the executable path */
3998 dir
= os_find_datadir();
3999 qemu_add_data_dir(dir
);
4002 /* add the datadir specified when building */
4003 qemu_add_data_dir(CONFIG_QEMU_DATADIR
);
4005 /* -L help lists the data directories and exits. */
4006 if (list_data_dirs
) {
4007 for (i
= 0; i
< data_dir_idx
; i
++) {
4008 printf("%s\n", data_dir
[i
]);
4013 /* machine_class: default to UP */
4014 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1;
4015 machine_class
->min_cpus
= machine_class
->min_cpus
?: 1;
4016 machine_class
->default_cpus
= machine_class
->default_cpus
?: 1;
4018 /* default to machine_class->default_cpus */
4019 smp_cpus
= machine_class
->default_cpus
;
4020 max_cpus
= machine_class
->default_cpus
;
4022 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4024 /* sanity-check smp_cpus and max_cpus against machine_class */
4025 if (smp_cpus
< machine_class
->min_cpus
) {
4026 error_report("Invalid SMP CPUs %d. The min CPUs "
4027 "supported by machine '%s' is %d", smp_cpus
,
4028 machine_class
->name
, machine_class
->min_cpus
);
4031 if (max_cpus
> machine_class
->max_cpus
) {
4032 error_report("Invalid SMP CPUs %d. The max CPUs "
4033 "supported by machine '%s' is %d", max_cpus
,
4034 machine_class
->name
, machine_class
->max_cpus
);
4039 * Get the default machine options from the machine if it is not already
4040 * specified either by the configuration file or by the command line.
4042 if (machine_class
->default_machine_opts
) {
4043 qemu_opts_set_defaults(qemu_find_opts("machine"),
4044 machine_class
->default_machine_opts
, 0);
4047 qemu_opts_foreach(qemu_find_opts("device"),
4048 default_driver_check
, NULL
, NULL
);
4049 qemu_opts_foreach(qemu_find_opts("global"),
4050 default_driver_check
, NULL
, NULL
);
4052 if (!vga_model
&& !default_vga
) {
4053 vga_interface_type
= VGA_DEVICE
;
4055 if (!has_defaults
|| machine_class
->no_serial
) {
4058 if (!has_defaults
|| machine_class
->no_parallel
) {
4059 default_parallel
= 0;
4061 if (!has_defaults
|| machine_class
->no_floppy
) {
4064 if (!has_defaults
|| machine_class
->no_cdrom
) {
4067 if (!has_defaults
|| machine_class
->no_sdcard
) {
4070 if (!has_defaults
) {
4071 default_monitor
= 0;
4076 if (is_daemonized()) {
4077 if (!preconfig_exit_requested
) {
4078 error_report("'preconfig' and 'daemonize' options are "
4079 "mutually exclusive");
4083 /* According to documentation and historically, -nographic redirects
4084 * serial port, parallel port and monitor to stdio, which does not work
4085 * with -daemonize. We can redirect these to null instead, but since
4086 * -nographic is legacy, let's just error out.
4087 * We disallow -nographic only if all other ports are not redirected
4088 * explicitly, to not break existing legacy setups which uses
4089 * -nographic _and_ redirects all ports explicitly - this is valid
4090 * usage, -nographic is just a no-op in this case.
4093 && (default_parallel
|| default_serial
|| default_monitor
)) {
4094 error_report("-nographic cannot be used with -daemonize");
4097 #ifdef CONFIG_CURSES
4098 if (dpy
.type
== DISPLAY_TYPE_CURSES
) {
4099 error_report("curses display cannot be used with -daemonize");
4106 if (default_parallel
)
4107 add_device_config(DEV_PARALLEL
, "null");
4108 if (default_serial
&& default_monitor
) {
4109 add_device_config(DEV_SERIAL
, "mon:stdio");
4112 add_device_config(DEV_SERIAL
, "stdio");
4113 if (default_monitor
)
4114 monitor_parse("stdio", "readline", false);
4118 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4119 if (default_parallel
)
4120 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4121 if (default_monitor
)
4122 monitor_parse("vc:80Cx24C", "readline", false);
4125 #if defined(CONFIG_VNC)
4126 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4130 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
4131 if (!qemu_display_find_default(&dpy
)) {
4132 dpy
.type
= DISPLAY_TYPE_NONE
;
4133 #if defined(CONFIG_VNC)
4134 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4138 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
4139 dpy
.type
= DISPLAY_TYPE_NONE
;
4142 if ((alt_grab
|| ctrl_grab
) && dpy
.type
!= DISPLAY_TYPE_SDL
) {
4143 error_report("-alt-grab and -ctrl-grab are only valid "
4144 "for SDL, ignoring option");
4146 if (dpy
.has_window_close
&&
4147 (dpy
.type
!= DISPLAY_TYPE_GTK
&& dpy
.type
!= DISPLAY_TYPE_SDL
)) {
4148 error_report("-no-quit is only valid for GTK and SDL, "
4152 qemu_display_early_init(&dpy
);
4153 qemu_console_early_init();
4155 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
4156 #if defined(CONFIG_OPENGL)
4157 error_report("OpenGL is not supported by the display");
4159 error_report("OpenGL support is disabled");
4167 qemu_opts_foreach(qemu_find_opts("object"),
4168 user_creatable_add_opts_foreach
,
4169 object_create_initial
, &error_fatal
);
4171 qemu_opts_foreach(qemu_find_opts("chardev"),
4172 chardev_init_func
, NULL
, &error_fatal
);
4173 /* now chardevs have been created we may have semihosting to connect */
4174 qemu_semihosting_connect_chardevs();
4176 #ifdef CONFIG_VIRTFS
4177 qemu_opts_foreach(qemu_find_opts("fsdev"),
4178 fsdev_init_func
, NULL
, &error_fatal
);
4181 if (qemu_opts_foreach(qemu_find_opts("device"),
4182 device_help_func
, NULL
, NULL
)) {
4187 * Note: we need to create block backends before
4188 * machine_set_property(), so machine properties can refer to
4191 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
4193 machine_opts
= qemu_get_machine_opts();
4194 qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4196 current_machine
->ram_size
= ram_size
;
4197 current_machine
->maxram_size
= maxram_size
;
4198 current_machine
->ram_slots
= ram_slots
;
4201 * Note: uses machine properties such as kernel-irqchip, must run
4202 * after machine_set_property().
4204 configure_accelerator(current_machine
, argv
[0]);
4207 * Beware, QOM objects created before this point miss global and
4208 * compat properties.
4210 * Global properties get set up by qdev_prop_register_global(),
4211 * called from user_register_global_props(), and certain option
4212 * desugaring. Also in CPU feature desugaring (buried in
4213 * parse_cpu_option()), which happens below this point, but may
4214 * only target the CPU type, which can only be created after
4215 * parse_cpu_option() returned the type.
4217 * Machine compat properties: object_set_machine_compat_props().
4218 * Accelerator compat props: object_set_accelerator_compat_props(),
4219 * called from configure_accelerator().
4222 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
4223 error_report("Machine type '%s' is deprecated: %s",
4224 machine_class
->name
, machine_class
->deprecation_reason
);
4228 * Note: creates a QOM object, must run only after global and
4229 * compat properties have been set up.
4231 migration_object_init();
4234 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4237 machine_opts
= qemu_get_machine_opts();
4238 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4239 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4240 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4241 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4243 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4245 boot_order
= qemu_opt_get(opts
, "order");
4247 validate_bootdevices(boot_order
, &error_fatal
);
4250 boot_once
= qemu_opt_get(opts
, "once");
4252 validate_bootdevices(boot_once
, &error_fatal
);
4255 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4256 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4260 boot_order
= machine_class
->default_boot_order
;
4263 if (!kernel_cmdline
) {
4264 kernel_cmdline
= "";
4265 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4268 linux_boot
= (kernel_filename
!= NULL
);
4270 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4271 error_report("-append only allowed with -kernel option");
4275 if (!linux_boot
&& initrd_filename
!= NULL
) {
4276 error_report("-initrd only allowed with -kernel option");
4280 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4281 /* fall back to the -kernel/-append */
4282 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4285 os_set_line_buffering();
4287 /* spice needs the timers to be initialized by this point */
4292 if (!tcg_enabled()) {
4293 error_report("-icount is not allowed with hardware virtualization");
4296 configure_icount(icount_opts
, &error_abort
);
4297 qemu_opts_del(icount_opts
);
4300 if (tcg_enabled()) {
4301 qemu_tcg_configure(accel_opts
, &error_fatal
);
4305 QemuOptsList
*net
= qemu_find_opts("net");
4306 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4308 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4312 if (net_init_clients(&err
) < 0) {
4313 error_report_err(err
);
4317 qemu_opts_foreach(qemu_find_opts("object"),
4318 user_creatable_add_opts_foreach
,
4319 object_create_delayed
, &error_fatal
);
4323 /* init the bluetooth world */
4324 if (foreach_device_config(DEV_BT
, bt_parse
))
4327 if (!xen_enabled()) {
4328 /* On 32-bit hosts, QEMU is limited by virtual address space */
4329 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4330 error_report("at most 2047 MB RAM can be simulated");
4337 dirty_bitmap_mig_init();
4339 qemu_opts_foreach(qemu_find_opts("mon"),
4340 mon_init_func
, NULL
, &error_fatal
);
4342 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4344 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4346 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4349 /* If no default VGA is requested, the default is "none". */
4351 vga_model
= get_default_vga_model(machine_class
);
4354 select_vgahw(machine_class
, vga_model
);
4358 i
= select_watchdog(watchdog
);
4360 exit (i
== 1 ? 1 : 0);
4363 /* This checkpoint is required by replay to separate prior clock
4364 reading from the other reads, because timer polling functions query
4365 clock values from the log. */
4366 replay_checkpoint(CHECKPOINT_INIT
);
4367 qdev_machine_init();
4369 current_machine
->boot_order
= boot_order
;
4371 /* parse features once if machine provides default cpu_type */
4372 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
4374 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
4376 parse_numa_opts(current_machine
);
4378 /* do monitor/qmp handling at preconfig state if requested */
4381 audio_init_audiodevs();
4383 /* from here on runstate is RUN_STATE_PRELAUNCH */
4384 machine_run_board_init(current_machine
);
4390 if (hax_enabled()) {
4394 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4395 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
4397 /* init USB devices */
4398 if (machine_usb(current_machine
)) {
4399 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4403 /* Check if IGD GFX passthrough. */
4406 /* init generic devices */
4407 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4408 qemu_opts_foreach(qemu_find_opts("device"),
4409 device_init_func
, NULL
, &error_fatal
);
4411 cpu_synchronize_all_post_init();
4413 rom_reset_order_override();
4415 /* Did we create any drives that we failed to create a device for? */
4416 drive_check_orphaned();
4418 /* Don't warn about the default network setup that you get if
4419 * no command line -net or -netdev options are specified. There
4420 * are two cases that we would otherwise complain about:
4421 * (1) board doesn't support a NIC but the implicit "-net nic"
4423 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4424 * sets up a nic that isn't connected to anything.
4426 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
4427 net_check_clients();
4431 qemu_boot_set(boot_once
, &error_fatal
);
4432 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4435 /* init local displays */
4436 ds
= init_displaystate();
4437 qemu_display_init(ds
, &dpy
);
4439 /* must be after terminal init, SDL library changes signal handlers */
4440 os_setup_signal_handling();
4442 /* init remote displays */
4444 qemu_opts_foreach(qemu_find_opts("vnc"),
4445 vnc_init_func
, NULL
, &error_fatal
);
4449 qemu_spice_display_init();
4452 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4456 qdev_machine_creation_done();
4458 /* TODO: once all bus devices are qdevified, this should be done
4459 * when bus is created by qdev.c */
4460 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4461 qemu_run_machine_init_done_notifiers();
4463 if (rom_check_and_register_reset() != 0) {
4464 error_report("rom check and register reset failed");
4470 /* This checkpoint is required by replay to separate prior clock
4471 reading from the other reads, because timer polling functions query
4472 clock values from the log. */
4473 replay_checkpoint(CHECKPOINT_RESET
);
4474 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
4475 register_global_state();
4477 Error
*local_err
= NULL
;
4478 if (load_snapshot(loadvm
, &local_err
) < 0) {
4479 error_report_err(local_err
);
4484 if (replay_mode
!= REPLAY_MODE_NONE
) {
4485 replay_vmstate_init();
4488 qdev_prop_check_globals();
4489 if (vmstate_dump_file
) {
4491 dump_vmstate_json_to_file(vmstate_dump_file
);
4496 Error
*local_err
= NULL
;
4497 qemu_start_incoming_migration(incoming
, &local_err
);
4499 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4502 } else if (autostart
) {
4506 accel_setup_post(current_machine
);
4511 gdbserver_cleanup();
4514 * cleaning up the migration object cancels any existing migration
4515 * try to do this early so that it also stops using devices.
4517 migration_shutdown();
4519 /* No more vcpu or device emulation activity beyond this point */
4522 job_cancel_sync_all();
4527 /* vhost-user must be cleaned up before chardevs. */
4533 user_creatable_cleanup();
4534 /* TODO: unref root container, check all devices are ok */