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