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