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/boards.h"
31 #include "hw/qdev-properties.h"
32 #include "qapi/error.h"
33 #include "qapi/qmp/qdict.h"
34 #include "qemu-version.h"
35 #include "qemu/cutils.h"
36 #include "qemu/help_option.h"
37 #include "qemu/uuid.h"
38 #include "sysemu/reset.h"
39 #include "sysemu/runstate.h"
40 #include "sysemu/runstate-action.h"
41 #include "sysemu/seccomp.h"
42 #include "sysemu/tcg.h"
43 #include "sysemu/xen.h"
45 #include "qemu/error-report.h"
46 #include "qemu/sockets.h"
47 #include "sysemu/accel.h"
49 #include "hw/isa/isa.h"
50 #include "hw/scsi/scsi.h"
51 #include "hw/display/vga.h"
52 #include "sysemu/watchdog.h"
53 #include "hw/firmware/smbios.h"
54 #include "hw/acpi/acpi.h"
55 #include "hw/xen/xen.h"
56 #include "hw/loader.h"
57 #include "monitor/qdev.h"
59 #include "net/slirp.h"
60 #include "monitor/monitor.h"
61 #include "ui/console.h"
63 #include "sysemu/sysemu.h"
64 #include "sysemu/numa.h"
65 #include "sysemu/hostmem.h"
66 #include "exec/gdbstub.h"
67 #include "qemu/timer.h"
68 #include "chardev/char.h"
69 #include "qemu/bitmap.h"
71 #include "sysemu/blockdev.h"
72 #include "hw/block/block.h"
73 #include "hw/i386/x86.h"
74 #include "hw/i386/pc.h"
75 #include "migration/misc.h"
76 #include "migration/snapshot.h"
77 #include "sysemu/tpm.h"
78 #include "sysemu/dma.h"
79 #include "hw/audio/soundhw.h"
80 #include "audio/audio.h"
81 #include "sysemu/cpus.h"
82 #include "sysemu/cpu-timers.h"
83 #include "migration/colo.h"
84 #include "migration/postcopy-ram.h"
85 #include "sysemu/kvm.h"
86 #include "sysemu/hax.h"
87 #include "qapi/qobject-input-visitor.h"
88 #include "qemu/option.h"
89 #include "qemu/config-file.h"
90 #include "qemu-options.h"
91 #include "qemu/main-loop.h"
93 #include "fsdev/qemu-fsdev.h"
95 #include "sysemu/qtest.h"
97 #include "disas/disas.h"
100 #include "trace/control.h"
101 #include "qemu/plugin.h"
102 #include "qemu/queue.h"
103 #include "sysemu/arch_init.h"
105 #include "ui/qemu-spice.h"
106 #include "qapi/string-input-visitor.h"
107 #include "qapi/opts-visitor.h"
108 #include "qapi/clone-visitor.h"
109 #include "qom/object_interfaces.h"
110 #include "hw/semihosting/semihost.h"
111 #include "crypto/init.h"
112 #include "sysemu/replay.h"
113 #include "qapi/qapi-events-run-state.h"
114 #include "qapi/qapi-visit-block-core.h"
115 #include "qapi/qapi-visit-ui.h"
116 #include "qapi/qapi-commands-block-core.h"
117 #include "qapi/qapi-commands-migration.h"
118 #include "qapi/qapi-commands-misc.h"
119 #include "qapi/qapi-commands-ui.h"
120 #include "qapi/qmp/qerror.h"
121 #include "sysemu/iothread.h"
122 #include "qemu/guest-random.h"
124 #define MAX_VIRTIO_CONSOLES 1
126 typedef struct BlockdevOptionsQueueEntry
{
127 BlockdevOptions
*bdo
;
129 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
130 } BlockdevOptionsQueueEntry
;
132 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
134 static const char *cpu_option
;
135 static const char *mem_path
;
136 static const char *incoming
;
137 static const char *loadvm
;
138 static ram_addr_t maxram_size
;
139 static uint64_t ram_slots
;
140 static int display_remote
;
142 static bool preconfig_requested
;
143 static QemuPluginList plugin_list
= QTAILQ_HEAD_INITIALIZER(plugin_list
);
144 static BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
145 static bool nographic
= false;
146 static int mem_prealloc
; /* force preallocation of physical target memory */
147 static ram_addr_t ram_size
;
148 static const char *vga_model
= NULL
;
149 static DisplayOptions dpy
;
150 static int num_serial_hds
;
151 static Chardev
**serial_hds
;
152 static const char *log_mask
;
153 static const char *log_file
;
154 static bool list_data_dirs
;
155 static const char *watchdog
;
156 static const char *qtest_chrdev
;
157 static const char *qtest_log
;
159 static int has_defaults
= 1;
160 static int default_serial
= 1;
161 static int default_parallel
= 1;
162 static int default_monitor
= 1;
163 static int default_floppy
= 1;
164 static int default_cdrom
= 1;
165 static int default_sdcard
= 1;
166 static int default_vga
= 1;
167 static int default_net
= 1;
173 { .driver
= "isa-serial", .flag
= &default_serial
},
174 { .driver
= "isa-parallel", .flag
= &default_parallel
},
175 { .driver
= "isa-fdc", .flag
= &default_floppy
},
176 { .driver
= "floppy", .flag
= &default_floppy
},
177 { .driver
= "ide-cd", .flag
= &default_cdrom
},
178 { .driver
= "ide-hd", .flag
= &default_cdrom
},
179 { .driver
= "ide-drive", .flag
= &default_cdrom
},
180 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
181 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
182 { .driver
= "VGA", .flag
= &default_vga
},
183 { .driver
= "isa-vga", .flag
= &default_vga
},
184 { .driver
= "cirrus-vga", .flag
= &default_vga
},
185 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
186 { .driver
= "vmware-svga", .flag
= &default_vga
},
187 { .driver
= "qxl-vga", .flag
= &default_vga
},
188 { .driver
= "virtio-vga", .flag
= &default_vga
},
189 { .driver
= "ati-vga", .flag
= &default_vga
},
190 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
193 static QemuOptsList qemu_rtc_opts
= {
195 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
200 .type
= QEMU_OPT_STRING
,
203 .type
= QEMU_OPT_STRING
,
206 .type
= QEMU_OPT_STRING
,
208 { /* end of list */ }
212 static QemuOptsList qemu_option_rom_opts
= {
213 .name
= "option-rom",
214 .implied_opt_name
= "romfile",
215 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
219 .type
= QEMU_OPT_NUMBER
,
222 .type
= QEMU_OPT_STRING
,
224 { /* end of list */ }
228 static QemuOptsList qemu_machine_opts
= {
230 .implied_opt_name
= "type",
232 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
235 * no elements => accept any
236 * sanity checking will happen later
237 * when setting machine properties
243 static QemuOptsList qemu_accel_opts
= {
245 .implied_opt_name
= "accel",
246 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
249 * no elements => accept any
250 * sanity checking will happen later
251 * when setting accelerator properties
257 static QemuOptsList qemu_boot_opts
= {
259 .implied_opt_name
= "order",
261 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
265 .type
= QEMU_OPT_STRING
,
268 .type
= QEMU_OPT_STRING
,
271 .type
= QEMU_OPT_BOOL
,
274 .type
= QEMU_OPT_STRING
,
276 .name
= "splash-time",
277 .type
= QEMU_OPT_NUMBER
,
279 .name
= "reboot-timeout",
280 .type
= QEMU_OPT_NUMBER
,
283 .type
= QEMU_OPT_BOOL
,
289 static QemuOptsList qemu_add_fd_opts
= {
291 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
295 .type
= QEMU_OPT_NUMBER
,
296 .help
= "file descriptor of which a duplicate is added to fd set",
299 .type
= QEMU_OPT_NUMBER
,
300 .help
= "ID of the fd set to add fd to",
303 .type
= QEMU_OPT_STRING
,
304 .help
= "free-form string used to describe fd",
306 { /* end of list */ }
310 static QemuOptsList qemu_object_opts
= {
312 .implied_opt_name
= "qom-type",
313 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
319 static QemuOptsList qemu_tpmdev_opts
= {
321 .implied_opt_name
= "type",
322 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
324 /* options are defined in the TPM backends */
325 { /* end of list */ }
329 static QemuOptsList qemu_overcommit_opts
= {
330 .name
= "overcommit",
331 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
335 .type
= QEMU_OPT_BOOL
,
339 .type
= QEMU_OPT_BOOL
,
341 { /* end of list */ }
345 static QemuOptsList qemu_msg_opts
= {
347 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
351 .type
= QEMU_OPT_BOOL
,
354 .name
= "guest-name",
355 .type
= QEMU_OPT_BOOL
,
356 .help
= "Prepends guest name for error messages but only if "
357 "-name guest is set otherwise option is ignored\n",
359 { /* end of list */ }
363 static QemuOptsList qemu_name_opts
= {
365 .implied_opt_name
= "guest",
367 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
371 .type
= QEMU_OPT_STRING
,
372 .help
= "Sets the name of the guest.\n"
373 "This name will be displayed in the SDL window caption.\n"
374 "The name will also be used for the VNC server",
377 .type
= QEMU_OPT_STRING
,
378 .help
= "Sets the name of the QEMU process, as shown in top etc",
380 .name
= "debug-threads",
381 .type
= QEMU_OPT_BOOL
,
382 .help
= "When enabled, name the individual threads; defaults off.\n"
383 "NOTE: The thread names are for debugging and not a\n"
386 { /* End of list */ }
390 static QemuOptsList qemu_mem_opts
= {
392 .implied_opt_name
= "size",
393 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
398 .type
= QEMU_OPT_SIZE
,
402 .type
= QEMU_OPT_NUMBER
,
406 .type
= QEMU_OPT_SIZE
,
408 { /* end of list */ }
412 static QemuOptsList qemu_icount_opts
= {
414 .implied_opt_name
= "shift",
416 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
420 .type
= QEMU_OPT_STRING
,
423 .type
= QEMU_OPT_BOOL
,
426 .type
= QEMU_OPT_BOOL
,
429 .type
= QEMU_OPT_STRING
,
432 .type
= QEMU_OPT_STRING
,
434 .name
= "rrsnapshot",
435 .type
= QEMU_OPT_STRING
,
437 { /* end of list */ }
441 static QemuOptsList qemu_fw_cfg_opts
= {
443 .implied_opt_name
= "name",
444 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
448 .type
= QEMU_OPT_STRING
,
449 .help
= "Sets the fw_cfg name of the blob to be inserted",
452 .type
= QEMU_OPT_STRING
,
453 .help
= "Sets the name of the file from which "
454 "the fw_cfg blob will be loaded",
457 .type
= QEMU_OPT_STRING
,
458 .help
= "Sets content of the blob to be inserted from a string",
461 .type
= QEMU_OPT_STRING
,
462 .help
= "Sets id of the object generating the fw_cfg blob "
465 { /* end of list */ }
469 static QemuOptsList qemu_action_opts
= {
472 .head
= QTAILQ_HEAD_INITIALIZER(qemu_action_opts
.head
),
476 .type
= QEMU_OPT_STRING
,
479 .type
= QEMU_OPT_STRING
,
482 .type
= QEMU_OPT_STRING
,
485 .type
= QEMU_OPT_STRING
,
487 { /* end of list */ }
492 * Get machine options
494 * Returns: machine options (never null).
496 static QemuOpts
*qemu_get_machine_opts(void)
498 return qemu_find_opts_singleton("machine");
501 const char *qemu_get_vm_name(void)
506 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
508 const char *driver
= qemu_opt_get(opts
, "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;
521 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
523 const char *proc_name
;
525 if (qemu_opt_get(opts
, "debug-threads")) {
526 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
528 qemu_name
= qemu_opt_get(opts
, "guest");
530 proc_name
= qemu_opt_get(opts
, "process");
532 os_set_proc_name(proc_name
);
538 bool defaults_enabled(void)
544 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
546 int fd
, dupfd
, flags
;
548 const char *fd_opaque
= NULL
;
551 fd
= qemu_opt_get_number(opts
, "fd", -1);
552 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
553 fd_opaque
= qemu_opt_get(opts
, "opaque");
556 error_setg(errp
, "fd option is required and must be non-negative");
560 if (fd
<= STDERR_FILENO
) {
561 error_setg(errp
, "fd cannot be a standard I/O stream");
566 * All fds inherited across exec() necessarily have FD_CLOEXEC
567 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
569 flags
= fcntl(fd
, F_GETFD
);
570 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
571 error_setg(errp
, "fd is not valid or already in use");
576 error_setg(errp
, "set option is required and must be non-negative");
580 #ifdef F_DUPFD_CLOEXEC
581 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
585 qemu_set_cloexec(dupfd
);
589 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
593 /* add the duplicate fd, and optionally the opaque string, to the fd set */
594 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
601 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
605 fd
= qemu_opt_get_number(opts
, "fd", -1);
612 /***********************************************************/
613 /* QEMU Block devices */
615 #define HD_OPTS "media=disk"
616 #define CDROM_OPTS "media=cdrom"
618 #define PFLASH_OPTS ""
622 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
624 BlockInterfaceType
*block_default_type
= opaque
;
626 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
629 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
631 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
632 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
637 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
638 int index
, const char *optstr
)
643 if (!enable
|| drive_get_by_index(type
, index
)) {
647 opts
= drive_add(type
, index
, NULL
, optstr
);
649 drive_enable_snapshot(NULL
, opts
, NULL
);
652 dinfo
= drive_new(opts
, type
, &error_abort
);
653 dinfo
->is_default
= true;
657 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
658 MachineClass
*machine_class
, int snapshot
)
661 * If the currently selected machine wishes to override the
662 * units-per-bus property of its default HBA interface type, do so
665 if (machine_class
->units_per_default_bus
) {
666 override_max_devs(machine_class
->block_default_type
,
667 machine_class
->units_per_default_bus
);
670 /* open the virtual block devices */
671 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
672 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
674 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
675 loc_push_restore(&bdo
->loc
);
676 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
678 qapi_free_BlockdevOptions(bdo
->bdo
);
682 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
685 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
686 &machine_class
->block_default_type
, &error_fatal
)) {
687 /* We printed help */
691 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
693 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
694 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
698 static QemuOptsList qemu_smp_opts
= {
700 .implied_opt_name
= "cpus",
702 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
706 .type
= QEMU_OPT_NUMBER
,
709 .type
= QEMU_OPT_NUMBER
,
712 .type
= QEMU_OPT_NUMBER
,
715 .type
= QEMU_OPT_NUMBER
,
718 .type
= QEMU_OPT_NUMBER
,
721 .type
= QEMU_OPT_NUMBER
,
727 static void realtime_init(void)
730 if (os_mlock() < 0) {
731 error_report("locking memory failed");
738 static void configure_msg(QemuOpts
*opts
)
740 error_with_timestamp
= qemu_opt_get_bool(opts
, "timestamp", false);
741 error_with_guestname
= qemu_opt_get_bool(opts
, "guest-name", false);
745 /***********************************************************/
748 static int usb_device_add(const char *devname
)
750 USBDevice
*dev
= NULL
;
752 if (!machine_usb(current_machine
)) {
756 dev
= usbdevice_create(devname
);
763 static int usb_parse(const char *cmdline
)
766 r
= usb_device_add(cmdline
);
768 error_report("could not add USB device '%s'", cmdline
);
773 /***********************************************************/
774 /* machine registration */
776 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
780 for (el
= machines
; el
; el
= el
->next
) {
781 MachineClass
*mc
= el
->data
;
783 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
791 static MachineClass
*find_default_machine(GSList
*machines
)
794 MachineClass
*default_machineclass
= NULL
;
796 for (el
= machines
; el
; el
= el
->next
) {
797 MachineClass
*mc
= el
->data
;
799 if (mc
->is_default
) {
800 assert(default_machineclass
== NULL
&& "Multiple default machines");
801 default_machineclass
= mc
;
805 return default_machineclass
;
808 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
810 ObjectProperty
*prop
;
811 ObjectPropertyIterator iter
;
813 if (!qemu_opt_has_help_opt(opts
)) {
817 object_property_iter_init(&iter
, OBJECT(machine
));
818 while ((prop
= object_property_iter_next(&iter
))) {
823 printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
824 prop
->name
, prop
->type
);
825 if (prop
->description
) {
826 printf(" (%s)\n", prop
->description
);
835 static void version(void)
837 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
838 QEMU_COPYRIGHT
"\n");
841 static void help(int exitcode
)
844 printf("usage: %s [options] [disk_image]\n\n"
845 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
846 error_get_progname());
848 #define QEMU_OPTIONS_GENERATE_HELP
849 #include "qemu-options-wrapper.h"
851 printf("\nDuring emulation, the following keys are useful:\n"
852 "ctrl-alt-f toggle full screen\n"
853 "ctrl-alt-n switch to virtual console 'n'\n"
854 "ctrl-alt toggle mouse and keyboard grab\n"
856 "When using -nographic, press 'ctrl-a h' to get some help.\n"
858 QEMU_HELP_BOTTOM
"\n");
863 #define HAS_ARG 0x0001
865 typedef struct QEMUOption
{
872 static const QEMUOption qemu_options
[] = {
873 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
874 #define QEMU_OPTIONS_GENERATE_OPTIONS
875 #include "qemu-options-wrapper.h"
879 typedef struct VGAInterfaceInfo
{
880 const char *opt_name
; /* option name */
881 const char *name
; /* human-readable name */
882 /* Class names indicating that support is available.
883 * If no class is specified, the interface is always available */
884 const char *class_names
[2];
887 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
890 .name
= "no graphic card",
894 .name
= "standard VGA",
895 .class_names
= { "VGA", "isa-vga" },
898 .opt_name
= "cirrus",
899 .name
= "Cirrus VGA",
900 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
903 .opt_name
= "vmware",
904 .name
= "VMWare SVGA",
905 .class_names
= { "vmware-svga" },
908 .opt_name
= "virtio",
909 .name
= "Virtio VGA",
910 .class_names
= { "virtio-vga" },
915 .class_names
= { "qxl-vga" },
919 .name
= "TCX framebuffer",
920 .class_names
= { "SUNW,tcx" },
924 .name
= "CG3 framebuffer",
925 .class_names
= { "cgthree" },
929 .name
= "Xen paravirtualized framebuffer",
933 static bool vga_interface_available(VGAInterfaceType t
)
935 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
937 assert(t
< VGA_TYPE_MAX
);
938 return !ti
->class_names
[0] ||
939 module_object_class_by_name(ti
->class_names
[0]) ||
940 module_object_class_by_name(ti
->class_names
[1]);
944 get_default_vga_model(const MachineClass
*machine_class
)
946 if (machine_class
->default_display
) {
947 return machine_class
->default_display
;
948 } else if (vga_interface_available(VGA_CIRRUS
)) {
950 } else if (vga_interface_available(VGA_STD
)) {
957 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
962 if (g_str_equal(p
, "help")) {
963 const char *def
= get_default_vga_model(machine_class
);
965 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
966 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
968 if (vga_interface_available(t
) && ti
->opt_name
) {
969 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
970 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
976 assert(vga_interface_type
== VGA_NONE
);
977 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
978 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
979 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
980 if (!vga_interface_available(t
)) {
981 error_report("%s not available", ti
->name
);
984 vga_interface_type
= t
;
988 if (t
== VGA_TYPE_MAX
) {
990 error_report("unknown vga type: %s", p
);
996 if (strstart(opts
, ",retrace=", &nextopt
)) {
998 if (strstart(opts
, "dumb", &nextopt
))
999 vga_retrace_method
= VGA_RETRACE_DUMB
;
1000 else if (strstart(opts
, "precise", &nextopt
))
1001 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1002 else goto invalid_vga
;
1003 } else goto invalid_vga
;
1008 static void parse_display_qapi(const char *optarg
)
1010 DisplayOptions
*opts
;
1013 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
1015 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
1016 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
1018 qapi_free_DisplayOptions(opts
);
1022 DisplayOptions
*qmp_query_display_options(Error
**errp
)
1024 return QAPI_CLONE(DisplayOptions
, &dpy
);
1027 static void parse_display(const char *p
)
1031 if (is_help_option(p
)) {
1032 qemu_display_help();
1036 if (strstart(p
, "sdl", &opts
)) {
1038 * sdl DisplayType needs hand-crafted parser instead of
1039 * parse_display_qapi() due to some options not in
1040 * DisplayOptions, specifically:
1042 * Already deprecated.
1043 * - ctrl_grab + alt_grab
1044 * Not clear yet what happens to them long-term. Should
1045 * replaced by something better or deprecated and dropped.
1047 dpy
.type
= DISPLAY_TYPE_SDL
;
1049 const char *nextopt
;
1051 if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1053 if (strstart(opts
, "on", &nextopt
)) {
1055 } else if (strstart(opts
, "off", &nextopt
)) {
1058 goto invalid_sdl_args
;
1060 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1062 if (strstart(opts
, "on", &nextopt
)) {
1064 } else if (strstart(opts
, "off", &nextopt
)) {
1067 goto invalid_sdl_args
;
1069 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
1071 dpy
.has_window_close
= true;
1072 if (strstart(opts
, "on", &nextopt
)) {
1073 dpy
.window_close
= true;
1074 } else if (strstart(opts
, "off", &nextopt
)) {
1075 dpy
.window_close
= false;
1077 goto invalid_sdl_args
;
1079 } else if (strstart(opts
, ",show-cursor=", &nextopt
)) {
1081 dpy
.has_show_cursor
= true;
1082 if (strstart(opts
, "on", &nextopt
)) {
1083 dpy
.show_cursor
= true;
1084 } else if (strstart(opts
, "off", &nextopt
)) {
1085 dpy
.show_cursor
= false;
1087 goto invalid_sdl_args
;
1089 } else if (strstart(opts
, ",gl=", &nextopt
)) {
1092 if (strstart(opts
, "on", &nextopt
)) {
1093 dpy
.gl
= DISPLAYGL_MODE_ON
;
1094 } else if (strstart(opts
, "core", &nextopt
)) {
1095 dpy
.gl
= DISPLAYGL_MODE_CORE
;
1096 } else if (strstart(opts
, "es", &nextopt
)) {
1097 dpy
.gl
= DISPLAYGL_MODE_ES
;
1098 } else if (strstart(opts
, "off", &nextopt
)) {
1099 dpy
.gl
= DISPLAYGL_MODE_OFF
;
1101 goto invalid_sdl_args
;
1105 error_report("invalid SDL option string");
1110 } else if (strstart(p
, "vnc", &opts
)) {
1112 * vnc isn't a (local) DisplayType but a protocol for remote
1116 vnc_parse(opts
+ 1);
1118 error_report("VNC requires a display argument vnc=<display>");
1122 parse_display_qapi(p
);
1126 static inline bool nonempty_str(const char *str
)
1131 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1135 const char *name
, *file
, *str
, *gen_id
;
1136 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1138 if (fw_cfg
== NULL
) {
1139 error_setg(errp
, "fw_cfg device not available");
1142 name
= qemu_opt_get(opts
, "name");
1143 file
= qemu_opt_get(opts
, "file");
1144 str
= qemu_opt_get(opts
, "string");
1145 gen_id
= qemu_opt_get(opts
, "gen_id");
1147 /* we need the name, and exactly one of: file, content string, gen_id */
1148 if (!nonempty_str(name
) ||
1149 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1150 error_setg(errp
, "name, plus exactly one of file,"
1151 " string and gen_id, are needed");
1154 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1155 error_setg(errp
, "name too long (max. %d char)",
1156 FW_CFG_MAX_FILE_PATH
- 1);
1159 if (nonempty_str(gen_id
)) {
1161 * In this particular case where the content is populated
1162 * internally, the "etc/" namespace protection is relaxed,
1163 * so do not emit a warning.
1165 } else if (strncmp(name
, "opt/", 4) != 0) {
1166 warn_report("externally provided fw_cfg item names "
1167 "should be prefixed with \"opt/\"");
1169 if (nonempty_str(str
)) {
1170 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1171 buf
= g_memdup(str
, size
);
1172 } else if (nonempty_str(gen_id
)) {
1173 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1179 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1180 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1185 /* For legacy, keep user files in a specific global order. */
1186 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1187 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1188 fw_cfg_reset_order_override(fw_cfg
);
1192 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1194 return qdev_device_help(opts
);
1197 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1201 dev
= qdev_device_add(opts
, errp
);
1202 if (!dev
&& *errp
) {
1203 error_report_err(*errp
);
1206 object_unref(OBJECT(dev
));
1211 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1213 Error
*local_err
= NULL
;
1215 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1217 error_propagate(errp
, local_err
);
1225 #ifdef CONFIG_VIRTFS
1226 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1228 return qemu_fsdev_add(opts
, errp
);
1232 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1234 return monitor_init_opts(opts
, errp
);
1237 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
1239 static int monitor_device_index
= 0;
1244 if (strstart(optarg
, "chardev:", &p
)) {
1245 snprintf(label
, sizeof(label
), "%s", p
);
1247 snprintf(label
, sizeof(label
), "compat_monitor%d",
1248 monitor_device_index
);
1249 opts
= qemu_chr_parse_compat(label
, optarg
, true);
1251 error_report("parse error: %s", optarg
);
1256 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1257 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1258 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1259 if (!strcmp(mode
, "control")) {
1260 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1262 assert(pretty
== false);
1264 monitor_device_index
++;
1267 struct device_config
{
1269 DEV_USB
, /* -usbdevice */
1270 DEV_SERIAL
, /* -serial */
1271 DEV_PARALLEL
, /* -parallel */
1272 DEV_DEBUGCON
, /* -debugcon */
1273 DEV_GDB
, /* -gdb, -s */
1274 DEV_SCLP
, /* s390 sclp */
1276 const char *cmdline
;
1278 QTAILQ_ENTRY(device_config
) next
;
1281 static QTAILQ_HEAD(, device_config
) device_configs
=
1282 QTAILQ_HEAD_INITIALIZER(device_configs
);
1284 static void add_device_config(int type
, const char *cmdline
)
1286 struct device_config
*conf
;
1288 conf
= g_malloc0(sizeof(*conf
));
1290 conf
->cmdline
= cmdline
;
1291 loc_save(&conf
->loc
);
1292 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1295 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1297 struct device_config
*conf
;
1300 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1301 if (conf
->type
!= type
)
1303 loc_push_restore(&conf
->loc
);
1304 rc
= func(conf
->cmdline
);
1305 loc_pop(&conf
->loc
);
1313 static void qemu_disable_default_devices(void)
1315 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1317 qemu_opts_foreach(qemu_find_opts("device"),
1318 default_driver_check
, NULL
, NULL
);
1319 qemu_opts_foreach(qemu_find_opts("global"),
1320 default_driver_check
, NULL
, NULL
);
1322 if (!vga_model
&& !default_vga
) {
1323 vga_interface_type
= VGA_DEVICE
;
1325 if (!has_defaults
|| machine_class
->no_serial
) {
1328 if (!has_defaults
|| machine_class
->no_parallel
) {
1329 default_parallel
= 0;
1331 if (!has_defaults
|| machine_class
->no_floppy
) {
1334 if (!has_defaults
|| machine_class
->no_cdrom
) {
1337 if (!has_defaults
|| machine_class
->no_sdcard
) {
1340 if (!has_defaults
) {
1341 default_monitor
= 0;
1347 static void qemu_create_default_devices(void)
1349 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1351 if (is_daemonized()) {
1352 /* According to documentation and historically, -nographic redirects
1353 * serial port, parallel port and monitor to stdio, which does not work
1354 * with -daemonize. We can redirect these to null instead, but since
1355 * -nographic is legacy, let's just error out.
1356 * We disallow -nographic only if all other ports are not redirected
1357 * explicitly, to not break existing legacy setups which uses
1358 * -nographic _and_ redirects all ports explicitly - this is valid
1359 * usage, -nographic is just a no-op in this case.
1362 && (default_parallel
|| default_serial
|| default_monitor
)) {
1363 error_report("-nographic cannot be used with -daemonize");
1369 if (default_parallel
)
1370 add_device_config(DEV_PARALLEL
, "null");
1371 if (default_serial
&& default_monitor
) {
1372 add_device_config(DEV_SERIAL
, "mon:stdio");
1375 add_device_config(DEV_SERIAL
, "stdio");
1376 if (default_monitor
)
1377 monitor_parse("stdio", "readline", false);
1381 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
1382 if (default_parallel
)
1383 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
1384 if (default_monitor
)
1385 monitor_parse("vc:80Cx24C", "readline", false);
1389 QemuOptsList
*net
= qemu_find_opts("net");
1390 qemu_opts_parse(net
, "nic", true, &error_abort
);
1392 qemu_opts_parse(net
, "user", true, &error_abort
);
1396 #if defined(CONFIG_VNC)
1397 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
1401 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1402 if (!qemu_display_find_default(&dpy
)) {
1403 dpy
.type
= DISPLAY_TYPE_NONE
;
1404 #if defined(CONFIG_VNC)
1405 vnc_parse("localhost:0,to=99,id=default");
1409 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1410 dpy
.type
= DISPLAY_TYPE_NONE
;
1413 /* If no default VGA is requested, the default is "none". */
1415 vga_model
= get_default_vga_model(machine_class
);
1418 select_vgahw(machine_class
, vga_model
);
1422 static int serial_parse(const char *devname
)
1424 int index
= num_serial_hds
;
1427 if (strcmp(devname
, "none") == 0)
1429 snprintf(label
, sizeof(label
), "serial%d", index
);
1430 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1432 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1433 if (!serial_hds
[index
]) {
1434 error_report("could not connect serial device"
1435 " to character backend '%s'", devname
);
1442 Chardev
*serial_hd(int i
)
1445 if (i
< num_serial_hds
) {
1446 return serial_hds
[i
];
1451 static int parallel_parse(const char *devname
)
1453 static int index
= 0;
1456 if (strcmp(devname
, "none") == 0)
1458 if (index
== MAX_PARALLEL_PORTS
) {
1459 error_report("too many parallel ports");
1462 snprintf(label
, sizeof(label
), "parallel%d", index
);
1463 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1464 if (!parallel_hds
[index
]) {
1465 error_report("could not connect parallel device"
1466 " to character backend '%s'", devname
);
1473 static int debugcon_parse(const char *devname
)
1477 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1478 error_report("invalid character backend '%s'", devname
);
1481 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1483 error_report("already have a debugcon device");
1486 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1487 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1491 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1493 const MachineClass
*mc1
= a
, *mc2
= b
;
1496 if (mc1
->family
== NULL
) {
1497 if (mc2
->family
== NULL
) {
1498 /* Compare standalone machine types against each other; they sort
1499 * in increasing order.
1501 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1502 object_class_get_name(OBJECT_CLASS(mc2
)));
1505 /* Standalone machine types sort after families. */
1509 if (mc2
->family
== NULL
) {
1510 /* Families sort before standalone machine types. */
1514 /* Families sort between each other alphabetically increasingly. */
1515 res
= strcmp(mc1
->family
, mc2
->family
);
1520 /* Within the same family, machine types sort in decreasing order. */
1521 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1522 object_class_get_name(OBJECT_CLASS(mc1
)));
1525 static MachineClass
*machine_parse(const char *name
, GSList
*machines
)
1530 if (is_help_option(name
)) {
1531 printf("Supported machines are:\n");
1532 machines
= g_slist_sort(machines
, machine_class_cmp
);
1533 for (el
= machines
; el
; el
= el
->next
) {
1534 MachineClass
*mc
= el
->data
;
1536 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1538 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1539 mc
->is_default
? " (default)" : "",
1540 mc
->deprecation_reason
? " (deprecated)" : "");
1545 mc
= find_machine(name
, machines
);
1547 error_report("unsupported machine type");
1548 error_printf("Use -machine help to list supported machines\n");
1554 static const char *pid_file
;
1555 static Notifier qemu_unlink_pidfile_notifier
;
1557 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1564 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1565 const char **poptarg
, int *poptind
)
1567 const QEMUOption
*popt
;
1568 int optind
= *poptind
;
1569 char *r
= argv
[optind
];
1572 loc_set_cmdline(argv
, optind
, 1);
1574 /* Treat --foo the same as -foo. */
1577 popt
= qemu_options
;
1580 error_report("invalid option");
1583 if (!strcmp(popt
->name
, r
+ 1))
1587 if (popt
->flags
& HAS_ARG
) {
1588 if (optind
>= argc
) {
1589 error_report("requires an argument");
1592 optarg
= argv
[optind
++];
1593 loc_set_cmdline(argv
, optind
- 2, 2);
1604 static MachineClass
*select_machine(void)
1606 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
1607 MachineClass
*machine_class
= find_default_machine(machines
);
1612 loc_push_none(&loc
);
1614 opts
= qemu_get_machine_opts();
1615 qemu_opts_loc_restore(opts
);
1617 optarg
= qemu_opt_get(opts
, "type");
1619 machine_class
= machine_parse(optarg
, machines
);
1622 if (!machine_class
) {
1623 error_report("No machine specified, and there is no default");
1624 error_printf("Use -machine help to list supported machines\n");
1629 g_slist_free(machines
);
1630 return machine_class
;
1633 static int object_parse_property_opt(Object
*obj
,
1634 const char *name
, const char *value
,
1635 const char *skip
, Error
**errp
)
1637 if (g_str_equal(name
, skip
)) {
1641 if (!object_property_parse(obj
, name
, value
, errp
)) {
1648 static int machine_set_property(void *opaque
,
1649 const char *name
, const char *value
,
1652 g_autofree
char *qom_name
= g_strdup(name
);
1655 for (p
= qom_name
; *p
; p
++) {
1661 /* Legacy options do not correspond to MachineState properties. */
1662 if (g_str_equal(qom_name
, "accel")) {
1665 if (g_str_equal(qom_name
, "igd-passthru")) {
1666 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name
, value
);
1669 if (g_str_equal(qom_name
, "kvm-shadow-mem")) {
1670 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name
, value
);
1673 if (g_str_equal(qom_name
, "kernel-irqchip")) {
1674 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name
, value
);
1675 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name
, value
);
1679 return object_parse_property_opt(opaque
, name
, value
, "type", errp
);
1683 * Initial object creation happens before all other
1684 * QEMU data types are created. The majority of objects
1685 * can be created at this point. The rng-egd object
1686 * cannot be created here, as it depends on the chardev
1689 static bool object_create_early(const char *type
, QemuOpts
*opts
)
1691 if (user_creatable_print_help(type
, opts
)) {
1696 * Objects should not be made "delayed" without a reason. If you
1697 * add one, state the reason in a comment!
1700 /* Reason: rng-egd property "chardev" */
1701 if (g_str_equal(type
, "rng-egd")) {
1705 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1706 /* Reason: cryptodev-vhost-user property "chardev" */
1707 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1712 /* Reason: vhost-user-blk-server property "node-name" */
1713 if (g_str_equal(type
, "vhost-user-blk-server")) {
1717 * Reason: filter-* property "netdev" etc.
1719 if (g_str_equal(type
, "filter-buffer") ||
1720 g_str_equal(type
, "filter-dump") ||
1721 g_str_equal(type
, "filter-mirror") ||
1722 g_str_equal(type
, "filter-redirector") ||
1723 g_str_equal(type
, "colo-compare") ||
1724 g_str_equal(type
, "filter-rewriter") ||
1725 g_str_equal(type
, "filter-replay")) {
1729 /* Allocation of large amounts of memory may delay
1730 * chardev initialization for too long, and trigger timeouts
1731 * on software that waits for a monitor socket to be created
1734 if (g_str_has_prefix(type
, "memory-backend-")) {
1741 static void qemu_apply_machine_options(void)
1743 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1744 QemuOpts
*machine_opts
= qemu_get_machine_opts();
1745 const char *boot_order
= NULL
;
1746 const char *boot_once
= NULL
;
1749 qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
1751 current_machine
->ram_size
= ram_size
;
1752 current_machine
->maxram_size
= maxram_size
;
1753 current_machine
->ram_slots
= ram_slots
;
1755 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
1757 boot_order
= qemu_opt_get(opts
, "order");
1759 validate_bootdevices(boot_order
, &error_fatal
);
1762 boot_once
= qemu_opt_get(opts
, "once");
1764 validate_bootdevices(boot_once
, &error_fatal
);
1767 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
1768 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
1772 boot_order
= machine_class
->default_boot_order
;
1775 current_machine
->boot_order
= boot_order
;
1776 current_machine
->boot_once
= boot_once
;
1778 if (semihosting_enabled() && !semihosting_get_argc()) {
1779 const char *kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
1780 const char *kernel_cmdline
= qemu_opt_get(machine_opts
, "append") ?: "";
1781 /* fall back to the -kernel/-append */
1782 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
1786 static void qemu_create_early_backends(void)
1788 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1790 if ((alt_grab
|| ctrl_grab
) && dpy
.type
!= DISPLAY_TYPE_SDL
) {
1791 error_report("-alt-grab and -ctrl-grab are only valid "
1792 "for SDL, ignoring option");
1794 if (dpy
.has_window_close
&&
1795 (dpy
.type
!= DISPLAY_TYPE_GTK
&& dpy
.type
!= DISPLAY_TYPE_SDL
)) {
1796 error_report("-no-quit is only valid for GTK and SDL, "
1800 qemu_display_early_init(&dpy
);
1801 qemu_console_early_init();
1803 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1804 #if defined(CONFIG_OPENGL)
1805 error_report("OpenGL is not supported by the display");
1807 error_report("OpenGL support is disabled");
1812 qemu_opts_foreach(qemu_find_opts("object"),
1813 user_creatable_add_opts_foreach
,
1814 object_create_early
, &error_fatal
);
1816 /* spice needs the timers to be initialized by this point */
1817 /* spice must initialize before audio as it changes the default auiodev */
1818 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1821 qemu_opts_foreach(qemu_find_opts("chardev"),
1822 chardev_init_func
, NULL
, &error_fatal
);
1824 #ifdef CONFIG_VIRTFS
1825 qemu_opts_foreach(qemu_find_opts("fsdev"),
1826 fsdev_init_func
, NULL
, &error_fatal
);
1830 * Note: we need to create audio and block backends before
1831 * machine_set_property(), so machine properties can refer to
1834 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
1835 audio_init_audiodevs();
1840 * The remainder of object creation happens after the
1841 * creation of chardev, fsdev, net clients and device data types.
1843 static bool object_create_late(const char *type
, QemuOpts
*opts
)
1845 return !object_create_early(type
, opts
);
1848 static void qemu_create_late_backends(void)
1851 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
1854 net_init_clients(&error_fatal
);
1856 qemu_opts_foreach(qemu_find_opts("object"),
1857 user_creatable_add_opts_foreach
,
1858 object_create_late
, &error_fatal
);
1860 if (tpm_init() < 0) {
1864 qemu_opts_foreach(qemu_find_opts("mon"),
1865 mon_init_func
, NULL
, &error_fatal
);
1867 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
1869 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
1871 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
1874 /* now chardevs have been created we may have semihosting to connect */
1875 qemu_semihosting_connect_chardevs();
1876 qemu_semihosting_console_init();
1879 static bool have_custom_ram_size(void)
1881 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
1882 return !!qemu_opt_get_size(opts
, "size", 0);
1885 static void qemu_resolve_machine_memdev(void)
1887 if (current_machine
->ram_memdev_id
) {
1889 ram_addr_t backend_size
;
1891 backend
= object_resolve_path_type(current_machine
->ram_memdev_id
,
1892 TYPE_MEMORY_BACKEND
, NULL
);
1894 error_report("Memory backend '%s' not found",
1895 current_machine
->ram_memdev_id
);
1898 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
1899 if (have_custom_ram_size() && backend_size
!= ram_size
) {
1900 error_report("Size specified by -m option must match size of "
1901 "explicitly specified 'memory-backend' property");
1905 error_report("'-mem-path' can't be used together with"
1906 "'-machine memory-backend'");
1909 ram_size
= backend_size
;
1912 if (!xen_enabled()) {
1913 /* On 32-bit hosts, QEMU is limited by virtual address space */
1914 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
1915 error_report("at most 2047 MB RAM can be simulated");
1921 static void set_memory_options(MachineClass
*mc
)
1924 const char *mem_str
;
1925 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
1926 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
1929 loc_push_none(&loc
);
1930 qemu_opts_loc_restore(opts
);
1933 mem_str
= qemu_opt_get(opts
, "size");
1936 error_report("missing 'size' option value");
1940 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
1942 /* Fix up legacy suffix-less format */
1943 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
1944 uint64_t overflow_check
= sz
;
1947 if (sz
/ MiB
!= overflow_check
) {
1948 error_report("too large 'size' option value");
1954 /* backward compatibility behaviour for case "-m 0" */
1956 sz
= default_ram_size
;
1959 sz
= QEMU_ALIGN_UP(sz
, 8192);
1960 if (mc
->fixup_ram_size
) {
1961 sz
= mc
->fixup_ram_size(sz
);
1964 if (ram_size
!= sz
) {
1965 error_report("ram size too large");
1969 /* store value for the future use */
1970 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
1971 maxram_size
= ram_size
;
1973 if (qemu_opt_get(opts
, "maxmem")) {
1976 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
1977 slots
= qemu_opt_get_number(opts
, "slots", 0);
1978 if (sz
< ram_size
) {
1979 error_report("invalid value of -m option maxmem: "
1980 "maximum memory size (0x%" PRIx64
") must be at least "
1981 "the initial memory size (0x" RAM_ADDR_FMT
")",
1984 } else if (slots
&& sz
== ram_size
) {
1985 error_report("invalid value of -m option maxmem: "
1986 "memory slots were specified but maximum memory size "
1987 "(0x%" PRIx64
") is equal to the initial memory size "
1988 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
1994 } else if (qemu_opt_get(opts
, "slots")) {
1995 error_report("invalid -m option value: missing 'maxmem' option");
2002 static void qemu_create_machine(MachineClass
*machine_class
)
2004 object_set_machine_compat_props(machine_class
->compat_props
);
2006 set_memory_options(machine_class
);
2008 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2009 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
2012 object_property_add_child(object_get_root(), "machine",
2013 OBJECT(current_machine
));
2014 object_property_add_child(container_get(OBJECT(current_machine
),
2016 "sysbus", OBJECT(sysbus_get_default()));
2018 if (machine_class
->minimum_page_bits
) {
2019 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2020 /* This would be a board error: specifying a minimum smaller than
2021 * a target's compile-time fixed setting.
2023 g_assert_not_reached();
2027 cpu_exec_init_all();
2030 if (machine_class
->hw_version
) {
2031 qemu_set_hw_version(machine_class
->hw_version
);
2034 machine_smp_parse(current_machine
,
2035 qemu_opts_find(qemu_find_opts("smp-opts"), NULL
), &error_fatal
);
2038 * Get the default machine options from the machine if it is not already
2039 * specified either by the configuration file or by the command line.
2041 if (machine_class
->default_machine_opts
) {
2042 qemu_opts_set_defaults(qemu_find_opts("machine"),
2043 machine_class
->default_machine_opts
, 0);
2047 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2051 g
= g_malloc0(sizeof(*g
));
2052 g
->driver
= qemu_opt_get(opts
, "driver");
2053 g
->property
= qemu_opt_get(opts
, "property");
2054 g
->value
= qemu_opt_get(opts
, "value");
2055 qdev_prop_register_global(g
);
2059 static int qemu_read_default_config_file(void)
2062 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2064 ret
= qemu_read_config_file(file
);
2065 if (ret
< 0 && ret
!= -ENOENT
) {
2072 static int qemu_set_option(const char *str
)
2074 Error
*local_err
= NULL
;
2075 char group
[64], id
[64], arg
[64];
2080 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2081 if (rc
< 3 || str
[offset
] != '=') {
2082 error_report("can't parse: \"%s\"", str
);
2086 list
= qemu_find_opts(group
);
2091 opts
= qemu_opts_find(list
, id
);
2093 error_report("there is no %s \"%s\" defined",
2098 if (!qemu_opt_set(opts
, arg
, str
+ offset
+ 1, &local_err
)) {
2099 error_report_err(local_err
);
2105 static void user_register_global_props(void)
2107 qemu_opts_foreach(qemu_find_opts("global"),
2108 global_init_func
, NULL
, NULL
);
2111 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2113 icount_configure(opts
, errp
);
2117 static int accelerator_set_property(void *opaque
,
2118 const char *name
, const char *value
,
2121 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2124 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2126 bool *p_init_failed
= opaque
;
2127 const char *acc
= qemu_opt_get(opts
, "accel");
2128 AccelClass
*ac
= accel_find(acc
);
2131 bool qtest_with_kvm
;
2133 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2136 *p_init_failed
= true;
2137 if (!qtest_with_kvm
) {
2138 error_report("invalid accelerator %s", acc
);
2142 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2143 object_apply_compat_props(OBJECT(accel
));
2144 qemu_opt_foreach(opts
, accelerator_set_property
,
2148 ret
= accel_init_machine(accel
, current_machine
);
2150 *p_init_failed
= true;
2151 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2152 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2160 static void configure_accelerators(const char *progname
)
2162 const char *accelerators
;
2163 bool init_failed
= false;
2165 qemu_opts_foreach(qemu_find_opts("icount"),
2166 do_configure_icount
, NULL
, &error_fatal
);
2168 accelerators
= qemu_opt_get(qemu_get_machine_opts(), "accel");
2169 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2170 char **accel_list
, **tmp
;
2172 if (accelerators
== NULL
) {
2173 /* Select the default accelerator */
2174 bool have_tcg
= accel_find("tcg");
2175 bool have_kvm
= accel_find("kvm");
2177 if (have_tcg
&& have_kvm
) {
2178 if (g_str_has_suffix(progname
, "kvm")) {
2179 /* If the program name ends with "kvm", we prefer KVM */
2180 accelerators
= "kvm:tcg";
2182 accelerators
= "tcg:kvm";
2184 } else if (have_kvm
) {
2185 accelerators
= "kvm";
2186 } else if (have_tcg
) {
2187 accelerators
= "tcg";
2189 error_report("No accelerator selected and"
2190 " no default accelerator available");
2194 accel_list
= g_strsplit(accelerators
, ":", 0);
2196 for (tmp
= accel_list
; *tmp
; tmp
++) {
2198 * Filter invalid accelerators here, to prevent obscenities
2199 * such as "-machine accel=tcg,,thread=single".
2201 if (accel_find(*tmp
)) {
2202 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2205 error_report("invalid accelerator %s", *tmp
);
2208 g_strfreev(accel_list
);
2210 if (accelerators
!= NULL
) {
2211 error_report("The -accel and \"-machine accel=\" options are incompatible");
2216 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2217 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2219 error_report("no accelerator found");
2224 if (init_failed
&& !qtest_chrdev
) {
2225 AccelClass
*ac
= ACCEL_GET_CLASS(current_accel());
2226 error_report("falling back to %s", ac
->name
);
2229 if (icount_enabled() && !tcg_enabled()) {
2230 error_report("-icount is not allowed with hardware virtualization");
2235 static void create_default_memdev(MachineState
*ms
, const char *path
)
2238 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
2240 obj
= object_new(path
? TYPE_MEMORY_BACKEND_FILE
: TYPE_MEMORY_BACKEND_RAM
);
2242 object_property_set_str(obj
, "mem-path", path
, &error_fatal
);
2244 object_property_set_int(obj
, "size", ms
->ram_size
, &error_fatal
);
2245 object_property_add_child(object_get_objects_root(), mc
->default_ram_id
,
2247 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2248 object_property_set_bool(obj
, "x-use-canonical-path-for-ramblock-id",
2249 false, &error_fatal
);
2250 user_creatable_complete(USER_CREATABLE(obj
), &error_fatal
);
2252 object_property_set_str(OBJECT(ms
), "memory-backend", mc
->default_ram_id
,
2256 static void qemu_validate_options(void)
2258 QemuOpts
*machine_opts
= qemu_get_machine_opts();
2259 const char *kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
2260 const char *initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
2261 const char *kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
2263 if (kernel_filename
== NULL
) {
2264 if (kernel_cmdline
!= NULL
) {
2265 error_report("-append only allowed with -kernel option");
2269 if (initrd_filename
!= NULL
) {
2270 error_report("-initrd only allowed with -kernel option");
2275 if (loadvm
&& preconfig_requested
) {
2276 error_report("'preconfig' and 'loadvm' options are "
2277 "mutually exclusive");
2280 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2281 error_report("'preconfig' supports '-incoming defer' only");
2285 #ifdef CONFIG_CURSES
2286 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2287 error_report("curses display cannot be used with -daemonize");
2293 static void qemu_process_sugar_options(void)
2298 val
= g_strdup_printf("%d",
2299 (uint32_t) qemu_opt_get_number(qemu_find_opts_singleton("smp-opts"), "cpus", 1));
2300 object_register_sugar_prop("memory-backend", "prealloc-threads", val
);
2302 object_register_sugar_prop("memory-backend", "prealloc", "on");
2306 int i
= select_watchdog(watchdog
);
2308 exit (i
== 1 ? 1 : 0);
2312 /* -action processing */
2315 * Process all the -action parameters parsed from cmdline.
2317 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2319 Error
*local_err
= NULL
;
2320 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2321 QObject
*ret
= NULL
;
2322 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2324 qobject_unref(qdict
);
2326 error_propagate(errp
, local_err
);
2332 static void qemu_process_early_options(void)
2334 #ifdef CONFIG_SECCOMP
2335 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2337 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2341 qemu_opts_foreach(qemu_find_opts("name"),
2342 parse_name
, NULL
, &error_fatal
);
2344 if (qemu_opts_foreach(qemu_find_opts("action"),
2345 process_runstate_actions
, NULL
, &error_fatal
)) {
2350 qemu_opts_foreach(qemu_find_opts("add-fd"),
2351 parse_add_fd
, NULL
, &error_fatal
);
2353 qemu_opts_foreach(qemu_find_opts("add-fd"),
2354 cleanup_add_fd
, NULL
, &error_fatal
);
2357 if (!trace_init_backends()) {
2362 /* Open the logfile at this point and set the log mask if necessary. */
2363 qemu_set_log_filename(log_file
, &error_fatal
);
2366 mask
= qemu_str_to_log_mask(log_mask
);
2368 qemu_print_log_usage(stdout
);
2376 qemu_add_default_firmwarepath();
2379 static void qemu_process_help_options(void)
2382 * Check for -cpu help and -device help before we call select_machine(),
2383 * which will return an error if the architecture has no default machine
2384 * type and the user did not specify one, so that the user doesn't need
2385 * to say '-cpu help -machine something'.
2387 if (cpu_option
&& is_help_option(cpu_option
)) {
2388 list_cpus(cpu_option
);
2392 if (qemu_opts_foreach(qemu_find_opts("device"),
2393 device_help_func
, NULL
, NULL
)) {
2397 /* -L help lists the data directories and exits. */
2398 if (list_data_dirs
) {
2399 qemu_list_data_dirs();
2404 static void qemu_maybe_daemonize(const char *pid_file
)
2409 rcu_disable_atfork();
2411 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
2412 error_reportf_err(err
, "cannot create PID file: ");
2416 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
2417 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
2420 static void qemu_init_displays(void)
2424 /* init local displays */
2425 ds
= init_displaystate();
2426 qemu_display_init(ds
, &dpy
);
2428 /* must be after terminal init, SDL library changes signal handlers */
2429 os_setup_signal_handling();
2431 /* init remote displays */
2433 qemu_opts_foreach(qemu_find_opts("vnc"),
2434 vnc_init_func
, NULL
, &error_fatal
);
2438 qemu_spice
.display_init();
2442 static void qemu_init_board(void)
2444 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
2446 if (machine_class
->default_ram_id
&& current_machine
->ram_size
&&
2447 numa_uses_legacy_mem() && !current_machine
->ram_memdev_id
) {
2448 create_default_memdev(current_machine
, mem_path
);
2451 /* process plugin before CPUs are created, but once -smp has been parsed */
2452 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2454 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2455 machine_run_board_init(current_machine
);
2458 * TODO To drop support for deprecated bogus if=..., move
2459 * drive_check_orphaned() here, replacing this call. Also drop
2460 * its deprecation warning, along with DriveInfo member
2461 * @claimed_by_board.
2463 drive_mark_claimed_by_board();
2467 if (hax_enabled()) {
2468 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2473 static void qemu_create_cli_devices(void)
2477 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2478 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2480 /* init USB devices */
2481 if (machine_usb(current_machine
)) {
2482 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2486 /* init generic devices */
2487 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2488 qemu_opts_foreach(qemu_find_opts("device"),
2489 device_init_func
, NULL
, &error_fatal
);
2490 rom_reset_order_override();
2493 static void qemu_machine_creation_done(void)
2495 /* Did we create any drives that we failed to create a device for? */
2496 drive_check_orphaned();
2498 /* Don't warn about the default network setup that you get if
2499 * no command line -net or -netdev options are specified. There
2500 * are two cases that we would otherwise complain about:
2501 * (1) board doesn't support a NIC but the implicit "-net nic"
2503 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2504 * sets up a nic that isn't connected to anything.
2506 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2507 net_check_clients();
2510 qdev_prop_check_globals();
2512 qdev_machine_creation_done();
2514 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2519 void qmp_x_exit_preconfig(Error
**errp
)
2521 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2522 error_setg(errp
, "The command is permitted only before machine initialization");
2527 qemu_create_cli_devices();
2528 qemu_machine_creation_done();
2531 Error
*local_err
= NULL
;
2532 if (load_snapshot(loadvm
, &local_err
) < 0) {
2533 error_report_err(local_err
);
2538 if (replay_mode
!= REPLAY_MODE_NONE
) {
2539 replay_vmstate_init();
2543 Error
*local_err
= NULL
;
2544 if (strcmp(incoming
, "defer") != 0) {
2545 qmp_migrate_incoming(incoming
, &local_err
);
2547 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2551 } else if (autostart
) {
2556 void qemu_init(int argc
, char **argv
, char **envp
)
2559 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2560 QemuOptsList
*olist
;
2563 MachineClass
*machine_class
;
2564 bool userconfig
= true;
2565 FILE *vmstate_dump_file
= NULL
;
2567 qemu_add_opts(&qemu_drive_opts
);
2568 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2569 qemu_add_drive_opts(&qemu_common_drive_opts
);
2570 qemu_add_drive_opts(&qemu_drive_opts
);
2571 qemu_add_drive_opts(&bdrv_runtime_opts
);
2572 qemu_add_opts(&qemu_chardev_opts
);
2573 qemu_add_opts(&qemu_device_opts
);
2574 qemu_add_opts(&qemu_netdev_opts
);
2575 qemu_add_opts(&qemu_nic_opts
);
2576 qemu_add_opts(&qemu_net_opts
);
2577 qemu_add_opts(&qemu_rtc_opts
);
2578 qemu_add_opts(&qemu_global_opts
);
2579 qemu_add_opts(&qemu_mon_opts
);
2580 qemu_add_opts(&qemu_trace_opts
);
2581 qemu_plugin_add_opts();
2582 qemu_add_opts(&qemu_option_rom_opts
);
2583 qemu_add_opts(&qemu_machine_opts
);
2584 qemu_add_opts(&qemu_accel_opts
);
2585 qemu_add_opts(&qemu_mem_opts
);
2586 qemu_add_opts(&qemu_smp_opts
);
2587 qemu_add_opts(&qemu_boot_opts
);
2588 qemu_add_opts(&qemu_add_fd_opts
);
2589 qemu_add_opts(&qemu_object_opts
);
2590 qemu_add_opts(&qemu_tpmdev_opts
);
2591 qemu_add_opts(&qemu_overcommit_opts
);
2592 qemu_add_opts(&qemu_msg_opts
);
2593 qemu_add_opts(&qemu_name_opts
);
2594 qemu_add_opts(&qemu_numa_opts
);
2595 qemu_add_opts(&qemu_icount_opts
);
2596 qemu_add_opts(&qemu_semihosting_config_opts
);
2597 qemu_add_opts(&qemu_fw_cfg_opts
);
2598 qemu_add_opts(&qemu_action_opts
);
2599 module_call_init(MODULE_INIT_OPTS
);
2601 error_init(argv
[0]);
2602 qemu_init_exec_dir(argv
[0]);
2604 qemu_init_subsystems();
2606 /* first pass of option parsing */
2608 while (optind
< argc
) {
2609 if (argv
[optind
][0] != '-') {
2613 const QEMUOption
*popt
;
2615 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2616 switch (popt
->index
) {
2617 case QEMU_OPTION_nouserconfig
:
2625 if (qemu_read_default_config_file() < 0) {
2630 /* second pass of option parsing */
2635 if (argv
[optind
][0] != '-') {
2636 loc_set_cmdline(argv
, optind
, 1);
2637 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2639 const QEMUOption
*popt
;
2641 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2642 if (!(popt
->arch_mask
& arch_type
)) {
2643 error_report("Option not supported for this target");
2646 switch(popt
->index
) {
2647 case QEMU_OPTION_cpu
:
2648 /* hw initialization will check this */
2649 cpu_option
= optarg
;
2651 case QEMU_OPTION_hda
:
2652 case QEMU_OPTION_hdb
:
2653 case QEMU_OPTION_hdc
:
2654 case QEMU_OPTION_hdd
:
2655 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2658 case QEMU_OPTION_blockdev
:
2661 BlockdevOptionsQueueEntry
*bdo
;
2663 v
= qobject_input_visitor_new_str(optarg
, "driver",
2666 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2667 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2670 loc_save(&bdo
->loc
);
2671 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2674 case QEMU_OPTION_drive
:
2675 if (drive_def(optarg
) == NULL
) {
2679 case QEMU_OPTION_set
:
2680 if (qemu_set_option(optarg
) != 0)
2683 case QEMU_OPTION_global
:
2684 if (qemu_global_option(optarg
) != 0)
2687 case QEMU_OPTION_mtdblock
:
2688 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2690 case QEMU_OPTION_sd
:
2691 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2693 case QEMU_OPTION_pflash
:
2694 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2696 case QEMU_OPTION_snapshot
:
2698 Error
*blocker
= NULL
;
2700 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
2702 replay_add_blocker(blocker
);
2705 case QEMU_OPTION_numa
:
2706 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2712 case QEMU_OPTION_display
:
2713 parse_display(optarg
);
2715 case QEMU_OPTION_nographic
:
2716 olist
= qemu_find_opts("machine");
2717 qemu_opts_parse_noisily(olist
, "graphics=off", false);
2719 dpy
.type
= DISPLAY_TYPE_NONE
;
2721 case QEMU_OPTION_curses
:
2722 #ifdef CONFIG_CURSES
2723 dpy
.type
= DISPLAY_TYPE_CURSES
;
2725 error_report("curses or iconv support is disabled");
2729 case QEMU_OPTION_portrait
:
2730 graphic_rotate
= 90;
2732 case QEMU_OPTION_rotate
:
2733 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2734 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2735 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2736 error_report("only 90, 180, 270 deg rotation is available");
2740 case QEMU_OPTION_kernel
:
2741 qemu_opts_set(qemu_find_opts("machine"), "kernel", optarg
, &error_abort
);
2743 case QEMU_OPTION_initrd
:
2744 qemu_opts_set(qemu_find_opts("machine"), "initrd", optarg
, &error_abort
);
2746 case QEMU_OPTION_append
:
2747 qemu_opts_set(qemu_find_opts("machine"), "append", optarg
, &error_abort
);
2749 case QEMU_OPTION_dtb
:
2750 qemu_opts_set(qemu_find_opts("machine"), "dtb", optarg
, &error_abort
);
2752 case QEMU_OPTION_cdrom
:
2753 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2755 case QEMU_OPTION_boot
:
2756 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2762 case QEMU_OPTION_fda
:
2763 case QEMU_OPTION_fdb
:
2764 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2767 case QEMU_OPTION_no_fd_bootchk
:
2770 case QEMU_OPTION_netdev
:
2772 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2776 case QEMU_OPTION_nic
:
2778 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
2782 case QEMU_OPTION_net
:
2784 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2788 #ifdef CONFIG_LIBISCSI
2789 case QEMU_OPTION_iscsi
:
2790 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
2797 case QEMU_OPTION_audio_help
:
2798 audio_legacy_help();
2801 case QEMU_OPTION_audiodev
:
2802 audio_parse_option(optarg
);
2804 case QEMU_OPTION_soundhw
:
2805 select_soundhw (optarg
);
2810 case QEMU_OPTION_version
:
2815 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
2822 case QEMU_OPTION_tpmdev
:
2823 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
2828 case QEMU_OPTION_mempath
:
2831 case QEMU_OPTION_mem_prealloc
:
2840 case QEMU_OPTION_DFILTER
:
2841 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
2843 case QEMU_OPTION_seed
:
2844 qemu_guest_random_seed_main(optarg
, &error_fatal
);
2847 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
2849 case QEMU_OPTION_gdb
:
2850 add_device_config(DEV_GDB
, optarg
);
2853 if (is_help_option(optarg
)) {
2854 list_data_dirs
= true;
2856 qemu_add_data_dir(g_strdup(optarg
));
2859 case QEMU_OPTION_bios
:
2860 qemu_opts_set(qemu_find_opts("machine"), "firmware", optarg
, &error_abort
);
2862 case QEMU_OPTION_singlestep
:
2869 keyboard_layout
= optarg
;
2871 case QEMU_OPTION_vga
:
2880 w
= strtol(p
, (char **)&p
, 10);
2883 error_report("invalid resolution or depth");
2889 h
= strtol(p
, (char **)&p
, 10);
2894 depth
= strtol(p
, (char **)&p
, 10);
2895 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
2896 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2897 depth
!= 24 && depth
!= 32)
2899 } else if (*p
== '\0') {
2900 depth
= graphic_depth
;
2907 graphic_depth
= depth
;
2910 case QEMU_OPTION_echr
:
2913 term_escape_char
= strtol(optarg
, &r
, 0);
2915 printf("Bad argument to echr\n");
2918 case QEMU_OPTION_monitor
:
2919 default_monitor
= 0;
2920 if (strncmp(optarg
, "none", 4)) {
2921 monitor_parse(optarg
, "readline", false);
2924 case QEMU_OPTION_qmp
:
2925 monitor_parse(optarg
, "control", false);
2926 default_monitor
= 0;
2928 case QEMU_OPTION_qmp_pretty
:
2929 monitor_parse(optarg
, "control", true);
2930 default_monitor
= 0;
2932 case QEMU_OPTION_mon
:
2933 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
2938 default_monitor
= 0;
2940 case QEMU_OPTION_chardev
:
2941 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
2947 case QEMU_OPTION_fsdev
:
2948 olist
= qemu_find_opts("fsdev");
2950 error_report("fsdev support is disabled");
2953 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
2958 case QEMU_OPTION_virtfs
: {
2961 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
2964 olist
= qemu_find_opts("virtfs");
2966 error_report("virtfs support is disabled");
2969 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
2974 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
2975 qemu_opt_get(opts
, "mount_tag") == NULL
) {
2976 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
2979 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
2980 qemu_opts_id(opts
) ?:
2981 qemu_opt_get(opts
, "mount_tag"),
2984 error_report("duplicate or invalid fsdev id: %s",
2985 qemu_opt_get(opts
, "mount_tag"));
2989 writeout
= qemu_opt_get(opts
, "writeout");
2991 #ifdef CONFIG_SYNC_FILE_RANGE
2992 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
2994 error_report("writeout=immediate not supported "
2995 "on this platform");
2999 qemu_opt_set(fsdev
, "fsdriver",
3000 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3001 path
= qemu_opt_get(opts
, "path");
3003 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3005 security_model
= qemu_opt_get(opts
, "security_model");
3006 if (security_model
) {
3007 qemu_opt_set(fsdev
, "security_model", security_model
,
3010 socket
= qemu_opt_get(opts
, "socket");
3012 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3014 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3016 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3019 qemu_opt_set_bool(fsdev
, "readonly",
3020 qemu_opt_get_bool(opts
, "readonly", 0),
3022 multidevs
= qemu_opt_get(opts
, "multidevs");
3024 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3026 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3028 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3029 qemu_opt_set(device
, "fsdev",
3030 qemu_opts_id(fsdev
), &error_abort
);
3031 qemu_opt_set(device
, "mount_tag",
3032 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3035 case QEMU_OPTION_serial
:
3036 add_device_config(DEV_SERIAL
, optarg
);
3038 if (strncmp(optarg
, "mon:", 4) == 0) {
3039 default_monitor
= 0;
3042 case QEMU_OPTION_watchdog
:
3044 error_report("only one watchdog option may be given");
3049 case QEMU_OPTION_action
:
3050 olist
= qemu_find_opts("action");
3051 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3055 case QEMU_OPTION_watchdog_action
:
3056 if (select_watchdog_action(optarg
) == -1) {
3057 error_report("unknown -watchdog-action parameter");
3061 case QEMU_OPTION_parallel
:
3062 add_device_config(DEV_PARALLEL
, optarg
);
3063 default_parallel
= 0;
3064 if (strncmp(optarg
, "mon:", 4) == 0) {
3065 default_monitor
= 0;
3068 case QEMU_OPTION_debugcon
:
3069 add_device_config(DEV_DEBUGCON
, optarg
);
3071 case QEMU_OPTION_loadvm
:
3074 case QEMU_OPTION_full_screen
:
3075 dpy
.has_full_screen
= true;
3076 dpy
.full_screen
= true;
3078 case QEMU_OPTION_alt_grab
:
3081 case QEMU_OPTION_ctrl_grab
:
3084 case QEMU_OPTION_no_quit
:
3085 dpy
.has_window_close
= true;
3086 dpy
.window_close
= false;
3088 case QEMU_OPTION_sdl
:
3090 dpy
.type
= DISPLAY_TYPE_SDL
;
3093 error_report("SDL support is disabled");
3096 case QEMU_OPTION_pidfile
:
3099 case QEMU_OPTION_win2k_hack
:
3100 win2k_install_hack
= 1;
3102 case QEMU_OPTION_acpitable
:
3103 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3108 acpi_table_add(opts
, &error_fatal
);
3110 case QEMU_OPTION_smbios
:
3111 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3116 smbios_entry_add(opts
, &error_fatal
);
3118 case QEMU_OPTION_fwcfg
:
3119 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3125 case QEMU_OPTION_preconfig
:
3126 preconfig_requested
= true;
3128 case QEMU_OPTION_enable_kvm
:
3129 olist
= qemu_find_opts("machine");
3130 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3133 case QEMU_OPTION_machine
:
3134 olist
= qemu_find_opts("machine");
3135 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3140 case QEMU_OPTION_accel
:
3141 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3143 optarg
= qemu_opt_get(accel_opts
, "accel");
3144 if (!optarg
|| is_help_option(optarg
)) {
3145 printf("Accelerators supported in QEMU binary:\n");
3146 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3148 for (el
= accel_list
; el
; el
= el
->next
) {
3149 gchar
*typename
= g_strdup(object_class_get_name(
3150 OBJECT_CLASS(el
->data
)));
3151 /* omit qtest which is used for tests only */
3152 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3153 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3154 gchar
**optname
= g_strsplit(typename
,
3155 ACCEL_CLASS_SUFFIX
, 0);
3156 printf("%s\n", optname
[0]);
3157 g_strfreev(optname
);
3161 g_slist_free(accel_list
);
3165 case QEMU_OPTION_usb
:
3166 olist
= qemu_find_opts("machine");
3167 qemu_opts_parse_noisily(olist
, "usb=on", false);
3169 case QEMU_OPTION_usbdevice
:
3170 error_report("'-usbdevice' is deprecated, please use "
3171 "'-device usb-...' instead");
3172 olist
= qemu_find_opts("machine");
3173 qemu_opts_parse_noisily(olist
, "usb=on", false);
3174 add_device_config(DEV_USB
, optarg
);
3176 case QEMU_OPTION_device
:
3177 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3182 case QEMU_OPTION_smp
:
3183 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3188 case QEMU_OPTION_vnc
:
3191 case QEMU_OPTION_no_acpi
:
3192 olist
= qemu_find_opts("machine");
3193 qemu_opts_parse_noisily(olist
, "acpi=off", false);
3195 case QEMU_OPTION_no_hpet
:
3196 olist
= qemu_find_opts("machine");
3197 qemu_opts_parse_noisily(olist
, "hpet=off", false);
3199 case QEMU_OPTION_no_reboot
:
3200 olist
= qemu_find_opts("action");
3201 qemu_opts_parse_noisily(olist
, "reboot=shutdown", false);
3203 case QEMU_OPTION_no_shutdown
:
3204 olist
= qemu_find_opts("action");
3205 qemu_opts_parse_noisily(olist
, "shutdown=pause", false);
3207 case QEMU_OPTION_uuid
:
3208 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3209 error_report("failed to parse UUID string: wrong format");
3212 qemu_uuid_set
= true;
3214 case QEMU_OPTION_option_rom
:
3215 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3216 error_report("too many option ROMs");
3219 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3224 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3225 option_rom
[nb_option_roms
].bootindex
=
3226 qemu_opt_get_number(opts
, "bootindex", -1);
3227 if (!option_rom
[nb_option_roms
].name
) {
3228 error_report("Option ROM file is not specified");
3233 case QEMU_OPTION_semihosting
:
3234 qemu_semihosting_enable();
3236 case QEMU_OPTION_semihosting_config
:
3237 if (qemu_semihosting_config_options(optarg
) != 0) {
3241 case QEMU_OPTION_name
:
3242 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3247 /* Capture guest name if -msg guest-name is used later */
3248 error_guest_name
= qemu_opt_get(opts
, "guest");
3250 case QEMU_OPTION_prom_env
:
3251 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3252 error_report("too many prom variables");
3255 prom_envs
[nb_prom_envs
] = optarg
;
3258 case QEMU_OPTION_old_param
:
3261 case QEMU_OPTION_rtc
:
3262 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3268 case QEMU_OPTION_icount
:
3269 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3275 case QEMU_OPTION_incoming
:
3277 runstate_set(RUN_STATE_INMIGRATE
);
3281 case QEMU_OPTION_only_migratable
:
3282 only_migratable
= 1;
3284 case QEMU_OPTION_nodefaults
:
3287 case QEMU_OPTION_xen_domid
:
3288 if (!(xen_available())) {
3289 error_report("Option not supported for this target");
3292 xen_domid
= atoi(optarg
);
3294 case QEMU_OPTION_xen_attach
:
3295 if (!(xen_available())) {
3296 error_report("Option not supported for this target");
3299 xen_mode
= XEN_ATTACH
;
3301 case QEMU_OPTION_xen_domid_restrict
:
3302 if (!(xen_available())) {
3303 error_report("Option not supported for this target");
3306 xen_domid_restrict
= true;
3308 case QEMU_OPTION_trace
:
3309 trace_opt_parse(optarg
);
3311 case QEMU_OPTION_plugin
:
3312 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3314 case QEMU_OPTION_readconfig
:
3316 int ret
= qemu_read_config_file(optarg
);
3318 error_report("read config %s: %s", optarg
,
3324 case QEMU_OPTION_spice
:
3325 olist
= qemu_find_opts_err("spice", NULL
);
3327 ui_module_load_one("spice-core");
3328 olist
= qemu_find_opts("spice");
3331 error_report("spice support is disabled");
3334 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3340 case QEMU_OPTION_writeconfig
:
3343 if (strcmp(optarg
, "-") == 0) {
3346 fp
= fopen(optarg
, "w");
3348 error_report("open %s: %s", optarg
,
3353 qemu_config_write(fp
);
3359 case QEMU_OPTION_qtest
:
3360 qtest_chrdev
= optarg
;
3362 case QEMU_OPTION_qtest_log
:
3365 case QEMU_OPTION_sandbox
:
3366 olist
= qemu_find_opts("sandbox");
3368 #ifndef CONFIG_SECCOMP
3369 error_report("-sandbox support is not enabled "
3370 "in this QEMU binary");
3375 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3380 case QEMU_OPTION_add_fd
:
3382 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3388 error_report("File descriptor passing is disabled on this "
3393 case QEMU_OPTION_object
:
3394 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
3400 case QEMU_OPTION_overcommit
:
3401 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3406 enable_mlock
= qemu_opt_get_bool(opts
, "mem-lock", false);
3407 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3409 case QEMU_OPTION_msg
:
3410 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3415 configure_msg(opts
);
3417 case QEMU_OPTION_dump_vmstate
:
3418 if (vmstate_dump_file
) {
3419 error_report("only one '-dump-vmstate' "
3420 "option may be given");
3423 vmstate_dump_file
= fopen(optarg
, "w");
3424 if (vmstate_dump_file
== NULL
) {
3425 error_report("open %s: %s", optarg
, strerror(errno
));
3429 case QEMU_OPTION_enable_sync_profile
:
3432 case QEMU_OPTION_nouserconfig
:
3433 /* Nothing to be parsed here. Especially, do not error out below. */
3436 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3437 error_report("Option not supported in this build");
3444 * Clear error location left behind by the loop.
3445 * Best done right after the loop. Do not insert code here!
3449 qemu_validate_options();
3450 qemu_process_sugar_options();
3453 * These options affect everything else and should be processed
3454 * before daemonizing.
3456 qemu_process_early_options();
3458 qemu_process_help_options();
3459 qemu_maybe_daemonize(pid_file
);
3461 qemu_init_main_loop(&error_fatal
);
3464 user_register_global_props();
3465 replay_configure(icount_opts
);
3467 configure_rtc(qemu_find_opts_singleton("rtc"));
3469 qemu_create_machine(select_machine());
3473 qemu_disable_default_devices();
3474 qemu_create_default_devices();
3475 qemu_create_early_backends();
3477 qemu_apply_machine_options();
3478 phase_advance(PHASE_MACHINE_CREATED
);
3481 * Note: uses machine properties such as kernel-irqchip, must run
3482 * after machine_set_property().
3484 configure_accelerators(argv
[0]);
3485 phase_advance(PHASE_ACCEL_CREATED
);
3488 * Beware, QOM objects created before this point miss global and
3489 * compat properties.
3491 * Global properties get set up by qdev_prop_register_global(),
3492 * called from user_register_global_props(), and certain option
3493 * desugaring. Also in CPU feature desugaring (buried in
3494 * parse_cpu_option()), which happens below this point, but may
3495 * only target the CPU type, which can only be created after
3496 * parse_cpu_option() returned the type.
3498 * Machine compat properties: object_set_machine_compat_props().
3499 * Accelerator compat props: object_set_accelerator_compat_props(),
3500 * called from configure_accelerator().
3503 machine_class
= MACHINE_GET_CLASS(current_machine
);
3504 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
3505 error_report("Machine type '%s' is deprecated: %s",
3506 machine_class
->name
, machine_class
->deprecation_reason
);
3510 * Note: creates a QOM object, must run only after global and
3511 * compat properties have been set up.
3513 migration_object_init();
3515 qemu_create_late_backends();
3517 /* parse features once if machine provides default cpu_type */
3518 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
3520 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
3523 qemu_resolve_machine_memdev();
3524 parse_numa_opts(current_machine
);
3526 if (vmstate_dump_file
) {
3528 dump_vmstate_json_to_file(vmstate_dump_file
);
3532 if (!preconfig_requested
) {
3533 qmp_x_exit_preconfig(&error_fatal
);
3535 qemu_init_displays();
3536 accel_setup_post(current_machine
);