]>
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 | */ |
0824d6fc | 24 | #include <unistd.h> |
0824d6fc FB |
25 | #include <fcntl.h> |
26 | #include <signal.h> | |
27 | #include <time.h> | |
0824d6fc | 28 | #include <errno.h> |
67b915a5 FB |
29 | #include <sys/time.h> |
30 | ||
d40cdb10 BS |
31 | #include "config-host.h" |
32 | ||
452dfbef | 33 | #ifdef CONFIG_SECCOMP |
9c17d615 | 34 | #include "sysemu/seccomp.h" |
452dfbef EO |
35 | #endif |
36 | ||
8a16d273 TS |
37 | #if defined(CONFIG_VDE) |
38 | #include <libvdeplug.h> | |
39 | #endif | |
40 | ||
73332e5c | 41 | #ifdef CONFIG_SDL |
59a36a2f | 42 | #if defined(__APPLE__) || defined(main) |
6693665a | 43 | #include <SDL.h> |
880fec5d | 44 | int qemu_main(int argc, char **argv, char **envp); |
45 | int main(int argc, char **argv) | |
46 | { | |
59a36a2f | 47 | return qemu_main(argc, argv, NULL); |
880fec5d | 48 | } |
49 | #undef main | |
50 | #define main qemu_main | |
96bcd4f8 | 51 | #endif |
73332e5c | 52 | #endif /* CONFIG_SDL */ |
0824d6fc | 53 | |
5b0753e0 FB |
54 | #ifdef CONFIG_COCOA |
55 | #undef main | |
56 | #define main qemu_main | |
57 | #endif /* CONFIG_COCOA */ | |
58 | ||
69e5bb68 AL |
59 | #include <glib.h> |
60 | ||
511d2b14 BS |
61 | #include "hw/hw.h" |
62 | #include "hw/boards.h" | |
63 | #include "hw/usb.h" | |
64 | #include "hw/pcmcia.h" | |
0d09e41a PB |
65 | #include "hw/i386/pc.h" |
66 | #include "hw/isa/isa.h" | |
511d2b14 | 67 | #include "hw/bt.h" |
0d09e41a PB |
68 | #include "sysemu/watchdog.h" |
69 | #include "hw/i386/smbios.h" | |
70 | #include "hw/xen/xen.h" | |
bd3c948d | 71 | #include "hw/qdev.h" |
45a50b16 | 72 | #include "hw/loader.h" |
b4a42f81 | 73 | #include "monitor/qdev.h" |
dccfcd0e | 74 | #include "sysemu/bt.h" |
1422e32d | 75 | #include "net/net.h" |
68ac40d2 | 76 | #include "net/slirp.h" |
83c9089e | 77 | #include "monitor/monitor.h" |
28ecbaee | 78 | #include "ui/console.h" |
9c17d615 | 79 | #include "sysemu/sysemu.h" |
022c62cb | 80 | #include "exec/gdbstub.h" |
1de7afc9 | 81 | #include "qemu/timer.h" |
dccfcd0e | 82 | #include "sysemu/char.h" |
b33276a7 | 83 | #include "qemu/bitmap.h" |
1de7afc9 | 84 | #include "qemu/cache-utils.h" |
9c17d615 | 85 | #include "sysemu/blockdev.h" |
0d09e41a | 86 | #include "hw/block/block.h" |
caf71f86 | 87 | #include "migration/block.h" |
bdee56f5 | 88 | #include "sysemu/tpm.h" |
9c17d615 | 89 | #include "sysemu/dma.h" |
511d2b14 | 90 | #include "audio/audio.h" |
caf71f86 | 91 | #include "migration/migration.h" |
9c17d615 | 92 | #include "sysemu/kvm.h" |
7b1b5d19 | 93 | #include "qapi/qmp/qjson.h" |
1de7afc9 PB |
94 | #include "qemu/option.h" |
95 | #include "qemu/config-file.h" | |
59a5264b | 96 | #include "qemu-options.h" |
1fa9a5e4 | 97 | #include "qmp-commands.h" |
1de7afc9 | 98 | #include "qemu/main-loop.h" |
758e8e38 | 99 | #ifdef CONFIG_VIRTFS |
74db920c GS |
100 | #include "fsdev/qemu-fsdev.h" |
101 | #endif | |
9c17d615 | 102 | #include "sysemu/qtest.h" |
511d2b14 | 103 | |
76cad711 | 104 | #include "disas/disas.h" |
fc01f7e7 | 105 | |
1de7afc9 | 106 | #include "qemu/sockets.h" |
511d2b14 | 107 | |
d918f23e | 108 | #include "slirp/libslirp.h" |
511d2b14 | 109 | |
94b0b5ff | 110 | #include "trace.h" |
e4858974 | 111 | #include "trace/control.h" |
1de7afc9 | 112 | #include "qemu/queue.h" |
9c17d615 PB |
113 | #include "sysemu/cpus.h" |
114 | #include "sysemu/arch_init.h" | |
1de7afc9 | 115 | #include "qemu/osdep.h" |
72cf2d4f | 116 | |
29b0040b | 117 | #include "ui/qemu-spice.h" |
68d98d3e | 118 | #include "qapi/string-input-visitor.h" |
269e09f3 | 119 | #include "qom/object_interfaces.h" |
29b0040b | 120 | |
1bfe856e | 121 | #define DEFAULT_RAM_SIZE 128 |
313aa567 | 122 | |
98b19252 | 123 | #define MAX_VIRTIO_CONSOLES 1 |
3ef669e1 | 124 | #define MAX_SCLP_CONSOLES 1 |
98b19252 | 125 | |
4524051c GH |
126 | static const char *data_dir[16]; |
127 | static int data_dir_idx; | |
1192dad8 | 128 | const char *bios_name = NULL; |
cb5a7aa8 | 129 | enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; |
993fbfdb | 130 | DisplayType display_type = DT_DEFAULT; |
4fdcac0e | 131 | static int display_remote; |
3d11d0eb | 132 | const char* keyboard_layout = NULL; |
c227f099 | 133 | ram_addr_t ram_size; |
c902760f | 134 | const char *mem_path = NULL; |
c902760f | 135 | int mem_prealloc = 0; /* force preallocation of physical target memory */ |
c4b1fcc0 | 136 | int nb_nics; |
7c9d8e07 | 137 | NICInfo nd_table[MAX_NICS]; |
d399f677 | 138 | int autostart; |
f6503059 AZ |
139 | static int rtc_utc = 1; |
140 | static int rtc_date_offset = -1; /* -1 means no change */ | |
884f17c2 | 141 | QEMUClockType rtc_clock; |
64465297 | 142 | int vga_interface_type = VGA_NONE; |
dbed7e40 BS |
143 | static int full_screen = 0; |
144 | static int no_frame = 0; | |
667accab | 145 | int no_quit = 0; |
8d11df9e | 146 | CharDriverState *serial_hds[MAX_SERIAL_PORTS]; |
6508fe59 | 147 | CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; |
9ede2fde | 148 | CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES]; |
3ef669e1 | 149 | CharDriverState *sclp_hds[MAX_SCLP_CONSOLES]; |
a09db21f | 150 | int win2k_install_hack = 0; |
1b530a6d | 151 | int singlestep = 0; |
6a00d601 | 152 | int smp_cpus = 1; |
6be68d7e | 153 | int max_cpus = 0; |
dc6b1c09 AP |
154 | int smp_cores = 1; |
155 | int smp_threads = 1; | |
821601ea | 156 | #ifdef CONFIG_VNC |
73fc9742 | 157 | const char *vnc_display; |
821601ea | 158 | #endif |
6515b203 | 159 | int acpi_enabled = 1; |
16b29ae1 | 160 | int no_hpet = 0; |
52ca8d6a | 161 | int fd_bootchk = 1; |
4fdcac0e | 162 | static int no_reboot; |
b2f76161 | 163 | int no_shutdown = 0; |
9467cd46 | 164 | int cursor_hide = 1; |
a171fe39 | 165 | int graphic_rotate = 0; |
09aaa160 | 166 | const char *watchdog; |
2e55e842 | 167 | QEMUOptionRom option_rom[MAX_OPTION_ROMS]; |
9ae02555 | 168 | int nb_option_roms; |
8e71621f | 169 | int semihosting_enabled = 0; |
2b8f2d41 | 170 | int old_param = 0; |
c35734b2 | 171 | const char *qemu_name; |
3780e197 | 172 | int alt_grab = 0; |
0ca9f8a4 | 173 | int ctrl_grab = 0; |
66508601 BS |
174 | unsigned int nb_prom_envs = 0; |
175 | const char *prom_envs[MAX_PROM_ENVS]; | |
95387491 | 176 | int boot_menu; |
6f2bfda3 | 177 | static bool boot_strict; |
3d3b8303 | 178 | uint8_t *boot_splash_filedata; |
d09acb9b | 179 | size_t boot_splash_filedata_size; |
3d3b8303 | 180 | uint8_t qemu_extra_params_fw[2]; |
0824d6fc | 181 | |
1ca4d09a GN |
182 | typedef struct FWBootEntry FWBootEntry; |
183 | ||
184 | struct FWBootEntry { | |
185 | QTAILQ_ENTRY(FWBootEntry) link; | |
186 | int32_t bootindex; | |
187 | DeviceState *dev; | |
188 | char *suffix; | |
189 | }; | |
190 | ||
4fdcac0e BS |
191 | static QTAILQ_HEAD(, FWBootEntry) fw_boot_order = |
192 | QTAILQ_HEAD_INITIALIZER(fw_boot_order); | |
1ca4d09a | 193 | |
268a362c AL |
194 | int nb_numa_nodes; |
195 | uint64_t node_mem[MAX_NODES]; | |
ee785fed | 196 | unsigned long *node_cpumask[MAX_NODES]; |
268a362c | 197 | |
8fcb1b90 | 198 | uint8_t qemu_uuid[16]; |
fc3b3295 | 199 | bool qemu_uuid_set; |
8fcb1b90 | 200 | |
76e30d0f JK |
201 | static QEMUBootSetHandler *boot_set_handler; |
202 | static void *boot_set_opaque; | |
203 | ||
fd42deeb GH |
204 | static NotifierList exit_notifiers = |
205 | NOTIFIER_LIST_INITIALIZER(exit_notifiers); | |
206 | ||
4cab946a GN |
207 | static NotifierList machine_init_done_notifiers = |
208 | NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers); | |
209 | ||
d5286af5 | 210 | static bool tcg_allowed = true; |
d5286af5 | 211 | bool xen_allowed; |
d745bef8 BS |
212 | uint32_t xen_domid; |
213 | enum xen_mode xen_mode = XEN_EMULATE; | |
d5ab9713 | 214 | static int tcg_tb_size; |
d745bef8 | 215 | |
998bbd74 | 216 | static int default_serial = 1; |
6a5e8b0e | 217 | static int default_parallel = 1; |
986c5f78 | 218 | static int default_virtcon = 1; |
3ef669e1 | 219 | static int default_sclp = 1; |
abdeed06 | 220 | static int default_monitor = 1; |
ac33f8fa GH |
221 | static int default_floppy = 1; |
222 | static int default_cdrom = 1; | |
223 | static int default_sdcard = 1; | |
7f1b17f2 | 224 | static int default_vga = 1; |
998bbd74 GH |
225 | |
226 | static struct { | |
227 | const char *driver; | |
228 | int *flag; | |
229 | } default_list[] = { | |
6a5e8b0e GH |
230 | { .driver = "isa-serial", .flag = &default_serial }, |
231 | { .driver = "isa-parallel", .flag = &default_parallel }, | |
d8bcbabf | 232 | { .driver = "isa-fdc", .flag = &default_floppy }, |
af6bf132 MA |
233 | { .driver = "ide-cd", .flag = &default_cdrom }, |
234 | { .driver = "ide-hd", .flag = &default_cdrom }, | |
d8bcbabf | 235 | { .driver = "ide-drive", .flag = &default_cdrom }, |
af6bf132 | 236 | { .driver = "scsi-cd", .flag = &default_cdrom }, |
392ecf54 AS |
237 | { .driver = "virtio-serial-pci", .flag = &default_virtcon }, |
238 | { .driver = "virtio-serial-s390", .flag = &default_virtcon }, | |
239 | { .driver = "virtio-serial", .flag = &default_virtcon }, | |
7f1b17f2 PB |
240 | { .driver = "VGA", .flag = &default_vga }, |
241 | { .driver = "isa-vga", .flag = &default_vga }, | |
242 | { .driver = "cirrus-vga", .flag = &default_vga }, | |
243 | { .driver = "isa-cirrus-vga", .flag = &default_vga }, | |
244 | { .driver = "vmware-svga", .flag = &default_vga }, | |
245 | { .driver = "qxl-vga", .flag = &default_vga }, | |
998bbd74 GH |
246 | }; |
247 | ||
4d454574 PB |
248 | static QemuOptsList qemu_rtc_opts = { |
249 | .name = "rtc", | |
250 | .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head), | |
251 | .desc = { | |
252 | { | |
253 | .name = "base", | |
254 | .type = QEMU_OPT_STRING, | |
255 | },{ | |
256 | .name = "clock", | |
257 | .type = QEMU_OPT_STRING, | |
258 | },{ | |
259 | .name = "driftfix", | |
260 | .type = QEMU_OPT_STRING, | |
261 | }, | |
262 | { /* end of list */ } | |
263 | }, | |
264 | }; | |
265 | ||
266 | static QemuOptsList qemu_sandbox_opts = { | |
267 | .name = "sandbox", | |
268 | .implied_opt_name = "enable", | |
269 | .head = QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts.head), | |
270 | .desc = { | |
271 | { | |
272 | .name = "enable", | |
273 | .type = QEMU_OPT_BOOL, | |
274 | }, | |
275 | { /* end of list */ } | |
276 | }, | |
277 | }; | |
278 | ||
279 | static QemuOptsList qemu_trace_opts = { | |
280 | .name = "trace", | |
281 | .implied_opt_name = "trace", | |
282 | .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head), | |
283 | .desc = { | |
284 | { | |
285 | .name = "events", | |
286 | .type = QEMU_OPT_STRING, | |
287 | },{ | |
288 | .name = "file", | |
289 | .type = QEMU_OPT_STRING, | |
290 | }, | |
291 | { /* end of list */ } | |
292 | }, | |
293 | }; | |
294 | ||
295 | static QemuOptsList qemu_option_rom_opts = { | |
296 | .name = "option-rom", | |
297 | .implied_opt_name = "romfile", | |
298 | .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head), | |
299 | .desc = { | |
300 | { | |
301 | .name = "bootindex", | |
302 | .type = QEMU_OPT_NUMBER, | |
303 | }, { | |
304 | .name = "romfile", | |
305 | .type = QEMU_OPT_STRING, | |
306 | }, | |
307 | { /* end of list */ } | |
308 | }, | |
309 | }; | |
310 | ||
311 | static QemuOptsList qemu_machine_opts = { | |
312 | .name = "machine", | |
313 | .implied_opt_name = "type", | |
314 | .merge_lists = true, | |
315 | .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head), | |
316 | .desc = { | |
317 | { | |
318 | .name = "type", | |
319 | .type = QEMU_OPT_STRING, | |
320 | .help = "emulated machine" | |
321 | }, { | |
322 | .name = "accel", | |
323 | .type = QEMU_OPT_STRING, | |
324 | .help = "accelerator list", | |
325 | }, { | |
326 | .name = "kernel_irqchip", | |
327 | .type = QEMU_OPT_BOOL, | |
328 | .help = "use KVM in-kernel irqchip", | |
329 | }, { | |
330 | .name = "kvm_shadow_mem", | |
331 | .type = QEMU_OPT_SIZE, | |
332 | .help = "KVM shadow MMU size", | |
333 | }, { | |
334 | .name = "kernel", | |
335 | .type = QEMU_OPT_STRING, | |
336 | .help = "Linux kernel image file", | |
337 | }, { | |
338 | .name = "initrd", | |
339 | .type = QEMU_OPT_STRING, | |
340 | .help = "Linux initial ramdisk file", | |
341 | }, { | |
342 | .name = "append", | |
343 | .type = QEMU_OPT_STRING, | |
344 | .help = "Linux kernel command line", | |
345 | }, { | |
346 | .name = "dtb", | |
347 | .type = QEMU_OPT_STRING, | |
348 | .help = "Linux kernel device tree file", | |
349 | }, { | |
350 | .name = "dumpdtb", | |
351 | .type = QEMU_OPT_STRING, | |
352 | .help = "Dump current dtb to a file and quit", | |
353 | }, { | |
354 | .name = "phandle_start", | |
c1b71b0c | 355 | .type = QEMU_OPT_NUMBER, |
4d454574 PB |
356 | .help = "The first phandle ID we may generate dynamically", |
357 | }, { | |
358 | .name = "dt_compatible", | |
359 | .type = QEMU_OPT_STRING, | |
360 | .help = "Overrides the \"compatible\" property of the dt root node", | |
361 | }, { | |
362 | .name = "dump-guest-core", | |
363 | .type = QEMU_OPT_BOOL, | |
364 | .help = "Include guest memory in a core dump", | |
365 | }, { | |
366 | .name = "mem-merge", | |
367 | .type = QEMU_OPT_BOOL, | |
368 | .help = "enable/disable memory merge support", | |
369 | },{ | |
370 | .name = "usb", | |
371 | .type = QEMU_OPT_BOOL, | |
372 | .help = "Set on/off to enable/disable usb", | |
1442d3e6 GH |
373 | },{ |
374 | .name = "firmware", | |
375 | .type = QEMU_OPT_STRING, | |
376 | .help = "firmware image", | |
135a129a AK |
377 | },{ |
378 | .name = "kvm-type", | |
379 | .type = QEMU_OPT_STRING, | |
380 | .help = "Specifies the KVM virtualization mode (HV, PR)", | |
4d454574 PB |
381 | }, |
382 | { /* End of list */ } | |
383 | }, | |
384 | }; | |
385 | ||
386 | static QemuOptsList qemu_boot_opts = { | |
387 | .name = "boot-opts", | |
6ef4716c MA |
388 | .implied_opt_name = "order", |
389 | .merge_lists = true, | |
4d454574 PB |
390 | .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head), |
391 | .desc = { | |
4d454574 PB |
392 | { |
393 | .name = "order", | |
394 | .type = QEMU_OPT_STRING, | |
395 | }, { | |
396 | .name = "once", | |
397 | .type = QEMU_OPT_STRING, | |
398 | }, { | |
399 | .name = "menu", | |
6ef4716c | 400 | .type = QEMU_OPT_BOOL, |
4d454574 PB |
401 | }, { |
402 | .name = "splash", | |
403 | .type = QEMU_OPT_STRING, | |
404 | }, { | |
405 | .name = "splash-time", | |
406 | .type = QEMU_OPT_STRING, | |
407 | }, { | |
408 | .name = "reboot-timeout", | |
409 | .type = QEMU_OPT_STRING, | |
c8a6ae8b AK |
410 | }, { |
411 | .name = "strict", | |
e5187b56 | 412 | .type = QEMU_OPT_BOOL, |
4d454574 PB |
413 | }, |
414 | { /*End of list */ } | |
415 | }, | |
416 | }; | |
417 | ||
418 | static QemuOptsList qemu_add_fd_opts = { | |
419 | .name = "add-fd", | |
420 | .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head), | |
421 | .desc = { | |
422 | { | |
423 | .name = "fd", | |
424 | .type = QEMU_OPT_NUMBER, | |
425 | .help = "file descriptor of which a duplicate is added to fd set", | |
426 | },{ | |
427 | .name = "set", | |
428 | .type = QEMU_OPT_NUMBER, | |
429 | .help = "ID of the fd set to add fd to", | |
430 | },{ | |
431 | .name = "opaque", | |
432 | .type = QEMU_OPT_STRING, | |
433 | .help = "free-form string used to describe fd", | |
434 | }, | |
435 | { /* end of list */ } | |
436 | }, | |
437 | }; | |
438 | ||
439 | static QemuOptsList qemu_object_opts = { | |
440 | .name = "object", | |
441 | .implied_opt_name = "qom-type", | |
442 | .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head), | |
443 | .desc = { | |
444 | { } | |
445 | }, | |
446 | }; | |
447 | ||
d1a0cf73 SB |
448 | static QemuOptsList qemu_tpmdev_opts = { |
449 | .name = "tpmdev", | |
450 | .implied_opt_name = "type", | |
451 | .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head), | |
452 | .desc = { | |
bb716238 | 453 | /* options are defined in the TPM backends */ |
d1a0cf73 SB |
454 | { /* end of list */ } |
455 | }, | |
456 | }; | |
457 | ||
888a6bc6 SM |
458 | static QemuOptsList qemu_realtime_opts = { |
459 | .name = "realtime", | |
460 | .head = QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts.head), | |
461 | .desc = { | |
462 | { | |
463 | .name = "mlock", | |
464 | .type = QEMU_OPT_BOOL, | |
465 | }, | |
466 | { /* end of list */ } | |
467 | }, | |
468 | }; | |
469 | ||
5e2ac519 SA |
470 | static QemuOptsList qemu_msg_opts = { |
471 | .name = "msg", | |
472 | .head = QTAILQ_HEAD_INITIALIZER(qemu_msg_opts.head), | |
473 | .desc = { | |
474 | { | |
475 | .name = "timestamp", | |
476 | .type = QEMU_OPT_BOOL, | |
477 | }, | |
478 | { /* end of list */ } | |
479 | }, | |
480 | }; | |
481 | ||
5d12f961 DDAG |
482 | static QemuOptsList qemu_name_opts = { |
483 | .name = "name", | |
484 | .implied_opt_name = "guest", | |
485 | .merge_lists = true, | |
486 | .head = QTAILQ_HEAD_INITIALIZER(qemu_name_opts.head), | |
487 | .desc = { | |
488 | { | |
489 | .name = "guest", | |
490 | .type = QEMU_OPT_STRING, | |
491 | .help = "Sets the name of the guest.\n" | |
492 | "This name will be displayed in the SDL window caption.\n" | |
493 | "The name will also be used for the VNC server", | |
494 | }, { | |
495 | .name = "process", | |
496 | .type = QEMU_OPT_STRING, | |
497 | .help = "Sets the name of the QEMU process, as shown in top etc", | |
498 | }, | |
499 | { /* End of list */ } | |
500 | }, | |
501 | }; | |
502 | ||
7f9d6e54 MA |
503 | /** |
504 | * Get machine options | |
505 | * | |
506 | * Returns: machine options (never null). | |
507 | */ | |
508 | QemuOpts *qemu_get_machine_opts(void) | |
509 | { | |
510 | QemuOptsList *list; | |
511 | QemuOpts *opts; | |
512 | ||
513 | list = qemu_find_opts("machine"); | |
514 | assert(list); | |
515 | opts = qemu_opts_find(list, NULL); | |
516 | if (!opts) { | |
87ea75d5 | 517 | opts = qemu_opts_create(list, NULL, 0, &error_abort); |
7f9d6e54 MA |
518 | } |
519 | return opts; | |
520 | } | |
521 | ||
31459f46 RS |
522 | const char *qemu_get_vm_name(void) |
523 | { | |
524 | return qemu_name; | |
525 | } | |
526 | ||
3d3b8303 WX |
527 | static void res_free(void) |
528 | { | |
529 | if (boot_splash_filedata != NULL) { | |
7267c094 | 530 | g_free(boot_splash_filedata); |
3d3b8303 WX |
531 | boot_splash_filedata = NULL; |
532 | } | |
533 | } | |
534 | ||
998bbd74 GH |
535 | static int default_driver_check(QemuOpts *opts, void *opaque) |
536 | { | |
537 | const char *driver = qemu_opt_get(opts, "driver"); | |
538 | int i; | |
539 | ||
540 | if (!driver) | |
541 | return 0; | |
542 | for (i = 0; i < ARRAY_SIZE(default_list); i++) { | |
543 | if (strcmp(default_list[i].driver, driver) != 0) | |
544 | continue; | |
545 | *(default_list[i].flag) = 0; | |
546 | } | |
547 | return 0; | |
548 | } | |
549 | ||
f5bbfba1 LC |
550 | /***********************************************************/ |
551 | /* QEMU state */ | |
552 | ||
0461d5a6 | 553 | static RunState current_run_state = RUN_STATE_PRELAUNCH; |
f5bbfba1 | 554 | |
5db9d4d1 LC |
555 | typedef struct { |
556 | RunState from; | |
557 | RunState to; | |
558 | } RunStateTransition; | |
559 | ||
560 | static const RunStateTransition runstate_transitions_def[] = { | |
561 | /* from -> to */ | |
0461d5a6 | 562 | { RUN_STATE_DEBUG, RUN_STATE_RUNNING }, |
eca01d3a | 563 | { RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE }, |
5db9d4d1 | 564 | |
0461d5a6 | 565 | { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING }, |
29ed72f1 | 566 | { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED }, |
5db9d4d1 | 567 | |
0461d5a6 | 568 | { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED }, |
8a9236f1 | 569 | { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE }, |
5db9d4d1 | 570 | |
0461d5a6 | 571 | { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING }, |
8a9236f1 | 572 | { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE }, |
5db9d4d1 | 573 | |
0461d5a6 | 574 | { RUN_STATE_PAUSED, RUN_STATE_RUNNING }, |
8a9236f1 | 575 | { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE }, |
5db9d4d1 | 576 | |
0461d5a6 | 577 | { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING }, |
8a9236f1 | 578 | { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE }, |
5db9d4d1 | 579 | |
0461d5a6 | 580 | { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING }, |
8a9236f1 | 581 | { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE }, |
0461d5a6 | 582 | { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE }, |
5db9d4d1 | 583 | |
0461d5a6 LC |
584 | { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING }, |
585 | { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE }, | |
5db9d4d1 | 586 | |
0461d5a6 | 587 | { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING }, |
5db9d4d1 | 588 | |
0461d5a6 LC |
589 | { RUN_STATE_RUNNING, RUN_STATE_DEBUG }, |
590 | { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR }, | |
591 | { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR }, | |
592 | { RUN_STATE_RUNNING, RUN_STATE_PAUSED }, | |
593 | { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE }, | |
594 | { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM }, | |
595 | { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM }, | |
596 | { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN }, | |
597 | { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG }, | |
ede085b3 | 598 | { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED }, |
5db9d4d1 | 599 | |
0461d5a6 | 600 | { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING }, |
5db9d4d1 | 601 | |
0461d5a6 | 602 | { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED }, |
8a9236f1 | 603 | { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE }, |
5db9d4d1 | 604 | |
ad02b96a LC |
605 | { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED }, |
606 | { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED }, | |
607 | { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING }, | |
608 | { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE }, | |
609 | ||
0461d5a6 | 610 | { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING }, |
8a9236f1 | 611 | { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE }, |
5db9d4d1 | 612 | |
df390768 | 613 | { RUN_STATE_GUEST_PANICKED, RUN_STATE_RUNNING }, |
fd2a2e1c | 614 | { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE }, |
ede085b3 | 615 | |
0461d5a6 | 616 | { RUN_STATE_MAX, RUN_STATE_MAX }, |
5db9d4d1 LC |
617 | }; |
618 | ||
0461d5a6 LC |
619 | static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX]; |
620 | ||
f5bbfba1 LC |
621 | bool runstate_check(RunState state) |
622 | { | |
623 | return current_run_state == state; | |
624 | } | |
625 | ||
4fdcac0e | 626 | static void runstate_init(void) |
5db9d4d1 LC |
627 | { |
628 | const RunStateTransition *p; | |
629 | ||
630 | memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions)); | |
631 | ||
0461d5a6 | 632 | for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) { |
5db9d4d1 LC |
633 | runstate_valid_transitions[p->from][p->to] = true; |
634 | } | |
635 | } | |
636 | ||
637 | /* This function will abort() on invalid state transitions */ | |
f5bbfba1 LC |
638 | void runstate_set(RunState new_state) |
639 | { | |
207c5cd2 LC |
640 | assert(new_state < RUN_STATE_MAX); |
641 | ||
642 | if (!runstate_valid_transitions[current_run_state][new_state]) { | |
643 | fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n", | |
644 | RunState_lookup[current_run_state], | |
645 | RunState_lookup[new_state]); | |
5db9d4d1 LC |
646 | abort(); |
647 | } | |
7e866003 | 648 | trace_runstate_set(new_state); |
f5bbfba1 LC |
649 | current_run_state = new_state; |
650 | } | |
651 | ||
1fa9a5e4 | 652 | int runstate_is_running(void) |
9e37b9dc | 653 | { |
1fa9a5e4 | 654 | return runstate_check(RUN_STATE_RUNNING); |
9e37b9dc LC |
655 | } |
656 | ||
ede085b3 HT |
657 | bool runstate_needs_reset(void) |
658 | { | |
659 | return runstate_check(RUN_STATE_INTERNAL_ERROR) || | |
df390768 | 660 | runstate_check(RUN_STATE_SHUTDOWN); |
ede085b3 HT |
661 | } |
662 | ||
1fa9a5e4 | 663 | StatusInfo *qmp_query_status(Error **errp) |
1354869c | 664 | { |
1fa9a5e4 LC |
665 | StatusInfo *info = g_malloc0(sizeof(*info)); |
666 | ||
667 | info->running = runstate_is_running(); | |
668 | info->singlestep = singlestep; | |
669 | info->status = current_run_state; | |
670 | ||
671 | return info; | |
1354869c LC |
672 | } |
673 | ||
8f0056b7 PB |
674 | /***********************************************************/ |
675 | /* real time host monotonic timer */ | |
09b26c5e | 676 | |
f6503059 AZ |
677 | /***********************************************************/ |
678 | /* host time/date access */ | |
679 | void qemu_get_timedate(struct tm *tm, int offset) | |
680 | { | |
681 | time_t ti; | |
f6503059 AZ |
682 | |
683 | time(&ti); | |
684 | ti += offset; | |
685 | if (rtc_date_offset == -1) { | |
686 | if (rtc_utc) | |
eb7ff6fb | 687 | gmtime_r(&ti, tm); |
f6503059 | 688 | else |
eb7ff6fb | 689 | localtime_r(&ti, tm); |
f6503059 AZ |
690 | } else { |
691 | ti -= rtc_date_offset; | |
eb7ff6fb | 692 | gmtime_r(&ti, tm); |
f6503059 | 693 | } |
f6503059 AZ |
694 | } |
695 | ||
696 | int qemu_timedate_diff(struct tm *tm) | |
697 | { | |
698 | time_t seconds; | |
699 | ||
700 | if (rtc_date_offset == -1) | |
701 | if (rtc_utc) | |
702 | seconds = mktimegm(tm); | |
f54c556c GN |
703 | else { |
704 | struct tm tmp = *tm; | |
705 | tmp.tm_isdst = -1; /* use timezone to figure it out */ | |
706 | seconds = mktime(&tmp); | |
707 | } | |
f6503059 AZ |
708 | else |
709 | seconds = mktimegm(tm) + rtc_date_offset; | |
710 | ||
711 | return seconds - time(NULL); | |
712 | } | |
713 | ||
80cd3478 LC |
714 | void rtc_change_mon_event(struct tm *tm) |
715 | { | |
716 | QObject *data; | |
717 | ||
718 | data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm)); | |
719 | monitor_protocol_event(QEVENT_RTC_CHANGE, data); | |
720 | qobject_decref(data); | |
721 | } | |
722 | ||
1ed2fc1f JK |
723 | static void configure_rtc_date_offset(const char *startdate, int legacy) |
724 | { | |
725 | time_t rtc_start_date; | |
726 | struct tm tm; | |
727 | ||
728 | if (!strcmp(startdate, "now") && legacy) { | |
729 | rtc_date_offset = -1; | |
730 | } else { | |
731 | if (sscanf(startdate, "%d-%d-%dT%d:%d:%d", | |
732 | &tm.tm_year, | |
733 | &tm.tm_mon, | |
734 | &tm.tm_mday, | |
735 | &tm.tm_hour, | |
736 | &tm.tm_min, | |
737 | &tm.tm_sec) == 6) { | |
738 | /* OK */ | |
739 | } else if (sscanf(startdate, "%d-%d-%d", | |
740 | &tm.tm_year, | |
741 | &tm.tm_mon, | |
742 | &tm.tm_mday) == 3) { | |
743 | tm.tm_hour = 0; | |
744 | tm.tm_min = 0; | |
745 | tm.tm_sec = 0; | |
746 | } else { | |
747 | goto date_fail; | |
748 | } | |
749 | tm.tm_year -= 1900; | |
750 | tm.tm_mon--; | |
751 | rtc_start_date = mktimegm(&tm); | |
752 | if (rtc_start_date == -1) { | |
753 | date_fail: | |
754 | fprintf(stderr, "Invalid date format. Valid formats are:\n" | |
755 | "'2006-06-17T16:01:21' or '2006-06-17'\n"); | |
756 | exit(1); | |
757 | } | |
758 | rtc_date_offset = time(NULL) - rtc_start_date; | |
759 | } | |
760 | } | |
761 | ||
762 | static void configure_rtc(QemuOpts *opts) | |
763 | { | |
764 | const char *value; | |
765 | ||
766 | value = qemu_opt_get(opts, "base"); | |
767 | if (value) { | |
768 | if (!strcmp(value, "utc")) { | |
769 | rtc_utc = 1; | |
770 | } else if (!strcmp(value, "localtime")) { | |
771 | rtc_utc = 0; | |
772 | } else { | |
773 | configure_rtc_date_offset(value, 0); | |
774 | } | |
775 | } | |
6875204c JK |
776 | value = qemu_opt_get(opts, "clock"); |
777 | if (value) { | |
778 | if (!strcmp(value, "host")) { | |
884f17c2 | 779 | rtc_clock = QEMU_CLOCK_HOST; |
78808141 | 780 | } else if (!strcmp(value, "rt")) { |
884f17c2 | 781 | rtc_clock = QEMU_CLOCK_REALTIME; |
6875204c | 782 | } else if (!strcmp(value, "vm")) { |
884f17c2 | 783 | rtc_clock = QEMU_CLOCK_VIRTUAL; |
6875204c JK |
784 | } else { |
785 | fprintf(stderr, "qemu: invalid option value '%s'\n", value); | |
786 | exit(1); | |
787 | } | |
788 | } | |
1ed2fc1f JK |
789 | value = qemu_opt_get(opts, "driftfix"); |
790 | if (value) { | |
7e4c0336 | 791 | if (!strcmp(value, "slew")) { |
433acf0d JK |
792 | static GlobalProperty slew_lost_ticks[] = { |
793 | { | |
794 | .driver = "mc146818rtc", | |
795 | .property = "lost_tick_policy", | |
796 | .value = "slew", | |
797 | }, | |
798 | { /* end of list */ } | |
799 | }; | |
800 | ||
801 | qdev_prop_register_global_list(slew_lost_ticks); | |
7e4c0336 | 802 | } else if (!strcmp(value, "none")) { |
433acf0d | 803 | /* discard is default */ |
1ed2fc1f JK |
804 | } else { |
805 | fprintf(stderr, "qemu: invalid option value '%s'\n", value); | |
806 | exit(1); | |
807 | } | |
808 | } | |
1ed2fc1f JK |
809 | } |
810 | ||
1ae26a18 AZ |
811 | /***********************************************************/ |
812 | /* Bluetooth support */ | |
813 | static int nb_hcis; | |
814 | static int cur_hci; | |
815 | static struct HCIInfo *hci_table[MAX_NICS]; | |
dc72ac14 | 816 | |
1ae26a18 AZ |
817 | struct HCIInfo *qemu_next_hci(void) |
818 | { | |
819 | if (cur_hci == nb_hcis) | |
820 | return &null_hci; | |
821 | ||
822 | return hci_table[cur_hci++]; | |
823 | } | |
824 | ||
dc72ac14 AZ |
825 | static int bt_hci_parse(const char *str) |
826 | { | |
827 | struct HCIInfo *hci; | |
c227f099 | 828 | bdaddr_t bdaddr; |
dc72ac14 AZ |
829 | |
830 | if (nb_hcis >= MAX_NICS) { | |
831 | fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS); | |
832 | return -1; | |
833 | } | |
834 | ||
835 | hci = hci_init(str); | |
836 | if (!hci) | |
837 | return -1; | |
838 | ||
839 | bdaddr.b[0] = 0x52; | |
840 | bdaddr.b[1] = 0x54; | |
841 | bdaddr.b[2] = 0x00; | |
842 | bdaddr.b[3] = 0x12; | |
843 | bdaddr.b[4] = 0x34; | |
844 | bdaddr.b[5] = 0x56 + nb_hcis; | |
845 | hci->bdaddr_set(hci, bdaddr.b); | |
846 | ||
847 | hci_table[nb_hcis++] = hci; | |
848 | ||
849 | return 0; | |
850 | } | |
851 | ||
852 | static void bt_vhci_add(int vlan_id) | |
853 | { | |
854 | struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id); | |
855 | ||
856 | if (!vlan->slave) | |
857 | fprintf(stderr, "qemu: warning: adding a VHCI to " | |
858 | "an empty scatternet %i\n", vlan_id); | |
859 | ||
860 | bt_vhci_init(bt_new_hci(vlan)); | |
861 | } | |
862 | ||
863 | static struct bt_device_s *bt_device_add(const char *opt) | |
864 | { | |
865 | struct bt_scatternet_s *vlan; | |
866 | int vlan_id = 0; | |
867 | char *endp = strstr(opt, ",vlan="); | |
868 | int len = (endp ? endp - opt : strlen(opt)) + 1; | |
869 | char devname[10]; | |
870 | ||
871 | pstrcpy(devname, MIN(sizeof(devname), len), opt); | |
872 | ||
873 | if (endp) { | |
874 | vlan_id = strtol(endp + 6, &endp, 0); | |
875 | if (*endp) { | |
876 | fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n"); | |
877 | return 0; | |
878 | } | |
879 | } | |
880 | ||
881 | vlan = qemu_find_bt_vlan(vlan_id); | |
882 | ||
883 | if (!vlan->slave) | |
884 | fprintf(stderr, "qemu: warning: adding a slave device to " | |
885 | "an empty scatternet %i\n", vlan_id); | |
886 | ||
887 | if (!strcmp(devname, "keyboard")) | |
888 | return bt_keyboard_init(vlan); | |
889 | ||
890 | fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname); | |
891 | return 0; | |
892 | } | |
893 | ||
894 | static int bt_parse(const char *opt) | |
895 | { | |
896 | const char *endp, *p; | |
897 | int vlan; | |
898 | ||
899 | if (strstart(opt, "hci", &endp)) { | |
900 | if (!*endp || *endp == ',') { | |
901 | if (*endp) | |
902 | if (!strstart(endp, ",vlan=", 0)) | |
903 | opt = endp + 1; | |
904 | ||
905 | return bt_hci_parse(opt); | |
906 | } | |
907 | } else if (strstart(opt, "vhci", &endp)) { | |
908 | if (!*endp || *endp == ',') { | |
909 | if (*endp) { | |
910 | if (strstart(endp, ",vlan=", &p)) { | |
911 | vlan = strtol(p, (char **) &endp, 0); | |
912 | if (*endp) { | |
913 | fprintf(stderr, "qemu: bad scatternet '%s'\n", p); | |
914 | return 1; | |
915 | } | |
916 | } else { | |
917 | fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1); | |
918 | return 1; | |
919 | } | |
920 | } else | |
921 | vlan = 0; | |
922 | ||
923 | bt_vhci_add(vlan); | |
924 | return 0; | |
925 | } | |
926 | } else if (strstart(opt, "device:", &endp)) | |
927 | return !bt_device_add(endp); | |
928 | ||
929 | fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt); | |
930 | return 1; | |
931 | } | |
932 | ||
7d76ad4f EO |
933 | static int parse_sandbox(QemuOpts *opts, void *opaque) |
934 | { | |
935 | /* FIXME: change this to true for 1.3 */ | |
936 | if (qemu_opt_get_bool(opts, "enable", false)) { | |
937 | #ifdef CONFIG_SECCOMP | |
938 | if (seccomp_start() < 0) { | |
939 | qerror_report(ERROR_CLASS_GENERIC_ERROR, | |
940 | "failed to install seccomp syscall filter in the kernel"); | |
941 | return -1; | |
942 | } | |
943 | #else | |
944 | qerror_report(ERROR_CLASS_GENERIC_ERROR, | |
945 | "sandboxing request but seccomp is not compiled into this build"); | |
946 | return -1; | |
947 | #endif | |
948 | } | |
949 | ||
950 | return 0; | |
951 | } | |
952 | ||
5d12f961 DDAG |
953 | static void parse_name(QemuOpts *opts) |
954 | { | |
955 | const char *proc_name; | |
956 | ||
957 | qemu_name = qemu_opt_get(opts, "guest"); | |
958 | ||
959 | proc_name = qemu_opt_get(opts, "process"); | |
960 | if (proc_name) { | |
961 | os_set_proc_name(proc_name); | |
962 | } | |
963 | } | |
964 | ||
094b287f LZ |
965 | bool usb_enabled(bool default_usb) |
966 | { | |
2ff3de68 | 967 | return qemu_opt_get_bool(qemu_get_machine_opts(), "usb", default_usb); |
094b287f LZ |
968 | } |
969 | ||
587ed6be CB |
970 | #ifndef _WIN32 |
971 | static int parse_add_fd(QemuOpts *opts, void *opaque) | |
972 | { | |
973 | int fd, dupfd, flags; | |
974 | int64_t fdset_id; | |
975 | const char *fd_opaque = NULL; | |
976 | ||
977 | fd = qemu_opt_get_number(opts, "fd", -1); | |
978 | fdset_id = qemu_opt_get_number(opts, "set", -1); | |
979 | fd_opaque = qemu_opt_get(opts, "opaque"); | |
980 | ||
981 | if (fd < 0) { | |
982 | qerror_report(ERROR_CLASS_GENERIC_ERROR, | |
983 | "fd option is required and must be non-negative"); | |
984 | return -1; | |
985 | } | |
986 | ||
987 | if (fd <= STDERR_FILENO) { | |
988 | qerror_report(ERROR_CLASS_GENERIC_ERROR, | |
989 | "fd cannot be a standard I/O stream"); | |
990 | return -1; | |
991 | } | |
992 | ||
993 | /* | |
994 | * All fds inherited across exec() necessarily have FD_CLOEXEC | |
995 | * clear, while qemu sets FD_CLOEXEC on all other fds used internally. | |
996 | */ | |
997 | flags = fcntl(fd, F_GETFD); | |
998 | if (flags == -1 || (flags & FD_CLOEXEC)) { | |
999 | qerror_report(ERROR_CLASS_GENERIC_ERROR, | |
1000 | "fd is not valid or already in use"); | |
1001 | return -1; | |
1002 | } | |
1003 | ||
1004 | if (fdset_id < 0) { | |
1005 | qerror_report(ERROR_CLASS_GENERIC_ERROR, | |
1006 | "set option is required and must be non-negative"); | |
1007 | return -1; | |
1008 | } | |
1009 | ||
1010 | #ifdef F_DUPFD_CLOEXEC | |
1011 | dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0); | |
1012 | #else | |
1013 | dupfd = dup(fd); | |
1014 | if (dupfd != -1) { | |
1015 | qemu_set_cloexec(dupfd); | |
1016 | } | |
1017 | #endif | |
1018 | if (dupfd == -1) { | |
1019 | qerror_report(ERROR_CLASS_GENERIC_ERROR, | |
1020 | "Error duplicating fd: %s", strerror(errno)); | |
1021 | return -1; | |
1022 | } | |
1023 | ||
1024 | /* add the duplicate fd, and optionally the opaque string, to the fd set */ | |
1025 | monitor_fdset_add_fd(dupfd, true, fdset_id, fd_opaque ? true : false, | |
1026 | fd_opaque, NULL); | |
1027 | ||
1028 | return 0; | |
1029 | } | |
1030 | ||
1031 | static int cleanup_add_fd(QemuOpts *opts, void *opaque) | |
1032 | { | |
1033 | int fd; | |
1034 | ||
1035 | fd = qemu_opt_get_number(opts, "fd", -1); | |
1036 | close(fd); | |
1037 | ||
1038 | return 0; | |
1039 | } | |
1040 | #endif | |
1041 | ||
1ae26a18 AZ |
1042 | /***********************************************************/ |
1043 | /* QEMU Block devices */ | |
1044 | ||
2292ddae MA |
1045 | #define HD_OPTS "media=disk" |
1046 | #define CDROM_OPTS "media=cdrom" | |
1047 | #define FD_OPTS "" | |
1048 | #define PFLASH_OPTS "" | |
1049 | #define MTD_OPTS "" | |
1050 | #define SD_OPTS "" | |
e4bcb14c | 1051 | |
9dfd7c7a GH |
1052 | static int drive_init_func(QemuOpts *opts, void *opaque) |
1053 | { | |
2d0d2837 | 1054 | BlockInterfaceType *block_default_type = opaque; |
9dfd7c7a | 1055 | |
2d0d2837 | 1056 | return drive_init(opts, *block_default_type) == NULL; |
9dfd7c7a GH |
1057 | } |
1058 | ||
1059 | static int drive_enable_snapshot(QemuOpts *opts, void *opaque) | |
1060 | { | |
1061 | if (NULL == qemu_opt_get(opts, "snapshot")) { | |
1062 | qemu_opt_set(opts, "snapshot", "on"); | |
1063 | } | |
1064 | return 0; | |
1065 | } | |
1066 | ||
3c42ea66 CB |
1067 | static void default_drive(int enable, int snapshot, BlockInterfaceType type, |
1068 | int index, const char *optstr) | |
4e5d9b57 MA |
1069 | { |
1070 | QemuOpts *opts; | |
1071 | ||
4e5d9b57 MA |
1072 | if (!enable || drive_get_by_index(type, index)) { |
1073 | return; | |
1074 | } | |
1075 | ||
1076 | opts = drive_add(type, index, NULL, optstr); | |
1077 | if (snapshot) { | |
1078 | drive_enable_snapshot(opts, NULL); | |
1079 | } | |
2d0d2837 | 1080 | if (!drive_init(opts, type)) { |
4e5d9b57 MA |
1081 | exit(1); |
1082 | } | |
1083 | } | |
1084 | ||
76e30d0f JK |
1085 | void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque) |
1086 | { | |
1087 | boot_set_handler = func; | |
1088 | boot_set_opaque = opaque; | |
1089 | } | |
1090 | ||
083b79c9 | 1091 | int qemu_boot_set(const char *boot_order) |
76e30d0f JK |
1092 | { |
1093 | if (!boot_set_handler) { | |
1094 | return -EINVAL; | |
1095 | } | |
083b79c9 | 1096 | return boot_set_handler(boot_set_opaque, boot_order); |
76e30d0f JK |
1097 | } |
1098 | ||
6ef4716c | 1099 | static void validate_bootdevices(const char *devices) |
ef3adf68 JK |
1100 | { |
1101 | /* We just do some generic consistency checks */ | |
1102 | const char *p; | |
1103 | int bitmap = 0; | |
1104 | ||
1105 | for (p = devices; *p != '\0'; p++) { | |
1106 | /* Allowed boot devices are: | |
1107 | * a-b: floppy disk drives | |
1108 | * c-f: IDE disk drives | |
07f35073 | 1109 | * g-m: machine implementation dependent drives |
ef3adf68 JK |
1110 | * n-p: network devices |
1111 | * It's up to each machine implementation to check if the given boot | |
1112 | * devices match the actual hardware implementation and firmware | |
1113 | * features. | |
1114 | */ | |
1115 | if (*p < 'a' || *p > 'p') { | |
1116 | fprintf(stderr, "Invalid boot device '%c'\n", *p); | |
1117 | exit(1); | |
1118 | } | |
1119 | if (bitmap & (1 << (*p - 'a'))) { | |
1120 | fprintf(stderr, "Boot device '%c' was given twice\n", *p); | |
1121 | exit(1); | |
1122 | } | |
1123 | bitmap |= 1 << (*p - 'a'); | |
1124 | } | |
ef3adf68 JK |
1125 | } |
1126 | ||
083b79c9 | 1127 | static void restore_boot_order(void *opaque) |
e0f084bf | 1128 | { |
083b79c9 | 1129 | char *normal_boot_order = opaque; |
37905d6a AW |
1130 | static int first = 1; |
1131 | ||
1132 | /* Restore boot order and remove ourselves after the first boot */ | |
1133 | if (first) { | |
1134 | first = 0; | |
1135 | return; | |
1136 | } | |
e0f084bf | 1137 | |
083b79c9 | 1138 | qemu_boot_set(normal_boot_order); |
e0f084bf | 1139 | |
083b79c9 MA |
1140 | qemu_unregister_reset(restore_boot_order, normal_boot_order); |
1141 | g_free(normal_boot_order); | |
e0f084bf JK |
1142 | } |
1143 | ||
1ca4d09a GN |
1144 | void add_boot_device_path(int32_t bootindex, DeviceState *dev, |
1145 | const char *suffix) | |
1146 | { | |
1147 | FWBootEntry *node, *i; | |
1148 | ||
1149 | if (bootindex < 0) { | |
1150 | return; | |
1151 | } | |
1152 | ||
1153 | assert(dev != NULL || suffix != NULL); | |
1154 | ||
7267c094 | 1155 | node = g_malloc0(sizeof(FWBootEntry)); |
1ca4d09a | 1156 | node->bootindex = bootindex; |
7f303adc | 1157 | node->suffix = g_strdup(suffix); |
1ca4d09a GN |
1158 | node->dev = dev; |
1159 | ||
1160 | QTAILQ_FOREACH(i, &fw_boot_order, link) { | |
1161 | if (i->bootindex == bootindex) { | |
1162 | fprintf(stderr, "Two devices with same boot index %d\n", bootindex); | |
1163 | exit(1); | |
1164 | } else if (i->bootindex < bootindex) { | |
1165 | continue; | |
1166 | } | |
1167 | QTAILQ_INSERT_BEFORE(i, node, link); | |
1168 | return; | |
1169 | } | |
1170 | QTAILQ_INSERT_TAIL(&fw_boot_order, node, link); | |
1171 | } | |
1172 | ||
7dc5af55 DD |
1173 | DeviceState *get_boot_device(uint32_t position) |
1174 | { | |
1175 | uint32_t counter = 0; | |
1176 | FWBootEntry *i = NULL; | |
1177 | DeviceState *res = NULL; | |
1178 | ||
1179 | if (!QTAILQ_EMPTY(&fw_boot_order)) { | |
1180 | QTAILQ_FOREACH(i, &fw_boot_order, link) { | |
1181 | if (counter == position) { | |
1182 | res = i->dev; | |
1183 | break; | |
1184 | } | |
1185 | counter++; | |
1186 | } | |
1187 | } | |
1188 | return res; | |
1189 | } | |
1190 | ||
962630f2 GN |
1191 | /* |
1192 | * This function returns null terminated string that consist of new line | |
71785aba | 1193 | * separated device paths. |
962630f2 GN |
1194 | * |
1195 | * memory pointed by "size" is assigned total length of the array in bytes | |
1196 | * | |
1197 | */ | |
0e7a7592 | 1198 | char *get_boot_devices_list(size_t *size) |
962630f2 GN |
1199 | { |
1200 | FWBootEntry *i; | |
0e7a7592 | 1201 | size_t total = 0; |
962630f2 GN |
1202 | char *list = NULL; |
1203 | ||
1204 | QTAILQ_FOREACH(i, &fw_boot_order, link) { | |
1205 | char *devpath = NULL, *bootpath; | |
0e7a7592 | 1206 | size_t len; |
962630f2 GN |
1207 | |
1208 | if (i->dev) { | |
1209 | devpath = qdev_get_fw_dev_path(i->dev); | |
1210 | assert(devpath); | |
1211 | } | |
1212 | ||
1213 | if (i->suffix && devpath) { | |
4fd37a98 BS |
1214 | size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1; |
1215 | ||
7267c094 | 1216 | bootpath = g_malloc(bootpathlen); |
4fd37a98 | 1217 | snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix); |
7267c094 | 1218 | g_free(devpath); |
962630f2 GN |
1219 | } else if (devpath) { |
1220 | bootpath = devpath; | |
1221 | } else { | |
1bf6ccd3 | 1222 | assert(i->suffix); |
7267c094 | 1223 | bootpath = g_strdup(i->suffix); |
962630f2 GN |
1224 | } |
1225 | ||
1226 | if (total) { | |
1227 | list[total-1] = '\n'; | |
1228 | } | |
1229 | len = strlen(bootpath) + 1; | |
7267c094 | 1230 | list = g_realloc(list, total + len); |
962630f2 GN |
1231 | memcpy(&list[total], bootpath, len); |
1232 | total += len; | |
7267c094 | 1233 | g_free(bootpath); |
962630f2 GN |
1234 | } |
1235 | ||
1236 | *size = total; | |
1237 | ||
c8a6ae8b AK |
1238 | if (boot_strict && *size > 0) { |
1239 | list[total-1] = '\n'; | |
4690579e AK |
1240 | list = g_realloc(list, total + 5); |
1241 | memcpy(&list[total], "HALT", 5); | |
1242 | *size = total + 5; | |
c8a6ae8b | 1243 | } |
962630f2 GN |
1244 | return list; |
1245 | } | |
1246 | ||
845e5bf9 EH |
1247 | static void numa_node_parse_cpus(int nodenr, const char *cpus) |
1248 | { | |
1249 | char *endptr; | |
1250 | unsigned long long value, endvalue; | |
1251 | ||
c881e20e EH |
1252 | /* Empty CPU range strings will be considered valid, they will simply |
1253 | * not set any bit in the CPU bitmap. | |
1254 | */ | |
1255 | if (!*cpus) { | |
1256 | return; | |
1257 | } | |
1258 | ||
1259 | if (parse_uint(cpus, &value, &endptr, 10) < 0) { | |
1260 | goto error; | |
1261 | } | |
845e5bf9 | 1262 | if (*endptr == '-') { |
c881e20e EH |
1263 | if (parse_uint_full(endptr + 1, &endvalue, 10) < 0) { |
1264 | goto error; | |
1265 | } | |
1266 | } else if (*endptr == '\0') { | |
845e5bf9 | 1267 | endvalue = value; |
c881e20e EH |
1268 | } else { |
1269 | goto error; | |
845e5bf9 EH |
1270 | } |
1271 | ||
c881e20e | 1272 | if (endvalue >= MAX_CPUMASK_BITS) { |
845e5bf9 EH |
1273 | endvalue = MAX_CPUMASK_BITS - 1; |
1274 | fprintf(stderr, | |
c881e20e | 1275 | "qemu: NUMA: A max of %d VCPUs are supported\n", |
845e5bf9 EH |
1276 | MAX_CPUMASK_BITS); |
1277 | } | |
1278 | ||
c881e20e EH |
1279 | if (endvalue < value) { |
1280 | goto error; | |
1281 | } | |
1282 | ||
845e5bf9 | 1283 | bitmap_set(node_cpumask[nodenr], value, endvalue-value+1); |
c881e20e EH |
1284 | return; |
1285 | ||
1286 | error: | |
1287 | fprintf(stderr, "qemu: Invalid NUMA CPU range: %s\n", cpus); | |
1288 | exit(1); | |
845e5bf9 EH |
1289 | } |
1290 | ||
268a362c AL |
1291 | static void numa_add(const char *optarg) |
1292 | { | |
1293 | char option[128]; | |
1294 | char *endptr; | |
e4ce85b2 | 1295 | unsigned long long nodenr; |
268a362c | 1296 | |
8f302cb0 EH |
1297 | optarg = get_opt_name(option, 128, optarg, ','); |
1298 | if (*optarg == ',') { | |
1299 | optarg++; | |
1300 | } | |
268a362c | 1301 | if (!strcmp(option, "node")) { |
ca4c6d36 EH |
1302 | |
1303 | if (nb_numa_nodes >= MAX_NODES) { | |
1304 | fprintf(stderr, "qemu: too many NUMA nodes\n"); | |
1305 | exit(1); | |
1306 | } | |
1307 | ||
268a362c AL |
1308 | if (get_param_value(option, 128, "nodeid", optarg) == 0) { |
1309 | nodenr = nb_numa_nodes; | |
1310 | } else { | |
5f139965 EH |
1311 | if (parse_uint_full(option, &nodenr, 10) < 0) { |
1312 | fprintf(stderr, "qemu: Invalid NUMA nodeid: %s\n", option); | |
1313 | exit(1); | |
1314 | } | |
268a362c AL |
1315 | } |
1316 | ||
e4ce85b2 EH |
1317 | if (nodenr >= MAX_NODES) { |
1318 | fprintf(stderr, "qemu: invalid NUMA nodeid: %llu\n", nodenr); | |
1319 | exit(1); | |
1320 | } | |
1321 | ||
268a362c AL |
1322 | if (get_param_value(option, 128, "mem", optarg) == 0) { |
1323 | node_mem[nodenr] = 0; | |
1324 | } else { | |
70b4f4bb | 1325 | int64_t sval; |
c03417b4 MA |
1326 | sval = strtosz(option, &endptr); |
1327 | if (sval < 0 || *endptr) { | |
9f9b17a4 JS |
1328 | fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg); |
1329 | exit(1); | |
268a362c | 1330 | } |
9f9b17a4 | 1331 | node_mem[nodenr] = sval; |
268a362c | 1332 | } |
ee785fed | 1333 | if (get_param_value(option, 128, "cpus", optarg) != 0) { |
845e5bf9 | 1334 | numa_node_parse_cpus(nodenr, option); |
268a362c AL |
1335 | } |
1336 | nb_numa_nodes++; | |
12e53a9d EH |
1337 | } else { |
1338 | fprintf(stderr, "Invalid -numa option: %s\n", option); | |
1339 | exit(1); | |
268a362c | 1340 | } |
268a362c AL |
1341 | } |
1342 | ||
12b7f57e MT |
1343 | static QemuOptsList qemu_smp_opts = { |
1344 | .name = "smp-opts", | |
1345 | .implied_opt_name = "cpus", | |
1346 | .merge_lists = true, | |
1347 | .head = QTAILQ_HEAD_INITIALIZER(qemu_smp_opts.head), | |
1348 | .desc = { | |
1349 | { | |
1350 | .name = "cpus", | |
1351 | .type = QEMU_OPT_NUMBER, | |
1352 | }, { | |
1353 | .name = "sockets", | |
1354 | .type = QEMU_OPT_NUMBER, | |
1355 | }, { | |
1356 | .name = "cores", | |
1357 | .type = QEMU_OPT_NUMBER, | |
1358 | }, { | |
1359 | .name = "threads", | |
1360 | .type = QEMU_OPT_NUMBER, | |
1361 | }, { | |
1362 | .name = "maxcpus", | |
1363 | .type = QEMU_OPT_NUMBER, | |
1364 | }, | |
1365 | { /*End of list */ } | |
1366 | }, | |
1367 | }; | |
1368 | ||
1369 | static void smp_parse(QemuOpts *opts) | |
dc6b1c09 | 1370 | { |
12b7f57e | 1371 | if (opts) { |
dc6b1c09 | 1372 | |
12b7f57e MT |
1373 | unsigned cpus = qemu_opt_get_number(opts, "cpus", 0); |
1374 | unsigned sockets = qemu_opt_get_number(opts, "sockets", 0); | |
1375 | unsigned cores = qemu_opt_get_number(opts, "cores", 0); | |
1376 | unsigned threads = qemu_opt_get_number(opts, "threads", 0); | |
1377 | ||
1378 | /* compute missing values, prefer sockets over cores over threads */ | |
1379 | if (cpus == 0 || sockets == 0) { | |
1380 | sockets = sockets > 0 ? sockets : 1; | |
1381 | cores = cores > 0 ? cores : 1; | |
dc6b1c09 | 1382 | threads = threads > 0 ? threads : 1; |
12b7f57e MT |
1383 | if (cpus == 0) { |
1384 | cpus = cores * threads * sockets; | |
1385 | } | |
dc6b1c09 | 1386 | } else { |
12b7f57e MT |
1387 | if (cores == 0) { |
1388 | threads = threads > 0 ? threads : 1; | |
1389 | cores = cpus / (sockets * threads); | |
1390 | } else { | |
1391 | threads = cpus / (cores * sockets); | |
1392 | } | |
dc6b1c09 | 1393 | } |
12b7f57e MT |
1394 | |
1395 | max_cpus = qemu_opt_get_number(opts, "maxcpus", 0); | |
1396 | ||
1397 | smp_cpus = cpus; | |
1398 | smp_cores = cores > 0 ? cores : 1; | |
1399 | smp_threads = threads > 0 ? threads : 1; | |
1400 | ||
dc6b1c09 | 1401 | } |
12b7f57e MT |
1402 | |
1403 | if (max_cpus == 0) { | |
dc6b1c09 | 1404 | max_cpus = smp_cpus; |
12b7f57e MT |
1405 | } |
1406 | ||
1407 | if (max_cpus > 255) { | |
1408 | fprintf(stderr, "Unsupported number of maxcpus\n"); | |
1409 | exit(1); | |
1410 | } | |
1411 | if (max_cpus < smp_cpus) { | |
1412 | fprintf(stderr, "maxcpus must be equal to or greater than smp\n"); | |
1413 | exit(1); | |
1414 | } | |
1415 | ||
dc6b1c09 AP |
1416 | } |
1417 | ||
888a6bc6 SM |
1418 | static void configure_realtime(QemuOpts *opts) |
1419 | { | |
1420 | bool enable_mlock; | |
1421 | ||
1422 | enable_mlock = qemu_opt_get_bool(opts, "mlock", true); | |
1423 | ||
1424 | if (enable_mlock) { | |
1425 | if (os_mlock() < 0) { | |
1426 | fprintf(stderr, "qemu: locking memory failed\n"); | |
1427 | exit(1); | |
1428 | } | |
1429 | } | |
1430 | } | |
1431 | ||
5e2ac519 SA |
1432 | |
1433 | static void configure_msg(QemuOpts *opts) | |
1434 | { | |
1435 | enable_timestamp_msg = qemu_opt_get_bool(opts, "timestamp", true); | |
1436 | } | |
1437 | ||
a594cfbf FB |
1438 | /***********************************************************/ |
1439 | /* USB devices */ | |
1440 | ||
fb08000c | 1441 | static int usb_device_add(const char *devname) |
a594cfbf | 1442 | { |
a5d2f727 | 1443 | USBDevice *dev = NULL; |
615fe4de MR |
1444 | #ifndef CONFIG_LINUX |
1445 | const char *p; | |
1446 | #endif | |
a594cfbf | 1447 | |
094b287f | 1448 | if (!usb_enabled(false)) { |
a594cfbf | 1449 | return -1; |
094b287f | 1450 | } |
a594cfbf | 1451 | |
0958b4cc GH |
1452 | /* drivers with .usbdevice_name entry in USBDeviceInfo */ |
1453 | dev = usbdevice_create(devname); | |
1454 | if (dev) | |
1455 | goto done; | |
1456 | ||
a5d2f727 | 1457 | /* the other ones */ |
e447fc63 GH |
1458 | #ifndef CONFIG_LINUX |
1459 | /* only the linux version is qdev-ified, usb-bsd still needs this */ | |
a594cfbf | 1460 | if (strstart(devname, "host:", &p)) { |
3741715c | 1461 | dev = usb_host_device_open(usb_bus_find(-1), p); |
a594cfbf | 1462 | } |
615fe4de | 1463 | #endif |
0d92ed30 PB |
1464 | if (!dev) |
1465 | return -1; | |
1466 | ||
a5d2f727 | 1467 | done: |
a594cfbf FB |
1468 | return 0; |
1469 | } | |
1470 | ||
1f3870ab AL |
1471 | static int usb_device_del(const char *devname) |
1472 | { | |
1473 | int bus_num, addr; | |
1474 | const char *p; | |
1475 | ||
1a3973b3 GH |
1476 | if (strstart(devname, "host:", &p)) { |
1477 | return -1; | |
1478 | } | |
5d0c5750 | 1479 | |
094b287f | 1480 | if (!usb_enabled(false)) { |
1f3870ab | 1481 | return -1; |
094b287f | 1482 | } |
1f3870ab AL |
1483 | |
1484 | p = strchr(devname, '.'); | |
1485 | if (!p) | |
1486 | return -1; | |
1487 | bus_num = strtoul(devname, NULL, 0); | |
1488 | addr = strtoul(p + 1, NULL, 0); | |
1489 | ||
a5d2f727 | 1490 | return usb_device_delete_addr(bus_num, addr); |
1f3870ab AL |
1491 | } |
1492 | ||
bd3c948d GH |
1493 | static int usb_parse(const char *cmdline) |
1494 | { | |
59d1c1c2 | 1495 | int r; |
fb08000c | 1496 | r = usb_device_add(cmdline); |
59d1c1c2 ST |
1497 | if (r < 0) { |
1498 | fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline); | |
1499 | } | |
1500 | return r; | |
bd3c948d GH |
1501 | } |
1502 | ||
d54908a5 | 1503 | void do_usb_add(Monitor *mon, const QDict *qdict) |
a594cfbf | 1504 | { |
59d1c1c2 | 1505 | const char *devname = qdict_get_str(qdict, "devname"); |
fb08000c | 1506 | if (usb_device_add(devname) < 0) { |
1ecda02b | 1507 | error_report("could not add USB device '%s'", devname); |
59d1c1c2 | 1508 | } |
a594cfbf FB |
1509 | } |
1510 | ||
d54908a5 | 1511 | void do_usb_del(Monitor *mon, const QDict *qdict) |
a594cfbf | 1512 | { |
59d1c1c2 ST |
1513 | const char *devname = qdict_get_str(qdict, "devname"); |
1514 | if (usb_device_del(devname) < 0) { | |
1ecda02b | 1515 | error_report("could not delete USB device '%s'", devname); |
59d1c1c2 | 1516 | } |
a594cfbf FB |
1517 | } |
1518 | ||
201a51fc AZ |
1519 | /***********************************************************/ |
1520 | /* PCMCIA/Cardbus */ | |
1521 | ||
1522 | static struct pcmcia_socket_entry_s { | |
bc24a225 | 1523 | PCMCIASocket *socket; |
201a51fc AZ |
1524 | struct pcmcia_socket_entry_s *next; |
1525 | } *pcmcia_sockets = 0; | |
1526 | ||
bc24a225 | 1527 | void pcmcia_socket_register(PCMCIASocket *socket) |
201a51fc AZ |
1528 | { |
1529 | struct pcmcia_socket_entry_s *entry; | |
1530 | ||
7267c094 | 1531 | entry = g_malloc(sizeof(struct pcmcia_socket_entry_s)); |
201a51fc AZ |
1532 | entry->socket = socket; |
1533 | entry->next = pcmcia_sockets; | |
1534 | pcmcia_sockets = entry; | |
1535 | } | |
1536 | ||
bc24a225 | 1537 | void pcmcia_socket_unregister(PCMCIASocket *socket) |
201a51fc AZ |
1538 | { |
1539 | struct pcmcia_socket_entry_s *entry, **ptr; | |
1540 | ||
1541 | ptr = &pcmcia_sockets; | |
1542 | for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr) | |
1543 | if (entry->socket == socket) { | |
1544 | *ptr = entry->next; | |
7267c094 | 1545 | g_free(entry); |
201a51fc AZ |
1546 | } |
1547 | } | |
1548 | ||
84f2d0ea | 1549 | void pcmcia_info(Monitor *mon, const QDict *qdict) |
201a51fc AZ |
1550 | { |
1551 | struct pcmcia_socket_entry_s *iter; | |
376253ec | 1552 | |
201a51fc | 1553 | if (!pcmcia_sockets) |
376253ec | 1554 | monitor_printf(mon, "No PCMCIA sockets\n"); |
201a51fc AZ |
1555 | |
1556 | for (iter = pcmcia_sockets; iter; iter = iter->next) | |
376253ec AL |
1557 | monitor_printf(mon, "%s: %s\n", iter->socket->slot_string, |
1558 | iter->socket->attached ? iter->socket->card_string : | |
1559 | "Empty"); | |
201a51fc AZ |
1560 | } |
1561 | ||
cc1daa40 FB |
1562 | /***********************************************************/ |
1563 | /* machine registration */ | |
1564 | ||
bdaf78e0 | 1565 | static QEMUMachine *first_machine = NULL; |
6f338c34 | 1566 | QEMUMachine *current_machine = NULL; |
cc1daa40 FB |
1567 | |
1568 | int qemu_register_machine(QEMUMachine *m) | |
1569 | { | |
1570 | QEMUMachine **pm; | |
1571 | pm = &first_machine; | |
1572 | while (*pm != NULL) | |
1573 | pm = &(*pm)->next; | |
1574 | m->next = NULL; | |
1575 | *pm = m; | |
1576 | return 0; | |
1577 | } | |
1578 | ||
9596ebb7 | 1579 | static QEMUMachine *find_machine(const char *name) |
cc1daa40 FB |
1580 | { |
1581 | QEMUMachine *m; | |
1582 | ||
1583 | for(m = first_machine; m != NULL; m = m->next) { | |
1584 | if (!strcmp(m->name, name)) | |
1585 | return m; | |
3f6599e6 MM |
1586 | if (m->alias && !strcmp(m->alias, name)) |
1587 | return m; | |
cc1daa40 FB |
1588 | } |
1589 | return NULL; | |
1590 | } | |
1591 | ||
2c8cffa5 | 1592 | QEMUMachine *find_default_machine(void) |
0c257437 AL |
1593 | { |
1594 | QEMUMachine *m; | |
1595 | ||
1596 | for(m = first_machine; m != NULL; m = m->next) { | |
1597 | if (m->is_default) { | |
1598 | return m; | |
1599 | } | |
1600 | } | |
1601 | return NULL; | |
1602 | } | |
1603 | ||
01d3c80d AL |
1604 | MachineInfoList *qmp_query_machines(Error **errp) |
1605 | { | |
1606 | MachineInfoList *mach_list = NULL; | |
1607 | QEMUMachine *m; | |
1608 | ||
1609 | for (m = first_machine; m; m = m->next) { | |
1610 | MachineInfoList *entry; | |
1611 | MachineInfo *info; | |
1612 | ||
1613 | info = g_malloc0(sizeof(*info)); | |
1614 | if (m->is_default) { | |
1615 | info->has_is_default = true; | |
1616 | info->is_default = true; | |
1617 | } | |
1618 | ||
1619 | if (m->alias) { | |
1620 | info->has_alias = true; | |
1621 | info->alias = g_strdup(m->alias); | |
1622 | } | |
1623 | ||
1624 | info->name = g_strdup(m->name); | |
c72e7688 | 1625 | info->cpu_max = !m->max_cpus ? 1 : m->max_cpus; |
01d3c80d AL |
1626 | |
1627 | entry = g_malloc0(sizeof(*entry)); | |
1628 | entry->value = info; | |
1629 | entry->next = mach_list; | |
1630 | mach_list = entry; | |
1631 | } | |
1632 | ||
1633 | return mach_list; | |
1634 | } | |
1635 | ||
8a7ddc38 FB |
1636 | /***********************************************************/ |
1637 | /* main execution loop */ | |
1638 | ||
0bd48850 FB |
1639 | struct vm_change_state_entry { |
1640 | VMChangeStateHandler *cb; | |
1641 | void *opaque; | |
72cf2d4f | 1642 | QLIST_ENTRY (vm_change_state_entry) entries; |
0bd48850 FB |
1643 | }; |
1644 | ||
72cf2d4f | 1645 | static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head; |
0bd48850 FB |
1646 | |
1647 | VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, | |
1648 | void *opaque) | |
1649 | { | |
1650 | VMChangeStateEntry *e; | |
1651 | ||
7267c094 | 1652 | e = g_malloc0(sizeof (*e)); |
0bd48850 FB |
1653 | |
1654 | e->cb = cb; | |
1655 | e->opaque = opaque; | |
72cf2d4f | 1656 | QLIST_INSERT_HEAD(&vm_change_state_head, e, entries); |
0bd48850 FB |
1657 | return e; |
1658 | } | |
1659 | ||
1660 | void qemu_del_vm_change_state_handler(VMChangeStateEntry *e) | |
1661 | { | |
72cf2d4f | 1662 | QLIST_REMOVE (e, entries); |
7267c094 | 1663 | g_free (e); |
0bd48850 FB |
1664 | } |
1665 | ||
1dfb4dd9 | 1666 | void vm_state_notify(int running, RunState state) |
0bd48850 FB |
1667 | { |
1668 | VMChangeStateEntry *e; | |
1669 | ||
1dfb4dd9 | 1670 | trace_vm_state_notify(running, state); |
94b0b5ff | 1671 | |
0bd48850 | 1672 | for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) { |
1dfb4dd9 | 1673 | e->cb(e->opaque, running, state); |
0bd48850 FB |
1674 | } |
1675 | } | |
1676 | ||
8a7ddc38 FB |
1677 | void vm_start(void) |
1678 | { | |
1354869c | 1679 | if (!runstate_is_running()) { |
8a7ddc38 | 1680 | cpu_enable_ticks(); |
0461d5a6 LC |
1681 | runstate_set(RUN_STATE_RUNNING); |
1682 | vm_state_notify(1, RUN_STATE_RUNNING); | |
d6dc3d42 | 1683 | resume_all_vcpus(); |
6ed2c484 | 1684 | monitor_protocol_event(QEVENT_RESUME, NULL); |
8a7ddc38 FB |
1685 | } |
1686 | } | |
1687 | ||
bb0c6722 FB |
1688 | /* reset/shutdown handler */ |
1689 | ||
1690 | typedef struct QEMUResetEntry { | |
72cf2d4f | 1691 | QTAILQ_ENTRY(QEMUResetEntry) entry; |
bb0c6722 FB |
1692 | QEMUResetHandler *func; |
1693 | void *opaque; | |
bb0c6722 FB |
1694 | } QEMUResetEntry; |
1695 | ||
72cf2d4f BS |
1696 | static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers = |
1697 | QTAILQ_HEAD_INITIALIZER(reset_handlers); | |
bb0c6722 | 1698 | static int reset_requested; |
f64622c4 GN |
1699 | static int shutdown_requested, shutdown_signal = -1; |
1700 | static pid_t shutdown_pid; | |
3475187d | 1701 | static int powerdown_requested; |
8cf71710 | 1702 | static int debug_requested; |
95b363b5 | 1703 | static int suspend_requested; |
4bc78a87 | 1704 | static WakeupReason wakeup_reason; |
a9552c8e IM |
1705 | static NotifierList powerdown_notifiers = |
1706 | NOTIFIER_LIST_INITIALIZER(powerdown_notifiers); | |
95b363b5 GH |
1707 | static NotifierList suspend_notifiers = |
1708 | NOTIFIER_LIST_INITIALIZER(suspend_notifiers); | |
1709 | static NotifierList wakeup_notifiers = | |
1710 | NOTIFIER_LIST_INITIALIZER(wakeup_notifiers); | |
4bc78a87 | 1711 | static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE); |
0461d5a6 | 1712 | static RunState vmstop_requested = RUN_STATE_MAX; |
bb0c6722 | 1713 | |
1291eb35 AP |
1714 | int qemu_shutdown_requested_get(void) |
1715 | { | |
1716 | return shutdown_requested; | |
1717 | } | |
1718 | ||
1719 | int qemu_reset_requested_get(void) | |
1720 | { | |
1721 | return reset_requested; | |
1722 | } | |
1723 | ||
4fdcac0e | 1724 | static int qemu_shutdown_requested(void) |
cf7a2fe2 AJ |
1725 | { |
1726 | int r = shutdown_requested; | |
1727 | shutdown_requested = 0; | |
1728 | return r; | |
1729 | } | |
1730 | ||
4fdcac0e | 1731 | static void qemu_kill_report(void) |
f64622c4 | 1732 | { |
35b30712 | 1733 | if (!qtest_driver() && shutdown_signal != -1) { |
f1d3fb04 PM |
1734 | fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal); |
1735 | if (shutdown_pid == 0) { | |
1736 | /* This happens for eg ^C at the terminal, so it's worth | |
1737 | * avoiding printing an odd message in that case. | |
1738 | */ | |
1739 | fputc('\n', stderr); | |
1740 | } else { | |
953ffe0f | 1741 | fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid); |
f1d3fb04 | 1742 | } |
f64622c4 GN |
1743 | shutdown_signal = -1; |
1744 | } | |
1745 | } | |
1746 | ||
4fdcac0e | 1747 | static int qemu_reset_requested(void) |
cf7a2fe2 AJ |
1748 | { |
1749 | int r = reset_requested; | |
1750 | reset_requested = 0; | |
1751 | return r; | |
1752 | } | |
1753 | ||
95b363b5 GH |
1754 | static int qemu_suspend_requested(void) |
1755 | { | |
1756 | int r = suspend_requested; | |
1757 | suspend_requested = 0; | |
1758 | return r; | |
1759 | } | |
1760 | ||
4bc78a87 | 1761 | static WakeupReason qemu_wakeup_requested(void) |
14058196 | 1762 | { |
4bc78a87 | 1763 | return wakeup_reason; |
14058196 LC |
1764 | } |
1765 | ||
4fdcac0e | 1766 | static int qemu_powerdown_requested(void) |
cf7a2fe2 AJ |
1767 | { |
1768 | int r = powerdown_requested; | |
1769 | powerdown_requested = 0; | |
1770 | return r; | |
1771 | } | |
1772 | ||
e568902a AL |
1773 | static int qemu_debug_requested(void) |
1774 | { | |
1775 | int r = debug_requested; | |
1776 | debug_requested = 0; | |
1777 | return r; | |
1778 | } | |
1779 | ||
0461d5a6 | 1780 | /* We use RUN_STATE_MAX but any invalid value will do */ |
0d45b702 | 1781 | static bool qemu_vmstop_requested(RunState *r) |
6e29f5da | 1782 | { |
0461d5a6 | 1783 | if (vmstop_requested < RUN_STATE_MAX) { |
0d45b702 | 1784 | *r = vmstop_requested; |
0461d5a6 | 1785 | vmstop_requested = RUN_STATE_MAX; |
0d45b702 LC |
1786 | return true; |
1787 | } | |
1788 | ||
1789 | return false; | |
6e29f5da AL |
1790 | } |
1791 | ||
a08d4367 | 1792 | void qemu_register_reset(QEMUResetHandler *func, void *opaque) |
bb0c6722 | 1793 | { |
7267c094 | 1794 | QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry)); |
bb0c6722 | 1795 | |
bb0c6722 FB |
1796 | re->func = func; |
1797 | re->opaque = opaque; | |
72cf2d4f | 1798 | QTAILQ_INSERT_TAIL(&reset_handlers, re, entry); |
bb0c6722 FB |
1799 | } |
1800 | ||
dda9b29f | 1801 | void qemu_unregister_reset(QEMUResetHandler *func, void *opaque) |
bb0c6722 FB |
1802 | { |
1803 | QEMUResetEntry *re; | |
1804 | ||
72cf2d4f | 1805 | QTAILQ_FOREACH(re, &reset_handlers, entry) { |
dda9b29f | 1806 | if (re->func == func && re->opaque == opaque) { |
72cf2d4f | 1807 | QTAILQ_REMOVE(&reset_handlers, re, entry); |
7267c094 | 1808 | g_free(re); |
dda9b29f JK |
1809 | return; |
1810 | } | |
1811 | } | |
1812 | } | |
1813 | ||
be522029 | 1814 | void qemu_devices_reset(void) |
dda9b29f JK |
1815 | { |
1816 | QEMUResetEntry *re, *nre; | |
1817 | ||
1818 | /* reset all devices */ | |
72cf2d4f | 1819 | QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) { |
bb0c6722 FB |
1820 | re->func(re->opaque); |
1821 | } | |
be522029 DG |
1822 | } |
1823 | ||
1824 | void qemu_system_reset(bool report) | |
1825 | { | |
1826 | if (current_machine && current_machine->reset) { | |
1827 | current_machine->reset(); | |
1828 | } else { | |
1829 | qemu_devices_reset(); | |
1830 | } | |
e063eb1f JK |
1831 | if (report) { |
1832 | monitor_protocol_event(QEVENT_RESET, NULL); | |
1833 | } | |
ea375f9a | 1834 | cpu_synchronize_all_post_reset(); |
bb0c6722 FB |
1835 | } |
1836 | ||
1837 | void qemu_system_reset_request(void) | |
1838 | { | |
d1beab82 FB |
1839 | if (no_reboot) { |
1840 | shutdown_requested = 1; | |
1841 | } else { | |
1842 | reset_requested = 1; | |
1843 | } | |
b4a3d965 | 1844 | cpu_stop_current(); |
d9f75a4e | 1845 | qemu_notify_event(); |
bb0c6722 FB |
1846 | } |
1847 | ||
95b363b5 GH |
1848 | static void qemu_system_suspend(void) |
1849 | { | |
1850 | pause_all_vcpus(); | |
1851 | notifier_list_notify(&suspend_notifiers, NULL); | |
ad02b96a | 1852 | runstate_set(RUN_STATE_SUSPENDED); |
53370b78 | 1853 | monitor_protocol_event(QEVENT_SUSPEND, NULL); |
95b363b5 GH |
1854 | } |
1855 | ||
1856 | void qemu_system_suspend_request(void) | |
1857 | { | |
9abc62f6 | 1858 | if (runstate_check(RUN_STATE_SUSPENDED)) { |
95b363b5 GH |
1859 | return; |
1860 | } | |
1861 | suspend_requested = 1; | |
1862 | cpu_stop_current(); | |
1863 | qemu_notify_event(); | |
1864 | } | |
1865 | ||
1866 | void qemu_register_suspend_notifier(Notifier *notifier) | |
1867 | { | |
1868 | notifier_list_add(&suspend_notifiers, notifier); | |
1869 | } | |
1870 | ||
1871 | void qemu_system_wakeup_request(WakeupReason reason) | |
1872 | { | |
9abc62f6 | 1873 | if (!runstate_check(RUN_STATE_SUSPENDED)) { |
95b363b5 GH |
1874 | return; |
1875 | } | |
1876 | if (!(wakeup_reason_mask & (1 << reason))) { | |
1877 | return; | |
1878 | } | |
ad02b96a | 1879 | runstate_set(RUN_STATE_RUNNING); |
4bc78a87 | 1880 | wakeup_reason = reason; |
95b363b5 | 1881 | qemu_notify_event(); |
95b363b5 GH |
1882 | } |
1883 | ||
1884 | void qemu_system_wakeup_enable(WakeupReason reason, bool enabled) | |
1885 | { | |
1886 | if (enabled) { | |
1887 | wakeup_reason_mask |= (1 << reason); | |
1888 | } else { | |
1889 | wakeup_reason_mask &= ~(1 << reason); | |
1890 | } | |
1891 | } | |
1892 | ||
1893 | void qemu_register_wakeup_notifier(Notifier *notifier) | |
1894 | { | |
1895 | notifier_list_add(&wakeup_notifiers, notifier); | |
1896 | } | |
1897 | ||
f64622c4 GN |
1898 | void qemu_system_killed(int signal, pid_t pid) |
1899 | { | |
1900 | shutdown_signal = signal; | |
1901 | shutdown_pid = pid; | |
d9389b96 | 1902 | no_shutdown = 0; |
f64622c4 GN |
1903 | qemu_system_shutdown_request(); |
1904 | } | |
1905 | ||
bb0c6722 FB |
1906 | void qemu_system_shutdown_request(void) |
1907 | { | |
1908 | shutdown_requested = 1; | |
d9f75a4e | 1909 | qemu_notify_event(); |
bb0c6722 FB |
1910 | } |
1911 | ||
013c2f15 IM |
1912 | static void qemu_system_powerdown(void) |
1913 | { | |
1914 | monitor_protocol_event(QEVENT_POWERDOWN, NULL); | |
1915 | notifier_list_notify(&powerdown_notifiers, NULL); | |
1916 | } | |
1917 | ||
3475187d FB |
1918 | void qemu_system_powerdown_request(void) |
1919 | { | |
1920 | powerdown_requested = 1; | |
d9f75a4e AL |
1921 | qemu_notify_event(); |
1922 | } | |
1923 | ||
a9552c8e IM |
1924 | void qemu_register_powerdown_notifier(Notifier *notifier) |
1925 | { | |
1926 | notifier_list_add(&powerdown_notifiers, notifier); | |
1927 | } | |
1928 | ||
8cf71710 JK |
1929 | void qemu_system_debug_request(void) |
1930 | { | |
1931 | debug_requested = 1; | |
83f338f7 | 1932 | qemu_notify_event(); |
8cf71710 JK |
1933 | } |
1934 | ||
1dfb4dd9 | 1935 | void qemu_system_vmstop_request(RunState state) |
8cf71710 | 1936 | { |
1dfb4dd9 | 1937 | vmstop_requested = state; |
8cf71710 JK |
1938 | qemu_notify_event(); |
1939 | } | |
1940 | ||
99435906 PB |
1941 | static bool main_loop_should_exit(void) |
1942 | { | |
1943 | RunState r; | |
1944 | if (qemu_debug_requested()) { | |
1945 | vm_stop(RUN_STATE_DEBUG); | |
1946 | } | |
95b363b5 GH |
1947 | if (qemu_suspend_requested()) { |
1948 | qemu_system_suspend(); | |
1949 | } | |
99435906 PB |
1950 | if (qemu_shutdown_requested()) { |
1951 | qemu_kill_report(); | |
1952 | monitor_protocol_event(QEVENT_SHUTDOWN, NULL); | |
1953 | if (no_shutdown) { | |
1954 | vm_stop(RUN_STATE_SHUTDOWN); | |
1955 | } else { | |
1956 | return true; | |
1957 | } | |
1958 | } | |
1959 | if (qemu_reset_requested()) { | |
1960 | pause_all_vcpus(); | |
1961 | cpu_synchronize_all_states(); | |
1962 | qemu_system_reset(VMRESET_REPORT); | |
1963 | resume_all_vcpus(); | |
ede085b3 | 1964 | if (runstate_needs_reset()) { |
99435906 PB |
1965 | runstate_set(RUN_STATE_PAUSED); |
1966 | } | |
1967 | } | |
14058196 LC |
1968 | if (qemu_wakeup_requested()) { |
1969 | pause_all_vcpus(); | |
1970 | cpu_synchronize_all_states(); | |
1971 | qemu_system_reset(VMRESET_SILENT); | |
4bc78a87 LJ |
1972 | notifier_list_notify(&wakeup_notifiers, &wakeup_reason); |
1973 | wakeup_reason = QEMU_WAKEUP_REASON_NONE; | |
14058196 | 1974 | resume_all_vcpus(); |
17c8660b | 1975 | monitor_protocol_event(QEVENT_WAKEUP, NULL); |
14058196 | 1976 | } |
99435906 | 1977 | if (qemu_powerdown_requested()) { |
013c2f15 | 1978 | qemu_system_powerdown(); |
99435906 PB |
1979 | } |
1980 | if (qemu_vmstop_requested(&r)) { | |
1981 | vm_stop(r); | |
1982 | } | |
1983 | return false; | |
1984 | } | |
1985 | ||
43b96858 AL |
1986 | static void main_loop(void) |
1987 | { | |
c9f711a5 | 1988 | bool nonblocking; |
99435906 | 1989 | int last_io = 0; |
8e1b90ec JK |
1990 | #ifdef CONFIG_PROFILER |
1991 | int64_t ti; | |
1992 | #endif | |
99435906 | 1993 | do { |
a7d4207d | 1994 | nonblocking = !kvm_enabled() && !xen_enabled() && last_io > 0; |
89bfc105 | 1995 | #ifdef CONFIG_PROFILER |
46481d39 | 1996 | ti = profile_getclock(); |
89bfc105 | 1997 | #endif |
c9f711a5 | 1998 | last_io = main_loop_wait(nonblocking); |
89bfc105 | 1999 | #ifdef CONFIG_PROFILER |
46481d39 | 2000 | dev_time += profile_getclock() - ti; |
89bfc105 | 2001 | #endif |
99435906 | 2002 | } while (!main_loop_should_exit()); |
b4608c04 FB |
2003 | } |
2004 | ||
9bd7e6d9 PB |
2005 | static void version(void) |
2006 | { | |
f75ca1ae | 2007 | printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n"); |
9bd7e6d9 PB |
2008 | } |
2009 | ||
15f82208 | 2010 | static void help(int exitcode) |
0824d6fc | 2011 | { |
a3adb7ad ME |
2012 | version(); |
2013 | printf("usage: %s [options] [disk_image]\n\n" | |
2014 | "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n", | |
2015 | error_get_progname()); | |
2016 | ||
77bd1119 ME |
2017 | #define QEMU_OPTIONS_GENERATE_HELP |
2018 | #include "qemu-options-wrapper.h" | |
a3adb7ad ME |
2019 | |
2020 | printf("\nDuring emulation, the following keys are useful:\n" | |
3f020d70 | 2021 | "ctrl-alt-f toggle full screen\n" |
2022 | "ctrl-alt-n switch to virtual console 'n'\n" | |
2023 | "ctrl-alt toggle mouse and keyboard grab\n" | |
2024 | "\n" | |
a3adb7ad ME |
2025 | "When using -nographic, press 'ctrl-a h' to get some help.\n"); |
2026 | ||
15f82208 | 2027 | exit(exitcode); |
0824d6fc FB |
2028 | } |
2029 | ||
cd6f1169 FB |
2030 | #define HAS_ARG 0x0001 |
2031 | ||
cd6f1169 FB |
2032 | typedef struct QEMUOption { |
2033 | const char *name; | |
2034 | int flags; | |
2035 | int index; | |
ad96090a | 2036 | uint32_t arch_mask; |
cd6f1169 FB |
2037 | } QEMUOption; |
2038 | ||
dbed7e40 | 2039 | static const QEMUOption qemu_options[] = { |
ad96090a | 2040 | { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL }, |
77bd1119 ME |
2041 | #define QEMU_OPTIONS_GENERATE_OPTIONS |
2042 | #include "qemu-options-wrapper.h" | |
cd6f1169 | 2043 | { NULL }, |
fc01f7e7 | 2044 | }; |
a369da5f BS |
2045 | |
2046 | static bool vga_available(void) | |
2047 | { | |
36b7f27d | 2048 | return object_class_by_name("VGA") || object_class_by_name("isa-vga"); |
a369da5f BS |
2049 | } |
2050 | ||
2051 | static bool cirrus_vga_available(void) | |
2052 | { | |
36b7f27d AJ |
2053 | return object_class_by_name("cirrus-vga") |
2054 | || object_class_by_name("isa-cirrus-vga"); | |
a369da5f BS |
2055 | } |
2056 | ||
2057 | static bool vmware_vga_available(void) | |
2058 | { | |
36b7f27d | 2059 | return object_class_by_name("vmware-svga"); |
a369da5f BS |
2060 | } |
2061 | ||
879049a3 AJ |
2062 | static bool qxl_vga_available(void) |
2063 | { | |
2064 | return object_class_by_name("qxl-vga"); | |
2065 | } | |
2066 | ||
af87bf29 MCA |
2067 | static bool tcx_vga_available(void) |
2068 | { | |
2069 | return object_class_by_name("SUNW,tcx"); | |
2070 | } | |
2071 | ||
2072 | static bool cg3_vga_available(void) | |
2073 | { | |
2074 | return object_class_by_name("cgthree"); | |
2075 | } | |
2076 | ||
3893c124 | 2077 | static void select_vgahw (const char *p) |
2078 | { | |
2079 | const char *opts; | |
2080 | ||
86176759 | 2081 | vga_interface_type = VGA_NONE; |
3893c124 | 2082 | if (strstart(p, "std", &opts)) { |
a369da5f BS |
2083 | if (vga_available()) { |
2084 | vga_interface_type = VGA_STD; | |
2085 | } else { | |
2086 | fprintf(stderr, "Error: standard VGA not available\n"); | |
2087 | exit(0); | |
2088 | } | |
3893c124 | 2089 | } else if (strstart(p, "cirrus", &opts)) { |
a369da5f BS |
2090 | if (cirrus_vga_available()) { |
2091 | vga_interface_type = VGA_CIRRUS; | |
2092 | } else { | |
2093 | fprintf(stderr, "Error: Cirrus VGA not available\n"); | |
2094 | exit(0); | |
2095 | } | |
3893c124 | 2096 | } else if (strstart(p, "vmware", &opts)) { |
a369da5f BS |
2097 | if (vmware_vga_available()) { |
2098 | vga_interface_type = VGA_VMWARE; | |
2099 | } else { | |
2100 | fprintf(stderr, "Error: VMWare SVGA not available\n"); | |
2101 | exit(0); | |
2102 | } | |
94909d9f | 2103 | } else if (strstart(p, "xenfb", &opts)) { |
86176759 | 2104 | vga_interface_type = VGA_XENFB; |
a19cbfb3 | 2105 | } else if (strstart(p, "qxl", &opts)) { |
879049a3 AJ |
2106 | if (qxl_vga_available()) { |
2107 | vga_interface_type = VGA_QXL; | |
2108 | } else { | |
2109 | fprintf(stderr, "Error: QXL VGA not available\n"); | |
2110 | exit(0); | |
2111 | } | |
af87bf29 MCA |
2112 | } else if (strstart(p, "tcx", &opts)) { |
2113 | if (tcx_vga_available()) { | |
2114 | vga_interface_type = VGA_TCX; | |
2115 | } else { | |
2116 | fprintf(stderr, "Error: TCX framebuffer not available\n"); | |
2117 | exit(0); | |
2118 | } | |
2119 | } else if (strstart(p, "cg3", &opts)) { | |
2120 | if (cg3_vga_available()) { | |
2121 | vga_interface_type = VGA_CG3; | |
2122 | } else { | |
2123 | fprintf(stderr, "Error: CG3 framebuffer not available\n"); | |
2124 | exit(0); | |
2125 | } | |
28b85ed8 | 2126 | } else if (!strstart(p, "none", &opts)) { |
3893c124 | 2127 | invalid_vga: |
2128 | fprintf(stderr, "Unknown vga type: %s\n", p); | |
2129 | exit(1); | |
2130 | } | |
cb5a7aa8 | 2131 | while (*opts) { |
2132 | const char *nextopt; | |
2133 | ||
2134 | if (strstart(opts, ",retrace=", &nextopt)) { | |
2135 | opts = nextopt; | |
2136 | if (strstart(opts, "dumb", &nextopt)) | |
2137 | vga_retrace_method = VGA_RETRACE_DUMB; | |
2138 | else if (strstart(opts, "precise", &nextopt)) | |
2139 | vga_retrace_method = VGA_RETRACE_PRECISE; | |
2140 | else goto invalid_vga; | |
2141 | } else goto invalid_vga; | |
2142 | opts = nextopt; | |
2143 | } | |
3893c124 | 2144 | } |
2145 | ||
1472a95b JS |
2146 | static DisplayType select_display(const char *p) |
2147 | { | |
2148 | const char *opts; | |
2149 | DisplayType display = DT_DEFAULT; | |
2150 | ||
2151 | if (strstart(p, "sdl", &opts)) { | |
2152 | #ifdef CONFIG_SDL | |
2153 | display = DT_SDL; | |
2154 | while (*opts) { | |
2155 | const char *nextopt; | |
2156 | ||
2157 | if (strstart(opts, ",frame=", &nextopt)) { | |
2158 | opts = nextopt; | |
2159 | if (strstart(opts, "on", &nextopt)) { | |
2160 | no_frame = 0; | |
2161 | } else if (strstart(opts, "off", &nextopt)) { | |
2162 | no_frame = 1; | |
2163 | } else { | |
05175535 | 2164 | goto invalid_sdl_args; |
1472a95b JS |
2165 | } |
2166 | } else if (strstart(opts, ",alt_grab=", &nextopt)) { | |
2167 | opts = nextopt; | |
2168 | if (strstart(opts, "on", &nextopt)) { | |
2169 | alt_grab = 1; | |
2170 | } else if (strstart(opts, "off", &nextopt)) { | |
2171 | alt_grab = 0; | |
2172 | } else { | |
05175535 | 2173 | goto invalid_sdl_args; |
1472a95b JS |
2174 | } |
2175 | } else if (strstart(opts, ",ctrl_grab=", &nextopt)) { | |
2176 | opts = nextopt; | |
2177 | if (strstart(opts, "on", &nextopt)) { | |
2178 | ctrl_grab = 1; | |
2179 | } else if (strstart(opts, "off", &nextopt)) { | |
2180 | ctrl_grab = 0; | |
2181 | } else { | |
05175535 | 2182 | goto invalid_sdl_args; |
1472a95b JS |
2183 | } |
2184 | } else if (strstart(opts, ",window_close=", &nextopt)) { | |
2185 | opts = nextopt; | |
2186 | if (strstart(opts, "on", &nextopt)) { | |
2187 | no_quit = 0; | |
2188 | } else if (strstart(opts, "off", &nextopt)) { | |
2189 | no_quit = 1; | |
2190 | } else { | |
05175535 | 2191 | goto invalid_sdl_args; |
1472a95b JS |
2192 | } |
2193 | } else { | |
05175535 PM |
2194 | invalid_sdl_args: |
2195 | fprintf(stderr, "Invalid SDL option string: %s\n", p); | |
2196 | exit(1); | |
1472a95b JS |
2197 | } |
2198 | opts = nextopt; | |
2199 | } | |
2200 | #else | |
2201 | fprintf(stderr, "SDL support is disabled\n"); | |
2202 | exit(1); | |
2203 | #endif | |
3264ff12 | 2204 | } else if (strstart(p, "vnc", &opts)) { |
821601ea | 2205 | #ifdef CONFIG_VNC |
3264ff12 JS |
2206 | display_remote++; |
2207 | ||
2208 | if (*opts) { | |
2209 | const char *nextopt; | |
2210 | ||
2211 | if (strstart(opts, "=", &nextopt)) { | |
2212 | vnc_display = nextopt; | |
2213 | } | |
2214 | } | |
2215 | if (!vnc_display) { | |
2216 | fprintf(stderr, "VNC requires a display argument vnc=<display>\n"); | |
2217 | exit(1); | |
2218 | } | |
821601ea JS |
2219 | #else |
2220 | fprintf(stderr, "VNC support is disabled\n"); | |
2221 | exit(1); | |
2222 | #endif | |
1472a95b JS |
2223 | } else if (strstart(p, "curses", &opts)) { |
2224 | #ifdef CONFIG_CURSES | |
2225 | display = DT_CURSES; | |
2226 | #else | |
2227 | fprintf(stderr, "Curses support is disabled\n"); | |
2228 | exit(1); | |
15546425 AL |
2229 | #endif |
2230 | } else if (strstart(p, "gtk", &opts)) { | |
2231 | #ifdef CONFIG_GTK | |
2232 | display = DT_GTK; | |
2233 | #else | |
2234 | fprintf(stderr, "GTK support is disabled\n"); | |
2235 | exit(1); | |
1472a95b | 2236 | #endif |
4171d32e JS |
2237 | } else if (strstart(p, "none", &opts)) { |
2238 | display = DT_NONE; | |
1472a95b | 2239 | } else { |
1472a95b JS |
2240 | fprintf(stderr, "Unknown display type: %s\n", p); |
2241 | exit(1); | |
2242 | } | |
2243 | ||
2244 | return display; | |
2245 | } | |
2246 | ||
7d4c3d53 MA |
2247 | static int balloon_parse(const char *arg) |
2248 | { | |
382f0743 | 2249 | QemuOpts *opts; |
7d4c3d53 | 2250 | |
382f0743 GH |
2251 | if (strcmp(arg, "none") == 0) { |
2252 | return 0; | |
2253 | } | |
2254 | ||
2255 | if (!strncmp(arg, "virtio", 6)) { | |
2256 | if (arg[6] == ',') { | |
2257 | /* have params -> parse them */ | |
3329f07b | 2258 | opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0); |
382f0743 GH |
2259 | if (!opts) |
2260 | return -1; | |
2261 | } else { | |
2262 | /* create empty opts */ | |
87ea75d5 PC |
2263 | opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, |
2264 | &error_abort); | |
7d4c3d53 | 2265 | } |
29f82b37 | 2266 | qemu_opt_set(opts, "driver", "virtio-balloon"); |
382f0743 | 2267 | return 0; |
7d4c3d53 | 2268 | } |
382f0743 GH |
2269 | |
2270 | return -1; | |
7d4c3d53 | 2271 | } |
7d4c3d53 | 2272 | |
5cea8590 PB |
2273 | char *qemu_find_file(int type, const char *name) |
2274 | { | |
4524051c | 2275 | int i; |
5cea8590 PB |
2276 | const char *subdir; |
2277 | char *buf; | |
2278 | ||
31783203 PM |
2279 | /* Try the name as a straight path first */ |
2280 | if (access(name, R_OK) == 0) { | |
4524051c | 2281 | trace_load_file(name, name); |
7267c094 | 2282 | return g_strdup(name); |
5cea8590 | 2283 | } |
4524051c | 2284 | |
5cea8590 PB |
2285 | switch (type) { |
2286 | case QEMU_FILE_TYPE_BIOS: | |
2287 | subdir = ""; | |
2288 | break; | |
2289 | case QEMU_FILE_TYPE_KEYMAP: | |
2290 | subdir = "keymaps/"; | |
2291 | break; | |
2292 | default: | |
2293 | abort(); | |
2294 | } | |
4524051c GH |
2295 | |
2296 | for (i = 0; i < data_dir_idx; i++) { | |
2297 | buf = g_strdup_printf("%s/%s%s", data_dir[i], subdir, name); | |
2298 | if (access(buf, R_OK) == 0) { | |
2299 | trace_load_file(name, buf); | |
2300 | return buf; | |
2301 | } | |
7267c094 | 2302 | g_free(buf); |
5cea8590 | 2303 | } |
4524051c | 2304 | return NULL; |
5cea8590 PB |
2305 | } |
2306 | ||
ff952ba2 MA |
2307 | static int device_help_func(QemuOpts *opts, void *opaque) |
2308 | { | |
2309 | return qdev_device_help(opts); | |
2310 | } | |
2311 | ||
f31d07d1 GH |
2312 | static int device_init_func(QemuOpts *opts, void *opaque) |
2313 | { | |
2314 | DeviceState *dev; | |
2315 | ||
2316 | dev = qdev_device_add(opts); | |
2317 | if (!dev) | |
2318 | return -1; | |
b09995ae | 2319 | object_unref(OBJECT(dev)); |
f31d07d1 GH |
2320 | return 0; |
2321 | } | |
2322 | ||
1a688d3b GH |
2323 | static int chardev_init_func(QemuOpts *opts, void *opaque) |
2324 | { | |
bd2d80b2 | 2325 | Error *local_err = NULL; |
1a688d3b | 2326 | |
bd2d80b2 | 2327 | qemu_chr_new_from_opts(opts, NULL, &local_err); |
84d18f06 | 2328 | if (local_err) { |
4a44d85e | 2329 | error_report("%s", error_get_pretty(local_err)); |
bd2d80b2 | 2330 | error_free(local_err); |
1a688d3b | 2331 | return -1; |
bd2d80b2 | 2332 | } |
1a688d3b GH |
2333 | return 0; |
2334 | } | |
2335 | ||
758e8e38 | 2336 | #ifdef CONFIG_VIRTFS |
74db920c GS |
2337 | static int fsdev_init_func(QemuOpts *opts, void *opaque) |
2338 | { | |
2339 | int ret; | |
2340 | ret = qemu_fsdev_add(opts); | |
2341 | ||
2342 | return ret; | |
2343 | } | |
2344 | #endif | |
2345 | ||
88589343 GH |
2346 | static int mon_init_func(QemuOpts *opts, void *opaque) |
2347 | { | |
2348 | CharDriverState *chr; | |
2349 | const char *chardev; | |
2350 | const char *mode; | |
2351 | int flags; | |
2352 | ||
2353 | mode = qemu_opt_get(opts, "mode"); | |
2354 | if (mode == NULL) { | |
2355 | mode = "readline"; | |
2356 | } | |
2357 | if (strcmp(mode, "readline") == 0) { | |
2358 | flags = MONITOR_USE_READLINE; | |
2359 | } else if (strcmp(mode, "control") == 0) { | |
2360 | flags = MONITOR_USE_CONTROL; | |
2361 | } else { | |
2362 | fprintf(stderr, "unknown monitor mode \"%s\"\n", mode); | |
2363 | exit(1); | |
2364 | } | |
2365 | ||
39eaab9a DB |
2366 | if (qemu_opt_get_bool(opts, "pretty", 0)) |
2367 | flags |= MONITOR_USE_PRETTY; | |
2368 | ||
88589343 GH |
2369 | if (qemu_opt_get_bool(opts, "default", 0)) |
2370 | flags |= MONITOR_IS_DEFAULT; | |
2371 | ||
2372 | chardev = qemu_opt_get(opts, "chardev"); | |
2373 | chr = qemu_chr_find(chardev); | |
2374 | if (chr == NULL) { | |
2375 | fprintf(stderr, "chardev \"%s\" not found\n", chardev); | |
2376 | exit(1); | |
2377 | } | |
2378 | ||
456d6069 | 2379 | qemu_chr_fe_claim_no_fail(chr); |
88589343 GH |
2380 | monitor_init(chr, flags); |
2381 | return 0; | |
2382 | } | |
2383 | ||
6ca5582d | 2384 | static void monitor_parse(const char *optarg, const char *mode) |
88589343 GH |
2385 | { |
2386 | static int monitor_device_index = 0; | |
2387 | QemuOpts *opts; | |
2388 | const char *p; | |
2389 | char label[32]; | |
2390 | int def = 0; | |
2391 | ||
2392 | if (strstart(optarg, "chardev:", &p)) { | |
2393 | snprintf(label, sizeof(label), "%s", p); | |
2394 | } else { | |
140e065d JK |
2395 | snprintf(label, sizeof(label), "compat_monitor%d", |
2396 | monitor_device_index); | |
2397 | if (monitor_device_index == 0) { | |
88589343 GH |
2398 | def = 1; |
2399 | } | |
2400 | opts = qemu_chr_parse_compat(label, optarg); | |
2401 | if (!opts) { | |
2402 | fprintf(stderr, "parse error: %s\n", optarg); | |
2403 | exit(1); | |
2404 | } | |
2405 | } | |
2406 | ||
8be7e7e4 | 2407 | opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, NULL); |
88589343 GH |
2408 | if (!opts) { |
2409 | fprintf(stderr, "duplicate chardev: %s\n", label); | |
2410 | exit(1); | |
2411 | } | |
6ca5582d | 2412 | qemu_opt_set(opts, "mode", mode); |
88589343 GH |
2413 | qemu_opt_set(opts, "chardev", label); |
2414 | if (def) | |
2415 | qemu_opt_set(opts, "default", "on"); | |
2416 | monitor_device_index++; | |
2417 | } | |
2418 | ||
bd3c948d GH |
2419 | struct device_config { |
2420 | enum { | |
aee1b935 GH |
2421 | DEV_USB, /* -usbdevice */ |
2422 | DEV_BT, /* -bt */ | |
2423 | DEV_SERIAL, /* -serial */ | |
2424 | DEV_PARALLEL, /* -parallel */ | |
2425 | DEV_VIRTCON, /* -virtioconsole */ | |
c9f398e5 | 2426 | DEV_DEBUGCON, /* -debugcon */ |
ef0c4a0d | 2427 | DEV_GDB, /* -gdb, -s */ |
3ef669e1 | 2428 | DEV_SCLP, /* s390 sclp */ |
bd3c948d GH |
2429 | } type; |
2430 | const char *cmdline; | |
d9a5954d | 2431 | Location loc; |
72cf2d4f | 2432 | QTAILQ_ENTRY(device_config) next; |
bd3c948d | 2433 | }; |
4fdcac0e BS |
2434 | |
2435 | static QTAILQ_HEAD(, device_config) device_configs = | |
2436 | QTAILQ_HEAD_INITIALIZER(device_configs); | |
bd3c948d GH |
2437 | |
2438 | static void add_device_config(int type, const char *cmdline) | |
2439 | { | |
2440 | struct device_config *conf; | |
2441 | ||
7267c094 | 2442 | conf = g_malloc0(sizeof(*conf)); |
bd3c948d GH |
2443 | conf->type = type; |
2444 | conf->cmdline = cmdline; | |
d9a5954d | 2445 | loc_save(&conf->loc); |
72cf2d4f | 2446 | QTAILQ_INSERT_TAIL(&device_configs, conf, next); |
bd3c948d GH |
2447 | } |
2448 | ||
2449 | static int foreach_device_config(int type, int (*func)(const char *cmdline)) | |
2450 | { | |
2451 | struct device_config *conf; | |
2452 | int rc; | |
2453 | ||
72cf2d4f | 2454 | QTAILQ_FOREACH(conf, &device_configs, next) { |
bd3c948d GH |
2455 | if (conf->type != type) |
2456 | continue; | |
d9a5954d | 2457 | loc_push_restore(&conf->loc); |
bd3c948d | 2458 | rc = func(conf->cmdline); |
d9a5954d | 2459 | loc_pop(&conf->loc); |
bd3c948d GH |
2460 | if (0 != rc) |
2461 | return rc; | |
2462 | } | |
2463 | return 0; | |
2464 | } | |
2465 | ||
998bbd74 GH |
2466 | static int serial_parse(const char *devname) |
2467 | { | |
2468 | static int index = 0; | |
2469 | char label[32]; | |
2470 | ||
2471 | if (strcmp(devname, "none") == 0) | |
2472 | return 0; | |
2473 | if (index == MAX_SERIAL_PORTS) { | |
2474 | fprintf(stderr, "qemu: too many serial ports\n"); | |
2475 | exit(1); | |
2476 | } | |
2477 | snprintf(label, sizeof(label), "serial%d", index); | |
27143a44 | 2478 | serial_hds[index] = qemu_chr_new(label, devname, NULL); |
998bbd74 | 2479 | if (!serial_hds[index]) { |
52d06136 PM |
2480 | fprintf(stderr, "qemu: could not connect serial device" |
2481 | " to character backend '%s'\n", devname); | |
998bbd74 GH |
2482 | return -1; |
2483 | } | |
2484 | index++; | |
2485 | return 0; | |
2486 | } | |
2487 | ||
6a5e8b0e GH |
2488 | static int parallel_parse(const char *devname) |
2489 | { | |
2490 | static int index = 0; | |
2491 | char label[32]; | |
2492 | ||
2493 | if (strcmp(devname, "none") == 0) | |
2494 | return 0; | |
2495 | if (index == MAX_PARALLEL_PORTS) { | |
2496 | fprintf(stderr, "qemu: too many parallel ports\n"); | |
2497 | exit(1); | |
2498 | } | |
2499 | snprintf(label, sizeof(label), "parallel%d", index); | |
27143a44 | 2500 | parallel_hds[index] = qemu_chr_new(label, devname, NULL); |
6a5e8b0e | 2501 | if (!parallel_hds[index]) { |
52d06136 PM |
2502 | fprintf(stderr, "qemu: could not connect parallel device" |
2503 | " to character backend '%s'\n", devname); | |
6a5e8b0e GH |
2504 | return -1; |
2505 | } | |
2506 | index++; | |
2507 | return 0; | |
2508 | } | |
2509 | ||
aee1b935 GH |
2510 | static int virtcon_parse(const char *devname) |
2511 | { | |
3329f07b | 2512 | QemuOptsList *device = qemu_find_opts("device"); |
aee1b935 GH |
2513 | static int index = 0; |
2514 | char label[32]; | |
392ecf54 | 2515 | QemuOpts *bus_opts, *dev_opts; |
aee1b935 GH |
2516 | |
2517 | if (strcmp(devname, "none") == 0) | |
2518 | return 0; | |
2519 | if (index == MAX_VIRTIO_CONSOLES) { | |
2520 | fprintf(stderr, "qemu: too many virtio consoles\n"); | |
2521 | exit(1); | |
2522 | } | |
392ecf54 | 2523 | |
87ea75d5 | 2524 | bus_opts = qemu_opts_create(device, NULL, 0, &error_abort); |
e87f7fc6 AL |
2525 | if (arch_type == QEMU_ARCH_S390X) { |
2526 | qemu_opt_set(bus_opts, "driver", "virtio-serial-s390"); | |
2527 | } else { | |
2528 | qemu_opt_set(bus_opts, "driver", "virtio-serial-pci"); | |
4d8b3c63 | 2529 | } |
392ecf54 | 2530 | |
87ea75d5 | 2531 | dev_opts = qemu_opts_create(device, NULL, 0, &error_abort); |
392ecf54 AS |
2532 | qemu_opt_set(dev_opts, "driver", "virtconsole"); |
2533 | ||
aee1b935 | 2534 | snprintf(label, sizeof(label), "virtcon%d", index); |
27143a44 | 2535 | virtcon_hds[index] = qemu_chr_new(label, devname, NULL); |
aee1b935 | 2536 | if (!virtcon_hds[index]) { |
52d06136 PM |
2537 | fprintf(stderr, "qemu: could not connect virtio console" |
2538 | " to character backend '%s'\n", devname); | |
aee1b935 GH |
2539 | return -1; |
2540 | } | |
392ecf54 AS |
2541 | qemu_opt_set(dev_opts, "chardev", label); |
2542 | ||
aee1b935 GH |
2543 | index++; |
2544 | return 0; | |
2545 | } | |
2546 | ||
3ef669e1 AG |
2547 | static int sclp_parse(const char *devname) |
2548 | { | |
2549 | QemuOptsList *device = qemu_find_opts("device"); | |
2550 | static int index = 0; | |
2551 | char label[32]; | |
2552 | QemuOpts *dev_opts; | |
2553 | ||
2554 | if (strcmp(devname, "none") == 0) { | |
2555 | return 0; | |
2556 | } | |
2557 | if (index == MAX_SCLP_CONSOLES) { | |
2558 | fprintf(stderr, "qemu: too many sclp consoles\n"); | |
2559 | exit(1); | |
2560 | } | |
2561 | ||
2562 | assert(arch_type == QEMU_ARCH_S390X); | |
2563 | ||
2564 | dev_opts = qemu_opts_create(device, NULL, 0, NULL); | |
2565 | qemu_opt_set(dev_opts, "driver", "sclpconsole"); | |
2566 | ||
2567 | snprintf(label, sizeof(label), "sclpcon%d", index); | |
2568 | sclp_hds[index] = qemu_chr_new(label, devname, NULL); | |
2569 | if (!sclp_hds[index]) { | |
2570 | fprintf(stderr, "qemu: could not connect sclp console" | |
2571 | " to character backend '%s'\n", devname); | |
2572 | return -1; | |
2573 | } | |
2574 | qemu_opt_set(dev_opts, "chardev", label); | |
2575 | ||
2576 | index++; | |
2577 | return 0; | |
2578 | } | |
2579 | ||
c9f398e5 | 2580 | static int debugcon_parse(const char *devname) |
4d8b3c63 | 2581 | { |
c9f398e5 PA |
2582 | QemuOpts *opts; |
2583 | ||
27143a44 | 2584 | if (!qemu_chr_new("debugcon", devname, NULL)) { |
c9f398e5 PA |
2585 | exit(1); |
2586 | } | |
8be7e7e4 | 2587 | opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL); |
c9f398e5 PA |
2588 | if (!opts) { |
2589 | fprintf(stderr, "qemu: already have a debugcon device\n"); | |
2590 | exit(1); | |
2591 | } | |
2592 | qemu_opt_set(opts, "driver", "isa-debugcon"); | |
2593 | qemu_opt_set(opts, "chardev", "debugcon"); | |
2594 | return 0; | |
2595 | } | |
2596 | ||
9052ea6b JK |
2597 | static QEMUMachine *machine_parse(const char *name) |
2598 | { | |
2599 | QEMUMachine *m, *machine = NULL; | |
2600 | ||
2601 | if (name) { | |
2602 | machine = find_machine(name); | |
2603 | } | |
2604 | if (machine) { | |
2605 | return machine; | |
2606 | } | |
2607 | printf("Supported machines are:\n"); | |
2608 | for (m = first_machine; m != NULL; m = m->next) { | |
2609 | if (m->alias) { | |
3b26486a | 2610 | printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name); |
9052ea6b | 2611 | } |
3b26486a | 2612 | printf("%-20s %s%s\n", m->name, m->desc, |
9052ea6b JK |
2613 | m->is_default ? " (default)" : ""); |
2614 | } | |
c8057f95 | 2615 | exit(!name || !is_help_option(name)); |
9052ea6b JK |
2616 | } |
2617 | ||
135a129a | 2618 | static int tcg_init(QEMUMachine *machine) |
303d4e86 | 2619 | { |
d5ab9713 | 2620 | tcg_exec_init(tcg_tb_size * 1024 * 1024); |
303d4e86 AP |
2621 | return 0; |
2622 | } | |
2623 | ||
2624 | static struct { | |
2625 | const char *opt_name; | |
2626 | const char *name; | |
2627 | int (*available)(void); | |
135a129a | 2628 | int (*init)(QEMUMachine *); |
d5286af5 | 2629 | bool *allowed; |
303d4e86 AP |
2630 | } accel_list[] = { |
2631 | { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed }, | |
3285cf4f | 2632 | { "xen", "Xen", xen_available, xen_init, &xen_allowed }, |
303d4e86 | 2633 | { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed }, |
d4fce24f | 2634 | { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed }, |
303d4e86 AP |
2635 | }; |
2636 | ||
135a129a | 2637 | static int configure_accelerator(QEMUMachine *machine) |
303d4e86 | 2638 | { |
36ad0e94 | 2639 | const char *p; |
303d4e86 AP |
2640 | char buf[10]; |
2641 | int i, ret; | |
217e21be LG |
2642 | bool accel_initialised = false; |
2643 | bool init_failed = false; | |
303d4e86 | 2644 | |
36ad0e94 | 2645 | p = qemu_opt_get(qemu_get_machine_opts(), "accel"); |
303d4e86 AP |
2646 | if (p == NULL) { |
2647 | /* Use the default "accelerator", tcg */ | |
2648 | p = "tcg"; | |
2649 | } | |
2650 | ||
1b785a97 | 2651 | while (!accel_initialised && *p != '\0') { |
303d4e86 AP |
2652 | if (*p == ':') { |
2653 | p++; | |
2654 | } | |
2655 | p = get_opt_name(buf, sizeof (buf), p, ':'); | |
2656 | for (i = 0; i < ARRAY_SIZE(accel_list); i++) { | |
2657 | if (strcmp(accel_list[i].opt_name, buf) == 0) { | |
e3c66d93 LG |
2658 | if (!accel_list[i].available()) { |
2659 | printf("%s not supported for this target\n", | |
2660 | accel_list[i].name); | |
2661 | continue; | |
2662 | } | |
d5286af5 | 2663 | *(accel_list[i].allowed) = true; |
135a129a | 2664 | ret = accel_list[i].init(machine); |
303d4e86 | 2665 | if (ret < 0) { |
217e21be | 2666 | init_failed = true; |
e3c66d93 LG |
2667 | fprintf(stderr, "failed to initialize %s: %s\n", |
2668 | accel_list[i].name, | |
2669 | strerror(-ret)); | |
d5286af5 | 2670 | *(accel_list[i].allowed) = false; |
303d4e86 | 2671 | } else { |
217e21be | 2672 | accel_initialised = true; |
303d4e86 AP |
2673 | } |
2674 | break; | |
2675 | } | |
2676 | } | |
2677 | if (i == ARRAY_SIZE(accel_list)) { | |
2678 | fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf); | |
2679 | } | |
2680 | } | |
2681 | ||
1b785a97 | 2682 | if (!accel_initialised) { |
217e21be LG |
2683 | if (!init_failed) { |
2684 | fprintf(stderr, "No accelerator found!\n"); | |
2685 | } | |
303d4e86 AP |
2686 | exit(1); |
2687 | } | |
2688 | ||
2689 | if (init_failed) { | |
2690 | fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name); | |
2691 | } | |
2692 | ||
1b785a97 | 2693 | return !accel_initialised; |
303d4e86 AP |
2694 | } |
2695 | ||
fd42deeb GH |
2696 | void qemu_add_exit_notifier(Notifier *notify) |
2697 | { | |
2698 | notifier_list_add(&exit_notifiers, notify); | |
2699 | } | |
2700 | ||
2701 | void qemu_remove_exit_notifier(Notifier *notify) | |
2702 | { | |
31552529 | 2703 | notifier_remove(notify); |
fd42deeb GH |
2704 | } |
2705 | ||
2706 | static void qemu_run_exit_notifiers(void) | |
2707 | { | |
9e8dd451 | 2708 | notifier_list_notify(&exit_notifiers, NULL); |
fd42deeb GH |
2709 | } |
2710 | ||
4cab946a GN |
2711 | void qemu_add_machine_init_done_notifier(Notifier *notify) |
2712 | { | |
2713 | notifier_list_add(&machine_init_done_notifiers, notify); | |
2714 | } | |
2715 | ||
2716 | static void qemu_run_machine_init_done_notifiers(void) | |
2717 | { | |
9e8dd451 | 2718 | notifier_list_notify(&machine_init_done_notifiers, NULL); |
4cab946a GN |
2719 | } |
2720 | ||
6530a97b AL |
2721 | static const QEMUOption *lookup_opt(int argc, char **argv, |
2722 | const char **poptarg, int *poptind) | |
2723 | { | |
2724 | const QEMUOption *popt; | |
2725 | int optind = *poptind; | |
2726 | char *r = argv[optind]; | |
2727 | const char *optarg; | |
2728 | ||
0f0bc3f1 | 2729 | loc_set_cmdline(argv, optind, 1); |
6530a97b AL |
2730 | optind++; |
2731 | /* Treat --foo the same as -foo. */ | |
2732 | if (r[1] == '-') | |
2733 | r++; | |
2734 | popt = qemu_options; | |
2735 | for(;;) { | |
2736 | if (!popt->name) { | |
0f0bc3f1 | 2737 | error_report("invalid option"); |
6530a97b AL |
2738 | exit(1); |
2739 | } | |
2740 | if (!strcmp(popt->name, r + 1)) | |
2741 | break; | |
2742 | popt++; | |
2743 | } | |
2744 | if (popt->flags & HAS_ARG) { | |
2745 | if (optind >= argc) { | |
0f0bc3f1 | 2746 | error_report("requires an argument"); |
6530a97b AL |
2747 | exit(1); |
2748 | } | |
2749 | optarg = argv[optind++]; | |
0f0bc3f1 | 2750 | loc_set_cmdline(argv, optind - 2, 2); |
6530a97b AL |
2751 | } else { |
2752 | optarg = NULL; | |
2753 | } | |
2754 | ||
2755 | *poptarg = optarg; | |
2756 | *poptind = optind; | |
2757 | ||
2758 | return popt; | |
2759 | } | |
2760 | ||
0750112a AL |
2761 | static gpointer malloc_and_trace(gsize n_bytes) |
2762 | { | |
2763 | void *ptr = malloc(n_bytes); | |
a74cd8cc | 2764 | trace_g_malloc(n_bytes, ptr); |
0750112a AL |
2765 | return ptr; |
2766 | } | |
2767 | ||
2768 | static gpointer realloc_and_trace(gpointer mem, gsize n_bytes) | |
2769 | { | |
2770 | void *ptr = realloc(mem, n_bytes); | |
a74cd8cc | 2771 | trace_g_realloc(mem, n_bytes, ptr); |
0750112a AL |
2772 | return ptr; |
2773 | } | |
2774 | ||
2775 | static void free_and_trace(gpointer mem) | |
2776 | { | |
a74cd8cc | 2777 | trace_g_free(mem); |
0750112a AL |
2778 | free(mem); |
2779 | } | |
2780 | ||
68d98d3e AL |
2781 | static int object_set_property(const char *name, const char *value, void *opaque) |
2782 | { | |
2783 | Object *obj = OBJECT(opaque); | |
2784 | StringInputVisitor *siv; | |
2785 | Error *local_err = NULL; | |
2786 | ||
2787 | if (strcmp(name, "qom-type") == 0 || strcmp(name, "id") == 0) { | |
2788 | return 0; | |
2789 | } | |
2790 | ||
2791 | siv = string_input_visitor_new(value); | |
2792 | object_property_set(obj, string_input_get_visitor(siv), name, &local_err); | |
2793 | string_input_visitor_cleanup(siv); | |
2794 | ||
2795 | if (local_err) { | |
2796 | qerror_report_err(local_err); | |
2797 | error_free(local_err); | |
2798 | return -1; | |
2799 | } | |
2800 | ||
2801 | return 0; | |
2802 | } | |
2803 | ||
2804 | static int object_create(QemuOpts *opts, void *opaque) | |
2805 | { | |
2806 | const char *type = qemu_opt_get(opts, "qom-type"); | |
2807 | const char *id = qemu_opts_id(opts); | |
90e9cf28 | 2808 | Error *local_err = NULL; |
68d98d3e AL |
2809 | Object *obj; |
2810 | ||
2811 | g_assert(type != NULL); | |
2812 | ||
2813 | if (id == NULL) { | |
2814 | qerror_report(QERR_MISSING_PARAMETER, "id"); | |
2815 | return -1; | |
2816 | } | |
2817 | ||
2818 | obj = object_new(type); | |
2819 | if (qemu_opt_foreach(opts, object_set_property, obj, 1) < 0) { | |
28ec2598 | 2820 | object_unref(obj); |
68d98d3e AL |
2821 | return -1; |
2822 | } | |
2823 | ||
269e09f3 IM |
2824 | if (!object_dynamic_cast(obj, TYPE_USER_CREATABLE)) { |
2825 | error_setg(&local_err, "object '%s' isn't supported by -object", | |
2826 | id); | |
2827 | goto out; | |
2828 | } | |
2829 | ||
2830 | user_creatable_complete(obj, &local_err); | |
2831 | if (local_err) { | |
2832 | goto out; | |
2833 | } | |
2834 | ||
68d98d3e | 2835 | object_property_add_child(container_get(object_get_root(), "/objects"), |
90e9cf28 IM |
2836 | id, obj, &local_err); |
2837 | ||
269e09f3 | 2838 | out: |
28ec2598 | 2839 | object_unref(obj); |
90e9cf28 IM |
2840 | if (local_err) { |
2841 | qerror_report_err(local_err); | |
2842 | error_free(local_err); | |
2843 | return -1; | |
2844 | } | |
68d98d3e AL |
2845 | return 0; |
2846 | } | |
2847 | ||
902b3d5c | 2848 | int main(int argc, char **argv, char **envp) |
0824d6fc | 2849 | { |
e4bcb14c | 2850 | int i; |
da1fcfda | 2851 | int snapshot, linux_boot; |
4e3de9e9 | 2852 | const char *icount_option = NULL; |
7f7f9873 | 2853 | const char *initrd_filename; |
a20dd508 | 2854 | const char *kernel_filename, *kernel_cmdline; |
e3fdc535 | 2855 | const char *boot_order; |
3023f332 | 2856 | DisplayState *ds; |
9f227bc3 | 2857 | int cyls, heads, secs, translation; |
2858 | QemuOpts *hda_opts = NULL, *opts, *machine_opts; | |
03b0ba70 | 2859 | QemuOptsList *olist; |
cd6f1169 | 2860 | int optind; |
6530a97b | 2861 | const char *optarg; |
d63d307f | 2862 | const char *loadvm = NULL; |
cc1daa40 | 2863 | QEMUMachine *machine; |
94fc95cd | 2864 | const char *cpu_model; |
7f1b17f2 | 2865 | const char *vga_model = "none"; |
d4fce24f PB |
2866 | const char *qtest_chrdev = NULL; |
2867 | const char *qtest_log = NULL; | |
93815bc2 | 2868 | const char *pid_file = NULL; |
5bb7910a | 2869 | const char *incoming = NULL; |
821601ea | 2870 | #ifdef CONFIG_VNC |
993fbfdb | 2871 | int show_vnc_port = 0; |
821601ea | 2872 | #endif |
3ed2d9ee | 2873 | bool defconfig = true; |
f29a5614 | 2874 | bool userconfig = true; |
c235d738 MF |
2875 | const char *log_mask = NULL; |
2876 | const char *log_file = NULL; | |
0750112a AL |
2877 | GMemVTable mem_trace = { |
2878 | .malloc = malloc_and_trace, | |
2879 | .realloc = realloc_and_trace, | |
2880 | .free = free_and_trace, | |
2881 | }; | |
23d15e86 | 2882 | const char *trace_events = NULL; |
e4858974 | 2883 | const char *trace_file = NULL; |
0b5538c3 | 2884 | |
fd42deeb | 2885 | atexit(qemu_run_exit_notifiers); |
65abca0a | 2886 | error_set_progname(argv[0]); |
10f5bff6 | 2887 | qemu_init_exec_dir(argv[0]); |
65abca0a | 2888 | |
0750112a | 2889 | g_mem_set_vtable(&mem_trace); |
db529aab | 2890 | if (!g_thread_supported()) { |
42ed3727 | 2891 | #if !GLIB_CHECK_VERSION(2, 31, 0) |
db529aab | 2892 | g_thread_init(NULL); |
42ed3727 AL |
2893 | #else |
2894 | fprintf(stderr, "glib threading failed to initialize.\n"); | |
2895 | exit(1); | |
2896 | #endif | |
db529aab | 2897 | } |
0750112a | 2898 | |
1b71f7c1 AF |
2899 | module_call_init(MODULE_INIT_QOM); |
2900 | ||
4d454574 | 2901 | qemu_add_opts(&qemu_drive_opts); |
968854c8 AK |
2902 | qemu_add_drive_opts(&qemu_legacy_drive_opts); |
2903 | qemu_add_drive_opts(&qemu_common_drive_opts); | |
2904 | qemu_add_drive_opts(&qemu_drive_opts); | |
4d454574 PB |
2905 | qemu_add_opts(&qemu_chardev_opts); |
2906 | qemu_add_opts(&qemu_device_opts); | |
2907 | qemu_add_opts(&qemu_netdev_opts); | |
2908 | qemu_add_opts(&qemu_net_opts); | |
2909 | qemu_add_opts(&qemu_rtc_opts); | |
2910 | qemu_add_opts(&qemu_global_opts); | |
2911 | qemu_add_opts(&qemu_mon_opts); | |
2912 | qemu_add_opts(&qemu_trace_opts); | |
2913 | qemu_add_opts(&qemu_option_rom_opts); | |
2914 | qemu_add_opts(&qemu_machine_opts); | |
12b7f57e | 2915 | qemu_add_opts(&qemu_smp_opts); |
4d454574 PB |
2916 | qemu_add_opts(&qemu_boot_opts); |
2917 | qemu_add_opts(&qemu_sandbox_opts); | |
2918 | qemu_add_opts(&qemu_add_fd_opts); | |
2919 | qemu_add_opts(&qemu_object_opts); | |
d1a0cf73 | 2920 | qemu_add_opts(&qemu_tpmdev_opts); |
888a6bc6 | 2921 | qemu_add_opts(&qemu_realtime_opts); |
5e2ac519 | 2922 | qemu_add_opts(&qemu_msg_opts); |
5d12f961 | 2923 | qemu_add_opts(&qemu_name_opts); |
4d454574 | 2924 | |
5db9d4d1 LC |
2925 | runstate_init(); |
2926 | ||
6875204c | 2927 | init_clocks(); |
884f17c2 | 2928 | rtc_clock = QEMU_CLOCK_HOST; |
6875204c | 2929 | |
b6a3e690 | 2930 | qemu_init_auxval(envp); |
664d2c44 | 2931 | qemu_cache_utils_init(); |
902b3d5c | 2932 | |
72cf2d4f | 2933 | QLIST_INIT (&vm_change_state_head); |
fe98ac14 | 2934 | os_setup_early_signal_handling(); |
be995c27 | 2935 | |
f80f9ec9 | 2936 | module_call_init(MODULE_INIT_MACHINE); |
0c257437 | 2937 | machine = find_default_machine(); |
94fc95cd | 2938 | cpu_model = NULL; |
4fc5d071 | 2939 | ram_size = 0; |
33e3963e | 2940 | snapshot = 0; |
9f227bc3 | 2941 | cyls = heads = secs = 0; |
2942 | translation = BIOS_ATA_TRANSLATION_AUTO; | |
c4b1fcc0 | 2943 | |
268a362c AL |
2944 | for (i = 0; i < MAX_NODES; i++) { |
2945 | node_mem[i] = 0; | |
ee785fed | 2946 | node_cpumask[i] = bitmap_new(MAX_CPUMASK_BITS); |
268a362c AL |
2947 | } |
2948 | ||
268a362c | 2949 | nb_numa_nodes = 0; |
7c9d8e07 | 2950 | nb_nics = 0; |
3b46e624 | 2951 | |
142c6b1a PL |
2952 | bdrv_init_with_whitelist(); |
2953 | ||
2c02d1ad | 2954 | autostart = 1; |
41bd639b | 2955 | |
292444cb AL |
2956 | /* first pass of option parsing */ |
2957 | optind = 1; | |
2958 | while (optind < argc) { | |
2959 | if (argv[optind][0] != '-') { | |
2960 | /* disk image */ | |
28e68d68 | 2961 | optind++; |
292444cb AL |
2962 | continue; |
2963 | } else { | |
2964 | const QEMUOption *popt; | |
2965 | ||
2966 | popt = lookup_opt(argc, argv, &optarg, &optind); | |
2967 | switch (popt->index) { | |
2968 | case QEMU_OPTION_nodefconfig: | |
3ed2d9ee | 2969 | defconfig = false; |
292444cb | 2970 | break; |
f29a5614 EH |
2971 | case QEMU_OPTION_nouserconfig: |
2972 | userconfig = false; | |
2973 | break; | |
292444cb AL |
2974 | } |
2975 | } | |
2976 | } | |
2977 | ||
2978 | if (defconfig) { | |
dcfb0939 | 2979 | int ret; |
f29a5614 | 2980 | ret = qemu_read_default_config_files(userconfig); |
b5a8fe5e | 2981 | if (ret < 0) { |
dcfb0939 | 2982 | exit(1); |
292444cb AL |
2983 | } |
2984 | } | |
2985 | ||
2986 | /* second pass of option parsing */ | |
cd6f1169 | 2987 | optind = 1; |
0824d6fc | 2988 | for(;;) { |
cd6f1169 | 2989 | if (optind >= argc) |
0824d6fc | 2990 | break; |
6530a97b | 2991 | if (argv[optind][0] != '-') { |
9f227bc3 | 2992 | hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS); |
cd6f1169 FB |
2993 | } else { |
2994 | const QEMUOption *popt; | |
2995 | ||
6530a97b | 2996 | popt = lookup_opt(argc, argv, &optarg, &optind); |
ad96090a BS |
2997 | if (!(popt->arch_mask & arch_type)) { |
2998 | printf("Option %s not supported for this target\n", popt->name); | |
2999 | exit(1); | |
3000 | } | |
cd6f1169 | 3001 | switch(popt->index) { |
cc1daa40 | 3002 | case QEMU_OPTION_M: |
9052ea6b | 3003 | machine = machine_parse(optarg); |
cc1daa40 | 3004 | break; |
e43d594e JK |
3005 | case QEMU_OPTION_no_kvm_irqchip: { |
3006 | olist = qemu_find_opts("machine"); | |
3007 | qemu_opts_parse(olist, "kernel_irqchip=off", 0); | |
3008 | break; | |
3009 | } | |
94fc95cd JM |
3010 | case QEMU_OPTION_cpu: |
3011 | /* hw initialization will check this */ | |
ecf40bea | 3012 | cpu_model = optarg; |
94fc95cd | 3013 | break; |
cd6f1169 | 3014 | case QEMU_OPTION_hda: |
9f227bc3 | 3015 | { |
3016 | char buf[256]; | |
3017 | if (cyls == 0) | |
3018 | snprintf(buf, sizeof(buf), "%s", HD_OPTS); | |
3019 | else | |
3020 | snprintf(buf, sizeof(buf), | |
3021 | "%s,cyls=%d,heads=%d,secs=%d%s", | |
3022 | HD_OPTS , cyls, heads, secs, | |
3023 | translation == BIOS_ATA_TRANSLATION_LBA ? | |
3024 | ",trans=lba" : | |
3025 | translation == BIOS_ATA_TRANSLATION_NONE ? | |
3026 | ",trans=none" : ""); | |
3027 | drive_add(IF_DEFAULT, 0, optarg, buf); | |
3028 | break; | |
3029 | } | |
cd6f1169 | 3030 | case QEMU_OPTION_hdb: |
cc1daa40 FB |
3031 | case QEMU_OPTION_hdc: |
3032 | case QEMU_OPTION_hdd: | |
2292ddae MA |
3033 | drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg, |
3034 | HD_OPTS); | |
fc01f7e7 | 3035 | break; |
e4bcb14c | 3036 | case QEMU_OPTION_drive: |
e2982c3a MT |
3037 | if (drive_def(optarg) == NULL) { |
3038 | exit(1); | |
3039 | } | |
e4bcb14c | 3040 | break; |
d058fe03 GH |
3041 | case QEMU_OPTION_set: |
3042 | if (qemu_set_option(optarg) != 0) | |
3043 | exit(1); | |
3044 | break; | |
d0fef6fb GH |
3045 | case QEMU_OPTION_global: |
3046 | if (qemu_global_option(optarg) != 0) | |
3047 | exit(1); | |
3048 | break; | |
3e3d5815 | 3049 | case QEMU_OPTION_mtdblock: |
2292ddae | 3050 | drive_add(IF_MTD, -1, optarg, MTD_OPTS); |
3e3d5815 | 3051 | break; |
a1bb27b1 | 3052 | case QEMU_OPTION_sd: |
80f4d9fc | 3053 | drive_add(IF_SD, -1, optarg, SD_OPTS); |
a1bb27b1 | 3054 | break; |
86f55663 | 3055 | case QEMU_OPTION_pflash: |
2292ddae | 3056 | drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS); |
86f55663 | 3057 | break; |
cd6f1169 | 3058 | case QEMU_OPTION_snapshot: |
33e3963e FB |
3059 | snapshot = 1; |
3060 | break; | |
cd6f1169 | 3061 | case QEMU_OPTION_hdachs: |
330d0414 | 3062 | { |
330d0414 FB |
3063 | const char *p; |
3064 | p = optarg; | |
3065 | cyls = strtol(p, (char **)&p, 0); | |
46d4767d FB |
3066 | if (cyls < 1 || cyls > 16383) |
3067 | goto chs_fail; | |
330d0414 FB |
3068 | if (*p != ',') |
3069 | goto chs_fail; | |
3070 | p++; | |
3071 | heads = strtol(p, (char **)&p, 0); | |
46d4767d FB |
3072 | if (heads < 1 || heads > 16) |
3073 | goto chs_fail; | |
330d0414 FB |
3074 | if (*p != ',') |
3075 | goto chs_fail; | |
3076 | p++; | |
3077 | secs = strtol(p, (char **)&p, 0); | |
46d4767d FB |
3078 | if (secs < 1 || secs > 63) |
3079 | goto chs_fail; | |
3080 | if (*p == ',') { | |
3081 | p++; | |
f31c41ff PB |
3082 | if (!strcmp(p, "large")) { |
3083 | translation = BIOS_ATA_TRANSLATION_LARGE; | |
3084 | } else if (!strcmp(p, "rechs")) { | |
3085 | translation = BIOS_ATA_TRANSLATION_RECHS; | |
3086 | } else if (!strcmp(p, "none")) { | |
46d4767d | 3087 | translation = BIOS_ATA_TRANSLATION_NONE; |
f31c41ff | 3088 | } else if (!strcmp(p, "lba")) { |
46d4767d | 3089 | translation = BIOS_ATA_TRANSLATION_LBA; |
f31c41ff | 3090 | } else if (!strcmp(p, "auto")) { |
46d4767d | 3091 | translation = BIOS_ATA_TRANSLATION_AUTO; |
f31c41ff | 3092 | } else { |
46d4767d | 3093 | goto chs_fail; |
f31c41ff | 3094 | } |
46d4767d | 3095 | } else if (*p != '\0') { |
c4b1fcc0 | 3096 | chs_fail: |
46d4767d FB |
3097 | fprintf(stderr, "qemu: invalid physical CHS format\n"); |
3098 | exit(1); | |
c4b1fcc0 | 3099 | } |
9f227bc3 | 3100 | if (hda_opts != NULL) { |
9dfd7c7a GH |
3101 | char num[16]; |
3102 | snprintf(num, sizeof(num), "%d", cyls); | |
3103 | qemu_opt_set(hda_opts, "cyls", num); | |
3104 | snprintf(num, sizeof(num), "%d", heads); | |
3105 | qemu_opt_set(hda_opts, "heads", num); | |
3106 | snprintf(num, sizeof(num), "%d", secs); | |
3107 | qemu_opt_set(hda_opts, "secs", num); | |
f31c41ff PB |
3108 | if (translation == BIOS_ATA_TRANSLATION_LARGE) { |
3109 | qemu_opt_set(hda_opts, "trans", "large"); | |
3110 | } else if (translation == BIOS_ATA_TRANSLATION_RECHS) { | |
3111 | qemu_opt_set(hda_opts, "trans", "rechs"); | |
3112 | } else if (translation == BIOS_ATA_TRANSLATION_LBA) { | |
9dfd7c7a | 3113 | qemu_opt_set(hda_opts, "trans", "lba"); |
f31c41ff | 3114 | } else if (translation == BIOS_ATA_TRANSLATION_NONE) { |
9dfd7c7a | 3115 | qemu_opt_set(hda_opts, "trans", "none"); |
f31c41ff | 3116 | } |
9dfd7c7a | 3117 | } |
330d0414 FB |
3118 | } |
3119 | break; | |
268a362c | 3120 | case QEMU_OPTION_numa: |
268a362c AL |
3121 | numa_add(optarg); |
3122 | break; | |
1472a95b JS |
3123 | case QEMU_OPTION_display: |
3124 | display_type = select_display(optarg); | |
3125 | break; | |
cd6f1169 | 3126 | case QEMU_OPTION_nographic: |
993fbfdb | 3127 | display_type = DT_NOGRAPHIC; |
a20dd508 | 3128 | break; |
4d3b6f6e | 3129 | case QEMU_OPTION_curses: |
47b05369 | 3130 | #ifdef CONFIG_CURSES |
993fbfdb | 3131 | display_type = DT_CURSES; |
47b05369 JS |
3132 | #else |
3133 | fprintf(stderr, "Curses support is disabled\n"); | |
3134 | exit(1); | |
4d3b6f6e | 3135 | #endif |
47b05369 | 3136 | break; |
a171fe39 | 3137 | case QEMU_OPTION_portrait: |
9312805d VK |
3138 | graphic_rotate = 90; |
3139 | break; | |
3140 | case QEMU_OPTION_rotate: | |
3141 | graphic_rotate = strtol(optarg, (char **) &optarg, 10); | |
3142 | if (graphic_rotate != 0 && graphic_rotate != 90 && | |
3143 | graphic_rotate != 180 && graphic_rotate != 270) { | |
3144 | fprintf(stderr, | |
3145 | "qemu: only 90, 180, 270 deg rotation is available\n"); | |
3146 | exit(1); | |
3147 | } | |
a171fe39 | 3148 | break; |
cd6f1169 | 3149 | case QEMU_OPTION_kernel: |
a0abe474 PM |
3150 | qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg); |
3151 | break; | |
3152 | case QEMU_OPTION_initrd: | |
3153 | qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg); | |
a20dd508 | 3154 | break; |
cd6f1169 | 3155 | case QEMU_OPTION_append: |
a0abe474 | 3156 | qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg); |
313aa567 | 3157 | break; |
412beee6 GL |
3158 | case QEMU_OPTION_dtb: |
3159 | qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg); | |
3160 | break; | |
cd6f1169 | 3161 | case QEMU_OPTION_cdrom: |
2292ddae | 3162 | drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS); |
36b486bb | 3163 | break; |
cd6f1169 | 3164 | case QEMU_OPTION_boot: |
8281abd5 MA |
3165 | opts = qemu_opts_parse(qemu_find_opts("boot-opts"), optarg, 1); |
3166 | if (!opts) { | |
3167 | exit(1); | |
36b486bb FB |
3168 | } |
3169 | break; | |
cd6f1169 | 3170 | case QEMU_OPTION_fda: |
cd6f1169 | 3171 | case QEMU_OPTION_fdb: |
2292ddae MA |
3172 | drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda, |
3173 | optarg, FD_OPTS); | |
c45886db | 3174 | break; |
52ca8d6a FB |
3175 | case QEMU_OPTION_no_fd_bootchk: |
3176 | fd_bootchk = 0; | |
3177 | break; | |
a1ea458f | 3178 | case QEMU_OPTION_netdev: |
3329f07b | 3179 | if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) { |
a1ea458f MM |
3180 | exit(1); |
3181 | } | |
3182 | break; | |
7c9d8e07 | 3183 | case QEMU_OPTION_net: |
3329f07b | 3184 | if (net_client_parse(qemu_find_opts("net"), optarg) == -1) { |
c4b1fcc0 FB |
3185 | exit(1); |
3186 | } | |
702c651c | 3187 | break; |
f9dadc98 RS |
3188 | #ifdef CONFIG_LIBISCSI |
3189 | case QEMU_OPTION_iscsi: | |
3190 | opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0); | |
3191 | if (!opts) { | |
3192 | exit(1); | |
3193 | } | |
3194 | break; | |
3195 | #endif | |
c7f74643 FB |
3196 | #ifdef CONFIG_SLIRP |
3197 | case QEMU_OPTION_tftp: | |
ad196a9d | 3198 | legacy_tftp_prefix = optarg; |
9bf05444 | 3199 | break; |
47d5d01a | 3200 | case QEMU_OPTION_bootp: |
ad196a9d | 3201 | legacy_bootp_filename = optarg; |
47d5d01a | 3202 | break; |
9bf05444 | 3203 | case QEMU_OPTION_redir: |
0752706d MA |
3204 | if (net_slirp_redir(optarg) < 0) |
3205 | exit(1); | |
9bf05444 | 3206 | break; |
c7f74643 | 3207 | #endif |
dc72ac14 | 3208 | case QEMU_OPTION_bt: |
bd3c948d | 3209 | add_device_config(DEV_BT, optarg); |
dc72ac14 | 3210 | break; |
1d14ffa9 FB |
3211 | case QEMU_OPTION_audio_help: |
3212 | AUD_help (); | |
3213 | exit (0); | |
3214 | break; | |
3215 | case QEMU_OPTION_soundhw: | |
3216 | select_soundhw (optarg); | |
3217 | break; | |
cd6f1169 | 3218 | case QEMU_OPTION_h: |
15f82208 | 3219 | help(0); |
cd6f1169 | 3220 | break; |
9bd7e6d9 PB |
3221 | case QEMU_OPTION_version: |
3222 | version(); | |
3223 | exit(0); | |
3224 | break; | |
00f82b8a | 3225 | case QEMU_OPTION_m: { |
70b4f4bb | 3226 | int64_t value; |
ff961015 | 3227 | uint64_t sz; |
961b42b9 | 3228 | char *end; |
9f9b17a4 | 3229 | |
961b42b9 MA |
3230 | value = strtosz(optarg, &end); |
3231 | if (value < 0 || *end) { | |
00f82b8a | 3232 | fprintf(stderr, "qemu: invalid ram size: %s\n", optarg); |
cd6f1169 FB |
3233 | exit(1); |
3234 | } | |
ff961015 MA |
3235 | sz = QEMU_ALIGN_UP((uint64_t)value, 8192); |
3236 | ram_size = sz; | |
3237 | if (ram_size != sz) { | |
00f82b8a AJ |
3238 | fprintf(stderr, "qemu: ram size too large\n"); |
3239 | exit(1); | |
3240 | } | |
cd6f1169 | 3241 | break; |
00f82b8a | 3242 | } |
d1a0cf73 SB |
3243 | #ifdef CONFIG_TPM |
3244 | case QEMU_OPTION_tpmdev: | |
3245 | if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) { | |
3246 | exit(1); | |
3247 | } | |
3248 | break; | |
3249 | #endif | |
c902760f MT |
3250 | case QEMU_OPTION_mempath: |
3251 | mem_path = optarg; | |
3252 | break; | |
c902760f MT |
3253 | case QEMU_OPTION_mem_prealloc: |
3254 | mem_prealloc = 1; | |
3255 | break; | |
cd6f1169 | 3256 | case QEMU_OPTION_d: |
c235d738 MF |
3257 | log_mask = optarg; |
3258 | break; | |
3259 | case QEMU_OPTION_D: | |
3260 | log_file = optarg; | |
cd6f1169 | 3261 | break; |
cd6f1169 | 3262 | case QEMU_OPTION_s: |
ef0c4a0d | 3263 | add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); |
cd6f1169 | 3264 | break; |
59030a8c | 3265 | case QEMU_OPTION_gdb: |
ef0c4a0d | 3266 | add_device_config(DEV_GDB, optarg); |
cd6f1169 | 3267 | break; |
cd6f1169 | 3268 | case QEMU_OPTION_L: |
4524051c GH |
3269 | if (data_dir_idx < ARRAY_SIZE(data_dir)) { |
3270 | data_dir[data_dir_idx++] = optarg; | |
3271 | } | |
cd6f1169 | 3272 | break; |
1192dad8 | 3273 | case QEMU_OPTION_bios: |
1442d3e6 | 3274 | qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg); |
1192dad8 | 3275 | break; |
1b530a6d AJ |
3276 | case QEMU_OPTION_singlestep: |
3277 | singlestep = 1; | |
3278 | break; | |
cd6f1169 | 3279 | case QEMU_OPTION_S: |
3c07f8e8 | 3280 | autostart = 0; |
cd6f1169 | 3281 | break; |
3d11d0eb FB |
3282 | case QEMU_OPTION_k: |
3283 | keyboard_layout = optarg; | |
3284 | break; | |
ee22c2f7 FB |
3285 | case QEMU_OPTION_localtime: |
3286 | rtc_utc = 0; | |
3287 | break; | |
3893c124 | 3288 | case QEMU_OPTION_vga: |
a369da5f | 3289 | vga_model = optarg; |
7f1b17f2 | 3290 | default_vga = 0; |
1bfe856e | 3291 | break; |
e9b137c2 FB |
3292 | case QEMU_OPTION_g: |
3293 | { | |
3294 | const char *p; | |
3295 | int w, h, depth; | |
3296 | p = optarg; | |
3297 | w = strtol(p, (char **)&p, 10); | |
3298 | if (w <= 0) { | |
3299 | graphic_error: | |
3300 | fprintf(stderr, "qemu: invalid resolution or depth\n"); | |
3301 | exit(1); | |
3302 | } | |
3303 | if (*p != 'x') | |
3304 | goto graphic_error; | |
3305 | p++; | |
3306 | h = strtol(p, (char **)&p, 10); | |
3307 | if (h <= 0) | |
3308 | goto graphic_error; | |
3309 | if (*p == 'x') { | |
3310 | p++; | |
3311 | depth = strtol(p, (char **)&p, 10); | |
5fafdf24 | 3312 | if (depth != 8 && depth != 15 && depth != 16 && |
e9b137c2 FB |
3313 | depth != 24 && depth != 32) |
3314 | goto graphic_error; | |
3315 | } else if (*p == '\0') { | |
3316 | depth = graphic_depth; | |
3317 | } else { | |
3318 | goto graphic_error; | |
3319 | } | |
3b46e624 | 3320 | |
e9b137c2 FB |
3321 | graphic_width = w; |
3322 | graphic_height = h; | |
3323 | graphic_depth = depth; | |
3324 | } | |
3325 | break; | |
20d8a3ed TS |
3326 | case QEMU_OPTION_echr: |
3327 | { | |
3328 | char *r; | |
3329 | term_escape_char = strtol(optarg, &r, 0); | |
3330 | if (r == optarg) | |
3331 | printf("Bad argument to echr\n"); | |
3332 | break; | |
3333 | } | |
82c643ff | 3334 | case QEMU_OPTION_monitor: |
6ca5582d | 3335 | default_monitor = 0; |
70e098af LC |
3336 | if (strncmp(optarg, "none", 4)) { |
3337 | monitor_parse(optarg, "readline"); | |
3338 | } | |
6ca5582d GH |
3339 | break; |
3340 | case QEMU_OPTION_qmp: | |
3341 | monitor_parse(optarg, "control"); | |
2d114dc1 | 3342 | default_monitor = 0; |
82c643ff | 3343 | break; |
22a0e04b | 3344 | case QEMU_OPTION_mon: |
3329f07b | 3345 | opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1); |
22a0e04b | 3346 | if (!opts) { |
22a0e04b GH |
3347 | exit(1); |
3348 | } | |
2d114dc1 | 3349 | default_monitor = 0; |
22a0e04b | 3350 | break; |
191bc01b | 3351 | case QEMU_OPTION_chardev: |
3329f07b | 3352 | opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1); |
191bc01b | 3353 | if (!opts) { |
191bc01b GH |
3354 | exit(1); |
3355 | } | |
191bc01b | 3356 | break; |
74db920c | 3357 | case QEMU_OPTION_fsdev: |
03b0ba70 GH |
3358 | olist = qemu_find_opts("fsdev"); |
3359 | if (!olist) { | |
3360 | fprintf(stderr, "fsdev is not supported by this qemu build.\n"); | |
3361 | exit(1); | |
3362 | } | |
3363 | opts = qemu_opts_parse(olist, optarg, 1); | |
74db920c | 3364 | if (!opts) { |
74db920c GS |
3365 | exit(1); |
3366 | } | |
3367 | break; | |
3d54abc7 | 3368 | case QEMU_OPTION_virtfs: { |
e14ea479 SH |
3369 | QemuOpts *fsdev; |
3370 | QemuOpts *device; | |
84a87cc4 | 3371 | const char *writeout, *sock_fd, *socket; |
3d54abc7 | 3372 | |
03b0ba70 GH |
3373 | olist = qemu_find_opts("virtfs"); |
3374 | if (!olist) { | |
3375 | fprintf(stderr, "virtfs is not supported by this qemu build.\n"); | |
3376 | exit(1); | |
3377 | } | |
3378 | opts = qemu_opts_parse(olist, optarg, 1); | |
3d54abc7 | 3379 | if (!opts) { |
3d54abc7 GS |
3380 | exit(1); |
3381 | } | |
3382 | ||
fbcbf101 | 3383 | if (qemu_opt_get(opts, "fsdriver") == NULL || |
99519f0a AK |
3384 | qemu_opt_get(opts, "mount_tag") == NULL) { |
3385 | fprintf(stderr, "Usage: -virtfs fsdriver,mount_tag=tag.\n"); | |
9ce56db6 VJ |
3386 | exit(1); |
3387 | } | |
e14ea479 | 3388 | fsdev = qemu_opts_create(qemu_find_opts("fsdev"), |
8be7e7e4 LC |
3389 | qemu_opt_get(opts, "mount_tag"), |
3390 | 1, NULL); | |
e14ea479 SH |
3391 | if (!fsdev) { |
3392 | fprintf(stderr, "duplicate fsdev id: %s\n", | |
3393 | qemu_opt_get(opts, "mount_tag")); | |
3d54abc7 GS |
3394 | exit(1); |
3395 | } | |
d3ab98e6 AK |
3396 | |
3397 | writeout = qemu_opt_get(opts, "writeout"); | |
3398 | if (writeout) { | |
3399 | #ifdef CONFIG_SYNC_FILE_RANGE | |
3400 | qemu_opt_set(fsdev, "writeout", writeout); | |
3401 | #else | |
3402 | fprintf(stderr, "writeout=immediate not supported on " | |
3403 | "this platform\n"); | |
3404 | exit(1); | |
3405 | #endif | |
3406 | } | |
fbcbf101 | 3407 | qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver")); |
e14ea479 SH |
3408 | qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path")); |
3409 | qemu_opt_set(fsdev, "security_model", | |
3410 | qemu_opt_get(opts, "security_model")); | |
84a87cc4 MK |
3411 | socket = qemu_opt_get(opts, "socket"); |
3412 | if (socket) { | |
3413 | qemu_opt_set(fsdev, "socket", socket); | |
3414 | } | |
4c793dda MK |
3415 | sock_fd = qemu_opt_get(opts, "sock_fd"); |
3416 | if (sock_fd) { | |
3417 | qemu_opt_set(fsdev, "sock_fd", sock_fd); | |
3418 | } | |
e14ea479 | 3419 | |
2c74c2cb MK |
3420 | qemu_opt_set_bool(fsdev, "readonly", |
3421 | qemu_opt_get_bool(opts, "readonly", 0)); | |
87ea75d5 PC |
3422 | device = qemu_opts_create(qemu_find_opts("device"), NULL, 0, |
3423 | &error_abort); | |
e14ea479 SH |
3424 | qemu_opt_set(device, "driver", "virtio-9p-pci"); |
3425 | qemu_opt_set(device, "fsdev", | |
3426 | qemu_opt_get(opts, "mount_tag")); | |
3427 | qemu_opt_set(device, "mount_tag", | |
3428 | qemu_opt_get(opts, "mount_tag")); | |
3d54abc7 GS |
3429 | break; |
3430 | } | |
9db221ae AK |
3431 | case QEMU_OPTION_virtfs_synth: { |
3432 | QemuOpts *fsdev; | |
3433 | QemuOpts *device; | |
3434 | ||
8be7e7e4 LC |
3435 | fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth", |
3436 | 1, NULL); | |
9db221ae AK |
3437 | if (!fsdev) { |
3438 | fprintf(stderr, "duplicate option: %s\n", "virtfs_synth"); | |
3439 | exit(1); | |
3440 | } | |
3441 | qemu_opt_set(fsdev, "fsdriver", "synth"); | |
9db221ae | 3442 | |
87ea75d5 PC |
3443 | device = qemu_opts_create(qemu_find_opts("device"), NULL, 0, |
3444 | &error_abort); | |
9db221ae AK |
3445 | qemu_opt_set(device, "driver", "virtio-9p-pci"); |
3446 | qemu_opt_set(device, "fsdev", "v_synth"); | |
3447 | qemu_opt_set(device, "mount_tag", "v_synth"); | |
3448 | break; | |
3449 | } | |
82c643ff | 3450 | case QEMU_OPTION_serial: |
998bbd74 GH |
3451 | add_device_config(DEV_SERIAL, optarg); |
3452 | default_serial = 0; | |
18141ed6 JK |
3453 | if (strncmp(optarg, "mon:", 4) == 0) { |
3454 | default_monitor = 0; | |
3455 | } | |
82c643ff | 3456 | break; |
9dd986cc | 3457 | case QEMU_OPTION_watchdog: |
09aaa160 MA |
3458 | if (watchdog) { |
3459 | fprintf(stderr, | |
3460 | "qemu: only one watchdog option may be given\n"); | |
3461 | return 1; | |
3462 | } | |
3463 | watchdog = optarg; | |
9dd986cc RJ |
3464 | break; |
3465 | case QEMU_OPTION_watchdog_action: | |
3466 | if (select_watchdog_action(optarg) == -1) { | |
3467 | fprintf(stderr, "Unknown -watchdog-action parameter\n"); | |
3468 | exit(1); | |
3469 | } | |
3470 | break; | |
51ecf136 | 3471 | case QEMU_OPTION_virtiocon: |
aee1b935 GH |
3472 | add_device_config(DEV_VIRTCON, optarg); |
3473 | default_virtcon = 0; | |
18141ed6 JK |
3474 | if (strncmp(optarg, "mon:", 4) == 0) { |
3475 | default_monitor = 0; | |
3476 | } | |
51ecf136 | 3477 | break; |
6508fe59 | 3478 | case QEMU_OPTION_parallel: |
6a5e8b0e GH |
3479 | add_device_config(DEV_PARALLEL, optarg); |
3480 | default_parallel = 0; | |
18141ed6 JK |
3481 | if (strncmp(optarg, "mon:", 4) == 0) { |
3482 | default_monitor = 0; | |
3483 | } | |
6508fe59 | 3484 | break; |
c9f398e5 PA |
3485 | case QEMU_OPTION_debugcon: |
3486 | add_device_config(DEV_DEBUGCON, optarg); | |
3487 | break; | |
d63d307f FB |
3488 | case QEMU_OPTION_loadvm: |
3489 | loadvm = optarg; | |
3490 | break; | |
3491 | case QEMU_OPTION_full_screen: | |
3492 | full_screen = 1; | |
3493 | break; | |
43523e93 TS |
3494 | case QEMU_OPTION_no_frame: |
3495 | no_frame = 1; | |
3496 | break; | |
3780e197 TS |
3497 | case QEMU_OPTION_alt_grab: |
3498 | alt_grab = 1; | |
3499 | break; | |
0ca9f8a4 DK |
3500 | case QEMU_OPTION_ctrl_grab: |
3501 | ctrl_grab = 1; | |
3502 | break; | |
667accab TS |
3503 | case QEMU_OPTION_no_quit: |
3504 | no_quit = 1; | |
3505 | break; | |
7d957bd8 | 3506 | case QEMU_OPTION_sdl: |
24f6ff86 | 3507 | #ifdef CONFIG_SDL |
993fbfdb | 3508 | display_type = DT_SDL; |
7d957bd8 | 3509 | break; |
58fc096c | 3510 | #else |
58fc096c JS |
3511 | fprintf(stderr, "SDL support is disabled\n"); |
3512 | exit(1); | |
667accab | 3513 | #endif |
f7cce898 | 3514 | case QEMU_OPTION_pidfile: |
93815bc2 | 3515 | pid_file = optarg; |
f7cce898 | 3516 | break; |
a09db21f FB |
3517 | case QEMU_OPTION_win2k_hack: |
3518 | win2k_install_hack = 1; | |
3519 | break; | |
433acf0d JK |
3520 | case QEMU_OPTION_rtc_td_hack: { |
3521 | static GlobalProperty slew_lost_ticks[] = { | |
3522 | { | |
3523 | .driver = "mc146818rtc", | |
3524 | .property = "lost_tick_policy", | |
3525 | .value = "slew", | |
3526 | }, | |
3527 | { /* end of list */ } | |
3528 | }; | |
3529 | ||
3530 | qdev_prop_register_global_list(slew_lost_ticks); | |
73822ec8 | 3531 | break; |
433acf0d | 3532 | } |
8a92ea2f | 3533 | case QEMU_OPTION_acpitable: |
0c764a9d | 3534 | opts = qemu_opts_parse(qemu_find_opts("acpi"), optarg, 1); |
f46e720a LE |
3535 | if (!opts) { |
3536 | exit(1); | |
3537 | } | |
0c764a9d | 3538 | do_acpitable_option(opts); |
8a92ea2f | 3539 | break; |
b6f6e3d3 | 3540 | case QEMU_OPTION_smbios: |
4f953d2f | 3541 | opts = qemu_opts_parse(qemu_find_opts("smbios"), optarg, 0); |
f46e720a LE |
3542 | if (!opts) { |
3543 | exit(1); | |
3544 | } | |
4f953d2f | 3545 | do_smbios_option(opts); |
b6f6e3d3 | 3546 | break; |
7ba1e619 | 3547 | case QEMU_OPTION_enable_kvm: |
303d4e86 | 3548 | olist = qemu_find_opts("machine"); |
303d4e86 AP |
3549 | qemu_opts_parse(olist, "accel=kvm", 0); |
3550 | break; | |
3551 | case QEMU_OPTION_machine: | |
3552 | olist = qemu_find_opts("machine"); | |
9052ea6b | 3553 | opts = qemu_opts_parse(olist, optarg, 1); |
303d4e86 | 3554 | if (!opts) { |
303d4e86 AP |
3555 | exit(1); |
3556 | } | |
2645c6dc JK |
3557 | optarg = qemu_opt_get(opts, "type"); |
3558 | if (optarg) { | |
3559 | machine = machine_parse(optarg); | |
3560 | } | |
7ba1e619 | 3561 | break; |
a0dac021 JK |
3562 | case QEMU_OPTION_no_kvm: |
3563 | olist = qemu_find_opts("machine"); | |
3564 | qemu_opts_parse(olist, "accel=tcg", 0); | |
3565 | break; | |
4086bde8 JK |
3566 | case QEMU_OPTION_no_kvm_pit: { |
3567 | fprintf(stderr, "Warning: KVM PIT can no longer be disabled " | |
3568 | "separately.\n"); | |
3569 | break; | |
3570 | } | |
c21fb4f8 JK |
3571 | case QEMU_OPTION_no_kvm_pit_reinjection: { |
3572 | static GlobalProperty kvm_pit_lost_tick_policy[] = { | |
3573 | { | |
3574 | .driver = "kvm-pit", | |
3575 | .property = "lost_tick_policy", | |
3576 | .value = "discard", | |
3577 | }, | |
3578 | { /* end of list */ } | |
3579 | }; | |
3580 | ||
3581 | fprintf(stderr, "Warning: option deprecated, use " | |
3582 | "lost_tick_policy property of kvm-pit instead.\n"); | |
3583 | qdev_prop_register_global_list(kvm_pit_lost_tick_policy); | |
3584 | break; | |
3585 | } | |
bb36d470 | 3586 | case QEMU_OPTION_usb: |
fa5358c6 PM |
3587 | olist = qemu_find_opts("machine"); |
3588 | qemu_opts_parse(olist, "usb=on", 0); | |
bb36d470 | 3589 | break; |
a594cfbf | 3590 | case QEMU_OPTION_usbdevice: |
fa5358c6 PM |
3591 | olist = qemu_find_opts("machine"); |
3592 | qemu_opts_parse(olist, "usb=on", 0); | |
bd3c948d GH |
3593 | add_device_config(DEV_USB, optarg); |
3594 | break; | |
3595 | case QEMU_OPTION_device: | |
3329f07b | 3596 | if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) { |
f31d07d1 GH |
3597 | exit(1); |
3598 | } | |
a594cfbf | 3599 | break; |
6a00d601 | 3600 | case QEMU_OPTION_smp: |
12b7f57e | 3601 | if (!qemu_opts_parse(qemu_find_opts("smp-opts"), optarg, 1)) { |
6be68d7e JS |
3602 | exit(1); |
3603 | } | |
6a00d601 | 3604 | break; |
24236869 | 3605 | case QEMU_OPTION_vnc: |
821601ea | 3606 | #ifdef CONFIG_VNC |
6b62dc2d | 3607 | display_remote++; |
821601ea JS |
3608 | vnc_display = optarg; |
3609 | #else | |
3610 | fprintf(stderr, "VNC support is disabled\n"); | |
3611 | exit(1); | |
3612 | #endif | |
3613 | break; | |
6515b203 FB |
3614 | case QEMU_OPTION_no_acpi: |
3615 | acpi_enabled = 0; | |
3616 | break; | |
16b29ae1 AL |
3617 | case QEMU_OPTION_no_hpet: |
3618 | no_hpet = 1; | |
3619 | break; | |
7d4c3d53 MA |
3620 | case QEMU_OPTION_balloon: |
3621 | if (balloon_parse(optarg) < 0) { | |
3622 | fprintf(stderr, "Unknown -balloon argument %s\n", optarg); | |
3623 | exit(1); | |
3624 | } | |
df97b920 | 3625 | break; |
d1beab82 FB |
3626 | case QEMU_OPTION_no_reboot: |
3627 | no_reboot = 1; | |
3628 | break; | |
b2f76161 AJ |
3629 | case QEMU_OPTION_no_shutdown: |
3630 | no_shutdown = 1; | |
3631 | break; | |
9467cd46 AZ |
3632 | case QEMU_OPTION_show_cursor: |
3633 | cursor_hide = 0; | |
3634 | break; | |
8fcb1b90 BS |
3635 | case QEMU_OPTION_uuid: |
3636 | if(qemu_uuid_parse(optarg, qemu_uuid) < 0) { | |
3637 | fprintf(stderr, "Fail to parse UUID string." | |
3638 | " Wrong format.\n"); | |
3639 | exit(1); | |
3640 | } | |
fc3b3295 | 3641 | qemu_uuid_set = true; |
8fcb1b90 | 3642 | break; |
9ae02555 TS |
3643 | case QEMU_OPTION_option_rom: |
3644 | if (nb_option_roms >= MAX_OPTION_ROMS) { | |
3645 | fprintf(stderr, "Too many option ROMs\n"); | |
3646 | exit(1); | |
3647 | } | |
2e55e842 | 3648 | opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1); |
49295ebc MA |
3649 | if (!opts) { |
3650 | exit(1); | |
3651 | } | |
2e55e842 GN |
3652 | option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile"); |
3653 | option_rom[nb_option_roms].bootindex = | |
3654 | qemu_opt_get_number(opts, "bootindex", -1); | |
3655 | if (!option_rom[nb_option_roms].name) { | |
3656 | fprintf(stderr, "Option ROM file is not specified\n"); | |
3657 | exit(1); | |
3658 | } | |
9ae02555 TS |
3659 | nb_option_roms++; |
3660 | break; | |
8e71621f PB |
3661 | case QEMU_OPTION_semihosting: |
3662 | semihosting_enabled = 1; | |
3663 | break; | |
88eed34a JK |
3664 | case QEMU_OPTION_tdf: |
3665 | fprintf(stderr, "Warning: user space PIT time drift fix " | |
3666 | "is no longer supported.\n"); | |
3667 | break; | |
c35734b2 | 3668 | case QEMU_OPTION_name: |
5d12f961 DDAG |
3669 | opts = qemu_opts_parse(qemu_find_opts("name"), optarg, 1); |
3670 | if (!opts) { | |
3671 | exit(1); | |
3672 | } | |
3673 | parse_name(opts); | |
c35734b2 | 3674 | break; |
66508601 BS |
3675 | case QEMU_OPTION_prom_env: |
3676 | if (nb_prom_envs >= MAX_PROM_ENVS) { | |
3677 | fprintf(stderr, "Too many prom variables\n"); | |
3678 | exit(1); | |
3679 | } | |
3680 | prom_envs[nb_prom_envs] = optarg; | |
3681 | nb_prom_envs++; | |
3682 | break; | |
2b8f2d41 AZ |
3683 | case QEMU_OPTION_old_param: |
3684 | old_param = 1; | |
05ebd537 | 3685 | break; |
f3dcfada | 3686 | case QEMU_OPTION_clock: |
6d327171 AB |
3687 | /* Clock options no longer exist. Keep this option for |
3688 | * backward compatibility. | |
3689 | */ | |
f3dcfada | 3690 | break; |
7e0af5d0 | 3691 | case QEMU_OPTION_startdate: |
1ed2fc1f JK |
3692 | configure_rtc_date_offset(optarg, 1); |
3693 | break; | |
3694 | case QEMU_OPTION_rtc: | |
3329f07b | 3695 | opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0); |
1ed2fc1f | 3696 | if (!opts) { |
1ed2fc1f | 3697 | exit(1); |
7e0af5d0 | 3698 | } |
1ed2fc1f | 3699 | configure_rtc(opts); |
7e0af5d0 | 3700 | break; |
26a5f13b | 3701 | case QEMU_OPTION_tb_size: |
d5ab9713 JK |
3702 | tcg_tb_size = strtol(optarg, NULL, 0); |
3703 | if (tcg_tb_size < 0) { | |
3704 | tcg_tb_size = 0; | |
3705 | } | |
26a5f13b | 3706 | break; |
2e70f6ef | 3707 | case QEMU_OPTION_icount: |
4e3de9e9 | 3708 | icount_option = optarg; |
2e70f6ef | 3709 | break; |
5bb7910a AL |
3710 | case QEMU_OPTION_incoming: |
3711 | incoming = optarg; | |
81323a6c | 3712 | runstate_set(RUN_STATE_INMIGRATE); |
5bb7910a | 3713 | break; |
d8c208dd GH |
3714 | case QEMU_OPTION_nodefaults: |
3715 | default_serial = 0; | |
3716 | default_parallel = 0; | |
aee1b935 | 3717 | default_virtcon = 0; |
2e788490 | 3718 | default_sclp = 0; |
d8c208dd | 3719 | default_monitor = 0; |
cb4522cc | 3720 | default_net = 0; |
ac33f8fa GH |
3721 | default_floppy = 0; |
3722 | default_cdrom = 0; | |
3723 | default_sdcard = 0; | |
7f1b17f2 | 3724 | default_vga = 0; |
d8c208dd | 3725 | break; |
e37630ca | 3726 | case QEMU_OPTION_xen_domid: |
ad96090a BS |
3727 | if (!(xen_available())) { |
3728 | printf("Option %s not supported for this target\n", popt->name); | |
3729 | exit(1); | |
3730 | } | |
e37630ca AL |
3731 | xen_domid = atoi(optarg); |
3732 | break; | |
3733 | case QEMU_OPTION_xen_create: | |
ad96090a BS |
3734 | if (!(xen_available())) { |
3735 | printf("Option %s not supported for this target\n", popt->name); | |
3736 | exit(1); | |
3737 | } | |
e37630ca AL |
3738 | xen_mode = XEN_CREATE; |
3739 | break; | |
3740 | case QEMU_OPTION_xen_attach: | |
ad96090a BS |
3741 | if (!(xen_available())) { |
3742 | printf("Option %s not supported for this target\n", popt->name); | |
3743 | exit(1); | |
3744 | } | |
e37630ca AL |
3745 | xen_mode = XEN_ATTACH; |
3746 | break; | |
ab6540d5 | 3747 | case QEMU_OPTION_trace: |
e4858974 | 3748 | { |
ab6540d5 | 3749 | opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0); |
e4858974 LV |
3750 | if (!opts) { |
3751 | exit(1); | |
ab6540d5 | 3752 | } |
23d15e86 | 3753 | trace_events = qemu_opt_get(opts, "events"); |
e4858974 | 3754 | trace_file = qemu_opt_get(opts, "file"); |
ab6540d5 | 3755 | break; |
e4858974 | 3756 | } |
715a664a GH |
3757 | case QEMU_OPTION_readconfig: |
3758 | { | |
dcfb0939 KW |
3759 | int ret = qemu_read_config_file(optarg); |
3760 | if (ret < 0) { | |
3761 | fprintf(stderr, "read config %s: %s\n", optarg, | |
3762 | strerror(-ret)); | |
715a664a GH |
3763 | exit(1); |
3764 | } | |
715a664a GH |
3765 | break; |
3766 | } | |
29b0040b GH |
3767 | case QEMU_OPTION_spice: |
3768 | olist = qemu_find_opts("spice"); | |
3769 | if (!olist) { | |
3770 | fprintf(stderr, "spice is not supported by this qemu build.\n"); | |
3771 | exit(1); | |
3772 | } | |
3773 | opts = qemu_opts_parse(olist, optarg, 0); | |
3774 | if (!opts) { | |
29b0040b GH |
3775 | exit(1); |
3776 | } | |
f963e4d0 | 3777 | display_remote++; |
29b0040b | 3778 | break; |
715a664a GH |
3779 | case QEMU_OPTION_writeconfig: |
3780 | { | |
3781 | FILE *fp; | |
3782 | if (strcmp(optarg, "-") == 0) { | |
3783 | fp = stdout; | |
3784 | } else { | |
3785 | fp = fopen(optarg, "w"); | |
3786 | if (fp == NULL) { | |
3787 | fprintf(stderr, "open %s: %s\n", optarg, strerror(errno)); | |
3788 | exit(1); | |
3789 | } | |
3790 | } | |
3791 | qemu_config_write(fp); | |
3792 | fclose(fp); | |
3793 | break; | |
3794 | } | |
c7f0f3b1 AL |
3795 | case QEMU_OPTION_qtest: |
3796 | qtest_chrdev = optarg; | |
3797 | break; | |
3798 | case QEMU_OPTION_qtest_log: | |
3799 | qtest_log = optarg; | |
3800 | break; | |
7d76ad4f EO |
3801 | case QEMU_OPTION_sandbox: |
3802 | opts = qemu_opts_parse(qemu_find_opts("sandbox"), optarg, 1); | |
3803 | if (!opts) { | |
49295ebc | 3804 | exit(1); |
7d76ad4f EO |
3805 | } |
3806 | break; | |
587ed6be CB |
3807 | case QEMU_OPTION_add_fd: |
3808 | #ifndef _WIN32 | |
3809 | opts = qemu_opts_parse(qemu_find_opts("add-fd"), optarg, 0); | |
3810 | if (!opts) { | |
49295ebc | 3811 | exit(1); |
587ed6be CB |
3812 | } |
3813 | #else | |
3814 | error_report("File descriptor passing is disabled on this " | |
3815 | "platform"); | |
3816 | exit(1); | |
3817 | #endif | |
3818 | break; | |
68d98d3e AL |
3819 | case QEMU_OPTION_object: |
3820 | opts = qemu_opts_parse(qemu_find_opts("object"), optarg, 1); | |
49295ebc MA |
3821 | if (!opts) { |
3822 | exit(1); | |
3823 | } | |
68d98d3e | 3824 | break; |
888a6bc6 SM |
3825 | case QEMU_OPTION_realtime: |
3826 | opts = qemu_opts_parse(qemu_find_opts("realtime"), optarg, 0); | |
3827 | if (!opts) { | |
3828 | exit(1); | |
3829 | } | |
3830 | configure_realtime(opts); | |
3831 | break; | |
5e2ac519 SA |
3832 | case QEMU_OPTION_msg: |
3833 | opts = qemu_opts_parse(qemu_find_opts("msg"), optarg, 0); | |
3834 | if (!opts) { | |
3835 | exit(1); | |
3836 | } | |
3837 | configure_msg(opts); | |
3838 | break; | |
59a5264b JS |
3839 | default: |
3840 | os_parse_cmd_args(popt->index, optarg); | |
cd6f1169 | 3841 | } |
0824d6fc FB |
3842 | } |
3843 | } | |
0f0bc3f1 | 3844 | loc_set_none(); |
c235d738 | 3845 | |
1c53786f PB |
3846 | if (qemu_init_main_loop()) { |
3847 | fprintf(stderr, "qemu_init_main_loop failed\n"); | |
3848 | exit(1); | |
3849 | } | |
3850 | ||
7d76ad4f EO |
3851 | if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 0)) { |
3852 | exit(1); | |
3853 | } | |
3854 | ||
587ed6be CB |
3855 | #ifndef _WIN32 |
3856 | if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL, 1)) { | |
3857 | exit(1); | |
3858 | } | |
3859 | ||
3860 | if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd, NULL, 1)) { | |
3861 | exit(1); | |
3862 | } | |
3863 | #endif | |
3864 | ||
fb7c269e DH |
3865 | if (machine == NULL) { |
3866 | fprintf(stderr, "No machine found.\n"); | |
3867 | exit(1); | |
3868 | } | |
3869 | ||
93bfef4c CV |
3870 | if (machine->hw_version) { |
3871 | qemu_set_version(machine->hw_version); | |
3872 | } | |
3873 | ||
68d98d3e AL |
3874 | if (qemu_opts_foreach(qemu_find_opts("object"), |
3875 | object_create, NULL, 0) != 0) { | |
3876 | exit(1); | |
3877 | } | |
3878 | ||
ecf40bea EH |
3879 | /* Init CPU def lists, based on config |
3880 | * - Must be called after all the qemu_read_config_file() calls | |
3881 | * - Must be called before list_cpus() | |
3882 | * - Must be called before machine->init() | |
3883 | */ | |
3884 | cpudef_init(); | |
3885 | ||
c8057f95 | 3886 | if (cpu_model && is_help_option(cpu_model)) { |
1d6528af | 3887 | list_cpus(stdout, &fprintf, cpu_model); |
ecf40bea EH |
3888 | exit(0); |
3889 | } | |
3890 | ||
c235d738 MF |
3891 | /* Open the logfile at this point, if necessary. We can't open the logfile |
3892 | * when encountering either of the logging options (-d or -D) because the | |
3893 | * other one may be encountered later on the command line, changing the | |
3894 | * location or level of logging. | |
3895 | */ | |
3896 | if (log_mask) { | |
b946bffa | 3897 | int mask; |
c235d738 | 3898 | if (log_file) { |
9a7e5424 | 3899 | qemu_set_log_filename(log_file); |
c235d738 | 3900 | } |
b946bffa PM |
3901 | |
3902 | mask = qemu_str_to_log_mask(log_mask); | |
3903 | if (!mask) { | |
3904 | qemu_print_log_usage(stdout); | |
3905 | exit(1); | |
3906 | } | |
3907 | qemu_set_log(mask); | |
c235d738 | 3908 | } |
330d0414 | 3909 | |
8a745f2a MM |
3910 | if (!is_daemonized()) { |
3911 | if (!trace_backend_init(trace_events, trace_file)) { | |
3912 | exit(1); | |
3913 | } | |
31d3c9b8 | 3914 | } |
0b5538c3 | 3915 | |
5cea8590 PB |
3916 | /* If no data_dir is specified then try to find it relative to the |
3917 | executable path. */ | |
4524051c | 3918 | if (data_dir_idx < ARRAY_SIZE(data_dir)) { |
10f5bff6 | 3919 | data_dir[data_dir_idx] = os_find_datadir(); |
4524051c GH |
3920 | if (data_dir[data_dir_idx] != NULL) { |
3921 | data_dir_idx++; | |
3922 | } | |
5cea8590 | 3923 | } |
60474fb5 | 3924 | /* If all else fails use the install path specified when building. */ |
4524051c GH |
3925 | if (data_dir_idx < ARRAY_SIZE(data_dir)) { |
3926 | data_dir[data_dir_idx++] = CONFIG_QEMU_DATADIR; | |
5cea8590 PB |
3927 | } |
3928 | ||
12b7f57e | 3929 | smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL)); |
6be68d7e | 3930 | |
3d878caa | 3931 | machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */ |
b2097003 AL |
3932 | if (smp_cpus > machine->max_cpus) { |
3933 | fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus " | |
3934 | "supported by machine `%s' (%d)\n", smp_cpus, machine->name, | |
3935 | machine->max_cpus); | |
3936 | exit(1); | |
3937 | } | |
3938 | ||
67b724e6 AP |
3939 | /* |
3940 | * Get the default machine options from the machine if it is not already | |
3941 | * specified either by the configuration file or by the command line. | |
3942 | */ | |
3943 | if (machine->default_machine_opts) { | |
25de5935 JK |
3944 | qemu_opts_set_defaults(qemu_find_opts("machine"), |
3945 | machine->default_machine_opts, 0); | |
67b724e6 AP |
3946 | } |
3947 | ||
3329f07b GH |
3948 | qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0); |
3949 | qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0); | |
998bbd74 | 3950 | |
986c5f78 GH |
3951 | if (machine->no_serial) { |
3952 | default_serial = 0; | |
3953 | } | |
3954 | if (machine->no_parallel) { | |
3955 | default_parallel = 0; | |
3956 | } | |
3957 | if (!machine->use_virtcon) { | |
3958 | default_virtcon = 0; | |
3959 | } | |
3ef669e1 AG |
3960 | if (!machine->use_sclp) { |
3961 | default_sclp = 0; | |
3962 | } | |
ac33f8fa GH |
3963 | if (machine->no_floppy) { |
3964 | default_floppy = 0; | |
3965 | } | |
3966 | if (machine->no_cdrom) { | |
3967 | default_cdrom = 0; | |
3968 | } | |
3969 | if (machine->no_sdcard) { | |
3970 | default_sdcard = 0; | |
3971 | } | |
986c5f78 | 3972 | |
ab51b1d5 MT |
3973 | if (is_daemonized()) { |
3974 | /* According to documentation and historically, -nographic redirects | |
3975 | * serial port, parallel port and monitor to stdio, which does not work | |
3976 | * with -daemonize. We can redirect these to null instead, but since | |
3977 | * -nographic is legacy, let's just error out. | |
3978 | * We disallow -nographic only if all other ports are not redirected | |
3979 | * explicitly, to not break existing legacy setups which uses | |
3980 | * -nographic _and_ redirects all ports explicitly - this is valid | |
3981 | * usage, -nographic is just a no-op in this case. | |
3982 | */ | |
3983 | if (display_type == DT_NOGRAPHIC | |
3984 | && (default_parallel || default_serial | |
3985 | || default_monitor || default_virtcon)) { | |
3986 | fprintf(stderr, "-nographic can not be used with -daemonize\n"); | |
3987 | exit(1); | |
3988 | } | |
3989 | #ifdef CONFIG_CURSES | |
3990 | if (display_type == DT_CURSES) { | |
3991 | fprintf(stderr, "curses display can not be used with -daemonize\n"); | |
3992 | exit(1); | |
3993 | } | |
3994 | #endif | |
3995 | } | |
3996 | ||
993fbfdb | 3997 | if (display_type == DT_NOGRAPHIC) { |
6a5e8b0e GH |
3998 | if (default_parallel) |
3999 | add_device_config(DEV_PARALLEL, "null"); | |
e1c09175 GH |
4000 | if (default_serial && default_monitor) { |
4001 | add_device_config(DEV_SERIAL, "mon:stdio"); | |
986c5f78 GH |
4002 | } else if (default_virtcon && default_monitor) { |
4003 | add_device_config(DEV_VIRTCON, "mon:stdio"); | |
3ef669e1 AG |
4004 | } else if (default_sclp && default_monitor) { |
4005 | add_device_config(DEV_SCLP, "mon:stdio"); | |
e1c09175 GH |
4006 | } else { |
4007 | if (default_serial) | |
4008 | add_device_config(DEV_SERIAL, "stdio"); | |
986c5f78 GH |
4009 | if (default_virtcon) |
4010 | add_device_config(DEV_VIRTCON, "stdio"); | |
3ef669e1 AG |
4011 | if (default_sclp) { |
4012 | add_device_config(DEV_SCLP, "stdio"); | |
4013 | } | |
e1c09175 | 4014 | if (default_monitor) |
6ca5582d | 4015 | monitor_parse("stdio", "readline"); |
e1c09175 | 4016 | } |
998bbd74 GH |
4017 | } else { |
4018 | if (default_serial) | |
4019 | add_device_config(DEV_SERIAL, "vc:80Cx24C"); | |
6a5e8b0e GH |
4020 | if (default_parallel) |
4021 | add_device_config(DEV_PARALLEL, "vc:80Cx24C"); | |
abdeed06 | 4022 | if (default_monitor) |
6ca5582d | 4023 | monitor_parse("vc:80Cx24C", "readline"); |
38536da1 AG |
4024 | if (default_virtcon) |
4025 | add_device_config(DEV_VIRTCON, "vc:80Cx24C"); | |
3ef669e1 AG |
4026 | if (default_sclp) { |
4027 | add_device_config(DEV_SCLP, "vc:80Cx24C"); | |
4028 | } | |
bc0129d9 AL |
4029 | } |
4030 | ||
15546425 AL |
4031 | if (display_type == DT_DEFAULT && !display_remote) { |
4032 | #if defined(CONFIG_GTK) | |
4033 | display_type = DT_GTK; | |
4034 | #elif defined(CONFIG_SDL) || defined(CONFIG_COCOA) | |
4035 | display_type = DT_SDL; | |
4036 | #elif defined(CONFIG_VNC) | |
4037 | vnc_display = "localhost:0,to=99"; | |
4038 | show_vnc_port = 1; | |
4039 | #else | |
4040 | display_type = DT_NONE; | |
4041 | #endif | |
4042 | } | |
4043 | ||
047d4e15 PW |
4044 | if ((no_frame || alt_grab || ctrl_grab) && display_type != DT_SDL) { |
4045 | fprintf(stderr, "-no-frame, -alt-grab and -ctrl-grab are only valid " | |
4046 | "for SDL, ignoring option\n"); | |
4047 | } | |
4048 | if (no_quit && (display_type != DT_GTK && display_type != DT_SDL)) { | |
4049 | fprintf(stderr, "-no-quit is only valid for GTK and SDL, " | |
4050 | "ignoring option\n"); | |
4051 | } | |
4052 | ||
15546425 AL |
4053 | #if defined(CONFIG_GTK) |
4054 | if (display_type == DT_GTK) { | |
4055 | early_gtk_display_init(); | |
4056 | } | |
4057 | #endif | |
4058 | ||
a5829fd9 T |
4059 | socket_init(); |
4060 | ||
3329f07b | 4061 | if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0) |
1a688d3b | 4062 | exit(1); |
758e8e38 | 4063 | #ifdef CONFIG_VIRTFS |
3329f07b | 4064 | if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) { |
74db920c GS |
4065 | exit(1); |
4066 | } | |
4067 | #endif | |
1a688d3b | 4068 | |
eb505be1 | 4069 | os_daemonize(); |
71e3ceb8 | 4070 | |
aa26bb2d | 4071 | if (pid_file && qemu_create_pidfile(pid_file) != 0) { |
eb505be1 | 4072 | os_pidfile_error(); |
93815bc2 TS |
4073 | exit(1); |
4074 | } | |
4075 | ||
0ac543de JK |
4076 | /* init the memory */ |
4077 | if (ram_size == 0) { | |
4078 | ram_size = DEFAULT_RAM_SIZE * 1024 * 1024; | |
4079 | } | |
4080 | ||
3d1d9652 BR |
4081 | if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) |
4082 | != 0) { | |
4083 | exit(0); | |
4084 | } | |
4085 | ||
135a129a | 4086 | configure_accelerator(machine); |
214910a7 | 4087 | |
d4fce24f | 4088 | if (qtest_chrdev) { |
23802b4f FZ |
4089 | Error *local_err = NULL; |
4090 | qtest_init(qtest_chrdev, qtest_log, &local_err); | |
4091 | if (local_err) { | |
4092 | error_report("%s", error_get_pretty(local_err)); | |
4093 | error_free(local_err); | |
4094 | exit(1); | |
4095 | } | |
a907cf59 EI |
4096 | } |
4097 | ||
2ff3de68 MA |
4098 | machine_opts = qemu_get_machine_opts(); |
4099 | kernel_filename = qemu_opt_get(machine_opts, "kernel"); | |
4100 | initrd_filename = qemu_opt_get(machine_opts, "initrd"); | |
4101 | kernel_cmdline = qemu_opt_get(machine_opts, "append"); | |
1442d3e6 | 4102 | bios_name = qemu_opt_get(machine_opts, "firmware"); |
967c0da7 | 4103 | |
e3fdc535 | 4104 | boot_order = machine->default_boot_order; |
8281abd5 MA |
4105 | opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL); |
4106 | if (opts) { | |
4107 | char *normal_boot_order; | |
4108 | const char *order, *once; | |
4109 | ||
4110 | order = qemu_opt_get(opts, "order"); | |
4111 | if (order) { | |
4112 | validate_bootdevices(order); | |
4113 | boot_order = order; | |
4114 | } | |
4115 | ||
4116 | once = qemu_opt_get(opts, "once"); | |
4117 | if (once) { | |
4118 | validate_bootdevices(once); | |
4119 | normal_boot_order = g_strdup(boot_order); | |
4120 | boot_order = once; | |
083b79c9 | 4121 | qemu_register_reset(restore_boot_order, normal_boot_order); |
8281abd5 MA |
4122 | } |
4123 | ||
4124 | boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu); | |
e5187b56 | 4125 | boot_strict = qemu_opt_get_bool(opts, "strict", false); |
8281abd5 MA |
4126 | } |
4127 | ||
a0abe474 PM |
4128 | if (!kernel_cmdline) { |
4129 | kernel_cmdline = ""; | |
4130 | } | |
4131 | ||
a20dd508 | 4132 | linux_boot = (kernel_filename != NULL); |
6c41b272 | 4133 | |
f8d39c01 TS |
4134 | if (!linux_boot && *kernel_cmdline != '\0') { |
4135 | fprintf(stderr, "-append only allowed with -kernel option\n"); | |
4136 | exit(1); | |
4137 | } | |
4138 | ||
4139 | if (!linux_boot && initrd_filename != NULL) { | |
4140 | fprintf(stderr, "-initrd only allowed with -kernel option\n"); | |
4141 | exit(1); | |
4142 | } | |
4143 | ||
2ff3de68 | 4144 | if (!linux_boot && qemu_opt_get(machine_opts, "dtb")) { |
412beee6 GL |
4145 | fprintf(stderr, "-dtb only allowed with -kernel option\n"); |
4146 | exit(1); | |
4147 | } | |
4148 | ||
9156d763 | 4149 | os_set_line_buffering(); |
3b46e624 | 4150 | |
49cf5728 PB |
4151 | qemu_init_cpu_loop(); |
4152 | qemu_mutex_lock_iothread(); | |
4153 | ||
ad1be899 AL |
4154 | #ifdef CONFIG_SPICE |
4155 | /* spice needs the timers to be initialized by this point */ | |
4156 | qemu_spice_init(); | |
4157 | #endif | |
4158 | ||
0abe905d MF |
4159 | if (icount_option && (kvm_enabled() || xen_enabled())) { |
4160 | fprintf(stderr, "-icount is not allowed with kvm or xen\n"); | |
4161 | exit(1); | |
4162 | } | |
4e3de9e9 | 4163 | configure_icount(icount_option); |
634fce96 | 4164 | |
f30dbae6 AK |
4165 | /* clean up network at qemu process termination */ |
4166 | atexit(&net_cleanup); | |
4167 | ||
dc1c9fe8 MM |
4168 | if (net_init_clients() < 0) { |
4169 | exit(1); | |
702c651c | 4170 | } |
f1510b2c | 4171 | |
d1a0cf73 SB |
4172 | #ifdef CONFIG_TPM |
4173 | if (tpm_init() < 0) { | |
4174 | exit(1); | |
4175 | } | |
4176 | #endif | |
4177 | ||
dc72ac14 | 4178 | /* init the bluetooth world */ |
bd3c948d GH |
4179 | if (foreach_device_config(DEV_BT, bt_parse)) |
4180 | exit(1); | |
dc72ac14 | 4181 | |
834e76ea AP |
4182 | if (!xen_enabled()) { |
4183 | /* On 32-bit hosts, QEMU is limited by virtual address space */ | |
4184 | if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) { | |
4185 | fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n"); | |
4186 | exit(1); | |
4187 | } | |
4188 | } | |
9ae02555 | 4189 | |
d5ab9713 | 4190 | cpu_exec_init_all(); |
26a5f13b | 4191 | |
c163b5ca LS |
4192 | blk_mig_init(); |
4193 | ||
e4bcb14c | 4194 | /* open the virtual block devices */ |
9dfd7c7a | 4195 | if (snapshot) |
3329f07b | 4196 | qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0); |
2d0d2837 CB |
4197 | if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, |
4198 | &machine->block_default_type, 1) != 0) { | |
9dfd7c7a | 4199 | exit(1); |
2d0d2837 | 4200 | } |
3e3d5815 | 4201 | |
3c42ea66 CB |
4202 | default_drive(default_cdrom, snapshot, machine->block_default_type, 2, |
4203 | CDROM_OPTS); | |
4204 | default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS); | |
4205 | default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS); | |
4e5d9b57 | 4206 | |
7908c78d | 4207 | register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL); |
8a7ddc38 | 4208 | |
268a362c AL |
4209 | if (nb_numa_nodes > 0) { |
4210 | int i; | |
4211 | ||
ea0e5418 SL |
4212 | if (nb_numa_nodes > MAX_NODES) { |
4213 | nb_numa_nodes = MAX_NODES; | |
268a362c AL |
4214 | } |
4215 | ||
4216 | /* If no memory size if given for any node, assume the default case | |
4217 | * and distribute the available memory equally across all nodes | |
4218 | */ | |
4219 | for (i = 0; i < nb_numa_nodes; i++) { | |
4220 | if (node_mem[i] != 0) | |
4221 | break; | |
4222 | } | |
4223 | if (i == nb_numa_nodes) { | |
4224 | uint64_t usedmem = 0; | |
4225 | ||
4226 | /* On Linux, the each node's border has to be 8MB aligned, | |
4227 | * the final node gets the rest. | |
4228 | */ | |
4229 | for (i = 0; i < nb_numa_nodes - 1; i++) { | |
4230 | node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1); | |
4231 | usedmem += node_mem[i]; | |
4232 | } | |
4233 | node_mem[i] = ram_size - usedmem; | |
4234 | } | |
4235 | ||
4236 | for (i = 0; i < nb_numa_nodes; i++) { | |
ee785fed | 4237 | if (!bitmap_empty(node_cpumask[i], MAX_CPUMASK_BITS)) { |
268a362c | 4238 | break; |
ee785fed | 4239 | } |
268a362c AL |
4240 | } |
4241 | /* assigning the VCPUs round-robin is easier to implement, guest OSes | |
4242 | * must cope with this anyway, because there are BIOSes out there in | |
4243 | * real machines which also use this scheme. | |
4244 | */ | |
4245 | if (i == nb_numa_nodes) { | |
991dfefd | 4246 | for (i = 0; i < max_cpus; i++) { |
ee785fed | 4247 | set_bit(i, node_cpumask[i % nb_numa_nodes]); |
268a362c AL |
4248 | } |
4249 | } | |
4250 | } | |
4251 | ||
3329f07b | 4252 | if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) { |
157b9319 JK |
4253 | exit(1); |
4254 | } | |
4255 | ||
998bbd74 GH |
4256 | if (foreach_device_config(DEV_SERIAL, serial_parse) < 0) |
4257 | exit(1); | |
6a5e8b0e GH |
4258 | if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) |
4259 | exit(1); | |
aee1b935 GH |
4260 | if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0) |
4261 | exit(1); | |
3ef669e1 AG |
4262 | if (foreach_device_config(DEV_SCLP, sclp_parse) < 0) { |
4263 | exit(1); | |
4264 | } | |
c9f398e5 PA |
4265 | if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0) |
4266 | exit(1); | |
2796dae0 | 4267 | |
7f1b17f2 | 4268 | /* If no default VGA is requested, the default is "none". */ |
3605ded5 AJ |
4269 | if (default_vga) { |
4270 | if (cirrus_vga_available()) { | |
4271 | vga_model = "cirrus"; | |
4272 | } else if (vga_available()) { | |
4273 | vga_model = "std"; | |
4274 | } | |
a369da5f | 4275 | } |
7f1b17f2 | 4276 | select_vgahw(vga_model); |
a369da5f | 4277 | |
09aaa160 MA |
4278 | if (watchdog) { |
4279 | i = select_watchdog(watchdog); | |
4280 | if (i > 0) | |
4281 | exit (i == 1 ? 1 : 0); | |
4282 | } | |
4283 | ||
b6b61144 | 4284 | if (machine->compat_props) { |
458fb679 | 4285 | qdev_prop_register_global_list(machine->compat_props); |
b6b61144 | 4286 | } |
d0fef6fb GH |
4287 | qemu_add_globals(); |
4288 | ||
1de81d28 AL |
4289 | qdev_machine_init(); |
4290 | ||
e689f7c6 MA |
4291 | QEMUMachineInitArgs args = { .machine = machine, |
4292 | .ram_size = ram_size, | |
c1654732 | 4293 | .boot_order = boot_order, |
5f072e1f EH |
4294 | .kernel_filename = kernel_filename, |
4295 | .kernel_cmdline = kernel_cmdline, | |
4296 | .initrd_filename = initrd_filename, | |
4297 | .cpu_model = cpu_model }; | |
4298 | machine->init(&args); | |
3023f332 | 4299 | |
b3e6d591 PB |
4300 | audio_init(); |
4301 | ||
ea375f9a | 4302 | cpu_synchronize_all_post_init(); |
268a362c | 4303 | |
87d0a28e | 4304 | set_numa_modes(); |
268a362c | 4305 | |
6f338c34 AL |
4306 | current_machine = machine; |
4307 | ||
3023f332 | 4308 | /* init USB devices */ |
094b287f | 4309 | if (usb_enabled(false)) { |
0752706d MA |
4310 | if (foreach_device_config(DEV_USB, usb_parse) < 0) |
4311 | exit(1); | |
3023f332 AL |
4312 | } |
4313 | ||
bd3c948d | 4314 | /* init generic devices */ |
3329f07b | 4315 | if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0) |
bd3c948d GH |
4316 | exit(1); |
4317 | ||
668680f7 MA |
4318 | net_check_clients(); |
4319 | ||
64840c66 | 4320 | ds = init_displaystate(); |
993fbfdb | 4321 | |
6b62dc2d | 4322 | /* init local displays */ |
993fbfdb AL |
4323 | switch (display_type) { |
4324 | case DT_NOGRAPHIC: | |
8111d028 | 4325 | (void)ds; /* avoid warning if no display is configured */ |
993fbfdb | 4326 | break; |
4d3b6f6e | 4327 | #if defined(CONFIG_CURSES) |
993fbfdb | 4328 | case DT_CURSES: |
ab51b1d5 | 4329 | curses_display_init(ds, full_screen); |
993fbfdb | 4330 | break; |
4d3b6f6e | 4331 | #endif |
5b0753e0 | 4332 | #if defined(CONFIG_SDL) |
993fbfdb AL |
4333 | case DT_SDL: |
4334 | sdl_display_init(ds, full_screen, no_frame); | |
4335 | break; | |
5b0753e0 | 4336 | #elif defined(CONFIG_COCOA) |
993fbfdb AL |
4337 | case DT_SDL: |
4338 | cocoa_display_init(ds, full_screen); | |
4339 | break; | |
15546425 AL |
4340 | #endif |
4341 | #if defined(CONFIG_GTK) | |
4342 | case DT_GTK: | |
787ba4f0 | 4343 | gtk_display_init(ds, full_screen); |
15546425 | 4344 | break; |
313aa567 | 4345 | #endif |
6b62dc2d GH |
4346 | default: |
4347 | break; | |
4348 | } | |
4349 | ||
0ce235a7 GN |
4350 | /* must be after terminal init, SDL library changes signal handlers */ |
4351 | os_setup_signal_handling(); | |
4352 | ||
821601ea | 4353 | #ifdef CONFIG_VNC |
6b62dc2d GH |
4354 | /* init remote displays */ |
4355 | if (vnc_display) { | |
2d55f0e8 | 4356 | Error *local_err = NULL; |
993fbfdb | 4357 | vnc_display_init(ds); |
2d55f0e8 PB |
4358 | vnc_display_open(ds, vnc_display, &local_err); |
4359 | if (local_err != NULL) { | |
4a44d85e SA |
4360 | error_report("Failed to start VNC server on `%s': %s", |
4361 | vnc_display, error_get_pretty(local_err)); | |
2d55f0e8 | 4362 | error_free(local_err); |
993fbfdb | 4363 | exit(1); |
94b204ca | 4364 | } |
f92f8afe | 4365 | |
993fbfdb AL |
4366 | if (show_vnc_port) { |
4367 | printf("VNC server running on `%s'\n", vnc_display_local_addr(ds)); | |
f92f8afe | 4368 | } |
313aa567 | 4369 | } |
821601ea | 4370 | #endif |
a3e22260 | 4371 | #ifdef CONFIG_SPICE |
9fa03286 GH |
4372 | if (using_spice) { |
4373 | qemu_spice_display_init(); | |
a3e22260 GH |
4374 | } |
4375 | #endif | |
5b08fc10 | 4376 | |
ef0c4a0d | 4377 | if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) { |
59030a8c | 4378 | exit(1); |
45669e00 | 4379 | } |
45669e00 | 4380 | |
3418bd25 GH |
4381 | qdev_machine_creation_done(); |
4382 | ||
15ff7705 GH |
4383 | if (rom_load_all() != 0) { |
4384 | fprintf(stderr, "rom loading failed\n"); | |
4385 | exit(1); | |
4386 | } | |
45a50b16 | 4387 | |
80376c3f IY |
4388 | /* TODO: once all bus devices are qdevified, this should be done |
4389 | * when bus is created by qdev.c */ | |
4390 | qemu_register_reset(qbus_reset_all_fn, sysbus_get_default()); | |
4cab946a GN |
4391 | qemu_run_machine_init_done_notifiers(); |
4392 | ||
d916b464 MT |
4393 | /* Done notifiers can load ROMs */ |
4394 | rom_load_done(); | |
4395 | ||
e063eb1f | 4396 | qemu_system_reset(VMRESET_SILENT); |
05f2401e | 4397 | if (loadvm) { |
03cd4655 | 4398 | if (load_vmstate(loadvm) < 0) { |
05f2401e JQ |
4399 | autostart = 0; |
4400 | } | |
4401 | } | |
d63d307f | 4402 | |
2bb8c10c | 4403 | if (incoming) { |
43eaae28 PB |
4404 | Error *local_err = NULL; |
4405 | qemu_start_incoming_migration(incoming, &local_err); | |
4406 | if (local_err) { | |
4a44d85e SA |
4407 | error_report("-incoming %s: %s", incoming, |
4408 | error_get_pretty(local_err)); | |
43eaae28 PB |
4409 | error_free(local_err); |
4410 | exit(1); | |
8ca5e801 | 4411 | } |
6b99dadc | 4412 | } else if (autostart) { |
c0f4ce77 | 4413 | vm_start(); |
6b99dadc | 4414 | } |
ffd843bc | 4415 | |
eb505be1 | 4416 | os_setup_post(); |
71e3ceb8 | 4417 | |
8a745f2a MM |
4418 | if (is_daemonized()) { |
4419 | if (!trace_backend_init(trace_events, trace_file)) { | |
4420 | exit(1); | |
4421 | } | |
4422 | } | |
4423 | ||
8a7ddc38 | 4424 | main_loop(); |
99435906 PB |
4425 | bdrv_close_all(); |
4426 | pause_all_vcpus(); | |
3d3b8303 | 4427 | res_free(); |
d1a0cf73 SB |
4428 | #ifdef CONFIG_TPM |
4429 | tpm_cleanup(); | |
4430 | #endif | |
b46a8906 | 4431 | |
0824d6fc FB |
4432 | return 0; |
4433 | } |