]>
Commit | Line | Data |
---|---|---|
0824d6fc | 1 | /* |
80cabfad | 2 | * QEMU System Emulator |
5fafdf24 | 3 | * |
68d0f70e | 4 | * Copyright (c) 2003-2008 Fabrice Bellard |
5fafdf24 | 5 | * |
1df912cf FB |
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: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
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 | |
22 | * THE SOFTWARE. | |
0824d6fc | 23 | */ |
e688df6b | 24 | |
d38ea87a | 25 | #include "qemu/osdep.h" |
49f95221 | 26 | #include "qemu/help-texts.h" |
2c65db5e | 27 | #include "qemu/datadir.h" |
3dc54b0e | 28 | #include "qemu/units.h" |
c5e3c918 | 29 | #include "exec/cpu-common.h" |
ec5f7ca8 | 30 | #include "exec/page-vary.h" |
a27bd6c7 | 31 | #include "hw/qdev-properties.h" |
6dd75472 | 32 | #include "qapi/compat-policy.h" |
e688df6b | 33 | #include "qapi/error.h" |
2a5ad60b | 34 | #include "qapi/qmp/qdict.h" |
e4383ca2 | 35 | #include "qapi/qmp/qstring.h" |
009ff893 | 36 | #include "qapi/qmp/qjson.h" |
67a1de0d | 37 | #include "qemu-version.h" |
f348b6d1 VB |
38 | #include "qemu/cutils.h" |
39 | #include "qemu/help_option.h" | |
15e09912 | 40 | #include "qemu/hw-version.h" |
cea25275 | 41 | #include "qemu/uuid.h" |
71e8a915 | 42 | #include "sysemu/reset.h" |
54d31236 | 43 | #include "sysemu/runstate.h" |
e6dba048 | 44 | #include "sysemu/runstate-action.h" |
9c17d615 | 45 | #include "sysemu/seccomp.h" |
14a48c1d | 46 | #include "sysemu/tcg.h" |
da278d58 | 47 | #include "sysemu/xen.h" |
452dfbef | 48 | |
d49b6836 | 49 | #include "qemu/error-report.h" |
c8897e8e | 50 | #include "qemu/sockets.h" |
940e43aa | 51 | #include "qemu/accel.h" |
511d2b14 | 52 | #include "hw/usb.h" |
0d09e41a | 53 | #include "hw/isa/isa.h" |
fb8b660e | 54 | #include "hw/scsi/scsi.h" |
866e2b37 | 55 | #include "hw/display/vga.h" |
0d09e41a | 56 | #include "sysemu/watchdog.h" |
a2eb5c0c | 57 | #include "hw/firmware/smbios.h" |
9f57061c | 58 | #include "hw/acpi/acpi.h" |
0d09e41a | 59 | #include "hw/xen/xen.h" |
45a50b16 | 60 | #include "hw/loader.h" |
b4a42f81 | 61 | #include "monitor/qdev.h" |
1422e32d | 62 | #include "net/net.h" |
68ac40d2 | 63 | #include "net/slirp.h" |
83c9089e | 64 | #include "monitor/monitor.h" |
28ecbaee | 65 | #include "ui/console.h" |
e0d2bd51 | 66 | #include "ui/input.h" |
9c17d615 | 67 | #include "sysemu/sysemu.h" |
e35704ba | 68 | #include "sysemu/numa.h" |
900c0ba3 | 69 | #include "sysemu/hostmem.h" |
022c62cb | 70 | #include "exec/gdbstub.h" |
1de7afc9 | 71 | #include "qemu/timer.h" |
8228e353 | 72 | #include "chardev/char.h" |
b33276a7 | 73 | #include "qemu/bitmap.h" |
03dd024f | 74 | #include "qemu/log.h" |
9c17d615 | 75 | #include "sysemu/blockdev.h" |
0d09e41a | 76 | #include "hw/block/block.h" |
c5e3c918 PB |
77 | #include "hw/i386/x86.h" |
78 | #include "hw/i386/pc.h" | |
7b1e1a22 | 79 | #include "migration/misc.h" |
5e22479a | 80 | #include "migration/snapshot.h" |
bdee56f5 | 81 | #include "sysemu/tpm.h" |
9c17d615 | 82 | #include "sysemu/dma.h" |
8a824e4d | 83 | #include "hw/audio/soundhw.h" |
511d2b14 | 84 | #include "audio/audio.h" |
4b4629d9 | 85 | #include "sysemu/cpus.h" |
740b1759 | 86 | #include "sysemu/cpu-timers.h" |
5821ebf9 | 87 | #include "migration/colo.h" |
1693c64c | 88 | #include "migration/postcopy-ram.h" |
9c17d615 | 89 | #include "sysemu/kvm.h" |
b0cb0a66 | 90 | #include "sysemu/hax.h" |
42e5f393 | 91 | #include "qapi/qobject-input-visitor.h" |
1de7afc9 PB |
92 | #include "qemu/option.h" |
93 | #include "qemu/config-file.h" | |
fd5fc4b1 | 94 | #include "qemu/qemu-options.h" |
1de7afc9 | 95 | #include "qemu/main-loop.h" |
758e8e38 | 96 | #ifdef CONFIG_VIRTFS |
74db920c GS |
97 | #include "fsdev/qemu-fsdev.h" |
98 | #endif | |
9c17d615 | 99 | #include "sysemu/qtest.h" |
511d2b14 | 100 | |
76cad711 | 101 | #include "disas/disas.h" |
fc01f7e7 | 102 | |
8b7a5507 | 103 | #include "trace.h" |
e4858974 | 104 | #include "trace/control.h" |
42229a75 | 105 | #include "qemu/plugin.h" |
1de7afc9 | 106 | #include "qemu/queue.h" |
9c17d615 | 107 | #include "sysemu/arch_init.h" |
abc27d42 | 108 | #include "exec/confidential-guest-support.h" |
72cf2d4f | 109 | |
29b0040b | 110 | #include "ui/qemu-spice.h" |
68d98d3e | 111 | #include "qapi/string-input-visitor.h" |
c4090f8e | 112 | #include "qapi/opts-visitor.h" |
776d1344 | 113 | #include "qapi/clone-visitor.h" |
84321831 | 114 | #include "qom/object_interfaces.h" |
6b5fe137 | 115 | #include "semihosting/semihost.h" |
ddbb0d09 | 116 | #include "crypto/init.h" |
b60c48a7 | 117 | #include "sysemu/replay.h" |
9af23989 MA |
118 | #include "qapi/qapi-events-run-state.h" |
119 | #include "qapi/qapi-visit-block-core.h" | |
6dd75472 | 120 | #include "qapi/qapi-visit-compat.h" |
776d1344 | 121 | #include "qapi/qapi-visit-ui.h" |
112ed241 | 122 | #include "qapi/qapi-commands-block-core.h" |
e69d50d6 | 123 | #include "qapi/qapi-commands-migration.h" |
ee55686e | 124 | #include "qapi/qapi-commands-misc.h" |
bc2f4fcb | 125 | #include "qapi/qapi-visit-qom.h" |
e1ca8f7e | 126 | #include "qapi/qapi-commands-ui.h" |
c0d4aa82 | 127 | #include "qapi/qmp/qdict.h" |
215aea0c | 128 | #include "block/qdict.h" |
0194749a | 129 | #include "qapi/qmp/qerror.h" |
dce8921b | 130 | #include "sysemu/iothread.h" |
9c09a251 | 131 | #include "qemu/guest-random.h" |
9ca9c893 | 132 | #include "qemu/keyval.h" |
29b0040b | 133 | |
d7795d3c GH |
134 | #include "config-host.h" |
135 | ||
98b19252 AS |
136 | #define MAX_VIRTIO_CONSOLES 1 |
137 | ||
64418657 PB |
138 | typedef struct BlockdevOptionsQueueEntry { |
139 | BlockdevOptions *bdo; | |
140 | Location loc; | |
141 | QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry) entry; | |
142 | } BlockdevOptionsQueueEntry; | |
143 | ||
144 | typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry) BlockdevOptionsQueue; | |
145 | ||
bc2f4fcb PB |
146 | typedef struct ObjectOption { |
147 | ObjectOptions *opts; | |
148 | QTAILQ_ENTRY(ObjectOption) next; | |
149 | } ObjectOption; | |
150 | ||
5dacda51 KW |
151 | typedef struct DeviceOption { |
152 | QDict *opts; | |
153 | Location loc; | |
154 | QTAILQ_ENTRY(DeviceOption) next; | |
155 | } DeviceOption; | |
156 | ||
0546c060 | 157 | static const char *cpu_option; |
d8e4de41 | 158 | static const char *mem_path; |
58c91595 | 159 | static const char *incoming; |
90285ec8 | 160 | static const char *loadvm; |
d8fb7d09 PB |
161 | static const char *accelerators; |
162 | static QDict *machine_opts_dict; | |
bc2f4fcb | 163 | static QTAILQ_HEAD(, ObjectOption) object_opts = QTAILQ_HEAD_INITIALIZER(object_opts); |
5dacda51 | 164 | static QTAILQ_HEAD(, DeviceOption) device_opts = QTAILQ_HEAD_INITIALIZER(device_opts); |
f5c9fcb8 PB |
165 | static ram_addr_t maxram_size; |
166 | static uint64_t ram_slots; | |
f650266b | 167 | static int display_remote; |
64418657 | 168 | static int snapshot; |
7691bdef | 169 | static bool preconfig_requested; |
8a745974 | 170 | static QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list); |
64418657 | 171 | static BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue); |
f650266b | 172 | static bool nographic = false; |
4d2c17b0 | 173 | static int mem_prealloc; /* force preallocation of physical target memory */ |
b326b6ea | 174 | static ram_addr_t ram_size; |
f650266b | 175 | static const char *vga_model = NULL; |
0c8d7065 | 176 | static DisplayOptions dpy; |
b8d880ba PM |
177 | static int num_serial_hds; |
178 | static Chardev **serial_hds; | |
0546c060 PB |
179 | static const char *log_mask; |
180 | static const char *log_file; | |
181 | static bool list_data_dirs; | |
4d2c17b0 | 182 | static const char *watchdog; |
eaf65114 TH |
183 | static const char *qtest_chrdev; |
184 | static const char *qtest_log; | |
1ca4d09a | 185 | |
d44229c5 | 186 | static int has_defaults = 1; |
998bbd74 | 187 | static int default_serial = 1; |
6a5e8b0e | 188 | static int default_parallel = 1; |
abdeed06 | 189 | static int default_monitor = 1; |
ac33f8fa GH |
190 | static int default_floppy = 1; |
191 | static int default_cdrom = 1; | |
192 | static int default_sdcard = 1; | |
7f1b17f2 | 193 | static int default_vga = 1; |
d30300f7 | 194 | static int default_net = 1; |
998bbd74 GH |
195 | |
196 | static struct { | |
197 | const char *driver; | |
198 | int *flag; | |
199 | } default_list[] = { | |
6a5e8b0e GH |
200 | { .driver = "isa-serial", .flag = &default_serial }, |
201 | { .driver = "isa-parallel", .flag = &default_parallel }, | |
d8bcbabf | 202 | { .driver = "isa-fdc", .flag = &default_floppy }, |
a92bd191 | 203 | { .driver = "floppy", .flag = &default_floppy }, |
af6bf132 MA |
204 | { .driver = "ide-cd", .flag = &default_cdrom }, |
205 | { .driver = "ide-hd", .flag = &default_cdrom }, | |
af6bf132 | 206 | { .driver = "scsi-cd", .flag = &default_cdrom }, |
f6f99b48 | 207 | { .driver = "scsi-hd", .flag = &default_cdrom }, |
7f1b17f2 PB |
208 | { .driver = "VGA", .flag = &default_vga }, |
209 | { .driver = "isa-vga", .flag = &default_vga }, | |
210 | { .driver = "cirrus-vga", .flag = &default_vga }, | |
211 | { .driver = "isa-cirrus-vga", .flag = &default_vga }, | |
212 | { .driver = "vmware-svga", .flag = &default_vga }, | |
213 | { .driver = "qxl-vga", .flag = &default_vga }, | |
a94f0c5c | 214 | { .driver = "virtio-vga", .flag = &default_vga }, |
862b4a29 | 215 | { .driver = "ati-vga", .flag = &default_vga }, |
267f6646 | 216 | { .driver = "vhost-user-vga", .flag = &default_vga }, |
f29d5261 | 217 | { .driver = "virtio-vga-gl", .flag = &default_vga }, |
998bbd74 GH |
218 | }; |
219 | ||
4d454574 PB |
220 | static QemuOptsList qemu_rtc_opts = { |
221 | .name = "rtc", | |
222 | .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head), | |
eb6a5209 | 223 | .merge_lists = true, |
4d454574 PB |
224 | .desc = { |
225 | { | |
226 | .name = "base", | |
227 | .type = QEMU_OPT_STRING, | |
228 | },{ | |
229 | .name = "clock", | |
230 | .type = QEMU_OPT_STRING, | |
231 | },{ | |
232 | .name = "driftfix", | |
233 | .type = QEMU_OPT_STRING, | |
234 | }, | |
235 | { /* end of list */ } | |
236 | }, | |
237 | }; | |
238 | ||
4d454574 PB |
239 | static QemuOptsList qemu_option_rom_opts = { |
240 | .name = "option-rom", | |
241 | .implied_opt_name = "romfile", | |
242 | .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head), | |
243 | .desc = { | |
244 | { | |
245 | .name = "bootindex", | |
246 | .type = QEMU_OPT_NUMBER, | |
247 | }, { | |
248 | .name = "romfile", | |
249 | .type = QEMU_OPT_STRING, | |
250 | }, | |
251 | { /* end of list */ } | |
252 | }, | |
253 | }; | |
254 | ||
8d4e9146 FK |
255 | static QemuOptsList qemu_accel_opts = { |
256 | .name = "accel", | |
257 | .implied_opt_name = "accel", | |
258 | .head = QTAILQ_HEAD_INITIALIZER(qemu_accel_opts.head), | |
8d4e9146 | 259 | .desc = { |
12ceaef6 PB |
260 | /* |
261 | * no elements => accept any | |
262 | * sanity checking will happen later | |
263 | * when setting accelerator properties | |
264 | */ | |
265 | { } | |
8d4e9146 FK |
266 | }, |
267 | }; | |
268 | ||
4d454574 PB |
269 | static QemuOptsList qemu_boot_opts = { |
270 | .name = "boot-opts", | |
6ef4716c MA |
271 | .implied_opt_name = "order", |
272 | .merge_lists = true, | |
4d454574 PB |
273 | .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head), |
274 | .desc = { | |
4d454574 PB |
275 | { |
276 | .name = "order", | |
277 | .type = QEMU_OPT_STRING, | |
278 | }, { | |
279 | .name = "once", | |
280 | .type = QEMU_OPT_STRING, | |
281 | }, { | |
282 | .name = "menu", | |
6ef4716c | 283 | .type = QEMU_OPT_BOOL, |
4d454574 PB |
284 | }, { |
285 | .name = "splash", | |
286 | .type = QEMU_OPT_STRING, | |
287 | }, { | |
288 | .name = "splash-time", | |
6912bb0b | 289 | .type = QEMU_OPT_NUMBER, |
4d454574 PB |
290 | }, { |
291 | .name = "reboot-timeout", | |
ee5d0f89 | 292 | .type = QEMU_OPT_NUMBER, |
c8a6ae8b AK |
293 | }, { |
294 | .name = "strict", | |
e5187b56 | 295 | .type = QEMU_OPT_BOOL, |
4d454574 PB |
296 | }, |
297 | { /*End of list */ } | |
298 | }, | |
299 | }; | |
300 | ||
301 | static QemuOptsList qemu_add_fd_opts = { | |
302 | .name = "add-fd", | |
303 | .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head), | |
304 | .desc = { | |
305 | { | |
306 | .name = "fd", | |
307 | .type = QEMU_OPT_NUMBER, | |
308 | .help = "file descriptor of which a duplicate is added to fd set", | |
309 | },{ | |
310 | .name = "set", | |
311 | .type = QEMU_OPT_NUMBER, | |
312 | .help = "ID of the fd set to add fd to", | |
313 | },{ | |
314 | .name = "opaque", | |
315 | .type = QEMU_OPT_STRING, | |
316 | .help = "free-form string used to describe fd", | |
317 | }, | |
318 | { /* end of list */ } | |
319 | }, | |
320 | }; | |
321 | ||
322 | static QemuOptsList qemu_object_opts = { | |
323 | .name = "object", | |
324 | .implied_opt_name = "qom-type", | |
325 | .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head), | |
326 | .desc = { | |
327 | { } | |
328 | }, | |
329 | }; | |
330 | ||
d1a0cf73 SB |
331 | static QemuOptsList qemu_tpmdev_opts = { |
332 | .name = "tpmdev", | |
333 | .implied_opt_name = "type", | |
334 | .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head), | |
335 | .desc = { | |
bb716238 | 336 | /* options are defined in the TPM backends */ |
d1a0cf73 SB |
337 | { /* end of list */ } |
338 | }, | |
339 | }; | |
340 | ||
6f131f13 MT |
341 | static QemuOptsList qemu_overcommit_opts = { |
342 | .name = "overcommit", | |
343 | .head = QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts.head), | |
344 | .desc = { | |
345 | { | |
346 | .name = "mem-lock", | |
347 | .type = QEMU_OPT_BOOL, | |
348 | }, | |
349 | { | |
350 | .name = "cpu-pm", | |
351 | .type = QEMU_OPT_BOOL, | |
352 | }, | |
353 | { /* end of list */ } | |
354 | }, | |
355 | }; | |
356 | ||
5e2ac519 SA |
357 | static QemuOptsList qemu_msg_opts = { |
358 | .name = "msg", | |
359 | .head = QTAILQ_HEAD_INITIALIZER(qemu_msg_opts.head), | |
360 | .desc = { | |
361 | { | |
362 | .name = "timestamp", | |
363 | .type = QEMU_OPT_BOOL, | |
364 | }, | |
2880ffb0 MS |
365 | { |
366 | .name = "guest-name", | |
367 | .type = QEMU_OPT_BOOL, | |
368 | .help = "Prepends guest name for error messages but only if " | |
369 | "-name guest is set otherwise option is ignored\n", | |
370 | }, | |
5e2ac519 SA |
371 | { /* end of list */ } |
372 | }, | |
373 | }; | |
374 | ||
5d12f961 DDAG |
375 | static QemuOptsList qemu_name_opts = { |
376 | .name = "name", | |
377 | .implied_opt_name = "guest", | |
378 | .merge_lists = true, | |
379 | .head = QTAILQ_HEAD_INITIALIZER(qemu_name_opts.head), | |
380 | .desc = { | |
381 | { | |
382 | .name = "guest", | |
383 | .type = QEMU_OPT_STRING, | |
384 | .help = "Sets the name of the guest.\n" | |
385 | "This name will be displayed in the SDL window caption.\n" | |
386 | "The name will also be used for the VNC server", | |
387 | }, { | |
388 | .name = "process", | |
389 | .type = QEMU_OPT_STRING, | |
390 | .help = "Sets the name of the QEMU process, as shown in top etc", | |
8f480de0 DDAG |
391 | }, { |
392 | .name = "debug-threads", | |
393 | .type = QEMU_OPT_BOOL, | |
394 | .help = "When enabled, name the individual threads; defaults off.\n" | |
395 | "NOTE: The thread names are for debugging and not a\n" | |
396 | "stable API.", | |
5d12f961 DDAG |
397 | }, |
398 | { /* End of list */ } | |
399 | }, | |
400 | }; | |
401 | ||
6e1d3c1c IM |
402 | static QemuOptsList qemu_mem_opts = { |
403 | .name = "memory", | |
404 | .implied_opt_name = "size", | |
405 | .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head), | |
406 | .merge_lists = true, | |
407 | .desc = { | |
408 | { | |
409 | .name = "size", | |
410 | .type = QEMU_OPT_SIZE, | |
411 | }, | |
c270fb9e IM |
412 | { |
413 | .name = "slots", | |
414 | .type = QEMU_OPT_NUMBER, | |
415 | }, | |
416 | { | |
417 | .name = "maxmem", | |
418 | .type = QEMU_OPT_SIZE, | |
419 | }, | |
6e1d3c1c IM |
420 | { /* end of list */ } |
421 | }, | |
422 | }; | |
423 | ||
1ad9580b ST |
424 | static QemuOptsList qemu_icount_opts = { |
425 | .name = "icount", | |
426 | .implied_opt_name = "shift", | |
427 | .merge_lists = true, | |
428 | .head = QTAILQ_HEAD_INITIALIZER(qemu_icount_opts.head), | |
429 | .desc = { | |
430 | { | |
431 | .name = "shift", | |
432 | .type = QEMU_OPT_STRING, | |
a8bfac37 ST |
433 | }, { |
434 | .name = "align", | |
435 | .type = QEMU_OPT_BOOL, | |
f1f4b57e VC |
436 | }, { |
437 | .name = "sleep", | |
438 | .type = QEMU_OPT_BOOL, | |
4c27b859 PD |
439 | }, { |
440 | .name = "rr", | |
441 | .type = QEMU_OPT_STRING, | |
442 | }, { | |
443 | .name = "rrfile", | |
444 | .type = QEMU_OPT_STRING, | |
9c2037d0 PD |
445 | }, { |
446 | .name = "rrsnapshot", | |
447 | .type = QEMU_OPT_STRING, | |
1ad9580b ST |
448 | }, |
449 | { /* end of list */ } | |
450 | }, | |
451 | }; | |
452 | ||
81b2b810 GS |
453 | static QemuOptsList qemu_fw_cfg_opts = { |
454 | .name = "fw_cfg", | |
455 | .implied_opt_name = "name", | |
456 | .head = QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts.head), | |
457 | .desc = { | |
458 | { | |
459 | .name = "name", | |
460 | .type = QEMU_OPT_STRING, | |
461 | .help = "Sets the fw_cfg name of the blob to be inserted", | |
462 | }, { | |
463 | .name = "file", | |
464 | .type = QEMU_OPT_STRING, | |
679be303 | 465 | .help = "Sets the name of the file from which " |
81b2b810 | 466 | "the fw_cfg blob will be loaded", |
6407d76e GS |
467 | }, { |
468 | .name = "string", | |
469 | .type = QEMU_OPT_STRING, | |
470 | .help = "Sets content of the blob to be inserted from a string", | |
6552d87c PMD |
471 | }, { |
472 | .name = "gen_id", | |
473 | .type = QEMU_OPT_STRING, | |
474 | .help = "Sets id of the object generating the fw_cfg blob " | |
475 | "to be inserted", | |
81b2b810 GS |
476 | }, |
477 | { /* end of list */ } | |
478 | }, | |
479 | }; | |
480 | ||
2a5ad60b AJ |
481 | static QemuOptsList qemu_action_opts = { |
482 | .name = "action", | |
483 | .merge_lists = true, | |
484 | .head = QTAILQ_HEAD_INITIALIZER(qemu_action_opts.head), | |
485 | .desc = { | |
486 | { | |
487 | .name = "shutdown", | |
488 | .type = QEMU_OPT_STRING, | |
489 | },{ | |
490 | .name = "reboot", | |
491 | .type = QEMU_OPT_STRING, | |
c753e8e7 AJ |
492 | },{ |
493 | .name = "panic", | |
494 | .type = QEMU_OPT_STRING, | |
2a5ad60b AJ |
495 | },{ |
496 | .name = "watchdog", | |
497 | .type = QEMU_OPT_STRING, | |
498 | }, | |
499 | { /* end of list */ } | |
500 | }, | |
501 | }; | |
502 | ||
31459f46 RS |
503 | const char *qemu_get_vm_name(void) |
504 | { | |
505 | return qemu_name; | |
506 | } | |
507 | ||
5dacda51 | 508 | static void default_driver_disable(const char *driver) |
998bbd74 | 509 | { |
998bbd74 GH |
510 | int i; |
511 | ||
5dacda51 KW |
512 | if (!driver) { |
513 | return; | |
514 | } | |
515 | ||
998bbd74 GH |
516 | for (i = 0; i < ARRAY_SIZE(default_list); i++) { |
517 | if (strcmp(default_list[i].driver, driver) != 0) | |
518 | continue; | |
519 | *(default_list[i].flag) = 0; | |
520 | } | |
5dacda51 KW |
521 | } |
522 | ||
523 | static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp) | |
524 | { | |
525 | const char *driver = qemu_opt_get(opts, "driver"); | |
526 | ||
527 | default_driver_disable(driver); | |
998bbd74 GH |
528 | return 0; |
529 | } | |
530 | ||
5dacda51 KW |
531 | static void default_driver_check_json(void) |
532 | { | |
533 | DeviceOption *opt; | |
534 | ||
535 | QTAILQ_FOREACH(opt, &device_opts, next) { | |
536 | const char *driver = qdict_get_try_str(opt->opts, "driver"); | |
537 | default_driver_disable(driver); | |
538 | } | |
539 | } | |
540 | ||
28d0de7a | 541 | static int parse_name(void *opaque, QemuOpts *opts, Error **errp) |
5d12f961 DDAG |
542 | { |
543 | const char *proc_name; | |
544 | ||
8f480de0 DDAG |
545 | if (qemu_opt_get(opts, "debug-threads")) { |
546 | qemu_thread_naming(qemu_opt_get_bool(opts, "debug-threads", false)); | |
547 | } | |
5d12f961 DDAG |
548 | qemu_name = qemu_opt_get(opts, "guest"); |
549 | ||
550 | proc_name = qemu_opt_get(opts, "process"); | |
551 | if (proc_name) { | |
552 | os_set_proc_name(proc_name); | |
553 | } | |
5b9d313e DDAG |
554 | |
555 | return 0; | |
5d12f961 DDAG |
556 | } |
557 | ||
f8b6f8ed MA |
558 | bool defaults_enabled(void) |
559 | { | |
560 | return has_defaults; | |
561 | } | |
562 | ||
587ed6be | 563 | #ifndef _WIN32 |
28d0de7a | 564 | static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp) |
587ed6be CB |
565 | { |
566 | int fd, dupfd, flags; | |
567 | int64_t fdset_id; | |
568 | const char *fd_opaque = NULL; | |
636a30a8 | 569 | AddfdInfo *fdinfo; |
587ed6be CB |
570 | |
571 | fd = qemu_opt_get_number(opts, "fd", -1); | |
572 | fdset_id = qemu_opt_get_number(opts, "set", -1); | |
573 | fd_opaque = qemu_opt_get(opts, "opaque"); | |
574 | ||
575 | if (fd < 0) { | |
6353218b | 576 | error_setg(errp, "fd option is required and must be non-negative"); |
587ed6be CB |
577 | return -1; |
578 | } | |
579 | ||
580 | if (fd <= STDERR_FILENO) { | |
6353218b | 581 | error_setg(errp, "fd cannot be a standard I/O stream"); |
587ed6be CB |
582 | return -1; |
583 | } | |
584 | ||
585 | /* | |
586 | * All fds inherited across exec() necessarily have FD_CLOEXEC | |
587 | * clear, while qemu sets FD_CLOEXEC on all other fds used internally. | |
588 | */ | |
589 | flags = fcntl(fd, F_GETFD); | |
590 | if (flags == -1 || (flags & FD_CLOEXEC)) { | |
6353218b | 591 | error_setg(errp, "fd is not valid or already in use"); |
587ed6be CB |
592 | return -1; |
593 | } | |
594 | ||
595 | if (fdset_id < 0) { | |
6353218b | 596 | error_setg(errp, "set option is required and must be non-negative"); |
587ed6be CB |
597 | return -1; |
598 | } | |
599 | ||
600 | #ifdef F_DUPFD_CLOEXEC | |
601 | dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0); | |
602 | #else | |
603 | dupfd = dup(fd); | |
604 | if (dupfd != -1) { | |
605 | qemu_set_cloexec(dupfd); | |
606 | } | |
607 | #endif | |
608 | if (dupfd == -1) { | |
6353218b | 609 | error_setg(errp, "error duplicating fd: %s", strerror(errno)); |
587ed6be CB |
610 | return -1; |
611 | } | |
612 | ||
613 | /* add the duplicate fd, and optionally the opaque string, to the fd set */ | |
636a30a8 PB |
614 | fdinfo = monitor_fdset_add_fd(dupfd, true, fdset_id, !!fd_opaque, fd_opaque, |
615 | &error_abort); | |
616 | g_free(fdinfo); | |
587ed6be CB |
617 | |
618 | return 0; | |
619 | } | |
620 | ||
28d0de7a | 621 | static int cleanup_add_fd(void *opaque, QemuOpts *opts, Error **errp) |
587ed6be CB |
622 | { |
623 | int fd; | |
624 | ||
625 | fd = qemu_opt_get_number(opts, "fd", -1); | |
626 | close(fd); | |
627 | ||
628 | return 0; | |
629 | } | |
630 | #endif | |
631 | ||
1ae26a18 AZ |
632 | /***********************************************************/ |
633 | /* QEMU Block devices */ | |
634 | ||
2292ddae MA |
635 | #define HD_OPTS "media=disk" |
636 | #define CDROM_OPTS "media=cdrom" | |
637 | #define FD_OPTS "" | |
638 | #define PFLASH_OPTS "" | |
639 | #define MTD_OPTS "" | |
640 | #define SD_OPTS "" | |
e4bcb14c | 641 | |
28d0de7a | 642 | static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp) |
9dfd7c7a | 643 | { |
2d0d2837 | 644 | BlockInterfaceType *block_default_type = opaque; |
9dfd7c7a | 645 | |
c4f26c9f | 646 | return drive_new(opts, *block_default_type, errp) == NULL; |
9dfd7c7a GH |
647 | } |
648 | ||
28d0de7a | 649 | static int drive_enable_snapshot(void *opaque, QemuOpts *opts, Error **errp) |
9dfd7c7a | 650 | { |
28de2f88 | 651 | if (qemu_opt_get(opts, "snapshot") == NULL) { |
f43e47db | 652 | qemu_opt_set(opts, "snapshot", "on", &error_abort); |
9dfd7c7a GH |
653 | } |
654 | return 0; | |
655 | } | |
656 | ||
3c42ea66 CB |
657 | static void default_drive(int enable, int snapshot, BlockInterfaceType type, |
658 | int index, const char *optstr) | |
4e5d9b57 MA |
659 | { |
660 | QemuOpts *opts; | |
a66c9dc7 | 661 | DriveInfo *dinfo; |
4e5d9b57 | 662 | |
4e5d9b57 MA |
663 | if (!enable || drive_get_by_index(type, index)) { |
664 | return; | |
665 | } | |
666 | ||
667 | opts = drive_add(type, index, NULL, optstr); | |
668 | if (snapshot) { | |
28d0de7a | 669 | drive_enable_snapshot(NULL, opts, NULL); |
4e5d9b57 | 670 | } |
a66c9dc7 | 671 | |
c4f26c9f | 672 | dinfo = drive_new(opts, type, &error_abort); |
a66c9dc7 JS |
673 | dinfo->is_default = true; |
674 | ||
4e5d9b57 MA |
675 | } |
676 | ||
d11bf9bf MA |
677 | static void configure_blockdev(BlockdevOptionsQueue *bdo_queue, |
678 | MachineClass *machine_class, int snapshot) | |
679 | { | |
680 | /* | |
681 | * If the currently selected machine wishes to override the | |
682 | * units-per-bus property of its default HBA interface type, do so | |
683 | * now. | |
684 | */ | |
685 | if (machine_class->units_per_default_bus) { | |
686 | override_max_devs(machine_class->block_default_type, | |
687 | machine_class->units_per_default_bus); | |
688 | } | |
689 | ||
690 | /* open the virtual block devices */ | |
691 | while (!QSIMPLEQ_EMPTY(bdo_queue)) { | |
692 | BlockdevOptionsQueueEntry *bdo = QSIMPLEQ_FIRST(bdo_queue); | |
693 | ||
694 | QSIMPLEQ_REMOVE_HEAD(bdo_queue, entry); | |
695 | loc_push_restore(&bdo->loc); | |
696 | qmp_blockdev_add(bdo->bdo, &error_fatal); | |
697 | loc_pop(&bdo->loc); | |
698 | qapi_free_BlockdevOptions(bdo->bdo); | |
699 | g_free(bdo); | |
700 | } | |
25863975 | 701 | if (snapshot) { |
d11bf9bf MA |
702 | qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, |
703 | NULL, NULL); | |
704 | } | |
705 | if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, | |
706 | &machine_class->block_default_type, &error_fatal)) { | |
707 | /* We printed help */ | |
708 | exit(0); | |
709 | } | |
710 | ||
711 | default_drive(default_cdrom, snapshot, machine_class->block_default_type, 2, | |
712 | CDROM_OPTS); | |
713 | default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS); | |
714 | default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS); | |
715 | ||
716 | } | |
717 | ||
12b7f57e MT |
718 | static QemuOptsList qemu_smp_opts = { |
719 | .name = "smp-opts", | |
720 | .implied_opt_name = "cpus", | |
721 | .merge_lists = true, | |
722 | .head = QTAILQ_HEAD_INITIALIZER(qemu_smp_opts.head), | |
723 | .desc = { | |
724 | { | |
725 | .name = "cpus", | |
726 | .type = QEMU_OPT_NUMBER, | |
727 | }, { | |
728 | .name = "sockets", | |
729 | .type = QEMU_OPT_NUMBER, | |
1b458422 LX |
730 | }, { |
731 | .name = "dies", | |
732 | .type = QEMU_OPT_NUMBER, | |
864c3b5c YW |
733 | }, { |
734 | .name = "clusters", | |
735 | .type = QEMU_OPT_NUMBER, | |
12b7f57e MT |
736 | }, { |
737 | .name = "cores", | |
738 | .type = QEMU_OPT_NUMBER, | |
739 | }, { | |
740 | .name = "threads", | |
741 | .type = QEMU_OPT_NUMBER, | |
742 | }, { | |
743 | .name = "maxcpus", | |
744 | .type = QEMU_OPT_NUMBER, | |
745 | }, | |
746 | { /*End of list */ } | |
747 | }, | |
748 | }; | |
749 | ||
28d16f38 | 750 | static void realtime_init(void) |
888a6bc6 | 751 | { |
888a6bc6 SM |
752 | if (enable_mlock) { |
753 | if (os_mlock() < 0) { | |
f61eddcb | 754 | error_report("locking memory failed"); |
888a6bc6 SM |
755 | exit(1); |
756 | } | |
757 | } | |
758 | } | |
759 | ||
5e2ac519 SA |
760 | |
761 | static void configure_msg(QemuOpts *opts) | |
762 | { | |
651d588f | 763 | message_with_timestamp = qemu_opt_get_bool(opts, "timestamp", false); |
2880ffb0 | 764 | error_with_guestname = qemu_opt_get_bool(opts, "guest-name", false); |
5e2ac519 SA |
765 | } |
766 | ||
a59d31a1 | 767 | |
a594cfbf FB |
768 | /***********************************************************/ |
769 | /* USB devices */ | |
770 | ||
fb08000c | 771 | static int usb_device_add(const char *devname) |
a594cfbf | 772 | { |
a5d2f727 | 773 | USBDevice *dev = NULL; |
a594cfbf | 774 | |
4bcbe0b6 | 775 | if (!machine_usb(current_machine)) { |
a594cfbf | 776 | return -1; |
094b287f | 777 | } |
a594cfbf | 778 | |
0958b4cc | 779 | dev = usbdevice_create(devname); |
0d92ed30 PB |
780 | if (!dev) |
781 | return -1; | |
782 | ||
a594cfbf FB |
783 | return 0; |
784 | } | |
785 | ||
bd3c948d GH |
786 | static int usb_parse(const char *cmdline) |
787 | { | |
59d1c1c2 | 788 | int r; |
fb08000c | 789 | r = usb_device_add(cmdline); |
59d1c1c2 | 790 | if (r < 0) { |
f61eddcb | 791 | error_report("could not add USB device '%s'", cmdline); |
59d1c1c2 ST |
792 | } |
793 | return r; | |
bd3c948d GH |
794 | } |
795 | ||
cc1daa40 FB |
796 | /***********************************************************/ |
797 | /* machine registration */ | |
798 | ||
c516cd1b | 799 | static MachineClass *find_machine(const char *name, GSList *machines) |
cc1daa40 | 800 | { |
c516cd1b | 801 | GSList *el; |
cc1daa40 | 802 | |
261747f1 | 803 | for (el = machines; el; el = el->next) { |
f2c93021 | 804 | MachineClass *mc = el->data; |
261747f1 | 805 | |
f2c93021 MA |
806 | if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) { |
807 | return mc; | |
261747f1 | 808 | } |
cc1daa40 | 809 | } |
261747f1 | 810 | |
f2c93021 | 811 | return NULL; |
cc1daa40 FB |
812 | } |
813 | ||
c516cd1b | 814 | static MachineClass *find_default_machine(GSList *machines) |
0c257437 | 815 | { |
c516cd1b | 816 | GSList *el; |
6db1857e | 817 | MachineClass *default_machineclass = NULL; |
0c257437 | 818 | |
261747f1 | 819 | for (el = machines; el; el = el->next) { |
f2c93021 | 820 | MachineClass *mc = el->data; |
261747f1 | 821 | |
f2c93021 | 822 | if (mc->is_default) { |
6db1857e PMD |
823 | assert(default_machineclass == NULL && "Multiple default machines"); |
824 | default_machineclass = mc; | |
0c257437 AL |
825 | } |
826 | } | |
261747f1 | 827 | |
6db1857e | 828 | return default_machineclass; |
0c257437 AL |
829 | } |
830 | ||
9bd7e6d9 PB |
831 | static void version(void) |
832 | { | |
7e563bfb | 833 | printf("QEMU emulator version " QEMU_FULL_VERSION "\n" |
d915b7bb | 834 | QEMU_COPYRIGHT "\n"); |
9bd7e6d9 PB |
835 | } |
836 | ||
15f82208 | 837 | static void help(int exitcode) |
0824d6fc | 838 | { |
a3adb7ad ME |
839 | version(); |
840 | printf("usage: %s [options] [disk_image]\n\n" | |
841 | "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n", | |
336d354b | 842 | g_get_prgname()); |
a3adb7ad | 843 | |
fd5fc4b1 PB |
844 | #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \ |
845 | if ((arch_mask) & arch_type) \ | |
846 | fputs(opt_help, stdout); | |
847 | ||
848 | #define ARCHHEADING(text, arch_mask) \ | |
849 | if ((arch_mask) & arch_type) \ | |
850 | puts(stringify(text)); | |
851 | ||
852 | #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL) | |
853 | ||
854 | #include "qemu-options.def" | |
a3adb7ad ME |
855 | |
856 | printf("\nDuring emulation, the following keys are useful:\n" | |
3f020d70 | 857 | "ctrl-alt-f toggle full screen\n" |
858 | "ctrl-alt-n switch to virtual console 'n'\n" | |
859 | "ctrl-alt toggle mouse and keyboard grab\n" | |
860 | "\n" | |
f5048cb7 EB |
861 | "When using -nographic, press 'ctrl-a h' to get some help.\n" |
862 | "\n" | |
863 | QEMU_HELP_BOTTOM "\n"); | |
a3adb7ad | 864 | |
15f82208 | 865 | exit(exitcode); |
0824d6fc FB |
866 | } |
867 | ||
cd6f1169 FB |
868 | #define HAS_ARG 0x0001 |
869 | ||
cd6f1169 FB |
870 | typedef struct QEMUOption { |
871 | const char *name; | |
872 | int flags; | |
873 | int index; | |
ad96090a | 874 | uint32_t arch_mask; |
cd6f1169 FB |
875 | } QEMUOption; |
876 | ||
dbed7e40 | 877 | static const QEMUOption qemu_options[] = { |
ad96090a | 878 | { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL }, |
fd5fc4b1 PB |
879 | |
880 | #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \ | |
881 | { option, opt_arg, opt_enum, arch_mask }, | |
882 | #define DEFHEADING(text) | |
883 | #define ARCHHEADING(text, arch_mask) | |
884 | ||
885 | #include "qemu-options.def" | |
cd6f1169 | 886 | { NULL }, |
fc01f7e7 | 887 | }; |
a369da5f | 888 | |
8c9a2b71 EH |
889 | typedef struct VGAInterfaceInfo { |
890 | const char *opt_name; /* option name */ | |
891 | const char *name; /* human-readable name */ | |
c2c7b22d EH |
892 | /* Class names indicating that support is available. |
893 | * If no class is specified, the interface is always available */ | |
894 | const char *class_names[2]; | |
8c9a2b71 EH |
895 | } VGAInterfaceInfo; |
896 | ||
53b93511 | 897 | static const VGAInterfaceInfo vga_interfaces[VGA_TYPE_MAX] = { |
8c9a2b71 EH |
898 | [VGA_NONE] = { |
899 | .opt_name = "none", | |
d2fa65cd | 900 | .name = "no graphic card", |
8c9a2b71 EH |
901 | }, |
902 | [VGA_STD] = { | |
903 | .opt_name = "std", | |
904 | .name = "standard VGA", | |
c2c7b22d | 905 | .class_names = { "VGA", "isa-vga" }, |
8c9a2b71 EH |
906 | }, |
907 | [VGA_CIRRUS] = { | |
908 | .opt_name = "cirrus", | |
909 | .name = "Cirrus VGA", | |
c2c7b22d | 910 | .class_names = { "cirrus-vga", "isa-cirrus-vga" }, |
8c9a2b71 EH |
911 | }, |
912 | [VGA_VMWARE] = { | |
913 | .opt_name = "vmware", | |
914 | .name = "VMWare SVGA", | |
c2c7b22d | 915 | .class_names = { "vmware-svga" }, |
8c9a2b71 EH |
916 | }, |
917 | [VGA_VIRTIO] = { | |
918 | .opt_name = "virtio", | |
919 | .name = "Virtio VGA", | |
c2c7b22d | 920 | .class_names = { "virtio-vga" }, |
8c9a2b71 EH |
921 | }, |
922 | [VGA_QXL] = { | |
923 | .opt_name = "qxl", | |
924 | .name = "QXL VGA", | |
c2c7b22d | 925 | .class_names = { "qxl-vga" }, |
8c9a2b71 EH |
926 | }, |
927 | [VGA_TCX] = { | |
928 | .opt_name = "tcx", | |
929 | .name = "TCX framebuffer", | |
e178113f | 930 | .class_names = { "sun-tcx" }, |
8c9a2b71 EH |
931 | }, |
932 | [VGA_CG3] = { | |
933 | .opt_name = "cg3", | |
934 | .name = "CG3 framebuffer", | |
c2c7b22d | 935 | .class_names = { "cgthree" }, |
8c9a2b71 | 936 | }, |
f07b3a83 | 937 | #ifdef CONFIG_XEN_BACKEND |
8c9a2b71 EH |
938 | [VGA_XENFB] = { |
939 | .opt_name = "xenfb", | |
d2fa65cd | 940 | .name = "Xen paravirtualized framebuffer", |
8c9a2b71 | 941 | }, |
f07b3a83 | 942 | #endif |
8c9a2b71 EH |
943 | }; |
944 | ||
c2c7b22d EH |
945 | static bool vga_interface_available(VGAInterfaceType t) |
946 | { | |
53b93511 | 947 | const VGAInterfaceInfo *ti = &vga_interfaces[t]; |
c2c7b22d EH |
948 | |
949 | assert(t < VGA_TYPE_MAX); | |
950 | return !ti->class_names[0] || | |
7ab6e7fc GH |
951 | module_object_class_by_name(ti->class_names[0]) || |
952 | module_object_class_by_name(ti->class_names[1]); | |
c2c7b22d EH |
953 | } |
954 | ||
dceb8852 MAL |
955 | static const char * |
956 | get_default_vga_model(const MachineClass *machine_class) | |
957 | { | |
958 | if (machine_class->default_display) { | |
959 | return machine_class->default_display; | |
960 | } else if (vga_interface_available(VGA_CIRRUS)) { | |
961 | return "cirrus"; | |
962 | } else if (vga_interface_available(VGA_STD)) { | |
963 | return "std"; | |
964 | } | |
965 | ||
966 | return NULL; | |
967 | } | |
968 | ||
969 | static void select_vgahw(const MachineClass *machine_class, const char *p) | |
3893c124 | 970 | { |
971 | const char *opts; | |
8c9a2b71 | 972 | int t; |
3893c124 | 973 | |
dceb8852 MAL |
974 | if (g_str_equal(p, "help")) { |
975 | const char *def = get_default_vga_model(machine_class); | |
976 | ||
977 | for (t = 0; t < VGA_TYPE_MAX; t++) { | |
978 | const VGAInterfaceInfo *ti = &vga_interfaces[t]; | |
979 | ||
980 | if (vga_interface_available(t) && ti->opt_name) { | |
981 | printf("%-20s %s%s\n", ti->opt_name, ti->name ?: "", | |
982 | g_str_equal(ti->opt_name, def) ? " (default)" : ""); | |
983 | } | |
984 | } | |
985 | exit(0); | |
986 | } | |
987 | ||
d44229c5 | 988 | assert(vga_interface_type == VGA_NONE); |
8c9a2b71 | 989 | for (t = 0; t < VGA_TYPE_MAX; t++) { |
53b93511 | 990 | const VGAInterfaceInfo *ti = &vga_interfaces[t]; |
8c9a2b71 | 991 | if (ti->opt_name && strstart(p, ti->opt_name, &opts)) { |
c2c7b22d | 992 | if (!vga_interface_available(t)) { |
8c9a2b71 EH |
993 | error_report("%s not available", ti->name); |
994 | exit(1); | |
995 | } | |
996 | vga_interface_type = t; | |
997 | break; | |
af87bf29 | 998 | } |
8c9a2b71 EH |
999 | } |
1000 | if (t == VGA_TYPE_MAX) { | |
3893c124 | 1001 | invalid_vga: |
3e515373 | 1002 | error_report("unknown vga type: %s", p); |
3893c124 | 1003 | exit(1); |
1004 | } | |
cb5a7aa8 | 1005 | while (*opts) { |
1006 | const char *nextopt; | |
1007 | ||
1008 | if (strstart(opts, ",retrace=", &nextopt)) { | |
1009 | opts = nextopt; | |
1010 | if (strstart(opts, "dumb", &nextopt)) | |
1011 | vga_retrace_method = VGA_RETRACE_DUMB; | |
1012 | else if (strstart(opts, "precise", &nextopt)) | |
1013 | vga_retrace_method = VGA_RETRACE_PRECISE; | |
1014 | else goto invalid_vga; | |
1015 | } else goto invalid_vga; | |
1016 | opts = nextopt; | |
1017 | } | |
3893c124 | 1018 | } |
1019 | ||
776d1344 GH |
1020 | static void parse_display_qapi(const char *optarg) |
1021 | { | |
776d1344 GH |
1022 | DisplayOptions *opts; |
1023 | Visitor *v; | |
1024 | ||
50beeb68 | 1025 | v = qobject_input_visitor_new_str(optarg, "type", &error_fatal); |
776d1344 GH |
1026 | |
1027 | visit_type_DisplayOptions(v, NULL, &opts, &error_fatal); | |
1028 | QAPI_CLONE_MEMBERS(DisplayOptions, &dpy, opts); | |
1029 | ||
1030 | qapi_free_DisplayOptions(opts); | |
1031 | visit_free(v); | |
1032 | } | |
1033 | ||
e1ca8f7e GH |
1034 | DisplayOptions *qmp_query_display_options(Error **errp) |
1035 | { | |
1036 | return QAPI_CLONE(DisplayOptions, &dpy); | |
1037 | } | |
1038 | ||
e3af9f9a | 1039 | static void parse_display(const char *p) |
1472a95b JS |
1040 | { |
1041 | const char *opts; | |
1472a95b | 1042 | |
c388f408 TH |
1043 | if (is_help_option(p)) { |
1044 | qemu_display_help(); | |
1045 | exit(0); | |
1046 | } | |
1047 | ||
1472a95b | 1048 | if (strstart(p, "sdl", &opts)) { |
7a61f438 GH |
1049 | /* |
1050 | * sdl DisplayType needs hand-crafted parser instead of | |
1051 | * parse_display_qapi() due to some options not in | |
1052 | * DisplayOptions, specifically: | |
7a61f438 | 1053 | * - ctrl_grab + alt_grab |
8e8e844b TH |
1054 | * They can't be moved into the QAPI since they use underscores, |
1055 | * thus they will get replaced by "grab-mod" in the long term | |
7a61f438 | 1056 | */ |
66c2207f | 1057 | #if defined(CONFIG_SDL) |
fe91f36a | 1058 | dpy.type = DISPLAY_TYPE_SDL; |
1472a95b JS |
1059 | while (*opts) { |
1060 | const char *nextopt; | |
1061 | ||
8e8e844b TH |
1062 | if (strstart(opts, ",grab-mod=", &nextopt)) { |
1063 | opts = nextopt; | |
1064 | if (strstart(opts, "lshift-lctrl-lalt", &nextopt)) { | |
1065 | alt_grab = 1; | |
1066 | } else if (strstart(opts, "rctrl", &nextopt)) { | |
1067 | ctrl_grab = 1; | |
1068 | } else { | |
1069 | goto invalid_sdl_args; | |
1070 | } | |
1071 | } else if (strstart(opts, ",alt_grab=", &nextopt)) { | |
1472a95b JS |
1072 | opts = nextopt; |
1073 | if (strstart(opts, "on", &nextopt)) { | |
1074 | alt_grab = 1; | |
1075 | } else if (strstart(opts, "off", &nextopt)) { | |
1076 | alt_grab = 0; | |
1077 | } else { | |
05175535 | 1078 | goto invalid_sdl_args; |
1472a95b | 1079 | } |
d46156fd | 1080 | warn_report("alt_grab is deprecated, use grab-mod instead."); |
1472a95b JS |
1081 | } else if (strstart(opts, ",ctrl_grab=", &nextopt)) { |
1082 | opts = nextopt; | |
1083 | if (strstart(opts, "on", &nextopt)) { | |
1084 | ctrl_grab = 1; | |
1085 | } else if (strstart(opts, "off", &nextopt)) { | |
1086 | ctrl_grab = 0; | |
1087 | } else { | |
05175535 | 1088 | goto invalid_sdl_args; |
1472a95b | 1089 | } |
d46156fd | 1090 | warn_report("ctrl_grab is deprecated, use grab-mod instead."); |
bb20b86d TH |
1091 | } else if (strstart(opts, ",window_close=", &nextopt) || |
1092 | strstart(opts, ",window-close=", &nextopt)) { | |
1093 | if (strstart(opts, ",window_close=", NULL)) { | |
1094 | warn_report("window_close with an underscore is deprecated," | |
1095 | " please use window-close instead."); | |
1096 | } | |
1472a95b | 1097 | opts = nextopt; |
fe91f36a | 1098 | dpy.has_window_close = true; |
1472a95b | 1099 | if (strstart(opts, "on", &nextopt)) { |
fe91f36a | 1100 | dpy.window_close = true; |
1472a95b | 1101 | } else if (strstart(opts, "off", &nextopt)) { |
fe91f36a | 1102 | dpy.window_close = false; |
1472a95b | 1103 | } else { |
05175535 | 1104 | goto invalid_sdl_args; |
1472a95b | 1105 | } |
86a088e6 GH |
1106 | } else if (strstart(opts, ",show-cursor=", &nextopt)) { |
1107 | opts = nextopt; | |
1108 | dpy.has_show_cursor = true; | |
1109 | if (strstart(opts, "on", &nextopt)) { | |
1110 | dpy.show_cursor = true; | |
1111 | } else if (strstart(opts, "off", &nextopt)) { | |
1112 | dpy.show_cursor = false; | |
1113 | } else { | |
1114 | goto invalid_sdl_args; | |
1115 | } | |
0b71a5d5 GH |
1116 | } else if (strstart(opts, ",gl=", &nextopt)) { |
1117 | opts = nextopt; | |
fe91f36a | 1118 | dpy.has_gl = true; |
0b71a5d5 | 1119 | if (strstart(opts, "on", &nextopt)) { |
62f27922 | 1120 | dpy.gl = DISPLAYGL_MODE_ON; |
4867e47c ET |
1121 | } else if (strstart(opts, "core", &nextopt)) { |
1122 | dpy.gl = DISPLAYGL_MODE_CORE; | |
1123 | } else if (strstart(opts, "es", &nextopt)) { | |
1124 | dpy.gl = DISPLAYGL_MODE_ES; | |
0b71a5d5 | 1125 | } else if (strstart(opts, "off", &nextopt)) { |
62f27922 | 1126 | dpy.gl = DISPLAYGL_MODE_OFF; |
0b71a5d5 GH |
1127 | } else { |
1128 | goto invalid_sdl_args; | |
1129 | } | |
1472a95b | 1130 | } else { |
05175535 | 1131 | invalid_sdl_args: |
3e515373 | 1132 | error_report("invalid SDL option string"); |
05175535 | 1133 | exit(1); |
1472a95b JS |
1134 | } |
1135 | opts = nextopt; | |
1136 | } | |
66c2207f TH |
1137 | #else |
1138 | error_report("SDL display supported is not available in this binary"); | |
1139 | exit(1); | |
1140 | #endif | |
3264ff12 | 1141 | } else if (strstart(p, "vnc", &opts)) { |
7a61f438 GH |
1142 | /* |
1143 | * vnc isn't a (local) DisplayType but a protocol for remote | |
1144 | * display access. | |
1145 | */ | |
4db14629 | 1146 | if (*opts == '=') { |
653c9747 | 1147 | vnc_parse(opts + 1); |
4db14629 | 1148 | } else { |
c6bf0f7f | 1149 | error_report("VNC requires a display argument vnc=<display>"); |
3264ff12 JS |
1150 | exit(1); |
1151 | } | |
1472a95b | 1152 | } else { |
776d1344 | 1153 | parse_display_qapi(p); |
1472a95b | 1154 | } |
1472a95b JS |
1155 | } |
1156 | ||
6407d76e GS |
1157 | static inline bool nonempty_str(const char *str) |
1158 | { | |
1159 | return str && *str; | |
1160 | } | |
1161 | ||
81b2b810 GS |
1162 | static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp) |
1163 | { | |
1164 | gchar *buf; | |
1165 | size_t size; | |
6552d87c | 1166 | const char *name, *file, *str, *gen_id; |
bab47d9a | 1167 | FWCfgState *fw_cfg = (FWCfgState *) opaque; |
81b2b810 | 1168 | |
bab47d9a | 1169 | if (fw_cfg == NULL) { |
406b6367 | 1170 | error_setg(errp, "fw_cfg device not available"); |
81b2b810 GS |
1171 | return -1; |
1172 | } | |
1173 | name = qemu_opt_get(opts, "name"); | |
1174 | file = qemu_opt_get(opts, "file"); | |
6407d76e | 1175 | str = qemu_opt_get(opts, "string"); |
6552d87c | 1176 | gen_id = qemu_opt_get(opts, "gen_id"); |
6407d76e | 1177 | |
6552d87c PMD |
1178 | /* we need the name, and exactly one of: file, content string, gen_id */ |
1179 | if (!nonempty_str(name) || | |
1180 | nonempty_str(file) + nonempty_str(str) + nonempty_str(gen_id) != 1) { | |
1181 | error_setg(errp, "name, plus exactly one of file," | |
1182 | " string and gen_id, are needed"); | |
81b2b810 GS |
1183 | return -1; |
1184 | } | |
1185 | if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) { | |
406b6367 MA |
1186 | error_setg(errp, "name too long (max. %d char)", |
1187 | FW_CFG_MAX_FILE_PATH - 1); | |
81b2b810 GS |
1188 | return -1; |
1189 | } | |
f7d8afb1 PMD |
1190 | if (nonempty_str(gen_id)) { |
1191 | /* | |
1192 | * In this particular case where the content is populated | |
1193 | * internally, the "etc/" namespace protection is relaxed, | |
1194 | * so do not emit a warning. | |
1195 | */ | |
1196 | } else if (strncmp(name, "opt/", 4) != 0) { | |
3dc6f869 AF |
1197 | warn_report("externally provided fw_cfg item names " |
1198 | "should be prefixed with \"opt/\""); | |
81b2b810 | 1199 | } |
6407d76e GS |
1200 | if (nonempty_str(str)) { |
1201 | size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */ | |
1202 | buf = g_memdup(str, size); | |
6552d87c | 1203 | } else if (nonempty_str(gen_id)) { |
07719518 | 1204 | if (!fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp)) { |
6552d87c PMD |
1205 | return -1; |
1206 | } | |
1207 | return 0; | |
6407d76e | 1208 | } else { |
353c7d58 LQ |
1209 | GError *err = NULL; |
1210 | if (!g_file_get_contents(file, &buf, &size, &err)) { | |
1211 | error_setg(errp, "can't load %s: %s", file, err->message); | |
1212 | g_error_free(err); | |
6407d76e GS |
1213 | return -1; |
1214 | } | |
81b2b810 | 1215 | } |
bab47d9a GH |
1216 | /* For legacy, keep user files in a specific global order. */ |
1217 | fw_cfg_set_order_override(fw_cfg, FW_CFG_ORDER_OVERRIDE_USER); | |
1218 | fw_cfg_add_file(fw_cfg, name, buf, size); | |
1219 | fw_cfg_reset_order_override(fw_cfg); | |
81b2b810 GS |
1220 | return 0; |
1221 | } | |
1222 | ||
28d0de7a | 1223 | static int device_help_func(void *opaque, QemuOpts *opts, Error **errp) |
ff952ba2 MA |
1224 | { |
1225 | return qdev_device_help(opts); | |
1226 | } | |
1227 | ||
28d0de7a | 1228 | static int device_init_func(void *opaque, QemuOpts *opts, Error **errp) |
f31d07d1 GH |
1229 | { |
1230 | DeviceState *dev; | |
1231 | ||
cd65f349 | 1232 | dev = qdev_device_add(opts, errp); |
f3a85056 JF |
1233 | if (!dev && *errp) { |
1234 | error_report_err(*errp); | |
f31d07d1 | 1235 | return -1; |
f3a85056 JF |
1236 | } else if (dev) { |
1237 | object_unref(OBJECT(dev)); | |
f006cf7f | 1238 | } |
f31d07d1 GH |
1239 | return 0; |
1240 | } | |
1241 | ||
28d0de7a | 1242 | static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) |
1a688d3b | 1243 | { |
bd2d80b2 | 1244 | Error *local_err = NULL; |
1a688d3b | 1245 | |
4ad6f6cb | 1246 | if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) { |
0ec846bf | 1247 | if (local_err) { |
dd4af977 | 1248 | error_propagate(errp, local_err); |
0ec846bf AN |
1249 | return -1; |
1250 | } | |
1251 | exit(0); | |
bd2d80b2 | 1252 | } |
1a688d3b GH |
1253 | return 0; |
1254 | } | |
1255 | ||
758e8e38 | 1256 | #ifdef CONFIG_VIRTFS |
28d0de7a | 1257 | static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp) |
74db920c | 1258 | { |
b836723d | 1259 | return qemu_fsdev_add(opts, errp); |
74db920c GS |
1260 | } |
1261 | #endif | |
1262 | ||
28d0de7a | 1263 | static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) |
88589343 | 1264 | { |
c3e95551 | 1265 | return monitor_init_opts(opts, errp); |
88589343 GH |
1266 | } |
1267 | ||
4821cd4c | 1268 | static void monitor_parse(const char *optarg, const char *mode, bool pretty) |
88589343 GH |
1269 | { |
1270 | static int monitor_device_index = 0; | |
1271 | QemuOpts *opts; | |
1272 | const char *p; | |
1273 | char label[32]; | |
88589343 GH |
1274 | |
1275 | if (strstart(optarg, "chardev:", &p)) { | |
1276 | snprintf(label, sizeof(label), "%s", p); | |
1277 | } else { | |
140e065d JK |
1278 | snprintf(label, sizeof(label), "compat_monitor%d", |
1279 | monitor_device_index); | |
95e30b2a | 1280 | opts = qemu_chr_parse_compat(label, optarg, true); |
88589343 | 1281 | if (!opts) { |
f61eddcb | 1282 | error_report("parse error: %s", optarg); |
88589343 GH |
1283 | exit(1); |
1284 | } | |
1285 | } | |
1286 | ||
822ac12d | 1287 | opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal); |
f43e47db MA |
1288 | qemu_opt_set(opts, "mode", mode, &error_abort); |
1289 | qemu_opt_set(opts, "chardev", label, &error_abort); | |
3c45f625 KW |
1290 | if (!strcmp(mode, "control")) { |
1291 | qemu_opt_set_bool(opts, "pretty", pretty, &error_abort); | |
1292 | } else { | |
1293 | assert(pretty == false); | |
1294 | } | |
88589343 GH |
1295 | monitor_device_index++; |
1296 | } | |
1297 | ||
bd3c948d GH |
1298 | struct device_config { |
1299 | enum { | |
aee1b935 | 1300 | DEV_USB, /* -usbdevice */ |
aee1b935 GH |
1301 | DEV_SERIAL, /* -serial */ |
1302 | DEV_PARALLEL, /* -parallel */ | |
c9f398e5 | 1303 | DEV_DEBUGCON, /* -debugcon */ |
ef0c4a0d | 1304 | DEV_GDB, /* -gdb, -s */ |
3ef669e1 | 1305 | DEV_SCLP, /* s390 sclp */ |
bd3c948d GH |
1306 | } type; |
1307 | const char *cmdline; | |
d9a5954d | 1308 | Location loc; |
72cf2d4f | 1309 | QTAILQ_ENTRY(device_config) next; |
bd3c948d | 1310 | }; |
4fdcac0e BS |
1311 | |
1312 | static QTAILQ_HEAD(, device_config) device_configs = | |
1313 | QTAILQ_HEAD_INITIALIZER(device_configs); | |
bd3c948d GH |
1314 | |
1315 | static void add_device_config(int type, const char *cmdline) | |
1316 | { | |
1317 | struct device_config *conf; | |
1318 | ||
7267c094 | 1319 | conf = g_malloc0(sizeof(*conf)); |
bd3c948d GH |
1320 | conf->type = type; |
1321 | conf->cmdline = cmdline; | |
d9a5954d | 1322 | loc_save(&conf->loc); |
72cf2d4f | 1323 | QTAILQ_INSERT_TAIL(&device_configs, conf, next); |
bd3c948d GH |
1324 | } |
1325 | ||
1326 | static int foreach_device_config(int type, int (*func)(const char *cmdline)) | |
1327 | { | |
1328 | struct device_config *conf; | |
1329 | int rc; | |
1330 | ||
72cf2d4f | 1331 | QTAILQ_FOREACH(conf, &device_configs, next) { |
bd3c948d GH |
1332 | if (conf->type != type) |
1333 | continue; | |
d9a5954d | 1334 | loc_push_restore(&conf->loc); |
bd3c948d | 1335 | rc = func(conf->cmdline); |
d9a5954d | 1336 | loc_pop(&conf->loc); |
28de2f88 | 1337 | if (rc) { |
bd3c948d | 1338 | return rc; |
28de2f88 | 1339 | } |
bd3c948d GH |
1340 | } |
1341 | return 0; | |
1342 | } | |
1343 | ||
f650266b PB |
1344 | static void qemu_disable_default_devices(void) |
1345 | { | |
1346 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
1347 | ||
5dacda51 | 1348 | default_driver_check_json(); |
f650266b PB |
1349 | qemu_opts_foreach(qemu_find_opts("device"), |
1350 | default_driver_check, NULL, NULL); | |
1351 | qemu_opts_foreach(qemu_find_opts("global"), | |
1352 | default_driver_check, NULL, NULL); | |
1353 | ||
1354 | if (!vga_model && !default_vga) { | |
1355 | vga_interface_type = VGA_DEVICE; | |
1356 | } | |
1357 | if (!has_defaults || machine_class->no_serial) { | |
1358 | default_serial = 0; | |
1359 | } | |
1360 | if (!has_defaults || machine_class->no_parallel) { | |
1361 | default_parallel = 0; | |
1362 | } | |
1363 | if (!has_defaults || machine_class->no_floppy) { | |
1364 | default_floppy = 0; | |
1365 | } | |
1366 | if (!has_defaults || machine_class->no_cdrom) { | |
1367 | default_cdrom = 0; | |
1368 | } | |
1369 | if (!has_defaults || machine_class->no_sdcard) { | |
1370 | default_sdcard = 0; | |
1371 | } | |
1372 | if (!has_defaults) { | |
1373 | default_monitor = 0; | |
1374 | default_net = 0; | |
1375 | default_vga = 0; | |
1376 | } | |
1377 | } | |
1378 | ||
1379 | static void qemu_create_default_devices(void) | |
1380 | { | |
1381 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
1382 | ||
1383 | if (is_daemonized()) { | |
1384 | /* According to documentation and historically, -nographic redirects | |
1385 | * serial port, parallel port and monitor to stdio, which does not work | |
1386 | * with -daemonize. We can redirect these to null instead, but since | |
1387 | * -nographic is legacy, let's just error out. | |
1388 | * We disallow -nographic only if all other ports are not redirected | |
1389 | * explicitly, to not break existing legacy setups which uses | |
1390 | * -nographic _and_ redirects all ports explicitly - this is valid | |
1391 | * usage, -nographic is just a no-op in this case. | |
1392 | */ | |
1393 | if (nographic | |
1394 | && (default_parallel || default_serial || default_monitor)) { | |
1395 | error_report("-nographic cannot be used with -daemonize"); | |
1396 | exit(1); | |
1397 | } | |
1398 | } | |
1399 | ||
1400 | if (nographic) { | |
1401 | if (default_parallel) | |
1402 | add_device_config(DEV_PARALLEL, "null"); | |
1403 | if (default_serial && default_monitor) { | |
1404 | add_device_config(DEV_SERIAL, "mon:stdio"); | |
1405 | } else { | |
1406 | if (default_serial) | |
1407 | add_device_config(DEV_SERIAL, "stdio"); | |
1408 | if (default_monitor) | |
1409 | monitor_parse("stdio", "readline", false); | |
1410 | } | |
1411 | } else { | |
1412 | if (default_serial) | |
1413 | add_device_config(DEV_SERIAL, "vc:80Cx24C"); | |
1414 | if (default_parallel) | |
1415 | add_device_config(DEV_PARALLEL, "vc:80Cx24C"); | |
1416 | if (default_monitor) | |
1417 | monitor_parse("vc:80Cx24C", "readline", false); | |
1418 | } | |
1419 | ||
1420 | if (default_net) { | |
1421 | QemuOptsList *net = qemu_find_opts("net"); | |
1422 | qemu_opts_parse(net, "nic", true, &error_abort); | |
1423 | #ifdef CONFIG_SLIRP | |
1424 | qemu_opts_parse(net, "user", true, &error_abort); | |
1425 | #endif | |
1426 | } | |
1427 | ||
1428 | #if defined(CONFIG_VNC) | |
1429 | if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head))) { | |
1430 | display_remote++; | |
1431 | } | |
1432 | #endif | |
1433 | if (dpy.type == DISPLAY_TYPE_DEFAULT && !display_remote) { | |
1434 | if (!qemu_display_find_default(&dpy)) { | |
1435 | dpy.type = DISPLAY_TYPE_NONE; | |
1436 | #if defined(CONFIG_VNC) | |
653c9747 | 1437 | vnc_parse("localhost:0,to=99,id=default"); |
f650266b PB |
1438 | #endif |
1439 | } | |
1440 | } | |
1441 | if (dpy.type == DISPLAY_TYPE_DEFAULT) { | |
1442 | dpy.type = DISPLAY_TYPE_NONE; | |
1443 | } | |
1444 | ||
1445 | /* If no default VGA is requested, the default is "none". */ | |
1446 | if (default_vga) { | |
1447 | vga_model = get_default_vga_model(machine_class); | |
1448 | } | |
1449 | if (vga_model) { | |
1450 | select_vgahw(machine_class, vga_model); | |
1451 | } | |
1452 | } | |
1453 | ||
998bbd74 GH |
1454 | static int serial_parse(const char *devname) |
1455 | { | |
6af2692e | 1456 | int index = num_serial_hds; |
998bbd74 GH |
1457 | char label[32]; |
1458 | ||
1459 | if (strcmp(devname, "none") == 0) | |
1460 | return 0; | |
998bbd74 | 1461 | snprintf(label, sizeof(label), "serial%d", index); |
6af2692e PM |
1462 | serial_hds = g_renew(Chardev *, serial_hds, index + 1); |
1463 | ||
4ad6f6cb | 1464 | serial_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL); |
998bbd74 | 1465 | if (!serial_hds[index]) { |
f61eddcb EH |
1466 | error_report("could not connect serial device" |
1467 | " to character backend '%s'", devname); | |
998bbd74 GH |
1468 | return -1; |
1469 | } | |
6af2692e | 1470 | num_serial_hds++; |
998bbd74 GH |
1471 | return 0; |
1472 | } | |
1473 | ||
a8d78cd0 PM |
1474 | Chardev *serial_hd(int i) |
1475 | { | |
1476 | assert(i >= 0); | |
6af2692e | 1477 | if (i < num_serial_hds) { |
a8d78cd0 PM |
1478 | return serial_hds[i]; |
1479 | } | |
1480 | return NULL; | |
1481 | } | |
1482 | ||
6a5e8b0e GH |
1483 | static int parallel_parse(const char *devname) |
1484 | { | |
1485 | static int index = 0; | |
1486 | char label[32]; | |
1487 | ||
1488 | if (strcmp(devname, "none") == 0) | |
1489 | return 0; | |
1490 | if (index == MAX_PARALLEL_PORTS) { | |
f61eddcb | 1491 | error_report("too many parallel ports"); |
6a5e8b0e GH |
1492 | exit(1); |
1493 | } | |
1494 | snprintf(label, sizeof(label), "parallel%d", index); | |
4ad6f6cb | 1495 | parallel_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL); |
6a5e8b0e | 1496 | if (!parallel_hds[index]) { |
f61eddcb EH |
1497 | error_report("could not connect parallel device" |
1498 | " to character backend '%s'", devname); | |
6a5e8b0e GH |
1499 | return -1; |
1500 | } | |
1501 | index++; | |
1502 | return 0; | |
1503 | } | |
1504 | ||
c9f398e5 | 1505 | static int debugcon_parse(const char *devname) |
4d8b3c63 | 1506 | { |
c9f398e5 PA |
1507 | QemuOpts *opts; |
1508 | ||
4ad6f6cb | 1509 | if (!qemu_chr_new_mux_mon("debugcon", devname, NULL)) { |
d7ecf712 | 1510 | error_report("invalid character backend '%s'", devname); |
c9f398e5 PA |
1511 | exit(1); |
1512 | } | |
8be7e7e4 | 1513 | opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL); |
c9f398e5 | 1514 | if (!opts) { |
f61eddcb | 1515 | error_report("already have a debugcon device"); |
c9f398e5 PA |
1516 | exit(1); |
1517 | } | |
f43e47db MA |
1518 | qemu_opt_set(opts, "driver", "isa-debugcon", &error_abort); |
1519 | qemu_opt_set(opts, "chardev", "debugcon", &error_abort); | |
c9f398e5 PA |
1520 | return 0; |
1521 | } | |
1522 | ||
2709f263 LE |
1523 | static gint machine_class_cmp(gconstpointer a, gconstpointer b) |
1524 | { | |
1525 | const MachineClass *mc1 = a, *mc2 = b; | |
1526 | int res; | |
1527 | ||
1528 | if (mc1->family == NULL) { | |
1529 | if (mc2->family == NULL) { | |
1530 | /* Compare standalone machine types against each other; they sort | |
1531 | * in increasing order. | |
1532 | */ | |
1533 | return strcmp(object_class_get_name(OBJECT_CLASS(mc1)), | |
1534 | object_class_get_name(OBJECT_CLASS(mc2))); | |
1535 | } | |
1536 | ||
1537 | /* Standalone machine types sort after families. */ | |
1538 | return 1; | |
1539 | } | |
1540 | ||
1541 | if (mc2->family == NULL) { | |
1542 | /* Families sort before standalone machine types. */ | |
1543 | return -1; | |
1544 | } | |
1545 | ||
1546 | /* Families sort between each other alphabetically increasingly. */ | |
1547 | res = strcmp(mc1->family, mc2->family); | |
1548 | if (res != 0) { | |
1549 | return res; | |
1550 | } | |
1551 | ||
1552 | /* Within the same family, machine types sort in decreasing order. */ | |
1553 | return strcmp(object_class_get_name(OBJECT_CLASS(mc2)), | |
1554 | object_class_get_name(OBJECT_CLASS(mc1))); | |
1555 | } | |
1556 | ||
d8fb7d09 | 1557 | static void machine_help_func(const QDict *qdict) |
9052ea6b | 1558 | { |
d8fb7d09 PB |
1559 | GSList *machines, *el; |
1560 | const char *type = qdict_get_try_str(qdict, "type"); | |
9052ea6b | 1561 | |
d8fb7d09 PB |
1562 | machines = object_class_get_list(TYPE_MACHINE, false); |
1563 | if (type) { | |
1564 | ObjectClass *machine_class = OBJECT_CLASS(find_machine(type, machines)); | |
1565 | if (machine_class) { | |
1566 | type_print_class_properties(object_class_get_name(machine_class)); | |
1567 | return; | |
9052ea6b | 1568 | } |
9052ea6b | 1569 | } |
261747f1 | 1570 | |
d8fb7d09 PB |
1571 | printf("Supported machines are:\n"); |
1572 | machines = g_slist_sort(machines, machine_class_cmp); | |
1573 | for (el = machines; el; el = el->next) { | |
1574 | MachineClass *mc = el->data; | |
1575 | if (mc->alias) { | |
1576 | printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name); | |
1577 | } | |
1578 | printf("%-20s %s%s%s\n", mc->name, mc->desc, | |
1579 | mc->is_default ? " (default)" : "", | |
1580 | mc->deprecation_reason ? " (deprecated)" : ""); | |
12cb82fd | 1581 | } |
9052ea6b JK |
1582 | } |
1583 | ||
a3c2f128 PB |
1584 | static void |
1585 | machine_merge_property(const char *propname, QDict *prop, Error **errp) | |
1586 | { | |
1587 | QDict *opts; | |
1588 | ||
1589 | opts = qdict_new(); | |
1590 | /* Preserve the caller's reference to prop. */ | |
1591 | qobject_ref(prop); | |
1592 | qdict_put(opts, propname, prop); | |
1593 | keyval_merge(machine_opts_dict, opts, errp); | |
1594 | qobject_unref(opts); | |
1595 | } | |
1596 | ||
fe68090e PB |
1597 | static void |
1598 | machine_parse_property_opt(QemuOptsList *opts_list, const char *propname, | |
f9dfae9c | 1599 | const char *arg) |
fe68090e | 1600 | { |
a3c2f128 | 1601 | QDict *prop = NULL; |
fe68090e | 1602 | bool help = false; |
fe68090e | 1603 | |
f9dfae9c | 1604 | prop = keyval_parse(arg, opts_list->implied_opt_name, &help, &error_fatal); |
fe68090e PB |
1605 | if (help) { |
1606 | qemu_opts_print_help(opts_list, true); | |
3e61a13a | 1607 | exit(0); |
fe68090e | 1608 | } |
f9dfae9c | 1609 | machine_merge_property(propname, prop, &error_fatal); |
a3c2f128 | 1610 | qobject_unref(prop); |
fe68090e PB |
1611 | } |
1612 | ||
90a84d13 MAL |
1613 | static const char *pid_file; |
1614 | static Notifier qemu_unlink_pidfile_notifier; | |
1615 | ||
1616 | static void qemu_unlink_pidfile(Notifier *n, void *data) | |
1617 | { | |
1618 | if (pid_file) { | |
1619 | unlink(pid_file); | |
1620 | } | |
1621 | } | |
1622 | ||
6530a97b AL |
1623 | static const QEMUOption *lookup_opt(int argc, char **argv, |
1624 | const char **poptarg, int *poptind) | |
1625 | { | |
1626 | const QEMUOption *popt; | |
1627 | int optind = *poptind; | |
1628 | char *r = argv[optind]; | |
1629 | const char *optarg; | |
1630 | ||
0f0bc3f1 | 1631 | loc_set_cmdline(argv, optind, 1); |
6530a97b AL |
1632 | optind++; |
1633 | /* Treat --foo the same as -foo. */ | |
1634 | if (r[1] == '-') | |
1635 | r++; | |
1636 | popt = qemu_options; | |
1637 | for(;;) { | |
1638 | if (!popt->name) { | |
0f0bc3f1 | 1639 | error_report("invalid option"); |
6530a97b AL |
1640 | exit(1); |
1641 | } | |
1642 | if (!strcmp(popt->name, r + 1)) | |
1643 | break; | |
1644 | popt++; | |
1645 | } | |
1646 | if (popt->flags & HAS_ARG) { | |
1647 | if (optind >= argc) { | |
0f0bc3f1 | 1648 | error_report("requires an argument"); |
6530a97b AL |
1649 | exit(1); |
1650 | } | |
1651 | optarg = argv[optind++]; | |
0f0bc3f1 | 1652 | loc_set_cmdline(argv, optind - 2, 2); |
6530a97b AL |
1653 | } else { |
1654 | optarg = NULL; | |
1655 | } | |
1656 | ||
1657 | *poptarg = optarg; | |
1658 | *poptind = optind; | |
1659 | ||
1660 | return popt; | |
1661 | } | |
1662 | ||
d8fb7d09 | 1663 | static MachineClass *select_machine(QDict *qdict, Error **errp) |
34f405ae | 1664 | { |
d8fb7d09 | 1665 | const char *optarg = qdict_get_try_str(qdict, "type"); |
c516cd1b | 1666 | GSList *machines = object_class_get_list(TYPE_MACHINE, false); |
d8fb7d09 PB |
1667 | MachineClass *machine_class; |
1668 | Error *local_err = NULL; | |
34f405ae | 1669 | |
34f405ae | 1670 | if (optarg) { |
d8fb7d09 PB |
1671 | machine_class = find_machine(optarg, machines); |
1672 | qdict_del(qdict, "type"); | |
1673 | if (!machine_class) { | |
1674 | error_setg(&local_err, "unsupported machine type"); | |
1675 | } | |
1676 | } else { | |
1677 | machine_class = find_default_machine(machines); | |
1678 | if (!machine_class) { | |
1679 | error_setg(&local_err, "No machine specified, and there is no default"); | |
1680 | } | |
34f405ae MA |
1681 | } |
1682 | ||
c516cd1b | 1683 | g_slist_free(machines); |
d8fb7d09 PB |
1684 | if (local_err) { |
1685 | error_append_hint(&local_err, "Use -machine help to list supported machines\n"); | |
1686 | error_propagate(errp, local_err); | |
1687 | } | |
7580f231 | 1688 | return machine_class; |
34f405ae MA |
1689 | } |
1690 | ||
e5db4bd8 PB |
1691 | static int object_parse_property_opt(Object *obj, |
1692 | const char *name, const char *value, | |
1693 | const char *skip, Error **errp) | |
68d98d3e | 1694 | { |
e5db4bd8 | 1695 | if (g_str_equal(name, skip)) { |
68d98d3e AL |
1696 | return 0; |
1697 | } | |
1698 | ||
668f62ec | 1699 | if (!object_property_parse(obj, name, value, errp)) { |
68d98d3e AL |
1700 | return -1; |
1701 | } | |
1702 | ||
1703 | return 0; | |
1704 | } | |
1705 | ||
d8fb7d09 PB |
1706 | /* *Non*recursively replace underscores with dashes in QDict keys. */ |
1707 | static void keyval_dashify(QDict *qdict, Error **errp) | |
e5db4bd8 | 1708 | { |
d8fb7d09 | 1709 | const QDictEntry *ent, *next; |
e5db4bd8 PB |
1710 | char *p; |
1711 | ||
d8fb7d09 PB |
1712 | for (ent = qdict_first(qdict); ent; ent = next) { |
1713 | g_autofree char *new_key = NULL; | |
1714 | ||
1715 | next = qdict_next(qdict, ent); | |
1716 | if (!strchr(ent->key, '_')) { | |
1717 | continue; | |
1718 | } | |
1719 | new_key = g_strdup(ent->key); | |
1720 | for (p = new_key; *p; p++) { | |
1721 | if (*p == '_') { | |
1722 | *p = '-'; | |
1723 | } | |
e5db4bd8 | 1724 | } |
d8fb7d09 PB |
1725 | if (qdict_haskey(qdict, new_key)) { |
1726 | error_setg(errp, "Conflict between '%s' and '%s'", ent->key, new_key); | |
1727 | return; | |
1728 | } | |
1729 | qobject_ref(ent->value); | |
1730 | qdict_put_obj(qdict, new_key, ent->value); | |
1731 | qdict_del(qdict, ent->key); | |
e5db4bd8 | 1732 | } |
d8fb7d09 PB |
1733 | } |
1734 | ||
1735 | static void qemu_apply_legacy_machine_options(QDict *qdict) | |
1736 | { | |
1737 | const char *value; | |
1738 | ||
1739 | keyval_dashify(qdict, &error_fatal); | |
e5db4bd8 | 1740 | |
6f6e1698 | 1741 | /* Legacy options do not correspond to MachineState properties. */ |
d8fb7d09 PB |
1742 | value = qdict_get_try_str(qdict, "accel"); |
1743 | if (value) { | |
1744 | accelerators = g_strdup(value); | |
1745 | qdict_del(qdict, "accel"); | |
6f6e1698 | 1746 | } |
d8fb7d09 PB |
1747 | |
1748 | value = qdict_get_try_str(qdict, "igd-passthru"); | |
1749 | if (value) { | |
1750 | object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value, | |
a8dc82ce | 1751 | false); |
d8fb7d09 | 1752 | qdict_del(qdict, "igd-passthru"); |
46472d82 | 1753 | } |
d8fb7d09 PB |
1754 | |
1755 | value = qdict_get_try_str(qdict, "kvm-shadow-mem"); | |
1756 | if (value) { | |
1757 | object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value, | |
a8dc82ce | 1758 | false); |
d8fb7d09 | 1759 | qdict_del(qdict, "kvm-shadow-mem"); |
23b0898e | 1760 | } |
d8fb7d09 PB |
1761 | |
1762 | value = qdict_get_try_str(qdict, "kernel-irqchip"); | |
1763 | if (value) { | |
1764 | object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value, | |
a8dc82ce | 1765 | false); |
d8fb7d09 | 1766 | object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value, |
a8dc82ce | 1767 | false); |
d8fb7d09 | 1768 | qdict_del(qdict, "kernel-irqchip"); |
faf20793 | 1769 | } |
e5db4bd8 | 1770 | } |
f08f9271 | 1771 | |
bc2f4fcb PB |
1772 | static void object_option_foreach_add(bool (*type_opt_predicate)(const char *)) |
1773 | { | |
1774 | ObjectOption *opt, *next; | |
1775 | ||
1776 | QTAILQ_FOREACH_SAFE(opt, &object_opts, next, next) { | |
1777 | const char *type = ObjectType_str(opt->opts->qom_type); | |
1778 | if (type_opt_predicate(type)) { | |
1779 | user_creatable_add_qapi(opt->opts, &error_fatal); | |
1780 | qapi_free_ObjectOptions(opt->opts); | |
1781 | QTAILQ_REMOVE(&object_opts, opt, next); | |
1782 | g_free(opt); | |
1783 | } | |
1784 | } | |
1785 | } | |
1786 | ||
49e98769 PB |
1787 | static void object_option_add_visitor(Visitor *v) |
1788 | { | |
1789 | ObjectOption *opt = g_new0(ObjectOption, 1); | |
1790 | visit_type_ObjectOptions(v, NULL, &opt->opts, &error_fatal); | |
1791 | QTAILQ_INSERT_TAIL(&object_opts, opt, next); | |
1792 | } | |
1793 | ||
bc2f4fcb PB |
1794 | static void object_option_parse(const char *optarg) |
1795 | { | |
bc2f4fcb PB |
1796 | QemuOpts *opts; |
1797 | const char *type; | |
1798 | Visitor *v; | |
1799 | ||
009ff893 PB |
1800 | if (optarg[0] == '{') { |
1801 | QObject *obj = qobject_from_json(optarg, &error_fatal); | |
bc2f4fcb | 1802 | |
009ff893 PB |
1803 | v = qobject_input_visitor_new(obj); |
1804 | qobject_unref(obj); | |
1805 | } else { | |
1806 | opts = qemu_opts_parse_noisily(qemu_find_opts("object"), | |
1807 | optarg, true); | |
1808 | if (!opts) { | |
1809 | exit(1); | |
1810 | } | |
1811 | ||
1812 | type = qemu_opt_get(opts, "qom-type"); | |
1813 | if (!type) { | |
1814 | error_setg(&error_fatal, QERR_MISSING_PARAMETER, "qom-type"); | |
1815 | } | |
1816 | if (user_creatable_print_help(type, opts)) { | |
1817 | exit(0); | |
1818 | } | |
1819 | ||
1820 | v = opts_visitor_new(opts); | |
bc2f4fcb PB |
1821 | } |
1822 | ||
49e98769 | 1823 | object_option_add_visitor(v); |
bc2f4fcb | 1824 | visit_free(v); |
bc2f4fcb PB |
1825 | } |
1826 | ||
f08f9271 DB |
1827 | /* |
1828 | * Initial object creation happens before all other | |
1829 | * QEMU data types are created. The majority of objects | |
1830 | * can be created at this point. The rng-egd object | |
1831 | * cannot be created here, as it depends on the chardev | |
1832 | * already existing. | |
1833 | */ | |
bc2f4fcb | 1834 | static bool object_create_early(const char *type) |
f08f9271 | 1835 | { |
edfb4389 MA |
1836 | /* |
1837 | * Objects should not be made "delayed" without a reason. If you | |
1838 | * add one, state the reason in a comment! | |
1839 | */ | |
1840 | ||
6ba7ada3 PB |
1841 | /* Reason: property "chardev" */ |
1842 | if (g_str_equal(type, "rng-egd") || | |
1843 | g_str_equal(type, "qtest")) { | |
f08f9271 DB |
1844 | return false; |
1845 | } | |
7dbb11c8 | 1846 | |
042cea27 | 1847 | #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX) |
edfb4389 | 1848 | /* Reason: cryptodev-vhost-user property "chardev" */ |
042cea27 GA |
1849 | if (g_str_equal(type, "cryptodev-vhost-user")) { |
1850 | return false; | |
1851 | } | |
1852 | #endif | |
1853 | ||
3578389b CX |
1854 | /* Reason: vhost-user-blk-server property "node-name" */ |
1855 | if (g_str_equal(type, "vhost-user-blk-server")) { | |
1856 | return false; | |
1857 | } | |
9d3e12e8 | 1858 | /* |
edfb4389 | 1859 | * Reason: filter-* property "netdev" etc. |
9d3e12e8 TH |
1860 | */ |
1861 | if (g_str_equal(type, "filter-buffer") || | |
f6d3afb5 | 1862 | g_str_equal(type, "filter-dump") || |
d46f75b2 | 1863 | g_str_equal(type, "filter-mirror") || |
7dce4e6f | 1864 | g_str_equal(type, "filter-redirector") || |
e6eee8ab | 1865 | g_str_equal(type, "colo-compare") || |
646c5478 PD |
1866 | g_str_equal(type, "filter-rewriter") || |
1867 | g_str_equal(type, "filter-replay")) { | |
7dbb11c8 YH |
1868 | return false; |
1869 | } | |
1870 | ||
b86f59c7 CF |
1871 | /* |
1872 | * Allocation of large amounts of memory may delay | |
6546d0db EH |
1873 | * chardev initialization for too long, and trigger timeouts |
1874 | * on software that waits for a monitor socket to be created | |
1875 | * (e.g. libvirt). | |
1876 | */ | |
1877 | if (g_str_has_prefix(type, "memory-backend-")) { | |
1878 | return false; | |
1879 | } | |
1880 | ||
f08f9271 DB |
1881 | return true; |
1882 | } | |
1883 | ||
d8fb7d09 | 1884 | static void qemu_apply_machine_options(QDict *qdict) |
7a84268d PB |
1885 | { |
1886 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
4b7acd2a PB |
1887 | const char *boot_order = NULL; |
1888 | const char *boot_once = NULL; | |
7a84268d PB |
1889 | QemuOpts *opts; |
1890 | ||
d8fb7d09 | 1891 | object_set_properties_from_keyval(OBJECT(current_machine), qdict, false, &error_fatal); |
7a84268d PB |
1892 | current_machine->ram_size = ram_size; |
1893 | current_machine->maxram_size = maxram_size; | |
1894 | current_machine->ram_slots = ram_slots; | |
1895 | ||
1896 | opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL); | |
1897 | if (opts) { | |
1898 | boot_order = qemu_opt_get(opts, "order"); | |
1899 | if (boot_order) { | |
1900 | validate_bootdevices(boot_order, &error_fatal); | |
1901 | } | |
1902 | ||
1903 | boot_once = qemu_opt_get(opts, "once"); | |
1904 | if (boot_once) { | |
1905 | validate_bootdevices(boot_once, &error_fatal); | |
1906 | } | |
1907 | ||
1908 | boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu); | |
1909 | boot_strict = qemu_opt_get_bool(opts, "strict", false); | |
1910 | } | |
1911 | ||
1912 | if (!boot_order) { | |
1913 | boot_order = machine_class->default_boot_order; | |
1914 | } | |
1915 | ||
1916 | current_machine->boot_order = boot_order; | |
4b7acd2a | 1917 | current_machine->boot_once = boot_once; |
7a84268d PB |
1918 | |
1919 | if (semihosting_enabled() && !semihosting_get_argc()) { | |
7a84268d | 1920 | /* fall back to the -kernel/-append */ |
d8fb7d09 | 1921 | semihosting_arg_fallback(current_machine->kernel_filename, current_machine->kernel_cmdline); |
7a84268d | 1922 | } |
fe68090e PB |
1923 | |
1924 | if (current_machine->smp.cpus > 1) { | |
1925 | Error *blocker = NULL; | |
1926 | error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); | |
1927 | replay_add_blocker(blocker); | |
1928 | } | |
7a84268d PB |
1929 | } |
1930 | ||
64418657 PB |
1931 | static void qemu_create_early_backends(void) |
1932 | { | |
1933 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
66c2207f TH |
1934 | #if defined(CONFIG_SDL) |
1935 | const bool use_sdl = (dpy.type == DISPLAY_TYPE_SDL); | |
1936 | #else | |
1937 | const bool use_sdl = false; | |
1938 | #endif | |
1939 | #if defined(CONFIG_GTK) | |
1940 | const bool use_gtk = (dpy.type == DISPLAY_TYPE_GTK); | |
1941 | #else | |
1942 | const bool use_gtk = false; | |
1943 | #endif | |
64418657 | 1944 | |
66c2207f | 1945 | if ((alt_grab || ctrl_grab) && !use_sdl) { |
64418657 PB |
1946 | error_report("-alt-grab and -ctrl-grab are only valid " |
1947 | "for SDL, ignoring option"); | |
1948 | } | |
66c2207f | 1949 | if (dpy.has_window_close && !use_gtk && !use_sdl) { |
fe86fe23 | 1950 | error_report("window-close is only valid for GTK and SDL, " |
64418657 PB |
1951 | "ignoring option"); |
1952 | } | |
1953 | ||
1954 | qemu_display_early_init(&dpy); | |
1955 | qemu_console_early_init(); | |
1956 | ||
1957 | if (dpy.has_gl && dpy.gl != DISPLAYGL_MODE_OFF && display_opengl == 0) { | |
1958 | #if defined(CONFIG_OPENGL) | |
1959 | error_report("OpenGL is not supported by the display"); | |
1960 | #else | |
1961 | error_report("OpenGL support is disabled"); | |
1962 | #endif | |
1963 | exit(1); | |
1964 | } | |
1965 | ||
bc2f4fcb | 1966 | object_option_foreach_add(object_create_early); |
64418657 PB |
1967 | |
1968 | /* spice needs the timers to be initialized by this point */ | |
3d76c3b6 | 1969 | /* spice must initialize before audio as it changes the default audiodev */ |
64418657 PB |
1970 | /* spice must initialize before chardevs (for spicevmc and spiceport) */ |
1971 | qemu_spice.init(); | |
1972 | ||
1973 | qemu_opts_foreach(qemu_find_opts("chardev"), | |
1974 | chardev_init_func, NULL, &error_fatal); | |
1975 | ||
1976 | #ifdef CONFIG_VIRTFS | |
1977 | qemu_opts_foreach(qemu_find_opts("fsdev"), | |
1978 | fsdev_init_func, NULL, &error_fatal); | |
1979 | #endif | |
1980 | ||
1981 | /* | |
1982 | * Note: we need to create audio and block backends before | |
d8fb7d09 | 1983 | * setting machine properties, so they can be referred to. |
64418657 PB |
1984 | */ |
1985 | configure_blockdev(&bdo_queue, machine_class, snapshot); | |
1986 | audio_init_audiodevs(); | |
1987 | } | |
1988 | ||
f08f9271 DB |
1989 | |
1990 | /* | |
1991 | * The remainder of object creation happens after the | |
9abce56d | 1992 | * creation of chardev, fsdev, net clients and device data types. |
f08f9271 | 1993 | */ |
bc2f4fcb | 1994 | static bool object_create_late(const char *type) |
f08f9271 | 1995 | { |
bc2f4fcb | 1996 | return !object_create_early(type); |
f08f9271 DB |
1997 | } |
1998 | ||
07a91b1a PB |
1999 | static void qemu_create_late_backends(void) |
2000 | { | |
2001 | if (qtest_chrdev) { | |
2002 | qtest_server_init(qtest_chrdev, qtest_log, &error_fatal); | |
2003 | } | |
2004 | ||
2005 | net_init_clients(&error_fatal); | |
2006 | ||
bc2f4fcb | 2007 | object_option_foreach_add(object_create_late); |
07a91b1a PB |
2008 | |
2009 | if (tpm_init() < 0) { | |
2010 | exit(1); | |
2011 | } | |
2012 | ||
2013 | qemu_opts_foreach(qemu_find_opts("mon"), | |
2014 | mon_init_func, NULL, &error_fatal); | |
2015 | ||
2016 | if (foreach_device_config(DEV_SERIAL, serial_parse) < 0) | |
2017 | exit(1); | |
2018 | if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) | |
2019 | exit(1); | |
2020 | if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0) | |
2021 | exit(1); | |
2022 | ||
2023 | /* now chardevs have been created we may have semihosting to connect */ | |
2024 | qemu_semihosting_connect_chardevs(); | |
2025 | qemu_semihosting_console_init(); | |
2026 | } | |
f08f9271 | 2027 | |
f5c9fcb8 PB |
2028 | static bool have_custom_ram_size(void) |
2029 | { | |
2030 | QemuOpts *opts = qemu_find_opts_singleton("memory"); | |
2031 | return !!qemu_opt_get_size(opts, "size", 0); | |
2032 | } | |
2033 | ||
b24986e7 PB |
2034 | static void qemu_resolve_machine_memdev(void) |
2035 | { | |
2036 | if (current_machine->ram_memdev_id) { | |
2037 | Object *backend; | |
2038 | ram_addr_t backend_size; | |
2039 | ||
2040 | backend = object_resolve_path_type(current_machine->ram_memdev_id, | |
2041 | TYPE_MEMORY_BACKEND, NULL); | |
2042 | if (!backend) { | |
2043 | error_report("Memory backend '%s' not found", | |
2044 | current_machine->ram_memdev_id); | |
2045 | exit(EXIT_FAILURE); | |
2046 | } | |
2047 | backend_size = object_property_get_uint(backend, "size", &error_abort); | |
2048 | if (have_custom_ram_size() && backend_size != ram_size) { | |
2049 | error_report("Size specified by -m option must match size of " | |
2050 | "explicitly specified 'memory-backend' property"); | |
2051 | exit(EXIT_FAILURE); | |
2052 | } | |
2053 | if (mem_path) { | |
2054 | error_report("'-mem-path' can't be used together with" | |
2055 | "'-machine memory-backend'"); | |
2056 | exit(EXIT_FAILURE); | |
2057 | } | |
2058 | ram_size = backend_size; | |
2059 | } | |
2060 | ||
2061 | if (!xen_enabled()) { | |
2062 | /* On 32-bit hosts, QEMU is limited by virtual address space */ | |
2063 | if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) { | |
2064 | error_report("at most 2047 MB RAM can be simulated"); | |
2065 | exit(1); | |
2066 | } | |
2067 | } | |
2068 | } | |
2069 | ||
f5c9fcb8 | 2070 | static void set_memory_options(MachineClass *mc) |
3b9985e9 MA |
2071 | { |
2072 | uint64_t sz; | |
2073 | const char *mem_str; | |
076b35b5 | 2074 | const ram_addr_t default_ram_size = mc->default_ram_size; |
3b9985e9 | 2075 | QemuOpts *opts = qemu_find_opts_singleton("memory"); |
bbe2d25c EH |
2076 | Location loc; |
2077 | ||
2078 | loc_push_none(&loc); | |
2079 | qemu_opts_loc_restore(opts); | |
3b9985e9 MA |
2080 | |
2081 | sz = 0; | |
2082 | mem_str = qemu_opt_get(opts, "size"); | |
2083 | if (mem_str) { | |
2084 | if (!*mem_str) { | |
2085 | error_report("missing 'size' option value"); | |
2086 | exit(EXIT_FAILURE); | |
2087 | } | |
2088 | ||
2089 | sz = qemu_opt_get_size(opts, "size", ram_size); | |
2090 | ||
2091 | /* Fix up legacy suffix-less format */ | |
2092 | if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) { | |
2093 | uint64_t overflow_check = sz; | |
2094 | ||
3dc54b0e PMD |
2095 | sz *= MiB; |
2096 | if (sz / MiB != overflow_check) { | |
3b9985e9 MA |
2097 | error_report("too large 'size' option value"); |
2098 | exit(EXIT_FAILURE); | |
2099 | } | |
2100 | } | |
2101 | } | |
2102 | ||
2103 | /* backward compatibility behaviour for case "-m 0" */ | |
2104 | if (sz == 0) { | |
2105 | sz = default_ram_size; | |
2106 | } | |
2107 | ||
2108 | sz = QEMU_ALIGN_UP(sz, 8192); | |
5c30ef93 CB |
2109 | if (mc->fixup_ram_size) { |
2110 | sz = mc->fixup_ram_size(sz); | |
2111 | } | |
3b9985e9 MA |
2112 | ram_size = sz; |
2113 | if (ram_size != sz) { | |
2114 | error_report("ram size too large"); | |
2115 | exit(EXIT_FAILURE); | |
2116 | } | |
2117 | ||
f5c9fcb8 | 2118 | maxram_size = ram_size; |
3b9985e9 | 2119 | |
951f2269 | 2120 | if (qemu_opt_get(opts, "maxmem")) { |
3b9985e9 MA |
2121 | uint64_t slots; |
2122 | ||
2123 | sz = qemu_opt_get_size(opts, "maxmem", 0); | |
214224ad | 2124 | slots = qemu_opt_get_number(opts, "slots", 0); |
3b9985e9 | 2125 | if (sz < ram_size) { |
214224ad PK |
2126 | error_report("invalid value of -m option maxmem: " |
2127 | "maximum memory size (0x%" PRIx64 ") must be at least " | |
2128 | "the initial memory size (0x" RAM_ADDR_FMT ")", | |
2129 | sz, ram_size); | |
3b9985e9 | 2130 | exit(EXIT_FAILURE); |
951f2269 | 2131 | } else if (slots && sz == ram_size) { |
214224ad PK |
2132 | error_report("invalid value of -m option maxmem: " |
2133 | "memory slots were specified but maximum memory size " | |
2134 | "(0x%" PRIx64 ") is equal to the initial memory size " | |
2135 | "(0x" RAM_ADDR_FMT ")", sz, ram_size); | |
3b9985e9 MA |
2136 | exit(EXIT_FAILURE); |
2137 | } | |
2138 | ||
f5c9fcb8 PB |
2139 | maxram_size = sz; |
2140 | ram_slots = slots; | |
951f2269 DH |
2141 | } else if (qemu_opt_get(opts, "slots")) { |
2142 | error_report("invalid -m option value: missing 'maxmem' option"); | |
3b9985e9 MA |
2143 | exit(EXIT_FAILURE); |
2144 | } | |
bbe2d25c EH |
2145 | |
2146 | loc_pop(&loc); | |
f5c9fcb8 PB |
2147 | } |
2148 | ||
d8fb7d09 | 2149 | static void qemu_create_machine(QDict *qdict) |
f5c9fcb8 | 2150 | { |
d8fb7d09 | 2151 | MachineClass *machine_class = select_machine(qdict, &error_fatal); |
f5c9fcb8 PB |
2152 | object_set_machine_compat_props(machine_class->compat_props); |
2153 | ||
2154 | set_memory_options(machine_class); | |
2155 | ||
2156 | current_machine = MACHINE(object_new_with_class(OBJECT_CLASS(machine_class))); | |
f5c9fcb8 PB |
2157 | object_property_add_child(object_get_root(), "machine", |
2158 | OBJECT(current_machine)); | |
2159 | object_property_add_child(container_get(OBJECT(current_machine), | |
2160 | "/unattached"), | |
2161 | "sysbus", OBJECT(sysbus_get_default())); | |
2162 | ||
2163 | if (machine_class->minimum_page_bits) { | |
2164 | if (!set_preferred_target_page_bits(machine_class->minimum_page_bits)) { | |
2165 | /* This would be a board error: specifying a minimum smaller than | |
2166 | * a target's compile-time fixed setting. | |
2167 | */ | |
2168 | g_assert_not_reached(); | |
2169 | } | |
2170 | } | |
2171 | ||
2172 | cpu_exec_init_all(); | |
2173 | page_size_init(); | |
2174 | ||
2175 | if (machine_class->hw_version) { | |
2176 | qemu_set_hw_version(machine_class->hw_version); | |
2177 | } | |
2178 | ||
f5c9fcb8 PB |
2179 | /* |
2180 | * Get the default machine options from the machine if it is not already | |
2181 | * specified either by the configuration file or by the command line. | |
2182 | */ | |
2183 | if (machine_class->default_machine_opts) { | |
d8fb7d09 PB |
2184 | QDict *default_opts = |
2185 | keyval_parse(machine_class->default_machine_opts, NULL, NULL, | |
2186 | &error_abort); | |
dadafe67 | 2187 | qemu_apply_legacy_machine_options(default_opts); |
d8fb7d09 PB |
2188 | object_set_properties_from_keyval(OBJECT(current_machine), default_opts, |
2189 | false, &error_abort); | |
2190 | qobject_unref(default_opts); | |
f5c9fcb8 | 2191 | } |
3b9985e9 MA |
2192 | } |
2193 | ||
8d76bfe8 EH |
2194 | static int global_init_func(void *opaque, QemuOpts *opts, Error **errp) |
2195 | { | |
2196 | GlobalProperty *g; | |
2197 | ||
2198 | g = g_malloc0(sizeof(*g)); | |
2199 | g->driver = qemu_opt_get(opts, "driver"); | |
2200 | g->property = qemu_opt_get(opts, "property"); | |
2201 | g->value = qemu_opt_get(opts, "value"); | |
8d76bfe8 EH |
2202 | qdev_prop_register_global(g); |
2203 | return 0; | |
2204 | } | |
2205 | ||
c0d4aa82 PB |
2206 | /* |
2207 | * Return whether configuration group @group is stored in QemuOpts, or | |
2208 | * recorded as one or more QDicts by qemu_record_config_group. | |
2209 | */ | |
2210 | static bool is_qemuopts_group(const char *group) | |
2211 | { | |
d8fb7d09 | 2212 | if (g_str_equal(group, "object") || |
e4383ca2 PB |
2213 | g_str_equal(group, "machine") || |
2214 | g_str_equal(group, "smp-opts")) { | |
49e98769 PB |
2215 | return false; |
2216 | } | |
c0d4aa82 PB |
2217 | return true; |
2218 | } | |
2219 | ||
2220 | static void qemu_record_config_group(const char *group, QDict *dict, | |
2221 | bool from_json, Error **errp) | |
2222 | { | |
49e98769 PB |
2223 | if (g_str_equal(group, "object")) { |
2224 | Visitor *v = qobject_input_visitor_new_keyval(QOBJECT(dict)); | |
2225 | object_option_add_visitor(v); | |
2226 | visit_free(v); | |
d8fb7d09 PB |
2227 | } else if (g_str_equal(group, "machine")) { |
2228 | /* | |
2229 | * Cannot merge string-valued and type-safe dictionaries, so JSON | |
2230 | * is not accepted yet for -M. | |
2231 | */ | |
2232 | assert(!from_json); | |
2233 | keyval_merge(machine_opts_dict, dict, errp); | |
e4383ca2 PB |
2234 | } else if (g_str_equal(group, "smp-opts")) { |
2235 | machine_merge_property("smp", dict, &error_fatal); | |
49e98769 PB |
2236 | } else { |
2237 | abort(); | |
2238 | } | |
c0d4aa82 PB |
2239 | } |
2240 | ||
2241 | /* | |
2242 | * Parse non-QemuOpts config file groups, pass the rest to | |
2243 | * qemu_config_do_parse. | |
2244 | */ | |
2245 | static void qemu_parse_config_group(const char *group, QDict *qdict, | |
2246 | void *opaque, Error **errp) | |
2247 | { | |
2248 | QObject *crumpled; | |
2249 | if (is_qemuopts_group(group)) { | |
2250 | qemu_config_do_parse(group, qdict, opaque, errp); | |
2251 | return; | |
2252 | } | |
2253 | ||
2254 | crumpled = qdict_crumple(qdict, errp); | |
2255 | if (!crumpled) { | |
2256 | return; | |
2257 | } | |
838e3700 PB |
2258 | switch (qobject_type(crumpled)) { |
2259 | case QTYPE_QDICT: | |
2260 | qemu_record_config_group(group, qobject_to(QDict, crumpled), false, errp); | |
2261 | break; | |
2262 | case QTYPE_QLIST: | |
c0d4aa82 | 2263 | error_setg(errp, "Lists cannot be at top level of a configuration section"); |
838e3700 PB |
2264 | break; |
2265 | default: | |
2266 | g_assert_not_reached(); | |
c0d4aa82 | 2267 | } |
838e3700 | 2268 | qobject_unref(crumpled); |
c0d4aa82 PB |
2269 | } |
2270 | ||
f7544edc | 2271 | static void qemu_read_default_config_file(Error **errp) |
726401be | 2272 | { |
f7544edc | 2273 | ERRP_GUARD(); |
726401be | 2274 | int ret; |
580e6ad6 | 2275 | g_autofree char *file = get_relocated_path(CONFIG_QEMU_CONFDIR "/qemu.conf"); |
726401be | 2276 | |
c0d4aa82 | 2277 | ret = qemu_read_config_file(file, qemu_parse_config_group, errp); |
f7544edc PB |
2278 | if (ret < 0) { |
2279 | if (ret == -ENOENT) { | |
2280 | error_free(*errp); | |
2281 | *errp = NULL; | |
2282 | } | |
726401be | 2283 | } |
726401be EH |
2284 | } |
2285 | ||
c0d4aa82 | 2286 | static void qemu_set_option(const char *str, Error **errp) |
ed7fa564 | 2287 | { |
ed7fa564 PB |
2288 | char group[64], id[64], arg[64]; |
2289 | QemuOptsList *list; | |
2290 | QemuOpts *opts; | |
2291 | int rc, offset; | |
2292 | ||
2293 | rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset); | |
2294 | if (rc < 3 || str[offset] != '=') { | |
c0d4aa82 PB |
2295 | error_setg(errp, "can't parse: \"%s\"", str); |
2296 | return; | |
ed7fa564 PB |
2297 | } |
2298 | ||
c0d4aa82 PB |
2299 | if (!is_qemuopts_group(group)) { |
2300 | error_setg(errp, "-set is not supported with %s", group); | |
2301 | } else { | |
2302 | list = qemu_find_opts_err(group, errp); | |
2303 | if (list) { | |
2304 | opts = qemu_opts_find(list, id); | |
2305 | if (!opts) { | |
2306 | error_setg(errp, "there is no %s \"%s\" defined", group, id); | |
2307 | return; | |
2308 | } | |
2309 | qemu_opt_set(opts, arg, str + offset + 1, errp); | |
2310 | } | |
ed7fa564 | 2311 | } |
ed7fa564 PB |
2312 | } |
2313 | ||
a0660e0b PX |
2314 | static void user_register_global_props(void) |
2315 | { | |
2316 | qemu_opts_foreach(qemu_find_opts("global"), | |
2317 | global_init_func, NULL, NULL); | |
2318 | } | |
2319 | ||
7f8b6126 PB |
2320 | static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp) |
2321 | { | |
8191d368 | 2322 | icount_configure(opts, errp); |
7f8b6126 PB |
2323 | return 0; |
2324 | } | |
2325 | ||
12ceaef6 PB |
2326 | static int accelerator_set_property(void *opaque, |
2327 | const char *name, const char *value, | |
2328 | Error **errp) | |
2329 | { | |
2330 | return object_parse_property_opt(opaque, name, value, "accel", errp); | |
2331 | } | |
2332 | ||
deda73e8 PB |
2333 | static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) |
2334 | { | |
6f6e1698 PB |
2335 | bool *p_init_failed = opaque; |
2336 | const char *acc = qemu_opt_get(opts, "accel"); | |
2337 | AccelClass *ac = accel_find(acc); | |
fc5cf826 | 2338 | AccelState *accel; |
6f6e1698 | 2339 | int ret; |
eaf65114 TH |
2340 | bool qtest_with_kvm; |
2341 | ||
2342 | qtest_with_kvm = g_str_equal(acc, "kvm") && qtest_chrdev != NULL; | |
6f6e1698 PB |
2343 | |
2344 | if (!ac) { | |
8b90f1c5 | 2345 | *p_init_failed = true; |
eaf65114 TH |
2346 | if (!qtest_with_kvm) { |
2347 | error_report("invalid accelerator %s", acc); | |
2348 | } | |
6f6e1698 PB |
2349 | return 0; |
2350 | } | |
fc5cf826 | 2351 | accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac))); |
fe174132 | 2352 | object_apply_compat_props(OBJECT(accel)); |
12ceaef6 PB |
2353 | qemu_opt_foreach(opts, accelerator_set_property, |
2354 | accel, | |
2355 | &error_fatal); | |
2356 | ||
fc5cf826 | 2357 | ret = accel_init_machine(accel, current_machine); |
6f6e1698 PB |
2358 | if (ret < 0) { |
2359 | *p_init_failed = true; | |
eaf65114 TH |
2360 | if (!qtest_with_kvm || ret != -ENOENT) { |
2361 | error_report("failed to initialize %s: %s", acc, strerror(-ret)); | |
2362 | } | |
6f6e1698 PB |
2363 | return 0; |
2364 | } | |
fe174132 | 2365 | |
6f6e1698 | 2366 | return 1; |
deda73e8 PB |
2367 | } |
2368 | ||
28a09617 | 2369 | static void configure_accelerators(const char *progname) |
deda73e8 | 2370 | { |
28a09617 | 2371 | bool init_failed = false; |
28a09617 PB |
2372 | |
2373 | qemu_opts_foreach(qemu_find_opts("icount"), | |
2374 | do_configure_icount, NULL, &error_fatal); | |
2375 | ||
6f6e1698 | 2376 | if (QTAILQ_EMPTY(&qemu_accel_opts.head)) { |
60ee3552 RH |
2377 | char **accel_list, **tmp; |
2378 | ||
7245ca74 | 2379 | if (accelerators == NULL) { |
6f6e1698 | 2380 | /* Select the default accelerator */ |
755ee1f3 RH |
2381 | bool have_tcg = accel_find("tcg"); |
2382 | bool have_kvm = accel_find("kvm"); | |
2383 | ||
2384 | if (have_tcg && have_kvm) { | |
2385 | if (g_str_has_suffix(progname, "kvm")) { | |
6f6e1698 | 2386 | /* If the program name ends with "kvm", we prefer KVM */ |
7245ca74 | 2387 | accelerators = "kvm:tcg"; |
6f6e1698 | 2388 | } else { |
7245ca74 | 2389 | accelerators = "tcg:kvm"; |
6f6e1698 | 2390 | } |
755ee1f3 | 2391 | } else if (have_kvm) { |
7245ca74 | 2392 | accelerators = "kvm"; |
755ee1f3 | 2393 | } else if (have_tcg) { |
7245ca74 | 2394 | accelerators = "tcg"; |
755ee1f3 RH |
2395 | } else { |
2396 | error_report("No accelerator selected and" | |
2397 | " no default accelerator available"); | |
2398 | exit(1); | |
28a09617 PB |
2399 | } |
2400 | } | |
7245ca74 | 2401 | accel_list = g_strsplit(accelerators, ":", 0); |
28a09617 | 2402 | |
a024b090 | 2403 | for (tmp = accel_list; *tmp; tmp++) { |
6f6e1698 PB |
2404 | /* |
2405 | * Filter invalid accelerators here, to prevent obscenities | |
2406 | * such as "-machine accel=tcg,,thread=single". | |
2407 | */ | |
2408 | if (accel_find(*tmp)) { | |
2409 | qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp, true); | |
8b90f1c5 PB |
2410 | } else { |
2411 | init_failed = true; | |
2412 | error_report("invalid accelerator %s", *tmp); | |
6f6e1698 | 2413 | } |
28a09617 | 2414 | } |
adb464ff | 2415 | g_strfreev(accel_list); |
6f6e1698 | 2416 | } else { |
7245ca74 | 2417 | if (accelerators != NULL) { |
6f6e1698 PB |
2418 | error_report("The -accel and \"-machine accel=\" options are incompatible"); |
2419 | exit(1); | |
28a09617 PB |
2420 | } |
2421 | } | |
28a09617 | 2422 | |
6f6e1698 PB |
2423 | if (!qemu_opts_foreach(qemu_find_opts("accel"), |
2424 | do_configure_accelerator, &init_failed, &error_fatal)) { | |
28a09617 | 2425 | if (!init_failed) { |
6f6e1698 | 2426 | error_report("no accelerator found"); |
28a09617 PB |
2427 | } |
2428 | exit(1); | |
2429 | } | |
2430 | ||
eaf65114 | 2431 | if (init_failed && !qtest_chrdev) { |
4f7f5893 | 2432 | AccelClass *ac = ACCEL_GET_CLASS(current_accel()); |
8b90f1c5 | 2433 | error_report("falling back to %s", ac->name); |
28a09617 PB |
2434 | } |
2435 | ||
740b1759 | 2436 | if (icount_enabled() && !tcg_enabled()) { |
deda73e8 PB |
2437 | error_report("-icount is not allowed with hardware virtualization"); |
2438 | exit(1); | |
2439 | } | |
2440 | } | |
2441 | ||
ffac16fa | 2442 | static void create_default_memdev(MachineState *ms, const char *path) |
900c0ba3 IM |
2443 | { |
2444 | Object *obj; | |
2445 | MachineClass *mc = MACHINE_GET_CLASS(ms); | |
2446 | ||
2447 | obj = object_new(path ? TYPE_MEMORY_BACKEND_FILE : TYPE_MEMORY_BACKEND_RAM); | |
2448 | if (path) { | |
5325cc34 | 2449 | object_property_set_str(obj, "mem-path", path, &error_fatal); |
900c0ba3 | 2450 | } |
5325cc34 | 2451 | object_property_set_int(obj, "size", ms->ram_size, &error_fatal); |
900c0ba3 | 2452 | object_property_add_child(object_get_objects_root(), mc->default_ram_id, |
d2623129 | 2453 | obj); |
d96c4d5f | 2454 | /* Ensure backend's memory region name is equal to mc->default_ram_id */ |
5325cc34 MA |
2455 | object_property_set_bool(obj, "x-use-canonical-path-for-ramblock-id", |
2456 | false, &error_fatal); | |
900c0ba3 IM |
2457 | user_creatable_complete(USER_CREATABLE(obj), &error_fatal); |
2458 | object_unref(obj); | |
5325cc34 | 2459 | object_property_set_str(OBJECT(ms), "memory-backend", mc->default_ram_id, |
900c0ba3 IM |
2460 | &error_fatal); |
2461 | } | |
2462 | ||
d8fb7d09 | 2463 | static void qemu_validate_options(const QDict *machine_opts) |
58c91595 | 2464 | { |
d8fb7d09 PB |
2465 | const char *kernel_filename = qdict_get_try_str(machine_opts, "kernel"); |
2466 | const char *initrd_filename = qdict_get_try_str(machine_opts, "initrd"); | |
2467 | const char *kernel_cmdline = qdict_get_try_str(machine_opts, "append"); | |
58c91595 PB |
2468 | |
2469 | if (kernel_filename == NULL) { | |
2470 | if (kernel_cmdline != NULL) { | |
2471 | error_report("-append only allowed with -kernel option"); | |
2472 | exit(1); | |
2473 | } | |
2474 | ||
2475 | if (initrd_filename != NULL) { | |
2476 | error_report("-initrd only allowed with -kernel option"); | |
2477 | exit(1); | |
2478 | } | |
2479 | } | |
2480 | ||
7691bdef | 2481 | if (loadvm && preconfig_requested) { |
90285ec8 PB |
2482 | error_report("'preconfig' and 'loadvm' options are " |
2483 | "mutually exclusive"); | |
2484 | exit(EXIT_FAILURE); | |
2485 | } | |
8fafaa04 PB |
2486 | if (incoming && preconfig_requested && strcmp(incoming, "defer") != 0) { |
2487 | error_report("'preconfig' supports '-incoming defer' only"); | |
58c91595 PB |
2488 | exit(EXIT_FAILURE); |
2489 | } | |
2490 | ||
2491 | #ifdef CONFIG_CURSES | |
2492 | if (is_daemonized() && dpy.type == DISPLAY_TYPE_CURSES) { | |
2493 | error_report("curses display cannot be used with -daemonize"); | |
2494 | exit(1); | |
2495 | } | |
2496 | #endif | |
2497 | } | |
2498 | ||
4d2c17b0 PB |
2499 | static void qemu_process_sugar_options(void) |
2500 | { | |
2501 | if (mem_prealloc) { | |
e4383ca2 PB |
2502 | QObject *smp = qdict_get(machine_opts_dict, "smp"); |
2503 | if (smp && qobject_type(smp) == QTYPE_QDICT) { | |
2504 | QObject *cpus = qdict_get(qobject_to(QDict, smp), "cpus"); | |
2505 | if (cpus && qobject_type(cpus) == QTYPE_QSTRING) { | |
2506 | const char *val = qstring_get_str(qobject_to(QString, cpus)); | |
2507 | object_register_sugar_prop("memory-backend", "prealloc-threads", | |
2508 | val, false); | |
2509 | } | |
2510 | } | |
a8dc82ce | 2511 | object_register_sugar_prop("memory-backend", "prealloc", "on", false); |
4d2c17b0 PB |
2512 | } |
2513 | ||
2514 | if (watchdog) { | |
2515 | int i = select_watchdog(watchdog); | |
2516 | if (i > 0) | |
2517 | exit (i == 1 ? 1 : 0); | |
2518 | } | |
2519 | } | |
2520 | ||
2a5ad60b AJ |
2521 | /* -action processing */ |
2522 | ||
2523 | /* | |
2524 | * Process all the -action parameters parsed from cmdline. | |
2525 | */ | |
2526 | static int process_runstate_actions(void *opaque, QemuOpts *opts, Error **errp) | |
2527 | { | |
2528 | Error *local_err = NULL; | |
2529 | QDict *qdict = qemu_opts_to_qdict(opts, NULL); | |
2530 | QObject *ret = NULL; | |
2531 | qmp_marshal_set_action(qdict, &ret, &local_err); | |
2532 | qobject_unref(ret); | |
2533 | qobject_unref(qdict); | |
2534 | if (local_err) { | |
2535 | error_propagate(errp, local_err); | |
2536 | return 1; | |
2537 | } | |
2538 | return 0; | |
2539 | } | |
2540 | ||
0546c060 PB |
2541 | static void qemu_process_early_options(void) |
2542 | { | |
0546c060 PB |
2543 | #ifdef CONFIG_SECCOMP |
2544 | QemuOptsList *olist = qemu_find_opts_err("sandbox", NULL); | |
2545 | if (olist) { | |
2546 | qemu_opts_foreach(olist, parse_sandbox, NULL, &error_fatal); | |
2547 | } | |
2548 | #endif | |
2549 | ||
2550 | qemu_opts_foreach(qemu_find_opts("name"), | |
2551 | parse_name, NULL, &error_fatal); | |
2552 | ||
2a5ad60b AJ |
2553 | if (qemu_opts_foreach(qemu_find_opts("action"), |
2554 | process_runstate_actions, NULL, &error_fatal)) { | |
2555 | exit(1); | |
2556 | } | |
2557 | ||
0546c060 PB |
2558 | #ifndef _WIN32 |
2559 | qemu_opts_foreach(qemu_find_opts("add-fd"), | |
2560 | parse_add_fd, NULL, &error_fatal); | |
2561 | ||
2562 | qemu_opts_foreach(qemu_find_opts("add-fd"), | |
2563 | cleanup_add_fd, NULL, &error_fatal); | |
2564 | #endif | |
2565 | ||
0546c060 | 2566 | /* Open the logfile at this point and set the log mask if necessary. */ |
b2528af1 RH |
2567 | { |
2568 | int mask = 0; | |
2569 | if (log_mask) { | |
2570 | mask = qemu_str_to_log_mask(log_mask); | |
2571 | if (!mask) { | |
2572 | qemu_print_log_usage(stdout); | |
2573 | exit(1); | |
2574 | } | |
0546c060 | 2575 | } |
b2528af1 | 2576 | qemu_set_log_filename_flags(log_file, mask, &error_fatal); |
0546c060 PB |
2577 | } |
2578 | ||
2c65db5e | 2579 | qemu_add_default_firmwarepath(); |
0546c060 PB |
2580 | } |
2581 | ||
2582 | static void qemu_process_help_options(void) | |
2583 | { | |
0546c060 PB |
2584 | /* |
2585 | * Check for -cpu help and -device help before we call select_machine(), | |
2586 | * which will return an error if the architecture has no default machine | |
2587 | * type and the user did not specify one, so that the user doesn't need | |
2588 | * to say '-cpu help -machine something'. | |
2589 | */ | |
2590 | if (cpu_option && is_help_option(cpu_option)) { | |
2591 | list_cpus(cpu_option); | |
2592 | exit(0); | |
2593 | } | |
2594 | ||
2595 | if (qemu_opts_foreach(qemu_find_opts("device"), | |
2596 | device_help_func, NULL, NULL)) { | |
2597 | exit(0); | |
2598 | } | |
2599 | ||
2600 | /* -L help lists the data directories and exits. */ | |
2601 | if (list_data_dirs) { | |
2c65db5e | 2602 | qemu_list_data_dirs(); |
0546c060 PB |
2603 | exit(0); |
2604 | } | |
2605 | } | |
2606 | ||
2607 | static void qemu_maybe_daemonize(const char *pid_file) | |
2608 | { | |
38f71349 | 2609 | Error *err = NULL; |
0546c060 PB |
2610 | |
2611 | os_daemonize(); | |
2612 | rcu_disable_atfork(); | |
2613 | ||
2614 | if (pid_file && !qemu_write_pidfile(pid_file, &err)) { | |
2615 | error_reportf_err(err, "cannot create PID file: "); | |
2616 | exit(1); | |
2617 | } | |
2618 | ||
2619 | qemu_unlink_pidfile_notifier.notify = qemu_unlink_pidfile; | |
2620 | qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier); | |
2621 | } | |
2622 | ||
7691bdef PB |
2623 | static void qemu_init_displays(void) |
2624 | { | |
2625 | DisplayState *ds; | |
2626 | ||
2627 | /* init local displays */ | |
2628 | ds = init_displaystate(); | |
2629 | qemu_display_init(ds, &dpy); | |
2630 | ||
2631 | /* must be after terminal init, SDL library changes signal handlers */ | |
2632 | os_setup_signal_handling(); | |
2633 | ||
2634 | /* init remote displays */ | |
2635 | #ifdef CONFIG_VNC | |
2636 | qemu_opts_foreach(qemu_find_opts("vnc"), | |
2637 | vnc_init_func, NULL, &error_fatal); | |
2638 | #endif | |
2639 | ||
2640 | if (using_spice) { | |
2641 | qemu_spice.display_init(); | |
2642 | } | |
2643 | } | |
2644 | ||
d8e4de41 PB |
2645 | static void qemu_init_board(void) |
2646 | { | |
2647 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
2648 | ||
2649 | if (machine_class->default_ram_id && current_machine->ram_size && | |
2650 | numa_uses_legacy_mem() && !current_machine->ram_memdev_id) { | |
2651 | create_default_memdev(current_machine, mem_path); | |
2652 | } | |
2653 | ||
8a745974 | 2654 | /* process plugin before CPUs are created, but once -smp has been parsed */ |
0572f558 | 2655 | qemu_plugin_load_list(&plugin_list, &error_fatal); |
8a745974 | 2656 | |
2f181fbd | 2657 | /* From here on we enter MACHINE_PHASE_INITIALIZED. */ |
d8e4de41 PB |
2658 | machine_run_board_init(current_machine); |
2659 | ||
fe9f70a1 | 2660 | drive_check_orphaned(); |
d8e4de41 PB |
2661 | |
2662 | realtime_init(); | |
2663 | ||
2664 | if (hax_enabled()) { | |
2665 | /* FIXME: why isn't cpu_synchronize_all_post_init enough? */ | |
2666 | hax_sync_vcpus(); | |
2667 | } | |
2668 | } | |
2669 | ||
2670 | static void qemu_create_cli_devices(void) | |
2671 | { | |
5dacda51 KW |
2672 | DeviceOption *opt; |
2673 | ||
d8e4de41 PB |
2674 | soundhw_init(); |
2675 | ||
2676 | qemu_opts_foreach(qemu_find_opts("fw_cfg"), | |
2677 | parse_fw_cfg, fw_cfg_find(), &error_fatal); | |
2678 | ||
2679 | /* init USB devices */ | |
2680 | if (machine_usb(current_machine)) { | |
2681 | if (foreach_device_config(DEV_USB, usb_parse) < 0) | |
2682 | exit(1); | |
2683 | } | |
2684 | ||
2685 | /* init generic devices */ | |
2686 | rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); | |
2687 | qemu_opts_foreach(qemu_find_opts("device"), | |
2688 | device_init_func, NULL, &error_fatal); | |
5dacda51 | 2689 | QTAILQ_FOREACH(opt, &device_opts, next) { |
64b4529a | 2690 | DeviceState *dev; |
5dacda51 KW |
2691 | loc_push_restore(&opt->loc); |
2692 | /* | |
2693 | * TODO Eventually we should call qmp_device_add() here to make sure it | |
2694 | * behaves the same, but QMP still has to accept incorrectly typed | |
2695 | * options until libvirt is fixed and we want to be strict on the CLI | |
2696 | * from the start, so call qdev_device_add_from_qdict() directly for | |
2697 | * now. | |
2698 | */ | |
64b4529a DB |
2699 | dev = qdev_device_add_from_qdict(opt->opts, true, &error_fatal); |
2700 | object_unref(OBJECT(dev)); | |
5dacda51 KW |
2701 | loc_pop(&opt->loc); |
2702 | } | |
d8e4de41 PB |
2703 | rom_reset_order_override(); |
2704 | } | |
2705 | ||
2706 | static void qemu_machine_creation_done(void) | |
2707 | { | |
abc27d42 DG |
2708 | MachineState *machine = MACHINE(qdev_get_machine()); |
2709 | ||
d8e4de41 PB |
2710 | /* Did we create any drives that we failed to create a device for? */ |
2711 | drive_check_orphaned(); | |
2712 | ||
2713 | /* Don't warn about the default network setup that you get if | |
2714 | * no command line -net or -netdev options are specified. There | |
2715 | * are two cases that we would otherwise complain about: | |
2716 | * (1) board doesn't support a NIC but the implicit "-net nic" | |
2717 | * requested one | |
2718 | * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic" | |
2719 | * sets up a nic that isn't connected to anything. | |
2720 | */ | |
2721 | if (!default_net && (!qtest_enabled() || has_defaults)) { | |
2722 | net_check_clients(); | |
2723 | } | |
2724 | ||
cca686b4 PB |
2725 | qdev_prop_check_globals(); |
2726 | ||
d8e4de41 PB |
2727 | qdev_machine_creation_done(); |
2728 | ||
abc27d42 DG |
2729 | if (machine->cgs) { |
2730 | /* | |
2731 | * Verify that Confidential Guest Support has actually been initialized | |
2732 | */ | |
2733 | assert(machine->cgs->ready); | |
2734 | } | |
2735 | ||
f66dc873 | 2736 | if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) { |
d8e4de41 PB |
2737 | exit(1); |
2738 | } | |
d8e4de41 PB |
2739 | } |
2740 | ||
b4e1a342 PB |
2741 | void qmp_x_exit_preconfig(Error **errp) |
2742 | { | |
2f181fbd | 2743 | if (phase_check(PHASE_MACHINE_INITIALIZED)) { |
b4e1a342 PB |
2744 | error_setg(errp, "The command is permitted only before machine initialization"); |
2745 | return; | |
2746 | } | |
2747 | ||
2748 | qemu_init_board(); | |
2749 | qemu_create_cli_devices(); | |
2750 | qemu_machine_creation_done(); | |
2751 | ||
2752 | if (loadvm) { | |
f9734d5d | 2753 | load_snapshot(loadvm, NULL, false, NULL, &error_fatal); |
b4e1a342 PB |
2754 | } |
2755 | if (replay_mode != REPLAY_MODE_NONE) { | |
2756 | replay_vmstate_init(); | |
2757 | } | |
2758 | ||
2759 | if (incoming) { | |
2760 | Error *local_err = NULL; | |
2761 | if (strcmp(incoming, "defer") != 0) { | |
2762 | qmp_migrate_incoming(incoming, &local_err); | |
2763 | if (local_err) { | |
2764 | error_reportf_err(local_err, "-incoming %s: ", incoming); | |
2765 | exit(1); | |
2766 | } | |
2767 | } | |
2768 | } else if (autostart) { | |
2769 | qmp_cont(NULL); | |
2770 | } | |
2771 | } | |
2772 | ||
7b733862 | 2773 | void qemu_init(int argc, char **argv, char **envp) |
0824d6fc | 2774 | { |
7a84268d | 2775 | QemuOpts *opts; |
d1cdd92e | 2776 | QemuOpts *icount_opts = NULL, *accel_opts = NULL; |
03b0ba70 | 2777 | QemuOptsList *olist; |
cd6f1169 | 2778 | int optind; |
6530a97b | 2779 | const char *optarg; |
0056ae24 | 2780 | MachineClass *machine_class; |
f29a5614 | 2781 | bool userconfig = true; |
abfd9ce3 | 2782 | FILE *vmstate_dump_file = NULL; |
0b5538c3 | 2783 | |
4d454574 | 2784 | qemu_add_opts(&qemu_drive_opts); |
968854c8 AK |
2785 | qemu_add_drive_opts(&qemu_legacy_drive_opts); |
2786 | qemu_add_drive_opts(&qemu_common_drive_opts); | |
2787 | qemu_add_drive_opts(&qemu_drive_opts); | |
c5f3014b | 2788 | qemu_add_drive_opts(&bdrv_runtime_opts); |
4d454574 PB |
2789 | qemu_add_opts(&qemu_chardev_opts); |
2790 | qemu_add_opts(&qemu_device_opts); | |
2791 | qemu_add_opts(&qemu_netdev_opts); | |
78cd6f7b | 2792 | qemu_add_opts(&qemu_nic_opts); |
4d454574 PB |
2793 | qemu_add_opts(&qemu_net_opts); |
2794 | qemu_add_opts(&qemu_rtc_opts); | |
2795 | qemu_add_opts(&qemu_global_opts); | |
2796 | qemu_add_opts(&qemu_mon_opts); | |
2797 | qemu_add_opts(&qemu_trace_opts); | |
42229a75 | 2798 | qemu_plugin_add_opts(); |
4d454574 | 2799 | qemu_add_opts(&qemu_option_rom_opts); |
8d4e9146 | 2800 | qemu_add_opts(&qemu_accel_opts); |
6e1d3c1c | 2801 | qemu_add_opts(&qemu_mem_opts); |
12b7f57e | 2802 | qemu_add_opts(&qemu_smp_opts); |
4d454574 | 2803 | qemu_add_opts(&qemu_boot_opts); |
4d454574 PB |
2804 | qemu_add_opts(&qemu_add_fd_opts); |
2805 | qemu_add_opts(&qemu_object_opts); | |
d1a0cf73 | 2806 | qemu_add_opts(&qemu_tpmdev_opts); |
1fdd4748 | 2807 | qemu_add_opts(&qemu_overcommit_opts); |
5e2ac519 | 2808 | qemu_add_opts(&qemu_msg_opts); |
5d12f961 | 2809 | qemu_add_opts(&qemu_name_opts); |
0042109a | 2810 | qemu_add_opts(&qemu_numa_opts); |
1ad9580b | 2811 | qemu_add_opts(&qemu_icount_opts); |
a38bb079 | 2812 | qemu_add_opts(&qemu_semihosting_config_opts); |
81b2b810 | 2813 | qemu_add_opts(&qemu_fw_cfg_opts); |
2a5ad60b | 2814 | qemu_add_opts(&qemu_action_opts); |
34294e2f | 2815 | module_call_init(MODULE_INIT_OPTS); |
4d454574 | 2816 | |
efd7ab22 PB |
2817 | error_init(argv[0]); |
2818 | qemu_init_exec_dir(argv[0]); | |
142c6b1a | 2819 | |
c80cafa0 | 2820 | qemu_init_arch_modules(); |
5ebbfecc | 2821 | |
efd7ab22 | 2822 | qemu_init_subsystems(); |
41bd639b | 2823 | |
292444cb AL |
2824 | /* first pass of option parsing */ |
2825 | optind = 1; | |
2826 | while (optind < argc) { | |
2827 | if (argv[optind][0] != '-') { | |
2828 | /* disk image */ | |
28e68d68 | 2829 | optind++; |
292444cb AL |
2830 | } else { |
2831 | const QEMUOption *popt; | |
2832 | ||
2833 | popt = lookup_opt(argc, argv, &optarg, &optind); | |
2834 | switch (popt->index) { | |
f29a5614 EH |
2835 | case QEMU_OPTION_nouserconfig: |
2836 | userconfig = false; | |
2837 | break; | |
292444cb AL |
2838 | } |
2839 | } | |
2840 | } | |
2841 | ||
d8fb7d09 | 2842 | machine_opts_dict = qdict_new(); |
1ea06c39 | 2843 | if (userconfig) { |
f7544edc | 2844 | qemu_read_default_config_file(&error_fatal); |
292444cb AL |
2845 | } |
2846 | ||
2847 | /* second pass of option parsing */ | |
cd6f1169 | 2848 | optind = 1; |
0824d6fc | 2849 | for(;;) { |
cd6f1169 | 2850 | if (optind >= argc) |
0824d6fc | 2851 | break; |
6530a97b | 2852 | if (argv[optind][0] != '-') { |
17f30eae | 2853 | loc_set_cmdline(argv, optind, 1); |
d1cdd92e | 2854 | drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS); |
cd6f1169 FB |
2855 | } else { |
2856 | const QEMUOption *popt; | |
2857 | ||
6530a97b | 2858 | popt = lookup_opt(argc, argv, &optarg, &optind); |
ad96090a | 2859 | if (!(popt->arch_mask & arch_type)) { |
da002526 | 2860 | error_report("Option not supported for this target"); |
ad96090a BS |
2861 | exit(1); |
2862 | } | |
cd6f1169 | 2863 | switch(popt->index) { |
94fc95cd JM |
2864 | case QEMU_OPTION_cpu: |
2865 | /* hw initialization will check this */ | |
c1c8cfe5 | 2866 | cpu_option = optarg; |
94fc95cd | 2867 | break; |
cd6f1169 | 2868 | case QEMU_OPTION_hda: |
cd6f1169 | 2869 | case QEMU_OPTION_hdb: |
cc1daa40 FB |
2870 | case QEMU_OPTION_hdc: |
2871 | case QEMU_OPTION_hdd: | |
2292ddae MA |
2872 | drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg, |
2873 | HD_OPTS); | |
fc01f7e7 | 2874 | break; |
42e5f393 MA |
2875 | case QEMU_OPTION_blockdev: |
2876 | { | |
2877 | Visitor *v; | |
651af51c | 2878 | BlockdevOptionsQueueEntry *bdo; |
42e5f393 | 2879 | |
92917cd2 MA |
2880 | v = qobject_input_visitor_new_str(optarg, "driver", |
2881 | &error_fatal); | |
42e5f393 | 2882 | |
651af51c | 2883 | bdo = g_new(BlockdevOptionsQueueEntry, 1); |
42e5f393 MA |
2884 | visit_type_BlockdevOptions(v, NULL, &bdo->bdo, |
2885 | &error_fatal); | |
2886 | visit_free(v); | |
2887 | loc_save(&bdo->loc); | |
2888 | QSIMPLEQ_INSERT_TAIL(&bdo_queue, bdo, entry); | |
2889 | break; | |
2890 | } | |
e4bcb14c | 2891 | case QEMU_OPTION_drive: |
cc67f28e EGE |
2892 | opts = qemu_opts_parse_noisily(qemu_find_opts("drive"), |
2893 | optarg, false); | |
2894 | if (opts == NULL) { | |
e2982c3a MT |
2895 | exit(1); |
2896 | } | |
99efa84d | 2897 | break; |
d058fe03 | 2898 | case QEMU_OPTION_set: |
c0d4aa82 | 2899 | qemu_set_option(optarg, &error_fatal); |
99efa84d | 2900 | break; |
d0fef6fb GH |
2901 | case QEMU_OPTION_global: |
2902 | if (qemu_global_option(optarg) != 0) | |
2903 | exit(1); | |
99efa84d | 2904 | break; |
3e3d5815 | 2905 | case QEMU_OPTION_mtdblock: |
2292ddae | 2906 | drive_add(IF_MTD, -1, optarg, MTD_OPTS); |
3e3d5815 | 2907 | break; |
a1bb27b1 | 2908 | case QEMU_OPTION_sd: |
80f4d9fc | 2909 | drive_add(IF_SD, -1, optarg, SD_OPTS); |
a1bb27b1 | 2910 | break; |
86f55663 | 2911 | case QEMU_OPTION_pflash: |
2292ddae | 2912 | drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS); |
86f55663 | 2913 | break; |
cd6f1169 | 2914 | case QEMU_OPTION_snapshot: |
25863975 PD |
2915 | { |
2916 | Error *blocker = NULL; | |
2917 | snapshot = 1; | |
2918 | error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, | |
2919 | "-snapshot"); | |
2920 | replay_add_blocker(blocker); | |
2921 | } | |
33e3963e | 2922 | break; |
268a362c | 2923 | case QEMU_OPTION_numa: |
70b94331 MA |
2924 | opts = qemu_opts_parse_noisily(qemu_find_opts("numa"), |
2925 | optarg, true); | |
0042109a WG |
2926 | if (!opts) { |
2927 | exit(1); | |
2928 | } | |
268a362c | 2929 | break; |
1472a95b | 2930 | case QEMU_OPTION_display: |
e3af9f9a | 2931 | parse_display(optarg); |
1472a95b | 2932 | break; |
cd6f1169 | 2933 | case QEMU_OPTION_nographic: |
d8fb7d09 | 2934 | qdict_put_str(machine_opts_dict, "graphics", "off"); |
cfc58cf3 | 2935 | nographic = true; |
0c8d7065 | 2936 | dpy.type = DISPLAY_TYPE_NONE; |
a20dd508 | 2937 | break; |
4d3b6f6e | 2938 | case QEMU_OPTION_curses: |
6695e4c0 TH |
2939 | warn_report("-curses is deprecated, " |
2940 | "use -display curses instead."); | |
47b05369 | 2941 | #ifdef CONFIG_CURSES |
14f130fa | 2942 | dpy.type = DISPLAY_TYPE_CURSES; |
47b05369 | 2943 | #else |
e08bb301 | 2944 | error_report("curses or iconv support is disabled"); |
47b05369 | 2945 | exit(1); |
4d3b6f6e | 2946 | #endif |
47b05369 | 2947 | break; |
a171fe39 | 2948 | case QEMU_OPTION_portrait: |
9312805d VK |
2949 | graphic_rotate = 90; |
2950 | break; | |
2951 | case QEMU_OPTION_rotate: | |
2952 | graphic_rotate = strtol(optarg, (char **) &optarg, 10); | |
2953 | if (graphic_rotate != 0 && graphic_rotate != 90 && | |
2954 | graphic_rotate != 180 && graphic_rotate != 270) { | |
f61eddcb | 2955 | error_report("only 90, 180, 270 deg rotation is available"); |
9312805d VK |
2956 | exit(1); |
2957 | } | |
a171fe39 | 2958 | break; |
cd6f1169 | 2959 | case QEMU_OPTION_kernel: |
d8fb7d09 | 2960 | qdict_put_str(machine_opts_dict, "kernel", optarg); |
a0abe474 PM |
2961 | break; |
2962 | case QEMU_OPTION_initrd: | |
d8fb7d09 | 2963 | qdict_put_str(machine_opts_dict, "initrd", optarg); |
a20dd508 | 2964 | break; |
cd6f1169 | 2965 | case QEMU_OPTION_append: |
d8fb7d09 | 2966 | qdict_put_str(machine_opts_dict, "append", optarg); |
313aa567 | 2967 | break; |
412beee6 | 2968 | case QEMU_OPTION_dtb: |
d8fb7d09 | 2969 | qdict_put_str(machine_opts_dict, "dtb", optarg); |
412beee6 | 2970 | break; |
cd6f1169 | 2971 | case QEMU_OPTION_cdrom: |
2292ddae | 2972 | drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS); |
36b486bb | 2973 | break; |
cd6f1169 | 2974 | case QEMU_OPTION_boot: |
70b94331 MA |
2975 | opts = qemu_opts_parse_noisily(qemu_find_opts("boot-opts"), |
2976 | optarg, true); | |
8281abd5 MA |
2977 | if (!opts) { |
2978 | exit(1); | |
36b486bb FB |
2979 | } |
2980 | break; | |
cd6f1169 | 2981 | case QEMU_OPTION_fda: |
cd6f1169 | 2982 | case QEMU_OPTION_fdb: |
2292ddae MA |
2983 | drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda, |
2984 | optarg, FD_OPTS); | |
c45886db | 2985 | break; |
52ca8d6a FB |
2986 | case QEMU_OPTION_no_fd_bootchk: |
2987 | fd_bootchk = 0; | |
2988 | break; | |
a1ea458f | 2989 | case QEMU_OPTION_netdev: |
d30300f7 | 2990 | default_net = 0; |
3329f07b | 2991 | if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) { |
a1ea458f MM |
2992 | exit(1); |
2993 | } | |
2994 | break; | |
78cd6f7b TH |
2995 | case QEMU_OPTION_nic: |
2996 | default_net = 0; | |
2997 | if (net_client_parse(qemu_find_opts("nic"), optarg) == -1) { | |
2998 | exit(1); | |
2999 | } | |
3000 | break; | |
7c9d8e07 | 3001 | case QEMU_OPTION_net: |
d30300f7 | 3002 | default_net = 0; |
3329f07b | 3003 | if (net_client_parse(qemu_find_opts("net"), optarg) == -1) { |
c4b1fcc0 FB |
3004 | exit(1); |
3005 | } | |
702c651c | 3006 | break; |
f9dadc98 RS |
3007 | #ifdef CONFIG_LIBISCSI |
3008 | case QEMU_OPTION_iscsi: | |
70b94331 MA |
3009 | opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"), |
3010 | optarg, false); | |
f9dadc98 RS |
3011 | if (!opts) { |
3012 | exit(1); | |
3013 | } | |
3014 | break; | |
c7f74643 | 3015 | #endif |
1d14ffa9 | 3016 | case QEMU_OPTION_audio_help: |
71830221 | 3017 | audio_legacy_help(); |
1d14ffa9 FB |
3018 | exit (0); |
3019 | break; | |
71830221 KZ |
3020 | case QEMU_OPTION_audiodev: |
3021 | audio_parse_option(optarg); | |
3022 | break; | |
1d14ffa9 FB |
3023 | case QEMU_OPTION_soundhw: |
3024 | select_soundhw (optarg); | |
3025 | break; | |
cd6f1169 | 3026 | case QEMU_OPTION_h: |
15f82208 | 3027 | help(0); |
cd6f1169 | 3028 | break; |
9bd7e6d9 PB |
3029 | case QEMU_OPTION_version: |
3030 | version(); | |
3031 | exit(0); | |
3032 | break; | |
3b9985e9 | 3033 | case QEMU_OPTION_m: |
70b94331 MA |
3034 | opts = qemu_opts_parse_noisily(qemu_find_opts("memory"), |
3035 | optarg, true); | |
6e1d3c1c IM |
3036 | if (!opts) { |
3037 | exit(EXIT_FAILURE); | |
3038 | } | |
cd6f1169 | 3039 | break; |
d1a0cf73 SB |
3040 | #ifdef CONFIG_TPM |
3041 | case QEMU_OPTION_tpmdev: | |
3042 | if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) { | |
3043 | exit(1); | |
3044 | } | |
3045 | break; | |
3046 | #endif | |
c902760f MT |
3047 | case QEMU_OPTION_mempath: |
3048 | mem_path = optarg; | |
3049 | break; | |
c902760f MT |
3050 | case QEMU_OPTION_mem_prealloc: |
3051 | mem_prealloc = 1; | |
3052 | break; | |
cd6f1169 | 3053 | case QEMU_OPTION_d: |
c235d738 MF |
3054 | log_mask = optarg; |
3055 | break; | |
3056 | case QEMU_OPTION_D: | |
3057 | log_file = optarg; | |
cd6f1169 | 3058 | break; |
3514552e | 3059 | case QEMU_OPTION_DFILTER: |
bd6fee9f | 3060 | qemu_set_dfilter_ranges(optarg, &error_fatal); |
3514552e | 3061 | break; |
9c09a251 RH |
3062 | case QEMU_OPTION_seed: |
3063 | qemu_guest_random_seed_main(optarg, &error_fatal); | |
3064 | break; | |
cd6f1169 | 3065 | case QEMU_OPTION_s: |
ef0c4a0d | 3066 | add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); |
cd6f1169 | 3067 | break; |
59030a8c | 3068 | case QEMU_OPTION_gdb: |
ef0c4a0d | 3069 | add_device_config(DEV_GDB, optarg); |
cd6f1169 | 3070 | break; |
cd6f1169 | 3071 | case QEMU_OPTION_L: |
37146e7e RJ |
3072 | if (is_help_option(optarg)) { |
3073 | list_data_dirs = true; | |
2a1cce90 | 3074 | } else { |
ea1edcd7 | 3075 | qemu_add_data_dir(g_strdup(optarg)); |
4524051c | 3076 | } |
cd6f1169 | 3077 | break; |
1192dad8 | 3078 | case QEMU_OPTION_bios: |
d8fb7d09 | 3079 | qdict_put_str(machine_opts_dict, "firmware", optarg); |
1192dad8 | 3080 | break; |
1b530a6d AJ |
3081 | case QEMU_OPTION_singlestep: |
3082 | singlestep = 1; | |
3083 | break; | |
cd6f1169 | 3084 | case QEMU_OPTION_S: |
3c07f8e8 | 3085 | autostart = 0; |
cd6f1169 | 3086 | break; |
99efa84d MA |
3087 | case QEMU_OPTION_k: |
3088 | keyboard_layout = optarg; | |
3089 | break; | |
3893c124 | 3090 | case QEMU_OPTION_vga: |
a369da5f | 3091 | vga_model = optarg; |
7f1b17f2 | 3092 | default_vga = 0; |
1bfe856e | 3093 | break; |
e9b137c2 FB |
3094 | case QEMU_OPTION_g: |
3095 | { | |
3096 | const char *p; | |
3097 | int w, h, depth; | |
3098 | p = optarg; | |
3099 | w = strtol(p, (char **)&p, 10); | |
3100 | if (w <= 0) { | |
3101 | graphic_error: | |
f61eddcb | 3102 | error_report("invalid resolution or depth"); |
e9b137c2 FB |
3103 | exit(1); |
3104 | } | |
3105 | if (*p != 'x') | |
3106 | goto graphic_error; | |
3107 | p++; | |
3108 | h = strtol(p, (char **)&p, 10); | |
3109 | if (h <= 0) | |
3110 | goto graphic_error; | |
3111 | if (*p == 'x') { | |
3112 | p++; | |
3113 | depth = strtol(p, (char **)&p, 10); | |
8ac919a0 LV |
3114 | if (depth != 1 && depth != 2 && depth != 4 && |
3115 | depth != 8 && depth != 15 && depth != 16 && | |
e9b137c2 FB |
3116 | depth != 24 && depth != 32) |
3117 | goto graphic_error; | |
3118 | } else if (*p == '\0') { | |
3119 | depth = graphic_depth; | |
3120 | } else { | |
3121 | goto graphic_error; | |
3122 | } | |
3b46e624 | 3123 | |
e9b137c2 FB |
3124 | graphic_width = w; |
3125 | graphic_height = h; | |
3126 | graphic_depth = depth; | |
3127 | } | |
3128 | break; | |
20d8a3ed TS |
3129 | case QEMU_OPTION_echr: |
3130 | { | |
3131 | char *r; | |
3132 | term_escape_char = strtol(optarg, &r, 0); | |
3133 | if (r == optarg) | |
3134 | printf("Bad argument to echr\n"); | |
3135 | break; | |
3136 | } | |
82c643ff | 3137 | case QEMU_OPTION_monitor: |
6ca5582d | 3138 | default_monitor = 0; |
70e098af | 3139 | if (strncmp(optarg, "none", 4)) { |
4821cd4c | 3140 | monitor_parse(optarg, "readline", false); |
70e098af | 3141 | } |
6ca5582d GH |
3142 | break; |
3143 | case QEMU_OPTION_qmp: | |
4821cd4c HR |
3144 | monitor_parse(optarg, "control", false); |
3145 | default_monitor = 0; | |
3146 | break; | |
3147 | case QEMU_OPTION_qmp_pretty: | |
3148 | monitor_parse(optarg, "control", true); | |
2d114dc1 | 3149 | default_monitor = 0; |
82c643ff | 3150 | break; |
22a0e04b | 3151 | case QEMU_OPTION_mon: |
70b94331 MA |
3152 | opts = qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg, |
3153 | true); | |
22a0e04b | 3154 | if (!opts) { |
22a0e04b GH |
3155 | exit(1); |
3156 | } | |
2d114dc1 | 3157 | default_monitor = 0; |
22a0e04b | 3158 | break; |
191bc01b | 3159 | case QEMU_OPTION_chardev: |
70b94331 MA |
3160 | opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), |
3161 | optarg, true); | |
191bc01b | 3162 | if (!opts) { |
191bc01b GH |
3163 | exit(1); |
3164 | } | |
191bc01b | 3165 | break; |
74db920c | 3166 | case QEMU_OPTION_fsdev: |
03b0ba70 GH |
3167 | olist = qemu_find_opts("fsdev"); |
3168 | if (!olist) { | |
5dfdae81 | 3169 | error_report("fsdev support is disabled"); |
03b0ba70 GH |
3170 | exit(1); |
3171 | } | |
70b94331 | 3172 | opts = qemu_opts_parse_noisily(olist, optarg, true); |
74db920c | 3173 | if (!opts) { |
74db920c GS |
3174 | exit(1); |
3175 | } | |
3176 | break; | |
3d54abc7 | 3177 | case QEMU_OPTION_virtfs: { |
e14ea479 SH |
3178 | QemuOpts *fsdev; |
3179 | QemuOpts *device; | |
1a6ed33c AM |
3180 | const char *writeout, *sock_fd, *socket, *path, *security_model, |
3181 | *multidevs; | |
3d54abc7 | 3182 | |
03b0ba70 GH |
3183 | olist = qemu_find_opts("virtfs"); |
3184 | if (!olist) { | |
5dfdae81 | 3185 | error_report("virtfs support is disabled"); |
03b0ba70 GH |
3186 | exit(1); |
3187 | } | |
70b94331 | 3188 | opts = qemu_opts_parse_noisily(olist, optarg, true); |
3d54abc7 | 3189 | if (!opts) { |
3d54abc7 GS |
3190 | exit(1); |
3191 | } | |
3192 | ||
fbcbf101 | 3193 | if (qemu_opt_get(opts, "fsdriver") == NULL || |
99519f0a | 3194 | qemu_opt_get(opts, "mount_tag") == NULL) { |
8afb9000 | 3195 | error_report("Usage: -virtfs fsdriver,mount_tag=tag"); |
9ce56db6 VJ |
3196 | exit(1); |
3197 | } | |
e14ea479 | 3198 | fsdev = qemu_opts_create(qemu_find_opts("fsdev"), |
3baa0a6a | 3199 | qemu_opts_id(opts) ?: |
8be7e7e4 LC |
3200 | qemu_opt_get(opts, "mount_tag"), |
3201 | 1, NULL); | |
e14ea479 | 3202 | if (!fsdev) { |
3baa0a6a | 3203 | error_report("duplicate or invalid fsdev id: %s", |
f61eddcb | 3204 | qemu_opt_get(opts, "mount_tag")); |
3d54abc7 GS |
3205 | exit(1); |
3206 | } | |
d3ab98e6 AK |
3207 | |
3208 | writeout = qemu_opt_get(opts, "writeout"); | |
3209 | if (writeout) { | |
3210 | #ifdef CONFIG_SYNC_FILE_RANGE | |
f43e47db | 3211 | qemu_opt_set(fsdev, "writeout", writeout, &error_abort); |
d3ab98e6 | 3212 | #else |
f61eddcb EH |
3213 | error_report("writeout=immediate not supported " |
3214 | "on this platform"); | |
d3ab98e6 AK |
3215 | exit(1); |
3216 | #endif | |
3217 | } | |
f43e47db MA |
3218 | qemu_opt_set(fsdev, "fsdriver", |
3219 | qemu_opt_get(opts, "fsdriver"), &error_abort); | |
32b69436 GK |
3220 | path = qemu_opt_get(opts, "path"); |
3221 | if (path) { | |
3222 | qemu_opt_set(fsdev, "path", path, &error_abort); | |
3223 | } | |
3224 | security_model = qemu_opt_get(opts, "security_model"); | |
3225 | if (security_model) { | |
3226 | qemu_opt_set(fsdev, "security_model", security_model, | |
3227 | &error_abort); | |
3228 | } | |
84a87cc4 MK |
3229 | socket = qemu_opt_get(opts, "socket"); |
3230 | if (socket) { | |
f43e47db | 3231 | qemu_opt_set(fsdev, "socket", socket, &error_abort); |
84a87cc4 | 3232 | } |
4c793dda MK |
3233 | sock_fd = qemu_opt_get(opts, "sock_fd"); |
3234 | if (sock_fd) { | |
f43e47db | 3235 | qemu_opt_set(fsdev, "sock_fd", sock_fd, &error_abort); |
4c793dda | 3236 | } |
e14ea479 | 3237 | |
2c74c2cb | 3238 | qemu_opt_set_bool(fsdev, "readonly", |
cccb7967 MA |
3239 | qemu_opt_get_bool(opts, "readonly", 0), |
3240 | &error_abort); | |
1a6ed33c AM |
3241 | multidevs = qemu_opt_get(opts, "multidevs"); |
3242 | if (multidevs) { | |
3243 | qemu_opt_set(fsdev, "multidevs", multidevs, &error_abort); | |
3244 | } | |
87ea75d5 PC |
3245 | device = qemu_opts_create(qemu_find_opts("device"), NULL, 0, |
3246 | &error_abort); | |
f43e47db | 3247 | qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort); |
e14ea479 | 3248 | qemu_opt_set(device, "fsdev", |
3baa0a6a | 3249 | qemu_opts_id(fsdev), &error_abort); |
e14ea479 | 3250 | qemu_opt_set(device, "mount_tag", |
f43e47db | 3251 | qemu_opt_get(opts, "mount_tag"), &error_abort); |
3d54abc7 GS |
3252 | break; |
3253 | } | |
82c643ff | 3254 | case QEMU_OPTION_serial: |
998bbd74 GH |
3255 | add_device_config(DEV_SERIAL, optarg); |
3256 | default_serial = 0; | |
18141ed6 JK |
3257 | if (strncmp(optarg, "mon:", 4) == 0) { |
3258 | default_monitor = 0; | |
3259 | } | |
82c643ff | 3260 | break; |
9dd986cc | 3261 | case QEMU_OPTION_watchdog: |
09aaa160 | 3262 | if (watchdog) { |
f61eddcb | 3263 | error_report("only one watchdog option may be given"); |
7b733862 | 3264 | exit(1); |
09aaa160 | 3265 | } |
d12b64ea | 3266 | warn_report("-watchdog is deprecated; use -device instead."); |
09aaa160 | 3267 | watchdog = optarg; |
9dd986cc | 3268 | break; |
2a5ad60b AJ |
3269 | case QEMU_OPTION_action: |
3270 | olist = qemu_find_opts("action"); | |
3271 | if (!qemu_opts_parse_noisily(olist, optarg, false)) { | |
3272 | exit(1); | |
3273 | } | |
3274 | break; | |
22afb46e PB |
3275 | case QEMU_OPTION_watchdog_action: { |
3276 | QemuOpts *opts; | |
3277 | opts = qemu_opts_create(qemu_find_opts("action"), NULL, 0, &error_abort); | |
3278 | qemu_opt_set(opts, "watchdog", optarg, &error_abort); | |
9dd986cc | 3279 | break; |
22afb46e | 3280 | } |
6508fe59 | 3281 | case QEMU_OPTION_parallel: |
6a5e8b0e GH |
3282 | add_device_config(DEV_PARALLEL, optarg); |
3283 | default_parallel = 0; | |
18141ed6 JK |
3284 | if (strncmp(optarg, "mon:", 4) == 0) { |
3285 | default_monitor = 0; | |
3286 | } | |
6508fe59 | 3287 | break; |
c9f398e5 PA |
3288 | case QEMU_OPTION_debugcon: |
3289 | add_device_config(DEV_DEBUGCON, optarg); | |
3290 | break; | |
99efa84d MA |
3291 | case QEMU_OPTION_loadvm: |
3292 | loadvm = optarg; | |
3293 | break; | |
d63d307f | 3294 | case QEMU_OPTION_full_screen: |
0c8d7065 GH |
3295 | dpy.has_full_screen = true; |
3296 | dpy.full_screen = true; | |
d63d307f | 3297 | break; |
3780e197 TS |
3298 | case QEMU_OPTION_alt_grab: |
3299 | alt_grab = 1; | |
d46156fd TH |
3300 | warn_report("-alt-grab is deprecated, please use " |
3301 | "-display sdl,grab-mod=lshift-lctrl-lalt instead."); | |
3780e197 | 3302 | break; |
0ca9f8a4 DK |
3303 | case QEMU_OPTION_ctrl_grab: |
3304 | ctrl_grab = 1; | |
d46156fd TH |
3305 | warn_report("-ctrl-grab is deprecated, please use " |
3306 | "-display sdl,grab-mod=rctrl instead."); | |
0ca9f8a4 | 3307 | break; |
7d957bd8 | 3308 | case QEMU_OPTION_sdl: |
6695e4c0 | 3309 | warn_report("-sdl is deprecated, use -display sdl instead."); |
24f6ff86 | 3310 | #ifdef CONFIG_SDL |
fe91f36a | 3311 | dpy.type = DISPLAY_TYPE_SDL; |
7d957bd8 | 3312 | break; |
58fc096c | 3313 | #else |
f61eddcb | 3314 | error_report("SDL support is disabled"); |
58fc096c | 3315 | exit(1); |
667accab | 3316 | #endif |
f7cce898 | 3317 | case QEMU_OPTION_pidfile: |
93815bc2 | 3318 | pid_file = optarg; |
f7cce898 | 3319 | break; |
a09db21f FB |
3320 | case QEMU_OPTION_win2k_hack: |
3321 | win2k_install_hack = 1; | |
3322 | break; | |
8a92ea2f | 3323 | case QEMU_OPTION_acpitable: |
70b94331 MA |
3324 | opts = qemu_opts_parse_noisily(qemu_find_opts("acpi"), |
3325 | optarg, true); | |
f46e720a LE |
3326 | if (!opts) { |
3327 | exit(1); | |
3328 | } | |
9f57061c | 3329 | acpi_table_add(opts, &error_fatal); |
8a92ea2f | 3330 | break; |
b6f6e3d3 | 3331 | case QEMU_OPTION_smbios: |
70b94331 MA |
3332 | opts = qemu_opts_parse_noisily(qemu_find_opts("smbios"), |
3333 | optarg, false); | |
f46e720a LE |
3334 | if (!opts) { |
3335 | exit(1); | |
3336 | } | |
1007a37e | 3337 | smbios_entry_add(opts, &error_fatal); |
b6f6e3d3 | 3338 | break; |
81b2b810 | 3339 | case QEMU_OPTION_fwcfg: |
70b94331 MA |
3340 | opts = qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"), |
3341 | optarg, true); | |
81b2b810 GS |
3342 | if (opts == NULL) { |
3343 | exit(1); | |
3344 | } | |
3345 | break; | |
047f7038 | 3346 | case QEMU_OPTION_preconfig: |
7691bdef | 3347 | preconfig_requested = true; |
047f7038 | 3348 | break; |
7ba1e619 | 3349 | case QEMU_OPTION_enable_kvm: |
d8fb7d09 | 3350 | qdict_put_str(machine_opts_dict, "accel", "kvm"); |
303d4e86 | 3351 | break; |
364c3e6b | 3352 | case QEMU_OPTION_M: |
303d4e86 | 3353 | case QEMU_OPTION_machine: |
d8fb7d09 PB |
3354 | { |
3355 | bool help; | |
3356 | ||
3357 | keyval_parse_into(machine_opts_dict, optarg, "type", &help, &error_fatal); | |
3358 | if (help) { | |
3359 | machine_help_func(machine_opts_dict); | |
3360 | exit(EXIT_SUCCESS); | |
3361 | } | |
3362 | break; | |
303d4e86 | 3363 | } |
a20fa79f | 3364 | case QEMU_OPTION_accel: |
8d4e9146 FK |
3365 | accel_opts = qemu_opts_parse_noisily(qemu_find_opts("accel"), |
3366 | optarg, true); | |
3367 | optarg = qemu_opt_get(accel_opts, "accel"); | |
bde4d920 | 3368 | if (!optarg || is_help_option(optarg)) { |
cbe6d636 WSM |
3369 | printf("Accelerators supported in QEMU binary:\n"); |
3370 | GSList *el, *accel_list = object_class_get_list(TYPE_ACCEL, | |
3371 | false); | |
3372 | for (el = accel_list; el; el = el->next) { | |
3373 | gchar *typename = g_strdup(object_class_get_name( | |
3374 | OBJECT_CLASS(el->data))); | |
3375 | /* omit qtest which is used for tests only */ | |
3376 | if (g_strcmp0(typename, ACCEL_CLASS_NAME("qtest")) && | |
3377 | g_str_has_suffix(typename, ACCEL_CLASS_SUFFIX)) { | |
3378 | gchar **optname = g_strsplit(typename, | |
3379 | ACCEL_CLASS_SUFFIX, 0); | |
3380 | printf("%s\n", optname[0]); | |
4903602e | 3381 | g_strfreev(optname); |
cbe6d636 WSM |
3382 | } |
3383 | g_free(typename); | |
3384 | } | |
3385 | g_slist_free(accel_list); | |
a20fa79f | 3386 | exit(0); |
8d4e9146 FK |
3387 | } |
3388 | break; | |
bb36d470 | 3389 | case QEMU_OPTION_usb: |
d8fb7d09 | 3390 | qdict_put_str(machine_opts_dict, "usb", "on"); |
bb36d470 | 3391 | break; |
a594cfbf | 3392 | case QEMU_OPTION_usbdevice: |
d8fb7d09 | 3393 | qdict_put_str(machine_opts_dict, "usb", "on"); |
bd3c948d GH |
3394 | add_device_config(DEV_USB, optarg); |
3395 | break; | |
3396 | case QEMU_OPTION_device: | |
5dacda51 KW |
3397 | if (optarg[0] == '{') { |
3398 | QObject *obj = qobject_from_json(optarg, &error_fatal); | |
3399 | DeviceOption *opt = g_new0(DeviceOption, 1); | |
3400 | opt->opts = qobject_to(QDict, obj); | |
3401 | loc_save(&opt->loc); | |
3402 | assert(opt->opts != NULL); | |
3403 | QTAILQ_INSERT_TAIL(&device_opts, opt, next); | |
3404 | } else { | |
3405 | if (!qemu_opts_parse_noisily(qemu_find_opts("device"), | |
3406 | optarg, true)) { | |
3407 | exit(1); | |
3408 | } | |
f31d07d1 | 3409 | } |
a594cfbf | 3410 | break; |
6a00d601 | 3411 | case QEMU_OPTION_smp: |
f9dfae9c MA |
3412 | machine_parse_property_opt(qemu_find_opts("smp-opts"), |
3413 | "smp", optarg); | |
6a00d601 | 3414 | break; |
99efa84d | 3415 | case QEMU_OPTION_vnc: |
653c9747 | 3416 | vnc_parse(optarg); |
821601ea | 3417 | break; |
6515b203 | 3418 | case QEMU_OPTION_no_acpi: |
d8fb7d09 | 3419 | qdict_put_str(machine_opts_dict, "acpi", "off"); |
6515b203 | 3420 | break; |
16b29ae1 | 3421 | case QEMU_OPTION_no_hpet: |
d8fb7d09 | 3422 | qdict_put_str(machine_opts_dict, "hpet", "off"); |
16b29ae1 | 3423 | break; |
d1beab82 | 3424 | case QEMU_OPTION_no_reboot: |
2a5ad60b AJ |
3425 | olist = qemu_find_opts("action"); |
3426 | qemu_opts_parse_noisily(olist, "reboot=shutdown", false); | |
d1beab82 | 3427 | break; |
b2f76161 | 3428 | case QEMU_OPTION_no_shutdown: |
2a5ad60b | 3429 | olist = qemu_find_opts("action"); |
c27025e0 | 3430 | qemu_opts_parse_noisily(olist, "shutdown=pause", false); |
b2f76161 | 3431 | break; |
8fcb1b90 | 3432 | case QEMU_OPTION_uuid: |
9c5ce8db | 3433 | if (qemu_uuid_parse(optarg, &qemu_uuid) < 0) { |
4cd70f34 | 3434 | error_report("failed to parse UUID string: wrong format"); |
8fcb1b90 BS |
3435 | exit(1); |
3436 | } | |
fc3b3295 | 3437 | qemu_uuid_set = true; |
8fcb1b90 | 3438 | break; |
99efa84d MA |
3439 | case QEMU_OPTION_option_rom: |
3440 | if (nb_option_roms >= MAX_OPTION_ROMS) { | |
3e515373 | 3441 | error_report("too many option ROMs"); |
99efa84d MA |
3442 | exit(1); |
3443 | } | |
70b94331 MA |
3444 | opts = qemu_opts_parse_noisily(qemu_find_opts("option-rom"), |
3445 | optarg, true); | |
49295ebc MA |
3446 | if (!opts) { |
3447 | exit(1); | |
3448 | } | |
2e55e842 GN |
3449 | option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile"); |
3450 | option_rom[nb_option_roms].bootindex = | |
3451 | qemu_opt_get_number(opts, "bootindex", -1); | |
3452 | if (!option_rom[nb_option_roms].name) { | |
f61eddcb | 3453 | error_report("Option ROM file is not specified"); |
2e55e842 GN |
3454 | exit(1); |
3455 | } | |
99efa84d MA |
3456 | nb_option_roms++; |
3457 | break; | |
8e71621f | 3458 | case QEMU_OPTION_semihosting: |
f1672e6f | 3459 | qemu_semihosting_enable(); |
a38bb079 LI |
3460 | break; |
3461 | case QEMU_OPTION_semihosting_config: | |
f1672e6f | 3462 | if (qemu_semihosting_config_options(optarg) != 0) { |
a38bb079 LI |
3463 | exit(1); |
3464 | } | |
8e71621f | 3465 | break; |
c35734b2 | 3466 | case QEMU_OPTION_name: |
70b94331 MA |
3467 | opts = qemu_opts_parse_noisily(qemu_find_opts("name"), |
3468 | optarg, true); | |
5d12f961 DDAG |
3469 | if (!opts) { |
3470 | exit(1); | |
3471 | } | |
2880ffb0 MS |
3472 | /* Capture guest name if -msg guest-name is used later */ |
3473 | error_guest_name = qemu_opt_get(opts, "guest"); | |
c35734b2 | 3474 | break; |
66508601 BS |
3475 | case QEMU_OPTION_prom_env: |
3476 | if (nb_prom_envs >= MAX_PROM_ENVS) { | |
3e515373 | 3477 | error_report("too many prom variables"); |
66508601 BS |
3478 | exit(1); |
3479 | } | |
3480 | prom_envs[nb_prom_envs] = optarg; | |
3481 | nb_prom_envs++; | |
3482 | break; | |
2b8f2d41 AZ |
3483 | case QEMU_OPTION_old_param: |
3484 | old_param = 1; | |
05ebd537 | 3485 | break; |
1ed2fc1f | 3486 | case QEMU_OPTION_rtc: |
70b94331 MA |
3487 | opts = qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg, |
3488 | false); | |
1ed2fc1f | 3489 | if (!opts) { |
1ed2fc1f | 3490 | exit(1); |
7e0af5d0 FB |
3491 | } |
3492 | break; | |
2e70f6ef | 3493 | case QEMU_OPTION_icount: |
70b94331 MA |
3494 | icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"), |
3495 | optarg, true); | |
1ad9580b ST |
3496 | if (!icount_opts) { |
3497 | exit(1); | |
3498 | } | |
2e70f6ef | 3499 | break; |
5bb7910a | 3500 | case QEMU_OPTION_incoming: |
7c76235a DDAG |
3501 | if (!incoming) { |
3502 | runstate_set(RUN_STATE_INMIGRATE); | |
3503 | } | |
5bb7910a AL |
3504 | incoming = optarg; |
3505 | break; | |
d15c05fc | 3506 | case QEMU_OPTION_only_migratable: |
811f8652 | 3507 | only_migratable = 1; |
d15c05fc | 3508 | break; |
d8c208dd | 3509 | case QEMU_OPTION_nodefaults: |
d44229c5 | 3510 | has_defaults = 0; |
d8c208dd | 3511 | break; |
e37630ca | 3512 | case QEMU_OPTION_xen_domid: |
6773fbf8 | 3513 | if (!(accel_find("xen"))) { |
da002526 | 3514 | error_report("Option not supported for this target"); |
ad96090a BS |
3515 | exit(1); |
3516 | } | |
e37630ca AL |
3517 | xen_domid = atoi(optarg); |
3518 | break; | |
e37630ca | 3519 | case QEMU_OPTION_xen_attach: |
6773fbf8 | 3520 | if (!(accel_find("xen"))) { |
da002526 | 3521 | error_report("Option not supported for this target"); |
ad96090a BS |
3522 | exit(1); |
3523 | } | |
e37630ca AL |
3524 | xen_mode = XEN_ATTACH; |
3525 | break; | |
1c599472 | 3526 | case QEMU_OPTION_xen_domid_restrict: |
6773fbf8 | 3527 | if (!(accel_find("xen"))) { |
1c599472 PD |
3528 | error_report("Option not supported for this target"); |
3529 | exit(1); | |
3530 | } | |
3531 | xen_domid_restrict = true; | |
3532 | break; | |
ab6540d5 | 3533 | case QEMU_OPTION_trace: |
92eecfff | 3534 | trace_opt_parse(optarg); |
ab6540d5 | 3535 | break; |
42229a75 LV |
3536 | case QEMU_OPTION_plugin: |
3537 | qemu_plugin_opt_parse(optarg, &plugin_list); | |
3538 | break; | |
715a664a | 3539 | case QEMU_OPTION_readconfig: |
c0d4aa82 | 3540 | qemu_read_config_file(optarg, qemu_parse_config_group, &error_fatal); |
f7544edc | 3541 | break; |
5324e3e9 | 3542 | #ifdef CONFIG_SPICE |
29b0040b | 3543 | case QEMU_OPTION_spice: |
9ed345a1 | 3544 | olist = qemu_find_opts_err("spice", NULL); |
29b0040b | 3545 | if (!olist) { |
5dfdae81 | 3546 | error_report("spice support is disabled"); |
29b0040b GH |
3547 | exit(1); |
3548 | } | |
70b94331 | 3549 | opts = qemu_opts_parse_noisily(olist, optarg, false); |
29b0040b | 3550 | if (!opts) { |
29b0040b GH |
3551 | exit(1); |
3552 | } | |
f963e4d0 | 3553 | display_remote++; |
29b0040b | 3554 | break; |
5324e3e9 | 3555 | #endif |
c7f0f3b1 AL |
3556 | case QEMU_OPTION_qtest: |
3557 | qtest_chrdev = optarg; | |
3558 | break; | |
3559 | case QEMU_OPTION_qtest_log: | |
3560 | qtest_log = optarg; | |
3561 | break; | |
7d76ad4f | 3562 | case QEMU_OPTION_sandbox: |
2bb814a4 MAL |
3563 | olist = qemu_find_opts("sandbox"); |
3564 | if (!olist) { | |
3565 | #ifndef CONFIG_SECCOMP | |
3566 | error_report("-sandbox support is not enabled " | |
3567 | "in this QEMU binary"); | |
3568 | #endif | |
3569 | exit(1); | |
3570 | } | |
3571 | ||
3572 | opts = qemu_opts_parse_noisily(olist, optarg, true); | |
7d76ad4f | 3573 | if (!opts) { |
49295ebc | 3574 | exit(1); |
7d76ad4f EO |
3575 | } |
3576 | break; | |
587ed6be CB |
3577 | case QEMU_OPTION_add_fd: |
3578 | #ifndef _WIN32 | |
70b94331 MA |
3579 | opts = qemu_opts_parse_noisily(qemu_find_opts("add-fd"), |
3580 | optarg, false); | |
587ed6be | 3581 | if (!opts) { |
49295ebc | 3582 | exit(1); |
587ed6be CB |
3583 | } |
3584 | #else | |
3585 | error_report("File descriptor passing is disabled on this " | |
3586 | "platform"); | |
3587 | exit(1); | |
3588 | #endif | |
3589 | break; | |
68d98d3e | 3590 | case QEMU_OPTION_object: |
bc2f4fcb | 3591 | object_option_parse(optarg); |
68d98d3e | 3592 | break; |
6f131f13 MT |
3593 | case QEMU_OPTION_overcommit: |
3594 | opts = qemu_opts_parse_noisily(qemu_find_opts("overcommit"), | |
3595 | optarg, false); | |
3596 | if (!opts) { | |
3597 | exit(1); | |
3598 | } | |
c8c9dc42 | 3599 | enable_mlock = qemu_opt_get_bool(opts, "mem-lock", false); |
6f131f13 | 3600 | enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", false); |
888a6bc6 | 3601 | break; |
6dd75472 MA |
3602 | case QEMU_OPTION_compat: |
3603 | { | |
3604 | CompatPolicy *opts; | |
3605 | Visitor *v; | |
3606 | ||
3607 | v = qobject_input_visitor_new_str(optarg, NULL, | |
3608 | &error_fatal); | |
3609 | ||
3610 | visit_type_CompatPolicy(v, NULL, &opts, &error_fatal); | |
3611 | QAPI_CLONE_MEMBERS(CompatPolicy, &compat_policy, opts); | |
3612 | ||
3613 | qapi_free_CompatPolicy(opts); | |
3614 | visit_free(v); | |
3615 | break; | |
3616 | } | |
5e2ac519 | 3617 | case QEMU_OPTION_msg: |
70b94331 MA |
3618 | opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg, |
3619 | false); | |
5e2ac519 SA |
3620 | if (!opts) { |
3621 | exit(1); | |
3622 | } | |
3623 | configure_msg(opts); | |
3624 | break; | |
abfd9ce3 | 3625 | case QEMU_OPTION_dump_vmstate: |
522abf69 | 3626 | if (vmstate_dump_file) { |
f61eddcb EH |
3627 | error_report("only one '-dump-vmstate' " |
3628 | "option may be given"); | |
522abf69 GA |
3629 | exit(1); |
3630 | } | |
abfd9ce3 AS |
3631 | vmstate_dump_file = fopen(optarg, "w"); |
3632 | if (vmstate_dump_file == NULL) { | |
f61eddcb | 3633 | error_report("open %s: %s", optarg, strerror(errno)); |
abfd9ce3 AS |
3634 | exit(1); |
3635 | } | |
12df189d EC |
3636 | break; |
3637 | case QEMU_OPTION_enable_sync_profile: | |
3638 | qsp_enable(); | |
abfd9ce3 | 3639 | break; |
aec0d0e1 MP |
3640 | case QEMU_OPTION_nouserconfig: |
3641 | /* Nothing to be parsed here. Especially, do not error out below. */ | |
3642 | break; | |
59a5264b | 3643 | default: |
1217d6ca TH |
3644 | if (os_parse_cmd_args(popt->index, optarg)) { |
3645 | error_report("Option not supported in this build"); | |
3646 | exit(1); | |
3647 | } | |
cd6f1169 | 3648 | } |
0824d6fc FB |
3649 | } |
3650 | } | |
43fa1e0b EH |
3651 | /* |
3652 | * Clear error location left behind by the loop. | |
3653 | * Best done right after the loop. Do not insert code here! | |
3654 | */ | |
3655 | loc_set_none(); | |
364c3e6b | 3656 | |
d8fb7d09 | 3657 | qemu_validate_options(machine_opts_dict); |
4d2c17b0 | 3658 | qemu_process_sugar_options(); |
58c91595 | 3659 | |
3df261b6 | 3660 | /* |
0546c060 PB |
3661 | * These options affect everything else and should be processed |
3662 | * before daemonizing. | |
3df261b6 | 3663 | */ |
0546c060 | 3664 | qemu_process_early_options(); |
3df261b6 | 3665 | |
0546c060 PB |
3666 | qemu_process_help_options(); |
3667 | qemu_maybe_daemonize(pid_file); | |
3668 | ||
10b6ee16 DHB |
3669 | /* |
3670 | * The trace backend must be initialized after daemonizing. | |
3671 | * trace_init_backends() will call st_init(), which will create the | |
3672 | * trace thread in the parent, and also register st_flush_trace_buffer() | |
3673 | * in atexit(). This function will force the parent to wait for the | |
3674 | * writeout thread to finish, which will not occur, and the parent | |
3675 | * process will be left in the host. | |
3676 | */ | |
3677 | if (!trace_init_backends()) { | |
3678 | exit(1); | |
3679 | } | |
3680 | trace_init_file(); | |
3681 | ||
efd7ab22 PB |
3682 | qemu_init_main_loop(&error_fatal); |
3683 | cpu_timers_init(); | |
3df261b6 | 3684 | |
fc4a4734 | 3685 | user_register_global_props(); |
4c27b859 PD |
3686 | replay_configure(icount_opts); |
3687 | ||
eb6a5209 AP |
3688 | configure_rtc(qemu_find_opts_singleton("rtc")); |
3689 | ||
d8fb7d09 | 3690 | qemu_create_machine(machine_opts_dict); |
67b724e6 | 3691 | |
5a1ee607 PB |
3692 | suspend_mux_open(); |
3693 | ||
f650266b PB |
3694 | qemu_disable_default_devices(); |
3695 | qemu_create_default_devices(); | |
64418657 | 3696 | qemu_create_early_backends(); |
cda4aa9a | 3697 | |
d8fb7d09 PB |
3698 | qemu_apply_legacy_machine_options(machine_opts_dict); |
3699 | qemu_apply_machine_options(machine_opts_dict); | |
3700 | qobject_unref(machine_opts_dict); | |
2f181fbd | 3701 | phase_advance(PHASE_MACHINE_CREATED); |
6b1b1440 | 3702 | |
0427b625 MA |
3703 | /* |
3704 | * Note: uses machine properties such as kernel-irqchip, must run | |
d8fb7d09 | 3705 | * after qemu_apply_machine_options. |
0427b625 | 3706 | */ |
28a09617 | 3707 | configure_accelerators(argv[0]); |
2f181fbd | 3708 | phase_advance(PHASE_ACCEL_CREATED); |
214910a7 | 3709 | |
0427b625 MA |
3710 | /* |
3711 | * Beware, QOM objects created before this point miss global and | |
3712 | * compat properties. | |
3713 | * | |
3714 | * Global properties get set up by qdev_prop_register_global(), | |
3715 | * called from user_register_global_props(), and certain option | |
3716 | * desugaring. Also in CPU feature desugaring (buried in | |
c1c8cfe5 | 3717 | * parse_cpu_option()), which happens below this point, but may |
0427b625 | 3718 | * only target the CPU type, which can only be created after |
c1c8cfe5 | 3719 | * parse_cpu_option() returned the type. |
0427b625 MA |
3720 | * |
3721 | * Machine compat properties: object_set_machine_compat_props(). | |
3722 | * Accelerator compat props: object_set_accelerator_compat_props(), | |
b86f59c7 | 3723 | * called from do_configure_accelerator(). |
0427b625 MA |
3724 | */ |
3725 | ||
f5c9fcb8 | 3726 | machine_class = MACHINE_GET_CLASS(current_machine); |
08fe6824 TH |
3727 | if (!qtest_enabled() && machine_class->deprecation_reason) { |
3728 | error_report("Machine type '%s' is deprecated: %s", | |
3729 | machine_class->name, machine_class->deprecation_reason); | |
3730 | } | |
3731 | ||
2fa23277 | 3732 | /* |
0427b625 MA |
3733 | * Note: creates a QOM object, must run only after global and |
3734 | * compat properties have been set up. | |
2fa23277 MA |
3735 | */ |
3736 | migration_object_init(); | |
3737 | ||
07a91b1a | 3738 | qemu_create_late_backends(); |
619985e9 | 3739 | |
6063d4c0 | 3740 | /* parse features once if machine provides default cpu_type */ |
2278b939 | 3741 | current_machine->cpu_type = machine_class->default_cpu_type; |
c1c8cfe5 EH |
3742 | if (cpu_option) { |
3743 | current_machine->cpu_type = parse_cpu_option(cpu_option); | |
6063d4c0 | 3744 | } |
b86f59c7 | 3745 | /* NB: for machine none cpu_type could STILL be NULL here! */ |
a1b18df9 | 3746 | |
b24986e7 | 3747 | qemu_resolve_machine_memdev(); |
d342eb76 | 3748 | parse_numa_opts(current_machine); |
6063d4c0 | 3749 | |
abfd9ce3 AS |
3750 | if (vmstate_dump_file) { |
3751 | /* dump and exit */ | |
4067691a | 3752 | module_load_qom_all(); |
abfd9ce3 | 3753 | dump_vmstate_json_to_file(vmstate_dump_file); |
7b733862 | 3754 | exit(0); |
abfd9ce3 | 3755 | } |
ffd843bc | 3756 | |
b4e1a342 PB |
3757 | if (!preconfig_requested) { |
3758 | qmp_x_exit_preconfig(&error_fatal); | |
3759 | } | |
facf7c60 | 3760 | qemu_init_displays(); |
7a64c17f | 3761 | accel_setup_post(current_machine); |
eb505be1 | 3762 | os_setup_post(); |
5a1ee607 | 3763 | resume_mux_open(); |
7b733862 | 3764 | } |