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