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