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/qjson.h"
35 #include "qemu-version.h"
36 #include "qemu/cutils.h"
37 #include "qemu/help_option.h"
38 #include "qemu/uuid.h"
39 #include "sysemu/reset.h"
40 #include "sysemu/runstate.h"
41 #include "sysemu/runstate-action.h"
42 #include "sysemu/seccomp.h"
43 #include "sysemu/tcg.h"
44 #include "sysemu/xen.h"
46 #include "qemu/error-report.h"
47 #include "qemu/sockets.h"
48 #include "qemu/accel.h"
50 #include "hw/isa/isa.h"
51 #include "hw/scsi/scsi.h"
52 #include "hw/display/vga.h"
53 #include "sysemu/watchdog.h"
54 #include "hw/firmware/smbios.h"
55 #include "hw/acpi/acpi.h"
56 #include "hw/xen/xen.h"
57 #include "hw/loader.h"
58 #include "monitor/qdev.h"
60 #include "net/slirp.h"
61 #include "monitor/monitor.h"
62 #include "ui/console.h"
64 #include "sysemu/sysemu.h"
65 #include "sysemu/numa.h"
66 #include "sysemu/hostmem.h"
67 #include "exec/gdbstub.h"
68 #include "qemu/timer.h"
69 #include "chardev/char.h"
70 #include "qemu/bitmap.h"
72 #include "sysemu/blockdev.h"
73 #include "hw/block/block.h"
74 #include "hw/i386/x86.h"
75 #include "hw/i386/pc.h"
76 #include "migration/misc.h"
77 #include "migration/snapshot.h"
78 #include "sysemu/tpm.h"
79 #include "sysemu/dma.h"
80 #include "hw/audio/soundhw.h"
81 #include "audio/audio.h"
82 #include "sysemu/cpus.h"
83 #include "sysemu/cpu-timers.h"
84 #include "migration/colo.h"
85 #include "migration/postcopy-ram.h"
86 #include "sysemu/kvm.h"
87 #include "sysemu/hax.h"
88 #include "qapi/qobject-input-visitor.h"
89 #include "qemu/option.h"
90 #include "qemu/config-file.h"
91 #include "qemu-options.h"
92 #include "qemu/main-loop.h"
94 #include "fsdev/qemu-fsdev.h"
96 #include "sysemu/qtest.h"
98 #include "disas/disas.h"
101 #include "trace/control.h"
102 #include "qemu/plugin.h"
103 #include "qemu/queue.h"
104 #include "sysemu/arch_init.h"
105 #include "exec/confidential-guest-support.h"
107 #include "ui/qemu-spice.h"
108 #include "qapi/string-input-visitor.h"
109 #include "qapi/opts-visitor.h"
110 #include "qapi/clone-visitor.h"
111 #include "qom/object_interfaces.h"
112 #include "semihosting/semihost.h"
113 #include "crypto/init.h"
114 #include "sysemu/replay.h"
115 #include "qapi/qapi-events-run-state.h"
116 #include "qapi/qapi-visit-block-core.h"
117 #include "qapi/qapi-visit-compat.h"
118 #include "qapi/qapi-visit-ui.h"
119 #include "qapi/qapi-commands-block-core.h"
120 #include "qapi/qapi-commands-migration.h"
121 #include "qapi/qapi-commands-misc.h"
122 #include "qapi/qapi-visit-qom.h"
123 #include "qapi/qapi-commands-ui.h"
124 #include "qapi/qmp/qerror.h"
125 #include "sysemu/iothread.h"
126 #include "qemu/guest-random.h"
128 #define MAX_VIRTIO_CONSOLES 1
130 typedef struct BlockdevOptionsQueueEntry
{
131 BlockdevOptions
*bdo
;
133 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
134 } BlockdevOptionsQueueEntry
;
136 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
138 typedef struct ObjectOption
{
140 QTAILQ_ENTRY(ObjectOption
) next
;
143 static const char *cpu_option
;
144 static const char *mem_path
;
145 static const char *incoming
;
146 static const char *loadvm
;
147 static QTAILQ_HEAD(, ObjectOption
) object_opts
= QTAILQ_HEAD_INITIALIZER(object_opts
);
148 static ram_addr_t maxram_size
;
149 static uint64_t ram_slots
;
150 static int display_remote
;
152 static bool preconfig_requested
;
153 static QemuPluginList plugin_list
= QTAILQ_HEAD_INITIALIZER(plugin_list
);
154 static BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
155 static bool nographic
= false;
156 static int mem_prealloc
; /* force preallocation of physical target memory */
157 static ram_addr_t ram_size
;
158 static const char *vga_model
= NULL
;
159 static DisplayOptions dpy
;
160 static int num_serial_hds
;
161 static Chardev
**serial_hds
;
162 static const char *log_mask
;
163 static const char *log_file
;
164 static bool list_data_dirs
;
165 static const char *watchdog
;
166 static const char *qtest_chrdev
;
167 static const char *qtest_log
;
169 static int has_defaults
= 1;
170 static int default_serial
= 1;
171 static int default_parallel
= 1;
172 static int default_monitor
= 1;
173 static int default_floppy
= 1;
174 static int default_cdrom
= 1;
175 static int default_sdcard
= 1;
176 static int default_vga
= 1;
177 static int default_net
= 1;
183 { .driver
= "isa-serial", .flag
= &default_serial
},
184 { .driver
= "isa-parallel", .flag
= &default_parallel
},
185 { .driver
= "isa-fdc", .flag
= &default_floppy
},
186 { .driver
= "floppy", .flag
= &default_floppy
},
187 { .driver
= "ide-cd", .flag
= &default_cdrom
},
188 { .driver
= "ide-hd", .flag
= &default_cdrom
},
189 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
190 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
191 { .driver
= "VGA", .flag
= &default_vga
},
192 { .driver
= "isa-vga", .flag
= &default_vga
},
193 { .driver
= "cirrus-vga", .flag
= &default_vga
},
194 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
195 { .driver
= "vmware-svga", .flag
= &default_vga
},
196 { .driver
= "qxl-vga", .flag
= &default_vga
},
197 { .driver
= "virtio-vga", .flag
= &default_vga
},
198 { .driver
= "ati-vga", .flag
= &default_vga
},
199 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
202 static QemuOptsList qemu_rtc_opts
= {
204 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
209 .type
= QEMU_OPT_STRING
,
212 .type
= QEMU_OPT_STRING
,
215 .type
= QEMU_OPT_STRING
,
217 { /* end of list */ }
221 static QemuOptsList qemu_option_rom_opts
= {
222 .name
= "option-rom",
223 .implied_opt_name
= "romfile",
224 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
228 .type
= QEMU_OPT_NUMBER
,
231 .type
= QEMU_OPT_STRING
,
233 { /* end of list */ }
237 static QemuOptsList qemu_machine_opts
= {
239 .implied_opt_name
= "type",
241 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
244 * no elements => accept any
245 * sanity checking will happen later
246 * when setting machine properties
252 static QemuOptsList qemu_accel_opts
= {
254 .implied_opt_name
= "accel",
255 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
258 * no elements => accept any
259 * sanity checking will happen later
260 * when setting accelerator properties
266 static QemuOptsList qemu_boot_opts
= {
268 .implied_opt_name
= "order",
270 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
274 .type
= QEMU_OPT_STRING
,
277 .type
= QEMU_OPT_STRING
,
280 .type
= QEMU_OPT_BOOL
,
283 .type
= QEMU_OPT_STRING
,
285 .name
= "splash-time",
286 .type
= QEMU_OPT_NUMBER
,
288 .name
= "reboot-timeout",
289 .type
= QEMU_OPT_NUMBER
,
292 .type
= QEMU_OPT_BOOL
,
298 static QemuOptsList qemu_add_fd_opts
= {
300 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
304 .type
= QEMU_OPT_NUMBER
,
305 .help
= "file descriptor of which a duplicate is added to fd set",
308 .type
= QEMU_OPT_NUMBER
,
309 .help
= "ID of the fd set to add fd to",
312 .type
= QEMU_OPT_STRING
,
313 .help
= "free-form string used to describe fd",
315 { /* end of list */ }
319 static QemuOptsList qemu_object_opts
= {
321 .implied_opt_name
= "qom-type",
322 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
328 static QemuOptsList qemu_tpmdev_opts
= {
330 .implied_opt_name
= "type",
331 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
333 /* options are defined in the TPM backends */
334 { /* end of list */ }
338 static QemuOptsList qemu_overcommit_opts
= {
339 .name
= "overcommit",
340 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
344 .type
= QEMU_OPT_BOOL
,
348 .type
= QEMU_OPT_BOOL
,
350 { /* end of list */ }
354 static QemuOptsList qemu_msg_opts
= {
356 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
360 .type
= QEMU_OPT_BOOL
,
363 .name
= "guest-name",
364 .type
= QEMU_OPT_BOOL
,
365 .help
= "Prepends guest name for error messages but only if "
366 "-name guest is set otherwise option is ignored\n",
368 { /* end of list */ }
372 static QemuOptsList qemu_name_opts
= {
374 .implied_opt_name
= "guest",
376 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
380 .type
= QEMU_OPT_STRING
,
381 .help
= "Sets the name of the guest.\n"
382 "This name will be displayed in the SDL window caption.\n"
383 "The name will also be used for the VNC server",
386 .type
= QEMU_OPT_STRING
,
387 .help
= "Sets the name of the QEMU process, as shown in top etc",
389 .name
= "debug-threads",
390 .type
= QEMU_OPT_BOOL
,
391 .help
= "When enabled, name the individual threads; defaults off.\n"
392 "NOTE: The thread names are for debugging and not a\n"
395 { /* End of list */ }
399 static QemuOptsList qemu_mem_opts
= {
401 .implied_opt_name
= "size",
402 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
407 .type
= QEMU_OPT_SIZE
,
411 .type
= QEMU_OPT_NUMBER
,
415 .type
= QEMU_OPT_SIZE
,
417 { /* end of list */ }
421 static QemuOptsList qemu_icount_opts
= {
423 .implied_opt_name
= "shift",
425 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
429 .type
= QEMU_OPT_STRING
,
432 .type
= QEMU_OPT_BOOL
,
435 .type
= QEMU_OPT_BOOL
,
438 .type
= QEMU_OPT_STRING
,
441 .type
= QEMU_OPT_STRING
,
443 .name
= "rrsnapshot",
444 .type
= QEMU_OPT_STRING
,
446 { /* end of list */ }
450 static QemuOptsList qemu_fw_cfg_opts
= {
452 .implied_opt_name
= "name",
453 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
457 .type
= QEMU_OPT_STRING
,
458 .help
= "Sets the fw_cfg name of the blob to be inserted",
461 .type
= QEMU_OPT_STRING
,
462 .help
= "Sets the name of the file from which "
463 "the fw_cfg blob will be loaded",
466 .type
= QEMU_OPT_STRING
,
467 .help
= "Sets content of the blob to be inserted from a string",
470 .type
= QEMU_OPT_STRING
,
471 .help
= "Sets id of the object generating the fw_cfg blob "
474 { /* end of list */ }
478 static QemuOptsList qemu_action_opts
= {
481 .head
= QTAILQ_HEAD_INITIALIZER(qemu_action_opts
.head
),
485 .type
= QEMU_OPT_STRING
,
488 .type
= QEMU_OPT_STRING
,
491 .type
= QEMU_OPT_STRING
,
494 .type
= QEMU_OPT_STRING
,
496 { /* end of list */ }
501 * Get machine options
503 * Returns: machine options (never null).
505 static QemuOpts
*qemu_get_machine_opts(void)
507 return qemu_find_opts_singleton("machine");
510 const char *qemu_get_vm_name(void)
515 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
517 const char *driver
= qemu_opt_get(opts
, "driver");
522 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
523 if (strcmp(default_list
[i
].driver
, driver
) != 0)
525 *(default_list
[i
].flag
) = 0;
530 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
532 const char *proc_name
;
534 if (qemu_opt_get(opts
, "debug-threads")) {
535 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
537 qemu_name
= qemu_opt_get(opts
, "guest");
539 proc_name
= qemu_opt_get(opts
, "process");
541 os_set_proc_name(proc_name
);
547 bool defaults_enabled(void)
553 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
555 int fd
, dupfd
, flags
;
557 const char *fd_opaque
= NULL
;
560 fd
= qemu_opt_get_number(opts
, "fd", -1);
561 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
562 fd_opaque
= qemu_opt_get(opts
, "opaque");
565 error_setg(errp
, "fd option is required and must be non-negative");
569 if (fd
<= STDERR_FILENO
) {
570 error_setg(errp
, "fd cannot be a standard I/O stream");
575 * All fds inherited across exec() necessarily have FD_CLOEXEC
576 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
578 flags
= fcntl(fd
, F_GETFD
);
579 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
580 error_setg(errp
, "fd is not valid or already in use");
585 error_setg(errp
, "set option is required and must be non-negative");
589 #ifdef F_DUPFD_CLOEXEC
590 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
594 qemu_set_cloexec(dupfd
);
598 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
602 /* add the duplicate fd, and optionally the opaque string, to the fd set */
603 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
610 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
614 fd
= qemu_opt_get_number(opts
, "fd", -1);
621 /***********************************************************/
622 /* QEMU Block devices */
624 #define HD_OPTS "media=disk"
625 #define CDROM_OPTS "media=cdrom"
627 #define PFLASH_OPTS ""
631 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
633 BlockInterfaceType
*block_default_type
= opaque
;
635 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
638 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
640 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
641 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
646 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
647 int index
, const char *optstr
)
652 if (!enable
|| drive_get_by_index(type
, index
)) {
656 opts
= drive_add(type
, index
, NULL
, optstr
);
658 drive_enable_snapshot(NULL
, opts
, NULL
);
661 dinfo
= drive_new(opts
, type
, &error_abort
);
662 dinfo
->is_default
= true;
666 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
667 MachineClass
*machine_class
, int snapshot
)
670 * If the currently selected machine wishes to override the
671 * units-per-bus property of its default HBA interface type, do so
674 if (machine_class
->units_per_default_bus
) {
675 override_max_devs(machine_class
->block_default_type
,
676 machine_class
->units_per_default_bus
);
679 /* open the virtual block devices */
680 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
681 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
683 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
684 loc_push_restore(&bdo
->loc
);
685 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
687 qapi_free_BlockdevOptions(bdo
->bdo
);
691 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
694 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
695 &machine_class
->block_default_type
, &error_fatal
)) {
696 /* We printed help */
700 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
702 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
703 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
707 static QemuOptsList qemu_smp_opts
= {
709 .implied_opt_name
= "cpus",
711 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
715 .type
= QEMU_OPT_NUMBER
,
718 .type
= QEMU_OPT_NUMBER
,
721 .type
= QEMU_OPT_NUMBER
,
724 .type
= QEMU_OPT_NUMBER
,
727 .type
= QEMU_OPT_NUMBER
,
730 .type
= QEMU_OPT_NUMBER
,
736 static void realtime_init(void)
739 if (os_mlock() < 0) {
740 error_report("locking memory failed");
747 static void configure_msg(QemuOpts
*opts
)
749 message_with_timestamp
= qemu_opt_get_bool(opts
, "timestamp", false);
750 error_with_guestname
= qemu_opt_get_bool(opts
, "guest-name", false);
754 /***********************************************************/
757 static int usb_device_add(const char *devname
)
759 USBDevice
*dev
= NULL
;
761 if (!machine_usb(current_machine
)) {
765 dev
= usbdevice_create(devname
);
772 static int usb_parse(const char *cmdline
)
775 r
= usb_device_add(cmdline
);
777 error_report("could not add USB device '%s'", cmdline
);
782 /***********************************************************/
783 /* machine registration */
785 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
789 for (el
= machines
; el
; el
= el
->next
) {
790 MachineClass
*mc
= el
->data
;
792 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
800 static MachineClass
*find_default_machine(GSList
*machines
)
803 MachineClass
*default_machineclass
= NULL
;
805 for (el
= machines
; el
; el
= el
->next
) {
806 MachineClass
*mc
= el
->data
;
808 if (mc
->is_default
) {
809 assert(default_machineclass
== NULL
&& "Multiple default machines");
810 default_machineclass
= mc
;
814 return default_machineclass
;
817 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
819 ObjectProperty
*prop
;
820 ObjectPropertyIterator iter
;
822 if (!qemu_opt_has_help_opt(opts
)) {
826 object_property_iter_init(&iter
, OBJECT(machine
));
827 while ((prop
= object_property_iter_next(&iter
))) {
832 printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
833 prop
->name
, prop
->type
);
834 if (prop
->description
) {
835 printf(" (%s)\n", prop
->description
);
844 static void version(void)
846 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
847 QEMU_COPYRIGHT
"\n");
850 static void help(int exitcode
)
853 printf("usage: %s [options] [disk_image]\n\n"
854 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
855 error_get_progname());
857 #define QEMU_OPTIONS_GENERATE_HELP
858 #include "qemu-options-wrapper.h"
860 printf("\nDuring emulation, the following keys are useful:\n"
861 "ctrl-alt-f toggle full screen\n"
862 "ctrl-alt-n switch to virtual console 'n'\n"
863 "ctrl-alt toggle mouse and keyboard grab\n"
865 "When using -nographic, press 'ctrl-a h' to get some help.\n"
867 QEMU_HELP_BOTTOM
"\n");
872 #define HAS_ARG 0x0001
874 typedef struct QEMUOption
{
881 static const QEMUOption qemu_options
[] = {
882 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
883 #define QEMU_OPTIONS_GENERATE_OPTIONS
884 #include "qemu-options-wrapper.h"
888 typedef struct VGAInterfaceInfo
{
889 const char *opt_name
; /* option name */
890 const char *name
; /* human-readable name */
891 /* Class names indicating that support is available.
892 * If no class is specified, the interface is always available */
893 const char *class_names
[2];
896 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
899 .name
= "no graphic card",
903 .name
= "standard VGA",
904 .class_names
= { "VGA", "isa-vga" },
907 .opt_name
= "cirrus",
908 .name
= "Cirrus VGA",
909 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
912 .opt_name
= "vmware",
913 .name
= "VMWare SVGA",
914 .class_names
= { "vmware-svga" },
917 .opt_name
= "virtio",
918 .name
= "Virtio VGA",
919 .class_names
= { "virtio-vga" },
924 .class_names
= { "qxl-vga" },
928 .name
= "TCX framebuffer",
929 .class_names
= { "sun-tcx" },
933 .name
= "CG3 framebuffer",
934 .class_names
= { "cgthree" },
938 .name
= "Xen paravirtualized framebuffer",
942 static bool vga_interface_available(VGAInterfaceType t
)
944 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
946 assert(t
< VGA_TYPE_MAX
);
947 return !ti
->class_names
[0] ||
948 module_object_class_by_name(ti
->class_names
[0]) ||
949 module_object_class_by_name(ti
->class_names
[1]);
953 get_default_vga_model(const MachineClass
*machine_class
)
955 if (machine_class
->default_display
) {
956 return machine_class
->default_display
;
957 } else if (vga_interface_available(VGA_CIRRUS
)) {
959 } else if (vga_interface_available(VGA_STD
)) {
966 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
971 if (g_str_equal(p
, "help")) {
972 const char *def
= get_default_vga_model(machine_class
);
974 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
975 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
977 if (vga_interface_available(t
) && ti
->opt_name
) {
978 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
979 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
985 assert(vga_interface_type
== VGA_NONE
);
986 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
987 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
988 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
989 if (!vga_interface_available(t
)) {
990 error_report("%s not available", ti
->name
);
993 vga_interface_type
= t
;
997 if (t
== VGA_TYPE_MAX
) {
999 error_report("unknown vga type: %s", p
);
1003 const char *nextopt
;
1005 if (strstart(opts
, ",retrace=", &nextopt
)) {
1007 if (strstart(opts
, "dumb", &nextopt
))
1008 vga_retrace_method
= VGA_RETRACE_DUMB
;
1009 else if (strstart(opts
, "precise", &nextopt
))
1010 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1011 else goto invalid_vga
;
1012 } else goto invalid_vga
;
1017 static void parse_display_qapi(const char *optarg
)
1019 DisplayOptions
*opts
;
1022 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
1024 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
1025 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
1027 qapi_free_DisplayOptions(opts
);
1031 DisplayOptions
*qmp_query_display_options(Error
**errp
)
1033 return QAPI_CLONE(DisplayOptions
, &dpy
);
1036 static void parse_display(const char *p
)
1040 if (is_help_option(p
)) {
1041 qemu_display_help();
1045 if (strstart(p
, "sdl", &opts
)) {
1047 * sdl DisplayType needs hand-crafted parser instead of
1048 * parse_display_qapi() due to some options not in
1049 * DisplayOptions, specifically:
1051 * Already deprecated.
1052 * - ctrl_grab + alt_grab
1053 * Not clear yet what happens to them long-term. Should
1054 * replaced by something better or deprecated and dropped.
1056 dpy
.type
= DISPLAY_TYPE_SDL
;
1058 const char *nextopt
;
1060 if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1062 if (strstart(opts
, "on", &nextopt
)) {
1064 } else if (strstart(opts
, "off", &nextopt
)) {
1067 goto invalid_sdl_args
;
1069 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1071 if (strstart(opts
, "on", &nextopt
)) {
1073 } else if (strstart(opts
, "off", &nextopt
)) {
1076 goto invalid_sdl_args
;
1078 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
1080 dpy
.has_window_close
= true;
1081 if (strstart(opts
, "on", &nextopt
)) {
1082 dpy
.window_close
= true;
1083 } else if (strstart(opts
, "off", &nextopt
)) {
1084 dpy
.window_close
= false;
1086 goto invalid_sdl_args
;
1088 } else if (strstart(opts
, ",show-cursor=", &nextopt
)) {
1090 dpy
.has_show_cursor
= true;
1091 if (strstart(opts
, "on", &nextopt
)) {
1092 dpy
.show_cursor
= true;
1093 } else if (strstart(opts
, "off", &nextopt
)) {
1094 dpy
.show_cursor
= false;
1096 goto invalid_sdl_args
;
1098 } else if (strstart(opts
, ",gl=", &nextopt
)) {
1101 if (strstart(opts
, "on", &nextopt
)) {
1102 dpy
.gl
= DISPLAYGL_MODE_ON
;
1103 } else if (strstart(opts
, "core", &nextopt
)) {
1104 dpy
.gl
= DISPLAYGL_MODE_CORE
;
1105 } else if (strstart(opts
, "es", &nextopt
)) {
1106 dpy
.gl
= DISPLAYGL_MODE_ES
;
1107 } else if (strstart(opts
, "off", &nextopt
)) {
1108 dpy
.gl
= DISPLAYGL_MODE_OFF
;
1110 goto invalid_sdl_args
;
1114 error_report("invalid SDL option string");
1119 } else if (strstart(p
, "vnc", &opts
)) {
1121 * vnc isn't a (local) DisplayType but a protocol for remote
1125 vnc_parse(opts
+ 1);
1127 error_report("VNC requires a display argument vnc=<display>");
1131 parse_display_qapi(p
);
1135 static inline bool nonempty_str(const char *str
)
1140 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1144 const char *name
, *file
, *str
, *gen_id
;
1145 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1147 if (fw_cfg
== NULL
) {
1148 error_setg(errp
, "fw_cfg device not available");
1151 name
= qemu_opt_get(opts
, "name");
1152 file
= qemu_opt_get(opts
, "file");
1153 str
= qemu_opt_get(opts
, "string");
1154 gen_id
= qemu_opt_get(opts
, "gen_id");
1156 /* we need the name, and exactly one of: file, content string, gen_id */
1157 if (!nonempty_str(name
) ||
1158 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1159 error_setg(errp
, "name, plus exactly one of file,"
1160 " string and gen_id, are needed");
1163 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1164 error_setg(errp
, "name too long (max. %d char)",
1165 FW_CFG_MAX_FILE_PATH
- 1);
1168 if (nonempty_str(gen_id
)) {
1170 * In this particular case where the content is populated
1171 * internally, the "etc/" namespace protection is relaxed,
1172 * so do not emit a warning.
1174 } else if (strncmp(name
, "opt/", 4) != 0) {
1175 warn_report("externally provided fw_cfg item names "
1176 "should be prefixed with \"opt/\"");
1178 if (nonempty_str(str
)) {
1179 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1180 buf
= g_memdup(str
, size
);
1181 } else if (nonempty_str(gen_id
)) {
1182 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1188 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1189 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1194 /* For legacy, keep user files in a specific global order. */
1195 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1196 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1197 fw_cfg_reset_order_override(fw_cfg
);
1201 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1203 return qdev_device_help(opts
);
1206 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1210 dev
= qdev_device_add(opts
, errp
);
1211 if (!dev
&& *errp
) {
1212 error_report_err(*errp
);
1215 object_unref(OBJECT(dev
));
1220 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1222 Error
*local_err
= NULL
;
1224 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1226 error_propagate(errp
, local_err
);
1234 #ifdef CONFIG_VIRTFS
1235 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1237 return qemu_fsdev_add(opts
, errp
);
1241 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1243 return monitor_init_opts(opts
, errp
);
1246 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
1248 static int monitor_device_index
= 0;
1253 if (strstart(optarg
, "chardev:", &p
)) {
1254 snprintf(label
, sizeof(label
), "%s", p
);
1256 snprintf(label
, sizeof(label
), "compat_monitor%d",
1257 monitor_device_index
);
1258 opts
= qemu_chr_parse_compat(label
, optarg
, true);
1260 error_report("parse error: %s", optarg
);
1265 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1266 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1267 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1268 if (!strcmp(mode
, "control")) {
1269 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1271 assert(pretty
== false);
1273 monitor_device_index
++;
1276 struct device_config
{
1278 DEV_USB
, /* -usbdevice */
1279 DEV_SERIAL
, /* -serial */
1280 DEV_PARALLEL
, /* -parallel */
1281 DEV_DEBUGCON
, /* -debugcon */
1282 DEV_GDB
, /* -gdb, -s */
1283 DEV_SCLP
, /* s390 sclp */
1285 const char *cmdline
;
1287 QTAILQ_ENTRY(device_config
) next
;
1290 static QTAILQ_HEAD(, device_config
) device_configs
=
1291 QTAILQ_HEAD_INITIALIZER(device_configs
);
1293 static void add_device_config(int type
, const char *cmdline
)
1295 struct device_config
*conf
;
1297 conf
= g_malloc0(sizeof(*conf
));
1299 conf
->cmdline
= cmdline
;
1300 loc_save(&conf
->loc
);
1301 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1304 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1306 struct device_config
*conf
;
1309 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1310 if (conf
->type
!= type
)
1312 loc_push_restore(&conf
->loc
);
1313 rc
= func(conf
->cmdline
);
1314 loc_pop(&conf
->loc
);
1322 static void qemu_disable_default_devices(void)
1324 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1326 qemu_opts_foreach(qemu_find_opts("device"),
1327 default_driver_check
, NULL
, NULL
);
1328 qemu_opts_foreach(qemu_find_opts("global"),
1329 default_driver_check
, NULL
, NULL
);
1331 if (!vga_model
&& !default_vga
) {
1332 vga_interface_type
= VGA_DEVICE
;
1334 if (!has_defaults
|| machine_class
->no_serial
) {
1337 if (!has_defaults
|| machine_class
->no_parallel
) {
1338 default_parallel
= 0;
1340 if (!has_defaults
|| machine_class
->no_floppy
) {
1343 if (!has_defaults
|| machine_class
->no_cdrom
) {
1346 if (!has_defaults
|| machine_class
->no_sdcard
) {
1349 if (!has_defaults
) {
1350 default_monitor
= 0;
1356 static void qemu_create_default_devices(void)
1358 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1360 if (is_daemonized()) {
1361 /* According to documentation and historically, -nographic redirects
1362 * serial port, parallel port and monitor to stdio, which does not work
1363 * with -daemonize. We can redirect these to null instead, but since
1364 * -nographic is legacy, let's just error out.
1365 * We disallow -nographic only if all other ports are not redirected
1366 * explicitly, to not break existing legacy setups which uses
1367 * -nographic _and_ redirects all ports explicitly - this is valid
1368 * usage, -nographic is just a no-op in this case.
1371 && (default_parallel
|| default_serial
|| default_monitor
)) {
1372 error_report("-nographic cannot be used with -daemonize");
1378 if (default_parallel
)
1379 add_device_config(DEV_PARALLEL
, "null");
1380 if (default_serial
&& default_monitor
) {
1381 add_device_config(DEV_SERIAL
, "mon:stdio");
1384 add_device_config(DEV_SERIAL
, "stdio");
1385 if (default_monitor
)
1386 monitor_parse("stdio", "readline", false);
1390 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
1391 if (default_parallel
)
1392 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
1393 if (default_monitor
)
1394 monitor_parse("vc:80Cx24C", "readline", false);
1398 QemuOptsList
*net
= qemu_find_opts("net");
1399 qemu_opts_parse(net
, "nic", true, &error_abort
);
1401 qemu_opts_parse(net
, "user", true, &error_abort
);
1405 #if defined(CONFIG_VNC)
1406 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
1410 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1411 if (!qemu_display_find_default(&dpy
)) {
1412 dpy
.type
= DISPLAY_TYPE_NONE
;
1413 #if defined(CONFIG_VNC)
1414 vnc_parse("localhost:0,to=99,id=default");
1418 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1419 dpy
.type
= DISPLAY_TYPE_NONE
;
1422 /* If no default VGA is requested, the default is "none". */
1424 vga_model
= get_default_vga_model(machine_class
);
1427 select_vgahw(machine_class
, vga_model
);
1431 static int serial_parse(const char *devname
)
1433 int index
= num_serial_hds
;
1436 if (strcmp(devname
, "none") == 0)
1438 snprintf(label
, sizeof(label
), "serial%d", index
);
1439 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1441 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1442 if (!serial_hds
[index
]) {
1443 error_report("could not connect serial device"
1444 " to character backend '%s'", devname
);
1451 Chardev
*serial_hd(int i
)
1454 if (i
< num_serial_hds
) {
1455 return serial_hds
[i
];
1460 static int parallel_parse(const char *devname
)
1462 static int index
= 0;
1465 if (strcmp(devname
, "none") == 0)
1467 if (index
== MAX_PARALLEL_PORTS
) {
1468 error_report("too many parallel ports");
1471 snprintf(label
, sizeof(label
), "parallel%d", index
);
1472 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1473 if (!parallel_hds
[index
]) {
1474 error_report("could not connect parallel device"
1475 " to character backend '%s'", devname
);
1482 static int debugcon_parse(const char *devname
)
1486 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1487 error_report("invalid character backend '%s'", devname
);
1490 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1492 error_report("already have a debugcon device");
1495 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1496 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1500 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1502 const MachineClass
*mc1
= a
, *mc2
= b
;
1505 if (mc1
->family
== NULL
) {
1506 if (mc2
->family
== NULL
) {
1507 /* Compare standalone machine types against each other; they sort
1508 * in increasing order.
1510 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1511 object_class_get_name(OBJECT_CLASS(mc2
)));
1514 /* Standalone machine types sort after families. */
1518 if (mc2
->family
== NULL
) {
1519 /* Families sort before standalone machine types. */
1523 /* Families sort between each other alphabetically increasingly. */
1524 res
= strcmp(mc1
->family
, mc2
->family
);
1529 /* Within the same family, machine types sort in decreasing order. */
1530 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1531 object_class_get_name(OBJECT_CLASS(mc1
)));
1534 static MachineClass
*machine_parse(const char *name
, GSList
*machines
)
1539 if (is_help_option(name
)) {
1540 printf("Supported machines are:\n");
1541 machines
= g_slist_sort(machines
, machine_class_cmp
);
1542 for (el
= machines
; el
; el
= el
->next
) {
1543 MachineClass
*mc
= el
->data
;
1545 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1547 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1548 mc
->is_default
? " (default)" : "",
1549 mc
->deprecation_reason
? " (deprecated)" : "");
1554 mc
= find_machine(name
, machines
);
1556 error_report("unsupported machine type");
1557 error_printf("Use -machine help to list supported machines\n");
1563 static const char *pid_file
;
1564 static Notifier qemu_unlink_pidfile_notifier
;
1566 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1573 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1574 const char **poptarg
, int *poptind
)
1576 const QEMUOption
*popt
;
1577 int optind
= *poptind
;
1578 char *r
= argv
[optind
];
1581 loc_set_cmdline(argv
, optind
, 1);
1583 /* Treat --foo the same as -foo. */
1586 popt
= qemu_options
;
1589 error_report("invalid option");
1592 if (!strcmp(popt
->name
, r
+ 1))
1596 if (popt
->flags
& HAS_ARG
) {
1597 if (optind
>= argc
) {
1598 error_report("requires an argument");
1601 optarg
= argv
[optind
++];
1602 loc_set_cmdline(argv
, optind
- 2, 2);
1613 static MachineClass
*select_machine(void)
1615 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
1616 MachineClass
*machine_class
= find_default_machine(machines
);
1621 loc_push_none(&loc
);
1623 opts
= qemu_get_machine_opts();
1624 qemu_opts_loc_restore(opts
);
1626 optarg
= qemu_opt_get(opts
, "type");
1628 machine_class
= machine_parse(optarg
, machines
);
1631 if (!machine_class
) {
1632 error_report("No machine specified, and there is no default");
1633 error_printf("Use -machine help to list supported machines\n");
1638 g_slist_free(machines
);
1639 return machine_class
;
1642 static int object_parse_property_opt(Object
*obj
,
1643 const char *name
, const char *value
,
1644 const char *skip
, Error
**errp
)
1646 if (g_str_equal(name
, skip
)) {
1650 if (!object_property_parse(obj
, name
, value
, errp
)) {
1657 static int machine_set_property(void *opaque
,
1658 const char *name
, const char *value
,
1661 g_autofree
char *qom_name
= g_strdup(name
);
1664 for (p
= qom_name
; *p
; p
++) {
1670 /* Legacy options do not correspond to MachineState properties. */
1671 if (g_str_equal(qom_name
, "accel")) {
1674 if (g_str_equal(qom_name
, "igd-passthru")) {
1675 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name
, value
,
1679 if (g_str_equal(qom_name
, "kvm-shadow-mem")) {
1680 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name
, value
,
1684 if (g_str_equal(qom_name
, "kernel-irqchip")) {
1685 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name
, value
,
1687 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name
, value
,
1692 return object_parse_property_opt(opaque
, name
, value
, "type", errp
);
1695 static void object_option_foreach_add(bool (*type_opt_predicate
)(const char *))
1697 ObjectOption
*opt
, *next
;
1699 QTAILQ_FOREACH_SAFE(opt
, &object_opts
, next
, next
) {
1700 const char *type
= ObjectType_str(opt
->opts
->qom_type
);
1701 if (type_opt_predicate(type
)) {
1702 user_creatable_add_qapi(opt
->opts
, &error_fatal
);
1703 qapi_free_ObjectOptions(opt
->opts
);
1704 QTAILQ_REMOVE(&object_opts
, opt
, next
);
1710 static void object_option_parse(const char *optarg
)
1717 if (optarg
[0] == '{') {
1718 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
1720 v
= qobject_input_visitor_new(obj
);
1723 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
1729 type
= qemu_opt_get(opts
, "qom-type");
1731 error_setg(&error_fatal
, QERR_MISSING_PARAMETER
, "qom-type");
1733 if (user_creatable_print_help(type
, opts
)) {
1737 v
= opts_visitor_new(opts
);
1740 opt
= g_new0(ObjectOption
, 1);
1741 visit_type_ObjectOptions(v
, NULL
, &opt
->opts
, &error_fatal
);
1744 QTAILQ_INSERT_TAIL(&object_opts
, opt
, next
);
1748 * Initial object creation happens before all other
1749 * QEMU data types are created. The majority of objects
1750 * can be created at this point. The rng-egd object
1751 * cannot be created here, as it depends on the chardev
1754 static bool object_create_early(const char *type
)
1757 * Objects should not be made "delayed" without a reason. If you
1758 * add one, state the reason in a comment!
1761 /* Reason: rng-egd property "chardev" */
1762 if (g_str_equal(type
, "rng-egd")) {
1766 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1767 /* Reason: cryptodev-vhost-user property "chardev" */
1768 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1773 /* Reason: vhost-user-blk-server property "node-name" */
1774 if (g_str_equal(type
, "vhost-user-blk-server")) {
1778 * Reason: filter-* property "netdev" etc.
1780 if (g_str_equal(type
, "filter-buffer") ||
1781 g_str_equal(type
, "filter-dump") ||
1782 g_str_equal(type
, "filter-mirror") ||
1783 g_str_equal(type
, "filter-redirector") ||
1784 g_str_equal(type
, "colo-compare") ||
1785 g_str_equal(type
, "filter-rewriter") ||
1786 g_str_equal(type
, "filter-replay")) {
1791 * Allocation of large amounts of memory may delay
1792 * chardev initialization for too long, and trigger timeouts
1793 * on software that waits for a monitor socket to be created
1796 if (g_str_has_prefix(type
, "memory-backend-")) {
1803 static void qemu_apply_machine_options(void)
1805 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1806 QemuOpts
*machine_opts
= qemu_get_machine_opts();
1807 const char *boot_order
= NULL
;
1808 const char *boot_once
= NULL
;
1811 qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
1813 current_machine
->ram_size
= ram_size
;
1814 current_machine
->maxram_size
= maxram_size
;
1815 current_machine
->ram_slots
= ram_slots
;
1817 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
1819 boot_order
= qemu_opt_get(opts
, "order");
1821 validate_bootdevices(boot_order
, &error_fatal
);
1824 boot_once
= qemu_opt_get(opts
, "once");
1826 validate_bootdevices(boot_once
, &error_fatal
);
1829 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
1830 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
1834 boot_order
= machine_class
->default_boot_order
;
1837 current_machine
->boot_order
= boot_order
;
1838 current_machine
->boot_once
= boot_once
;
1840 if (semihosting_enabled() && !semihosting_get_argc()) {
1841 const char *kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
1842 const char *kernel_cmdline
= qemu_opt_get(machine_opts
, "append") ?: "";
1843 /* fall back to the -kernel/-append */
1844 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
1848 static void qemu_create_early_backends(void)
1850 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1852 if ((alt_grab
|| ctrl_grab
) && dpy
.type
!= DISPLAY_TYPE_SDL
) {
1853 error_report("-alt-grab and -ctrl-grab are only valid "
1854 "for SDL, ignoring option");
1856 if (dpy
.has_window_close
&&
1857 (dpy
.type
!= DISPLAY_TYPE_GTK
&& dpy
.type
!= DISPLAY_TYPE_SDL
)) {
1858 error_report("-no-quit is only valid for GTK and SDL, "
1862 qemu_display_early_init(&dpy
);
1863 qemu_console_early_init();
1865 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1866 #if defined(CONFIG_OPENGL)
1867 error_report("OpenGL is not supported by the display");
1869 error_report("OpenGL support is disabled");
1874 object_option_foreach_add(object_create_early
);
1876 /* spice needs the timers to be initialized by this point */
1877 /* spice must initialize before audio as it changes the default auiodev */
1878 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1881 qemu_opts_foreach(qemu_find_opts("chardev"),
1882 chardev_init_func
, NULL
, &error_fatal
);
1884 #ifdef CONFIG_VIRTFS
1885 qemu_opts_foreach(qemu_find_opts("fsdev"),
1886 fsdev_init_func
, NULL
, &error_fatal
);
1890 * Note: we need to create audio and block backends before
1891 * machine_set_property(), so machine properties can refer to
1894 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
1895 audio_init_audiodevs();
1900 * The remainder of object creation happens after the
1901 * creation of chardev, fsdev, net clients and device data types.
1903 static bool object_create_late(const char *type
)
1905 return !object_create_early(type
);
1908 static void qemu_create_late_backends(void)
1911 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
1914 net_init_clients(&error_fatal
);
1916 object_option_foreach_add(object_create_late
);
1918 if (tpm_init() < 0) {
1922 qemu_opts_foreach(qemu_find_opts("mon"),
1923 mon_init_func
, NULL
, &error_fatal
);
1925 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
1927 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
1929 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
1932 /* now chardevs have been created we may have semihosting to connect */
1933 qemu_semihosting_connect_chardevs();
1934 qemu_semihosting_console_init();
1937 static bool have_custom_ram_size(void)
1939 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
1940 return !!qemu_opt_get_size(opts
, "size", 0);
1943 static void qemu_resolve_machine_memdev(void)
1945 if (current_machine
->ram_memdev_id
) {
1947 ram_addr_t backend_size
;
1949 backend
= object_resolve_path_type(current_machine
->ram_memdev_id
,
1950 TYPE_MEMORY_BACKEND
, NULL
);
1952 error_report("Memory backend '%s' not found",
1953 current_machine
->ram_memdev_id
);
1956 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
1957 if (have_custom_ram_size() && backend_size
!= ram_size
) {
1958 error_report("Size specified by -m option must match size of "
1959 "explicitly specified 'memory-backend' property");
1963 error_report("'-mem-path' can't be used together with"
1964 "'-machine memory-backend'");
1967 ram_size
= backend_size
;
1970 if (!xen_enabled()) {
1971 /* On 32-bit hosts, QEMU is limited by virtual address space */
1972 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
1973 error_report("at most 2047 MB RAM can be simulated");
1979 static void set_memory_options(MachineClass
*mc
)
1982 const char *mem_str
;
1983 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
1984 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
1987 loc_push_none(&loc
);
1988 qemu_opts_loc_restore(opts
);
1991 mem_str
= qemu_opt_get(opts
, "size");
1994 error_report("missing 'size' option value");
1998 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2000 /* Fix up legacy suffix-less format */
2001 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2002 uint64_t overflow_check
= sz
;
2005 if (sz
/ MiB
!= overflow_check
) {
2006 error_report("too large 'size' option value");
2012 /* backward compatibility behaviour for case "-m 0" */
2014 sz
= default_ram_size
;
2017 sz
= QEMU_ALIGN_UP(sz
, 8192);
2018 if (mc
->fixup_ram_size
) {
2019 sz
= mc
->fixup_ram_size(sz
);
2022 if (ram_size
!= sz
) {
2023 error_report("ram size too large");
2027 /* store value for the future use */
2028 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2029 maxram_size
= ram_size
;
2031 if (qemu_opt_get(opts
, "maxmem")) {
2034 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2035 slots
= qemu_opt_get_number(opts
, "slots", 0);
2036 if (sz
< ram_size
) {
2037 error_report("invalid value of -m option maxmem: "
2038 "maximum memory size (0x%" PRIx64
") must be at least "
2039 "the initial memory size (0x" RAM_ADDR_FMT
")",
2042 } else if (slots
&& sz
== ram_size
) {
2043 error_report("invalid value of -m option maxmem: "
2044 "memory slots were specified but maximum memory size "
2045 "(0x%" PRIx64
") is equal to the initial memory size "
2046 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2052 } else if (qemu_opt_get(opts
, "slots")) {
2053 error_report("invalid -m option value: missing 'maxmem' option");
2060 static void qemu_create_machine(MachineClass
*machine_class
)
2062 object_set_machine_compat_props(machine_class
->compat_props
);
2064 set_memory_options(machine_class
);
2066 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2067 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
2070 object_property_add_child(object_get_root(), "machine",
2071 OBJECT(current_machine
));
2072 object_property_add_child(container_get(OBJECT(current_machine
),
2074 "sysbus", OBJECT(sysbus_get_default()));
2076 if (machine_class
->minimum_page_bits
) {
2077 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2078 /* This would be a board error: specifying a minimum smaller than
2079 * a target's compile-time fixed setting.
2081 g_assert_not_reached();
2085 cpu_exec_init_all();
2088 if (machine_class
->hw_version
) {
2089 qemu_set_hw_version(machine_class
->hw_version
);
2092 machine_smp_parse(current_machine
,
2093 qemu_opts_find(qemu_find_opts("smp-opts"), NULL
), &error_fatal
);
2096 * Get the default machine options from the machine if it is not already
2097 * specified either by the configuration file or by the command line.
2099 if (machine_class
->default_machine_opts
) {
2100 qemu_opts_set_defaults(qemu_find_opts("machine"),
2101 machine_class
->default_machine_opts
, 0);
2105 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2109 g
= g_malloc0(sizeof(*g
));
2110 g
->driver
= qemu_opt_get(opts
, "driver");
2111 g
->property
= qemu_opt_get(opts
, "property");
2112 g
->value
= qemu_opt_get(opts
, "value");
2113 qdev_prop_register_global(g
);
2117 static void qemu_read_default_config_file(Error
**errp
)
2121 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2123 ret
= qemu_read_config_file(file
, errp
);
2125 if (ret
== -ENOENT
) {
2132 static int qemu_set_option(const char *str
)
2134 Error
*local_err
= NULL
;
2135 char group
[64], id
[64], arg
[64];
2140 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2141 if (rc
< 3 || str
[offset
] != '=') {
2142 error_report("can't parse: \"%s\"", str
);
2146 list
= qemu_find_opts(group
);
2151 opts
= qemu_opts_find(list
, id
);
2153 error_report("there is no %s \"%s\" defined",
2158 if (!qemu_opt_set(opts
, arg
, str
+ offset
+ 1, &local_err
)) {
2159 error_report_err(local_err
);
2165 static void user_register_global_props(void)
2167 qemu_opts_foreach(qemu_find_opts("global"),
2168 global_init_func
, NULL
, NULL
);
2171 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2173 icount_configure(opts
, errp
);
2177 static int accelerator_set_property(void *opaque
,
2178 const char *name
, const char *value
,
2181 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2184 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2186 bool *p_init_failed
= opaque
;
2187 const char *acc
= qemu_opt_get(opts
, "accel");
2188 AccelClass
*ac
= accel_find(acc
);
2191 bool qtest_with_kvm
;
2193 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2196 *p_init_failed
= true;
2197 if (!qtest_with_kvm
) {
2198 error_report("invalid accelerator %s", acc
);
2202 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2203 object_apply_compat_props(OBJECT(accel
));
2204 qemu_opt_foreach(opts
, accelerator_set_property
,
2208 ret
= accel_init_machine(accel
, current_machine
);
2210 *p_init_failed
= true;
2211 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2212 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2220 static void configure_accelerators(const char *progname
)
2222 const char *accelerators
;
2223 bool init_failed
= false;
2225 qemu_opts_foreach(qemu_find_opts("icount"),
2226 do_configure_icount
, NULL
, &error_fatal
);
2228 accelerators
= qemu_opt_get(qemu_get_machine_opts(), "accel");
2229 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2230 char **accel_list
, **tmp
;
2232 if (accelerators
== NULL
) {
2233 /* Select the default accelerator */
2234 bool have_tcg
= accel_find("tcg");
2235 bool have_kvm
= accel_find("kvm");
2237 if (have_tcg
&& have_kvm
) {
2238 if (g_str_has_suffix(progname
, "kvm")) {
2239 /* If the program name ends with "kvm", we prefer KVM */
2240 accelerators
= "kvm:tcg";
2242 accelerators
= "tcg:kvm";
2244 } else if (have_kvm
) {
2245 accelerators
= "kvm";
2246 } else if (have_tcg
) {
2247 accelerators
= "tcg";
2249 error_report("No accelerator selected and"
2250 " no default accelerator available");
2254 accel_list
= g_strsplit(accelerators
, ":", 0);
2256 for (tmp
= accel_list
; *tmp
; tmp
++) {
2258 * Filter invalid accelerators here, to prevent obscenities
2259 * such as "-machine accel=tcg,,thread=single".
2261 if (accel_find(*tmp
)) {
2262 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2265 error_report("invalid accelerator %s", *tmp
);
2268 g_strfreev(accel_list
);
2270 if (accelerators
!= NULL
) {
2271 error_report("The -accel and \"-machine accel=\" options are incompatible");
2276 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2277 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2279 error_report("no accelerator found");
2284 if (init_failed
&& !qtest_chrdev
) {
2285 AccelClass
*ac
= ACCEL_GET_CLASS(current_accel());
2286 error_report("falling back to %s", ac
->name
);
2289 if (icount_enabled() && !tcg_enabled()) {
2290 error_report("-icount is not allowed with hardware virtualization");
2295 static void create_default_memdev(MachineState
*ms
, const char *path
)
2298 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
2300 obj
= object_new(path
? TYPE_MEMORY_BACKEND_FILE
: TYPE_MEMORY_BACKEND_RAM
);
2302 object_property_set_str(obj
, "mem-path", path
, &error_fatal
);
2304 object_property_set_int(obj
, "size", ms
->ram_size
, &error_fatal
);
2305 object_property_add_child(object_get_objects_root(), mc
->default_ram_id
,
2307 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2308 object_property_set_bool(obj
, "x-use-canonical-path-for-ramblock-id",
2309 false, &error_fatal
);
2310 user_creatable_complete(USER_CREATABLE(obj
), &error_fatal
);
2312 object_property_set_str(OBJECT(ms
), "memory-backend", mc
->default_ram_id
,
2316 static void qemu_validate_options(void)
2318 QemuOpts
*machine_opts
= qemu_get_machine_opts();
2319 const char *kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
2320 const char *initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
2321 const char *kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
2323 if (kernel_filename
== NULL
) {
2324 if (kernel_cmdline
!= NULL
) {
2325 error_report("-append only allowed with -kernel option");
2329 if (initrd_filename
!= NULL
) {
2330 error_report("-initrd only allowed with -kernel option");
2335 if (loadvm
&& preconfig_requested
) {
2336 error_report("'preconfig' and 'loadvm' options are "
2337 "mutually exclusive");
2340 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2341 error_report("'preconfig' supports '-incoming defer' only");
2345 #ifdef CONFIG_CURSES
2346 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2347 error_report("curses display cannot be used with -daemonize");
2353 static void qemu_process_sugar_options(void)
2358 val
= g_strdup_printf("%d",
2359 (uint32_t) qemu_opt_get_number(qemu_find_opts_singleton("smp-opts"), "cpus", 1));
2360 object_register_sugar_prop("memory-backend", "prealloc-threads", val
,
2363 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2367 int i
= select_watchdog(watchdog
);
2369 exit (i
== 1 ? 1 : 0);
2373 /* -action processing */
2376 * Process all the -action parameters parsed from cmdline.
2378 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2380 Error
*local_err
= NULL
;
2381 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2382 QObject
*ret
= NULL
;
2383 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2385 qobject_unref(qdict
);
2387 error_propagate(errp
, local_err
);
2393 static void qemu_process_early_options(void)
2395 #ifdef CONFIG_SECCOMP
2396 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2398 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2402 qemu_opts_foreach(qemu_find_opts("name"),
2403 parse_name
, NULL
, &error_fatal
);
2405 if (qemu_opts_foreach(qemu_find_opts("action"),
2406 process_runstate_actions
, NULL
, &error_fatal
)) {
2411 qemu_opts_foreach(qemu_find_opts("add-fd"),
2412 parse_add_fd
, NULL
, &error_fatal
);
2414 qemu_opts_foreach(qemu_find_opts("add-fd"),
2415 cleanup_add_fd
, NULL
, &error_fatal
);
2418 /* Open the logfile at this point and set the log mask if necessary. */
2420 qemu_set_log_filename(log_file
, &error_fatal
);
2424 mask
= qemu_str_to_log_mask(log_mask
);
2426 qemu_print_log_usage(stdout
);
2434 qemu_add_default_firmwarepath();
2437 static void qemu_process_help_options(void)
2440 * Check for -cpu help and -device help before we call select_machine(),
2441 * which will return an error if the architecture has no default machine
2442 * type and the user did not specify one, so that the user doesn't need
2443 * to say '-cpu help -machine something'.
2445 if (cpu_option
&& is_help_option(cpu_option
)) {
2446 list_cpus(cpu_option
);
2450 if (qemu_opts_foreach(qemu_find_opts("device"),
2451 device_help_func
, NULL
, NULL
)) {
2455 /* -L help lists the data directories and exits. */
2456 if (list_data_dirs
) {
2457 qemu_list_data_dirs();
2462 static void qemu_maybe_daemonize(const char *pid_file
)
2467 rcu_disable_atfork();
2469 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
2470 error_reportf_err(err
, "cannot create PID file: ");
2474 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
2475 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
2478 static void qemu_init_displays(void)
2482 /* init local displays */
2483 ds
= init_displaystate();
2484 qemu_display_init(ds
, &dpy
);
2486 /* must be after terminal init, SDL library changes signal handlers */
2487 os_setup_signal_handling();
2489 /* init remote displays */
2491 qemu_opts_foreach(qemu_find_opts("vnc"),
2492 vnc_init_func
, NULL
, &error_fatal
);
2496 qemu_spice
.display_init();
2500 static void qemu_init_board(void)
2502 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
2504 if (machine_class
->default_ram_id
&& current_machine
->ram_size
&&
2505 numa_uses_legacy_mem() && !current_machine
->ram_memdev_id
) {
2506 create_default_memdev(current_machine
, mem_path
);
2509 /* process plugin before CPUs are created, but once -smp has been parsed */
2510 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2512 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2513 machine_run_board_init(current_machine
);
2515 drive_check_orphaned();
2519 if (hax_enabled()) {
2520 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2525 static void qemu_create_cli_devices(void)
2529 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2530 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2532 /* init USB devices */
2533 if (machine_usb(current_machine
)) {
2534 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2538 /* init generic devices */
2539 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2540 qemu_opts_foreach(qemu_find_opts("device"),
2541 device_init_func
, NULL
, &error_fatal
);
2542 rom_reset_order_override();
2545 static void qemu_machine_creation_done(void)
2547 MachineState
*machine
= MACHINE(qdev_get_machine());
2549 /* Did we create any drives that we failed to create a device for? */
2550 drive_check_orphaned();
2552 /* Don't warn about the default network setup that you get if
2553 * no command line -net or -netdev options are specified. There
2554 * are two cases that we would otherwise complain about:
2555 * (1) board doesn't support a NIC but the implicit "-net nic"
2557 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2558 * sets up a nic that isn't connected to anything.
2560 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2561 net_check_clients();
2564 qdev_prop_check_globals();
2566 qdev_machine_creation_done();
2570 * Verify that Confidential Guest Support has actually been initialized
2572 assert(machine
->cgs
->ready
);
2575 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2580 void qmp_x_exit_preconfig(Error
**errp
)
2582 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2583 error_setg(errp
, "The command is permitted only before machine initialization");
2588 qemu_create_cli_devices();
2589 qemu_machine_creation_done();
2592 Error
*local_err
= NULL
;
2593 if (!load_snapshot(loadvm
, NULL
, false, NULL
, &local_err
)) {
2594 error_report_err(local_err
);
2599 if (replay_mode
!= REPLAY_MODE_NONE
) {
2600 replay_vmstate_init();
2604 Error
*local_err
= NULL
;
2605 if (strcmp(incoming
, "defer") != 0) {
2606 qmp_migrate_incoming(incoming
, &local_err
);
2608 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2612 } else if (autostart
) {
2617 void qemu_init(int argc
, char **argv
, char **envp
)
2620 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2621 QemuOptsList
*olist
;
2624 MachineClass
*machine_class
;
2625 bool userconfig
= true;
2626 FILE *vmstate_dump_file
= NULL
;
2628 qemu_add_opts(&qemu_drive_opts
);
2629 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2630 qemu_add_drive_opts(&qemu_common_drive_opts
);
2631 qemu_add_drive_opts(&qemu_drive_opts
);
2632 qemu_add_drive_opts(&bdrv_runtime_opts
);
2633 qemu_add_opts(&qemu_chardev_opts
);
2634 qemu_add_opts(&qemu_device_opts
);
2635 qemu_add_opts(&qemu_netdev_opts
);
2636 qemu_add_opts(&qemu_nic_opts
);
2637 qemu_add_opts(&qemu_net_opts
);
2638 qemu_add_opts(&qemu_rtc_opts
);
2639 qemu_add_opts(&qemu_global_opts
);
2640 qemu_add_opts(&qemu_mon_opts
);
2641 qemu_add_opts(&qemu_trace_opts
);
2642 qemu_plugin_add_opts();
2643 qemu_add_opts(&qemu_option_rom_opts
);
2644 qemu_add_opts(&qemu_machine_opts
);
2645 qemu_add_opts(&qemu_accel_opts
);
2646 qemu_add_opts(&qemu_mem_opts
);
2647 qemu_add_opts(&qemu_smp_opts
);
2648 qemu_add_opts(&qemu_boot_opts
);
2649 qemu_add_opts(&qemu_add_fd_opts
);
2650 qemu_add_opts(&qemu_object_opts
);
2651 qemu_add_opts(&qemu_tpmdev_opts
);
2652 qemu_add_opts(&qemu_overcommit_opts
);
2653 qemu_add_opts(&qemu_msg_opts
);
2654 qemu_add_opts(&qemu_name_opts
);
2655 qemu_add_opts(&qemu_numa_opts
);
2656 qemu_add_opts(&qemu_icount_opts
);
2657 qemu_add_opts(&qemu_semihosting_config_opts
);
2658 qemu_add_opts(&qemu_fw_cfg_opts
);
2659 qemu_add_opts(&qemu_action_opts
);
2660 module_call_init(MODULE_INIT_OPTS
);
2662 error_init(argv
[0]);
2663 qemu_init_exec_dir(argv
[0]);
2665 qemu_init_subsystems();
2667 /* first pass of option parsing */
2669 while (optind
< argc
) {
2670 if (argv
[optind
][0] != '-') {
2674 const QEMUOption
*popt
;
2676 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2677 switch (popt
->index
) {
2678 case QEMU_OPTION_nouserconfig
:
2686 qemu_read_default_config_file(&error_fatal
);
2689 /* second pass of option parsing */
2694 if (argv
[optind
][0] != '-') {
2695 loc_set_cmdline(argv
, optind
, 1);
2696 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2698 const QEMUOption
*popt
;
2700 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2701 if (!(popt
->arch_mask
& arch_type
)) {
2702 error_report("Option not supported for this target");
2705 switch(popt
->index
) {
2706 case QEMU_OPTION_cpu
:
2707 /* hw initialization will check this */
2708 cpu_option
= optarg
;
2710 case QEMU_OPTION_hda
:
2711 case QEMU_OPTION_hdb
:
2712 case QEMU_OPTION_hdc
:
2713 case QEMU_OPTION_hdd
:
2714 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2717 case QEMU_OPTION_blockdev
:
2720 BlockdevOptionsQueueEntry
*bdo
;
2722 v
= qobject_input_visitor_new_str(optarg
, "driver",
2725 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2726 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2729 loc_save(&bdo
->loc
);
2730 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2733 case QEMU_OPTION_drive
:
2734 if (drive_def(optarg
) == NULL
) {
2738 case QEMU_OPTION_set
:
2739 if (qemu_set_option(optarg
) != 0)
2742 case QEMU_OPTION_global
:
2743 if (qemu_global_option(optarg
) != 0)
2746 case QEMU_OPTION_mtdblock
:
2747 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2749 case QEMU_OPTION_sd
:
2750 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2752 case QEMU_OPTION_pflash
:
2753 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2755 case QEMU_OPTION_snapshot
:
2757 Error
*blocker
= NULL
;
2759 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
2761 replay_add_blocker(blocker
);
2764 case QEMU_OPTION_numa
:
2765 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2771 case QEMU_OPTION_display
:
2772 parse_display(optarg
);
2774 case QEMU_OPTION_nographic
:
2775 olist
= qemu_find_opts("machine");
2776 qemu_opts_parse_noisily(olist
, "graphics=off", false);
2778 dpy
.type
= DISPLAY_TYPE_NONE
;
2780 case QEMU_OPTION_curses
:
2781 #ifdef CONFIG_CURSES
2782 dpy
.type
= DISPLAY_TYPE_CURSES
;
2784 error_report("curses or iconv support is disabled");
2788 case QEMU_OPTION_portrait
:
2789 graphic_rotate
= 90;
2791 case QEMU_OPTION_rotate
:
2792 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2793 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2794 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2795 error_report("only 90, 180, 270 deg rotation is available");
2799 case QEMU_OPTION_kernel
:
2800 qemu_opts_set(qemu_find_opts("machine"), "kernel", optarg
, &error_abort
);
2802 case QEMU_OPTION_initrd
:
2803 qemu_opts_set(qemu_find_opts("machine"), "initrd", optarg
, &error_abort
);
2805 case QEMU_OPTION_append
:
2806 qemu_opts_set(qemu_find_opts("machine"), "append", optarg
, &error_abort
);
2808 case QEMU_OPTION_dtb
:
2809 qemu_opts_set(qemu_find_opts("machine"), "dtb", optarg
, &error_abort
);
2811 case QEMU_OPTION_cdrom
:
2812 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2814 case QEMU_OPTION_boot
:
2815 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2821 case QEMU_OPTION_fda
:
2822 case QEMU_OPTION_fdb
:
2823 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2826 case QEMU_OPTION_no_fd_bootchk
:
2829 case QEMU_OPTION_netdev
:
2831 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2835 case QEMU_OPTION_nic
:
2837 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
2841 case QEMU_OPTION_net
:
2843 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2847 #ifdef CONFIG_LIBISCSI
2848 case QEMU_OPTION_iscsi
:
2849 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
2856 case QEMU_OPTION_audio_help
:
2857 audio_legacy_help();
2860 case QEMU_OPTION_audiodev
:
2861 audio_parse_option(optarg
);
2863 case QEMU_OPTION_soundhw
:
2864 select_soundhw (optarg
);
2869 case QEMU_OPTION_version
:
2874 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
2881 case QEMU_OPTION_tpmdev
:
2882 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
2887 case QEMU_OPTION_mempath
:
2890 case QEMU_OPTION_mem_prealloc
:
2899 case QEMU_OPTION_DFILTER
:
2900 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
2902 case QEMU_OPTION_seed
:
2903 qemu_guest_random_seed_main(optarg
, &error_fatal
);
2906 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
2908 case QEMU_OPTION_gdb
:
2909 add_device_config(DEV_GDB
, optarg
);
2912 if (is_help_option(optarg
)) {
2913 list_data_dirs
= true;
2915 qemu_add_data_dir(g_strdup(optarg
));
2918 case QEMU_OPTION_bios
:
2919 qemu_opts_set(qemu_find_opts("machine"), "firmware", optarg
, &error_abort
);
2921 case QEMU_OPTION_singlestep
:
2928 keyboard_layout
= optarg
;
2930 case QEMU_OPTION_vga
:
2939 w
= strtol(p
, (char **)&p
, 10);
2942 error_report("invalid resolution or depth");
2948 h
= strtol(p
, (char **)&p
, 10);
2953 depth
= strtol(p
, (char **)&p
, 10);
2954 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
2955 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2956 depth
!= 24 && depth
!= 32)
2958 } else if (*p
== '\0') {
2959 depth
= graphic_depth
;
2966 graphic_depth
= depth
;
2969 case QEMU_OPTION_echr
:
2972 term_escape_char
= strtol(optarg
, &r
, 0);
2974 printf("Bad argument to echr\n");
2977 case QEMU_OPTION_monitor
:
2978 default_monitor
= 0;
2979 if (strncmp(optarg
, "none", 4)) {
2980 monitor_parse(optarg
, "readline", false);
2983 case QEMU_OPTION_qmp
:
2984 monitor_parse(optarg
, "control", false);
2985 default_monitor
= 0;
2987 case QEMU_OPTION_qmp_pretty
:
2988 monitor_parse(optarg
, "control", true);
2989 default_monitor
= 0;
2991 case QEMU_OPTION_mon
:
2992 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
2997 default_monitor
= 0;
2999 case QEMU_OPTION_chardev
:
3000 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3006 case QEMU_OPTION_fsdev
:
3007 olist
= qemu_find_opts("fsdev");
3009 error_report("fsdev support is disabled");
3012 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3017 case QEMU_OPTION_virtfs
: {
3020 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3023 olist
= qemu_find_opts("virtfs");
3025 error_report("virtfs support is disabled");
3028 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3033 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3034 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3035 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3038 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3039 qemu_opts_id(opts
) ?:
3040 qemu_opt_get(opts
, "mount_tag"),
3043 error_report("duplicate or invalid fsdev id: %s",
3044 qemu_opt_get(opts
, "mount_tag"));
3048 writeout
= qemu_opt_get(opts
, "writeout");
3050 #ifdef CONFIG_SYNC_FILE_RANGE
3051 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3053 error_report("writeout=immediate not supported "
3054 "on this platform");
3058 qemu_opt_set(fsdev
, "fsdriver",
3059 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3060 path
= qemu_opt_get(opts
, "path");
3062 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3064 security_model
= qemu_opt_get(opts
, "security_model");
3065 if (security_model
) {
3066 qemu_opt_set(fsdev
, "security_model", security_model
,
3069 socket
= qemu_opt_get(opts
, "socket");
3071 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3073 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3075 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3078 qemu_opt_set_bool(fsdev
, "readonly",
3079 qemu_opt_get_bool(opts
, "readonly", 0),
3081 multidevs
= qemu_opt_get(opts
, "multidevs");
3083 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3085 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3087 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3088 qemu_opt_set(device
, "fsdev",
3089 qemu_opts_id(fsdev
), &error_abort
);
3090 qemu_opt_set(device
, "mount_tag",
3091 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3094 case QEMU_OPTION_serial
:
3095 add_device_config(DEV_SERIAL
, optarg
);
3097 if (strncmp(optarg
, "mon:", 4) == 0) {
3098 default_monitor
= 0;
3101 case QEMU_OPTION_watchdog
:
3103 error_report("only one watchdog option may be given");
3108 case QEMU_OPTION_action
:
3109 olist
= qemu_find_opts("action");
3110 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3114 case QEMU_OPTION_watchdog_action
:
3115 if (select_watchdog_action(optarg
) == -1) {
3116 error_report("unknown -watchdog-action parameter");
3120 case QEMU_OPTION_parallel
:
3121 add_device_config(DEV_PARALLEL
, optarg
);
3122 default_parallel
= 0;
3123 if (strncmp(optarg
, "mon:", 4) == 0) {
3124 default_monitor
= 0;
3127 case QEMU_OPTION_debugcon
:
3128 add_device_config(DEV_DEBUGCON
, optarg
);
3130 case QEMU_OPTION_loadvm
:
3133 case QEMU_OPTION_full_screen
:
3134 dpy
.has_full_screen
= true;
3135 dpy
.full_screen
= true;
3137 case QEMU_OPTION_alt_grab
:
3140 case QEMU_OPTION_ctrl_grab
:
3143 case QEMU_OPTION_no_quit
:
3144 dpy
.has_window_close
= true;
3145 dpy
.window_close
= false;
3147 case QEMU_OPTION_sdl
:
3149 dpy
.type
= DISPLAY_TYPE_SDL
;
3152 error_report("SDL support is disabled");
3155 case QEMU_OPTION_pidfile
:
3158 case QEMU_OPTION_win2k_hack
:
3159 win2k_install_hack
= 1;
3161 case QEMU_OPTION_acpitable
:
3162 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3167 acpi_table_add(opts
, &error_fatal
);
3169 case QEMU_OPTION_smbios
:
3170 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3175 smbios_entry_add(opts
, &error_fatal
);
3177 case QEMU_OPTION_fwcfg
:
3178 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3184 case QEMU_OPTION_preconfig
:
3185 preconfig_requested
= true;
3187 case QEMU_OPTION_enable_kvm
:
3188 olist
= qemu_find_opts("machine");
3189 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3192 case QEMU_OPTION_machine
:
3193 olist
= qemu_find_opts("machine");
3194 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3199 case QEMU_OPTION_accel
:
3200 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3202 optarg
= qemu_opt_get(accel_opts
, "accel");
3203 if (!optarg
|| is_help_option(optarg
)) {
3204 printf("Accelerators supported in QEMU binary:\n");
3205 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3207 for (el
= accel_list
; el
; el
= el
->next
) {
3208 gchar
*typename
= g_strdup(object_class_get_name(
3209 OBJECT_CLASS(el
->data
)));
3210 /* omit qtest which is used for tests only */
3211 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3212 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3213 gchar
**optname
= g_strsplit(typename
,
3214 ACCEL_CLASS_SUFFIX
, 0);
3215 printf("%s\n", optname
[0]);
3216 g_strfreev(optname
);
3220 g_slist_free(accel_list
);
3224 case QEMU_OPTION_usb
:
3225 olist
= qemu_find_opts("machine");
3226 qemu_opts_parse_noisily(olist
, "usb=on", false);
3228 case QEMU_OPTION_usbdevice
:
3229 olist
= qemu_find_opts("machine");
3230 qemu_opts_parse_noisily(olist
, "usb=on", false);
3231 add_device_config(DEV_USB
, optarg
);
3233 case QEMU_OPTION_device
:
3234 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3239 case QEMU_OPTION_smp
:
3240 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3245 case QEMU_OPTION_vnc
:
3248 case QEMU_OPTION_no_acpi
:
3249 olist
= qemu_find_opts("machine");
3250 qemu_opts_parse_noisily(olist
, "acpi=off", false);
3252 case QEMU_OPTION_no_hpet
:
3253 olist
= qemu_find_opts("machine");
3254 qemu_opts_parse_noisily(olist
, "hpet=off", false);
3256 case QEMU_OPTION_no_reboot
:
3257 olist
= qemu_find_opts("action");
3258 qemu_opts_parse_noisily(olist
, "reboot=shutdown", false);
3260 case QEMU_OPTION_no_shutdown
:
3261 olist
= qemu_find_opts("action");
3262 qemu_opts_parse_noisily(olist
, "shutdown=pause", false);
3264 case QEMU_OPTION_uuid
:
3265 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3266 error_report("failed to parse UUID string: wrong format");
3269 qemu_uuid_set
= true;
3271 case QEMU_OPTION_option_rom
:
3272 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3273 error_report("too many option ROMs");
3276 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3281 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3282 option_rom
[nb_option_roms
].bootindex
=
3283 qemu_opt_get_number(opts
, "bootindex", -1);
3284 if (!option_rom
[nb_option_roms
].name
) {
3285 error_report("Option ROM file is not specified");
3290 case QEMU_OPTION_semihosting
:
3291 qemu_semihosting_enable();
3293 case QEMU_OPTION_semihosting_config
:
3294 if (qemu_semihosting_config_options(optarg
) != 0) {
3298 case QEMU_OPTION_name
:
3299 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3304 /* Capture guest name if -msg guest-name is used later */
3305 error_guest_name
= qemu_opt_get(opts
, "guest");
3307 case QEMU_OPTION_prom_env
:
3308 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3309 error_report("too many prom variables");
3312 prom_envs
[nb_prom_envs
] = optarg
;
3315 case QEMU_OPTION_old_param
:
3318 case QEMU_OPTION_rtc
:
3319 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3325 case QEMU_OPTION_icount
:
3326 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3332 case QEMU_OPTION_incoming
:
3334 runstate_set(RUN_STATE_INMIGRATE
);
3338 case QEMU_OPTION_only_migratable
:
3339 only_migratable
= 1;
3341 case QEMU_OPTION_nodefaults
:
3344 case QEMU_OPTION_xen_domid
:
3345 if (!(xen_available())) {
3346 error_report("Option not supported for this target");
3349 xen_domid
= atoi(optarg
);
3351 case QEMU_OPTION_xen_attach
:
3352 if (!(xen_available())) {
3353 error_report("Option not supported for this target");
3356 xen_mode
= XEN_ATTACH
;
3358 case QEMU_OPTION_xen_domid_restrict
:
3359 if (!(xen_available())) {
3360 error_report("Option not supported for this target");
3363 xen_domid_restrict
= true;
3365 case QEMU_OPTION_trace
:
3366 trace_opt_parse(optarg
);
3368 case QEMU_OPTION_plugin
:
3369 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3371 case QEMU_OPTION_readconfig
:
3372 qemu_read_config_file(optarg
, &error_fatal
);
3374 case QEMU_OPTION_spice
:
3375 olist
= qemu_find_opts_err("spice", NULL
);
3377 ui_module_load_one("spice-core");
3378 olist
= qemu_find_opts("spice");
3381 error_report("spice support is disabled");
3384 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3390 case QEMU_OPTION_writeconfig
:
3393 warn_report("-writeconfig is deprecated and will go away without a replacement");
3394 if (strcmp(optarg
, "-") == 0) {
3397 fp
= fopen(optarg
, "w");
3399 error_report("open %s: %s", optarg
,
3404 qemu_config_write(fp
);
3410 case QEMU_OPTION_qtest
:
3411 qtest_chrdev
= optarg
;
3413 case QEMU_OPTION_qtest_log
:
3416 case QEMU_OPTION_sandbox
:
3417 olist
= qemu_find_opts("sandbox");
3419 #ifndef CONFIG_SECCOMP
3420 error_report("-sandbox support is not enabled "
3421 "in this QEMU binary");
3426 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3431 case QEMU_OPTION_add_fd
:
3433 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3439 error_report("File descriptor passing is disabled on this "
3444 case QEMU_OPTION_object
:
3445 object_option_parse(optarg
);
3447 case QEMU_OPTION_overcommit
:
3448 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3453 enable_mlock
= qemu_opt_get_bool(opts
, "mem-lock", false);
3454 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3456 case QEMU_OPTION_compat
:
3461 v
= qobject_input_visitor_new_str(optarg
, NULL
,
3464 visit_type_CompatPolicy(v
, NULL
, &opts
, &error_fatal
);
3465 QAPI_CLONE_MEMBERS(CompatPolicy
, &compat_policy
, opts
);
3467 qapi_free_CompatPolicy(opts
);
3471 case QEMU_OPTION_msg
:
3472 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3477 configure_msg(opts
);
3479 case QEMU_OPTION_dump_vmstate
:
3480 if (vmstate_dump_file
) {
3481 error_report("only one '-dump-vmstate' "
3482 "option may be given");
3485 vmstate_dump_file
= fopen(optarg
, "w");
3486 if (vmstate_dump_file
== NULL
) {
3487 error_report("open %s: %s", optarg
, strerror(errno
));
3491 case QEMU_OPTION_enable_sync_profile
:
3494 case QEMU_OPTION_nouserconfig
:
3495 /* Nothing to be parsed here. Especially, do not error out below. */
3498 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3499 error_report("Option not supported in this build");
3506 * Clear error location left behind by the loop.
3507 * Best done right after the loop. Do not insert code here!
3511 qemu_validate_options();
3512 qemu_process_sugar_options();
3515 * These options affect everything else and should be processed
3516 * before daemonizing.
3518 qemu_process_early_options();
3520 qemu_process_help_options();
3521 qemu_maybe_daemonize(pid_file
);
3524 * The trace backend must be initialized after daemonizing.
3525 * trace_init_backends() will call st_init(), which will create the
3526 * trace thread in the parent, and also register st_flush_trace_buffer()
3527 * in atexit(). This function will force the parent to wait for the
3528 * writeout thread to finish, which will not occur, and the parent
3529 * process will be left in the host.
3531 if (!trace_init_backends()) {
3536 qemu_init_main_loop(&error_fatal
);
3539 user_register_global_props();
3540 replay_configure(icount_opts
);
3542 configure_rtc(qemu_find_opts_singleton("rtc"));
3544 qemu_create_machine(select_machine());
3548 qemu_disable_default_devices();
3549 qemu_create_default_devices();
3550 qemu_create_early_backends();
3552 qemu_apply_machine_options();
3553 phase_advance(PHASE_MACHINE_CREATED
);
3556 * Note: uses machine properties such as kernel-irqchip, must run
3557 * after machine_set_property().
3559 configure_accelerators(argv
[0]);
3560 phase_advance(PHASE_ACCEL_CREATED
);
3563 * Beware, QOM objects created before this point miss global and
3564 * compat properties.
3566 * Global properties get set up by qdev_prop_register_global(),
3567 * called from user_register_global_props(), and certain option
3568 * desugaring. Also in CPU feature desugaring (buried in
3569 * parse_cpu_option()), which happens below this point, but may
3570 * only target the CPU type, which can only be created after
3571 * parse_cpu_option() returned the type.
3573 * Machine compat properties: object_set_machine_compat_props().
3574 * Accelerator compat props: object_set_accelerator_compat_props(),
3575 * called from do_configure_accelerator().
3578 machine_class
= MACHINE_GET_CLASS(current_machine
);
3579 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
3580 error_report("Machine type '%s' is deprecated: %s",
3581 machine_class
->name
, machine_class
->deprecation_reason
);
3585 * Note: creates a QOM object, must run only after global and
3586 * compat properties have been set up.
3588 migration_object_init();
3590 qemu_create_late_backends();
3592 /* parse features once if machine provides default cpu_type */
3593 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
3595 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
3597 /* NB: for machine none cpu_type could STILL be NULL here! */
3599 qemu_resolve_machine_memdev();
3600 parse_numa_opts(current_machine
);
3602 if (vmstate_dump_file
) {
3604 dump_vmstate_json_to_file(vmstate_dump_file
);
3608 if (!preconfig_requested
) {
3609 qmp_x_exit_preconfig(&error_fatal
);
3611 qemu_init_displays();
3612 accel_setup_post(current_machine
);