]>
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 EH |
936 | }, |
937 | [VGA_XENFB] = { | |
938 | .opt_name = "xenfb", | |
d2fa65cd | 939 | .name = "Xen paravirtualized framebuffer", |
8c9a2b71 EH |
940 | }, |
941 | }; | |
942 | ||
c2c7b22d EH |
943 | static bool vga_interface_available(VGAInterfaceType t) |
944 | { | |
53b93511 | 945 | const VGAInterfaceInfo *ti = &vga_interfaces[t]; |
c2c7b22d EH |
946 | |
947 | assert(t < VGA_TYPE_MAX); | |
948 | return !ti->class_names[0] || | |
7ab6e7fc GH |
949 | module_object_class_by_name(ti->class_names[0]) || |
950 | module_object_class_by_name(ti->class_names[1]); | |
c2c7b22d EH |
951 | } |
952 | ||
dceb8852 MAL |
953 | static const char * |
954 | get_default_vga_model(const MachineClass *machine_class) | |
955 | { | |
956 | if (machine_class->default_display) { | |
957 | return machine_class->default_display; | |
958 | } else if (vga_interface_available(VGA_CIRRUS)) { | |
959 | return "cirrus"; | |
960 | } else if (vga_interface_available(VGA_STD)) { | |
961 | return "std"; | |
962 | } | |
963 | ||
964 | return NULL; | |
965 | } | |
966 | ||
967 | static void select_vgahw(const MachineClass *machine_class, const char *p) | |
3893c124 | 968 | { |
969 | const char *opts; | |
8c9a2b71 | 970 | int t; |
3893c124 | 971 | |
dceb8852 MAL |
972 | if (g_str_equal(p, "help")) { |
973 | const char *def = get_default_vga_model(machine_class); | |
974 | ||
975 | for (t = 0; t < VGA_TYPE_MAX; t++) { | |
976 | const VGAInterfaceInfo *ti = &vga_interfaces[t]; | |
977 | ||
978 | if (vga_interface_available(t) && ti->opt_name) { | |
979 | printf("%-20s %s%s\n", ti->opt_name, ti->name ?: "", | |
980 | g_str_equal(ti->opt_name, def) ? " (default)" : ""); | |
981 | } | |
982 | } | |
983 | exit(0); | |
984 | } | |
985 | ||
d44229c5 | 986 | assert(vga_interface_type == VGA_NONE); |
8c9a2b71 | 987 | for (t = 0; t < VGA_TYPE_MAX; t++) { |
53b93511 | 988 | const VGAInterfaceInfo *ti = &vga_interfaces[t]; |
8c9a2b71 | 989 | if (ti->opt_name && strstart(p, ti->opt_name, &opts)) { |
c2c7b22d | 990 | if (!vga_interface_available(t)) { |
8c9a2b71 EH |
991 | error_report("%s not available", ti->name); |
992 | exit(1); | |
993 | } | |
994 | vga_interface_type = t; | |
995 | break; | |
af87bf29 | 996 | } |
8c9a2b71 EH |
997 | } |
998 | if (t == VGA_TYPE_MAX) { | |
3893c124 | 999 | invalid_vga: |
3e515373 | 1000 | error_report("unknown vga type: %s", p); |
3893c124 | 1001 | exit(1); |
1002 | } | |
cb5a7aa8 | 1003 | while (*opts) { |
1004 | const char *nextopt; | |
1005 | ||
1006 | if (strstart(opts, ",retrace=", &nextopt)) { | |
1007 | opts = nextopt; | |
1008 | if (strstart(opts, "dumb", &nextopt)) | |
1009 | vga_retrace_method = VGA_RETRACE_DUMB; | |
1010 | else if (strstart(opts, "precise", &nextopt)) | |
1011 | vga_retrace_method = VGA_RETRACE_PRECISE; | |
1012 | else goto invalid_vga; | |
1013 | } else goto invalid_vga; | |
1014 | opts = nextopt; | |
1015 | } | |
3893c124 | 1016 | } |
1017 | ||
776d1344 GH |
1018 | static void parse_display_qapi(const char *optarg) |
1019 | { | |
776d1344 GH |
1020 | DisplayOptions *opts; |
1021 | Visitor *v; | |
1022 | ||
50beeb68 | 1023 | v = qobject_input_visitor_new_str(optarg, "type", &error_fatal); |
776d1344 GH |
1024 | |
1025 | visit_type_DisplayOptions(v, NULL, &opts, &error_fatal); | |
1026 | QAPI_CLONE_MEMBERS(DisplayOptions, &dpy, opts); | |
1027 | ||
1028 | qapi_free_DisplayOptions(opts); | |
1029 | visit_free(v); | |
1030 | } | |
1031 | ||
e1ca8f7e GH |
1032 | DisplayOptions *qmp_query_display_options(Error **errp) |
1033 | { | |
1034 | return QAPI_CLONE(DisplayOptions, &dpy); | |
1035 | } | |
1036 | ||
e3af9f9a | 1037 | static void parse_display(const char *p) |
1472a95b JS |
1038 | { |
1039 | const char *opts; | |
1472a95b | 1040 | |
c388f408 TH |
1041 | if (is_help_option(p)) { |
1042 | qemu_display_help(); | |
1043 | exit(0); | |
1044 | } | |
1045 | ||
1472a95b | 1046 | if (strstart(p, "sdl", &opts)) { |
7a61f438 GH |
1047 | /* |
1048 | * sdl DisplayType needs hand-crafted parser instead of | |
1049 | * parse_display_qapi() due to some options not in | |
1050 | * DisplayOptions, specifically: | |
7a61f438 | 1051 | * - ctrl_grab + alt_grab |
8e8e844b TH |
1052 | * They can't be moved into the QAPI since they use underscores, |
1053 | * thus they will get replaced by "grab-mod" in the long term | |
7a61f438 | 1054 | */ |
66c2207f | 1055 | #if defined(CONFIG_SDL) |
fe91f36a | 1056 | dpy.type = DISPLAY_TYPE_SDL; |
1472a95b JS |
1057 | while (*opts) { |
1058 | const char *nextopt; | |
1059 | ||
8e8e844b TH |
1060 | if (strstart(opts, ",grab-mod=", &nextopt)) { |
1061 | opts = nextopt; | |
1062 | if (strstart(opts, "lshift-lctrl-lalt", &nextopt)) { | |
1063 | alt_grab = 1; | |
1064 | } else if (strstart(opts, "rctrl", &nextopt)) { | |
1065 | ctrl_grab = 1; | |
1066 | } else { | |
1067 | goto invalid_sdl_args; | |
1068 | } | |
1069 | } else if (strstart(opts, ",alt_grab=", &nextopt)) { | |
1472a95b JS |
1070 | opts = nextopt; |
1071 | if (strstart(opts, "on", &nextopt)) { | |
1072 | alt_grab = 1; | |
1073 | } else if (strstart(opts, "off", &nextopt)) { | |
1074 | alt_grab = 0; | |
1075 | } else { | |
05175535 | 1076 | goto invalid_sdl_args; |
1472a95b | 1077 | } |
d46156fd | 1078 | warn_report("alt_grab is deprecated, use grab-mod instead."); |
1472a95b JS |
1079 | } else if (strstart(opts, ",ctrl_grab=", &nextopt)) { |
1080 | opts = nextopt; | |
1081 | if (strstart(opts, "on", &nextopt)) { | |
1082 | ctrl_grab = 1; | |
1083 | } else if (strstart(opts, "off", &nextopt)) { | |
1084 | ctrl_grab = 0; | |
1085 | } else { | |
05175535 | 1086 | goto invalid_sdl_args; |
1472a95b | 1087 | } |
d46156fd | 1088 | warn_report("ctrl_grab is deprecated, use grab-mod instead."); |
bb20b86d TH |
1089 | } else if (strstart(opts, ",window_close=", &nextopt) || |
1090 | strstart(opts, ",window-close=", &nextopt)) { | |
1091 | if (strstart(opts, ",window_close=", NULL)) { | |
1092 | warn_report("window_close with an underscore is deprecated," | |
1093 | " please use window-close instead."); | |
1094 | } | |
1472a95b | 1095 | opts = nextopt; |
fe91f36a | 1096 | dpy.has_window_close = true; |
1472a95b | 1097 | if (strstart(opts, "on", &nextopt)) { |
fe91f36a | 1098 | dpy.window_close = true; |
1472a95b | 1099 | } else if (strstart(opts, "off", &nextopt)) { |
fe91f36a | 1100 | dpy.window_close = false; |
1472a95b | 1101 | } else { |
05175535 | 1102 | goto invalid_sdl_args; |
1472a95b | 1103 | } |
86a088e6 GH |
1104 | } else if (strstart(opts, ",show-cursor=", &nextopt)) { |
1105 | opts = nextopt; | |
1106 | dpy.has_show_cursor = true; | |
1107 | if (strstart(opts, "on", &nextopt)) { | |
1108 | dpy.show_cursor = true; | |
1109 | } else if (strstart(opts, "off", &nextopt)) { | |
1110 | dpy.show_cursor = false; | |
1111 | } else { | |
1112 | goto invalid_sdl_args; | |
1113 | } | |
0b71a5d5 GH |
1114 | } else if (strstart(opts, ",gl=", &nextopt)) { |
1115 | opts = nextopt; | |
fe91f36a | 1116 | dpy.has_gl = true; |
0b71a5d5 | 1117 | if (strstart(opts, "on", &nextopt)) { |
62f27922 | 1118 | dpy.gl = DISPLAYGL_MODE_ON; |
4867e47c ET |
1119 | } else if (strstart(opts, "core", &nextopt)) { |
1120 | dpy.gl = DISPLAYGL_MODE_CORE; | |
1121 | } else if (strstart(opts, "es", &nextopt)) { | |
1122 | dpy.gl = DISPLAYGL_MODE_ES; | |
0b71a5d5 | 1123 | } else if (strstart(opts, "off", &nextopt)) { |
62f27922 | 1124 | dpy.gl = DISPLAYGL_MODE_OFF; |
0b71a5d5 GH |
1125 | } else { |
1126 | goto invalid_sdl_args; | |
1127 | } | |
1472a95b | 1128 | } else { |
05175535 | 1129 | invalid_sdl_args: |
3e515373 | 1130 | error_report("invalid SDL option string"); |
05175535 | 1131 | exit(1); |
1472a95b JS |
1132 | } |
1133 | opts = nextopt; | |
1134 | } | |
66c2207f TH |
1135 | #else |
1136 | error_report("SDL display supported is not available in this binary"); | |
1137 | exit(1); | |
1138 | #endif | |
3264ff12 | 1139 | } else if (strstart(p, "vnc", &opts)) { |
7a61f438 GH |
1140 | /* |
1141 | * vnc isn't a (local) DisplayType but a protocol for remote | |
1142 | * display access. | |
1143 | */ | |
4db14629 | 1144 | if (*opts == '=') { |
653c9747 | 1145 | vnc_parse(opts + 1); |
4db14629 | 1146 | } else { |
c6bf0f7f | 1147 | error_report("VNC requires a display argument vnc=<display>"); |
3264ff12 JS |
1148 | exit(1); |
1149 | } | |
1472a95b | 1150 | } else { |
776d1344 | 1151 | parse_display_qapi(p); |
1472a95b | 1152 | } |
1472a95b JS |
1153 | } |
1154 | ||
6407d76e GS |
1155 | static inline bool nonempty_str(const char *str) |
1156 | { | |
1157 | return str && *str; | |
1158 | } | |
1159 | ||
81b2b810 GS |
1160 | static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp) |
1161 | { | |
1162 | gchar *buf; | |
1163 | size_t size; | |
6552d87c | 1164 | const char *name, *file, *str, *gen_id; |
bab47d9a | 1165 | FWCfgState *fw_cfg = (FWCfgState *) opaque; |
81b2b810 | 1166 | |
bab47d9a | 1167 | if (fw_cfg == NULL) { |
406b6367 | 1168 | error_setg(errp, "fw_cfg device not available"); |
81b2b810 GS |
1169 | return -1; |
1170 | } | |
1171 | name = qemu_opt_get(opts, "name"); | |
1172 | file = qemu_opt_get(opts, "file"); | |
6407d76e | 1173 | str = qemu_opt_get(opts, "string"); |
6552d87c | 1174 | gen_id = qemu_opt_get(opts, "gen_id"); |
6407d76e | 1175 | |
6552d87c PMD |
1176 | /* we need the name, and exactly one of: file, content string, gen_id */ |
1177 | if (!nonempty_str(name) || | |
1178 | nonempty_str(file) + nonempty_str(str) + nonempty_str(gen_id) != 1) { | |
1179 | error_setg(errp, "name, plus exactly one of file," | |
1180 | " string and gen_id, are needed"); | |
81b2b810 GS |
1181 | return -1; |
1182 | } | |
1183 | if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) { | |
406b6367 MA |
1184 | error_setg(errp, "name too long (max. %d char)", |
1185 | FW_CFG_MAX_FILE_PATH - 1); | |
81b2b810 GS |
1186 | return -1; |
1187 | } | |
f7d8afb1 PMD |
1188 | if (nonempty_str(gen_id)) { |
1189 | /* | |
1190 | * In this particular case where the content is populated | |
1191 | * internally, the "etc/" namespace protection is relaxed, | |
1192 | * so do not emit a warning. | |
1193 | */ | |
1194 | } else if (strncmp(name, "opt/", 4) != 0) { | |
3dc6f869 AF |
1195 | warn_report("externally provided fw_cfg item names " |
1196 | "should be prefixed with \"opt/\""); | |
81b2b810 | 1197 | } |
6407d76e GS |
1198 | if (nonempty_str(str)) { |
1199 | size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */ | |
1200 | buf = g_memdup(str, size); | |
6552d87c | 1201 | } else if (nonempty_str(gen_id)) { |
07719518 | 1202 | if (!fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp)) { |
6552d87c PMD |
1203 | return -1; |
1204 | } | |
1205 | return 0; | |
6407d76e | 1206 | } else { |
353c7d58 LQ |
1207 | GError *err = NULL; |
1208 | if (!g_file_get_contents(file, &buf, &size, &err)) { | |
1209 | error_setg(errp, "can't load %s: %s", file, err->message); | |
1210 | g_error_free(err); | |
6407d76e GS |
1211 | return -1; |
1212 | } | |
81b2b810 | 1213 | } |
bab47d9a GH |
1214 | /* For legacy, keep user files in a specific global order. */ |
1215 | fw_cfg_set_order_override(fw_cfg, FW_CFG_ORDER_OVERRIDE_USER); | |
1216 | fw_cfg_add_file(fw_cfg, name, buf, size); | |
1217 | fw_cfg_reset_order_override(fw_cfg); | |
81b2b810 GS |
1218 | return 0; |
1219 | } | |
1220 | ||
28d0de7a | 1221 | static int device_help_func(void *opaque, QemuOpts *opts, Error **errp) |
ff952ba2 MA |
1222 | { |
1223 | return qdev_device_help(opts); | |
1224 | } | |
1225 | ||
28d0de7a | 1226 | static int device_init_func(void *opaque, QemuOpts *opts, Error **errp) |
f31d07d1 GH |
1227 | { |
1228 | DeviceState *dev; | |
1229 | ||
cd65f349 | 1230 | dev = qdev_device_add(opts, errp); |
f3a85056 JF |
1231 | if (!dev && *errp) { |
1232 | error_report_err(*errp); | |
f31d07d1 | 1233 | return -1; |
f3a85056 JF |
1234 | } else if (dev) { |
1235 | object_unref(OBJECT(dev)); | |
f006cf7f | 1236 | } |
f31d07d1 GH |
1237 | return 0; |
1238 | } | |
1239 | ||
28d0de7a | 1240 | static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) |
1a688d3b | 1241 | { |
bd2d80b2 | 1242 | Error *local_err = NULL; |
1a688d3b | 1243 | |
4ad6f6cb | 1244 | if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) { |
0ec846bf | 1245 | if (local_err) { |
dd4af977 | 1246 | error_propagate(errp, local_err); |
0ec846bf AN |
1247 | return -1; |
1248 | } | |
1249 | exit(0); | |
bd2d80b2 | 1250 | } |
1a688d3b GH |
1251 | return 0; |
1252 | } | |
1253 | ||
758e8e38 | 1254 | #ifdef CONFIG_VIRTFS |
28d0de7a | 1255 | static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp) |
74db920c | 1256 | { |
b836723d | 1257 | return qemu_fsdev_add(opts, errp); |
74db920c GS |
1258 | } |
1259 | #endif | |
1260 | ||
28d0de7a | 1261 | static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) |
88589343 | 1262 | { |
c3e95551 | 1263 | return monitor_init_opts(opts, errp); |
88589343 GH |
1264 | } |
1265 | ||
4821cd4c | 1266 | static void monitor_parse(const char *optarg, const char *mode, bool pretty) |
88589343 GH |
1267 | { |
1268 | static int monitor_device_index = 0; | |
1269 | QemuOpts *opts; | |
1270 | const char *p; | |
1271 | char label[32]; | |
88589343 GH |
1272 | |
1273 | if (strstart(optarg, "chardev:", &p)) { | |
1274 | snprintf(label, sizeof(label), "%s", p); | |
1275 | } else { | |
140e065d JK |
1276 | snprintf(label, sizeof(label), "compat_monitor%d", |
1277 | monitor_device_index); | |
95e30b2a | 1278 | opts = qemu_chr_parse_compat(label, optarg, true); |
88589343 | 1279 | if (!opts) { |
f61eddcb | 1280 | error_report("parse error: %s", optarg); |
88589343 GH |
1281 | exit(1); |
1282 | } | |
1283 | } | |
1284 | ||
822ac12d | 1285 | opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal); |
f43e47db MA |
1286 | qemu_opt_set(opts, "mode", mode, &error_abort); |
1287 | qemu_opt_set(opts, "chardev", label, &error_abort); | |
3c45f625 KW |
1288 | if (!strcmp(mode, "control")) { |
1289 | qemu_opt_set_bool(opts, "pretty", pretty, &error_abort); | |
1290 | } else { | |
1291 | assert(pretty == false); | |
1292 | } | |
88589343 GH |
1293 | monitor_device_index++; |
1294 | } | |
1295 | ||
bd3c948d GH |
1296 | struct device_config { |
1297 | enum { | |
aee1b935 | 1298 | DEV_USB, /* -usbdevice */ |
aee1b935 GH |
1299 | DEV_SERIAL, /* -serial */ |
1300 | DEV_PARALLEL, /* -parallel */ | |
c9f398e5 | 1301 | DEV_DEBUGCON, /* -debugcon */ |
ef0c4a0d | 1302 | DEV_GDB, /* -gdb, -s */ |
3ef669e1 | 1303 | DEV_SCLP, /* s390 sclp */ |
bd3c948d GH |
1304 | } type; |
1305 | const char *cmdline; | |
d9a5954d | 1306 | Location loc; |
72cf2d4f | 1307 | QTAILQ_ENTRY(device_config) next; |
bd3c948d | 1308 | }; |
4fdcac0e BS |
1309 | |
1310 | static QTAILQ_HEAD(, device_config) device_configs = | |
1311 | QTAILQ_HEAD_INITIALIZER(device_configs); | |
bd3c948d GH |
1312 | |
1313 | static void add_device_config(int type, const char *cmdline) | |
1314 | { | |
1315 | struct device_config *conf; | |
1316 | ||
7267c094 | 1317 | conf = g_malloc0(sizeof(*conf)); |
bd3c948d GH |
1318 | conf->type = type; |
1319 | conf->cmdline = cmdline; | |
d9a5954d | 1320 | loc_save(&conf->loc); |
72cf2d4f | 1321 | QTAILQ_INSERT_TAIL(&device_configs, conf, next); |
bd3c948d GH |
1322 | } |
1323 | ||
1324 | static int foreach_device_config(int type, int (*func)(const char *cmdline)) | |
1325 | { | |
1326 | struct device_config *conf; | |
1327 | int rc; | |
1328 | ||
72cf2d4f | 1329 | QTAILQ_FOREACH(conf, &device_configs, next) { |
bd3c948d GH |
1330 | if (conf->type != type) |
1331 | continue; | |
d9a5954d | 1332 | loc_push_restore(&conf->loc); |
bd3c948d | 1333 | rc = func(conf->cmdline); |
d9a5954d | 1334 | loc_pop(&conf->loc); |
28de2f88 | 1335 | if (rc) { |
bd3c948d | 1336 | return rc; |
28de2f88 | 1337 | } |
bd3c948d GH |
1338 | } |
1339 | return 0; | |
1340 | } | |
1341 | ||
f650266b PB |
1342 | static void qemu_disable_default_devices(void) |
1343 | { | |
1344 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
1345 | ||
5dacda51 | 1346 | default_driver_check_json(); |
f650266b PB |
1347 | qemu_opts_foreach(qemu_find_opts("device"), |
1348 | default_driver_check, NULL, NULL); | |
1349 | qemu_opts_foreach(qemu_find_opts("global"), | |
1350 | default_driver_check, NULL, NULL); | |
1351 | ||
1352 | if (!vga_model && !default_vga) { | |
1353 | vga_interface_type = VGA_DEVICE; | |
1354 | } | |
1355 | if (!has_defaults || machine_class->no_serial) { | |
1356 | default_serial = 0; | |
1357 | } | |
1358 | if (!has_defaults || machine_class->no_parallel) { | |
1359 | default_parallel = 0; | |
1360 | } | |
1361 | if (!has_defaults || machine_class->no_floppy) { | |
1362 | default_floppy = 0; | |
1363 | } | |
1364 | if (!has_defaults || machine_class->no_cdrom) { | |
1365 | default_cdrom = 0; | |
1366 | } | |
1367 | if (!has_defaults || machine_class->no_sdcard) { | |
1368 | default_sdcard = 0; | |
1369 | } | |
1370 | if (!has_defaults) { | |
1371 | default_monitor = 0; | |
1372 | default_net = 0; | |
1373 | default_vga = 0; | |
1374 | } | |
1375 | } | |
1376 | ||
1377 | static void qemu_create_default_devices(void) | |
1378 | { | |
1379 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
1380 | ||
1381 | if (is_daemonized()) { | |
1382 | /* According to documentation and historically, -nographic redirects | |
1383 | * serial port, parallel port and monitor to stdio, which does not work | |
1384 | * with -daemonize. We can redirect these to null instead, but since | |
1385 | * -nographic is legacy, let's just error out. | |
1386 | * We disallow -nographic only if all other ports are not redirected | |
1387 | * explicitly, to not break existing legacy setups which uses | |
1388 | * -nographic _and_ redirects all ports explicitly - this is valid | |
1389 | * usage, -nographic is just a no-op in this case. | |
1390 | */ | |
1391 | if (nographic | |
1392 | && (default_parallel || default_serial || default_monitor)) { | |
1393 | error_report("-nographic cannot be used with -daemonize"); | |
1394 | exit(1); | |
1395 | } | |
1396 | } | |
1397 | ||
1398 | if (nographic) { | |
1399 | if (default_parallel) | |
1400 | add_device_config(DEV_PARALLEL, "null"); | |
1401 | if (default_serial && default_monitor) { | |
1402 | add_device_config(DEV_SERIAL, "mon:stdio"); | |
1403 | } else { | |
1404 | if (default_serial) | |
1405 | add_device_config(DEV_SERIAL, "stdio"); | |
1406 | if (default_monitor) | |
1407 | monitor_parse("stdio", "readline", false); | |
1408 | } | |
1409 | } else { | |
1410 | if (default_serial) | |
1411 | add_device_config(DEV_SERIAL, "vc:80Cx24C"); | |
1412 | if (default_parallel) | |
1413 | add_device_config(DEV_PARALLEL, "vc:80Cx24C"); | |
1414 | if (default_monitor) | |
1415 | monitor_parse("vc:80Cx24C", "readline", false); | |
1416 | } | |
1417 | ||
1418 | if (default_net) { | |
1419 | QemuOptsList *net = qemu_find_opts("net"); | |
1420 | qemu_opts_parse(net, "nic", true, &error_abort); | |
1421 | #ifdef CONFIG_SLIRP | |
1422 | qemu_opts_parse(net, "user", true, &error_abort); | |
1423 | #endif | |
1424 | } | |
1425 | ||
1426 | #if defined(CONFIG_VNC) | |
1427 | if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head))) { | |
1428 | display_remote++; | |
1429 | } | |
1430 | #endif | |
1431 | if (dpy.type == DISPLAY_TYPE_DEFAULT && !display_remote) { | |
1432 | if (!qemu_display_find_default(&dpy)) { | |
1433 | dpy.type = DISPLAY_TYPE_NONE; | |
1434 | #if defined(CONFIG_VNC) | |
653c9747 | 1435 | vnc_parse("localhost:0,to=99,id=default"); |
f650266b PB |
1436 | #endif |
1437 | } | |
1438 | } | |
1439 | if (dpy.type == DISPLAY_TYPE_DEFAULT) { | |
1440 | dpy.type = DISPLAY_TYPE_NONE; | |
1441 | } | |
1442 | ||
1443 | /* If no default VGA is requested, the default is "none". */ | |
1444 | if (default_vga) { | |
1445 | vga_model = get_default_vga_model(machine_class); | |
1446 | } | |
1447 | if (vga_model) { | |
1448 | select_vgahw(machine_class, vga_model); | |
1449 | } | |
1450 | } | |
1451 | ||
998bbd74 GH |
1452 | static int serial_parse(const char *devname) |
1453 | { | |
6af2692e | 1454 | int index = num_serial_hds; |
998bbd74 GH |
1455 | char label[32]; |
1456 | ||
1457 | if (strcmp(devname, "none") == 0) | |
1458 | return 0; | |
998bbd74 | 1459 | snprintf(label, sizeof(label), "serial%d", index); |
6af2692e PM |
1460 | serial_hds = g_renew(Chardev *, serial_hds, index + 1); |
1461 | ||
4ad6f6cb | 1462 | serial_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL); |
998bbd74 | 1463 | if (!serial_hds[index]) { |
f61eddcb EH |
1464 | error_report("could not connect serial device" |
1465 | " to character backend '%s'", devname); | |
998bbd74 GH |
1466 | return -1; |
1467 | } | |
6af2692e | 1468 | num_serial_hds++; |
998bbd74 GH |
1469 | return 0; |
1470 | } | |
1471 | ||
a8d78cd0 PM |
1472 | Chardev *serial_hd(int i) |
1473 | { | |
1474 | assert(i >= 0); | |
6af2692e | 1475 | if (i < num_serial_hds) { |
a8d78cd0 PM |
1476 | return serial_hds[i]; |
1477 | } | |
1478 | return NULL; | |
1479 | } | |
1480 | ||
6a5e8b0e GH |
1481 | static int parallel_parse(const char *devname) |
1482 | { | |
1483 | static int index = 0; | |
1484 | char label[32]; | |
1485 | ||
1486 | if (strcmp(devname, "none") == 0) | |
1487 | return 0; | |
1488 | if (index == MAX_PARALLEL_PORTS) { | |
f61eddcb | 1489 | error_report("too many parallel ports"); |
6a5e8b0e GH |
1490 | exit(1); |
1491 | } | |
1492 | snprintf(label, sizeof(label), "parallel%d", index); | |
4ad6f6cb | 1493 | parallel_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL); |
6a5e8b0e | 1494 | if (!parallel_hds[index]) { |
f61eddcb EH |
1495 | error_report("could not connect parallel device" |
1496 | " to character backend '%s'", devname); | |
6a5e8b0e GH |
1497 | return -1; |
1498 | } | |
1499 | index++; | |
1500 | return 0; | |
1501 | } | |
1502 | ||
c9f398e5 | 1503 | static int debugcon_parse(const char *devname) |
4d8b3c63 | 1504 | { |
c9f398e5 PA |
1505 | QemuOpts *opts; |
1506 | ||
4ad6f6cb | 1507 | if (!qemu_chr_new_mux_mon("debugcon", devname, NULL)) { |
d7ecf712 | 1508 | error_report("invalid character backend '%s'", devname); |
c9f398e5 PA |
1509 | exit(1); |
1510 | } | |
8be7e7e4 | 1511 | opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL); |
c9f398e5 | 1512 | if (!opts) { |
f61eddcb | 1513 | error_report("already have a debugcon device"); |
c9f398e5 PA |
1514 | exit(1); |
1515 | } | |
f43e47db MA |
1516 | qemu_opt_set(opts, "driver", "isa-debugcon", &error_abort); |
1517 | qemu_opt_set(opts, "chardev", "debugcon", &error_abort); | |
c9f398e5 PA |
1518 | return 0; |
1519 | } | |
1520 | ||
2709f263 LE |
1521 | static gint machine_class_cmp(gconstpointer a, gconstpointer b) |
1522 | { | |
1523 | const MachineClass *mc1 = a, *mc2 = b; | |
1524 | int res; | |
1525 | ||
1526 | if (mc1->family == NULL) { | |
1527 | if (mc2->family == NULL) { | |
1528 | /* Compare standalone machine types against each other; they sort | |
1529 | * in increasing order. | |
1530 | */ | |
1531 | return strcmp(object_class_get_name(OBJECT_CLASS(mc1)), | |
1532 | object_class_get_name(OBJECT_CLASS(mc2))); | |
1533 | } | |
1534 | ||
1535 | /* Standalone machine types sort after families. */ | |
1536 | return 1; | |
1537 | } | |
1538 | ||
1539 | if (mc2->family == NULL) { | |
1540 | /* Families sort before standalone machine types. */ | |
1541 | return -1; | |
1542 | } | |
1543 | ||
1544 | /* Families sort between each other alphabetically increasingly. */ | |
1545 | res = strcmp(mc1->family, mc2->family); | |
1546 | if (res != 0) { | |
1547 | return res; | |
1548 | } | |
1549 | ||
1550 | /* Within the same family, machine types sort in decreasing order. */ | |
1551 | return strcmp(object_class_get_name(OBJECT_CLASS(mc2)), | |
1552 | object_class_get_name(OBJECT_CLASS(mc1))); | |
1553 | } | |
1554 | ||
d8fb7d09 | 1555 | static void machine_help_func(const QDict *qdict) |
9052ea6b | 1556 | { |
d8fb7d09 PB |
1557 | GSList *machines, *el; |
1558 | const char *type = qdict_get_try_str(qdict, "type"); | |
9052ea6b | 1559 | |
d8fb7d09 PB |
1560 | machines = object_class_get_list(TYPE_MACHINE, false); |
1561 | if (type) { | |
1562 | ObjectClass *machine_class = OBJECT_CLASS(find_machine(type, machines)); | |
1563 | if (machine_class) { | |
1564 | type_print_class_properties(object_class_get_name(machine_class)); | |
1565 | return; | |
9052ea6b | 1566 | } |
9052ea6b | 1567 | } |
261747f1 | 1568 | |
d8fb7d09 PB |
1569 | printf("Supported machines are:\n"); |
1570 | machines = g_slist_sort(machines, machine_class_cmp); | |
1571 | for (el = machines; el; el = el->next) { | |
1572 | MachineClass *mc = el->data; | |
1573 | if (mc->alias) { | |
1574 | printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name); | |
1575 | } | |
1576 | printf("%-20s %s%s%s\n", mc->name, mc->desc, | |
1577 | mc->is_default ? " (default)" : "", | |
1578 | mc->deprecation_reason ? " (deprecated)" : ""); | |
12cb82fd | 1579 | } |
9052ea6b JK |
1580 | } |
1581 | ||
a3c2f128 PB |
1582 | static void |
1583 | machine_merge_property(const char *propname, QDict *prop, Error **errp) | |
1584 | { | |
1585 | QDict *opts; | |
1586 | ||
1587 | opts = qdict_new(); | |
1588 | /* Preserve the caller's reference to prop. */ | |
1589 | qobject_ref(prop); | |
1590 | qdict_put(opts, propname, prop); | |
1591 | keyval_merge(machine_opts_dict, opts, errp); | |
1592 | qobject_unref(opts); | |
1593 | } | |
1594 | ||
fe68090e PB |
1595 | static void |
1596 | machine_parse_property_opt(QemuOptsList *opts_list, const char *propname, | |
f9dfae9c | 1597 | const char *arg) |
fe68090e | 1598 | { |
a3c2f128 | 1599 | QDict *prop = NULL; |
fe68090e | 1600 | bool help = false; |
fe68090e | 1601 | |
f9dfae9c | 1602 | prop = keyval_parse(arg, opts_list->implied_opt_name, &help, &error_fatal); |
fe68090e PB |
1603 | if (help) { |
1604 | qemu_opts_print_help(opts_list, true); | |
3e61a13a | 1605 | exit(0); |
fe68090e | 1606 | } |
f9dfae9c | 1607 | machine_merge_property(propname, prop, &error_fatal); |
a3c2f128 | 1608 | qobject_unref(prop); |
fe68090e PB |
1609 | } |
1610 | ||
90a84d13 MAL |
1611 | static const char *pid_file; |
1612 | static Notifier qemu_unlink_pidfile_notifier; | |
1613 | ||
1614 | static void qemu_unlink_pidfile(Notifier *n, void *data) | |
1615 | { | |
1616 | if (pid_file) { | |
1617 | unlink(pid_file); | |
1618 | } | |
1619 | } | |
1620 | ||
6530a97b AL |
1621 | static const QEMUOption *lookup_opt(int argc, char **argv, |
1622 | const char **poptarg, int *poptind) | |
1623 | { | |
1624 | const QEMUOption *popt; | |
1625 | int optind = *poptind; | |
1626 | char *r = argv[optind]; | |
1627 | const char *optarg; | |
1628 | ||
0f0bc3f1 | 1629 | loc_set_cmdline(argv, optind, 1); |
6530a97b AL |
1630 | optind++; |
1631 | /* Treat --foo the same as -foo. */ | |
1632 | if (r[1] == '-') | |
1633 | r++; | |
1634 | popt = qemu_options; | |
1635 | for(;;) { | |
1636 | if (!popt->name) { | |
0f0bc3f1 | 1637 | error_report("invalid option"); |
6530a97b AL |
1638 | exit(1); |
1639 | } | |
1640 | if (!strcmp(popt->name, r + 1)) | |
1641 | break; | |
1642 | popt++; | |
1643 | } | |
1644 | if (popt->flags & HAS_ARG) { | |
1645 | if (optind >= argc) { | |
0f0bc3f1 | 1646 | error_report("requires an argument"); |
6530a97b AL |
1647 | exit(1); |
1648 | } | |
1649 | optarg = argv[optind++]; | |
0f0bc3f1 | 1650 | loc_set_cmdline(argv, optind - 2, 2); |
6530a97b AL |
1651 | } else { |
1652 | optarg = NULL; | |
1653 | } | |
1654 | ||
1655 | *poptarg = optarg; | |
1656 | *poptind = optind; | |
1657 | ||
1658 | return popt; | |
1659 | } | |
1660 | ||
d8fb7d09 | 1661 | static MachineClass *select_machine(QDict *qdict, Error **errp) |
34f405ae | 1662 | { |
d8fb7d09 | 1663 | const char *optarg = qdict_get_try_str(qdict, "type"); |
c516cd1b | 1664 | GSList *machines = object_class_get_list(TYPE_MACHINE, false); |
d8fb7d09 PB |
1665 | MachineClass *machine_class; |
1666 | Error *local_err = NULL; | |
34f405ae | 1667 | |
34f405ae | 1668 | if (optarg) { |
d8fb7d09 PB |
1669 | machine_class = find_machine(optarg, machines); |
1670 | qdict_del(qdict, "type"); | |
1671 | if (!machine_class) { | |
1672 | error_setg(&local_err, "unsupported machine type"); | |
1673 | } | |
1674 | } else { | |
1675 | machine_class = find_default_machine(machines); | |
1676 | if (!machine_class) { | |
1677 | error_setg(&local_err, "No machine specified, and there is no default"); | |
1678 | } | |
34f405ae MA |
1679 | } |
1680 | ||
c516cd1b | 1681 | g_slist_free(machines); |
d8fb7d09 PB |
1682 | if (local_err) { |
1683 | error_append_hint(&local_err, "Use -machine help to list supported machines\n"); | |
1684 | error_propagate(errp, local_err); | |
1685 | } | |
7580f231 | 1686 | return machine_class; |
34f405ae MA |
1687 | } |
1688 | ||
e5db4bd8 PB |
1689 | static int object_parse_property_opt(Object *obj, |
1690 | const char *name, const char *value, | |
1691 | const char *skip, Error **errp) | |
68d98d3e | 1692 | { |
e5db4bd8 | 1693 | if (g_str_equal(name, skip)) { |
68d98d3e AL |
1694 | return 0; |
1695 | } | |
1696 | ||
668f62ec | 1697 | if (!object_property_parse(obj, name, value, errp)) { |
68d98d3e AL |
1698 | return -1; |
1699 | } | |
1700 | ||
1701 | return 0; | |
1702 | } | |
1703 | ||
d8fb7d09 PB |
1704 | /* *Non*recursively replace underscores with dashes in QDict keys. */ |
1705 | static void keyval_dashify(QDict *qdict, Error **errp) | |
e5db4bd8 | 1706 | { |
d8fb7d09 | 1707 | const QDictEntry *ent, *next; |
e5db4bd8 PB |
1708 | char *p; |
1709 | ||
d8fb7d09 PB |
1710 | for (ent = qdict_first(qdict); ent; ent = next) { |
1711 | g_autofree char *new_key = NULL; | |
1712 | ||
1713 | next = qdict_next(qdict, ent); | |
1714 | if (!strchr(ent->key, '_')) { | |
1715 | continue; | |
1716 | } | |
1717 | new_key = g_strdup(ent->key); | |
1718 | for (p = new_key; *p; p++) { | |
1719 | if (*p == '_') { | |
1720 | *p = '-'; | |
1721 | } | |
e5db4bd8 | 1722 | } |
d8fb7d09 PB |
1723 | if (qdict_haskey(qdict, new_key)) { |
1724 | error_setg(errp, "Conflict between '%s' and '%s'", ent->key, new_key); | |
1725 | return; | |
1726 | } | |
1727 | qobject_ref(ent->value); | |
1728 | qdict_put_obj(qdict, new_key, ent->value); | |
1729 | qdict_del(qdict, ent->key); | |
e5db4bd8 | 1730 | } |
d8fb7d09 PB |
1731 | } |
1732 | ||
1733 | static void qemu_apply_legacy_machine_options(QDict *qdict) | |
1734 | { | |
1735 | const char *value; | |
1736 | ||
1737 | keyval_dashify(qdict, &error_fatal); | |
e5db4bd8 | 1738 | |
6f6e1698 | 1739 | /* Legacy options do not correspond to MachineState properties. */ |
d8fb7d09 PB |
1740 | value = qdict_get_try_str(qdict, "accel"); |
1741 | if (value) { | |
1742 | accelerators = g_strdup(value); | |
1743 | qdict_del(qdict, "accel"); | |
6f6e1698 | 1744 | } |
d8fb7d09 PB |
1745 | |
1746 | value = qdict_get_try_str(qdict, "igd-passthru"); | |
1747 | if (value) { | |
1748 | object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value, | |
a8dc82ce | 1749 | false); |
d8fb7d09 | 1750 | qdict_del(qdict, "igd-passthru"); |
46472d82 | 1751 | } |
d8fb7d09 PB |
1752 | |
1753 | value = qdict_get_try_str(qdict, "kvm-shadow-mem"); | |
1754 | if (value) { | |
1755 | object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value, | |
a8dc82ce | 1756 | false); |
d8fb7d09 | 1757 | qdict_del(qdict, "kvm-shadow-mem"); |
23b0898e | 1758 | } |
d8fb7d09 PB |
1759 | |
1760 | value = qdict_get_try_str(qdict, "kernel-irqchip"); | |
1761 | if (value) { | |
1762 | object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value, | |
a8dc82ce | 1763 | false); |
d8fb7d09 | 1764 | object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value, |
a8dc82ce | 1765 | false); |
d8fb7d09 | 1766 | qdict_del(qdict, "kernel-irqchip"); |
faf20793 | 1767 | } |
e5db4bd8 | 1768 | } |
f08f9271 | 1769 | |
bc2f4fcb PB |
1770 | static void object_option_foreach_add(bool (*type_opt_predicate)(const char *)) |
1771 | { | |
1772 | ObjectOption *opt, *next; | |
1773 | ||
1774 | QTAILQ_FOREACH_SAFE(opt, &object_opts, next, next) { | |
1775 | const char *type = ObjectType_str(opt->opts->qom_type); | |
1776 | if (type_opt_predicate(type)) { | |
1777 | user_creatable_add_qapi(opt->opts, &error_fatal); | |
1778 | qapi_free_ObjectOptions(opt->opts); | |
1779 | QTAILQ_REMOVE(&object_opts, opt, next); | |
1780 | g_free(opt); | |
1781 | } | |
1782 | } | |
1783 | } | |
1784 | ||
49e98769 PB |
1785 | static void object_option_add_visitor(Visitor *v) |
1786 | { | |
1787 | ObjectOption *opt = g_new0(ObjectOption, 1); | |
1788 | visit_type_ObjectOptions(v, NULL, &opt->opts, &error_fatal); | |
1789 | QTAILQ_INSERT_TAIL(&object_opts, opt, next); | |
1790 | } | |
1791 | ||
bc2f4fcb PB |
1792 | static void object_option_parse(const char *optarg) |
1793 | { | |
bc2f4fcb PB |
1794 | QemuOpts *opts; |
1795 | const char *type; | |
1796 | Visitor *v; | |
1797 | ||
009ff893 PB |
1798 | if (optarg[0] == '{') { |
1799 | QObject *obj = qobject_from_json(optarg, &error_fatal); | |
bc2f4fcb | 1800 | |
009ff893 PB |
1801 | v = qobject_input_visitor_new(obj); |
1802 | qobject_unref(obj); | |
1803 | } else { | |
1804 | opts = qemu_opts_parse_noisily(qemu_find_opts("object"), | |
1805 | optarg, true); | |
1806 | if (!opts) { | |
1807 | exit(1); | |
1808 | } | |
1809 | ||
1810 | type = qemu_opt_get(opts, "qom-type"); | |
1811 | if (!type) { | |
1812 | error_setg(&error_fatal, QERR_MISSING_PARAMETER, "qom-type"); | |
1813 | } | |
1814 | if (user_creatable_print_help(type, opts)) { | |
1815 | exit(0); | |
1816 | } | |
1817 | ||
1818 | v = opts_visitor_new(opts); | |
bc2f4fcb PB |
1819 | } |
1820 | ||
49e98769 | 1821 | object_option_add_visitor(v); |
bc2f4fcb | 1822 | visit_free(v); |
bc2f4fcb PB |
1823 | } |
1824 | ||
f08f9271 DB |
1825 | /* |
1826 | * Initial object creation happens before all other | |
1827 | * QEMU data types are created. The majority of objects | |
1828 | * can be created at this point. The rng-egd object | |
1829 | * cannot be created here, as it depends on the chardev | |
1830 | * already existing. | |
1831 | */ | |
bc2f4fcb | 1832 | static bool object_create_early(const char *type) |
f08f9271 | 1833 | { |
edfb4389 MA |
1834 | /* |
1835 | * Objects should not be made "delayed" without a reason. If you | |
1836 | * add one, state the reason in a comment! | |
1837 | */ | |
1838 | ||
6ba7ada3 PB |
1839 | /* Reason: property "chardev" */ |
1840 | if (g_str_equal(type, "rng-egd") || | |
1841 | g_str_equal(type, "qtest")) { | |
f08f9271 DB |
1842 | return false; |
1843 | } | |
7dbb11c8 | 1844 | |
042cea27 | 1845 | #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX) |
edfb4389 | 1846 | /* Reason: cryptodev-vhost-user property "chardev" */ |
042cea27 GA |
1847 | if (g_str_equal(type, "cryptodev-vhost-user")) { |
1848 | return false; | |
1849 | } | |
1850 | #endif | |
1851 | ||
3578389b CX |
1852 | /* Reason: vhost-user-blk-server property "node-name" */ |
1853 | if (g_str_equal(type, "vhost-user-blk-server")) { | |
1854 | return false; | |
1855 | } | |
9d3e12e8 | 1856 | /* |
edfb4389 | 1857 | * Reason: filter-* property "netdev" etc. |
9d3e12e8 TH |
1858 | */ |
1859 | if (g_str_equal(type, "filter-buffer") || | |
f6d3afb5 | 1860 | g_str_equal(type, "filter-dump") || |
d46f75b2 | 1861 | g_str_equal(type, "filter-mirror") || |
7dce4e6f | 1862 | g_str_equal(type, "filter-redirector") || |
e6eee8ab | 1863 | g_str_equal(type, "colo-compare") || |
646c5478 PD |
1864 | g_str_equal(type, "filter-rewriter") || |
1865 | g_str_equal(type, "filter-replay")) { | |
7dbb11c8 YH |
1866 | return false; |
1867 | } | |
1868 | ||
b86f59c7 CF |
1869 | /* |
1870 | * Allocation of large amounts of memory may delay | |
6546d0db EH |
1871 | * chardev initialization for too long, and trigger timeouts |
1872 | * on software that waits for a monitor socket to be created | |
1873 | * (e.g. libvirt). | |
1874 | */ | |
1875 | if (g_str_has_prefix(type, "memory-backend-")) { | |
1876 | return false; | |
1877 | } | |
1878 | ||
f08f9271 DB |
1879 | return true; |
1880 | } | |
1881 | ||
d8fb7d09 | 1882 | static void qemu_apply_machine_options(QDict *qdict) |
7a84268d PB |
1883 | { |
1884 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
4b7acd2a PB |
1885 | const char *boot_order = NULL; |
1886 | const char *boot_once = NULL; | |
7a84268d PB |
1887 | QemuOpts *opts; |
1888 | ||
d8fb7d09 | 1889 | object_set_properties_from_keyval(OBJECT(current_machine), qdict, false, &error_fatal); |
7a84268d PB |
1890 | current_machine->ram_size = ram_size; |
1891 | current_machine->maxram_size = maxram_size; | |
1892 | current_machine->ram_slots = ram_slots; | |
1893 | ||
1894 | opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL); | |
1895 | if (opts) { | |
1896 | boot_order = qemu_opt_get(opts, "order"); | |
1897 | if (boot_order) { | |
1898 | validate_bootdevices(boot_order, &error_fatal); | |
1899 | } | |
1900 | ||
1901 | boot_once = qemu_opt_get(opts, "once"); | |
1902 | if (boot_once) { | |
1903 | validate_bootdevices(boot_once, &error_fatal); | |
1904 | } | |
1905 | ||
1906 | boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu); | |
1907 | boot_strict = qemu_opt_get_bool(opts, "strict", false); | |
1908 | } | |
1909 | ||
1910 | if (!boot_order) { | |
1911 | boot_order = machine_class->default_boot_order; | |
1912 | } | |
1913 | ||
1914 | current_machine->boot_order = boot_order; | |
4b7acd2a | 1915 | current_machine->boot_once = boot_once; |
7a84268d PB |
1916 | |
1917 | if (semihosting_enabled() && !semihosting_get_argc()) { | |
7a84268d | 1918 | /* fall back to the -kernel/-append */ |
d8fb7d09 | 1919 | semihosting_arg_fallback(current_machine->kernel_filename, current_machine->kernel_cmdline); |
7a84268d | 1920 | } |
fe68090e PB |
1921 | |
1922 | if (current_machine->smp.cpus > 1) { | |
1923 | Error *blocker = NULL; | |
1924 | error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); | |
1925 | replay_add_blocker(blocker); | |
1926 | } | |
7a84268d PB |
1927 | } |
1928 | ||
64418657 PB |
1929 | static void qemu_create_early_backends(void) |
1930 | { | |
1931 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
66c2207f TH |
1932 | #if defined(CONFIG_SDL) |
1933 | const bool use_sdl = (dpy.type == DISPLAY_TYPE_SDL); | |
1934 | #else | |
1935 | const bool use_sdl = false; | |
1936 | #endif | |
1937 | #if defined(CONFIG_GTK) | |
1938 | const bool use_gtk = (dpy.type == DISPLAY_TYPE_GTK); | |
1939 | #else | |
1940 | const bool use_gtk = false; | |
1941 | #endif | |
64418657 | 1942 | |
66c2207f | 1943 | if ((alt_grab || ctrl_grab) && !use_sdl) { |
64418657 PB |
1944 | error_report("-alt-grab and -ctrl-grab are only valid " |
1945 | "for SDL, ignoring option"); | |
1946 | } | |
66c2207f | 1947 | if (dpy.has_window_close && !use_gtk && !use_sdl) { |
fe86fe23 | 1948 | error_report("window-close is only valid for GTK and SDL, " |
64418657 PB |
1949 | "ignoring option"); |
1950 | } | |
1951 | ||
1952 | qemu_display_early_init(&dpy); | |
1953 | qemu_console_early_init(); | |
1954 | ||
1955 | if (dpy.has_gl && dpy.gl != DISPLAYGL_MODE_OFF && display_opengl == 0) { | |
1956 | #if defined(CONFIG_OPENGL) | |
1957 | error_report("OpenGL is not supported by the display"); | |
1958 | #else | |
1959 | error_report("OpenGL support is disabled"); | |
1960 | #endif | |
1961 | exit(1); | |
1962 | } | |
1963 | ||
bc2f4fcb | 1964 | object_option_foreach_add(object_create_early); |
64418657 PB |
1965 | |
1966 | /* spice needs the timers to be initialized by this point */ | |
3d76c3b6 | 1967 | /* spice must initialize before audio as it changes the default audiodev */ |
64418657 PB |
1968 | /* spice must initialize before chardevs (for spicevmc and spiceport) */ |
1969 | qemu_spice.init(); | |
1970 | ||
1971 | qemu_opts_foreach(qemu_find_opts("chardev"), | |
1972 | chardev_init_func, NULL, &error_fatal); | |
1973 | ||
1974 | #ifdef CONFIG_VIRTFS | |
1975 | qemu_opts_foreach(qemu_find_opts("fsdev"), | |
1976 | fsdev_init_func, NULL, &error_fatal); | |
1977 | #endif | |
1978 | ||
1979 | /* | |
1980 | * Note: we need to create audio and block backends before | |
d8fb7d09 | 1981 | * setting machine properties, so they can be referred to. |
64418657 PB |
1982 | */ |
1983 | configure_blockdev(&bdo_queue, machine_class, snapshot); | |
1984 | audio_init_audiodevs(); | |
1985 | } | |
1986 | ||
f08f9271 DB |
1987 | |
1988 | /* | |
1989 | * The remainder of object creation happens after the | |
9abce56d | 1990 | * creation of chardev, fsdev, net clients and device data types. |
f08f9271 | 1991 | */ |
bc2f4fcb | 1992 | static bool object_create_late(const char *type) |
f08f9271 | 1993 | { |
bc2f4fcb | 1994 | return !object_create_early(type); |
f08f9271 DB |
1995 | } |
1996 | ||
07a91b1a PB |
1997 | static void qemu_create_late_backends(void) |
1998 | { | |
1999 | if (qtest_chrdev) { | |
2000 | qtest_server_init(qtest_chrdev, qtest_log, &error_fatal); | |
2001 | } | |
2002 | ||
2003 | net_init_clients(&error_fatal); | |
2004 | ||
bc2f4fcb | 2005 | object_option_foreach_add(object_create_late); |
07a91b1a PB |
2006 | |
2007 | if (tpm_init() < 0) { | |
2008 | exit(1); | |
2009 | } | |
2010 | ||
2011 | qemu_opts_foreach(qemu_find_opts("mon"), | |
2012 | mon_init_func, NULL, &error_fatal); | |
2013 | ||
2014 | if (foreach_device_config(DEV_SERIAL, serial_parse) < 0) | |
2015 | exit(1); | |
2016 | if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) | |
2017 | exit(1); | |
2018 | if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0) | |
2019 | exit(1); | |
2020 | ||
2021 | /* now chardevs have been created we may have semihosting to connect */ | |
2022 | qemu_semihosting_connect_chardevs(); | |
2023 | qemu_semihosting_console_init(); | |
2024 | } | |
f08f9271 | 2025 | |
f5c9fcb8 PB |
2026 | static bool have_custom_ram_size(void) |
2027 | { | |
2028 | QemuOpts *opts = qemu_find_opts_singleton("memory"); | |
2029 | return !!qemu_opt_get_size(opts, "size", 0); | |
2030 | } | |
2031 | ||
b24986e7 PB |
2032 | static void qemu_resolve_machine_memdev(void) |
2033 | { | |
2034 | if (current_machine->ram_memdev_id) { | |
2035 | Object *backend; | |
2036 | ram_addr_t backend_size; | |
2037 | ||
2038 | backend = object_resolve_path_type(current_machine->ram_memdev_id, | |
2039 | TYPE_MEMORY_BACKEND, NULL); | |
2040 | if (!backend) { | |
2041 | error_report("Memory backend '%s' not found", | |
2042 | current_machine->ram_memdev_id); | |
2043 | exit(EXIT_FAILURE); | |
2044 | } | |
2045 | backend_size = object_property_get_uint(backend, "size", &error_abort); | |
2046 | if (have_custom_ram_size() && backend_size != ram_size) { | |
2047 | error_report("Size specified by -m option must match size of " | |
2048 | "explicitly specified 'memory-backend' property"); | |
2049 | exit(EXIT_FAILURE); | |
2050 | } | |
2051 | if (mem_path) { | |
2052 | error_report("'-mem-path' can't be used together with" | |
2053 | "'-machine memory-backend'"); | |
2054 | exit(EXIT_FAILURE); | |
2055 | } | |
2056 | ram_size = backend_size; | |
2057 | } | |
2058 | ||
2059 | if (!xen_enabled()) { | |
2060 | /* On 32-bit hosts, QEMU is limited by virtual address space */ | |
2061 | if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) { | |
2062 | error_report("at most 2047 MB RAM can be simulated"); | |
2063 | exit(1); | |
2064 | } | |
2065 | } | |
2066 | } | |
2067 | ||
f5c9fcb8 | 2068 | static void set_memory_options(MachineClass *mc) |
3b9985e9 MA |
2069 | { |
2070 | uint64_t sz; | |
2071 | const char *mem_str; | |
076b35b5 | 2072 | const ram_addr_t default_ram_size = mc->default_ram_size; |
3b9985e9 | 2073 | QemuOpts *opts = qemu_find_opts_singleton("memory"); |
bbe2d25c EH |
2074 | Location loc; |
2075 | ||
2076 | loc_push_none(&loc); | |
2077 | qemu_opts_loc_restore(opts); | |
3b9985e9 MA |
2078 | |
2079 | sz = 0; | |
2080 | mem_str = qemu_opt_get(opts, "size"); | |
2081 | if (mem_str) { | |
2082 | if (!*mem_str) { | |
2083 | error_report("missing 'size' option value"); | |
2084 | exit(EXIT_FAILURE); | |
2085 | } | |
2086 | ||
2087 | sz = qemu_opt_get_size(opts, "size", ram_size); | |
2088 | ||
2089 | /* Fix up legacy suffix-less format */ | |
2090 | if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) { | |
2091 | uint64_t overflow_check = sz; | |
2092 | ||
3dc54b0e PMD |
2093 | sz *= MiB; |
2094 | if (sz / MiB != overflow_check) { | |
3b9985e9 MA |
2095 | error_report("too large 'size' option value"); |
2096 | exit(EXIT_FAILURE); | |
2097 | } | |
2098 | } | |
2099 | } | |
2100 | ||
2101 | /* backward compatibility behaviour for case "-m 0" */ | |
2102 | if (sz == 0) { | |
2103 | sz = default_ram_size; | |
2104 | } | |
2105 | ||
2106 | sz = QEMU_ALIGN_UP(sz, 8192); | |
5c30ef93 CB |
2107 | if (mc->fixup_ram_size) { |
2108 | sz = mc->fixup_ram_size(sz); | |
2109 | } | |
3b9985e9 MA |
2110 | ram_size = sz; |
2111 | if (ram_size != sz) { | |
2112 | error_report("ram size too large"); | |
2113 | exit(EXIT_FAILURE); | |
2114 | } | |
2115 | ||
f5c9fcb8 | 2116 | maxram_size = ram_size; |
3b9985e9 | 2117 | |
951f2269 | 2118 | if (qemu_opt_get(opts, "maxmem")) { |
3b9985e9 MA |
2119 | uint64_t slots; |
2120 | ||
2121 | sz = qemu_opt_get_size(opts, "maxmem", 0); | |
214224ad | 2122 | slots = qemu_opt_get_number(opts, "slots", 0); |
3b9985e9 | 2123 | if (sz < ram_size) { |
214224ad PK |
2124 | error_report("invalid value of -m option maxmem: " |
2125 | "maximum memory size (0x%" PRIx64 ") must be at least " | |
2126 | "the initial memory size (0x" RAM_ADDR_FMT ")", | |
2127 | sz, ram_size); | |
3b9985e9 | 2128 | exit(EXIT_FAILURE); |
951f2269 | 2129 | } else if (slots && sz == ram_size) { |
214224ad PK |
2130 | error_report("invalid value of -m option maxmem: " |
2131 | "memory slots were specified but maximum memory size " | |
2132 | "(0x%" PRIx64 ") is equal to the initial memory size " | |
2133 | "(0x" RAM_ADDR_FMT ")", sz, ram_size); | |
3b9985e9 MA |
2134 | exit(EXIT_FAILURE); |
2135 | } | |
2136 | ||
f5c9fcb8 PB |
2137 | maxram_size = sz; |
2138 | ram_slots = slots; | |
951f2269 DH |
2139 | } else if (qemu_opt_get(opts, "slots")) { |
2140 | error_report("invalid -m option value: missing 'maxmem' option"); | |
3b9985e9 MA |
2141 | exit(EXIT_FAILURE); |
2142 | } | |
bbe2d25c EH |
2143 | |
2144 | loc_pop(&loc); | |
f5c9fcb8 PB |
2145 | } |
2146 | ||
d8fb7d09 | 2147 | static void qemu_create_machine(QDict *qdict) |
f5c9fcb8 | 2148 | { |
d8fb7d09 | 2149 | MachineClass *machine_class = select_machine(qdict, &error_fatal); |
f5c9fcb8 PB |
2150 | object_set_machine_compat_props(machine_class->compat_props); |
2151 | ||
2152 | set_memory_options(machine_class); | |
2153 | ||
2154 | current_machine = MACHINE(object_new_with_class(OBJECT_CLASS(machine_class))); | |
f5c9fcb8 PB |
2155 | object_property_add_child(object_get_root(), "machine", |
2156 | OBJECT(current_machine)); | |
2157 | object_property_add_child(container_get(OBJECT(current_machine), | |
2158 | "/unattached"), | |
2159 | "sysbus", OBJECT(sysbus_get_default())); | |
2160 | ||
2161 | if (machine_class->minimum_page_bits) { | |
2162 | if (!set_preferred_target_page_bits(machine_class->minimum_page_bits)) { | |
2163 | /* This would be a board error: specifying a minimum smaller than | |
2164 | * a target's compile-time fixed setting. | |
2165 | */ | |
2166 | g_assert_not_reached(); | |
2167 | } | |
2168 | } | |
2169 | ||
2170 | cpu_exec_init_all(); | |
2171 | page_size_init(); | |
2172 | ||
2173 | if (machine_class->hw_version) { | |
2174 | qemu_set_hw_version(machine_class->hw_version); | |
2175 | } | |
2176 | ||
f5c9fcb8 PB |
2177 | /* |
2178 | * Get the default machine options from the machine if it is not already | |
2179 | * specified either by the configuration file or by the command line. | |
2180 | */ | |
2181 | if (machine_class->default_machine_opts) { | |
d8fb7d09 PB |
2182 | QDict *default_opts = |
2183 | keyval_parse(machine_class->default_machine_opts, NULL, NULL, | |
2184 | &error_abort); | |
dadafe67 | 2185 | qemu_apply_legacy_machine_options(default_opts); |
d8fb7d09 PB |
2186 | object_set_properties_from_keyval(OBJECT(current_machine), default_opts, |
2187 | false, &error_abort); | |
2188 | qobject_unref(default_opts); | |
f5c9fcb8 | 2189 | } |
3b9985e9 MA |
2190 | } |
2191 | ||
8d76bfe8 EH |
2192 | static int global_init_func(void *opaque, QemuOpts *opts, Error **errp) |
2193 | { | |
2194 | GlobalProperty *g; | |
2195 | ||
2196 | g = g_malloc0(sizeof(*g)); | |
2197 | g->driver = qemu_opt_get(opts, "driver"); | |
2198 | g->property = qemu_opt_get(opts, "property"); | |
2199 | g->value = qemu_opt_get(opts, "value"); | |
8d76bfe8 EH |
2200 | qdev_prop_register_global(g); |
2201 | return 0; | |
2202 | } | |
2203 | ||
c0d4aa82 PB |
2204 | /* |
2205 | * Return whether configuration group @group is stored in QemuOpts, or | |
2206 | * recorded as one or more QDicts by qemu_record_config_group. | |
2207 | */ | |
2208 | static bool is_qemuopts_group(const char *group) | |
2209 | { | |
d8fb7d09 | 2210 | if (g_str_equal(group, "object") || |
e4383ca2 PB |
2211 | g_str_equal(group, "machine") || |
2212 | g_str_equal(group, "smp-opts")) { | |
49e98769 PB |
2213 | return false; |
2214 | } | |
c0d4aa82 PB |
2215 | return true; |
2216 | } | |
2217 | ||
2218 | static void qemu_record_config_group(const char *group, QDict *dict, | |
2219 | bool from_json, Error **errp) | |
2220 | { | |
49e98769 PB |
2221 | if (g_str_equal(group, "object")) { |
2222 | Visitor *v = qobject_input_visitor_new_keyval(QOBJECT(dict)); | |
2223 | object_option_add_visitor(v); | |
2224 | visit_free(v); | |
d8fb7d09 PB |
2225 | } else if (g_str_equal(group, "machine")) { |
2226 | /* | |
2227 | * Cannot merge string-valued and type-safe dictionaries, so JSON | |
2228 | * is not accepted yet for -M. | |
2229 | */ | |
2230 | assert(!from_json); | |
2231 | keyval_merge(machine_opts_dict, dict, errp); | |
e4383ca2 PB |
2232 | } else if (g_str_equal(group, "smp-opts")) { |
2233 | machine_merge_property("smp", dict, &error_fatal); | |
49e98769 PB |
2234 | } else { |
2235 | abort(); | |
2236 | } | |
c0d4aa82 PB |
2237 | } |
2238 | ||
2239 | /* | |
2240 | * Parse non-QemuOpts config file groups, pass the rest to | |
2241 | * qemu_config_do_parse. | |
2242 | */ | |
2243 | static void qemu_parse_config_group(const char *group, QDict *qdict, | |
2244 | void *opaque, Error **errp) | |
2245 | { | |
2246 | QObject *crumpled; | |
2247 | if (is_qemuopts_group(group)) { | |
2248 | qemu_config_do_parse(group, qdict, opaque, errp); | |
2249 | return; | |
2250 | } | |
2251 | ||
2252 | crumpled = qdict_crumple(qdict, errp); | |
2253 | if (!crumpled) { | |
2254 | return; | |
2255 | } | |
838e3700 PB |
2256 | switch (qobject_type(crumpled)) { |
2257 | case QTYPE_QDICT: | |
2258 | qemu_record_config_group(group, qobject_to(QDict, crumpled), false, errp); | |
2259 | break; | |
2260 | case QTYPE_QLIST: | |
c0d4aa82 | 2261 | error_setg(errp, "Lists cannot be at top level of a configuration section"); |
838e3700 PB |
2262 | break; |
2263 | default: | |
2264 | g_assert_not_reached(); | |
c0d4aa82 | 2265 | } |
838e3700 | 2266 | qobject_unref(crumpled); |
c0d4aa82 PB |
2267 | } |
2268 | ||
f7544edc | 2269 | static void qemu_read_default_config_file(Error **errp) |
726401be | 2270 | { |
f7544edc | 2271 | ERRP_GUARD(); |
726401be | 2272 | int ret; |
580e6ad6 | 2273 | g_autofree char *file = get_relocated_path(CONFIG_QEMU_CONFDIR "/qemu.conf"); |
726401be | 2274 | |
c0d4aa82 | 2275 | ret = qemu_read_config_file(file, qemu_parse_config_group, errp); |
f7544edc PB |
2276 | if (ret < 0) { |
2277 | if (ret == -ENOENT) { | |
2278 | error_free(*errp); | |
2279 | *errp = NULL; | |
2280 | } | |
726401be | 2281 | } |
726401be EH |
2282 | } |
2283 | ||
c0d4aa82 | 2284 | static void qemu_set_option(const char *str, Error **errp) |
ed7fa564 | 2285 | { |
ed7fa564 PB |
2286 | char group[64], id[64], arg[64]; |
2287 | QemuOptsList *list; | |
2288 | QemuOpts *opts; | |
2289 | int rc, offset; | |
2290 | ||
2291 | rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset); | |
2292 | if (rc < 3 || str[offset] != '=') { | |
c0d4aa82 PB |
2293 | error_setg(errp, "can't parse: \"%s\"", str); |
2294 | return; | |
ed7fa564 PB |
2295 | } |
2296 | ||
c0d4aa82 PB |
2297 | if (!is_qemuopts_group(group)) { |
2298 | error_setg(errp, "-set is not supported with %s", group); | |
2299 | } else { | |
2300 | list = qemu_find_opts_err(group, errp); | |
2301 | if (list) { | |
2302 | opts = qemu_opts_find(list, id); | |
2303 | if (!opts) { | |
2304 | error_setg(errp, "there is no %s \"%s\" defined", group, id); | |
2305 | return; | |
2306 | } | |
2307 | qemu_opt_set(opts, arg, str + offset + 1, errp); | |
2308 | } | |
ed7fa564 | 2309 | } |
ed7fa564 PB |
2310 | } |
2311 | ||
a0660e0b PX |
2312 | static void user_register_global_props(void) |
2313 | { | |
2314 | qemu_opts_foreach(qemu_find_opts("global"), | |
2315 | global_init_func, NULL, NULL); | |
2316 | } | |
2317 | ||
7f8b6126 PB |
2318 | static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp) |
2319 | { | |
8191d368 | 2320 | icount_configure(opts, errp); |
7f8b6126 PB |
2321 | return 0; |
2322 | } | |
2323 | ||
12ceaef6 PB |
2324 | static int accelerator_set_property(void *opaque, |
2325 | const char *name, const char *value, | |
2326 | Error **errp) | |
2327 | { | |
2328 | return object_parse_property_opt(opaque, name, value, "accel", errp); | |
2329 | } | |
2330 | ||
deda73e8 PB |
2331 | static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) |
2332 | { | |
6f6e1698 PB |
2333 | bool *p_init_failed = opaque; |
2334 | const char *acc = qemu_opt_get(opts, "accel"); | |
2335 | AccelClass *ac = accel_find(acc); | |
fc5cf826 | 2336 | AccelState *accel; |
6f6e1698 | 2337 | int ret; |
eaf65114 TH |
2338 | bool qtest_with_kvm; |
2339 | ||
2340 | qtest_with_kvm = g_str_equal(acc, "kvm") && qtest_chrdev != NULL; | |
6f6e1698 PB |
2341 | |
2342 | if (!ac) { | |
8b90f1c5 | 2343 | *p_init_failed = true; |
eaf65114 TH |
2344 | if (!qtest_with_kvm) { |
2345 | error_report("invalid accelerator %s", acc); | |
2346 | } | |
6f6e1698 PB |
2347 | return 0; |
2348 | } | |
fc5cf826 | 2349 | accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac))); |
fe174132 | 2350 | object_apply_compat_props(OBJECT(accel)); |
12ceaef6 PB |
2351 | qemu_opt_foreach(opts, accelerator_set_property, |
2352 | accel, | |
2353 | &error_fatal); | |
2354 | ||
fc5cf826 | 2355 | ret = accel_init_machine(accel, current_machine); |
6f6e1698 PB |
2356 | if (ret < 0) { |
2357 | *p_init_failed = true; | |
eaf65114 TH |
2358 | if (!qtest_with_kvm || ret != -ENOENT) { |
2359 | error_report("failed to initialize %s: %s", acc, strerror(-ret)); | |
2360 | } | |
6f6e1698 PB |
2361 | return 0; |
2362 | } | |
fe174132 | 2363 | |
6f6e1698 | 2364 | return 1; |
deda73e8 PB |
2365 | } |
2366 | ||
28a09617 | 2367 | static void configure_accelerators(const char *progname) |
deda73e8 | 2368 | { |
28a09617 | 2369 | bool init_failed = false; |
28a09617 PB |
2370 | |
2371 | qemu_opts_foreach(qemu_find_opts("icount"), | |
2372 | do_configure_icount, NULL, &error_fatal); | |
2373 | ||
6f6e1698 | 2374 | if (QTAILQ_EMPTY(&qemu_accel_opts.head)) { |
60ee3552 RH |
2375 | char **accel_list, **tmp; |
2376 | ||
7245ca74 | 2377 | if (accelerators == NULL) { |
6f6e1698 | 2378 | /* Select the default accelerator */ |
755ee1f3 RH |
2379 | bool have_tcg = accel_find("tcg"); |
2380 | bool have_kvm = accel_find("kvm"); | |
2381 | ||
2382 | if (have_tcg && have_kvm) { | |
2383 | if (g_str_has_suffix(progname, "kvm")) { | |
6f6e1698 | 2384 | /* If the program name ends with "kvm", we prefer KVM */ |
7245ca74 | 2385 | accelerators = "kvm:tcg"; |
6f6e1698 | 2386 | } else { |
7245ca74 | 2387 | accelerators = "tcg:kvm"; |
6f6e1698 | 2388 | } |
755ee1f3 | 2389 | } else if (have_kvm) { |
7245ca74 | 2390 | accelerators = "kvm"; |
755ee1f3 | 2391 | } else if (have_tcg) { |
7245ca74 | 2392 | accelerators = "tcg"; |
755ee1f3 RH |
2393 | } else { |
2394 | error_report("No accelerator selected and" | |
2395 | " no default accelerator available"); | |
2396 | exit(1); | |
28a09617 PB |
2397 | } |
2398 | } | |
7245ca74 | 2399 | accel_list = g_strsplit(accelerators, ":", 0); |
28a09617 | 2400 | |
a024b090 | 2401 | for (tmp = accel_list; *tmp; tmp++) { |
6f6e1698 PB |
2402 | /* |
2403 | * Filter invalid accelerators here, to prevent obscenities | |
2404 | * such as "-machine accel=tcg,,thread=single". | |
2405 | */ | |
2406 | if (accel_find(*tmp)) { | |
2407 | qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp, true); | |
8b90f1c5 PB |
2408 | } else { |
2409 | init_failed = true; | |
2410 | error_report("invalid accelerator %s", *tmp); | |
6f6e1698 | 2411 | } |
28a09617 | 2412 | } |
adb464ff | 2413 | g_strfreev(accel_list); |
6f6e1698 | 2414 | } else { |
7245ca74 | 2415 | if (accelerators != NULL) { |
6f6e1698 PB |
2416 | error_report("The -accel and \"-machine accel=\" options are incompatible"); |
2417 | exit(1); | |
28a09617 PB |
2418 | } |
2419 | } | |
28a09617 | 2420 | |
6f6e1698 PB |
2421 | if (!qemu_opts_foreach(qemu_find_opts("accel"), |
2422 | do_configure_accelerator, &init_failed, &error_fatal)) { | |
28a09617 | 2423 | if (!init_failed) { |
6f6e1698 | 2424 | error_report("no accelerator found"); |
28a09617 PB |
2425 | } |
2426 | exit(1); | |
2427 | } | |
2428 | ||
eaf65114 | 2429 | if (init_failed && !qtest_chrdev) { |
4f7f5893 | 2430 | AccelClass *ac = ACCEL_GET_CLASS(current_accel()); |
8b90f1c5 | 2431 | error_report("falling back to %s", ac->name); |
28a09617 PB |
2432 | } |
2433 | ||
740b1759 | 2434 | if (icount_enabled() && !tcg_enabled()) { |
deda73e8 PB |
2435 | error_report("-icount is not allowed with hardware virtualization"); |
2436 | exit(1); | |
2437 | } | |
2438 | } | |
2439 | ||
ffac16fa | 2440 | static void create_default_memdev(MachineState *ms, const char *path) |
900c0ba3 IM |
2441 | { |
2442 | Object *obj; | |
2443 | MachineClass *mc = MACHINE_GET_CLASS(ms); | |
2444 | ||
2445 | obj = object_new(path ? TYPE_MEMORY_BACKEND_FILE : TYPE_MEMORY_BACKEND_RAM); | |
2446 | if (path) { | |
5325cc34 | 2447 | object_property_set_str(obj, "mem-path", path, &error_fatal); |
900c0ba3 | 2448 | } |
5325cc34 | 2449 | object_property_set_int(obj, "size", ms->ram_size, &error_fatal); |
900c0ba3 | 2450 | object_property_add_child(object_get_objects_root(), mc->default_ram_id, |
d2623129 | 2451 | obj); |
d96c4d5f | 2452 | /* Ensure backend's memory region name is equal to mc->default_ram_id */ |
5325cc34 MA |
2453 | object_property_set_bool(obj, "x-use-canonical-path-for-ramblock-id", |
2454 | false, &error_fatal); | |
900c0ba3 IM |
2455 | user_creatable_complete(USER_CREATABLE(obj), &error_fatal); |
2456 | object_unref(obj); | |
5325cc34 | 2457 | object_property_set_str(OBJECT(ms), "memory-backend", mc->default_ram_id, |
900c0ba3 IM |
2458 | &error_fatal); |
2459 | } | |
2460 | ||
d8fb7d09 | 2461 | static void qemu_validate_options(const QDict *machine_opts) |
58c91595 | 2462 | { |
d8fb7d09 PB |
2463 | const char *kernel_filename = qdict_get_try_str(machine_opts, "kernel"); |
2464 | const char *initrd_filename = qdict_get_try_str(machine_opts, "initrd"); | |
2465 | const char *kernel_cmdline = qdict_get_try_str(machine_opts, "append"); | |
58c91595 PB |
2466 | |
2467 | if (kernel_filename == NULL) { | |
2468 | if (kernel_cmdline != NULL) { | |
2469 | error_report("-append only allowed with -kernel option"); | |
2470 | exit(1); | |
2471 | } | |
2472 | ||
2473 | if (initrd_filename != NULL) { | |
2474 | error_report("-initrd only allowed with -kernel option"); | |
2475 | exit(1); | |
2476 | } | |
2477 | } | |
2478 | ||
7691bdef | 2479 | if (loadvm && preconfig_requested) { |
90285ec8 PB |
2480 | error_report("'preconfig' and 'loadvm' options are " |
2481 | "mutually exclusive"); | |
2482 | exit(EXIT_FAILURE); | |
2483 | } | |
8fafaa04 PB |
2484 | if (incoming && preconfig_requested && strcmp(incoming, "defer") != 0) { |
2485 | error_report("'preconfig' supports '-incoming defer' only"); | |
58c91595 PB |
2486 | exit(EXIT_FAILURE); |
2487 | } | |
2488 | ||
2489 | #ifdef CONFIG_CURSES | |
2490 | if (is_daemonized() && dpy.type == DISPLAY_TYPE_CURSES) { | |
2491 | error_report("curses display cannot be used with -daemonize"); | |
2492 | exit(1); | |
2493 | } | |
2494 | #endif | |
2495 | } | |
2496 | ||
4d2c17b0 PB |
2497 | static void qemu_process_sugar_options(void) |
2498 | { | |
2499 | if (mem_prealloc) { | |
e4383ca2 PB |
2500 | QObject *smp = qdict_get(machine_opts_dict, "smp"); |
2501 | if (smp && qobject_type(smp) == QTYPE_QDICT) { | |
2502 | QObject *cpus = qdict_get(qobject_to(QDict, smp), "cpus"); | |
2503 | if (cpus && qobject_type(cpus) == QTYPE_QSTRING) { | |
2504 | const char *val = qstring_get_str(qobject_to(QString, cpus)); | |
2505 | object_register_sugar_prop("memory-backend", "prealloc-threads", | |
2506 | val, false); | |
2507 | } | |
2508 | } | |
a8dc82ce | 2509 | object_register_sugar_prop("memory-backend", "prealloc", "on", false); |
4d2c17b0 PB |
2510 | } |
2511 | ||
2512 | if (watchdog) { | |
2513 | int i = select_watchdog(watchdog); | |
2514 | if (i > 0) | |
2515 | exit (i == 1 ? 1 : 0); | |
2516 | } | |
2517 | } | |
2518 | ||
2a5ad60b AJ |
2519 | /* -action processing */ |
2520 | ||
2521 | /* | |
2522 | * Process all the -action parameters parsed from cmdline. | |
2523 | */ | |
2524 | static int process_runstate_actions(void *opaque, QemuOpts *opts, Error **errp) | |
2525 | { | |
2526 | Error *local_err = NULL; | |
2527 | QDict *qdict = qemu_opts_to_qdict(opts, NULL); | |
2528 | QObject *ret = NULL; | |
2529 | qmp_marshal_set_action(qdict, &ret, &local_err); | |
2530 | qobject_unref(ret); | |
2531 | qobject_unref(qdict); | |
2532 | if (local_err) { | |
2533 | error_propagate(errp, local_err); | |
2534 | return 1; | |
2535 | } | |
2536 | return 0; | |
2537 | } | |
2538 | ||
0546c060 PB |
2539 | static void qemu_process_early_options(void) |
2540 | { | |
0546c060 PB |
2541 | #ifdef CONFIG_SECCOMP |
2542 | QemuOptsList *olist = qemu_find_opts_err("sandbox", NULL); | |
2543 | if (olist) { | |
2544 | qemu_opts_foreach(olist, parse_sandbox, NULL, &error_fatal); | |
2545 | } | |
2546 | #endif | |
2547 | ||
2548 | qemu_opts_foreach(qemu_find_opts("name"), | |
2549 | parse_name, NULL, &error_fatal); | |
2550 | ||
2a5ad60b AJ |
2551 | if (qemu_opts_foreach(qemu_find_opts("action"), |
2552 | process_runstate_actions, NULL, &error_fatal)) { | |
2553 | exit(1); | |
2554 | } | |
2555 | ||
0546c060 PB |
2556 | #ifndef _WIN32 |
2557 | qemu_opts_foreach(qemu_find_opts("add-fd"), | |
2558 | parse_add_fd, NULL, &error_fatal); | |
2559 | ||
2560 | qemu_opts_foreach(qemu_find_opts("add-fd"), | |
2561 | cleanup_add_fd, NULL, &error_fatal); | |
2562 | #endif | |
2563 | ||
0546c060 | 2564 | /* Open the logfile at this point and set the log mask if necessary. */ |
b2528af1 RH |
2565 | { |
2566 | int mask = 0; | |
2567 | if (log_mask) { | |
2568 | mask = qemu_str_to_log_mask(log_mask); | |
2569 | if (!mask) { | |
2570 | qemu_print_log_usage(stdout); | |
2571 | exit(1); | |
2572 | } | |
0546c060 | 2573 | } |
b2528af1 | 2574 | qemu_set_log_filename_flags(log_file, mask, &error_fatal); |
0546c060 PB |
2575 | } |
2576 | ||
2c65db5e | 2577 | qemu_add_default_firmwarepath(); |
0546c060 PB |
2578 | } |
2579 | ||
2580 | static void qemu_process_help_options(void) | |
2581 | { | |
0546c060 PB |
2582 | /* |
2583 | * Check for -cpu help and -device help before we call select_machine(), | |
2584 | * which will return an error if the architecture has no default machine | |
2585 | * type and the user did not specify one, so that the user doesn't need | |
2586 | * to say '-cpu help -machine something'. | |
2587 | */ | |
2588 | if (cpu_option && is_help_option(cpu_option)) { | |
2589 | list_cpus(cpu_option); | |
2590 | exit(0); | |
2591 | } | |
2592 | ||
2593 | if (qemu_opts_foreach(qemu_find_opts("device"), | |
2594 | device_help_func, NULL, NULL)) { | |
2595 | exit(0); | |
2596 | } | |
2597 | ||
2598 | /* -L help lists the data directories and exits. */ | |
2599 | if (list_data_dirs) { | |
2c65db5e | 2600 | qemu_list_data_dirs(); |
0546c060 PB |
2601 | exit(0); |
2602 | } | |
2603 | } | |
2604 | ||
2605 | static void qemu_maybe_daemonize(const char *pid_file) | |
2606 | { | |
38f71349 | 2607 | Error *err = NULL; |
0546c060 PB |
2608 | |
2609 | os_daemonize(); | |
2610 | rcu_disable_atfork(); | |
2611 | ||
2612 | if (pid_file && !qemu_write_pidfile(pid_file, &err)) { | |
2613 | error_reportf_err(err, "cannot create PID file: "); | |
2614 | exit(1); | |
2615 | } | |
2616 | ||
2617 | qemu_unlink_pidfile_notifier.notify = qemu_unlink_pidfile; | |
2618 | qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier); | |
2619 | } | |
2620 | ||
7691bdef PB |
2621 | static void qemu_init_displays(void) |
2622 | { | |
2623 | DisplayState *ds; | |
2624 | ||
2625 | /* init local displays */ | |
2626 | ds = init_displaystate(); | |
2627 | qemu_display_init(ds, &dpy); | |
2628 | ||
2629 | /* must be after terminal init, SDL library changes signal handlers */ | |
2630 | os_setup_signal_handling(); | |
2631 | ||
2632 | /* init remote displays */ | |
2633 | #ifdef CONFIG_VNC | |
2634 | qemu_opts_foreach(qemu_find_opts("vnc"), | |
2635 | vnc_init_func, NULL, &error_fatal); | |
2636 | #endif | |
2637 | ||
2638 | if (using_spice) { | |
2639 | qemu_spice.display_init(); | |
2640 | } | |
2641 | } | |
2642 | ||
d8e4de41 PB |
2643 | static void qemu_init_board(void) |
2644 | { | |
2645 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
2646 | ||
2647 | if (machine_class->default_ram_id && current_machine->ram_size && | |
2648 | numa_uses_legacy_mem() && !current_machine->ram_memdev_id) { | |
2649 | create_default_memdev(current_machine, mem_path); | |
2650 | } | |
2651 | ||
8a745974 | 2652 | /* process plugin before CPUs are created, but once -smp has been parsed */ |
0572f558 | 2653 | qemu_plugin_load_list(&plugin_list, &error_fatal); |
8a745974 | 2654 | |
2f181fbd | 2655 | /* From here on we enter MACHINE_PHASE_INITIALIZED. */ |
d8e4de41 PB |
2656 | machine_run_board_init(current_machine); |
2657 | ||
fe9f70a1 | 2658 | drive_check_orphaned(); |
d8e4de41 PB |
2659 | |
2660 | realtime_init(); | |
2661 | ||
2662 | if (hax_enabled()) { | |
2663 | /* FIXME: why isn't cpu_synchronize_all_post_init enough? */ | |
2664 | hax_sync_vcpus(); | |
2665 | } | |
2666 | } | |
2667 | ||
2668 | static void qemu_create_cli_devices(void) | |
2669 | { | |
5dacda51 KW |
2670 | DeviceOption *opt; |
2671 | ||
d8e4de41 PB |
2672 | soundhw_init(); |
2673 | ||
2674 | qemu_opts_foreach(qemu_find_opts("fw_cfg"), | |
2675 | parse_fw_cfg, fw_cfg_find(), &error_fatal); | |
2676 | ||
2677 | /* init USB devices */ | |
2678 | if (machine_usb(current_machine)) { | |
2679 | if (foreach_device_config(DEV_USB, usb_parse) < 0) | |
2680 | exit(1); | |
2681 | } | |
2682 | ||
2683 | /* init generic devices */ | |
2684 | rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); | |
2685 | qemu_opts_foreach(qemu_find_opts("device"), | |
2686 | device_init_func, NULL, &error_fatal); | |
5dacda51 | 2687 | QTAILQ_FOREACH(opt, &device_opts, next) { |
64b4529a | 2688 | DeviceState *dev; |
5dacda51 KW |
2689 | loc_push_restore(&opt->loc); |
2690 | /* | |
2691 | * TODO Eventually we should call qmp_device_add() here to make sure it | |
2692 | * behaves the same, but QMP still has to accept incorrectly typed | |
2693 | * options until libvirt is fixed and we want to be strict on the CLI | |
2694 | * from the start, so call qdev_device_add_from_qdict() directly for | |
2695 | * now. | |
2696 | */ | |
64b4529a DB |
2697 | dev = qdev_device_add_from_qdict(opt->opts, true, &error_fatal); |
2698 | object_unref(OBJECT(dev)); | |
5dacda51 KW |
2699 | loc_pop(&opt->loc); |
2700 | } | |
d8e4de41 PB |
2701 | rom_reset_order_override(); |
2702 | } | |
2703 | ||
2704 | static void qemu_machine_creation_done(void) | |
2705 | { | |
abc27d42 DG |
2706 | MachineState *machine = MACHINE(qdev_get_machine()); |
2707 | ||
d8e4de41 PB |
2708 | /* Did we create any drives that we failed to create a device for? */ |
2709 | drive_check_orphaned(); | |
2710 | ||
2711 | /* Don't warn about the default network setup that you get if | |
2712 | * no command line -net or -netdev options are specified. There | |
2713 | * are two cases that we would otherwise complain about: | |
2714 | * (1) board doesn't support a NIC but the implicit "-net nic" | |
2715 | * requested one | |
2716 | * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic" | |
2717 | * sets up a nic that isn't connected to anything. | |
2718 | */ | |
2719 | if (!default_net && (!qtest_enabled() || has_defaults)) { | |
2720 | net_check_clients(); | |
2721 | } | |
2722 | ||
cca686b4 PB |
2723 | qdev_prop_check_globals(); |
2724 | ||
d8e4de41 PB |
2725 | qdev_machine_creation_done(); |
2726 | ||
abc27d42 DG |
2727 | if (machine->cgs) { |
2728 | /* | |
2729 | * Verify that Confidential Guest Support has actually been initialized | |
2730 | */ | |
2731 | assert(machine->cgs->ready); | |
2732 | } | |
2733 | ||
f66dc873 | 2734 | if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) { |
d8e4de41 PB |
2735 | exit(1); |
2736 | } | |
d8e4de41 PB |
2737 | } |
2738 | ||
b4e1a342 PB |
2739 | void qmp_x_exit_preconfig(Error **errp) |
2740 | { | |
2f181fbd | 2741 | if (phase_check(PHASE_MACHINE_INITIALIZED)) { |
b4e1a342 PB |
2742 | error_setg(errp, "The command is permitted only before machine initialization"); |
2743 | return; | |
2744 | } | |
2745 | ||
2746 | qemu_init_board(); | |
2747 | qemu_create_cli_devices(); | |
2748 | qemu_machine_creation_done(); | |
2749 | ||
2750 | if (loadvm) { | |
f9734d5d | 2751 | load_snapshot(loadvm, NULL, false, NULL, &error_fatal); |
b4e1a342 PB |
2752 | } |
2753 | if (replay_mode != REPLAY_MODE_NONE) { | |
2754 | replay_vmstate_init(); | |
2755 | } | |
2756 | ||
2757 | if (incoming) { | |
2758 | Error *local_err = NULL; | |
2759 | if (strcmp(incoming, "defer") != 0) { | |
2760 | qmp_migrate_incoming(incoming, &local_err); | |
2761 | if (local_err) { | |
2762 | error_reportf_err(local_err, "-incoming %s: ", incoming); | |
2763 | exit(1); | |
2764 | } | |
2765 | } | |
2766 | } else if (autostart) { | |
2767 | qmp_cont(NULL); | |
2768 | } | |
2769 | } | |
2770 | ||
7b733862 | 2771 | void qemu_init(int argc, char **argv, char **envp) |
0824d6fc | 2772 | { |
7a84268d | 2773 | QemuOpts *opts; |
d1cdd92e | 2774 | QemuOpts *icount_opts = NULL, *accel_opts = NULL; |
03b0ba70 | 2775 | QemuOptsList *olist; |
cd6f1169 | 2776 | int optind; |
6530a97b | 2777 | const char *optarg; |
0056ae24 | 2778 | MachineClass *machine_class; |
f29a5614 | 2779 | bool userconfig = true; |
abfd9ce3 | 2780 | FILE *vmstate_dump_file = NULL; |
0b5538c3 | 2781 | |
4d454574 | 2782 | qemu_add_opts(&qemu_drive_opts); |
968854c8 AK |
2783 | qemu_add_drive_opts(&qemu_legacy_drive_opts); |
2784 | qemu_add_drive_opts(&qemu_common_drive_opts); | |
2785 | qemu_add_drive_opts(&qemu_drive_opts); | |
c5f3014b | 2786 | qemu_add_drive_opts(&bdrv_runtime_opts); |
4d454574 PB |
2787 | qemu_add_opts(&qemu_chardev_opts); |
2788 | qemu_add_opts(&qemu_device_opts); | |
2789 | qemu_add_opts(&qemu_netdev_opts); | |
78cd6f7b | 2790 | qemu_add_opts(&qemu_nic_opts); |
4d454574 PB |
2791 | qemu_add_opts(&qemu_net_opts); |
2792 | qemu_add_opts(&qemu_rtc_opts); | |
2793 | qemu_add_opts(&qemu_global_opts); | |
2794 | qemu_add_opts(&qemu_mon_opts); | |
2795 | qemu_add_opts(&qemu_trace_opts); | |
42229a75 | 2796 | qemu_plugin_add_opts(); |
4d454574 | 2797 | qemu_add_opts(&qemu_option_rom_opts); |
8d4e9146 | 2798 | qemu_add_opts(&qemu_accel_opts); |
6e1d3c1c | 2799 | qemu_add_opts(&qemu_mem_opts); |
12b7f57e | 2800 | qemu_add_opts(&qemu_smp_opts); |
4d454574 | 2801 | qemu_add_opts(&qemu_boot_opts); |
4d454574 PB |
2802 | qemu_add_opts(&qemu_add_fd_opts); |
2803 | qemu_add_opts(&qemu_object_opts); | |
d1a0cf73 | 2804 | qemu_add_opts(&qemu_tpmdev_opts); |
1fdd4748 | 2805 | qemu_add_opts(&qemu_overcommit_opts); |
5e2ac519 | 2806 | qemu_add_opts(&qemu_msg_opts); |
5d12f961 | 2807 | qemu_add_opts(&qemu_name_opts); |
0042109a | 2808 | qemu_add_opts(&qemu_numa_opts); |
1ad9580b | 2809 | qemu_add_opts(&qemu_icount_opts); |
a38bb079 | 2810 | qemu_add_opts(&qemu_semihosting_config_opts); |
81b2b810 | 2811 | qemu_add_opts(&qemu_fw_cfg_opts); |
2a5ad60b | 2812 | qemu_add_opts(&qemu_action_opts); |
34294e2f | 2813 | module_call_init(MODULE_INIT_OPTS); |
4d454574 | 2814 | |
efd7ab22 PB |
2815 | error_init(argv[0]); |
2816 | qemu_init_exec_dir(argv[0]); | |
142c6b1a | 2817 | |
c80cafa0 | 2818 | qemu_init_arch_modules(); |
5ebbfecc | 2819 | |
efd7ab22 | 2820 | qemu_init_subsystems(); |
41bd639b | 2821 | |
292444cb AL |
2822 | /* first pass of option parsing */ |
2823 | optind = 1; | |
2824 | while (optind < argc) { | |
2825 | if (argv[optind][0] != '-') { | |
2826 | /* disk image */ | |
28e68d68 | 2827 | optind++; |
292444cb AL |
2828 | } else { |
2829 | const QEMUOption *popt; | |
2830 | ||
2831 | popt = lookup_opt(argc, argv, &optarg, &optind); | |
2832 | switch (popt->index) { | |
f29a5614 EH |
2833 | case QEMU_OPTION_nouserconfig: |
2834 | userconfig = false; | |
2835 | break; | |
292444cb AL |
2836 | } |
2837 | } | |
2838 | } | |
2839 | ||
d8fb7d09 | 2840 | machine_opts_dict = qdict_new(); |
1ea06c39 | 2841 | if (userconfig) { |
f7544edc | 2842 | qemu_read_default_config_file(&error_fatal); |
292444cb AL |
2843 | } |
2844 | ||
2845 | /* second pass of option parsing */ | |
cd6f1169 | 2846 | optind = 1; |
0824d6fc | 2847 | for(;;) { |
cd6f1169 | 2848 | if (optind >= argc) |
0824d6fc | 2849 | break; |
6530a97b | 2850 | if (argv[optind][0] != '-') { |
17f30eae | 2851 | loc_set_cmdline(argv, optind, 1); |
d1cdd92e | 2852 | drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS); |
cd6f1169 FB |
2853 | } else { |
2854 | const QEMUOption *popt; | |
2855 | ||
6530a97b | 2856 | popt = lookup_opt(argc, argv, &optarg, &optind); |
ad96090a | 2857 | if (!(popt->arch_mask & arch_type)) { |
da002526 | 2858 | error_report("Option not supported for this target"); |
ad96090a BS |
2859 | exit(1); |
2860 | } | |
cd6f1169 | 2861 | switch(popt->index) { |
94fc95cd JM |
2862 | case QEMU_OPTION_cpu: |
2863 | /* hw initialization will check this */ | |
c1c8cfe5 | 2864 | cpu_option = optarg; |
94fc95cd | 2865 | break; |
cd6f1169 | 2866 | case QEMU_OPTION_hda: |
cd6f1169 | 2867 | case QEMU_OPTION_hdb: |
cc1daa40 FB |
2868 | case QEMU_OPTION_hdc: |
2869 | case QEMU_OPTION_hdd: | |
2292ddae MA |
2870 | drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg, |
2871 | HD_OPTS); | |
fc01f7e7 | 2872 | break; |
42e5f393 MA |
2873 | case QEMU_OPTION_blockdev: |
2874 | { | |
2875 | Visitor *v; | |
651af51c | 2876 | BlockdevOptionsQueueEntry *bdo; |
42e5f393 | 2877 | |
92917cd2 MA |
2878 | v = qobject_input_visitor_new_str(optarg, "driver", |
2879 | &error_fatal); | |
42e5f393 | 2880 | |
651af51c | 2881 | bdo = g_new(BlockdevOptionsQueueEntry, 1); |
42e5f393 MA |
2882 | visit_type_BlockdevOptions(v, NULL, &bdo->bdo, |
2883 | &error_fatal); | |
2884 | visit_free(v); | |
2885 | loc_save(&bdo->loc); | |
2886 | QSIMPLEQ_INSERT_TAIL(&bdo_queue, bdo, entry); | |
2887 | break; | |
2888 | } | |
e4bcb14c | 2889 | case QEMU_OPTION_drive: |
cc67f28e EGE |
2890 | opts = qemu_opts_parse_noisily(qemu_find_opts("drive"), |
2891 | optarg, false); | |
2892 | if (opts == NULL) { | |
e2982c3a MT |
2893 | exit(1); |
2894 | } | |
99efa84d | 2895 | break; |
d058fe03 | 2896 | case QEMU_OPTION_set: |
c0d4aa82 | 2897 | qemu_set_option(optarg, &error_fatal); |
99efa84d | 2898 | break; |
d0fef6fb GH |
2899 | case QEMU_OPTION_global: |
2900 | if (qemu_global_option(optarg) != 0) | |
2901 | exit(1); | |
99efa84d | 2902 | break; |
3e3d5815 | 2903 | case QEMU_OPTION_mtdblock: |
2292ddae | 2904 | drive_add(IF_MTD, -1, optarg, MTD_OPTS); |
3e3d5815 | 2905 | break; |
a1bb27b1 | 2906 | case QEMU_OPTION_sd: |
80f4d9fc | 2907 | drive_add(IF_SD, -1, optarg, SD_OPTS); |
a1bb27b1 | 2908 | break; |
86f55663 | 2909 | case QEMU_OPTION_pflash: |
2292ddae | 2910 | drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS); |
86f55663 | 2911 | break; |
cd6f1169 | 2912 | case QEMU_OPTION_snapshot: |
25863975 PD |
2913 | { |
2914 | Error *blocker = NULL; | |
2915 | snapshot = 1; | |
2916 | error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, | |
2917 | "-snapshot"); | |
2918 | replay_add_blocker(blocker); | |
2919 | } | |
33e3963e | 2920 | break; |
268a362c | 2921 | case QEMU_OPTION_numa: |
70b94331 MA |
2922 | opts = qemu_opts_parse_noisily(qemu_find_opts("numa"), |
2923 | optarg, true); | |
0042109a WG |
2924 | if (!opts) { |
2925 | exit(1); | |
2926 | } | |
268a362c | 2927 | break; |
1472a95b | 2928 | case QEMU_OPTION_display: |
e3af9f9a | 2929 | parse_display(optarg); |
1472a95b | 2930 | break; |
cd6f1169 | 2931 | case QEMU_OPTION_nographic: |
d8fb7d09 | 2932 | qdict_put_str(machine_opts_dict, "graphics", "off"); |
cfc58cf3 | 2933 | nographic = true; |
0c8d7065 | 2934 | dpy.type = DISPLAY_TYPE_NONE; |
a20dd508 | 2935 | break; |
4d3b6f6e | 2936 | case QEMU_OPTION_curses: |
6695e4c0 TH |
2937 | warn_report("-curses is deprecated, " |
2938 | "use -display curses instead."); | |
47b05369 | 2939 | #ifdef CONFIG_CURSES |
14f130fa | 2940 | dpy.type = DISPLAY_TYPE_CURSES; |
47b05369 | 2941 | #else |
e08bb301 | 2942 | error_report("curses or iconv support is disabled"); |
47b05369 | 2943 | exit(1); |
4d3b6f6e | 2944 | #endif |
47b05369 | 2945 | break; |
a171fe39 | 2946 | case QEMU_OPTION_portrait: |
9312805d VK |
2947 | graphic_rotate = 90; |
2948 | break; | |
2949 | case QEMU_OPTION_rotate: | |
2950 | graphic_rotate = strtol(optarg, (char **) &optarg, 10); | |
2951 | if (graphic_rotate != 0 && graphic_rotate != 90 && | |
2952 | graphic_rotate != 180 && graphic_rotate != 270) { | |
f61eddcb | 2953 | error_report("only 90, 180, 270 deg rotation is available"); |
9312805d VK |
2954 | exit(1); |
2955 | } | |
a171fe39 | 2956 | break; |
cd6f1169 | 2957 | case QEMU_OPTION_kernel: |
d8fb7d09 | 2958 | qdict_put_str(machine_opts_dict, "kernel", optarg); |
a0abe474 PM |
2959 | break; |
2960 | case QEMU_OPTION_initrd: | |
d8fb7d09 | 2961 | qdict_put_str(machine_opts_dict, "initrd", optarg); |
a20dd508 | 2962 | break; |
cd6f1169 | 2963 | case QEMU_OPTION_append: |
d8fb7d09 | 2964 | qdict_put_str(machine_opts_dict, "append", optarg); |
313aa567 | 2965 | break; |
412beee6 | 2966 | case QEMU_OPTION_dtb: |
d8fb7d09 | 2967 | qdict_put_str(machine_opts_dict, "dtb", optarg); |
412beee6 | 2968 | break; |
cd6f1169 | 2969 | case QEMU_OPTION_cdrom: |
2292ddae | 2970 | drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS); |
36b486bb | 2971 | break; |
cd6f1169 | 2972 | case QEMU_OPTION_boot: |
70b94331 MA |
2973 | opts = qemu_opts_parse_noisily(qemu_find_opts("boot-opts"), |
2974 | optarg, true); | |
8281abd5 MA |
2975 | if (!opts) { |
2976 | exit(1); | |
36b486bb FB |
2977 | } |
2978 | break; | |
cd6f1169 | 2979 | case QEMU_OPTION_fda: |
cd6f1169 | 2980 | case QEMU_OPTION_fdb: |
2292ddae MA |
2981 | drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda, |
2982 | optarg, FD_OPTS); | |
c45886db | 2983 | break; |
52ca8d6a FB |
2984 | case QEMU_OPTION_no_fd_bootchk: |
2985 | fd_bootchk = 0; | |
2986 | break; | |
a1ea458f | 2987 | case QEMU_OPTION_netdev: |
d30300f7 | 2988 | default_net = 0; |
3329f07b | 2989 | if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) { |
a1ea458f MM |
2990 | exit(1); |
2991 | } | |
2992 | break; | |
78cd6f7b TH |
2993 | case QEMU_OPTION_nic: |
2994 | default_net = 0; | |
2995 | if (net_client_parse(qemu_find_opts("nic"), optarg) == -1) { | |
2996 | exit(1); | |
2997 | } | |
2998 | break; | |
7c9d8e07 | 2999 | case QEMU_OPTION_net: |
d30300f7 | 3000 | default_net = 0; |
3329f07b | 3001 | if (net_client_parse(qemu_find_opts("net"), optarg) == -1) { |
c4b1fcc0 FB |
3002 | exit(1); |
3003 | } | |
702c651c | 3004 | break; |
f9dadc98 RS |
3005 | #ifdef CONFIG_LIBISCSI |
3006 | case QEMU_OPTION_iscsi: | |
70b94331 MA |
3007 | opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"), |
3008 | optarg, false); | |
f9dadc98 RS |
3009 | if (!opts) { |
3010 | exit(1); | |
3011 | } | |
3012 | break; | |
c7f74643 | 3013 | #endif |
1d14ffa9 | 3014 | case QEMU_OPTION_audio_help: |
71830221 | 3015 | audio_legacy_help(); |
1d14ffa9 FB |
3016 | exit (0); |
3017 | break; | |
71830221 KZ |
3018 | case QEMU_OPTION_audiodev: |
3019 | audio_parse_option(optarg); | |
3020 | break; | |
1d14ffa9 FB |
3021 | case QEMU_OPTION_soundhw: |
3022 | select_soundhw (optarg); | |
3023 | break; | |
cd6f1169 | 3024 | case QEMU_OPTION_h: |
15f82208 | 3025 | help(0); |
cd6f1169 | 3026 | break; |
9bd7e6d9 PB |
3027 | case QEMU_OPTION_version: |
3028 | version(); | |
3029 | exit(0); | |
3030 | break; | |
3b9985e9 | 3031 | case QEMU_OPTION_m: |
70b94331 MA |
3032 | opts = qemu_opts_parse_noisily(qemu_find_opts("memory"), |
3033 | optarg, true); | |
6e1d3c1c IM |
3034 | if (!opts) { |
3035 | exit(EXIT_FAILURE); | |
3036 | } | |
cd6f1169 | 3037 | break; |
d1a0cf73 SB |
3038 | #ifdef CONFIG_TPM |
3039 | case QEMU_OPTION_tpmdev: | |
3040 | if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) { | |
3041 | exit(1); | |
3042 | } | |
3043 | break; | |
3044 | #endif | |
c902760f MT |
3045 | case QEMU_OPTION_mempath: |
3046 | mem_path = optarg; | |
3047 | break; | |
c902760f MT |
3048 | case QEMU_OPTION_mem_prealloc: |
3049 | mem_prealloc = 1; | |
3050 | break; | |
cd6f1169 | 3051 | case QEMU_OPTION_d: |
c235d738 MF |
3052 | log_mask = optarg; |
3053 | break; | |
3054 | case QEMU_OPTION_D: | |
3055 | log_file = optarg; | |
cd6f1169 | 3056 | break; |
3514552e | 3057 | case QEMU_OPTION_DFILTER: |
bd6fee9f | 3058 | qemu_set_dfilter_ranges(optarg, &error_fatal); |
3514552e | 3059 | break; |
9c09a251 RH |
3060 | case QEMU_OPTION_seed: |
3061 | qemu_guest_random_seed_main(optarg, &error_fatal); | |
3062 | break; | |
cd6f1169 | 3063 | case QEMU_OPTION_s: |
ef0c4a0d | 3064 | add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); |
cd6f1169 | 3065 | break; |
59030a8c | 3066 | case QEMU_OPTION_gdb: |
ef0c4a0d | 3067 | add_device_config(DEV_GDB, optarg); |
cd6f1169 | 3068 | break; |
cd6f1169 | 3069 | case QEMU_OPTION_L: |
37146e7e RJ |
3070 | if (is_help_option(optarg)) { |
3071 | list_data_dirs = true; | |
2a1cce90 | 3072 | } else { |
ea1edcd7 | 3073 | qemu_add_data_dir(g_strdup(optarg)); |
4524051c | 3074 | } |
cd6f1169 | 3075 | break; |
1192dad8 | 3076 | case QEMU_OPTION_bios: |
d8fb7d09 | 3077 | qdict_put_str(machine_opts_dict, "firmware", optarg); |
1192dad8 | 3078 | break; |
1b530a6d AJ |
3079 | case QEMU_OPTION_singlestep: |
3080 | singlestep = 1; | |
3081 | break; | |
cd6f1169 | 3082 | case QEMU_OPTION_S: |
3c07f8e8 | 3083 | autostart = 0; |
cd6f1169 | 3084 | break; |
99efa84d MA |
3085 | case QEMU_OPTION_k: |
3086 | keyboard_layout = optarg; | |
3087 | break; | |
3893c124 | 3088 | case QEMU_OPTION_vga: |
a369da5f | 3089 | vga_model = optarg; |
7f1b17f2 | 3090 | default_vga = 0; |
1bfe856e | 3091 | break; |
e9b137c2 FB |
3092 | case QEMU_OPTION_g: |
3093 | { | |
3094 | const char *p; | |
3095 | int w, h, depth; | |
3096 | p = optarg; | |
3097 | w = strtol(p, (char **)&p, 10); | |
3098 | if (w <= 0) { | |
3099 | graphic_error: | |
f61eddcb | 3100 | error_report("invalid resolution or depth"); |
e9b137c2 FB |
3101 | exit(1); |
3102 | } | |
3103 | if (*p != 'x') | |
3104 | goto graphic_error; | |
3105 | p++; | |
3106 | h = strtol(p, (char **)&p, 10); | |
3107 | if (h <= 0) | |
3108 | goto graphic_error; | |
3109 | if (*p == 'x') { | |
3110 | p++; | |
3111 | depth = strtol(p, (char **)&p, 10); | |
8ac919a0 LV |
3112 | if (depth != 1 && depth != 2 && depth != 4 && |
3113 | depth != 8 && depth != 15 && depth != 16 && | |
e9b137c2 FB |
3114 | depth != 24 && depth != 32) |
3115 | goto graphic_error; | |
3116 | } else if (*p == '\0') { | |
3117 | depth = graphic_depth; | |
3118 | } else { | |
3119 | goto graphic_error; | |
3120 | } | |
3b46e624 | 3121 | |
e9b137c2 FB |
3122 | graphic_width = w; |
3123 | graphic_height = h; | |
3124 | graphic_depth = depth; | |
3125 | } | |
3126 | break; | |
20d8a3ed TS |
3127 | case QEMU_OPTION_echr: |
3128 | { | |
3129 | char *r; | |
3130 | term_escape_char = strtol(optarg, &r, 0); | |
3131 | if (r == optarg) | |
3132 | printf("Bad argument to echr\n"); | |
3133 | break; | |
3134 | } | |
82c643ff | 3135 | case QEMU_OPTION_monitor: |
6ca5582d | 3136 | default_monitor = 0; |
70e098af | 3137 | if (strncmp(optarg, "none", 4)) { |
4821cd4c | 3138 | monitor_parse(optarg, "readline", false); |
70e098af | 3139 | } |
6ca5582d GH |
3140 | break; |
3141 | case QEMU_OPTION_qmp: | |
4821cd4c HR |
3142 | monitor_parse(optarg, "control", false); |
3143 | default_monitor = 0; | |
3144 | break; | |
3145 | case QEMU_OPTION_qmp_pretty: | |
3146 | monitor_parse(optarg, "control", true); | |
2d114dc1 | 3147 | default_monitor = 0; |
82c643ff | 3148 | break; |
22a0e04b | 3149 | case QEMU_OPTION_mon: |
70b94331 MA |
3150 | opts = qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg, |
3151 | true); | |
22a0e04b | 3152 | if (!opts) { |
22a0e04b GH |
3153 | exit(1); |
3154 | } | |
2d114dc1 | 3155 | default_monitor = 0; |
22a0e04b | 3156 | break; |
191bc01b | 3157 | case QEMU_OPTION_chardev: |
70b94331 MA |
3158 | opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), |
3159 | optarg, true); | |
191bc01b | 3160 | if (!opts) { |
191bc01b GH |
3161 | exit(1); |
3162 | } | |
191bc01b | 3163 | break; |
74db920c | 3164 | case QEMU_OPTION_fsdev: |
03b0ba70 GH |
3165 | olist = qemu_find_opts("fsdev"); |
3166 | if (!olist) { | |
5dfdae81 | 3167 | error_report("fsdev support is disabled"); |
03b0ba70 GH |
3168 | exit(1); |
3169 | } | |
70b94331 | 3170 | opts = qemu_opts_parse_noisily(olist, optarg, true); |
74db920c | 3171 | if (!opts) { |
74db920c GS |
3172 | exit(1); |
3173 | } | |
3174 | break; | |
3d54abc7 | 3175 | case QEMU_OPTION_virtfs: { |
e14ea479 SH |
3176 | QemuOpts *fsdev; |
3177 | QemuOpts *device; | |
1a6ed33c AM |
3178 | const char *writeout, *sock_fd, *socket, *path, *security_model, |
3179 | *multidevs; | |
3d54abc7 | 3180 | |
03b0ba70 GH |
3181 | olist = qemu_find_opts("virtfs"); |
3182 | if (!olist) { | |
5dfdae81 | 3183 | error_report("virtfs support is disabled"); |
03b0ba70 GH |
3184 | exit(1); |
3185 | } | |
70b94331 | 3186 | opts = qemu_opts_parse_noisily(olist, optarg, true); |
3d54abc7 | 3187 | if (!opts) { |
3d54abc7 GS |
3188 | exit(1); |
3189 | } | |
3190 | ||
fbcbf101 | 3191 | if (qemu_opt_get(opts, "fsdriver") == NULL || |
99519f0a | 3192 | qemu_opt_get(opts, "mount_tag") == NULL) { |
8afb9000 | 3193 | error_report("Usage: -virtfs fsdriver,mount_tag=tag"); |
9ce56db6 VJ |
3194 | exit(1); |
3195 | } | |
e14ea479 | 3196 | fsdev = qemu_opts_create(qemu_find_opts("fsdev"), |
3baa0a6a | 3197 | qemu_opts_id(opts) ?: |
8be7e7e4 LC |
3198 | qemu_opt_get(opts, "mount_tag"), |
3199 | 1, NULL); | |
e14ea479 | 3200 | if (!fsdev) { |
3baa0a6a | 3201 | error_report("duplicate or invalid fsdev id: %s", |
f61eddcb | 3202 | qemu_opt_get(opts, "mount_tag")); |
3d54abc7 GS |
3203 | exit(1); |
3204 | } | |
d3ab98e6 AK |
3205 | |
3206 | writeout = qemu_opt_get(opts, "writeout"); | |
3207 | if (writeout) { | |
3208 | #ifdef CONFIG_SYNC_FILE_RANGE | |
f43e47db | 3209 | qemu_opt_set(fsdev, "writeout", writeout, &error_abort); |
d3ab98e6 | 3210 | #else |
f61eddcb EH |
3211 | error_report("writeout=immediate not supported " |
3212 | "on this platform"); | |
d3ab98e6 AK |
3213 | exit(1); |
3214 | #endif | |
3215 | } | |
f43e47db MA |
3216 | qemu_opt_set(fsdev, "fsdriver", |
3217 | qemu_opt_get(opts, "fsdriver"), &error_abort); | |
32b69436 GK |
3218 | path = qemu_opt_get(opts, "path"); |
3219 | if (path) { | |
3220 | qemu_opt_set(fsdev, "path", path, &error_abort); | |
3221 | } | |
3222 | security_model = qemu_opt_get(opts, "security_model"); | |
3223 | if (security_model) { | |
3224 | qemu_opt_set(fsdev, "security_model", security_model, | |
3225 | &error_abort); | |
3226 | } | |
84a87cc4 MK |
3227 | socket = qemu_opt_get(opts, "socket"); |
3228 | if (socket) { | |
f43e47db | 3229 | qemu_opt_set(fsdev, "socket", socket, &error_abort); |
84a87cc4 | 3230 | } |
4c793dda MK |
3231 | sock_fd = qemu_opt_get(opts, "sock_fd"); |
3232 | if (sock_fd) { | |
f43e47db | 3233 | qemu_opt_set(fsdev, "sock_fd", sock_fd, &error_abort); |
4c793dda | 3234 | } |
e14ea479 | 3235 | |
2c74c2cb | 3236 | qemu_opt_set_bool(fsdev, "readonly", |
cccb7967 MA |
3237 | qemu_opt_get_bool(opts, "readonly", 0), |
3238 | &error_abort); | |
1a6ed33c AM |
3239 | multidevs = qemu_opt_get(opts, "multidevs"); |
3240 | if (multidevs) { | |
3241 | qemu_opt_set(fsdev, "multidevs", multidevs, &error_abort); | |
3242 | } | |
87ea75d5 PC |
3243 | device = qemu_opts_create(qemu_find_opts("device"), NULL, 0, |
3244 | &error_abort); | |
f43e47db | 3245 | qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort); |
e14ea479 | 3246 | qemu_opt_set(device, "fsdev", |
3baa0a6a | 3247 | qemu_opts_id(fsdev), &error_abort); |
e14ea479 | 3248 | qemu_opt_set(device, "mount_tag", |
f43e47db | 3249 | qemu_opt_get(opts, "mount_tag"), &error_abort); |
3d54abc7 GS |
3250 | break; |
3251 | } | |
82c643ff | 3252 | case QEMU_OPTION_serial: |
998bbd74 GH |
3253 | add_device_config(DEV_SERIAL, optarg); |
3254 | default_serial = 0; | |
18141ed6 JK |
3255 | if (strncmp(optarg, "mon:", 4) == 0) { |
3256 | default_monitor = 0; | |
3257 | } | |
82c643ff | 3258 | break; |
9dd986cc | 3259 | case QEMU_OPTION_watchdog: |
09aaa160 | 3260 | if (watchdog) { |
f61eddcb | 3261 | error_report("only one watchdog option may be given"); |
7b733862 | 3262 | exit(1); |
09aaa160 | 3263 | } |
d12b64ea | 3264 | warn_report("-watchdog is deprecated; use -device instead."); |
09aaa160 | 3265 | watchdog = optarg; |
9dd986cc | 3266 | break; |
2a5ad60b AJ |
3267 | case QEMU_OPTION_action: |
3268 | olist = qemu_find_opts("action"); | |
3269 | if (!qemu_opts_parse_noisily(olist, optarg, false)) { | |
3270 | exit(1); | |
3271 | } | |
3272 | break; | |
22afb46e PB |
3273 | case QEMU_OPTION_watchdog_action: { |
3274 | QemuOpts *opts; | |
3275 | opts = qemu_opts_create(qemu_find_opts("action"), NULL, 0, &error_abort); | |
3276 | qemu_opt_set(opts, "watchdog", optarg, &error_abort); | |
9dd986cc | 3277 | break; |
22afb46e | 3278 | } |
6508fe59 | 3279 | case QEMU_OPTION_parallel: |
6a5e8b0e GH |
3280 | add_device_config(DEV_PARALLEL, optarg); |
3281 | default_parallel = 0; | |
18141ed6 JK |
3282 | if (strncmp(optarg, "mon:", 4) == 0) { |
3283 | default_monitor = 0; | |
3284 | } | |
6508fe59 | 3285 | break; |
c9f398e5 PA |
3286 | case QEMU_OPTION_debugcon: |
3287 | add_device_config(DEV_DEBUGCON, optarg); | |
3288 | break; | |
99efa84d MA |
3289 | case QEMU_OPTION_loadvm: |
3290 | loadvm = optarg; | |
3291 | break; | |
d63d307f | 3292 | case QEMU_OPTION_full_screen: |
0c8d7065 GH |
3293 | dpy.has_full_screen = true; |
3294 | dpy.full_screen = true; | |
d63d307f | 3295 | break; |
3780e197 TS |
3296 | case QEMU_OPTION_alt_grab: |
3297 | alt_grab = 1; | |
d46156fd TH |
3298 | warn_report("-alt-grab is deprecated, please use " |
3299 | "-display sdl,grab-mod=lshift-lctrl-lalt instead."); | |
3780e197 | 3300 | break; |
0ca9f8a4 DK |
3301 | case QEMU_OPTION_ctrl_grab: |
3302 | ctrl_grab = 1; | |
d46156fd TH |
3303 | warn_report("-ctrl-grab is deprecated, please use " |
3304 | "-display sdl,grab-mod=rctrl instead."); | |
0ca9f8a4 | 3305 | break; |
7d957bd8 | 3306 | case QEMU_OPTION_sdl: |
6695e4c0 | 3307 | warn_report("-sdl is deprecated, use -display sdl instead."); |
24f6ff86 | 3308 | #ifdef CONFIG_SDL |
fe91f36a | 3309 | dpy.type = DISPLAY_TYPE_SDL; |
7d957bd8 | 3310 | break; |
58fc096c | 3311 | #else |
f61eddcb | 3312 | error_report("SDL support is disabled"); |
58fc096c | 3313 | exit(1); |
667accab | 3314 | #endif |
f7cce898 | 3315 | case QEMU_OPTION_pidfile: |
93815bc2 | 3316 | pid_file = optarg; |
f7cce898 | 3317 | break; |
a09db21f FB |
3318 | case QEMU_OPTION_win2k_hack: |
3319 | win2k_install_hack = 1; | |
3320 | break; | |
8a92ea2f | 3321 | case QEMU_OPTION_acpitable: |
70b94331 MA |
3322 | opts = qemu_opts_parse_noisily(qemu_find_opts("acpi"), |
3323 | optarg, true); | |
f46e720a LE |
3324 | if (!opts) { |
3325 | exit(1); | |
3326 | } | |
9f57061c | 3327 | acpi_table_add(opts, &error_fatal); |
8a92ea2f | 3328 | break; |
b6f6e3d3 | 3329 | case QEMU_OPTION_smbios: |
70b94331 MA |
3330 | opts = qemu_opts_parse_noisily(qemu_find_opts("smbios"), |
3331 | optarg, false); | |
f46e720a LE |
3332 | if (!opts) { |
3333 | exit(1); | |
3334 | } | |
1007a37e | 3335 | smbios_entry_add(opts, &error_fatal); |
b6f6e3d3 | 3336 | break; |
81b2b810 | 3337 | case QEMU_OPTION_fwcfg: |
70b94331 MA |
3338 | opts = qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"), |
3339 | optarg, true); | |
81b2b810 GS |
3340 | if (opts == NULL) { |
3341 | exit(1); | |
3342 | } | |
3343 | break; | |
047f7038 | 3344 | case QEMU_OPTION_preconfig: |
7691bdef | 3345 | preconfig_requested = true; |
047f7038 | 3346 | break; |
7ba1e619 | 3347 | case QEMU_OPTION_enable_kvm: |
d8fb7d09 | 3348 | qdict_put_str(machine_opts_dict, "accel", "kvm"); |
303d4e86 | 3349 | break; |
364c3e6b | 3350 | case QEMU_OPTION_M: |
303d4e86 | 3351 | case QEMU_OPTION_machine: |
d8fb7d09 PB |
3352 | { |
3353 | bool help; | |
3354 | ||
3355 | keyval_parse_into(machine_opts_dict, optarg, "type", &help, &error_fatal); | |
3356 | if (help) { | |
3357 | machine_help_func(machine_opts_dict); | |
3358 | exit(EXIT_SUCCESS); | |
3359 | } | |
3360 | break; | |
303d4e86 | 3361 | } |
a20fa79f | 3362 | case QEMU_OPTION_accel: |
8d4e9146 FK |
3363 | accel_opts = qemu_opts_parse_noisily(qemu_find_opts("accel"), |
3364 | optarg, true); | |
3365 | optarg = qemu_opt_get(accel_opts, "accel"); | |
bde4d920 | 3366 | if (!optarg || is_help_option(optarg)) { |
cbe6d636 WSM |
3367 | printf("Accelerators supported in QEMU binary:\n"); |
3368 | GSList *el, *accel_list = object_class_get_list(TYPE_ACCEL, | |
3369 | false); | |
3370 | for (el = accel_list; el; el = el->next) { | |
3371 | gchar *typename = g_strdup(object_class_get_name( | |
3372 | OBJECT_CLASS(el->data))); | |
3373 | /* omit qtest which is used for tests only */ | |
3374 | if (g_strcmp0(typename, ACCEL_CLASS_NAME("qtest")) && | |
3375 | g_str_has_suffix(typename, ACCEL_CLASS_SUFFIX)) { | |
3376 | gchar **optname = g_strsplit(typename, | |
3377 | ACCEL_CLASS_SUFFIX, 0); | |
3378 | printf("%s\n", optname[0]); | |
4903602e | 3379 | g_strfreev(optname); |
cbe6d636 WSM |
3380 | } |
3381 | g_free(typename); | |
3382 | } | |
3383 | g_slist_free(accel_list); | |
a20fa79f | 3384 | exit(0); |
8d4e9146 FK |
3385 | } |
3386 | break; | |
bb36d470 | 3387 | case QEMU_OPTION_usb: |
d8fb7d09 | 3388 | qdict_put_str(machine_opts_dict, "usb", "on"); |
bb36d470 | 3389 | break; |
a594cfbf | 3390 | case QEMU_OPTION_usbdevice: |
d8fb7d09 | 3391 | qdict_put_str(machine_opts_dict, "usb", "on"); |
bd3c948d GH |
3392 | add_device_config(DEV_USB, optarg); |
3393 | break; | |
3394 | case QEMU_OPTION_device: | |
5dacda51 KW |
3395 | if (optarg[0] == '{') { |
3396 | QObject *obj = qobject_from_json(optarg, &error_fatal); | |
3397 | DeviceOption *opt = g_new0(DeviceOption, 1); | |
3398 | opt->opts = qobject_to(QDict, obj); | |
3399 | loc_save(&opt->loc); | |
3400 | assert(opt->opts != NULL); | |
3401 | QTAILQ_INSERT_TAIL(&device_opts, opt, next); | |
3402 | } else { | |
3403 | if (!qemu_opts_parse_noisily(qemu_find_opts("device"), | |
3404 | optarg, true)) { | |
3405 | exit(1); | |
3406 | } | |
f31d07d1 | 3407 | } |
a594cfbf | 3408 | break; |
6a00d601 | 3409 | case QEMU_OPTION_smp: |
f9dfae9c MA |
3410 | machine_parse_property_opt(qemu_find_opts("smp-opts"), |
3411 | "smp", optarg); | |
6a00d601 | 3412 | break; |
99efa84d | 3413 | case QEMU_OPTION_vnc: |
653c9747 | 3414 | vnc_parse(optarg); |
821601ea | 3415 | break; |
6515b203 | 3416 | case QEMU_OPTION_no_acpi: |
d8fb7d09 | 3417 | qdict_put_str(machine_opts_dict, "acpi", "off"); |
6515b203 | 3418 | break; |
16b29ae1 | 3419 | case QEMU_OPTION_no_hpet: |
d8fb7d09 | 3420 | qdict_put_str(machine_opts_dict, "hpet", "off"); |
16b29ae1 | 3421 | break; |
d1beab82 | 3422 | case QEMU_OPTION_no_reboot: |
2a5ad60b AJ |
3423 | olist = qemu_find_opts("action"); |
3424 | qemu_opts_parse_noisily(olist, "reboot=shutdown", false); | |
d1beab82 | 3425 | break; |
b2f76161 | 3426 | case QEMU_OPTION_no_shutdown: |
2a5ad60b | 3427 | olist = qemu_find_opts("action"); |
c27025e0 | 3428 | qemu_opts_parse_noisily(olist, "shutdown=pause", false); |
b2f76161 | 3429 | break; |
8fcb1b90 | 3430 | case QEMU_OPTION_uuid: |
9c5ce8db | 3431 | if (qemu_uuid_parse(optarg, &qemu_uuid) < 0) { |
4cd70f34 | 3432 | error_report("failed to parse UUID string: wrong format"); |
8fcb1b90 BS |
3433 | exit(1); |
3434 | } | |
fc3b3295 | 3435 | qemu_uuid_set = true; |
8fcb1b90 | 3436 | break; |
99efa84d MA |
3437 | case QEMU_OPTION_option_rom: |
3438 | if (nb_option_roms >= MAX_OPTION_ROMS) { | |
3e515373 | 3439 | error_report("too many option ROMs"); |
99efa84d MA |
3440 | exit(1); |
3441 | } | |
70b94331 MA |
3442 | opts = qemu_opts_parse_noisily(qemu_find_opts("option-rom"), |
3443 | optarg, true); | |
49295ebc MA |
3444 | if (!opts) { |
3445 | exit(1); | |
3446 | } | |
2e55e842 GN |
3447 | option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile"); |
3448 | option_rom[nb_option_roms].bootindex = | |
3449 | qemu_opt_get_number(opts, "bootindex", -1); | |
3450 | if (!option_rom[nb_option_roms].name) { | |
f61eddcb | 3451 | error_report("Option ROM file is not specified"); |
2e55e842 GN |
3452 | exit(1); |
3453 | } | |
99efa84d MA |
3454 | nb_option_roms++; |
3455 | break; | |
8e71621f | 3456 | case QEMU_OPTION_semihosting: |
f1672e6f | 3457 | qemu_semihosting_enable(); |
a38bb079 LI |
3458 | break; |
3459 | case QEMU_OPTION_semihosting_config: | |
f1672e6f | 3460 | if (qemu_semihosting_config_options(optarg) != 0) { |
a38bb079 LI |
3461 | exit(1); |
3462 | } | |
8e71621f | 3463 | break; |
c35734b2 | 3464 | case QEMU_OPTION_name: |
70b94331 MA |
3465 | opts = qemu_opts_parse_noisily(qemu_find_opts("name"), |
3466 | optarg, true); | |
5d12f961 DDAG |
3467 | if (!opts) { |
3468 | exit(1); | |
3469 | } | |
2880ffb0 MS |
3470 | /* Capture guest name if -msg guest-name is used later */ |
3471 | error_guest_name = qemu_opt_get(opts, "guest"); | |
c35734b2 | 3472 | break; |
66508601 BS |
3473 | case QEMU_OPTION_prom_env: |
3474 | if (nb_prom_envs >= MAX_PROM_ENVS) { | |
3e515373 | 3475 | error_report("too many prom variables"); |
66508601 BS |
3476 | exit(1); |
3477 | } | |
3478 | prom_envs[nb_prom_envs] = optarg; | |
3479 | nb_prom_envs++; | |
3480 | break; | |
2b8f2d41 AZ |
3481 | case QEMU_OPTION_old_param: |
3482 | old_param = 1; | |
05ebd537 | 3483 | break; |
1ed2fc1f | 3484 | case QEMU_OPTION_rtc: |
70b94331 MA |
3485 | opts = qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg, |
3486 | false); | |
1ed2fc1f | 3487 | if (!opts) { |
1ed2fc1f | 3488 | exit(1); |
7e0af5d0 FB |
3489 | } |
3490 | break; | |
2e70f6ef | 3491 | case QEMU_OPTION_icount: |
70b94331 MA |
3492 | icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"), |
3493 | optarg, true); | |
1ad9580b ST |
3494 | if (!icount_opts) { |
3495 | exit(1); | |
3496 | } | |
2e70f6ef | 3497 | break; |
5bb7910a | 3498 | case QEMU_OPTION_incoming: |
7c76235a DDAG |
3499 | if (!incoming) { |
3500 | runstate_set(RUN_STATE_INMIGRATE); | |
3501 | } | |
5bb7910a AL |
3502 | incoming = optarg; |
3503 | break; | |
d15c05fc | 3504 | case QEMU_OPTION_only_migratable: |
811f8652 | 3505 | only_migratable = 1; |
d15c05fc | 3506 | break; |
d8c208dd | 3507 | case QEMU_OPTION_nodefaults: |
d44229c5 | 3508 | has_defaults = 0; |
d8c208dd | 3509 | break; |
e37630ca | 3510 | case QEMU_OPTION_xen_domid: |
6773fbf8 | 3511 | if (!(accel_find("xen"))) { |
da002526 | 3512 | error_report("Option not supported for this target"); |
ad96090a BS |
3513 | exit(1); |
3514 | } | |
e37630ca AL |
3515 | xen_domid = atoi(optarg); |
3516 | break; | |
e37630ca | 3517 | case QEMU_OPTION_xen_attach: |
6773fbf8 | 3518 | if (!(accel_find("xen"))) { |
da002526 | 3519 | error_report("Option not supported for this target"); |
ad96090a BS |
3520 | exit(1); |
3521 | } | |
e37630ca AL |
3522 | xen_mode = XEN_ATTACH; |
3523 | break; | |
1c599472 | 3524 | case QEMU_OPTION_xen_domid_restrict: |
6773fbf8 | 3525 | if (!(accel_find("xen"))) { |
1c599472 PD |
3526 | error_report("Option not supported for this target"); |
3527 | exit(1); | |
3528 | } | |
3529 | xen_domid_restrict = true; | |
3530 | break; | |
ab6540d5 | 3531 | case QEMU_OPTION_trace: |
92eecfff | 3532 | trace_opt_parse(optarg); |
ab6540d5 | 3533 | break; |
42229a75 LV |
3534 | case QEMU_OPTION_plugin: |
3535 | qemu_plugin_opt_parse(optarg, &plugin_list); | |
3536 | break; | |
715a664a | 3537 | case QEMU_OPTION_readconfig: |
c0d4aa82 | 3538 | qemu_read_config_file(optarg, qemu_parse_config_group, &error_fatal); |
f7544edc | 3539 | break; |
5324e3e9 | 3540 | #ifdef CONFIG_SPICE |
29b0040b | 3541 | case QEMU_OPTION_spice: |
9ed345a1 | 3542 | olist = qemu_find_opts_err("spice", NULL); |
29b0040b | 3543 | if (!olist) { |
5dfdae81 | 3544 | error_report("spice support is disabled"); |
29b0040b GH |
3545 | exit(1); |
3546 | } | |
70b94331 | 3547 | opts = qemu_opts_parse_noisily(olist, optarg, false); |
29b0040b | 3548 | if (!opts) { |
29b0040b GH |
3549 | exit(1); |
3550 | } | |
f963e4d0 | 3551 | display_remote++; |
29b0040b | 3552 | break; |
5324e3e9 | 3553 | #endif |
c7f0f3b1 AL |
3554 | case QEMU_OPTION_qtest: |
3555 | qtest_chrdev = optarg; | |
3556 | break; | |
3557 | case QEMU_OPTION_qtest_log: | |
3558 | qtest_log = optarg; | |
3559 | break; | |
7d76ad4f | 3560 | case QEMU_OPTION_sandbox: |
2bb814a4 MAL |
3561 | olist = qemu_find_opts("sandbox"); |
3562 | if (!olist) { | |
3563 | #ifndef CONFIG_SECCOMP | |
3564 | error_report("-sandbox support is not enabled " | |
3565 | "in this QEMU binary"); | |
3566 | #endif | |
3567 | exit(1); | |
3568 | } | |
3569 | ||
3570 | opts = qemu_opts_parse_noisily(olist, optarg, true); | |
7d76ad4f | 3571 | if (!opts) { |
49295ebc | 3572 | exit(1); |
7d76ad4f EO |
3573 | } |
3574 | break; | |
587ed6be CB |
3575 | case QEMU_OPTION_add_fd: |
3576 | #ifndef _WIN32 | |
70b94331 MA |
3577 | opts = qemu_opts_parse_noisily(qemu_find_opts("add-fd"), |
3578 | optarg, false); | |
587ed6be | 3579 | if (!opts) { |
49295ebc | 3580 | exit(1); |
587ed6be CB |
3581 | } |
3582 | #else | |
3583 | error_report("File descriptor passing is disabled on this " | |
3584 | "platform"); | |
3585 | exit(1); | |
3586 | #endif | |
3587 | break; | |
68d98d3e | 3588 | case QEMU_OPTION_object: |
bc2f4fcb | 3589 | object_option_parse(optarg); |
68d98d3e | 3590 | break; |
6f131f13 MT |
3591 | case QEMU_OPTION_overcommit: |
3592 | opts = qemu_opts_parse_noisily(qemu_find_opts("overcommit"), | |
3593 | optarg, false); | |
3594 | if (!opts) { | |
3595 | exit(1); | |
3596 | } | |
c8c9dc42 | 3597 | enable_mlock = qemu_opt_get_bool(opts, "mem-lock", false); |
6f131f13 | 3598 | enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", false); |
888a6bc6 | 3599 | break; |
6dd75472 MA |
3600 | case QEMU_OPTION_compat: |
3601 | { | |
3602 | CompatPolicy *opts; | |
3603 | Visitor *v; | |
3604 | ||
3605 | v = qobject_input_visitor_new_str(optarg, NULL, | |
3606 | &error_fatal); | |
3607 | ||
3608 | visit_type_CompatPolicy(v, NULL, &opts, &error_fatal); | |
3609 | QAPI_CLONE_MEMBERS(CompatPolicy, &compat_policy, opts); | |
3610 | ||
3611 | qapi_free_CompatPolicy(opts); | |
3612 | visit_free(v); | |
3613 | break; | |
3614 | } | |
5e2ac519 | 3615 | case QEMU_OPTION_msg: |
70b94331 MA |
3616 | opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg, |
3617 | false); | |
5e2ac519 SA |
3618 | if (!opts) { |
3619 | exit(1); | |
3620 | } | |
3621 | configure_msg(opts); | |
3622 | break; | |
abfd9ce3 | 3623 | case QEMU_OPTION_dump_vmstate: |
522abf69 | 3624 | if (vmstate_dump_file) { |
f61eddcb EH |
3625 | error_report("only one '-dump-vmstate' " |
3626 | "option may be given"); | |
522abf69 GA |
3627 | exit(1); |
3628 | } | |
abfd9ce3 AS |
3629 | vmstate_dump_file = fopen(optarg, "w"); |
3630 | if (vmstate_dump_file == NULL) { | |
f61eddcb | 3631 | error_report("open %s: %s", optarg, strerror(errno)); |
abfd9ce3 AS |
3632 | exit(1); |
3633 | } | |
12df189d EC |
3634 | break; |
3635 | case QEMU_OPTION_enable_sync_profile: | |
3636 | qsp_enable(); | |
abfd9ce3 | 3637 | break; |
aec0d0e1 MP |
3638 | case QEMU_OPTION_nouserconfig: |
3639 | /* Nothing to be parsed here. Especially, do not error out below. */ | |
3640 | break; | |
59a5264b | 3641 | default: |
1217d6ca TH |
3642 | if (os_parse_cmd_args(popt->index, optarg)) { |
3643 | error_report("Option not supported in this build"); | |
3644 | exit(1); | |
3645 | } | |
cd6f1169 | 3646 | } |
0824d6fc FB |
3647 | } |
3648 | } | |
43fa1e0b EH |
3649 | /* |
3650 | * Clear error location left behind by the loop. | |
3651 | * Best done right after the loop. Do not insert code here! | |
3652 | */ | |
3653 | loc_set_none(); | |
364c3e6b | 3654 | |
d8fb7d09 | 3655 | qemu_validate_options(machine_opts_dict); |
4d2c17b0 | 3656 | qemu_process_sugar_options(); |
58c91595 | 3657 | |
3df261b6 | 3658 | /* |
0546c060 PB |
3659 | * These options affect everything else and should be processed |
3660 | * before daemonizing. | |
3df261b6 | 3661 | */ |
0546c060 | 3662 | qemu_process_early_options(); |
3df261b6 | 3663 | |
0546c060 PB |
3664 | qemu_process_help_options(); |
3665 | qemu_maybe_daemonize(pid_file); | |
3666 | ||
10b6ee16 DHB |
3667 | /* |
3668 | * The trace backend must be initialized after daemonizing. | |
3669 | * trace_init_backends() will call st_init(), which will create the | |
3670 | * trace thread in the parent, and also register st_flush_trace_buffer() | |
3671 | * in atexit(). This function will force the parent to wait for the | |
3672 | * writeout thread to finish, which will not occur, and the parent | |
3673 | * process will be left in the host. | |
3674 | */ | |
3675 | if (!trace_init_backends()) { | |
3676 | exit(1); | |
3677 | } | |
3678 | trace_init_file(); | |
3679 | ||
efd7ab22 PB |
3680 | qemu_init_main_loop(&error_fatal); |
3681 | cpu_timers_init(); | |
3df261b6 | 3682 | |
fc4a4734 | 3683 | user_register_global_props(); |
4c27b859 PD |
3684 | replay_configure(icount_opts); |
3685 | ||
eb6a5209 AP |
3686 | configure_rtc(qemu_find_opts_singleton("rtc")); |
3687 | ||
d8fb7d09 | 3688 | qemu_create_machine(machine_opts_dict); |
67b724e6 | 3689 | |
5a1ee607 PB |
3690 | suspend_mux_open(); |
3691 | ||
f650266b PB |
3692 | qemu_disable_default_devices(); |
3693 | qemu_create_default_devices(); | |
64418657 | 3694 | qemu_create_early_backends(); |
cda4aa9a | 3695 | |
d8fb7d09 PB |
3696 | qemu_apply_legacy_machine_options(machine_opts_dict); |
3697 | qemu_apply_machine_options(machine_opts_dict); | |
3698 | qobject_unref(machine_opts_dict); | |
2f181fbd | 3699 | phase_advance(PHASE_MACHINE_CREATED); |
6b1b1440 | 3700 | |
0427b625 MA |
3701 | /* |
3702 | * Note: uses machine properties such as kernel-irqchip, must run | |
d8fb7d09 | 3703 | * after qemu_apply_machine_options. |
0427b625 | 3704 | */ |
28a09617 | 3705 | configure_accelerators(argv[0]); |
2f181fbd | 3706 | phase_advance(PHASE_ACCEL_CREATED); |
214910a7 | 3707 | |
0427b625 MA |
3708 | /* |
3709 | * Beware, QOM objects created before this point miss global and | |
3710 | * compat properties. | |
3711 | * | |
3712 | * Global properties get set up by qdev_prop_register_global(), | |
3713 | * called from user_register_global_props(), and certain option | |
3714 | * desugaring. Also in CPU feature desugaring (buried in | |
c1c8cfe5 | 3715 | * parse_cpu_option()), which happens below this point, but may |
0427b625 | 3716 | * only target the CPU type, which can only be created after |
c1c8cfe5 | 3717 | * parse_cpu_option() returned the type. |
0427b625 MA |
3718 | * |
3719 | * Machine compat properties: object_set_machine_compat_props(). | |
3720 | * Accelerator compat props: object_set_accelerator_compat_props(), | |
b86f59c7 | 3721 | * called from do_configure_accelerator(). |
0427b625 MA |
3722 | */ |
3723 | ||
f5c9fcb8 | 3724 | machine_class = MACHINE_GET_CLASS(current_machine); |
08fe6824 TH |
3725 | if (!qtest_enabled() && machine_class->deprecation_reason) { |
3726 | error_report("Machine type '%s' is deprecated: %s", | |
3727 | machine_class->name, machine_class->deprecation_reason); | |
3728 | } | |
3729 | ||
2fa23277 | 3730 | /* |
0427b625 MA |
3731 | * Note: creates a QOM object, must run only after global and |
3732 | * compat properties have been set up. | |
2fa23277 MA |
3733 | */ |
3734 | migration_object_init(); | |
3735 | ||
07a91b1a | 3736 | qemu_create_late_backends(); |
619985e9 | 3737 | |
6063d4c0 | 3738 | /* parse features once if machine provides default cpu_type */ |
2278b939 | 3739 | current_machine->cpu_type = machine_class->default_cpu_type; |
c1c8cfe5 EH |
3740 | if (cpu_option) { |
3741 | current_machine->cpu_type = parse_cpu_option(cpu_option); | |
6063d4c0 | 3742 | } |
b86f59c7 | 3743 | /* NB: for machine none cpu_type could STILL be NULL here! */ |
a1b18df9 | 3744 | |
b24986e7 | 3745 | qemu_resolve_machine_memdev(); |
d342eb76 | 3746 | parse_numa_opts(current_machine); |
6063d4c0 | 3747 | |
abfd9ce3 AS |
3748 | if (vmstate_dump_file) { |
3749 | /* dump and exit */ | |
4067691a | 3750 | module_load_qom_all(); |
abfd9ce3 | 3751 | dump_vmstate_json_to_file(vmstate_dump_file); |
7b733862 | 3752 | exit(0); |
abfd9ce3 | 3753 | } |
ffd843bc | 3754 | |
b4e1a342 PB |
3755 | if (!preconfig_requested) { |
3756 | qmp_x_exit_preconfig(&error_fatal); | |
3757 | } | |
facf7c60 | 3758 | qemu_init_displays(); |
7a64c17f | 3759 | accel_setup_post(current_machine); |
eb505be1 | 3760 | os_setup_post(); |
5a1ee607 | 3761 | resume_mux_open(); |
7b733862 | 3762 | } |