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 "exec/page-vary.h"
31 #include "hw/qdev-properties.h"
32 #include "qapi/compat-policy.h"
33 #include "qapi/error.h"
34 #include "qapi/qmp/qdict.h"
35 #include "qapi/qmp/qstring.h"
36 #include "qapi/qmp/qjson.h"
37 #include "qemu-version.h"
38 #include "qemu/cutils.h"
39 #include "qemu/help_option.h"
40 #include "qemu/hw-version.h"
41 #include "qemu/uuid.h"
42 #include "sysemu/reset.h"
43 #include "sysemu/runstate.h"
44 #include "sysemu/runstate-action.h"
45 #include "sysemu/seccomp.h"
46 #include "sysemu/tcg.h"
47 #include "sysemu/xen.h"
49 #include "qemu/error-report.h"
50 #include "qemu/sockets.h"
51 #include "qemu/accel.h"
53 #include "hw/isa/isa.h"
54 #include "hw/scsi/scsi.h"
55 #include "hw/display/vga.h"
56 #include "sysemu/watchdog.h"
57 #include "hw/firmware/smbios.h"
58 #include "hw/acpi/acpi.h"
59 #include "hw/xen/xen.h"
60 #include "hw/loader.h"
61 #include "monitor/qdev.h"
63 #include "net/slirp.h"
64 #include "monitor/monitor.h"
65 #include "ui/console.h"
67 #include "sysemu/sysemu.h"
68 #include "sysemu/numa.h"
69 #include "sysemu/hostmem.h"
70 #include "exec/gdbstub.h"
71 #include "qemu/timer.h"
72 #include "chardev/char.h"
73 #include "qemu/bitmap.h"
75 #include "sysemu/blockdev.h"
76 #include "hw/block/block.h"
77 #include "hw/i386/x86.h"
78 #include "hw/i386/pc.h"
79 #include "migration/misc.h"
80 #include "migration/snapshot.h"
81 #include "sysemu/tpm.h"
82 #include "sysemu/dma.h"
83 #include "hw/audio/soundhw.h"
84 #include "audio/audio.h"
85 #include "sysemu/cpus.h"
86 #include "sysemu/cpu-timers.h"
87 #include "migration/colo.h"
88 #include "migration/postcopy-ram.h"
89 #include "sysemu/kvm.h"
90 #include "sysemu/hax.h"
91 #include "qapi/qobject-input-visitor.h"
92 #include "qemu/option.h"
93 #include "qemu/config-file.h"
94 #include "qemu/qemu-options.h"
95 #include "qemu/main-loop.h"
97 #include "fsdev/qemu-fsdev.h"
99 #include "sysemu/qtest.h"
101 #include "disas/disas.h"
104 #include "trace/control.h"
105 #include "qemu/plugin.h"
106 #include "qemu/queue.h"
107 #include "sysemu/arch_init.h"
108 #include "exec/confidential-guest-support.h"
110 #include "ui/qemu-spice.h"
111 #include "qapi/string-input-visitor.h"
112 #include "qapi/opts-visitor.h"
113 #include "qapi/clone-visitor.h"
114 #include "qom/object_interfaces.h"
115 #include "semihosting/semihost.h"
116 #include "crypto/init.h"
117 #include "sysemu/replay.h"
118 #include "qapi/qapi-events-run-state.h"
119 #include "qapi/qapi-visit-block-core.h"
120 #include "qapi/qapi-visit-compat.h"
121 #include "qapi/qapi-visit-ui.h"
122 #include "qapi/qapi-commands-block-core.h"
123 #include "qapi/qapi-commands-migration.h"
124 #include "qapi/qapi-commands-misc.h"
125 #include "qapi/qapi-visit-qom.h"
126 #include "qapi/qapi-commands-ui.h"
127 #include "qapi/qmp/qdict.h"
128 #include "qapi/qmp/qerror.h"
129 #include "sysemu/iothread.h"
130 #include "qemu/guest-random.h"
132 #include "config-host.h"
134 #define MAX_VIRTIO_CONSOLES 1
136 typedef struct BlockdevOptionsQueueEntry
{
137 BlockdevOptions
*bdo
;
139 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
140 } BlockdevOptionsQueueEntry
;
142 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
144 typedef struct ObjectOption
{
146 QTAILQ_ENTRY(ObjectOption
) next
;
149 typedef struct DeviceOption
{
152 QTAILQ_ENTRY(DeviceOption
) next
;
155 static const char *cpu_option
;
156 static const char *mem_path
;
157 static const char *incoming
;
158 static const char *loadvm
;
159 static const char *accelerators
;
160 static QDict
*machine_opts_dict
;
161 static QTAILQ_HEAD(, ObjectOption
) object_opts
= QTAILQ_HEAD_INITIALIZER(object_opts
);
162 static QTAILQ_HEAD(, DeviceOption
) device_opts
= QTAILQ_HEAD_INITIALIZER(device_opts
);
163 static ram_addr_t maxram_size
;
164 static uint64_t ram_slots
;
165 static int display_remote
;
167 static bool preconfig_requested
;
168 static QemuPluginList plugin_list
= QTAILQ_HEAD_INITIALIZER(plugin_list
);
169 static BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
170 static bool nographic
= false;
171 static int mem_prealloc
; /* force preallocation of physical target memory */
172 static ram_addr_t ram_size
;
173 static const char *vga_model
= NULL
;
174 static DisplayOptions dpy
;
175 static int num_serial_hds
;
176 static Chardev
**serial_hds
;
177 static const char *log_mask
;
178 static const char *log_file
;
179 static bool list_data_dirs
;
180 static const char *watchdog
;
181 static const char *qtest_chrdev
;
182 static const char *qtest_log
;
184 static int has_defaults
= 1;
185 static int default_serial
= 1;
186 static int default_parallel
= 1;
187 static int default_monitor
= 1;
188 static int default_floppy
= 1;
189 static int default_cdrom
= 1;
190 static int default_sdcard
= 1;
191 static int default_vga
= 1;
192 static int default_net
= 1;
198 { .driver
= "isa-serial", .flag
= &default_serial
},
199 { .driver
= "isa-parallel", .flag
= &default_parallel
},
200 { .driver
= "isa-fdc", .flag
= &default_floppy
},
201 { .driver
= "floppy", .flag
= &default_floppy
},
202 { .driver
= "ide-cd", .flag
= &default_cdrom
},
203 { .driver
= "ide-hd", .flag
= &default_cdrom
},
204 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
205 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
206 { .driver
= "VGA", .flag
= &default_vga
},
207 { .driver
= "isa-vga", .flag
= &default_vga
},
208 { .driver
= "cirrus-vga", .flag
= &default_vga
},
209 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
210 { .driver
= "vmware-svga", .flag
= &default_vga
},
211 { .driver
= "qxl-vga", .flag
= &default_vga
},
212 { .driver
= "virtio-vga", .flag
= &default_vga
},
213 { .driver
= "ati-vga", .flag
= &default_vga
},
214 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
215 { .driver
= "virtio-vga-gl", .flag
= &default_vga
},
218 static QemuOptsList qemu_rtc_opts
= {
220 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
225 .type
= QEMU_OPT_STRING
,
228 .type
= QEMU_OPT_STRING
,
231 .type
= QEMU_OPT_STRING
,
233 { /* end of list */ }
237 static QemuOptsList qemu_option_rom_opts
= {
238 .name
= "option-rom",
239 .implied_opt_name
= "romfile",
240 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
244 .type
= QEMU_OPT_NUMBER
,
247 .type
= QEMU_OPT_STRING
,
249 { /* end of list */ }
253 static QemuOptsList qemu_accel_opts
= {
255 .implied_opt_name
= "accel",
256 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
259 * no elements => accept any
260 * sanity checking will happen later
261 * when setting accelerator properties
267 static QemuOptsList qemu_boot_opts
= {
269 .implied_opt_name
= "order",
271 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
275 .type
= QEMU_OPT_STRING
,
278 .type
= QEMU_OPT_STRING
,
281 .type
= QEMU_OPT_BOOL
,
284 .type
= QEMU_OPT_STRING
,
286 .name
= "splash-time",
287 .type
= QEMU_OPT_NUMBER
,
289 .name
= "reboot-timeout",
290 .type
= QEMU_OPT_NUMBER
,
293 .type
= QEMU_OPT_BOOL
,
299 static QemuOptsList qemu_add_fd_opts
= {
301 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
305 .type
= QEMU_OPT_NUMBER
,
306 .help
= "file descriptor of which a duplicate is added to fd set",
309 .type
= QEMU_OPT_NUMBER
,
310 .help
= "ID of the fd set to add fd to",
313 .type
= QEMU_OPT_STRING
,
314 .help
= "free-form string used to describe fd",
316 { /* end of list */ }
320 static QemuOptsList qemu_object_opts
= {
322 .implied_opt_name
= "qom-type",
323 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
329 static QemuOptsList qemu_tpmdev_opts
= {
331 .implied_opt_name
= "type",
332 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
334 /* options are defined in the TPM backends */
335 { /* end of list */ }
339 static QemuOptsList qemu_overcommit_opts
= {
340 .name
= "overcommit",
341 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
345 .type
= QEMU_OPT_BOOL
,
349 .type
= QEMU_OPT_BOOL
,
351 { /* end of list */ }
355 static QemuOptsList qemu_msg_opts
= {
357 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
361 .type
= QEMU_OPT_BOOL
,
364 .name
= "guest-name",
365 .type
= QEMU_OPT_BOOL
,
366 .help
= "Prepends guest name for error messages but only if "
367 "-name guest is set otherwise option is ignored\n",
369 { /* end of list */ }
373 static QemuOptsList qemu_name_opts
= {
375 .implied_opt_name
= "guest",
377 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
381 .type
= QEMU_OPT_STRING
,
382 .help
= "Sets the name of the guest.\n"
383 "This name will be displayed in the SDL window caption.\n"
384 "The name will also be used for the VNC server",
387 .type
= QEMU_OPT_STRING
,
388 .help
= "Sets the name of the QEMU process, as shown in top etc",
390 .name
= "debug-threads",
391 .type
= QEMU_OPT_BOOL
,
392 .help
= "When enabled, name the individual threads; defaults off.\n"
393 "NOTE: The thread names are for debugging and not a\n"
396 { /* End of list */ }
400 static QemuOptsList qemu_mem_opts
= {
402 .implied_opt_name
= "size",
403 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
408 .type
= QEMU_OPT_SIZE
,
412 .type
= QEMU_OPT_NUMBER
,
416 .type
= QEMU_OPT_SIZE
,
418 { /* end of list */ }
422 static QemuOptsList qemu_icount_opts
= {
424 .implied_opt_name
= "shift",
426 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
430 .type
= QEMU_OPT_STRING
,
433 .type
= QEMU_OPT_BOOL
,
436 .type
= QEMU_OPT_BOOL
,
439 .type
= QEMU_OPT_STRING
,
442 .type
= QEMU_OPT_STRING
,
444 .name
= "rrsnapshot",
445 .type
= QEMU_OPT_STRING
,
447 { /* end of list */ }
451 static QemuOptsList qemu_fw_cfg_opts
= {
453 .implied_opt_name
= "name",
454 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
458 .type
= QEMU_OPT_STRING
,
459 .help
= "Sets the fw_cfg name of the blob to be inserted",
462 .type
= QEMU_OPT_STRING
,
463 .help
= "Sets the name of the file from which "
464 "the fw_cfg blob will be loaded",
467 .type
= QEMU_OPT_STRING
,
468 .help
= "Sets content of the blob to be inserted from a string",
471 .type
= QEMU_OPT_STRING
,
472 .help
= "Sets id of the object generating the fw_cfg blob "
475 { /* end of list */ }
479 static QemuOptsList qemu_action_opts
= {
482 .head
= QTAILQ_HEAD_INITIALIZER(qemu_action_opts
.head
),
486 .type
= QEMU_OPT_STRING
,
489 .type
= QEMU_OPT_STRING
,
492 .type
= QEMU_OPT_STRING
,
495 .type
= QEMU_OPT_STRING
,
497 { /* end of list */ }
501 const char *qemu_get_vm_name(void)
506 static void default_driver_disable(const char *driver
)
514 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
515 if (strcmp(default_list
[i
].driver
, driver
) != 0)
517 *(default_list
[i
].flag
) = 0;
521 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
523 const char *driver
= qemu_opt_get(opts
, "driver");
525 default_driver_disable(driver
);
529 static void default_driver_check_json(void)
533 QTAILQ_FOREACH(opt
, &device_opts
, next
) {
534 const char *driver
= qdict_get_try_str(opt
->opts
, "driver");
535 default_driver_disable(driver
);
539 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
541 const char *proc_name
;
543 if (qemu_opt_get(opts
, "debug-threads")) {
544 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
546 qemu_name
= qemu_opt_get(opts
, "guest");
548 proc_name
= qemu_opt_get(opts
, "process");
550 os_set_proc_name(proc_name
);
556 bool defaults_enabled(void)
562 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
564 int fd
, dupfd
, flags
;
566 const char *fd_opaque
= NULL
;
569 fd
= qemu_opt_get_number(opts
, "fd", -1);
570 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
571 fd_opaque
= qemu_opt_get(opts
, "opaque");
574 error_setg(errp
, "fd option is required and must be non-negative");
578 if (fd
<= STDERR_FILENO
) {
579 error_setg(errp
, "fd cannot be a standard I/O stream");
584 * All fds inherited across exec() necessarily have FD_CLOEXEC
585 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
587 flags
= fcntl(fd
, F_GETFD
);
588 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
589 error_setg(errp
, "fd is not valid or already in use");
594 error_setg(errp
, "set option is required and must be non-negative");
598 #ifdef F_DUPFD_CLOEXEC
599 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
603 qemu_set_cloexec(dupfd
);
607 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
611 /* add the duplicate fd, and optionally the opaque string, to the fd set */
612 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
619 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
623 fd
= qemu_opt_get_number(opts
, "fd", -1);
630 /***********************************************************/
631 /* QEMU Block devices */
633 #define HD_OPTS "media=disk"
634 #define CDROM_OPTS "media=cdrom"
636 #define PFLASH_OPTS ""
640 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
642 BlockInterfaceType
*block_default_type
= opaque
;
644 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
647 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
649 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
650 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
655 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
656 int index
, const char *optstr
)
661 if (!enable
|| drive_get_by_index(type
, index
)) {
665 opts
= drive_add(type
, index
, NULL
, optstr
);
667 drive_enable_snapshot(NULL
, opts
, NULL
);
670 dinfo
= drive_new(opts
, type
, &error_abort
);
671 dinfo
->is_default
= true;
675 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
676 MachineClass
*machine_class
, int snapshot
)
679 * If the currently selected machine wishes to override the
680 * units-per-bus property of its default HBA interface type, do so
683 if (machine_class
->units_per_default_bus
) {
684 override_max_devs(machine_class
->block_default_type
,
685 machine_class
->units_per_default_bus
);
688 /* open the virtual block devices */
689 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
690 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
692 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
693 loc_push_restore(&bdo
->loc
);
694 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
696 qapi_free_BlockdevOptions(bdo
->bdo
);
700 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
703 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
704 &machine_class
->block_default_type
, &error_fatal
)) {
705 /* We printed help */
709 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
711 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
712 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
716 static QemuOptsList qemu_smp_opts
= {
718 .implied_opt_name
= "cpus",
720 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
724 .type
= QEMU_OPT_NUMBER
,
727 .type
= QEMU_OPT_NUMBER
,
730 .type
= QEMU_OPT_NUMBER
,
733 .type
= QEMU_OPT_NUMBER
,
736 .type
= QEMU_OPT_NUMBER
,
739 .type
= QEMU_OPT_NUMBER
,
742 .type
= QEMU_OPT_NUMBER
,
748 static void realtime_init(void)
751 if (os_mlock() < 0) {
752 error_report("locking memory failed");
759 static void configure_msg(QemuOpts
*opts
)
761 message_with_timestamp
= qemu_opt_get_bool(opts
, "timestamp", false);
762 error_with_guestname
= qemu_opt_get_bool(opts
, "guest-name", false);
766 /***********************************************************/
769 static int usb_device_add(const char *devname
)
771 USBDevice
*dev
= NULL
;
773 if (!machine_usb(current_machine
)) {
777 dev
= usbdevice_create(devname
);
784 static int usb_parse(const char *cmdline
)
787 r
= usb_device_add(cmdline
);
789 error_report("could not add USB device '%s'", cmdline
);
794 /***********************************************************/
795 /* machine registration */
797 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
801 for (el
= machines
; el
; el
= el
->next
) {
802 MachineClass
*mc
= el
->data
;
804 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
812 static MachineClass
*find_default_machine(GSList
*machines
)
815 MachineClass
*default_machineclass
= NULL
;
817 for (el
= machines
; el
; el
= el
->next
) {
818 MachineClass
*mc
= el
->data
;
820 if (mc
->is_default
) {
821 assert(default_machineclass
== NULL
&& "Multiple default machines");
822 default_machineclass
= mc
;
826 return default_machineclass
;
829 static void version(void)
831 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
832 QEMU_COPYRIGHT
"\n");
835 static void help(int exitcode
)
838 printf("usage: %s [options] [disk_image]\n\n"
839 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
842 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
843 if ((arch_mask) & arch_type) \
844 fputs(opt_help, stdout);
846 #define ARCHHEADING(text, arch_mask) \
847 if ((arch_mask) & arch_type) \
848 puts(stringify(text));
850 #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL)
852 #include "qemu-options.def"
854 printf("\nDuring emulation, the following keys are useful:\n"
855 "ctrl-alt-f toggle full screen\n"
856 "ctrl-alt-n switch to virtual console 'n'\n"
857 "ctrl-alt toggle mouse and keyboard grab\n"
859 "When using -nographic, press 'ctrl-a h' to get some help.\n"
861 QEMU_HELP_BOTTOM
"\n");
866 #define HAS_ARG 0x0001
868 typedef struct QEMUOption
{
875 static const QEMUOption qemu_options
[] = {
876 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
878 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
879 { option, opt_arg, opt_enum, arch_mask },
880 #define DEFHEADING(text)
881 #define ARCHHEADING(text, arch_mask)
883 #include "qemu-options.def"
887 typedef struct VGAInterfaceInfo
{
888 const char *opt_name
; /* option name */
889 const char *name
; /* human-readable name */
890 /* Class names indicating that support is available.
891 * If no class is specified, the interface is always available */
892 const char *class_names
[2];
895 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
898 .name
= "no graphic card",
902 .name
= "standard VGA",
903 .class_names
= { "VGA", "isa-vga" },
906 .opt_name
= "cirrus",
907 .name
= "Cirrus VGA",
908 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
911 .opt_name
= "vmware",
912 .name
= "VMWare SVGA",
913 .class_names
= { "vmware-svga" },
916 .opt_name
= "virtio",
917 .name
= "Virtio VGA",
918 .class_names
= { "virtio-vga" },
923 .class_names
= { "qxl-vga" },
927 .name
= "TCX framebuffer",
928 .class_names
= { "sun-tcx" },
932 .name
= "CG3 framebuffer",
933 .class_names
= { "cgthree" },
937 .name
= "Xen paravirtualized framebuffer",
941 static bool vga_interface_available(VGAInterfaceType t
)
943 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
945 assert(t
< VGA_TYPE_MAX
);
946 return !ti
->class_names
[0] ||
947 module_object_class_by_name(ti
->class_names
[0]) ||
948 module_object_class_by_name(ti
->class_names
[1]);
952 get_default_vga_model(const MachineClass
*machine_class
)
954 if (machine_class
->default_display
) {
955 return machine_class
->default_display
;
956 } else if (vga_interface_available(VGA_CIRRUS
)) {
958 } else if (vga_interface_available(VGA_STD
)) {
965 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
970 if (g_str_equal(p
, "help")) {
971 const char *def
= get_default_vga_model(machine_class
);
973 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
974 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
976 if (vga_interface_available(t
) && ti
->opt_name
) {
977 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
978 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
984 assert(vga_interface_type
== VGA_NONE
);
985 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
986 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
987 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
988 if (!vga_interface_available(t
)) {
989 error_report("%s not available", ti
->name
);
992 vga_interface_type
= t
;
996 if (t
== VGA_TYPE_MAX
) {
998 error_report("unknown vga type: %s", p
);
1002 const char *nextopt
;
1004 if (strstart(opts
, ",retrace=", &nextopt
)) {
1006 if (strstart(opts
, "dumb", &nextopt
))
1007 vga_retrace_method
= VGA_RETRACE_DUMB
;
1008 else if (strstart(opts
, "precise", &nextopt
))
1009 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1010 else goto invalid_vga
;
1011 } else goto invalid_vga
;
1016 static void parse_display_qapi(const char *optarg
)
1018 DisplayOptions
*opts
;
1021 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
1023 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
1024 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
1026 qapi_free_DisplayOptions(opts
);
1030 DisplayOptions
*qmp_query_display_options(Error
**errp
)
1032 return QAPI_CLONE(DisplayOptions
, &dpy
);
1035 static void parse_display(const char *p
)
1039 if (is_help_option(p
)) {
1040 qemu_display_help();
1044 if (strstart(p
, "sdl", &opts
)) {
1046 * sdl DisplayType needs hand-crafted parser instead of
1047 * parse_display_qapi() due to some options not in
1048 * DisplayOptions, specifically:
1049 * - ctrl_grab + alt_grab
1050 * They can't be moved into the QAPI since they use underscores,
1051 * thus they will get replaced by "grab-mod" in the long term
1053 #if defined(CONFIG_SDL)
1054 dpy
.type
= DISPLAY_TYPE_SDL
;
1056 const char *nextopt
;
1058 if (strstart(opts
, ",grab-mod=", &nextopt
)) {
1060 if (strstart(opts
, "lshift-lctrl-lalt", &nextopt
)) {
1062 } else if (strstart(opts
, "rctrl", &nextopt
)) {
1065 goto invalid_sdl_args
;
1067 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1069 if (strstart(opts
, "on", &nextopt
)) {
1071 } else if (strstart(opts
, "off", &nextopt
)) {
1074 goto invalid_sdl_args
;
1076 warn_report("alt_grab is deprecated, use grab-mod instead.");
1077 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1079 if (strstart(opts
, "on", &nextopt
)) {
1081 } else if (strstart(opts
, "off", &nextopt
)) {
1084 goto invalid_sdl_args
;
1086 warn_report("ctrl_grab is deprecated, use grab-mod instead.");
1087 } else if (strstart(opts
, ",window_close=", &nextopt
) ||
1088 strstart(opts
, ",window-close=", &nextopt
)) {
1089 if (strstart(opts
, ",window_close=", NULL
)) {
1090 warn_report("window_close with an underscore is deprecated,"
1091 " please use window-close instead.");
1094 dpy
.has_window_close
= true;
1095 if (strstart(opts
, "on", &nextopt
)) {
1096 dpy
.window_close
= true;
1097 } else if (strstart(opts
, "off", &nextopt
)) {
1098 dpy
.window_close
= false;
1100 goto invalid_sdl_args
;
1102 } else if (strstart(opts
, ",show-cursor=", &nextopt
)) {
1104 dpy
.has_show_cursor
= true;
1105 if (strstart(opts
, "on", &nextopt
)) {
1106 dpy
.show_cursor
= true;
1107 } else if (strstart(opts
, "off", &nextopt
)) {
1108 dpy
.show_cursor
= false;
1110 goto invalid_sdl_args
;
1112 } else if (strstart(opts
, ",gl=", &nextopt
)) {
1115 if (strstart(opts
, "on", &nextopt
)) {
1116 dpy
.gl
= DISPLAYGL_MODE_ON
;
1117 } else if (strstart(opts
, "core", &nextopt
)) {
1118 dpy
.gl
= DISPLAYGL_MODE_CORE
;
1119 } else if (strstart(opts
, "es", &nextopt
)) {
1120 dpy
.gl
= DISPLAYGL_MODE_ES
;
1121 } else if (strstart(opts
, "off", &nextopt
)) {
1122 dpy
.gl
= DISPLAYGL_MODE_OFF
;
1124 goto invalid_sdl_args
;
1128 error_report("invalid SDL option string");
1134 error_report("SDL display supported is not available in this binary");
1137 } else if (strstart(p
, "vnc", &opts
)) {
1139 * vnc isn't a (local) DisplayType but a protocol for remote
1143 vnc_parse(opts
+ 1);
1145 error_report("VNC requires a display argument vnc=<display>");
1149 parse_display_qapi(p
);
1153 static inline bool nonempty_str(const char *str
)
1158 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1162 const char *name
, *file
, *str
, *gen_id
;
1163 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1165 if (fw_cfg
== NULL
) {
1166 error_setg(errp
, "fw_cfg device not available");
1169 name
= qemu_opt_get(opts
, "name");
1170 file
= qemu_opt_get(opts
, "file");
1171 str
= qemu_opt_get(opts
, "string");
1172 gen_id
= qemu_opt_get(opts
, "gen_id");
1174 /* we need the name, and exactly one of: file, content string, gen_id */
1175 if (!nonempty_str(name
) ||
1176 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1177 error_setg(errp
, "name, plus exactly one of file,"
1178 " string and gen_id, are needed");
1181 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1182 error_setg(errp
, "name too long (max. %d char)",
1183 FW_CFG_MAX_FILE_PATH
- 1);
1186 if (nonempty_str(gen_id
)) {
1188 * In this particular case where the content is populated
1189 * internally, the "etc/" namespace protection is relaxed,
1190 * so do not emit a warning.
1192 } else if (strncmp(name
, "opt/", 4) != 0) {
1193 warn_report("externally provided fw_cfg item names "
1194 "should be prefixed with \"opt/\"");
1196 if (nonempty_str(str
)) {
1197 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1198 buf
= g_memdup(str
, size
);
1199 } else if (nonempty_str(gen_id
)) {
1200 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1206 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1207 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1212 /* For legacy, keep user files in a specific global order. */
1213 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1214 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1215 fw_cfg_reset_order_override(fw_cfg
);
1219 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1221 return qdev_device_help(opts
);
1224 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1228 dev
= qdev_device_add(opts
, errp
);
1229 if (!dev
&& *errp
) {
1230 error_report_err(*errp
);
1233 object_unref(OBJECT(dev
));
1238 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1240 Error
*local_err
= NULL
;
1242 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1244 error_propagate(errp
, local_err
);
1252 #ifdef CONFIG_VIRTFS
1253 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1255 return qemu_fsdev_add(opts
, errp
);
1259 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1261 return monitor_init_opts(opts
, errp
);
1264 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
1266 static int monitor_device_index
= 0;
1271 if (strstart(optarg
, "chardev:", &p
)) {
1272 snprintf(label
, sizeof(label
), "%s", p
);
1274 snprintf(label
, sizeof(label
), "compat_monitor%d",
1275 monitor_device_index
);
1276 opts
= qemu_chr_parse_compat(label
, optarg
, true);
1278 error_report("parse error: %s", optarg
);
1283 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1284 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1285 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1286 if (!strcmp(mode
, "control")) {
1287 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1289 assert(pretty
== false);
1291 monitor_device_index
++;
1294 struct device_config
{
1296 DEV_USB
, /* -usbdevice */
1297 DEV_SERIAL
, /* -serial */
1298 DEV_PARALLEL
, /* -parallel */
1299 DEV_DEBUGCON
, /* -debugcon */
1300 DEV_GDB
, /* -gdb, -s */
1301 DEV_SCLP
, /* s390 sclp */
1303 const char *cmdline
;
1305 QTAILQ_ENTRY(device_config
) next
;
1308 static QTAILQ_HEAD(, device_config
) device_configs
=
1309 QTAILQ_HEAD_INITIALIZER(device_configs
);
1311 static void add_device_config(int type
, const char *cmdline
)
1313 struct device_config
*conf
;
1315 conf
= g_malloc0(sizeof(*conf
));
1317 conf
->cmdline
= cmdline
;
1318 loc_save(&conf
->loc
);
1319 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1322 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1324 struct device_config
*conf
;
1327 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1328 if (conf
->type
!= type
)
1330 loc_push_restore(&conf
->loc
);
1331 rc
= func(conf
->cmdline
);
1332 loc_pop(&conf
->loc
);
1340 static void qemu_disable_default_devices(void)
1342 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1344 default_driver_check_json();
1345 qemu_opts_foreach(qemu_find_opts("device"),
1346 default_driver_check
, NULL
, NULL
);
1347 qemu_opts_foreach(qemu_find_opts("global"),
1348 default_driver_check
, NULL
, NULL
);
1350 if (!vga_model
&& !default_vga
) {
1351 vga_interface_type
= VGA_DEVICE
;
1353 if (!has_defaults
|| machine_class
->no_serial
) {
1356 if (!has_defaults
|| machine_class
->no_parallel
) {
1357 default_parallel
= 0;
1359 if (!has_defaults
|| machine_class
->no_floppy
) {
1362 if (!has_defaults
|| machine_class
->no_cdrom
) {
1365 if (!has_defaults
|| machine_class
->no_sdcard
) {
1368 if (!has_defaults
) {
1369 default_monitor
= 0;
1375 static void qemu_create_default_devices(void)
1377 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1379 if (is_daemonized()) {
1380 /* According to documentation and historically, -nographic redirects
1381 * serial port, parallel port and monitor to stdio, which does not work
1382 * with -daemonize. We can redirect these to null instead, but since
1383 * -nographic is legacy, let's just error out.
1384 * We disallow -nographic only if all other ports are not redirected
1385 * explicitly, to not break existing legacy setups which uses
1386 * -nographic _and_ redirects all ports explicitly - this is valid
1387 * usage, -nographic is just a no-op in this case.
1390 && (default_parallel
|| default_serial
|| default_monitor
)) {
1391 error_report("-nographic cannot be used with -daemonize");
1397 if (default_parallel
)
1398 add_device_config(DEV_PARALLEL
, "null");
1399 if (default_serial
&& default_monitor
) {
1400 add_device_config(DEV_SERIAL
, "mon:stdio");
1403 add_device_config(DEV_SERIAL
, "stdio");
1404 if (default_monitor
)
1405 monitor_parse("stdio", "readline", false);
1409 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
1410 if (default_parallel
)
1411 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
1412 if (default_monitor
)
1413 monitor_parse("vc:80Cx24C", "readline", false);
1417 QemuOptsList
*net
= qemu_find_opts("net");
1418 qemu_opts_parse(net
, "nic", true, &error_abort
);
1420 qemu_opts_parse(net
, "user", true, &error_abort
);
1424 #if defined(CONFIG_VNC)
1425 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
1429 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1430 if (!qemu_display_find_default(&dpy
)) {
1431 dpy
.type
= DISPLAY_TYPE_NONE
;
1432 #if defined(CONFIG_VNC)
1433 vnc_parse("localhost:0,to=99,id=default");
1437 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1438 dpy
.type
= DISPLAY_TYPE_NONE
;
1441 /* If no default VGA is requested, the default is "none". */
1443 vga_model
= get_default_vga_model(machine_class
);
1446 select_vgahw(machine_class
, vga_model
);
1450 static int serial_parse(const char *devname
)
1452 int index
= num_serial_hds
;
1455 if (strcmp(devname
, "none") == 0)
1457 snprintf(label
, sizeof(label
), "serial%d", index
);
1458 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1460 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1461 if (!serial_hds
[index
]) {
1462 error_report("could not connect serial device"
1463 " to character backend '%s'", devname
);
1470 Chardev
*serial_hd(int i
)
1473 if (i
< num_serial_hds
) {
1474 return serial_hds
[i
];
1479 static int parallel_parse(const char *devname
)
1481 static int index
= 0;
1484 if (strcmp(devname
, "none") == 0)
1486 if (index
== MAX_PARALLEL_PORTS
) {
1487 error_report("too many parallel ports");
1490 snprintf(label
, sizeof(label
), "parallel%d", index
);
1491 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1492 if (!parallel_hds
[index
]) {
1493 error_report("could not connect parallel device"
1494 " to character backend '%s'", devname
);
1501 static int debugcon_parse(const char *devname
)
1505 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1506 error_report("invalid character backend '%s'", devname
);
1509 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1511 error_report("already have a debugcon device");
1514 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1515 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1519 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1521 const MachineClass
*mc1
= a
, *mc2
= b
;
1524 if (mc1
->family
== NULL
) {
1525 if (mc2
->family
== NULL
) {
1526 /* Compare standalone machine types against each other; they sort
1527 * in increasing order.
1529 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1530 object_class_get_name(OBJECT_CLASS(mc2
)));
1533 /* Standalone machine types sort after families. */
1537 if (mc2
->family
== NULL
) {
1538 /* Families sort before standalone machine types. */
1542 /* Families sort between each other alphabetically increasingly. */
1543 res
= strcmp(mc1
->family
, mc2
->family
);
1548 /* Within the same family, machine types sort in decreasing order. */
1549 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1550 object_class_get_name(OBJECT_CLASS(mc1
)));
1553 static void machine_help_func(const QDict
*qdict
)
1555 GSList
*machines
, *el
;
1556 const char *type
= qdict_get_try_str(qdict
, "type");
1558 machines
= object_class_get_list(TYPE_MACHINE
, false);
1560 ObjectClass
*machine_class
= OBJECT_CLASS(find_machine(type
, machines
));
1561 if (machine_class
) {
1562 type_print_class_properties(object_class_get_name(machine_class
));
1567 printf("Supported machines are:\n");
1568 machines
= g_slist_sort(machines
, machine_class_cmp
);
1569 for (el
= machines
; el
; el
= el
->next
) {
1570 MachineClass
*mc
= el
->data
;
1572 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1574 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1575 mc
->is_default
? " (default)" : "",
1576 mc
->deprecation_reason
? " (deprecated)" : "");
1581 machine_merge_property(const char *propname
, QDict
*prop
, Error
**errp
)
1586 /* Preserve the caller's reference to prop. */
1588 qdict_put(opts
, propname
, prop
);
1589 keyval_merge(machine_opts_dict
, opts
, errp
);
1590 qobject_unref(opts
);
1594 machine_parse_property_opt(QemuOptsList
*opts_list
, const char *propname
,
1600 prop
= keyval_parse(arg
, opts_list
->implied_opt_name
, &help
, &error_fatal
);
1602 qemu_opts_print_help(opts_list
, true);
1605 machine_merge_property(propname
, prop
, &error_fatal
);
1606 qobject_unref(prop
);
1609 static const char *pid_file
;
1610 static Notifier qemu_unlink_pidfile_notifier
;
1612 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1619 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1620 const char **poptarg
, int *poptind
)
1622 const QEMUOption
*popt
;
1623 int optind
= *poptind
;
1624 char *r
= argv
[optind
];
1627 loc_set_cmdline(argv
, optind
, 1);
1629 /* Treat --foo the same as -foo. */
1632 popt
= qemu_options
;
1635 error_report("invalid option");
1638 if (!strcmp(popt
->name
, r
+ 1))
1642 if (popt
->flags
& HAS_ARG
) {
1643 if (optind
>= argc
) {
1644 error_report("requires an argument");
1647 optarg
= argv
[optind
++];
1648 loc_set_cmdline(argv
, optind
- 2, 2);
1659 static MachineClass
*select_machine(QDict
*qdict
, Error
**errp
)
1661 const char *optarg
= qdict_get_try_str(qdict
, "type");
1662 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
1663 MachineClass
*machine_class
;
1664 Error
*local_err
= NULL
;
1667 machine_class
= find_machine(optarg
, machines
);
1668 qdict_del(qdict
, "type");
1669 if (!machine_class
) {
1670 error_setg(&local_err
, "unsupported machine type");
1673 machine_class
= find_default_machine(machines
);
1674 if (!machine_class
) {
1675 error_setg(&local_err
, "No machine specified, and there is no default");
1679 g_slist_free(machines
);
1681 error_append_hint(&local_err
, "Use -machine help to list supported machines\n");
1682 error_propagate(errp
, local_err
);
1684 return machine_class
;
1687 static int object_parse_property_opt(Object
*obj
,
1688 const char *name
, const char *value
,
1689 const char *skip
, Error
**errp
)
1691 if (g_str_equal(name
, skip
)) {
1695 if (!object_property_parse(obj
, name
, value
, errp
)) {
1702 /* *Non*recursively replace underscores with dashes in QDict keys. */
1703 static void keyval_dashify(QDict
*qdict
, Error
**errp
)
1705 const QDictEntry
*ent
, *next
;
1708 for (ent
= qdict_first(qdict
); ent
; ent
= next
) {
1709 g_autofree
char *new_key
= NULL
;
1711 next
= qdict_next(qdict
, ent
);
1712 if (!strchr(ent
->key
, '_')) {
1715 new_key
= g_strdup(ent
->key
);
1716 for (p
= new_key
; *p
; p
++) {
1721 if (qdict_haskey(qdict
, new_key
)) {
1722 error_setg(errp
, "Conflict between '%s' and '%s'", ent
->key
, new_key
);
1725 qobject_ref(ent
->value
);
1726 qdict_put_obj(qdict
, new_key
, ent
->value
);
1727 qdict_del(qdict
, ent
->key
);
1731 static void qemu_apply_legacy_machine_options(QDict
*qdict
)
1735 keyval_dashify(qdict
, &error_fatal
);
1737 /* Legacy options do not correspond to MachineState properties. */
1738 value
= qdict_get_try_str(qdict
, "accel");
1740 accelerators
= g_strdup(value
);
1741 qdict_del(qdict
, "accel");
1744 value
= qdict_get_try_str(qdict
, "igd-passthru");
1746 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value
,
1748 qdict_del(qdict
, "igd-passthru");
1751 value
= qdict_get_try_str(qdict
, "kvm-shadow-mem");
1753 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value
,
1755 qdict_del(qdict
, "kvm-shadow-mem");
1758 value
= qdict_get_try_str(qdict
, "kernel-irqchip");
1760 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value
,
1762 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value
,
1764 qdict_del(qdict
, "kernel-irqchip");
1768 static void object_option_foreach_add(bool (*type_opt_predicate
)(const char *))
1770 ObjectOption
*opt
, *next
;
1772 QTAILQ_FOREACH_SAFE(opt
, &object_opts
, next
, next
) {
1773 const char *type
= ObjectType_str(opt
->opts
->qom_type
);
1774 if (type_opt_predicate(type
)) {
1775 user_creatable_add_qapi(opt
->opts
, &error_fatal
);
1776 qapi_free_ObjectOptions(opt
->opts
);
1777 QTAILQ_REMOVE(&object_opts
, opt
, next
);
1783 static void object_option_add_visitor(Visitor
*v
)
1785 ObjectOption
*opt
= g_new0(ObjectOption
, 1);
1786 visit_type_ObjectOptions(v
, NULL
, &opt
->opts
, &error_fatal
);
1787 QTAILQ_INSERT_TAIL(&object_opts
, opt
, next
);
1790 static void object_option_parse(const char *optarg
)
1796 if (optarg
[0] == '{') {
1797 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
1799 v
= qobject_input_visitor_new(obj
);
1802 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
1808 type
= qemu_opt_get(opts
, "qom-type");
1810 error_setg(&error_fatal
, QERR_MISSING_PARAMETER
, "qom-type");
1812 if (user_creatable_print_help(type
, opts
)) {
1816 v
= opts_visitor_new(opts
);
1819 object_option_add_visitor(v
);
1824 * Initial object creation happens before all other
1825 * QEMU data types are created. The majority of objects
1826 * can be created at this point. The rng-egd object
1827 * cannot be created here, as it depends on the chardev
1830 static bool object_create_early(const char *type
)
1833 * Objects should not be made "delayed" without a reason. If you
1834 * add one, state the reason in a comment!
1837 /* Reason: property "chardev" */
1838 if (g_str_equal(type
, "rng-egd") ||
1839 g_str_equal(type
, "qtest")) {
1843 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1844 /* Reason: cryptodev-vhost-user property "chardev" */
1845 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1850 /* Reason: vhost-user-blk-server property "node-name" */
1851 if (g_str_equal(type
, "vhost-user-blk-server")) {
1855 * Reason: filter-* property "netdev" etc.
1857 if (g_str_equal(type
, "filter-buffer") ||
1858 g_str_equal(type
, "filter-dump") ||
1859 g_str_equal(type
, "filter-mirror") ||
1860 g_str_equal(type
, "filter-redirector") ||
1861 g_str_equal(type
, "colo-compare") ||
1862 g_str_equal(type
, "filter-rewriter") ||
1863 g_str_equal(type
, "filter-replay")) {
1868 * Allocation of large amounts of memory may delay
1869 * chardev initialization for too long, and trigger timeouts
1870 * on software that waits for a monitor socket to be created
1873 if (g_str_has_prefix(type
, "memory-backend-")) {
1880 static void qemu_apply_machine_options(QDict
*qdict
)
1882 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1883 const char *boot_order
= NULL
;
1884 const char *boot_once
= NULL
;
1887 object_set_properties_from_keyval(OBJECT(current_machine
), qdict
, false, &error_fatal
);
1888 current_machine
->ram_size
= ram_size
;
1889 current_machine
->maxram_size
= maxram_size
;
1890 current_machine
->ram_slots
= ram_slots
;
1892 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
1894 boot_order
= qemu_opt_get(opts
, "order");
1896 validate_bootdevices(boot_order
, &error_fatal
);
1899 boot_once
= qemu_opt_get(opts
, "once");
1901 validate_bootdevices(boot_once
, &error_fatal
);
1904 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
1905 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
1909 boot_order
= machine_class
->default_boot_order
;
1912 current_machine
->boot_order
= boot_order
;
1913 current_machine
->boot_once
= boot_once
;
1915 if (semihosting_enabled() && !semihosting_get_argc()) {
1916 /* fall back to the -kernel/-append */
1917 semihosting_arg_fallback(current_machine
->kernel_filename
, current_machine
->kernel_cmdline
);
1920 if (current_machine
->smp
.cpus
> 1) {
1921 Error
*blocker
= NULL
;
1922 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1923 replay_add_blocker(blocker
);
1927 static void qemu_create_early_backends(void)
1929 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1930 #if defined(CONFIG_SDL)
1931 const bool use_sdl
= (dpy
.type
== DISPLAY_TYPE_SDL
);
1933 const bool use_sdl
= false;
1935 #if defined(CONFIG_GTK)
1936 const bool use_gtk
= (dpy
.type
== DISPLAY_TYPE_GTK
);
1938 const bool use_gtk
= false;
1941 if ((alt_grab
|| ctrl_grab
) && !use_sdl
) {
1942 error_report("-alt-grab and -ctrl-grab are only valid "
1943 "for SDL, ignoring option");
1945 if (dpy
.has_window_close
&& !use_gtk
&& !use_sdl
) {
1946 error_report("window-close is only valid for GTK and SDL, "
1950 qemu_display_early_init(&dpy
);
1951 qemu_console_early_init();
1953 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1954 #if defined(CONFIG_OPENGL)
1955 error_report("OpenGL is not supported by the display");
1957 error_report("OpenGL support is disabled");
1962 object_option_foreach_add(object_create_early
);
1964 /* spice needs the timers to be initialized by this point */
1965 /* spice must initialize before audio as it changes the default audiodev */
1966 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1969 qemu_opts_foreach(qemu_find_opts("chardev"),
1970 chardev_init_func
, NULL
, &error_fatal
);
1972 #ifdef CONFIG_VIRTFS
1973 qemu_opts_foreach(qemu_find_opts("fsdev"),
1974 fsdev_init_func
, NULL
, &error_fatal
);
1978 * Note: we need to create audio and block backends before
1979 * setting machine properties, so they can be referred to.
1981 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
1982 audio_init_audiodevs();
1987 * The remainder of object creation happens after the
1988 * creation of chardev, fsdev, net clients and device data types.
1990 static bool object_create_late(const char *type
)
1992 return !object_create_early(type
);
1995 static void qemu_create_late_backends(void)
1998 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
2001 net_init_clients(&error_fatal
);
2003 object_option_foreach_add(object_create_late
);
2005 if (tpm_init() < 0) {
2009 qemu_opts_foreach(qemu_find_opts("mon"),
2010 mon_init_func
, NULL
, &error_fatal
);
2012 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2014 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2016 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2019 /* now chardevs have been created we may have semihosting to connect */
2020 qemu_semihosting_connect_chardevs();
2021 qemu_semihosting_console_init();
2024 static bool have_custom_ram_size(void)
2026 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2027 return !!qemu_opt_get_size(opts
, "size", 0);
2030 static void qemu_resolve_machine_memdev(void)
2032 if (current_machine
->ram_memdev_id
) {
2034 ram_addr_t backend_size
;
2036 backend
= object_resolve_path_type(current_machine
->ram_memdev_id
,
2037 TYPE_MEMORY_BACKEND
, NULL
);
2039 error_report("Memory backend '%s' not found",
2040 current_machine
->ram_memdev_id
);
2043 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
2044 if (have_custom_ram_size() && backend_size
!= ram_size
) {
2045 error_report("Size specified by -m option must match size of "
2046 "explicitly specified 'memory-backend' property");
2050 error_report("'-mem-path' can't be used together with"
2051 "'-machine memory-backend'");
2054 ram_size
= backend_size
;
2057 if (!xen_enabled()) {
2058 /* On 32-bit hosts, QEMU is limited by virtual address space */
2059 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2060 error_report("at most 2047 MB RAM can be simulated");
2066 static void set_memory_options(MachineClass
*mc
)
2069 const char *mem_str
;
2070 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2071 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2074 loc_push_none(&loc
);
2075 qemu_opts_loc_restore(opts
);
2078 mem_str
= qemu_opt_get(opts
, "size");
2081 error_report("missing 'size' option value");
2085 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2087 /* Fix up legacy suffix-less format */
2088 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2089 uint64_t overflow_check
= sz
;
2092 if (sz
/ MiB
!= overflow_check
) {
2093 error_report("too large 'size' option value");
2099 /* backward compatibility behaviour for case "-m 0" */
2101 sz
= default_ram_size
;
2104 sz
= QEMU_ALIGN_UP(sz
, 8192);
2105 if (mc
->fixup_ram_size
) {
2106 sz
= mc
->fixup_ram_size(sz
);
2109 if (ram_size
!= sz
) {
2110 error_report("ram size too large");
2114 maxram_size
= ram_size
;
2116 if (qemu_opt_get(opts
, "maxmem")) {
2119 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2120 slots
= qemu_opt_get_number(opts
, "slots", 0);
2121 if (sz
< ram_size
) {
2122 error_report("invalid value of -m option maxmem: "
2123 "maximum memory size (0x%" PRIx64
") must be at least "
2124 "the initial memory size (0x" RAM_ADDR_FMT
")",
2127 } else if (slots
&& sz
== ram_size
) {
2128 error_report("invalid value of -m option maxmem: "
2129 "memory slots were specified but maximum memory size "
2130 "(0x%" PRIx64
") is equal to the initial memory size "
2131 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2137 } else if (qemu_opt_get(opts
, "slots")) {
2138 error_report("invalid -m option value: missing 'maxmem' option");
2145 static void qemu_create_machine(QDict
*qdict
)
2147 MachineClass
*machine_class
= select_machine(qdict
, &error_fatal
);
2148 object_set_machine_compat_props(machine_class
->compat_props
);
2150 set_memory_options(machine_class
);
2152 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2153 object_property_add_child(object_get_root(), "machine",
2154 OBJECT(current_machine
));
2155 object_property_add_child(container_get(OBJECT(current_machine
),
2157 "sysbus", OBJECT(sysbus_get_default()));
2159 if (machine_class
->minimum_page_bits
) {
2160 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2161 /* This would be a board error: specifying a minimum smaller than
2162 * a target's compile-time fixed setting.
2164 g_assert_not_reached();
2168 cpu_exec_init_all();
2171 if (machine_class
->hw_version
) {
2172 qemu_set_hw_version(machine_class
->hw_version
);
2176 * Get the default machine options from the machine if it is not already
2177 * specified either by the configuration file or by the command line.
2179 if (machine_class
->default_machine_opts
) {
2180 QDict
*default_opts
=
2181 keyval_parse(machine_class
->default_machine_opts
, NULL
, NULL
,
2183 qemu_apply_legacy_machine_options(default_opts
);
2184 object_set_properties_from_keyval(OBJECT(current_machine
), default_opts
,
2185 false, &error_abort
);
2186 qobject_unref(default_opts
);
2190 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2194 g
= g_malloc0(sizeof(*g
));
2195 g
->driver
= qemu_opt_get(opts
, "driver");
2196 g
->property
= qemu_opt_get(opts
, "property");
2197 g
->value
= qemu_opt_get(opts
, "value");
2198 qdev_prop_register_global(g
);
2203 * Return whether configuration group @group is stored in QemuOpts, or
2204 * recorded as one or more QDicts by qemu_record_config_group.
2206 static bool is_qemuopts_group(const char *group
)
2208 if (g_str_equal(group
, "object") ||
2209 g_str_equal(group
, "machine") ||
2210 g_str_equal(group
, "smp-opts")) {
2216 static void qemu_record_config_group(const char *group
, QDict
*dict
,
2217 bool from_json
, Error
**errp
)
2219 if (g_str_equal(group
, "object")) {
2220 Visitor
*v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2221 object_option_add_visitor(v
);
2223 } else if (g_str_equal(group
, "machine")) {
2225 * Cannot merge string-valued and type-safe dictionaries, so JSON
2226 * is not accepted yet for -M.
2229 keyval_merge(machine_opts_dict
, dict
, errp
);
2230 } else if (g_str_equal(group
, "smp-opts")) {
2231 machine_merge_property("smp", dict
, &error_fatal
);
2238 * Parse non-QemuOpts config file groups, pass the rest to
2239 * qemu_config_do_parse.
2241 static void qemu_parse_config_group(const char *group
, QDict
*qdict
,
2242 void *opaque
, Error
**errp
)
2245 if (is_qemuopts_group(group
)) {
2246 qemu_config_do_parse(group
, qdict
, opaque
, errp
);
2250 crumpled
= qdict_crumple(qdict
, errp
);
2254 switch (qobject_type(crumpled
)) {
2256 qemu_record_config_group(group
, qobject_to(QDict
, crumpled
), false, errp
);
2259 error_setg(errp
, "Lists cannot be at top level of a configuration section");
2262 g_assert_not_reached();
2264 qobject_unref(crumpled
);
2267 static void qemu_read_default_config_file(Error
**errp
)
2271 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2273 ret
= qemu_read_config_file(file
, qemu_parse_config_group
, errp
);
2275 if (ret
== -ENOENT
) {
2282 static void qemu_set_option(const char *str
, Error
**errp
)
2284 char group
[64], id
[64], arg
[64];
2289 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2290 if (rc
< 3 || str
[offset
] != '=') {
2291 error_setg(errp
, "can't parse: \"%s\"", str
);
2295 if (!is_qemuopts_group(group
)) {
2296 error_setg(errp
, "-set is not supported with %s", group
);
2298 list
= qemu_find_opts_err(group
, errp
);
2300 opts
= qemu_opts_find(list
, id
);
2302 error_setg(errp
, "there is no %s \"%s\" defined", group
, id
);
2305 qemu_opt_set(opts
, arg
, str
+ offset
+ 1, errp
);
2310 static void user_register_global_props(void)
2312 qemu_opts_foreach(qemu_find_opts("global"),
2313 global_init_func
, NULL
, NULL
);
2316 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2318 icount_configure(opts
, errp
);
2322 static int accelerator_set_property(void *opaque
,
2323 const char *name
, const char *value
,
2326 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2329 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2331 bool *p_init_failed
= opaque
;
2332 const char *acc
= qemu_opt_get(opts
, "accel");
2333 AccelClass
*ac
= accel_find(acc
);
2336 bool qtest_with_kvm
;
2338 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2341 *p_init_failed
= true;
2342 if (!qtest_with_kvm
) {
2343 error_report("invalid accelerator %s", acc
);
2347 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2348 object_apply_compat_props(OBJECT(accel
));
2349 qemu_opt_foreach(opts
, accelerator_set_property
,
2353 ret
= accel_init_machine(accel
, current_machine
);
2355 *p_init_failed
= true;
2356 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2357 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2365 static void configure_accelerators(const char *progname
)
2367 bool init_failed
= false;
2369 qemu_opts_foreach(qemu_find_opts("icount"),
2370 do_configure_icount
, NULL
, &error_fatal
);
2372 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2373 char **accel_list
, **tmp
;
2375 if (accelerators
== NULL
) {
2376 /* Select the default accelerator */
2377 bool have_tcg
= accel_find("tcg");
2378 bool have_kvm
= accel_find("kvm");
2380 if (have_tcg
&& have_kvm
) {
2381 if (g_str_has_suffix(progname
, "kvm")) {
2382 /* If the program name ends with "kvm", we prefer KVM */
2383 accelerators
= "kvm:tcg";
2385 accelerators
= "tcg:kvm";
2387 } else if (have_kvm
) {
2388 accelerators
= "kvm";
2389 } else if (have_tcg
) {
2390 accelerators
= "tcg";
2392 error_report("No accelerator selected and"
2393 " no default accelerator available");
2397 accel_list
= g_strsplit(accelerators
, ":", 0);
2399 for (tmp
= accel_list
; *tmp
; tmp
++) {
2401 * Filter invalid accelerators here, to prevent obscenities
2402 * such as "-machine accel=tcg,,thread=single".
2404 if (accel_find(*tmp
)) {
2405 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2408 error_report("invalid accelerator %s", *tmp
);
2411 g_strfreev(accel_list
);
2413 if (accelerators
!= NULL
) {
2414 error_report("The -accel and \"-machine accel=\" options are incompatible");
2419 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2420 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2422 error_report("no accelerator found");
2427 if (init_failed
&& !qtest_chrdev
) {
2428 AccelClass
*ac
= ACCEL_GET_CLASS(current_accel());
2429 error_report("falling back to %s", ac
->name
);
2432 if (icount_enabled() && !tcg_enabled()) {
2433 error_report("-icount is not allowed with hardware virtualization");
2438 static void create_default_memdev(MachineState
*ms
, const char *path
)
2441 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
2443 obj
= object_new(path
? TYPE_MEMORY_BACKEND_FILE
: TYPE_MEMORY_BACKEND_RAM
);
2445 object_property_set_str(obj
, "mem-path", path
, &error_fatal
);
2447 object_property_set_int(obj
, "size", ms
->ram_size
, &error_fatal
);
2448 object_property_add_child(object_get_objects_root(), mc
->default_ram_id
,
2450 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2451 object_property_set_bool(obj
, "x-use-canonical-path-for-ramblock-id",
2452 false, &error_fatal
);
2453 user_creatable_complete(USER_CREATABLE(obj
), &error_fatal
);
2455 object_property_set_str(OBJECT(ms
), "memory-backend", mc
->default_ram_id
,
2459 static void qemu_validate_options(const QDict
*machine_opts
)
2461 const char *kernel_filename
= qdict_get_try_str(machine_opts
, "kernel");
2462 const char *initrd_filename
= qdict_get_try_str(machine_opts
, "initrd");
2463 const char *kernel_cmdline
= qdict_get_try_str(machine_opts
, "append");
2465 if (kernel_filename
== NULL
) {
2466 if (kernel_cmdline
!= NULL
) {
2467 error_report("-append only allowed with -kernel option");
2471 if (initrd_filename
!= NULL
) {
2472 error_report("-initrd only allowed with -kernel option");
2477 if (loadvm
&& preconfig_requested
) {
2478 error_report("'preconfig' and 'loadvm' options are "
2479 "mutually exclusive");
2482 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2483 error_report("'preconfig' supports '-incoming defer' only");
2487 #ifdef CONFIG_CURSES
2488 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2489 error_report("curses display cannot be used with -daemonize");
2495 static void qemu_process_sugar_options(void)
2498 QObject
*smp
= qdict_get(machine_opts_dict
, "smp");
2499 if (smp
&& qobject_type(smp
) == QTYPE_QDICT
) {
2500 QObject
*cpus
= qdict_get(qobject_to(QDict
, smp
), "cpus");
2501 if (cpus
&& qobject_type(cpus
) == QTYPE_QSTRING
) {
2502 const char *val
= qstring_get_str(qobject_to(QString
, cpus
));
2503 object_register_sugar_prop("memory-backend", "prealloc-threads",
2507 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2511 int i
= select_watchdog(watchdog
);
2513 exit (i
== 1 ? 1 : 0);
2517 /* -action processing */
2520 * Process all the -action parameters parsed from cmdline.
2522 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2524 Error
*local_err
= NULL
;
2525 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2526 QObject
*ret
= NULL
;
2527 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2529 qobject_unref(qdict
);
2531 error_propagate(errp
, local_err
);
2537 static void qemu_process_early_options(void)
2539 #ifdef CONFIG_SECCOMP
2540 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2542 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2546 qemu_opts_foreach(qemu_find_opts("name"),
2547 parse_name
, NULL
, &error_fatal
);
2549 if (qemu_opts_foreach(qemu_find_opts("action"),
2550 process_runstate_actions
, NULL
, &error_fatal
)) {
2555 qemu_opts_foreach(qemu_find_opts("add-fd"),
2556 parse_add_fd
, NULL
, &error_fatal
);
2558 qemu_opts_foreach(qemu_find_opts("add-fd"),
2559 cleanup_add_fd
, NULL
, &error_fatal
);
2562 /* Open the logfile at this point and set the log mask if necessary. */
2564 qemu_set_log_filename(log_file
, &error_fatal
);
2568 mask
= qemu_str_to_log_mask(log_mask
);
2570 qemu_print_log_usage(stdout
);
2578 qemu_add_default_firmwarepath();
2581 static void qemu_process_help_options(void)
2584 * Check for -cpu help and -device help before we call select_machine(),
2585 * which will return an error if the architecture has no default machine
2586 * type and the user did not specify one, so that the user doesn't need
2587 * to say '-cpu help -machine something'.
2589 if (cpu_option
&& is_help_option(cpu_option
)) {
2590 list_cpus(cpu_option
);
2594 if (qemu_opts_foreach(qemu_find_opts("device"),
2595 device_help_func
, NULL
, NULL
)) {
2599 /* -L help lists the data directories and exits. */
2600 if (list_data_dirs
) {
2601 qemu_list_data_dirs();
2606 static void qemu_maybe_daemonize(const char *pid_file
)
2611 rcu_disable_atfork();
2613 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
2614 error_reportf_err(err
, "cannot create PID file: ");
2618 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
2619 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
2622 static void qemu_init_displays(void)
2626 /* init local displays */
2627 ds
= init_displaystate();
2628 qemu_display_init(ds
, &dpy
);
2630 /* must be after terminal init, SDL library changes signal handlers */
2631 os_setup_signal_handling();
2633 /* init remote displays */
2635 qemu_opts_foreach(qemu_find_opts("vnc"),
2636 vnc_init_func
, NULL
, &error_fatal
);
2640 qemu_spice
.display_init();
2644 static void qemu_init_board(void)
2646 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
2648 if (machine_class
->default_ram_id
&& current_machine
->ram_size
&&
2649 numa_uses_legacy_mem() && !current_machine
->ram_memdev_id
) {
2650 create_default_memdev(current_machine
, mem_path
);
2653 /* process plugin before CPUs are created, but once -smp has been parsed */
2654 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2656 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2657 machine_run_board_init(current_machine
);
2659 drive_check_orphaned();
2663 if (hax_enabled()) {
2664 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2669 static void qemu_create_cli_devices(void)
2675 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2676 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2678 /* init USB devices */
2679 if (machine_usb(current_machine
)) {
2680 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2684 /* init generic devices */
2685 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2686 qemu_opts_foreach(qemu_find_opts("device"),
2687 device_init_func
, NULL
, &error_fatal
);
2688 QTAILQ_FOREACH(opt
, &device_opts
, next
) {
2690 loc_push_restore(&opt
->loc
);
2692 * TODO Eventually we should call qmp_device_add() here to make sure it
2693 * behaves the same, but QMP still has to accept incorrectly typed
2694 * options until libvirt is fixed and we want to be strict on the CLI
2695 * from the start, so call qdev_device_add_from_qdict() directly for
2698 dev
= qdev_device_add_from_qdict(opt
->opts
, true, &error_fatal
);
2699 object_unref(OBJECT(dev
));
2702 rom_reset_order_override();
2705 static void qemu_machine_creation_done(void)
2707 MachineState
*machine
= MACHINE(qdev_get_machine());
2709 /* Did we create any drives that we failed to create a device for? */
2710 drive_check_orphaned();
2712 /* Don't warn about the default network setup that you get if
2713 * no command line -net or -netdev options are specified. There
2714 * are two cases that we would otherwise complain about:
2715 * (1) board doesn't support a NIC but the implicit "-net nic"
2717 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2718 * sets up a nic that isn't connected to anything.
2720 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2721 net_check_clients();
2724 qdev_prop_check_globals();
2726 qdev_machine_creation_done();
2730 * Verify that Confidential Guest Support has actually been initialized
2732 assert(machine
->cgs
->ready
);
2735 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2740 void qmp_x_exit_preconfig(Error
**errp
)
2742 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2743 error_setg(errp
, "The command is permitted only before machine initialization");
2748 qemu_create_cli_devices();
2749 qemu_machine_creation_done();
2752 load_snapshot(loadvm
, NULL
, false, NULL
, &error_fatal
);
2754 if (replay_mode
!= REPLAY_MODE_NONE
) {
2755 replay_vmstate_init();
2759 Error
*local_err
= NULL
;
2760 if (strcmp(incoming
, "defer") != 0) {
2761 qmp_migrate_incoming(incoming
, &local_err
);
2763 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2767 } else if (autostart
) {
2772 void qemu_init(int argc
, char **argv
, char **envp
)
2775 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2776 QemuOptsList
*olist
;
2779 MachineClass
*machine_class
;
2780 bool userconfig
= true;
2781 FILE *vmstate_dump_file
= NULL
;
2783 qemu_add_opts(&qemu_drive_opts
);
2784 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2785 qemu_add_drive_opts(&qemu_common_drive_opts
);
2786 qemu_add_drive_opts(&qemu_drive_opts
);
2787 qemu_add_drive_opts(&bdrv_runtime_opts
);
2788 qemu_add_opts(&qemu_chardev_opts
);
2789 qemu_add_opts(&qemu_device_opts
);
2790 qemu_add_opts(&qemu_netdev_opts
);
2791 qemu_add_opts(&qemu_nic_opts
);
2792 qemu_add_opts(&qemu_net_opts
);
2793 qemu_add_opts(&qemu_rtc_opts
);
2794 qemu_add_opts(&qemu_global_opts
);
2795 qemu_add_opts(&qemu_mon_opts
);
2796 qemu_add_opts(&qemu_trace_opts
);
2797 qemu_plugin_add_opts();
2798 qemu_add_opts(&qemu_option_rom_opts
);
2799 qemu_add_opts(&qemu_accel_opts
);
2800 qemu_add_opts(&qemu_mem_opts
);
2801 qemu_add_opts(&qemu_smp_opts
);
2802 qemu_add_opts(&qemu_boot_opts
);
2803 qemu_add_opts(&qemu_add_fd_opts
);
2804 qemu_add_opts(&qemu_object_opts
);
2805 qemu_add_opts(&qemu_tpmdev_opts
);
2806 qemu_add_opts(&qemu_overcommit_opts
);
2807 qemu_add_opts(&qemu_msg_opts
);
2808 qemu_add_opts(&qemu_name_opts
);
2809 qemu_add_opts(&qemu_numa_opts
);
2810 qemu_add_opts(&qemu_icount_opts
);
2811 qemu_add_opts(&qemu_semihosting_config_opts
);
2812 qemu_add_opts(&qemu_fw_cfg_opts
);
2813 qemu_add_opts(&qemu_action_opts
);
2814 module_call_init(MODULE_INIT_OPTS
);
2816 error_init(argv
[0]);
2817 qemu_init_exec_dir(argv
[0]);
2819 qemu_init_arch_modules();
2821 qemu_init_subsystems();
2823 /* first pass of option parsing */
2825 while (optind
< argc
) {
2826 if (argv
[optind
][0] != '-') {
2830 const QEMUOption
*popt
;
2832 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2833 switch (popt
->index
) {
2834 case QEMU_OPTION_nouserconfig
:
2841 machine_opts_dict
= qdict_new();
2843 qemu_read_default_config_file(&error_fatal
);
2846 /* second pass of option parsing */
2851 if (argv
[optind
][0] != '-') {
2852 loc_set_cmdline(argv
, optind
, 1);
2853 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2855 const QEMUOption
*popt
;
2857 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2858 if (!(popt
->arch_mask
& arch_type
)) {
2859 error_report("Option not supported for this target");
2862 switch(popt
->index
) {
2863 case QEMU_OPTION_cpu
:
2864 /* hw initialization will check this */
2865 cpu_option
= optarg
;
2867 case QEMU_OPTION_hda
:
2868 case QEMU_OPTION_hdb
:
2869 case QEMU_OPTION_hdc
:
2870 case QEMU_OPTION_hdd
:
2871 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2874 case QEMU_OPTION_blockdev
:
2877 BlockdevOptionsQueueEntry
*bdo
;
2879 v
= qobject_input_visitor_new_str(optarg
, "driver",
2882 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2883 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2886 loc_save(&bdo
->loc
);
2887 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2890 case QEMU_OPTION_drive
:
2891 opts
= qemu_opts_parse_noisily(qemu_find_opts("drive"),
2897 case QEMU_OPTION_set
:
2898 qemu_set_option(optarg
, &error_fatal
);
2900 case QEMU_OPTION_global
:
2901 if (qemu_global_option(optarg
) != 0)
2904 case QEMU_OPTION_mtdblock
:
2905 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2907 case QEMU_OPTION_sd
:
2908 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2910 case QEMU_OPTION_pflash
:
2911 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2913 case QEMU_OPTION_snapshot
:
2915 Error
*blocker
= NULL
;
2917 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
2919 replay_add_blocker(blocker
);
2922 case QEMU_OPTION_numa
:
2923 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2929 case QEMU_OPTION_display
:
2930 parse_display(optarg
);
2932 case QEMU_OPTION_nographic
:
2933 qdict_put_str(machine_opts_dict
, "graphics", "off");
2935 dpy
.type
= DISPLAY_TYPE_NONE
;
2937 case QEMU_OPTION_curses
:
2938 warn_report("-curses is deprecated, "
2939 "use -display curses instead.");
2940 #ifdef CONFIG_CURSES
2941 dpy
.type
= DISPLAY_TYPE_CURSES
;
2943 error_report("curses or iconv support is disabled");
2947 case QEMU_OPTION_portrait
:
2948 graphic_rotate
= 90;
2950 case QEMU_OPTION_rotate
:
2951 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2952 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2953 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2954 error_report("only 90, 180, 270 deg rotation is available");
2958 case QEMU_OPTION_kernel
:
2959 qdict_put_str(machine_opts_dict
, "kernel", optarg
);
2961 case QEMU_OPTION_initrd
:
2962 qdict_put_str(machine_opts_dict
, "initrd", optarg
);
2964 case QEMU_OPTION_append
:
2965 qdict_put_str(machine_opts_dict
, "append", optarg
);
2967 case QEMU_OPTION_dtb
:
2968 qdict_put_str(machine_opts_dict
, "dtb", optarg
);
2970 case QEMU_OPTION_cdrom
:
2971 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2973 case QEMU_OPTION_boot
:
2974 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2980 case QEMU_OPTION_fda
:
2981 case QEMU_OPTION_fdb
:
2982 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2985 case QEMU_OPTION_no_fd_bootchk
:
2988 case QEMU_OPTION_netdev
:
2990 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2994 case QEMU_OPTION_nic
:
2996 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
3000 case QEMU_OPTION_net
:
3002 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3006 #ifdef CONFIG_LIBISCSI
3007 case QEMU_OPTION_iscsi
:
3008 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3015 case QEMU_OPTION_audio_help
:
3016 audio_legacy_help();
3019 case QEMU_OPTION_audiodev
:
3020 audio_parse_option(optarg
);
3022 case QEMU_OPTION_soundhw
:
3023 select_soundhw (optarg
);
3028 case QEMU_OPTION_version
:
3033 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3040 case QEMU_OPTION_tpmdev
:
3041 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3046 case QEMU_OPTION_mempath
:
3049 case QEMU_OPTION_mem_prealloc
:
3058 case QEMU_OPTION_DFILTER
:
3059 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3061 case QEMU_OPTION_seed
:
3062 qemu_guest_random_seed_main(optarg
, &error_fatal
);
3065 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3067 case QEMU_OPTION_gdb
:
3068 add_device_config(DEV_GDB
, optarg
);
3071 if (is_help_option(optarg
)) {
3072 list_data_dirs
= true;
3074 qemu_add_data_dir(g_strdup(optarg
));
3077 case QEMU_OPTION_bios
:
3078 qdict_put_str(machine_opts_dict
, "firmware", optarg
);
3080 case QEMU_OPTION_singlestep
:
3087 keyboard_layout
= optarg
;
3089 case QEMU_OPTION_vga
:
3098 w
= strtol(p
, (char **)&p
, 10);
3101 error_report("invalid resolution or depth");
3107 h
= strtol(p
, (char **)&p
, 10);
3112 depth
= strtol(p
, (char **)&p
, 10);
3113 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
3114 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3115 depth
!= 24 && depth
!= 32)
3117 } else if (*p
== '\0') {
3118 depth
= graphic_depth
;
3125 graphic_depth
= depth
;
3128 case QEMU_OPTION_echr
:
3131 term_escape_char
= strtol(optarg
, &r
, 0);
3133 printf("Bad argument to echr\n");
3136 case QEMU_OPTION_monitor
:
3137 default_monitor
= 0;
3138 if (strncmp(optarg
, "none", 4)) {
3139 monitor_parse(optarg
, "readline", false);
3142 case QEMU_OPTION_qmp
:
3143 monitor_parse(optarg
, "control", false);
3144 default_monitor
= 0;
3146 case QEMU_OPTION_qmp_pretty
:
3147 monitor_parse(optarg
, "control", true);
3148 default_monitor
= 0;
3150 case QEMU_OPTION_mon
:
3151 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3156 default_monitor
= 0;
3158 case QEMU_OPTION_chardev
:
3159 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3165 case QEMU_OPTION_fsdev
:
3166 olist
= qemu_find_opts("fsdev");
3168 error_report("fsdev support is disabled");
3171 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3176 case QEMU_OPTION_virtfs
: {
3179 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3182 olist
= qemu_find_opts("virtfs");
3184 error_report("virtfs support is disabled");
3187 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3192 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3193 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3194 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3197 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3198 qemu_opts_id(opts
) ?:
3199 qemu_opt_get(opts
, "mount_tag"),
3202 error_report("duplicate or invalid fsdev id: %s",
3203 qemu_opt_get(opts
, "mount_tag"));
3207 writeout
= qemu_opt_get(opts
, "writeout");
3209 #ifdef CONFIG_SYNC_FILE_RANGE
3210 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3212 error_report("writeout=immediate not supported "
3213 "on this platform");
3217 qemu_opt_set(fsdev
, "fsdriver",
3218 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3219 path
= qemu_opt_get(opts
, "path");
3221 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3223 security_model
= qemu_opt_get(opts
, "security_model");
3224 if (security_model
) {
3225 qemu_opt_set(fsdev
, "security_model", security_model
,
3228 socket
= qemu_opt_get(opts
, "socket");
3230 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3232 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3234 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3237 qemu_opt_set_bool(fsdev
, "readonly",
3238 qemu_opt_get_bool(opts
, "readonly", 0),
3240 multidevs
= qemu_opt_get(opts
, "multidevs");
3242 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3244 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3246 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3247 qemu_opt_set(device
, "fsdev",
3248 qemu_opts_id(fsdev
), &error_abort
);
3249 qemu_opt_set(device
, "mount_tag",
3250 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3253 case QEMU_OPTION_serial
:
3254 add_device_config(DEV_SERIAL
, optarg
);
3256 if (strncmp(optarg
, "mon:", 4) == 0) {
3257 default_monitor
= 0;
3260 case QEMU_OPTION_watchdog
:
3262 error_report("only one watchdog option may be given");
3265 warn_report("-watchdog is deprecated; use -device instead.");
3268 case QEMU_OPTION_action
:
3269 olist
= qemu_find_opts("action");
3270 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3274 case QEMU_OPTION_watchdog_action
: {
3276 opts
= qemu_opts_create(qemu_find_opts("action"), NULL
, 0, &error_abort
);
3277 qemu_opt_set(opts
, "watchdog", optarg
, &error_abort
);
3280 case QEMU_OPTION_parallel
:
3281 add_device_config(DEV_PARALLEL
, optarg
);
3282 default_parallel
= 0;
3283 if (strncmp(optarg
, "mon:", 4) == 0) {
3284 default_monitor
= 0;
3287 case QEMU_OPTION_debugcon
:
3288 add_device_config(DEV_DEBUGCON
, optarg
);
3290 case QEMU_OPTION_loadvm
:
3293 case QEMU_OPTION_full_screen
:
3294 dpy
.has_full_screen
= true;
3295 dpy
.full_screen
= true;
3297 case QEMU_OPTION_alt_grab
:
3299 warn_report("-alt-grab is deprecated, please use "
3300 "-display sdl,grab-mod=lshift-lctrl-lalt instead.");
3302 case QEMU_OPTION_ctrl_grab
:
3304 warn_report("-ctrl-grab is deprecated, please use "
3305 "-display sdl,grab-mod=rctrl instead.");
3307 case QEMU_OPTION_sdl
:
3308 warn_report("-sdl is deprecated, use -display sdl instead.");
3310 dpy
.type
= DISPLAY_TYPE_SDL
;
3313 error_report("SDL support is disabled");
3316 case QEMU_OPTION_pidfile
:
3319 case QEMU_OPTION_win2k_hack
:
3320 win2k_install_hack
= 1;
3322 case QEMU_OPTION_acpitable
:
3323 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3328 acpi_table_add(opts
, &error_fatal
);
3330 case QEMU_OPTION_smbios
:
3331 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3336 smbios_entry_add(opts
, &error_fatal
);
3338 case QEMU_OPTION_fwcfg
:
3339 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3345 case QEMU_OPTION_preconfig
:
3346 preconfig_requested
= true;
3348 case QEMU_OPTION_enable_kvm
:
3349 qdict_put_str(machine_opts_dict
, "accel", "kvm");
3352 case QEMU_OPTION_machine
:
3356 keyval_parse_into(machine_opts_dict
, optarg
, "type", &help
, &error_fatal
);
3358 machine_help_func(machine_opts_dict
);
3363 case QEMU_OPTION_accel
:
3364 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3366 optarg
= qemu_opt_get(accel_opts
, "accel");
3367 if (!optarg
|| is_help_option(optarg
)) {
3368 printf("Accelerators supported in QEMU binary:\n");
3369 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3371 for (el
= accel_list
; el
; el
= el
->next
) {
3372 gchar
*typename
= g_strdup(object_class_get_name(
3373 OBJECT_CLASS(el
->data
)));
3374 /* omit qtest which is used for tests only */
3375 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3376 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3377 gchar
**optname
= g_strsplit(typename
,
3378 ACCEL_CLASS_SUFFIX
, 0);
3379 printf("%s\n", optname
[0]);
3380 g_strfreev(optname
);
3384 g_slist_free(accel_list
);
3388 case QEMU_OPTION_usb
:
3389 qdict_put_str(machine_opts_dict
, "usb", "on");
3391 case QEMU_OPTION_usbdevice
:
3392 qdict_put_str(machine_opts_dict
, "usb", "on");
3393 add_device_config(DEV_USB
, optarg
);
3395 case QEMU_OPTION_device
:
3396 if (optarg
[0] == '{') {
3397 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
3398 DeviceOption
*opt
= g_new0(DeviceOption
, 1);
3399 opt
->opts
= qobject_to(QDict
, obj
);
3400 loc_save(&opt
->loc
);
3401 assert(opt
->opts
!= NULL
);
3402 QTAILQ_INSERT_TAIL(&device_opts
, opt
, next
);
3404 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3410 case QEMU_OPTION_smp
:
3411 machine_parse_property_opt(qemu_find_opts("smp-opts"),
3414 case QEMU_OPTION_vnc
:
3417 case QEMU_OPTION_no_acpi
:
3418 qdict_put_str(machine_opts_dict
, "acpi", "off");
3420 case QEMU_OPTION_no_hpet
:
3421 qdict_put_str(machine_opts_dict
, "hpet", "off");
3423 case QEMU_OPTION_no_reboot
:
3424 olist
= qemu_find_opts("action");
3425 qemu_opts_parse_noisily(olist
, "reboot=shutdown", false);
3427 case QEMU_OPTION_no_shutdown
:
3428 olist
= qemu_find_opts("action");
3429 qemu_opts_parse_noisily(olist
, "shutdown=pause", false);
3431 case QEMU_OPTION_uuid
:
3432 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3433 error_report("failed to parse UUID string: wrong format");
3436 qemu_uuid_set
= true;
3438 case QEMU_OPTION_option_rom
:
3439 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3440 error_report("too many option ROMs");
3443 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3448 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3449 option_rom
[nb_option_roms
].bootindex
=
3450 qemu_opt_get_number(opts
, "bootindex", -1);
3451 if (!option_rom
[nb_option_roms
].name
) {
3452 error_report("Option ROM file is not specified");
3457 case QEMU_OPTION_semihosting
:
3458 qemu_semihosting_enable();
3460 case QEMU_OPTION_semihosting_config
:
3461 if (qemu_semihosting_config_options(optarg
) != 0) {
3465 case QEMU_OPTION_name
:
3466 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3471 /* Capture guest name if -msg guest-name is used later */
3472 error_guest_name
= qemu_opt_get(opts
, "guest");
3474 case QEMU_OPTION_prom_env
:
3475 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3476 error_report("too many prom variables");
3479 prom_envs
[nb_prom_envs
] = optarg
;
3482 case QEMU_OPTION_old_param
:
3485 case QEMU_OPTION_rtc
:
3486 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3492 case QEMU_OPTION_icount
:
3493 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3499 case QEMU_OPTION_incoming
:
3501 runstate_set(RUN_STATE_INMIGRATE
);
3505 case QEMU_OPTION_only_migratable
:
3506 only_migratable
= 1;
3508 case QEMU_OPTION_nodefaults
:
3511 case QEMU_OPTION_xen_domid
:
3512 if (!(accel_find("xen"))) {
3513 error_report("Option not supported for this target");
3516 xen_domid
= atoi(optarg
);
3518 case QEMU_OPTION_xen_attach
:
3519 if (!(accel_find("xen"))) {
3520 error_report("Option not supported for this target");
3523 xen_mode
= XEN_ATTACH
;
3525 case QEMU_OPTION_xen_domid_restrict
:
3526 if (!(accel_find("xen"))) {
3527 error_report("Option not supported for this target");
3530 xen_domid_restrict
= true;
3532 case QEMU_OPTION_trace
:
3533 trace_opt_parse(optarg
);
3535 case QEMU_OPTION_plugin
:
3536 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3538 case QEMU_OPTION_readconfig
:
3539 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);
3555 case QEMU_OPTION_writeconfig
:
3558 warn_report("-writeconfig is deprecated and will go away without a replacement");
3559 if (strcmp(optarg
, "-") == 0) {
3562 fp
= fopen(optarg
, "w");
3564 error_report("open %s: %s", optarg
,
3569 qemu_config_write(fp
);
3575 case QEMU_OPTION_qtest
:
3576 qtest_chrdev
= optarg
;
3578 case QEMU_OPTION_qtest_log
:
3581 case QEMU_OPTION_sandbox
:
3582 olist
= qemu_find_opts("sandbox");
3584 #ifndef CONFIG_SECCOMP
3585 error_report("-sandbox support is not enabled "
3586 "in this QEMU binary");
3591 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3596 case QEMU_OPTION_add_fd
:
3598 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3604 error_report("File descriptor passing is disabled on this "
3609 case QEMU_OPTION_object
:
3610 object_option_parse(optarg
);
3612 case QEMU_OPTION_overcommit
:
3613 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3618 enable_mlock
= qemu_opt_get_bool(opts
, "mem-lock", false);
3619 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3621 case QEMU_OPTION_compat
:
3626 v
= qobject_input_visitor_new_str(optarg
, NULL
,
3629 visit_type_CompatPolicy(v
, NULL
, &opts
, &error_fatal
);
3630 QAPI_CLONE_MEMBERS(CompatPolicy
, &compat_policy
, opts
);
3632 qapi_free_CompatPolicy(opts
);
3636 case QEMU_OPTION_msg
:
3637 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3642 configure_msg(opts
);
3644 case QEMU_OPTION_dump_vmstate
:
3645 if (vmstate_dump_file
) {
3646 error_report("only one '-dump-vmstate' "
3647 "option may be given");
3650 vmstate_dump_file
= fopen(optarg
, "w");
3651 if (vmstate_dump_file
== NULL
) {
3652 error_report("open %s: %s", optarg
, strerror(errno
));
3656 case QEMU_OPTION_enable_sync_profile
:
3659 case QEMU_OPTION_nouserconfig
:
3660 /* Nothing to be parsed here. Especially, do not error out below. */
3663 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3664 error_report("Option not supported in this build");
3671 * Clear error location left behind by the loop.
3672 * Best done right after the loop. Do not insert code here!
3676 qemu_validate_options(machine_opts_dict
);
3677 qemu_process_sugar_options();
3680 * These options affect everything else and should be processed
3681 * before daemonizing.
3683 qemu_process_early_options();
3685 qemu_process_help_options();
3686 qemu_maybe_daemonize(pid_file
);
3689 * The trace backend must be initialized after daemonizing.
3690 * trace_init_backends() will call st_init(), which will create the
3691 * trace thread in the parent, and also register st_flush_trace_buffer()
3692 * in atexit(). This function will force the parent to wait for the
3693 * writeout thread to finish, which will not occur, and the parent
3694 * process will be left in the host.
3696 if (!trace_init_backends()) {
3701 qemu_init_main_loop(&error_fatal
);
3704 user_register_global_props();
3705 replay_configure(icount_opts
);
3707 configure_rtc(qemu_find_opts_singleton("rtc"));
3709 qemu_create_machine(machine_opts_dict
);
3713 qemu_disable_default_devices();
3714 qemu_create_default_devices();
3715 qemu_create_early_backends();
3717 qemu_apply_legacy_machine_options(machine_opts_dict
);
3718 qemu_apply_machine_options(machine_opts_dict
);
3719 qobject_unref(machine_opts_dict
);
3720 phase_advance(PHASE_MACHINE_CREATED
);
3723 * Note: uses machine properties such as kernel-irqchip, must run
3724 * after qemu_apply_machine_options.
3726 configure_accelerators(argv
[0]);
3727 phase_advance(PHASE_ACCEL_CREATED
);
3730 * Beware, QOM objects created before this point miss global and
3731 * compat properties.
3733 * Global properties get set up by qdev_prop_register_global(),
3734 * called from user_register_global_props(), and certain option
3735 * desugaring. Also in CPU feature desugaring (buried in
3736 * parse_cpu_option()), which happens below this point, but may
3737 * only target the CPU type, which can only be created after
3738 * parse_cpu_option() returned the type.
3740 * Machine compat properties: object_set_machine_compat_props().
3741 * Accelerator compat props: object_set_accelerator_compat_props(),
3742 * called from do_configure_accelerator().
3745 machine_class
= MACHINE_GET_CLASS(current_machine
);
3746 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
3747 error_report("Machine type '%s' is deprecated: %s",
3748 machine_class
->name
, machine_class
->deprecation_reason
);
3752 * Note: creates a QOM object, must run only after global and
3753 * compat properties have been set up.
3755 migration_object_init();
3757 qemu_create_late_backends();
3759 /* parse features once if machine provides default cpu_type */
3760 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
3762 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
3764 /* NB: for machine none cpu_type could STILL be NULL here! */
3766 qemu_resolve_machine_memdev();
3767 parse_numa_opts(current_machine
);
3769 if (vmstate_dump_file
) {
3771 module_load_qom_all();
3772 dump_vmstate_json_to_file(vmstate_dump_file
);
3776 if (!preconfig_requested
) {
3777 qmp_x_exit_preconfig(&error_fatal
);
3779 qemu_init_displays();
3780 accel_setup_post(current_machine
);