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