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