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-common.h"
27 #include "qemu/datadir.h"
28 #include "qemu/units.h"
29 #include "exec/cpu-common.h"
30 #include "hw/qdev-properties.h"
31 #include "qapi/compat-policy.h"
32 #include "qapi/error.h"
33 #include "qapi/qmp/qdict.h"
34 #include "qapi/qmp/qstring.h"
35 #include "qapi/qmp/qjson.h"
36 #include "qemu-version.h"
37 #include "qemu/cutils.h"
38 #include "qemu/help_option.h"
39 #include "qemu/uuid.h"
40 #include "sysemu/reset.h"
41 #include "sysemu/runstate.h"
42 #include "sysemu/runstate-action.h"
43 #include "sysemu/seccomp.h"
44 #include "sysemu/tcg.h"
45 #include "sysemu/xen.h"
47 #include "qemu/error-report.h"
48 #include "qemu/sockets.h"
49 #include "qemu/accel.h"
51 #include "hw/isa/isa.h"
52 #include "hw/scsi/scsi.h"
53 #include "hw/display/vga.h"
54 #include "sysemu/watchdog.h"
55 #include "hw/firmware/smbios.h"
56 #include "hw/acpi/acpi.h"
57 #include "hw/xen/xen.h"
58 #include "hw/loader.h"
59 #include "monitor/qdev.h"
61 #include "net/slirp.h"
62 #include "monitor/monitor.h"
63 #include "ui/console.h"
65 #include "sysemu/sysemu.h"
66 #include "sysemu/numa.h"
67 #include "sysemu/hostmem.h"
68 #include "exec/gdbstub.h"
69 #include "qemu/timer.h"
70 #include "chardev/char.h"
71 #include "qemu/bitmap.h"
73 #include "sysemu/blockdev.h"
74 #include "hw/block/block.h"
75 #include "hw/i386/x86.h"
76 #include "hw/i386/pc.h"
77 #include "migration/misc.h"
78 #include "migration/snapshot.h"
79 #include "sysemu/tpm.h"
80 #include "sysemu/dma.h"
81 #include "hw/audio/soundhw.h"
82 #include "audio/audio.h"
83 #include "sysemu/cpus.h"
84 #include "sysemu/cpu-timers.h"
85 #include "migration/colo.h"
86 #include "migration/postcopy-ram.h"
87 #include "sysemu/kvm.h"
88 #include "sysemu/hax.h"
89 #include "qapi/qobject-input-visitor.h"
90 #include "qemu/option.h"
91 #include "qemu/config-file.h"
92 #include "qemu/qemu-options.h"
93 #include "qemu/main-loop.h"
95 #include "fsdev/qemu-fsdev.h"
97 #include "sysemu/qtest.h"
99 #include "disas/disas.h"
102 #include "trace/control.h"
103 #include "qemu/plugin.h"
104 #include "qemu/queue.h"
105 #include "sysemu/arch_init.h"
106 #include "exec/confidential-guest-support.h"
108 #include "ui/qemu-spice.h"
109 #include "qapi/string-input-visitor.h"
110 #include "qapi/opts-visitor.h"
111 #include "qapi/clone-visitor.h"
112 #include "qom/object_interfaces.h"
113 #include "semihosting/semihost.h"
114 #include "crypto/init.h"
115 #include "sysemu/replay.h"
116 #include "qapi/qapi-events-run-state.h"
117 #include "qapi/qapi-visit-block-core.h"
118 #include "qapi/qapi-visit-compat.h"
119 #include "qapi/qapi-visit-ui.h"
120 #include "qapi/qapi-commands-block-core.h"
121 #include "qapi/qapi-commands-migration.h"
122 #include "qapi/qapi-commands-misc.h"
123 #include "qapi/qapi-visit-qom.h"
124 #include "qapi/qapi-commands-ui.h"
125 #include "qapi/qmp/qdict.h"
126 #include "qapi/qmp/qerror.h"
127 #include "sysemu/iothread.h"
128 #include "qemu/guest-random.h"
130 #include "config-host.h"
132 #define MAX_VIRTIO_CONSOLES 1
134 typedef struct BlockdevOptionsQueueEntry {
135 BlockdevOptions *bdo;
137 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry) entry;
138 } BlockdevOptionsQueueEntry;
140 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry) BlockdevOptionsQueue;
142 typedef struct ObjectOption {
144 QTAILQ_ENTRY(ObjectOption) next;
147 typedef struct DeviceOption {
150 QTAILQ_ENTRY(DeviceOption) next;
153 static const char *cpu_option;
154 static const char *mem_path;
155 static const char *incoming;
156 static const char *loadvm;
157 static const char *accelerators;
158 static QDict *machine_opts_dict;
159 static QTAILQ_HEAD(, ObjectOption) object_opts = QTAILQ_HEAD_INITIALIZER(object_opts);
160 static QTAILQ_HEAD(, DeviceOption) device_opts = QTAILQ_HEAD_INITIALIZER(device_opts);
161 static ram_addr_t maxram_size;
162 static uint64_t ram_slots;
163 static int display_remote;
165 static bool preconfig_requested;
166 static QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list);
167 static BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
168 static bool nographic = false;
169 static int mem_prealloc; /* force preallocation of physical target memory */
170 static ram_addr_t ram_size;
171 static const char *vga_model = NULL;
172 static DisplayOptions dpy;
173 static int num_serial_hds;
174 static Chardev **serial_hds;
175 static const char *log_mask;
176 static const char *log_file;
177 static bool list_data_dirs;
178 static const char *watchdog;
179 static const char *qtest_chrdev;
180 static const char *qtest_log;
182 static int has_defaults = 1;
183 static int default_serial = 1;
184 static int default_parallel = 1;
185 static int default_monitor = 1;
186 static int default_floppy = 1;
187 static int default_cdrom = 1;
188 static int default_sdcard = 1;
189 static int default_vga = 1;
190 static int default_net = 1;
196 { .driver = "isa-serial", .flag = &default_serial },
197 { .driver = "isa-parallel", .flag = &default_parallel },
198 { .driver = "isa-fdc", .flag = &default_floppy },
199 { .driver = "floppy", .flag = &default_floppy },
200 { .driver = "ide-cd", .flag = &default_cdrom },
201 { .driver = "ide-hd", .flag = &default_cdrom },
202 { .driver = "scsi-cd", .flag = &default_cdrom },
203 { .driver = "scsi-hd", .flag = &default_cdrom },
204 { .driver = "VGA", .flag = &default_vga },
205 { .driver = "isa-vga", .flag = &default_vga },
206 { .driver = "cirrus-vga", .flag = &default_vga },
207 { .driver = "isa-cirrus-vga", .flag = &default_vga },
208 { .driver = "vmware-svga", .flag = &default_vga },
209 { .driver = "qxl-vga", .flag = &default_vga },
210 { .driver = "virtio-vga", .flag = &default_vga },
211 { .driver = "ati-vga", .flag = &default_vga },
212 { .driver = "vhost-user-vga", .flag = &default_vga },
213 { .driver = "virtio-vga-gl", .flag = &default_vga },
216 static QemuOptsList qemu_rtc_opts = {
218 .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head),
223 .type = QEMU_OPT_STRING,
226 .type = QEMU_OPT_STRING,
229 .type = QEMU_OPT_STRING,
231 { /* end of list */ }
235 static QemuOptsList qemu_option_rom_opts = {
236 .name = "option-rom",
237 .implied_opt_name = "romfile",
238 .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head),
242 .type = QEMU_OPT_NUMBER,
245 .type = QEMU_OPT_STRING,
247 { /* end of list */ }
251 static QemuOptsList qemu_accel_opts = {
253 .implied_opt_name = "accel",
254 .head = QTAILQ_HEAD_INITIALIZER(qemu_accel_opts.head),
257 * no elements => accept any
258 * sanity checking will happen later
259 * when setting accelerator properties
265 static QemuOptsList qemu_boot_opts = {
267 .implied_opt_name = "order",
269 .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head),
273 .type = QEMU_OPT_STRING,
276 .type = QEMU_OPT_STRING,
279 .type = QEMU_OPT_BOOL,
282 .type = QEMU_OPT_STRING,
284 .name = "splash-time",
285 .type = QEMU_OPT_NUMBER,
287 .name = "reboot-timeout",
288 .type = QEMU_OPT_NUMBER,
291 .type = QEMU_OPT_BOOL,
297 static QemuOptsList qemu_add_fd_opts = {
299 .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head),
303 .type = QEMU_OPT_NUMBER,
304 .help = "file descriptor of which a duplicate is added to fd set",
307 .type = QEMU_OPT_NUMBER,
308 .help = "ID of the fd set to add fd to",
311 .type = QEMU_OPT_STRING,
312 .help = "free-form string used to describe fd",
314 { /* end of list */ }
318 static QemuOptsList qemu_object_opts = {
320 .implied_opt_name = "qom-type",
321 .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
327 static QemuOptsList qemu_tpmdev_opts = {
329 .implied_opt_name = "type",
330 .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head),
332 /* options are defined in the TPM backends */
333 { /* end of list */ }
337 static QemuOptsList qemu_overcommit_opts = {
338 .name = "overcommit",
339 .head = QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts.head),
343 .type = QEMU_OPT_BOOL,
347 .type = QEMU_OPT_BOOL,
349 { /* end of list */ }
353 static QemuOptsList qemu_msg_opts = {
355 .head = QTAILQ_HEAD_INITIALIZER(qemu_msg_opts.head),
359 .type = QEMU_OPT_BOOL,
362 .name = "guest-name",
363 .type = QEMU_OPT_BOOL,
364 .help = "Prepends guest name for error messages but only if "
365 "-name guest is set otherwise option is ignored\n",
367 { /* end of list */ }
371 static QemuOptsList qemu_name_opts = {
373 .implied_opt_name = "guest",
375 .head = QTAILQ_HEAD_INITIALIZER(qemu_name_opts.head),
379 .type = QEMU_OPT_STRING,
380 .help = "Sets the name of the guest.\n"
381 "This name will be displayed in the SDL window caption.\n"
382 "The name will also be used for the VNC server",
385 .type = QEMU_OPT_STRING,
386 .help = "Sets the name of the QEMU process, as shown in top etc",
388 .name = "debug-threads",
389 .type = QEMU_OPT_BOOL,
390 .help = "When enabled, name the individual threads; defaults off.\n"
391 "NOTE: The thread names are for debugging and not a\n"
394 { /* End of list */ }
398 static QemuOptsList qemu_mem_opts = {
400 .implied_opt_name = "size",
401 .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head),
406 .type = QEMU_OPT_SIZE,
410 .type = QEMU_OPT_NUMBER,
414 .type = QEMU_OPT_SIZE,
416 { /* end of list */ }
420 static QemuOptsList qemu_icount_opts = {
422 .implied_opt_name = "shift",
424 .head = QTAILQ_HEAD_INITIALIZER(qemu_icount_opts.head),
428 .type = QEMU_OPT_STRING,
431 .type = QEMU_OPT_BOOL,
434 .type = QEMU_OPT_BOOL,
437 .type = QEMU_OPT_STRING,
440 .type = QEMU_OPT_STRING,
442 .name = "rrsnapshot",
443 .type = QEMU_OPT_STRING,
445 { /* end of list */ }
449 static QemuOptsList qemu_fw_cfg_opts = {
451 .implied_opt_name = "name",
452 .head = QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts.head),
456 .type = QEMU_OPT_STRING,
457 .help = "Sets the fw_cfg name of the blob to be inserted",
460 .type = QEMU_OPT_STRING,
461 .help = "Sets the name of the file from which "
462 "the fw_cfg blob will be loaded",
465 .type = QEMU_OPT_STRING,
466 .help = "Sets content of the blob to be inserted from a string",
469 .type = QEMU_OPT_STRING,
470 .help = "Sets id of the object generating the fw_cfg blob "
473 { /* end of list */ }
477 static QemuOptsList qemu_action_opts = {
480 .head = QTAILQ_HEAD_INITIALIZER(qemu_action_opts.head),
484 .type = QEMU_OPT_STRING,
487 .type = QEMU_OPT_STRING,
490 .type = QEMU_OPT_STRING,
493 .type = QEMU_OPT_STRING,
495 { /* end of list */ }
499 const char *qemu_get_vm_name(void)
504 static void default_driver_disable(const char *driver)
512 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
513 if (strcmp(default_list[i].driver, driver) != 0)
515 *(default_list[i].flag) = 0;
519 static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp)
521 const char *driver = qemu_opt_get(opts, "driver");
523 default_driver_disable(driver);
527 static void default_driver_check_json(void)
531 QTAILQ_FOREACH(opt, &device_opts, next) {
532 const char *driver = qdict_get_try_str(opt->opts, "driver");
533 default_driver_disable(driver);
537 static int parse_name(void *opaque, QemuOpts *opts, Error **errp)
539 const char *proc_name;
541 if (qemu_opt_get(opts, "debug-threads")) {
542 qemu_thread_naming(qemu_opt_get_bool(opts, "debug-threads", false));
544 qemu_name = qemu_opt_get(opts, "guest");
546 proc_name = qemu_opt_get(opts, "process");
548 os_set_proc_name(proc_name);
554 bool defaults_enabled(void)
560 static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp)
562 int fd, dupfd, flags;
564 const char *fd_opaque = NULL;
567 fd = qemu_opt_get_number(opts, "fd", -1);
568 fdset_id = qemu_opt_get_number(opts, "set", -1);
569 fd_opaque = qemu_opt_get(opts, "opaque");
572 error_setg(errp, "fd option is required and must be non-negative");
576 if (fd <= STDERR_FILENO) {
577 error_setg(errp, "fd cannot be a standard I/O stream");
582 * All fds inherited across exec() necessarily have FD_CLOEXEC
583 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
585 flags = fcntl(fd, F_GETFD);
586 if (flags == -1 || (flags & FD_CLOEXEC)) {
587 error_setg(errp, "fd is not valid or already in use");
592 error_setg(errp, "set option is required and must be non-negative");
596 #ifdef F_DUPFD_CLOEXEC
597 dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
601 qemu_set_cloexec(dupfd);
605 error_setg(errp, "error duplicating fd: %s", strerror(errno));
609 /* add the duplicate fd, and optionally the opaque string, to the fd set */
610 fdinfo = monitor_fdset_add_fd(dupfd, true, fdset_id, !!fd_opaque, fd_opaque,
617 static int cleanup_add_fd(void *opaque, QemuOpts *opts, Error **errp)
621 fd = qemu_opt_get_number(opts, "fd", -1);
628 /***********************************************************/
629 /* QEMU Block devices */
631 #define HD_OPTS "media=disk"
632 #define CDROM_OPTS "media=cdrom"
634 #define PFLASH_OPTS ""
638 static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp)
640 BlockInterfaceType *block_default_type = opaque;
642 return drive_new(opts, *block_default_type, errp) == NULL;
645 static int drive_enable_snapshot(void *opaque, QemuOpts *opts, Error **errp)
647 if (qemu_opt_get(opts, "snapshot") == NULL) {
648 qemu_opt_set(opts, "snapshot", "on", &error_abort);
653 static void default_drive(int enable, int snapshot, BlockInterfaceType type,
654 int index, const char *optstr)
659 if (!enable || drive_get_by_index(type, index)) {
663 opts = drive_add(type, index, NULL, optstr);
665 drive_enable_snapshot(NULL, opts, NULL);
668 dinfo = drive_new(opts, type, &error_abort);
669 dinfo->is_default = true;
673 static void configure_blockdev(BlockdevOptionsQueue *bdo_queue,
674 MachineClass *machine_class, int snapshot)
677 * If the currently selected machine wishes to override the
678 * units-per-bus property of its default HBA interface type, do so
681 if (machine_class->units_per_default_bus) {
682 override_max_devs(machine_class->block_default_type,
683 machine_class->units_per_default_bus);
686 /* open the virtual block devices */
687 while (!QSIMPLEQ_EMPTY(bdo_queue)) {
688 BlockdevOptionsQueueEntry *bdo = QSIMPLEQ_FIRST(bdo_queue);
690 QSIMPLEQ_REMOVE_HEAD(bdo_queue, entry);
691 loc_push_restore(&bdo->loc);
692 qmp_blockdev_add(bdo->bdo, &error_fatal);
694 qapi_free_BlockdevOptions(bdo->bdo);
698 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot,
701 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func,
702 &machine_class->block_default_type, &error_fatal)) {
703 /* We printed help */
707 default_drive(default_cdrom, snapshot, machine_class->block_default_type, 2,
709 default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS);
710 default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS);
714 static QemuOptsList qemu_smp_opts = {
716 .implied_opt_name = "cpus",
718 .head = QTAILQ_HEAD_INITIALIZER(qemu_smp_opts.head),
722 .type = QEMU_OPT_NUMBER,
725 .type = QEMU_OPT_NUMBER,
728 .type = QEMU_OPT_NUMBER,
731 .type = QEMU_OPT_NUMBER,
734 .type = QEMU_OPT_NUMBER,
737 .type = QEMU_OPT_NUMBER,
740 .type = QEMU_OPT_NUMBER,
746 static void realtime_init(void)
749 if (os_mlock() < 0) {
750 error_report("locking memory failed");
757 static void configure_msg(QemuOpts *opts)
759 message_with_timestamp = qemu_opt_get_bool(opts, "timestamp", false);
760 error_with_guestname = qemu_opt_get_bool(opts, "guest-name", false);
764 /***********************************************************/
767 static int usb_device_add(const char *devname)
769 USBDevice *dev = NULL;
771 if (!machine_usb(current_machine)) {
775 dev = usbdevice_create(devname);
782 static int usb_parse(const char *cmdline)
785 r = usb_device_add(cmdline);
787 error_report("could not add USB device '%s'", cmdline);
792 /***********************************************************/
793 /* machine registration */
795 static MachineClass *find_machine(const char *name, GSList *machines)
799 for (el = machines; el; el = el->next) {
800 MachineClass *mc = el->data;
802 if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) {
810 static MachineClass *find_default_machine(GSList *machines)
813 MachineClass *default_machineclass = NULL;
815 for (el = machines; el; el = el->next) {
816 MachineClass *mc = el->data;
818 if (mc->is_default) {
819 assert(default_machineclass == NULL && "Multiple default machines");
820 default_machineclass = mc;
824 return default_machineclass;
827 static void version(void)
829 printf("QEMU emulator version " QEMU_FULL_VERSION "\n"
830 QEMU_COPYRIGHT "\n");
833 static void help(int exitcode)
836 printf("usage: %s [options] [disk_image]\n\n"
837 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
838 error_get_progname());
840 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
841 if ((arch_mask) & arch_type) \
842 fputs(opt_help, stdout);
844 #define ARCHHEADING(text, arch_mask) \
845 if ((arch_mask) & arch_type) \
846 puts(stringify(text));
848 #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL)
850 #include "qemu-options.def"
852 printf("\nDuring emulation, the following keys are useful:\n"
853 "ctrl-alt-f toggle full screen\n"
854 "ctrl-alt-n switch to virtual console 'n'\n"
855 "ctrl-alt toggle mouse and keyboard grab\n"
857 "When using -nographic, press 'ctrl-a h' to get some help.\n"
859 QEMU_HELP_BOTTOM "\n");
864 #define HAS_ARG 0x0001
866 typedef struct QEMUOption {
873 static const QEMUOption qemu_options[] = {
874 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
876 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
877 { option, opt_arg, opt_enum, arch_mask },
878 #define DEFHEADING(text)
879 #define ARCHHEADING(text, arch_mask)
881 #include "qemu-options.def"
885 typedef struct VGAInterfaceInfo {
886 const char *opt_name; /* option name */
887 const char *name; /* human-readable name */
888 /* Class names indicating that support is available.
889 * If no class is specified, the interface is always available */
890 const char *class_names[2];
893 static const VGAInterfaceInfo vga_interfaces[VGA_TYPE_MAX] = {
896 .name = "no graphic card",
900 .name = "standard VGA",
901 .class_names = { "VGA", "isa-vga" },
904 .opt_name = "cirrus",
905 .name = "Cirrus VGA",
906 .class_names = { "cirrus-vga", "isa-cirrus-vga" },
909 .opt_name = "vmware",
910 .name = "VMWare SVGA",
911 .class_names = { "vmware-svga" },
914 .opt_name = "virtio",
915 .name = "Virtio VGA",
916 .class_names = { "virtio-vga" },
921 .class_names = { "qxl-vga" },
925 .name = "TCX framebuffer",
926 .class_names = { "sun-tcx" },
930 .name = "CG3 framebuffer",
931 .class_names = { "cgthree" },
935 .name = "Xen paravirtualized framebuffer",
939 static bool vga_interface_available(VGAInterfaceType t)
941 const VGAInterfaceInfo *ti = &vga_interfaces[t];
943 assert(t < VGA_TYPE_MAX);
944 return !ti->class_names[0] ||
945 module_object_class_by_name(ti->class_names[0]) ||
946 module_object_class_by_name(ti->class_names[1]);
950 get_default_vga_model(const MachineClass *machine_class)
952 if (machine_class->default_display) {
953 return machine_class->default_display;
954 } else if (vga_interface_available(VGA_CIRRUS)) {
956 } else if (vga_interface_available(VGA_STD)) {
963 static void select_vgahw(const MachineClass *machine_class, const char *p)
968 if (g_str_equal(p, "help")) {
969 const char *def = get_default_vga_model(machine_class);
971 for (t = 0; t < VGA_TYPE_MAX; t++) {
972 const VGAInterfaceInfo *ti = &vga_interfaces[t];
974 if (vga_interface_available(t) && ti->opt_name) {
975 printf("%-20s %s%s\n", ti->opt_name, ti->name ?: "",
976 g_str_equal(ti->opt_name, def) ? " (default)" : "");
982 assert(vga_interface_type == VGA_NONE);
983 for (t = 0; t < VGA_TYPE_MAX; t++) {
984 const VGAInterfaceInfo *ti = &vga_interfaces[t];
985 if (ti->opt_name && strstart(p, ti->opt_name, &opts)) {
986 if (!vga_interface_available(t)) {
987 error_report("%s not available", ti->name);
990 vga_interface_type = t;
994 if (t == VGA_TYPE_MAX) {
996 error_report("unknown vga type: %s", p);
1000 const char *nextopt;
1002 if (strstart(opts, ",retrace=", &nextopt)) {
1004 if (strstart(opts, "dumb", &nextopt))
1005 vga_retrace_method = VGA_RETRACE_DUMB;
1006 else if (strstart(opts, "precise", &nextopt))
1007 vga_retrace_method = VGA_RETRACE_PRECISE;
1008 else goto invalid_vga;
1009 } else goto invalid_vga;
1014 static void parse_display_qapi(const char *optarg)
1016 DisplayOptions *opts;
1019 v = qobject_input_visitor_new_str(optarg, "type", &error_fatal);
1021 visit_type_DisplayOptions(v, NULL, &opts, &error_fatal);
1022 QAPI_CLONE_MEMBERS(DisplayOptions, &dpy, opts);
1024 qapi_free_DisplayOptions(opts);
1028 DisplayOptions *qmp_query_display_options(Error **errp)
1030 return QAPI_CLONE(DisplayOptions, &dpy);
1033 static void parse_display(const char *p)
1037 if (is_help_option(p)) {
1038 qemu_display_help();
1042 if (strstart(p, "sdl", &opts)) {
1044 * sdl DisplayType needs hand-crafted parser instead of
1045 * parse_display_qapi() due to some options not in
1046 * DisplayOptions, specifically:
1047 * - ctrl_grab + alt_grab
1048 * They can't be moved into the QAPI since they use underscores,
1049 * thus they will get replaced by "grab-mod" in the long term
1051 #if defined(CONFIG_SDL)
1052 dpy.type = DISPLAY_TYPE_SDL;
1054 const char *nextopt;
1056 if (strstart(opts, ",grab-mod=", &nextopt)) {
1058 if (strstart(opts, "lshift-lctrl-lalt", &nextopt)) {
1060 } else if (strstart(opts, "rctrl", &nextopt)) {
1063 goto invalid_sdl_args;
1065 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
1067 if (strstart(opts, "on", &nextopt)) {
1069 } else if (strstart(opts, "off", &nextopt)) {
1072 goto invalid_sdl_args;
1074 warn_report("alt_grab is deprecated, use grab-mod instead.");
1075 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
1077 if (strstart(opts, "on", &nextopt)) {
1079 } else if (strstart(opts, "off", &nextopt)) {
1082 goto invalid_sdl_args;
1084 warn_report("ctrl_grab is deprecated, use grab-mod instead.");
1085 } else if (strstart(opts, ",window_close=", &nextopt) ||
1086 strstart(opts, ",window-close=", &nextopt)) {
1087 if (strstart(opts, ",window_close=", NULL)) {
1088 warn_report("window_close with an underscore is deprecated,"
1089 " please use window-close instead.");
1092 dpy.has_window_close = true;
1093 if (strstart(opts, "on", &nextopt)) {
1094 dpy.window_close = true;
1095 } else if (strstart(opts, "off", &nextopt)) {
1096 dpy.window_close = false;
1098 goto invalid_sdl_args;
1100 } else if (strstart(opts, ",show-cursor=", &nextopt)) {
1102 dpy.has_show_cursor = true;
1103 if (strstart(opts, "on", &nextopt)) {
1104 dpy.show_cursor = true;
1105 } else if (strstart(opts, "off", &nextopt)) {
1106 dpy.show_cursor = false;
1108 goto invalid_sdl_args;
1110 } else if (strstart(opts, ",gl=", &nextopt)) {
1113 if (strstart(opts, "on", &nextopt)) {
1114 dpy.gl = DISPLAYGL_MODE_ON;
1115 } else if (strstart(opts, "core", &nextopt)) {
1116 dpy.gl = DISPLAYGL_MODE_CORE;
1117 } else if (strstart(opts, "es", &nextopt)) {
1118 dpy.gl = DISPLAYGL_MODE_ES;
1119 } else if (strstart(opts, "off", &nextopt)) {
1120 dpy.gl = DISPLAYGL_MODE_OFF;
1122 goto invalid_sdl_args;
1126 error_report("invalid SDL option string");
1132 error_report("SDL display supported is not available in this binary");
1135 } else if (strstart(p, "vnc", &opts)) {
1137 * vnc isn't a (local) DisplayType but a protocol for remote
1141 vnc_parse(opts + 1);
1143 error_report("VNC requires a display argument vnc=<display>");
1147 parse_display_qapi(p);
1151 static inline bool nonempty_str(const char *str)
1156 static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)
1160 const char *name, *file, *str, *gen_id;
1161 FWCfgState *fw_cfg = (FWCfgState *) opaque;
1163 if (fw_cfg == NULL) {
1164 error_setg(errp, "fw_cfg device not available");
1167 name = qemu_opt_get(opts, "name");
1168 file = qemu_opt_get(opts, "file");
1169 str = qemu_opt_get(opts, "string");
1170 gen_id = qemu_opt_get(opts, "gen_id");
1172 /* we need the name, and exactly one of: file, content string, gen_id */
1173 if (!nonempty_str(name) ||
1174 nonempty_str(file) + nonempty_str(str) + nonempty_str(gen_id) != 1) {
1175 error_setg(errp, "name, plus exactly one of file,"
1176 " string and gen_id, are needed");
1179 if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) {
1180 error_setg(errp, "name too long (max. %d char)",
1181 FW_CFG_MAX_FILE_PATH - 1);
1184 if (nonempty_str(gen_id)) {
1186 * In this particular case where the content is populated
1187 * internally, the "etc/" namespace protection is relaxed,
1188 * so do not emit a warning.
1190 } else if (strncmp(name, "opt/", 4) != 0) {
1191 warn_report("externally provided fw_cfg item names "
1192 "should be prefixed with \"opt/\"");
1194 if (nonempty_str(str)) {
1195 size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */
1196 buf = g_memdup(str, size);
1197 } else if (nonempty_str(gen_id)) {
1198 if (!fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp)) {
1204 if (!g_file_get_contents(file, &buf, &size, &err)) {
1205 error_setg(errp, "can't load %s: %s", file, err->message);
1210 /* For legacy, keep user files in a specific global order. */
1211 fw_cfg_set_order_override(fw_cfg, FW_CFG_ORDER_OVERRIDE_USER);
1212 fw_cfg_add_file(fw_cfg, name, buf, size);
1213 fw_cfg_reset_order_override(fw_cfg);
1217 static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)
1219 return qdev_device_help(opts);
1222 static int device_init_func(void *opaque, QemuOpts *opts, Error **errp)
1226 dev = qdev_device_add(opts, errp);
1227 if (!dev && *errp) {
1228 error_report_err(*errp);
1231 object_unref(OBJECT(dev));
1236 static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
1238 Error *local_err = NULL;
1240 if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
1242 error_propagate(errp, local_err);
1250 #ifdef CONFIG_VIRTFS
1251 static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
1253 return qemu_fsdev_add(opts, errp);
1257 static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
1259 return monitor_init_opts(opts, errp);
1262 static void monitor_parse(const char *optarg, const char *mode, bool pretty)
1264 static int monitor_device_index = 0;
1269 if (strstart(optarg, "chardev:", &p)) {
1270 snprintf(label, sizeof(label), "%s", p);
1272 snprintf(label, sizeof(label), "compat_monitor%d",
1273 monitor_device_index);
1274 opts = qemu_chr_parse_compat(label, optarg, true);
1276 error_report("parse error: %s", optarg);
1281 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
1282 qemu_opt_set(opts, "mode", mode, &error_abort);
1283 qemu_opt_set(opts, "chardev", label, &error_abort);
1284 if (!strcmp(mode, "control")) {
1285 qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
1287 assert(pretty == false);
1289 monitor_device_index++;
1292 struct device_config {
1294 DEV_USB, /* -usbdevice */
1295 DEV_SERIAL, /* -serial */
1296 DEV_PARALLEL, /* -parallel */
1297 DEV_DEBUGCON, /* -debugcon */
1298 DEV_GDB, /* -gdb, -s */
1299 DEV_SCLP, /* s390 sclp */
1301 const char *cmdline;
1303 QTAILQ_ENTRY(device_config) next;
1306 static QTAILQ_HEAD(, device_config) device_configs =
1307 QTAILQ_HEAD_INITIALIZER(device_configs);
1309 static void add_device_config(int type, const char *cmdline)
1311 struct device_config *conf;
1313 conf = g_malloc0(sizeof(*conf));
1315 conf->cmdline = cmdline;
1316 loc_save(&conf->loc);
1317 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
1320 static int foreach_device_config(int type, int (*func)(const char *cmdline))
1322 struct device_config *conf;
1325 QTAILQ_FOREACH(conf, &device_configs, next) {
1326 if (conf->type != type)
1328 loc_push_restore(&conf->loc);
1329 rc = func(conf->cmdline);
1330 loc_pop(&conf->loc);
1338 static void qemu_disable_default_devices(void)
1340 MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
1342 default_driver_check_json();
1343 qemu_opts_foreach(qemu_find_opts("device"),
1344 default_driver_check, NULL, NULL);
1345 qemu_opts_foreach(qemu_find_opts("global"),
1346 default_driver_check, NULL, NULL);
1348 if (!vga_model && !default_vga) {
1349 vga_interface_type = VGA_DEVICE;
1351 if (!has_defaults || machine_class->no_serial) {
1354 if (!has_defaults || machine_class->no_parallel) {
1355 default_parallel = 0;
1357 if (!has_defaults || machine_class->no_floppy) {
1360 if (!has_defaults || machine_class->no_cdrom) {
1363 if (!has_defaults || machine_class->no_sdcard) {
1366 if (!has_defaults) {
1367 default_monitor = 0;
1373 static void qemu_create_default_devices(void)
1375 MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
1377 if (is_daemonized()) {
1378 /* According to documentation and historically, -nographic redirects
1379 * serial port, parallel port and monitor to stdio, which does not work
1380 * with -daemonize. We can redirect these to null instead, but since
1381 * -nographic is legacy, let's just error out.
1382 * We disallow -nographic only if all other ports are not redirected
1383 * explicitly, to not break existing legacy setups which uses
1384 * -nographic _and_ redirects all ports explicitly - this is valid
1385 * usage, -nographic is just a no-op in this case.
1388 && (default_parallel || default_serial || default_monitor)) {
1389 error_report("-nographic cannot be used with -daemonize");
1395 if (default_parallel)
1396 add_device_config(DEV_PARALLEL, "null");
1397 if (default_serial && default_monitor) {
1398 add_device_config(DEV_SERIAL, "mon:stdio");
1401 add_device_config(DEV_SERIAL, "stdio");
1402 if (default_monitor)
1403 monitor_parse("stdio", "readline", false);
1407 add_device_config(DEV_SERIAL, "vc:80Cx24C");
1408 if (default_parallel)
1409 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
1410 if (default_monitor)
1411 monitor_parse("vc:80Cx24C", "readline", false);
1415 QemuOptsList *net = qemu_find_opts("net");
1416 qemu_opts_parse(net, "nic", true, &error_abort);
1418 qemu_opts_parse(net, "user", true, &error_abort);
1422 #if defined(CONFIG_VNC)
1423 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head))) {
1427 if (dpy.type == DISPLAY_TYPE_DEFAULT && !display_remote) {
1428 if (!qemu_display_find_default(&dpy)) {
1429 dpy.type = DISPLAY_TYPE_NONE;
1430 #if defined(CONFIG_VNC)
1431 vnc_parse("localhost:0,to=99,id=default");
1435 if (dpy.type == DISPLAY_TYPE_DEFAULT) {
1436 dpy.type = DISPLAY_TYPE_NONE;
1439 /* If no default VGA is requested, the default is "none". */
1441 vga_model = get_default_vga_model(machine_class);
1444 select_vgahw(machine_class, vga_model);
1448 static int serial_parse(const char *devname)
1450 int index = num_serial_hds;
1453 if (strcmp(devname, "none") == 0)
1455 snprintf(label, sizeof(label), "serial%d", index);
1456 serial_hds = g_renew(Chardev *, serial_hds, index + 1);
1458 serial_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL);
1459 if (!serial_hds[index]) {
1460 error_report("could not connect serial device"
1461 " to character backend '%s'", devname);
1468 Chardev *serial_hd(int i)
1471 if (i < num_serial_hds) {
1472 return serial_hds[i];
1477 static int parallel_parse(const char *devname)
1479 static int index = 0;
1482 if (strcmp(devname, "none") == 0)
1484 if (index == MAX_PARALLEL_PORTS) {
1485 error_report("too many parallel ports");
1488 snprintf(label, sizeof(label), "parallel%d", index);
1489 parallel_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL);
1490 if (!parallel_hds[index]) {
1491 error_report("could not connect parallel device"
1492 " to character backend '%s'", devname);
1499 static int debugcon_parse(const char *devname)
1503 if (!qemu_chr_new_mux_mon("debugcon", devname, NULL)) {
1504 error_report("invalid character backend '%s'", devname);
1507 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL);
1509 error_report("already have a debugcon device");
1512 qemu_opt_set(opts, "driver", "isa-debugcon", &error_abort);
1513 qemu_opt_set(opts, "chardev", "debugcon", &error_abort);
1517 static gint machine_class_cmp(gconstpointer a, gconstpointer b)
1519 const MachineClass *mc1 = a, *mc2 = b;
1522 if (mc1->family == NULL) {
1523 if (mc2->family == NULL) {
1524 /* Compare standalone machine types against each other; they sort
1525 * in increasing order.
1527 return strcmp(object_class_get_name(OBJECT_CLASS(mc1)),
1528 object_class_get_name(OBJECT_CLASS(mc2)));
1531 /* Standalone machine types sort after families. */
1535 if (mc2->family == NULL) {
1536 /* Families sort before standalone machine types. */
1540 /* Families sort between each other alphabetically increasingly. */
1541 res = strcmp(mc1->family, mc2->family);
1546 /* Within the same family, machine types sort in decreasing order. */
1547 return strcmp(object_class_get_name(OBJECT_CLASS(mc2)),
1548 object_class_get_name(OBJECT_CLASS(mc1)));
1551 static void machine_help_func(const QDict *qdict)
1553 GSList *machines, *el;
1554 const char *type = qdict_get_try_str(qdict, "type");
1556 machines = object_class_get_list(TYPE_MACHINE, false);
1558 ObjectClass *machine_class = OBJECT_CLASS(find_machine(type, machines));
1559 if (machine_class) {
1560 type_print_class_properties(object_class_get_name(machine_class));
1565 printf("Supported machines are:\n");
1566 machines = g_slist_sort(machines, machine_class_cmp);
1567 for (el = machines; el; el = el->next) {
1568 MachineClass *mc = el->data;
1570 printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name);
1572 printf("%-20s %s%s%s\n", mc->name, mc->desc,
1573 mc->is_default ? " (default)" : "",
1574 mc->deprecation_reason ? " (deprecated)" : "");
1579 machine_merge_property(const char *propname, QDict *prop, Error **errp)
1584 /* Preserve the caller's reference to prop. */
1586 qdict_put(opts, propname, prop);
1587 keyval_merge(machine_opts_dict, opts, errp);
1588 qobject_unref(opts);
1592 machine_parse_property_opt(QemuOptsList *opts_list, const char *propname,
1598 prop = keyval_parse(arg, opts_list->implied_opt_name, &help, &error_fatal);
1600 qemu_opts_print_help(opts_list, true);
1603 machine_merge_property(propname, prop, &error_fatal);
1604 qobject_unref(prop);
1607 static const char *pid_file;
1608 static Notifier qemu_unlink_pidfile_notifier;
1610 static void qemu_unlink_pidfile(Notifier *n, void *data)
1617 static const QEMUOption *lookup_opt(int argc, char **argv,
1618 const char **poptarg, int *poptind)
1620 const QEMUOption *popt;
1621 int optind = *poptind;
1622 char *r = argv[optind];
1625 loc_set_cmdline(argv, optind, 1);
1627 /* Treat --foo the same as -foo. */
1630 popt = qemu_options;
1633 error_report("invalid option");
1636 if (!strcmp(popt->name, r + 1))
1640 if (popt->flags & HAS_ARG) {
1641 if (optind >= argc) {
1642 error_report("requires an argument");
1645 optarg = argv[optind++];
1646 loc_set_cmdline(argv, optind - 2, 2);
1657 static MachineClass *select_machine(QDict *qdict, Error **errp)
1659 const char *optarg = qdict_get_try_str(qdict, "type");
1660 GSList *machines = object_class_get_list(TYPE_MACHINE, false);
1661 MachineClass *machine_class;
1662 Error *local_err = NULL;
1665 machine_class = find_machine(optarg, machines);
1666 qdict_del(qdict, "type");
1667 if (!machine_class) {
1668 error_setg(&local_err, "unsupported machine type");
1671 machine_class = find_default_machine(machines);
1672 if (!machine_class) {
1673 error_setg(&local_err, "No machine specified, and there is no default");
1677 g_slist_free(machines);
1679 error_append_hint(&local_err, "Use -machine help to list supported machines\n");
1680 error_propagate(errp, local_err);
1682 return machine_class;
1685 static int object_parse_property_opt(Object *obj,
1686 const char *name, const char *value,
1687 const char *skip, Error **errp)
1689 if (g_str_equal(name, skip)) {
1693 if (!object_property_parse(obj, name, value, errp)) {
1700 /* *Non*recursively replace underscores with dashes in QDict keys. */
1701 static void keyval_dashify(QDict *qdict, Error **errp)
1703 const QDictEntry *ent, *next;
1706 for (ent = qdict_first(qdict); ent; ent = next) {
1707 g_autofree char *new_key = NULL;
1709 next = qdict_next(qdict, ent);
1710 if (!strchr(ent->key, '_')) {
1713 new_key = g_strdup(ent->key);
1714 for (p = new_key; *p; p++) {
1719 if (qdict_haskey(qdict, new_key)) {
1720 error_setg(errp, "Conflict between '%s' and '%s'", ent->key, new_key);
1723 qobject_ref(ent->value);
1724 qdict_put_obj(qdict, new_key, ent->value);
1725 qdict_del(qdict, ent->key);
1729 static void qemu_apply_legacy_machine_options(QDict *qdict)
1733 keyval_dashify(qdict, &error_fatal);
1735 /* Legacy options do not correspond to MachineState properties. */
1736 value = qdict_get_try_str(qdict, "accel");
1738 accelerators = g_strdup(value);
1739 qdict_del(qdict, "accel");
1742 value = qdict_get_try_str(qdict, "igd-passthru");
1744 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value,
1746 qdict_del(qdict, "igd-passthru");
1749 value = qdict_get_try_str(qdict, "kvm-shadow-mem");
1751 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value,
1753 qdict_del(qdict, "kvm-shadow-mem");
1756 value = qdict_get_try_str(qdict, "kernel-irqchip");
1758 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value,
1760 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value,
1762 qdict_del(qdict, "kernel-irqchip");
1766 static void object_option_foreach_add(bool (*type_opt_predicate)(const char *))
1768 ObjectOption *opt, *next;
1770 QTAILQ_FOREACH_SAFE(opt, &object_opts, next, next) {
1771 const char *type = ObjectType_str(opt->opts->qom_type);
1772 if (type_opt_predicate(type)) {
1773 user_creatable_add_qapi(opt->opts, &error_fatal);
1774 qapi_free_ObjectOptions(opt->opts);
1775 QTAILQ_REMOVE(&object_opts, opt, next);
1781 static void object_option_add_visitor(Visitor *v)
1783 ObjectOption *opt = g_new0(ObjectOption, 1);
1784 visit_type_ObjectOptions(v, NULL, &opt->opts, &error_fatal);
1785 QTAILQ_INSERT_TAIL(&object_opts, opt, next);
1788 static void object_option_parse(const char *optarg)
1794 if (optarg[0] == '{') {
1795 QObject *obj = qobject_from_json(optarg, &error_fatal);
1797 v = qobject_input_visitor_new(obj);
1800 opts = qemu_opts_parse_noisily(qemu_find_opts("object"),
1806 type = qemu_opt_get(opts, "qom-type");
1808 error_setg(&error_fatal, QERR_MISSING_PARAMETER, "qom-type");
1810 if (user_creatable_print_help(type, opts)) {
1814 v = opts_visitor_new(opts);
1817 object_option_add_visitor(v);
1822 * Initial object creation happens before all other
1823 * QEMU data types are created. The majority of objects
1824 * can be created at this point. The rng-egd object
1825 * cannot be created here, as it depends on the chardev
1828 static bool object_create_early(const char *type)
1831 * Objects should not be made "delayed" without a reason. If you
1832 * add one, state the reason in a comment!
1835 /* Reason: property "chardev" */
1836 if (g_str_equal(type, "rng-egd") ||
1837 g_str_equal(type, "qtest")) {
1841 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1842 /* Reason: cryptodev-vhost-user property "chardev" */
1843 if (g_str_equal(type, "cryptodev-vhost-user")) {
1848 /* Reason: vhost-user-blk-server property "node-name" */
1849 if (g_str_equal(type, "vhost-user-blk-server")) {
1853 * Reason: filter-* property "netdev" etc.
1855 if (g_str_equal(type, "filter-buffer") ||
1856 g_str_equal(type, "filter-dump") ||
1857 g_str_equal(type, "filter-mirror") ||
1858 g_str_equal(type, "filter-redirector") ||
1859 g_str_equal(type, "colo-compare") ||
1860 g_str_equal(type, "filter-rewriter") ||
1861 g_str_equal(type, "filter-replay")) {
1866 * Allocation of large amounts of memory may delay
1867 * chardev initialization for too long, and trigger timeouts
1868 * on software that waits for a monitor socket to be created
1871 if (g_str_has_prefix(type, "memory-backend-")) {
1878 static void qemu_apply_machine_options(QDict *qdict)
1880 MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
1881 const char *boot_order = NULL;
1882 const char *boot_once = NULL;
1885 object_set_properties_from_keyval(OBJECT(current_machine), qdict, false, &error_fatal);
1886 current_machine->ram_size = ram_size;
1887 current_machine->maxram_size = maxram_size;
1888 current_machine->ram_slots = ram_slots;
1890 opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
1892 boot_order = qemu_opt_get(opts, "order");
1894 validate_bootdevices(boot_order, &error_fatal);
1897 boot_once = qemu_opt_get(opts, "once");
1899 validate_bootdevices(boot_once, &error_fatal);
1902 boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu);
1903 boot_strict = qemu_opt_get_bool(opts, "strict", false);
1907 boot_order = machine_class->default_boot_order;
1910 current_machine->boot_order = boot_order;
1911 current_machine->boot_once = boot_once;
1913 if (semihosting_enabled() && !semihosting_get_argc()) {
1914 /* fall back to the -kernel/-append */
1915 semihosting_arg_fallback(current_machine->kernel_filename, current_machine->kernel_cmdline);
1918 if (current_machine->smp.cpus > 1) {
1919 Error *blocker = NULL;
1920 error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp");
1921 replay_add_blocker(blocker);
1925 static void qemu_create_early_backends(void)
1927 MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
1928 #if defined(CONFIG_SDL)
1929 const bool use_sdl = (dpy.type == DISPLAY_TYPE_SDL);
1931 const bool use_sdl = false;
1933 #if defined(CONFIG_GTK)
1934 const bool use_gtk = (dpy.type == DISPLAY_TYPE_GTK);
1936 const bool use_gtk = false;
1939 if ((alt_grab || ctrl_grab) && !use_sdl) {
1940 error_report("-alt-grab and -ctrl-grab are only valid "
1941 "for SDL, ignoring option");
1943 if (dpy.has_window_close && !use_gtk && !use_sdl) {
1944 error_report("window-close is only valid for GTK and SDL, "
1948 qemu_display_early_init(&dpy);
1949 qemu_console_early_init();
1951 if (dpy.has_gl && dpy.gl != DISPLAYGL_MODE_OFF && display_opengl == 0) {
1952 #if defined(CONFIG_OPENGL)
1953 error_report("OpenGL is not supported by the display");
1955 error_report("OpenGL support is disabled");
1960 object_option_foreach_add(object_create_early);
1962 /* spice needs the timers to be initialized by this point */
1963 /* spice must initialize before audio as it changes the default auiodev */
1964 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1967 qemu_opts_foreach(qemu_find_opts("chardev"),
1968 chardev_init_func, NULL, &error_fatal);
1970 #ifdef CONFIG_VIRTFS
1971 qemu_opts_foreach(qemu_find_opts("fsdev"),
1972 fsdev_init_func, NULL, &error_fatal);
1976 * Note: we need to create audio and block backends before
1977 * setting machine properties, so they can be referred to.
1979 configure_blockdev(&bdo_queue, machine_class, snapshot);
1980 audio_init_audiodevs();
1985 * The remainder of object creation happens after the
1986 * creation of chardev, fsdev, net clients and device data types.
1988 static bool object_create_late(const char *type)
1990 return !object_create_early(type);
1993 static void qemu_create_late_backends(void)
1996 qtest_server_init(qtest_chrdev, qtest_log, &error_fatal);
1999 net_init_clients(&error_fatal);
2001 object_option_foreach_add(object_create_late);
2003 if (tpm_init() < 0) {
2007 qemu_opts_foreach(qemu_find_opts("mon"),
2008 mon_init_func, NULL, &error_fatal);
2010 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
2012 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
2014 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
2017 /* now chardevs have been created we may have semihosting to connect */
2018 qemu_semihosting_connect_chardevs();
2019 qemu_semihosting_console_init();
2022 static bool have_custom_ram_size(void)
2024 QemuOpts *opts = qemu_find_opts_singleton("memory");
2025 return !!qemu_opt_get_size(opts, "size", 0);
2028 static void qemu_resolve_machine_memdev(void)
2030 if (current_machine->ram_memdev_id) {
2032 ram_addr_t backend_size;
2034 backend = object_resolve_path_type(current_machine->ram_memdev_id,
2035 TYPE_MEMORY_BACKEND, NULL);
2037 error_report("Memory backend '%s' not found",
2038 current_machine->ram_memdev_id);
2041 backend_size = object_property_get_uint(backend, "size", &error_abort);
2042 if (have_custom_ram_size() && backend_size != ram_size) {
2043 error_report("Size specified by -m option must match size of "
2044 "explicitly specified 'memory-backend' property");
2048 error_report("'-mem-path' can't be used together with"
2049 "'-machine memory-backend'");
2052 ram_size = backend_size;
2055 if (!xen_enabled()) {
2056 /* On 32-bit hosts, QEMU is limited by virtual address space */
2057 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
2058 error_report("at most 2047 MB RAM can be simulated");
2064 static void set_memory_options(MachineClass *mc)
2067 const char *mem_str;
2068 const ram_addr_t default_ram_size = mc->default_ram_size;
2069 QemuOpts *opts = qemu_find_opts_singleton("memory");
2072 loc_push_none(&loc);
2073 qemu_opts_loc_restore(opts);
2076 mem_str = qemu_opt_get(opts, "size");
2079 error_report("missing 'size' option value");
2083 sz = qemu_opt_get_size(opts, "size", ram_size);
2085 /* Fix up legacy suffix-less format */
2086 if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) {
2087 uint64_t overflow_check = sz;
2090 if (sz / MiB != overflow_check) {
2091 error_report("too large 'size' option value");
2097 /* backward compatibility behaviour for case "-m 0" */
2099 sz = default_ram_size;
2102 sz = QEMU_ALIGN_UP(sz, 8192);
2103 if (mc->fixup_ram_size) {
2104 sz = mc->fixup_ram_size(sz);
2107 if (ram_size != sz) {
2108 error_report("ram size too large");
2112 maxram_size = ram_size;
2114 if (qemu_opt_get(opts, "maxmem")) {
2117 sz = qemu_opt_get_size(opts, "maxmem", 0);
2118 slots = qemu_opt_get_number(opts, "slots", 0);
2119 if (sz < ram_size) {
2120 error_report("invalid value of -m option maxmem: "
2121 "maximum memory size (0x%" PRIx64 ") must be at least "
2122 "the initial memory size (0x" RAM_ADDR_FMT ")",
2125 } else if (slots && sz == ram_size) {
2126 error_report("invalid value of -m option maxmem: "
2127 "memory slots were specified but maximum memory size "
2128 "(0x%" PRIx64 ") is equal to the initial memory size "
2129 "(0x" RAM_ADDR_FMT ")", sz, ram_size);
2135 } else if (qemu_opt_get(opts, "slots")) {
2136 error_report("invalid -m option value: missing 'maxmem' option");
2143 static void qemu_create_machine(QDict *qdict)
2145 MachineClass *machine_class = select_machine(qdict, &error_fatal);
2146 object_set_machine_compat_props(machine_class->compat_props);
2148 set_memory_options(machine_class);
2150 current_machine = MACHINE(object_new_with_class(OBJECT_CLASS(machine_class)));
2151 object_property_add_child(object_get_root(), "machine",
2152 OBJECT(current_machine));
2153 object_property_add_child(container_get(OBJECT(current_machine),
2155 "sysbus", OBJECT(sysbus_get_default()));
2157 if (machine_class->minimum_page_bits) {
2158 if (!set_preferred_target_page_bits(machine_class->minimum_page_bits)) {
2159 /* This would be a board error: specifying a minimum smaller than
2160 * a target's compile-time fixed setting.
2162 g_assert_not_reached();
2166 cpu_exec_init_all();
2169 if (machine_class->hw_version) {
2170 qemu_set_hw_version(machine_class->hw_version);
2174 * Get the default machine options from the machine if it is not already
2175 * specified either by the configuration file or by the command line.
2177 if (machine_class->default_machine_opts) {
2178 QDict *default_opts =
2179 keyval_parse(machine_class->default_machine_opts, NULL, NULL,
2181 qemu_apply_legacy_machine_options(default_opts);
2182 object_set_properties_from_keyval(OBJECT(current_machine), default_opts,
2183 false, &error_abort);
2184 qobject_unref(default_opts);
2188 static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
2192 g = g_malloc0(sizeof(*g));
2193 g->driver = qemu_opt_get(opts, "driver");
2194 g->property = qemu_opt_get(opts, "property");
2195 g->value = qemu_opt_get(opts, "value");
2196 qdev_prop_register_global(g);
2201 * Return whether configuration group @group is stored in QemuOpts, or
2202 * recorded as one or more QDicts by qemu_record_config_group.
2204 static bool is_qemuopts_group(const char *group)
2206 if (g_str_equal(group, "object") ||
2207 g_str_equal(group, "machine") ||
2208 g_str_equal(group, "smp-opts")) {
2214 static void qemu_record_config_group(const char *group, QDict *dict,
2215 bool from_json, Error **errp)
2217 if (g_str_equal(group, "object")) {
2218 Visitor *v = qobject_input_visitor_new_keyval(QOBJECT(dict));
2219 object_option_add_visitor(v);
2221 } else if (g_str_equal(group, "machine")) {
2223 * Cannot merge string-valued and type-safe dictionaries, so JSON
2224 * is not accepted yet for -M.
2227 keyval_merge(machine_opts_dict, dict, errp);
2228 } else if (g_str_equal(group, "smp-opts")) {
2229 machine_merge_property("smp", dict, &error_fatal);
2236 * Parse non-QemuOpts config file groups, pass the rest to
2237 * qemu_config_do_parse.
2239 static void qemu_parse_config_group(const char *group, QDict *qdict,
2240 void *opaque, Error **errp)
2243 if (is_qemuopts_group(group)) {
2244 qemu_config_do_parse(group, qdict, opaque, errp);
2248 crumpled = qdict_crumple(qdict, errp);
2252 switch (qobject_type(crumpled)) {
2254 qemu_record_config_group(group, qobject_to(QDict, crumpled), false, errp);
2257 error_setg(errp, "Lists cannot be at top level of a configuration section");
2260 g_assert_not_reached();
2262 qobject_unref(crumpled);
2265 static void qemu_read_default_config_file(Error **errp)
2269 g_autofree char *file = get_relocated_path(CONFIG_QEMU_CONFDIR "/qemu.conf");
2271 ret = qemu_read_config_file(file, qemu_parse_config_group, errp);
2273 if (ret == -ENOENT) {
2280 static void qemu_set_option(const char *str, Error **errp)
2282 char group[64], id[64], arg[64];
2287 rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset);
2288 if (rc < 3 || str[offset] != '=') {
2289 error_setg(errp, "can't parse: \"%s\"", str);
2293 if (!is_qemuopts_group(group)) {
2294 error_setg(errp, "-set is not supported with %s", group);
2296 list = qemu_find_opts_err(group, errp);
2298 opts = qemu_opts_find(list, id);
2300 error_setg(errp, "there is no %s \"%s\" defined", group, id);
2303 qemu_opt_set(opts, arg, str + offset + 1, errp);
2308 static void user_register_global_props(void)
2310 qemu_opts_foreach(qemu_find_opts("global"),
2311 global_init_func, NULL, NULL);
2314 static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp)
2316 icount_configure(opts, errp);
2320 static int accelerator_set_property(void *opaque,
2321 const char *name, const char *value,
2324 return object_parse_property_opt(opaque, name, value, "accel", errp);
2327 static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)
2329 bool *p_init_failed = opaque;
2330 const char *acc = qemu_opt_get(opts, "accel");
2331 AccelClass *ac = accel_find(acc);
2334 bool qtest_with_kvm;
2336 qtest_with_kvm = g_str_equal(acc, "kvm") && qtest_chrdev != NULL;
2339 *p_init_failed = true;
2340 if (!qtest_with_kvm) {
2341 error_report("invalid accelerator %s", acc);
2345 accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac)));
2346 object_apply_compat_props(OBJECT(accel));
2347 qemu_opt_foreach(opts, accelerator_set_property,
2351 ret = accel_init_machine(accel, current_machine);
2353 *p_init_failed = true;
2354 if (!qtest_with_kvm || ret != -ENOENT) {
2355 error_report("failed to initialize %s: %s", acc, strerror(-ret));
2363 static void configure_accelerators(const char *progname)
2365 bool init_failed = false;
2367 qemu_opts_foreach(qemu_find_opts("icount"),
2368 do_configure_icount, NULL, &error_fatal);
2370 if (QTAILQ_EMPTY(&qemu_accel_opts.head)) {
2371 char **accel_list, **tmp;
2373 if (accelerators == NULL) {
2374 /* Select the default accelerator */
2375 bool have_tcg = accel_find("tcg");
2376 bool have_kvm = accel_find("kvm");
2378 if (have_tcg && have_kvm) {
2379 if (g_str_has_suffix(progname, "kvm")) {
2380 /* If the program name ends with "kvm", we prefer KVM */
2381 accelerators = "kvm:tcg";
2383 accelerators = "tcg:kvm";
2385 } else if (have_kvm) {
2386 accelerators = "kvm";
2387 } else if (have_tcg) {
2388 accelerators = "tcg";
2390 error_report("No accelerator selected and"
2391 " no default accelerator available");
2395 accel_list = g_strsplit(accelerators, ":", 0);
2397 for (tmp = accel_list; *tmp; tmp++) {
2399 * Filter invalid accelerators here, to prevent obscenities
2400 * such as "-machine accel=tcg,,thread=single".
2402 if (accel_find(*tmp)) {
2403 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp, true);
2406 error_report("invalid accelerator %s", *tmp);
2409 g_strfreev(accel_list);
2411 if (accelerators != NULL) {
2412 error_report("The -accel and \"-machine accel=\" options are incompatible");
2417 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2418 do_configure_accelerator, &init_failed, &error_fatal)) {
2420 error_report("no accelerator found");
2425 if (init_failed && !qtest_chrdev) {
2426 AccelClass *ac = ACCEL_GET_CLASS(current_accel());
2427 error_report("falling back to %s", ac->name);
2430 if (icount_enabled() && !tcg_enabled()) {
2431 error_report("-icount is not allowed with hardware virtualization");
2436 static void create_default_memdev(MachineState *ms, const char *path)
2439 MachineClass *mc = MACHINE_GET_CLASS(ms);
2441 obj = object_new(path ? TYPE_MEMORY_BACKEND_FILE : TYPE_MEMORY_BACKEND_RAM);
2443 object_property_set_str(obj, "mem-path", path, &error_fatal);
2445 object_property_set_int(obj, "size", ms->ram_size, &error_fatal);
2446 object_property_add_child(object_get_objects_root(), mc->default_ram_id,
2448 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2449 object_property_set_bool(obj, "x-use-canonical-path-for-ramblock-id",
2450 false, &error_fatal);
2451 user_creatable_complete(USER_CREATABLE(obj), &error_fatal);
2453 object_property_set_str(OBJECT(ms), "memory-backend", mc->default_ram_id,
2457 static void qemu_validate_options(const QDict *machine_opts)
2459 const char *kernel_filename = qdict_get_try_str(machine_opts, "kernel");
2460 const char *initrd_filename = qdict_get_try_str(machine_opts, "initrd");
2461 const char *kernel_cmdline = qdict_get_try_str(machine_opts, "append");
2463 if (kernel_filename == NULL) {
2464 if (kernel_cmdline != NULL) {
2465 error_report("-append only allowed with -kernel option");
2469 if (initrd_filename != NULL) {
2470 error_report("-initrd only allowed with -kernel option");
2475 if (loadvm && preconfig_requested) {
2476 error_report("'preconfig' and 'loadvm' options are "
2477 "mutually exclusive");
2480 if (incoming && preconfig_requested && strcmp(incoming, "defer") != 0) {
2481 error_report("'preconfig' supports '-incoming defer' only");
2485 #ifdef CONFIG_CURSES
2486 if (is_daemonized() && dpy.type == DISPLAY_TYPE_CURSES) {
2487 error_report("curses display cannot be used with -daemonize");
2493 static void qemu_process_sugar_options(void)
2496 QObject *smp = qdict_get(machine_opts_dict, "smp");
2497 if (smp && qobject_type(smp) == QTYPE_QDICT) {
2498 QObject *cpus = qdict_get(qobject_to(QDict, smp), "cpus");
2499 if (cpus && qobject_type(cpus) == QTYPE_QSTRING) {
2500 const char *val = qstring_get_str(qobject_to(QString, cpus));
2501 object_register_sugar_prop("memory-backend", "prealloc-threads",
2505 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2509 int i = select_watchdog(watchdog);
2511 exit (i == 1 ? 1 : 0);
2515 /* -action processing */
2518 * Process all the -action parameters parsed from cmdline.
2520 static int process_runstate_actions(void *opaque, QemuOpts *opts, Error **errp)
2522 Error *local_err = NULL;
2523 QDict *qdict = qemu_opts_to_qdict(opts, NULL);
2524 QObject *ret = NULL;
2525 qmp_marshal_set_action(qdict, &ret, &local_err);
2527 qobject_unref(qdict);
2529 error_propagate(errp, local_err);
2535 static void qemu_process_early_options(void)
2537 #ifdef CONFIG_SECCOMP
2538 QemuOptsList *olist = qemu_find_opts_err("sandbox", NULL);
2540 qemu_opts_foreach(olist, parse_sandbox, NULL, &error_fatal);
2544 qemu_opts_foreach(qemu_find_opts("name"),
2545 parse_name, NULL, &error_fatal);
2547 if (qemu_opts_foreach(qemu_find_opts("action"),
2548 process_runstate_actions, NULL, &error_fatal)) {
2553 qemu_opts_foreach(qemu_find_opts("add-fd"),
2554 parse_add_fd, NULL, &error_fatal);
2556 qemu_opts_foreach(qemu_find_opts("add-fd"),
2557 cleanup_add_fd, NULL, &error_fatal);
2560 /* Open the logfile at this point and set the log mask if necessary. */
2562 qemu_set_log_filename(log_file, &error_fatal);
2566 mask = qemu_str_to_log_mask(log_mask);
2568 qemu_print_log_usage(stdout);
2576 qemu_add_default_firmwarepath();
2579 static void qemu_process_help_options(void)
2582 * Check for -cpu help and -device help before we call select_machine(),
2583 * which will return an error if the architecture has no default machine
2584 * type and the user did not specify one, so that the user doesn't need
2585 * to say '-cpu help -machine something'.
2587 if (cpu_option && is_help_option(cpu_option)) {
2588 list_cpus(cpu_option);
2592 if (qemu_opts_foreach(qemu_find_opts("device"),
2593 device_help_func, NULL, NULL)) {
2597 /* -L help lists the data directories and exits. */
2598 if (list_data_dirs) {
2599 qemu_list_data_dirs();
2604 static void qemu_maybe_daemonize(const char *pid_file)
2609 rcu_disable_atfork();
2611 if (pid_file && !qemu_write_pidfile(pid_file, &err)) {
2612 error_reportf_err(err, "cannot create PID file: ");
2616 qemu_unlink_pidfile_notifier.notify = qemu_unlink_pidfile;
2617 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier);
2620 static void qemu_init_displays(void)
2624 /* init local displays */
2625 ds = init_displaystate();
2626 qemu_display_init(ds, &dpy);
2628 /* must be after terminal init, SDL library changes signal handlers */
2629 os_setup_signal_handling();
2631 /* init remote displays */
2633 qemu_opts_foreach(qemu_find_opts("vnc"),
2634 vnc_init_func, NULL, &error_fatal);
2638 qemu_spice.display_init();
2642 static void qemu_init_board(void)
2644 MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
2646 if (machine_class->default_ram_id && current_machine->ram_size &&
2647 numa_uses_legacy_mem() && !current_machine->ram_memdev_id) {
2648 create_default_memdev(current_machine, mem_path);
2651 /* process plugin before CPUs are created, but once -smp has been parsed */
2652 qemu_plugin_load_list(&plugin_list, &error_fatal);
2654 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2655 machine_run_board_init(current_machine);
2657 drive_check_orphaned();
2661 if (hax_enabled()) {
2662 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2667 static void qemu_create_cli_devices(void)
2673 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2674 parse_fw_cfg, fw_cfg_find(), &error_fatal);
2676 /* init USB devices */
2677 if (machine_usb(current_machine)) {
2678 if (foreach_device_config(DEV_USB, usb_parse) < 0)
2682 /* init generic devices */
2683 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE);
2684 qemu_opts_foreach(qemu_find_opts("device"),
2685 device_init_func, NULL, &error_fatal);
2686 QTAILQ_FOREACH(opt, &device_opts, next) {
2688 loc_push_restore(&opt->loc);
2690 * TODO Eventually we should call qmp_device_add() here to make sure it
2691 * behaves the same, but QMP still has to accept incorrectly typed
2692 * options until libvirt is fixed and we want to be strict on the CLI
2693 * from the start, so call qdev_device_add_from_qdict() directly for
2696 dev = qdev_device_add_from_qdict(opt->opts, true, &error_fatal);
2697 object_unref(OBJECT(dev));
2700 rom_reset_order_override();
2703 static void qemu_machine_creation_done(void)
2705 MachineState *machine = MACHINE(qdev_get_machine());
2707 /* Did we create any drives that we failed to create a device for? */
2708 drive_check_orphaned();
2710 /* Don't warn about the default network setup that you get if
2711 * no command line -net or -netdev options are specified. There
2712 * are two cases that we would otherwise complain about:
2713 * (1) board doesn't support a NIC but the implicit "-net nic"
2715 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2716 * sets up a nic that isn't connected to anything.
2718 if (!default_net && (!qtest_enabled() || has_defaults)) {
2719 net_check_clients();
2722 qdev_prop_check_globals();
2724 qdev_machine_creation_done();
2728 * Verify that Confidential Guest Support has actually been initialized
2730 assert(machine->cgs->ready);
2733 if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
2738 void qmp_x_exit_preconfig(Error **errp)
2740 if (phase_check(PHASE_MACHINE_INITIALIZED)) {
2741 error_setg(errp, "The command is permitted only before machine initialization");
2746 qemu_create_cli_devices();
2747 qemu_machine_creation_done();
2750 load_snapshot(loadvm, NULL, false, NULL, &error_fatal);
2752 if (replay_mode != REPLAY_MODE_NONE) {
2753 replay_vmstate_init();
2757 Error *local_err = NULL;
2758 if (strcmp(incoming, "defer") != 0) {
2759 qmp_migrate_incoming(incoming, &local_err);
2761 error_reportf_err(local_err, "-incoming %s: ", incoming);
2765 } else if (autostart) {
2770 void qemu_init(int argc, char **argv, char **envp)
2773 QemuOpts *icount_opts = NULL, *accel_opts = NULL;
2774 QemuOptsList *olist;
2777 MachineClass *machine_class;
2778 bool userconfig = true;
2779 FILE *vmstate_dump_file = NULL;
2781 qemu_add_opts(&qemu_drive_opts);
2782 qemu_add_drive_opts(&qemu_legacy_drive_opts);
2783 qemu_add_drive_opts(&qemu_common_drive_opts);
2784 qemu_add_drive_opts(&qemu_drive_opts);
2785 qemu_add_drive_opts(&bdrv_runtime_opts);
2786 qemu_add_opts(&qemu_chardev_opts);
2787 qemu_add_opts(&qemu_device_opts);
2788 qemu_add_opts(&qemu_netdev_opts);
2789 qemu_add_opts(&qemu_nic_opts);
2790 qemu_add_opts(&qemu_net_opts);
2791 qemu_add_opts(&qemu_rtc_opts);
2792 qemu_add_opts(&qemu_global_opts);
2793 qemu_add_opts(&qemu_mon_opts);
2794 qemu_add_opts(&qemu_trace_opts);
2795 qemu_plugin_add_opts();
2796 qemu_add_opts(&qemu_option_rom_opts);
2797 qemu_add_opts(&qemu_accel_opts);
2798 qemu_add_opts(&qemu_mem_opts);
2799 qemu_add_opts(&qemu_smp_opts);
2800 qemu_add_opts(&qemu_boot_opts);
2801 qemu_add_opts(&qemu_add_fd_opts);
2802 qemu_add_opts(&qemu_object_opts);
2803 qemu_add_opts(&qemu_tpmdev_opts);
2804 qemu_add_opts(&qemu_overcommit_opts);
2805 qemu_add_opts(&qemu_msg_opts);
2806 qemu_add_opts(&qemu_name_opts);
2807 qemu_add_opts(&qemu_numa_opts);
2808 qemu_add_opts(&qemu_icount_opts);
2809 qemu_add_opts(&qemu_semihosting_config_opts);
2810 qemu_add_opts(&qemu_fw_cfg_opts);
2811 qemu_add_opts(&qemu_action_opts);
2812 module_call_init(MODULE_INIT_OPTS);
2814 error_init(argv[0]);
2815 qemu_init_exec_dir(argv[0]);
2817 #ifdef CONFIG_MODULES
2818 module_init_info(qemu_modinfo);
2819 module_allow_arch(TARGET_NAME);
2822 qemu_init_subsystems();
2824 /* first pass of option parsing */
2826 while (optind < argc) {
2827 if (argv[optind][0] != '-') {
2831 const QEMUOption *popt;
2833 popt = lookup_opt(argc, argv, &optarg, &optind);
2834 switch (popt->index) {
2835 case QEMU_OPTION_nouserconfig:
2842 machine_opts_dict = qdict_new();
2844 qemu_read_default_config_file(&error_fatal);
2847 /* second pass of option parsing */
2852 if (argv[optind][0] != '-') {
2853 loc_set_cmdline(argv, optind, 1);
2854 drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
2856 const QEMUOption *popt;
2858 popt = lookup_opt(argc, argv, &optarg, &optind);
2859 if (!(popt->arch_mask & arch_type)) {
2860 error_report("Option not supported for this target");
2863 switch(popt->index) {
2864 case QEMU_OPTION_cpu:
2865 /* hw initialization will check this */
2866 cpu_option = optarg;
2868 case QEMU_OPTION_hda:
2869 case QEMU_OPTION_hdb:
2870 case QEMU_OPTION_hdc:
2871 case QEMU_OPTION_hdd:
2872 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2875 case QEMU_OPTION_blockdev:
2878 BlockdevOptionsQueueEntry *bdo;
2880 v = qobject_input_visitor_new_str(optarg, "driver",
2883 bdo = g_new(BlockdevOptionsQueueEntry, 1);
2884 visit_type_BlockdevOptions(v, NULL, &bdo->bdo,
2887 loc_save(&bdo->loc);
2888 QSIMPLEQ_INSERT_TAIL(&bdo_queue, bdo, entry);
2891 case QEMU_OPTION_drive:
2892 opts = qemu_opts_parse_noisily(qemu_find_opts("drive"),
2898 case QEMU_OPTION_set:
2899 qemu_set_option(optarg, &error_fatal);
2901 case QEMU_OPTION_global:
2902 if (qemu_global_option(optarg) != 0)
2905 case QEMU_OPTION_mtdblock:
2906 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
2908 case QEMU_OPTION_sd:
2909 drive_add(IF_SD, -1, optarg, SD_OPTS);
2911 case QEMU_OPTION_pflash:
2912 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
2914 case QEMU_OPTION_snapshot:
2916 Error *blocker = NULL;
2918 error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED,
2920 replay_add_blocker(blocker);
2923 case QEMU_OPTION_numa:
2924 opts = qemu_opts_parse_noisily(qemu_find_opts("numa"),
2930 case QEMU_OPTION_display:
2931 parse_display(optarg);
2933 case QEMU_OPTION_nographic:
2934 qdict_put_str(machine_opts_dict, "graphics", "off");
2936 dpy.type = DISPLAY_TYPE_NONE;
2938 case QEMU_OPTION_curses:
2939 warn_report("-curses is deprecated, "
2940 "use -display curses instead.");
2941 #ifdef CONFIG_CURSES
2942 dpy.type = DISPLAY_TYPE_CURSES;
2944 error_report("curses or iconv support is disabled");
2948 case QEMU_OPTION_portrait:
2949 graphic_rotate = 90;
2951 case QEMU_OPTION_rotate:
2952 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
2953 if (graphic_rotate != 0 && graphic_rotate != 90 &&
2954 graphic_rotate != 180 && graphic_rotate != 270) {
2955 error_report("only 90, 180, 270 deg rotation is available");
2959 case QEMU_OPTION_kernel:
2960 qdict_put_str(machine_opts_dict, "kernel", optarg);
2962 case QEMU_OPTION_initrd:
2963 qdict_put_str(machine_opts_dict, "initrd", optarg);
2965 case QEMU_OPTION_append:
2966 qdict_put_str(machine_opts_dict, "append", optarg);
2968 case QEMU_OPTION_dtb:
2969 qdict_put_str(machine_opts_dict, "dtb", optarg);
2971 case QEMU_OPTION_cdrom:
2972 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
2974 case QEMU_OPTION_boot:
2975 opts = qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2981 case QEMU_OPTION_fda:
2982 case QEMU_OPTION_fdb:
2983 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2986 case QEMU_OPTION_no_fd_bootchk:
2989 case QEMU_OPTION_netdev:
2991 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
2995 case QEMU_OPTION_nic:
2997 if (net_client_parse(qemu_find_opts("nic"), optarg) == -1) {
3001 case QEMU_OPTION_net:
3003 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
3007 #ifdef CONFIG_LIBISCSI
3008 case QEMU_OPTION_iscsi:
3009 opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3016 case QEMU_OPTION_audio_help:
3017 audio_legacy_help();
3020 case QEMU_OPTION_audiodev:
3021 audio_parse_option(optarg);
3023 case QEMU_OPTION_soundhw:
3024 select_soundhw (optarg);
3029 case QEMU_OPTION_version:
3034 opts = qemu_opts_parse_noisily(qemu_find_opts("memory"),
3041 case QEMU_OPTION_tpmdev:
3042 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
3047 case QEMU_OPTION_mempath:
3050 case QEMU_OPTION_mem_prealloc:
3059 case QEMU_OPTION_DFILTER:
3060 qemu_set_dfilter_ranges(optarg, &error_fatal);
3062 case QEMU_OPTION_seed:
3063 qemu_guest_random_seed_main(optarg, &error_fatal);
3066 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
3068 case QEMU_OPTION_gdb:
3069 add_device_config(DEV_GDB, optarg);
3072 if (is_help_option(optarg)) {
3073 list_data_dirs = true;
3075 qemu_add_data_dir(g_strdup(optarg));
3078 case QEMU_OPTION_bios:
3079 qdict_put_str(machine_opts_dict, "firmware", optarg);
3081 case QEMU_OPTION_singlestep:
3088 keyboard_layout = optarg;
3090 case QEMU_OPTION_vga:
3099 w = strtol(p, (char **)&p, 10);
3102 error_report("invalid resolution or depth");
3108 h = strtol(p, (char **)&p, 10);
3113 depth = strtol(p, (char **)&p, 10);
3114 if (depth != 1 && depth != 2 && depth != 4 &&
3115 depth != 8 && depth != 15 && depth != 16 &&
3116 depth != 24 && depth != 32)
3118 } else if (*p == '\0') {
3119 depth = graphic_depth;
3126 graphic_depth = depth;
3129 case QEMU_OPTION_echr:
3132 term_escape_char = strtol(optarg, &r, 0);
3134 printf("Bad argument to echr\n");
3137 case QEMU_OPTION_monitor:
3138 default_monitor = 0;
3139 if (strncmp(optarg, "none", 4)) {
3140 monitor_parse(optarg, "readline", false);
3143 case QEMU_OPTION_qmp:
3144 monitor_parse(optarg, "control", false);
3145 default_monitor = 0;
3147 case QEMU_OPTION_qmp_pretty:
3148 monitor_parse(optarg, "control", true);
3149 default_monitor = 0;
3151 case QEMU_OPTION_mon:
3152 opts = qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg,
3157 default_monitor = 0;
3159 case QEMU_OPTION_chardev:
3160 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3166 case QEMU_OPTION_fsdev:
3167 olist = qemu_find_opts("fsdev");
3169 error_report("fsdev support is disabled");
3172 opts = qemu_opts_parse_noisily(olist, optarg, true);
3177 case QEMU_OPTION_virtfs: {
3180 const char *writeout, *sock_fd, *socket, *path, *security_model,
3183 olist = qemu_find_opts("virtfs");
3185 error_report("virtfs support is disabled");
3188 opts = qemu_opts_parse_noisily(olist, optarg, true);
3193 if (qemu_opt_get(opts, "fsdriver") == NULL ||
3194 qemu_opt_get(opts, "mount_tag") == NULL) {
3195 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3198 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
3199 qemu_opts_id(opts) ?:
3200 qemu_opt_get(opts, "mount_tag"),
3203 error_report("duplicate or invalid fsdev id: %s",
3204 qemu_opt_get(opts, "mount_tag"));
3208 writeout = qemu_opt_get(opts, "writeout");
3210 #ifdef CONFIG_SYNC_FILE_RANGE
3211 qemu_opt_set(fsdev, "writeout", writeout, &error_abort);
3213 error_report("writeout=immediate not supported "
3214 "on this platform");
3218 qemu_opt_set(fsdev, "fsdriver",
3219 qemu_opt_get(opts, "fsdriver"), &error_abort);
3220 path = qemu_opt_get(opts, "path");
3222 qemu_opt_set(fsdev, "path", path, &error_abort);
3224 security_model = qemu_opt_get(opts, "security_model");
3225 if (security_model) {
3226 qemu_opt_set(fsdev, "security_model", security_model,
3229 socket = qemu_opt_get(opts, "socket");
3231 qemu_opt_set(fsdev, "socket", socket, &error_abort);
3233 sock_fd = qemu_opt_get(opts, "sock_fd");
3235 qemu_opt_set(fsdev, "sock_fd", sock_fd, &error_abort);
3238 qemu_opt_set_bool(fsdev, "readonly",
3239 qemu_opt_get_bool(opts, "readonly", 0),
3241 multidevs = qemu_opt_get(opts, "multidevs");
3243 qemu_opt_set(fsdev, "multidevs", multidevs, &error_abort);
3245 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3247 qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort);
3248 qemu_opt_set(device, "fsdev",
3249 qemu_opts_id(fsdev), &error_abort);
3250 qemu_opt_set(device, "mount_tag",
3251 qemu_opt_get(opts, "mount_tag"), &error_abort);
3254 case QEMU_OPTION_serial:
3255 add_device_config(DEV_SERIAL, optarg);
3257 if (strncmp(optarg, "mon:", 4) == 0) {
3258 default_monitor = 0;
3261 case QEMU_OPTION_watchdog:
3263 error_report("only one watchdog option may be given");
3266 warn_report("-watchdog is deprecated; use -device instead.");
3269 case QEMU_OPTION_action:
3270 olist = qemu_find_opts("action");
3271 if (!qemu_opts_parse_noisily(olist, optarg, false)) {
3275 case QEMU_OPTION_watchdog_action: {
3277 opts = qemu_opts_create(qemu_find_opts("action"), NULL, 0, &error_abort);
3278 qemu_opt_set(opts, "watchdog", optarg, &error_abort);
3281 case QEMU_OPTION_parallel:
3282 add_device_config(DEV_PARALLEL, optarg);
3283 default_parallel = 0;
3284 if (strncmp(optarg, "mon:", 4) == 0) {
3285 default_monitor = 0;
3288 case QEMU_OPTION_debugcon:
3289 add_device_config(DEV_DEBUGCON, optarg);
3291 case QEMU_OPTION_loadvm:
3294 case QEMU_OPTION_full_screen:
3295 dpy.has_full_screen = true;
3296 dpy.full_screen = true;
3298 case QEMU_OPTION_alt_grab:
3300 warn_report("-alt-grab is deprecated, please use "
3301 "-display sdl,grab-mod=lshift-lctrl-lalt instead.");
3303 case QEMU_OPTION_ctrl_grab:
3305 warn_report("-ctrl-grab is deprecated, please use "
3306 "-display sdl,grab-mod=rctrl instead.");
3308 case QEMU_OPTION_sdl:
3309 warn_report("-sdl is deprecated, use -display sdl instead.");
3311 dpy.type = DISPLAY_TYPE_SDL;
3314 error_report("SDL support is disabled");
3317 case QEMU_OPTION_pidfile:
3320 case QEMU_OPTION_win2k_hack:
3321 win2k_install_hack = 1;
3323 case QEMU_OPTION_acpitable:
3324 opts = qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3329 acpi_table_add(opts, &error_fatal);
3331 case QEMU_OPTION_smbios:
3332 opts = qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3337 smbios_entry_add(opts, &error_fatal);
3339 case QEMU_OPTION_fwcfg:
3340 opts = qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3346 case QEMU_OPTION_preconfig:
3347 preconfig_requested = true;
3349 case QEMU_OPTION_enable_kvm:
3350 qdict_put_str(machine_opts_dict, "accel", "kvm");
3353 case QEMU_OPTION_machine:
3357 keyval_parse_into(machine_opts_dict, optarg, "type", &help, &error_fatal);
3359 machine_help_func(machine_opts_dict);
3364 case QEMU_OPTION_accel:
3365 accel_opts = qemu_opts_parse_noisily(qemu_find_opts("accel"),
3367 optarg = qemu_opt_get(accel_opts, "accel");
3368 if (!optarg || is_help_option(optarg)) {
3369 printf("Accelerators supported in QEMU binary:\n");
3370 GSList *el, *accel_list = object_class_get_list(TYPE_ACCEL,
3372 for (el = accel_list; el; el = el->next) {
3373 gchar *typename = g_strdup(object_class_get_name(
3374 OBJECT_CLASS(el->data)));
3375 /* omit qtest which is used for tests only */
3376 if (g_strcmp0(typename, ACCEL_CLASS_NAME("qtest")) &&
3377 g_str_has_suffix(typename, ACCEL_CLASS_SUFFIX)) {
3378 gchar **optname = g_strsplit(typename,
3379 ACCEL_CLASS_SUFFIX, 0);
3380 printf("%s\n", optname[0]);
3381 g_strfreev(optname);
3385 g_slist_free(accel_list);
3389 case QEMU_OPTION_usb:
3390 qdict_put_str(machine_opts_dict, "usb", "on");
3392 case QEMU_OPTION_usbdevice:
3393 qdict_put_str(machine_opts_dict, "usb", "on");
3394 add_device_config(DEV_USB, optarg);
3396 case QEMU_OPTION_device:
3397 if (optarg[0] == '{') {
3398 QObject *obj = qobject_from_json(optarg, &error_fatal);
3399 DeviceOption *opt = g_new0(DeviceOption, 1);
3400 opt->opts = qobject_to(QDict, obj);
3401 loc_save(&opt->loc);
3402 assert(opt->opts != NULL);
3403 QTAILQ_INSERT_TAIL(&device_opts, opt, next);
3405 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3411 case QEMU_OPTION_smp:
3412 machine_parse_property_opt(qemu_find_opts("smp-opts"),
3415 case QEMU_OPTION_vnc:
3418 case QEMU_OPTION_no_acpi:
3419 qdict_put_str(machine_opts_dict, "acpi", "off");
3421 case QEMU_OPTION_no_hpet:
3422 qdict_put_str(machine_opts_dict, "hpet", "off");
3424 case QEMU_OPTION_no_reboot:
3425 olist = qemu_find_opts("action");
3426 qemu_opts_parse_noisily(olist, "reboot=shutdown", false);
3428 case QEMU_OPTION_no_shutdown:
3429 olist = qemu_find_opts("action");
3430 qemu_opts_parse_noisily(olist, "shutdown=pause", false);
3432 case QEMU_OPTION_uuid:
3433 if (qemu_uuid_parse(optarg, &qemu_uuid) < 0) {
3434 error_report("failed to parse UUID string: wrong format");
3437 qemu_uuid_set = true;
3439 case QEMU_OPTION_option_rom:
3440 if (nb_option_roms >= MAX_OPTION_ROMS) {
3441 error_report("too many option ROMs");
3444 opts = qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3449 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
3450 option_rom[nb_option_roms].bootindex =
3451 qemu_opt_get_number(opts, "bootindex", -1);
3452 if (!option_rom[nb_option_roms].name) {
3453 error_report("Option ROM file is not specified");
3458 case QEMU_OPTION_semihosting:
3459 qemu_semihosting_enable();
3461 case QEMU_OPTION_semihosting_config:
3462 if (qemu_semihosting_config_options(optarg) != 0) {
3466 case QEMU_OPTION_name:
3467 opts = qemu_opts_parse_noisily(qemu_find_opts("name"),
3472 /* Capture guest name if -msg guest-name is used later */
3473 error_guest_name = qemu_opt_get(opts, "guest");
3475 case QEMU_OPTION_prom_env:
3476 if (nb_prom_envs >= MAX_PROM_ENVS) {
3477 error_report("too many prom variables");
3480 prom_envs[nb_prom_envs] = optarg;
3483 case QEMU_OPTION_old_param:
3486 case QEMU_OPTION_rtc:
3487 opts = qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg,
3493 case QEMU_OPTION_icount:
3494 icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"),
3500 case QEMU_OPTION_incoming:
3502 runstate_set(RUN_STATE_INMIGRATE);
3506 case QEMU_OPTION_only_migratable:
3507 only_migratable = 1;
3509 case QEMU_OPTION_nodefaults:
3512 case QEMU_OPTION_xen_domid:
3513 if (!(accel_find("xen"))) {
3514 error_report("Option not supported for this target");
3517 xen_domid = atoi(optarg);
3519 case QEMU_OPTION_xen_attach:
3520 if (!(accel_find("xen"))) {
3521 error_report("Option not supported for this target");
3524 xen_mode = XEN_ATTACH;
3526 case QEMU_OPTION_xen_domid_restrict:
3527 if (!(accel_find("xen"))) {
3528 error_report("Option not supported for this target");
3531 xen_domid_restrict = true;
3533 case QEMU_OPTION_trace:
3534 trace_opt_parse(optarg);
3536 case QEMU_OPTION_plugin:
3537 qemu_plugin_opt_parse(optarg, &plugin_list);
3539 case QEMU_OPTION_readconfig:
3540 qemu_read_config_file(optarg, qemu_parse_config_group, &error_fatal);
3542 case QEMU_OPTION_spice:
3543 olist = qemu_find_opts_err("spice", NULL);
3545 error_report("spice support is disabled");
3548 opts = qemu_opts_parse_noisily(olist, optarg, false);
3554 case QEMU_OPTION_writeconfig:
3557 warn_report("-writeconfig is deprecated and will go away without a replacement");
3558 if (strcmp(optarg, "-") == 0) {
3561 fp = fopen(optarg, "w");
3563 error_report("open %s: %s", optarg,
3568 qemu_config_write(fp);
3574 case QEMU_OPTION_qtest:
3575 qtest_chrdev = optarg;
3577 case QEMU_OPTION_qtest_log:
3580 case QEMU_OPTION_sandbox:
3581 olist = qemu_find_opts("sandbox");
3583 #ifndef CONFIG_SECCOMP
3584 error_report("-sandbox support is not enabled "
3585 "in this QEMU binary");
3590 opts = qemu_opts_parse_noisily(olist, optarg, true);
3595 case QEMU_OPTION_add_fd:
3597 opts = qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3603 error_report("File descriptor passing is disabled on this "
3608 case QEMU_OPTION_object:
3609 object_option_parse(optarg);
3611 case QEMU_OPTION_overcommit:
3612 opts = qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3617 enable_mlock = qemu_opt_get_bool(opts, "mem-lock", false);
3618 enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", false);
3620 case QEMU_OPTION_compat:
3625 v = qobject_input_visitor_new_str(optarg, NULL,
3628 visit_type_CompatPolicy(v, NULL, &opts, &error_fatal);
3629 QAPI_CLONE_MEMBERS(CompatPolicy, &compat_policy, opts);
3631 qapi_free_CompatPolicy(opts);
3635 case QEMU_OPTION_msg:
3636 opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg,
3641 configure_msg(opts);
3643 case QEMU_OPTION_dump_vmstate:
3644 if (vmstate_dump_file) {
3645 error_report("only one '-dump-vmstate' "
3646 "option may be given");
3649 vmstate_dump_file = fopen(optarg, "w");
3650 if (vmstate_dump_file == NULL) {
3651 error_report("open %s: %s", optarg, strerror(errno));
3655 case QEMU_OPTION_enable_sync_profile:
3658 case QEMU_OPTION_nouserconfig:
3659 /* Nothing to be parsed here. Especially, do not error out below. */
3662 if (os_parse_cmd_args(popt->index, optarg)) {
3663 error_report("Option not supported in this build");
3670 * Clear error location left behind by the loop.
3671 * Best done right after the loop. Do not insert code here!
3675 qemu_validate_options(machine_opts_dict);
3676 qemu_process_sugar_options();
3679 * These options affect everything else and should be processed
3680 * before daemonizing.
3682 qemu_process_early_options();
3684 qemu_process_help_options();
3685 qemu_maybe_daemonize(pid_file);
3688 * The trace backend must be initialized after daemonizing.
3689 * trace_init_backends() will call st_init(), which will create the
3690 * trace thread in the parent, and also register st_flush_trace_buffer()
3691 * in atexit(). This function will force the parent to wait for the
3692 * writeout thread to finish, which will not occur, and the parent
3693 * process will be left in the host.
3695 if (!trace_init_backends()) {
3700 qemu_init_main_loop(&error_fatal);
3703 user_register_global_props();
3704 replay_configure(icount_opts);
3706 configure_rtc(qemu_find_opts_singleton("rtc"));
3708 qemu_create_machine(machine_opts_dict);
3712 qemu_disable_default_devices();
3713 qemu_create_default_devices();
3714 qemu_create_early_backends();
3716 qemu_apply_legacy_machine_options(machine_opts_dict);
3717 qemu_apply_machine_options(machine_opts_dict);
3718 qobject_unref(machine_opts_dict);
3719 phase_advance(PHASE_MACHINE_CREATED);
3722 * Note: uses machine properties such as kernel-irqchip, must run
3723 * after qemu_apply_machine_options.
3725 configure_accelerators(argv[0]);
3726 phase_advance(PHASE_ACCEL_CREATED);
3729 * Beware, QOM objects created before this point miss global and
3730 * compat properties.
3732 * Global properties get set up by qdev_prop_register_global(),
3733 * called from user_register_global_props(), and certain option
3734 * desugaring. Also in CPU feature desugaring (buried in
3735 * parse_cpu_option()), which happens below this point, but may
3736 * only target the CPU type, which can only be created after
3737 * parse_cpu_option() returned the type.
3739 * Machine compat properties: object_set_machine_compat_props().
3740 * Accelerator compat props: object_set_accelerator_compat_props(),
3741 * called from do_configure_accelerator().
3744 machine_class = MACHINE_GET_CLASS(current_machine);
3745 if (!qtest_enabled() && machine_class->deprecation_reason) {
3746 error_report("Machine type '%s' is deprecated: %s",
3747 machine_class->name, machine_class->deprecation_reason);
3751 * Note: creates a QOM object, must run only after global and
3752 * compat properties have been set up.
3754 migration_object_init();
3756 qemu_create_late_backends();
3758 /* parse features once if machine provides default cpu_type */
3759 current_machine->cpu_type = machine_class->default_cpu_type;
3761 current_machine->cpu_type = parse_cpu_option(cpu_option);
3763 /* NB: for machine none cpu_type could STILL be NULL here! */
3765 qemu_resolve_machine_memdev();
3766 parse_numa_opts(current_machine);
3768 if (vmstate_dump_file) {
3770 module_load_qom_all();
3771 dump_vmstate_json_to_file(vmstate_dump_file);
3775 if (!preconfig_requested) {
3776 qmp_x_exit_preconfig(&error_fatal);
3778 qemu_init_displays();
3779 accel_setup_post(current_machine);