]>
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" |
3dc54b0e | 27 | #include "qemu/units.h" |
fe48442f | 28 | #include "hw/boards.h" |
a27bd6c7 | 29 | #include "hw/qdev-properties.h" |
e688df6b | 30 | #include "qapi/error.h" |
67a1de0d | 31 | #include "qemu-version.h" |
f348b6d1 VB |
32 | #include "qemu/cutils.h" |
33 | #include "qemu/help_option.h" | |
cea25275 | 34 | #include "qemu/uuid.h" |
71e8a915 | 35 | #include "sysemu/reset.h" |
54d31236 | 36 | #include "sysemu/runstate.h" |
9c17d615 | 37 | #include "sysemu/seccomp.h" |
14a48c1d | 38 | #include "sysemu/tcg.h" |
da278d58 | 39 | #include "sysemu/xen.h" |
452dfbef | 40 | |
d49b6836 | 41 | #include "qemu/error-report.h" |
c8897e8e | 42 | #include "qemu/sockets.h" |
a1a9cb0c | 43 | #include "sysemu/accel.h" |
511d2b14 | 44 | #include "hw/usb.h" |
0d09e41a | 45 | #include "hw/isa/isa.h" |
fb8b660e | 46 | #include "hw/scsi/scsi.h" |
866e2b37 | 47 | #include "hw/display/vga.h" |
0d09e41a | 48 | #include "sysemu/watchdog.h" |
a2eb5c0c | 49 | #include "hw/firmware/smbios.h" |
9f57061c | 50 | #include "hw/acpi/acpi.h" |
0d09e41a | 51 | #include "hw/xen/xen.h" |
45a50b16 | 52 | #include "hw/loader.h" |
b4a42f81 | 53 | #include "monitor/qdev.h" |
1422e32d | 54 | #include "net/net.h" |
68ac40d2 | 55 | #include "net/slirp.h" |
83c9089e | 56 | #include "monitor/monitor.h" |
28ecbaee | 57 | #include "ui/console.h" |
e0d2bd51 | 58 | #include "ui/input.h" |
9c17d615 | 59 | #include "sysemu/sysemu.h" |
e35704ba | 60 | #include "sysemu/numa.h" |
900c0ba3 | 61 | #include "sysemu/hostmem.h" |
022c62cb | 62 | #include "exec/gdbstub.h" |
1de7afc9 | 63 | #include "qemu/timer.h" |
8228e353 | 64 | #include "chardev/char.h" |
b33276a7 | 65 | #include "qemu/bitmap.h" |
03dd024f | 66 | #include "qemu/log.h" |
9c17d615 | 67 | #include "sysemu/blockdev.h" |
0d09e41a | 68 | #include "hw/block/block.h" |
7b1e1a22 | 69 | #include "migration/misc.h" |
5e22479a | 70 | #include "migration/snapshot.h" |
84a899de | 71 | #include "migration/global_state.h" |
bdee56f5 | 72 | #include "sysemu/tpm.h" |
9c17d615 | 73 | #include "sysemu/dma.h" |
8a824e4d | 74 | #include "hw/audio/soundhw.h" |
511d2b14 | 75 | #include "audio/audio.h" |
4b4629d9 | 76 | #include "sysemu/cpus.h" |
740b1759 | 77 | #include "sysemu/cpu-timers.h" |
5821ebf9 | 78 | #include "migration/colo.h" |
1693c64c | 79 | #include "migration/postcopy-ram.h" |
9c17d615 | 80 | #include "sysemu/kvm.h" |
b0cb0a66 | 81 | #include "sysemu/hax.h" |
42e5f393 | 82 | #include "qapi/qobject-input-visitor.h" |
1de7afc9 PB |
83 | #include "qemu/option.h" |
84 | #include "qemu/config-file.h" | |
59a5264b | 85 | #include "qemu-options.h" |
1de7afc9 | 86 | #include "qemu/main-loop.h" |
758e8e38 | 87 | #ifdef CONFIG_VIRTFS |
74db920c GS |
88 | #include "fsdev/qemu-fsdev.h" |
89 | #endif | |
9c17d615 | 90 | #include "sysemu/qtest.h" |
511d2b14 | 91 | |
76cad711 | 92 | #include "disas/disas.h" |
fc01f7e7 | 93 | |
8b7a5507 | 94 | #include "trace.h" |
e4858974 | 95 | #include "trace/control.h" |
42229a75 | 96 | #include "qemu/plugin.h" |
1de7afc9 | 97 | #include "qemu/queue.h" |
9c17d615 | 98 | #include "sysemu/arch_init.h" |
72cf2d4f | 99 | |
29b0040b | 100 | #include "ui/qemu-spice.h" |
68d98d3e | 101 | #include "qapi/string-input-visitor.h" |
c4090f8e | 102 | #include "qapi/opts-visitor.h" |
776d1344 | 103 | #include "qapi/clone-visitor.h" |
84321831 | 104 | #include "qom/object_interfaces.h" |
f1672e6f | 105 | #include "hw/semihosting/semihost.h" |
ddbb0d09 | 106 | #include "crypto/init.h" |
b60c48a7 | 107 | #include "sysemu/replay.h" |
9af23989 MA |
108 | #include "qapi/qapi-events-run-state.h" |
109 | #include "qapi/qapi-visit-block-core.h" | |
776d1344 | 110 | #include "qapi/qapi-visit-ui.h" |
112ed241 | 111 | #include "qapi/qapi-commands-block-core.h" |
112ed241 | 112 | #include "qapi/qapi-commands-run-state.h" |
e1ca8f7e | 113 | #include "qapi/qapi-commands-ui.h" |
0194749a | 114 | #include "qapi/qmp/qerror.h" |
dce8921b | 115 | #include "sysemu/iothread.h" |
9c09a251 | 116 | #include "qemu/guest-random.h" |
29b0040b | 117 | |
98b19252 AS |
118 | #define MAX_VIRTIO_CONSOLES 1 |
119 | ||
0546c060 | 120 | static const char *cpu_option; |
4524051c GH |
121 | static const char *data_dir[16]; |
122 | static int data_dir_idx; | |
d8e4de41 PB |
123 | static const char *mem_path; |
124 | static const char *boot_order; | |
125 | static const char *boot_once; | |
58c91595 | 126 | static const char *incoming; |
90285ec8 | 127 | static const char *loadvm; |
cb5a7aa8 | 128 | enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; |
da076ffe | 129 | int display_opengl; |
3d11d0eb | 130 | const char* keyboard_layout = NULL; |
b326b6ea | 131 | static ram_addr_t ram_size; |
28d16f38 | 132 | bool enable_mlock = false; |
6f131f13 | 133 | bool enable_cpu_pm = false; |
c4b1fcc0 | 134 | int nb_nics; |
7c9d8e07 | 135 | NICInfo nd_table[MAX_NICS]; |
efd7ab22 | 136 | int autostart = 1; |
7e166ebd AP |
137 | static enum { |
138 | RTC_BASE_UTC, | |
139 | RTC_BASE_LOCALTIME, | |
140 | RTC_BASE_DATETIME, | |
141 | } rtc_base_type = RTC_BASE_UTC; | |
eb6a5209 AP |
142 | static time_t rtc_ref_start_datetime; |
143 | static int rtc_realtime_clock_offset; /* used only with QEMU_CLOCK_REALTIME */ | |
144 | static int rtc_host_datetime_offset = -1; /* valid & used only with | |
145 | RTC_BASE_DATETIME */ | |
884f17c2 | 146 | QEMUClockType rtc_clock; |
64465297 | 147 | int vga_interface_type = VGA_NONE; |
0c8d7065 | 148 | static DisplayOptions dpy; |
b8d880ba PM |
149 | static int num_serial_hds; |
150 | static Chardev **serial_hds; | |
0546c060 PB |
151 | static const char *log_mask; |
152 | static const char *log_file; | |
153 | static bool list_data_dirs; | |
0ec7b3e7 | 154 | Chardev *parallel_hds[MAX_PARALLEL_PORTS]; |
a09db21f | 155 | int win2k_install_hack = 0; |
1b530a6d | 156 | int singlestep = 0; |
52ca8d6a | 157 | int fd_bootchk = 1; |
4fdcac0e | 158 | static int no_reboot; |
b2f76161 | 159 | int no_shutdown = 0; |
a171fe39 | 160 | int graphic_rotate = 0; |
09aaa160 | 161 | const char *watchdog; |
2e55e842 | 162 | QEMUOptionRom option_rom[MAX_OPTION_ROMS]; |
9ae02555 | 163 | int nb_option_roms; |
2b8f2d41 | 164 | int old_param = 0; |
c35734b2 | 165 | const char *qemu_name; |
3780e197 | 166 | int alt_grab = 0; |
0ca9f8a4 | 167 | int ctrl_grab = 0; |
66508601 BS |
168 | unsigned int nb_prom_envs = 0; |
169 | const char *prom_envs[MAX_PROM_ENVS]; | |
95387491 | 170 | int boot_menu; |
bc74112f | 171 | bool boot_strict; |
3d3b8303 | 172 | uint8_t *boot_splash_filedata; |
811f8652 | 173 | int only_migratable; /* turn it off unless user states otherwise */ |
46ea94ca | 174 | bool wakeup_suspend_enabled; |
a8bfac37 | 175 | int icount_align_option; |
eaf65114 TH |
176 | static const char *qtest_chrdev; |
177 | static const char *qtest_log; | |
1ca4d09a | 178 | |
9c5ce8db | 179 | /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the |
caad057b EH |
180 | * little-endian "wire format" described in the SMBIOS 2.6 specification. |
181 | */ | |
9c5ce8db | 182 | QemuUUID qemu_uuid; |
fc3b3295 | 183 | bool qemu_uuid_set; |
8fcb1b90 | 184 | |
fd42deeb GH |
185 | static NotifierList exit_notifiers = |
186 | NOTIFIER_LIST_INITIALIZER(exit_notifiers); | |
187 | ||
4cab946a GN |
188 | static NotifierList machine_init_done_notifiers = |
189 | NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers); | |
190 | ||
d745bef8 BS |
191 | uint32_t xen_domid; |
192 | enum xen_mode xen_mode = XEN_EMULATE; | |
1c599472 | 193 | bool xen_domid_restrict; |
d745bef8 | 194 | |
d44229c5 | 195 | static int has_defaults = 1; |
998bbd74 | 196 | static int default_serial = 1; |
6a5e8b0e | 197 | static int default_parallel = 1; |
abdeed06 | 198 | static int default_monitor = 1; |
ac33f8fa GH |
199 | static int default_floppy = 1; |
200 | static int default_cdrom = 1; | |
201 | static int default_sdcard = 1; | |
7f1b17f2 | 202 | static int default_vga = 1; |
d30300f7 | 203 | static int default_net = 1; |
998bbd74 GH |
204 | |
205 | static struct { | |
206 | const char *driver; | |
207 | int *flag; | |
208 | } default_list[] = { | |
6a5e8b0e GH |
209 | { .driver = "isa-serial", .flag = &default_serial }, |
210 | { .driver = "isa-parallel", .flag = &default_parallel }, | |
d8bcbabf | 211 | { .driver = "isa-fdc", .flag = &default_floppy }, |
a92bd191 | 212 | { .driver = "floppy", .flag = &default_floppy }, |
af6bf132 MA |
213 | { .driver = "ide-cd", .flag = &default_cdrom }, |
214 | { .driver = "ide-hd", .flag = &default_cdrom }, | |
d8bcbabf | 215 | { .driver = "ide-drive", .flag = &default_cdrom }, |
af6bf132 | 216 | { .driver = "scsi-cd", .flag = &default_cdrom }, |
f6f99b48 | 217 | { .driver = "scsi-hd", .flag = &default_cdrom }, |
7f1b17f2 PB |
218 | { .driver = "VGA", .flag = &default_vga }, |
219 | { .driver = "isa-vga", .flag = &default_vga }, | |
220 | { .driver = "cirrus-vga", .flag = &default_vga }, | |
221 | { .driver = "isa-cirrus-vga", .flag = &default_vga }, | |
222 | { .driver = "vmware-svga", .flag = &default_vga }, | |
223 | { .driver = "qxl-vga", .flag = &default_vga }, | |
a94f0c5c | 224 | { .driver = "virtio-vga", .flag = &default_vga }, |
862b4a29 | 225 | { .driver = "ati-vga", .flag = &default_vga }, |
267f6646 | 226 | { .driver = "vhost-user-vga", .flag = &default_vga }, |
998bbd74 GH |
227 | }; |
228 | ||
4d454574 PB |
229 | static QemuOptsList qemu_rtc_opts = { |
230 | .name = "rtc", | |
231 | .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head), | |
eb6a5209 | 232 | .merge_lists = true, |
4d454574 PB |
233 | .desc = { |
234 | { | |
235 | .name = "base", | |
236 | .type = QEMU_OPT_STRING, | |
237 | },{ | |
238 | .name = "clock", | |
239 | .type = QEMU_OPT_STRING, | |
240 | },{ | |
241 | .name = "driftfix", | |
242 | .type = QEMU_OPT_STRING, | |
243 | }, | |
244 | { /* end of list */ } | |
245 | }, | |
246 | }; | |
247 | ||
4d454574 PB |
248 | static QemuOptsList qemu_option_rom_opts = { |
249 | .name = "option-rom", | |
250 | .implied_opt_name = "romfile", | |
251 | .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head), | |
252 | .desc = { | |
253 | { | |
254 | .name = "bootindex", | |
255 | .type = QEMU_OPT_NUMBER, | |
256 | }, { | |
257 | .name = "romfile", | |
258 | .type = QEMU_OPT_STRING, | |
259 | }, | |
260 | { /* end of list */ } | |
261 | }, | |
262 | }; | |
263 | ||
264 | static QemuOptsList qemu_machine_opts = { | |
265 | .name = "machine", | |
266 | .implied_opt_name = "type", | |
267 | .merge_lists = true, | |
268 | .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head), | |
269 | .desc = { | |
49d2e648 MA |
270 | /* |
271 | * no elements => accept any | |
272 | * sanity checking will happen later | |
273 | * when setting machine properties | |
274 | */ | |
275 | { } | |
4d454574 PB |
276 | }, |
277 | }; | |
278 | ||
8d4e9146 FK |
279 | static QemuOptsList qemu_accel_opts = { |
280 | .name = "accel", | |
281 | .implied_opt_name = "accel", | |
282 | .head = QTAILQ_HEAD_INITIALIZER(qemu_accel_opts.head), | |
8d4e9146 | 283 | .desc = { |
12ceaef6 PB |
284 | /* |
285 | * no elements => accept any | |
286 | * sanity checking will happen later | |
287 | * when setting accelerator properties | |
288 | */ | |
289 | { } | |
8d4e9146 FK |
290 | }, |
291 | }; | |
292 | ||
4d454574 PB |
293 | static QemuOptsList qemu_boot_opts = { |
294 | .name = "boot-opts", | |
6ef4716c MA |
295 | .implied_opt_name = "order", |
296 | .merge_lists = true, | |
4d454574 PB |
297 | .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head), |
298 | .desc = { | |
4d454574 PB |
299 | { |
300 | .name = "order", | |
301 | .type = QEMU_OPT_STRING, | |
302 | }, { | |
303 | .name = "once", | |
304 | .type = QEMU_OPT_STRING, | |
305 | }, { | |
306 | .name = "menu", | |
6ef4716c | 307 | .type = QEMU_OPT_BOOL, |
4d454574 PB |
308 | }, { |
309 | .name = "splash", | |
310 | .type = QEMU_OPT_STRING, | |
311 | }, { | |
312 | .name = "splash-time", | |
6912bb0b | 313 | .type = QEMU_OPT_NUMBER, |
4d454574 PB |
314 | }, { |
315 | .name = "reboot-timeout", | |
ee5d0f89 | 316 | .type = QEMU_OPT_NUMBER, |
c8a6ae8b AK |
317 | }, { |
318 | .name = "strict", | |
e5187b56 | 319 | .type = QEMU_OPT_BOOL, |
4d454574 PB |
320 | }, |
321 | { /*End of list */ } | |
322 | }, | |
323 | }; | |
324 | ||
325 | static QemuOptsList qemu_add_fd_opts = { | |
326 | .name = "add-fd", | |
327 | .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head), | |
328 | .desc = { | |
329 | { | |
330 | .name = "fd", | |
331 | .type = QEMU_OPT_NUMBER, | |
332 | .help = "file descriptor of which a duplicate is added to fd set", | |
333 | },{ | |
334 | .name = "set", | |
335 | .type = QEMU_OPT_NUMBER, | |
336 | .help = "ID of the fd set to add fd to", | |
337 | },{ | |
338 | .name = "opaque", | |
339 | .type = QEMU_OPT_STRING, | |
340 | .help = "free-form string used to describe fd", | |
341 | }, | |
342 | { /* end of list */ } | |
343 | }, | |
344 | }; | |
345 | ||
346 | static QemuOptsList qemu_object_opts = { | |
347 | .name = "object", | |
348 | .implied_opt_name = "qom-type", | |
349 | .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head), | |
350 | .desc = { | |
351 | { } | |
352 | }, | |
353 | }; | |
354 | ||
d1a0cf73 SB |
355 | static QemuOptsList qemu_tpmdev_opts = { |
356 | .name = "tpmdev", | |
357 | .implied_opt_name = "type", | |
358 | .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head), | |
359 | .desc = { | |
bb716238 | 360 | /* options are defined in the TPM backends */ |
d1a0cf73 SB |
361 | { /* end of list */ } |
362 | }, | |
363 | }; | |
364 | ||
888a6bc6 SM |
365 | static QemuOptsList qemu_realtime_opts = { |
366 | .name = "realtime", | |
367 | .head = QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts.head), | |
368 | .desc = { | |
369 | { | |
370 | .name = "mlock", | |
371 | .type = QEMU_OPT_BOOL, | |
372 | }, | |
373 | { /* end of list */ } | |
374 | }, | |
375 | }; | |
376 | ||
6f131f13 MT |
377 | static QemuOptsList qemu_overcommit_opts = { |
378 | .name = "overcommit", | |
379 | .head = QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts.head), | |
380 | .desc = { | |
381 | { | |
382 | .name = "mem-lock", | |
383 | .type = QEMU_OPT_BOOL, | |
384 | }, | |
385 | { | |
386 | .name = "cpu-pm", | |
387 | .type = QEMU_OPT_BOOL, | |
388 | }, | |
389 | { /* end of list */ } | |
390 | }, | |
391 | }; | |
392 | ||
5e2ac519 SA |
393 | static QemuOptsList qemu_msg_opts = { |
394 | .name = "msg", | |
395 | .head = QTAILQ_HEAD_INITIALIZER(qemu_msg_opts.head), | |
396 | .desc = { | |
397 | { | |
398 | .name = "timestamp", | |
399 | .type = QEMU_OPT_BOOL, | |
400 | }, | |
2880ffb0 MS |
401 | { |
402 | .name = "guest-name", | |
403 | .type = QEMU_OPT_BOOL, | |
404 | .help = "Prepends guest name for error messages but only if " | |
405 | "-name guest is set otherwise option is ignored\n", | |
406 | }, | |
5e2ac519 SA |
407 | { /* end of list */ } |
408 | }, | |
409 | }; | |
410 | ||
5d12f961 DDAG |
411 | static QemuOptsList qemu_name_opts = { |
412 | .name = "name", | |
413 | .implied_opt_name = "guest", | |
414 | .merge_lists = true, | |
415 | .head = QTAILQ_HEAD_INITIALIZER(qemu_name_opts.head), | |
416 | .desc = { | |
417 | { | |
418 | .name = "guest", | |
419 | .type = QEMU_OPT_STRING, | |
420 | .help = "Sets the name of the guest.\n" | |
421 | "This name will be displayed in the SDL window caption.\n" | |
422 | "The name will also be used for the VNC server", | |
423 | }, { | |
424 | .name = "process", | |
425 | .type = QEMU_OPT_STRING, | |
426 | .help = "Sets the name of the QEMU process, as shown in top etc", | |
8f480de0 DDAG |
427 | }, { |
428 | .name = "debug-threads", | |
429 | .type = QEMU_OPT_BOOL, | |
430 | .help = "When enabled, name the individual threads; defaults off.\n" | |
431 | "NOTE: The thread names are for debugging and not a\n" | |
432 | "stable API.", | |
5d12f961 DDAG |
433 | }, |
434 | { /* End of list */ } | |
435 | }, | |
436 | }; | |
437 | ||
6e1d3c1c IM |
438 | static QemuOptsList qemu_mem_opts = { |
439 | .name = "memory", | |
440 | .implied_opt_name = "size", | |
441 | .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head), | |
442 | .merge_lists = true, | |
443 | .desc = { | |
444 | { | |
445 | .name = "size", | |
446 | .type = QEMU_OPT_SIZE, | |
447 | }, | |
c270fb9e IM |
448 | { |
449 | .name = "slots", | |
450 | .type = QEMU_OPT_NUMBER, | |
451 | }, | |
452 | { | |
453 | .name = "maxmem", | |
454 | .type = QEMU_OPT_SIZE, | |
455 | }, | |
6e1d3c1c IM |
456 | { /* end of list */ } |
457 | }, | |
458 | }; | |
459 | ||
1ad9580b ST |
460 | static QemuOptsList qemu_icount_opts = { |
461 | .name = "icount", | |
462 | .implied_opt_name = "shift", | |
463 | .merge_lists = true, | |
464 | .head = QTAILQ_HEAD_INITIALIZER(qemu_icount_opts.head), | |
465 | .desc = { | |
466 | { | |
467 | .name = "shift", | |
468 | .type = QEMU_OPT_STRING, | |
a8bfac37 ST |
469 | }, { |
470 | .name = "align", | |
471 | .type = QEMU_OPT_BOOL, | |
f1f4b57e VC |
472 | }, { |
473 | .name = "sleep", | |
474 | .type = QEMU_OPT_BOOL, | |
4c27b859 PD |
475 | }, { |
476 | .name = "rr", | |
477 | .type = QEMU_OPT_STRING, | |
478 | }, { | |
479 | .name = "rrfile", | |
480 | .type = QEMU_OPT_STRING, | |
9c2037d0 PD |
481 | }, { |
482 | .name = "rrsnapshot", | |
483 | .type = QEMU_OPT_STRING, | |
1ad9580b ST |
484 | }, |
485 | { /* end of list */ } | |
486 | }, | |
487 | }; | |
488 | ||
81b2b810 GS |
489 | static QemuOptsList qemu_fw_cfg_opts = { |
490 | .name = "fw_cfg", | |
491 | .implied_opt_name = "name", | |
492 | .head = QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts.head), | |
493 | .desc = { | |
494 | { | |
495 | .name = "name", | |
496 | .type = QEMU_OPT_STRING, | |
497 | .help = "Sets the fw_cfg name of the blob to be inserted", | |
498 | }, { | |
499 | .name = "file", | |
500 | .type = QEMU_OPT_STRING, | |
679be303 | 501 | .help = "Sets the name of the file from which " |
81b2b810 | 502 | "the fw_cfg blob will be loaded", |
6407d76e GS |
503 | }, { |
504 | .name = "string", | |
505 | .type = QEMU_OPT_STRING, | |
506 | .help = "Sets content of the blob to be inserted from a string", | |
6552d87c PMD |
507 | }, { |
508 | .name = "gen_id", | |
509 | .type = QEMU_OPT_STRING, | |
510 | .help = "Sets id of the object generating the fw_cfg blob " | |
511 | "to be inserted", | |
81b2b810 GS |
512 | }, |
513 | { /* end of list */ } | |
514 | }, | |
515 | }; | |
516 | ||
7f9d6e54 MA |
517 | /** |
518 | * Get machine options | |
519 | * | |
520 | * Returns: machine options (never null). | |
521 | */ | |
522 | QemuOpts *qemu_get_machine_opts(void) | |
523 | { | |
e96e5ae8 | 524 | return qemu_find_opts_singleton("machine"); |
7f9d6e54 MA |
525 | } |
526 | ||
31459f46 RS |
527 | const char *qemu_get_vm_name(void) |
528 | { | |
529 | return qemu_name; | |
530 | } | |
531 | ||
3d3b8303 WX |
532 | static void res_free(void) |
533 | { | |
012aef07 MA |
534 | g_free(boot_splash_filedata); |
535 | boot_splash_filedata = NULL; | |
3d3b8303 WX |
536 | } |
537 | ||
28d0de7a | 538 | static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp) |
998bbd74 GH |
539 | { |
540 | const char *driver = qemu_opt_get(opts, "driver"); | |
541 | int i; | |
542 | ||
543 | if (!driver) | |
544 | return 0; | |
545 | for (i = 0; i < ARRAY_SIZE(default_list); i++) { | |
546 | if (strcmp(default_list[i].driver, driver) != 0) | |
547 | continue; | |
548 | *(default_list[i].flag) = 0; | |
549 | } | |
550 | return 0; | |
551 | } | |
552 | ||
f5bbfba1 LC |
553 | /***********************************************************/ |
554 | /* QEMU state */ | |
555 | ||
047f7038 | 556 | static RunState current_run_state = RUN_STATE_PRECONFIG; |
f5bbfba1 | 557 | |
7fb1cf16 EB |
558 | /* We use RUN_STATE__MAX but any invalid value will do */ |
559 | static RunState vmstop_requested = RUN_STATE__MAX; | |
74892d24 PB |
560 | static QemuMutex vmstop_lock; |
561 | ||
5db9d4d1 LC |
562 | typedef struct { |
563 | RunState from; | |
564 | RunState to; | |
565 | } RunStateTransition; | |
566 | ||
567 | static const RunStateTransition runstate_transitions_def[] = { | |
568 | /* from -> to */ | |
047f7038 IM |
569 | { RUN_STATE_PRECONFIG, RUN_STATE_PRELAUNCH }, |
570 | /* Early switch to inmigrate state to allow -incoming CLI option work | |
571 | * as it used to. TODO: delay actual switching to inmigrate state to | |
572 | * the point after machine is built and remove this hack. | |
573 | */ | |
574 | { RUN_STATE_PRECONFIG, RUN_STATE_INMIGRATE }, | |
575 | ||
0461d5a6 | 576 | { RUN_STATE_DEBUG, RUN_STATE_RUNNING }, |
eca01d3a | 577 | { RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE }, |
7ec13c79 | 578 | { RUN_STATE_DEBUG, RUN_STATE_PRELAUNCH }, |
5db9d4d1 | 579 | |
ca3fc39e JQ |
580 | { RUN_STATE_INMIGRATE, RUN_STATE_INTERNAL_ERROR }, |
581 | { RUN_STATE_INMIGRATE, RUN_STATE_IO_ERROR }, | |
29ed72f1 | 582 | { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED }, |
ca3fc39e JQ |
583 | { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING }, |
584 | { RUN_STATE_INMIGRATE, RUN_STATE_SHUTDOWN }, | |
585 | { RUN_STATE_INMIGRATE, RUN_STATE_SUSPENDED }, | |
586 | { RUN_STATE_INMIGRATE, RUN_STATE_WATCHDOG }, | |
587 | { RUN_STATE_INMIGRATE, RUN_STATE_GUEST_PANICKED }, | |
2a6e6e59 | 588 | { RUN_STATE_INMIGRATE, RUN_STATE_FINISH_MIGRATE }, |
98799b0d PB |
589 | { RUN_STATE_INMIGRATE, RUN_STATE_PRELAUNCH }, |
590 | { RUN_STATE_INMIGRATE, RUN_STATE_POSTMIGRATE }, | |
21142ba7 | 591 | { RUN_STATE_INMIGRATE, RUN_STATE_COLO }, |
5db9d4d1 | 592 | |
0461d5a6 | 593 | { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED }, |
8a9236f1 | 594 | { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE }, |
7ec13c79 | 595 | { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PRELAUNCH }, |
5db9d4d1 | 596 | |
0461d5a6 | 597 | { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING }, |
8a9236f1 | 598 | { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE }, |
7ec13c79 | 599 | { RUN_STATE_IO_ERROR, RUN_STATE_PRELAUNCH }, |
5db9d4d1 | 600 | |
0461d5a6 | 601 | { RUN_STATE_PAUSED, RUN_STATE_RUNNING }, |
8a9236f1 | 602 | { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE }, |
505d786f | 603 | { RUN_STATE_PAUSED, RUN_STATE_POSTMIGRATE }, |
7ec13c79 | 604 | { RUN_STATE_PAUSED, RUN_STATE_PRELAUNCH }, |
21142ba7 | 605 | { RUN_STATE_PAUSED, RUN_STATE_COLO}, |
5db9d4d1 | 606 | |
0461d5a6 | 607 | { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING }, |
8a9236f1 | 608 | { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE }, |
7ec13c79 | 609 | { RUN_STATE_POSTMIGRATE, RUN_STATE_PRELAUNCH }, |
5db9d4d1 | 610 | |
0461d5a6 | 611 | { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING }, |
8a9236f1 | 612 | { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE }, |
0461d5a6 | 613 | { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE }, |
5db9d4d1 | 614 | |
0461d5a6 | 615 | { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING }, |
505d786f | 616 | { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PAUSED }, |
0461d5a6 | 617 | { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE }, |
7ec13c79 | 618 | { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH }, |
21142ba7 | 619 | { RUN_STATE_FINISH_MIGRATE, RUN_STATE_COLO}, |
5db9d4d1 | 620 | |
0461d5a6 | 621 | { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING }, |
7ec13c79 | 622 | { RUN_STATE_RESTORE_VM, RUN_STATE_PRELAUNCH }, |
5db9d4d1 | 623 | |
21142ba7 HZ |
624 | { RUN_STATE_COLO, RUN_STATE_RUNNING }, |
625 | ||
0461d5a6 LC |
626 | { RUN_STATE_RUNNING, RUN_STATE_DEBUG }, |
627 | { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR }, | |
628 | { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR }, | |
629 | { RUN_STATE_RUNNING, RUN_STATE_PAUSED }, | |
630 | { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE }, | |
631 | { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM }, | |
632 | { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM }, | |
633 | { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN }, | |
634 | { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG }, | |
ede085b3 | 635 | { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED }, |
21142ba7 | 636 | { RUN_STATE_RUNNING, RUN_STATE_COLO}, |
5db9d4d1 | 637 | |
0461d5a6 | 638 | { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING }, |
5db9d4d1 | 639 | |
0461d5a6 | 640 | { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED }, |
8a9236f1 | 641 | { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE }, |
7ec13c79 | 642 | { RUN_STATE_SHUTDOWN, RUN_STATE_PRELAUNCH }, |
5647051f | 643 | { RUN_STATE_SHUTDOWN, RUN_STATE_COLO }, |
5db9d4d1 | 644 | |
ad02b96a LC |
645 | { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED }, |
646 | { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED }, | |
647 | { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING }, | |
648 | { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE }, | |
7ec13c79 | 649 | { RUN_STATE_SUSPENDED, RUN_STATE_PRELAUNCH }, |
21142ba7 | 650 | { RUN_STATE_SUSPENDED, RUN_STATE_COLO}, |
ad02b96a | 651 | |
0461d5a6 | 652 | { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING }, |
8a9236f1 | 653 | { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE }, |
7ec13c79 | 654 | { RUN_STATE_WATCHDOG, RUN_STATE_PRELAUNCH }, |
21142ba7 | 655 | { RUN_STATE_WATCHDOG, RUN_STATE_COLO}, |
5db9d4d1 | 656 | |
df390768 | 657 | { RUN_STATE_GUEST_PANICKED, RUN_STATE_RUNNING }, |
fd2a2e1c | 658 | { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE }, |
7ec13c79 | 659 | { RUN_STATE_GUEST_PANICKED, RUN_STATE_PRELAUNCH }, |
ede085b3 | 660 | |
7fb1cf16 | 661 | { RUN_STATE__MAX, RUN_STATE__MAX }, |
5db9d4d1 LC |
662 | }; |
663 | ||
7fb1cf16 | 664 | static bool runstate_valid_transitions[RUN_STATE__MAX][RUN_STATE__MAX]; |
0461d5a6 | 665 | |
f5bbfba1 LC |
666 | bool runstate_check(RunState state) |
667 | { | |
668 | return current_run_state == state; | |
669 | } | |
670 | ||
5e0f1940 JQ |
671 | bool runstate_store(char *str, size_t size) |
672 | { | |
977c736f | 673 | const char *state = RunState_str(current_run_state); |
5e0f1940 JQ |
674 | size_t len = strlen(state) + 1; |
675 | ||
676 | if (len > size) { | |
677 | return false; | |
678 | } | |
679 | memcpy(str, state, len); | |
680 | return true; | |
681 | } | |
682 | ||
4fdcac0e | 683 | static void runstate_init(void) |
5db9d4d1 LC |
684 | { |
685 | const RunStateTransition *p; | |
686 | ||
687 | memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions)); | |
7fb1cf16 | 688 | for (p = &runstate_transitions_def[0]; p->from != RUN_STATE__MAX; p++) { |
5db9d4d1 LC |
689 | runstate_valid_transitions[p->from][p->to] = true; |
690 | } | |
74892d24 PB |
691 | |
692 | qemu_mutex_init(&vmstop_lock); | |
5db9d4d1 LC |
693 | } |
694 | ||
695 | /* This function will abort() on invalid state transitions */ | |
f5bbfba1 LC |
696 | void runstate_set(RunState new_state) |
697 | { | |
7fb1cf16 | 698 | assert(new_state < RUN_STATE__MAX); |
207c5cd2 | 699 | |
ff12e3ae | 700 | trace_runstate_set(current_run_state, RunState_str(current_run_state), |
b1939fcd | 701 | new_state, RunState_str(new_state)); |
ff12e3ae | 702 | |
e92a2d9c LZ |
703 | if (current_run_state == new_state) { |
704 | return; | |
705 | } | |
706 | ||
207c5cd2 | 707 | if (!runstate_valid_transitions[current_run_state][new_state]) { |
f61eddcb | 708 | error_report("invalid runstate transition: '%s' -> '%s'", |
977c736f MA |
709 | RunState_str(current_run_state), |
710 | RunState_str(new_state)); | |
5db9d4d1 LC |
711 | abort(); |
712 | } | |
ff12e3ae | 713 | |
f5bbfba1 LC |
714 | current_run_state = new_state; |
715 | } | |
716 | ||
1fa9a5e4 | 717 | int runstate_is_running(void) |
9e37b9dc | 718 | { |
1fa9a5e4 | 719 | return runstate_check(RUN_STATE_RUNNING); |
9e37b9dc LC |
720 | } |
721 | ||
ede085b3 HT |
722 | bool runstate_needs_reset(void) |
723 | { | |
724 | return runstate_check(RUN_STATE_INTERNAL_ERROR) || | |
df390768 | 725 | runstate_check(RUN_STATE_SHUTDOWN); |
ede085b3 HT |
726 | } |
727 | ||
1fa9a5e4 | 728 | StatusInfo *qmp_query_status(Error **errp) |
1354869c | 729 | { |
1fa9a5e4 LC |
730 | StatusInfo *info = g_malloc0(sizeof(*info)); |
731 | ||
732 | info->running = runstate_is_running(); | |
733 | info->singlestep = singlestep; | |
734 | info->status = current_run_state; | |
735 | ||
736 | return info; | |
1354869c LC |
737 | } |
738 | ||
2d76e823 | 739 | bool qemu_vmstop_requested(RunState *r) |
74892d24 PB |
740 | { |
741 | qemu_mutex_lock(&vmstop_lock); | |
742 | *r = vmstop_requested; | |
7fb1cf16 | 743 | vmstop_requested = RUN_STATE__MAX; |
74892d24 | 744 | qemu_mutex_unlock(&vmstop_lock); |
7fb1cf16 | 745 | return *r < RUN_STATE__MAX; |
74892d24 PB |
746 | } |
747 | ||
748 | void qemu_system_vmstop_request_prepare(void) | |
749 | { | |
750 | qemu_mutex_lock(&vmstop_lock); | |
751 | } | |
752 | ||
753 | void qemu_system_vmstop_request(RunState state) | |
754 | { | |
755 | vmstop_requested = state; | |
756 | qemu_mutex_unlock(&vmstop_lock); | |
757 | qemu_notify_event(); | |
758 | } | |
759 | ||
8f0056b7 | 760 | /***********************************************************/ |
eb6a5209 | 761 | /* RTC reference time/date access */ |
ac0989f5 | 762 | static time_t qemu_ref_timedate(QEMUClockType clock) |
eb6a5209 | 763 | { |
ac0989f5 AP |
764 | time_t value = qemu_clock_get_ms(clock) / 1000; |
765 | switch (clock) { | |
eb6a5209 AP |
766 | case QEMU_CLOCK_REALTIME: |
767 | value -= rtc_realtime_clock_offset; | |
4e8de606 | 768 | /* fall through */ |
eb6a5209 AP |
769 | case QEMU_CLOCK_VIRTUAL: |
770 | value += rtc_ref_start_datetime; | |
771 | break; | |
772 | case QEMU_CLOCK_HOST: | |
773 | if (rtc_base_type == RTC_BASE_DATETIME) { | |
774 | value -= rtc_host_datetime_offset; | |
775 | } | |
776 | break; | |
777 | default: | |
778 | assert(0); | |
779 | } | |
780 | return value; | |
2ed1ebcf PD |
781 | } |
782 | ||
f6503059 AZ |
783 | void qemu_get_timedate(struct tm *tm, int offset) |
784 | { | |
ac0989f5 | 785 | time_t ti = qemu_ref_timedate(rtc_clock); |
f6503059 | 786 | |
f6503059 | 787 | ti += offset; |
7e166ebd AP |
788 | |
789 | switch (rtc_base_type) { | |
eb6a5209 | 790 | case RTC_BASE_DATETIME: |
7e166ebd | 791 | case RTC_BASE_UTC: |
eb7ff6fb | 792 | gmtime_r(&ti, tm); |
7e166ebd AP |
793 | break; |
794 | case RTC_BASE_LOCALTIME: | |
795 | localtime_r(&ti, tm); | |
796 | break; | |
f6503059 | 797 | } |
f6503059 AZ |
798 | } |
799 | ||
800 | int qemu_timedate_diff(struct tm *tm) | |
801 | { | |
802 | time_t seconds; | |
803 | ||
7e166ebd | 804 | switch (rtc_base_type) { |
eb6a5209 | 805 | case RTC_BASE_DATETIME: |
7e166ebd AP |
806 | case RTC_BASE_UTC: |
807 | seconds = mktimegm(tm); | |
808 | break; | |
809 | case RTC_BASE_LOCALTIME: | |
810 | { | |
811 | struct tm tmp = *tm; | |
812 | tmp.tm_isdst = -1; /* use timezone to figure it out */ | |
813 | seconds = mktime(&tmp); | |
814 | break; | |
815 | } | |
7e166ebd AP |
816 | default: |
817 | abort(); | |
818 | } | |
f6503059 | 819 | |
ac0989f5 | 820 | return seconds - qemu_ref_timedate(QEMU_CLOCK_HOST); |
f6503059 AZ |
821 | } |
822 | ||
eb6a5209 | 823 | static void configure_rtc_base_datetime(const char *startdate) |
1ed2fc1f | 824 | { |
7e166ebd | 825 | time_t rtc_start_datetime; |
1ed2fc1f JK |
826 | struct tm tm; |
827 | ||
fdaf2d58 TH |
828 | if (sscanf(startdate, "%d-%d-%dT%d:%d:%d", &tm.tm_year, &tm.tm_mon, |
829 | &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec) == 6) { | |
830 | /* OK */ | |
831 | } else if (sscanf(startdate, "%d-%d-%d", | |
832 | &tm.tm_year, &tm.tm_mon, &tm.tm_mday) == 3) { | |
833 | tm.tm_hour = 0; | |
834 | tm.tm_min = 0; | |
835 | tm.tm_sec = 0; | |
1ed2fc1f | 836 | } else { |
fdaf2d58 TH |
837 | goto date_fail; |
838 | } | |
839 | tm.tm_year -= 1900; | |
840 | tm.tm_mon--; | |
7e166ebd AP |
841 | rtc_start_datetime = mktimegm(&tm); |
842 | if (rtc_start_datetime == -1) { | |
fdaf2d58 | 843 | date_fail: |
7e166ebd | 844 | error_report("invalid datetime format"); |
fdaf2d58 TH |
845 | error_printf("valid formats: " |
846 | "'2006-06-17T16:01:21' or '2006-06-17'\n"); | |
847 | exit(1); | |
1ed2fc1f | 848 | } |
eb6a5209 AP |
849 | rtc_host_datetime_offset = rtc_ref_start_datetime - rtc_start_datetime; |
850 | rtc_ref_start_datetime = rtc_start_datetime; | |
1ed2fc1f JK |
851 | } |
852 | ||
853 | static void configure_rtc(QemuOpts *opts) | |
854 | { | |
855 | const char *value; | |
856 | ||
eb6a5209 AP |
857 | /* Set defaults */ |
858 | rtc_clock = QEMU_CLOCK_HOST; | |
859 | rtc_ref_start_datetime = qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000; | |
860 | rtc_realtime_clock_offset = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000; | |
861 | ||
1ed2fc1f JK |
862 | value = qemu_opt_get(opts, "base"); |
863 | if (value) { | |
864 | if (!strcmp(value, "utc")) { | |
7e166ebd | 865 | rtc_base_type = RTC_BASE_UTC; |
1ed2fc1f | 866 | } else if (!strcmp(value, "localtime")) { |
0194749a | 867 | Error *blocker = NULL; |
7e166ebd | 868 | rtc_base_type = RTC_BASE_LOCALTIME; |
0194749a PD |
869 | error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, |
870 | "-rtc base=localtime"); | |
871 | replay_add_blocker(blocker); | |
1ed2fc1f | 872 | } else { |
7e166ebd | 873 | rtc_base_type = RTC_BASE_DATETIME; |
eb6a5209 | 874 | configure_rtc_base_datetime(value); |
1ed2fc1f JK |
875 | } |
876 | } | |
6875204c JK |
877 | value = qemu_opt_get(opts, "clock"); |
878 | if (value) { | |
879 | if (!strcmp(value, "host")) { | |
884f17c2 | 880 | rtc_clock = QEMU_CLOCK_HOST; |
78808141 | 881 | } else if (!strcmp(value, "rt")) { |
884f17c2 | 882 | rtc_clock = QEMU_CLOCK_REALTIME; |
6875204c | 883 | } else if (!strcmp(value, "vm")) { |
884f17c2 | 884 | rtc_clock = QEMU_CLOCK_VIRTUAL; |
6875204c | 885 | } else { |
f61eddcb | 886 | error_report("invalid option value '%s'", value); |
6875204c JK |
887 | exit(1); |
888 | } | |
889 | } | |
1ed2fc1f JK |
890 | value = qemu_opt_get(opts, "driftfix"); |
891 | if (value) { | |
7e4c0336 | 892 | if (!strcmp(value, "slew")) { |
1fff3c20 PB |
893 | object_register_sugar_prop("mc146818rtc", |
894 | "lost_tick_policy", | |
895 | "slew"); | |
7e4c0336 | 896 | } else if (!strcmp(value, "none")) { |
433acf0d | 897 | /* discard is default */ |
1ed2fc1f | 898 | } else { |
f61eddcb | 899 | error_report("invalid option value '%s'", value); |
1ed2fc1f JK |
900 | exit(1); |
901 | } | |
902 | } | |
1ed2fc1f JK |
903 | } |
904 | ||
28d0de7a | 905 | static int parse_name(void *opaque, QemuOpts *opts, Error **errp) |
5d12f961 DDAG |
906 | { |
907 | const char *proc_name; | |
908 | ||
8f480de0 DDAG |
909 | if (qemu_opt_get(opts, "debug-threads")) { |
910 | qemu_thread_naming(qemu_opt_get_bool(opts, "debug-threads", false)); | |
911 | } | |
5d12f961 DDAG |
912 | qemu_name = qemu_opt_get(opts, "guest"); |
913 | ||
914 | proc_name = qemu_opt_get(opts, "process"); | |
915 | if (proc_name) { | |
916 | os_set_proc_name(proc_name); | |
917 | } | |
5b9d313e DDAG |
918 | |
919 | return 0; | |
5d12f961 DDAG |
920 | } |
921 | ||
f8b6f8ed MA |
922 | bool defaults_enabled(void) |
923 | { | |
924 | return has_defaults; | |
925 | } | |
926 | ||
587ed6be | 927 | #ifndef _WIN32 |
28d0de7a | 928 | static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp) |
587ed6be CB |
929 | { |
930 | int fd, dupfd, flags; | |
931 | int64_t fdset_id; | |
932 | const char *fd_opaque = NULL; | |
636a30a8 | 933 | AddfdInfo *fdinfo; |
587ed6be CB |
934 | |
935 | fd = qemu_opt_get_number(opts, "fd", -1); | |
936 | fdset_id = qemu_opt_get_number(opts, "set", -1); | |
937 | fd_opaque = qemu_opt_get(opts, "opaque"); | |
938 | ||
939 | if (fd < 0) { | |
6353218b | 940 | error_setg(errp, "fd option is required and must be non-negative"); |
587ed6be CB |
941 | return -1; |
942 | } | |
943 | ||
944 | if (fd <= STDERR_FILENO) { | |
6353218b | 945 | error_setg(errp, "fd cannot be a standard I/O stream"); |
587ed6be CB |
946 | return -1; |
947 | } | |
948 | ||
949 | /* | |
950 | * All fds inherited across exec() necessarily have FD_CLOEXEC | |
951 | * clear, while qemu sets FD_CLOEXEC on all other fds used internally. | |
952 | */ | |
953 | flags = fcntl(fd, F_GETFD); | |
954 | if (flags == -1 || (flags & FD_CLOEXEC)) { | |
6353218b | 955 | error_setg(errp, "fd is not valid or already in use"); |
587ed6be CB |
956 | return -1; |
957 | } | |
958 | ||
959 | if (fdset_id < 0) { | |
6353218b | 960 | error_setg(errp, "set option is required and must be non-negative"); |
587ed6be CB |
961 | return -1; |
962 | } | |
963 | ||
964 | #ifdef F_DUPFD_CLOEXEC | |
965 | dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0); | |
966 | #else | |
967 | dupfd = dup(fd); | |
968 | if (dupfd != -1) { | |
969 | qemu_set_cloexec(dupfd); | |
970 | } | |
971 | #endif | |
972 | if (dupfd == -1) { | |
6353218b | 973 | error_setg(errp, "error duplicating fd: %s", strerror(errno)); |
587ed6be CB |
974 | return -1; |
975 | } | |
976 | ||
977 | /* add the duplicate fd, and optionally the opaque string, to the fd set */ | |
636a30a8 PB |
978 | fdinfo = monitor_fdset_add_fd(dupfd, true, fdset_id, !!fd_opaque, fd_opaque, |
979 | &error_abort); | |
980 | g_free(fdinfo); | |
587ed6be CB |
981 | |
982 | return 0; | |
983 | } | |
984 | ||
28d0de7a | 985 | static int cleanup_add_fd(void *opaque, QemuOpts *opts, Error **errp) |
587ed6be CB |
986 | { |
987 | int fd; | |
988 | ||
989 | fd = qemu_opt_get_number(opts, "fd", -1); | |
990 | close(fd); | |
991 | ||
992 | return 0; | |
993 | } | |
994 | #endif | |
995 | ||
1ae26a18 AZ |
996 | /***********************************************************/ |
997 | /* QEMU Block devices */ | |
998 | ||
2292ddae MA |
999 | #define HD_OPTS "media=disk" |
1000 | #define CDROM_OPTS "media=cdrom" | |
1001 | #define FD_OPTS "" | |
1002 | #define PFLASH_OPTS "" | |
1003 | #define MTD_OPTS "" | |
1004 | #define SD_OPTS "" | |
e4bcb14c | 1005 | |
28d0de7a | 1006 | static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp) |
9dfd7c7a | 1007 | { |
2d0d2837 | 1008 | BlockInterfaceType *block_default_type = opaque; |
9dfd7c7a | 1009 | |
c4f26c9f | 1010 | return drive_new(opts, *block_default_type, errp) == NULL; |
9dfd7c7a GH |
1011 | } |
1012 | ||
28d0de7a | 1013 | static int drive_enable_snapshot(void *opaque, QemuOpts *opts, Error **errp) |
9dfd7c7a | 1014 | { |
28de2f88 | 1015 | if (qemu_opt_get(opts, "snapshot") == NULL) { |
f43e47db | 1016 | qemu_opt_set(opts, "snapshot", "on", &error_abort); |
9dfd7c7a GH |
1017 | } |
1018 | return 0; | |
1019 | } | |
1020 | ||
3c42ea66 CB |
1021 | static void default_drive(int enable, int snapshot, BlockInterfaceType type, |
1022 | int index, const char *optstr) | |
4e5d9b57 MA |
1023 | { |
1024 | QemuOpts *opts; | |
a66c9dc7 | 1025 | DriveInfo *dinfo; |
4e5d9b57 | 1026 | |
4e5d9b57 MA |
1027 | if (!enable || drive_get_by_index(type, index)) { |
1028 | return; | |
1029 | } | |
1030 | ||
1031 | opts = drive_add(type, index, NULL, optstr); | |
1032 | if (snapshot) { | |
28d0de7a | 1033 | drive_enable_snapshot(NULL, opts, NULL); |
4e5d9b57 | 1034 | } |
a66c9dc7 | 1035 | |
c4f26c9f | 1036 | dinfo = drive_new(opts, type, &error_abort); |
a66c9dc7 JS |
1037 | dinfo->is_default = true; |
1038 | ||
4e5d9b57 MA |
1039 | } |
1040 | ||
651af51c MA |
1041 | typedef struct BlockdevOptionsQueueEntry { |
1042 | BlockdevOptions *bdo; | |
1043 | Location loc; | |
1044 | QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry) entry; | |
1045 | } BlockdevOptionsQueueEntry; | |
1046 | ||
1047 | typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry) BlockdevOptionsQueue; | |
1048 | ||
d11bf9bf MA |
1049 | static void configure_blockdev(BlockdevOptionsQueue *bdo_queue, |
1050 | MachineClass *machine_class, int snapshot) | |
1051 | { | |
1052 | /* | |
1053 | * If the currently selected machine wishes to override the | |
1054 | * units-per-bus property of its default HBA interface type, do so | |
1055 | * now. | |
1056 | */ | |
1057 | if (machine_class->units_per_default_bus) { | |
1058 | override_max_devs(machine_class->block_default_type, | |
1059 | machine_class->units_per_default_bus); | |
1060 | } | |
1061 | ||
1062 | /* open the virtual block devices */ | |
1063 | while (!QSIMPLEQ_EMPTY(bdo_queue)) { | |
1064 | BlockdevOptionsQueueEntry *bdo = QSIMPLEQ_FIRST(bdo_queue); | |
1065 | ||
1066 | QSIMPLEQ_REMOVE_HEAD(bdo_queue, entry); | |
1067 | loc_push_restore(&bdo->loc); | |
1068 | qmp_blockdev_add(bdo->bdo, &error_fatal); | |
1069 | loc_pop(&bdo->loc); | |
1070 | qapi_free_BlockdevOptions(bdo->bdo); | |
1071 | g_free(bdo); | |
1072 | } | |
25863975 | 1073 | if (snapshot) { |
d11bf9bf MA |
1074 | qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, |
1075 | NULL, NULL); | |
1076 | } | |
1077 | if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, | |
1078 | &machine_class->block_default_type, &error_fatal)) { | |
1079 | /* We printed help */ | |
1080 | exit(0); | |
1081 | } | |
1082 | ||
1083 | default_drive(default_cdrom, snapshot, machine_class->block_default_type, 2, | |
1084 | CDROM_OPTS); | |
1085 | default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS); | |
1086 | default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS); | |
1087 | ||
1088 | } | |
1089 | ||
12b7f57e MT |
1090 | static QemuOptsList qemu_smp_opts = { |
1091 | .name = "smp-opts", | |
1092 | .implied_opt_name = "cpus", | |
1093 | .merge_lists = true, | |
1094 | .head = QTAILQ_HEAD_INITIALIZER(qemu_smp_opts.head), | |
1095 | .desc = { | |
1096 | { | |
1097 | .name = "cpus", | |
1098 | .type = QEMU_OPT_NUMBER, | |
1099 | }, { | |
1100 | .name = "sockets", | |
1101 | .type = QEMU_OPT_NUMBER, | |
1b458422 LX |
1102 | }, { |
1103 | .name = "dies", | |
1104 | .type = QEMU_OPT_NUMBER, | |
12b7f57e MT |
1105 | }, { |
1106 | .name = "cores", | |
1107 | .type = QEMU_OPT_NUMBER, | |
1108 | }, { | |
1109 | .name = "threads", | |
1110 | .type = QEMU_OPT_NUMBER, | |
1111 | }, { | |
1112 | .name = "maxcpus", | |
1113 | .type = QEMU_OPT_NUMBER, | |
1114 | }, | |
1115 | { /*End of list */ } | |
1116 | }, | |
1117 | }; | |
1118 | ||
28d16f38 | 1119 | static void realtime_init(void) |
888a6bc6 | 1120 | { |
888a6bc6 SM |
1121 | if (enable_mlock) { |
1122 | if (os_mlock() < 0) { | |
f61eddcb | 1123 | error_report("locking memory failed"); |
888a6bc6 SM |
1124 | exit(1); |
1125 | } | |
1126 | } | |
1127 | } | |
1128 | ||
5e2ac519 SA |
1129 | |
1130 | static void configure_msg(QemuOpts *opts) | |
1131 | { | |
deda497b | 1132 | error_with_timestamp = qemu_opt_get_bool(opts, "timestamp", false); |
2880ffb0 | 1133 | error_with_guestname = qemu_opt_get_bool(opts, "guest-name", false); |
5e2ac519 SA |
1134 | } |
1135 | ||
a59d31a1 | 1136 | |
a594cfbf FB |
1137 | /***********************************************************/ |
1138 | /* USB devices */ | |
1139 | ||
fb08000c | 1140 | static int usb_device_add(const char *devname) |
a594cfbf | 1141 | { |
a5d2f727 | 1142 | USBDevice *dev = NULL; |
a594cfbf | 1143 | |
4bcbe0b6 | 1144 | if (!machine_usb(current_machine)) { |
a594cfbf | 1145 | return -1; |
094b287f | 1146 | } |
a594cfbf | 1147 | |
0958b4cc | 1148 | dev = usbdevice_create(devname); |
0d92ed30 PB |
1149 | if (!dev) |
1150 | return -1; | |
1151 | ||
a594cfbf FB |
1152 | return 0; |
1153 | } | |
1154 | ||
bd3c948d GH |
1155 | static int usb_parse(const char *cmdline) |
1156 | { | |
59d1c1c2 | 1157 | int r; |
fb08000c | 1158 | r = usb_device_add(cmdline); |
59d1c1c2 | 1159 | if (r < 0) { |
f61eddcb | 1160 | error_report("could not add USB device '%s'", cmdline); |
59d1c1c2 ST |
1161 | } |
1162 | return r; | |
bd3c948d GH |
1163 | } |
1164 | ||
cc1daa40 FB |
1165 | /***********************************************************/ |
1166 | /* machine registration */ | |
1167 | ||
0056ae24 | 1168 | MachineState *current_machine; |
cc1daa40 | 1169 | |
c516cd1b | 1170 | static MachineClass *find_machine(const char *name, GSList *machines) |
cc1daa40 | 1171 | { |
c516cd1b | 1172 | GSList *el; |
cc1daa40 | 1173 | |
261747f1 | 1174 | for (el = machines; el; el = el->next) { |
f2c93021 | 1175 | MachineClass *mc = el->data; |
261747f1 | 1176 | |
f2c93021 MA |
1177 | if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) { |
1178 | return mc; | |
261747f1 | 1179 | } |
cc1daa40 | 1180 | } |
261747f1 | 1181 | |
f2c93021 | 1182 | return NULL; |
cc1daa40 FB |
1183 | } |
1184 | ||
c516cd1b | 1185 | static MachineClass *find_default_machine(GSList *machines) |
0c257437 | 1186 | { |
c516cd1b | 1187 | GSList *el; |
6db1857e | 1188 | MachineClass *default_machineclass = NULL; |
0c257437 | 1189 | |
261747f1 | 1190 | for (el = machines; el; el = el->next) { |
f2c93021 | 1191 | MachineClass *mc = el->data; |
261747f1 | 1192 | |
f2c93021 | 1193 | if (mc->is_default) { |
6db1857e PMD |
1194 | assert(default_machineclass == NULL && "Multiple default machines"); |
1195 | default_machineclass = mc; | |
0c257437 AL |
1196 | } |
1197 | } | |
261747f1 | 1198 | |
6db1857e | 1199 | return default_machineclass; |
0c257437 AL |
1200 | } |
1201 | ||
52eb3dfd MA |
1202 | static int machine_help_func(QemuOpts *opts, MachineState *machine) |
1203 | { | |
1204 | ObjectProperty *prop; | |
7746abd8 | 1205 | ObjectPropertyIterator iter; |
52eb3dfd MA |
1206 | |
1207 | if (!qemu_opt_has_help_opt(opts)) { | |
1208 | return 0; | |
1209 | } | |
1210 | ||
7746abd8 DB |
1211 | object_property_iter_init(&iter, OBJECT(machine)); |
1212 | while ((prop = object_property_iter_next(&iter))) { | |
52eb3dfd MA |
1213 | if (!prop->set) { |
1214 | continue; | |
1215 | } | |
1216 | ||
26eaf2cd MA |
1217 | printf("%s.%s=%s", MACHINE_GET_CLASS(machine)->name, |
1218 | prop->name, prop->type); | |
52eb3dfd | 1219 | if (prop->description) { |
26eaf2cd | 1220 | printf(" (%s)\n", prop->description); |
52eb3dfd | 1221 | } else { |
26eaf2cd | 1222 | printf("\n"); |
52eb3dfd MA |
1223 | } |
1224 | } | |
1225 | ||
1226 | return 1; | |
1227 | } | |
1228 | ||
2f780b6a | 1229 | struct VMChangeStateEntry { |
0bd48850 FB |
1230 | VMChangeStateHandler *cb; |
1231 | void *opaque; | |
2f780b6a | 1232 | QTAILQ_ENTRY(VMChangeStateEntry) entries; |
60dbc5a1 | 1233 | int priority; |
0bd48850 FB |
1234 | }; |
1235 | ||
efd7ab22 PB |
1236 | static QTAILQ_HEAD(, VMChangeStateEntry) vm_change_state_head = |
1237 | QTAILQ_HEAD_INITIALIZER(vm_change_state_head); | |
0bd48850 | 1238 | |
60dbc5a1 SH |
1239 | /** |
1240 | * qemu_add_vm_change_state_handler_prio: | |
1241 | * @cb: the callback to invoke | |
1242 | * @opaque: user data passed to the callback | |
1243 | * @priority: low priorities execute first when the vm runs and the reverse is | |
1244 | * true when the vm stops | |
1245 | * | |
1246 | * Register a callback function that is invoked when the vm starts or stops | |
1247 | * running. | |
1248 | * | |
1249 | * Returns: an entry to be freed using qemu_del_vm_change_state_handler() | |
1250 | */ | |
1251 | VMChangeStateEntry *qemu_add_vm_change_state_handler_prio( | |
1252 | VMChangeStateHandler *cb, void *opaque, int priority) | |
0bd48850 FB |
1253 | { |
1254 | VMChangeStateEntry *e; | |
60dbc5a1 | 1255 | VMChangeStateEntry *other; |
0bd48850 | 1256 | |
60dbc5a1 | 1257 | e = g_malloc0(sizeof(*e)); |
0bd48850 FB |
1258 | e->cb = cb; |
1259 | e->opaque = opaque; | |
60dbc5a1 SH |
1260 | e->priority = priority; |
1261 | ||
1262 | /* Keep list sorted in ascending priority order */ | |
1263 | QTAILQ_FOREACH(other, &vm_change_state_head, entries) { | |
1264 | if (priority < other->priority) { | |
1265 | QTAILQ_INSERT_BEFORE(other, e, entries); | |
1266 | return e; | |
1267 | } | |
1268 | } | |
1269 | ||
1270 | QTAILQ_INSERT_TAIL(&vm_change_state_head, e, entries); | |
0bd48850 FB |
1271 | return e; |
1272 | } | |
1273 | ||
60dbc5a1 SH |
1274 | VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, |
1275 | void *opaque) | |
1276 | { | |
1277 | return qemu_add_vm_change_state_handler_prio(cb, opaque, 0); | |
1278 | } | |
1279 | ||
0bd48850 FB |
1280 | void qemu_del_vm_change_state_handler(VMChangeStateEntry *e) |
1281 | { | |
60dbc5a1 SH |
1282 | QTAILQ_REMOVE(&vm_change_state_head, e, entries); |
1283 | g_free(e); | |
0bd48850 FB |
1284 | } |
1285 | ||
1dfb4dd9 | 1286 | void vm_state_notify(int running, RunState state) |
0bd48850 | 1287 | { |
9b10ac86 | 1288 | VMChangeStateEntry *e, *next; |
0bd48850 | 1289 | |
ff12e3ae | 1290 | trace_vm_state_notify(running, state, RunState_str(state)); |
94b0b5ff | 1291 | |
60dbc5a1 SH |
1292 | if (running) { |
1293 | QTAILQ_FOREACH_SAFE(e, &vm_change_state_head, entries, next) { | |
1294 | e->cb(e->opaque, running, state); | |
1295 | } | |
1296 | } else { | |
1297 | QTAILQ_FOREACH_REVERSE_SAFE(e, &vm_change_state_head, entries, next) { | |
1298 | e->cb(e->opaque, running, state); | |
1299 | } | |
0bd48850 FB |
1300 | } |
1301 | } | |
1302 | ||
aedbe192 EB |
1303 | static ShutdownCause reset_requested; |
1304 | static ShutdownCause shutdown_requested; | |
1305 | static int shutdown_signal; | |
f64622c4 | 1306 | static pid_t shutdown_pid; |
3475187d | 1307 | static int powerdown_requested; |
8cf71710 | 1308 | static int debug_requested; |
95b363b5 | 1309 | static int suspend_requested; |
047f7038 | 1310 | static bool preconfig_exit_requested = true; |
4bc78a87 | 1311 | static WakeupReason wakeup_reason; |
a9552c8e IM |
1312 | static NotifierList powerdown_notifiers = |
1313 | NOTIFIER_LIST_INITIALIZER(powerdown_notifiers); | |
95b363b5 GH |
1314 | static NotifierList suspend_notifiers = |
1315 | NOTIFIER_LIST_INITIALIZER(suspend_notifiers); | |
1316 | static NotifierList wakeup_notifiers = | |
1317 | NOTIFIER_LIST_INITIALIZER(wakeup_notifiers); | |
2dadd753 YS |
1318 | static NotifierList shutdown_notifiers = |
1319 | NOTIFIER_LIST_INITIALIZER(shutdown_notifiers); | |
4bc78a87 | 1320 | static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE); |
bb0c6722 | 1321 | |
aedbe192 | 1322 | ShutdownCause qemu_shutdown_requested_get(void) |
1291eb35 AP |
1323 | { |
1324 | return shutdown_requested; | |
1325 | } | |
1326 | ||
aedbe192 | 1327 | ShutdownCause qemu_reset_requested_get(void) |
1291eb35 AP |
1328 | { |
1329 | return reset_requested; | |
1330 | } | |
1331 | ||
4fdcac0e | 1332 | static int qemu_shutdown_requested(void) |
cf7a2fe2 | 1333 | { |
d73415a3 | 1334 | return qatomic_xchg(&shutdown_requested, SHUTDOWN_CAUSE_NONE); |
cf7a2fe2 AJ |
1335 | } |
1336 | ||
4fdcac0e | 1337 | static void qemu_kill_report(void) |
f64622c4 | 1338 | { |
7af88279 | 1339 | if (!qtest_driver() && shutdown_signal) { |
f1d3fb04 PM |
1340 | if (shutdown_pid == 0) { |
1341 | /* This happens for eg ^C at the terminal, so it's worth | |
1342 | * avoiding printing an odd message in that case. | |
1343 | */ | |
f61eddcb | 1344 | error_report("terminating on signal %d", shutdown_signal); |
f1d3fb04 | 1345 | } else { |
fbe7e332 MP |
1346 | char *shutdown_cmd = qemu_get_pid_name(shutdown_pid); |
1347 | ||
1348 | error_report("terminating on signal %d from pid " FMT_pid " (%s)", | |
1349 | shutdown_signal, shutdown_pid, | |
1350 | shutdown_cmd ? shutdown_cmd : "<unknown process>"); | |
1351 | g_free(shutdown_cmd); | |
f1d3fb04 | 1352 | } |
7af88279 | 1353 | shutdown_signal = 0; |
f64622c4 GN |
1354 | } |
1355 | } | |
1356 | ||
aedbe192 | 1357 | static ShutdownCause qemu_reset_requested(void) |
cf7a2fe2 | 1358 | { |
aedbe192 EB |
1359 | ShutdownCause r = reset_requested; |
1360 | ||
8bd7f71d | 1361 | if (r && replay_checkpoint(CHECKPOINT_RESET_REQUESTED)) { |
aedbe192 | 1362 | reset_requested = SHUTDOWN_CAUSE_NONE; |
8bd7f71d PD |
1363 | return r; |
1364 | } | |
aedbe192 | 1365 | return SHUTDOWN_CAUSE_NONE; |
cf7a2fe2 AJ |
1366 | } |
1367 | ||
95b363b5 GH |
1368 | static int qemu_suspend_requested(void) |
1369 | { | |
1370 | int r = suspend_requested; | |
8bd7f71d PD |
1371 | if (r && replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED)) { |
1372 | suspend_requested = 0; | |
1373 | return r; | |
1374 | } | |
1375 | return false; | |
95b363b5 GH |
1376 | } |
1377 | ||
4bc78a87 | 1378 | static WakeupReason qemu_wakeup_requested(void) |
14058196 | 1379 | { |
4bc78a87 | 1380 | return wakeup_reason; |
14058196 LC |
1381 | } |
1382 | ||
4fdcac0e | 1383 | static int qemu_powerdown_requested(void) |
cf7a2fe2 AJ |
1384 | { |
1385 | int r = powerdown_requested; | |
1386 | powerdown_requested = 0; | |
1387 | return r; | |
1388 | } | |
1389 | ||
e568902a AL |
1390 | static int qemu_debug_requested(void) |
1391 | { | |
1392 | int r = debug_requested; | |
1393 | debug_requested = 0; | |
1394 | return r; | |
1395 | } | |
1396 | ||
047f7038 IM |
1397 | void qemu_exit_preconfig_request(void) |
1398 | { | |
1399 | preconfig_exit_requested = true; | |
1400 | } | |
1401 | ||
aedbe192 EB |
1402 | /* |
1403 | * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE. | |
1404 | */ | |
1405 | void qemu_system_reset(ShutdownCause reason) | |
be522029 | 1406 | { |
0056ae24 MA |
1407 | MachineClass *mc; |
1408 | ||
1409 | mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL; | |
1410 | ||
efdaf797 DG |
1411 | cpu_synchronize_all_states(); |
1412 | ||
958db90c | 1413 | if (mc && mc->reset) { |
a0628599 | 1414 | mc->reset(current_machine); |
be522029 DG |
1415 | } else { |
1416 | qemu_devices_reset(); | |
1417 | } | |
3bf5de52 | 1418 | if (reason && reason != SHUTDOWN_CAUSE_SUBSYSTEM_RESET) { |
ecd7a0d5 | 1419 | qapi_event_send_reset(shutdown_caused_by_guest(reason), reason); |
e063eb1f | 1420 | } |
ea375f9a | 1421 | cpu_synchronize_all_post_reset(); |
bb0c6722 FB |
1422 | } |
1423 | ||
4b5e06c9 NP |
1424 | /* |
1425 | * Wake the VM after suspend. | |
1426 | */ | |
1427 | static void qemu_system_wakeup(void) | |
1428 | { | |
1429 | MachineClass *mc; | |
1430 | ||
1431 | mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL; | |
1432 | ||
1433 | if (mc && mc->wakeup) { | |
1434 | mc->wakeup(current_machine); | |
4b5e06c9 NP |
1435 | } |
1436 | } | |
1437 | ||
c86f106b | 1438 | void qemu_system_guest_panicked(GuestPanicInformation *info) |
5f5b5942 | 1439 | { |
4ada99ad | 1440 | qemu_log_mask(LOG_GUEST_ERROR, "Guest crashed"); |
f47291b7 | 1441 | |
bac05aa9 AS |
1442 | if (current_cpu) { |
1443 | current_cpu->crash_occurred = true; | |
1444 | } | |
c86f106b | 1445 | qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE, |
3ab72385 | 1446 | !!info, info); |
5f5b5942 | 1447 | vm_stop(RUN_STATE_GUEST_PANICKED); |
864111f4 CB |
1448 | if (!no_shutdown) { |
1449 | qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF, | |
3ab72385 | 1450 | !!info, info); |
cf83f140 | 1451 | qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC); |
864111f4 | 1452 | } |
c86f106b AN |
1453 | |
1454 | if (info) { | |
e8ed97a6 | 1455 | if (info->type == GUEST_PANIC_INFORMATION_TYPE_HYPER_V) { |
4ada99ad | 1456 | qemu_log_mask(LOG_GUEST_ERROR, "\nHV crash parameters: (%#"PRIx64 |
f47291b7 | 1457 | " %#"PRIx64" %#"PRIx64" %#"PRIx64" %#"PRIx64")\n", |
e8ed97a6 AN |
1458 | info->u.hyper_v.arg1, |
1459 | info->u.hyper_v.arg2, | |
1460 | info->u.hyper_v.arg3, | |
1461 | info->u.hyper_v.arg4, | |
1462 | info->u.hyper_v.arg5); | |
4ada99ad CB |
1463 | } else if (info->type == GUEST_PANIC_INFORMATION_TYPE_S390) { |
1464 | qemu_log_mask(LOG_GUEST_ERROR, " on cpu %d: %s\n" | |
1465 | "PSW: 0x%016" PRIx64 " 0x%016" PRIx64"\n", | |
1466 | info->u.s390.core, | |
1467 | S390CrashReason_str(info->u.s390.reason), | |
1468 | info->u.s390.psw_mask, | |
1469 | info->u.s390.psw_addr); | |
f47291b7 | 1470 | } |
c86f106b AN |
1471 | qapi_free_GuestPanicInformation(info); |
1472 | } | |
5f5b5942 AS |
1473 | } |
1474 | ||
7dc58dee ZP |
1475 | void qemu_system_guest_crashloaded(GuestPanicInformation *info) |
1476 | { | |
1477 | qemu_log_mask(LOG_GUEST_ERROR, "Guest crash loaded"); | |
1478 | ||
1479 | qapi_event_send_guest_crashloaded(GUEST_PANIC_ACTION_RUN, | |
1480 | !!info, info); | |
1481 | ||
1482 | if (info) { | |
1483 | qapi_free_GuestPanicInformation(info); | |
1484 | } | |
1485 | } | |
1486 | ||
cf83f140 | 1487 | void qemu_system_reset_request(ShutdownCause reason) |
bb0c6722 | 1488 | { |
76ed4b18 | 1489 | if (no_reboot && reason != SHUTDOWN_CAUSE_SUBSYSTEM_RESET) { |
cf83f140 | 1490 | shutdown_requested = reason; |
d1beab82 | 1491 | } else { |
cf83f140 | 1492 | reset_requested = reason; |
d1beab82 | 1493 | } |
b4a3d965 | 1494 | cpu_stop_current(); |
d9f75a4e | 1495 | qemu_notify_event(); |
bb0c6722 FB |
1496 | } |
1497 | ||
95b363b5 GH |
1498 | static void qemu_system_suspend(void) |
1499 | { | |
1500 | pause_all_vcpus(); | |
1501 | notifier_list_notify(&suspend_notifiers, NULL); | |
ad02b96a | 1502 | runstate_set(RUN_STATE_SUSPENDED); |
3ab72385 | 1503 | qapi_event_send_suspend(); |
95b363b5 GH |
1504 | } |
1505 | ||
1506 | void qemu_system_suspend_request(void) | |
1507 | { | |
9abc62f6 | 1508 | if (runstate_check(RUN_STATE_SUSPENDED)) { |
95b363b5 GH |
1509 | return; |
1510 | } | |
1511 | suspend_requested = 1; | |
1512 | cpu_stop_current(); | |
1513 | qemu_notify_event(); | |
1514 | } | |
1515 | ||
1516 | void qemu_register_suspend_notifier(Notifier *notifier) | |
1517 | { | |
1518 | notifier_list_add(&suspend_notifiers, notifier); | |
1519 | } | |
1520 | ||
fb064112 | 1521 | void qemu_system_wakeup_request(WakeupReason reason, Error **errp) |
95b363b5 | 1522 | { |
4fed9421 AK |
1523 | trace_system_wakeup_request(reason); |
1524 | ||
9abc62f6 | 1525 | if (!runstate_check(RUN_STATE_SUSPENDED)) { |
fb064112 DHB |
1526 | error_setg(errp, |
1527 | "Unable to wake up: guest is not in suspended state"); | |
95b363b5 GH |
1528 | return; |
1529 | } | |
1530 | if (!(wakeup_reason_mask & (1 << reason))) { | |
1531 | return; | |
1532 | } | |
ad02b96a | 1533 | runstate_set(RUN_STATE_RUNNING); |
4bc78a87 | 1534 | wakeup_reason = reason; |
95b363b5 | 1535 | qemu_notify_event(); |
95b363b5 GH |
1536 | } |
1537 | ||
1538 | void qemu_system_wakeup_enable(WakeupReason reason, bool enabled) | |
1539 | { | |
1540 | if (enabled) { | |
1541 | wakeup_reason_mask |= (1 << reason); | |
1542 | } else { | |
1543 | wakeup_reason_mask &= ~(1 << reason); | |
1544 | } | |
1545 | } | |
1546 | ||
1547 | void qemu_register_wakeup_notifier(Notifier *notifier) | |
1548 | { | |
1549 | notifier_list_add(&wakeup_notifiers, notifier); | |
1550 | } | |
1551 | ||
46ea94ca DHB |
1552 | void qemu_register_wakeup_support(void) |
1553 | { | |
1554 | wakeup_suspend_enabled = true; | |
1555 | } | |
1556 | ||
fb064112 | 1557 | bool qemu_wakeup_suspend_enabled(void) |
46ea94ca DHB |
1558 | { |
1559 | return wakeup_suspend_enabled; | |
1560 | } | |
1561 | ||
f64622c4 GN |
1562 | void qemu_system_killed(int signal, pid_t pid) |
1563 | { | |
1564 | shutdown_signal = signal; | |
1565 | shutdown_pid = pid; | |
d9389b96 | 1566 | no_shutdown = 0; |
8bd7f71d PD |
1567 | |
1568 | /* Cannot call qemu_system_shutdown_request directly because | |
1569 | * we are in a signal handler. | |
1570 | */ | |
aedbe192 | 1571 | shutdown_requested = SHUTDOWN_CAUSE_HOST_SIGNAL; |
8bd7f71d | 1572 | qemu_notify_event(); |
f64622c4 GN |
1573 | } |
1574 | ||
cf83f140 | 1575 | void qemu_system_shutdown_request(ShutdownCause reason) |
bb0c6722 | 1576 | { |
cf83f140 EB |
1577 | trace_qemu_system_shutdown_request(reason); |
1578 | replay_shutdown_request(reason); | |
1579 | shutdown_requested = reason; | |
d9f75a4e | 1580 | qemu_notify_event(); |
bb0c6722 FB |
1581 | } |
1582 | ||
013c2f15 IM |
1583 | static void qemu_system_powerdown(void) |
1584 | { | |
3ab72385 | 1585 | qapi_event_send_powerdown(); |
013c2f15 IM |
1586 | notifier_list_notify(&powerdown_notifiers, NULL); |
1587 | } | |
1588 | ||
2dadd753 YS |
1589 | static void qemu_system_shutdown(ShutdownCause cause) |
1590 | { | |
1591 | qapi_event_send_shutdown(shutdown_caused_by_guest(cause), cause); | |
1592 | notifier_list_notify(&shutdown_notifiers, &cause); | |
1593 | } | |
1594 | ||
3475187d FB |
1595 | void qemu_system_powerdown_request(void) |
1596 | { | |
bc78cff9 | 1597 | trace_qemu_system_powerdown_request(); |
3475187d | 1598 | powerdown_requested = 1; |
d9f75a4e AL |
1599 | qemu_notify_event(); |
1600 | } | |
1601 | ||
a9552c8e IM |
1602 | void qemu_register_powerdown_notifier(Notifier *notifier) |
1603 | { | |
1604 | notifier_list_add(&powerdown_notifiers, notifier); | |
1605 | } | |
1606 | ||
2dadd753 YS |
1607 | void qemu_register_shutdown_notifier(Notifier *notifier) |
1608 | { | |
1609 | notifier_list_add(&shutdown_notifiers, notifier); | |
1610 | } | |
1611 | ||
8cf71710 JK |
1612 | void qemu_system_debug_request(void) |
1613 | { | |
1614 | debug_requested = 1; | |
83f338f7 | 1615 | qemu_notify_event(); |
8cf71710 JK |
1616 | } |
1617 | ||
99435906 PB |
1618 | static bool main_loop_should_exit(void) |
1619 | { | |
1620 | RunState r; | |
aedbe192 EB |
1621 | ShutdownCause request; |
1622 | ||
047f7038 IM |
1623 | if (preconfig_exit_requested) { |
1624 | if (runstate_check(RUN_STATE_PRECONFIG)) { | |
1625 | runstate_set(RUN_STATE_PRELAUNCH); | |
1626 | } | |
1627 | preconfig_exit_requested = false; | |
1628 | return true; | |
1629 | } | |
99435906 PB |
1630 | if (qemu_debug_requested()) { |
1631 | vm_stop(RUN_STATE_DEBUG); | |
1632 | } | |
95b363b5 GH |
1633 | if (qemu_suspend_requested()) { |
1634 | qemu_system_suspend(); | |
1635 | } | |
aedbe192 EB |
1636 | request = qemu_shutdown_requested(); |
1637 | if (request) { | |
99435906 | 1638 | qemu_kill_report(); |
2dadd753 | 1639 | qemu_system_shutdown(request); |
99435906 PB |
1640 | if (no_shutdown) { |
1641 | vm_stop(RUN_STATE_SHUTDOWN); | |
1642 | } else { | |
1643 | return true; | |
1644 | } | |
1645 | } | |
aedbe192 EB |
1646 | request = qemu_reset_requested(); |
1647 | if (request) { | |
99435906 | 1648 | pause_all_vcpus(); |
aedbe192 | 1649 | qemu_system_reset(request); |
99435906 | 1650 | resume_all_vcpus(); |
ddad81bd LV |
1651 | /* |
1652 | * runstate can change in pause_all_vcpus() | |
1653 | * as iothread mutex is unlocked | |
1654 | */ | |
7ec13c79 | 1655 | if (!runstate_check(RUN_STATE_RUNNING) && |
ddad81bd LV |
1656 | !runstate_check(RUN_STATE_INMIGRATE) && |
1657 | !runstate_check(RUN_STATE_FINISH_MIGRATE)) { | |
7ec13c79 | 1658 | runstate_set(RUN_STATE_PRELAUNCH); |
99435906 PB |
1659 | } |
1660 | } | |
14058196 LC |
1661 | if (qemu_wakeup_requested()) { |
1662 | pause_all_vcpus(); | |
4b5e06c9 | 1663 | qemu_system_wakeup(); |
4bc78a87 LJ |
1664 | notifier_list_notify(&wakeup_notifiers, &wakeup_reason); |
1665 | wakeup_reason = QEMU_WAKEUP_REASON_NONE; | |
14058196 | 1666 | resume_all_vcpus(); |
3ab72385 | 1667 | qapi_event_send_wakeup(); |
14058196 | 1668 | } |
99435906 | 1669 | if (qemu_powerdown_requested()) { |
013c2f15 | 1670 | qemu_system_powerdown(); |
99435906 PB |
1671 | } |
1672 | if (qemu_vmstop_requested(&r)) { | |
1673 | vm_stop(r); | |
1674 | } | |
1675 | return false; | |
1676 | } | |
1677 | ||
7b733862 | 1678 | void qemu_main_loop(void) |
43b96858 | 1679 | { |
8e1b90ec JK |
1680 | #ifdef CONFIG_PROFILER |
1681 | int64_t ti; | |
1682 | #endif | |
0f5319ea | 1683 | while (!main_loop_should_exit()) { |
89bfc105 | 1684 | #ifdef CONFIG_PROFILER |
46481d39 | 1685 | ti = profile_getclock(); |
89bfc105 | 1686 | #endif |
e330c118 | 1687 | main_loop_wait(false); |
89bfc105 | 1688 | #ifdef CONFIG_PROFILER |
46481d39 | 1689 | dev_time += profile_getclock() - ti; |
89bfc105 | 1690 | #endif |
0f5319ea | 1691 | } |
b4608c04 FB |
1692 | } |
1693 | ||
9bd7e6d9 PB |
1694 | static void version(void) |
1695 | { | |
7e563bfb | 1696 | printf("QEMU emulator version " QEMU_FULL_VERSION "\n" |
d915b7bb | 1697 | QEMU_COPYRIGHT "\n"); |
9bd7e6d9 PB |
1698 | } |
1699 | ||
15f82208 | 1700 | static void help(int exitcode) |
0824d6fc | 1701 | { |
a3adb7ad ME |
1702 | version(); |
1703 | printf("usage: %s [options] [disk_image]\n\n" | |
1704 | "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n", | |
1705 | error_get_progname()); | |
1706 | ||
77bd1119 ME |
1707 | #define QEMU_OPTIONS_GENERATE_HELP |
1708 | #include "qemu-options-wrapper.h" | |
a3adb7ad ME |
1709 | |
1710 | printf("\nDuring emulation, the following keys are useful:\n" | |
3f020d70 | 1711 | "ctrl-alt-f toggle full screen\n" |
1712 | "ctrl-alt-n switch to virtual console 'n'\n" | |
1713 | "ctrl-alt toggle mouse and keyboard grab\n" | |
1714 | "\n" | |
f5048cb7 EB |
1715 | "When using -nographic, press 'ctrl-a h' to get some help.\n" |
1716 | "\n" | |
1717 | QEMU_HELP_BOTTOM "\n"); | |
a3adb7ad | 1718 | |
15f82208 | 1719 | exit(exitcode); |
0824d6fc FB |
1720 | } |
1721 | ||
cd6f1169 FB |
1722 | #define HAS_ARG 0x0001 |
1723 | ||
cd6f1169 FB |
1724 | typedef struct QEMUOption { |
1725 | const char *name; | |
1726 | int flags; | |
1727 | int index; | |
ad96090a | 1728 | uint32_t arch_mask; |
cd6f1169 FB |
1729 | } QEMUOption; |
1730 | ||
dbed7e40 | 1731 | static const QEMUOption qemu_options[] = { |
ad96090a | 1732 | { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL }, |
77bd1119 ME |
1733 | #define QEMU_OPTIONS_GENERATE_OPTIONS |
1734 | #include "qemu-options-wrapper.h" | |
cd6f1169 | 1735 | { NULL }, |
fc01f7e7 | 1736 | }; |
a369da5f | 1737 | |
8c9a2b71 EH |
1738 | typedef struct VGAInterfaceInfo { |
1739 | const char *opt_name; /* option name */ | |
1740 | const char *name; /* human-readable name */ | |
c2c7b22d EH |
1741 | /* Class names indicating that support is available. |
1742 | * If no class is specified, the interface is always available */ | |
1743 | const char *class_names[2]; | |
8c9a2b71 EH |
1744 | } VGAInterfaceInfo; |
1745 | ||
53b93511 | 1746 | static const VGAInterfaceInfo vga_interfaces[VGA_TYPE_MAX] = { |
8c9a2b71 EH |
1747 | [VGA_NONE] = { |
1748 | .opt_name = "none", | |
d2fa65cd | 1749 | .name = "no graphic card", |
8c9a2b71 EH |
1750 | }, |
1751 | [VGA_STD] = { | |
1752 | .opt_name = "std", | |
1753 | .name = "standard VGA", | |
c2c7b22d | 1754 | .class_names = { "VGA", "isa-vga" }, |
8c9a2b71 EH |
1755 | }, |
1756 | [VGA_CIRRUS] = { | |
1757 | .opt_name = "cirrus", | |
1758 | .name = "Cirrus VGA", | |
c2c7b22d | 1759 | .class_names = { "cirrus-vga", "isa-cirrus-vga" }, |
8c9a2b71 EH |
1760 | }, |
1761 | [VGA_VMWARE] = { | |
1762 | .opt_name = "vmware", | |
1763 | .name = "VMWare SVGA", | |
c2c7b22d | 1764 | .class_names = { "vmware-svga" }, |
8c9a2b71 EH |
1765 | }, |
1766 | [VGA_VIRTIO] = { | |
1767 | .opt_name = "virtio", | |
1768 | .name = "Virtio VGA", | |
c2c7b22d | 1769 | .class_names = { "virtio-vga" }, |
8c9a2b71 EH |
1770 | }, |
1771 | [VGA_QXL] = { | |
1772 | .opt_name = "qxl", | |
1773 | .name = "QXL VGA", | |
c2c7b22d | 1774 | .class_names = { "qxl-vga" }, |
8c9a2b71 EH |
1775 | }, |
1776 | [VGA_TCX] = { | |
1777 | .opt_name = "tcx", | |
1778 | .name = "TCX framebuffer", | |
c2c7b22d | 1779 | .class_names = { "SUNW,tcx" }, |
8c9a2b71 EH |
1780 | }, |
1781 | [VGA_CG3] = { | |
1782 | .opt_name = "cg3", | |
1783 | .name = "CG3 framebuffer", | |
c2c7b22d | 1784 | .class_names = { "cgthree" }, |
8c9a2b71 EH |
1785 | }, |
1786 | [VGA_XENFB] = { | |
1787 | .opt_name = "xenfb", | |
d2fa65cd | 1788 | .name = "Xen paravirtualized framebuffer", |
8c9a2b71 EH |
1789 | }, |
1790 | }; | |
1791 | ||
c2c7b22d EH |
1792 | static bool vga_interface_available(VGAInterfaceType t) |
1793 | { | |
53b93511 | 1794 | const VGAInterfaceInfo *ti = &vga_interfaces[t]; |
c2c7b22d EH |
1795 | |
1796 | assert(t < VGA_TYPE_MAX); | |
1797 | return !ti->class_names[0] || | |
7ab6e7fc GH |
1798 | module_object_class_by_name(ti->class_names[0]) || |
1799 | module_object_class_by_name(ti->class_names[1]); | |
c2c7b22d EH |
1800 | } |
1801 | ||
dceb8852 MAL |
1802 | static const char * |
1803 | get_default_vga_model(const MachineClass *machine_class) | |
1804 | { | |
1805 | if (machine_class->default_display) { | |
1806 | return machine_class->default_display; | |
1807 | } else if (vga_interface_available(VGA_CIRRUS)) { | |
1808 | return "cirrus"; | |
1809 | } else if (vga_interface_available(VGA_STD)) { | |
1810 | return "std"; | |
1811 | } | |
1812 | ||
1813 | return NULL; | |
1814 | } | |
1815 | ||
1816 | static void select_vgahw(const MachineClass *machine_class, const char *p) | |
3893c124 | 1817 | { |
1818 | const char *opts; | |
8c9a2b71 | 1819 | int t; |
3893c124 | 1820 | |
dceb8852 MAL |
1821 | if (g_str_equal(p, "help")) { |
1822 | const char *def = get_default_vga_model(machine_class); | |
1823 | ||
1824 | for (t = 0; t < VGA_TYPE_MAX; t++) { | |
1825 | const VGAInterfaceInfo *ti = &vga_interfaces[t]; | |
1826 | ||
1827 | if (vga_interface_available(t) && ti->opt_name) { | |
1828 | printf("%-20s %s%s\n", ti->opt_name, ti->name ?: "", | |
1829 | g_str_equal(ti->opt_name, def) ? " (default)" : ""); | |
1830 | } | |
1831 | } | |
1832 | exit(0); | |
1833 | } | |
1834 | ||
d44229c5 | 1835 | assert(vga_interface_type == VGA_NONE); |
8c9a2b71 | 1836 | for (t = 0; t < VGA_TYPE_MAX; t++) { |
53b93511 | 1837 | const VGAInterfaceInfo *ti = &vga_interfaces[t]; |
8c9a2b71 | 1838 | if (ti->opt_name && strstart(p, ti->opt_name, &opts)) { |
c2c7b22d | 1839 | if (!vga_interface_available(t)) { |
8c9a2b71 EH |
1840 | error_report("%s not available", ti->name); |
1841 | exit(1); | |
1842 | } | |
1843 | vga_interface_type = t; | |
1844 | break; | |
af87bf29 | 1845 | } |
8c9a2b71 EH |
1846 | } |
1847 | if (t == VGA_TYPE_MAX) { | |
3893c124 | 1848 | invalid_vga: |
3e515373 | 1849 | error_report("unknown vga type: %s", p); |
3893c124 | 1850 | exit(1); |
1851 | } | |
cb5a7aa8 | 1852 | while (*opts) { |
1853 | const char *nextopt; | |
1854 | ||
1855 | if (strstart(opts, ",retrace=", &nextopt)) { | |
1856 | opts = nextopt; | |
1857 | if (strstart(opts, "dumb", &nextopt)) | |
1858 | vga_retrace_method = VGA_RETRACE_DUMB; | |
1859 | else if (strstart(opts, "precise", &nextopt)) | |
1860 | vga_retrace_method = VGA_RETRACE_PRECISE; | |
1861 | else goto invalid_vga; | |
1862 | } else goto invalid_vga; | |
1863 | opts = nextopt; | |
1864 | } | |
3893c124 | 1865 | } |
1866 | ||
776d1344 GH |
1867 | static void parse_display_qapi(const char *optarg) |
1868 | { | |
776d1344 GH |
1869 | DisplayOptions *opts; |
1870 | Visitor *v; | |
1871 | ||
50beeb68 | 1872 | v = qobject_input_visitor_new_str(optarg, "type", &error_fatal); |
776d1344 GH |
1873 | |
1874 | visit_type_DisplayOptions(v, NULL, &opts, &error_fatal); | |
1875 | QAPI_CLONE_MEMBERS(DisplayOptions, &dpy, opts); | |
1876 | ||
1877 | qapi_free_DisplayOptions(opts); | |
1878 | visit_free(v); | |
1879 | } | |
1880 | ||
e1ca8f7e GH |
1881 | DisplayOptions *qmp_query_display_options(Error **errp) |
1882 | { | |
1883 | return QAPI_CLONE(DisplayOptions, &dpy); | |
1884 | } | |
1885 | ||
e3af9f9a | 1886 | static void parse_display(const char *p) |
1472a95b JS |
1887 | { |
1888 | const char *opts; | |
1472a95b | 1889 | |
c388f408 TH |
1890 | if (is_help_option(p)) { |
1891 | qemu_display_help(); | |
1892 | exit(0); | |
1893 | } | |
1894 | ||
1472a95b | 1895 | if (strstart(p, "sdl", &opts)) { |
7a61f438 GH |
1896 | /* |
1897 | * sdl DisplayType needs hand-crafted parser instead of | |
1898 | * parse_display_qapi() due to some options not in | |
1899 | * DisplayOptions, specifically: | |
1900 | * - frame | |
1901 | * Already deprecated. | |
1902 | * - ctrl_grab + alt_grab | |
1903 | * Not clear yet what happens to them long-term. Should | |
1904 | * replaced by something better or deprecated and dropped. | |
1905 | */ | |
fe91f36a | 1906 | dpy.type = DISPLAY_TYPE_SDL; |
1472a95b JS |
1907 | while (*opts) { |
1908 | const char *nextopt; | |
1909 | ||
09bd7ba9 | 1910 | if (strstart(opts, ",alt_grab=", &nextopt)) { |
1472a95b JS |
1911 | opts = nextopt; |
1912 | if (strstart(opts, "on", &nextopt)) { | |
1913 | alt_grab = 1; | |
1914 | } else if (strstart(opts, "off", &nextopt)) { | |
1915 | alt_grab = 0; | |
1916 | } else { | |
05175535 | 1917 | goto invalid_sdl_args; |
1472a95b JS |
1918 | } |
1919 | } else if (strstart(opts, ",ctrl_grab=", &nextopt)) { | |
1920 | opts = nextopt; | |
1921 | if (strstart(opts, "on", &nextopt)) { | |
1922 | ctrl_grab = 1; | |
1923 | } else if (strstart(opts, "off", &nextopt)) { | |
1924 | ctrl_grab = 0; | |
1925 | } else { | |
05175535 | 1926 | goto invalid_sdl_args; |
1472a95b JS |
1927 | } |
1928 | } else if (strstart(opts, ",window_close=", &nextopt)) { | |
1929 | opts = nextopt; | |
fe91f36a | 1930 | dpy.has_window_close = true; |
1472a95b | 1931 | if (strstart(opts, "on", &nextopt)) { |
fe91f36a | 1932 | dpy.window_close = true; |
1472a95b | 1933 | } else if (strstart(opts, "off", &nextopt)) { |
fe91f36a | 1934 | dpy.window_close = false; |
1472a95b | 1935 | } else { |
05175535 | 1936 | goto invalid_sdl_args; |
1472a95b | 1937 | } |
86a088e6 GH |
1938 | } else if (strstart(opts, ",show-cursor=", &nextopt)) { |
1939 | opts = nextopt; | |
1940 | dpy.has_show_cursor = true; | |
1941 | if (strstart(opts, "on", &nextopt)) { | |
1942 | dpy.show_cursor = true; | |
1943 | } else if (strstart(opts, "off", &nextopt)) { | |
1944 | dpy.show_cursor = false; | |
1945 | } else { | |
1946 | goto invalid_sdl_args; | |
1947 | } | |
0b71a5d5 GH |
1948 | } else if (strstart(opts, ",gl=", &nextopt)) { |
1949 | opts = nextopt; | |
fe91f36a | 1950 | dpy.has_gl = true; |
0b71a5d5 | 1951 | if (strstart(opts, "on", &nextopt)) { |
62f27922 | 1952 | dpy.gl = DISPLAYGL_MODE_ON; |
4867e47c ET |
1953 | } else if (strstart(opts, "core", &nextopt)) { |
1954 | dpy.gl = DISPLAYGL_MODE_CORE; | |
1955 | } else if (strstart(opts, "es", &nextopt)) { | |
1956 | dpy.gl = DISPLAYGL_MODE_ES; | |
0b71a5d5 | 1957 | } else if (strstart(opts, "off", &nextopt)) { |
62f27922 | 1958 | dpy.gl = DISPLAYGL_MODE_OFF; |
0b71a5d5 GH |
1959 | } else { |
1960 | goto invalid_sdl_args; | |
1961 | } | |
1472a95b | 1962 | } else { |
05175535 | 1963 | invalid_sdl_args: |
3e515373 | 1964 | error_report("invalid SDL option string"); |
05175535 | 1965 | exit(1); |
1472a95b JS |
1966 | } |
1967 | opts = nextopt; | |
1968 | } | |
3264ff12 | 1969 | } else if (strstart(p, "vnc", &opts)) { |
7a61f438 GH |
1970 | /* |
1971 | * vnc isn't a (local) DisplayType but a protocol for remote | |
1972 | * display access. | |
1973 | */ | |
4db14629 | 1974 | if (*opts == '=') { |
7b1ee0f2 | 1975 | vnc_parse(opts + 1, &error_fatal); |
4db14629 | 1976 | } else { |
c6bf0f7f | 1977 | error_report("VNC requires a display argument vnc=<display>"); |
3264ff12 JS |
1978 | exit(1); |
1979 | } | |
1472a95b | 1980 | } else { |
776d1344 | 1981 | parse_display_qapi(p); |
1472a95b | 1982 | } |
1472a95b JS |
1983 | } |
1984 | ||
5cea8590 PB |
1985 | char *qemu_find_file(int type, const char *name) |
1986 | { | |
4524051c | 1987 | int i; |
5cea8590 PB |
1988 | const char *subdir; |
1989 | char *buf; | |
1990 | ||
31783203 PM |
1991 | /* Try the name as a straight path first */ |
1992 | if (access(name, R_OK) == 0) { | |
4524051c | 1993 | trace_load_file(name, name); |
7267c094 | 1994 | return g_strdup(name); |
5cea8590 | 1995 | } |
4524051c | 1996 | |
5cea8590 PB |
1997 | switch (type) { |
1998 | case QEMU_FILE_TYPE_BIOS: | |
1999 | subdir = ""; | |
2000 | break; | |
2001 | case QEMU_FILE_TYPE_KEYMAP: | |
2002 | subdir = "keymaps/"; | |
2003 | break; | |
2004 | default: | |
2005 | abort(); | |
2006 | } | |
4524051c GH |
2007 | |
2008 | for (i = 0; i < data_dir_idx; i++) { | |
2009 | buf = g_strdup_printf("%s/%s%s", data_dir[i], subdir, name); | |
2010 | if (access(buf, R_OK) == 0) { | |
2011 | trace_load_file(name, buf); | |
2012 | return buf; | |
2013 | } | |
7267c094 | 2014 | g_free(buf); |
5cea8590 | 2015 | } |
4524051c | 2016 | return NULL; |
5cea8590 PB |
2017 | } |
2018 | ||
ea1edcd7 | 2019 | void qemu_add_data_dir(char *path) |
2a1cce90 GH |
2020 | { |
2021 | int i; | |
2022 | ||
2023 | if (path == NULL) { | |
2024 | return; | |
2025 | } | |
2026 | if (data_dir_idx == ARRAY_SIZE(data_dir)) { | |
2027 | return; | |
2028 | } | |
2029 | for (i = 0; i < data_dir_idx; i++) { | |
2030 | if (strcmp(data_dir[i], path) == 0) { | |
ea1edcd7 PB |
2031 | g_free(path); /* duplicate */ |
2032 | return; | |
2a1cce90 GH |
2033 | } |
2034 | } | |
ea1edcd7 | 2035 | data_dir[data_dir_idx++] = path; |
2a1cce90 GH |
2036 | } |
2037 | ||
6407d76e GS |
2038 | static inline bool nonempty_str(const char *str) |
2039 | { | |
2040 | return str && *str; | |
2041 | } | |
2042 | ||
81b2b810 GS |
2043 | static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp) |
2044 | { | |
2045 | gchar *buf; | |
2046 | size_t size; | |
6552d87c | 2047 | const char *name, *file, *str, *gen_id; |
bab47d9a | 2048 | FWCfgState *fw_cfg = (FWCfgState *) opaque; |
81b2b810 | 2049 | |
bab47d9a | 2050 | if (fw_cfg == NULL) { |
406b6367 | 2051 | error_setg(errp, "fw_cfg device not available"); |
81b2b810 GS |
2052 | return -1; |
2053 | } | |
2054 | name = qemu_opt_get(opts, "name"); | |
2055 | file = qemu_opt_get(opts, "file"); | |
6407d76e | 2056 | str = qemu_opt_get(opts, "string"); |
6552d87c | 2057 | gen_id = qemu_opt_get(opts, "gen_id"); |
6407d76e | 2058 | |
6552d87c PMD |
2059 | /* we need the name, and exactly one of: file, content string, gen_id */ |
2060 | if (!nonempty_str(name) || | |
2061 | nonempty_str(file) + nonempty_str(str) + nonempty_str(gen_id) != 1) { | |
2062 | error_setg(errp, "name, plus exactly one of file," | |
2063 | " string and gen_id, are needed"); | |
81b2b810 GS |
2064 | return -1; |
2065 | } | |
2066 | if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) { | |
406b6367 MA |
2067 | error_setg(errp, "name too long (max. %d char)", |
2068 | FW_CFG_MAX_FILE_PATH - 1); | |
81b2b810 GS |
2069 | return -1; |
2070 | } | |
f7d8afb1 PMD |
2071 | if (nonempty_str(gen_id)) { |
2072 | /* | |
2073 | * In this particular case where the content is populated | |
2074 | * internally, the "etc/" namespace protection is relaxed, | |
2075 | * so do not emit a warning. | |
2076 | */ | |
2077 | } else if (strncmp(name, "opt/", 4) != 0) { | |
3dc6f869 AF |
2078 | warn_report("externally provided fw_cfg item names " |
2079 | "should be prefixed with \"opt/\""); | |
81b2b810 | 2080 | } |
6407d76e GS |
2081 | if (nonempty_str(str)) { |
2082 | size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */ | |
2083 | buf = g_memdup(str, size); | |
6552d87c | 2084 | } else if (nonempty_str(gen_id)) { |
07719518 | 2085 | if (!fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp)) { |
6552d87c PMD |
2086 | return -1; |
2087 | } | |
2088 | return 0; | |
6407d76e | 2089 | } else { |
353c7d58 LQ |
2090 | GError *err = NULL; |
2091 | if (!g_file_get_contents(file, &buf, &size, &err)) { | |
2092 | error_setg(errp, "can't load %s: %s", file, err->message); | |
2093 | g_error_free(err); | |
6407d76e GS |
2094 | return -1; |
2095 | } | |
81b2b810 | 2096 | } |
bab47d9a GH |
2097 | /* For legacy, keep user files in a specific global order. */ |
2098 | fw_cfg_set_order_override(fw_cfg, FW_CFG_ORDER_OVERRIDE_USER); | |
2099 | fw_cfg_add_file(fw_cfg, name, buf, size); | |
2100 | fw_cfg_reset_order_override(fw_cfg); | |
81b2b810 GS |
2101 | return 0; |
2102 | } | |
2103 | ||
28d0de7a | 2104 | static int device_help_func(void *opaque, QemuOpts *opts, Error **errp) |
ff952ba2 MA |
2105 | { |
2106 | return qdev_device_help(opts); | |
2107 | } | |
2108 | ||
28d0de7a | 2109 | static int device_init_func(void *opaque, QemuOpts *opts, Error **errp) |
f31d07d1 GH |
2110 | { |
2111 | DeviceState *dev; | |
2112 | ||
cd65f349 | 2113 | dev = qdev_device_add(opts, errp); |
f3a85056 JF |
2114 | if (!dev && *errp) { |
2115 | error_report_err(*errp); | |
f31d07d1 | 2116 | return -1; |
f3a85056 JF |
2117 | } else if (dev) { |
2118 | object_unref(OBJECT(dev)); | |
f006cf7f | 2119 | } |
f31d07d1 GH |
2120 | return 0; |
2121 | } | |
2122 | ||
28d0de7a | 2123 | static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) |
1a688d3b | 2124 | { |
bd2d80b2 | 2125 | Error *local_err = NULL; |
1a688d3b | 2126 | |
4ad6f6cb | 2127 | if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) { |
0ec846bf | 2128 | if (local_err) { |
dd4af977 | 2129 | error_propagate(errp, local_err); |
0ec846bf AN |
2130 | return -1; |
2131 | } | |
2132 | exit(0); | |
bd2d80b2 | 2133 | } |
1a688d3b GH |
2134 | return 0; |
2135 | } | |
2136 | ||
758e8e38 | 2137 | #ifdef CONFIG_VIRTFS |
28d0de7a | 2138 | static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp) |
74db920c | 2139 | { |
b836723d | 2140 | return qemu_fsdev_add(opts, errp); |
74db920c GS |
2141 | } |
2142 | #endif | |
2143 | ||
28d0de7a | 2144 | static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) |
88589343 | 2145 | { |
c3e95551 | 2146 | return monitor_init_opts(opts, errp); |
88589343 GH |
2147 | } |
2148 | ||
4821cd4c | 2149 | static void monitor_parse(const char *optarg, const char *mode, bool pretty) |
88589343 GH |
2150 | { |
2151 | static int monitor_device_index = 0; | |
2152 | QemuOpts *opts; | |
2153 | const char *p; | |
2154 | char label[32]; | |
88589343 GH |
2155 | |
2156 | if (strstart(optarg, "chardev:", &p)) { | |
2157 | snprintf(label, sizeof(label), "%s", p); | |
2158 | } else { | |
140e065d JK |
2159 | snprintf(label, sizeof(label), "compat_monitor%d", |
2160 | monitor_device_index); | |
95e30b2a | 2161 | opts = qemu_chr_parse_compat(label, optarg, true); |
88589343 | 2162 | if (!opts) { |
f61eddcb | 2163 | error_report("parse error: %s", optarg); |
88589343 GH |
2164 | exit(1); |
2165 | } | |
2166 | } | |
2167 | ||
822ac12d | 2168 | opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal); |
f43e47db MA |
2169 | qemu_opt_set(opts, "mode", mode, &error_abort); |
2170 | qemu_opt_set(opts, "chardev", label, &error_abort); | |
3c45f625 KW |
2171 | if (!strcmp(mode, "control")) { |
2172 | qemu_opt_set_bool(opts, "pretty", pretty, &error_abort); | |
2173 | } else { | |
2174 | assert(pretty == false); | |
2175 | } | |
88589343 GH |
2176 | monitor_device_index++; |
2177 | } | |
2178 | ||
bd3c948d GH |
2179 | struct device_config { |
2180 | enum { | |
aee1b935 | 2181 | DEV_USB, /* -usbdevice */ |
aee1b935 GH |
2182 | DEV_SERIAL, /* -serial */ |
2183 | DEV_PARALLEL, /* -parallel */ | |
c9f398e5 | 2184 | DEV_DEBUGCON, /* -debugcon */ |
ef0c4a0d | 2185 | DEV_GDB, /* -gdb, -s */ |
3ef669e1 | 2186 | DEV_SCLP, /* s390 sclp */ |
bd3c948d GH |
2187 | } type; |
2188 | const char *cmdline; | |
d9a5954d | 2189 | Location loc; |
72cf2d4f | 2190 | QTAILQ_ENTRY(device_config) next; |
bd3c948d | 2191 | }; |
4fdcac0e BS |
2192 | |
2193 | static QTAILQ_HEAD(, device_config) device_configs = | |
2194 | QTAILQ_HEAD_INITIALIZER(device_configs); | |
bd3c948d GH |
2195 | |
2196 | static void add_device_config(int type, const char *cmdline) | |
2197 | { | |
2198 | struct device_config *conf; | |
2199 | ||
7267c094 | 2200 | conf = g_malloc0(sizeof(*conf)); |
bd3c948d GH |
2201 | conf->type = type; |
2202 | conf->cmdline = cmdline; | |
d9a5954d | 2203 | loc_save(&conf->loc); |
72cf2d4f | 2204 | QTAILQ_INSERT_TAIL(&device_configs, conf, next); |
bd3c948d GH |
2205 | } |
2206 | ||
2207 | static int foreach_device_config(int type, int (*func)(const char *cmdline)) | |
2208 | { | |
2209 | struct device_config *conf; | |
2210 | int rc; | |
2211 | ||
72cf2d4f | 2212 | QTAILQ_FOREACH(conf, &device_configs, next) { |
bd3c948d GH |
2213 | if (conf->type != type) |
2214 | continue; | |
d9a5954d | 2215 | loc_push_restore(&conf->loc); |
bd3c948d | 2216 | rc = func(conf->cmdline); |
d9a5954d | 2217 | loc_pop(&conf->loc); |
28de2f88 | 2218 | if (rc) { |
bd3c948d | 2219 | return rc; |
28de2f88 | 2220 | } |
bd3c948d GH |
2221 | } |
2222 | return 0; | |
2223 | } | |
2224 | ||
998bbd74 GH |
2225 | static int serial_parse(const char *devname) |
2226 | { | |
6af2692e | 2227 | int index = num_serial_hds; |
998bbd74 GH |
2228 | char label[32]; |
2229 | ||
2230 | if (strcmp(devname, "none") == 0) | |
2231 | return 0; | |
998bbd74 | 2232 | snprintf(label, sizeof(label), "serial%d", index); |
6af2692e PM |
2233 | serial_hds = g_renew(Chardev *, serial_hds, index + 1); |
2234 | ||
4ad6f6cb | 2235 | serial_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL); |
998bbd74 | 2236 | if (!serial_hds[index]) { |
f61eddcb EH |
2237 | error_report("could not connect serial device" |
2238 | " to character backend '%s'", devname); | |
998bbd74 GH |
2239 | return -1; |
2240 | } | |
6af2692e | 2241 | num_serial_hds++; |
998bbd74 GH |
2242 | return 0; |
2243 | } | |
2244 | ||
a8d78cd0 PM |
2245 | Chardev *serial_hd(int i) |
2246 | { | |
2247 | assert(i >= 0); | |
6af2692e | 2248 | if (i < num_serial_hds) { |
a8d78cd0 PM |
2249 | return serial_hds[i]; |
2250 | } | |
2251 | return NULL; | |
2252 | } | |
2253 | ||
b8846a4d PM |
2254 | int serial_max_hds(void) |
2255 | { | |
2256 | return num_serial_hds; | |
2257 | } | |
2258 | ||
6a5e8b0e GH |
2259 | static int parallel_parse(const char *devname) |
2260 | { | |
2261 | static int index = 0; | |
2262 | char label[32]; | |
2263 | ||
2264 | if (strcmp(devname, "none") == 0) | |
2265 | return 0; | |
2266 | if (index == MAX_PARALLEL_PORTS) { | |
f61eddcb | 2267 | error_report("too many parallel ports"); |
6a5e8b0e GH |
2268 | exit(1); |
2269 | } | |
2270 | snprintf(label, sizeof(label), "parallel%d", index); | |
4ad6f6cb | 2271 | parallel_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL); |
6a5e8b0e | 2272 | if (!parallel_hds[index]) { |
f61eddcb EH |
2273 | error_report("could not connect parallel device" |
2274 | " to character backend '%s'", devname); | |
6a5e8b0e GH |
2275 | return -1; |
2276 | } | |
2277 | index++; | |
2278 | return 0; | |
2279 | } | |
2280 | ||
c9f398e5 | 2281 | static int debugcon_parse(const char *devname) |
4d8b3c63 | 2282 | { |
c9f398e5 PA |
2283 | QemuOpts *opts; |
2284 | ||
4ad6f6cb | 2285 | if (!qemu_chr_new_mux_mon("debugcon", devname, NULL)) { |
d7ecf712 | 2286 | error_report("invalid character backend '%s'", devname); |
c9f398e5 PA |
2287 | exit(1); |
2288 | } | |
8be7e7e4 | 2289 | opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL); |
c9f398e5 | 2290 | if (!opts) { |
f61eddcb | 2291 | error_report("already have a debugcon device"); |
c9f398e5 PA |
2292 | exit(1); |
2293 | } | |
f43e47db MA |
2294 | qemu_opt_set(opts, "driver", "isa-debugcon", &error_abort); |
2295 | qemu_opt_set(opts, "chardev", "debugcon", &error_abort); | |
c9f398e5 PA |
2296 | return 0; |
2297 | } | |
2298 | ||
2709f263 LE |
2299 | static gint machine_class_cmp(gconstpointer a, gconstpointer b) |
2300 | { | |
2301 | const MachineClass *mc1 = a, *mc2 = b; | |
2302 | int res; | |
2303 | ||
2304 | if (mc1->family == NULL) { | |
2305 | if (mc2->family == NULL) { | |
2306 | /* Compare standalone machine types against each other; they sort | |
2307 | * in increasing order. | |
2308 | */ | |
2309 | return strcmp(object_class_get_name(OBJECT_CLASS(mc1)), | |
2310 | object_class_get_name(OBJECT_CLASS(mc2))); | |
2311 | } | |
2312 | ||
2313 | /* Standalone machine types sort after families. */ | |
2314 | return 1; | |
2315 | } | |
2316 | ||
2317 | if (mc2->family == NULL) { | |
2318 | /* Families sort before standalone machine types. */ | |
2319 | return -1; | |
2320 | } | |
2321 | ||
2322 | /* Families sort between each other alphabetically increasingly. */ | |
2323 | res = strcmp(mc1->family, mc2->family); | |
2324 | if (res != 0) { | |
2325 | return res; | |
2326 | } | |
2327 | ||
2328 | /* Within the same family, machine types sort in decreasing order. */ | |
2329 | return strcmp(object_class_get_name(OBJECT_CLASS(mc2)), | |
2330 | object_class_get_name(OBJECT_CLASS(mc1))); | |
2331 | } | |
2332 | ||
c516cd1b | 2333 | static MachineClass *machine_parse(const char *name, GSList *machines) |
9052ea6b | 2334 | { |
12cb82fd | 2335 | MachineClass *mc; |
c516cd1b | 2336 | GSList *el; |
9052ea6b | 2337 | |
12cb82fd | 2338 | if (is_help_option(name)) { |
025172d5 | 2339 | printf("Supported machines are:\n"); |
2709f263 | 2340 | machines = g_slist_sort(machines, machine_class_cmp); |
025172d5 MR |
2341 | for (el = machines; el; el = el->next) { |
2342 | MachineClass *mc = el->data; | |
958db90c MA |
2343 | if (mc->alias) { |
2344 | printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name); | |
025172d5 | 2345 | } |
08fe6824 TH |
2346 | printf("%-20s %s%s%s\n", mc->name, mc->desc, |
2347 | mc->is_default ? " (default)" : "", | |
2348 | mc->deprecation_reason ? " (deprecated)" : ""); | |
9052ea6b | 2349 | } |
12cb82fd | 2350 | exit(0); |
9052ea6b | 2351 | } |
261747f1 | 2352 | |
12cb82fd MA |
2353 | mc = find_machine(name, machines); |
2354 | if (!mc) { | |
2355 | error_report("unsupported machine type"); | |
2356 | error_printf("Use -machine help to list supported machines\n"); | |
2357 | exit(1); | |
2358 | } | |
2359 | return mc; | |
9052ea6b JK |
2360 | } |
2361 | ||
fd42deeb GH |
2362 | void qemu_add_exit_notifier(Notifier *notify) |
2363 | { | |
2364 | notifier_list_add(&exit_notifiers, notify); | |
2365 | } | |
2366 | ||
2367 | void qemu_remove_exit_notifier(Notifier *notify) | |
2368 | { | |
31552529 | 2369 | notifier_remove(notify); |
fd42deeb GH |
2370 | } |
2371 | ||
2372 | static void qemu_run_exit_notifiers(void) | |
2373 | { | |
9e8dd451 | 2374 | notifier_list_notify(&exit_notifiers, NULL); |
fd42deeb GH |
2375 | } |
2376 | ||
90a84d13 MAL |
2377 | static const char *pid_file; |
2378 | static Notifier qemu_unlink_pidfile_notifier; | |
2379 | ||
2380 | static void qemu_unlink_pidfile(Notifier *n, void *data) | |
2381 | { | |
2382 | if (pid_file) { | |
2383 | unlink(pid_file); | |
2384 | } | |
2385 | } | |
2386 | ||
c8ca2a23 | 2387 | bool machine_init_done; |
71cdd1cb | 2388 | |
4cab946a GN |
2389 | void qemu_add_machine_init_done_notifier(Notifier *notify) |
2390 | { | |
2391 | notifier_list_add(&machine_init_done_notifiers, notify); | |
71cdd1cb PB |
2392 | if (machine_init_done) { |
2393 | notify->notify(notify, NULL); | |
2394 | } | |
4cab946a GN |
2395 | } |
2396 | ||
b86eacb8 MA |
2397 | void qemu_remove_machine_init_done_notifier(Notifier *notify) |
2398 | { | |
2399 | notifier_remove(notify); | |
2400 | } | |
2401 | ||
4cab946a GN |
2402 | static void qemu_run_machine_init_done_notifiers(void) |
2403 | { | |
71cdd1cb | 2404 | machine_init_done = true; |
c8ca2a23 | 2405 | notifier_list_notify(&machine_init_done_notifiers, NULL); |
4cab946a GN |
2406 | } |
2407 | ||
6530a97b AL |
2408 | static const QEMUOption *lookup_opt(int argc, char **argv, |
2409 | const char **poptarg, int *poptind) | |
2410 | { | |
2411 | const QEMUOption *popt; | |
2412 | int optind = *poptind; | |
2413 | char *r = argv[optind]; | |
2414 | const char *optarg; | |
2415 | ||
0f0bc3f1 | 2416 | loc_set_cmdline(argv, optind, 1); |
6530a97b AL |
2417 | optind++; |
2418 | /* Treat --foo the same as -foo. */ | |
2419 | if (r[1] == '-') | |
2420 | r++; | |
2421 | popt = qemu_options; | |
2422 | for(;;) { | |
2423 | if (!popt->name) { | |
0f0bc3f1 | 2424 | error_report("invalid option"); |
6530a97b AL |
2425 | exit(1); |
2426 | } | |
2427 | if (!strcmp(popt->name, r + 1)) | |
2428 | break; | |
2429 | popt++; | |
2430 | } | |
2431 | if (popt->flags & HAS_ARG) { | |
2432 | if (optind >= argc) { | |
0f0bc3f1 | 2433 | error_report("requires an argument"); |
6530a97b AL |
2434 | exit(1); |
2435 | } | |
2436 | optarg = argv[optind++]; | |
0f0bc3f1 | 2437 | loc_set_cmdline(argv, optind - 2, 2); |
6530a97b AL |
2438 | } else { |
2439 | optarg = NULL; | |
2440 | } | |
2441 | ||
2442 | *poptarg = optarg; | |
2443 | *poptind = optind; | |
2444 | ||
2445 | return popt; | |
2446 | } | |
2447 | ||
7580f231 | 2448 | static MachineClass *select_machine(void) |
34f405ae | 2449 | { |
c516cd1b WY |
2450 | GSList *machines = object_class_get_list(TYPE_MACHINE, false); |
2451 | MachineClass *machine_class = find_default_machine(machines); | |
34f405ae MA |
2452 | const char *optarg; |
2453 | QemuOpts *opts; | |
2454 | Location loc; | |
2455 | ||
2456 | loc_push_none(&loc); | |
2457 | ||
2458 | opts = qemu_get_machine_opts(); | |
2459 | qemu_opts_loc_restore(opts); | |
2460 | ||
2461 | optarg = qemu_opt_get(opts, "type"); | |
2462 | if (optarg) { | |
c516cd1b | 2463 | machine_class = machine_parse(optarg, machines); |
34f405ae MA |
2464 | } |
2465 | ||
7580f231 | 2466 | if (!machine_class) { |
34f405ae MA |
2467 | error_report("No machine specified, and there is no default"); |
2468 | error_printf("Use -machine help to list supported machines\n"); | |
2469 | exit(1); | |
2470 | } | |
2471 | ||
2472 | loc_pop(&loc); | |
c516cd1b | 2473 | g_slist_free(machines); |
7580f231 | 2474 | return machine_class; |
34f405ae MA |
2475 | } |
2476 | ||
e5db4bd8 PB |
2477 | static int object_parse_property_opt(Object *obj, |
2478 | const char *name, const char *value, | |
2479 | const char *skip, Error **errp) | |
68d98d3e | 2480 | { |
e5db4bd8 | 2481 | if (g_str_equal(name, skip)) { |
68d98d3e AL |
2482 | return 0; |
2483 | } | |
2484 | ||
668f62ec | 2485 | if (!object_property_parse(obj, name, value, errp)) { |
68d98d3e AL |
2486 | return -1; |
2487 | } | |
2488 | ||
2489 | return 0; | |
2490 | } | |
2491 | ||
e5db4bd8 PB |
2492 | static int machine_set_property(void *opaque, |
2493 | const char *name, const char *value, | |
2494 | Error **errp) | |
2495 | { | |
2496 | g_autofree char *qom_name = g_strdup(name); | |
2497 | char *p; | |
2498 | ||
2499 | for (p = qom_name; *p; p++) { | |
2500 | if (*p == '_') { | |
2501 | *p = '-'; | |
2502 | } | |
2503 | } | |
2504 | ||
6f6e1698 PB |
2505 | /* Legacy options do not correspond to MachineState properties. */ |
2506 | if (g_str_equal(qom_name, "accel")) { | |
2507 | return 0; | |
2508 | } | |
46472d82 PB |
2509 | if (g_str_equal(qom_name, "igd-passthru")) { |
2510 | object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, value); | |
2511 | return 0; | |
2512 | } | |
faf20793 | 2513 | if (g_str_equal(qom_name, "kvm-shadow-mem")) { |
23b0898e PB |
2514 | object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value); |
2515 | return 0; | |
2516 | } | |
faf20793 SM |
2517 | if (g_str_equal(qom_name, "kernel-irqchip")) { |
2518 | object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value); | |
2519 | object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name, value); | |
2520 | return 0; | |
2521 | } | |
6f6e1698 | 2522 | |
e5db4bd8 PB |
2523 | return object_parse_property_opt(opaque, name, value, "type", errp); |
2524 | } | |
f08f9271 DB |
2525 | |
2526 | /* | |
2527 | * Initial object creation happens before all other | |
2528 | * QEMU data types are created. The majority of objects | |
2529 | * can be created at this point. The rng-egd object | |
2530 | * cannot be created here, as it depends on the chardev | |
2531 | * already existing. | |
2532 | */ | |
1195fa2b | 2533 | static bool object_create_initial(const char *type, QemuOpts *opts) |
f08f9271 | 2534 | { |
3e9297f3 | 2535 | if (user_creatable_print_help(type, opts)) { |
1195fa2b MAL |
2536 | exit(0); |
2537 | } | |
2538 | ||
edfb4389 MA |
2539 | /* |
2540 | * Objects should not be made "delayed" without a reason. If you | |
2541 | * add one, state the reason in a comment! | |
2542 | */ | |
2543 | ||
2544 | /* Reason: rng-egd property "chardev" */ | |
9ea18ed2 | 2545 | if (g_str_equal(type, "rng-egd")) { |
f08f9271 DB |
2546 | return false; |
2547 | } | |
7dbb11c8 | 2548 | |
042cea27 | 2549 | #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX) |
edfb4389 | 2550 | /* Reason: cryptodev-vhost-user property "chardev" */ |
042cea27 GA |
2551 | if (g_str_equal(type, "cryptodev-vhost-user")) { |
2552 | return false; | |
2553 | } | |
2554 | #endif | |
2555 | ||
3578389b CX |
2556 | /* Reason: vhost-user-blk-server property "node-name" */ |
2557 | if (g_str_equal(type, "vhost-user-blk-server")) { | |
2558 | return false; | |
2559 | } | |
9d3e12e8 | 2560 | /* |
edfb4389 | 2561 | * Reason: filter-* property "netdev" etc. |
9d3e12e8 TH |
2562 | */ |
2563 | if (g_str_equal(type, "filter-buffer") || | |
f6d3afb5 | 2564 | g_str_equal(type, "filter-dump") || |
d46f75b2 | 2565 | g_str_equal(type, "filter-mirror") || |
7dce4e6f | 2566 | g_str_equal(type, "filter-redirector") || |
e6eee8ab | 2567 | g_str_equal(type, "colo-compare") || |
646c5478 PD |
2568 | g_str_equal(type, "filter-rewriter") || |
2569 | g_str_equal(type, "filter-replay")) { | |
7dbb11c8 YH |
2570 | return false; |
2571 | } | |
2572 | ||
6546d0db EH |
2573 | /* Memory allocation by backends needs to be done |
2574 | * after configure_accelerator() (due to the tcg_enabled() | |
2575 | * checks at memory_region_init_*()). | |
2576 | * | |
2577 | * Also, allocation of large amounts of memory may delay | |
2578 | * chardev initialization for too long, and trigger timeouts | |
2579 | * on software that waits for a monitor socket to be created | |
2580 | * (e.g. libvirt). | |
2581 | */ | |
2582 | if (g_str_has_prefix(type, "memory-backend-")) { | |
2583 | return false; | |
2584 | } | |
2585 | ||
f08f9271 DB |
2586 | return true; |
2587 | } | |
2588 | ||
2589 | ||
2590 | /* | |
2591 | * The remainder of object creation happens after the | |
9abce56d | 2592 | * creation of chardev, fsdev, net clients and device data types. |
f08f9271 | 2593 | */ |
1195fa2b | 2594 | static bool object_create_delayed(const char *type, QemuOpts *opts) |
f08f9271 | 2595 | { |
1195fa2b | 2596 | return !object_create_initial(type, opts); |
f08f9271 DB |
2597 | } |
2598 | ||
2599 | ||
2a7b18a3 | 2600 | static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size, |
076b35b5 | 2601 | MachineClass *mc) |
3b9985e9 MA |
2602 | { |
2603 | uint64_t sz; | |
2604 | const char *mem_str; | |
076b35b5 | 2605 | const ram_addr_t default_ram_size = mc->default_ram_size; |
3b9985e9 | 2606 | QemuOpts *opts = qemu_find_opts_singleton("memory"); |
bbe2d25c EH |
2607 | Location loc; |
2608 | ||
2609 | loc_push_none(&loc); | |
2610 | qemu_opts_loc_restore(opts); | |
3b9985e9 MA |
2611 | |
2612 | sz = 0; | |
2613 | mem_str = qemu_opt_get(opts, "size"); | |
2614 | if (mem_str) { | |
2615 | if (!*mem_str) { | |
2616 | error_report("missing 'size' option value"); | |
2617 | exit(EXIT_FAILURE); | |
2618 | } | |
2619 | ||
2620 | sz = qemu_opt_get_size(opts, "size", ram_size); | |
2621 | ||
2622 | /* Fix up legacy suffix-less format */ | |
2623 | if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) { | |
2624 | uint64_t overflow_check = sz; | |
2625 | ||
3dc54b0e PMD |
2626 | sz *= MiB; |
2627 | if (sz / MiB != overflow_check) { | |
3b9985e9 MA |
2628 | error_report("too large 'size' option value"); |
2629 | exit(EXIT_FAILURE); | |
2630 | } | |
2631 | } | |
2632 | } | |
2633 | ||
2634 | /* backward compatibility behaviour for case "-m 0" */ | |
2635 | if (sz == 0) { | |
2636 | sz = default_ram_size; | |
2637 | } | |
2638 | ||
2639 | sz = QEMU_ALIGN_UP(sz, 8192); | |
5c30ef93 CB |
2640 | if (mc->fixup_ram_size) { |
2641 | sz = mc->fixup_ram_size(sz); | |
2642 | } | |
3b9985e9 MA |
2643 | ram_size = sz; |
2644 | if (ram_size != sz) { | |
2645 | error_report("ram size too large"); | |
2646 | exit(EXIT_FAILURE); | |
2647 | } | |
2648 | ||
2649 | /* store value for the future use */ | |
39101f25 | 2650 | qemu_opt_set_number(opts, "size", ram_size, &error_abort); |
3b9985e9 MA |
2651 | *maxram_size = ram_size; |
2652 | ||
951f2269 | 2653 | if (qemu_opt_get(opts, "maxmem")) { |
3b9985e9 MA |
2654 | uint64_t slots; |
2655 | ||
2656 | sz = qemu_opt_get_size(opts, "maxmem", 0); | |
214224ad | 2657 | slots = qemu_opt_get_number(opts, "slots", 0); |
3b9985e9 | 2658 | if (sz < ram_size) { |
214224ad PK |
2659 | error_report("invalid value of -m option maxmem: " |
2660 | "maximum memory size (0x%" PRIx64 ") must be at least " | |
2661 | "the initial memory size (0x" RAM_ADDR_FMT ")", | |
2662 | sz, ram_size); | |
3b9985e9 | 2663 | exit(EXIT_FAILURE); |
951f2269 | 2664 | } else if (slots && sz == ram_size) { |
214224ad PK |
2665 | error_report("invalid value of -m option maxmem: " |
2666 | "memory slots were specified but maximum memory size " | |
2667 | "(0x%" PRIx64 ") is equal to the initial memory size " | |
2668 | "(0x" RAM_ADDR_FMT ")", sz, ram_size); | |
3b9985e9 MA |
2669 | exit(EXIT_FAILURE); |
2670 | } | |
2671 | ||
3b9985e9 MA |
2672 | *maxram_size = sz; |
2673 | *ram_slots = slots; | |
951f2269 DH |
2674 | } else if (qemu_opt_get(opts, "slots")) { |
2675 | error_report("invalid -m option value: missing 'maxmem' option"); | |
3b9985e9 MA |
2676 | exit(EXIT_FAILURE); |
2677 | } | |
bbe2d25c EH |
2678 | |
2679 | loc_pop(&loc); | |
2a7b18a3 | 2680 | return !!mem_str; |
3b9985e9 MA |
2681 | } |
2682 | ||
8d76bfe8 EH |
2683 | static int global_init_func(void *opaque, QemuOpts *opts, Error **errp) |
2684 | { | |
2685 | GlobalProperty *g; | |
2686 | ||
2687 | g = g_malloc0(sizeof(*g)); | |
2688 | g->driver = qemu_opt_get(opts, "driver"); | |
2689 | g->property = qemu_opt_get(opts, "property"); | |
2690 | g->value = qemu_opt_get(opts, "value"); | |
8d76bfe8 EH |
2691 | qdev_prop_register_global(g); |
2692 | return 0; | |
2693 | } | |
2694 | ||
726401be EH |
2695 | static int qemu_read_default_config_file(void) |
2696 | { | |
2697 | int ret; | |
580e6ad6 | 2698 | g_autofree char *file = get_relocated_path(CONFIG_QEMU_CONFDIR "/qemu.conf"); |
726401be | 2699 | |
580e6ad6 | 2700 | ret = qemu_read_config_file(file); |
726401be EH |
2701 | if (ret < 0 && ret != -ENOENT) { |
2702 | return ret; | |
2703 | } | |
2704 | ||
2705 | return 0; | |
2706 | } | |
2707 | ||
a0660e0b PX |
2708 | static void user_register_global_props(void) |
2709 | { | |
2710 | qemu_opts_foreach(qemu_find_opts("global"), | |
2711 | global_init_func, NULL, NULL); | |
2712 | } | |
2713 | ||
7f8b6126 PB |
2714 | static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp) |
2715 | { | |
8191d368 | 2716 | icount_configure(opts, errp); |
7f8b6126 PB |
2717 | return 0; |
2718 | } | |
2719 | ||
12ceaef6 PB |
2720 | static int accelerator_set_property(void *opaque, |
2721 | const char *name, const char *value, | |
2722 | Error **errp) | |
2723 | { | |
2724 | return object_parse_property_opt(opaque, name, value, "accel", errp); | |
2725 | } | |
2726 | ||
deda73e8 PB |
2727 | static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) |
2728 | { | |
6f6e1698 PB |
2729 | bool *p_init_failed = opaque; |
2730 | const char *acc = qemu_opt_get(opts, "accel"); | |
2731 | AccelClass *ac = accel_find(acc); | |
fc5cf826 | 2732 | AccelState *accel; |
6f6e1698 | 2733 | int ret; |
eaf65114 TH |
2734 | bool qtest_with_kvm; |
2735 | ||
2736 | qtest_with_kvm = g_str_equal(acc, "kvm") && qtest_chrdev != NULL; | |
6f6e1698 PB |
2737 | |
2738 | if (!ac) { | |
8b90f1c5 | 2739 | *p_init_failed = true; |
eaf65114 TH |
2740 | if (!qtest_with_kvm) { |
2741 | error_report("invalid accelerator %s", acc); | |
2742 | } | |
6f6e1698 PB |
2743 | return 0; |
2744 | } | |
fc5cf826 | 2745 | accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac))); |
fe174132 | 2746 | object_apply_compat_props(OBJECT(accel)); |
12ceaef6 PB |
2747 | qemu_opt_foreach(opts, accelerator_set_property, |
2748 | accel, | |
2749 | &error_fatal); | |
2750 | ||
fc5cf826 | 2751 | ret = accel_init_machine(accel, current_machine); |
6f6e1698 PB |
2752 | if (ret < 0) { |
2753 | *p_init_failed = true; | |
eaf65114 TH |
2754 | if (!qtest_with_kvm || ret != -ENOENT) { |
2755 | error_report("failed to initialize %s: %s", acc, strerror(-ret)); | |
2756 | } | |
6f6e1698 PB |
2757 | return 0; |
2758 | } | |
fe174132 | 2759 | |
6f6e1698 | 2760 | return 1; |
deda73e8 PB |
2761 | } |
2762 | ||
28a09617 | 2763 | static void configure_accelerators(const char *progname) |
deda73e8 | 2764 | { |
28a09617 | 2765 | const char *accel; |
28a09617 | 2766 | bool init_failed = false; |
28a09617 PB |
2767 | |
2768 | qemu_opts_foreach(qemu_find_opts("icount"), | |
2769 | do_configure_icount, NULL, &error_fatal); | |
2770 | ||
2771 | accel = qemu_opt_get(qemu_get_machine_opts(), "accel"); | |
6f6e1698 | 2772 | if (QTAILQ_EMPTY(&qemu_accel_opts.head)) { |
60ee3552 RH |
2773 | char **accel_list, **tmp; |
2774 | ||
6f6e1698 PB |
2775 | if (accel == NULL) { |
2776 | /* Select the default accelerator */ | |
755ee1f3 RH |
2777 | bool have_tcg = accel_find("tcg"); |
2778 | bool have_kvm = accel_find("kvm"); | |
2779 | ||
2780 | if (have_tcg && have_kvm) { | |
2781 | if (g_str_has_suffix(progname, "kvm")) { | |
6f6e1698 PB |
2782 | /* If the program name ends with "kvm", we prefer KVM */ |
2783 | accel = "kvm:tcg"; | |
2784 | } else { | |
2785 | accel = "tcg:kvm"; | |
2786 | } | |
755ee1f3 RH |
2787 | } else if (have_kvm) { |
2788 | accel = "kvm"; | |
2789 | } else if (have_tcg) { | |
2790 | accel = "tcg"; | |
2791 | } else { | |
2792 | error_report("No accelerator selected and" | |
2793 | " no default accelerator available"); | |
2794 | exit(1); | |
28a09617 PB |
2795 | } |
2796 | } | |
6f6e1698 | 2797 | accel_list = g_strsplit(accel, ":", 0); |
28a09617 | 2798 | |
a024b090 | 2799 | for (tmp = accel_list; *tmp; tmp++) { |
6f6e1698 PB |
2800 | /* |
2801 | * Filter invalid accelerators here, to prevent obscenities | |
2802 | * such as "-machine accel=tcg,,thread=single". | |
2803 | */ | |
2804 | if (accel_find(*tmp)) { | |
2805 | qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp, true); | |
8b90f1c5 PB |
2806 | } else { |
2807 | init_failed = true; | |
2808 | error_report("invalid accelerator %s", *tmp); | |
6f6e1698 | 2809 | } |
28a09617 | 2810 | } |
adb464ff | 2811 | g_strfreev(accel_list); |
6f6e1698 PB |
2812 | } else { |
2813 | if (accel != NULL) { | |
2814 | error_report("The -accel and \"-machine accel=\" options are incompatible"); | |
2815 | exit(1); | |
28a09617 PB |
2816 | } |
2817 | } | |
28a09617 | 2818 | |
6f6e1698 PB |
2819 | if (!qemu_opts_foreach(qemu_find_opts("accel"), |
2820 | do_configure_accelerator, &init_failed, &error_fatal)) { | |
28a09617 | 2821 | if (!init_failed) { |
6f6e1698 | 2822 | error_report("no accelerator found"); |
28a09617 PB |
2823 | } |
2824 | exit(1); | |
2825 | } | |
2826 | ||
eaf65114 | 2827 | if (init_failed && !qtest_chrdev) { |
4f7f5893 | 2828 | AccelClass *ac = ACCEL_GET_CLASS(current_accel()); |
8b90f1c5 | 2829 | error_report("falling back to %s", ac->name); |
28a09617 PB |
2830 | } |
2831 | ||
740b1759 | 2832 | if (icount_enabled() && !tcg_enabled()) { |
deda73e8 PB |
2833 | error_report("-icount is not allowed with hardware virtualization"); |
2834 | exit(1); | |
2835 | } | |
2836 | } | |
2837 | ||
ffac16fa | 2838 | static void create_default_memdev(MachineState *ms, const char *path) |
900c0ba3 IM |
2839 | { |
2840 | Object *obj; | |
2841 | MachineClass *mc = MACHINE_GET_CLASS(ms); | |
2842 | ||
2843 | obj = object_new(path ? TYPE_MEMORY_BACKEND_FILE : TYPE_MEMORY_BACKEND_RAM); | |
2844 | if (path) { | |
5325cc34 | 2845 | object_property_set_str(obj, "mem-path", path, &error_fatal); |
900c0ba3 | 2846 | } |
5325cc34 | 2847 | object_property_set_int(obj, "size", ms->ram_size, &error_fatal); |
900c0ba3 | 2848 | object_property_add_child(object_get_objects_root(), mc->default_ram_id, |
d2623129 | 2849 | obj); |
d96c4d5f | 2850 | /* Ensure backend's memory region name is equal to mc->default_ram_id */ |
5325cc34 MA |
2851 | object_property_set_bool(obj, "x-use-canonical-path-for-ramblock-id", |
2852 | false, &error_fatal); | |
900c0ba3 IM |
2853 | user_creatable_complete(USER_CREATABLE(obj), &error_fatal); |
2854 | object_unref(obj); | |
5325cc34 | 2855 | object_property_set_str(OBJECT(ms), "memory-backend", mc->default_ram_id, |
900c0ba3 IM |
2856 | &error_fatal); |
2857 | } | |
2858 | ||
ea1edcd7 PB |
2859 | /* |
2860 | * Find a likely location for support files using the location of the binary. | |
2861 | * When running from the build tree this will be "$bindir/pc-bios". | |
2862 | * Otherwise, this is CONFIG_QEMU_DATADIR (possibly relocated). | |
2863 | * | |
2864 | * The caller must use g_free() to free the returned data when it is | |
2865 | * no longer required. | |
2866 | */ | |
2867 | static char *find_datadir(void) | |
2868 | { | |
2869 | g_autofree char *dir = NULL; | |
2870 | ||
2871 | dir = g_build_filename(qemu_get_exec_dir(), "pc-bios", NULL); | |
2872 | if (g_file_test(dir, G_FILE_TEST_IS_DIR)) { | |
2873 | return g_steal_pointer(&dir); | |
2874 | } | |
2875 | ||
2876 | return get_relocated_path(CONFIG_QEMU_DATADIR); | |
2877 | } | |
2878 | ||
58c91595 PB |
2879 | static void qemu_validate_options(void) |
2880 | { | |
2881 | QemuOpts *machine_opts = qemu_get_machine_opts(); | |
2882 | const char *kernel_filename = qemu_opt_get(machine_opts, "kernel"); | |
2883 | const char *initrd_filename = qemu_opt_get(machine_opts, "initrd"); | |
2884 | const char *kernel_cmdline = qemu_opt_get(machine_opts, "append"); | |
2885 | ||
2886 | if (kernel_filename == NULL) { | |
2887 | if (kernel_cmdline != NULL) { | |
2888 | error_report("-append only allowed with -kernel option"); | |
2889 | exit(1); | |
2890 | } | |
2891 | ||
2892 | if (initrd_filename != NULL) { | |
2893 | error_report("-initrd only allowed with -kernel option"); | |
2894 | exit(1); | |
2895 | } | |
2896 | } | |
2897 | ||
90285ec8 PB |
2898 | if (loadvm && !preconfig_exit_requested) { |
2899 | error_report("'preconfig' and 'loadvm' options are " | |
2900 | "mutually exclusive"); | |
2901 | exit(EXIT_FAILURE); | |
2902 | } | |
58c91595 PB |
2903 | if (incoming && !preconfig_exit_requested) { |
2904 | error_report("'preconfig' and 'incoming' options are " | |
2905 | "mutually exclusive"); | |
2906 | exit(EXIT_FAILURE); | |
2907 | } | |
2908 | ||
2909 | #ifdef CONFIG_CURSES | |
2910 | if (is_daemonized() && dpy.type == DISPLAY_TYPE_CURSES) { | |
2911 | error_report("curses display cannot be used with -daemonize"); | |
2912 | exit(1); | |
2913 | } | |
2914 | #endif | |
2915 | } | |
2916 | ||
0546c060 PB |
2917 | static void qemu_process_early_options(void) |
2918 | { | |
2919 | char **dirs; | |
2920 | int i; | |
2921 | ||
2922 | #ifdef CONFIG_SECCOMP | |
2923 | QemuOptsList *olist = qemu_find_opts_err("sandbox", NULL); | |
2924 | if (olist) { | |
2925 | qemu_opts_foreach(olist, parse_sandbox, NULL, &error_fatal); | |
2926 | } | |
2927 | #endif | |
2928 | ||
2929 | qemu_opts_foreach(qemu_find_opts("name"), | |
2930 | parse_name, NULL, &error_fatal); | |
2931 | ||
2932 | #ifndef _WIN32 | |
2933 | qemu_opts_foreach(qemu_find_opts("add-fd"), | |
2934 | parse_add_fd, NULL, &error_fatal); | |
2935 | ||
2936 | qemu_opts_foreach(qemu_find_opts("add-fd"), | |
2937 | cleanup_add_fd, NULL, &error_fatal); | |
2938 | #endif | |
2939 | ||
2940 | if (!trace_init_backends()) { | |
2941 | exit(1); | |
2942 | } | |
2943 | trace_init_file(); | |
2944 | ||
2945 | /* Open the logfile at this point and set the log mask if necessary. */ | |
2946 | qemu_set_log_filename(log_file, &error_fatal); | |
2947 | if (log_mask) { | |
2948 | int mask; | |
2949 | mask = qemu_str_to_log_mask(log_mask); | |
2950 | if (!mask) { | |
2951 | qemu_print_log_usage(stdout); | |
2952 | exit(1); | |
2953 | } | |
2954 | qemu_set_log(mask); | |
2955 | } else { | |
2956 | qemu_set_log(0); | |
2957 | } | |
2958 | ||
2959 | /* add configured firmware directories */ | |
2960 | dirs = g_strsplit(CONFIG_QEMU_FIRMWAREPATH, G_SEARCHPATH_SEPARATOR_S, 0); | |
2961 | for (i = 0; dirs[i] != NULL; i++) { | |
2962 | qemu_add_data_dir(get_relocated_path(dirs[i])); | |
2963 | } | |
2964 | g_strfreev(dirs); | |
2965 | ||
2966 | /* try to find datadir relative to the executable path */ | |
2967 | qemu_add_data_dir(find_datadir()); | |
2968 | } | |
2969 | ||
2970 | static void qemu_process_help_options(void) | |
2971 | { | |
2972 | int i; | |
2973 | ||
2974 | /* | |
2975 | * Check for -cpu help and -device help before we call select_machine(), | |
2976 | * which will return an error if the architecture has no default machine | |
2977 | * type and the user did not specify one, so that the user doesn't need | |
2978 | * to say '-cpu help -machine something'. | |
2979 | */ | |
2980 | if (cpu_option && is_help_option(cpu_option)) { | |
2981 | list_cpus(cpu_option); | |
2982 | exit(0); | |
2983 | } | |
2984 | ||
2985 | if (qemu_opts_foreach(qemu_find_opts("device"), | |
2986 | device_help_func, NULL, NULL)) { | |
2987 | exit(0); | |
2988 | } | |
2989 | ||
2990 | /* -L help lists the data directories and exits. */ | |
2991 | if (list_data_dirs) { | |
2992 | for (i = 0; i < data_dir_idx; i++) { | |
2993 | printf("%s\n", data_dir[i]); | |
2994 | } | |
2995 | exit(0); | |
2996 | } | |
2997 | } | |
2998 | ||
2999 | static void qemu_maybe_daemonize(const char *pid_file) | |
3000 | { | |
3001 | Error *err; | |
3002 | ||
3003 | os_daemonize(); | |
3004 | rcu_disable_atfork(); | |
3005 | ||
3006 | if (pid_file && !qemu_write_pidfile(pid_file, &err)) { | |
3007 | error_reportf_err(err, "cannot create PID file: "); | |
3008 | exit(1); | |
3009 | } | |
3010 | ||
3011 | qemu_unlink_pidfile_notifier.notify = qemu_unlink_pidfile; | |
3012 | qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier); | |
3013 | } | |
3014 | ||
efd7ab22 PB |
3015 | static void qemu_init_subsystems(void) |
3016 | { | |
3017 | Error *err; | |
3018 | ||
3019 | os_set_line_buffering(); | |
3020 | ||
3021 | module_call_init(MODULE_INIT_TRACE); | |
3022 | ||
3023 | qemu_init_cpu_list(); | |
3024 | qemu_init_cpu_loop(); | |
3025 | qemu_mutex_lock_iothread(); | |
3026 | ||
3027 | atexit(qemu_run_exit_notifiers); | |
3028 | ||
3029 | module_call_init(MODULE_INIT_QOM); | |
3030 | module_call_init(MODULE_INIT_MIGRATION); | |
3031 | ||
3032 | runstate_init(); | |
3033 | precopy_infrastructure_init(); | |
3034 | postcopy_infrastructure_init(); | |
3035 | monitor_init_globals(); | |
3036 | ||
3037 | if (qcrypto_init(&err) < 0) { | |
3038 | error_reportf_err(err, "cannot initialize crypto: "); | |
3039 | exit(1); | |
3040 | } | |
3041 | ||
3042 | os_setup_early_signal_handling(); | |
3043 | ||
3044 | bdrv_init_with_whitelist(); | |
3045 | socket_init(); | |
3046 | } | |
0546c060 | 3047 | |
d8e4de41 PB |
3048 | /* |
3049 | * Called after leaving preconfig state. From here on runstate is | |
3050 | * RUN_STATE_PRELAUNCH or RUN_STATE_INMIGRATE. | |
3051 | */ | |
3052 | static void qemu_init_board(void) | |
3053 | { | |
3054 | MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); | |
3055 | ||
3056 | if (machine_class->default_ram_id && current_machine->ram_size && | |
3057 | numa_uses_legacy_mem() && !current_machine->ram_memdev_id) { | |
3058 | create_default_memdev(current_machine, mem_path); | |
3059 | } | |
3060 | ||
3061 | machine_run_board_init(current_machine); | |
3062 | ||
3063 | /* | |
3064 | * TODO To drop support for deprecated bogus if=..., move | |
3065 | * drive_check_orphaned() here, replacing this call. Also drop | |
3066 | * its deprecation warning, along with DriveInfo member | |
3067 | * @claimed_by_board. | |
3068 | */ | |
3069 | drive_mark_claimed_by_board(); | |
3070 | ||
3071 | realtime_init(); | |
3072 | ||
3073 | if (hax_enabled()) { | |
3074 | /* FIXME: why isn't cpu_synchronize_all_post_init enough? */ | |
3075 | hax_sync_vcpus(); | |
3076 | } | |
3077 | } | |
3078 | ||
3079 | static void qemu_create_cli_devices(void) | |
3080 | { | |
3081 | soundhw_init(); | |
3082 | ||
3083 | qemu_opts_foreach(qemu_find_opts("fw_cfg"), | |
3084 | parse_fw_cfg, fw_cfg_find(), &error_fatal); | |
3085 | ||
3086 | /* init USB devices */ | |
3087 | if (machine_usb(current_machine)) { | |
3088 | if (foreach_device_config(DEV_USB, usb_parse) < 0) | |
3089 | exit(1); | |
3090 | } | |
3091 | ||
3092 | /* init generic devices */ | |
3093 | rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); | |
3094 | qemu_opts_foreach(qemu_find_opts("device"), | |
3095 | device_init_func, NULL, &error_fatal); | |
3096 | rom_reset_order_override(); | |
3097 | } | |
3098 | ||
3099 | static void qemu_machine_creation_done(void) | |
3100 | { | |
3101 | DisplayState *ds; | |
3102 | ||
3103 | cpu_synchronize_all_post_init(); | |
3104 | ||
3105 | /* Did we create any drives that we failed to create a device for? */ | |
3106 | drive_check_orphaned(); | |
3107 | ||
3108 | /* Don't warn about the default network setup that you get if | |
3109 | * no command line -net or -netdev options are specified. There | |
3110 | * are two cases that we would otherwise complain about: | |
3111 | * (1) board doesn't support a NIC but the implicit "-net nic" | |
3112 | * requested one | |
3113 | * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic" | |
3114 | * sets up a nic that isn't connected to anything. | |
3115 | */ | |
3116 | if (!default_net && (!qtest_enabled() || has_defaults)) { | |
3117 | net_check_clients(); | |
3118 | } | |
3119 | ||
3120 | if (boot_once) { | |
3121 | qemu_boot_set(boot_once, &error_fatal); | |
3122 | qemu_register_reset(restore_boot_order, g_strdup(boot_order)); | |
3123 | } | |
3124 | ||
3125 | /* init local displays */ | |
3126 | ds = init_displaystate(); | |
3127 | qemu_display_init(ds, &dpy); | |
3128 | ||
3129 | /* must be after terminal init, SDL library changes signal handlers */ | |
3130 | os_setup_signal_handling(); | |
3131 | ||
3132 | /* init remote displays */ | |
3133 | #ifdef CONFIG_VNC | |
3134 | qemu_opts_foreach(qemu_find_opts("vnc"), | |
3135 | vnc_init_func, NULL, &error_fatal); | |
3136 | #endif | |
3137 | ||
3138 | if (using_spice) { | |
3139 | qemu_spice.display_init(); | |
3140 | } | |
3141 | ||
3142 | if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) { | |
3143 | exit(1); | |
3144 | } | |
3145 | ||
3146 | qdev_machine_creation_done(); | |
3147 | ||
3148 | /* TODO: once all bus devices are qdevified, this should be done | |
3149 | * when bus is created by qdev.c */ | |
3150 | /* | |
3151 | * TODO: If we had a main 'reset container' that the whole system | |
3152 | * lived in, we could reset that using the multi-phase reset | |
3153 | * APIs. For the moment, we just reset the sysbus, which will cause | |
3154 | * all devices hanging off it (and all their child buses, recursively) | |
3155 | * to be reset. Note that this will *not* reset any Device objects | |
3156 | * which are not attached to some part of the qbus tree! | |
3157 | */ | |
3158 | qemu_register_reset(resettable_cold_reset_fn, sysbus_get_default()); | |
3159 | qemu_run_machine_init_done_notifiers(); | |
3160 | ||
3161 | if (rom_check_and_register_reset() != 0) { | |
3162 | error_report("rom check and register reset failed"); | |
3163 | exit(1); | |
3164 | } | |
3165 | ||
3166 | replay_start(); | |
3167 | ||
3168 | /* This checkpoint is required by replay to separate prior clock | |
3169 | reading from the other reads, because timer polling functions query | |
3170 | clock values from the log. */ | |
3171 | replay_checkpoint(CHECKPOINT_RESET); | |
3172 | qemu_system_reset(SHUTDOWN_CAUSE_NONE); | |
3173 | register_global_state(); | |
3174 | } | |
3175 | ||
7b733862 | 3176 | void qemu_init(int argc, char **argv, char **envp) |
0824d6fc | 3177 | { |
e4bcb14c | 3178 | int i; |
efd7ab22 | 3179 | int snapshot = 0; |
8d4e9146 | 3180 | QemuOpts *opts, *machine_opts; |
d1cdd92e | 3181 | QemuOpts *icount_opts = NULL, *accel_opts = NULL; |
03b0ba70 | 3182 | QemuOptsList *olist; |
cd6f1169 | 3183 | int optind; |
6530a97b | 3184 | const char *optarg; |
0056ae24 | 3185 | MachineClass *machine_class; |
d44229c5 | 3186 | const char *vga_model = NULL; |
f29a5614 | 3187 | bool userconfig = true; |
cfc58cf3 | 3188 | bool nographic = false; |
1f0dfe02 | 3189 | int display_remote = 0; |
3b9985e9 | 3190 | ram_addr_t maxram_size; |
c270fb9e | 3191 | uint64_t ram_slots = 0; |
abfd9ce3 | 3192 | FILE *vmstate_dump_file = NULL; |
ddbb0d09 | 3193 | Error *err = NULL; |
2a7b18a3 | 3194 | bool have_custom_ram_size; |
651af51c | 3195 | BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue); |
42229a75 | 3196 | QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list); |
4ebc74db | 3197 | int mem_prealloc = 0; /* force preallocation of physical target memory */ |
0b5538c3 | 3198 | |
4d454574 | 3199 | qemu_add_opts(&qemu_drive_opts); |
968854c8 AK |
3200 | qemu_add_drive_opts(&qemu_legacy_drive_opts); |
3201 | qemu_add_drive_opts(&qemu_common_drive_opts); | |
3202 | qemu_add_drive_opts(&qemu_drive_opts); | |
c5f3014b | 3203 | qemu_add_drive_opts(&bdrv_runtime_opts); |
4d454574 PB |
3204 | qemu_add_opts(&qemu_chardev_opts); |
3205 | qemu_add_opts(&qemu_device_opts); | |
3206 | qemu_add_opts(&qemu_netdev_opts); | |
78cd6f7b | 3207 | qemu_add_opts(&qemu_nic_opts); |
4d454574 PB |
3208 | qemu_add_opts(&qemu_net_opts); |
3209 | qemu_add_opts(&qemu_rtc_opts); | |
3210 | qemu_add_opts(&qemu_global_opts); | |
3211 | qemu_add_opts(&qemu_mon_opts); | |
3212 | qemu_add_opts(&qemu_trace_opts); | |
42229a75 | 3213 | qemu_plugin_add_opts(); |
4d454574 PB |
3214 | qemu_add_opts(&qemu_option_rom_opts); |
3215 | qemu_add_opts(&qemu_machine_opts); | |
8d4e9146 | 3216 | qemu_add_opts(&qemu_accel_opts); |
6e1d3c1c | 3217 | qemu_add_opts(&qemu_mem_opts); |
12b7f57e | 3218 | qemu_add_opts(&qemu_smp_opts); |
4d454574 | 3219 | qemu_add_opts(&qemu_boot_opts); |
4d454574 PB |
3220 | qemu_add_opts(&qemu_add_fd_opts); |
3221 | qemu_add_opts(&qemu_object_opts); | |
d1a0cf73 | 3222 | qemu_add_opts(&qemu_tpmdev_opts); |
888a6bc6 | 3223 | qemu_add_opts(&qemu_realtime_opts); |
1fdd4748 | 3224 | qemu_add_opts(&qemu_overcommit_opts); |
5e2ac519 | 3225 | qemu_add_opts(&qemu_msg_opts); |
5d12f961 | 3226 | qemu_add_opts(&qemu_name_opts); |
0042109a | 3227 | qemu_add_opts(&qemu_numa_opts); |
1ad9580b | 3228 | qemu_add_opts(&qemu_icount_opts); |
a38bb079 | 3229 | qemu_add_opts(&qemu_semihosting_config_opts); |
81b2b810 | 3230 | qemu_add_opts(&qemu_fw_cfg_opts); |
34294e2f | 3231 | module_call_init(MODULE_INIT_OPTS); |
4d454574 | 3232 | |
efd7ab22 PB |
3233 | error_init(argv[0]); |
3234 | qemu_init_exec_dir(argv[0]); | |
142c6b1a | 3235 | |
efd7ab22 | 3236 | qemu_init_subsystems(); |
41bd639b | 3237 | |
292444cb AL |
3238 | /* first pass of option parsing */ |
3239 | optind = 1; | |
3240 | while (optind < argc) { | |
3241 | if (argv[optind][0] != '-') { | |
3242 | /* disk image */ | |
28e68d68 | 3243 | optind++; |
292444cb AL |
3244 | } else { |
3245 | const QEMUOption *popt; | |
3246 | ||
3247 | popt = lookup_opt(argc, argv, &optarg, &optind); | |
3248 | switch (popt->index) { | |
f29a5614 EH |
3249 | case QEMU_OPTION_nouserconfig: |
3250 | userconfig = false; | |
3251 | break; | |
292444cb AL |
3252 | } |
3253 | } | |
3254 | } | |
3255 | ||
1ea06c39 | 3256 | if (userconfig) { |
726401be | 3257 | if (qemu_read_default_config_file() < 0) { |
dcfb0939 | 3258 | exit(1); |
292444cb AL |
3259 | } |
3260 | } | |
3261 | ||
3262 | /* second pass of option parsing */ | |
cd6f1169 | 3263 | optind = 1; |
0824d6fc | 3264 | for(;;) { |
cd6f1169 | 3265 | if (optind >= argc) |
0824d6fc | 3266 | break; |
6530a97b | 3267 | if (argv[optind][0] != '-') { |
17f30eae | 3268 | loc_set_cmdline(argv, optind, 1); |
d1cdd92e | 3269 | drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS); |
cd6f1169 FB |
3270 | } else { |
3271 | const QEMUOption *popt; | |
3272 | ||
6530a97b | 3273 | popt = lookup_opt(argc, argv, &optarg, &optind); |
ad96090a | 3274 | if (!(popt->arch_mask & arch_type)) { |
da002526 | 3275 | error_report("Option not supported for this target"); |
ad96090a BS |
3276 | exit(1); |
3277 | } | |
cd6f1169 | 3278 | switch(popt->index) { |
94fc95cd JM |
3279 | case QEMU_OPTION_cpu: |
3280 | /* hw initialization will check this */ | |
c1c8cfe5 | 3281 | cpu_option = optarg; |
94fc95cd | 3282 | break; |
cd6f1169 | 3283 | case QEMU_OPTION_hda: |
cd6f1169 | 3284 | case QEMU_OPTION_hdb: |
cc1daa40 FB |
3285 | case QEMU_OPTION_hdc: |
3286 | case QEMU_OPTION_hdd: | |
2292ddae MA |
3287 | drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg, |
3288 | HD_OPTS); | |
fc01f7e7 | 3289 | break; |
42e5f393 MA |
3290 | case QEMU_OPTION_blockdev: |
3291 | { | |
3292 | Visitor *v; | |
651af51c | 3293 | BlockdevOptionsQueueEntry *bdo; |
42e5f393 | 3294 | |
92917cd2 MA |
3295 | v = qobject_input_visitor_new_str(optarg, "driver", |
3296 | &error_fatal); | |
42e5f393 | 3297 | |
651af51c | 3298 | bdo = g_new(BlockdevOptionsQueueEntry, 1); |
42e5f393 MA |
3299 | visit_type_BlockdevOptions(v, NULL, &bdo->bdo, |
3300 | &error_fatal); | |
3301 | visit_free(v); | |
3302 | loc_save(&bdo->loc); | |
3303 | QSIMPLEQ_INSERT_TAIL(&bdo_queue, bdo, entry); | |
3304 | break; | |
3305 | } | |
e4bcb14c | 3306 | case QEMU_OPTION_drive: |
e2982c3a MT |
3307 | if (drive_def(optarg) == NULL) { |
3308 | exit(1); | |
3309 | } | |
99efa84d | 3310 | break; |
d058fe03 GH |
3311 | case QEMU_OPTION_set: |
3312 | if (qemu_set_option(optarg) != 0) | |
3313 | exit(1); | |
99efa84d | 3314 | break; |
d0fef6fb GH |
3315 | case QEMU_OPTION_global: |
3316 | if (qemu_global_option(optarg) != 0) | |
3317 | exit(1); | |
99efa84d | 3318 | break; |
3e3d5815 | 3319 | case QEMU_OPTION_mtdblock: |
2292ddae | 3320 | drive_add(IF_MTD, -1, optarg, MTD_OPTS); |
3e3d5815 | 3321 | break; |
a1bb27b1 | 3322 | case QEMU_OPTION_sd: |
80f4d9fc | 3323 | drive_add(IF_SD, -1, optarg, SD_OPTS); |
a1bb27b1 | 3324 | break; |
86f55663 | 3325 | case QEMU_OPTION_pflash: |
2292ddae | 3326 | drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS); |
86f55663 | 3327 | break; |
cd6f1169 | 3328 | case QEMU_OPTION_snapshot: |
25863975 PD |
3329 | { |
3330 | Error *blocker = NULL; | |
3331 | snapshot = 1; | |
3332 | error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, | |
3333 | "-snapshot"); | |
3334 | replay_add_blocker(blocker); | |
3335 | } | |
33e3963e | 3336 | break; |
268a362c | 3337 | case QEMU_OPTION_numa: |
70b94331 MA |
3338 | opts = qemu_opts_parse_noisily(qemu_find_opts("numa"), |
3339 | optarg, true); | |
0042109a WG |
3340 | if (!opts) { |
3341 | exit(1); | |
3342 | } | |
268a362c | 3343 | break; |
1472a95b | 3344 | case QEMU_OPTION_display: |
e3af9f9a | 3345 | parse_display(optarg); |
1472a95b | 3346 | break; |
cd6f1169 | 3347 | case QEMU_OPTION_nographic: |
cfc58cf3 EH |
3348 | olist = qemu_find_opts("machine"); |
3349 | qemu_opts_parse_noisily(olist, "graphics=off", false); | |
3350 | nographic = true; | |
0c8d7065 | 3351 | dpy.type = DISPLAY_TYPE_NONE; |
a20dd508 | 3352 | break; |
4d3b6f6e | 3353 | case QEMU_OPTION_curses: |
47b05369 | 3354 | #ifdef CONFIG_CURSES |
14f130fa | 3355 | dpy.type = DISPLAY_TYPE_CURSES; |
47b05369 | 3356 | #else |
e08bb301 | 3357 | error_report("curses or iconv support is disabled"); |
47b05369 | 3358 | exit(1); |
4d3b6f6e | 3359 | #endif |
47b05369 | 3360 | break; |
a171fe39 | 3361 | case QEMU_OPTION_portrait: |
9312805d VK |
3362 | graphic_rotate = 90; |
3363 | break; | |
3364 | case QEMU_OPTION_rotate: | |
3365 | graphic_rotate = strtol(optarg, (char **) &optarg, 10); | |
3366 | if (graphic_rotate != 0 && graphic_rotate != 90 && | |
3367 | graphic_rotate != 180 && graphic_rotate != 270) { | |
f61eddcb | 3368 | error_report("only 90, 180, 270 deg rotation is available"); |
9312805d VK |
3369 | exit(1); |
3370 | } | |
a171fe39 | 3371 | break; |
cd6f1169 | 3372 | case QEMU_OPTION_kernel: |
8ef3a4be | 3373 | qemu_opts_set(qemu_find_opts("machine"), NULL, "kernel", optarg, |
79087c78 | 3374 | &error_abort); |
a0abe474 PM |
3375 | break; |
3376 | case QEMU_OPTION_initrd: | |
8ef3a4be | 3377 | qemu_opts_set(qemu_find_opts("machine"), NULL, "initrd", optarg, |
79087c78 | 3378 | &error_abort); |
a20dd508 | 3379 | break; |
cd6f1169 | 3380 | case QEMU_OPTION_append: |
8ef3a4be | 3381 | qemu_opts_set(qemu_find_opts("machine"), NULL, "append", optarg, |
79087c78 | 3382 | &error_abort); |
313aa567 | 3383 | break; |
412beee6 | 3384 | case QEMU_OPTION_dtb: |
8ef3a4be | 3385 | qemu_opts_set(qemu_find_opts("machine"), NULL, "dtb", optarg, |
79087c78 | 3386 | &error_abort); |
412beee6 | 3387 | break; |
cd6f1169 | 3388 | case QEMU_OPTION_cdrom: |
2292ddae | 3389 | drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS); |
36b486bb | 3390 | break; |
cd6f1169 | 3391 | case QEMU_OPTION_boot: |
70b94331 MA |
3392 | opts = qemu_opts_parse_noisily(qemu_find_opts("boot-opts"), |
3393 | optarg, true); | |
8281abd5 MA |
3394 | if (!opts) { |
3395 | exit(1); | |
36b486bb FB |
3396 | } |
3397 | break; | |
cd6f1169 | 3398 | case QEMU_OPTION_fda: |
cd6f1169 | 3399 | case QEMU_OPTION_fdb: |
2292ddae MA |
3400 | drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda, |
3401 | optarg, FD_OPTS); | |
c45886db | 3402 | break; |
52ca8d6a FB |
3403 | case QEMU_OPTION_no_fd_bootchk: |
3404 | fd_bootchk = 0; | |
3405 | break; | |
a1ea458f | 3406 | case QEMU_OPTION_netdev: |
d30300f7 | 3407 | default_net = 0; |
3329f07b | 3408 | if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) { |
a1ea458f MM |
3409 | exit(1); |
3410 | } | |
3411 | break; | |
78cd6f7b TH |
3412 | case QEMU_OPTION_nic: |
3413 | default_net = 0; | |
3414 | if (net_client_parse(qemu_find_opts("nic"), optarg) == -1) { | |
3415 | exit(1); | |
3416 | } | |
3417 | break; | |
7c9d8e07 | 3418 | case QEMU_OPTION_net: |
d30300f7 | 3419 | default_net = 0; |
3329f07b | 3420 | if (net_client_parse(qemu_find_opts("net"), optarg) == -1) { |
c4b1fcc0 FB |
3421 | exit(1); |
3422 | } | |
702c651c | 3423 | break; |
f9dadc98 RS |
3424 | #ifdef CONFIG_LIBISCSI |
3425 | case QEMU_OPTION_iscsi: | |
70b94331 MA |
3426 | opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"), |
3427 | optarg, false); | |
f9dadc98 RS |
3428 | if (!opts) { |
3429 | exit(1); | |
3430 | } | |
3431 | break; | |
c7f74643 | 3432 | #endif |
1d14ffa9 | 3433 | case QEMU_OPTION_audio_help: |
71830221 | 3434 | audio_legacy_help(); |
1d14ffa9 FB |
3435 | exit (0); |
3436 | break; | |
71830221 KZ |
3437 | case QEMU_OPTION_audiodev: |
3438 | audio_parse_option(optarg); | |
3439 | break; | |
1d14ffa9 FB |
3440 | case QEMU_OPTION_soundhw: |
3441 | select_soundhw (optarg); | |
3442 | break; | |
cd6f1169 | 3443 | case QEMU_OPTION_h: |
15f82208 | 3444 | help(0); |
cd6f1169 | 3445 | break; |
9bd7e6d9 PB |
3446 | case QEMU_OPTION_version: |
3447 | version(); | |
3448 | exit(0); | |
3449 | break; | |
3b9985e9 | 3450 | case QEMU_OPTION_m: |
70b94331 MA |
3451 | opts = qemu_opts_parse_noisily(qemu_find_opts("memory"), |
3452 | optarg, true); | |
6e1d3c1c IM |
3453 | if (!opts) { |
3454 | exit(EXIT_FAILURE); | |
3455 | } | |
cd6f1169 | 3456 | break; |
d1a0cf73 SB |
3457 | #ifdef CONFIG_TPM |
3458 | case QEMU_OPTION_tpmdev: | |
3459 | if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) { | |
3460 | exit(1); | |
3461 | } | |
3462 | break; | |
3463 | #endif | |
c902760f MT |
3464 | case QEMU_OPTION_mempath: |
3465 | mem_path = optarg; | |
3466 | break; | |
c902760f MT |
3467 | case QEMU_OPTION_mem_prealloc: |
3468 | mem_prealloc = 1; | |
3469 | break; | |
cd6f1169 | 3470 | case QEMU_OPTION_d: |
c235d738 MF |
3471 | log_mask = optarg; |
3472 | break; | |
3473 | case QEMU_OPTION_D: | |
3474 | log_file = optarg; | |
cd6f1169 | 3475 | break; |
3514552e | 3476 | case QEMU_OPTION_DFILTER: |
bd6fee9f | 3477 | qemu_set_dfilter_ranges(optarg, &error_fatal); |
3514552e | 3478 | break; |
9c09a251 RH |
3479 | case QEMU_OPTION_seed: |
3480 | qemu_guest_random_seed_main(optarg, &error_fatal); | |
3481 | break; | |
cd6f1169 | 3482 | case QEMU_OPTION_s: |
ef0c4a0d | 3483 | add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); |
cd6f1169 | 3484 | break; |
59030a8c | 3485 | case QEMU_OPTION_gdb: |
ef0c4a0d | 3486 | add_device_config(DEV_GDB, optarg); |
cd6f1169 | 3487 | break; |
cd6f1169 | 3488 | case QEMU_OPTION_L: |
37146e7e RJ |
3489 | if (is_help_option(optarg)) { |
3490 | list_data_dirs = true; | |
2a1cce90 | 3491 | } else { |
ea1edcd7 | 3492 | qemu_add_data_dir(g_strdup(optarg)); |
4524051c | 3493 | } |
cd6f1169 | 3494 | break; |
1192dad8 | 3495 | case QEMU_OPTION_bios: |
8ef3a4be | 3496 | qemu_opts_set(qemu_find_opts("machine"), NULL, "firmware", optarg, |
79087c78 | 3497 | &error_abort); |
1192dad8 | 3498 | break; |
1b530a6d AJ |
3499 | case QEMU_OPTION_singlestep: |
3500 | singlestep = 1; | |
3501 | break; | |
cd6f1169 | 3502 | case QEMU_OPTION_S: |
3c07f8e8 | 3503 | autostart = 0; |
cd6f1169 | 3504 | break; |
99efa84d MA |
3505 | case QEMU_OPTION_k: |
3506 | keyboard_layout = optarg; | |
3507 | break; | |
3893c124 | 3508 | case QEMU_OPTION_vga: |
a369da5f | 3509 | vga_model = optarg; |
7f1b17f2 | 3510 | default_vga = 0; |
1bfe856e | 3511 | break; |
e9b137c2 FB |
3512 | case QEMU_OPTION_g: |
3513 | { | |
3514 | const char *p; | |
3515 | int w, h, depth; | |
3516 | p = optarg; | |
3517 | w = strtol(p, (char **)&p, 10); | |
3518 | if (w <= 0) { | |
3519 | graphic_error: | |
f61eddcb | 3520 | error_report("invalid resolution or depth"); |
e9b137c2 FB |
3521 | exit(1); |
3522 | } | |
3523 | if (*p != 'x') | |
3524 | goto graphic_error; | |
3525 | p++; | |
3526 | h = strtol(p, (char **)&p, 10); | |
3527 | if (h <= 0) | |
3528 | goto graphic_error; | |
3529 | if (*p == 'x') { | |
3530 | p++; | |
3531 | depth = strtol(p, (char **)&p, 10); | |
8ac919a0 LV |
3532 | if (depth != 1 && depth != 2 && depth != 4 && |
3533 | depth != 8 && depth != 15 && depth != 16 && | |
e9b137c2 FB |
3534 | depth != 24 && depth != 32) |
3535 | goto graphic_error; | |
3536 | } else if (*p == '\0') { | |
3537 | depth = graphic_depth; | |
3538 | } else { | |
3539 | goto graphic_error; | |
3540 | } | |
3b46e624 | 3541 | |
e9b137c2 FB |
3542 | graphic_width = w; |
3543 | graphic_height = h; | |
3544 | graphic_depth = depth; | |
3545 | } | |
3546 | break; | |
20d8a3ed TS |
3547 | case QEMU_OPTION_echr: |
3548 | { | |
3549 | char *r; | |
3550 | term_escape_char = strtol(optarg, &r, 0); | |
3551 | if (r == optarg) | |
3552 | printf("Bad argument to echr\n"); | |
3553 | break; | |
3554 | } | |
82c643ff | 3555 | case QEMU_OPTION_monitor: |
6ca5582d | 3556 | default_monitor = 0; |
70e098af | 3557 | if (strncmp(optarg, "none", 4)) { |
4821cd4c | 3558 | monitor_parse(optarg, "readline", false); |
70e098af | 3559 | } |
6ca5582d GH |
3560 | break; |
3561 | case QEMU_OPTION_qmp: | |
4821cd4c HR |
3562 | monitor_parse(optarg, "control", false); |
3563 | default_monitor = 0; | |
3564 | break; | |
3565 | case QEMU_OPTION_qmp_pretty: | |
3566 | monitor_parse(optarg, "control", true); | |
2d114dc1 | 3567 | default_monitor = 0; |
82c643ff | 3568 | break; |
22a0e04b | 3569 | case QEMU_OPTION_mon: |
70b94331 MA |
3570 | opts = qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg, |
3571 | true); | |
22a0e04b | 3572 | if (!opts) { |
22a0e04b GH |
3573 | exit(1); |
3574 | } | |
2d114dc1 | 3575 | default_monitor = 0; |
22a0e04b | 3576 | break; |
191bc01b | 3577 | case QEMU_OPTION_chardev: |
70b94331 MA |
3578 | opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), |
3579 | optarg, true); | |
191bc01b | 3580 | if (!opts) { |
191bc01b GH |
3581 | exit(1); |
3582 | } | |
191bc01b | 3583 | break; |
74db920c | 3584 | case QEMU_OPTION_fsdev: |
03b0ba70 GH |
3585 | olist = qemu_find_opts("fsdev"); |
3586 | if (!olist) { | |
5dfdae81 | 3587 | error_report("fsdev support is disabled"); |
03b0ba70 GH |
3588 | exit(1); |
3589 | } | |
70b94331 | 3590 | opts = qemu_opts_parse_noisily(olist, optarg, true); |
74db920c | 3591 | if (!opts) { |
74db920c GS |
3592 | exit(1); |
3593 | } | |
3594 | break; | |
3d54abc7 | 3595 | case QEMU_OPTION_virtfs: { |
e14ea479 SH |
3596 | QemuOpts *fsdev; |
3597 | QemuOpts *device; | |
1a6ed33c AM |
3598 | const char *writeout, *sock_fd, *socket, *path, *security_model, |
3599 | *multidevs; | |
3d54abc7 | 3600 | |
03b0ba70 GH |
3601 | olist = qemu_find_opts("virtfs"); |
3602 | if (!olist) { | |
5dfdae81 | 3603 | error_report("virtfs support is disabled"); |
03b0ba70 GH |
3604 | exit(1); |
3605 | } | |
70b94331 | 3606 | opts = qemu_opts_parse_noisily(olist, optarg, true); |
3d54abc7 | 3607 | if (!opts) { |
3d54abc7 GS |
3608 | exit(1); |
3609 | } | |
3610 | ||
fbcbf101 | 3611 | if (qemu_opt_get(opts, "fsdriver") == NULL || |
99519f0a | 3612 | qemu_opt_get(opts, "mount_tag") == NULL) { |
8afb9000 | 3613 | error_report("Usage: -virtfs fsdriver,mount_tag=tag"); |
9ce56db6 VJ |
3614 | exit(1); |
3615 | } | |
e14ea479 | 3616 | fsdev = qemu_opts_create(qemu_find_opts("fsdev"), |
3baa0a6a | 3617 | qemu_opts_id(opts) ?: |
8be7e7e4 LC |
3618 | qemu_opt_get(opts, "mount_tag"), |
3619 | 1, NULL); | |
e14ea479 | 3620 | if (!fsdev) { |
3baa0a6a | 3621 | error_report("duplicate or invalid fsdev id: %s", |
f61eddcb | 3622 | qemu_opt_get(opts, "mount_tag")); |
3d54abc7 GS |
3623 | exit(1); |
3624 | } | |
d3ab98e6 AK |
3625 | |
3626 | writeout = qemu_opt_get(opts, "writeout"); | |
3627 | if (writeout) { | |
3628 | #ifdef CONFIG_SYNC_FILE_RANGE | |
f43e47db | 3629 | qemu_opt_set(fsdev, "writeout", writeout, &error_abort); |
d3ab98e6 | 3630 | #else |
f61eddcb EH |
3631 | error_report("writeout=immediate not supported " |
3632 | "on this platform"); | |
d3ab98e6 AK |
3633 | exit(1); |
3634 | #endif | |
3635 | } | |
f43e47db MA |
3636 | qemu_opt_set(fsdev, "fsdriver", |
3637 | qemu_opt_get(opts, "fsdriver"), &error_abort); | |
32b69436 GK |
3638 | path = qemu_opt_get(opts, "path"); |
3639 | if (path) { | |
3640 | qemu_opt_set(fsdev, "path", path, &error_abort); | |
3641 | } | |
3642 | security_model = qemu_opt_get(opts, "security_model"); | |
3643 | if (security_model) { | |
3644 | qemu_opt_set(fsdev, "security_model", security_model, | |
3645 | &error_abort); | |
3646 | } | |
84a87cc4 MK |
3647 | socket = qemu_opt_get(opts, "socket"); |
3648 | if (socket) { | |
f43e47db | 3649 | qemu_opt_set(fsdev, "socket", socket, &error_abort); |
84a87cc4 | 3650 | } |
4c793dda MK |
3651 | sock_fd = qemu_opt_get(opts, "sock_fd"); |
3652 | if (sock_fd) { | |
f43e47db | 3653 | qemu_opt_set(fsdev, "sock_fd", sock_fd, &error_abort); |
4c793dda | 3654 | } |
e14ea479 | 3655 | |
2c74c2cb | 3656 | qemu_opt_set_bool(fsdev, "readonly", |
cccb7967 MA |
3657 | qemu_opt_get_bool(opts, "readonly", 0), |
3658 | &error_abort); | |
1a6ed33c AM |
3659 | multidevs = qemu_opt_get(opts, "multidevs"); |
3660 | if (multidevs) { | |
3661 | qemu_opt_set(fsdev, "multidevs", multidevs, &error_abort); | |
3662 | } | |
87ea75d5 PC |
3663 | device = qemu_opts_create(qemu_find_opts("device"), NULL, 0, |
3664 | &error_abort); | |
f43e47db | 3665 | qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort); |
e14ea479 | 3666 | qemu_opt_set(device, "fsdev", |
3baa0a6a | 3667 | qemu_opts_id(fsdev), &error_abort); |
e14ea479 | 3668 | qemu_opt_set(device, "mount_tag", |
f43e47db | 3669 | qemu_opt_get(opts, "mount_tag"), &error_abort); |
3d54abc7 GS |
3670 | break; |
3671 | } | |
82c643ff | 3672 | case QEMU_OPTION_serial: |
998bbd74 GH |
3673 | add_device_config(DEV_SERIAL, optarg); |
3674 | default_serial = 0; | |
18141ed6 JK |
3675 | if (strncmp(optarg, "mon:", 4) == 0) { |
3676 | default_monitor = 0; | |
3677 | } | |
82c643ff | 3678 | break; |
9dd986cc | 3679 | case QEMU_OPTION_watchdog: |
09aaa160 | 3680 | if (watchdog) { |
f61eddcb | 3681 | error_report("only one watchdog option may be given"); |
7b733862 | 3682 | exit(1); |
09aaa160 MA |
3683 | } |
3684 | watchdog = optarg; | |
9dd986cc RJ |
3685 | break; |
3686 | case QEMU_OPTION_watchdog_action: | |
3687 | if (select_watchdog_action(optarg) == -1) { | |
3e515373 | 3688 | error_report("unknown -watchdog-action parameter"); |
9dd986cc RJ |
3689 | exit(1); |
3690 | } | |
3691 | break; | |
6508fe59 | 3692 | case QEMU_OPTION_parallel: |
6a5e8b0e GH |
3693 | add_device_config(DEV_PARALLEL, optarg); |
3694 | default_parallel = 0; | |
18141ed6 JK |
3695 | if (strncmp(optarg, "mon:", 4) == 0) { |
3696 | default_monitor = 0; | |
3697 | } | |
6508fe59 | 3698 | break; |
c9f398e5 PA |
3699 | case QEMU_OPTION_debugcon: |
3700 | add_device_config(DEV_DEBUGCON, optarg); | |
3701 | break; | |
99efa84d MA |
3702 | case QEMU_OPTION_loadvm: |
3703 | loadvm = optarg; | |
3704 | break; | |
d63d307f | 3705 | case QEMU_OPTION_full_screen: |
0c8d7065 GH |
3706 | dpy.has_full_screen = true; |
3707 | dpy.full_screen = true; | |
d63d307f | 3708 | break; |
3780e197 TS |
3709 | case QEMU_OPTION_alt_grab: |
3710 | alt_grab = 1; | |
3711 | break; | |
0ca9f8a4 DK |
3712 | case QEMU_OPTION_ctrl_grab: |
3713 | ctrl_grab = 1; | |
3714 | break; | |
667accab | 3715 | case QEMU_OPTION_no_quit: |
0c8d7065 GH |
3716 | dpy.has_window_close = true; |
3717 | dpy.window_close = false; | |
667accab | 3718 | break; |
7d957bd8 | 3719 | case QEMU_OPTION_sdl: |
24f6ff86 | 3720 | #ifdef CONFIG_SDL |
fe91f36a | 3721 | dpy.type = DISPLAY_TYPE_SDL; |
7d957bd8 | 3722 | break; |
58fc096c | 3723 | #else |
f61eddcb | 3724 | error_report("SDL support is disabled"); |
58fc096c | 3725 | exit(1); |
667accab | 3726 | #endif |
f7cce898 | 3727 | case QEMU_OPTION_pidfile: |
93815bc2 | 3728 | pid_file = optarg; |
f7cce898 | 3729 | break; |
a09db21f FB |
3730 | case QEMU_OPTION_win2k_hack: |
3731 | win2k_install_hack = 1; | |
3732 | break; | |
8a92ea2f | 3733 | case QEMU_OPTION_acpitable: |
70b94331 MA |
3734 | opts = qemu_opts_parse_noisily(qemu_find_opts("acpi"), |
3735 | optarg, true); | |
f46e720a LE |
3736 | if (!opts) { |
3737 | exit(1); | |
3738 | } | |
9f57061c | 3739 | acpi_table_add(opts, &error_fatal); |
8a92ea2f | 3740 | break; |
b6f6e3d3 | 3741 | case QEMU_OPTION_smbios: |
70b94331 MA |
3742 | opts = qemu_opts_parse_noisily(qemu_find_opts("smbios"), |
3743 | optarg, false); | |
f46e720a LE |
3744 | if (!opts) { |
3745 | exit(1); | |
3746 | } | |
1007a37e | 3747 | smbios_entry_add(opts, &error_fatal); |
b6f6e3d3 | 3748 | break; |
81b2b810 | 3749 | case QEMU_OPTION_fwcfg: |
70b94331 MA |
3750 | opts = qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"), |
3751 | optarg, true); | |
81b2b810 GS |
3752 | if (opts == NULL) { |
3753 | exit(1); | |
3754 | } | |
3755 | break; | |
047f7038 IM |
3756 | case QEMU_OPTION_preconfig: |
3757 | preconfig_exit_requested = false; | |
3758 | break; | |
7ba1e619 | 3759 | case QEMU_OPTION_enable_kvm: |
303d4e86 | 3760 | olist = qemu_find_opts("machine"); |
70b94331 | 3761 | qemu_opts_parse_noisily(olist, "accel=kvm", false); |
303d4e86 | 3762 | break; |
364c3e6b | 3763 | case QEMU_OPTION_M: |
303d4e86 AP |
3764 | case QEMU_OPTION_machine: |
3765 | olist = qemu_find_opts("machine"); | |
70b94331 | 3766 | opts = qemu_opts_parse_noisily(olist, optarg, true); |
303d4e86 | 3767 | if (!opts) { |
303d4e86 AP |
3768 | exit(1); |
3769 | } | |
7ba1e619 | 3770 | break; |
a20fa79f | 3771 | case QEMU_OPTION_accel: |
8d4e9146 FK |
3772 | accel_opts = qemu_opts_parse_noisily(qemu_find_opts("accel"), |
3773 | optarg, true); | |
3774 | optarg = qemu_opt_get(accel_opts, "accel"); | |
bde4d920 | 3775 | if (!optarg || is_help_option(optarg)) { |
cbe6d636 WSM |
3776 | printf("Accelerators supported in QEMU binary:\n"); |
3777 | GSList *el, *accel_list = object_class_get_list(TYPE_ACCEL, | |
3778 | false); | |
3779 | for (el = accel_list; el; el = el->next) { | |
3780 | gchar *typename = g_strdup(object_class_get_name( | |
3781 | OBJECT_CLASS(el->data))); | |
3782 | /* omit qtest which is used for tests only */ | |
3783 | if (g_strcmp0(typename, ACCEL_CLASS_NAME("qtest")) && | |
3784 | g_str_has_suffix(typename, ACCEL_CLASS_SUFFIX)) { | |
3785 | gchar **optname = g_strsplit(typename, | |
3786 | ACCEL_CLASS_SUFFIX, 0); | |
3787 | printf("%s\n", optname[0]); | |
4903602e | 3788 | g_strfreev(optname); |
cbe6d636 WSM |
3789 | } |
3790 | g_free(typename); | |
3791 | } | |
3792 | g_slist_free(accel_list); | |
a20fa79f | 3793 | exit(0); |
8d4e9146 FK |
3794 | } |
3795 | break; | |
bb36d470 | 3796 | case QEMU_OPTION_usb: |
fa5358c6 | 3797 | olist = qemu_find_opts("machine"); |
70b94331 | 3798 | qemu_opts_parse_noisily(olist, "usb=on", false); |
bb36d470 | 3799 | break; |
a594cfbf | 3800 | case QEMU_OPTION_usbdevice: |
a358a3af TH |
3801 | error_report("'-usbdevice' is deprecated, please use " |
3802 | "'-device usb-...' instead"); | |
fa5358c6 | 3803 | olist = qemu_find_opts("machine"); |
70b94331 | 3804 | qemu_opts_parse_noisily(olist, "usb=on", false); |
bd3c948d GH |
3805 | add_device_config(DEV_USB, optarg); |
3806 | break; | |
3807 | case QEMU_OPTION_device: | |
70b94331 MA |
3808 | if (!qemu_opts_parse_noisily(qemu_find_opts("device"), |
3809 | optarg, true)) { | |
f31d07d1 GH |
3810 | exit(1); |
3811 | } | |
a594cfbf | 3812 | break; |
6a00d601 | 3813 | case QEMU_OPTION_smp: |
70b94331 MA |
3814 | if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"), |
3815 | optarg, true)) { | |
6be68d7e JS |
3816 | exit(1); |
3817 | } | |
6a00d601 | 3818 | break; |
99efa84d | 3819 | case QEMU_OPTION_vnc: |
7b1ee0f2 | 3820 | vnc_parse(optarg, &error_fatal); |
821601ea | 3821 | break; |
6515b203 | 3822 | case QEMU_OPTION_no_acpi: |
17e89077 GH |
3823 | olist = qemu_find_opts("machine"); |
3824 | qemu_opts_parse_noisily(olist, "acpi=off", false); | |
6515b203 | 3825 | break; |
16b29ae1 | 3826 | case QEMU_OPTION_no_hpet: |
0259c78c EH |
3827 | olist = qemu_find_opts("machine"); |
3828 | qemu_opts_parse_noisily(olist, "hpet=off", false); | |
16b29ae1 | 3829 | break; |
d1beab82 FB |
3830 | case QEMU_OPTION_no_reboot: |
3831 | no_reboot = 1; | |
3832 | break; | |
b2f76161 AJ |
3833 | case QEMU_OPTION_no_shutdown: |
3834 | no_shutdown = 1; | |
3835 | break; | |
9467cd46 | 3836 | case QEMU_OPTION_show_cursor: |
df2ac3cc GH |
3837 | warn_report("The -show-cursor option is deprecated. Please " |
3838 | "add show-cursor=on to your -display options."); | |
3839 | warn_report("When using the default display you can use " | |
3840 | "-display default,show-cursor=on"); | |
09aa82ee GH |
3841 | dpy.has_show_cursor = true; |
3842 | dpy.show_cursor = true; | |
9467cd46 | 3843 | break; |
8fcb1b90 | 3844 | case QEMU_OPTION_uuid: |
9c5ce8db | 3845 | if (qemu_uuid_parse(optarg, &qemu_uuid) < 0) { |
4cd70f34 | 3846 | error_report("failed to parse UUID string: wrong format"); |
8fcb1b90 BS |
3847 | exit(1); |
3848 | } | |
fc3b3295 | 3849 | qemu_uuid_set = true; |
8fcb1b90 | 3850 | break; |
99efa84d MA |
3851 | case QEMU_OPTION_option_rom: |
3852 | if (nb_option_roms >= MAX_OPTION_ROMS) { | |
3e515373 | 3853 | error_report("too many option ROMs"); |
99efa84d MA |
3854 | exit(1); |
3855 | } | |
70b94331 MA |
3856 | opts = qemu_opts_parse_noisily(qemu_find_opts("option-rom"), |
3857 | optarg, true); | |
49295ebc MA |
3858 | if (!opts) { |
3859 | exit(1); | |
3860 | } | |
2e55e842 GN |
3861 | option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile"); |
3862 | option_rom[nb_option_roms].bootindex = | |
3863 | qemu_opt_get_number(opts, "bootindex", -1); | |
3864 | if (!option_rom[nb_option_roms].name) { | |
f61eddcb | 3865 | error_report("Option ROM file is not specified"); |
2e55e842 GN |
3866 | exit(1); |
3867 | } | |
99efa84d MA |
3868 | nb_option_roms++; |
3869 | break; | |
8e71621f | 3870 | case QEMU_OPTION_semihosting: |
f1672e6f | 3871 | qemu_semihosting_enable(); |
a38bb079 LI |
3872 | break; |
3873 | case QEMU_OPTION_semihosting_config: | |
f1672e6f | 3874 | if (qemu_semihosting_config_options(optarg) != 0) { |
a38bb079 LI |
3875 | exit(1); |
3876 | } | |
8e71621f | 3877 | break; |
c35734b2 | 3878 | case QEMU_OPTION_name: |
70b94331 MA |
3879 | opts = qemu_opts_parse_noisily(qemu_find_opts("name"), |
3880 | optarg, true); | |
5d12f961 DDAG |
3881 | if (!opts) { |
3882 | exit(1); | |
3883 | } | |
2880ffb0 MS |
3884 | /* Capture guest name if -msg guest-name is used later */ |
3885 | error_guest_name = qemu_opt_get(opts, "guest"); | |
c35734b2 | 3886 | break; |
66508601 BS |
3887 | case QEMU_OPTION_prom_env: |
3888 | if (nb_prom_envs >= MAX_PROM_ENVS) { | |
3e515373 | 3889 | error_report("too many prom variables"); |
66508601 BS |
3890 | exit(1); |
3891 | } | |
3892 | prom_envs[nb_prom_envs] = optarg; | |
3893 | nb_prom_envs++; | |
3894 | break; | |
2b8f2d41 AZ |
3895 | case QEMU_OPTION_old_param: |
3896 | old_param = 1; | |
05ebd537 | 3897 | break; |
1ed2fc1f | 3898 | case QEMU_OPTION_rtc: |
70b94331 MA |
3899 | opts = qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg, |
3900 | false); | |
1ed2fc1f | 3901 | if (!opts) { |
1ed2fc1f | 3902 | exit(1); |
7e0af5d0 FB |
3903 | } |
3904 | break; | |
26a5f13b | 3905 | case QEMU_OPTION_tb_size: |
f940488f EC |
3906 | #ifndef CONFIG_TCG |
3907 | error_report("TCG is disabled"); | |
3908 | exit(1); | |
3909 | #endif | |
fe174132 PB |
3910 | warn_report("The -tb-size option is deprecated, use -accel tcg,tb-size instead"); |
3911 | object_register_sugar_prop(ACCEL_CLASS_NAME("tcg"), "tb-size", optarg); | |
26a5f13b | 3912 | break; |
2e70f6ef | 3913 | case QEMU_OPTION_icount: |
70b94331 MA |
3914 | icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"), |
3915 | optarg, true); | |
1ad9580b ST |
3916 | if (!icount_opts) { |
3917 | exit(1); | |
3918 | } | |
2e70f6ef | 3919 | break; |
5bb7910a | 3920 | case QEMU_OPTION_incoming: |
7c76235a DDAG |
3921 | if (!incoming) { |
3922 | runstate_set(RUN_STATE_INMIGRATE); | |
3923 | } | |
5bb7910a AL |
3924 | incoming = optarg; |
3925 | break; | |
d15c05fc | 3926 | case QEMU_OPTION_only_migratable: |
811f8652 | 3927 | only_migratable = 1; |
d15c05fc | 3928 | break; |
d8c208dd | 3929 | case QEMU_OPTION_nodefaults: |
d44229c5 | 3930 | has_defaults = 0; |
d8c208dd | 3931 | break; |
e37630ca | 3932 | case QEMU_OPTION_xen_domid: |
ad96090a | 3933 | if (!(xen_available())) { |
da002526 | 3934 | error_report("Option not supported for this target"); |
ad96090a BS |
3935 | exit(1); |
3936 | } | |
e37630ca AL |
3937 | xen_domid = atoi(optarg); |
3938 | break; | |
e37630ca | 3939 | case QEMU_OPTION_xen_attach: |
ad96090a | 3940 | if (!(xen_available())) { |
da002526 | 3941 | error_report("Option not supported for this target"); |
ad96090a BS |
3942 | exit(1); |
3943 | } | |
e37630ca AL |
3944 | xen_mode = XEN_ATTACH; |
3945 | break; | |
1c599472 PD |
3946 | case QEMU_OPTION_xen_domid_restrict: |
3947 | if (!(xen_available())) { | |
3948 | error_report("Option not supported for this target"); | |
3949 | exit(1); | |
3950 | } | |
3951 | xen_domid_restrict = true; | |
3952 | break; | |
ab6540d5 | 3953 | case QEMU_OPTION_trace: |
92eecfff | 3954 | trace_opt_parse(optarg); |
ab6540d5 | 3955 | break; |
42229a75 LV |
3956 | case QEMU_OPTION_plugin: |
3957 | qemu_plugin_opt_parse(optarg, &plugin_list); | |
3958 | break; | |
715a664a GH |
3959 | case QEMU_OPTION_readconfig: |
3960 | { | |
dcfb0939 KW |
3961 | int ret = qemu_read_config_file(optarg); |
3962 | if (ret < 0) { | |
f61eddcb EH |
3963 | error_report("read config %s: %s", optarg, |
3964 | strerror(-ret)); | |
715a664a GH |
3965 | exit(1); |
3966 | } | |
715a664a GH |
3967 | break; |
3968 | } | |
29b0040b | 3969 | case QEMU_OPTION_spice: |
9ed345a1 GH |
3970 | olist = qemu_find_opts_err("spice", NULL); |
3971 | if (!olist) { | |
3972 | ui_module_load_one("spice-core"); | |
3973 | olist = qemu_find_opts("spice"); | |
3974 | } | |
29b0040b | 3975 | if (!olist) { |
5dfdae81 | 3976 | error_report("spice support is disabled"); |
29b0040b GH |
3977 | exit(1); |
3978 | } | |
70b94331 | 3979 | opts = qemu_opts_parse_noisily(olist, optarg, false); |
29b0040b | 3980 | if (!opts) { |
29b0040b GH |
3981 | exit(1); |
3982 | } | |
f963e4d0 | 3983 | display_remote++; |
29b0040b | 3984 | break; |
715a664a GH |
3985 | case QEMU_OPTION_writeconfig: |
3986 | { | |
3987 | FILE *fp; | |
3988 | if (strcmp(optarg, "-") == 0) { | |
3989 | fp = stdout; | |
3990 | } else { | |
3991 | fp = fopen(optarg, "w"); | |
3992 | if (fp == NULL) { | |
f61eddcb EH |
3993 | error_report("open %s: %s", optarg, |
3994 | strerror(errno)); | |
715a664a GH |
3995 | exit(1); |
3996 | } | |
3997 | } | |
3998 | qemu_config_write(fp); | |
7fb8b5d9 CG |
3999 | if (fp != stdout) { |
4000 | fclose(fp); | |
4001 | } | |
715a664a GH |
4002 | break; |
4003 | } | |
c7f0f3b1 AL |
4004 | case QEMU_OPTION_qtest: |
4005 | qtest_chrdev = optarg; | |
4006 | break; | |
4007 | case QEMU_OPTION_qtest_log: | |
4008 | qtest_log = optarg; | |
4009 | break; | |
7d76ad4f | 4010 | case QEMU_OPTION_sandbox: |
2bb814a4 MAL |
4011 | olist = qemu_find_opts("sandbox"); |
4012 | if (!olist) { | |
4013 | #ifndef CONFIG_SECCOMP | |
4014 | error_report("-sandbox support is not enabled " | |
4015 | "in this QEMU binary"); | |
4016 | #endif | |
4017 | exit(1); | |
4018 | } | |
4019 | ||
4020 | opts = qemu_opts_parse_noisily(olist, optarg, true); | |
7d76ad4f | 4021 | if (!opts) { |
49295ebc | 4022 | exit(1); |
7d76ad4f EO |
4023 | } |
4024 | break; | |
587ed6be CB |
4025 | case QEMU_OPTION_add_fd: |
4026 | #ifndef _WIN32 | |
70b94331 MA |
4027 | opts = qemu_opts_parse_noisily(qemu_find_opts("add-fd"), |
4028 | optarg, false); | |
587ed6be | 4029 | if (!opts) { |
49295ebc | 4030 | exit(1); |
587ed6be CB |
4031 | } |
4032 | #else | |
4033 | error_report("File descriptor passing is disabled on this " | |
4034 | "platform"); | |
4035 | exit(1); | |
4036 | #endif | |
4037 | break; | |
68d98d3e | 4038 | case QEMU_OPTION_object: |
70b94331 MA |
4039 | opts = qemu_opts_parse_noisily(qemu_find_opts("object"), |
4040 | optarg, true); | |
49295ebc MA |
4041 | if (!opts) { |
4042 | exit(1); | |
4043 | } | |
68d98d3e | 4044 | break; |
888a6bc6 | 4045 | case QEMU_OPTION_realtime: |
583f34c4 TH |
4046 | warn_report("'-realtime mlock=...' is deprecated, please use " |
4047 | "'-overcommit mem-lock=...' instead"); | |
70b94331 MA |
4048 | opts = qemu_opts_parse_noisily(qemu_find_opts("realtime"), |
4049 | optarg, false); | |
888a6bc6 SM |
4050 | if (!opts) { |
4051 | exit(1); | |
4052 | } | |
6f131f13 MT |
4053 | /* Don't override the -overcommit option if set */ |
4054 | enable_mlock = enable_mlock || | |
4055 | qemu_opt_get_bool(opts, "mlock", true); | |
4056 | break; | |
4057 | case QEMU_OPTION_overcommit: | |
4058 | opts = qemu_opts_parse_noisily(qemu_find_opts("overcommit"), | |
4059 | optarg, false); | |
4060 | if (!opts) { | |
4061 | exit(1); | |
4062 | } | |
4063 | /* Don't override the -realtime option if set */ | |
4064 | enable_mlock = enable_mlock || | |
4065 | qemu_opt_get_bool(opts, "mem-lock", false); | |
4066 | enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", false); | |
888a6bc6 | 4067 | break; |
5e2ac519 | 4068 | case QEMU_OPTION_msg: |
70b94331 MA |
4069 | opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg, |
4070 | false); | |
5e2ac519 SA |
4071 | if (!opts) { |
4072 | exit(1); | |
4073 | } | |
4074 | configure_msg(opts); | |
4075 | break; | |
abfd9ce3 | 4076 | case QEMU_OPTION_dump_vmstate: |
522abf69 | 4077 | if (vmstate_dump_file) { |
f61eddcb EH |
4078 | error_report("only one '-dump-vmstate' " |
4079 | "option may be given"); | |
522abf69 GA |
4080 | exit(1); |
4081 | } | |
abfd9ce3 AS |
4082 | vmstate_dump_file = fopen(optarg, "w"); |
4083 | if (vmstate_dump_file == NULL) { | |
f61eddcb | 4084 | error_report("open %s: %s", optarg, strerror(errno)); |
abfd9ce3 AS |
4085 | exit(1); |
4086 | } | |
12df189d EC |
4087 | break; |
4088 | case QEMU_OPTION_enable_sync_profile: | |
4089 | qsp_enable(); | |
abfd9ce3 | 4090 | break; |
aec0d0e1 MP |
4091 | case QEMU_OPTION_nouserconfig: |
4092 | /* Nothing to be parsed here. Especially, do not error out below. */ | |
4093 | break; | |
59a5264b | 4094 | default: |
1217d6ca TH |
4095 | if (os_parse_cmd_args(popt->index, optarg)) { |
4096 | error_report("Option not supported in this build"); | |
4097 | exit(1); | |
4098 | } | |
cd6f1169 | 4099 | } |
0824d6fc FB |
4100 | } |
4101 | } | |
43fa1e0b EH |
4102 | /* |
4103 | * Clear error location left behind by the loop. | |
4104 | * Best done right after the loop. Do not insert code here! | |
4105 | */ | |
4106 | loc_set_none(); | |
364c3e6b | 4107 | |
58c91595 PB |
4108 | qemu_validate_options(); |
4109 | ||
3df261b6 | 4110 | /* |
0546c060 PB |
4111 | * These options affect everything else and should be processed |
4112 | * before daemonizing. | |
3df261b6 | 4113 | */ |
0546c060 | 4114 | qemu_process_early_options(); |
3df261b6 | 4115 | |
0546c060 PB |
4116 | qemu_process_help_options(); |
4117 | qemu_maybe_daemonize(pid_file); | |
4118 | ||
efd7ab22 PB |
4119 | qemu_init_main_loop(&error_fatal); |
4120 | cpu_timers_init(); | |
3df261b6 | 4121 | |
fc4a4734 | 4122 | user_register_global_props(); |
4c27b859 PD |
4123 | replay_configure(icount_opts); |
4124 | ||
eb6a5209 AP |
4125 | configure_rtc(qemu_find_opts_singleton("rtc")); |
4126 | ||
7580f231 | 4127 | machine_class = select_machine(); |
1a3ec8c1 | 4128 | object_set_machine_compat_props(machine_class->compat_props); |
076b35b5 | 4129 | |
2a7b18a3 IM |
4130 | have_custom_ram_size = set_memory_options(&ram_slots, &maxram_size, |
4131 | machine_class); | |
4132 | ||
3c75e12e | 4133 | current_machine = MACHINE(object_new_with_class(OBJECT_CLASS(machine_class))); |
52eb3dfd MA |
4134 | if (machine_help_func(qemu_get_machine_opts(), current_machine)) { |
4135 | exit(0); | |
4136 | } | |
0056ae24 | 4137 | object_property_add_child(object_get_root(), "machine", |
d2623129 | 4138 | OBJECT(current_machine)); |
e2fb3fbb MA |
4139 | object_property_add_child(container_get(OBJECT(current_machine), |
4140 | "/unattached"), | |
d2623129 | 4141 | "sysbus", OBJECT(sysbus_get_default())); |
20bccb82 PM |
4142 | |
4143 | if (machine_class->minimum_page_bits) { | |
4144 | if (!set_preferred_target_page_bits(machine_class->minimum_page_bits)) { | |
4145 | /* This would be a board error: specifying a minimum smaller than | |
4146 | * a target's compile-time fixed setting. | |
4147 | */ | |
4148 | g_assert_not_reached(); | |
4149 | } | |
4150 | } | |
4151 | ||
b5c2c3d0 | 4152 | cpu_exec_init_all(); |
efd7ab22 | 4153 | page_size_init(); |
0056ae24 | 4154 | |
958db90c | 4155 | if (machine_class->hw_version) { |
35c2c8dc | 4156 | qemu_set_hw_version(machine_class->hw_version); |
93bfef4c CV |
4157 | } |
4158 | ||
3df8c4f3 PB |
4159 | machine_smp_parse(current_machine, |
4160 | qemu_opts_find(qemu_find_opts("smp-opts"), NULL), &error_fatal); | |
b2097003 | 4161 | |
ffac16fa IM |
4162 | if (mem_prealloc) { |
4163 | char *val; | |
4164 | ||
4165 | val = g_strdup_printf("%d", current_machine->smp.cpus); | |
4166 | object_register_sugar_prop("memory-backend", "prealloc-threads", val); | |
4167 | g_free(val); | |
4ebc74db | 4168 | object_register_sugar_prop("memory-backend", "prealloc", "on"); |
ffac16fa IM |
4169 | } |
4170 | ||
67b724e6 AP |
4171 | /* |
4172 | * Get the default machine options from the machine if it is not already | |
4173 | * specified either by the configuration file or by the command line. | |
4174 | */ | |
958db90c | 4175 | if (machine_class->default_machine_opts) { |
25de5935 | 4176 | qemu_opts_set_defaults(qemu_find_opts("machine"), |
958db90c | 4177 | machine_class->default_machine_opts, 0); |
67b724e6 AP |
4178 | } |
4179 | ||
42229a75 LV |
4180 | /* process plugin before CPUs are created, but once -smp has been parsed */ |
4181 | if (qemu_plugin_load_list(&plugin_list)) { | |
4182 | exit(1); | |
4183 | } | |
4184 | ||
28d0de7a MA |
4185 | qemu_opts_foreach(qemu_find_opts("device"), |
4186 | default_driver_check, NULL, NULL); | |
4187 | qemu_opts_foreach(qemu_find_opts("global"), | |
4188 | default_driver_check, NULL, NULL); | |
998bbd74 | 4189 | |
d44229c5 MW |
4190 | if (!vga_model && !default_vga) { |
4191 | vga_interface_type = VGA_DEVICE; | |
4192 | } | |
958db90c | 4193 | if (!has_defaults || machine_class->no_serial) { |
986c5f78 GH |
4194 | default_serial = 0; |
4195 | } | |
958db90c | 4196 | if (!has_defaults || machine_class->no_parallel) { |
986c5f78 GH |
4197 | default_parallel = 0; |
4198 | } | |
958db90c | 4199 | if (!has_defaults || machine_class->no_floppy) { |
ac33f8fa GH |
4200 | default_floppy = 0; |
4201 | } | |
958db90c | 4202 | if (!has_defaults || machine_class->no_cdrom) { |
ac33f8fa GH |
4203 | default_cdrom = 0; |
4204 | } | |
958db90c | 4205 | if (!has_defaults || machine_class->no_sdcard) { |
ac33f8fa GH |
4206 | default_sdcard = 0; |
4207 | } | |
d44229c5 MW |
4208 | if (!has_defaults) { |
4209 | default_monitor = 0; | |
4210 | default_net = 0; | |
4211 | default_vga = 0; | |
4212 | } | |
986c5f78 | 4213 | |
ab51b1d5 MT |
4214 | if (is_daemonized()) { |
4215 | /* According to documentation and historically, -nographic redirects | |
4216 | * serial port, parallel port and monitor to stdio, which does not work | |
4217 | * with -daemonize. We can redirect these to null instead, but since | |
4218 | * -nographic is legacy, let's just error out. | |
4219 | * We disallow -nographic only if all other ports are not redirected | |
4220 | * explicitly, to not break existing legacy setups which uses | |
4221 | * -nographic _and_ redirects all ports explicitly - this is valid | |
4222 | * usage, -nographic is just a no-op in this case. | |
4223 | */ | |
cfc58cf3 | 4224 | if (nographic |
9fd7e96a | 4225 | && (default_parallel || default_serial || default_monitor)) { |
4cd70f34 | 4226 | error_report("-nographic cannot be used with -daemonize"); |
ab51b1d5 MT |
4227 | exit(1); |
4228 | } | |
ab51b1d5 MT |
4229 | } |
4230 | ||
cfc58cf3 | 4231 | if (nographic) { |
6a5e8b0e GH |
4232 | if (default_parallel) |
4233 | add_device_config(DEV_PARALLEL, "null"); | |
e1c09175 GH |
4234 | if (default_serial && default_monitor) { |
4235 | add_device_config(DEV_SERIAL, "mon:stdio"); | |
4236 | } else { | |
4237 | if (default_serial) | |
4238 | add_device_config(DEV_SERIAL, "stdio"); | |
4239 | if (default_monitor) | |
4821cd4c | 4240 | monitor_parse("stdio", "readline", false); |
e1c09175 | 4241 | } |
998bbd74 GH |
4242 | } else { |
4243 | if (default_serial) | |
4244 | add_device_config(DEV_SERIAL, "vc:80Cx24C"); | |
6a5e8b0e GH |
4245 | if (default_parallel) |
4246 | add_device_config(DEV_PARALLEL, "vc:80Cx24C"); | |
abdeed06 | 4247 | if (default_monitor) |
4821cd4c | 4248 | monitor_parse("vc:80Cx24C", "readline", false); |
bc0129d9 AL |
4249 | } |
4250 | ||
006decd4 GH |
4251 | #if defined(CONFIG_VNC) |
4252 | if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head))) { | |
4253 | display_remote++; | |
4254 | } | |
4255 | #endif | |
e3af9f9a | 4256 | if (dpy.type == DISPLAY_TYPE_DEFAULT && !display_remote) { |
898f9d41 GH |
4257 | if (!qemu_display_find_default(&dpy)) { |
4258 | dpy.type = DISPLAY_TYPE_NONE; | |
4259 | #if defined(CONFIG_VNC) | |
4260 | vnc_parse("localhost:0,to=99,id=default", &error_abort); | |
15546425 | 4261 | #endif |
898f9d41 | 4262 | } |
15546425 | 4263 | } |
db71589f GH |
4264 | if (dpy.type == DISPLAY_TYPE_DEFAULT) { |
4265 | dpy.type = DISPLAY_TYPE_NONE; | |
15546425 AL |
4266 | } |
4267 | ||
09bd7ba9 TH |
4268 | if ((alt_grab || ctrl_grab) && dpy.type != DISPLAY_TYPE_SDL) { |
4269 | error_report("-alt-grab and -ctrl-grab are only valid " | |
f61eddcb | 4270 | "for SDL, ignoring option"); |
047d4e15 | 4271 | } |
78782712 | 4272 | if (dpy.has_window_close && |
e3af9f9a | 4273 | (dpy.type != DISPLAY_TYPE_GTK && dpy.type != DISPLAY_TYPE_SDL)) { |
f61eddcb EH |
4274 | error_report("-no-quit is only valid for GTK and SDL, " |
4275 | "ignoring option"); | |
047d4e15 PW |
4276 | } |
4277 | ||
5ee1718f | 4278 | qemu_display_early_init(&dpy); |
777357d7 MAL |
4279 | qemu_console_early_init(); |
4280 | ||
62f27922 | 4281 | if (dpy.has_gl && dpy.gl != DISPLAYGL_MODE_OFF && display_opengl == 0) { |
0b71a5d5 | 4282 | #if defined(CONFIG_OPENGL) |
8afb9000 | 4283 | error_report("OpenGL is not supported by the display"); |
0b71a5d5 | 4284 | #else |
5dfdae81 | 4285 | error_report("OpenGL support is disabled"); |
0b71a5d5 GH |
4286 | #endif |
4287 | exit(1); | |
4288 | } | |
15546425 | 4289 | |
7e1e0c11 MA |
4290 | qemu_opts_foreach(qemu_find_opts("object"), |
4291 | user_creatable_add_opts_foreach, | |
4292 | object_create_initial, &error_fatal); | |
a4c7367f | 4293 | |
93ab5844 GH |
4294 | /* spice needs the timers to be initialized by this point */ |
4295 | /* spice must initialize before audio as it changes the default auiodev */ | |
4296 | /* spice must initialize before chardevs (for spicevmc and spiceport) */ | |
63be30e6 | 4297 | qemu_spice.init(); |
93ab5844 | 4298 | |
dd4af977 MA |
4299 | qemu_opts_foreach(qemu_find_opts("chardev"), |
4300 | chardev_init_func, NULL, &error_fatal); | |
2c189a4e | 4301 | |
758e8e38 | 4302 | #ifdef CONFIG_VIRTFS |
b836723d MA |
4303 | qemu_opts_foreach(qemu_find_opts("fsdev"), |
4304 | fsdev_init_func, NULL, &error_fatal); | |
74db920c | 4305 | #endif |
1a688d3b | 4306 | |
cda4aa9a | 4307 | /* |
dea1fb88 | 4308 | * Note: we need to create audio and block backends before |
cda4aa9a | 4309 | * machine_set_property(), so machine properties can refer to |
2fa23277 | 4310 | * them. |
cda4aa9a MA |
4311 | */ |
4312 | configure_blockdev(&bdo_queue, machine_class, snapshot); | |
dea1fb88 | 4313 | audio_init_audiodevs(); |
cda4aa9a | 4314 | |
6b1b1440 | 4315 | machine_opts = qemu_get_machine_opts(); |
702832b8 MA |
4316 | qemu_opt_foreach(machine_opts, machine_set_property, current_machine, |
4317 | &error_fatal); | |
622e99c5 IM |
4318 | current_machine->ram_size = ram_size; |
4319 | current_machine->maxram_size = maxram_size; | |
4320 | current_machine->ram_slots = ram_slots; | |
6b1b1440 | 4321 | |
0427b625 MA |
4322 | /* |
4323 | * Note: uses machine properties such as kernel-irqchip, must run | |
4324 | * after machine_set_property(). | |
4325 | */ | |
28a09617 | 4326 | configure_accelerators(argv[0]); |
214910a7 | 4327 | |
0427b625 MA |
4328 | /* |
4329 | * Beware, QOM objects created before this point miss global and | |
4330 | * compat properties. | |
4331 | * | |
4332 | * Global properties get set up by qdev_prop_register_global(), | |
4333 | * called from user_register_global_props(), and certain option | |
4334 | * desugaring. Also in CPU feature desugaring (buried in | |
c1c8cfe5 | 4335 | * parse_cpu_option()), which happens below this point, but may |
0427b625 | 4336 | * only target the CPU type, which can only be created after |
c1c8cfe5 | 4337 | * parse_cpu_option() returned the type. |
0427b625 MA |
4338 | * |
4339 | * Machine compat properties: object_set_machine_compat_props(). | |
4340 | * Accelerator compat props: object_set_accelerator_compat_props(), | |
4341 | * called from configure_accelerator(). | |
4342 | */ | |
4343 | ||
08fe6824 TH |
4344 | if (!qtest_enabled() && machine_class->deprecation_reason) { |
4345 | error_report("Machine type '%s' is deprecated: %s", | |
4346 | machine_class->name, machine_class->deprecation_reason); | |
4347 | } | |
4348 | ||
2fa23277 | 4349 | /* |
0427b625 MA |
4350 | * Note: creates a QOM object, must run only after global and |
4351 | * compat properties have been set up. | |
2fa23277 MA |
4352 | */ |
4353 | migration_object_init(); | |
4354 | ||
2c189a4e | 4355 | if (qtest_chrdev) { |
2b8985f1 | 4356 | qtest_server_init(qtest_chrdev, qtest_log, &error_fatal); |
2c189a4e DB |
4357 | } |
4358 | ||
8281abd5 MA |
4359 | opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL); |
4360 | if (opts) { | |
f05f47bb GA |
4361 | boot_order = qemu_opt_get(opts, "order"); |
4362 | if (boot_order) { | |
007b0657 | 4363 | validate_bootdevices(boot_order, &error_fatal); |
8281abd5 MA |
4364 | } |
4365 | ||
f05f47bb GA |
4366 | boot_once = qemu_opt_get(opts, "once"); |
4367 | if (boot_once) { | |
007b0657 | 4368 | validate_bootdevices(boot_once, &error_fatal); |
8281abd5 MA |
4369 | } |
4370 | ||
4371 | boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu); | |
e5187b56 | 4372 | boot_strict = qemu_opt_get_bool(opts, "strict", false); |
8281abd5 MA |
4373 | } |
4374 | ||
f05f47bb GA |
4375 | if (!boot_order) { |
4376 | boot_order = machine_class->default_boot_order; | |
4377 | } | |
4378 | ||
58c91595 PB |
4379 | if (semihosting_enabled() && !semihosting_get_argc()) { |
4380 | const char *kernel_filename = qemu_opt_get(machine_opts, "kernel"); | |
4381 | const char *kernel_cmdline = qemu_opt_get(machine_opts, "append"); | |
a59d31a1 LA |
4382 | /* fall back to the -kernel/-append */ |
4383 | semihosting_arg_fallback(kernel_filename, kernel_cmdline); | |
4384 | } | |
4385 | ||
d30300f7 EH |
4386 | if (default_net) { |
4387 | QemuOptsList *net = qemu_find_opts("net"); | |
4388 | qemu_opts_set(net, NULL, "type", "nic", &error_abort); | |
4389 | #ifdef CONFIG_SLIRP | |
4390 | qemu_opts_set(net, NULL, "type", "user", &error_abort); | |
4391 | #endif | |
4392 | } | |
4393 | ||
34f708b0 TH |
4394 | if (net_init_clients(&err) < 0) { |
4395 | error_report_err(err); | |
dc1c9fe8 | 4396 | exit(1); |
702c651c | 4397 | } |
f1510b2c | 4398 | |
7e1e0c11 MA |
4399 | qemu_opts_foreach(qemu_find_opts("object"), |
4400 | user_creatable_add_opts_foreach, | |
4401 | object_create_delayed, &error_fatal); | |
9abce56d | 4402 | |
d64072c0 MA |
4403 | if (tpm_init() < 0) { |
4404 | exit(1); | |
4405 | } | |
d1a0cf73 | 4406 | |
2d5a3a8b MA |
4407 | qemu_opts_foreach(qemu_find_opts("mon"), |
4408 | mon_init_func, NULL, &error_fatal); | |
157b9319 | 4409 | |
998bbd74 GH |
4410 | if (foreach_device_config(DEV_SERIAL, serial_parse) < 0) |
4411 | exit(1); | |
6a5e8b0e GH |
4412 | if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) |
4413 | exit(1); | |
c9f398e5 PA |
4414 | if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0) |
4415 | exit(1); | |
2796dae0 | 4416 | |
619985e9 KF |
4417 | /* now chardevs have been created we may have semihosting to connect */ |
4418 | qemu_semihosting_connect_chardevs(); | |
e19c520f | 4419 | qemu_semihosting_console_init(); |
619985e9 | 4420 | |
7f1b17f2 | 4421 | /* If no default VGA is requested, the default is "none". */ |
3605ded5 | 4422 | if (default_vga) { |
dceb8852 | 4423 | vga_model = get_default_vga_model(machine_class); |
a369da5f | 4424 | } |
d44229c5 | 4425 | if (vga_model) { |
dceb8852 | 4426 | select_vgahw(machine_class, vga_model); |
d44229c5 | 4427 | } |
a369da5f | 4428 | |
09aaa160 MA |
4429 | if (watchdog) { |
4430 | i = select_watchdog(watchdog); | |
4431 | if (i > 0) | |
4432 | exit (i == 1 ? 1 : 0); | |
4433 | } | |
4434 | ||
8bd7f71d PD |
4435 | /* This checkpoint is required by replay to separate prior clock |
4436 | reading from the other reads, because timer polling functions query | |
4437 | clock values from the log. */ | |
4438 | replay_checkpoint(CHECKPOINT_INIT); | |
1de81d28 | 4439 | |
3ef96221 | 4440 | current_machine->boot_order = boot_order; |
3ef96221 | 4441 | |
6063d4c0 | 4442 | /* parse features once if machine provides default cpu_type */ |
2278b939 | 4443 | current_machine->cpu_type = machine_class->default_cpu_type; |
c1c8cfe5 EH |
4444 | if (cpu_option) { |
4445 | current_machine->cpu_type = parse_cpu_option(cpu_option); | |
6063d4c0 | 4446 | } |
a1b18df9 | 4447 | |
2a7b18a3 IM |
4448 | if (current_machine->ram_memdev_id) { |
4449 | Object *backend; | |
4450 | ram_addr_t backend_size; | |
4451 | ||
4452 | backend = object_resolve_path_type(current_machine->ram_memdev_id, | |
4453 | TYPE_MEMORY_BACKEND, NULL); | |
4951247d MAL |
4454 | if (!backend) { |
4455 | error_report("Memory backend '%s' not found", | |
4456 | current_machine->ram_memdev_id); | |
4457 | exit(EXIT_FAILURE); | |
4458 | } | |
2a7b18a3 IM |
4459 | backend_size = object_property_get_uint(backend, "size", &error_abort); |
4460 | if (have_custom_ram_size && backend_size != ram_size) { | |
4461 | error_report("Size specified by -m option must match size of " | |
4462 | "explicitly specified 'memory-backend' property"); | |
4463 | exit(EXIT_FAILURE); | |
4464 | } | |
1148e4f4 IM |
4465 | if (mem_path) { |
4466 | error_report("'-mem-path' can't be used together with" | |
4467 | "'-machine memory-backend'"); | |
4468 | exit(EXIT_FAILURE); | |
4469 | } | |
2a7b18a3 IM |
4470 | ram_size = backend_size; |
4471 | } | |
4472 | ||
4473 | if (!xen_enabled()) { | |
4474 | /* On 32-bit hosts, QEMU is limited by virtual address space */ | |
4475 | if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) { | |
4476 | error_report("at most 2047 MB RAM can be simulated"); | |
4477 | exit(1); | |
4478 | } | |
4479 | } | |
4480 | ||
d342eb76 | 4481 | parse_numa_opts(current_machine); |
6063d4c0 | 4482 | |
59d55a16 IM |
4483 | /* do monitor/qmp handling at preconfig state if requested */ |
4484 | qemu_main_loop(); | |
4485 | ||
d8e4de41 PB |
4486 | qemu_init_board(); |
4487 | qemu_create_cli_devices(); | |
4488 | qemu_machine_creation_done(); | |
4cab946a | 4489 | |
bb3d7702 | 4490 | if (loadvm) { |
927d6638 | 4491 | Error *local_err = NULL; |
5e22479a | 4492 | if (load_snapshot(loadvm, &local_err) < 0) { |
927d6638 | 4493 | error_report_err(local_err); |
05f2401e | 4494 | autostart = 0; |
827beacb | 4495 | exit(1); |
05f2401e JQ |
4496 | } |
4497 | } | |
bb3d7702 PD |
4498 | if (replay_mode != REPLAY_MODE_NONE) { |
4499 | replay_vmstate_init(); | |
4500 | } | |
d63d307f | 4501 | |
d828c430 | 4502 | qdev_prop_check_globals(); |
abfd9ce3 AS |
4503 | if (vmstate_dump_file) { |
4504 | /* dump and exit */ | |
4505 | dump_vmstate_json_to_file(vmstate_dump_file); | |
7b733862 | 4506 | exit(0); |
abfd9ce3 | 4507 | } |
2bb8c10c | 4508 | if (incoming) { |
43eaae28 PB |
4509 | Error *local_err = NULL; |
4510 | qemu_start_incoming_migration(incoming, &local_err); | |
4511 | if (local_err) { | |
c29b77f9 | 4512 | error_reportf_err(local_err, "-incoming %s: ", incoming); |
43eaae28 | 4513 | exit(1); |
8ca5e801 | 4514 | } |
6b99dadc | 4515 | } else if (autostart) { |
c0f4ce77 | 4516 | vm_start(); |
6b99dadc | 4517 | } |
ffd843bc | 4518 | |
7a64c17f | 4519 | accel_setup_post(current_machine); |
eb505be1 | 4520 | os_setup_post(); |
71e3ceb8 | 4521 | |
7b733862 AB |
4522 | return; |
4523 | } | |
4486e89c | 4524 | |
7b733862 AB |
4525 | void qemu_cleanup(void) |
4526 | { | |
1bb982b8 KF |
4527 | gdbserver_cleanup(); |
4528 | ||
892ae715 DDAG |
4529 | /* |
4530 | * cleaning up the migration object cancels any existing migration | |
4531 | * try to do this early so that it also stops using devices. | |
4532 | */ | |
4533 | migration_shutdown(); | |
4534 | ||
e6f0ac4d HR |
4535 | /* |
4536 | * We must cancel all block jobs while the block layer is drained, | |
4537 | * or cancelling will be affected by throttling and thus may block | |
4538 | * for an extended period of time. | |
4539 | * vm_shutdown() will bdrv_drain_all(), so we may as well include | |
4540 | * it in the drained section. | |
4541 | * We do not need to end this section, because we do not want any | |
4542 | * requests happening from here on anyway. | |
4543 | */ | |
4544 | bdrv_drain_all_begin(); | |
4545 | ||
4486e89c SH |
4546 | /* No more vcpu or device emulation activity beyond this point */ |
4547 | vm_shutdown(); | |
ae25dccb | 4548 | replay_finish(); |
4486e89c | 4549 | |
b3b5299d | 4550 | job_cancel_sync_all(); |
452589b6 | 4551 | bdrv_close_all(); |
00d09fdb | 4552 | |
3d3b8303 | 4553 | res_free(); |
b46a8906 | 4554 | |
aa5cb7f5 | 4555 | /* vhost-user must be cleaned up before chardevs. */ |
c37cacab | 4556 | tpm_cleanup(); |
8caf911d | 4557 | net_cleanup(); |
a384c205 | 4558 | audio_cleanup(); |
2ef45716 | 4559 | monitor_cleanup(); |
aa5cb7f5 | 4560 | qemu_chr_cleanup(); |
9d5139e5 | 4561 | user_creatable_cleanup(); |
474628e8 | 4562 | /* TODO: unref root container, check all devices are ok */ |
0824d6fc | 4563 | } |