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/hw-version.h"
40 #include "qemu/uuid.h"
41 #include "sysemu/reset.h"
42 #include "sysemu/runstate.h"
43 #include "sysemu/runstate-action.h"
44 #include "sysemu/seccomp.h"
45 #include "sysemu/tcg.h"
46 #include "sysemu/xen.h"
48 #include "qemu/error-report.h"
49 #include "qemu/sockets.h"
50 #include "qemu/accel.h"
52 #include "hw/isa/isa.h"
53 #include "hw/scsi/scsi.h"
54 #include "hw/display/vga.h"
55 #include "sysemu/watchdog.h"
56 #include "hw/firmware/smbios.h"
57 #include "hw/acpi/acpi.h"
58 #include "hw/xen/xen.h"
59 #include "hw/loader.h"
60 #include "monitor/qdev.h"
62 #include "net/slirp.h"
63 #include "monitor/monitor.h"
64 #include "ui/console.h"
66 #include "sysemu/sysemu.h"
67 #include "sysemu/numa.h"
68 #include "sysemu/hostmem.h"
69 #include "exec/gdbstub.h"
70 #include "qemu/timer.h"
71 #include "chardev/char.h"
72 #include "qemu/bitmap.h"
74 #include "sysemu/blockdev.h"
75 #include "hw/block/block.h"
76 #include "hw/i386/x86.h"
77 #include "hw/i386/pc.h"
78 #include "migration/misc.h"
79 #include "migration/snapshot.h"
80 #include "sysemu/tpm.h"
81 #include "sysemu/dma.h"
82 #include "hw/audio/soundhw.h"
83 #include "audio/audio.h"
84 #include "sysemu/cpus.h"
85 #include "sysemu/cpu-timers.h"
86 #include "migration/colo.h"
87 #include "migration/postcopy-ram.h"
88 #include "sysemu/kvm.h"
89 #include "sysemu/hax.h"
90 #include "qapi/qobject-input-visitor.h"
91 #include "qemu/option.h"
92 #include "qemu/config-file.h"
93 #include "qemu/qemu-options.h"
94 #include "qemu/main-loop.h"
96 #include "fsdev/qemu-fsdev.h"
98 #include "sysemu/qtest.h"
100 #include "disas/disas.h"
103 #include "trace/control.h"
104 #include "qemu/plugin.h"
105 #include "qemu/queue.h"
106 #include "sysemu/arch_init.h"
107 #include "exec/confidential-guest-support.h"
109 #include "ui/qemu-spice.h"
110 #include "qapi/string-input-visitor.h"
111 #include "qapi/opts-visitor.h"
112 #include "qapi/clone-visitor.h"
113 #include "qom/object_interfaces.h"
114 #include "semihosting/semihost.h"
115 #include "crypto/init.h"
116 #include "sysemu/replay.h"
117 #include "qapi/qapi-events-run-state.h"
118 #include "qapi/qapi-visit-block-core.h"
119 #include "qapi/qapi-visit-compat.h"
120 #include "qapi/qapi-visit-ui.h"
121 #include "qapi/qapi-commands-block-core.h"
122 #include "qapi/qapi-commands-migration.h"
123 #include "qapi/qapi-commands-misc.h"
124 #include "qapi/qapi-visit-qom.h"
125 #include "qapi/qapi-commands-ui.h"
126 #include "qapi/qmp/qdict.h"
127 #include "qapi/qmp/qerror.h"
128 #include "sysemu/iothread.h"
129 #include "qemu/guest-random.h"
131 #include "config-host.h"
133 #define MAX_VIRTIO_CONSOLES 1
135 typedef struct BlockdevOptionsQueueEntry
{
136 BlockdevOptions
*bdo
;
138 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
139 } BlockdevOptionsQueueEntry
;
141 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
143 typedef struct ObjectOption
{
145 QTAILQ_ENTRY(ObjectOption
) next
;
148 typedef struct DeviceOption
{
151 QTAILQ_ENTRY(DeviceOption
) next
;
154 static const char *cpu_option
;
155 static const char *mem_path
;
156 static const char *incoming
;
157 static const char *loadvm
;
158 static const char *accelerators
;
159 static QDict
*machine_opts_dict
;
160 static QTAILQ_HEAD(, ObjectOption
) object_opts
= QTAILQ_HEAD_INITIALIZER(object_opts
);
161 static QTAILQ_HEAD(, DeviceOption
) device_opts
= QTAILQ_HEAD_INITIALIZER(device_opts
);
162 static ram_addr_t maxram_size
;
163 static uint64_t ram_slots
;
164 static int display_remote
;
166 static bool preconfig_requested
;
167 static QemuPluginList plugin_list
= QTAILQ_HEAD_INITIALIZER(plugin_list
);
168 static BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
169 static bool nographic
= false;
170 static int mem_prealloc
; /* force preallocation of physical target memory */
171 static ram_addr_t ram_size
;
172 static const char *vga_model
= NULL
;
173 static DisplayOptions dpy
;
174 static int num_serial_hds
;
175 static Chardev
**serial_hds
;
176 static const char *log_mask
;
177 static const char *log_file
;
178 static bool list_data_dirs
;
179 static const char *watchdog
;
180 static const char *qtest_chrdev
;
181 static const char *qtest_log
;
183 static int has_defaults
= 1;
184 static int default_serial
= 1;
185 static int default_parallel
= 1;
186 static int default_monitor
= 1;
187 static int default_floppy
= 1;
188 static int default_cdrom
= 1;
189 static int default_sdcard
= 1;
190 static int default_vga
= 1;
191 static int default_net
= 1;
197 { .driver
= "isa-serial", .flag
= &default_serial
},
198 { .driver
= "isa-parallel", .flag
= &default_parallel
},
199 { .driver
= "isa-fdc", .flag
= &default_floppy
},
200 { .driver
= "floppy", .flag
= &default_floppy
},
201 { .driver
= "ide-cd", .flag
= &default_cdrom
},
202 { .driver
= "ide-hd", .flag
= &default_cdrom
},
203 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
204 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
205 { .driver
= "VGA", .flag
= &default_vga
},
206 { .driver
= "isa-vga", .flag
= &default_vga
},
207 { .driver
= "cirrus-vga", .flag
= &default_vga
},
208 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
209 { .driver
= "vmware-svga", .flag
= &default_vga
},
210 { .driver
= "qxl-vga", .flag
= &default_vga
},
211 { .driver
= "virtio-vga", .flag
= &default_vga
},
212 { .driver
= "ati-vga", .flag
= &default_vga
},
213 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
214 { .driver
= "virtio-vga-gl", .flag
= &default_vga
},
217 static QemuOptsList qemu_rtc_opts
= {
219 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
224 .type
= QEMU_OPT_STRING
,
227 .type
= QEMU_OPT_STRING
,
230 .type
= QEMU_OPT_STRING
,
232 { /* end of list */ }
236 static QemuOptsList qemu_option_rom_opts
= {
237 .name
= "option-rom",
238 .implied_opt_name
= "romfile",
239 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
243 .type
= QEMU_OPT_NUMBER
,
246 .type
= QEMU_OPT_STRING
,
248 { /* end of list */ }
252 static QemuOptsList qemu_accel_opts
= {
254 .implied_opt_name
= "accel",
255 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
258 * no elements => accept any
259 * sanity checking will happen later
260 * when setting accelerator properties
266 static QemuOptsList qemu_boot_opts
= {
268 .implied_opt_name
= "order",
270 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
274 .type
= QEMU_OPT_STRING
,
277 .type
= QEMU_OPT_STRING
,
280 .type
= QEMU_OPT_BOOL
,
283 .type
= QEMU_OPT_STRING
,
285 .name
= "splash-time",
286 .type
= QEMU_OPT_NUMBER
,
288 .name
= "reboot-timeout",
289 .type
= QEMU_OPT_NUMBER
,
292 .type
= QEMU_OPT_BOOL
,
298 static QemuOptsList qemu_add_fd_opts
= {
300 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
304 .type
= QEMU_OPT_NUMBER
,
305 .help
= "file descriptor of which a duplicate is added to fd set",
308 .type
= QEMU_OPT_NUMBER
,
309 .help
= "ID of the fd set to add fd to",
312 .type
= QEMU_OPT_STRING
,
313 .help
= "free-form string used to describe fd",
315 { /* end of list */ }
319 static QemuOptsList qemu_object_opts
= {
321 .implied_opt_name
= "qom-type",
322 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
328 static QemuOptsList qemu_tpmdev_opts
= {
330 .implied_opt_name
= "type",
331 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
333 /* options are defined in the TPM backends */
334 { /* end of list */ }
338 static QemuOptsList qemu_overcommit_opts
= {
339 .name
= "overcommit",
340 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
344 .type
= QEMU_OPT_BOOL
,
348 .type
= QEMU_OPT_BOOL
,
350 { /* end of list */ }
354 static QemuOptsList qemu_msg_opts
= {
356 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
360 .type
= QEMU_OPT_BOOL
,
363 .name
= "guest-name",
364 .type
= QEMU_OPT_BOOL
,
365 .help
= "Prepends guest name for error messages but only if "
366 "-name guest is set otherwise option is ignored\n",
368 { /* end of list */ }
372 static QemuOptsList qemu_name_opts
= {
374 .implied_opt_name
= "guest",
376 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
380 .type
= QEMU_OPT_STRING
,
381 .help
= "Sets the name of the guest.\n"
382 "This name will be displayed in the SDL window caption.\n"
383 "The name will also be used for the VNC server",
386 .type
= QEMU_OPT_STRING
,
387 .help
= "Sets the name of the QEMU process, as shown in top etc",
389 .name
= "debug-threads",
390 .type
= QEMU_OPT_BOOL
,
391 .help
= "When enabled, name the individual threads; defaults off.\n"
392 "NOTE: The thread names are for debugging and not a\n"
395 { /* End of list */ }
399 static QemuOptsList qemu_mem_opts
= {
401 .implied_opt_name
= "size",
402 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
407 .type
= QEMU_OPT_SIZE
,
411 .type
= QEMU_OPT_NUMBER
,
415 .type
= QEMU_OPT_SIZE
,
417 { /* end of list */ }
421 static QemuOptsList qemu_icount_opts
= {
423 .implied_opt_name
= "shift",
425 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
429 .type
= QEMU_OPT_STRING
,
432 .type
= QEMU_OPT_BOOL
,
435 .type
= QEMU_OPT_BOOL
,
438 .type
= QEMU_OPT_STRING
,
441 .type
= QEMU_OPT_STRING
,
443 .name
= "rrsnapshot",
444 .type
= QEMU_OPT_STRING
,
446 { /* end of list */ }
450 static QemuOptsList qemu_fw_cfg_opts
= {
452 .implied_opt_name
= "name",
453 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
457 .type
= QEMU_OPT_STRING
,
458 .help
= "Sets the fw_cfg name of the blob to be inserted",
461 .type
= QEMU_OPT_STRING
,
462 .help
= "Sets the name of the file from which "
463 "the fw_cfg blob will be loaded",
466 .type
= QEMU_OPT_STRING
,
467 .help
= "Sets content of the blob to be inserted from a string",
470 .type
= QEMU_OPT_STRING
,
471 .help
= "Sets id of the object generating the fw_cfg blob "
474 { /* end of list */ }
478 static QemuOptsList qemu_action_opts
= {
481 .head
= QTAILQ_HEAD_INITIALIZER(qemu_action_opts
.head
),
485 .type
= QEMU_OPT_STRING
,
488 .type
= QEMU_OPT_STRING
,
491 .type
= QEMU_OPT_STRING
,
494 .type
= QEMU_OPT_STRING
,
496 { /* end of list */ }
500 const char *qemu_get_vm_name(void)
505 static void default_driver_disable(const char *driver
)
513 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
514 if (strcmp(default_list
[i
].driver
, driver
) != 0)
516 *(default_list
[i
].flag
) = 0;
520 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
522 const char *driver
= qemu_opt_get(opts
, "driver");
524 default_driver_disable(driver
);
528 static void default_driver_check_json(void)
532 QTAILQ_FOREACH(opt
, &device_opts
, next
) {
533 const char *driver
= qdict_get_try_str(opt
->opts
, "driver");
534 default_driver_disable(driver
);
538 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
540 const char *proc_name
;
542 if (qemu_opt_get(opts
, "debug-threads")) {
543 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
545 qemu_name
= qemu_opt_get(opts
, "guest");
547 proc_name
= qemu_opt_get(opts
, "process");
549 os_set_proc_name(proc_name
);
555 bool defaults_enabled(void)
561 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
563 int fd
, dupfd
, flags
;
565 const char *fd_opaque
= NULL
;
568 fd
= qemu_opt_get_number(opts
, "fd", -1);
569 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
570 fd_opaque
= qemu_opt_get(opts
, "opaque");
573 error_setg(errp
, "fd option is required and must be non-negative");
577 if (fd
<= STDERR_FILENO
) {
578 error_setg(errp
, "fd cannot be a standard I/O stream");
583 * All fds inherited across exec() necessarily have FD_CLOEXEC
584 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
586 flags
= fcntl(fd
, F_GETFD
);
587 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
588 error_setg(errp
, "fd is not valid or already in use");
593 error_setg(errp
, "set option is required and must be non-negative");
597 #ifdef F_DUPFD_CLOEXEC
598 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
602 qemu_set_cloexec(dupfd
);
606 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
610 /* add the duplicate fd, and optionally the opaque string, to the fd set */
611 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
618 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
622 fd
= qemu_opt_get_number(opts
, "fd", -1);
629 /***********************************************************/
630 /* QEMU Block devices */
632 #define HD_OPTS "media=disk"
633 #define CDROM_OPTS "media=cdrom"
635 #define PFLASH_OPTS ""
639 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
641 BlockInterfaceType
*block_default_type
= opaque
;
643 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
646 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
648 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
649 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
654 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
655 int index
, const char *optstr
)
660 if (!enable
|| drive_get_by_index(type
, index
)) {
664 opts
= drive_add(type
, index
, NULL
, optstr
);
666 drive_enable_snapshot(NULL
, opts
, NULL
);
669 dinfo
= drive_new(opts
, type
, &error_abort
);
670 dinfo
->is_default
= true;
674 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
675 MachineClass
*machine_class
, int snapshot
)
678 * If the currently selected machine wishes to override the
679 * units-per-bus property of its default HBA interface type, do so
682 if (machine_class
->units_per_default_bus
) {
683 override_max_devs(machine_class
->block_default_type
,
684 machine_class
->units_per_default_bus
);
687 /* open the virtual block devices */
688 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
689 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
691 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
692 loc_push_restore(&bdo
->loc
);
693 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
695 qapi_free_BlockdevOptions(bdo
->bdo
);
699 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
702 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
703 &machine_class
->block_default_type
, &error_fatal
)) {
704 /* We printed help */
708 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
710 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
711 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
715 static QemuOptsList qemu_smp_opts
= {
717 .implied_opt_name
= "cpus",
719 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
723 .type
= QEMU_OPT_NUMBER
,
726 .type
= QEMU_OPT_NUMBER
,
729 .type
= QEMU_OPT_NUMBER
,
732 .type
= QEMU_OPT_NUMBER
,
735 .type
= QEMU_OPT_NUMBER
,
738 .type
= QEMU_OPT_NUMBER
,
741 .type
= QEMU_OPT_NUMBER
,
747 static void realtime_init(void)
750 if (os_mlock() < 0) {
751 error_report("locking memory failed");
758 static void configure_msg(QemuOpts
*opts
)
760 message_with_timestamp
= qemu_opt_get_bool(opts
, "timestamp", false);
761 error_with_guestname
= qemu_opt_get_bool(opts
, "guest-name", false);
765 /***********************************************************/
768 static int usb_device_add(const char *devname
)
770 USBDevice
*dev
= NULL
;
772 if (!machine_usb(current_machine
)) {
776 dev
= usbdevice_create(devname
);
783 static int usb_parse(const char *cmdline
)
786 r
= usb_device_add(cmdline
);
788 error_report("could not add USB device '%s'", cmdline
);
793 /***********************************************************/
794 /* machine registration */
796 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
800 for (el
= machines
; el
; el
= el
->next
) {
801 MachineClass
*mc
= el
->data
;
803 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
811 static MachineClass
*find_default_machine(GSList
*machines
)
814 MachineClass
*default_machineclass
= NULL
;
816 for (el
= machines
; el
; el
= el
->next
) {
817 MachineClass
*mc
= el
->data
;
819 if (mc
->is_default
) {
820 assert(default_machineclass
== NULL
&& "Multiple default machines");
821 default_machineclass
= mc
;
825 return default_machineclass
;
828 static void version(void)
830 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
831 QEMU_COPYRIGHT
"\n");
834 static void help(int exitcode
)
837 printf("usage: %s [options] [disk_image]\n\n"
838 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
839 error_get_progname());
841 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
842 if ((arch_mask) & arch_type) \
843 fputs(opt_help, stdout);
845 #define ARCHHEADING(text, arch_mask) \
846 if ((arch_mask) & arch_type) \
847 puts(stringify(text));
849 #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL)
851 #include "qemu-options.def"
853 printf("\nDuring emulation, the following keys are useful:\n"
854 "ctrl-alt-f toggle full screen\n"
855 "ctrl-alt-n switch to virtual console 'n'\n"
856 "ctrl-alt toggle mouse and keyboard grab\n"
858 "When using -nographic, press 'ctrl-a h' to get some help.\n"
860 QEMU_HELP_BOTTOM
"\n");
865 #define HAS_ARG 0x0001
867 typedef struct QEMUOption
{
874 static const QEMUOption qemu_options
[] = {
875 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
877 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
878 { option, opt_arg, opt_enum, arch_mask },
879 #define DEFHEADING(text)
880 #define ARCHHEADING(text, arch_mask)
882 #include "qemu-options.def"
886 typedef struct VGAInterfaceInfo
{
887 const char *opt_name
; /* option name */
888 const char *name
; /* human-readable name */
889 /* Class names indicating that support is available.
890 * If no class is specified, the interface is always available */
891 const char *class_names
[2];
894 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
897 .name
= "no graphic card",
901 .name
= "standard VGA",
902 .class_names
= { "VGA", "isa-vga" },
905 .opt_name
= "cirrus",
906 .name
= "Cirrus VGA",
907 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
910 .opt_name
= "vmware",
911 .name
= "VMWare SVGA",
912 .class_names
= { "vmware-svga" },
915 .opt_name
= "virtio",
916 .name
= "Virtio VGA",
917 .class_names
= { "virtio-vga" },
922 .class_names
= { "qxl-vga" },
926 .name
= "TCX framebuffer",
927 .class_names
= { "sun-tcx" },
931 .name
= "CG3 framebuffer",
932 .class_names
= { "cgthree" },
936 .name
= "Xen paravirtualized framebuffer",
940 static bool vga_interface_available(VGAInterfaceType t
)
942 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
944 assert(t
< VGA_TYPE_MAX
);
945 return !ti
->class_names
[0] ||
946 module_object_class_by_name(ti
->class_names
[0]) ||
947 module_object_class_by_name(ti
->class_names
[1]);
951 get_default_vga_model(const MachineClass
*machine_class
)
953 if (machine_class
->default_display
) {
954 return machine_class
->default_display
;
955 } else if (vga_interface_available(VGA_CIRRUS
)) {
957 } else if (vga_interface_available(VGA_STD
)) {
964 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
969 if (g_str_equal(p
, "help")) {
970 const char *def
= get_default_vga_model(machine_class
);
972 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
973 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
975 if (vga_interface_available(t
) && ti
->opt_name
) {
976 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
977 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
983 assert(vga_interface_type
== VGA_NONE
);
984 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
985 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
986 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
987 if (!vga_interface_available(t
)) {
988 error_report("%s not available", ti
->name
);
991 vga_interface_type
= t
;
995 if (t
== VGA_TYPE_MAX
) {
997 error_report("unknown vga type: %s", p
);
1001 const char *nextopt
;
1003 if (strstart(opts
, ",retrace=", &nextopt
)) {
1005 if (strstart(opts
, "dumb", &nextopt
))
1006 vga_retrace_method
= VGA_RETRACE_DUMB
;
1007 else if (strstart(opts
, "precise", &nextopt
))
1008 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1009 else goto invalid_vga
;
1010 } else goto invalid_vga
;
1015 static void parse_display_qapi(const char *optarg
)
1017 DisplayOptions
*opts
;
1020 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
1022 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
1023 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
1025 qapi_free_DisplayOptions(opts
);
1029 DisplayOptions
*qmp_query_display_options(Error
**errp
)
1031 return QAPI_CLONE(DisplayOptions
, &dpy
);
1034 static void parse_display(const char *p
)
1038 if (is_help_option(p
)) {
1039 qemu_display_help();
1043 if (strstart(p
, "sdl", &opts
)) {
1045 * sdl DisplayType needs hand-crafted parser instead of
1046 * parse_display_qapi() due to some options not in
1047 * DisplayOptions, specifically:
1048 * - ctrl_grab + alt_grab
1049 * They can't be moved into the QAPI since they use underscores,
1050 * thus they will get replaced by "grab-mod" in the long term
1052 #if defined(CONFIG_SDL)
1053 dpy
.type
= DISPLAY_TYPE_SDL
;
1055 const char *nextopt
;
1057 if (strstart(opts
, ",grab-mod=", &nextopt
)) {
1059 if (strstart(opts
, "lshift-lctrl-lalt", &nextopt
)) {
1061 } else if (strstart(opts
, "rctrl", &nextopt
)) {
1064 goto invalid_sdl_args
;
1066 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1068 if (strstart(opts
, "on", &nextopt
)) {
1070 } else if (strstart(opts
, "off", &nextopt
)) {
1073 goto invalid_sdl_args
;
1075 warn_report("alt_grab is deprecated, use grab-mod instead.");
1076 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1078 if (strstart(opts
, "on", &nextopt
)) {
1080 } else if (strstart(opts
, "off", &nextopt
)) {
1083 goto invalid_sdl_args
;
1085 warn_report("ctrl_grab is deprecated, use grab-mod instead.");
1086 } else if (strstart(opts
, ",window_close=", &nextopt
) ||
1087 strstart(opts
, ",window-close=", &nextopt
)) {
1088 if (strstart(opts
, ",window_close=", NULL
)) {
1089 warn_report("window_close with an underscore is deprecated,"
1090 " please use window-close instead.");
1093 dpy
.has_window_close
= true;
1094 if (strstart(opts
, "on", &nextopt
)) {
1095 dpy
.window_close
= true;
1096 } else if (strstart(opts
, "off", &nextopt
)) {
1097 dpy
.window_close
= false;
1099 goto invalid_sdl_args
;
1101 } else if (strstart(opts
, ",show-cursor=", &nextopt
)) {
1103 dpy
.has_show_cursor
= true;
1104 if (strstart(opts
, "on", &nextopt
)) {
1105 dpy
.show_cursor
= true;
1106 } else if (strstart(opts
, "off", &nextopt
)) {
1107 dpy
.show_cursor
= false;
1109 goto invalid_sdl_args
;
1111 } else if (strstart(opts
, ",gl=", &nextopt
)) {
1114 if (strstart(opts
, "on", &nextopt
)) {
1115 dpy
.gl
= DISPLAYGL_MODE_ON
;
1116 } else if (strstart(opts
, "core", &nextopt
)) {
1117 dpy
.gl
= DISPLAYGL_MODE_CORE
;
1118 } else if (strstart(opts
, "es", &nextopt
)) {
1119 dpy
.gl
= DISPLAYGL_MODE_ES
;
1120 } else if (strstart(opts
, "off", &nextopt
)) {
1121 dpy
.gl
= DISPLAYGL_MODE_OFF
;
1123 goto invalid_sdl_args
;
1127 error_report("invalid SDL option string");
1133 error_report("SDL display supported is not available in this binary");
1136 } else if (strstart(p
, "vnc", &opts
)) {
1138 * vnc isn't a (local) DisplayType but a protocol for remote
1142 vnc_parse(opts
+ 1);
1144 error_report("VNC requires a display argument vnc=<display>");
1148 parse_display_qapi(p
);
1152 static inline bool nonempty_str(const char *str
)
1157 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1161 const char *name
, *file
, *str
, *gen_id
;
1162 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1164 if (fw_cfg
== NULL
) {
1165 error_setg(errp
, "fw_cfg device not available");
1168 name
= qemu_opt_get(opts
, "name");
1169 file
= qemu_opt_get(opts
, "file");
1170 str
= qemu_opt_get(opts
, "string");
1171 gen_id
= qemu_opt_get(opts
, "gen_id");
1173 /* we need the name, and exactly one of: file, content string, gen_id */
1174 if (!nonempty_str(name
) ||
1175 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1176 error_setg(errp
, "name, plus exactly one of file,"
1177 " string and gen_id, are needed");
1180 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1181 error_setg(errp
, "name too long (max. %d char)",
1182 FW_CFG_MAX_FILE_PATH
- 1);
1185 if (nonempty_str(gen_id
)) {
1187 * In this particular case where the content is populated
1188 * internally, the "etc/" namespace protection is relaxed,
1189 * so do not emit a warning.
1191 } else if (strncmp(name
, "opt/", 4) != 0) {
1192 warn_report("externally provided fw_cfg item names "
1193 "should be prefixed with \"opt/\"");
1195 if (nonempty_str(str
)) {
1196 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1197 buf
= g_memdup(str
, size
);
1198 } else if (nonempty_str(gen_id
)) {
1199 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1205 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1206 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1211 /* For legacy, keep user files in a specific global order. */
1212 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1213 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1214 fw_cfg_reset_order_override(fw_cfg
);
1218 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1220 return qdev_device_help(opts
);
1223 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1227 dev
= qdev_device_add(opts
, errp
);
1228 if (!dev
&& *errp
) {
1229 error_report_err(*errp
);
1232 object_unref(OBJECT(dev
));
1237 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1239 Error
*local_err
= NULL
;
1241 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1243 error_propagate(errp
, local_err
);
1251 #ifdef CONFIG_VIRTFS
1252 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1254 return qemu_fsdev_add(opts
, errp
);
1258 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1260 return monitor_init_opts(opts
, errp
);
1263 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
1265 static int monitor_device_index
= 0;
1270 if (strstart(optarg
, "chardev:", &p
)) {
1271 snprintf(label
, sizeof(label
), "%s", p
);
1273 snprintf(label
, sizeof(label
), "compat_monitor%d",
1274 monitor_device_index
);
1275 opts
= qemu_chr_parse_compat(label
, optarg
, true);
1277 error_report("parse error: %s", optarg
);
1282 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1283 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1284 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1285 if (!strcmp(mode
, "control")) {
1286 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1288 assert(pretty
== false);
1290 monitor_device_index
++;
1293 struct device_config
{
1295 DEV_USB
, /* -usbdevice */
1296 DEV_SERIAL
, /* -serial */
1297 DEV_PARALLEL
, /* -parallel */
1298 DEV_DEBUGCON
, /* -debugcon */
1299 DEV_GDB
, /* -gdb, -s */
1300 DEV_SCLP
, /* s390 sclp */
1302 const char *cmdline
;
1304 QTAILQ_ENTRY(device_config
) next
;
1307 static QTAILQ_HEAD(, device_config
) device_configs
=
1308 QTAILQ_HEAD_INITIALIZER(device_configs
);
1310 static void add_device_config(int type
, const char *cmdline
)
1312 struct device_config
*conf
;
1314 conf
= g_malloc0(sizeof(*conf
));
1316 conf
->cmdline
= cmdline
;
1317 loc_save(&conf
->loc
);
1318 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1321 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1323 struct device_config
*conf
;
1326 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1327 if (conf
->type
!= type
)
1329 loc_push_restore(&conf
->loc
);
1330 rc
= func(conf
->cmdline
);
1331 loc_pop(&conf
->loc
);
1339 static void qemu_disable_default_devices(void)
1341 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1343 default_driver_check_json();
1344 qemu_opts_foreach(qemu_find_opts("device"),
1345 default_driver_check
, NULL
, NULL
);
1346 qemu_opts_foreach(qemu_find_opts("global"),
1347 default_driver_check
, NULL
, NULL
);
1349 if (!vga_model
&& !default_vga
) {
1350 vga_interface_type
= VGA_DEVICE
;
1352 if (!has_defaults
|| machine_class
->no_serial
) {
1355 if (!has_defaults
|| machine_class
->no_parallel
) {
1356 default_parallel
= 0;
1358 if (!has_defaults
|| machine_class
->no_floppy
) {
1361 if (!has_defaults
|| machine_class
->no_cdrom
) {
1364 if (!has_defaults
|| machine_class
->no_sdcard
) {
1367 if (!has_defaults
) {
1368 default_monitor
= 0;
1374 static void qemu_create_default_devices(void)
1376 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1378 if (is_daemonized()) {
1379 /* According to documentation and historically, -nographic redirects
1380 * serial port, parallel port and monitor to stdio, which does not work
1381 * with -daemonize. We can redirect these to null instead, but since
1382 * -nographic is legacy, let's just error out.
1383 * We disallow -nographic only if all other ports are not redirected
1384 * explicitly, to not break existing legacy setups which uses
1385 * -nographic _and_ redirects all ports explicitly - this is valid
1386 * usage, -nographic is just a no-op in this case.
1389 && (default_parallel
|| default_serial
|| default_monitor
)) {
1390 error_report("-nographic cannot be used with -daemonize");
1396 if (default_parallel
)
1397 add_device_config(DEV_PARALLEL
, "null");
1398 if (default_serial
&& default_monitor
) {
1399 add_device_config(DEV_SERIAL
, "mon:stdio");
1402 add_device_config(DEV_SERIAL
, "stdio");
1403 if (default_monitor
)
1404 monitor_parse("stdio", "readline", false);
1408 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
1409 if (default_parallel
)
1410 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
1411 if (default_monitor
)
1412 monitor_parse("vc:80Cx24C", "readline", false);
1416 QemuOptsList
*net
= qemu_find_opts("net");
1417 qemu_opts_parse(net
, "nic", true, &error_abort
);
1419 qemu_opts_parse(net
, "user", true, &error_abort
);
1423 #if defined(CONFIG_VNC)
1424 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
1428 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1429 if (!qemu_display_find_default(&dpy
)) {
1430 dpy
.type
= DISPLAY_TYPE_NONE
;
1431 #if defined(CONFIG_VNC)
1432 vnc_parse("localhost:0,to=99,id=default");
1436 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1437 dpy
.type
= DISPLAY_TYPE_NONE
;
1440 /* If no default VGA is requested, the default is "none". */
1442 vga_model
= get_default_vga_model(machine_class
);
1445 select_vgahw(machine_class
, vga_model
);
1449 static int serial_parse(const char *devname
)
1451 int index
= num_serial_hds
;
1454 if (strcmp(devname
, "none") == 0)
1456 snprintf(label
, sizeof(label
), "serial%d", index
);
1457 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1459 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1460 if (!serial_hds
[index
]) {
1461 error_report("could not connect serial device"
1462 " to character backend '%s'", devname
);
1469 Chardev
*serial_hd(int i
)
1472 if (i
< num_serial_hds
) {
1473 return serial_hds
[i
];
1478 static int parallel_parse(const char *devname
)
1480 static int index
= 0;
1483 if (strcmp(devname
, "none") == 0)
1485 if (index
== MAX_PARALLEL_PORTS
) {
1486 error_report("too many parallel ports");
1489 snprintf(label
, sizeof(label
), "parallel%d", index
);
1490 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1491 if (!parallel_hds
[index
]) {
1492 error_report("could not connect parallel device"
1493 " to character backend '%s'", devname
);
1500 static int debugcon_parse(const char *devname
)
1504 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1505 error_report("invalid character backend '%s'", devname
);
1508 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1510 error_report("already have a debugcon device");
1513 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1514 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1518 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1520 const MachineClass
*mc1
= a
, *mc2
= b
;
1523 if (mc1
->family
== NULL
) {
1524 if (mc2
->family
== NULL
) {
1525 /* Compare standalone machine types against each other; they sort
1526 * in increasing order.
1528 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1529 object_class_get_name(OBJECT_CLASS(mc2
)));
1532 /* Standalone machine types sort after families. */
1536 if (mc2
->family
== NULL
) {
1537 /* Families sort before standalone machine types. */
1541 /* Families sort between each other alphabetically increasingly. */
1542 res
= strcmp(mc1
->family
, mc2
->family
);
1547 /* Within the same family, machine types sort in decreasing order. */
1548 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1549 object_class_get_name(OBJECT_CLASS(mc1
)));
1552 static void machine_help_func(const QDict
*qdict
)
1554 GSList
*machines
, *el
;
1555 const char *type
= qdict_get_try_str(qdict
, "type");
1557 machines
= object_class_get_list(TYPE_MACHINE
, false);
1559 ObjectClass
*machine_class
= OBJECT_CLASS(find_machine(type
, machines
));
1560 if (machine_class
) {
1561 type_print_class_properties(object_class_get_name(machine_class
));
1566 printf("Supported machines are:\n");
1567 machines
= g_slist_sort(machines
, machine_class_cmp
);
1568 for (el
= machines
; el
; el
= el
->next
) {
1569 MachineClass
*mc
= el
->data
;
1571 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1573 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1574 mc
->is_default
? " (default)" : "",
1575 mc
->deprecation_reason
? " (deprecated)" : "");
1580 machine_merge_property(const char *propname
, QDict
*prop
, Error
**errp
)
1585 /* Preserve the caller's reference to prop. */
1587 qdict_put(opts
, propname
, prop
);
1588 keyval_merge(machine_opts_dict
, opts
, errp
);
1589 qobject_unref(opts
);
1593 machine_parse_property_opt(QemuOptsList
*opts_list
, const char *propname
,
1599 prop
= keyval_parse(arg
, opts_list
->implied_opt_name
, &help
, &error_fatal
);
1601 qemu_opts_print_help(opts_list
, true);
1604 machine_merge_property(propname
, prop
, &error_fatal
);
1605 qobject_unref(prop
);
1608 static const char *pid_file
;
1609 static Notifier qemu_unlink_pidfile_notifier
;
1611 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1618 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1619 const char **poptarg
, int *poptind
)
1621 const QEMUOption
*popt
;
1622 int optind
= *poptind
;
1623 char *r
= argv
[optind
];
1626 loc_set_cmdline(argv
, optind
, 1);
1628 /* Treat --foo the same as -foo. */
1631 popt
= qemu_options
;
1634 error_report("invalid option");
1637 if (!strcmp(popt
->name
, r
+ 1))
1641 if (popt
->flags
& HAS_ARG
) {
1642 if (optind
>= argc
) {
1643 error_report("requires an argument");
1646 optarg
= argv
[optind
++];
1647 loc_set_cmdline(argv
, optind
- 2, 2);
1658 static MachineClass
*select_machine(QDict
*qdict
, Error
**errp
)
1660 const char *optarg
= qdict_get_try_str(qdict
, "type");
1661 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
1662 MachineClass
*machine_class
;
1663 Error
*local_err
= NULL
;
1666 machine_class
= find_machine(optarg
, machines
);
1667 qdict_del(qdict
, "type");
1668 if (!machine_class
) {
1669 error_setg(&local_err
, "unsupported machine type");
1672 machine_class
= find_default_machine(machines
);
1673 if (!machine_class
) {
1674 error_setg(&local_err
, "No machine specified, and there is no default");
1678 g_slist_free(machines
);
1680 error_append_hint(&local_err
, "Use -machine help to list supported machines\n");
1681 error_propagate(errp
, local_err
);
1683 return machine_class
;
1686 static int object_parse_property_opt(Object
*obj
,
1687 const char *name
, const char *value
,
1688 const char *skip
, Error
**errp
)
1690 if (g_str_equal(name
, skip
)) {
1694 if (!object_property_parse(obj
, name
, value
, errp
)) {
1701 /* *Non*recursively replace underscores with dashes in QDict keys. */
1702 static void keyval_dashify(QDict
*qdict
, Error
**errp
)
1704 const QDictEntry
*ent
, *next
;
1707 for (ent
= qdict_first(qdict
); ent
; ent
= next
) {
1708 g_autofree
char *new_key
= NULL
;
1710 next
= qdict_next(qdict
, ent
);
1711 if (!strchr(ent
->key
, '_')) {
1714 new_key
= g_strdup(ent
->key
);
1715 for (p
= new_key
; *p
; p
++) {
1720 if (qdict_haskey(qdict
, new_key
)) {
1721 error_setg(errp
, "Conflict between '%s' and '%s'", ent
->key
, new_key
);
1724 qobject_ref(ent
->value
);
1725 qdict_put_obj(qdict
, new_key
, ent
->value
);
1726 qdict_del(qdict
, ent
->key
);
1730 static void qemu_apply_legacy_machine_options(QDict
*qdict
)
1734 keyval_dashify(qdict
, &error_fatal
);
1736 /* Legacy options do not correspond to MachineState properties. */
1737 value
= qdict_get_try_str(qdict
, "accel");
1739 accelerators
= g_strdup(value
);
1740 qdict_del(qdict
, "accel");
1743 value
= qdict_get_try_str(qdict
, "igd-passthru");
1745 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value
,
1747 qdict_del(qdict
, "igd-passthru");
1750 value
= qdict_get_try_str(qdict
, "kvm-shadow-mem");
1752 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value
,
1754 qdict_del(qdict
, "kvm-shadow-mem");
1757 value
= qdict_get_try_str(qdict
, "kernel-irqchip");
1759 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value
,
1761 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value
,
1763 qdict_del(qdict
, "kernel-irqchip");
1767 static void object_option_foreach_add(bool (*type_opt_predicate
)(const char *))
1769 ObjectOption
*opt
, *next
;
1771 QTAILQ_FOREACH_SAFE(opt
, &object_opts
, next
, next
) {
1772 const char *type
= ObjectType_str(opt
->opts
->qom_type
);
1773 if (type_opt_predicate(type
)) {
1774 user_creatable_add_qapi(opt
->opts
, &error_fatal
);
1775 qapi_free_ObjectOptions(opt
->opts
);
1776 QTAILQ_REMOVE(&object_opts
, opt
, next
);
1782 static void object_option_add_visitor(Visitor
*v
)
1784 ObjectOption
*opt
= g_new0(ObjectOption
, 1);
1785 visit_type_ObjectOptions(v
, NULL
, &opt
->opts
, &error_fatal
);
1786 QTAILQ_INSERT_TAIL(&object_opts
, opt
, next
);
1789 static void object_option_parse(const char *optarg
)
1795 if (optarg
[0] == '{') {
1796 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
1798 v
= qobject_input_visitor_new(obj
);
1801 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
1807 type
= qemu_opt_get(opts
, "qom-type");
1809 error_setg(&error_fatal
, QERR_MISSING_PARAMETER
, "qom-type");
1811 if (user_creatable_print_help(type
, opts
)) {
1815 v
= opts_visitor_new(opts
);
1818 object_option_add_visitor(v
);
1823 * Initial object creation happens before all other
1824 * QEMU data types are created. The majority of objects
1825 * can be created at this point. The rng-egd object
1826 * cannot be created here, as it depends on the chardev
1829 static bool object_create_early(const char *type
)
1832 * Objects should not be made "delayed" without a reason. If you
1833 * add one, state the reason in a comment!
1836 /* Reason: property "chardev" */
1837 if (g_str_equal(type
, "rng-egd") ||
1838 g_str_equal(type
, "qtest")) {
1842 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1843 /* Reason: cryptodev-vhost-user property "chardev" */
1844 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1849 /* Reason: vhost-user-blk-server property "node-name" */
1850 if (g_str_equal(type
, "vhost-user-blk-server")) {
1854 * Reason: filter-* property "netdev" etc.
1856 if (g_str_equal(type
, "filter-buffer") ||
1857 g_str_equal(type
, "filter-dump") ||
1858 g_str_equal(type
, "filter-mirror") ||
1859 g_str_equal(type
, "filter-redirector") ||
1860 g_str_equal(type
, "colo-compare") ||
1861 g_str_equal(type
, "filter-rewriter") ||
1862 g_str_equal(type
, "filter-replay")) {
1867 * Allocation of large amounts of memory may delay
1868 * chardev initialization for too long, and trigger timeouts
1869 * on software that waits for a monitor socket to be created
1872 if (g_str_has_prefix(type
, "memory-backend-")) {
1879 static void qemu_apply_machine_options(QDict
*qdict
)
1881 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1882 const char *boot_order
= NULL
;
1883 const char *boot_once
= NULL
;
1886 object_set_properties_from_keyval(OBJECT(current_machine
), qdict
, false, &error_fatal
);
1887 current_machine
->ram_size
= ram_size
;
1888 current_machine
->maxram_size
= maxram_size
;
1889 current_machine
->ram_slots
= ram_slots
;
1891 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
1893 boot_order
= qemu_opt_get(opts
, "order");
1895 validate_bootdevices(boot_order
, &error_fatal
);
1898 boot_once
= qemu_opt_get(opts
, "once");
1900 validate_bootdevices(boot_once
, &error_fatal
);
1903 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
1904 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
1908 boot_order
= machine_class
->default_boot_order
;
1911 current_machine
->boot_order
= boot_order
;
1912 current_machine
->boot_once
= boot_once
;
1914 if (semihosting_enabled() && !semihosting_get_argc()) {
1915 /* fall back to the -kernel/-append */
1916 semihosting_arg_fallback(current_machine
->kernel_filename
, current_machine
->kernel_cmdline
);
1919 if (current_machine
->smp
.cpus
> 1) {
1920 Error
*blocker
= NULL
;
1921 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1922 replay_add_blocker(blocker
);
1926 static void qemu_create_early_backends(void)
1928 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1929 #if defined(CONFIG_SDL)
1930 const bool use_sdl
= (dpy
.type
== DISPLAY_TYPE_SDL
);
1932 const bool use_sdl
= false;
1934 #if defined(CONFIG_GTK)
1935 const bool use_gtk
= (dpy
.type
== DISPLAY_TYPE_GTK
);
1937 const bool use_gtk
= false;
1940 if ((alt_grab
|| ctrl_grab
) && !use_sdl
) {
1941 error_report("-alt-grab and -ctrl-grab are only valid "
1942 "for SDL, ignoring option");
1944 if (dpy
.has_window_close
&& !use_gtk
&& !use_sdl
) {
1945 error_report("window-close is only valid for GTK and SDL, "
1949 qemu_display_early_init(&dpy
);
1950 qemu_console_early_init();
1952 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1953 #if defined(CONFIG_OPENGL)
1954 error_report("OpenGL is not supported by the display");
1956 error_report("OpenGL support is disabled");
1961 object_option_foreach_add(object_create_early
);
1963 /* spice needs the timers to be initialized by this point */
1964 /* spice must initialize before audio as it changes the default auiodev */
1965 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1968 qemu_opts_foreach(qemu_find_opts("chardev"),
1969 chardev_init_func
, NULL
, &error_fatal
);
1971 #ifdef CONFIG_VIRTFS
1972 qemu_opts_foreach(qemu_find_opts("fsdev"),
1973 fsdev_init_func
, NULL
, &error_fatal
);
1977 * Note: we need to create audio and block backends before
1978 * setting machine properties, so they can be referred to.
1980 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
1981 audio_init_audiodevs();
1986 * The remainder of object creation happens after the
1987 * creation of chardev, fsdev, net clients and device data types.
1989 static bool object_create_late(const char *type
)
1991 return !object_create_early(type
);
1994 static void qemu_create_late_backends(void)
1997 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
2000 net_init_clients(&error_fatal
);
2002 object_option_foreach_add(object_create_late
);
2004 if (tpm_init() < 0) {
2008 qemu_opts_foreach(qemu_find_opts("mon"),
2009 mon_init_func
, NULL
, &error_fatal
);
2011 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2013 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2015 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2018 /* now chardevs have been created we may have semihosting to connect */
2019 qemu_semihosting_connect_chardevs();
2020 qemu_semihosting_console_init();
2023 static bool have_custom_ram_size(void)
2025 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2026 return !!qemu_opt_get_size(opts
, "size", 0);
2029 static void qemu_resolve_machine_memdev(void)
2031 if (current_machine
->ram_memdev_id
) {
2033 ram_addr_t backend_size
;
2035 backend
= object_resolve_path_type(current_machine
->ram_memdev_id
,
2036 TYPE_MEMORY_BACKEND
, NULL
);
2038 error_report("Memory backend '%s' not found",
2039 current_machine
->ram_memdev_id
);
2042 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
2043 if (have_custom_ram_size() && backend_size
!= ram_size
) {
2044 error_report("Size specified by -m option must match size of "
2045 "explicitly specified 'memory-backend' property");
2049 error_report("'-mem-path' can't be used together with"
2050 "'-machine memory-backend'");
2053 ram_size
= backend_size
;
2056 if (!xen_enabled()) {
2057 /* On 32-bit hosts, QEMU is limited by virtual address space */
2058 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2059 error_report("at most 2047 MB RAM can be simulated");
2065 static void set_memory_options(MachineClass
*mc
)
2068 const char *mem_str
;
2069 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2070 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2073 loc_push_none(&loc
);
2074 qemu_opts_loc_restore(opts
);
2077 mem_str
= qemu_opt_get(opts
, "size");
2080 error_report("missing 'size' option value");
2084 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2086 /* Fix up legacy suffix-less format */
2087 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2088 uint64_t overflow_check
= sz
;
2091 if (sz
/ MiB
!= overflow_check
) {
2092 error_report("too large 'size' option value");
2098 /* backward compatibility behaviour for case "-m 0" */
2100 sz
= default_ram_size
;
2103 sz
= QEMU_ALIGN_UP(sz
, 8192);
2104 if (mc
->fixup_ram_size
) {
2105 sz
= mc
->fixup_ram_size(sz
);
2108 if (ram_size
!= sz
) {
2109 error_report("ram size too large");
2113 maxram_size
= ram_size
;
2115 if (qemu_opt_get(opts
, "maxmem")) {
2118 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2119 slots
= qemu_opt_get_number(opts
, "slots", 0);
2120 if (sz
< ram_size
) {
2121 error_report("invalid value of -m option maxmem: "
2122 "maximum memory size (0x%" PRIx64
") must be at least "
2123 "the initial memory size (0x" RAM_ADDR_FMT
")",
2126 } else if (slots
&& sz
== ram_size
) {
2127 error_report("invalid value of -m option maxmem: "
2128 "memory slots were specified but maximum memory size "
2129 "(0x%" PRIx64
") is equal to the initial memory size "
2130 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2136 } else if (qemu_opt_get(opts
, "slots")) {
2137 error_report("invalid -m option value: missing 'maxmem' option");
2144 static void qemu_create_machine(QDict
*qdict
)
2146 MachineClass
*machine_class
= select_machine(qdict
, &error_fatal
);
2147 object_set_machine_compat_props(machine_class
->compat_props
);
2149 set_memory_options(machine_class
);
2151 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2152 object_property_add_child(object_get_root(), "machine",
2153 OBJECT(current_machine
));
2154 object_property_add_child(container_get(OBJECT(current_machine
),
2156 "sysbus", OBJECT(sysbus_get_default()));
2158 if (machine_class
->minimum_page_bits
) {
2159 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2160 /* This would be a board error: specifying a minimum smaller than
2161 * a target's compile-time fixed setting.
2163 g_assert_not_reached();
2167 cpu_exec_init_all();
2170 if (machine_class
->hw_version
) {
2171 qemu_set_hw_version(machine_class
->hw_version
);
2175 * Get the default machine options from the machine if it is not already
2176 * specified either by the configuration file or by the command line.
2178 if (machine_class
->default_machine_opts
) {
2179 QDict
*default_opts
=
2180 keyval_parse(machine_class
->default_machine_opts
, NULL
, NULL
,
2182 qemu_apply_legacy_machine_options(default_opts
);
2183 object_set_properties_from_keyval(OBJECT(current_machine
), default_opts
,
2184 false, &error_abort
);
2185 qobject_unref(default_opts
);
2189 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2193 g
= g_malloc0(sizeof(*g
));
2194 g
->driver
= qemu_opt_get(opts
, "driver");
2195 g
->property
= qemu_opt_get(opts
, "property");
2196 g
->value
= qemu_opt_get(opts
, "value");
2197 qdev_prop_register_global(g
);
2202 * Return whether configuration group @group is stored in QemuOpts, or
2203 * recorded as one or more QDicts by qemu_record_config_group.
2205 static bool is_qemuopts_group(const char *group
)
2207 if (g_str_equal(group
, "object") ||
2208 g_str_equal(group
, "machine") ||
2209 g_str_equal(group
, "smp-opts")) {
2215 static void qemu_record_config_group(const char *group
, QDict
*dict
,
2216 bool from_json
, Error
**errp
)
2218 if (g_str_equal(group
, "object")) {
2219 Visitor
*v
= qobject_input_visitor_new_keyval(QOBJECT(dict
));
2220 object_option_add_visitor(v
);
2222 } else if (g_str_equal(group
, "machine")) {
2224 * Cannot merge string-valued and type-safe dictionaries, so JSON
2225 * is not accepted yet for -M.
2228 keyval_merge(machine_opts_dict
, dict
, errp
);
2229 } else if (g_str_equal(group
, "smp-opts")) {
2230 machine_merge_property("smp", dict
, &error_fatal
);
2237 * Parse non-QemuOpts config file groups, pass the rest to
2238 * qemu_config_do_parse.
2240 static void qemu_parse_config_group(const char *group
, QDict
*qdict
,
2241 void *opaque
, Error
**errp
)
2244 if (is_qemuopts_group(group
)) {
2245 qemu_config_do_parse(group
, qdict
, opaque
, errp
);
2249 crumpled
= qdict_crumple(qdict
, errp
);
2253 switch (qobject_type(crumpled
)) {
2255 qemu_record_config_group(group
, qobject_to(QDict
, crumpled
), false, errp
);
2258 error_setg(errp
, "Lists cannot be at top level of a configuration section");
2261 g_assert_not_reached();
2263 qobject_unref(crumpled
);
2266 static void qemu_read_default_config_file(Error
**errp
)
2270 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2272 ret
= qemu_read_config_file(file
, qemu_parse_config_group
, errp
);
2274 if (ret
== -ENOENT
) {
2281 static void qemu_set_option(const char *str
, Error
**errp
)
2283 char group
[64], id
[64], arg
[64];
2288 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2289 if (rc
< 3 || str
[offset
] != '=') {
2290 error_setg(errp
, "can't parse: \"%s\"", str
);
2294 if (!is_qemuopts_group(group
)) {
2295 error_setg(errp
, "-set is not supported with %s", group
);
2297 list
= qemu_find_opts_err(group
, errp
);
2299 opts
= qemu_opts_find(list
, id
);
2301 error_setg(errp
, "there is no %s \"%s\" defined", group
, id
);
2304 qemu_opt_set(opts
, arg
, str
+ offset
+ 1, errp
);
2309 static void user_register_global_props(void)
2311 qemu_opts_foreach(qemu_find_opts("global"),
2312 global_init_func
, NULL
, NULL
);
2315 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2317 icount_configure(opts
, errp
);
2321 static int accelerator_set_property(void *opaque
,
2322 const char *name
, const char *value
,
2325 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2328 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2330 bool *p_init_failed
= opaque
;
2331 const char *acc
= qemu_opt_get(opts
, "accel");
2332 AccelClass
*ac
= accel_find(acc
);
2335 bool qtest_with_kvm
;
2337 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2340 *p_init_failed
= true;
2341 if (!qtest_with_kvm
) {
2342 error_report("invalid accelerator %s", acc
);
2346 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2347 object_apply_compat_props(OBJECT(accel
));
2348 qemu_opt_foreach(opts
, accelerator_set_property
,
2352 ret
= accel_init_machine(accel
, current_machine
);
2354 *p_init_failed
= true;
2355 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2356 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2364 static void configure_accelerators(const char *progname
)
2366 bool init_failed
= false;
2368 qemu_opts_foreach(qemu_find_opts("icount"),
2369 do_configure_icount
, NULL
, &error_fatal
);
2371 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2372 char **accel_list
, **tmp
;
2374 if (accelerators
== NULL
) {
2375 /* Select the default accelerator */
2376 bool have_tcg
= accel_find("tcg");
2377 bool have_kvm
= accel_find("kvm");
2379 if (have_tcg
&& have_kvm
) {
2380 if (g_str_has_suffix(progname
, "kvm")) {
2381 /* If the program name ends with "kvm", we prefer KVM */
2382 accelerators
= "kvm:tcg";
2384 accelerators
= "tcg:kvm";
2386 } else if (have_kvm
) {
2387 accelerators
= "kvm";
2388 } else if (have_tcg
) {
2389 accelerators
= "tcg";
2391 error_report("No accelerator selected and"
2392 " no default accelerator available");
2396 accel_list
= g_strsplit(accelerators
, ":", 0);
2398 for (tmp
= accel_list
; *tmp
; tmp
++) {
2400 * Filter invalid accelerators here, to prevent obscenities
2401 * such as "-machine accel=tcg,,thread=single".
2403 if (accel_find(*tmp
)) {
2404 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2407 error_report("invalid accelerator %s", *tmp
);
2410 g_strfreev(accel_list
);
2412 if (accelerators
!= NULL
) {
2413 error_report("The -accel and \"-machine accel=\" options are incompatible");
2418 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2419 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2421 error_report("no accelerator found");
2426 if (init_failed
&& !qtest_chrdev
) {
2427 AccelClass
*ac
= ACCEL_GET_CLASS(current_accel());
2428 error_report("falling back to %s", ac
->name
);
2431 if (icount_enabled() && !tcg_enabled()) {
2432 error_report("-icount is not allowed with hardware virtualization");
2437 static void create_default_memdev(MachineState
*ms
, const char *path
)
2440 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
2442 obj
= object_new(path
? TYPE_MEMORY_BACKEND_FILE
: TYPE_MEMORY_BACKEND_RAM
);
2444 object_property_set_str(obj
, "mem-path", path
, &error_fatal
);
2446 object_property_set_int(obj
, "size", ms
->ram_size
, &error_fatal
);
2447 object_property_add_child(object_get_objects_root(), mc
->default_ram_id
,
2449 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2450 object_property_set_bool(obj
, "x-use-canonical-path-for-ramblock-id",
2451 false, &error_fatal
);
2452 user_creatable_complete(USER_CREATABLE(obj
), &error_fatal
);
2454 object_property_set_str(OBJECT(ms
), "memory-backend", mc
->default_ram_id
,
2458 static void qemu_validate_options(const QDict
*machine_opts
)
2460 const char *kernel_filename
= qdict_get_try_str(machine_opts
, "kernel");
2461 const char *initrd_filename
= qdict_get_try_str(machine_opts
, "initrd");
2462 const char *kernel_cmdline
= qdict_get_try_str(machine_opts
, "append");
2464 if (kernel_filename
== NULL
) {
2465 if (kernel_cmdline
!= NULL
) {
2466 error_report("-append only allowed with -kernel option");
2470 if (initrd_filename
!= NULL
) {
2471 error_report("-initrd only allowed with -kernel option");
2476 if (loadvm
&& preconfig_requested
) {
2477 error_report("'preconfig' and 'loadvm' options are "
2478 "mutually exclusive");
2481 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2482 error_report("'preconfig' supports '-incoming defer' only");
2486 #ifdef CONFIG_CURSES
2487 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2488 error_report("curses display cannot be used with -daemonize");
2494 static void qemu_process_sugar_options(void)
2497 QObject
*smp
= qdict_get(machine_opts_dict
, "smp");
2498 if (smp
&& qobject_type(smp
) == QTYPE_QDICT
) {
2499 QObject
*cpus
= qdict_get(qobject_to(QDict
, smp
), "cpus");
2500 if (cpus
&& qobject_type(cpus
) == QTYPE_QSTRING
) {
2501 const char *val
= qstring_get_str(qobject_to(QString
, cpus
));
2502 object_register_sugar_prop("memory-backend", "prealloc-threads",
2506 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2510 int i
= select_watchdog(watchdog
);
2512 exit (i
== 1 ? 1 : 0);
2516 /* -action processing */
2519 * Process all the -action parameters parsed from cmdline.
2521 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2523 Error
*local_err
= NULL
;
2524 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2525 QObject
*ret
= NULL
;
2526 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2528 qobject_unref(qdict
);
2530 error_propagate(errp
, local_err
);
2536 static void qemu_process_early_options(void)
2538 #ifdef CONFIG_SECCOMP
2539 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2541 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2545 qemu_opts_foreach(qemu_find_opts("name"),
2546 parse_name
, NULL
, &error_fatal
);
2548 if (qemu_opts_foreach(qemu_find_opts("action"),
2549 process_runstate_actions
, NULL
, &error_fatal
)) {
2554 qemu_opts_foreach(qemu_find_opts("add-fd"),
2555 parse_add_fd
, NULL
, &error_fatal
);
2557 qemu_opts_foreach(qemu_find_opts("add-fd"),
2558 cleanup_add_fd
, NULL
, &error_fatal
);
2561 /* Open the logfile at this point and set the log mask if necessary. */
2563 qemu_set_log_filename(log_file
, &error_fatal
);
2567 mask
= qemu_str_to_log_mask(log_mask
);
2569 qemu_print_log_usage(stdout
);
2577 qemu_add_default_firmwarepath();
2580 static void qemu_process_help_options(void)
2583 * Check for -cpu help and -device help before we call select_machine(),
2584 * which will return an error if the architecture has no default machine
2585 * type and the user did not specify one, so that the user doesn't need
2586 * to say '-cpu help -machine something'.
2588 if (cpu_option
&& is_help_option(cpu_option
)) {
2589 list_cpus(cpu_option
);
2593 if (qemu_opts_foreach(qemu_find_opts("device"),
2594 device_help_func
, NULL
, NULL
)) {
2598 /* -L help lists the data directories and exits. */
2599 if (list_data_dirs
) {
2600 qemu_list_data_dirs();
2605 static void qemu_maybe_daemonize(const char *pid_file
)
2610 rcu_disable_atfork();
2612 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
2613 error_reportf_err(err
, "cannot create PID file: ");
2617 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
2618 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
2621 static void qemu_init_displays(void)
2625 /* init local displays */
2626 ds
= init_displaystate();
2627 qemu_display_init(ds
, &dpy
);
2629 /* must be after terminal init, SDL library changes signal handlers */
2630 os_setup_signal_handling();
2632 /* init remote displays */
2634 qemu_opts_foreach(qemu_find_opts("vnc"),
2635 vnc_init_func
, NULL
, &error_fatal
);
2639 qemu_spice
.display_init();
2643 static void qemu_init_board(void)
2645 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
2647 if (machine_class
->default_ram_id
&& current_machine
->ram_size
&&
2648 numa_uses_legacy_mem() && !current_machine
->ram_memdev_id
) {
2649 create_default_memdev(current_machine
, mem_path
);
2652 /* process plugin before CPUs are created, but once -smp has been parsed */
2653 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2655 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2656 machine_run_board_init(current_machine
);
2658 drive_check_orphaned();
2662 if (hax_enabled()) {
2663 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2668 static void qemu_create_cli_devices(void)
2674 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2675 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2677 /* init USB devices */
2678 if (machine_usb(current_machine
)) {
2679 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2683 /* init generic devices */
2684 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2685 qemu_opts_foreach(qemu_find_opts("device"),
2686 device_init_func
, NULL
, &error_fatal
);
2687 QTAILQ_FOREACH(opt
, &device_opts
, next
) {
2689 loc_push_restore(&opt
->loc
);
2691 * TODO Eventually we should call qmp_device_add() here to make sure it
2692 * behaves the same, but QMP still has to accept incorrectly typed
2693 * options until libvirt is fixed and we want to be strict on the CLI
2694 * from the start, so call qdev_device_add_from_qdict() directly for
2697 dev
= qdev_device_add_from_qdict(opt
->opts
, true, &error_fatal
);
2698 object_unref(OBJECT(dev
));
2701 rom_reset_order_override();
2704 static void qemu_machine_creation_done(void)
2706 MachineState
*machine
= MACHINE(qdev_get_machine());
2708 /* Did we create any drives that we failed to create a device for? */
2709 drive_check_orphaned();
2711 /* Don't warn about the default network setup that you get if
2712 * no command line -net or -netdev options are specified. There
2713 * are two cases that we would otherwise complain about:
2714 * (1) board doesn't support a NIC but the implicit "-net nic"
2716 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2717 * sets up a nic that isn't connected to anything.
2719 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2720 net_check_clients();
2723 qdev_prop_check_globals();
2725 qdev_machine_creation_done();
2729 * Verify that Confidential Guest Support has actually been initialized
2731 assert(machine
->cgs
->ready
);
2734 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2739 void qmp_x_exit_preconfig(Error
**errp
)
2741 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2742 error_setg(errp
, "The command is permitted only before machine initialization");
2747 qemu_create_cli_devices();
2748 qemu_machine_creation_done();
2751 load_snapshot(loadvm
, NULL
, false, NULL
, &error_fatal
);
2753 if (replay_mode
!= REPLAY_MODE_NONE
) {
2754 replay_vmstate_init();
2758 Error
*local_err
= NULL
;
2759 if (strcmp(incoming
, "defer") != 0) {
2760 qmp_migrate_incoming(incoming
, &local_err
);
2762 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2766 } else if (autostart
) {
2771 void qemu_init(int argc
, char **argv
, char **envp
)
2774 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2775 QemuOptsList
*olist
;
2778 MachineClass
*machine_class
;
2779 bool userconfig
= true;
2780 FILE *vmstate_dump_file
= NULL
;
2782 qemu_add_opts(&qemu_drive_opts
);
2783 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2784 qemu_add_drive_opts(&qemu_common_drive_opts
);
2785 qemu_add_drive_opts(&qemu_drive_opts
);
2786 qemu_add_drive_opts(&bdrv_runtime_opts
);
2787 qemu_add_opts(&qemu_chardev_opts
);
2788 qemu_add_opts(&qemu_device_opts
);
2789 qemu_add_opts(&qemu_netdev_opts
);
2790 qemu_add_opts(&qemu_nic_opts
);
2791 qemu_add_opts(&qemu_net_opts
);
2792 qemu_add_opts(&qemu_rtc_opts
);
2793 qemu_add_opts(&qemu_global_opts
);
2794 qemu_add_opts(&qemu_mon_opts
);
2795 qemu_add_opts(&qemu_trace_opts
);
2796 qemu_plugin_add_opts();
2797 qemu_add_opts(&qemu_option_rom_opts
);
2798 qemu_add_opts(&qemu_accel_opts
);
2799 qemu_add_opts(&qemu_mem_opts
);
2800 qemu_add_opts(&qemu_smp_opts
);
2801 qemu_add_opts(&qemu_boot_opts
);
2802 qemu_add_opts(&qemu_add_fd_opts
);
2803 qemu_add_opts(&qemu_object_opts
);
2804 qemu_add_opts(&qemu_tpmdev_opts
);
2805 qemu_add_opts(&qemu_overcommit_opts
);
2806 qemu_add_opts(&qemu_msg_opts
);
2807 qemu_add_opts(&qemu_name_opts
);
2808 qemu_add_opts(&qemu_numa_opts
);
2809 qemu_add_opts(&qemu_icount_opts
);
2810 qemu_add_opts(&qemu_semihosting_config_opts
);
2811 qemu_add_opts(&qemu_fw_cfg_opts
);
2812 qemu_add_opts(&qemu_action_opts
);
2813 module_call_init(MODULE_INIT_OPTS
);
2815 error_init(argv
[0]);
2816 qemu_init_exec_dir(argv
[0]);
2818 #ifdef CONFIG_MODULES
2819 module_init_info(qemu_modinfo
);
2820 module_allow_arch(TARGET_NAME
);
2823 qemu_init_subsystems();
2825 /* first pass of option parsing */
2827 while (optind
< argc
) {
2828 if (argv
[optind
][0] != '-') {
2832 const QEMUOption
*popt
;
2834 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2835 switch (popt
->index
) {
2836 case QEMU_OPTION_nouserconfig
:
2843 machine_opts_dict
= qdict_new();
2845 qemu_read_default_config_file(&error_fatal
);
2848 /* second pass of option parsing */
2853 if (argv
[optind
][0] != '-') {
2854 loc_set_cmdline(argv
, optind
, 1);
2855 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2857 const QEMUOption
*popt
;
2859 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2860 if (!(popt
->arch_mask
& arch_type
)) {
2861 error_report("Option not supported for this target");
2864 switch(popt
->index
) {
2865 case QEMU_OPTION_cpu
:
2866 /* hw initialization will check this */
2867 cpu_option
= optarg
;
2869 case QEMU_OPTION_hda
:
2870 case QEMU_OPTION_hdb
:
2871 case QEMU_OPTION_hdc
:
2872 case QEMU_OPTION_hdd
:
2873 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2876 case QEMU_OPTION_blockdev
:
2879 BlockdevOptionsQueueEntry
*bdo
;
2881 v
= qobject_input_visitor_new_str(optarg
, "driver",
2884 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2885 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2888 loc_save(&bdo
->loc
);
2889 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2892 case QEMU_OPTION_drive
:
2893 opts
= qemu_opts_parse_noisily(qemu_find_opts("drive"),
2899 case QEMU_OPTION_set
:
2900 qemu_set_option(optarg
, &error_fatal
);
2902 case QEMU_OPTION_global
:
2903 if (qemu_global_option(optarg
) != 0)
2906 case QEMU_OPTION_mtdblock
:
2907 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2909 case QEMU_OPTION_sd
:
2910 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2912 case QEMU_OPTION_pflash
:
2913 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2915 case QEMU_OPTION_snapshot
:
2917 Error
*blocker
= NULL
;
2919 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
2921 replay_add_blocker(blocker
);
2924 case QEMU_OPTION_numa
:
2925 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2931 case QEMU_OPTION_display
:
2932 parse_display(optarg
);
2934 case QEMU_OPTION_nographic
:
2935 qdict_put_str(machine_opts_dict
, "graphics", "off");
2937 dpy
.type
= DISPLAY_TYPE_NONE
;
2939 case QEMU_OPTION_curses
:
2940 warn_report("-curses is deprecated, "
2941 "use -display curses instead.");
2942 #ifdef CONFIG_CURSES
2943 dpy
.type
= DISPLAY_TYPE_CURSES
;
2945 error_report("curses or iconv support is disabled");
2949 case QEMU_OPTION_portrait
:
2950 graphic_rotate
= 90;
2952 case QEMU_OPTION_rotate
:
2953 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2954 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2955 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2956 error_report("only 90, 180, 270 deg rotation is available");
2960 case QEMU_OPTION_kernel
:
2961 qdict_put_str(machine_opts_dict
, "kernel", optarg
);
2963 case QEMU_OPTION_initrd
:
2964 qdict_put_str(machine_opts_dict
, "initrd", optarg
);
2966 case QEMU_OPTION_append
:
2967 qdict_put_str(machine_opts_dict
, "append", optarg
);
2969 case QEMU_OPTION_dtb
:
2970 qdict_put_str(machine_opts_dict
, "dtb", optarg
);
2972 case QEMU_OPTION_cdrom
:
2973 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2975 case QEMU_OPTION_boot
:
2976 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2982 case QEMU_OPTION_fda
:
2983 case QEMU_OPTION_fdb
:
2984 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2987 case QEMU_OPTION_no_fd_bootchk
:
2990 case QEMU_OPTION_netdev
:
2992 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2996 case QEMU_OPTION_nic
:
2998 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
3002 case QEMU_OPTION_net
:
3004 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3008 #ifdef CONFIG_LIBISCSI
3009 case QEMU_OPTION_iscsi
:
3010 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3017 case QEMU_OPTION_audio_help
:
3018 audio_legacy_help();
3021 case QEMU_OPTION_audiodev
:
3022 audio_parse_option(optarg
);
3024 case QEMU_OPTION_soundhw
:
3025 select_soundhw (optarg
);
3030 case QEMU_OPTION_version
:
3035 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3042 case QEMU_OPTION_tpmdev
:
3043 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3048 case QEMU_OPTION_mempath
:
3051 case QEMU_OPTION_mem_prealloc
:
3060 case QEMU_OPTION_DFILTER
:
3061 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3063 case QEMU_OPTION_seed
:
3064 qemu_guest_random_seed_main(optarg
, &error_fatal
);
3067 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3069 case QEMU_OPTION_gdb
:
3070 add_device_config(DEV_GDB
, optarg
);
3073 if (is_help_option(optarg
)) {
3074 list_data_dirs
= true;
3076 qemu_add_data_dir(g_strdup(optarg
));
3079 case QEMU_OPTION_bios
:
3080 qdict_put_str(machine_opts_dict
, "firmware", optarg
);
3082 case QEMU_OPTION_singlestep
:
3089 keyboard_layout
= optarg
;
3091 case QEMU_OPTION_vga
:
3100 w
= strtol(p
, (char **)&p
, 10);
3103 error_report("invalid resolution or depth");
3109 h
= strtol(p
, (char **)&p
, 10);
3114 depth
= strtol(p
, (char **)&p
, 10);
3115 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
3116 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3117 depth
!= 24 && depth
!= 32)
3119 } else if (*p
== '\0') {
3120 depth
= graphic_depth
;
3127 graphic_depth
= depth
;
3130 case QEMU_OPTION_echr
:
3133 term_escape_char
= strtol(optarg
, &r
, 0);
3135 printf("Bad argument to echr\n");
3138 case QEMU_OPTION_monitor
:
3139 default_monitor
= 0;
3140 if (strncmp(optarg
, "none", 4)) {
3141 monitor_parse(optarg
, "readline", false);
3144 case QEMU_OPTION_qmp
:
3145 monitor_parse(optarg
, "control", false);
3146 default_monitor
= 0;
3148 case QEMU_OPTION_qmp_pretty
:
3149 monitor_parse(optarg
, "control", true);
3150 default_monitor
= 0;
3152 case QEMU_OPTION_mon
:
3153 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3158 default_monitor
= 0;
3160 case QEMU_OPTION_chardev
:
3161 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3167 case QEMU_OPTION_fsdev
:
3168 olist
= qemu_find_opts("fsdev");
3170 error_report("fsdev support is disabled");
3173 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3178 case QEMU_OPTION_virtfs
: {
3181 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3184 olist
= qemu_find_opts("virtfs");
3186 error_report("virtfs support is disabled");
3189 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3194 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3195 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3196 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3199 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3200 qemu_opts_id(opts
) ?:
3201 qemu_opt_get(opts
, "mount_tag"),
3204 error_report("duplicate or invalid fsdev id: %s",
3205 qemu_opt_get(opts
, "mount_tag"));
3209 writeout
= qemu_opt_get(opts
, "writeout");
3211 #ifdef CONFIG_SYNC_FILE_RANGE
3212 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3214 error_report("writeout=immediate not supported "
3215 "on this platform");
3219 qemu_opt_set(fsdev
, "fsdriver",
3220 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3221 path
= qemu_opt_get(opts
, "path");
3223 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3225 security_model
= qemu_opt_get(opts
, "security_model");
3226 if (security_model
) {
3227 qemu_opt_set(fsdev
, "security_model", security_model
,
3230 socket
= qemu_opt_get(opts
, "socket");
3232 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3234 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3236 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3239 qemu_opt_set_bool(fsdev
, "readonly",
3240 qemu_opt_get_bool(opts
, "readonly", 0),
3242 multidevs
= qemu_opt_get(opts
, "multidevs");
3244 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3246 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3248 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3249 qemu_opt_set(device
, "fsdev",
3250 qemu_opts_id(fsdev
), &error_abort
);
3251 qemu_opt_set(device
, "mount_tag",
3252 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3255 case QEMU_OPTION_serial
:
3256 add_device_config(DEV_SERIAL
, optarg
);
3258 if (strncmp(optarg
, "mon:", 4) == 0) {
3259 default_monitor
= 0;
3262 case QEMU_OPTION_watchdog
:
3264 error_report("only one watchdog option may be given");
3267 warn_report("-watchdog is deprecated; use -device instead.");
3270 case QEMU_OPTION_action
:
3271 olist
= qemu_find_opts("action");
3272 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3276 case QEMU_OPTION_watchdog_action
: {
3278 opts
= qemu_opts_create(qemu_find_opts("action"), NULL
, 0, &error_abort
);
3279 qemu_opt_set(opts
, "watchdog", optarg
, &error_abort
);
3282 case QEMU_OPTION_parallel
:
3283 add_device_config(DEV_PARALLEL
, optarg
);
3284 default_parallel
= 0;
3285 if (strncmp(optarg
, "mon:", 4) == 0) {
3286 default_monitor
= 0;
3289 case QEMU_OPTION_debugcon
:
3290 add_device_config(DEV_DEBUGCON
, optarg
);
3292 case QEMU_OPTION_loadvm
:
3295 case QEMU_OPTION_full_screen
:
3296 dpy
.has_full_screen
= true;
3297 dpy
.full_screen
= true;
3299 case QEMU_OPTION_alt_grab
:
3301 warn_report("-alt-grab is deprecated, please use "
3302 "-display sdl,grab-mod=lshift-lctrl-lalt instead.");
3304 case QEMU_OPTION_ctrl_grab
:
3306 warn_report("-ctrl-grab is deprecated, please use "
3307 "-display sdl,grab-mod=rctrl instead.");
3309 case QEMU_OPTION_sdl
:
3310 warn_report("-sdl is deprecated, use -display sdl instead.");
3312 dpy
.type
= DISPLAY_TYPE_SDL
;
3315 error_report("SDL support is disabled");
3318 case QEMU_OPTION_pidfile
:
3321 case QEMU_OPTION_win2k_hack
:
3322 win2k_install_hack
= 1;
3324 case QEMU_OPTION_acpitable
:
3325 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3330 acpi_table_add(opts
, &error_fatal
);
3332 case QEMU_OPTION_smbios
:
3333 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3338 smbios_entry_add(opts
, &error_fatal
);
3340 case QEMU_OPTION_fwcfg
:
3341 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3347 case QEMU_OPTION_preconfig
:
3348 preconfig_requested
= true;
3350 case QEMU_OPTION_enable_kvm
:
3351 qdict_put_str(machine_opts_dict
, "accel", "kvm");
3354 case QEMU_OPTION_machine
:
3358 keyval_parse_into(machine_opts_dict
, optarg
, "type", &help
, &error_fatal
);
3360 machine_help_func(machine_opts_dict
);
3365 case QEMU_OPTION_accel
:
3366 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3368 optarg
= qemu_opt_get(accel_opts
, "accel");
3369 if (!optarg
|| is_help_option(optarg
)) {
3370 printf("Accelerators supported in QEMU binary:\n");
3371 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3373 for (el
= accel_list
; el
; el
= el
->next
) {
3374 gchar
*typename
= g_strdup(object_class_get_name(
3375 OBJECT_CLASS(el
->data
)));
3376 /* omit qtest which is used for tests only */
3377 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3378 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3379 gchar
**optname
= g_strsplit(typename
,
3380 ACCEL_CLASS_SUFFIX
, 0);
3381 printf("%s\n", optname
[0]);
3382 g_strfreev(optname
);
3386 g_slist_free(accel_list
);
3390 case QEMU_OPTION_usb
:
3391 qdict_put_str(machine_opts_dict
, "usb", "on");
3393 case QEMU_OPTION_usbdevice
:
3394 qdict_put_str(machine_opts_dict
, "usb", "on");
3395 add_device_config(DEV_USB
, optarg
);
3397 case QEMU_OPTION_device
:
3398 if (optarg
[0] == '{') {
3399 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
3400 DeviceOption
*opt
= g_new0(DeviceOption
, 1);
3401 opt
->opts
= qobject_to(QDict
, obj
);
3402 loc_save(&opt
->loc
);
3403 assert(opt
->opts
!= NULL
);
3404 QTAILQ_INSERT_TAIL(&device_opts
, opt
, next
);
3406 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3412 case QEMU_OPTION_smp
:
3413 machine_parse_property_opt(qemu_find_opts("smp-opts"),
3416 case QEMU_OPTION_vnc
:
3419 case QEMU_OPTION_no_acpi
:
3420 qdict_put_str(machine_opts_dict
, "acpi", "off");
3422 case QEMU_OPTION_no_hpet
:
3423 qdict_put_str(machine_opts_dict
, "hpet", "off");
3425 case QEMU_OPTION_no_reboot
:
3426 olist
= qemu_find_opts("action");
3427 qemu_opts_parse_noisily(olist
, "reboot=shutdown", false);
3429 case QEMU_OPTION_no_shutdown
:
3430 olist
= qemu_find_opts("action");
3431 qemu_opts_parse_noisily(olist
, "shutdown=pause", false);
3433 case QEMU_OPTION_uuid
:
3434 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3435 error_report("failed to parse UUID string: wrong format");
3438 qemu_uuid_set
= true;
3440 case QEMU_OPTION_option_rom
:
3441 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3442 error_report("too many option ROMs");
3445 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3450 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3451 option_rom
[nb_option_roms
].bootindex
=
3452 qemu_opt_get_number(opts
, "bootindex", -1);
3453 if (!option_rom
[nb_option_roms
].name
) {
3454 error_report("Option ROM file is not specified");
3459 case QEMU_OPTION_semihosting
:
3460 qemu_semihosting_enable();
3462 case QEMU_OPTION_semihosting_config
:
3463 if (qemu_semihosting_config_options(optarg
) != 0) {
3467 case QEMU_OPTION_name
:
3468 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3473 /* Capture guest name if -msg guest-name is used later */
3474 error_guest_name
= qemu_opt_get(opts
, "guest");
3476 case QEMU_OPTION_prom_env
:
3477 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3478 error_report("too many prom variables");
3481 prom_envs
[nb_prom_envs
] = optarg
;
3484 case QEMU_OPTION_old_param
:
3487 case QEMU_OPTION_rtc
:
3488 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3494 case QEMU_OPTION_icount
:
3495 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3501 case QEMU_OPTION_incoming
:
3503 runstate_set(RUN_STATE_INMIGRATE
);
3507 case QEMU_OPTION_only_migratable
:
3508 only_migratable
= 1;
3510 case QEMU_OPTION_nodefaults
:
3513 case QEMU_OPTION_xen_domid
:
3514 if (!(accel_find("xen"))) {
3515 error_report("Option not supported for this target");
3518 xen_domid
= atoi(optarg
);
3520 case QEMU_OPTION_xen_attach
:
3521 if (!(accel_find("xen"))) {
3522 error_report("Option not supported for this target");
3525 xen_mode
= XEN_ATTACH
;
3527 case QEMU_OPTION_xen_domid_restrict
:
3528 if (!(accel_find("xen"))) {
3529 error_report("Option not supported for this target");
3532 xen_domid_restrict
= true;
3534 case QEMU_OPTION_trace
:
3535 trace_opt_parse(optarg
);
3537 case QEMU_OPTION_plugin
:
3538 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3540 case QEMU_OPTION_readconfig
:
3541 qemu_read_config_file(optarg
, qemu_parse_config_group
, &error_fatal
);
3543 case QEMU_OPTION_spice
:
3544 olist
= qemu_find_opts_err("spice", NULL
);
3546 error_report("spice support is disabled");
3549 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
);