4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
26 #include "qemu-common.h"
27 #include "qemu/datadir.h"
28 #include "qemu/units.h"
29 #include "exec/cpu-common.h"
30 #include "hw/qdev-properties.h"
31 #include "qapi/compat-policy.h"
32 #include "qapi/error.h"
33 #include "qapi/qmp/qdict.h"
34 #include "qapi/qmp/qstring.h"
35 #include "qapi/qmp/qjson.h"
36 #include "qemu-version.h"
37 #include "qemu/cutils.h"
38 #include "qemu/help_option.h"
39 #include "qemu/uuid.h"
40 #include "sysemu/reset.h"
41 #include "sysemu/runstate.h"
42 #include "sysemu/runstate-action.h"
43 #include "sysemu/seccomp.h"
44 #include "sysemu/tcg.h"
45 #include "sysemu/xen.h"
47 #include "qemu/error-report.h"
48 #include "qemu/sockets.h"
49 #include "qemu/accel.h"
51 #include "hw/isa/isa.h"
52 #include "hw/scsi/scsi.h"
53 #include "hw/display/vga.h"
54 #include "sysemu/watchdog.h"
55 #include "hw/firmware/smbios.h"
56 #include "hw/acpi/acpi.h"
57 #include "hw/xen/xen.h"
58 #include "hw/loader.h"
59 #include "monitor/qdev.h"
61 #include "net/slirp.h"
62 #include "monitor/monitor.h"
63 #include "ui/console.h"
65 #include "sysemu/sysemu.h"
66 #include "sysemu/numa.h"
67 #include "sysemu/hostmem.h"
68 #include "exec/gdbstub.h"
69 #include "qemu/timer.h"
70 #include "chardev/char.h"
71 #include "qemu/bitmap.h"
73 #include "sysemu/blockdev.h"
74 #include "hw/block/block.h"
75 #include "hw/i386/x86.h"
76 #include "hw/i386/pc.h"
77 #include "migration/misc.h"
78 #include "migration/snapshot.h"
79 #include "sysemu/tpm.h"
80 #include "sysemu/dma.h"
81 #include "hw/audio/soundhw.h"
82 #include "audio/audio.h"
83 #include "sysemu/cpus.h"
84 #include "sysemu/cpu-timers.h"
85 #include "migration/colo.h"
86 #include "migration/postcopy-ram.h"
87 #include "sysemu/kvm.h"
88 #include "sysemu/hax.h"
89 #include "qapi/qobject-input-visitor.h"
90 #include "qemu/option.h"
91 #include "qemu/config-file.h"
92 #include "qemu/qemu-options.h"
93 #include "qemu/main-loop.h"
95 #include "fsdev/qemu-fsdev.h"
97 #include "sysemu/qtest.h"
99 #include "disas/disas.h"
102 #include "trace/control.h"
103 #include "qemu/plugin.h"
104 #include "qemu/queue.h"
105 #include "sysemu/arch_init.h"
106 #include "exec/confidential-guest-support.h"
108 #include "ui/qemu-spice.h"
109 #include "qapi/string-input-visitor.h"
110 #include "qapi/opts-visitor.h"
111 #include "qapi/clone-visitor.h"
112 #include "qom/object_interfaces.h"
113 #include "semihosting/semihost.h"
114 #include "crypto/init.h"
115 #include "sysemu/replay.h"
116 #include "qapi/qapi-events-run-state.h"
117 #include "qapi/qapi-visit-block-core.h"
118 #include "qapi/qapi-visit-compat.h"
119 #include "qapi/qapi-visit-ui.h"
120 #include "qapi/qapi-commands-block-core.h"
121 #include "qapi/qapi-commands-migration.h"
122 #include "qapi/qapi-commands-misc.h"
123 #include "qapi/qapi-visit-qom.h"
124 #include "qapi/qapi-commands-ui.h"
125 #include "qapi/qmp/qdict.h"
126 #include "qapi/qmp/qerror.h"
127 #include "sysemu/iothread.h"
128 #include "qemu/guest-random.h"
130 #include "config-host.h"
132 #define MAX_VIRTIO_CONSOLES 1
134 typedef struct BlockdevOptionsQueueEntry
{
135 BlockdevOptions
*bdo
;
137 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
138 } BlockdevOptionsQueueEntry
;
140 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
142 typedef struct ObjectOption
{
144 QTAILQ_ENTRY(ObjectOption
) next
;
147 typedef struct DeviceOption
{
150 QTAILQ_ENTRY(DeviceOption
) next
;
153 static const char *cpu_option
;
154 static const char *mem_path
;
155 static const char *incoming
;
156 static const char *loadvm
;
157 static const char *accelerators
;
158 static QDict
*machine_opts_dict
;
159 static QTAILQ_HEAD(, ObjectOption
) object_opts
= QTAILQ_HEAD_INITIALIZER(object_opts
);
160 static QTAILQ_HEAD(, DeviceOption
) device_opts
= QTAILQ_HEAD_INITIALIZER(device_opts
);
161 static ram_addr_t maxram_size
;
162 static uint64_t ram_slots
;
163 static int display_remote
;
165 static bool preconfig_requested
;
166 static QemuPluginList plugin_list
= QTAILQ_HEAD_INITIALIZER(plugin_list
);
167 static BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
168 static bool nographic
= false;
169 static int mem_prealloc
; /* force preallocation of physical target memory */
170 static ram_addr_t ram_size
;
171 static const char *vga_model
= NULL
;
172 static DisplayOptions dpy
;
173 static int num_serial_hds
;
174 static Chardev
**serial_hds
;
175 static const char *log_mask
;
176 static const char *log_file
;
177 static bool list_data_dirs
;
178 static const char *watchdog
;
179 static const char *qtest_chrdev
;
180 static const char *qtest_log
;
182 static int has_defaults
= 1;
183 static int default_serial
= 1;
184 static int default_parallel
= 1;
185 static int default_monitor
= 1;
186 static int default_floppy
= 1;
187 static int default_cdrom
= 1;
188 static int default_sdcard
= 1;
189 static int default_vga
= 1;
190 static int default_net
= 1;
196 { .driver
= "isa-serial", .flag
= &default_serial
},
197 { .driver
= "isa-parallel", .flag
= &default_parallel
},
198 { .driver
= "isa-fdc", .flag
= &default_floppy
},
199 { .driver
= "floppy", .flag
= &default_floppy
},
200 { .driver
= "ide-cd", .flag
= &default_cdrom
},
201 { .driver
= "ide-hd", .flag
= &default_cdrom
},
202 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
203 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
204 { .driver
= "VGA", .flag
= &default_vga
},
205 { .driver
= "isa-vga", .flag
= &default_vga
},
206 { .driver
= "cirrus-vga", .flag
= &default_vga
},
207 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
208 { .driver
= "vmware-svga", .flag
= &default_vga
},
209 { .driver
= "qxl-vga", .flag
= &default_vga
},
210 { .driver
= "virtio-vga", .flag
= &default_vga
},
211 { .driver
= "ati-vga", .flag
= &default_vga
},
212 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
213 { .driver
= "virtio-vga-gl", .flag
= &default_vga
},
216 static QemuOptsList qemu_rtc_opts
= {
218 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
223 .type
= QEMU_OPT_STRING
,
226 .type
= QEMU_OPT_STRING
,
229 .type
= QEMU_OPT_STRING
,
231 { /* end of list */ }
235 static QemuOptsList qemu_option_rom_opts
= {
236 .name
= "option-rom",
237 .implied_opt_name
= "romfile",
238 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
242 .type
= QEMU_OPT_NUMBER
,
245 .type
= QEMU_OPT_STRING
,
247 { /* end of list */ }
251 static QemuOptsList qemu_accel_opts
= {
253 .implied_opt_name
= "accel",
254 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
257 * no elements => accept any
258 * sanity checking will happen later
259 * when setting accelerator properties
265 static QemuOptsList qemu_boot_opts
= {
267 .implied_opt_name
= "order",
269 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
273 .type
= QEMU_OPT_STRING
,
276 .type
= QEMU_OPT_STRING
,
279 .type
= QEMU_OPT_BOOL
,
282 .type
= QEMU_OPT_STRING
,
284 .name
= "splash-time",
285 .type
= QEMU_OPT_NUMBER
,
287 .name
= "reboot-timeout",
288 .type
= QEMU_OPT_NUMBER
,
291 .type
= QEMU_OPT_BOOL
,
297 static QemuOptsList qemu_add_fd_opts
= {
299 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
303 .type
= QEMU_OPT_NUMBER
,
304 .help
= "file descriptor of which a duplicate is added to fd set",
307 .type
= QEMU_OPT_NUMBER
,
308 .help
= "ID of the fd set to add fd to",
311 .type
= QEMU_OPT_STRING
,
312 .help
= "free-form string used to describe fd",
314 { /* end of list */ }
318 static QemuOptsList qemu_object_opts
= {
320 .implied_opt_name
= "qom-type",
321 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
327 static QemuOptsList qemu_tpmdev_opts
= {
329 .implied_opt_name
= "type",
330 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
332 /* options are defined in the TPM backends */
333 { /* end of list */ }
337 static QemuOptsList qemu_overcommit_opts
= {
338 .name
= "overcommit",
339 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
343 .type
= QEMU_OPT_BOOL
,
347 .type
= QEMU_OPT_BOOL
,
349 { /* end of list */ }
353 static QemuOptsList qemu_msg_opts
= {
355 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
359 .type
= QEMU_OPT_BOOL
,
362 .name
= "guest-name",
363 .type
= QEMU_OPT_BOOL
,
364 .help
= "Prepends guest name for error messages but only if "
365 "-name guest is set otherwise option is ignored\n",
367 { /* end of list */ }
371 static QemuOptsList qemu_name_opts
= {
373 .implied_opt_name
= "guest",
375 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
379 .type
= QEMU_OPT_STRING
,
380 .help
= "Sets the name of the guest.\n"
381 "This name will be displayed in the SDL window caption.\n"
382 "The name will also be used for the VNC server",
385 .type
= QEMU_OPT_STRING
,
386 .help
= "Sets the name of the QEMU process, as shown in top etc",
388 .name
= "debug-threads",
389 .type
= QEMU_OPT_BOOL
,
390 .help
= "When enabled, name the individual threads; defaults off.\n"
391 "NOTE: The thread names are for debugging and not a\n"
394 { /* End of list */ }
398 static QemuOptsList qemu_mem_opts
= {
400 .implied_opt_name
= "size",
401 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
406 .type
= QEMU_OPT_SIZE
,
410 .type
= QEMU_OPT_NUMBER
,
414 .type
= QEMU_OPT_SIZE
,
416 { /* end of list */ }
420 static QemuOptsList qemu_icount_opts
= {
422 .implied_opt_name
= "shift",
424 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
428 .type
= QEMU_OPT_STRING
,
431 .type
= QEMU_OPT_BOOL
,
434 .type
= QEMU_OPT_BOOL
,
437 .type
= QEMU_OPT_STRING
,
440 .type
= QEMU_OPT_STRING
,
442 .name
= "rrsnapshot",
443 .type
= QEMU_OPT_STRING
,
445 { /* end of list */ }
449 static QemuOptsList qemu_fw_cfg_opts
= {
451 .implied_opt_name
= "name",
452 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
456 .type
= QEMU_OPT_STRING
,
457 .help
= "Sets the fw_cfg name of the blob to be inserted",
460 .type
= QEMU_OPT_STRING
,
461 .help
= "Sets the name of the file from which "
462 "the fw_cfg blob will be loaded",
465 .type
= QEMU_OPT_STRING
,
466 .help
= "Sets content of the blob to be inserted from a string",
469 .type
= QEMU_OPT_STRING
,
470 .help
= "Sets id of the object generating the fw_cfg blob "
473 { /* end of list */ }
477 static QemuOptsList qemu_action_opts
= {
480 .head
= QTAILQ_HEAD_INITIALIZER(qemu_action_opts
.head
),
484 .type
= QEMU_OPT_STRING
,
487 .type
= QEMU_OPT_STRING
,
490 .type
= QEMU_OPT_STRING
,
493 .type
= QEMU_OPT_STRING
,
495 { /* end of list */ }
499 const char *qemu_get_vm_name(void)
504 static void default_driver_disable(const char *driver
)
512 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
513 if (strcmp(default_list
[i
].driver
, driver
) != 0)
515 *(default_list
[i
].flag
) = 0;
519 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
521 const char *driver
= qemu_opt_get(opts
, "driver");
523 default_driver_disable(driver
);
527 static void default_driver_check_json(void)
531 QTAILQ_FOREACH(opt
, &device_opts
, next
) {
532 const char *driver
= qdict_get_try_str(opt
->opts
, "driver");
533 default_driver_disable(driver
);
537 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
539 const char *proc_name
;
541 if (qemu_opt_get(opts
, "debug-threads")) {
542 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
544 qemu_name
= qemu_opt_get(opts
, "guest");
546 proc_name
= qemu_opt_get(opts
, "process");
548 os_set_proc_name(proc_name
);
554 bool defaults_enabled(void)
560 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
562 int fd
, dupfd
, flags
;
564 const char *fd_opaque
= NULL
;
567 fd
= qemu_opt_get_number(opts
, "fd", -1);
568 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
569 fd_opaque
= qemu_opt_get(opts
, "opaque");
572 error_setg(errp
, "fd option is required and must be non-negative");
576 if (fd
<= STDERR_FILENO
) {
577 error_setg(errp
, "fd cannot be a standard I/O stream");
582 * All fds inherited across exec() necessarily have FD_CLOEXEC
583 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
585 flags
= fcntl(fd
, F_GETFD
);
586 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
587 error_setg(errp
, "fd is not valid or already in use");
592 error_setg(errp
, "set option is required and must be non-negative");
596 #ifdef F_DUPFD_CLOEXEC
597 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
601 qemu_set_cloexec(dupfd
);
605 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
609 /* add the duplicate fd, and optionally the opaque string, to the fd set */
610 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
617 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
621 fd
= qemu_opt_get_number(opts
, "fd", -1);
628 /***********************************************************/
629 /* QEMU Block devices */
631 #define HD_OPTS "media=disk"
632 #define CDROM_OPTS "media=cdrom"
634 #define PFLASH_OPTS ""
638 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
640 BlockInterfaceType
*block_default_type
= opaque
;
642 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
645 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
647 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
648 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
653 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
654 int index
, const char *optstr
)
659 if (!enable
|| drive_get_by_index(type
, index
)) {
663 opts
= drive_add(type
, index
, NULL
, optstr
);
665 drive_enable_snapshot(NULL
, opts
, NULL
);
668 dinfo
= drive_new(opts
, type
, &error_abort
);
669 dinfo
->is_default
= true;
673 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
674 MachineClass
*machine_class
, int snapshot
)
677 * If the currently selected machine wishes to override the
678 * units-per-bus property of its default HBA interface type, do so
681 if (machine_class
->units_per_default_bus
) {
682 override_max_devs(machine_class
->block_default_type
,
683 machine_class
->units_per_default_bus
);
686 /* open the virtual block devices */
687 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
688 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
690 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
691 loc_push_restore(&bdo
->loc
);
692 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
694 qapi_free_BlockdevOptions(bdo
->bdo
);
698 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
701 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
702 &machine_class
->block_default_type
, &error_fatal
)) {
703 /* We printed help */
707 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
709 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
710 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
714 static QemuOptsList qemu_smp_opts
= {
716 .implied_opt_name
= "cpus",
718 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
722 .type
= QEMU_OPT_NUMBER
,
725 .type
= QEMU_OPT_NUMBER
,
728 .type
= QEMU_OPT_NUMBER
,
731 .type
= QEMU_OPT_NUMBER
,
734 .type
= QEMU_OPT_NUMBER
,
737 .type
= QEMU_OPT_NUMBER
,
743 static void realtime_init(void)
746 if (os_mlock() < 0) {
747 error_report("locking memory failed");
754 static void configure_msg(QemuOpts
*opts
)
756 message_with_timestamp
= qemu_opt_get_bool(opts
, "timestamp", false);
757 error_with_guestname
= qemu_opt_get_bool(opts
, "guest-name", false);
761 /***********************************************************/
764 static int usb_device_add(const char *devname
)
766 USBDevice
*dev
= NULL
;
768 if (!machine_usb(current_machine
)) {
772 dev
= usbdevice_create(devname
);
779 static int usb_parse(const char *cmdline
)
782 r
= usb_device_add(cmdline
);
784 error_report("could not add USB device '%s'", cmdline
);
789 /***********************************************************/
790 /* machine registration */
792 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
796 for (el
= machines
; el
; el
= el
->next
) {
797 MachineClass
*mc
= el
->data
;
799 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
807 static MachineClass
*find_default_machine(GSList
*machines
)
810 MachineClass
*default_machineclass
= NULL
;
812 for (el
= machines
; el
; el
= el
->next
) {
813 MachineClass
*mc
= el
->data
;
815 if (mc
->is_default
) {
816 assert(default_machineclass
== NULL
&& "Multiple default machines");
817 default_machineclass
= mc
;
821 return default_machineclass
;
824 static void version(void)
826 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
827 QEMU_COPYRIGHT
"\n");
830 static void help(int exitcode
)
833 printf("usage: %s [options] [disk_image]\n\n"
834 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
835 error_get_progname());
837 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
838 if ((arch_mask) & arch_type) \
839 fputs(opt_help, stdout);
841 #define ARCHHEADING(text, arch_mask) \
842 if ((arch_mask) & arch_type) \
843 puts(stringify(text));
845 #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL)
847 #include "qemu-options.def"
849 printf("\nDuring emulation, the following keys are useful:\n"
850 "ctrl-alt-f toggle full screen\n"
851 "ctrl-alt-n switch to virtual console 'n'\n"
852 "ctrl-alt toggle mouse and keyboard grab\n"
854 "When using -nographic, press 'ctrl-a h' to get some help.\n"
856 QEMU_HELP_BOTTOM
"\n");
861 #define HAS_ARG 0x0001
863 typedef struct QEMUOption
{
870 static const QEMUOption qemu_options
[] = {
871 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
873 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
874 { option, opt_arg, opt_enum, arch_mask },
875 #define DEFHEADING(text)
876 #define ARCHHEADING(text, arch_mask)
878 #include "qemu-options.def"
882 typedef struct VGAInterfaceInfo
{
883 const char *opt_name
; /* option name */
884 const char *name
; /* human-readable name */
885 /* Class names indicating that support is available.
886 * If no class is specified, the interface is always available */
887 const char *class_names
[2];
890 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
893 .name
= "no graphic card",
897 .name
= "standard VGA",
898 .class_names
= { "VGA", "isa-vga" },
901 .opt_name
= "cirrus",
902 .name
= "Cirrus VGA",
903 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
906 .opt_name
= "vmware",
907 .name
= "VMWare SVGA",
908 .class_names
= { "vmware-svga" },
911 .opt_name
= "virtio",
912 .name
= "Virtio VGA",
913 .class_names
= { "virtio-vga" },
918 .class_names
= { "qxl-vga" },
922 .name
= "TCX framebuffer",
923 .class_names
= { "sun-tcx" },
927 .name
= "CG3 framebuffer",
928 .class_names
= { "cgthree" },
932 .name
= "Xen paravirtualized framebuffer",
936 static bool vga_interface_available(VGAInterfaceType t
)
938 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
940 assert(t
< VGA_TYPE_MAX
);
941 return !ti
->class_names
[0] ||
942 module_object_class_by_name(ti
->class_names
[0]) ||
943 module_object_class_by_name(ti
->class_names
[1]);
947 get_default_vga_model(const MachineClass
*machine_class
)
949 if (machine_class
->default_display
) {
950 return machine_class
->default_display
;
951 } else if (vga_interface_available(VGA_CIRRUS
)) {
953 } else if (vga_interface_available(VGA_STD
)) {
960 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
965 if (g_str_equal(p
, "help")) {
966 const char *def
= get_default_vga_model(machine_class
);
968 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
969 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
971 if (vga_interface_available(t
) && ti
->opt_name
) {
972 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
973 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
979 assert(vga_interface_type
== VGA_NONE
);
980 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
981 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
982 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
983 if (!vga_interface_available(t
)) {
984 error_report("%s not available", ti
->name
);
987 vga_interface_type
= t
;
991 if (t
== VGA_TYPE_MAX
) {
993 error_report("unknown vga type: %s", p
);
999 if (strstart(opts
, ",retrace=", &nextopt
)) {
1001 if (strstart(opts
, "dumb", &nextopt
))
1002 vga_retrace_method
= VGA_RETRACE_DUMB
;
1003 else if (strstart(opts
, "precise", &nextopt
))
1004 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1005 else goto invalid_vga
;
1006 } else goto invalid_vga
;
1011 static void parse_display_qapi(const char *optarg
)
1013 DisplayOptions
*opts
;
1016 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
1018 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
1019 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
1021 qapi_free_DisplayOptions(opts
);
1025 DisplayOptions
*qmp_query_display_options(Error
**errp
)
1027 return QAPI_CLONE(DisplayOptions
, &dpy
);
1030 static void parse_display(const char *p
)
1034 if (is_help_option(p
)) {
1035 qemu_display_help();
1039 if (strstart(p
, "sdl", &opts
)) {
1041 * sdl DisplayType needs hand-crafted parser instead of
1042 * parse_display_qapi() due to some options not in
1043 * DisplayOptions, specifically:
1044 * - ctrl_grab + alt_grab
1045 * They can't be moved into the QAPI since they use underscores,
1046 * thus they will get replaced by "grab-mod" in the long term
1048 #if defined(CONFIG_SDL)
1049 dpy
.type
= DISPLAY_TYPE_SDL
;
1051 const char *nextopt
;
1053 if (strstart(opts
, ",grab-mod=", &nextopt
)) {
1055 if (strstart(opts
, "lshift-lctrl-lalt", &nextopt
)) {
1057 } else if (strstart(opts
, "rctrl", &nextopt
)) {
1060 goto invalid_sdl_args
;
1062 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1064 if (strstart(opts
, "on", &nextopt
)) {
1066 } else if (strstart(opts
, "off", &nextopt
)) {
1069 goto invalid_sdl_args
;
1071 warn_report("alt_grab is deprecated, use grab-mod instead.");
1072 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1074 if (strstart(opts
, "on", &nextopt
)) {
1076 } else if (strstart(opts
, "off", &nextopt
)) {
1079 goto invalid_sdl_args
;
1081 warn_report("ctrl_grab is deprecated, use grab-mod instead.");
1082 } else if (strstart(opts
, ",window_close=", &nextopt
) ||
1083 strstart(opts
, ",window-close=", &nextopt
)) {
1084 if (strstart(opts
, ",window_close=", NULL
)) {
1085 warn_report("window_close with an underscore is deprecated,"
1086 " please use window-close instead.");
1089 dpy
.has_window_close
= true;
1090 if (strstart(opts
, "on", &nextopt
)) {
1091 dpy
.window_close
= true;
1092 } else if (strstart(opts
, "off", &nextopt
)) {
1093 dpy
.window_close
= false;
1095 goto invalid_sdl_args
;
1097 } else if (strstart(opts
, ",show-cursor=", &nextopt
)) {
1099 dpy
.has_show_cursor
= true;
1100 if (strstart(opts
, "on", &nextopt
)) {
1101 dpy
.show_cursor
= true;
1102 } else if (strstart(opts
, "off", &nextopt
)) {
1103 dpy
.show_cursor
= false;
1105 goto invalid_sdl_args
;
1107 } else if (strstart(opts
, ",gl=", &nextopt
)) {
1110 if (strstart(opts
, "on", &nextopt
)) {
1111 dpy
.gl
= DISPLAYGL_MODE_ON
;
1112 } else if (strstart(opts
, "core", &nextopt
)) {
1113 dpy
.gl
= DISPLAYGL_MODE_CORE
;
1114 } else if (strstart(opts
, "es", &nextopt
)) {
1115 dpy
.gl
= DISPLAYGL_MODE_ES
;
1116 } else if (strstart(opts
, "off", &nextopt
)) {
1117 dpy
.gl
= DISPLAYGL_MODE_OFF
;
1119 goto invalid_sdl_args
;
1123 error_report("invalid SDL option string");
1129 error_report("SDL display supported is not available in this binary");
1132 } else if (strstart(p
, "vnc", &opts
)) {
1134 * vnc isn't a (local) DisplayType but a protocol for remote
1138 vnc_parse(opts
+ 1);
1140 error_report("VNC requires a display argument vnc=<display>");
1144 parse_display_qapi(p
);
1148 static inline bool nonempty_str(const char *str
)
1153 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1157 const char *name
, *file
, *str
, *gen_id
;
1158 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1160 if (fw_cfg
== NULL
) {
1161 error_setg(errp
, "fw_cfg device not available");
1164 name
= qemu_opt_get(opts
, "name");
1165 file
= qemu_opt_get(opts
, "file");
1166 str
= qemu_opt_get(opts
, "string");
1167 gen_id
= qemu_opt_get(opts
, "gen_id");
1169 /* we need the name, and exactly one of: file, content string, gen_id */
1170 if (!nonempty_str(name
) ||
1171 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1172 error_setg(errp
, "name, plus exactly one of file,"
1173 " string and gen_id, are needed");
1176 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1177 error_setg(errp
, "name too long (max. %d char)",
1178 FW_CFG_MAX_FILE_PATH
- 1);
1181 if (nonempty_str(gen_id
)) {
1183 * In this particular case where the content is populated
1184 * internally, the "etc/" namespace protection is relaxed,
1185 * so do not emit a warning.
1187 } else if (strncmp(name
, "opt/", 4) != 0) {
1188 warn_report("externally provided fw_cfg item names "
1189 "should be prefixed with \"opt/\"");
1191 if (nonempty_str(str
)) {
1192 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1193 buf
= g_memdup(str
, size
);
1194 } else if (nonempty_str(gen_id
)) {
1195 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1201 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1202 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1207 /* For legacy, keep user files in a specific global order. */
1208 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1209 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1210 fw_cfg_reset_order_override(fw_cfg
);
1214 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1216 return qdev_device_help(opts
);
1219 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1223 dev
= qdev_device_add(opts
, errp
);
1224 if (!dev
&& *errp
) {
1225 error_report_err(*errp
);
1228 object_unref(OBJECT(dev
));
1233 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1235 Error
*local_err
= NULL
;
1237 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1239 error_propagate(errp
, local_err
);
1247 #ifdef CONFIG_VIRTFS
1248 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1250 return qemu_fsdev_add(opts
, errp
);
1254 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1256 return monitor_init_opts(opts
, errp
);
1259 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
1261 static int monitor_device_index
= 0;
1266 if (strstart(optarg
, "chardev:", &p
)) {
1267 snprintf(label
, sizeof(label
), "%s", p
);
1269 snprintf(label
, sizeof(label
), "compat_monitor%d",
1270 monitor_device_index
);
1271 opts
= qemu_chr_parse_compat(label
, optarg
, true);
1273 error_report("parse error: %s", optarg
);
1278 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1279 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1280 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1281 if (!strcmp(mode
, "control")) {
1282 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1284 assert(pretty
== false);
1286 monitor_device_index
++;
1289 struct device_config
{
1291 DEV_USB
, /* -usbdevice */
1292 DEV_SERIAL
, /* -serial */
1293 DEV_PARALLEL
, /* -parallel */
1294 DEV_DEBUGCON
, /* -debugcon */
1295 DEV_GDB
, /* -gdb, -s */
1296 DEV_SCLP
, /* s390 sclp */
1298 const char *cmdline
;
1300 QTAILQ_ENTRY(device_config
) next
;
1303 static QTAILQ_HEAD(, device_config
) device_configs
=
1304 QTAILQ_HEAD_INITIALIZER(device_configs
);
1306 static void add_device_config(int type
, const char *cmdline
)
1308 struct device_config
*conf
;
1310 conf
= g_malloc0(sizeof(*conf
));
1312 conf
->cmdline
= cmdline
;
1313 loc_save(&conf
->loc
);
1314 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1317 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1319 struct device_config
*conf
;
1322 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1323 if (conf
->type
!= type
)
1325 loc_push_restore(&conf
->loc
);
1326 rc
= func(conf
->cmdline
);
1327 loc_pop(&conf
->loc
);
1335 static void qemu_disable_default_devices(void)
1337 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1339 default_driver_check_json();
1340 qemu_opts_foreach(qemu_find_opts("device"),
1341 default_driver_check
, NULL
, NULL
);
1342 qemu_opts_foreach(qemu_find_opts("global"),
1343 default_driver_check
, NULL
, NULL
);
1345 if (!vga_model
&& !default_vga
) {
1346 vga_interface_type
= VGA_DEVICE
;
1348 if (!has_defaults
|| machine_class
->no_serial
) {
1351 if (!has_defaults
|| machine_class
->no_parallel
) {
1352 default_parallel
= 0;
1354 if (!has_defaults
|| machine_class
->no_floppy
) {
1357 if (!has_defaults
|| machine_class
->no_cdrom
) {
1360 if (!has_defaults
|| machine_class
->no_sdcard
) {
1363 if (!has_defaults
) {
1364 default_monitor
= 0;
1370 static void qemu_create_default_devices(void)
1372 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1374 if (is_daemonized()) {
1375 /* According to documentation and historically, -nographic redirects
1376 * serial port, parallel port and monitor to stdio, which does not work
1377 * with -daemonize. We can redirect these to null instead, but since
1378 * -nographic is legacy, let's just error out.
1379 * We disallow -nographic only if all other ports are not redirected
1380 * explicitly, to not break existing legacy setups which uses
1381 * -nographic _and_ redirects all ports explicitly - this is valid
1382 * usage, -nographic is just a no-op in this case.
1385 && (default_parallel
|| default_serial
|| default_monitor
)) {
1386 error_report("-nographic cannot be used with -daemonize");
1392 if (default_parallel
)
1393 add_device_config(DEV_PARALLEL
, "null");
1394 if (default_serial
&& default_monitor
) {
1395 add_device_config(DEV_SERIAL
, "mon:stdio");
1398 add_device_config(DEV_SERIAL
, "stdio");
1399 if (default_monitor
)
1400 monitor_parse("stdio", "readline", false);
1404 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
1405 if (default_parallel
)
1406 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
1407 if (default_monitor
)
1408 monitor_parse("vc:80Cx24C", "readline", false);
1412 QemuOptsList
*net
= qemu_find_opts("net");
1413 qemu_opts_parse(net
, "nic", true, &error_abort
);
1415 qemu_opts_parse(net
, "user", true, &error_abort
);
1419 #if defined(CONFIG_VNC)
1420 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
1424 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1425 if (!qemu_display_find_default(&dpy
)) {
1426 dpy
.type
= DISPLAY_TYPE_NONE
;
1427 #if defined(CONFIG_VNC)
1428 vnc_parse("localhost:0,to=99,id=default");
1432 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1433 dpy
.type
= DISPLAY_TYPE_NONE
;
1436 /* If no default VGA is requested, the default is "none". */
1438 vga_model
= get_default_vga_model(machine_class
);
1441 select_vgahw(machine_class
, vga_model
);
1445 static int serial_parse(const char *devname
)
1447 int index
= num_serial_hds
;
1450 if (strcmp(devname
, "none") == 0)
1452 snprintf(label
, sizeof(label
), "serial%d", index
);
1453 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1455 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1456 if (!serial_hds
[index
]) {
1457 error_report("could not connect serial device"
1458 " to character backend '%s'", devname
);
1465 Chardev
*serial_hd(int i
)
1468 if (i
< num_serial_hds
) {
1469 return serial_hds
[i
];
1474 static int parallel_parse(const char *devname
)
1476 static int index
= 0;
1479 if (strcmp(devname
, "none") == 0)
1481 if (index
== MAX_PARALLEL_PORTS
) {
1482 error_report("too many parallel ports");
1485 snprintf(label
, sizeof(label
), "parallel%d", index
);
1486 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1487 if (!parallel_hds
[index
]) {
1488 error_report("could not connect parallel device"
1489 " to character backend '%s'", devname
);
1496 static int debugcon_parse(const char *devname
)
1500 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1501 error_report("invalid character backend '%s'", devname
);
1504 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1506 error_report("already have a debugcon device");
1509 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1510 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1514 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1516 const MachineClass
*mc1
= a
, *mc2
= b
;
1519 if (mc1
->family
== NULL
) {
1520 if (mc2
->family
== NULL
) {
1521 /* Compare standalone machine types against each other; they sort
1522 * in increasing order.
1524 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1525 object_class_get_name(OBJECT_CLASS(mc2
)));
1528 /* Standalone machine types sort after families. */
1532 if (mc2
->family
== NULL
) {
1533 /* Families sort before standalone machine types. */
1537 /* Families sort between each other alphabetically increasingly. */
1538 res
= strcmp(mc1
->family
, mc2
->family
);
1543 /* Within the same family, machine types sort in decreasing order. */
1544 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1545 object_class_get_name(OBJECT_CLASS(mc1
)));
1548 static void machine_help_func(const QDict
*qdict
)
1550 GSList
*machines
, *el
;
1551 const char *type
= qdict_get_try_str(qdict
, "type");
1553 machines
= object_class_get_list(TYPE_MACHINE
, false);
1555 ObjectClass
*machine_class
= OBJECT_CLASS(find_machine(type
, machines
));
1556 if (machine_class
) {
1557 type_print_class_properties(object_class_get_name(machine_class
));
1562 printf("Supported machines are:\n");
1563 machines
= g_slist_sort(machines
, machine_class_cmp
);
1564 for (el
= machines
; el
; el
= el
->next
) {
1565 MachineClass
*mc
= el
->data
;
1567 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1569 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1570 mc
->is_default
? " (default)" : "",
1571 mc
->deprecation_reason
? " (deprecated)" : "");
1576 machine_merge_property(const char *propname
, QDict
*prop
, Error
**errp
)
1581 /* Preserve the caller's reference to prop. */
1583 qdict_put(opts
, propname
, prop
);
1584 keyval_merge(machine_opts_dict
, opts
, errp
);
1585 qobject_unref(opts
);
1589 machine_parse_property_opt(QemuOptsList
*opts_list
, const char *propname
,
1595 prop
= keyval_parse(arg
, opts_list
->implied_opt_name
, &help
, &error_fatal
);
1597 qemu_opts_print_help(opts_list
, true);
1600 machine_merge_property(propname
, prop
, &error_fatal
);
1601 qobject_unref(prop
);
1604 static const char *pid_file
;
1605 static Notifier qemu_unlink_pidfile_notifier
;
1607 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1614 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1615 const char **poptarg
, int *poptind
)
1617 const QEMUOption
*popt
;
1618 int optind
= *poptind
;
1619 char *r
= argv
[optind
];
1622 loc_set_cmdline(argv
, optind
, 1);
1624 /* Treat --foo the same as -foo. */
1627 popt
= qemu_options
;
1630 error_report("invalid option");
1633 if (!strcmp(popt
->name
, r
+ 1))
1637 if (popt
->flags
& HAS_ARG
) {
1638 if (optind
>= argc
) {
1639 error_report("requires an argument");
1642 optarg
= argv
[optind
++];
1643 loc_set_cmdline(argv
, optind
- 2, 2);
1654 static MachineClass
*select_machine(QDict
*qdict
, Error
**errp
)
1656 const char *optarg
= qdict_get_try_str(qdict
, "type");
1657 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
1658 MachineClass
*machine_class
;
1659 Error
*local_err
= NULL
;
1662 machine_class
= find_machine(optarg
, machines
);
1663 qdict_del(qdict
, "type");
1664 if (!machine_class
) {
1665 error_setg(&local_err
, "unsupported machine type");
1668 machine_class
= find_default_machine(machines
);
1669 if (!machine_class
) {
1670 error_setg(&local_err
, "No machine specified, and there is no default");
1674 g_slist_free(machines
);
1676 error_append_hint(&local_err
, "Use -machine help to list supported machines\n");
1677 error_propagate(errp
, local_err
);
1679 return machine_class
;
1682 static int object_parse_property_opt(Object
*obj
,
1683 const char *name
, const char *value
,
1684 const char *skip
, Error
**errp
)
1686 if (g_str_equal(name
, skip
)) {
1690 if (!object_property_parse(obj
, name
, value
, errp
)) {
1697 /* *Non*recursively replace underscores with dashes in QDict keys. */
1698 static void keyval_dashify(QDict
*qdict
, Error
**errp
)
1700 const QDictEntry
*ent
, *next
;
1703 for (ent
= qdict_first(qdict
); ent
; ent
= next
) {
1704 g_autofree
char *new_key
= NULL
;
1706 next
= qdict_next(qdict
, ent
);
1707 if (!strchr(ent
->key
, '_')) {
1710 new_key
= g_strdup(ent
->key
);
1711 for (p
= new_key
; *p
; p
++) {
1716 if (qdict_haskey(qdict
, new_key
)) {
1717 error_setg(errp
, "Conflict between '%s' and '%s'", ent
->key
, new_key
);
1720 qobject_ref(ent
->value
);
1721 qdict_put_obj(qdict
, new_key
, ent
->value
);
1722 qdict_del(qdict
, ent
->key
);
1726 static void qemu_apply_legacy_machine_options(QDict
*qdict
)
1730 keyval_dashify(qdict
, &error_fatal
);
1732 /* Legacy options do not correspond to MachineState properties. */
1733 value
= qdict_get_try_str(qdict
, "accel");
1735 accelerators
= g_strdup(value
);
1736 qdict_del(qdict
, "accel");
1739 value
= qdict_get_try_str(qdict
, "igd-passthru");
1741 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value
,
1743 qdict_del(qdict
, "igd-passthru");
1746 value
= qdict_get_try_str(qdict
, "kvm-shadow-mem");
1748 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value
,
1750 qdict_del(qdict
, "kvm-shadow-mem");
1753 value
= qdict_get_try_str(qdict
, "kernel-irqchip");
1755 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value
,
1757 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value
,
1759 qdict_del(qdict
, "kernel-irqchip");
1763 static void object_option_foreach_add(bool (*type_opt_predicate
)(const char *))
1765 ObjectOption
*opt
, *next
;
1767 QTAILQ_FOREACH_SAFE(opt
, &object_opts
, next
, next
) {
1768 const char *type
= ObjectType_str(opt
->opts
->qom_type
);
1769 if (type_opt_predicate(type
)) {
1770 user_creatable_add_qapi(opt
->opts
, &error_fatal
);
1771 qapi_free_ObjectOptions(opt
->opts
);
1772 QTAILQ_REMOVE(&object_opts
, opt
, next
);
1778 static void object_option_add_visitor(Visitor
*v
)
1780 ObjectOption
*opt
= g_new0(ObjectOption
, 1);
1781 visit_type_ObjectOptions(v
, NULL
, &opt
->opts
, &error_fatal
);
1782 QTAILQ_INSERT_TAIL(&object_opts
, opt
, next
);
1785 static void object_option_parse(const char *optarg
)
1791 if (optarg
[0] == '{') {
1792 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
1794 v
= qobject_input_visitor_new(obj
);
1797 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
1803 type
= qemu_opt_get(opts
, "qom-type");
1805 error_setg(&error_fatal
, QERR_MISSING_PARAMETER
, "qom-type");
1807 if (user_creatable_print_help(type
, opts
)) {
1811 v
= opts_visitor_new(opts
);
1814 object_option_add_visitor(v
);
1819 * Initial object creation happens before all other
1820 * QEMU data types are created. The majority of objects
1821 * can be created at this point. The rng-egd object
1822 * cannot be created here, as it depends on the chardev
1825 static bool object_create_early(const char *type
)
1828 * Objects should not be made "delayed" without a reason. If you
1829 * add one, state the reason in a comment!
1832 /* Reason: property "chardev" */
1833 if (g_str_equal(type
, "rng-egd") ||
1834 g_str_equal(type
, "qtest")) {
1838 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1839 /* Reason: cryptodev-vhost-user property "chardev" */
1840 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1845 /* Reason: vhost-user-blk-server property "node-name" */
1846 if (g_str_equal(type
, "vhost-user-blk-server")) {
1850 * Reason: filter-* property "netdev" etc.
1852 if (g_str_equal(type
, "filter-buffer") ||
1853 g_str_equal(type
, "filter-dump") ||
1854 g_str_equal(type
, "filter-mirror") ||
1855 g_str_equal(type
, "filter-redirector") ||
1856 g_str_equal(type
, "colo-compare") ||
1857 g_str_equal(type
, "filter-rewriter") ||
1858 g_str_equal(type
, "filter-replay")) {
1863 * Allocation of large amounts of memory may delay
1864 * chardev initialization for too long, and trigger timeouts
1865 * on software that waits for a monitor socket to be created
1868 if (g_str_has_prefix(type
, "memory-backend-")) {
1875 static void qemu_apply_machine_options(QDict
*qdict
)
1877 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1878 const char *boot_order
= NULL
;
1879 const char *boot_once
= NULL
;
1882 object_set_properties_from_keyval(OBJECT(current_machine
), qdict
, false, &error_fatal
);
1883 current_machine
->ram_size
= ram_size
;
1884 current_machine
->maxram_size
= maxram_size
;
1885 current_machine
->ram_slots
= ram_slots
;
1887 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
1889 boot_order
= qemu_opt_get(opts
, "order");
1891 validate_bootdevices(boot_order
, &error_fatal
);
1894 boot_once
= qemu_opt_get(opts
, "once");
1896 validate_bootdevices(boot_once
, &error_fatal
);
1899 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
1900 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
1904 boot_order
= machine_class
->default_boot_order
;
1907 current_machine
->boot_order
= boot_order
;
1908 current_machine
->boot_once
= boot_once
;
1910 if (semihosting_enabled() && !semihosting_get_argc()) {
1911 /* fall back to the -kernel/-append */
1912 semihosting_arg_fallback(current_machine
->kernel_filename
, current_machine
->kernel_cmdline
);
1915 if (current_machine
->smp
.cpus
> 1) {
1916 Error
*blocker
= NULL
;
1917 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1918 replay_add_blocker(blocker
);
1922 static void qemu_create_early_backends(void)
1924 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1925 #if defined(CONFIG_SDL)
1926 const bool use_sdl
= (dpy
.type
== DISPLAY_TYPE_SDL
);
1928 const bool use_sdl
= false;
1930 #if defined(CONFIG_GTK)
1931 const bool use_gtk
= (dpy
.type
== DISPLAY_TYPE_GTK
);
1933 const bool use_gtk
= false;
1936 if ((alt_grab
|| ctrl_grab
) && !use_sdl
) {
1937 error_report("-alt-grab and -ctrl-grab are only valid "
1938 "for SDL, ignoring option");
1940 if (dpy
.has_window_close
&& !use_gtk
&& !use_sdl
) {
1941 error_report("-no-quit is only valid for GTK and SDL, "
1945 qemu_display_early_init(&dpy
);
1946 qemu_console_early_init();
1948 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1949 #if defined(CONFIG_OPENGL)
1950 error_report("OpenGL is not supported by the display");
1952 error_report("OpenGL support is disabled");
1957 object_option_foreach_add(object_create_early
);
1959 /* spice needs the timers to be initialized by this point */
1960 /* spice must initialize before audio as it changes the default auiodev */
1961 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1964 qemu_opts_foreach(qemu_find_opts("chardev"),
1965 chardev_init_func
, NULL
, &error_fatal
);
1967 #ifdef CONFIG_VIRTFS
1968 qemu_opts_foreach(qemu_find_opts("fsdev"),
1969 fsdev_init_func
, NULL
, &error_fatal
);
1973 * Note: we need to create audio and block backends before
1974 * setting machine properties, so they can be referred to.
1976 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
1977 audio_init_audiodevs();
1982 * The remainder of object creation happens after the
1983 * creation of chardev, fsdev, net clients and device data types.
1985 static bool object_create_late(const char *type
)
1987 return !object_create_early(type
);
1990 static void qemu_create_late_backends(void)
1993 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
1996 net_init_clients(&error_fatal
);
1998 object_option_foreach_add(object_create_late
);
2000 if (tpm_init() < 0) {
2004 qemu_opts_foreach(qemu_find_opts("mon"),
2005 mon_init_func
, NULL
, &error_fatal
);
2007 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2009 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2011 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2014 /* now chardevs have been created we may have semihosting to connect */
2015 qemu_semihosting_connect_chardevs();
2016 qemu_semihosting_console_init();
2019 static bool have_custom_ram_size(void)
2021 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2022 return !!qemu_opt_get_size(opts
, "size", 0);
2025 static void qemu_resolve_machine_memdev(void)
2027 if (current_machine
->ram_memdev_id
) {
2029 ram_addr_t backend_size
;
2031 backend
= object_resolve_path_type(current_machine
->ram_memdev_id
,
2032 TYPE_MEMORY_BACKEND
, NULL
);
2034 error_report("Memory backend '%s' not found",
2035 current_machine
->ram_memdev_id
);
2038 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
2039 if (have_custom_ram_size() && backend_size
!= ram_size
) {
2040 error_report("Size specified by -m option must match size of "
2041 "explicitly specified 'memory-backend' property");
2045 error_report("'-mem-path' can't be used together with"
2046 "'-machine memory-backend'");
2049 ram_size
= backend_size
;
2052 if (!xen_enabled()) {
2053 /* On 32-bit hosts, QEMU is limited by virtual address space */
2054 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2055 error_report("at most 2047 MB RAM can be simulated");
2061 static void set_memory_options(MachineClass
*mc
)
2064 const char *mem_str
;
2065 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2066 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2069 loc_push_none(&loc
);
2070 qemu_opts_loc_restore(opts
);
2073 mem_str
= qemu_opt_get(opts
, "size");
2076 error_report("missing 'size' option value");
2080 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2082 /* Fix up legacy suffix-less format */
2083 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2084 uint64_t overflow_check
= sz
;
2087 if (sz
/ MiB
!= overflow_check
) {
2088 error_report("too large 'size' option value");
2094 /* backward compatibility behaviour for case "-m 0" */
2096 sz
= default_ram_size
;
2099 sz
= QEMU_ALIGN_UP(sz
, 8192);
2100 if (mc
->fixup_ram_size
) {
2101 sz
= mc
->fixup_ram_size(sz
);
2104 if (ram_size
!= sz
) {
2105 error_report("ram size too large");
2109 maxram_size
= ram_size
;
2111 if (qemu_opt_get(opts
, "maxmem")) {
2114 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2115 slots
= qemu_opt_get_number(opts
, "slots", 0);
2116 if (sz
< ram_size
) {
2117 error_report("invalid value of -m option maxmem: "
2118 "maximum memory size (0x%" PRIx64
") must be at least "
2119 "the initial memory size (0x" RAM_ADDR_FMT
")",
2122 } else if (slots
&& sz
== ram_size
) {
2123 error_report("invalid value of -m option maxmem: "
2124 "memory slots were specified but maximum memory size "
2125 "(0x%" PRIx64
") is equal to the initial memory size "
2126 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2132 } else if (qemu_opt_get(opts
, "slots")) {
2133 error_report("invalid -m option value: missing 'maxmem' option");
2140 static void qemu_create_machine(QDict
*qdict
)
2142 MachineClass
*machine_class
= select_machine(qdict
, &error_fatal
);
2143 object_set_machine_compat_props(machine_class
->compat_props
);
2145 set_memory_options(machine_class
);
2147 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2148 object_property_add_child(object_get_root(), "machine",
2149 OBJECT(current_machine
));
2150 object_property_add_child(container_get(OBJECT(current_machine
),
2152 "sysbus", OBJECT(sysbus_get_default()));
2154 if (machine_class
->minimum_page_bits
) {
2155 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2156 /* This would be a board error: specifying a minimum smaller than
2157 * a target's compile-time fixed setting.
2159 g_assert_not_reached();
2163 cpu_exec_init_all();
2166 if (machine_class
->hw_version
) {
2167 qemu_set_hw_version(machine_class
->hw_version
);
2171 * Get the default machine options from the machine if it is not already
2172 * specified either by the configuration file or by the command line.
2174 if (machine_class
->default_machine_opts
) {
2175 QDict
*default_opts
=
2176 keyval_parse(machine_class
->default_machine_opts
, NULL
, NULL
,
2178 qemu_apply_legacy_machine_options(default_opts
);
2179 object_set_properties_from_keyval(OBJECT(current_machine
), default_opts
,
2180 false, &error_abort
);
2181 qobject_unref(default_opts
);
2185 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2189 g
= g_malloc0(sizeof(*g
));
2190 g
->driver
= qemu_opt_get(opts
, "driver");
2191 g
->property
= qemu_opt_get(opts
, "property");
2192 g
->value
= qemu_opt_get(opts
, "value");
2193 qdev_prop_register_global(g
);
2198 * Return whether configuration group @group is stored in QemuOpts, or
2199 * recorded as one or more QDicts by qemu_record_config_group.
2201 static bool is_qemuopts_group(const char *group
)
2203 if (g_str_equal(group
, "object") ||
2204 g_str_equal(group
, "machine") ||
2205 g_str_equal(group
, "smp-opts")) {
2211 static void qemu_record_config_group(const char *group
, QDict
*dict
,
2212 bool from_json
, Error
**errp
)
2214 if (g_str_equal(group
, "object")) {
2215 Visitor
*v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2216 object_option_add_visitor(v
);
2218 } else if (g_str_equal(group
, "machine")) {
2220 * Cannot merge string-valued and type-safe dictionaries, so JSON
2221 * is not accepted yet for -M.
2224 keyval_merge(machine_opts_dict
, dict
, errp
);
2225 } else if (g_str_equal(group
, "smp-opts")) {
2226 machine_merge_property("smp", dict
, &error_fatal
);
2233 * Parse non-QemuOpts config file groups, pass the rest to
2234 * qemu_config_do_parse.
2236 static void qemu_parse_config_group(const char *group
, QDict
*qdict
,
2237 void *opaque
, Error
**errp
)
2240 if (is_qemuopts_group(group
)) {
2241 qemu_config_do_parse(group
, qdict
, opaque
, errp
);
2245 crumpled
= qdict_crumple(qdict
, errp
);
2249 switch (qobject_type(crumpled
)) {
2251 qemu_record_config_group(group
, qobject_to(QDict
, crumpled
), false, errp
);
2254 error_setg(errp
, "Lists cannot be at top level of a configuration section");
2257 g_assert_not_reached();
2259 qobject_unref(crumpled
);
2262 static void qemu_read_default_config_file(Error
**errp
)
2266 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2268 ret
= qemu_read_config_file(file
, qemu_parse_config_group
, errp
);
2270 if (ret
== -ENOENT
) {
2277 static void qemu_set_option(const char *str
, Error
**errp
)
2279 char group
[64], id
[64], arg
[64];
2284 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2285 if (rc
< 3 || str
[offset
] != '=') {
2286 error_setg(errp
, "can't parse: \"%s\"", str
);
2290 if (!is_qemuopts_group(group
)) {
2291 error_setg(errp
, "-set is not supported with %s", group
);
2293 list
= qemu_find_opts_err(group
, errp
);
2295 opts
= qemu_opts_find(list
, id
);
2297 error_setg(errp
, "there is no %s \"%s\" defined", group
, id
);
2300 qemu_opt_set(opts
, arg
, str
+ offset
+ 1, errp
);
2305 static void user_register_global_props(void)
2307 qemu_opts_foreach(qemu_find_opts("global"),
2308 global_init_func
, NULL
, NULL
);
2311 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2313 icount_configure(opts
, errp
);
2317 static int accelerator_set_property(void *opaque
,
2318 const char *name
, const char *value
,
2321 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2324 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2326 bool *p_init_failed
= opaque
;
2327 const char *acc
= qemu_opt_get(opts
, "accel");
2328 AccelClass
*ac
= accel_find(acc
);
2331 bool qtest_with_kvm
;
2333 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2336 *p_init_failed
= true;
2337 if (!qtest_with_kvm
) {
2338 error_report("invalid accelerator %s", acc
);
2342 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2343 object_apply_compat_props(OBJECT(accel
));
2344 qemu_opt_foreach(opts
, accelerator_set_property
,
2348 ret
= accel_init_machine(accel
, current_machine
);
2350 *p_init_failed
= true;
2351 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2352 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2360 static void configure_accelerators(const char *progname
)
2362 bool init_failed
= false;
2364 qemu_opts_foreach(qemu_find_opts("icount"),
2365 do_configure_icount
, NULL
, &error_fatal
);
2367 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2368 char **accel_list
, **tmp
;
2370 if (accelerators
== NULL
) {
2371 /* Select the default accelerator */
2372 bool have_tcg
= accel_find("tcg");
2373 bool have_kvm
= accel_find("kvm");
2375 if (have_tcg
&& have_kvm
) {
2376 if (g_str_has_suffix(progname
, "kvm")) {
2377 /* If the program name ends with "kvm", we prefer KVM */
2378 accelerators
= "kvm:tcg";
2380 accelerators
= "tcg:kvm";
2382 } else if (have_kvm
) {
2383 accelerators
= "kvm";
2384 } else if (have_tcg
) {
2385 accelerators
= "tcg";
2387 error_report("No accelerator selected and"
2388 " no default accelerator available");
2392 accel_list
= g_strsplit(accelerators
, ":", 0);
2394 for (tmp
= accel_list
; *tmp
; tmp
++) {
2396 * Filter invalid accelerators here, to prevent obscenities
2397 * such as "-machine accel=tcg,,thread=single".
2399 if (accel_find(*tmp
)) {
2400 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2403 error_report("invalid accelerator %s", *tmp
);
2406 g_strfreev(accel_list
);
2408 if (accelerators
!= NULL
) {
2409 error_report("The -accel and \"-machine accel=\" options are incompatible");
2414 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2415 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2417 error_report("no accelerator found");
2422 if (init_failed
&& !qtest_chrdev
) {
2423 AccelClass
*ac
= ACCEL_GET_CLASS(current_accel());
2424 error_report("falling back to %s", ac
->name
);
2427 if (icount_enabled() && !tcg_enabled()) {
2428 error_report("-icount is not allowed with hardware virtualization");
2433 static void create_default_memdev(MachineState
*ms
, const char *path
)
2436 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
2438 obj
= object_new(path
? TYPE_MEMORY_BACKEND_FILE
: TYPE_MEMORY_BACKEND_RAM
);
2440 object_property_set_str(obj
, "mem-path", path
, &error_fatal
);
2442 object_property_set_int(obj
, "size", ms
->ram_size
, &error_fatal
);
2443 object_property_add_child(object_get_objects_root(), mc
->default_ram_id
,
2445 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2446 object_property_set_bool(obj
, "x-use-canonical-path-for-ramblock-id",
2447 false, &error_fatal
);
2448 user_creatable_complete(USER_CREATABLE(obj
), &error_fatal
);
2450 object_property_set_str(OBJECT(ms
), "memory-backend", mc
->default_ram_id
,
2454 static void qemu_validate_options(const QDict
*machine_opts
)
2456 const char *kernel_filename
= qdict_get_try_str(machine_opts
, "kernel");
2457 const char *initrd_filename
= qdict_get_try_str(machine_opts
, "initrd");
2458 const char *kernel_cmdline
= qdict_get_try_str(machine_opts
, "append");
2460 if (kernel_filename
== NULL
) {
2461 if (kernel_cmdline
!= NULL
) {
2462 error_report("-append only allowed with -kernel option");
2466 if (initrd_filename
!= NULL
) {
2467 error_report("-initrd only allowed with -kernel option");
2472 if (loadvm
&& preconfig_requested
) {
2473 error_report("'preconfig' and 'loadvm' options are "
2474 "mutually exclusive");
2477 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2478 error_report("'preconfig' supports '-incoming defer' only");
2482 #ifdef CONFIG_CURSES
2483 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2484 error_report("curses display cannot be used with -daemonize");
2490 static void qemu_process_sugar_options(void)
2493 QObject
*smp
= qdict_get(machine_opts_dict
, "smp");
2494 if (smp
&& qobject_type(smp
) == QTYPE_QDICT
) {
2495 QObject
*cpus
= qdict_get(qobject_to(QDict
, smp
), "cpus");
2496 if (cpus
&& qobject_type(cpus
) == QTYPE_QSTRING
) {
2497 const char *val
= qstring_get_str(qobject_to(QString
, cpus
));
2498 object_register_sugar_prop("memory-backend", "prealloc-threads",
2502 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2506 int i
= select_watchdog(watchdog
);
2508 exit (i
== 1 ? 1 : 0);
2512 /* -action processing */
2515 * Process all the -action parameters parsed from cmdline.
2517 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2519 Error
*local_err
= NULL
;
2520 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2521 QObject
*ret
= NULL
;
2522 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2524 qobject_unref(qdict
);
2526 error_propagate(errp
, local_err
);
2532 static void qemu_process_early_options(void)
2534 #ifdef CONFIG_SECCOMP
2535 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2537 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2541 qemu_opts_foreach(qemu_find_opts("name"),
2542 parse_name
, NULL
, &error_fatal
);
2544 if (qemu_opts_foreach(qemu_find_opts("action"),
2545 process_runstate_actions
, NULL
, &error_fatal
)) {
2550 qemu_opts_foreach(qemu_find_opts("add-fd"),
2551 parse_add_fd
, NULL
, &error_fatal
);
2553 qemu_opts_foreach(qemu_find_opts("add-fd"),
2554 cleanup_add_fd
, NULL
, &error_fatal
);
2557 /* Open the logfile at this point and set the log mask if necessary. */
2559 qemu_set_log_filename(log_file
, &error_fatal
);
2563 mask
= qemu_str_to_log_mask(log_mask
);
2565 qemu_print_log_usage(stdout
);
2573 qemu_add_default_firmwarepath();
2576 static void qemu_process_help_options(void)
2579 * Check for -cpu help and -device help before we call select_machine(),
2580 * which will return an error if the architecture has no default machine
2581 * type and the user did not specify one, so that the user doesn't need
2582 * to say '-cpu help -machine something'.
2584 if (cpu_option
&& is_help_option(cpu_option
)) {
2585 list_cpus(cpu_option
);
2589 if (qemu_opts_foreach(qemu_find_opts("device"),
2590 device_help_func
, NULL
, NULL
)) {
2594 /* -L help lists the data directories and exits. */
2595 if (list_data_dirs
) {
2596 qemu_list_data_dirs();
2601 static void qemu_maybe_daemonize(const char *pid_file
)
2606 rcu_disable_atfork();
2608 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
2609 error_reportf_err(err
, "cannot create PID file: ");
2613 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
2614 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
2617 static void qemu_init_displays(void)
2621 /* init local displays */
2622 ds
= init_displaystate();
2623 qemu_display_init(ds
, &dpy
);
2625 /* must be after terminal init, SDL library changes signal handlers */
2626 os_setup_signal_handling();
2628 /* init remote displays */
2630 qemu_opts_foreach(qemu_find_opts("vnc"),
2631 vnc_init_func
, NULL
, &error_fatal
);
2635 qemu_spice
.display_init();
2639 static void qemu_init_board(void)
2641 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
2643 if (machine_class
->default_ram_id
&& current_machine
->ram_size
&&
2644 numa_uses_legacy_mem() && !current_machine
->ram_memdev_id
) {
2645 create_default_memdev(current_machine
, mem_path
);
2648 /* process plugin before CPUs are created, but once -smp has been parsed */
2649 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2651 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2652 machine_run_board_init(current_machine
);
2654 drive_check_orphaned();
2658 if (hax_enabled()) {
2659 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2664 static void qemu_create_cli_devices(void)
2670 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2671 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2673 /* init USB devices */
2674 if (machine_usb(current_machine
)) {
2675 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2679 /* init generic devices */
2680 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2681 qemu_opts_foreach(qemu_find_opts("device"),
2682 device_init_func
, NULL
, &error_fatal
);
2683 QTAILQ_FOREACH(opt
, &device_opts
, next
) {
2684 loc_push_restore(&opt
->loc
);
2686 * TODO Eventually we should call qmp_device_add() here to make sure it
2687 * behaves the same, but QMP still has to accept incorrectly typed
2688 * options until libvirt is fixed and we want to be strict on the CLI
2689 * from the start, so call qdev_device_add_from_qdict() directly for
2692 qdev_device_add_from_qdict(opt
->opts
, true, &error_fatal
);
2695 rom_reset_order_override();
2698 static void qemu_machine_creation_done(void)
2700 MachineState
*machine
= MACHINE(qdev_get_machine());
2702 /* Did we create any drives that we failed to create a device for? */
2703 drive_check_orphaned();
2705 /* Don't warn about the default network setup that you get if
2706 * no command line -net or -netdev options are specified. There
2707 * are two cases that we would otherwise complain about:
2708 * (1) board doesn't support a NIC but the implicit "-net nic"
2710 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2711 * sets up a nic that isn't connected to anything.
2713 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2714 net_check_clients();
2717 qdev_prop_check_globals();
2719 qdev_machine_creation_done();
2723 * Verify that Confidential Guest Support has actually been initialized
2725 assert(machine
->cgs
->ready
);
2728 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2733 void qmp_x_exit_preconfig(Error
**errp
)
2735 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2736 error_setg(errp
, "The command is permitted only before machine initialization");
2741 qemu_create_cli_devices();
2742 qemu_machine_creation_done();
2745 load_snapshot(loadvm
, NULL
, false, NULL
, &error_fatal
);
2747 if (replay_mode
!= REPLAY_MODE_NONE
) {
2748 replay_vmstate_init();
2752 Error
*local_err
= NULL
;
2753 if (strcmp(incoming
, "defer") != 0) {
2754 qmp_migrate_incoming(incoming
, &local_err
);
2756 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2760 } else if (autostart
) {
2765 void qemu_init(int argc
, char **argv
, char **envp
)
2768 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2769 QemuOptsList
*olist
;
2772 MachineClass
*machine_class
;
2773 bool userconfig
= true;
2774 FILE *vmstate_dump_file
= NULL
;
2776 qemu_add_opts(&qemu_drive_opts
);
2777 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2778 qemu_add_drive_opts(&qemu_common_drive_opts
);
2779 qemu_add_drive_opts(&qemu_drive_opts
);
2780 qemu_add_drive_opts(&bdrv_runtime_opts
);
2781 qemu_add_opts(&qemu_chardev_opts
);
2782 qemu_add_opts(&qemu_device_opts
);
2783 qemu_add_opts(&qemu_netdev_opts
);
2784 qemu_add_opts(&qemu_nic_opts
);
2785 qemu_add_opts(&qemu_net_opts
);
2786 qemu_add_opts(&qemu_rtc_opts
);
2787 qemu_add_opts(&qemu_global_opts
);
2788 qemu_add_opts(&qemu_mon_opts
);
2789 qemu_add_opts(&qemu_trace_opts
);
2790 qemu_plugin_add_opts();
2791 qemu_add_opts(&qemu_option_rom_opts
);
2792 qemu_add_opts(&qemu_accel_opts
);
2793 qemu_add_opts(&qemu_mem_opts
);
2794 qemu_add_opts(&qemu_smp_opts
);
2795 qemu_add_opts(&qemu_boot_opts
);
2796 qemu_add_opts(&qemu_add_fd_opts
);
2797 qemu_add_opts(&qemu_object_opts
);
2798 qemu_add_opts(&qemu_tpmdev_opts
);
2799 qemu_add_opts(&qemu_overcommit_opts
);
2800 qemu_add_opts(&qemu_msg_opts
);
2801 qemu_add_opts(&qemu_name_opts
);
2802 qemu_add_opts(&qemu_numa_opts
);
2803 qemu_add_opts(&qemu_icount_opts
);
2804 qemu_add_opts(&qemu_semihosting_config_opts
);
2805 qemu_add_opts(&qemu_fw_cfg_opts
);
2806 qemu_add_opts(&qemu_action_opts
);
2807 module_call_init(MODULE_INIT_OPTS
);
2809 error_init(argv
[0]);
2810 qemu_init_exec_dir(argv
[0]);
2812 #ifdef CONFIG_MODULES
2813 module_init_info(qemu_modinfo
);
2814 module_allow_arch(TARGET_NAME
);
2817 qemu_init_subsystems();
2819 /* first pass of option parsing */
2821 while (optind
< argc
) {
2822 if (argv
[optind
][0] != '-') {
2826 const QEMUOption
*popt
;
2828 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2829 switch (popt
->index
) {
2830 case QEMU_OPTION_nouserconfig
:
2837 machine_opts_dict
= qdict_new();
2839 qemu_read_default_config_file(&error_fatal
);
2842 /* second pass of option parsing */
2847 if (argv
[optind
][0] != '-') {
2848 loc_set_cmdline(argv
, optind
, 1);
2849 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2851 const QEMUOption
*popt
;
2853 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2854 if (!(popt
->arch_mask
& arch_type
)) {
2855 error_report("Option not supported for this target");
2858 switch(popt
->index
) {
2859 case QEMU_OPTION_cpu
:
2860 /* hw initialization will check this */
2861 cpu_option
= optarg
;
2863 case QEMU_OPTION_hda
:
2864 case QEMU_OPTION_hdb
:
2865 case QEMU_OPTION_hdc
:
2866 case QEMU_OPTION_hdd
:
2867 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2870 case QEMU_OPTION_blockdev
:
2873 BlockdevOptionsQueueEntry
*bdo
;
2875 v
= qobject_input_visitor_new_str(optarg
, "driver",
2878 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2879 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2882 loc_save(&bdo
->loc
);
2883 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2886 case QEMU_OPTION_drive
:
2887 if (drive_def(optarg
) == NULL
) {
2891 case QEMU_OPTION_set
:
2892 qemu_set_option(optarg
, &error_fatal
);
2894 case QEMU_OPTION_global
:
2895 if (qemu_global_option(optarg
) != 0)
2898 case QEMU_OPTION_mtdblock
:
2899 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2901 case QEMU_OPTION_sd
:
2902 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2904 case QEMU_OPTION_pflash
:
2905 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2907 case QEMU_OPTION_snapshot
:
2909 Error
*blocker
= NULL
;
2911 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
2913 replay_add_blocker(blocker
);
2916 case QEMU_OPTION_numa
:
2917 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2923 case QEMU_OPTION_display
:
2924 parse_display(optarg
);
2926 case QEMU_OPTION_nographic
:
2927 qdict_put_str(machine_opts_dict
, "graphics", "off");
2929 dpy
.type
= DISPLAY_TYPE_NONE
;
2931 case QEMU_OPTION_curses
:
2932 warn_report("-curses is deprecated, "
2933 "use -display curses instead.");
2934 #ifdef CONFIG_CURSES
2935 dpy
.type
= DISPLAY_TYPE_CURSES
;
2937 error_report("curses or iconv support is disabled");
2941 case QEMU_OPTION_portrait
:
2942 graphic_rotate
= 90;
2944 case QEMU_OPTION_rotate
:
2945 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2946 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2947 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2948 error_report("only 90, 180, 270 deg rotation is available");
2952 case QEMU_OPTION_kernel
:
2953 qdict_put_str(machine_opts_dict
, "kernel", optarg
);
2955 case QEMU_OPTION_initrd
:
2956 qdict_put_str(machine_opts_dict
, "initrd", optarg
);
2958 case QEMU_OPTION_append
:
2959 qdict_put_str(machine_opts_dict
, "append", optarg
);
2961 case QEMU_OPTION_dtb
:
2962 qdict_put_str(machine_opts_dict
, "dtb", optarg
);
2964 case QEMU_OPTION_cdrom
:
2965 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2967 case QEMU_OPTION_boot
:
2968 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2974 case QEMU_OPTION_fda
:
2975 case QEMU_OPTION_fdb
:
2976 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2979 case QEMU_OPTION_no_fd_bootchk
:
2982 case QEMU_OPTION_netdev
:
2984 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2988 case QEMU_OPTION_nic
:
2990 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
2994 case QEMU_OPTION_net
:
2996 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3000 #ifdef CONFIG_LIBISCSI
3001 case QEMU_OPTION_iscsi
:
3002 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3009 case QEMU_OPTION_audio_help
:
3010 audio_legacy_help();
3013 case QEMU_OPTION_audiodev
:
3014 audio_parse_option(optarg
);
3016 case QEMU_OPTION_soundhw
:
3017 select_soundhw (optarg
);
3022 case QEMU_OPTION_version
:
3027 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3034 case QEMU_OPTION_tpmdev
:
3035 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3040 case QEMU_OPTION_mempath
:
3043 case QEMU_OPTION_mem_prealloc
:
3052 case QEMU_OPTION_DFILTER
:
3053 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3055 case QEMU_OPTION_seed
:
3056 qemu_guest_random_seed_main(optarg
, &error_fatal
);
3059 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3061 case QEMU_OPTION_gdb
:
3062 add_device_config(DEV_GDB
, optarg
);
3065 if (is_help_option(optarg
)) {
3066 list_data_dirs
= true;
3068 qemu_add_data_dir(g_strdup(optarg
));
3071 case QEMU_OPTION_bios
:
3072 qdict_put_str(machine_opts_dict
, "firmware", optarg
);
3074 case QEMU_OPTION_singlestep
:
3081 keyboard_layout
= optarg
;
3083 case QEMU_OPTION_vga
:
3092 w
= strtol(p
, (char **)&p
, 10);
3095 error_report("invalid resolution or depth");
3101 h
= strtol(p
, (char **)&p
, 10);
3106 depth
= strtol(p
, (char **)&p
, 10);
3107 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
3108 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3109 depth
!= 24 && depth
!= 32)
3111 } else if (*p
== '\0') {
3112 depth
= graphic_depth
;
3119 graphic_depth
= depth
;
3122 case QEMU_OPTION_echr
:
3125 term_escape_char
= strtol(optarg
, &r
, 0);
3127 printf("Bad argument to echr\n");
3130 case QEMU_OPTION_monitor
:
3131 default_monitor
= 0;
3132 if (strncmp(optarg
, "none", 4)) {
3133 monitor_parse(optarg
, "readline", false);
3136 case QEMU_OPTION_qmp
:
3137 monitor_parse(optarg
, "control", false);
3138 default_monitor
= 0;
3140 case QEMU_OPTION_qmp_pretty
:
3141 monitor_parse(optarg
, "control", true);
3142 default_monitor
= 0;
3144 case QEMU_OPTION_mon
:
3145 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3150 default_monitor
= 0;
3152 case QEMU_OPTION_chardev
:
3153 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3159 case QEMU_OPTION_fsdev
:
3160 olist
= qemu_find_opts("fsdev");
3162 error_report("fsdev support is disabled");
3165 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3170 case QEMU_OPTION_virtfs
: {
3173 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3176 olist
= qemu_find_opts("virtfs");
3178 error_report("virtfs support is disabled");
3181 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3186 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3187 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3188 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3191 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3192 qemu_opts_id(opts
) ?:
3193 qemu_opt_get(opts
, "mount_tag"),
3196 error_report("duplicate or invalid fsdev id: %s",
3197 qemu_opt_get(opts
, "mount_tag"));
3201 writeout
= qemu_opt_get(opts
, "writeout");
3203 #ifdef CONFIG_SYNC_FILE_RANGE
3204 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3206 error_report("writeout=immediate not supported "
3207 "on this platform");
3211 qemu_opt_set(fsdev
, "fsdriver",
3212 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3213 path
= qemu_opt_get(opts
, "path");
3215 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3217 security_model
= qemu_opt_get(opts
, "security_model");
3218 if (security_model
) {
3219 qemu_opt_set(fsdev
, "security_model", security_model
,
3222 socket
= qemu_opt_get(opts
, "socket");
3224 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3226 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3228 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3231 qemu_opt_set_bool(fsdev
, "readonly",
3232 qemu_opt_get_bool(opts
, "readonly", 0),
3234 multidevs
= qemu_opt_get(opts
, "multidevs");
3236 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3238 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3240 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3241 qemu_opt_set(device
, "fsdev",
3242 qemu_opts_id(fsdev
), &error_abort
);
3243 qemu_opt_set(device
, "mount_tag",
3244 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3247 case QEMU_OPTION_serial
:
3248 add_device_config(DEV_SERIAL
, optarg
);
3250 if (strncmp(optarg
, "mon:", 4) == 0) {
3251 default_monitor
= 0;
3254 case QEMU_OPTION_watchdog
:
3256 error_report("only one watchdog option may be given");
3261 case QEMU_OPTION_action
:
3262 olist
= qemu_find_opts("action");
3263 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3267 case QEMU_OPTION_watchdog_action
:
3268 if (select_watchdog_action(optarg
) == -1) {
3269 error_report("unknown -watchdog-action parameter");
3273 case QEMU_OPTION_parallel
:
3274 add_device_config(DEV_PARALLEL
, optarg
);
3275 default_parallel
= 0;
3276 if (strncmp(optarg
, "mon:", 4) == 0) {
3277 default_monitor
= 0;
3280 case QEMU_OPTION_debugcon
:
3281 add_device_config(DEV_DEBUGCON
, optarg
);
3283 case QEMU_OPTION_loadvm
:
3286 case QEMU_OPTION_full_screen
:
3287 dpy
.has_full_screen
= true;
3288 dpy
.full_screen
= true;
3290 case QEMU_OPTION_alt_grab
:
3292 warn_report("-alt-grab is deprecated, please use "
3293 "-display sdl,grab-mod=lshift-lctrl-lalt instead.");
3295 case QEMU_OPTION_ctrl_grab
:
3297 warn_report("-ctrl-grab is deprecated, please use "
3298 "-display sdl,grab-mod=rctrl instead.");
3300 case QEMU_OPTION_no_quit
:
3301 dpy
.has_window_close
= true;
3302 dpy
.window_close
= false;
3303 warn_report("-no-quit is deprecated, please use "
3304 "-display ...,window-close=off instead.");
3306 case QEMU_OPTION_sdl
:
3307 warn_report("-sdl is deprecated, use -display sdl instead.");
3309 dpy
.type
= DISPLAY_TYPE_SDL
;
3312 error_report("SDL support is disabled");
3315 case QEMU_OPTION_pidfile
:
3318 case QEMU_OPTION_win2k_hack
:
3319 win2k_install_hack
= 1;
3321 case QEMU_OPTION_acpitable
:
3322 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3327 acpi_table_add(opts
, &error_fatal
);
3329 case QEMU_OPTION_smbios
:
3330 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3335 smbios_entry_add(opts
, &error_fatal
);
3337 case QEMU_OPTION_fwcfg
:
3338 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3344 case QEMU_OPTION_preconfig
:
3345 preconfig_requested
= true;
3347 case QEMU_OPTION_enable_kvm
:
3348 qdict_put_str(machine_opts_dict
, "accel", "kvm");
3351 case QEMU_OPTION_machine
:
3355 keyval_parse_into(machine_opts_dict
, optarg
, "type", &help
, &error_fatal
);
3357 machine_help_func(machine_opts_dict
);
3362 case QEMU_OPTION_accel
:
3363 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3365 optarg
= qemu_opt_get(accel_opts
, "accel");
3366 if (!optarg
|| is_help_option(optarg
)) {
3367 printf("Accelerators supported in QEMU binary:\n");
3368 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3370 for (el
= accel_list
; el
; el
= el
->next
) {
3371 gchar
*typename
= g_strdup(object_class_get_name(
3372 OBJECT_CLASS(el
->data
)));
3373 /* omit qtest which is used for tests only */
3374 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3375 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3376 gchar
**optname
= g_strsplit(typename
,
3377 ACCEL_CLASS_SUFFIX
, 0);
3378 printf("%s\n", optname
[0]);
3379 g_strfreev(optname
);
3383 g_slist_free(accel_list
);
3387 case QEMU_OPTION_usb
:
3388 qdict_put_str(machine_opts_dict
, "usb", "on");
3390 case QEMU_OPTION_usbdevice
:
3391 qdict_put_str(machine_opts_dict
, "usb", "on");
3392 add_device_config(DEV_USB
, optarg
);
3394 case QEMU_OPTION_device
:
3395 if (optarg
[0] == '{') {
3396 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
3397 DeviceOption
*opt
= g_new0(DeviceOption
, 1);
3398 opt
->opts
= qobject_to(QDict
, obj
);
3399 loc_save(&opt
->loc
);
3400 assert(opt
->opts
!= NULL
);
3401 QTAILQ_INSERT_TAIL(&device_opts
, opt
, next
);
3403 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3409 case QEMU_OPTION_smp
:
3410 machine_parse_property_opt(qemu_find_opts("smp-opts"),
3413 case QEMU_OPTION_vnc
:
3416 case QEMU_OPTION_no_acpi
:
3417 qdict_put_str(machine_opts_dict
, "acpi", "off");
3419 case QEMU_OPTION_no_hpet
:
3420 qdict_put_str(machine_opts_dict
, "hpet", "off");
3422 case QEMU_OPTION_no_reboot
:
3423 olist
= qemu_find_opts("action");
3424 qemu_opts_parse_noisily(olist
, "reboot=shutdown", false);
3426 case QEMU_OPTION_no_shutdown
:
3427 olist
= qemu_find_opts("action");
3428 qemu_opts_parse_noisily(olist
, "shutdown=pause", false);
3430 case QEMU_OPTION_uuid
:
3431 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3432 error_report("failed to parse UUID string: wrong format");
3435 qemu_uuid_set
= true;
3437 case QEMU_OPTION_option_rom
:
3438 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3439 error_report("too many option ROMs");
3442 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3447 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3448 option_rom
[nb_option_roms
].bootindex
=
3449 qemu_opt_get_number(opts
, "bootindex", -1);
3450 if (!option_rom
[nb_option_roms
].name
) {
3451 error_report("Option ROM file is not specified");
3456 case QEMU_OPTION_semihosting
:
3457 qemu_semihosting_enable();
3459 case QEMU_OPTION_semihosting_config
:
3460 if (qemu_semihosting_config_options(optarg
) != 0) {
3464 case QEMU_OPTION_name
:
3465 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3470 /* Capture guest name if -msg guest-name is used later */
3471 error_guest_name
= qemu_opt_get(opts
, "guest");
3473 case QEMU_OPTION_prom_env
:
3474 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3475 error_report("too many prom variables");
3478 prom_envs
[nb_prom_envs
] = optarg
;
3481 case QEMU_OPTION_old_param
:
3484 case QEMU_OPTION_rtc
:
3485 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3491 case QEMU_OPTION_icount
:
3492 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3498 case QEMU_OPTION_incoming
:
3500 runstate_set(RUN_STATE_INMIGRATE
);
3504 case QEMU_OPTION_only_migratable
:
3505 only_migratable
= 1;
3507 case QEMU_OPTION_nodefaults
:
3510 case QEMU_OPTION_xen_domid
:
3511 if (!(accel_find("xen"))) {
3512 error_report("Option not supported for this target");
3515 xen_domid
= atoi(optarg
);
3517 case QEMU_OPTION_xen_attach
:
3518 if (!(accel_find("xen"))) {
3519 error_report("Option not supported for this target");
3522 xen_mode
= XEN_ATTACH
;
3524 case QEMU_OPTION_xen_domid_restrict
:
3525 if (!(accel_find("xen"))) {
3526 error_report("Option not supported for this target");
3529 xen_domid_restrict
= true;
3531 case QEMU_OPTION_trace
:
3532 trace_opt_parse(optarg
);
3534 case QEMU_OPTION_plugin
:
3535 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3537 case QEMU_OPTION_readconfig
:
3538 qemu_read_config_file(optarg
, qemu_parse_config_group
, &error_fatal
);
3540 case QEMU_OPTION_spice
:
3541 olist
= qemu_find_opts_err("spice", NULL
);
3543 error_report("spice support is disabled");
3546 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3552 case QEMU_OPTION_writeconfig
:
3555 warn_report("-writeconfig is deprecated and will go away without a replacement");
3556 if (strcmp(optarg
, "-") == 0) {
3559 fp
= fopen(optarg
, "w");
3561 error_report("open %s: %s", optarg
,
3566 qemu_config_write(fp
);
3572 case QEMU_OPTION_qtest
:
3573 qtest_chrdev
= optarg
;
3575 case QEMU_OPTION_qtest_log
:
3578 case QEMU_OPTION_sandbox
:
3579 olist
= qemu_find_opts("sandbox");
3581 #ifndef CONFIG_SECCOMP
3582 error_report("-sandbox support is not enabled "
3583 "in this QEMU binary");
3588 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3593 case QEMU_OPTION_add_fd
:
3595 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3601 error_report("File descriptor passing is disabled on this "
3606 case QEMU_OPTION_object
:
3607 object_option_parse(optarg
);
3609 case QEMU_OPTION_overcommit
:
3610 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3615 enable_mlock
= qemu_opt_get_bool(opts
, "mem-lock", false);
3616 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3618 case QEMU_OPTION_compat
:
3623 v
= qobject_input_visitor_new_str(optarg
, NULL
,
3626 visit_type_CompatPolicy(v
, NULL
, &opts
, &error_fatal
);
3627 QAPI_CLONE_MEMBERS(CompatPolicy
, &compat_policy
, opts
);
3629 qapi_free_CompatPolicy(opts
);
3633 case QEMU_OPTION_msg
:
3634 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3639 configure_msg(opts
);
3641 case QEMU_OPTION_dump_vmstate
:
3642 if (vmstate_dump_file
) {
3643 error_report("only one '-dump-vmstate' "
3644 "option may be given");
3647 vmstate_dump_file
= fopen(optarg
, "w");
3648 if (vmstate_dump_file
== NULL
) {
3649 error_report("open %s: %s", optarg
, strerror(errno
));
3653 case QEMU_OPTION_enable_sync_profile
:
3656 case QEMU_OPTION_nouserconfig
:
3657 /* Nothing to be parsed here. Especially, do not error out below. */
3660 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3661 error_report("Option not supported in this build");
3668 * Clear error location left behind by the loop.
3669 * Best done right after the loop. Do not insert code here!
3673 qemu_validate_options(machine_opts_dict
);
3674 qemu_process_sugar_options();
3677 * These options affect everything else and should be processed
3678 * before daemonizing.
3680 qemu_process_early_options();
3682 qemu_process_help_options();
3683 qemu_maybe_daemonize(pid_file
);
3686 * The trace backend must be initialized after daemonizing.
3687 * trace_init_backends() will call st_init(), which will create the
3688 * trace thread in the parent, and also register st_flush_trace_buffer()
3689 * in atexit(). This function will force the parent to wait for the
3690 * writeout thread to finish, which will not occur, and the parent
3691 * process will be left in the host.
3693 if (!trace_init_backends()) {
3698 qemu_init_main_loop(&error_fatal
);
3701 user_register_global_props();
3702 replay_configure(icount_opts
);
3704 configure_rtc(qemu_find_opts_singleton("rtc"));
3706 qemu_create_machine(machine_opts_dict
);
3710 qemu_disable_default_devices();
3711 qemu_create_default_devices();
3712 qemu_create_early_backends();
3714 qemu_apply_legacy_machine_options(machine_opts_dict
);
3715 qemu_apply_machine_options(machine_opts_dict
);
3716 qobject_unref(machine_opts_dict
);
3717 phase_advance(PHASE_MACHINE_CREATED
);
3720 * Note: uses machine properties such as kernel-irqchip, must run
3721 * after qemu_apply_machine_options.
3723 configure_accelerators(argv
[0]);
3724 phase_advance(PHASE_ACCEL_CREATED
);
3727 * Beware, QOM objects created before this point miss global and
3728 * compat properties.
3730 * Global properties get set up by qdev_prop_register_global(),
3731 * called from user_register_global_props(), and certain option
3732 * desugaring. Also in CPU feature desugaring (buried in
3733 * parse_cpu_option()), which happens below this point, but may
3734 * only target the CPU type, which can only be created after
3735 * parse_cpu_option() returned the type.
3737 * Machine compat properties: object_set_machine_compat_props().
3738 * Accelerator compat props: object_set_accelerator_compat_props(),
3739 * called from do_configure_accelerator().
3742 machine_class
= MACHINE_GET_CLASS(current_machine
);
3743 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
3744 error_report("Machine type '%s' is deprecated: %s",
3745 machine_class
->name
, machine_class
->deprecation_reason
);
3749 * Note: creates a QOM object, must run only after global and
3750 * compat properties have been set up.
3752 migration_object_init();
3754 qemu_create_late_backends();
3756 /* parse features once if machine provides default cpu_type */
3757 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
3759 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
3761 /* NB: for machine none cpu_type could STILL be NULL here! */
3763 qemu_resolve_machine_memdev();
3764 parse_numa_opts(current_machine
);
3766 if (vmstate_dump_file
) {
3768 dump_vmstate_json_to_file(vmstate_dump_file
);
3772 if (!preconfig_requested
) {
3773 qmp_x_exit_preconfig(&error_fatal
);
3775 qemu_init_displays();
3776 accel_setup_post(current_machine
);