4 * Copyright (c) 2003-2008 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
24 #include "qemu/osdep.h"
25 #include "qemu-version.h"
26 #include "qemu/cutils.h"
27 #include "qemu/help_option.h"
28 #include "qemu/uuid.h"
31 #include "sysemu/seccomp.h"
34 #if defined(CONFIG_VDE)
35 #include <libvdeplug.h>
39 #if defined(__APPLE__) || defined(main)
41 int qemu_main(int argc
, char **argv
, char **envp
);
42 int main(int argc
, char **argv
)
44 return qemu_main(argc
, argv
, NULL
);
47 #define main qemu_main
49 #endif /* CONFIG_SDL */
53 #define main qemu_main
54 #endif /* CONFIG_COCOA */
57 #include "qemu/error-report.h"
58 #include "qemu/sockets.h"
60 #include "hw/boards.h"
61 #include "sysemu/accel.h"
63 #include "hw/i386/pc.h"
64 #include "hw/isa/isa.h"
65 #include "hw/scsi/scsi.h"
67 #include "sysemu/watchdog.h"
68 #include "hw/smbios/smbios.h"
69 #include "hw/acpi/acpi.h"
70 #include "hw/xen/xen.h"
72 #include "hw/loader.h"
73 #include "monitor/qdev.h"
74 #include "sysemu/bt.h"
76 #include "net/slirp.h"
77 #include "monitor/monitor.h"
78 #include "ui/console.h"
80 #include "sysemu/sysemu.h"
81 #include "sysemu/numa.h"
82 #include "exec/gdbstub.h"
83 #include "qemu/timer.h"
84 #include "sysemu/char.h"
85 #include "qemu/bitmap.h"
87 #include "sysemu/blockdev.h"
88 #include "hw/block/block.h"
89 #include "migration/block.h"
90 #include "sysemu/tpm.h"
91 #include "sysemu/dma.h"
92 #include "hw/audio/audio.h"
93 #include "audio/audio.h"
94 #include "migration/migration.h"
95 #include "sysemu/cpus.h"
96 #include "migration/colo.h"
97 #include "sysemu/kvm.h"
98 #include "sysemu/hax.h"
99 #include "qapi/qobject-input-visitor.h"
100 #include "qapi/qobject-input-visitor.h"
101 #include "qapi-visit.h"
102 #include "qapi/qmp/qjson.h"
103 #include "qemu/option.h"
104 #include "qemu/config-file.h"
105 #include "qemu-options.h"
106 #include "qmp-commands.h"
107 #include "qemu/main-loop.h"
109 #include "fsdev/qemu-fsdev.h"
111 #include "sysemu/qtest.h"
113 #include "disas/disas.h"
116 #include "slirp/libslirp.h"
118 #include "trace-root.h"
119 #include "trace/control.h"
120 #include "qemu/queue.h"
121 #include "sysemu/arch_init.h"
123 #include "ui/qemu-spice.h"
124 #include "qapi/string-input-visitor.h"
125 #include "qapi/opts-visitor.h"
126 #include "qom/object_interfaces.h"
127 #include "qapi-event.h"
128 #include "exec/semihost.h"
129 #include "crypto/init.h"
130 #include "sysemu/replay.h"
131 #include "qapi/qmp/qerror.h"
132 #include "sysemu/iothread.h"
134 #define MAX_VIRTIO_CONSOLES 1
135 #define MAX_SCLP_CONSOLES 1
137 static const char *data_dir
[16];
138 static int data_dir_idx
;
139 const char *bios_name
= NULL
;
140 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
141 int request_opengl
= -1;
143 const char* keyboard_layout
= NULL
;
145 const char *mem_path
= NULL
;
146 int mem_prealloc
= 0; /* force preallocation of physical target memory */
147 bool enable_mlock
= false;
149 NICInfo nd_table
[MAX_NICS
];
151 static int rtc_utc
= 1;
152 static int rtc_date_offset
= -1; /* -1 means no change */
153 QEMUClockType rtc_clock
;
154 int vga_interface_type
= VGA_NONE
;
155 static int full_screen
= 0;
156 static int no_frame
= 0;
158 static bool grab_on_hover
;
159 Chardev
*serial_hds
[MAX_SERIAL_PORTS
];
160 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
161 Chardev
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
162 Chardev
*sclp_hds
[MAX_SCLP_CONSOLES
];
163 int win2k_install_hack
= 0;
169 int acpi_enabled
= 1;
172 static int no_reboot
;
175 int graphic_rotate
= 0;
176 const char *watchdog
;
177 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
180 const char *qemu_name
;
183 unsigned int nb_prom_envs
= 0;
184 const char *prom_envs
[MAX_PROM_ENVS
];
187 uint8_t *boot_splash_filedata
;
188 size_t boot_splash_filedata_size
;
189 uint8_t qemu_extra_params_fw
[2];
190 int only_migratable
; /* turn it off unless user states otherwise */
192 int icount_align_option
;
194 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
195 * little-endian "wire format" described in the SMBIOS 2.6 specification.
200 static NotifierList exit_notifiers
=
201 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
203 static NotifierList machine_init_done_notifiers
=
204 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
208 enum xen_mode xen_mode
= XEN_EMULATE
;
209 bool xen_domid_restrict
;
211 static int has_defaults
= 1;
212 static int default_serial
= 1;
213 static int default_parallel
= 1;
214 static int default_virtcon
= 1;
215 static int default_sclp
= 1;
216 static int default_monitor
= 1;
217 static int default_floppy
= 1;
218 static int default_cdrom
= 1;
219 static int default_sdcard
= 1;
220 static int default_vga
= 1;
221 static int default_net
= 1;
227 { .driver
= "isa-serial", .flag
= &default_serial
},
228 { .driver
= "isa-parallel", .flag
= &default_parallel
},
229 { .driver
= "isa-fdc", .flag
= &default_floppy
},
230 { .driver
= "floppy", .flag
= &default_floppy
},
231 { .driver
= "ide-cd", .flag
= &default_cdrom
},
232 { .driver
= "ide-hd", .flag
= &default_cdrom
},
233 { .driver
= "ide-drive", .flag
= &default_cdrom
},
234 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
235 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
236 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
237 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
238 { .driver
= "VGA", .flag
= &default_vga
},
239 { .driver
= "isa-vga", .flag
= &default_vga
},
240 { .driver
= "cirrus-vga", .flag
= &default_vga
},
241 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
242 { .driver
= "vmware-svga", .flag
= &default_vga
},
243 { .driver
= "qxl-vga", .flag
= &default_vga
},
244 { .driver
= "virtio-vga", .flag
= &default_vga
},
247 static QemuOptsList qemu_rtc_opts
= {
249 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
253 .type
= QEMU_OPT_STRING
,
256 .type
= QEMU_OPT_STRING
,
259 .type
= QEMU_OPT_STRING
,
261 { /* end of list */ }
265 static QemuOptsList qemu_sandbox_opts
= {
267 .implied_opt_name
= "enable",
268 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
272 .type
= QEMU_OPT_BOOL
,
274 { /* end of list */ }
278 static QemuOptsList qemu_option_rom_opts
= {
279 .name
= "option-rom",
280 .implied_opt_name
= "romfile",
281 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
285 .type
= QEMU_OPT_NUMBER
,
288 .type
= QEMU_OPT_STRING
,
290 { /* end of list */ }
294 static QemuOptsList qemu_machine_opts
= {
296 .implied_opt_name
= "type",
298 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
301 * no elements => accept any
302 * sanity checking will happen later
303 * when setting machine properties
309 static QemuOptsList qemu_accel_opts
= {
311 .implied_opt_name
= "accel",
312 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
317 .type
= QEMU_OPT_STRING
,
318 .help
= "Select the type of accelerator",
322 .type
= QEMU_OPT_STRING
,
323 .help
= "Enable/disable multi-threaded TCG",
325 { /* end of list */ }
329 static QemuOptsList qemu_boot_opts
= {
331 .implied_opt_name
= "order",
333 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
337 .type
= QEMU_OPT_STRING
,
340 .type
= QEMU_OPT_STRING
,
343 .type
= QEMU_OPT_BOOL
,
346 .type
= QEMU_OPT_STRING
,
348 .name
= "splash-time",
349 .type
= QEMU_OPT_STRING
,
351 .name
= "reboot-timeout",
352 .type
= QEMU_OPT_STRING
,
355 .type
= QEMU_OPT_BOOL
,
361 static QemuOptsList qemu_add_fd_opts
= {
363 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
367 .type
= QEMU_OPT_NUMBER
,
368 .help
= "file descriptor of which a duplicate is added to fd set",
371 .type
= QEMU_OPT_NUMBER
,
372 .help
= "ID of the fd set to add fd to",
375 .type
= QEMU_OPT_STRING
,
376 .help
= "free-form string used to describe fd",
378 { /* end of list */ }
382 static QemuOptsList qemu_object_opts
= {
384 .implied_opt_name
= "qom-type",
385 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
391 static QemuOptsList qemu_tpmdev_opts
= {
393 .implied_opt_name
= "type",
394 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
396 /* options are defined in the TPM backends */
397 { /* end of list */ }
401 static QemuOptsList qemu_realtime_opts
= {
403 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
407 .type
= QEMU_OPT_BOOL
,
409 { /* end of list */ }
413 static QemuOptsList qemu_msg_opts
= {
415 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
419 .type
= QEMU_OPT_BOOL
,
421 { /* end of list */ }
425 static QemuOptsList qemu_name_opts
= {
427 .implied_opt_name
= "guest",
429 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
433 .type
= QEMU_OPT_STRING
,
434 .help
= "Sets the name of the guest.\n"
435 "This name will be displayed in the SDL window caption.\n"
436 "The name will also be used for the VNC server",
439 .type
= QEMU_OPT_STRING
,
440 .help
= "Sets the name of the QEMU process, as shown in top etc",
442 .name
= "debug-threads",
443 .type
= QEMU_OPT_BOOL
,
444 .help
= "When enabled, name the individual threads; defaults off.\n"
445 "NOTE: The thread names are for debugging and not a\n"
448 { /* End of list */ }
452 static QemuOptsList qemu_mem_opts
= {
454 .implied_opt_name
= "size",
455 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
460 .type
= QEMU_OPT_SIZE
,
464 .type
= QEMU_OPT_NUMBER
,
468 .type
= QEMU_OPT_SIZE
,
470 { /* end of list */ }
474 static QemuOptsList qemu_icount_opts
= {
476 .implied_opt_name
= "shift",
478 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
482 .type
= QEMU_OPT_STRING
,
485 .type
= QEMU_OPT_BOOL
,
488 .type
= QEMU_OPT_BOOL
,
491 .type
= QEMU_OPT_STRING
,
494 .type
= QEMU_OPT_STRING
,
496 .name
= "rrsnapshot",
497 .type
= QEMU_OPT_STRING
,
499 { /* end of list */ }
503 static QemuOptsList qemu_semihosting_config_opts
= {
504 .name
= "semihosting-config",
505 .implied_opt_name
= "enable",
506 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
510 .type
= QEMU_OPT_BOOL
,
513 .type
= QEMU_OPT_STRING
,
516 .type
= QEMU_OPT_STRING
,
518 { /* end of list */ }
522 static QemuOptsList qemu_fw_cfg_opts
= {
524 .implied_opt_name
= "name",
525 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
529 .type
= QEMU_OPT_STRING
,
530 .help
= "Sets the fw_cfg name of the blob to be inserted",
533 .type
= QEMU_OPT_STRING
,
534 .help
= "Sets the name of the file from which\n"
535 "the fw_cfg blob will be loaded",
538 .type
= QEMU_OPT_STRING
,
539 .help
= "Sets content of the blob to be inserted from a string",
541 { /* end of list */ }
546 * Get machine options
548 * Returns: machine options (never null).
550 QemuOpts
*qemu_get_machine_opts(void)
552 return qemu_find_opts_singleton("machine");
555 const char *qemu_get_vm_name(void)
560 static void res_free(void)
562 g_free(boot_splash_filedata
);
563 boot_splash_filedata
= NULL
;
566 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
568 const char *driver
= qemu_opt_get(opts
, "driver");
573 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
574 if (strcmp(default_list
[i
].driver
, driver
) != 0)
576 *(default_list
[i
].flag
) = 0;
581 /***********************************************************/
584 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
586 /* We use RUN_STATE__MAX but any invalid value will do */
587 static RunState vmstop_requested
= RUN_STATE__MAX
;
588 static QemuMutex vmstop_lock
;
593 } RunStateTransition
;
595 static const RunStateTransition runstate_transitions_def
[] = {
597 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
598 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
599 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
601 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
602 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
603 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
604 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
605 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
606 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
607 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
608 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
609 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
610 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
611 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
612 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
614 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
615 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
616 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
618 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
619 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
620 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
622 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
623 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
624 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
625 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
627 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
628 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
629 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
631 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
632 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
633 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
635 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
636 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
637 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
638 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
640 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
641 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
643 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
645 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
646 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
647 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
648 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
649 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
650 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
651 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
652 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
653 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
654 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
655 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
657 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
659 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
660 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
661 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
663 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
664 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
665 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
666 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
667 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
668 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
670 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
671 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
672 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
673 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
675 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
676 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
677 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
679 { RUN_STATE__MAX
, RUN_STATE__MAX
},
682 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
684 bool runstate_check(RunState state
)
686 return current_run_state
== state
;
689 bool runstate_store(char *str
, size_t size
)
691 const char *state
= RunState_lookup
[current_run_state
];
692 size_t len
= strlen(state
) + 1;
697 memcpy(str
, state
, len
);
701 static void runstate_init(void)
703 const RunStateTransition
*p
;
705 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
706 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
707 runstate_valid_transitions
[p
->from
][p
->to
] = true;
710 qemu_mutex_init(&vmstop_lock
);
713 /* This function will abort() on invalid state transitions */
714 void runstate_set(RunState new_state
)
716 assert(new_state
< RUN_STATE__MAX
);
718 if (current_run_state
== new_state
) {
722 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
723 error_report("invalid runstate transition: '%s' -> '%s'",
724 RunState_lookup
[current_run_state
],
725 RunState_lookup
[new_state
]);
728 trace_runstate_set(new_state
);
729 current_run_state
= new_state
;
732 int runstate_is_running(void)
734 return runstate_check(RUN_STATE_RUNNING
);
737 bool runstate_needs_reset(void)
739 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
740 runstate_check(RUN_STATE_SHUTDOWN
);
743 StatusInfo
*qmp_query_status(Error
**errp
)
745 StatusInfo
*info
= g_malloc0(sizeof(*info
));
747 info
->running
= runstate_is_running();
748 info
->singlestep
= singlestep
;
749 info
->status
= current_run_state
;
754 bool qemu_vmstop_requested(RunState
*r
)
756 qemu_mutex_lock(&vmstop_lock
);
757 *r
= vmstop_requested
;
758 vmstop_requested
= RUN_STATE__MAX
;
759 qemu_mutex_unlock(&vmstop_lock
);
760 return *r
< RUN_STATE__MAX
;
763 void qemu_system_vmstop_request_prepare(void)
765 qemu_mutex_lock(&vmstop_lock
);
768 void qemu_system_vmstop_request(RunState state
)
770 vmstop_requested
= state
;
771 qemu_mutex_unlock(&vmstop_lock
);
775 /***********************************************************/
776 /* real time host monotonic timer */
778 static time_t qemu_time(void)
780 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
783 /***********************************************************/
784 /* host time/date access */
785 void qemu_get_timedate(struct tm
*tm
, int offset
)
787 time_t ti
= qemu_time();
790 if (rtc_date_offset
== -1) {
794 localtime_r(&ti
, tm
);
796 ti
-= rtc_date_offset
;
801 int qemu_timedate_diff(struct tm
*tm
)
805 if (rtc_date_offset
== -1)
807 seconds
= mktimegm(tm
);
810 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
811 seconds
= mktime(&tmp
);
814 seconds
= mktimegm(tm
) + rtc_date_offset
;
816 return seconds
- qemu_time();
819 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
821 time_t rtc_start_date
;
824 if (!strcmp(startdate
, "now") && legacy
) {
825 rtc_date_offset
= -1;
827 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
835 } else if (sscanf(startdate
, "%d-%d-%d",
847 rtc_start_date
= mktimegm(&tm
);
848 if (rtc_start_date
== -1) {
850 error_report("invalid date format");
851 error_printf("valid formats: "
852 "'2006-06-17T16:01:21' or '2006-06-17'\n");
855 rtc_date_offset
= qemu_time() - rtc_start_date
;
859 static void configure_rtc(QemuOpts
*opts
)
863 value
= qemu_opt_get(opts
, "base");
865 if (!strcmp(value
, "utc")) {
867 } else if (!strcmp(value
, "localtime")) {
868 Error
*blocker
= NULL
;
870 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
871 "-rtc base=localtime");
872 replay_add_blocker(blocker
);
874 configure_rtc_date_offset(value
, 0);
877 value
= qemu_opt_get(opts
, "clock");
879 if (!strcmp(value
, "host")) {
880 rtc_clock
= QEMU_CLOCK_HOST
;
881 } else if (!strcmp(value
, "rt")) {
882 rtc_clock
= QEMU_CLOCK_REALTIME
;
883 } else if (!strcmp(value
, "vm")) {
884 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
886 error_report("invalid option value '%s'", value
);
890 value
= qemu_opt_get(opts
, "driftfix");
892 if (!strcmp(value
, "slew")) {
893 static GlobalProperty slew_lost_ticks
= {
894 .driver
= "mc146818rtc",
895 .property
= "lost_tick_policy",
899 qdev_prop_register_global(&slew_lost_ticks
);
900 } else if (!strcmp(value
, "none")) {
901 /* discard is default */
903 error_report("invalid option value '%s'", value
);
909 /***********************************************************/
910 /* Bluetooth support */
913 static struct HCIInfo
*hci_table
[MAX_NICS
];
915 struct HCIInfo
*qemu_next_hci(void)
917 if (cur_hci
== nb_hcis
)
920 return hci_table
[cur_hci
++];
923 static int bt_hci_parse(const char *str
)
928 if (nb_hcis
>= MAX_NICS
) {
929 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
942 bdaddr
.b
[5] = 0x56 + nb_hcis
;
943 hci
->bdaddr_set(hci
, bdaddr
.b
);
945 hci_table
[nb_hcis
++] = hci
;
950 static void bt_vhci_add(int vlan_id
)
952 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
955 error_report("warning: adding a VHCI to an empty scatternet %i",
958 bt_vhci_init(bt_new_hci(vlan
));
961 static struct bt_device_s
*bt_device_add(const char *opt
)
963 struct bt_scatternet_s
*vlan
;
965 char *endp
= strstr(opt
, ",vlan=");
966 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
969 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
972 vlan_id
= strtol(endp
+ 6, &endp
, 0);
974 error_report("unrecognised bluetooth vlan Id");
979 vlan
= qemu_find_bt_vlan(vlan_id
);
982 error_report("warning: adding a slave device to an empty scatternet %i",
985 if (!strcmp(devname
, "keyboard"))
986 return bt_keyboard_init(vlan
);
988 error_report("unsupported bluetooth device '%s'", devname
);
992 static int bt_parse(const char *opt
)
994 const char *endp
, *p
;
997 if (strstart(opt
, "hci", &endp
)) {
998 if (!*endp
|| *endp
== ',') {
1000 if (!strstart(endp
, ",vlan=", 0))
1003 return bt_hci_parse(opt
);
1005 } else if (strstart(opt
, "vhci", &endp
)) {
1006 if (!*endp
|| *endp
== ',') {
1008 if (strstart(endp
, ",vlan=", &p
)) {
1009 vlan
= strtol(p
, (char **) &endp
, 0);
1011 error_report("bad scatternet '%s'", p
);
1015 error_report("bad parameter '%s'", endp
+ 1);
1024 } else if (strstart(opt
, "device:", &endp
))
1025 return !bt_device_add(endp
);
1027 error_report("bad bluetooth parameter '%s'", opt
);
1031 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1033 /* FIXME: change this to true for 1.3 */
1034 if (qemu_opt_get_bool(opts
, "enable", false)) {
1035 #ifdef CONFIG_SECCOMP
1036 if (seccomp_start() < 0) {
1037 error_report("failed to install seccomp syscall filter "
1042 error_report("seccomp support is disabled");
1050 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1052 const char *proc_name
;
1054 if (qemu_opt_get(opts
, "debug-threads")) {
1055 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1057 qemu_name
= qemu_opt_get(opts
, "guest");
1059 proc_name
= qemu_opt_get(opts
, "process");
1061 os_set_proc_name(proc_name
);
1067 bool defaults_enabled(void)
1069 return has_defaults
;
1073 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1075 int fd
, dupfd
, flags
;
1077 const char *fd_opaque
= NULL
;
1080 fd
= qemu_opt_get_number(opts
, "fd", -1);
1081 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1082 fd_opaque
= qemu_opt_get(opts
, "opaque");
1085 error_report("fd option is required and must be non-negative");
1089 if (fd
<= STDERR_FILENO
) {
1090 error_report("fd cannot be a standard I/O stream");
1095 * All fds inherited across exec() necessarily have FD_CLOEXEC
1096 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1098 flags
= fcntl(fd
, F_GETFD
);
1099 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1100 error_report("fd is not valid or already in use");
1105 error_report("set option is required and must be non-negative");
1109 #ifdef F_DUPFD_CLOEXEC
1110 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1114 qemu_set_cloexec(dupfd
);
1118 error_report("error duplicating fd: %s", strerror(errno
));
1122 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1123 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1130 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1134 fd
= qemu_opt_get_number(opts
, "fd", -1);
1141 /***********************************************************/
1142 /* QEMU Block devices */
1144 #define HD_OPTS "media=disk"
1145 #define CDROM_OPTS "media=cdrom"
1147 #define PFLASH_OPTS ""
1151 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1153 BlockInterfaceType
*block_default_type
= opaque
;
1155 return drive_new(opts
, *block_default_type
) == NULL
;
1158 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1160 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1161 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1166 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1167 int index
, const char *optstr
)
1172 if (!enable
|| drive_get_by_index(type
, index
)) {
1176 opts
= drive_add(type
, index
, NULL
, optstr
);
1178 drive_enable_snapshot(NULL
, opts
, NULL
);
1181 dinfo
= drive_new(opts
, type
);
1185 dinfo
->is_default
= true;
1189 static QemuOptsList qemu_smp_opts
= {
1191 .implied_opt_name
= "cpus",
1192 .merge_lists
= true,
1193 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1197 .type
= QEMU_OPT_NUMBER
,
1200 .type
= QEMU_OPT_NUMBER
,
1203 .type
= QEMU_OPT_NUMBER
,
1206 .type
= QEMU_OPT_NUMBER
,
1209 .type
= QEMU_OPT_NUMBER
,
1211 { /*End of list */ }
1215 static void smp_parse(QemuOpts
*opts
)
1218 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1219 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1220 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1221 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1223 /* compute missing values, prefer sockets over cores over threads */
1224 if (cpus
== 0 || sockets
== 0) {
1225 sockets
= sockets
> 0 ? sockets
: 1;
1226 cores
= cores
> 0 ? cores
: 1;
1227 threads
= threads
> 0 ? threads
: 1;
1229 cpus
= cores
* threads
* sockets
;
1231 } else if (cores
== 0) {
1232 threads
= threads
> 0 ? threads
: 1;
1233 cores
= cpus
/ (sockets
* threads
);
1234 cores
= cores
> 0 ? cores
: 1;
1235 } else if (threads
== 0) {
1236 threads
= cpus
/ (cores
* sockets
);
1237 threads
= threads
> 0 ? threads
: 1;
1238 } else if (sockets
* cores
* threads
< cpus
) {
1239 error_report("cpu topology: "
1240 "sockets (%u) * cores (%u) * threads (%u) < "
1242 sockets
, cores
, threads
, cpus
);
1246 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1248 if (max_cpus
< cpus
) {
1249 error_report("maxcpus must be equal to or greater than smp");
1253 if (sockets
* cores
* threads
> max_cpus
) {
1254 error_report("cpu topology: "
1255 "sockets (%u) * cores (%u) * threads (%u) > "
1257 sockets
, cores
, threads
, max_cpus
);
1263 smp_threads
= threads
;
1267 Error
*blocker
= NULL
;
1268 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1269 replay_add_blocker(blocker
);
1273 static void realtime_init(void)
1276 if (os_mlock() < 0) {
1277 error_report("locking memory failed");
1284 static void configure_msg(QemuOpts
*opts
)
1286 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1289 /***********************************************************/
1292 typedef struct SemihostingConfig
{
1294 SemihostingTarget target
;
1297 const char *cmdline
; /* concatenated argv */
1298 } SemihostingConfig
;
1300 static SemihostingConfig semihosting
;
1302 bool semihosting_enabled(void)
1304 return semihosting
.enabled
;
1307 SemihostingTarget
semihosting_get_target(void)
1309 return semihosting
.target
;
1312 const char *semihosting_get_arg(int i
)
1314 if (i
>= semihosting
.argc
) {
1317 return semihosting
.argv
[i
];
1320 int semihosting_get_argc(void)
1322 return semihosting
.argc
;
1325 const char *semihosting_get_cmdline(void)
1327 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1328 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1330 return semihosting
.cmdline
;
1333 static int add_semihosting_arg(void *opaque
,
1334 const char *name
, const char *val
,
1337 SemihostingConfig
*s
= opaque
;
1338 if (strcmp(name
, "arg") == 0) {
1340 /* one extra element as g_strjoinv() expects NULL-terminated array */
1341 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1342 s
->argv
[s
->argc
- 1] = val
;
1343 s
->argv
[s
->argc
] = NULL
;
1348 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1349 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1354 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1356 /* split -append and initialize argv[1..n] */
1357 cmd_token
= strtok(g_strdup(cmd
), " ");
1359 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1360 cmd_token
= strtok(NULL
, " ");
1364 /* Now we still need this for compatibility with XEN. */
1365 bool has_igd_gfx_passthru
;
1366 static void igd_gfx_passthru(void)
1368 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1371 /***********************************************************/
1374 static int usb_device_add(const char *devname
)
1376 USBDevice
*dev
= NULL
;
1377 #ifndef CONFIG_LINUX
1381 if (!machine_usb(current_machine
)) {
1385 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1386 dev
= usbdevice_create(devname
);
1390 /* the other ones */
1391 #ifndef CONFIG_LINUX
1392 /* only the linux version is qdev-ified, usb-bsd still needs this */
1393 if (strstart(devname
, "host:", &p
)) {
1394 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1404 static int usb_device_del(const char *devname
)
1409 if (strstart(devname
, "host:", &p
)) {
1413 if (!machine_usb(current_machine
)) {
1417 p
= strchr(devname
, '.');
1420 bus_num
= strtoul(devname
, NULL
, 0);
1421 addr
= strtoul(p
+ 1, NULL
, 0);
1423 return usb_device_delete_addr(bus_num
, addr
);
1426 static int usb_parse(const char *cmdline
)
1429 r
= usb_device_add(cmdline
);
1431 error_report("could not add USB device '%s'", cmdline
);
1436 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1438 const char *devname
= qdict_get_str(qdict
, "devname");
1439 if (usb_device_add(devname
) < 0) {
1440 error_report("could not add USB device '%s'", devname
);
1444 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1446 const char *devname
= qdict_get_str(qdict
, "devname");
1447 if (usb_device_del(devname
) < 0) {
1448 error_report("could not delete USB device '%s'", devname
);
1452 /***********************************************************/
1453 /* machine registration */
1455 MachineState
*current_machine
;
1457 static MachineClass
*find_machine(const char *name
)
1459 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1460 MachineClass
*mc
= NULL
;
1462 for (el
= machines
; el
; el
= el
->next
) {
1463 MachineClass
*temp
= el
->data
;
1465 if (!strcmp(temp
->name
, name
)) {
1470 !strcmp(temp
->alias
, name
)) {
1476 g_slist_free(machines
);
1480 MachineClass
*find_default_machine(void)
1482 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1483 MachineClass
*mc
= NULL
;
1485 for (el
= machines
; el
; el
= el
->next
) {
1486 MachineClass
*temp
= el
->data
;
1488 if (temp
->is_default
) {
1494 g_slist_free(machines
);
1498 MachineInfoList
*qmp_query_machines(Error
**errp
)
1500 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1501 MachineInfoList
*mach_list
= NULL
;
1503 for (el
= machines
; el
; el
= el
->next
) {
1504 MachineClass
*mc
= el
->data
;
1505 MachineInfoList
*entry
;
1508 info
= g_malloc0(sizeof(*info
));
1509 if (mc
->is_default
) {
1510 info
->has_is_default
= true;
1511 info
->is_default
= true;
1515 info
->has_alias
= true;
1516 info
->alias
= g_strdup(mc
->alias
);
1519 info
->name
= g_strdup(mc
->name
);
1520 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1521 info
->hotpluggable_cpus
= mc
->has_hotpluggable_cpus
;
1523 entry
= g_malloc0(sizeof(*entry
));
1524 entry
->value
= info
;
1525 entry
->next
= mach_list
;
1529 g_slist_free(machines
);
1533 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1535 ObjectProperty
*prop
;
1536 ObjectPropertyIterator iter
;
1538 if (!qemu_opt_has_help_opt(opts
)) {
1542 object_property_iter_init(&iter
, OBJECT(machine
));
1543 while ((prop
= object_property_iter_next(&iter
))) {
1548 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1549 prop
->name
, prop
->type
);
1550 if (prop
->description
) {
1551 error_printf(" (%s)\n", prop
->description
);
1560 /***********************************************************/
1561 /* main execution loop */
1563 struct vm_change_state_entry
{
1564 VMChangeStateHandler
*cb
;
1566 QLIST_ENTRY (vm_change_state_entry
) entries
;
1569 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1571 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1574 VMChangeStateEntry
*e
;
1576 e
= g_malloc0(sizeof (*e
));
1580 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1584 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1586 QLIST_REMOVE (e
, entries
);
1590 void vm_state_notify(int running
, RunState state
)
1592 VMChangeStateEntry
*e
, *next
;
1594 trace_vm_state_notify(running
, state
);
1596 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1597 e
->cb(e
->opaque
, running
, state
);
1601 static int reset_requested
;
1602 static int shutdown_requested
, shutdown_signal
= -1;
1603 static pid_t shutdown_pid
;
1604 static int powerdown_requested
;
1605 static int debug_requested
;
1606 static int suspend_requested
;
1607 static WakeupReason wakeup_reason
;
1608 static NotifierList powerdown_notifiers
=
1609 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1610 static NotifierList suspend_notifiers
=
1611 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1612 static NotifierList wakeup_notifiers
=
1613 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1614 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1616 int qemu_shutdown_requested_get(void)
1618 return shutdown_requested
;
1621 int qemu_reset_requested_get(void)
1623 return reset_requested
;
1626 static int qemu_shutdown_requested(void)
1628 return atomic_xchg(&shutdown_requested
, 0);
1631 static void qemu_kill_report(void)
1633 if (!qtest_driver() && shutdown_signal
!= -1) {
1634 if (shutdown_pid
== 0) {
1635 /* This happens for eg ^C at the terminal, so it's worth
1636 * avoiding printing an odd message in that case.
1638 error_report("terminating on signal %d", shutdown_signal
);
1640 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1642 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1643 shutdown_signal
, shutdown_pid
,
1644 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1645 g_free(shutdown_cmd
);
1647 shutdown_signal
= -1;
1651 static int qemu_reset_requested(void)
1653 int r
= reset_requested
;
1654 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1655 reset_requested
= 0;
1661 static int qemu_suspend_requested(void)
1663 int r
= suspend_requested
;
1664 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1665 suspend_requested
= 0;
1671 static WakeupReason
qemu_wakeup_requested(void)
1673 return wakeup_reason
;
1676 static int qemu_powerdown_requested(void)
1678 int r
= powerdown_requested
;
1679 powerdown_requested
= 0;
1683 static int qemu_debug_requested(void)
1685 int r
= debug_requested
;
1686 debug_requested
= 0;
1690 void qemu_system_reset(bool report
)
1694 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1696 cpu_synchronize_all_states();
1698 if (mc
&& mc
->reset
) {
1701 qemu_devices_reset();
1704 qapi_event_send_reset(&error_abort
);
1706 cpu_synchronize_all_post_reset();
1709 void qemu_system_guest_panicked(GuestPanicInformation
*info
)
1711 qemu_log_mask(LOG_GUEST_ERROR
, "Guest crashed\n");
1714 current_cpu
->crash_occurred
= true;
1716 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
,
1717 !!info
, info
, &error_abort
);
1718 vm_stop(RUN_STATE_GUEST_PANICKED
);
1720 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1721 !!info
, info
, &error_abort
);
1722 qemu_system_shutdown_request();
1726 if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_HYPER_V
) {
1727 qemu_log_mask(LOG_GUEST_ERROR
, "HV crash parameters: (%#"PRIx64
1728 " %#"PRIx64
" %#"PRIx64
" %#"PRIx64
" %#"PRIx64
")\n",
1729 info
->u
.hyper_v
.arg1
,
1730 info
->u
.hyper_v
.arg2
,
1731 info
->u
.hyper_v
.arg3
,
1732 info
->u
.hyper_v
.arg4
,
1733 info
->u
.hyper_v
.arg5
);
1735 qapi_free_GuestPanicInformation(info
);
1739 void qemu_system_reset_request(void)
1742 shutdown_requested
= 1;
1744 reset_requested
= 1;
1747 qemu_notify_event();
1750 static void qemu_system_suspend(void)
1753 notifier_list_notify(&suspend_notifiers
, NULL
);
1754 runstate_set(RUN_STATE_SUSPENDED
);
1755 qapi_event_send_suspend(&error_abort
);
1758 void qemu_system_suspend_request(void)
1760 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1763 suspend_requested
= 1;
1765 qemu_notify_event();
1768 void qemu_register_suspend_notifier(Notifier
*notifier
)
1770 notifier_list_add(&suspend_notifiers
, notifier
);
1773 void qemu_system_wakeup_request(WakeupReason reason
)
1775 trace_system_wakeup_request(reason
);
1777 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1780 if (!(wakeup_reason_mask
& (1 << reason
))) {
1783 runstate_set(RUN_STATE_RUNNING
);
1784 wakeup_reason
= reason
;
1785 qemu_notify_event();
1788 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1791 wakeup_reason_mask
|= (1 << reason
);
1793 wakeup_reason_mask
&= ~(1 << reason
);
1797 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1799 notifier_list_add(&wakeup_notifiers
, notifier
);
1802 void qemu_system_killed(int signal
, pid_t pid
)
1804 shutdown_signal
= signal
;
1808 /* Cannot call qemu_system_shutdown_request directly because
1809 * we are in a signal handler.
1811 shutdown_requested
= 1;
1812 qemu_notify_event();
1815 void qemu_system_shutdown_request(void)
1817 trace_qemu_system_shutdown_request();
1818 replay_shutdown_request();
1819 shutdown_requested
= 1;
1820 qemu_notify_event();
1823 static void qemu_system_powerdown(void)
1825 qapi_event_send_powerdown(&error_abort
);
1826 notifier_list_notify(&powerdown_notifiers
, NULL
);
1829 void qemu_system_powerdown_request(void)
1831 trace_qemu_system_powerdown_request();
1832 powerdown_requested
= 1;
1833 qemu_notify_event();
1836 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1838 notifier_list_add(&powerdown_notifiers
, notifier
);
1841 void qemu_system_debug_request(void)
1843 debug_requested
= 1;
1844 qemu_notify_event();
1847 static bool main_loop_should_exit(void)
1850 if (qemu_debug_requested()) {
1851 vm_stop(RUN_STATE_DEBUG
);
1853 if (qemu_suspend_requested()) {
1854 qemu_system_suspend();
1856 if (qemu_shutdown_requested()) {
1858 qapi_event_send_shutdown(&error_abort
);
1860 vm_stop(RUN_STATE_SHUTDOWN
);
1865 if (qemu_reset_requested()) {
1867 qemu_system_reset(VMRESET_REPORT
);
1869 if (!runstate_check(RUN_STATE_RUNNING
) &&
1870 !runstate_check(RUN_STATE_INMIGRATE
)) {
1871 runstate_set(RUN_STATE_PRELAUNCH
);
1874 if (qemu_wakeup_requested()) {
1876 qemu_system_reset(VMRESET_SILENT
);
1877 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1878 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1880 qapi_event_send_wakeup(&error_abort
);
1882 if (qemu_powerdown_requested()) {
1883 qemu_system_powerdown();
1885 if (qemu_vmstop_requested(&r
)) {
1891 static void main_loop(void)
1893 #ifdef CONFIG_PROFILER
1897 #ifdef CONFIG_PROFILER
1898 ti
= profile_getclock();
1900 main_loop_wait(false);
1901 #ifdef CONFIG_PROFILER
1902 dev_time
+= profile_getclock() - ti
;
1904 } while (!main_loop_should_exit());
1907 static void version(void)
1909 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1910 QEMU_COPYRIGHT
"\n");
1913 static void help(int exitcode
)
1916 printf("usage: %s [options] [disk_image]\n\n"
1917 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1918 error_get_progname());
1920 #define QEMU_OPTIONS_GENERATE_HELP
1921 #include "qemu-options-wrapper.h"
1923 printf("\nDuring emulation, the following keys are useful:\n"
1924 "ctrl-alt-f toggle full screen\n"
1925 "ctrl-alt-n switch to virtual console 'n'\n"
1926 "ctrl-alt toggle mouse and keyboard grab\n"
1928 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1933 #define HAS_ARG 0x0001
1935 typedef struct QEMUOption
{
1942 static const QEMUOption qemu_options
[] = {
1943 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1944 #define QEMU_OPTIONS_GENERATE_OPTIONS
1945 #include "qemu-options-wrapper.h"
1949 typedef struct VGAInterfaceInfo
{
1950 const char *opt_name
; /* option name */
1951 const char *name
; /* human-readable name */
1952 /* Class names indicating that support is available.
1953 * If no class is specified, the interface is always available */
1954 const char *class_names
[2];
1957 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1963 .name
= "standard VGA",
1964 .class_names
= { "VGA", "isa-vga" },
1967 .opt_name
= "cirrus",
1968 .name
= "Cirrus VGA",
1969 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1972 .opt_name
= "vmware",
1973 .name
= "VMWare SVGA",
1974 .class_names
= { "vmware-svga" },
1977 .opt_name
= "virtio",
1978 .name
= "Virtio VGA",
1979 .class_names
= { "virtio-vga" },
1984 .class_names
= { "qxl-vga" },
1988 .name
= "TCX framebuffer",
1989 .class_names
= { "SUNW,tcx" },
1993 .name
= "CG3 framebuffer",
1994 .class_names
= { "cgthree" },
1997 .opt_name
= "xenfb",
2001 static bool vga_interface_available(VGAInterfaceType t
)
2003 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2005 assert(t
< VGA_TYPE_MAX
);
2006 return !ti
->class_names
[0] ||
2007 object_class_by_name(ti
->class_names
[0]) ||
2008 object_class_by_name(ti
->class_names
[1]);
2011 static void select_vgahw(const char *p
)
2016 assert(vga_interface_type
== VGA_NONE
);
2017 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2018 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2019 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2020 if (!vga_interface_available(t
)) {
2021 error_report("%s not available", ti
->name
);
2024 vga_interface_type
= t
;
2028 if (t
== VGA_TYPE_MAX
) {
2030 error_report("unknown vga type: %s", p
);
2034 const char *nextopt
;
2036 if (strstart(opts
, ",retrace=", &nextopt
)) {
2038 if (strstart(opts
, "dumb", &nextopt
))
2039 vga_retrace_method
= VGA_RETRACE_DUMB
;
2040 else if (strstart(opts
, "precise", &nextopt
))
2041 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2042 else goto invalid_vga
;
2043 } else goto invalid_vga
;
2048 typedef enum DisplayType
{
2058 static DisplayType
select_display(const char *p
)
2061 DisplayType display
= DT_DEFAULT
;
2063 if (strstart(p
, "sdl", &opts
)) {
2067 const char *nextopt
;
2069 if (strstart(opts
, ",frame=", &nextopt
)) {
2071 if (strstart(opts
, "on", &nextopt
)) {
2073 } else if (strstart(opts
, "off", &nextopt
)) {
2076 goto invalid_sdl_args
;
2078 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2080 if (strstart(opts
, "on", &nextopt
)) {
2082 } else if (strstart(opts
, "off", &nextopt
)) {
2085 goto invalid_sdl_args
;
2087 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2089 if (strstart(opts
, "on", &nextopt
)) {
2091 } else if (strstart(opts
, "off", &nextopt
)) {
2094 goto invalid_sdl_args
;
2096 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2098 if (strstart(opts
, "on", &nextopt
)) {
2100 } else if (strstart(opts
, "off", &nextopt
)) {
2103 goto invalid_sdl_args
;
2105 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2107 if (strstart(opts
, "on", &nextopt
)) {
2109 } else if (strstart(opts
, "off", &nextopt
)) {
2112 goto invalid_sdl_args
;
2116 error_report("invalid SDL option string");
2122 error_report("SDL support is disabled");
2125 } else if (strstart(p
, "vnc", &opts
)) {
2127 vnc_parse(opts
+ 1, &error_fatal
);
2129 error_report("VNC requires a display argument vnc=<display>");
2132 } else if (strstart(p
, "egl-headless", &opts
)) {
2133 #ifdef CONFIG_OPENGL
2138 fprintf(stderr
, "egl support is disabled\n");
2141 } else if (strstart(p
, "curses", &opts
)) {
2142 #ifdef CONFIG_CURSES
2143 display
= DT_CURSES
;
2145 error_report("curses support is disabled");
2148 } else if (strstart(p
, "gtk", &opts
)) {
2152 const char *nextopt
;
2154 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2156 if (strstart(opts
, "on", &nextopt
)) {
2157 grab_on_hover
= true;
2158 } else if (strstart(opts
, "off", &nextopt
)) {
2159 grab_on_hover
= false;
2161 goto invalid_gtk_args
;
2163 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2165 if (strstart(opts
, "on", &nextopt
)) {
2167 } else if (strstart(opts
, "off", &nextopt
)) {
2170 goto invalid_gtk_args
;
2174 error_report("invalid GTK option string");
2180 error_report("GTK support is disabled");
2183 } else if (strstart(p
, "none", &opts
)) {
2186 error_report("unknown display type");
2193 static int balloon_parse(const char *arg
)
2197 if (strcmp(arg
, "none") == 0) {
2201 if (!strncmp(arg
, "virtio", 6)) {
2202 if (arg
[6] == ',') {
2203 /* have params -> parse them */
2204 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2209 /* create empty opts */
2210 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2213 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2220 char *qemu_find_file(int type
, const char *name
)
2226 /* Try the name as a straight path first */
2227 if (access(name
, R_OK
) == 0) {
2228 trace_load_file(name
, name
);
2229 return g_strdup(name
);
2233 case QEMU_FILE_TYPE_BIOS
:
2236 case QEMU_FILE_TYPE_KEYMAP
:
2237 subdir
= "keymaps/";
2243 for (i
= 0; i
< data_dir_idx
; i
++) {
2244 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2245 if (access(buf
, R_OK
) == 0) {
2246 trace_load_file(name
, buf
);
2254 static inline bool nonempty_str(const char *str
)
2259 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2263 const char *name
, *file
, *str
;
2264 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2266 if (fw_cfg
== NULL
) {
2267 error_report("fw_cfg device not available");
2270 name
= qemu_opt_get(opts
, "name");
2271 file
= qemu_opt_get(opts
, "file");
2272 str
= qemu_opt_get(opts
, "string");
2274 /* we need name and either a file or the content string */
2275 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2276 error_report("invalid argument(s)");
2279 if (nonempty_str(file
) && nonempty_str(str
)) {
2280 error_report("file and string are mutually exclusive");
2283 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2284 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2287 if (strncmp(name
, "opt/", 4) != 0) {
2288 error_report("warning: externally provided fw_cfg item names "
2289 "should be prefixed with \"opt/\"");
2291 if (nonempty_str(str
)) {
2292 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2293 buf
= g_memdup(str
, size
);
2295 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2296 error_report("can't load %s", file
);
2300 /* For legacy, keep user files in a specific global order. */
2301 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2302 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2303 fw_cfg_reset_order_override(fw_cfg
);
2307 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2309 return qdev_device_help(opts
);
2312 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2317 dev
= qdev_device_add(opts
, &err
);
2319 error_report_err(err
);
2322 object_unref(OBJECT(dev
));
2326 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2328 Error
*local_err
= NULL
;
2330 qemu_chr_new_from_opts(opts
, &local_err
);
2332 error_report_err(local_err
);
2338 #ifdef CONFIG_VIRTFS
2339 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2341 return qemu_fsdev_add(opts
);
2345 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2348 const char *chardev
;
2352 mode
= qemu_opt_get(opts
, "mode");
2356 if (strcmp(mode
, "readline") == 0) {
2357 flags
= MONITOR_USE_READLINE
;
2358 } else if (strcmp(mode
, "control") == 0) {
2359 flags
= MONITOR_USE_CONTROL
;
2361 error_report("unknown monitor mode \"%s\"", mode
);
2365 if (qemu_opt_get_bool(opts
, "pretty", 0))
2366 flags
|= MONITOR_USE_PRETTY
;
2368 if (qemu_opt_get_bool(opts
, "default", 0)) {
2369 error_report("option 'default' does nothing and is deprecated");
2372 chardev
= qemu_opt_get(opts
, "chardev");
2373 chr
= qemu_chr_find(chardev
);
2375 error_report("chardev \"%s\" not found", chardev
);
2379 monitor_init(chr
, flags
);
2383 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2385 static int monitor_device_index
= 0;
2390 if (strstart(optarg
, "chardev:", &p
)) {
2391 snprintf(label
, sizeof(label
), "%s", p
);
2393 snprintf(label
, sizeof(label
), "compat_monitor%d",
2394 monitor_device_index
);
2395 opts
= qemu_chr_parse_compat(label
, optarg
);
2397 error_report("parse error: %s", optarg
);
2402 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2403 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2404 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2405 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2406 monitor_device_index
++;
2409 struct device_config
{
2411 DEV_USB
, /* -usbdevice */
2413 DEV_SERIAL
, /* -serial */
2414 DEV_PARALLEL
, /* -parallel */
2415 DEV_VIRTCON
, /* -virtioconsole */
2416 DEV_DEBUGCON
, /* -debugcon */
2417 DEV_GDB
, /* -gdb, -s */
2418 DEV_SCLP
, /* s390 sclp */
2420 const char *cmdline
;
2422 QTAILQ_ENTRY(device_config
) next
;
2425 static QTAILQ_HEAD(, device_config
) device_configs
=
2426 QTAILQ_HEAD_INITIALIZER(device_configs
);
2428 static void add_device_config(int type
, const char *cmdline
)
2430 struct device_config
*conf
;
2432 conf
= g_malloc0(sizeof(*conf
));
2434 conf
->cmdline
= cmdline
;
2435 loc_save(&conf
->loc
);
2436 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2439 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2441 struct device_config
*conf
;
2444 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2445 if (conf
->type
!= type
)
2447 loc_push_restore(&conf
->loc
);
2448 rc
= func(conf
->cmdline
);
2449 loc_pop(&conf
->loc
);
2457 static int serial_parse(const char *devname
)
2459 static int index
= 0;
2462 if (strcmp(devname
, "none") == 0)
2464 if (index
== MAX_SERIAL_PORTS
) {
2465 error_report("too many serial ports");
2468 snprintf(label
, sizeof(label
), "serial%d", index
);
2469 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2470 if (!serial_hds
[index
]) {
2471 error_report("could not connect serial device"
2472 " to character backend '%s'", devname
);
2479 static int parallel_parse(const char *devname
)
2481 static int index
= 0;
2484 if (strcmp(devname
, "none") == 0)
2486 if (index
== MAX_PARALLEL_PORTS
) {
2487 error_report("too many parallel ports");
2490 snprintf(label
, sizeof(label
), "parallel%d", index
);
2491 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2492 if (!parallel_hds
[index
]) {
2493 error_report("could not connect parallel device"
2494 " to character backend '%s'", devname
);
2501 static int virtcon_parse(const char *devname
)
2503 QemuOptsList
*device
= qemu_find_opts("device");
2504 static int index
= 0;
2506 QemuOpts
*bus_opts
, *dev_opts
;
2508 if (strcmp(devname
, "none") == 0)
2510 if (index
== MAX_VIRTIO_CONSOLES
) {
2511 error_report("too many virtio consoles");
2515 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2516 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2518 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2519 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2521 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2522 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2523 if (!virtcon_hds
[index
]) {
2524 error_report("could not connect virtio console"
2525 " to character backend '%s'", devname
);
2528 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2534 static int sclp_parse(const char *devname
)
2536 QemuOptsList
*device
= qemu_find_opts("device");
2537 static int index
= 0;
2541 if (strcmp(devname
, "none") == 0) {
2544 if (index
== MAX_SCLP_CONSOLES
) {
2545 error_report("too many sclp consoles");
2549 assert(arch_type
== QEMU_ARCH_S390X
);
2551 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2552 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2554 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2555 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2556 if (!sclp_hds
[index
]) {
2557 error_report("could not connect sclp console"
2558 " to character backend '%s'", devname
);
2561 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2567 static int debugcon_parse(const char *devname
)
2571 if (!qemu_chr_new("debugcon", devname
)) {
2574 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2576 error_report("already have a debugcon device");
2579 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2580 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2584 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2586 const MachineClass
*mc1
= a
, *mc2
= b
;
2589 if (mc1
->family
== NULL
) {
2590 if (mc2
->family
== NULL
) {
2591 /* Compare standalone machine types against each other; they sort
2592 * in increasing order.
2594 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2595 object_class_get_name(OBJECT_CLASS(mc2
)));
2598 /* Standalone machine types sort after families. */
2602 if (mc2
->family
== NULL
) {
2603 /* Families sort before standalone machine types. */
2607 /* Families sort between each other alphabetically increasingly. */
2608 res
= strcmp(mc1
->family
, mc2
->family
);
2613 /* Within the same family, machine types sort in decreasing order. */
2614 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2615 object_class_get_name(OBJECT_CLASS(mc1
)));
2618 static MachineClass
*machine_parse(const char *name
)
2620 MachineClass
*mc
= NULL
;
2621 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2624 mc
= find_machine(name
);
2627 g_slist_free(machines
);
2630 if (name
&& !is_help_option(name
)) {
2631 error_report("unsupported machine type");
2632 error_printf("Use -machine help to list supported machines\n");
2634 printf("Supported machines are:\n");
2635 machines
= g_slist_sort(machines
, machine_class_cmp
);
2636 for (el
= machines
; el
; el
= el
->next
) {
2637 MachineClass
*mc
= el
->data
;
2639 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2641 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2642 mc
->is_default
? " (default)" : "");
2646 g_slist_free(machines
);
2647 exit(!name
|| !is_help_option(name
));
2650 void qemu_add_exit_notifier(Notifier
*notify
)
2652 notifier_list_add(&exit_notifiers
, notify
);
2655 void qemu_remove_exit_notifier(Notifier
*notify
)
2657 notifier_remove(notify
);
2660 static void qemu_run_exit_notifiers(void)
2662 notifier_list_notify(&exit_notifiers
, NULL
);
2665 static bool machine_init_done
;
2667 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2669 notifier_list_add(&machine_init_done_notifiers
, notify
);
2670 if (machine_init_done
) {
2671 notify
->notify(notify
, NULL
);
2675 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2677 notifier_remove(notify
);
2680 static void qemu_run_machine_init_done_notifiers(void)
2682 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2683 machine_init_done
= true;
2686 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2687 const char **poptarg
, int *poptind
)
2689 const QEMUOption
*popt
;
2690 int optind
= *poptind
;
2691 char *r
= argv
[optind
];
2694 loc_set_cmdline(argv
, optind
, 1);
2696 /* Treat --foo the same as -foo. */
2699 popt
= qemu_options
;
2702 error_report("invalid option");
2705 if (!strcmp(popt
->name
, r
+ 1))
2709 if (popt
->flags
& HAS_ARG
) {
2710 if (optind
>= argc
) {
2711 error_report("requires an argument");
2714 optarg
= argv
[optind
++];
2715 loc_set_cmdline(argv
, optind
- 2, 2);
2726 static MachineClass
*select_machine(void)
2728 MachineClass
*machine_class
= find_default_machine();
2733 loc_push_none(&loc
);
2735 opts
= qemu_get_machine_opts();
2736 qemu_opts_loc_restore(opts
);
2738 optarg
= qemu_opt_get(opts
, "type");
2740 machine_class
= machine_parse(optarg
);
2743 if (!machine_class
) {
2744 error_report("No machine specified, and there is no default");
2745 error_printf("Use -machine help to list supported machines\n");
2750 return machine_class
;
2753 static int machine_set_property(void *opaque
,
2754 const char *name
, const char *value
,
2757 Object
*obj
= OBJECT(opaque
);
2758 Error
*local_err
= NULL
;
2761 if (strcmp(name
, "type") == 0) {
2765 qom_name
= g_strdup(name
);
2766 for (p
= qom_name
; *p
; p
++) {
2772 object_property_parse(obj
, value
, qom_name
, &local_err
);
2776 error_report_err(local_err
);
2785 * Initial object creation happens before all other
2786 * QEMU data types are created. The majority of objects
2787 * can be created at this point. The rng-egd object
2788 * cannot be created here, as it depends on the chardev
2791 static bool object_create_initial(const char *type
)
2793 if (g_str_equal(type
, "rng-egd")) {
2798 * return false for concrete netfilters since
2799 * they depend on netdevs already existing
2801 if (g_str_equal(type
, "filter-buffer") ||
2802 g_str_equal(type
, "filter-dump") ||
2803 g_str_equal(type
, "filter-mirror") ||
2804 g_str_equal(type
, "filter-redirector") ||
2805 g_str_equal(type
, "colo-compare") ||
2806 g_str_equal(type
, "filter-rewriter") ||
2807 g_str_equal(type
, "filter-replay")) {
2811 /* Memory allocation by backends needs to be done
2812 * after configure_accelerator() (due to the tcg_enabled()
2813 * checks at memory_region_init_*()).
2815 * Also, allocation of large amounts of memory may delay
2816 * chardev initialization for too long, and trigger timeouts
2817 * on software that waits for a monitor socket to be created
2820 if (g_str_has_prefix(type
, "memory-backend-")) {
2829 * The remainder of object creation happens after the
2830 * creation of chardev, fsdev, net clients and device data types.
2832 static bool object_create_delayed(const char *type
)
2834 return !object_create_initial(type
);
2838 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2842 const char *mem_str
;
2843 const char *maxmem_str
, *slots_str
;
2844 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2845 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2848 loc_push_none(&loc
);
2849 qemu_opts_loc_restore(opts
);
2852 mem_str
= qemu_opt_get(opts
, "size");
2855 error_report("missing 'size' option value");
2859 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2861 /* Fix up legacy suffix-less format */
2862 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2863 uint64_t overflow_check
= sz
;
2866 if ((sz
>> 20) != overflow_check
) {
2867 error_report("too large 'size' option value");
2873 /* backward compatibility behaviour for case "-m 0" */
2875 sz
= default_ram_size
;
2878 sz
= QEMU_ALIGN_UP(sz
, 8192);
2880 if (ram_size
!= sz
) {
2881 error_report("ram size too large");
2885 /* store value for the future use */
2886 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2887 *maxram_size
= ram_size
;
2889 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2890 slots_str
= qemu_opt_get(opts
, "slots");
2891 if (maxmem_str
&& slots_str
) {
2894 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2895 slots
= qemu_opt_get_number(opts
, "slots", 0);
2896 if (sz
< ram_size
) {
2897 error_report("invalid value of -m option maxmem: "
2898 "maximum memory size (0x%" PRIx64
") must be at least "
2899 "the initial memory size (0x" RAM_ADDR_FMT
")",
2902 } else if (sz
> ram_size
) {
2904 error_report("invalid value of -m option: maxmem was "
2905 "specified, but no hotplug slots were specified");
2909 error_report("invalid value of -m option maxmem: "
2910 "memory slots were specified but maximum memory size "
2911 "(0x%" PRIx64
") is equal to the initial memory size "
2912 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2918 } else if ((!maxmem_str
&& slots_str
) ||
2919 (maxmem_str
&& !slots_str
)) {
2920 error_report("invalid -m option value: missing "
2921 "'%s' option", slots_str
? "maxmem" : "slots");
2928 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2932 g
= g_malloc0(sizeof(*g
));
2933 g
->driver
= qemu_opt_get(opts
, "driver");
2934 g
->property
= qemu_opt_get(opts
, "property");
2935 g
->value
= qemu_opt_get(opts
, "value");
2936 g
->user_provided
= true;
2937 g
->errp
= &error_fatal
;
2938 qdev_prop_register_global(g
);
2942 static int qemu_read_default_config_file(void)
2946 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2947 if (ret
< 0 && ret
!= -ENOENT
) {
2954 int main(int argc
, char **argv
, char **envp
)
2957 int snapshot
, linux_boot
;
2958 const char *initrd_filename
;
2959 const char *kernel_filename
, *kernel_cmdline
;
2960 const char *boot_order
= NULL
;
2961 const char *boot_once
= NULL
;
2963 int cyls
, heads
, secs
, translation
;
2964 QemuOpts
*opts
, *machine_opts
;
2965 QemuOpts
*hda_opts
= NULL
, *icount_opts
= NULL
, *accel_opts
= NULL
;
2966 QemuOptsList
*olist
;
2969 const char *loadvm
= NULL
;
2970 MachineClass
*machine_class
;
2971 const char *cpu_model
;
2972 const char *vga_model
= NULL
;
2973 const char *qtest_chrdev
= NULL
;
2974 const char *qtest_log
= NULL
;
2975 const char *pid_file
= NULL
;
2976 const char *incoming
= NULL
;
2977 bool defconfig
= true;
2978 bool userconfig
= true;
2979 bool nographic
= false;
2980 DisplayType display_type
= DT_DEFAULT
;
2981 int display_remote
= 0;
2982 const char *log_mask
= NULL
;
2983 const char *log_file
= NULL
;
2984 char *trace_file
= NULL
;
2985 ram_addr_t maxram_size
;
2986 uint64_t ram_slots
= 0;
2987 FILE *vmstate_dump_file
= NULL
;
2988 Error
*main_loop_err
= NULL
;
2990 bool list_data_dirs
= false;
2991 typedef struct BlockdevOptions_queue
{
2992 BlockdevOptions
*bdo
;
2994 QSIMPLEQ_ENTRY(BlockdevOptions_queue
) entry
;
2995 } BlockdevOptions_queue
;
2996 QSIMPLEQ_HEAD(, BlockdevOptions_queue
) bdo_queue
2997 = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
2999 module_call_init(MODULE_INIT_TRACE
);
3001 qemu_init_cpu_list();
3002 qemu_init_cpu_loop();
3003 qemu_mutex_lock_iothread();
3005 atexit(qemu_run_exit_notifiers
);
3006 error_set_progname(argv
[0]);
3007 qemu_init_exec_dir(argv
[0]);
3009 module_call_init(MODULE_INIT_QOM
);
3010 monitor_init_qmp_commands();
3012 qemu_add_opts(&qemu_drive_opts
);
3013 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3014 qemu_add_drive_opts(&qemu_common_drive_opts
);
3015 qemu_add_drive_opts(&qemu_drive_opts
);
3016 qemu_add_drive_opts(&bdrv_runtime_opts
);
3017 qemu_add_opts(&qemu_chardev_opts
);
3018 qemu_add_opts(&qemu_device_opts
);
3019 qemu_add_opts(&qemu_netdev_opts
);
3020 qemu_add_opts(&qemu_net_opts
);
3021 qemu_add_opts(&qemu_rtc_opts
);
3022 qemu_add_opts(&qemu_global_opts
);
3023 qemu_add_opts(&qemu_mon_opts
);
3024 qemu_add_opts(&qemu_trace_opts
);
3025 qemu_add_opts(&qemu_option_rom_opts
);
3026 qemu_add_opts(&qemu_machine_opts
);
3027 qemu_add_opts(&qemu_accel_opts
);
3028 qemu_add_opts(&qemu_mem_opts
);
3029 qemu_add_opts(&qemu_smp_opts
);
3030 qemu_add_opts(&qemu_boot_opts
);
3031 qemu_add_opts(&qemu_sandbox_opts
);
3032 qemu_add_opts(&qemu_add_fd_opts
);
3033 qemu_add_opts(&qemu_object_opts
);
3034 qemu_add_opts(&qemu_tpmdev_opts
);
3035 qemu_add_opts(&qemu_realtime_opts
);
3036 qemu_add_opts(&qemu_msg_opts
);
3037 qemu_add_opts(&qemu_name_opts
);
3038 qemu_add_opts(&qemu_numa_opts
);
3039 qemu_add_opts(&qemu_icount_opts
);
3040 qemu_add_opts(&qemu_semihosting_config_opts
);
3041 qemu_add_opts(&qemu_fw_cfg_opts
);
3042 module_call_init(MODULE_INIT_OPTS
);
3046 if (qcrypto_init(&err
) < 0) {
3047 error_reportf_err(err
, "cannot initialize crypto: ");
3050 rtc_clock
= QEMU_CLOCK_HOST
;
3052 QLIST_INIT (&vm_change_state_head
);
3053 os_setup_early_signal_handling();
3057 cyls
= heads
= secs
= 0;
3058 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3062 bdrv_init_with_whitelist();
3066 /* first pass of option parsing */
3068 while (optind
< argc
) {
3069 if (argv
[optind
][0] != '-') {
3073 const QEMUOption
*popt
;
3075 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3076 switch (popt
->index
) {
3077 case QEMU_OPTION_nodefconfig
:
3080 case QEMU_OPTION_nouserconfig
:
3087 if (defconfig
&& userconfig
) {
3088 if (qemu_read_default_config_file() < 0) {
3093 /* second pass of option parsing */
3098 if (argv
[optind
][0] != '-') {
3099 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3101 const QEMUOption
*popt
;
3103 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3104 if (!(popt
->arch_mask
& arch_type
)) {
3105 error_report("Option not supported for this target");
3108 switch(popt
->index
) {
3109 case QEMU_OPTION_no_kvm_irqchip
: {
3110 olist
= qemu_find_opts("machine");
3111 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3114 case QEMU_OPTION_cpu
:
3115 /* hw initialization will check this */
3118 case QEMU_OPTION_hda
:
3122 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3124 snprintf(buf
, sizeof(buf
),
3125 "%s,cyls=%d,heads=%d,secs=%d%s",
3126 HD_OPTS
, cyls
, heads
, secs
,
3127 translation
== BIOS_ATA_TRANSLATION_LBA
?
3129 translation
== BIOS_ATA_TRANSLATION_NONE
?
3130 ",trans=none" : "");
3131 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3134 case QEMU_OPTION_hdb
:
3135 case QEMU_OPTION_hdc
:
3136 case QEMU_OPTION_hdd
:
3137 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3140 case QEMU_OPTION_blockdev
:
3143 BlockdevOptions_queue
*bdo
;
3145 v
= qobject_input_visitor_new_str(optarg
, "driver", &err
);
3147 error_report_err(err
);
3151 bdo
= g_new(BlockdevOptions_queue
, 1);
3152 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
3155 loc_save(&bdo
->loc
);
3156 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
3159 case QEMU_OPTION_drive
:
3160 if (drive_def(optarg
) == NULL
) {
3164 case QEMU_OPTION_set
:
3165 if (qemu_set_option(optarg
) != 0)
3168 case QEMU_OPTION_global
:
3169 if (qemu_global_option(optarg
) != 0)
3172 case QEMU_OPTION_mtdblock
:
3173 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3175 case QEMU_OPTION_sd
:
3176 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3178 case QEMU_OPTION_pflash
:
3179 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3181 case QEMU_OPTION_snapshot
:
3184 case QEMU_OPTION_hdachs
:
3188 cyls
= strtol(p
, (char **)&p
, 0);
3189 if (cyls
< 1 || cyls
> 16383)
3194 heads
= strtol(p
, (char **)&p
, 0);
3195 if (heads
< 1 || heads
> 16)
3200 secs
= strtol(p
, (char **)&p
, 0);
3201 if (secs
< 1 || secs
> 63)
3205 if (!strcmp(p
, "large")) {
3206 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3207 } else if (!strcmp(p
, "rechs")) {
3208 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3209 } else if (!strcmp(p
, "none")) {
3210 translation
= BIOS_ATA_TRANSLATION_NONE
;
3211 } else if (!strcmp(p
, "lba")) {
3212 translation
= BIOS_ATA_TRANSLATION_LBA
;
3213 } else if (!strcmp(p
, "auto")) {
3214 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3218 } else if (*p
!= '\0') {
3220 error_report("invalid physical CHS format");
3223 if (hda_opts
!= NULL
) {
3224 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3226 qemu_opt_set_number(hda_opts
, "heads", heads
,
3228 qemu_opt_set_number(hda_opts
, "secs", secs
,
3230 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3231 qemu_opt_set(hda_opts
, "trans", "large",
3233 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3234 qemu_opt_set(hda_opts
, "trans", "rechs",
3236 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3237 qemu_opt_set(hda_opts
, "trans", "lba",
3239 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3240 qemu_opt_set(hda_opts
, "trans", "none",
3245 error_report("'-hdachs' is deprecated, please use '-device"
3246 " ide-hd,cyls=c,heads=h,secs=s,...' instead");
3248 case QEMU_OPTION_numa
:
3249 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3255 case QEMU_OPTION_display
:
3256 display_type
= select_display(optarg
);
3258 case QEMU_OPTION_nographic
:
3259 olist
= qemu_find_opts("machine");
3260 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3262 display_type
= DT_NONE
;
3264 case QEMU_OPTION_curses
:
3265 #ifdef CONFIG_CURSES
3266 display_type
= DT_CURSES
;
3268 error_report("curses support is disabled");
3272 case QEMU_OPTION_portrait
:
3273 graphic_rotate
= 90;
3275 case QEMU_OPTION_rotate
:
3276 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3277 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3278 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3279 error_report("only 90, 180, 270 deg rotation is available");
3283 case QEMU_OPTION_kernel
:
3284 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3287 case QEMU_OPTION_initrd
:
3288 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3291 case QEMU_OPTION_append
:
3292 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3295 case QEMU_OPTION_dtb
:
3296 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3299 case QEMU_OPTION_cdrom
:
3300 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3302 case QEMU_OPTION_boot
:
3303 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3309 case QEMU_OPTION_fda
:
3310 case QEMU_OPTION_fdb
:
3311 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3314 case QEMU_OPTION_no_fd_bootchk
:
3317 case QEMU_OPTION_netdev
:
3319 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3323 case QEMU_OPTION_net
:
3325 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3329 #ifdef CONFIG_LIBISCSI
3330 case QEMU_OPTION_iscsi
:
3331 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3339 case QEMU_OPTION_tftp
:
3340 error_report("The -tftp option is deprecated. "
3341 "Please use '-netdev user,tftp=...' instead.");
3342 legacy_tftp_prefix
= optarg
;
3344 case QEMU_OPTION_bootp
:
3345 error_report("The -bootp option is deprecated. "
3346 "Please use '-netdev user,bootfile=...' instead.");
3347 legacy_bootp_filename
= optarg
;
3349 case QEMU_OPTION_redir
:
3350 error_report("The -redir option is deprecated. "
3351 "Please use '-netdev user,hostfwd=...' instead.");
3352 if (net_slirp_redir(optarg
) < 0)
3356 case QEMU_OPTION_bt
:
3357 add_device_config(DEV_BT
, optarg
);
3359 case QEMU_OPTION_audio_help
:
3363 case QEMU_OPTION_soundhw
:
3364 select_soundhw (optarg
);
3369 case QEMU_OPTION_version
:
3374 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3381 case QEMU_OPTION_tpmdev
:
3382 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3387 case QEMU_OPTION_mempath
:
3390 case QEMU_OPTION_mem_prealloc
:
3399 case QEMU_OPTION_DFILTER
:
3400 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3403 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3405 case QEMU_OPTION_gdb
:
3406 add_device_config(DEV_GDB
, optarg
);
3409 if (is_help_option(optarg
)) {
3410 list_data_dirs
= true;
3411 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3412 data_dir
[data_dir_idx
++] = optarg
;
3415 case QEMU_OPTION_bios
:
3416 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3419 case QEMU_OPTION_singlestep
:
3426 keyboard_layout
= optarg
;
3428 case QEMU_OPTION_localtime
:
3431 case QEMU_OPTION_vga
:
3440 w
= strtol(p
, (char **)&p
, 10);
3443 error_report("invalid resolution or depth");
3449 h
= strtol(p
, (char **)&p
, 10);
3454 depth
= strtol(p
, (char **)&p
, 10);
3455 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3456 depth
!= 24 && depth
!= 32)
3458 } else if (*p
== '\0') {
3459 depth
= graphic_depth
;
3466 graphic_depth
= depth
;
3469 case QEMU_OPTION_echr
:
3472 term_escape_char
= strtol(optarg
, &r
, 0);
3474 printf("Bad argument to echr\n");
3477 case QEMU_OPTION_monitor
:
3478 default_monitor
= 0;
3479 if (strncmp(optarg
, "none", 4)) {
3480 monitor_parse(optarg
, "readline", false);
3483 case QEMU_OPTION_qmp
:
3484 monitor_parse(optarg
, "control", false);
3485 default_monitor
= 0;
3487 case QEMU_OPTION_qmp_pretty
:
3488 monitor_parse(optarg
, "control", true);
3489 default_monitor
= 0;
3491 case QEMU_OPTION_mon
:
3492 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3497 default_monitor
= 0;
3499 case QEMU_OPTION_chardev
:
3500 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3506 case QEMU_OPTION_fsdev
:
3507 olist
= qemu_find_opts("fsdev");
3509 error_report("fsdev support is disabled");
3512 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3517 case QEMU_OPTION_virtfs
: {
3520 const char *writeout
, *sock_fd
, *socket
;
3522 olist
= qemu_find_opts("virtfs");
3524 error_report("virtfs support is disabled");
3527 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3532 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3533 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3534 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3537 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3538 qemu_opts_id(opts
) ?:
3539 qemu_opt_get(opts
, "mount_tag"),
3542 error_report("duplicate or invalid fsdev id: %s",
3543 qemu_opt_get(opts
, "mount_tag"));
3547 writeout
= qemu_opt_get(opts
, "writeout");
3549 #ifdef CONFIG_SYNC_FILE_RANGE
3550 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3552 error_report("writeout=immediate not supported "
3553 "on this platform");
3557 qemu_opt_set(fsdev
, "fsdriver",
3558 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3559 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3561 qemu_opt_set(fsdev
, "security_model",
3562 qemu_opt_get(opts
, "security_model"),
3564 socket
= qemu_opt_get(opts
, "socket");
3566 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3568 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3570 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3573 qemu_opt_set_bool(fsdev
, "readonly",
3574 qemu_opt_get_bool(opts
, "readonly", 0),
3576 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3578 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3579 qemu_opt_set(device
, "fsdev",
3580 qemu_opts_id(fsdev
), &error_abort
);
3581 qemu_opt_set(device
, "mount_tag",
3582 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3585 case QEMU_OPTION_virtfs_synth
: {
3589 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3592 error_report("duplicate option: %s", "virtfs_synth");
3595 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3597 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3599 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3600 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3601 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3604 case QEMU_OPTION_serial
:
3605 add_device_config(DEV_SERIAL
, optarg
);
3607 if (strncmp(optarg
, "mon:", 4) == 0) {
3608 default_monitor
= 0;
3611 case QEMU_OPTION_watchdog
:
3613 error_report("only one watchdog option may be given");
3618 case QEMU_OPTION_watchdog_action
:
3619 if (select_watchdog_action(optarg
) == -1) {
3620 error_report("unknown -watchdog-action parameter");
3624 case QEMU_OPTION_virtiocon
:
3625 add_device_config(DEV_VIRTCON
, optarg
);
3626 default_virtcon
= 0;
3627 if (strncmp(optarg
, "mon:", 4) == 0) {
3628 default_monitor
= 0;
3631 case QEMU_OPTION_parallel
:
3632 add_device_config(DEV_PARALLEL
, optarg
);
3633 default_parallel
= 0;
3634 if (strncmp(optarg
, "mon:", 4) == 0) {
3635 default_monitor
= 0;
3638 case QEMU_OPTION_debugcon
:
3639 add_device_config(DEV_DEBUGCON
, optarg
);
3641 case QEMU_OPTION_loadvm
:
3644 case QEMU_OPTION_full_screen
:
3647 case QEMU_OPTION_no_frame
:
3650 case QEMU_OPTION_alt_grab
:
3653 case QEMU_OPTION_ctrl_grab
:
3656 case QEMU_OPTION_no_quit
:
3659 case QEMU_OPTION_sdl
:
3661 display_type
= DT_SDL
;
3664 error_report("SDL support is disabled");
3667 case QEMU_OPTION_pidfile
:
3670 case QEMU_OPTION_win2k_hack
:
3671 win2k_install_hack
= 1;
3673 case QEMU_OPTION_rtc_td_hack
: {
3674 static GlobalProperty slew_lost_ticks
= {
3675 .driver
= "mc146818rtc",
3676 .property
= "lost_tick_policy",
3680 qdev_prop_register_global(&slew_lost_ticks
);
3683 case QEMU_OPTION_acpitable
:
3684 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3689 acpi_table_add(opts
, &error_fatal
);
3691 case QEMU_OPTION_smbios
:
3692 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3697 smbios_entry_add(opts
, &error_fatal
);
3699 case QEMU_OPTION_fwcfg
:
3700 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3706 case QEMU_OPTION_enable_kvm
:
3707 olist
= qemu_find_opts("machine");
3708 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3710 case QEMU_OPTION_enable_hax
:
3711 olist
= qemu_find_opts("machine");
3712 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3715 case QEMU_OPTION_machine
:
3716 olist
= qemu_find_opts("machine");
3717 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3722 case QEMU_OPTION_no_kvm
:
3723 olist
= qemu_find_opts("machine");
3724 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3726 case QEMU_OPTION_no_kvm_pit
: {
3727 error_report("warning: ignoring deprecated option");
3730 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3731 static GlobalProperty kvm_pit_lost_tick_policy
= {
3732 .driver
= "kvm-pit",
3733 .property
= "lost_tick_policy",
3737 error_report("warning: deprecated, replaced by "
3738 "-global kvm-pit.lost_tick_policy=discard");
3739 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3742 case QEMU_OPTION_accel
: {
3743 QemuOpts
*accel_opts
;
3745 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3747 optarg
= qemu_opt_get(accel_opts
, "accel");
3748 if (!optarg
|| is_help_option(optarg
)) {
3749 error_printf("Possible accelerators: kvm, xen, hax, tcg\n");
3752 accel_opts
= qemu_opts_create(qemu_find_opts("machine"), NULL
,
3753 false, &error_abort
);
3754 qemu_opt_set(accel_opts
, "accel", optarg
, &error_abort
);
3757 case QEMU_OPTION_usb
:
3758 olist
= qemu_find_opts("machine");
3759 qemu_opts_parse_noisily(olist
, "usb=on", false);
3761 case QEMU_OPTION_usbdevice
:
3762 olist
= qemu_find_opts("machine");
3763 qemu_opts_parse_noisily(olist
, "usb=on", false);
3764 add_device_config(DEV_USB
, optarg
);
3766 case QEMU_OPTION_device
:
3767 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3772 case QEMU_OPTION_smp
:
3773 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3778 case QEMU_OPTION_vnc
:
3779 vnc_parse(optarg
, &error_fatal
);
3781 case QEMU_OPTION_no_acpi
:
3784 case QEMU_OPTION_no_hpet
:
3787 case QEMU_OPTION_balloon
:
3788 if (balloon_parse(optarg
) < 0) {
3789 error_report("unknown -balloon argument %s", optarg
);
3793 case QEMU_OPTION_no_reboot
:
3796 case QEMU_OPTION_no_shutdown
:
3799 case QEMU_OPTION_show_cursor
:
3802 case QEMU_OPTION_uuid
:
3803 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3804 error_report("failed to parse UUID string: wrong format");
3807 qemu_uuid_set
= true;
3809 case QEMU_OPTION_option_rom
:
3810 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3811 error_report("too many option ROMs");
3814 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3819 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3820 option_rom
[nb_option_roms
].bootindex
=
3821 qemu_opt_get_number(opts
, "bootindex", -1);
3822 if (!option_rom
[nb_option_roms
].name
) {
3823 error_report("Option ROM file is not specified");
3828 case QEMU_OPTION_semihosting
:
3829 semihosting
.enabled
= true;
3830 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3832 case QEMU_OPTION_semihosting_config
:
3833 semihosting
.enabled
= true;
3834 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3837 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3839 const char *target
= qemu_opt_get(opts
, "target");
3840 if (target
!= NULL
) {
3841 if (strcmp("native", target
) == 0) {
3842 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3843 } else if (strcmp("gdb", target
) == 0) {
3844 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3845 } else if (strcmp("auto", target
) == 0) {
3846 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3848 error_report("unsupported semihosting-config %s",
3853 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3855 /* Set semihosting argument count and vector */
3856 qemu_opt_foreach(opts
, add_semihosting_arg
,
3857 &semihosting
, NULL
);
3859 error_report("unsupported semihosting-config %s", optarg
);
3863 case QEMU_OPTION_tdf
:
3864 error_report("warning: ignoring deprecated option");
3866 case QEMU_OPTION_name
:
3867 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3873 case QEMU_OPTION_prom_env
:
3874 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3875 error_report("too many prom variables");
3878 prom_envs
[nb_prom_envs
] = optarg
;
3881 case QEMU_OPTION_old_param
:
3884 case QEMU_OPTION_clock
:
3885 /* Clock options no longer exist. Keep this option for
3886 * backward compatibility.
3889 case QEMU_OPTION_startdate
:
3890 configure_rtc_date_offset(optarg
, 1);
3892 case QEMU_OPTION_rtc
:
3893 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3898 configure_rtc(opts
);
3900 case QEMU_OPTION_tb_size
:
3901 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3902 if (tcg_tb_size
< 0) {
3906 case QEMU_OPTION_icount
:
3907 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3913 case QEMU_OPTION_incoming
:
3915 runstate_set(RUN_STATE_INMIGRATE
);
3919 case QEMU_OPTION_only_migratable
:
3920 only_migratable
= 1;
3922 case QEMU_OPTION_nodefaults
:
3925 case QEMU_OPTION_xen_domid
:
3926 if (!(xen_available())) {
3927 error_report("Option not supported for this target");
3930 xen_domid
= atoi(optarg
);
3932 case QEMU_OPTION_xen_create
:
3933 if (!(xen_available())) {
3934 error_report("Option not supported for this target");
3937 xen_mode
= XEN_CREATE
;
3939 case QEMU_OPTION_xen_attach
:
3940 if (!(xen_available())) {
3941 error_report("Option not supported for this target");
3944 xen_mode
= XEN_ATTACH
;
3946 case QEMU_OPTION_xen_domid_restrict
:
3947 if (!(xen_available())) {
3948 error_report("Option not supported for this target");
3951 xen_domid_restrict
= true;
3953 case QEMU_OPTION_trace
:
3955 trace_file
= trace_opt_parse(optarg
);
3957 case QEMU_OPTION_readconfig
:
3959 int ret
= qemu_read_config_file(optarg
);
3961 error_report("read config %s: %s", optarg
,
3967 case QEMU_OPTION_spice
:
3968 olist
= qemu_find_opts("spice");
3970 error_report("spice support is disabled");
3973 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3979 case QEMU_OPTION_writeconfig
:
3982 if (strcmp(optarg
, "-") == 0) {
3985 fp
= fopen(optarg
, "w");
3987 error_report("open %s: %s", optarg
,
3992 qemu_config_write(fp
);
3998 case QEMU_OPTION_qtest
:
3999 qtest_chrdev
= optarg
;
4001 case QEMU_OPTION_qtest_log
:
4004 case QEMU_OPTION_sandbox
:
4005 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4011 case QEMU_OPTION_add_fd
:
4013 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4019 error_report("File descriptor passing is disabled on this "
4024 case QEMU_OPTION_object
:
4025 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
4031 case QEMU_OPTION_realtime
:
4032 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4037 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4039 case QEMU_OPTION_msg
:
4040 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4045 configure_msg(opts
);
4047 case QEMU_OPTION_dump_vmstate
:
4048 if (vmstate_dump_file
) {
4049 error_report("only one '-dump-vmstate' "
4050 "option may be given");
4053 vmstate_dump_file
= fopen(optarg
, "w");
4054 if (vmstate_dump_file
== NULL
) {
4055 error_report("open %s: %s", optarg
, strerror(errno
));
4060 os_parse_cmd_args(popt
->index
, optarg
);
4065 * Clear error location left behind by the loop.
4066 * Best done right after the loop. Do not insert code here!
4070 replay_configure(icount_opts
);
4072 machine_class
= select_machine();
4074 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4078 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4079 error_report("could not acquire pid file: %s", strerror(errno
));
4083 if (qemu_init_main_loop(&main_loop_err
)) {
4084 error_report_err(main_loop_err
);
4088 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4089 parse_sandbox
, NULL
, NULL
)) {
4093 if (qemu_opts_foreach(qemu_find_opts("name"),
4094 parse_name
, NULL
, NULL
)) {
4099 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4100 parse_add_fd
, NULL
, NULL
)) {
4104 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4105 cleanup_add_fd
, NULL
, NULL
)) {
4110 current_machine
= MACHINE(object_new(object_class_get_name(
4111 OBJECT_CLASS(machine_class
))));
4112 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4115 object_property_add_child(object_get_root(), "machine",
4116 OBJECT(current_machine
), &error_abort
);
4118 if (machine_class
->minimum_page_bits
) {
4119 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4120 /* This would be a board error: specifying a minimum smaller than
4121 * a target's compile-time fixed setting.
4123 g_assert_not_reached();
4127 cpu_exec_init_all();
4129 if (machine_class
->hw_version
) {
4130 qemu_set_hw_version(machine_class
->hw_version
);
4133 if (cpu_model
&& is_help_option(cpu_model
)) {
4134 list_cpus(stdout
, &fprintf
, cpu_model
);
4138 if (!trace_init_backends()) {
4141 trace_init_file(trace_file
);
4143 /* Open the logfile at this point and set the log mask if necessary.
4146 qemu_set_log_filename(log_file
, &error_fatal
);
4151 mask
= qemu_str_to_log_mask(log_mask
);
4153 qemu_print_log_usage(stdout
);
4161 /* If no data_dir is specified then try to find it relative to the
4163 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4164 data_dir
[data_dir_idx
] = os_find_datadir();
4165 if (data_dir
[data_dir_idx
] != NULL
) {
4169 /* If all else fails use the install path specified when building. */
4170 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4171 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4174 /* -L help lists the data directories and exits. */
4175 if (list_data_dirs
) {
4176 for (i
= 0; i
< data_dir_idx
; i
++) {
4177 printf("%s\n", data_dir
[i
]);
4182 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4184 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4185 if (max_cpus
> machine_class
->max_cpus
) {
4186 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4187 "supported by machine '%s' (%d)", max_cpus
,
4188 machine_class
->name
, machine_class
->max_cpus
);
4193 * Get the default machine options from the machine if it is not already
4194 * specified either by the configuration file or by the command line.
4196 if (machine_class
->default_machine_opts
) {
4197 qemu_opts_set_defaults(qemu_find_opts("machine"),
4198 machine_class
->default_machine_opts
, 0);
4201 qemu_opts_foreach(qemu_find_opts("device"),
4202 default_driver_check
, NULL
, NULL
);
4203 qemu_opts_foreach(qemu_find_opts("global"),
4204 default_driver_check
, NULL
, NULL
);
4206 if (!vga_model
&& !default_vga
) {
4207 vga_interface_type
= VGA_DEVICE
;
4209 if (!has_defaults
|| machine_class
->no_serial
) {
4212 if (!has_defaults
|| machine_class
->no_parallel
) {
4213 default_parallel
= 0;
4215 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4216 default_virtcon
= 0;
4218 if (!has_defaults
|| !machine_class
->use_sclp
) {
4221 if (!has_defaults
|| machine_class
->no_floppy
) {
4224 if (!has_defaults
|| machine_class
->no_cdrom
) {
4227 if (!has_defaults
|| machine_class
->no_sdcard
) {
4230 if (!has_defaults
) {
4231 default_monitor
= 0;
4236 if (is_daemonized()) {
4237 /* According to documentation and historically, -nographic redirects
4238 * serial port, parallel port and monitor to stdio, which does not work
4239 * with -daemonize. We can redirect these to null instead, but since
4240 * -nographic is legacy, let's just error out.
4241 * We disallow -nographic only if all other ports are not redirected
4242 * explicitly, to not break existing legacy setups which uses
4243 * -nographic _and_ redirects all ports explicitly - this is valid
4244 * usage, -nographic is just a no-op in this case.
4247 && (default_parallel
|| default_serial
4248 || default_monitor
|| default_virtcon
)) {
4249 error_report("-nographic cannot be used with -daemonize");
4252 #ifdef CONFIG_CURSES
4253 if (display_type
== DT_CURSES
) {
4254 error_report("curses display cannot be used with -daemonize");
4261 if (default_parallel
)
4262 add_device_config(DEV_PARALLEL
, "null");
4263 if (default_serial
&& default_monitor
) {
4264 add_device_config(DEV_SERIAL
, "mon:stdio");
4265 } else if (default_virtcon
&& default_monitor
) {
4266 add_device_config(DEV_VIRTCON
, "mon:stdio");
4267 } else if (default_sclp
&& default_monitor
) {
4268 add_device_config(DEV_SCLP
, "mon:stdio");
4271 add_device_config(DEV_SERIAL
, "stdio");
4272 if (default_virtcon
)
4273 add_device_config(DEV_VIRTCON
, "stdio");
4275 add_device_config(DEV_SCLP
, "stdio");
4277 if (default_monitor
)
4278 monitor_parse("stdio", "readline", false);
4282 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4283 if (default_parallel
)
4284 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4285 if (default_monitor
)
4286 monitor_parse("vc:80Cx24C", "readline", false);
4287 if (default_virtcon
)
4288 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4290 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4294 #if defined(CONFIG_VNC)
4295 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4299 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4300 #if defined(CONFIG_GTK)
4301 display_type
= DT_GTK
;
4302 #elif defined(CONFIG_SDL)
4303 display_type
= DT_SDL
;
4304 #elif defined(CONFIG_COCOA)
4305 display_type
= DT_COCOA
;
4306 #elif defined(CONFIG_VNC)
4307 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4309 display_type
= DT_NONE
;
4313 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4314 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4315 "for SDL, ignoring option");
4317 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4318 error_report("-no-quit is only valid for GTK and SDL, "
4322 if (display_type
== DT_GTK
) {
4323 early_gtk_display_init(request_opengl
);
4326 if (display_type
== DT_SDL
) {
4327 sdl_display_early_init(request_opengl
);
4330 qemu_console_early_init();
4332 if (request_opengl
== 1 && display_opengl
== 0) {
4333 #if defined(CONFIG_OPENGL)
4334 error_report("OpenGL is not supported by the display");
4336 error_report("OpenGL support is disabled");
4344 if (qemu_opts_foreach(qemu_find_opts("object"),
4345 user_creatable_add_opts_foreach
,
4346 object_create_initial
, NULL
)) {
4350 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4351 chardev_init_func
, NULL
, NULL
)) {
4355 #ifdef CONFIG_VIRTFS
4356 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4357 fsdev_init_func
, NULL
, NULL
)) {
4362 if (qemu_opts_foreach(qemu_find_opts("device"),
4363 device_help_func
, NULL
, NULL
)) {
4367 machine_opts
= qemu_get_machine_opts();
4368 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4370 object_unref(OBJECT(current_machine
));
4374 configure_accelerator(current_machine
);
4377 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4380 machine_opts
= qemu_get_machine_opts();
4381 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4382 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4383 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4384 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4386 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4388 boot_order
= qemu_opt_get(opts
, "order");
4390 validate_bootdevices(boot_order
, &error_fatal
);
4393 boot_once
= qemu_opt_get(opts
, "once");
4395 validate_bootdevices(boot_once
, &error_fatal
);
4398 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4399 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4403 boot_order
= machine_class
->default_boot_order
;
4406 if (!kernel_cmdline
) {
4407 kernel_cmdline
= "";
4408 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4411 linux_boot
= (kernel_filename
!= NULL
);
4413 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4414 error_report("-append only allowed with -kernel option");
4418 if (!linux_boot
&& initrd_filename
!= NULL
) {
4419 error_report("-initrd only allowed with -kernel option");
4423 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4424 /* fall back to the -kernel/-append */
4425 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4428 os_set_line_buffering();
4430 /* spice needs the timers to be initialized by this point */
4435 if (!tcg_enabled()) {
4436 error_report("-icount is not allowed with hardware virtualization");
4439 configure_icount(icount_opts
, &error_abort
);
4440 qemu_opts_del(icount_opts
);
4443 qemu_tcg_configure(accel_opts
, &error_fatal
);
4446 QemuOptsList
*net
= qemu_find_opts("net");
4447 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4449 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4455 if (net_init_clients() < 0) {
4459 if (qemu_opts_foreach(qemu_find_opts("object"),
4460 user_creatable_add_opts_foreach
,
4461 object_create_delayed
, NULL
)) {
4466 if (tpm_init() < 0) {
4471 /* init the bluetooth world */
4472 if (foreach_device_config(DEV_BT
, bt_parse
))
4475 if (!xen_enabled()) {
4476 /* On 32-bit hosts, QEMU is limited by virtual address space */
4477 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4478 error_report("at most 2047 MB RAM can be simulated");
4486 /* If the currently selected machine wishes to override the units-per-bus
4487 * property of its default HBA interface type, do so now. */
4488 if (machine_class
->units_per_default_bus
) {
4489 override_max_devs(machine_class
->block_default_type
,
4490 machine_class
->units_per_default_bus
);
4493 /* open the virtual block devices */
4494 while (!QSIMPLEQ_EMPTY(&bdo_queue
)) {
4495 BlockdevOptions_queue
*bdo
= QSIMPLEQ_FIRST(&bdo_queue
);
4497 QSIMPLEQ_REMOVE_HEAD(&bdo_queue
, entry
);
4498 loc_push_restore(&bdo
->loc
);
4499 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
4501 qapi_free_BlockdevOptions(bdo
->bdo
);
4504 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4505 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4508 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4509 &machine_class
->block_default_type
, NULL
)) {
4513 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4515 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4516 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4518 parse_numa_opts(current_machine
);
4520 if (qemu_opts_foreach(qemu_find_opts("mon"),
4521 mon_init_func
, NULL
, NULL
)) {
4525 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4527 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4529 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4531 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4534 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4537 /* If no default VGA is requested, the default is "none". */
4539 if (machine_class
->default_display
) {
4540 vga_model
= machine_class
->default_display
;
4541 } else if (vga_interface_available(VGA_CIRRUS
)) {
4542 vga_model
= "cirrus";
4543 } else if (vga_interface_available(VGA_STD
)) {
4548 select_vgahw(vga_model
);
4552 i
= select_watchdog(watchdog
);
4554 exit (i
== 1 ? 1 : 0);
4557 machine_register_compat_props(current_machine
);
4559 qemu_opts_foreach(qemu_find_opts("global"),
4560 global_init_func
, NULL
, NULL
);
4562 /* This checkpoint is required by replay to separate prior clock
4563 reading from the other reads, because timer polling functions query
4564 clock values from the log. */
4565 replay_checkpoint(CHECKPOINT_INIT
);
4566 qdev_machine_init();
4568 current_machine
->ram_size
= ram_size
;
4569 current_machine
->maxram_size
= maxram_size
;
4570 current_machine
->ram_slots
= ram_slots
;
4571 current_machine
->boot_order
= boot_order
;
4572 current_machine
->cpu_model
= cpu_model
;
4574 machine_run_board_init(current_machine
);
4580 if (hax_enabled()) {
4584 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4585 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4589 /* init USB devices */
4590 if (machine_usb(current_machine
)) {
4591 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4595 /* Check if IGD GFX passthrough. */
4598 /* init generic devices */
4599 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4600 if (qemu_opts_foreach(qemu_find_opts("device"),
4601 device_init_func
, NULL
, NULL
)) {
4605 cpu_synchronize_all_post_init();
4607 rom_reset_order_override();
4610 * Create frontends for -drive if=scsi leftovers.
4611 * Normally, frontends for -drive get created by machine
4612 * initialization for onboard SCSI HBAs. However, we create a few
4613 * more ever since SCSI qdevification, but this is pretty much an
4614 * implementation accident, and deprecated.
4616 scsi_legacy_handle_cmdline();
4618 /* Did we create any drives that we failed to create a device for? */
4619 drive_check_orphaned();
4621 /* Don't warn about the default network setup that you get if
4622 * no command line -net or -netdev options are specified. There
4623 * are two cases that we would otherwise complain about:
4624 * (1) board doesn't support a NIC but the implicit "-net nic"
4626 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4627 * sets up a nic that isn't connected to anything.
4630 net_check_clients();
4635 qemu_boot_set(boot_once
, &error_fatal
);
4636 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4639 ds
= init_displaystate();
4641 /* init local displays */
4642 switch (display_type
) {
4644 curses_display_init(ds
, full_screen
);
4647 sdl_display_init(ds
, full_screen
, no_frame
);
4650 cocoa_display_init(ds
, full_screen
);
4653 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4659 /* must be after terminal init, SDL library changes signal handlers */
4660 os_setup_signal_handling();
4662 /* init remote displays */
4664 qemu_opts_foreach(qemu_find_opts("vnc"),
4665 vnc_init_func
, NULL
, NULL
);
4669 qemu_spice_display_init();
4672 #ifdef CONFIG_OPENGL
4673 if (display_type
== DT_EGL
) {
4674 egl_headless_init();
4678 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4682 qdev_machine_creation_done();
4684 /* TODO: once all bus devices are qdevified, this should be done
4685 * when bus is created by qdev.c */
4686 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4687 qemu_run_machine_init_done_notifiers();
4689 if (rom_check_and_register_reset() != 0) {
4690 error_report("rom check and register reset failed");
4696 /* This checkpoint is required by replay to separate prior clock
4697 reading from the other reads, because timer polling functions query
4698 clock values from the log. */
4699 replay_checkpoint(CHECKPOINT_RESET
);
4700 qemu_system_reset(VMRESET_SILENT
);
4701 register_global_state();
4702 if (replay_mode
!= REPLAY_MODE_NONE
) {
4703 replay_vmstate_init();
4704 } else if (loadvm
) {
4705 Error
*local_err
= NULL
;
4706 if (load_vmstate(loadvm
, &local_err
) < 0) {
4707 error_report_err(local_err
);
4712 qdev_prop_check_globals();
4713 if (vmstate_dump_file
) {
4715 dump_vmstate_json_to_file(vmstate_dump_file
);
4720 Error
*local_err
= NULL
;
4721 qemu_start_incoming_migration(incoming
, &local_err
);
4723 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4726 } else if (autostart
) {
4733 replay_disable_events();
4734 iothread_stop_all();
4740 /* vhost-user must be cleaned up before chardevs. */
4745 /* TODO: unref root container, check all devices are ok */