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)
36 #define SDL_MAIN_HANDLED
38 #if SDL_MAJOR_VERSION == 1
39 int qemu_main(int argc
, char **argv
);
40 int main(int argc
, char **argv
)
42 return qemu_main(argc
, argv
);
45 #define main qemu_main
46 #elif SDL_MAJOR_VERSION == 2
49 #error undefined SDL version
52 #endif /* CONFIG_SDL */
56 #define main qemu_main
57 #endif /* CONFIG_COCOA */
60 #include "qemu/error-report.h"
61 #include "qemu/sockets.h"
63 #include "hw/boards.h"
64 #include "sysemu/accel.h"
66 #include "hw/isa/isa.h"
67 #include "hw/scsi/scsi.h"
68 #include "hw/display/vga.h"
70 #include "sysemu/watchdog.h"
71 #include "hw/firmware/smbios.h"
72 #include "hw/acpi/acpi.h"
73 #include "hw/xen/xen.h"
75 #include "hw/loader.h"
76 #include "monitor/qdev.h"
77 #include "sysemu/bt.h"
79 #include "net/slirp.h"
80 #include "monitor/monitor.h"
81 #include "ui/console.h"
83 #include "sysemu/sysemu.h"
84 #include "sysemu/numa.h"
85 #include "exec/gdbstub.h"
86 #include "qemu/timer.h"
87 #include "chardev/char.h"
88 #include "qemu/bitmap.h"
90 #include "sysemu/blockdev.h"
91 #include "hw/block/block.h"
92 #include "migration/misc.h"
93 #include "migration/snapshot.h"
94 #include "migration/global_state.h"
95 #include "sysemu/tpm.h"
96 #include "sysemu/dma.h"
97 #include "hw/audio/soundhw.h"
98 #include "audio/audio.h"
99 #include "sysemu/cpus.h"
100 #include "migration/colo.h"
101 #include "migration/postcopy-ram.h"
102 #include "sysemu/kvm.h"
103 #include "sysemu/hax.h"
104 #include "qapi/qobject-input-visitor.h"
105 #include "qemu/option.h"
106 #include "qemu/config-file.h"
107 #include "qemu-options.h"
108 #include "qemu/main-loop.h"
110 #include "fsdev/qemu-fsdev.h"
112 #include "sysemu/qtest.h"
114 #include "disas/disas.h"
117 #include "slirp/libslirp.h"
119 #include "trace-root.h"
120 #include "trace/control.h"
121 #include "qemu/queue.h"
122 #include "sysemu/arch_init.h"
124 #include "ui/qemu-spice.h"
125 #include "qapi/string-input-visitor.h"
126 #include "qapi/opts-visitor.h"
127 #include "qapi/clone-visitor.h"
128 #include "qom/object_interfaces.h"
129 #include "exec/semihost.h"
130 #include "crypto/init.h"
131 #include "sysemu/replay.h"
132 #include "qapi/qapi-events-run-state.h"
133 #include "qapi/qapi-visit-block-core.h"
134 #include "qapi/qapi-visit-ui.h"
135 #include "qapi/qapi-commands-block-core.h"
136 #include "qapi/qapi-commands-misc.h"
137 #include "qapi/qapi-commands-run-state.h"
138 #include "qapi/qapi-commands-ui.h"
139 #include "qapi/qmp/qerror.h"
140 #include "sysemu/iothread.h"
142 #define MAX_VIRTIO_CONSOLES 1
144 static const char *data_dir
[16];
145 static int data_dir_idx
;
146 const char *bios_name
= NULL
;
147 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
149 const char* keyboard_layout
= NULL
;
151 const char *mem_path
= NULL
;
152 int mem_prealloc
= 0; /* force preallocation of physical target memory */
153 bool enable_mlock
= false;
154 bool enable_cpu_pm
= false;
156 NICInfo nd_table
[MAX_NICS
];
162 } rtc_base_type
= RTC_BASE_UTC
;
163 static time_t rtc_ref_start_datetime
;
164 static int rtc_realtime_clock_offset
; /* used only with QEMU_CLOCK_REALTIME */
165 static int rtc_host_datetime_offset
= -1; /* valid & used only with
167 QEMUClockType rtc_clock
;
168 int vga_interface_type
= VGA_NONE
;
169 static DisplayOptions dpy
;
171 static int num_serial_hds
;
172 static Chardev
**serial_hds
;
173 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
174 Chardev
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
175 int win2k_install_hack
= 0;
178 unsigned int max_cpus
;
181 int acpi_enabled
= 1;
184 static int no_reboot
;
187 int graphic_rotate
= 0;
188 const char *watchdog
;
189 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
192 const char *qemu_name
;
195 unsigned int nb_prom_envs
= 0;
196 const char *prom_envs
[MAX_PROM_ENVS
];
199 uint8_t *boot_splash_filedata
;
200 size_t boot_splash_filedata_size
;
201 uint8_t qemu_extra_params_fw
[2];
202 bool wakeup_suspend_enabled
;
204 int icount_align_option
;
206 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
207 * little-endian "wire format" described in the SMBIOS 2.6 specification.
212 /* Trace unassigned memory or i/o accesses. */
213 bool trace_unassigned
;
215 static NotifierList exit_notifiers
=
216 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
218 static NotifierList machine_init_done_notifiers
=
219 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
223 enum xen_mode xen_mode
= XEN_EMULATE
;
224 bool xen_domid_restrict
;
226 static int has_defaults
= 1;
227 static int default_serial
= 1;
228 static int default_parallel
= 1;
229 static int default_virtcon
= 1;
230 static int default_monitor
= 1;
231 static int default_floppy
= 1;
232 static int default_cdrom
= 1;
233 static int default_sdcard
= 1;
234 static int default_vga
= 1;
235 static int default_net
= 1;
241 { .driver
= "isa-serial", .flag
= &default_serial
},
242 { .driver
= "isa-parallel", .flag
= &default_parallel
},
243 { .driver
= "isa-fdc", .flag
= &default_floppy
},
244 { .driver
= "floppy", .flag
= &default_floppy
},
245 { .driver
= "ide-cd", .flag
= &default_cdrom
},
246 { .driver
= "ide-hd", .flag
= &default_cdrom
},
247 { .driver
= "ide-drive", .flag
= &default_cdrom
},
248 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
249 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
250 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
251 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
252 { .driver
= "VGA", .flag
= &default_vga
},
253 { .driver
= "isa-vga", .flag
= &default_vga
},
254 { .driver
= "cirrus-vga", .flag
= &default_vga
},
255 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
256 { .driver
= "vmware-svga", .flag
= &default_vga
},
257 { .driver
= "qxl-vga", .flag
= &default_vga
},
258 { .driver
= "virtio-vga", .flag
= &default_vga
},
261 static QemuOptsList qemu_rtc_opts
= {
263 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
268 .type
= QEMU_OPT_STRING
,
271 .type
= QEMU_OPT_STRING
,
274 .type
= QEMU_OPT_STRING
,
276 { /* end of list */ }
280 static QemuOptsList qemu_option_rom_opts
= {
281 .name
= "option-rom",
282 .implied_opt_name
= "romfile",
283 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
287 .type
= QEMU_OPT_NUMBER
,
290 .type
= QEMU_OPT_STRING
,
292 { /* end of list */ }
296 static QemuOptsList qemu_machine_opts
= {
298 .implied_opt_name
= "type",
300 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
303 * no elements => accept any
304 * sanity checking will happen later
305 * when setting machine properties
311 static QemuOptsList qemu_accel_opts
= {
313 .implied_opt_name
= "accel",
314 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
319 .type
= QEMU_OPT_STRING
,
320 .help
= "Select the type of accelerator",
324 .type
= QEMU_OPT_STRING
,
325 .help
= "Enable/disable multi-threaded TCG",
327 { /* end of list */ }
331 static QemuOptsList qemu_boot_opts
= {
333 .implied_opt_name
= "order",
335 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
339 .type
= QEMU_OPT_STRING
,
342 .type
= QEMU_OPT_STRING
,
345 .type
= QEMU_OPT_BOOL
,
348 .type
= QEMU_OPT_STRING
,
350 .name
= "splash-time",
351 .type
= QEMU_OPT_STRING
,
353 .name
= "reboot-timeout",
354 .type
= QEMU_OPT_STRING
,
357 .type
= QEMU_OPT_BOOL
,
363 static QemuOptsList qemu_add_fd_opts
= {
365 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
369 .type
= QEMU_OPT_NUMBER
,
370 .help
= "file descriptor of which a duplicate is added to fd set",
373 .type
= QEMU_OPT_NUMBER
,
374 .help
= "ID of the fd set to add fd to",
377 .type
= QEMU_OPT_STRING
,
378 .help
= "free-form string used to describe fd",
380 { /* end of list */ }
384 static QemuOptsList qemu_object_opts
= {
386 .implied_opt_name
= "qom-type",
387 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
393 static QemuOptsList qemu_tpmdev_opts
= {
395 .implied_opt_name
= "type",
396 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
398 /* options are defined in the TPM backends */
399 { /* end of list */ }
403 static QemuOptsList qemu_realtime_opts
= {
405 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
409 .type
= QEMU_OPT_BOOL
,
411 { /* end of list */ }
415 static QemuOptsList qemu_overcommit_opts
= {
416 .name
= "overcommit",
417 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
421 .type
= QEMU_OPT_BOOL
,
425 .type
= QEMU_OPT_BOOL
,
427 { /* end of list */ }
431 static QemuOptsList qemu_msg_opts
= {
433 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
437 .type
= QEMU_OPT_BOOL
,
439 { /* end of list */ }
443 static QemuOptsList qemu_name_opts
= {
445 .implied_opt_name
= "guest",
447 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
451 .type
= QEMU_OPT_STRING
,
452 .help
= "Sets the name of the guest.\n"
453 "This name will be displayed in the SDL window caption.\n"
454 "The name will also be used for the VNC server",
457 .type
= QEMU_OPT_STRING
,
458 .help
= "Sets the name of the QEMU process, as shown in top etc",
460 .name
= "debug-threads",
461 .type
= QEMU_OPT_BOOL
,
462 .help
= "When enabled, name the individual threads; defaults off.\n"
463 "NOTE: The thread names are for debugging and not a\n"
466 { /* End of list */ }
470 static QemuOptsList qemu_mem_opts
= {
472 .implied_opt_name
= "size",
473 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
478 .type
= QEMU_OPT_SIZE
,
482 .type
= QEMU_OPT_NUMBER
,
486 .type
= QEMU_OPT_SIZE
,
488 { /* end of list */ }
492 static QemuOptsList qemu_icount_opts
= {
494 .implied_opt_name
= "shift",
496 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
500 .type
= QEMU_OPT_STRING
,
503 .type
= QEMU_OPT_BOOL
,
506 .type
= QEMU_OPT_BOOL
,
509 .type
= QEMU_OPT_STRING
,
512 .type
= QEMU_OPT_STRING
,
514 .name
= "rrsnapshot",
515 .type
= QEMU_OPT_STRING
,
517 { /* end of list */ }
521 static QemuOptsList qemu_semihosting_config_opts
= {
522 .name
= "semihosting-config",
523 .implied_opt_name
= "enable",
524 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
528 .type
= QEMU_OPT_BOOL
,
531 .type
= QEMU_OPT_STRING
,
534 .type
= QEMU_OPT_STRING
,
536 { /* end of list */ }
540 static QemuOptsList qemu_fw_cfg_opts
= {
542 .implied_opt_name
= "name",
543 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
547 .type
= QEMU_OPT_STRING
,
548 .help
= "Sets the fw_cfg name of the blob to be inserted",
551 .type
= QEMU_OPT_STRING
,
552 .help
= "Sets the name of the file from which "
553 "the fw_cfg blob will be loaded",
556 .type
= QEMU_OPT_STRING
,
557 .help
= "Sets content of the blob to be inserted from a string",
559 { /* end of list */ }
564 * Get machine options
566 * Returns: machine options (never null).
568 QemuOpts
*qemu_get_machine_opts(void)
570 return qemu_find_opts_singleton("machine");
573 const char *qemu_get_vm_name(void)
578 static void res_free(void)
580 g_free(boot_splash_filedata
);
581 boot_splash_filedata
= NULL
;
584 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
586 const char *driver
= qemu_opt_get(opts
, "driver");
591 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
592 if (strcmp(default_list
[i
].driver
, driver
) != 0)
594 *(default_list
[i
].flag
) = 0;
599 /***********************************************************/
602 static RunState current_run_state
= RUN_STATE_PRECONFIG
;
604 /* We use RUN_STATE__MAX but any invalid value will do */
605 static RunState vmstop_requested
= RUN_STATE__MAX
;
606 static QemuMutex vmstop_lock
;
611 } RunStateTransition
;
613 static const RunStateTransition runstate_transitions_def
[] = {
615 { RUN_STATE_PRECONFIG
, RUN_STATE_PRELAUNCH
},
616 /* Early switch to inmigrate state to allow -incoming CLI option work
617 * as it used to. TODO: delay actual switching to inmigrate state to
618 * the point after machine is built and remove this hack.
620 { RUN_STATE_PRECONFIG
, RUN_STATE_INMIGRATE
},
622 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
623 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
624 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
626 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
627 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
628 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
629 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
630 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
631 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
632 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
633 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
634 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
635 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
636 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
637 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
639 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
640 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
641 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
643 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
644 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
645 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
647 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
648 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
649 { RUN_STATE_PAUSED
, RUN_STATE_POSTMIGRATE
},
650 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
651 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
653 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
654 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
655 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
657 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
658 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
659 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
661 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
662 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PAUSED
},
663 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
664 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
665 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
667 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
668 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
670 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
672 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
673 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
674 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
675 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
676 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
677 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
678 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
679 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
680 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
681 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
682 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
684 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
686 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
687 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
688 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
690 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
691 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
692 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
693 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
694 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
695 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
697 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
698 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
699 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
700 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
702 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
703 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
704 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
706 { RUN_STATE__MAX
, RUN_STATE__MAX
},
709 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
711 bool runstate_check(RunState state
)
713 return current_run_state
== state
;
716 bool runstate_store(char *str
, size_t size
)
718 const char *state
= RunState_str(current_run_state
);
719 size_t len
= strlen(state
) + 1;
724 memcpy(str
, state
, len
);
728 static void runstate_init(void)
730 const RunStateTransition
*p
;
732 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
733 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
734 runstate_valid_transitions
[p
->from
][p
->to
] = true;
737 qemu_mutex_init(&vmstop_lock
);
740 /* This function will abort() on invalid state transitions */
741 void runstate_set(RunState new_state
)
743 assert(new_state
< RUN_STATE__MAX
);
745 if (current_run_state
== new_state
) {
749 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
750 error_report("invalid runstate transition: '%s' -> '%s'",
751 RunState_str(current_run_state
),
752 RunState_str(new_state
));
755 trace_runstate_set(new_state
);
756 current_run_state
= new_state
;
759 int runstate_is_running(void)
761 return runstate_check(RUN_STATE_RUNNING
);
764 bool runstate_needs_reset(void)
766 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
767 runstate_check(RUN_STATE_SHUTDOWN
);
770 StatusInfo
*qmp_query_status(Error
**errp
)
772 StatusInfo
*info
= g_malloc0(sizeof(*info
));
774 info
->running
= runstate_is_running();
775 info
->singlestep
= singlestep
;
776 info
->status
= current_run_state
;
781 bool qemu_vmstop_requested(RunState
*r
)
783 qemu_mutex_lock(&vmstop_lock
);
784 *r
= vmstop_requested
;
785 vmstop_requested
= RUN_STATE__MAX
;
786 qemu_mutex_unlock(&vmstop_lock
);
787 return *r
< RUN_STATE__MAX
;
790 void qemu_system_vmstop_request_prepare(void)
792 qemu_mutex_lock(&vmstop_lock
);
795 void qemu_system_vmstop_request(RunState state
)
797 vmstop_requested
= state
;
798 qemu_mutex_unlock(&vmstop_lock
);
802 /***********************************************************/
803 /* RTC reference time/date access */
804 static time_t qemu_ref_timedate(QEMUClockType clock
)
806 time_t value
= qemu_clock_get_ms(clock
) / 1000;
808 case QEMU_CLOCK_REALTIME
:
809 value
-= rtc_realtime_clock_offset
;
811 case QEMU_CLOCK_VIRTUAL
:
812 value
+= rtc_ref_start_datetime
;
814 case QEMU_CLOCK_HOST
:
815 if (rtc_base_type
== RTC_BASE_DATETIME
) {
816 value
-= rtc_host_datetime_offset
;
825 void qemu_get_timedate(struct tm
*tm
, int offset
)
827 time_t ti
= qemu_ref_timedate(rtc_clock
);
831 switch (rtc_base_type
) {
832 case RTC_BASE_DATETIME
:
836 case RTC_BASE_LOCALTIME
:
837 localtime_r(&ti
, tm
);
842 int qemu_timedate_diff(struct tm
*tm
)
846 switch (rtc_base_type
) {
847 case RTC_BASE_DATETIME
:
849 seconds
= mktimegm(tm
);
851 case RTC_BASE_LOCALTIME
:
854 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
855 seconds
= mktime(&tmp
);
862 return seconds
- qemu_ref_timedate(QEMU_CLOCK_HOST
);
865 static void configure_rtc_base_datetime(const char *startdate
)
867 time_t rtc_start_datetime
;
870 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d", &tm
.tm_year
, &tm
.tm_mon
,
871 &tm
.tm_mday
, &tm
.tm_hour
, &tm
.tm_min
, &tm
.tm_sec
) == 6) {
873 } else if (sscanf(startdate
, "%d-%d-%d",
874 &tm
.tm_year
, &tm
.tm_mon
, &tm
.tm_mday
) == 3) {
883 rtc_start_datetime
= mktimegm(&tm
);
884 if (rtc_start_datetime
== -1) {
886 error_report("invalid datetime format");
887 error_printf("valid formats: "
888 "'2006-06-17T16:01:21' or '2006-06-17'\n");
891 rtc_host_datetime_offset
= rtc_ref_start_datetime
- rtc_start_datetime
;
892 rtc_ref_start_datetime
= rtc_start_datetime
;
895 static void configure_rtc(QemuOpts
*opts
)
900 rtc_clock
= QEMU_CLOCK_HOST
;
901 rtc_ref_start_datetime
= qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
902 rtc_realtime_clock_offset
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) / 1000;
904 value
= qemu_opt_get(opts
, "base");
906 if (!strcmp(value
, "utc")) {
907 rtc_base_type
= RTC_BASE_UTC
;
908 } else if (!strcmp(value
, "localtime")) {
909 Error
*blocker
= NULL
;
910 rtc_base_type
= RTC_BASE_LOCALTIME
;
911 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
912 "-rtc base=localtime");
913 replay_add_blocker(blocker
);
915 rtc_base_type
= RTC_BASE_DATETIME
;
916 configure_rtc_base_datetime(value
);
919 value
= qemu_opt_get(opts
, "clock");
921 if (!strcmp(value
, "host")) {
922 rtc_clock
= QEMU_CLOCK_HOST
;
923 } else if (!strcmp(value
, "rt")) {
924 rtc_clock
= QEMU_CLOCK_REALTIME
;
925 } else if (!strcmp(value
, "vm")) {
926 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
928 error_report("invalid option value '%s'", value
);
932 value
= qemu_opt_get(opts
, "driftfix");
934 if (!strcmp(value
, "slew")) {
935 static GlobalProperty slew_lost_ticks
= {
936 .driver
= "mc146818rtc",
937 .property
= "lost_tick_policy",
941 qdev_prop_register_global(&slew_lost_ticks
);
942 } else if (!strcmp(value
, "none")) {
943 /* discard is default */
945 error_report("invalid option value '%s'", value
);
951 /***********************************************************/
952 /* Bluetooth support */
955 static struct HCIInfo
*hci_table
[MAX_NICS
];
957 struct HCIInfo
*qemu_next_hci(void)
959 if (cur_hci
== nb_hcis
)
962 return hci_table
[cur_hci
++];
965 static int bt_hci_parse(const char *str
)
970 if (nb_hcis
>= MAX_NICS
) {
971 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
984 bdaddr
.b
[5] = 0x56 + nb_hcis
;
985 hci
->bdaddr_set(hci
, bdaddr
.b
);
987 hci_table
[nb_hcis
++] = hci
;
992 static void bt_vhci_add(int vlan_id
)
994 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
997 warn_report("adding a VHCI to an empty scatternet %i",
1000 bt_vhci_init(bt_new_hci(vlan
));
1003 static struct bt_device_s
*bt_device_add(const char *opt
)
1005 struct bt_scatternet_s
*vlan
;
1007 char *endp
= strstr(opt
, ",vlan=");
1008 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
1011 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
1014 vlan_id
= strtol(endp
+ 6, &endp
, 0);
1016 error_report("unrecognised bluetooth vlan Id");
1021 vlan
= qemu_find_bt_vlan(vlan_id
);
1024 warn_report("adding a slave device to an empty scatternet %i",
1027 if (!strcmp(devname
, "keyboard"))
1028 return bt_keyboard_init(vlan
);
1030 error_report("unsupported bluetooth device '%s'", devname
);
1034 static int bt_parse(const char *opt
)
1036 const char *endp
, *p
;
1039 if (strstart(opt
, "hci", &endp
)) {
1040 if (!*endp
|| *endp
== ',') {
1042 if (!strstart(endp
, ",vlan=", 0))
1045 return bt_hci_parse(opt
);
1047 } else if (strstart(opt
, "vhci", &endp
)) {
1048 if (!*endp
|| *endp
== ',') {
1050 if (strstart(endp
, ",vlan=", &p
)) {
1051 vlan
= strtol(p
, (char **) &endp
, 0);
1053 error_report("bad scatternet '%s'", p
);
1057 error_report("bad parameter '%s'", endp
+ 1);
1066 } else if (strstart(opt
, "device:", &endp
))
1067 return !bt_device_add(endp
);
1069 error_report("bad bluetooth parameter '%s'", opt
);
1073 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1075 const char *proc_name
;
1077 if (qemu_opt_get(opts
, "debug-threads")) {
1078 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1080 qemu_name
= qemu_opt_get(opts
, "guest");
1082 proc_name
= qemu_opt_get(opts
, "process");
1084 os_set_proc_name(proc_name
);
1090 bool defaults_enabled(void)
1092 return has_defaults
;
1096 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1098 int fd
, dupfd
, flags
;
1100 const char *fd_opaque
= NULL
;
1103 fd
= qemu_opt_get_number(opts
, "fd", -1);
1104 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1105 fd_opaque
= qemu_opt_get(opts
, "opaque");
1108 error_setg(errp
, "fd option is required and must be non-negative");
1112 if (fd
<= STDERR_FILENO
) {
1113 error_setg(errp
, "fd cannot be a standard I/O stream");
1118 * All fds inherited across exec() necessarily have FD_CLOEXEC
1119 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1121 flags
= fcntl(fd
, F_GETFD
);
1122 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1123 error_setg(errp
, "fd is not valid or already in use");
1128 error_setg(errp
, "set option is required and must be non-negative");
1132 #ifdef F_DUPFD_CLOEXEC
1133 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1137 qemu_set_cloexec(dupfd
);
1141 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
1145 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1146 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1153 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1157 fd
= qemu_opt_get_number(opts
, "fd", -1);
1164 /***********************************************************/
1165 /* QEMU Block devices */
1167 #define HD_OPTS "media=disk"
1168 #define CDROM_OPTS "media=cdrom"
1170 #define PFLASH_OPTS ""
1174 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1176 BlockInterfaceType
*block_default_type
= opaque
;
1178 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
1181 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1183 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1184 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1189 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1190 int index
, const char *optstr
)
1195 if (!enable
|| drive_get_by_index(type
, index
)) {
1199 opts
= drive_add(type
, index
, NULL
, optstr
);
1201 drive_enable_snapshot(NULL
, opts
, NULL
);
1204 dinfo
= drive_new(opts
, type
, &error_abort
);
1205 dinfo
->is_default
= true;
1209 static QemuOptsList qemu_smp_opts
= {
1211 .implied_opt_name
= "cpus",
1212 .merge_lists
= true,
1213 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1217 .type
= QEMU_OPT_NUMBER
,
1220 .type
= QEMU_OPT_NUMBER
,
1223 .type
= QEMU_OPT_NUMBER
,
1226 .type
= QEMU_OPT_NUMBER
,
1229 .type
= QEMU_OPT_NUMBER
,
1231 { /*End of list */ }
1235 static void smp_parse(QemuOpts
*opts
)
1238 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1239 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1240 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1241 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1243 /* compute missing values, prefer sockets over cores over threads */
1244 if (cpus
== 0 || sockets
== 0) {
1245 cores
= cores
> 0 ? cores
: 1;
1246 threads
= threads
> 0 ? threads
: 1;
1248 sockets
= sockets
> 0 ? sockets
: 1;
1249 cpus
= cores
* threads
* sockets
;
1251 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1252 sockets
= max_cpus
/ (cores
* threads
);
1254 } else if (cores
== 0) {
1255 threads
= threads
> 0 ? threads
: 1;
1256 cores
= cpus
/ (sockets
* threads
);
1257 cores
= cores
> 0 ? cores
: 1;
1258 } else if (threads
== 0) {
1259 threads
= cpus
/ (cores
* sockets
);
1260 threads
= threads
> 0 ? threads
: 1;
1261 } else if (sockets
* cores
* threads
< cpus
) {
1262 error_report("cpu topology: "
1263 "sockets (%u) * cores (%u) * threads (%u) < "
1265 sockets
, cores
, threads
, cpus
);
1269 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1271 if (max_cpus
< cpus
) {
1272 error_report("maxcpus must be equal to or greater than smp");
1276 if (sockets
* cores
* threads
> max_cpus
) {
1277 error_report("cpu topology: "
1278 "sockets (%u) * cores (%u) * threads (%u) > "
1280 sockets
, cores
, threads
, max_cpus
);
1284 if (sockets
* cores
* threads
!= max_cpus
) {
1285 warn_report("Invalid CPU topology deprecated: "
1286 "sockets (%u) * cores (%u) * threads (%u) "
1288 sockets
, cores
, threads
, max_cpus
);
1293 smp_threads
= threads
;
1297 Error
*blocker
= NULL
;
1298 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1299 replay_add_blocker(blocker
);
1303 static void realtime_init(void)
1306 if (os_mlock() < 0) {
1307 error_report("locking memory failed");
1314 static void configure_msg(QemuOpts
*opts
)
1316 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1319 /***********************************************************/
1322 typedef struct SemihostingConfig
{
1324 SemihostingTarget target
;
1327 const char *cmdline
; /* concatenated argv */
1328 } SemihostingConfig
;
1330 static SemihostingConfig semihosting
;
1332 bool semihosting_enabled(void)
1334 return semihosting
.enabled
;
1337 SemihostingTarget
semihosting_get_target(void)
1339 return semihosting
.target
;
1342 const char *semihosting_get_arg(int i
)
1344 if (i
>= semihosting
.argc
) {
1347 return semihosting
.argv
[i
];
1350 int semihosting_get_argc(void)
1352 return semihosting
.argc
;
1355 const char *semihosting_get_cmdline(void)
1357 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1358 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1360 return semihosting
.cmdline
;
1363 static int add_semihosting_arg(void *opaque
,
1364 const char *name
, const char *val
,
1367 SemihostingConfig
*s
= opaque
;
1368 if (strcmp(name
, "arg") == 0) {
1370 /* one extra element as g_strjoinv() expects NULL-terminated array */
1371 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1372 s
->argv
[s
->argc
- 1] = val
;
1373 s
->argv
[s
->argc
] = NULL
;
1378 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1379 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1384 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1386 /* split -append and initialize argv[1..n] */
1387 cmd_token
= strtok(g_strdup(cmd
), " ");
1389 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1390 cmd_token
= strtok(NULL
, " ");
1394 /* Now we still need this for compatibility with XEN. */
1395 bool has_igd_gfx_passthru
;
1396 static void igd_gfx_passthru(void)
1398 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1401 /***********************************************************/
1404 static int usb_device_add(const char *devname
)
1406 USBDevice
*dev
= NULL
;
1408 if (!machine_usb(current_machine
)) {
1412 dev
= usbdevice_create(devname
);
1419 static int usb_parse(const char *cmdline
)
1422 r
= usb_device_add(cmdline
);
1424 error_report("could not add USB device '%s'", cmdline
);
1429 /***********************************************************/
1430 /* machine registration */
1432 MachineState
*current_machine
;
1434 static MachineClass
*find_machine(const char *name
)
1436 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1437 MachineClass
*mc
= NULL
;
1439 for (el
= machines
; el
; el
= el
->next
) {
1440 MachineClass
*temp
= el
->data
;
1442 if (!strcmp(temp
->name
, name
)) {
1447 !strcmp(temp
->alias
, name
)) {
1453 g_slist_free(machines
);
1457 MachineClass
*find_default_machine(void)
1459 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1460 MachineClass
*mc
= NULL
;
1462 for (el
= machines
; el
; el
= el
->next
) {
1463 MachineClass
*temp
= el
->data
;
1465 if (temp
->is_default
) {
1471 g_slist_free(machines
);
1475 MachineInfoList
*qmp_query_machines(Error
**errp
)
1477 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1478 MachineInfoList
*mach_list
= NULL
;
1480 for (el
= machines
; el
; el
= el
->next
) {
1481 MachineClass
*mc
= el
->data
;
1482 MachineInfoList
*entry
;
1485 info
= g_malloc0(sizeof(*info
));
1486 if (mc
->is_default
) {
1487 info
->has_is_default
= true;
1488 info
->is_default
= true;
1492 info
->has_alias
= true;
1493 info
->alias
= g_strdup(mc
->alias
);
1496 info
->name
= g_strdup(mc
->name
);
1497 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1498 info
->hotpluggable_cpus
= mc
->has_hotpluggable_cpus
;
1500 entry
= g_malloc0(sizeof(*entry
));
1501 entry
->value
= info
;
1502 entry
->next
= mach_list
;
1506 g_slist_free(machines
);
1510 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1512 ObjectProperty
*prop
;
1513 ObjectPropertyIterator iter
;
1515 if (!qemu_opt_has_help_opt(opts
)) {
1519 object_property_iter_init(&iter
, OBJECT(machine
));
1520 while ((prop
= object_property_iter_next(&iter
))) {
1525 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1526 prop
->name
, prop
->type
);
1527 if (prop
->description
) {
1528 error_printf(" (%s)\n", prop
->description
);
1537 struct vm_change_state_entry
{
1538 VMChangeStateHandler
*cb
;
1540 QLIST_ENTRY (vm_change_state_entry
) entries
;
1543 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1545 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1548 VMChangeStateEntry
*e
;
1550 e
= g_malloc0(sizeof (*e
));
1554 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1558 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1560 QLIST_REMOVE (e
, entries
);
1564 void vm_state_notify(int running
, RunState state
)
1566 VMChangeStateEntry
*e
, *next
;
1568 trace_vm_state_notify(running
, state
);
1570 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1571 e
->cb(e
->opaque
, running
, state
);
1575 static ShutdownCause reset_requested
;
1576 static ShutdownCause shutdown_requested
;
1577 static int shutdown_signal
;
1578 static pid_t shutdown_pid
;
1579 static int powerdown_requested
;
1580 static int debug_requested
;
1581 static int suspend_requested
;
1582 static bool preconfig_exit_requested
= true;
1583 static WakeupReason wakeup_reason
;
1584 static NotifierList powerdown_notifiers
=
1585 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1586 static NotifierList suspend_notifiers
=
1587 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1588 static NotifierList wakeup_notifiers
=
1589 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1590 static NotifierList shutdown_notifiers
=
1591 NOTIFIER_LIST_INITIALIZER(shutdown_notifiers
);
1592 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1594 ShutdownCause
qemu_shutdown_requested_get(void)
1596 return shutdown_requested
;
1599 ShutdownCause
qemu_reset_requested_get(void)
1601 return reset_requested
;
1604 static int qemu_shutdown_requested(void)
1606 return atomic_xchg(&shutdown_requested
, SHUTDOWN_CAUSE_NONE
);
1609 static void qemu_kill_report(void)
1611 if (!qtest_driver() && shutdown_signal
) {
1612 if (shutdown_pid
== 0) {
1613 /* This happens for eg ^C at the terminal, so it's worth
1614 * avoiding printing an odd message in that case.
1616 error_report("terminating on signal %d", shutdown_signal
);
1618 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1620 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1621 shutdown_signal
, shutdown_pid
,
1622 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1623 g_free(shutdown_cmd
);
1625 shutdown_signal
= 0;
1629 static ShutdownCause
qemu_reset_requested(void)
1631 ShutdownCause r
= reset_requested
;
1633 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1634 reset_requested
= SHUTDOWN_CAUSE_NONE
;
1637 return SHUTDOWN_CAUSE_NONE
;
1640 static int qemu_suspend_requested(void)
1642 int r
= suspend_requested
;
1643 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1644 suspend_requested
= 0;
1650 static WakeupReason
qemu_wakeup_requested(void)
1652 return wakeup_reason
;
1655 static int qemu_powerdown_requested(void)
1657 int r
= powerdown_requested
;
1658 powerdown_requested
= 0;
1662 static int qemu_debug_requested(void)
1664 int r
= debug_requested
;
1665 debug_requested
= 0;
1669 void qemu_exit_preconfig_request(void)
1671 preconfig_exit_requested
= true;
1675 * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE.
1677 void qemu_system_reset(ShutdownCause reason
)
1681 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1683 cpu_synchronize_all_states();
1685 if (mc
&& mc
->reset
) {
1688 qemu_devices_reset();
1690 if (reason
!= SHUTDOWN_CAUSE_SUBSYSTEM_RESET
) {
1691 qapi_event_send_reset(shutdown_caused_by_guest(reason
), reason
);
1693 cpu_synchronize_all_post_reset();
1696 void qemu_system_guest_panicked(GuestPanicInformation
*info
)
1698 qemu_log_mask(LOG_GUEST_ERROR
, "Guest crashed");
1701 current_cpu
->crash_occurred
= true;
1703 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
,
1705 vm_stop(RUN_STATE_GUEST_PANICKED
);
1707 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1709 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC
);
1713 if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_HYPER_V
) {
1714 qemu_log_mask(LOG_GUEST_ERROR
, "\nHV crash parameters: (%#"PRIx64
1715 " %#"PRIx64
" %#"PRIx64
" %#"PRIx64
" %#"PRIx64
")\n",
1716 info
->u
.hyper_v
.arg1
,
1717 info
->u
.hyper_v
.arg2
,
1718 info
->u
.hyper_v
.arg3
,
1719 info
->u
.hyper_v
.arg4
,
1720 info
->u
.hyper_v
.arg5
);
1721 } else if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_S390
) {
1722 qemu_log_mask(LOG_GUEST_ERROR
, " on cpu %d: %s\n"
1723 "PSW: 0x%016" PRIx64
" 0x%016" PRIx64
"\n",
1725 S390CrashReason_str(info
->u
.s390
.reason
),
1726 info
->u
.s390
.psw_mask
,
1727 info
->u
.s390
.psw_addr
);
1729 qapi_free_GuestPanicInformation(info
);
1733 void qemu_system_reset_request(ShutdownCause reason
)
1735 if (no_reboot
&& reason
!= SHUTDOWN_CAUSE_SUBSYSTEM_RESET
) {
1736 shutdown_requested
= reason
;
1738 reset_requested
= reason
;
1741 qemu_notify_event();
1744 static void qemu_system_suspend(void)
1747 notifier_list_notify(&suspend_notifiers
, NULL
);
1748 runstate_set(RUN_STATE_SUSPENDED
);
1749 qapi_event_send_suspend();
1752 void qemu_system_suspend_request(void)
1754 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1757 suspend_requested
= 1;
1759 qemu_notify_event();
1762 void qemu_register_suspend_notifier(Notifier
*notifier
)
1764 notifier_list_add(&suspend_notifiers
, notifier
);
1767 void qemu_system_wakeup_request(WakeupReason reason
, Error
**errp
)
1769 trace_system_wakeup_request(reason
);
1771 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1773 "Unable to wake up: guest is not in suspended state");
1776 if (!(wakeup_reason_mask
& (1 << reason
))) {
1779 runstate_set(RUN_STATE_RUNNING
);
1780 wakeup_reason
= reason
;
1781 qemu_notify_event();
1784 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1787 wakeup_reason_mask
|= (1 << reason
);
1789 wakeup_reason_mask
&= ~(1 << reason
);
1793 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1795 notifier_list_add(&wakeup_notifiers
, notifier
);
1798 void qemu_register_wakeup_support(void)
1800 wakeup_suspend_enabled
= true;
1803 bool qemu_wakeup_suspend_enabled(void)
1805 return wakeup_suspend_enabled
;
1808 CurrentMachineParams
*qmp_query_current_machine(Error
**errp
)
1810 CurrentMachineParams
*params
= g_malloc0(sizeof(*params
));
1811 params
->wakeup_suspend_support
= qemu_wakeup_suspend_enabled();
1816 void qemu_system_killed(int signal
, pid_t pid
)
1818 shutdown_signal
= signal
;
1822 /* Cannot call qemu_system_shutdown_request directly because
1823 * we are in a signal handler.
1825 shutdown_requested
= SHUTDOWN_CAUSE_HOST_SIGNAL
;
1826 qemu_notify_event();
1829 void qemu_system_shutdown_request(ShutdownCause reason
)
1831 trace_qemu_system_shutdown_request(reason
);
1832 replay_shutdown_request(reason
);
1833 shutdown_requested
= reason
;
1834 qemu_notify_event();
1837 static void qemu_system_powerdown(void)
1839 qapi_event_send_powerdown();
1840 notifier_list_notify(&powerdown_notifiers
, NULL
);
1843 static void qemu_system_shutdown(ShutdownCause cause
)
1845 qapi_event_send_shutdown(shutdown_caused_by_guest(cause
), cause
);
1846 notifier_list_notify(&shutdown_notifiers
, &cause
);
1849 void qemu_system_powerdown_request(void)
1851 trace_qemu_system_powerdown_request();
1852 powerdown_requested
= 1;
1853 qemu_notify_event();
1856 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1858 notifier_list_add(&powerdown_notifiers
, notifier
);
1861 void qemu_register_shutdown_notifier(Notifier
*notifier
)
1863 notifier_list_add(&shutdown_notifiers
, notifier
);
1866 void qemu_system_debug_request(void)
1868 debug_requested
= 1;
1869 qemu_notify_event();
1872 static bool main_loop_should_exit(void)
1875 ShutdownCause request
;
1877 if (preconfig_exit_requested
) {
1878 if (runstate_check(RUN_STATE_PRECONFIG
)) {
1879 runstate_set(RUN_STATE_PRELAUNCH
);
1881 preconfig_exit_requested
= false;
1884 if (qemu_debug_requested()) {
1885 vm_stop(RUN_STATE_DEBUG
);
1887 if (qemu_suspend_requested()) {
1888 qemu_system_suspend();
1890 request
= qemu_shutdown_requested();
1893 qemu_system_shutdown(request
);
1895 vm_stop(RUN_STATE_SHUTDOWN
);
1900 request
= qemu_reset_requested();
1903 qemu_system_reset(request
);
1905 if (!runstate_check(RUN_STATE_RUNNING
) &&
1906 !runstate_check(RUN_STATE_INMIGRATE
)) {
1907 runstate_set(RUN_STATE_PRELAUNCH
);
1910 if (qemu_wakeup_requested()) {
1912 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
1913 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1914 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1916 qapi_event_send_wakeup();
1918 if (qemu_powerdown_requested()) {
1919 qemu_system_powerdown();
1921 if (qemu_vmstop_requested(&r
)) {
1927 static void main_loop(void)
1929 #ifdef CONFIG_PROFILER
1932 while (!main_loop_should_exit()) {
1933 #ifdef CONFIG_PROFILER
1934 ti
= profile_getclock();
1936 main_loop_wait(false);
1937 #ifdef CONFIG_PROFILER
1938 dev_time
+= profile_getclock() - ti
;
1943 static void version(void)
1945 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
1946 QEMU_COPYRIGHT
"\n");
1949 static void QEMU_NORETURN
help(int exitcode
)
1952 printf("usage: %s [options] [disk_image]\n\n"
1953 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1954 error_get_progname());
1956 #define QEMU_OPTIONS_GENERATE_HELP
1957 #include "qemu-options-wrapper.h"
1959 printf("\nDuring emulation, the following keys are useful:\n"
1960 "ctrl-alt-f toggle full screen\n"
1961 "ctrl-alt-n switch to virtual console 'n'\n"
1962 "ctrl-alt toggle mouse and keyboard grab\n"
1964 "When using -nographic, press 'ctrl-a h' to get some help.\n"
1966 QEMU_HELP_BOTTOM
"\n");
1971 #define HAS_ARG 0x0001
1973 typedef struct QEMUOption
{
1980 static const QEMUOption qemu_options
[] = {
1981 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1982 #define QEMU_OPTIONS_GENERATE_OPTIONS
1983 #include "qemu-options-wrapper.h"
1987 typedef struct VGAInterfaceInfo
{
1988 const char *opt_name
; /* option name */
1989 const char *name
; /* human-readable name */
1990 /* Class names indicating that support is available.
1991 * If no class is specified, the interface is always available */
1992 const char *class_names
[2];
1995 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
2001 .name
= "standard VGA",
2002 .class_names
= { "VGA", "isa-vga" },
2005 .opt_name
= "cirrus",
2006 .name
= "Cirrus VGA",
2007 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
2010 .opt_name
= "vmware",
2011 .name
= "VMWare SVGA",
2012 .class_names
= { "vmware-svga" },
2015 .opt_name
= "virtio",
2016 .name
= "Virtio VGA",
2017 .class_names
= { "virtio-vga" },
2022 .class_names
= { "qxl-vga" },
2026 .name
= "TCX framebuffer",
2027 .class_names
= { "SUNW,tcx" },
2031 .name
= "CG3 framebuffer",
2032 .class_names
= { "cgthree" },
2035 .opt_name
= "xenfb",
2039 static bool vga_interface_available(VGAInterfaceType t
)
2041 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2043 assert(t
< VGA_TYPE_MAX
);
2044 return !ti
->class_names
[0] ||
2045 object_class_by_name(ti
->class_names
[0]) ||
2046 object_class_by_name(ti
->class_names
[1]);
2049 static void select_vgahw(const char *p
)
2054 assert(vga_interface_type
== VGA_NONE
);
2055 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2056 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2057 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2058 if (!vga_interface_available(t
)) {
2059 error_report("%s not available", ti
->name
);
2062 vga_interface_type
= t
;
2066 if (t
== VGA_TYPE_MAX
) {
2068 error_report("unknown vga type: %s", p
);
2072 const char *nextopt
;
2074 if (strstart(opts
, ",retrace=", &nextopt
)) {
2076 if (strstart(opts
, "dumb", &nextopt
))
2077 vga_retrace_method
= VGA_RETRACE_DUMB
;
2078 else if (strstart(opts
, "precise", &nextopt
))
2079 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2080 else goto invalid_vga
;
2081 } else goto invalid_vga
;
2086 static void parse_display_qapi(const char *optarg
)
2088 DisplayOptions
*opts
;
2091 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
2093 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
2094 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
2096 qapi_free_DisplayOptions(opts
);
2100 DisplayOptions
*qmp_query_display_options(Error
**errp
)
2102 return QAPI_CLONE(DisplayOptions
, &dpy
);
2105 static void parse_display(const char *p
)
2109 if (strstart(p
, "sdl", &opts
)) {
2111 * sdl DisplayType needs hand-crafted parser instead of
2112 * parse_display_qapi() due to some options not in
2113 * DisplayOptions, specifically:
2115 * Already deprecated.
2116 * - ctrl_grab + alt_grab
2117 * Not clear yet what happens to them long-term. Should
2118 * replaced by something better or deprecated and dropped.
2120 dpy
.type
= DISPLAY_TYPE_SDL
;
2122 const char *nextopt
;
2124 if (strstart(opts
, ",frame=", &nextopt
)) {
2125 g_printerr("The frame= sdl option is deprecated, and will be\n"
2126 "removed in a future release.\n");
2128 if (strstart(opts
, "on", &nextopt
)) {
2130 } else if (strstart(opts
, "off", &nextopt
)) {
2133 goto invalid_sdl_args
;
2135 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2137 if (strstart(opts
, "on", &nextopt
)) {
2139 } else if (strstart(opts
, "off", &nextopt
)) {
2142 goto invalid_sdl_args
;
2144 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2146 if (strstart(opts
, "on", &nextopt
)) {
2148 } else if (strstart(opts
, "off", &nextopt
)) {
2151 goto invalid_sdl_args
;
2153 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2155 dpy
.has_window_close
= true;
2156 if (strstart(opts
, "on", &nextopt
)) {
2157 dpy
.window_close
= true;
2158 } else if (strstart(opts
, "off", &nextopt
)) {
2159 dpy
.window_close
= false;
2161 goto invalid_sdl_args
;
2163 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2166 if (strstart(opts
, "on", &nextopt
)) {
2167 dpy
.gl
= DISPLAYGL_MODE_ON
;
2168 } else if (strstart(opts
, "core", &nextopt
)) {
2169 dpy
.gl
= DISPLAYGL_MODE_CORE
;
2170 } else if (strstart(opts
, "es", &nextopt
)) {
2171 dpy
.gl
= DISPLAYGL_MODE_ES
;
2172 } else if (strstart(opts
, "off", &nextopt
)) {
2173 dpy
.gl
= DISPLAYGL_MODE_OFF
;
2175 goto invalid_sdl_args
;
2179 error_report("invalid SDL option string");
2184 } else if (strstart(p
, "vnc", &opts
)) {
2186 * vnc isn't a (local) DisplayType but a protocol for remote
2190 vnc_parse(opts
+ 1, &error_fatal
);
2192 error_report("VNC requires a display argument vnc=<display>");
2196 parse_display_qapi(p
);
2200 char *qemu_find_file(int type
, const char *name
)
2206 /* Try the name as a straight path first */
2207 if (access(name
, R_OK
) == 0) {
2208 trace_load_file(name
, name
);
2209 return g_strdup(name
);
2213 case QEMU_FILE_TYPE_BIOS
:
2216 case QEMU_FILE_TYPE_KEYMAP
:
2217 subdir
= "keymaps/";
2223 for (i
= 0; i
< data_dir_idx
; i
++) {
2224 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2225 if (access(buf
, R_OK
) == 0) {
2226 trace_load_file(name
, buf
);
2234 static void qemu_add_data_dir(const char *path
)
2241 if (data_dir_idx
== ARRAY_SIZE(data_dir
)) {
2244 for (i
= 0; i
< data_dir_idx
; i
++) {
2245 if (strcmp(data_dir
[i
], path
) == 0) {
2246 return; /* duplicate */
2249 data_dir
[data_dir_idx
++] = g_strdup(path
);
2252 static inline bool nonempty_str(const char *str
)
2257 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2261 const char *name
, *file
, *str
;
2262 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2264 if (fw_cfg
== NULL
) {
2265 error_setg(errp
, "fw_cfg device not available");
2268 name
= qemu_opt_get(opts
, "name");
2269 file
= qemu_opt_get(opts
, "file");
2270 str
= qemu_opt_get(opts
, "string");
2272 /* we need name and either a file or the content string */
2273 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2274 error_setg(errp
, "invalid argument(s)");
2277 if (nonempty_str(file
) && nonempty_str(str
)) {
2278 error_setg(errp
, "file and string are mutually exclusive");
2281 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2282 error_setg(errp
, "name too long (max. %d char)",
2283 FW_CFG_MAX_FILE_PATH
- 1);
2286 if (strncmp(name
, "opt/", 4) != 0) {
2287 warn_report("externally provided fw_cfg item names "
2288 "should be prefixed with \"opt/\"");
2290 if (nonempty_str(str
)) {
2291 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2292 buf
= g_memdup(str
, size
);
2295 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
2296 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
2301 /* For legacy, keep user files in a specific global order. */
2302 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2303 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2304 fw_cfg_reset_order_override(fw_cfg
);
2308 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2310 return qdev_device_help(opts
);
2313 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2317 dev
= qdev_device_add(opts
, errp
);
2321 object_unref(OBJECT(dev
));
2325 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2327 Error
*local_err
= NULL
;
2329 if (!qemu_chr_new_from_opts(opts
, &local_err
)) {
2331 error_propagate(errp
, local_err
);
2339 #ifdef CONFIG_VIRTFS
2340 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2342 return qemu_fsdev_add(opts
, errp
);
2346 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2349 const char *chardev
;
2353 mode
= qemu_opt_get(opts
, "mode");
2357 if (strcmp(mode
, "readline") == 0) {
2358 flags
= MONITOR_USE_READLINE
;
2359 } else if (strcmp(mode
, "control") == 0) {
2360 flags
= MONITOR_USE_CONTROL
;
2362 error_setg(errp
, "unknown monitor mode \"%s\"", mode
);
2366 if (qemu_opt_get_bool(opts
, "pretty", 0))
2367 flags
|= MONITOR_USE_PRETTY
;
2369 chardev
= qemu_opt_get(opts
, "chardev");
2371 error_report("chardev is required");
2374 chr
= qemu_chr_find(chardev
);
2376 error_setg(errp
, "chardev \"%s\" not found", chardev
);
2380 monitor_init(chr
, flags
);
2384 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2386 static int monitor_device_index
= 0;
2391 if (strstart(optarg
, "chardev:", &p
)) {
2392 snprintf(label
, sizeof(label
), "%s", p
);
2394 snprintf(label
, sizeof(label
), "compat_monitor%d",
2395 monitor_device_index
);
2396 opts
= qemu_chr_parse_compat(label
, optarg
, true);
2398 error_report("parse error: %s", optarg
);
2403 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2404 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2405 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2406 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2407 monitor_device_index
++;
2410 struct device_config
{
2412 DEV_USB
, /* -usbdevice */
2414 DEV_SERIAL
, /* -serial */
2415 DEV_PARALLEL
, /* -parallel */
2416 DEV_VIRTCON
, /* -virtioconsole */
2417 DEV_DEBUGCON
, /* -debugcon */
2418 DEV_GDB
, /* -gdb, -s */
2419 DEV_SCLP
, /* s390 sclp */
2421 const char *cmdline
;
2423 QTAILQ_ENTRY(device_config
) next
;
2426 static QTAILQ_HEAD(, device_config
) device_configs
=
2427 QTAILQ_HEAD_INITIALIZER(device_configs
);
2429 static void add_device_config(int type
, const char *cmdline
)
2431 struct device_config
*conf
;
2433 conf
= g_malloc0(sizeof(*conf
));
2435 conf
->cmdline
= cmdline
;
2436 loc_save(&conf
->loc
);
2437 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2440 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2442 struct device_config
*conf
;
2445 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2446 if (conf
->type
!= type
)
2448 loc_push_restore(&conf
->loc
);
2449 rc
= func(conf
->cmdline
);
2450 loc_pop(&conf
->loc
);
2458 static int serial_parse(const char *devname
)
2460 int index
= num_serial_hds
;
2463 if (strcmp(devname
, "none") == 0)
2465 snprintf(label
, sizeof(label
), "serial%d", index
);
2466 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
2468 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
);
2469 if (!serial_hds
[index
]) {
2470 error_report("could not connect serial device"
2471 " to character backend '%s'", devname
);
2478 Chardev
*serial_hd(int i
)
2481 if (i
< num_serial_hds
) {
2482 return serial_hds
[i
];
2487 int serial_max_hds(void)
2489 return num_serial_hds
;
2492 static int parallel_parse(const char *devname
)
2494 static int index
= 0;
2497 if (strcmp(devname
, "none") == 0)
2499 if (index
== MAX_PARALLEL_PORTS
) {
2500 error_report("too many parallel ports");
2503 snprintf(label
, sizeof(label
), "parallel%d", index
);
2504 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
);
2505 if (!parallel_hds
[index
]) {
2506 error_report("could not connect parallel device"
2507 " to character backend '%s'", devname
);
2514 static int virtcon_parse(const char *devname
)
2516 QemuOptsList
*device
= qemu_find_opts("device");
2517 static int index
= 0;
2519 QemuOpts
*bus_opts
, *dev_opts
;
2521 if (strcmp(devname
, "none") == 0)
2523 if (index
== MAX_VIRTIO_CONSOLES
) {
2524 error_report("too many virtio consoles");
2528 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2529 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2531 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2532 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2534 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2535 virtcon_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
);
2536 if (!virtcon_hds
[index
]) {
2537 error_report("could not connect virtio console"
2538 " to character backend '%s'", devname
);
2541 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2547 static int debugcon_parse(const char *devname
)
2551 if (!qemu_chr_new_mux_mon("debugcon", devname
)) {
2552 error_report("invalid character backend '%s'", devname
);
2555 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2557 error_report("already have a debugcon device");
2560 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2561 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2565 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2567 const MachineClass
*mc1
= a
, *mc2
= b
;
2570 if (mc1
->family
== NULL
) {
2571 if (mc2
->family
== NULL
) {
2572 /* Compare standalone machine types against each other; they sort
2573 * in increasing order.
2575 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2576 object_class_get_name(OBJECT_CLASS(mc2
)));
2579 /* Standalone machine types sort after families. */
2583 if (mc2
->family
== NULL
) {
2584 /* Families sort before standalone machine types. */
2588 /* Families sort between each other alphabetically increasingly. */
2589 res
= strcmp(mc1
->family
, mc2
->family
);
2594 /* Within the same family, machine types sort in decreasing order. */
2595 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2596 object_class_get_name(OBJECT_CLASS(mc1
)));
2599 static MachineClass
*machine_parse(const char *name
)
2601 MachineClass
*mc
= NULL
;
2602 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2605 mc
= find_machine(name
);
2608 g_slist_free(machines
);
2611 if (name
&& !is_help_option(name
)) {
2612 error_report("unsupported machine type");
2613 error_printf("Use -machine help to list supported machines\n");
2615 printf("Supported machines are:\n");
2616 machines
= g_slist_sort(machines
, machine_class_cmp
);
2617 for (el
= machines
; el
; el
= el
->next
) {
2618 MachineClass
*mc
= el
->data
;
2620 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2622 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
2623 mc
->is_default
? " (default)" : "",
2624 mc
->deprecation_reason
? " (deprecated)" : "");
2628 g_slist_free(machines
);
2629 exit(!name
|| !is_help_option(name
));
2632 void qemu_add_exit_notifier(Notifier
*notify
)
2634 notifier_list_add(&exit_notifiers
, notify
);
2637 void qemu_remove_exit_notifier(Notifier
*notify
)
2639 notifier_remove(notify
);
2642 static void qemu_run_exit_notifiers(void)
2644 notifier_list_notify(&exit_notifiers
, NULL
);
2647 static const char *pid_file
;
2648 static Notifier qemu_unlink_pidfile_notifier
;
2650 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
2657 bool machine_init_done
;
2659 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2661 notifier_list_add(&machine_init_done_notifiers
, notify
);
2662 if (machine_init_done
) {
2663 notify
->notify(notify
, NULL
);
2667 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2669 notifier_remove(notify
);
2672 static void qemu_run_machine_init_done_notifiers(void)
2674 machine_init_done
= true;
2675 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2678 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2679 const char **poptarg
, int *poptind
)
2681 const QEMUOption
*popt
;
2682 int optind
= *poptind
;
2683 char *r
= argv
[optind
];
2686 loc_set_cmdline(argv
, optind
, 1);
2688 /* Treat --foo the same as -foo. */
2691 popt
= qemu_options
;
2694 error_report("invalid option");
2697 if (!strcmp(popt
->name
, r
+ 1))
2701 if (popt
->flags
& HAS_ARG
) {
2702 if (optind
>= argc
) {
2703 error_report("requires an argument");
2706 optarg
= argv
[optind
++];
2707 loc_set_cmdline(argv
, optind
- 2, 2);
2718 static MachineClass
*select_machine(void)
2720 MachineClass
*machine_class
= find_default_machine();
2725 loc_push_none(&loc
);
2727 opts
= qemu_get_machine_opts();
2728 qemu_opts_loc_restore(opts
);
2730 optarg
= qemu_opt_get(opts
, "type");
2732 machine_class
= machine_parse(optarg
);
2735 if (!machine_class
) {
2736 error_report("No machine specified, and there is no default");
2737 error_printf("Use -machine help to list supported machines\n");
2742 return machine_class
;
2745 static int machine_set_property(void *opaque
,
2746 const char *name
, const char *value
,
2749 Object
*obj
= OBJECT(opaque
);
2750 Error
*local_err
= NULL
;
2753 if (strcmp(name
, "type") == 0) {
2757 qom_name
= g_strdup(name
);
2758 for (p
= qom_name
; *p
; p
++) {
2764 object_property_parse(obj
, value
, qom_name
, &local_err
);
2768 error_propagate(errp
, local_err
);
2777 * Initial object creation happens before all other
2778 * QEMU data types are created. The majority of objects
2779 * can be created at this point. The rng-egd object
2780 * cannot be created here, as it depends on the chardev
2783 static bool object_create_initial(const char *type
, QemuOpts
*opts
)
2787 if (is_help_option(type
)) {
2790 printf("List of user creatable objects:\n");
2791 list
= object_class_get_list_sorted(TYPE_USER_CREATABLE
, false);
2792 for (l
= list
; l
!= NULL
; l
= l
->next
) {
2793 ObjectClass
*oc
= OBJECT_CLASS(l
->data
);
2794 printf(" %s\n", object_class_get_name(oc
));
2800 klass
= object_class_by_name(type
);
2801 if (klass
&& qemu_opt_has_help_opt(opts
)) {
2802 ObjectPropertyIterator iter
;
2803 ObjectProperty
*prop
;
2804 GPtrArray
*array
= g_ptr_array_new();
2807 object_class_property_iter_init(&iter
, klass
);
2808 while ((prop
= object_property_iter_next(&iter
))) {
2815 str
= g_string_new(NULL
);
2816 g_string_append_printf(str
, " %s=<%s>", prop
->name
, prop
->type
);
2817 if (prop
->description
) {
2818 if (str
->len
< 24) {
2819 g_string_append_printf(str
, "%*s", 24 - (int)str
->len
, "");
2821 g_string_append_printf(str
, " - %s", prop
->description
);
2823 g_ptr_array_add(array
, g_string_free(str
, false));
2825 g_ptr_array_sort(array
, (GCompareFunc
)qemu_pstrcmp0
);
2826 if (array
->len
> 0) {
2827 printf("%s options:\n", type
);
2829 printf("There are no options for %s.\n", type
);
2831 for (i
= 0; i
< array
->len
; i
++) {
2832 printf("%s\n", (char *)array
->pdata
[i
]);
2834 g_ptr_array_set_free_func(array
, g_free
);
2835 g_ptr_array_free(array
, true);
2839 if (g_str_equal(type
, "rng-egd") ||
2840 g_str_has_prefix(type
, "pr-manager-")) {
2844 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
2845 if (g_str_equal(type
, "cryptodev-vhost-user")) {
2851 * return false for concrete netfilters since
2852 * they depend on netdevs already existing
2854 if (g_str_equal(type
, "filter-buffer") ||
2855 g_str_equal(type
, "filter-dump") ||
2856 g_str_equal(type
, "filter-mirror") ||
2857 g_str_equal(type
, "filter-redirector") ||
2858 g_str_equal(type
, "colo-compare") ||
2859 g_str_equal(type
, "filter-rewriter") ||
2860 g_str_equal(type
, "filter-replay")) {
2864 /* Memory allocation by backends needs to be done
2865 * after configure_accelerator() (due to the tcg_enabled()
2866 * checks at memory_region_init_*()).
2868 * Also, allocation of large amounts of memory may delay
2869 * chardev initialization for too long, and trigger timeouts
2870 * on software that waits for a monitor socket to be created
2873 if (g_str_has_prefix(type
, "memory-backend-")) {
2882 * The remainder of object creation happens after the
2883 * creation of chardev, fsdev, net clients and device data types.
2885 static bool object_create_delayed(const char *type
, QemuOpts
*opts
)
2887 return !object_create_initial(type
, opts
);
2891 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2895 const char *mem_str
;
2896 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2897 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2900 loc_push_none(&loc
);
2901 qemu_opts_loc_restore(opts
);
2904 mem_str
= qemu_opt_get(opts
, "size");
2907 error_report("missing 'size' option value");
2911 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2913 /* Fix up legacy suffix-less format */
2914 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2915 uint64_t overflow_check
= sz
;
2918 if (sz
/ MiB
!= overflow_check
) {
2919 error_report("too large 'size' option value");
2925 /* backward compatibility behaviour for case "-m 0" */
2927 sz
= default_ram_size
;
2930 sz
= QEMU_ALIGN_UP(sz
, 8192);
2932 if (ram_size
!= sz
) {
2933 error_report("ram size too large");
2937 /* store value for the future use */
2938 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2939 *maxram_size
= ram_size
;
2941 if (qemu_opt_get(opts
, "maxmem")) {
2944 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2945 slots
= qemu_opt_get_number(opts
, "slots", 0);
2946 if (sz
< ram_size
) {
2947 error_report("invalid value of -m option maxmem: "
2948 "maximum memory size (0x%" PRIx64
") must be at least "
2949 "the initial memory size (0x" RAM_ADDR_FMT
")",
2952 } else if (slots
&& sz
== ram_size
) {
2953 error_report("invalid value of -m option maxmem: "
2954 "memory slots were specified but maximum memory size "
2955 "(0x%" PRIx64
") is equal to the initial memory size "
2956 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2962 } else if (qemu_opt_get(opts
, "slots")) {
2963 error_report("invalid -m option value: missing 'maxmem' option");
2970 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2974 g
= g_malloc0(sizeof(*g
));
2975 g
->driver
= qemu_opt_get(opts
, "driver");
2976 g
->property
= qemu_opt_get(opts
, "property");
2977 g
->value
= qemu_opt_get(opts
, "value");
2978 g
->user_provided
= true;
2979 g
->errp
= &error_fatal
;
2980 qdev_prop_register_global(g
);
2984 static int qemu_read_default_config_file(void)
2988 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2989 if (ret
< 0 && ret
!= -ENOENT
) {
2996 static void user_register_global_props(void)
2998 qemu_opts_foreach(qemu_find_opts("global"),
2999 global_init_func
, NULL
, NULL
);
3003 * Note: we should see that these properties are actually having a
3004 * priority: accel < machine < user. This means e.g. when user
3005 * specifies something in "-global", it'll always be used with highest
3006 * priority than either machine/accelerator compat properties.
3008 static void register_global_properties(MachineState
*ms
)
3010 accel_register_compat_props(ms
->accelerator
);
3011 machine_register_compat_props(ms
);
3012 user_register_global_props();
3015 int main(int argc
, char **argv
)
3018 int snapshot
, linux_boot
;
3019 const char *initrd_filename
;
3020 const char *kernel_filename
, *kernel_cmdline
;
3021 const char *boot_order
= NULL
;
3022 const char *boot_once
= NULL
;
3024 QemuOpts
*opts
, *machine_opts
;
3025 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
3026 QemuOptsList
*olist
;
3029 const char *loadvm
= NULL
;
3030 MachineClass
*machine_class
;
3031 const char *cpu_model
;
3032 const char *vga_model
= NULL
;
3033 const char *qtest_chrdev
= NULL
;
3034 const char *qtest_log
= NULL
;
3035 const char *incoming
= NULL
;
3036 bool userconfig
= true;
3037 bool nographic
= false;
3038 int display_remote
= 0;
3039 const char *log_mask
= NULL
;
3040 const char *log_file
= NULL
;
3041 char *trace_file
= NULL
;
3042 ram_addr_t maxram_size
;
3043 uint64_t ram_slots
= 0;
3044 FILE *vmstate_dump_file
= NULL
;
3045 Error
*main_loop_err
= NULL
;
3047 bool list_data_dirs
= false;
3049 typedef struct BlockdevOptions_queue
{
3050 BlockdevOptions
*bdo
;
3052 QSIMPLEQ_ENTRY(BlockdevOptions_queue
) entry
;
3053 } BlockdevOptions_queue
;
3054 QSIMPLEQ_HEAD(, BlockdevOptions_queue
) bdo_queue
3055 = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
3057 module_call_init(MODULE_INIT_TRACE
);
3059 qemu_init_cpu_list();
3060 qemu_init_cpu_loop();
3062 qemu_mutex_lock_iothread();
3064 atexit(qemu_run_exit_notifiers
);
3065 error_set_progname(argv
[0]);
3066 qemu_init_exec_dir(argv
[0]);
3068 module_call_init(MODULE_INIT_QOM
);
3070 qemu_add_opts(&qemu_drive_opts
);
3071 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3072 qemu_add_drive_opts(&qemu_common_drive_opts
);
3073 qemu_add_drive_opts(&qemu_drive_opts
);
3074 qemu_add_drive_opts(&bdrv_runtime_opts
);
3075 qemu_add_opts(&qemu_chardev_opts
);
3076 qemu_add_opts(&qemu_device_opts
);
3077 qemu_add_opts(&qemu_netdev_opts
);
3078 qemu_add_opts(&qemu_nic_opts
);
3079 qemu_add_opts(&qemu_net_opts
);
3080 qemu_add_opts(&qemu_rtc_opts
);
3081 qemu_add_opts(&qemu_global_opts
);
3082 qemu_add_opts(&qemu_mon_opts
);
3083 qemu_add_opts(&qemu_trace_opts
);
3084 qemu_add_opts(&qemu_option_rom_opts
);
3085 qemu_add_opts(&qemu_machine_opts
);
3086 qemu_add_opts(&qemu_accel_opts
);
3087 qemu_add_opts(&qemu_mem_opts
);
3088 qemu_add_opts(&qemu_smp_opts
);
3089 qemu_add_opts(&qemu_boot_opts
);
3090 qemu_add_opts(&qemu_add_fd_opts
);
3091 qemu_add_opts(&qemu_object_opts
);
3092 qemu_add_opts(&qemu_tpmdev_opts
);
3093 qemu_add_opts(&qemu_realtime_opts
);
3094 qemu_add_opts(&qemu_overcommit_opts
);
3095 qemu_add_opts(&qemu_msg_opts
);
3096 qemu_add_opts(&qemu_name_opts
);
3097 qemu_add_opts(&qemu_numa_opts
);
3098 qemu_add_opts(&qemu_icount_opts
);
3099 qemu_add_opts(&qemu_semihosting_config_opts
);
3100 qemu_add_opts(&qemu_fw_cfg_opts
);
3101 module_call_init(MODULE_INIT_OPTS
);
3104 postcopy_infrastructure_init();
3105 monitor_init_globals();
3107 if (qcrypto_init(&err
) < 0) {
3108 error_reportf_err(err
, "cannot initialize crypto: ");
3112 QLIST_INIT (&vm_change_state_head
);
3113 os_setup_early_signal_handling();
3120 bdrv_init_with_whitelist();
3124 /* first pass of option parsing */
3126 while (optind
< argc
) {
3127 if (argv
[optind
][0] != '-') {
3131 const QEMUOption
*popt
;
3133 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3134 switch (popt
->index
) {
3135 case QEMU_OPTION_nouserconfig
:
3143 if (qemu_read_default_config_file() < 0) {
3148 /* second pass of option parsing */
3153 if (argv
[optind
][0] != '-') {
3154 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3156 const QEMUOption
*popt
;
3158 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3159 if (!(popt
->arch_mask
& arch_type
)) {
3160 error_report("Option not supported for this target");
3163 switch(popt
->index
) {
3164 case QEMU_OPTION_cpu
:
3165 /* hw initialization will check this */
3168 case QEMU_OPTION_hda
:
3169 case QEMU_OPTION_hdb
:
3170 case QEMU_OPTION_hdc
:
3171 case QEMU_OPTION_hdd
:
3172 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3175 case QEMU_OPTION_blockdev
:
3178 BlockdevOptions_queue
*bdo
;
3180 v
= qobject_input_visitor_new_str(optarg
, "driver",
3183 bdo
= g_new(BlockdevOptions_queue
, 1);
3184 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
3187 loc_save(&bdo
->loc
);
3188 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
3191 case QEMU_OPTION_drive
:
3192 if (drive_def(optarg
) == NULL
) {
3196 case QEMU_OPTION_set
:
3197 if (qemu_set_option(optarg
) != 0)
3200 case QEMU_OPTION_global
:
3201 if (qemu_global_option(optarg
) != 0)
3204 case QEMU_OPTION_mtdblock
:
3205 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3207 case QEMU_OPTION_sd
:
3208 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3210 case QEMU_OPTION_pflash
:
3211 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3213 case QEMU_OPTION_snapshot
:
3216 case QEMU_OPTION_numa
:
3217 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3223 case QEMU_OPTION_display
:
3224 parse_display(optarg
);
3226 case QEMU_OPTION_nographic
:
3227 olist
= qemu_find_opts("machine");
3228 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3230 dpy
.type
= DISPLAY_TYPE_NONE
;
3232 case QEMU_OPTION_curses
:
3233 #ifdef CONFIG_CURSES
3234 dpy
.type
= DISPLAY_TYPE_CURSES
;
3236 error_report("curses support is disabled");
3240 case QEMU_OPTION_portrait
:
3241 graphic_rotate
= 90;
3243 case QEMU_OPTION_rotate
:
3244 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3245 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3246 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3247 error_report("only 90, 180, 270 deg rotation is available");
3251 case QEMU_OPTION_kernel
:
3252 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3255 case QEMU_OPTION_initrd
:
3256 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3259 case QEMU_OPTION_append
:
3260 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3263 case QEMU_OPTION_dtb
:
3264 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3267 case QEMU_OPTION_cdrom
:
3268 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3270 case QEMU_OPTION_boot
:
3271 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3277 case QEMU_OPTION_fda
:
3278 case QEMU_OPTION_fdb
:
3279 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3282 case QEMU_OPTION_no_fd_bootchk
:
3285 case QEMU_OPTION_netdev
:
3287 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3291 case QEMU_OPTION_nic
:
3293 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
3297 case QEMU_OPTION_net
:
3299 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3303 #ifdef CONFIG_LIBISCSI
3304 case QEMU_OPTION_iscsi
:
3305 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3312 case QEMU_OPTION_bt
:
3313 warn_report("The bluetooth subsystem is deprecated and will "
3314 "be removed soon. If the bluetooth subsystem is "
3315 "still useful for you, please send a mail to "
3316 "qemu-devel@nongnu.org with your usecase.");
3317 add_device_config(DEV_BT
, optarg
);
3319 case QEMU_OPTION_audio_help
:
3323 case QEMU_OPTION_soundhw
:
3324 select_soundhw (optarg
);
3329 case QEMU_OPTION_version
:
3334 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3341 case QEMU_OPTION_tpmdev
:
3342 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3347 case QEMU_OPTION_mempath
:
3350 case QEMU_OPTION_mem_prealloc
:
3359 case QEMU_OPTION_DFILTER
:
3360 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3363 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3365 case QEMU_OPTION_gdb
:
3366 add_device_config(DEV_GDB
, optarg
);
3369 if (is_help_option(optarg
)) {
3370 list_data_dirs
= true;
3372 qemu_add_data_dir(optarg
);
3375 case QEMU_OPTION_bios
:
3376 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3379 case QEMU_OPTION_singlestep
:
3386 keyboard_layout
= optarg
;
3388 case QEMU_OPTION_vga
:
3397 w
= strtol(p
, (char **)&p
, 10);
3400 error_report("invalid resolution or depth");
3406 h
= strtol(p
, (char **)&p
, 10);
3411 depth
= strtol(p
, (char **)&p
, 10);
3412 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3413 depth
!= 24 && depth
!= 32)
3415 } else if (*p
== '\0') {
3416 depth
= graphic_depth
;
3423 graphic_depth
= depth
;
3426 case QEMU_OPTION_echr
:
3429 term_escape_char
= strtol(optarg
, &r
, 0);
3431 printf("Bad argument to echr\n");
3434 case QEMU_OPTION_monitor
:
3435 default_monitor
= 0;
3436 if (strncmp(optarg
, "none", 4)) {
3437 monitor_parse(optarg
, "readline", false);
3440 case QEMU_OPTION_qmp
:
3441 monitor_parse(optarg
, "control", false);
3442 default_monitor
= 0;
3444 case QEMU_OPTION_qmp_pretty
:
3445 monitor_parse(optarg
, "control", true);
3446 default_monitor
= 0;
3448 case QEMU_OPTION_mon
:
3449 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3454 default_monitor
= 0;
3456 case QEMU_OPTION_chardev
:
3457 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3463 case QEMU_OPTION_fsdev
:
3464 olist
= qemu_find_opts("fsdev");
3466 error_report("fsdev support is disabled");
3469 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3474 case QEMU_OPTION_virtfs
: {
3477 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
;
3479 olist
= qemu_find_opts("virtfs");
3481 error_report("virtfs support is disabled");
3484 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3489 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3490 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3491 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3494 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3495 qemu_opts_id(opts
) ?:
3496 qemu_opt_get(opts
, "mount_tag"),
3499 error_report("duplicate or invalid fsdev id: %s",
3500 qemu_opt_get(opts
, "mount_tag"));
3504 writeout
= qemu_opt_get(opts
, "writeout");
3506 #ifdef CONFIG_SYNC_FILE_RANGE
3507 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3509 error_report("writeout=immediate not supported "
3510 "on this platform");
3514 qemu_opt_set(fsdev
, "fsdriver",
3515 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3516 path
= qemu_opt_get(opts
, "path");
3518 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3520 security_model
= qemu_opt_get(opts
, "security_model");
3521 if (security_model
) {
3522 qemu_opt_set(fsdev
, "security_model", security_model
,
3525 socket
= qemu_opt_get(opts
, "socket");
3527 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3529 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3531 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3534 qemu_opt_set_bool(fsdev
, "readonly",
3535 qemu_opt_get_bool(opts
, "readonly", 0),
3537 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3539 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3540 qemu_opt_set(device
, "fsdev",
3541 qemu_opts_id(fsdev
), &error_abort
);
3542 qemu_opt_set(device
, "mount_tag",
3543 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3546 case QEMU_OPTION_virtfs_synth
: {
3550 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3553 error_report("duplicate option: %s", "virtfs_synth");
3556 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3558 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3560 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3561 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3562 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3565 case QEMU_OPTION_serial
:
3566 add_device_config(DEV_SERIAL
, optarg
);
3568 if (strncmp(optarg
, "mon:", 4) == 0) {
3569 default_monitor
= 0;
3572 case QEMU_OPTION_watchdog
:
3574 error_report("only one watchdog option may be given");
3579 case QEMU_OPTION_watchdog_action
:
3580 if (select_watchdog_action(optarg
) == -1) {
3581 error_report("unknown -watchdog-action parameter");
3585 case QEMU_OPTION_virtiocon
:
3586 warn_report("This option is deprecated, "
3587 "use '-device virtconsole' instead");
3588 add_device_config(DEV_VIRTCON
, optarg
);
3589 default_virtcon
= 0;
3590 if (strncmp(optarg
, "mon:", 4) == 0) {
3591 default_monitor
= 0;
3594 case QEMU_OPTION_parallel
:
3595 add_device_config(DEV_PARALLEL
, optarg
);
3596 default_parallel
= 0;
3597 if (strncmp(optarg
, "mon:", 4) == 0) {
3598 default_monitor
= 0;
3601 case QEMU_OPTION_debugcon
:
3602 add_device_config(DEV_DEBUGCON
, optarg
);
3604 case QEMU_OPTION_loadvm
:
3607 case QEMU_OPTION_full_screen
:
3608 dpy
.has_full_screen
= true;
3609 dpy
.full_screen
= true;
3611 case QEMU_OPTION_no_frame
:
3612 g_printerr("The -no-frame switch is deprecated, and will be\n"
3613 "removed in a future release.\n");
3616 case QEMU_OPTION_alt_grab
:
3619 case QEMU_OPTION_ctrl_grab
:
3622 case QEMU_OPTION_no_quit
:
3623 dpy
.has_window_close
= true;
3624 dpy
.window_close
= false;
3626 case QEMU_OPTION_sdl
:
3628 dpy
.type
= DISPLAY_TYPE_SDL
;
3631 error_report("SDL support is disabled");
3634 case QEMU_OPTION_pidfile
:
3637 case QEMU_OPTION_win2k_hack
:
3638 win2k_install_hack
= 1;
3640 case QEMU_OPTION_acpitable
:
3641 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3646 acpi_table_add(opts
, &error_fatal
);
3648 case QEMU_OPTION_smbios
:
3649 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3654 smbios_entry_add(opts
, &error_fatal
);
3656 case QEMU_OPTION_fwcfg
:
3657 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3663 case QEMU_OPTION_preconfig
:
3664 preconfig_exit_requested
= false;
3666 case QEMU_OPTION_enable_kvm
:
3667 olist
= qemu_find_opts("machine");
3668 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3670 case QEMU_OPTION_enable_hax
:
3671 warn_report("Option is deprecated, use '-accel hax' instead");
3672 olist
= qemu_find_opts("machine");
3673 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3676 case QEMU_OPTION_machine
:
3677 olist
= qemu_find_opts("machine");
3678 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3683 case QEMU_OPTION_no_kvm
:
3684 olist
= qemu_find_opts("machine");
3685 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3687 case QEMU_OPTION_accel
:
3688 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3690 optarg
= qemu_opt_get(accel_opts
, "accel");
3691 if (!optarg
|| is_help_option(optarg
)) {
3692 error_printf("Possible accelerators: kvm, xen, hax, tcg\n");
3695 opts
= qemu_opts_create(qemu_find_opts("machine"), NULL
,
3696 false, &error_abort
);
3697 qemu_opt_set(opts
, "accel", optarg
, &error_abort
);
3699 case QEMU_OPTION_usb
:
3700 olist
= qemu_find_opts("machine");
3701 qemu_opts_parse_noisily(olist
, "usb=on", false);
3703 case QEMU_OPTION_usbdevice
:
3704 error_report("'-usbdevice' is deprecated, please use "
3705 "'-device usb-...' instead");
3706 olist
= qemu_find_opts("machine");
3707 qemu_opts_parse_noisily(olist
, "usb=on", false);
3708 add_device_config(DEV_USB
, optarg
);
3710 case QEMU_OPTION_device
:
3711 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3716 case QEMU_OPTION_smp
:
3717 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3722 case QEMU_OPTION_vnc
:
3723 vnc_parse(optarg
, &error_fatal
);
3725 case QEMU_OPTION_no_acpi
:
3728 case QEMU_OPTION_no_hpet
:
3731 case QEMU_OPTION_no_reboot
:
3734 case QEMU_OPTION_no_shutdown
:
3737 case QEMU_OPTION_show_cursor
:
3740 case QEMU_OPTION_uuid
:
3741 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3742 error_report("failed to parse UUID string: wrong format");
3745 qemu_uuid_set
= true;
3747 case QEMU_OPTION_option_rom
:
3748 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3749 error_report("too many option ROMs");
3752 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3757 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3758 option_rom
[nb_option_roms
].bootindex
=
3759 qemu_opt_get_number(opts
, "bootindex", -1);
3760 if (!option_rom
[nb_option_roms
].name
) {
3761 error_report("Option ROM file is not specified");
3766 case QEMU_OPTION_semihosting
:
3767 semihosting
.enabled
= true;
3768 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3770 case QEMU_OPTION_semihosting_config
:
3771 semihosting
.enabled
= true;
3772 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3775 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3777 const char *target
= qemu_opt_get(opts
, "target");
3778 if (target
!= NULL
) {
3779 if (strcmp("native", target
) == 0) {
3780 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3781 } else if (strcmp("gdb", target
) == 0) {
3782 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3783 } else if (strcmp("auto", target
) == 0) {
3784 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3786 error_report("unsupported semihosting-config %s",
3791 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3793 /* Set semihosting argument count and vector */
3794 qemu_opt_foreach(opts
, add_semihosting_arg
,
3795 &semihosting
, NULL
);
3797 error_report("unsupported semihosting-config %s", optarg
);
3801 case QEMU_OPTION_name
:
3802 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3808 case QEMU_OPTION_prom_env
:
3809 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3810 error_report("too many prom variables");
3813 prom_envs
[nb_prom_envs
] = optarg
;
3816 case QEMU_OPTION_old_param
:
3819 case QEMU_OPTION_clock
:
3820 /* Clock options no longer exist. Keep this option for
3821 * backward compatibility.
3823 warn_report("This option is ignored and will be removed soon");
3825 case QEMU_OPTION_rtc
:
3826 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3832 case QEMU_OPTION_tb_size
:
3834 error_report("TCG is disabled");
3837 if (qemu_strtoul(optarg
, NULL
, 0, &tcg_tb_size
) < 0) {
3838 error_report("Invalid argument to -tb-size");
3842 case QEMU_OPTION_icount
:
3843 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3849 case QEMU_OPTION_incoming
:
3851 runstate_set(RUN_STATE_INMIGRATE
);
3855 case QEMU_OPTION_only_migratable
:
3857 * TODO: we can remove this option one day, and we
3860 * "-global migration.only-migratable=true"
3862 qemu_global_option("migration.only-migratable=true");
3864 case QEMU_OPTION_nodefaults
:
3867 case QEMU_OPTION_xen_domid
:
3868 if (!(xen_available())) {
3869 error_report("Option not supported for this target");
3872 xen_domid
= atoi(optarg
);
3874 case QEMU_OPTION_xen_create
:
3875 if (!(xen_available())) {
3876 error_report("Option not supported for this target");
3879 xen_mode
= XEN_CREATE
;
3881 case QEMU_OPTION_xen_attach
:
3882 if (!(xen_available())) {
3883 error_report("Option not supported for this target");
3886 xen_mode
= XEN_ATTACH
;
3888 case QEMU_OPTION_xen_domid_restrict
:
3889 if (!(xen_available())) {
3890 error_report("Option not supported for this target");
3893 xen_domid_restrict
= true;
3895 case QEMU_OPTION_trace
:
3897 trace_file
= trace_opt_parse(optarg
);
3899 case QEMU_OPTION_trace_unassigned
:
3900 trace_unassigned
= true;
3902 case QEMU_OPTION_readconfig
:
3904 int ret
= qemu_read_config_file(optarg
);
3906 error_report("read config %s: %s", optarg
,
3912 case QEMU_OPTION_spice
:
3913 olist
= qemu_find_opts("spice");
3915 error_report("spice support is disabled");
3918 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3924 case QEMU_OPTION_writeconfig
:
3927 if (strcmp(optarg
, "-") == 0) {
3930 fp
= fopen(optarg
, "w");
3932 error_report("open %s: %s", optarg
,
3937 qemu_config_write(fp
);
3943 case QEMU_OPTION_qtest
:
3944 qtest_chrdev
= optarg
;
3946 case QEMU_OPTION_qtest_log
:
3949 case QEMU_OPTION_sandbox
:
3950 #ifdef CONFIG_SECCOMP
3951 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
3957 error_report("-sandbox support is not enabled "
3958 "in this QEMU binary");
3962 case QEMU_OPTION_add_fd
:
3964 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3970 error_report("File descriptor passing is disabled on this "
3975 case QEMU_OPTION_object
:
3976 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
3982 case QEMU_OPTION_realtime
:
3983 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
3988 /* Don't override the -overcommit option if set */
3989 enable_mlock
= enable_mlock
||
3990 qemu_opt_get_bool(opts
, "mlock", true);
3992 case QEMU_OPTION_overcommit
:
3993 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3998 /* Don't override the -realtime option if set */
3999 enable_mlock
= enable_mlock
||
4000 qemu_opt_get_bool(opts
, "mem-lock", false);
4001 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
4003 case QEMU_OPTION_msg
:
4004 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4009 configure_msg(opts
);
4011 case QEMU_OPTION_dump_vmstate
:
4012 if (vmstate_dump_file
) {
4013 error_report("only one '-dump-vmstate' "
4014 "option may be given");
4017 vmstate_dump_file
= fopen(optarg
, "w");
4018 if (vmstate_dump_file
== NULL
) {
4019 error_report("open %s: %s", optarg
, strerror(errno
));
4023 case QEMU_OPTION_enable_sync_profile
:
4026 case QEMU_OPTION_nouserconfig
:
4027 /* Nothing to be parsed here. Especially, do not error out below. */
4030 if (os_parse_cmd_args(popt
->index
, optarg
)) {
4031 error_report("Option not supported in this build");
4038 * Clear error location left behind by the loop.
4039 * Best done right after the loop. Do not insert code here!
4043 replay_configure(icount_opts
);
4045 if (incoming
&& !preconfig_exit_requested
) {
4046 error_report("'preconfig' and 'incoming' options are "
4047 "mutually exclusive");
4051 configure_rtc(qemu_find_opts_singleton("rtc"));
4053 machine_class
= select_machine();
4055 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4058 rcu_disable_atfork();
4060 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
4061 error_reportf_err(err
, "cannot create PID file: ");
4065 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
4066 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
4068 if (qemu_init_main_loop(&main_loop_err
)) {
4069 error_report_err(main_loop_err
);
4073 #ifdef CONFIG_SECCOMP
4074 olist
= qemu_find_opts_err("sandbox", NULL
);
4076 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
4080 qemu_opts_foreach(qemu_find_opts("name"),
4081 parse_name
, NULL
, &error_fatal
);
4084 qemu_opts_foreach(qemu_find_opts("add-fd"),
4085 parse_add_fd
, NULL
, &error_fatal
);
4087 qemu_opts_foreach(qemu_find_opts("add-fd"),
4088 cleanup_add_fd
, NULL
, &error_fatal
);
4091 current_machine
= MACHINE(object_new(object_class_get_name(
4092 OBJECT_CLASS(machine_class
))));
4093 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4096 object_property_add_child(object_get_root(), "machine",
4097 OBJECT(current_machine
), &error_abort
);
4099 if (machine_class
->minimum_page_bits
) {
4100 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4101 /* This would be a board error: specifying a minimum smaller than
4102 * a target's compile-time fixed setting.
4104 g_assert_not_reached();
4108 cpu_exec_init_all();
4110 if (machine_class
->hw_version
) {
4111 qemu_set_hw_version(machine_class
->hw_version
);
4114 if (cpu_model
&& is_help_option(cpu_model
)) {
4115 list_cpus(stdout
, &fprintf
, cpu_model
);
4119 if (!trace_init_backends()) {
4122 trace_init_file(trace_file
);
4124 /* Open the logfile at this point and set the log mask if necessary.
4127 qemu_set_log_filename(log_file
, &error_fatal
);
4132 mask
= qemu_str_to_log_mask(log_mask
);
4134 qemu_print_log_usage(stdout
);
4142 /* add configured firmware directories */
4143 dirs
= g_strsplit(CONFIG_QEMU_FIRMWAREPATH
, G_SEARCHPATH_SEPARATOR_S
, 0);
4144 for (i
= 0; dirs
[i
] != NULL
; i
++) {
4145 qemu_add_data_dir(dirs
[i
]);
4149 /* try to find datadir relative to the executable path */
4150 dir
= os_find_datadir();
4151 qemu_add_data_dir(dir
);
4154 /* add the datadir specified when building */
4155 qemu_add_data_dir(CONFIG_QEMU_DATADIR
);
4157 /* -L help lists the data directories and exits. */
4158 if (list_data_dirs
) {
4159 for (i
= 0; i
< data_dir_idx
; i
++) {
4160 printf("%s\n", data_dir
[i
]);
4165 /* machine_class: default to UP */
4166 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1;
4167 machine_class
->min_cpus
= machine_class
->min_cpus
?: 1;
4168 machine_class
->default_cpus
= machine_class
->default_cpus
?: 1;
4170 /* default to machine_class->default_cpus */
4171 smp_cpus
= machine_class
->default_cpus
;
4172 max_cpus
= machine_class
->default_cpus
;
4174 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4176 /* sanity-check smp_cpus and max_cpus against machine_class */
4177 if (smp_cpus
< machine_class
->min_cpus
) {
4178 error_report("Invalid SMP CPUs %d. The min CPUs "
4179 "supported by machine '%s' is %d", smp_cpus
,
4180 machine_class
->name
, machine_class
->min_cpus
);
4183 if (max_cpus
> machine_class
->max_cpus
) {
4184 error_report("Invalid SMP CPUs %d. The max CPUs "
4185 "supported by machine '%s' is %d", max_cpus
,
4186 machine_class
->name
, machine_class
->max_cpus
);
4191 * Get the default machine options from the machine if it is not already
4192 * specified either by the configuration file or by the command line.
4194 if (machine_class
->default_machine_opts
) {
4195 qemu_opts_set_defaults(qemu_find_opts("machine"),
4196 machine_class
->default_machine_opts
, 0);
4199 qemu_opts_foreach(qemu_find_opts("device"),
4200 default_driver_check
, NULL
, NULL
);
4201 qemu_opts_foreach(qemu_find_opts("global"),
4202 default_driver_check
, NULL
, NULL
);
4204 if (!vga_model
&& !default_vga
) {
4205 vga_interface_type
= VGA_DEVICE
;
4207 if (!has_defaults
|| machine_class
->no_serial
) {
4210 if (!has_defaults
|| machine_class
->no_parallel
) {
4211 default_parallel
= 0;
4213 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4214 default_virtcon
= 0;
4216 if (!has_defaults
|| machine_class
->no_floppy
) {
4219 if (!has_defaults
|| machine_class
->no_cdrom
) {
4222 if (!has_defaults
|| machine_class
->no_sdcard
) {
4225 if (!has_defaults
) {
4226 default_monitor
= 0;
4231 if (is_daemonized()) {
4232 if (!preconfig_exit_requested
) {
4233 error_report("'preconfig' and 'daemonize' options are "
4234 "mutually exclusive");
4238 /* According to documentation and historically, -nographic redirects
4239 * serial port, parallel port and monitor to stdio, which does not work
4240 * with -daemonize. We can redirect these to null instead, but since
4241 * -nographic is legacy, let's just error out.
4242 * We disallow -nographic only if all other ports are not redirected
4243 * explicitly, to not break existing legacy setups which uses
4244 * -nographic _and_ redirects all ports explicitly - this is valid
4245 * usage, -nographic is just a no-op in this case.
4248 && (default_parallel
|| default_serial
4249 || default_monitor
|| default_virtcon
)) {
4250 error_report("-nographic cannot be used with -daemonize");
4253 #ifdef CONFIG_CURSES
4254 if (dpy
.type
== DISPLAY_TYPE_CURSES
) {
4255 error_report("curses display cannot be used with -daemonize");
4262 if (default_parallel
)
4263 add_device_config(DEV_PARALLEL
, "null");
4264 if (default_serial
&& default_monitor
) {
4265 add_device_config(DEV_SERIAL
, "mon:stdio");
4266 } else if (default_virtcon
&& default_monitor
) {
4267 add_device_config(DEV_VIRTCON
, "mon:stdio");
4270 add_device_config(DEV_SERIAL
, "stdio");
4271 if (default_virtcon
)
4272 add_device_config(DEV_VIRTCON
, "stdio");
4273 if (default_monitor
)
4274 monitor_parse("stdio", "readline", false);
4278 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4279 if (default_parallel
)
4280 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4281 if (default_monitor
)
4282 monitor_parse("vc:80Cx24C", "readline", false);
4283 if (default_virtcon
)
4284 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4287 #if defined(CONFIG_VNC)
4288 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4292 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
4293 if (!qemu_display_find_default(&dpy
)) {
4294 dpy
.type
= DISPLAY_TYPE_NONE
;
4295 #if defined(CONFIG_VNC)
4296 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4300 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
4301 dpy
.type
= DISPLAY_TYPE_NONE
;
4304 if ((no_frame
|| alt_grab
|| ctrl_grab
) && dpy
.type
!= DISPLAY_TYPE_SDL
) {
4305 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4306 "for SDL, ignoring option");
4308 if (dpy
.has_window_close
&&
4309 (dpy
.type
!= DISPLAY_TYPE_GTK
&& dpy
.type
!= DISPLAY_TYPE_SDL
)) {
4310 error_report("-no-quit is only valid for GTK and SDL, "
4314 qemu_display_early_init(&dpy
);
4315 qemu_console_early_init();
4317 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
4318 #if defined(CONFIG_OPENGL)
4319 error_report("OpenGL is not supported by the display");
4321 error_report("OpenGL support is disabled");
4329 qemu_opts_foreach(qemu_find_opts("object"),
4330 user_creatable_add_opts_foreach
,
4331 object_create_initial
, &error_fatal
);
4333 qemu_opts_foreach(qemu_find_opts("chardev"),
4334 chardev_init_func
, NULL
, &error_fatal
);
4336 #ifdef CONFIG_VIRTFS
4337 qemu_opts_foreach(qemu_find_opts("fsdev"),
4338 fsdev_init_func
, NULL
, &error_fatal
);
4341 if (qemu_opts_foreach(qemu_find_opts("device"),
4342 device_help_func
, NULL
, NULL
)) {
4346 machine_opts
= qemu_get_machine_opts();
4347 qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4350 configure_accelerator(current_machine
);
4352 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
4353 error_report("Machine type '%s' is deprecated: %s",
4354 machine_class
->name
, machine_class
->deprecation_reason
);
4358 * Register all the global properties, including accel properties,
4359 * machine properties, and user-specified ones.
4361 register_global_properties(current_machine
);
4364 * Migration object can only be created after global properties
4365 * are applied correctly.
4367 migration_object_init();
4370 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4373 machine_opts
= qemu_get_machine_opts();
4374 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4375 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4376 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4377 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4379 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4381 boot_order
= qemu_opt_get(opts
, "order");
4383 validate_bootdevices(boot_order
, &error_fatal
);
4386 boot_once
= qemu_opt_get(opts
, "once");
4388 validate_bootdevices(boot_once
, &error_fatal
);
4391 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4392 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4396 boot_order
= machine_class
->default_boot_order
;
4399 if (!kernel_cmdline
) {
4400 kernel_cmdline
= "";
4401 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4404 linux_boot
= (kernel_filename
!= NULL
);
4406 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4407 error_report("-append only allowed with -kernel option");
4411 if (!linux_boot
&& initrd_filename
!= NULL
) {
4412 error_report("-initrd only allowed with -kernel option");
4416 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4417 /* fall back to the -kernel/-append */
4418 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4421 os_set_line_buffering();
4423 /* spice needs the timers to be initialized by this point */
4428 if (!tcg_enabled()) {
4429 error_report("-icount is not allowed with hardware virtualization");
4432 configure_icount(icount_opts
, &error_abort
);
4433 qemu_opts_del(icount_opts
);
4436 if (tcg_enabled()) {
4437 qemu_tcg_configure(accel_opts
, &error_fatal
);
4441 QemuOptsList
*net
= qemu_find_opts("net");
4442 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4444 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4448 if (net_init_clients(&err
) < 0) {
4449 error_report_err(err
);
4453 qemu_opts_foreach(qemu_find_opts("object"),
4454 user_creatable_add_opts_foreach
,
4455 object_create_delayed
, &error_fatal
);
4459 /* init the bluetooth world */
4460 if (foreach_device_config(DEV_BT
, bt_parse
))
4463 if (!xen_enabled()) {
4464 /* On 32-bit hosts, QEMU is limited by virtual address space */
4465 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4466 error_report("at most 2047 MB RAM can be simulated");
4473 dirty_bitmap_mig_init();
4475 /* If the currently selected machine wishes to override the units-per-bus
4476 * property of its default HBA interface type, do so now. */
4477 if (machine_class
->units_per_default_bus
) {
4478 override_max_devs(machine_class
->block_default_type
,
4479 machine_class
->units_per_default_bus
);
4482 /* open the virtual block devices */
4483 while (!QSIMPLEQ_EMPTY(&bdo_queue
)) {
4484 BlockdevOptions_queue
*bdo
= QSIMPLEQ_FIRST(&bdo_queue
);
4486 QSIMPLEQ_REMOVE_HEAD(&bdo_queue
, entry
);
4487 loc_push_restore(&bdo
->loc
);
4488 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
4490 qapi_free_BlockdevOptions(bdo
->bdo
);
4493 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4494 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4497 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4498 &machine_class
->block_default_type
, &error_fatal
)) {
4499 /* We printed help */
4503 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4505 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4506 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4508 qemu_opts_foreach(qemu_find_opts("mon"),
4509 mon_init_func
, NULL
, &error_fatal
);
4511 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4513 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4515 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4517 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4520 /* If no default VGA is requested, the default is "none". */
4522 if (machine_class
->default_display
) {
4523 vga_model
= machine_class
->default_display
;
4524 } else if (vga_interface_available(VGA_CIRRUS
)) {
4525 vga_model
= "cirrus";
4526 } else if (vga_interface_available(VGA_STD
)) {
4531 select_vgahw(vga_model
);
4535 i
= select_watchdog(watchdog
);
4537 exit (i
== 1 ? 1 : 0);
4540 /* This checkpoint is required by replay to separate prior clock
4541 reading from the other reads, because timer polling functions query
4542 clock values from the log. */
4543 replay_checkpoint(CHECKPOINT_INIT
);
4544 qdev_machine_init();
4546 current_machine
->ram_size
= ram_size
;
4547 current_machine
->maxram_size
= maxram_size
;
4548 current_machine
->ram_slots
= ram_slots
;
4549 current_machine
->boot_order
= boot_order
;
4551 /* parse features once if machine provides default cpu_type */
4552 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
4554 current_machine
->cpu_type
= parse_cpu_model(cpu_model
);
4556 parse_numa_opts(current_machine
);
4558 /* do monitor/qmp handling at preconfig state if requested */
4561 /* from here on runstate is RUN_STATE_PRELAUNCH */
4562 machine_run_board_init(current_machine
);
4568 if (hax_enabled()) {
4572 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4573 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
4575 /* init USB devices */
4576 if (machine_usb(current_machine
)) {
4577 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4581 /* Check if IGD GFX passthrough. */
4584 /* init generic devices */
4585 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4586 qemu_opts_foreach(qemu_find_opts("device"),
4587 device_init_func
, NULL
, &error_fatal
);
4589 cpu_synchronize_all_post_init();
4591 rom_reset_order_override();
4593 /* Did we create any drives that we failed to create a device for? */
4594 drive_check_orphaned();
4596 /* Don't warn about the default network setup that you get if
4597 * no command line -net or -netdev options are specified. There
4598 * are two cases that we would otherwise complain about:
4599 * (1) board doesn't support a NIC but the implicit "-net nic"
4601 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4602 * sets up a nic that isn't connected to anything.
4604 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
4605 net_check_clients();
4609 qemu_boot_set(boot_once
, &error_fatal
);
4610 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4613 /* init local displays */
4614 ds
= init_displaystate();
4615 qemu_display_init(ds
, &dpy
);
4617 /* must be after terminal init, SDL library changes signal handlers */
4618 os_setup_signal_handling();
4620 /* init remote displays */
4622 qemu_opts_foreach(qemu_find_opts("vnc"),
4623 vnc_init_func
, NULL
, &error_fatal
);
4627 qemu_spice_display_init();
4630 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4634 qdev_machine_creation_done();
4636 /* TODO: once all bus devices are qdevified, this should be done
4637 * when bus is created by qdev.c */
4638 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4639 qemu_run_machine_init_done_notifiers();
4641 if (rom_check_and_register_reset() != 0) {
4642 error_report("rom check and register reset failed");
4648 /* This checkpoint is required by replay to separate prior clock
4649 reading from the other reads, because timer polling functions query
4650 clock values from the log. */
4651 replay_checkpoint(CHECKPOINT_RESET
);
4652 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
4653 register_global_state();
4655 Error
*local_err
= NULL
;
4656 if (load_snapshot(loadvm
, &local_err
) < 0) {
4657 error_report_err(local_err
);
4662 if (replay_mode
!= REPLAY_MODE_NONE
) {
4663 replay_vmstate_init();
4666 qdev_prop_check_globals();
4667 if (vmstate_dump_file
) {
4669 dump_vmstate_json_to_file(vmstate_dump_file
);
4674 Error
*local_err
= NULL
;
4675 qemu_start_incoming_migration(incoming
, &local_err
);
4677 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4680 } else if (autostart
) {
4684 accel_setup_post(current_machine
);
4689 gdbserver_cleanup();
4691 /* No more vcpu or device emulation activity beyond this point */
4694 job_cancel_sync_all();
4699 /* vhost-user must be cleaned up before chardevs. */
4705 user_creatable_cleanup();
4706 migration_object_finalize();
4707 /* TODO: unref root container, check all devices are ok */