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"
66 #include "sysemu/watchdog.h"
67 #include "hw/smbios/smbios.h"
68 #include "hw/acpi/acpi.h"
69 #include "hw/xen/xen.h"
71 #include "hw/loader.h"
72 #include "monitor/qdev.h"
73 #include "sysemu/bt.h"
75 #include "net/slirp.h"
76 #include "monitor/monitor.h"
77 #include "ui/console.h"
79 #include "sysemu/sysemu.h"
80 #include "sysemu/numa.h"
81 #include "exec/gdbstub.h"
82 #include "qemu/timer.h"
83 #include "sysemu/char.h"
84 #include "qemu/bitmap.h"
86 #include "sysemu/blockdev.h"
87 #include "hw/block/block.h"
88 #include "migration/block.h"
89 #include "sysemu/tpm.h"
90 #include "sysemu/dma.h"
91 #include "audio/audio.h"
92 #include "migration/migration.h"
93 #include "sysemu/cpus.h"
94 #include "migration/colo.h"
95 #include "sysemu/kvm.h"
96 #include "sysemu/hax.h"
97 #include "qapi/qmp/qjson.h"
98 #include "qemu/option.h"
99 #include "qemu/config-file.h"
100 #include "qemu-options.h"
101 #include "qmp-commands.h"
102 #include "qemu/main-loop.h"
104 #include "fsdev/qemu-fsdev.h"
106 #include "sysemu/qtest.h"
108 #include "disas/disas.h"
111 #include "slirp/libslirp.h"
114 #include "trace/control.h"
115 #include "qemu/queue.h"
116 #include "sysemu/arch_init.h"
118 #include "ui/qemu-spice.h"
119 #include "qapi/string-input-visitor.h"
120 #include "qapi/opts-visitor.h"
121 #include "qom/object_interfaces.h"
122 #include "qapi-event.h"
123 #include "exec/semihost.h"
124 #include "crypto/init.h"
125 #include "sysemu/replay.h"
126 #include "qapi/qmp/qerror.h"
127 #include "sysemu/iothread.h"
129 #define MAX_VIRTIO_CONSOLES 1
130 #define MAX_SCLP_CONSOLES 1
132 static const char *data_dir
[16];
133 static int data_dir_idx
;
134 const char *bios_name
= NULL
;
135 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
136 int request_opengl
= -1;
138 const char* keyboard_layout
= NULL
;
140 const char *mem_path
= NULL
;
141 int mem_prealloc
= 0; /* force preallocation of physical target memory */
142 bool enable_mlock
= false;
144 NICInfo nd_table
[MAX_NICS
];
146 static int rtc_utc
= 1;
147 static int rtc_date_offset
= -1; /* -1 means no change */
148 QEMUClockType rtc_clock
;
149 int vga_interface_type
= VGA_NONE
;
150 static int full_screen
= 0;
151 static int no_frame
= 0;
153 static bool grab_on_hover
;
154 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
155 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
156 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
157 CharDriverState
*sclp_hds
[MAX_SCLP_CONSOLES
];
158 int win2k_install_hack
= 0;
164 int acpi_enabled
= 1;
167 static int no_reboot
;
170 int graphic_rotate
= 0;
171 const char *watchdog
;
172 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
175 const char *qemu_name
;
178 unsigned int nb_prom_envs
= 0;
179 const char *prom_envs
[MAX_PROM_ENVS
];
182 uint8_t *boot_splash_filedata
;
183 size_t boot_splash_filedata_size
;
184 uint8_t qemu_extra_params_fw
[2];
186 int icount_align_option
;
188 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
189 * little-endian "wire format" described in the SMBIOS 2.6 specification.
194 static NotifierList exit_notifiers
=
195 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
197 static NotifierList machine_init_done_notifiers
=
198 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
202 enum xen_mode xen_mode
= XEN_EMULATE
;
204 static int has_defaults
= 1;
205 static int default_serial
= 1;
206 static int default_parallel
= 1;
207 static int default_virtcon
= 1;
208 static int default_sclp
= 1;
209 static int default_monitor
= 1;
210 static int default_floppy
= 1;
211 static int default_cdrom
= 1;
212 static int default_sdcard
= 1;
213 static int default_vga
= 1;
214 static int default_net
= 1;
220 { .driver
= "isa-serial", .flag
= &default_serial
},
221 { .driver
= "isa-parallel", .flag
= &default_parallel
},
222 { .driver
= "isa-fdc", .flag
= &default_floppy
},
223 { .driver
= "floppy", .flag
= &default_floppy
},
224 { .driver
= "ide-cd", .flag
= &default_cdrom
},
225 { .driver
= "ide-hd", .flag
= &default_cdrom
},
226 { .driver
= "ide-drive", .flag
= &default_cdrom
},
227 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
228 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
229 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
230 { .driver
= "VGA", .flag
= &default_vga
},
231 { .driver
= "isa-vga", .flag
= &default_vga
},
232 { .driver
= "cirrus-vga", .flag
= &default_vga
},
233 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
234 { .driver
= "vmware-svga", .flag
= &default_vga
},
235 { .driver
= "qxl-vga", .flag
= &default_vga
},
236 { .driver
= "virtio-vga", .flag
= &default_vga
},
239 static QemuOptsList qemu_rtc_opts
= {
241 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
245 .type
= QEMU_OPT_STRING
,
248 .type
= QEMU_OPT_STRING
,
251 .type
= QEMU_OPT_STRING
,
253 { /* end of list */ }
257 static QemuOptsList qemu_sandbox_opts
= {
259 .implied_opt_name
= "enable",
260 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
264 .type
= QEMU_OPT_BOOL
,
266 { /* end of list */ }
270 static QemuOptsList qemu_option_rom_opts
= {
271 .name
= "option-rom",
272 .implied_opt_name
= "romfile",
273 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
277 .type
= QEMU_OPT_NUMBER
,
280 .type
= QEMU_OPT_STRING
,
282 { /* end of list */ }
286 static QemuOptsList qemu_machine_opts
= {
288 .implied_opt_name
= "type",
290 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
293 * no elements => accept any
294 * sanity checking will happen later
295 * when setting machine properties
301 static QemuOptsList qemu_boot_opts
= {
303 .implied_opt_name
= "order",
305 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
309 .type
= QEMU_OPT_STRING
,
312 .type
= QEMU_OPT_STRING
,
315 .type
= QEMU_OPT_BOOL
,
318 .type
= QEMU_OPT_STRING
,
320 .name
= "splash-time",
321 .type
= QEMU_OPT_STRING
,
323 .name
= "reboot-timeout",
324 .type
= QEMU_OPT_STRING
,
327 .type
= QEMU_OPT_BOOL
,
333 static QemuOptsList qemu_add_fd_opts
= {
335 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
339 .type
= QEMU_OPT_NUMBER
,
340 .help
= "file descriptor of which a duplicate is added to fd set",
343 .type
= QEMU_OPT_NUMBER
,
344 .help
= "ID of the fd set to add fd to",
347 .type
= QEMU_OPT_STRING
,
348 .help
= "free-form string used to describe fd",
350 { /* end of list */ }
354 static QemuOptsList qemu_object_opts
= {
356 .implied_opt_name
= "qom-type",
357 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
363 static QemuOptsList qemu_tpmdev_opts
= {
365 .implied_opt_name
= "type",
366 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
368 /* options are defined in the TPM backends */
369 { /* end of list */ }
373 static QemuOptsList qemu_realtime_opts
= {
375 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
379 .type
= QEMU_OPT_BOOL
,
381 { /* end of list */ }
385 static QemuOptsList qemu_msg_opts
= {
387 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
391 .type
= QEMU_OPT_BOOL
,
393 { /* end of list */ }
397 static QemuOptsList qemu_name_opts
= {
399 .implied_opt_name
= "guest",
401 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
405 .type
= QEMU_OPT_STRING
,
406 .help
= "Sets the name of the guest.\n"
407 "This name will be displayed in the SDL window caption.\n"
408 "The name will also be used for the VNC server",
411 .type
= QEMU_OPT_STRING
,
412 .help
= "Sets the name of the QEMU process, as shown in top etc",
414 .name
= "debug-threads",
415 .type
= QEMU_OPT_BOOL
,
416 .help
= "When enabled, name the individual threads; defaults off.\n"
417 "NOTE: The thread names are for debugging and not a\n"
420 { /* End of list */ }
424 static QemuOptsList qemu_mem_opts
= {
426 .implied_opt_name
= "size",
427 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
432 .type
= QEMU_OPT_SIZE
,
436 .type
= QEMU_OPT_NUMBER
,
440 .type
= QEMU_OPT_SIZE
,
442 { /* end of list */ }
446 static QemuOptsList qemu_icount_opts
= {
448 .implied_opt_name
= "shift",
450 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
454 .type
= QEMU_OPT_STRING
,
457 .type
= QEMU_OPT_BOOL
,
460 .type
= QEMU_OPT_BOOL
,
463 .type
= QEMU_OPT_STRING
,
466 .type
= QEMU_OPT_STRING
,
468 { /* end of list */ }
472 static QemuOptsList qemu_semihosting_config_opts
= {
473 .name
= "semihosting-config",
474 .implied_opt_name
= "enable",
475 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
479 .type
= QEMU_OPT_BOOL
,
482 .type
= QEMU_OPT_STRING
,
485 .type
= QEMU_OPT_STRING
,
487 { /* end of list */ }
491 static QemuOptsList qemu_fw_cfg_opts
= {
493 .implied_opt_name
= "name",
494 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
498 .type
= QEMU_OPT_STRING
,
499 .help
= "Sets the fw_cfg name of the blob to be inserted",
502 .type
= QEMU_OPT_STRING
,
503 .help
= "Sets the name of the file from which\n"
504 "the fw_cfg blob will be loaded",
507 .type
= QEMU_OPT_STRING
,
508 .help
= "Sets content of the blob to be inserted from a string",
510 { /* end of list */ }
514 #ifdef CONFIG_LIBISCSI
515 static QemuOptsList qemu_iscsi_opts
= {
517 .head
= QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts
.head
),
521 .type
= QEMU_OPT_STRING
,
522 .help
= "username for CHAP authentication to target",
525 .type
= QEMU_OPT_STRING
,
526 .help
= "password for CHAP authentication to target",
528 .name
= "password-secret",
529 .type
= QEMU_OPT_STRING
,
530 .help
= "ID of the secret providing password for CHAP "
531 "authentication to target",
533 .name
= "header-digest",
534 .type
= QEMU_OPT_STRING
,
535 .help
= "HeaderDigest setting. "
536 "{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
538 .name
= "initiator-name",
539 .type
= QEMU_OPT_STRING
,
540 .help
= "Initiator iqn name to use when connecting",
543 .type
= QEMU_OPT_NUMBER
,
544 .help
= "Request timeout in seconds (default 0 = no timeout)",
546 { /* end of list */ }
552 * Get machine options
554 * Returns: machine options (never null).
556 QemuOpts
*qemu_get_machine_opts(void)
558 return qemu_find_opts_singleton("machine");
561 const char *qemu_get_vm_name(void)
566 static void res_free(void)
568 g_free(boot_splash_filedata
);
569 boot_splash_filedata
= NULL
;
572 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
574 const char *driver
= qemu_opt_get(opts
, "driver");
579 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
580 if (strcmp(default_list
[i
].driver
, driver
) != 0)
582 *(default_list
[i
].flag
) = 0;
587 /***********************************************************/
590 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
592 /* We use RUN_STATE__MAX but any invalid value will do */
593 static RunState vmstop_requested
= RUN_STATE__MAX
;
594 static QemuMutex vmstop_lock
;
599 } RunStateTransition
;
601 static const RunStateTransition runstate_transitions_def
[] = {
603 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
604 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
605 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
607 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
608 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
609 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
610 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
611 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
612 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
613 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
614 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
615 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
616 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
617 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
618 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
620 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
621 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
622 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
624 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
625 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
626 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
628 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
629 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
630 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
631 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
633 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
634 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
635 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
637 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
638 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
639 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
641 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
642 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
643 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
644 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
646 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
647 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
649 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
651 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
652 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
653 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
654 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
655 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
656 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
657 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
658 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
659 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
660 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
661 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
663 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
665 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
666 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
667 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
669 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
670 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
671 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
672 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
673 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
674 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
676 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
677 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
678 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
679 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
681 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
682 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
683 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
685 { RUN_STATE__MAX
, RUN_STATE__MAX
},
688 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
690 bool runstate_check(RunState state
)
692 return current_run_state
== state
;
695 bool runstate_store(char *str
, size_t size
)
697 const char *state
= RunState_lookup
[current_run_state
];
698 size_t len
= strlen(state
) + 1;
703 memcpy(str
, state
, len
);
707 static void runstate_init(void)
709 const RunStateTransition
*p
;
711 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
712 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
713 runstate_valid_transitions
[p
->from
][p
->to
] = true;
716 qemu_mutex_init(&vmstop_lock
);
719 /* This function will abort() on invalid state transitions */
720 void runstate_set(RunState new_state
)
722 assert(new_state
< RUN_STATE__MAX
);
724 if (current_run_state
== new_state
) {
728 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
729 error_report("invalid runstate transition: '%s' -> '%s'",
730 RunState_lookup
[current_run_state
],
731 RunState_lookup
[new_state
]);
734 trace_runstate_set(new_state
);
735 current_run_state
= new_state
;
738 int runstate_is_running(void)
740 return runstate_check(RUN_STATE_RUNNING
);
743 bool runstate_needs_reset(void)
745 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
746 runstate_check(RUN_STATE_SHUTDOWN
);
749 StatusInfo
*qmp_query_status(Error
**errp
)
751 StatusInfo
*info
= g_malloc0(sizeof(*info
));
753 info
->running
= runstate_is_running();
754 info
->singlestep
= singlestep
;
755 info
->status
= current_run_state
;
760 static bool qemu_vmstop_requested(RunState
*r
)
762 qemu_mutex_lock(&vmstop_lock
);
763 *r
= vmstop_requested
;
764 vmstop_requested
= RUN_STATE__MAX
;
765 qemu_mutex_unlock(&vmstop_lock
);
766 return *r
< RUN_STATE__MAX
;
769 void qemu_system_vmstop_request_prepare(void)
771 qemu_mutex_lock(&vmstop_lock
);
774 void qemu_system_vmstop_request(RunState state
)
776 vmstop_requested
= state
;
777 qemu_mutex_unlock(&vmstop_lock
);
785 qemu_vmstop_requested(&requested
);
786 if (runstate_is_running() && requested
== RUN_STATE__MAX
) {
790 /* Ensure that a STOP/RESUME pair of events is emitted if a
791 * vmstop request was pending. The BLOCK_IO_ERROR event, for
792 * example, according to documentation is always followed by
795 if (runstate_is_running()) {
796 qapi_event_send_stop(&error_abort
);
798 replay_enable_events();
800 runstate_set(RUN_STATE_RUNNING
);
801 vm_state_notify(1, RUN_STATE_RUNNING
);
805 qapi_event_send_resume(&error_abort
);
809 /***********************************************************/
810 /* real time host monotonic timer */
812 static time_t qemu_time(void)
814 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
817 /***********************************************************/
818 /* host time/date access */
819 void qemu_get_timedate(struct tm
*tm
, int offset
)
821 time_t ti
= qemu_time();
824 if (rtc_date_offset
== -1) {
828 localtime_r(&ti
, tm
);
830 ti
-= rtc_date_offset
;
835 int qemu_timedate_diff(struct tm
*tm
)
839 if (rtc_date_offset
== -1)
841 seconds
= mktimegm(tm
);
844 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
845 seconds
= mktime(&tmp
);
848 seconds
= mktimegm(tm
) + rtc_date_offset
;
850 return seconds
- qemu_time();
853 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
855 time_t rtc_start_date
;
858 if (!strcmp(startdate
, "now") && legacy
) {
859 rtc_date_offset
= -1;
861 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
869 } else if (sscanf(startdate
, "%d-%d-%d",
881 rtc_start_date
= mktimegm(&tm
);
882 if (rtc_start_date
== -1) {
884 error_report("invalid date format");
885 error_printf("valid formats: "
886 "'2006-06-17T16:01:21' or '2006-06-17'\n");
889 rtc_date_offset
= qemu_time() - rtc_start_date
;
893 static void configure_rtc(QemuOpts
*opts
)
897 value
= qemu_opt_get(opts
, "base");
899 if (!strcmp(value
, "utc")) {
901 } else if (!strcmp(value
, "localtime")) {
902 Error
*blocker
= NULL
;
904 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
905 "-rtc base=localtime");
906 replay_add_blocker(blocker
);
908 configure_rtc_date_offset(value
, 0);
911 value
= qemu_opt_get(opts
, "clock");
913 if (!strcmp(value
, "host")) {
914 rtc_clock
= QEMU_CLOCK_HOST
;
915 } else if (!strcmp(value
, "rt")) {
916 rtc_clock
= QEMU_CLOCK_REALTIME
;
917 } else if (!strcmp(value
, "vm")) {
918 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
920 error_report("invalid option value '%s'", value
);
924 value
= qemu_opt_get(opts
, "driftfix");
926 if (!strcmp(value
, "slew")) {
927 static GlobalProperty slew_lost_ticks
= {
928 .driver
= "mc146818rtc",
929 .property
= "lost_tick_policy",
933 qdev_prop_register_global(&slew_lost_ticks
);
934 } else if (!strcmp(value
, "none")) {
935 /* discard is default */
937 error_report("invalid option value '%s'", value
);
943 /***********************************************************/
944 /* Bluetooth support */
947 static struct HCIInfo
*hci_table
[MAX_NICS
];
949 struct HCIInfo
*qemu_next_hci(void)
951 if (cur_hci
== nb_hcis
)
954 return hci_table
[cur_hci
++];
957 static int bt_hci_parse(const char *str
)
962 if (nb_hcis
>= MAX_NICS
) {
963 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
976 bdaddr
.b
[5] = 0x56 + nb_hcis
;
977 hci
->bdaddr_set(hci
, bdaddr
.b
);
979 hci_table
[nb_hcis
++] = hci
;
984 static void bt_vhci_add(int vlan_id
)
986 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
989 error_report("warning: adding a VHCI to an empty scatternet %i",
992 bt_vhci_init(bt_new_hci(vlan
));
995 static struct bt_device_s
*bt_device_add(const char *opt
)
997 struct bt_scatternet_s
*vlan
;
999 char *endp
= strstr(opt
, ",vlan=");
1000 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
1003 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
1006 vlan_id
= strtol(endp
+ 6, &endp
, 0);
1008 error_report("unrecognised bluetooth vlan Id");
1013 vlan
= qemu_find_bt_vlan(vlan_id
);
1016 error_report("warning: adding a slave device to an empty scatternet %i",
1019 if (!strcmp(devname
, "keyboard"))
1020 return bt_keyboard_init(vlan
);
1022 error_report("unsupported bluetooth device '%s'", devname
);
1026 static int bt_parse(const char *opt
)
1028 const char *endp
, *p
;
1031 if (strstart(opt
, "hci", &endp
)) {
1032 if (!*endp
|| *endp
== ',') {
1034 if (!strstart(endp
, ",vlan=", 0))
1037 return bt_hci_parse(opt
);
1039 } else if (strstart(opt
, "vhci", &endp
)) {
1040 if (!*endp
|| *endp
== ',') {
1042 if (strstart(endp
, ",vlan=", &p
)) {
1043 vlan
= strtol(p
, (char **) &endp
, 0);
1045 error_report("bad scatternet '%s'", p
);
1049 error_report("bad parameter '%s'", endp
+ 1);
1058 } else if (strstart(opt
, "device:", &endp
))
1059 return !bt_device_add(endp
);
1061 error_report("bad bluetooth parameter '%s'", opt
);
1065 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1067 /* FIXME: change this to true for 1.3 */
1068 if (qemu_opt_get_bool(opts
, "enable", false)) {
1069 #ifdef CONFIG_SECCOMP
1070 if (seccomp_start() < 0) {
1071 error_report("failed to install seccomp syscall filter "
1076 error_report("seccomp support is disabled");
1084 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1086 const char *proc_name
;
1088 if (qemu_opt_get(opts
, "debug-threads")) {
1089 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1091 qemu_name
= qemu_opt_get(opts
, "guest");
1093 proc_name
= qemu_opt_get(opts
, "process");
1095 os_set_proc_name(proc_name
);
1101 bool defaults_enabled(void)
1103 return has_defaults
;
1107 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1109 int fd
, dupfd
, flags
;
1111 const char *fd_opaque
= NULL
;
1114 fd
= qemu_opt_get_number(opts
, "fd", -1);
1115 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1116 fd_opaque
= qemu_opt_get(opts
, "opaque");
1119 error_report("fd option is required and must be non-negative");
1123 if (fd
<= STDERR_FILENO
) {
1124 error_report("fd cannot be a standard I/O stream");
1129 * All fds inherited across exec() necessarily have FD_CLOEXEC
1130 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1132 flags
= fcntl(fd
, F_GETFD
);
1133 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1134 error_report("fd is not valid or already in use");
1139 error_report("set option is required and must be non-negative");
1143 #ifdef F_DUPFD_CLOEXEC
1144 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1148 qemu_set_cloexec(dupfd
);
1152 error_report("error duplicating fd: %s", strerror(errno
));
1156 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1157 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1164 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1168 fd
= qemu_opt_get_number(opts
, "fd", -1);
1175 /***********************************************************/
1176 /* QEMU Block devices */
1178 #define HD_OPTS "media=disk"
1179 #define CDROM_OPTS "media=cdrom"
1181 #define PFLASH_OPTS ""
1185 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1187 BlockInterfaceType
*block_default_type
= opaque
;
1189 return drive_new(opts
, *block_default_type
) == NULL
;
1192 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1194 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1195 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1200 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1201 int index
, const char *optstr
)
1206 if (!enable
|| drive_get_by_index(type
, index
)) {
1210 opts
= drive_add(type
, index
, NULL
, optstr
);
1212 drive_enable_snapshot(NULL
, opts
, NULL
);
1215 dinfo
= drive_new(opts
, type
);
1219 dinfo
->is_default
= true;
1223 static QemuOptsList qemu_smp_opts
= {
1225 .implied_opt_name
= "cpus",
1226 .merge_lists
= true,
1227 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1231 .type
= QEMU_OPT_NUMBER
,
1234 .type
= QEMU_OPT_NUMBER
,
1237 .type
= QEMU_OPT_NUMBER
,
1240 .type
= QEMU_OPT_NUMBER
,
1243 .type
= QEMU_OPT_NUMBER
,
1245 { /*End of list */ }
1249 static void smp_parse(QemuOpts
*opts
)
1252 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1253 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1254 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1255 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1257 /* compute missing values, prefer sockets over cores over threads */
1258 if (cpus
== 0 || sockets
== 0) {
1259 sockets
= sockets
> 0 ? sockets
: 1;
1260 cores
= cores
> 0 ? cores
: 1;
1261 threads
= threads
> 0 ? threads
: 1;
1263 cpus
= cores
* threads
* sockets
;
1265 } else if (cores
== 0) {
1266 threads
= threads
> 0 ? threads
: 1;
1267 cores
= cpus
/ (sockets
* threads
);
1268 cores
= cores
> 0 ? cores
: 1;
1269 } else if (threads
== 0) {
1270 threads
= cpus
/ (cores
* sockets
);
1271 threads
= threads
> 0 ? threads
: 1;
1272 } else if (sockets
* cores
* threads
< cpus
) {
1273 error_report("cpu topology: "
1274 "sockets (%u) * cores (%u) * threads (%u) < "
1276 sockets
, cores
, threads
, cpus
);
1280 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1282 if (max_cpus
< cpus
) {
1283 error_report("maxcpus must be equal to or greater than smp");
1287 if (sockets
* cores
* threads
> max_cpus
) {
1288 error_report("cpu topology: "
1289 "sockets (%u) * cores (%u) * threads (%u) > "
1291 sockets
, cores
, threads
, max_cpus
);
1297 smp_threads
= threads
;
1301 Error
*blocker
= NULL
;
1302 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1303 replay_add_blocker(blocker
);
1307 static void realtime_init(void)
1310 if (os_mlock() < 0) {
1311 error_report("locking memory failed");
1318 static void configure_msg(QemuOpts
*opts
)
1320 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1323 /***********************************************************/
1326 typedef struct SemihostingConfig
{
1328 SemihostingTarget target
;
1331 const char *cmdline
; /* concatenated argv */
1332 } SemihostingConfig
;
1334 static SemihostingConfig semihosting
;
1336 bool semihosting_enabled(void)
1338 return semihosting
.enabled
;
1341 SemihostingTarget
semihosting_get_target(void)
1343 return semihosting
.target
;
1346 const char *semihosting_get_arg(int i
)
1348 if (i
>= semihosting
.argc
) {
1351 return semihosting
.argv
[i
];
1354 int semihosting_get_argc(void)
1356 return semihosting
.argc
;
1359 const char *semihosting_get_cmdline(void)
1361 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1362 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1364 return semihosting
.cmdline
;
1367 static int add_semihosting_arg(void *opaque
,
1368 const char *name
, const char *val
,
1371 SemihostingConfig
*s
= opaque
;
1372 if (strcmp(name
, "arg") == 0) {
1374 /* one extra element as g_strjoinv() expects NULL-terminated array */
1375 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1376 s
->argv
[s
->argc
- 1] = val
;
1377 s
->argv
[s
->argc
] = NULL
;
1382 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1383 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1388 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1390 /* split -append and initialize argv[1..n] */
1391 cmd_token
= strtok(g_strdup(cmd
), " ");
1393 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1394 cmd_token
= strtok(NULL
, " ");
1398 /* Now we still need this for compatibility with XEN. */
1399 bool has_igd_gfx_passthru
;
1400 static void igd_gfx_passthru(void)
1402 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1405 /***********************************************************/
1408 static int usb_device_add(const char *devname
)
1410 USBDevice
*dev
= NULL
;
1411 #ifndef CONFIG_LINUX
1415 if (!machine_usb(current_machine
)) {
1419 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1420 dev
= usbdevice_create(devname
);
1424 /* the other ones */
1425 #ifndef CONFIG_LINUX
1426 /* only the linux version is qdev-ified, usb-bsd still needs this */
1427 if (strstart(devname
, "host:", &p
)) {
1428 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1438 static int usb_device_del(const char *devname
)
1443 if (strstart(devname
, "host:", &p
)) {
1447 if (!machine_usb(current_machine
)) {
1451 p
= strchr(devname
, '.');
1454 bus_num
= strtoul(devname
, NULL
, 0);
1455 addr
= strtoul(p
+ 1, NULL
, 0);
1457 return usb_device_delete_addr(bus_num
, addr
);
1460 static int usb_parse(const char *cmdline
)
1463 r
= usb_device_add(cmdline
);
1465 error_report("could not add USB device '%s'", cmdline
);
1470 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1472 const char *devname
= qdict_get_str(qdict
, "devname");
1473 if (usb_device_add(devname
) < 0) {
1474 error_report("could not add USB device '%s'", devname
);
1478 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1480 const char *devname
= qdict_get_str(qdict
, "devname");
1481 if (usb_device_del(devname
) < 0) {
1482 error_report("could not delete USB device '%s'", devname
);
1486 /***********************************************************/
1487 /* machine registration */
1489 MachineState
*current_machine
;
1491 static MachineClass
*find_machine(const char *name
)
1493 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1494 MachineClass
*mc
= NULL
;
1496 for (el
= machines
; el
; el
= el
->next
) {
1497 MachineClass
*temp
= el
->data
;
1499 if (!strcmp(temp
->name
, name
)) {
1504 !strcmp(temp
->alias
, name
)) {
1510 g_slist_free(machines
);
1514 MachineClass
*find_default_machine(void)
1516 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1517 MachineClass
*mc
= NULL
;
1519 for (el
= machines
; el
; el
= el
->next
) {
1520 MachineClass
*temp
= el
->data
;
1522 if (temp
->is_default
) {
1528 g_slist_free(machines
);
1532 MachineInfoList
*qmp_query_machines(Error
**errp
)
1534 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1535 MachineInfoList
*mach_list
= NULL
;
1537 for (el
= machines
; el
; el
= el
->next
) {
1538 MachineClass
*mc
= el
->data
;
1539 MachineInfoList
*entry
;
1542 info
= g_malloc0(sizeof(*info
));
1543 if (mc
->is_default
) {
1544 info
->has_is_default
= true;
1545 info
->is_default
= true;
1549 info
->has_alias
= true;
1550 info
->alias
= g_strdup(mc
->alias
);
1553 info
->name
= g_strdup(mc
->name
);
1554 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1555 info
->hotpluggable_cpus
= !!mc
->query_hotpluggable_cpus
;
1557 entry
= g_malloc0(sizeof(*entry
));
1558 entry
->value
= info
;
1559 entry
->next
= mach_list
;
1563 g_slist_free(machines
);
1567 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1569 ObjectProperty
*prop
;
1570 ObjectPropertyIterator iter
;
1572 if (!qemu_opt_has_help_opt(opts
)) {
1576 object_property_iter_init(&iter
, OBJECT(machine
));
1577 while ((prop
= object_property_iter_next(&iter
))) {
1582 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1583 prop
->name
, prop
->type
);
1584 if (prop
->description
) {
1585 error_printf(" (%s)\n", prop
->description
);
1594 /***********************************************************/
1595 /* main execution loop */
1597 struct vm_change_state_entry
{
1598 VMChangeStateHandler
*cb
;
1600 QLIST_ENTRY (vm_change_state_entry
) entries
;
1603 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1605 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1608 VMChangeStateEntry
*e
;
1610 e
= g_malloc0(sizeof (*e
));
1614 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1618 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1620 QLIST_REMOVE (e
, entries
);
1624 void vm_state_notify(int running
, RunState state
)
1626 VMChangeStateEntry
*e
, *next
;
1628 trace_vm_state_notify(running
, state
);
1630 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1631 e
->cb(e
->opaque
, running
, state
);
1635 static int reset_requested
;
1636 static int shutdown_requested
, shutdown_signal
= -1;
1637 static pid_t shutdown_pid
;
1638 static int powerdown_requested
;
1639 static int debug_requested
;
1640 static int suspend_requested
;
1641 static WakeupReason wakeup_reason
;
1642 static NotifierList powerdown_notifiers
=
1643 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1644 static NotifierList suspend_notifiers
=
1645 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1646 static NotifierList wakeup_notifiers
=
1647 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1648 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1650 int qemu_shutdown_requested_get(void)
1652 return shutdown_requested
;
1655 int qemu_reset_requested_get(void)
1657 return reset_requested
;
1660 static int qemu_shutdown_requested(void)
1662 return atomic_xchg(&shutdown_requested
, 0);
1665 static void qemu_kill_report(void)
1667 if (!qtest_driver() && shutdown_signal
!= -1) {
1668 if (shutdown_pid
== 0) {
1669 /* This happens for eg ^C at the terminal, so it's worth
1670 * avoiding printing an odd message in that case.
1672 error_report("terminating on signal %d", shutdown_signal
);
1674 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1676 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1677 shutdown_signal
, shutdown_pid
,
1678 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1679 g_free(shutdown_cmd
);
1681 shutdown_signal
= -1;
1685 static int qemu_reset_requested(void)
1687 int r
= reset_requested
;
1688 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1689 reset_requested
= 0;
1695 static int qemu_suspend_requested(void)
1697 int r
= suspend_requested
;
1698 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1699 suspend_requested
= 0;
1705 static WakeupReason
qemu_wakeup_requested(void)
1707 return wakeup_reason
;
1710 static int qemu_powerdown_requested(void)
1712 int r
= powerdown_requested
;
1713 powerdown_requested
= 0;
1717 static int qemu_debug_requested(void)
1719 int r
= debug_requested
;
1720 debug_requested
= 0;
1724 void qemu_system_reset(bool report
)
1728 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1730 cpu_synchronize_all_states();
1732 if (mc
&& mc
->reset
) {
1735 qemu_devices_reset();
1738 qapi_event_send_reset(&error_abort
);
1740 cpu_synchronize_all_post_reset();
1743 void qemu_system_guest_panicked(void)
1746 current_cpu
->crash_occurred
= true;
1748 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
, &error_abort
);
1749 vm_stop(RUN_STATE_GUEST_PANICKED
);
1751 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1753 qemu_system_shutdown_request();
1757 void qemu_system_reset_request(void)
1760 shutdown_requested
= 1;
1762 reset_requested
= 1;
1765 qemu_notify_event();
1768 static void qemu_system_suspend(void)
1771 notifier_list_notify(&suspend_notifiers
, NULL
);
1772 runstate_set(RUN_STATE_SUSPENDED
);
1773 qapi_event_send_suspend(&error_abort
);
1776 void qemu_system_suspend_request(void)
1778 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1781 suspend_requested
= 1;
1783 qemu_notify_event();
1786 void qemu_register_suspend_notifier(Notifier
*notifier
)
1788 notifier_list_add(&suspend_notifiers
, notifier
);
1791 void qemu_system_wakeup_request(WakeupReason reason
)
1793 trace_system_wakeup_request(reason
);
1795 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1798 if (!(wakeup_reason_mask
& (1 << reason
))) {
1801 runstate_set(RUN_STATE_RUNNING
);
1802 wakeup_reason
= reason
;
1803 qemu_notify_event();
1806 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1809 wakeup_reason_mask
|= (1 << reason
);
1811 wakeup_reason_mask
&= ~(1 << reason
);
1815 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1817 notifier_list_add(&wakeup_notifiers
, notifier
);
1820 void qemu_system_killed(int signal
, pid_t pid
)
1822 shutdown_signal
= signal
;
1826 /* Cannot call qemu_system_shutdown_request directly because
1827 * we are in a signal handler.
1829 shutdown_requested
= 1;
1830 qemu_notify_event();
1833 void qemu_system_shutdown_request(void)
1835 trace_qemu_system_shutdown_request();
1836 replay_shutdown_request();
1837 shutdown_requested
= 1;
1838 qemu_notify_event();
1841 static void qemu_system_powerdown(void)
1843 qapi_event_send_powerdown(&error_abort
);
1844 notifier_list_notify(&powerdown_notifiers
, NULL
);
1847 void qemu_system_powerdown_request(void)
1849 trace_qemu_system_powerdown_request();
1850 powerdown_requested
= 1;
1851 qemu_notify_event();
1854 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1856 notifier_list_add(&powerdown_notifiers
, notifier
);
1859 void qemu_system_debug_request(void)
1861 debug_requested
= 1;
1862 qemu_notify_event();
1865 static bool main_loop_should_exit(void)
1868 if (qemu_debug_requested()) {
1869 vm_stop(RUN_STATE_DEBUG
);
1871 if (qemu_suspend_requested()) {
1872 qemu_system_suspend();
1874 if (qemu_shutdown_requested()) {
1876 qapi_event_send_shutdown(&error_abort
);
1878 vm_stop(RUN_STATE_SHUTDOWN
);
1883 if (qemu_reset_requested()) {
1885 qemu_system_reset(VMRESET_REPORT
);
1887 if (!runstate_check(RUN_STATE_RUNNING
) &&
1888 !runstate_check(RUN_STATE_INMIGRATE
)) {
1889 runstate_set(RUN_STATE_PRELAUNCH
);
1892 if (qemu_wakeup_requested()) {
1894 qemu_system_reset(VMRESET_SILENT
);
1895 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1896 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1898 qapi_event_send_wakeup(&error_abort
);
1900 if (qemu_powerdown_requested()) {
1901 qemu_system_powerdown();
1903 if (qemu_vmstop_requested(&r
)) {
1909 static void main_loop(void)
1913 #ifdef CONFIG_PROFILER
1917 nonblocking
= tcg_enabled() && last_io
> 0;
1918 #ifdef CONFIG_PROFILER
1919 ti
= profile_getclock();
1921 last_io
= main_loop_wait(nonblocking
);
1922 #ifdef CONFIG_PROFILER
1923 dev_time
+= profile_getclock() - ti
;
1925 } while (!main_loop_should_exit());
1928 static void version(void)
1930 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1931 QEMU_COPYRIGHT
"\n");
1934 static void help(int exitcode
)
1937 printf("usage: %s [options] [disk_image]\n\n"
1938 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1939 error_get_progname());
1941 #define QEMU_OPTIONS_GENERATE_HELP
1942 #include "qemu-options-wrapper.h"
1944 printf("\nDuring emulation, the following keys are useful:\n"
1945 "ctrl-alt-f toggle full screen\n"
1946 "ctrl-alt-n switch to virtual console 'n'\n"
1947 "ctrl-alt toggle mouse and keyboard grab\n"
1949 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1954 #define HAS_ARG 0x0001
1956 typedef struct QEMUOption
{
1963 static const QEMUOption qemu_options
[] = {
1964 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1965 #define QEMU_OPTIONS_GENERATE_OPTIONS
1966 #include "qemu-options-wrapper.h"
1970 typedef struct VGAInterfaceInfo
{
1971 const char *opt_name
; /* option name */
1972 const char *name
; /* human-readable name */
1973 /* Class names indicating that support is available.
1974 * If no class is specified, the interface is always available */
1975 const char *class_names
[2];
1978 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1984 .name
= "standard VGA",
1985 .class_names
= { "VGA", "isa-vga" },
1988 .opt_name
= "cirrus",
1989 .name
= "Cirrus VGA",
1990 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1993 .opt_name
= "vmware",
1994 .name
= "VMWare SVGA",
1995 .class_names
= { "vmware-svga" },
1998 .opt_name
= "virtio",
1999 .name
= "Virtio VGA",
2000 .class_names
= { "virtio-vga" },
2005 .class_names
= { "qxl-vga" },
2009 .name
= "TCX framebuffer",
2010 .class_names
= { "SUNW,tcx" },
2014 .name
= "CG3 framebuffer",
2015 .class_names
= { "cgthree" },
2018 .opt_name
= "xenfb",
2022 static bool vga_interface_available(VGAInterfaceType t
)
2024 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2026 assert(t
< VGA_TYPE_MAX
);
2027 return !ti
->class_names
[0] ||
2028 object_class_by_name(ti
->class_names
[0]) ||
2029 object_class_by_name(ti
->class_names
[1]);
2032 static void select_vgahw(const char *p
)
2037 assert(vga_interface_type
== VGA_NONE
);
2038 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2039 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2040 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2041 if (!vga_interface_available(t
)) {
2042 error_report("%s not available", ti
->name
);
2045 vga_interface_type
= t
;
2049 if (t
== VGA_TYPE_MAX
) {
2051 error_report("unknown vga type: %s", p
);
2055 const char *nextopt
;
2057 if (strstart(opts
, ",retrace=", &nextopt
)) {
2059 if (strstart(opts
, "dumb", &nextopt
))
2060 vga_retrace_method
= VGA_RETRACE_DUMB
;
2061 else if (strstart(opts
, "precise", &nextopt
))
2062 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2063 else goto invalid_vga
;
2064 } else goto invalid_vga
;
2069 typedef enum DisplayType
{
2078 static DisplayType
select_display(const char *p
)
2081 DisplayType display
= DT_DEFAULT
;
2083 if (strstart(p
, "sdl", &opts
)) {
2087 const char *nextopt
;
2089 if (strstart(opts
, ",frame=", &nextopt
)) {
2091 if (strstart(opts
, "on", &nextopt
)) {
2093 } else if (strstart(opts
, "off", &nextopt
)) {
2096 goto invalid_sdl_args
;
2098 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2100 if (strstart(opts
, "on", &nextopt
)) {
2102 } else if (strstart(opts
, "off", &nextopt
)) {
2105 goto invalid_sdl_args
;
2107 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2109 if (strstart(opts
, "on", &nextopt
)) {
2111 } else if (strstart(opts
, "off", &nextopt
)) {
2114 goto invalid_sdl_args
;
2116 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2118 if (strstart(opts
, "on", &nextopt
)) {
2120 } else if (strstart(opts
, "off", &nextopt
)) {
2123 goto invalid_sdl_args
;
2125 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2127 if (strstart(opts
, "on", &nextopt
)) {
2129 } else if (strstart(opts
, "off", &nextopt
)) {
2132 goto invalid_sdl_args
;
2136 error_report("invalid SDL option string");
2142 error_report("SDL support is disabled");
2145 } else if (strstart(p
, "vnc", &opts
)) {
2147 vnc_parse(opts
+ 1, &error_fatal
);
2149 error_report("VNC requires a display argument vnc=<display>");
2152 } else if (strstart(p
, "curses", &opts
)) {
2153 #ifdef CONFIG_CURSES
2154 display
= DT_CURSES
;
2156 error_report("curses support is disabled");
2159 } else if (strstart(p
, "gtk", &opts
)) {
2163 const char *nextopt
;
2165 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2167 if (strstart(opts
, "on", &nextopt
)) {
2168 grab_on_hover
= true;
2169 } else if (strstart(opts
, "off", &nextopt
)) {
2170 grab_on_hover
= false;
2172 goto invalid_gtk_args
;
2174 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2176 if (strstart(opts
, "on", &nextopt
)) {
2178 } else if (strstart(opts
, "off", &nextopt
)) {
2181 goto invalid_gtk_args
;
2185 error_report("invalid GTK option string");
2191 error_report("GTK support is disabled");
2194 } else if (strstart(p
, "none", &opts
)) {
2197 error_report("unknown display type");
2204 static int balloon_parse(const char *arg
)
2208 if (strcmp(arg
, "none") == 0) {
2212 if (!strncmp(arg
, "virtio", 6)) {
2213 if (arg
[6] == ',') {
2214 /* have params -> parse them */
2215 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2220 /* create empty opts */
2221 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2224 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2231 char *qemu_find_file(int type
, const char *name
)
2237 /* Try the name as a straight path first */
2238 if (access(name
, R_OK
) == 0) {
2239 trace_load_file(name
, name
);
2240 return g_strdup(name
);
2244 case QEMU_FILE_TYPE_BIOS
:
2247 case QEMU_FILE_TYPE_KEYMAP
:
2248 subdir
= "keymaps/";
2254 for (i
= 0; i
< data_dir_idx
; i
++) {
2255 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2256 if (access(buf
, R_OK
) == 0) {
2257 trace_load_file(name
, buf
);
2265 static inline bool nonempty_str(const char *str
)
2270 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2274 const char *name
, *file
, *str
;
2275 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2277 if (fw_cfg
== NULL
) {
2278 error_report("fw_cfg device not available");
2281 name
= qemu_opt_get(opts
, "name");
2282 file
= qemu_opt_get(opts
, "file");
2283 str
= qemu_opt_get(opts
, "string");
2285 /* we need name and either a file or the content string */
2286 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2287 error_report("invalid argument(s)");
2290 if (nonempty_str(file
) && nonempty_str(str
)) {
2291 error_report("file and string are mutually exclusive");
2294 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2295 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2298 if (strncmp(name
, "opt/", 4) != 0) {
2299 error_report("warning: externally provided fw_cfg item names "
2300 "should be prefixed with \"opt/\"");
2302 if (nonempty_str(str
)) {
2303 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2304 buf
= g_memdup(str
, size
);
2306 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2307 error_report("can't load %s", file
);
2311 /* For legacy, keep user files in a specific global order. */
2312 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2313 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2314 fw_cfg_reset_order_override(fw_cfg
);
2318 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2320 return qdev_device_help(opts
);
2323 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2328 dev
= qdev_device_add(opts
, &err
);
2330 error_report_err(err
);
2333 object_unref(OBJECT(dev
));
2337 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2339 Error
*local_err
= NULL
;
2341 qemu_chr_new_from_opts(opts
, &local_err
);
2343 error_report_err(local_err
);
2349 #ifdef CONFIG_VIRTFS
2350 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2352 return qemu_fsdev_add(opts
);
2356 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2358 CharDriverState
*chr
;
2359 const char *chardev
;
2363 mode
= qemu_opt_get(opts
, "mode");
2367 if (strcmp(mode
, "readline") == 0) {
2368 flags
= MONITOR_USE_READLINE
;
2369 } else if (strcmp(mode
, "control") == 0) {
2370 flags
= MONITOR_USE_CONTROL
;
2372 error_report("unknown monitor mode \"%s\"", mode
);
2376 if (qemu_opt_get_bool(opts
, "pretty", 0))
2377 flags
|= MONITOR_USE_PRETTY
;
2379 if (qemu_opt_get_bool(opts
, "default", 0)) {
2380 error_report("option 'default' does nothing and is deprecated");
2383 chardev
= qemu_opt_get(opts
, "chardev");
2384 chr
= qemu_chr_find(chardev
);
2386 error_report("chardev \"%s\" not found", chardev
);
2390 monitor_init(chr
, flags
);
2394 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2396 static int monitor_device_index
= 0;
2401 if (strstart(optarg
, "chardev:", &p
)) {
2402 snprintf(label
, sizeof(label
), "%s", p
);
2404 snprintf(label
, sizeof(label
), "compat_monitor%d",
2405 monitor_device_index
);
2406 opts
= qemu_chr_parse_compat(label
, optarg
);
2408 error_report("parse error: %s", optarg
);
2413 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2414 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2415 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2416 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2417 monitor_device_index
++;
2420 struct device_config
{
2422 DEV_USB
, /* -usbdevice */
2424 DEV_SERIAL
, /* -serial */
2425 DEV_PARALLEL
, /* -parallel */
2426 DEV_VIRTCON
, /* -virtioconsole */
2427 DEV_DEBUGCON
, /* -debugcon */
2428 DEV_GDB
, /* -gdb, -s */
2429 DEV_SCLP
, /* s390 sclp */
2431 const char *cmdline
;
2433 QTAILQ_ENTRY(device_config
) next
;
2436 static QTAILQ_HEAD(, device_config
) device_configs
=
2437 QTAILQ_HEAD_INITIALIZER(device_configs
);
2439 static void add_device_config(int type
, const char *cmdline
)
2441 struct device_config
*conf
;
2443 conf
= g_malloc0(sizeof(*conf
));
2445 conf
->cmdline
= cmdline
;
2446 loc_save(&conf
->loc
);
2447 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2450 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2452 struct device_config
*conf
;
2455 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2456 if (conf
->type
!= type
)
2458 loc_push_restore(&conf
->loc
);
2459 rc
= func(conf
->cmdline
);
2460 loc_pop(&conf
->loc
);
2468 static int serial_parse(const char *devname
)
2470 static int index
= 0;
2473 if (strcmp(devname
, "none") == 0)
2475 if (index
== MAX_SERIAL_PORTS
) {
2476 error_report("too many serial ports");
2479 snprintf(label
, sizeof(label
), "serial%d", index
);
2480 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2481 if (!serial_hds
[index
]) {
2482 error_report("could not connect serial device"
2483 " to character backend '%s'", devname
);
2490 static int parallel_parse(const char *devname
)
2492 static int index
= 0;
2495 if (strcmp(devname
, "none") == 0)
2497 if (index
== MAX_PARALLEL_PORTS
) {
2498 error_report("too many parallel ports");
2501 snprintf(label
, sizeof(label
), "parallel%d", index
);
2502 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2503 if (!parallel_hds
[index
]) {
2504 error_report("could not connect parallel device"
2505 " to character backend '%s'", devname
);
2512 static int virtcon_parse(const char *devname
)
2514 QemuOptsList
*device
= qemu_find_opts("device");
2515 static int index
= 0;
2517 QemuOpts
*bus_opts
, *dev_opts
;
2519 if (strcmp(devname
, "none") == 0)
2521 if (index
== MAX_VIRTIO_CONSOLES
) {
2522 error_report("too many virtio consoles");
2526 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2527 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2529 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2530 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2532 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2533 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2534 if (!virtcon_hds
[index
]) {
2535 error_report("could not connect virtio console"
2536 " to character backend '%s'", devname
);
2539 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2545 static int sclp_parse(const char *devname
)
2547 QemuOptsList
*device
= qemu_find_opts("device");
2548 static int index
= 0;
2552 if (strcmp(devname
, "none") == 0) {
2555 if (index
== MAX_SCLP_CONSOLES
) {
2556 error_report("too many sclp consoles");
2560 assert(arch_type
== QEMU_ARCH_S390X
);
2562 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2563 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2565 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2566 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2567 if (!sclp_hds
[index
]) {
2568 error_report("could not connect sclp console"
2569 " to character backend '%s'", devname
);
2572 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2578 static int debugcon_parse(const char *devname
)
2582 if (!qemu_chr_new("debugcon", devname
)) {
2585 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2587 error_report("already have a debugcon device");
2590 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2591 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2595 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2597 const MachineClass
*mc1
= a
, *mc2
= b
;
2600 if (mc1
->family
== NULL
) {
2601 if (mc2
->family
== NULL
) {
2602 /* Compare standalone machine types against each other; they sort
2603 * in increasing order.
2605 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2606 object_class_get_name(OBJECT_CLASS(mc2
)));
2609 /* Standalone machine types sort after families. */
2613 if (mc2
->family
== NULL
) {
2614 /* Families sort before standalone machine types. */
2618 /* Families sort between each other alphabetically increasingly. */
2619 res
= strcmp(mc1
->family
, mc2
->family
);
2624 /* Within the same family, machine types sort in decreasing order. */
2625 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2626 object_class_get_name(OBJECT_CLASS(mc1
)));
2629 static MachineClass
*machine_parse(const char *name
)
2631 MachineClass
*mc
= NULL
;
2632 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2635 mc
= find_machine(name
);
2638 g_slist_free(machines
);
2641 if (name
&& !is_help_option(name
)) {
2642 error_report("unsupported machine type");
2643 error_printf("Use -machine help to list supported machines\n");
2645 printf("Supported machines are:\n");
2646 machines
= g_slist_sort(machines
, machine_class_cmp
);
2647 for (el
= machines
; el
; el
= el
->next
) {
2648 MachineClass
*mc
= el
->data
;
2650 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2652 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2653 mc
->is_default
? " (default)" : "");
2657 g_slist_free(machines
);
2658 exit(!name
|| !is_help_option(name
));
2661 void qemu_add_exit_notifier(Notifier
*notify
)
2663 notifier_list_add(&exit_notifiers
, notify
);
2666 void qemu_remove_exit_notifier(Notifier
*notify
)
2668 notifier_remove(notify
);
2671 static void qemu_run_exit_notifiers(void)
2673 notifier_list_notify(&exit_notifiers
, NULL
);
2676 static bool machine_init_done
;
2678 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2680 notifier_list_add(&machine_init_done_notifiers
, notify
);
2681 if (machine_init_done
) {
2682 notify
->notify(notify
, NULL
);
2686 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2688 notifier_remove(notify
);
2691 static void qemu_run_machine_init_done_notifiers(void)
2693 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2694 machine_init_done
= true;
2697 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2698 const char **poptarg
, int *poptind
)
2700 const QEMUOption
*popt
;
2701 int optind
= *poptind
;
2702 char *r
= argv
[optind
];
2705 loc_set_cmdline(argv
, optind
, 1);
2707 /* Treat --foo the same as -foo. */
2710 popt
= qemu_options
;
2713 error_report("invalid option");
2716 if (!strcmp(popt
->name
, r
+ 1))
2720 if (popt
->flags
& HAS_ARG
) {
2721 if (optind
>= argc
) {
2722 error_report("requires an argument");
2725 optarg
= argv
[optind
++];
2726 loc_set_cmdline(argv
, optind
- 2, 2);
2737 static MachineClass
*select_machine(void)
2739 MachineClass
*machine_class
= find_default_machine();
2744 loc_push_none(&loc
);
2746 opts
= qemu_get_machine_opts();
2747 qemu_opts_loc_restore(opts
);
2749 optarg
= qemu_opt_get(opts
, "type");
2751 machine_class
= machine_parse(optarg
);
2754 if (!machine_class
) {
2755 error_report("No machine specified, and there is no default");
2756 error_printf("Use -machine help to list supported machines\n");
2761 return machine_class
;
2764 static int machine_set_property(void *opaque
,
2765 const char *name
, const char *value
,
2768 Object
*obj
= OBJECT(opaque
);
2769 Error
*local_err
= NULL
;
2772 if (strcmp(name
, "type") == 0) {
2776 qom_name
= g_strdup(name
);
2777 for (p
= qom_name
; *p
; p
++) {
2783 object_property_parse(obj
, value
, qom_name
, &local_err
);
2787 error_report_err(local_err
);
2796 * Initial object creation happens before all other
2797 * QEMU data types are created. The majority of objects
2798 * can be created at this point. The rng-egd object
2799 * cannot be created here, as it depends on the chardev
2802 static bool object_create_initial(const char *type
)
2804 if (g_str_equal(type
, "rng-egd")) {
2809 * return false for concrete netfilters since
2810 * they depend on netdevs already existing
2812 if (g_str_equal(type
, "filter-buffer") ||
2813 g_str_equal(type
, "filter-dump") ||
2814 g_str_equal(type
, "filter-mirror") ||
2815 g_str_equal(type
, "filter-redirector") ||
2816 g_str_equal(type
, "colo-compare") ||
2817 g_str_equal(type
, "filter-rewriter") ||
2818 g_str_equal(type
, "filter-replay")) {
2822 /* Memory allocation by backends needs to be done
2823 * after configure_accelerator() (due to the tcg_enabled()
2824 * checks at memory_region_init_*()).
2826 * Also, allocation of large amounts of memory may delay
2827 * chardev initialization for too long, and trigger timeouts
2828 * on software that waits for a monitor socket to be created
2831 if (g_str_has_prefix(type
, "memory-backend-")) {
2840 * The remainder of object creation happens after the
2841 * creation of chardev, fsdev, net clients and device data types.
2843 static bool object_create_delayed(const char *type
)
2845 return !object_create_initial(type
);
2849 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2853 const char *mem_str
;
2854 const char *maxmem_str
, *slots_str
;
2855 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2856 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2859 loc_push_none(&loc
);
2860 qemu_opts_loc_restore(opts
);
2863 mem_str
= qemu_opt_get(opts
, "size");
2866 error_report("missing 'size' option value");
2870 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2872 /* Fix up legacy suffix-less format */
2873 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2874 uint64_t overflow_check
= sz
;
2877 if ((sz
>> 20) != overflow_check
) {
2878 error_report("too large 'size' option value");
2884 /* backward compatibility behaviour for case "-m 0" */
2886 sz
= default_ram_size
;
2889 sz
= QEMU_ALIGN_UP(sz
, 8192);
2891 if (ram_size
!= sz
) {
2892 error_report("ram size too large");
2896 /* store value for the future use */
2897 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2898 *maxram_size
= ram_size
;
2900 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2901 slots_str
= qemu_opt_get(opts
, "slots");
2902 if (maxmem_str
&& slots_str
) {
2905 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2906 slots
= qemu_opt_get_number(opts
, "slots", 0);
2907 if (sz
< ram_size
) {
2908 error_report("invalid value of -m option maxmem: "
2909 "maximum memory size (0x%" PRIx64
") must be at least "
2910 "the initial memory size (0x" RAM_ADDR_FMT
")",
2913 } else if (sz
> ram_size
) {
2915 error_report("invalid value of -m option: maxmem was "
2916 "specified, but no hotplug slots were specified");
2920 error_report("invalid value of -m option maxmem: "
2921 "memory slots were specified but maximum memory size "
2922 "(0x%" PRIx64
") is equal to the initial memory size "
2923 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2929 } else if ((!maxmem_str
&& slots_str
) ||
2930 (maxmem_str
&& !slots_str
)) {
2931 error_report("invalid -m option value: missing "
2932 "'%s' option", slots_str
? "maxmem" : "slots");
2939 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2943 g
= g_malloc0(sizeof(*g
));
2944 g
->driver
= qemu_opt_get(opts
, "driver");
2945 g
->property
= qemu_opt_get(opts
, "property");
2946 g
->value
= qemu_opt_get(opts
, "value");
2947 g
->user_provided
= true;
2948 g
->errp
= &error_fatal
;
2949 qdev_prop_register_global(g
);
2953 static int qemu_read_default_config_file(void)
2957 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2958 if (ret
< 0 && ret
!= -ENOENT
) {
2965 int main(int argc
, char **argv
, char **envp
)
2968 int snapshot
, linux_boot
;
2969 const char *initrd_filename
;
2970 const char *kernel_filename
, *kernel_cmdline
;
2971 const char *boot_order
= NULL
;
2972 const char *boot_once
= NULL
;
2974 int cyls
, heads
, secs
, translation
;
2975 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
2976 QemuOptsList
*olist
;
2979 const char *loadvm
= NULL
;
2980 MachineClass
*machine_class
;
2981 const char *cpu_model
;
2982 const char *vga_model
= NULL
;
2983 const char *qtest_chrdev
= NULL
;
2984 const char *qtest_log
= NULL
;
2985 const char *pid_file
= NULL
;
2986 const char *incoming
= NULL
;
2987 bool defconfig
= true;
2988 bool userconfig
= true;
2989 bool nographic
= false;
2990 DisplayType display_type
= DT_DEFAULT
;
2991 int display_remote
= 0;
2992 const char *log_mask
= NULL
;
2993 const char *log_file
= NULL
;
2994 char *trace_file
= NULL
;
2995 ram_addr_t maxram_size
;
2996 uint64_t ram_slots
= 0;
2997 FILE *vmstate_dump_file
= NULL
;
2998 Error
*main_loop_err
= NULL
;
3000 bool list_data_dirs
= false;
3002 module_call_init(MODULE_INIT_TRACE
);
3004 qemu_init_cpu_list();
3005 qemu_init_cpu_loop();
3006 qemu_mutex_lock_iothread();
3008 atexit(qemu_run_exit_notifiers
);
3009 error_set_progname(argv
[0]);
3010 qemu_init_exec_dir(argv
[0]);
3012 module_call_init(MODULE_INIT_QOM
);
3013 module_call_init(MODULE_INIT_QAPI
);
3015 qemu_add_opts(&qemu_drive_opts
);
3016 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3017 qemu_add_drive_opts(&qemu_common_drive_opts
);
3018 qemu_add_drive_opts(&qemu_drive_opts
);
3019 qemu_add_drive_opts(&bdrv_runtime_opts
);
3020 qemu_add_opts(&qemu_chardev_opts
);
3021 qemu_add_opts(&qemu_device_opts
);
3022 qemu_add_opts(&qemu_netdev_opts
);
3023 qemu_add_opts(&qemu_net_opts
);
3024 qemu_add_opts(&qemu_rtc_opts
);
3025 qemu_add_opts(&qemu_global_opts
);
3026 qemu_add_opts(&qemu_mon_opts
);
3027 qemu_add_opts(&qemu_trace_opts
);
3028 qemu_add_opts(&qemu_option_rom_opts
);
3029 qemu_add_opts(&qemu_machine_opts
);
3030 qemu_add_opts(&qemu_mem_opts
);
3031 qemu_add_opts(&qemu_smp_opts
);
3032 qemu_add_opts(&qemu_boot_opts
);
3033 qemu_add_opts(&qemu_sandbox_opts
);
3034 qemu_add_opts(&qemu_add_fd_opts
);
3035 qemu_add_opts(&qemu_object_opts
);
3036 qemu_add_opts(&qemu_tpmdev_opts
);
3037 qemu_add_opts(&qemu_realtime_opts
);
3038 qemu_add_opts(&qemu_msg_opts
);
3039 qemu_add_opts(&qemu_name_opts
);
3040 qemu_add_opts(&qemu_numa_opts
);
3041 qemu_add_opts(&qemu_icount_opts
);
3042 qemu_add_opts(&qemu_semihosting_config_opts
);
3043 qemu_add_opts(&qemu_fw_cfg_opts
);
3044 #ifdef CONFIG_LIBISCSI
3045 qemu_add_opts(&qemu_iscsi_opts
);
3047 module_call_init(MODULE_INIT_OPTS
);
3051 if (qcrypto_init(&err
) < 0) {
3052 error_reportf_err(err
, "cannot initialize crypto: ");
3055 rtc_clock
= QEMU_CLOCK_HOST
;
3057 QLIST_INIT (&vm_change_state_head
);
3058 os_setup_early_signal_handling();
3062 cyls
= heads
= secs
= 0;
3063 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3067 bdrv_init_with_whitelist();
3071 /* first pass of option parsing */
3073 while (optind
< argc
) {
3074 if (argv
[optind
][0] != '-') {
3078 const QEMUOption
*popt
;
3080 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3081 switch (popt
->index
) {
3082 case QEMU_OPTION_nodefconfig
:
3085 case QEMU_OPTION_nouserconfig
:
3092 if (defconfig
&& userconfig
) {
3093 if (qemu_read_default_config_file() < 0) {
3098 /* second pass of option parsing */
3103 if (argv
[optind
][0] != '-') {
3104 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3106 const QEMUOption
*popt
;
3108 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3109 if (!(popt
->arch_mask
& arch_type
)) {
3110 error_report("Option not supported for this target");
3113 switch(popt
->index
) {
3114 case QEMU_OPTION_no_kvm_irqchip
: {
3115 olist
= qemu_find_opts("machine");
3116 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3119 case QEMU_OPTION_cpu
:
3120 /* hw initialization will check this */
3123 case QEMU_OPTION_hda
:
3127 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3129 snprintf(buf
, sizeof(buf
),
3130 "%s,cyls=%d,heads=%d,secs=%d%s",
3131 HD_OPTS
, cyls
, heads
, secs
,
3132 translation
== BIOS_ATA_TRANSLATION_LBA
?
3134 translation
== BIOS_ATA_TRANSLATION_NONE
?
3135 ",trans=none" : "");
3136 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3139 case QEMU_OPTION_hdb
:
3140 case QEMU_OPTION_hdc
:
3141 case QEMU_OPTION_hdd
:
3142 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3145 case QEMU_OPTION_drive
:
3146 if (drive_def(optarg
) == NULL
) {
3150 case QEMU_OPTION_set
:
3151 if (qemu_set_option(optarg
) != 0)
3154 case QEMU_OPTION_global
:
3155 if (qemu_global_option(optarg
) != 0)
3158 case QEMU_OPTION_mtdblock
:
3159 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3161 case QEMU_OPTION_sd
:
3162 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3164 case QEMU_OPTION_pflash
:
3165 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3167 case QEMU_OPTION_snapshot
:
3170 case QEMU_OPTION_hdachs
:
3174 cyls
= strtol(p
, (char **)&p
, 0);
3175 if (cyls
< 1 || cyls
> 16383)
3180 heads
= strtol(p
, (char **)&p
, 0);
3181 if (heads
< 1 || heads
> 16)
3186 secs
= strtol(p
, (char **)&p
, 0);
3187 if (secs
< 1 || secs
> 63)
3191 if (!strcmp(p
, "large")) {
3192 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3193 } else if (!strcmp(p
, "rechs")) {
3194 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3195 } else if (!strcmp(p
, "none")) {
3196 translation
= BIOS_ATA_TRANSLATION_NONE
;
3197 } else if (!strcmp(p
, "lba")) {
3198 translation
= BIOS_ATA_TRANSLATION_LBA
;
3199 } else if (!strcmp(p
, "auto")) {
3200 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3204 } else if (*p
!= '\0') {
3206 error_report("invalid physical CHS format");
3209 if (hda_opts
!= NULL
) {
3210 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3212 qemu_opt_set_number(hda_opts
, "heads", heads
,
3214 qemu_opt_set_number(hda_opts
, "secs", secs
,
3216 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3217 qemu_opt_set(hda_opts
, "trans", "large",
3219 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3220 qemu_opt_set(hda_opts
, "trans", "rechs",
3222 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3223 qemu_opt_set(hda_opts
, "trans", "lba",
3225 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3226 qemu_opt_set(hda_opts
, "trans", "none",
3232 case QEMU_OPTION_numa
:
3233 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3239 case QEMU_OPTION_display
:
3240 display_type
= select_display(optarg
);
3242 case QEMU_OPTION_nographic
:
3243 olist
= qemu_find_opts("machine");
3244 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3246 display_type
= DT_NONE
;
3248 case QEMU_OPTION_curses
:
3249 #ifdef CONFIG_CURSES
3250 display_type
= DT_CURSES
;
3252 error_report("curses support is disabled");
3256 case QEMU_OPTION_portrait
:
3257 graphic_rotate
= 90;
3259 case QEMU_OPTION_rotate
:
3260 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3261 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3262 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3263 error_report("only 90, 180, 270 deg rotation is available");
3267 case QEMU_OPTION_kernel
:
3268 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3271 case QEMU_OPTION_initrd
:
3272 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3275 case QEMU_OPTION_append
:
3276 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3279 case QEMU_OPTION_dtb
:
3280 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3283 case QEMU_OPTION_cdrom
:
3284 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3286 case QEMU_OPTION_boot
:
3287 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3293 case QEMU_OPTION_fda
:
3294 case QEMU_OPTION_fdb
:
3295 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3298 case QEMU_OPTION_no_fd_bootchk
:
3301 case QEMU_OPTION_netdev
:
3303 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3307 case QEMU_OPTION_net
:
3309 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3313 #ifdef CONFIG_LIBISCSI
3314 case QEMU_OPTION_iscsi
:
3315 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3323 case QEMU_OPTION_tftp
:
3324 error_report("The -tftp option is deprecated. "
3325 "Please use '-netdev user,tftp=...' instead.");
3326 legacy_tftp_prefix
= optarg
;
3328 case QEMU_OPTION_bootp
:
3329 error_report("The -bootp option is deprecated. "
3330 "Please use '-netdev user,bootfile=...' instead.");
3331 legacy_bootp_filename
= optarg
;
3333 case QEMU_OPTION_redir
:
3334 error_report("The -redir option is deprecated. "
3335 "Please use '-netdev user,hostfwd=...' instead.");
3336 if (net_slirp_redir(optarg
) < 0)
3340 case QEMU_OPTION_bt
:
3341 add_device_config(DEV_BT
, optarg
);
3343 case QEMU_OPTION_audio_help
:
3347 case QEMU_OPTION_soundhw
:
3348 select_soundhw (optarg
);
3353 case QEMU_OPTION_version
:
3358 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3365 case QEMU_OPTION_tpmdev
:
3366 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3371 case QEMU_OPTION_mempath
:
3374 case QEMU_OPTION_mem_prealloc
:
3383 case QEMU_OPTION_DFILTER
:
3384 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3387 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3389 case QEMU_OPTION_gdb
:
3390 add_device_config(DEV_GDB
, optarg
);
3393 if (is_help_option(optarg
)) {
3394 list_data_dirs
= true;
3395 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3396 data_dir
[data_dir_idx
++] = optarg
;
3399 case QEMU_OPTION_bios
:
3400 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3403 case QEMU_OPTION_singlestep
:
3410 keyboard_layout
= optarg
;
3412 case QEMU_OPTION_localtime
:
3415 case QEMU_OPTION_vga
:
3424 w
= strtol(p
, (char **)&p
, 10);
3427 error_report("invalid resolution or depth");
3433 h
= strtol(p
, (char **)&p
, 10);
3438 depth
= strtol(p
, (char **)&p
, 10);
3439 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3440 depth
!= 24 && depth
!= 32)
3442 } else if (*p
== '\0') {
3443 depth
= graphic_depth
;
3450 graphic_depth
= depth
;
3453 case QEMU_OPTION_echr
:
3456 term_escape_char
= strtol(optarg
, &r
, 0);
3458 printf("Bad argument to echr\n");
3461 case QEMU_OPTION_monitor
:
3462 default_monitor
= 0;
3463 if (strncmp(optarg
, "none", 4)) {
3464 monitor_parse(optarg
, "readline", false);
3467 case QEMU_OPTION_qmp
:
3468 monitor_parse(optarg
, "control", false);
3469 default_monitor
= 0;
3471 case QEMU_OPTION_qmp_pretty
:
3472 monitor_parse(optarg
, "control", true);
3473 default_monitor
= 0;
3475 case QEMU_OPTION_mon
:
3476 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3481 default_monitor
= 0;
3483 case QEMU_OPTION_chardev
:
3484 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3490 case QEMU_OPTION_fsdev
:
3491 olist
= qemu_find_opts("fsdev");
3493 error_report("fsdev support is disabled");
3496 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3501 case QEMU_OPTION_virtfs
: {
3504 const char *writeout
, *sock_fd
, *socket
;
3506 olist
= qemu_find_opts("virtfs");
3508 error_report("virtfs support is disabled");
3511 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3516 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3517 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3518 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3521 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3522 qemu_opt_get(opts
, "mount_tag"),
3525 error_report("duplicate fsdev id: %s",
3526 qemu_opt_get(opts
, "mount_tag"));
3530 writeout
= qemu_opt_get(opts
, "writeout");
3532 #ifdef CONFIG_SYNC_FILE_RANGE
3533 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3535 error_report("writeout=immediate not supported "
3536 "on this platform");
3540 qemu_opt_set(fsdev
, "fsdriver",
3541 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3542 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3544 qemu_opt_set(fsdev
, "security_model",
3545 qemu_opt_get(opts
, "security_model"),
3547 socket
= qemu_opt_get(opts
, "socket");
3549 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3551 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3553 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3556 qemu_opt_set_bool(fsdev
, "readonly",
3557 qemu_opt_get_bool(opts
, "readonly", 0),
3559 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3561 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3562 qemu_opt_set(device
, "fsdev",
3563 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3564 qemu_opt_set(device
, "mount_tag",
3565 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3568 case QEMU_OPTION_virtfs_synth
: {
3572 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3575 error_report("duplicate option: %s", "virtfs_synth");
3578 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3580 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3582 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3583 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3584 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3587 case QEMU_OPTION_serial
:
3588 add_device_config(DEV_SERIAL
, optarg
);
3590 if (strncmp(optarg
, "mon:", 4) == 0) {
3591 default_monitor
= 0;
3594 case QEMU_OPTION_watchdog
:
3596 error_report("only one watchdog option may be given");
3601 case QEMU_OPTION_watchdog_action
:
3602 if (select_watchdog_action(optarg
) == -1) {
3603 error_report("unknown -watchdog-action parameter");
3607 case QEMU_OPTION_virtiocon
:
3608 add_device_config(DEV_VIRTCON
, optarg
);
3609 default_virtcon
= 0;
3610 if (strncmp(optarg
, "mon:", 4) == 0) {
3611 default_monitor
= 0;
3614 case QEMU_OPTION_parallel
:
3615 add_device_config(DEV_PARALLEL
, optarg
);
3616 default_parallel
= 0;
3617 if (strncmp(optarg
, "mon:", 4) == 0) {
3618 default_monitor
= 0;
3621 case QEMU_OPTION_debugcon
:
3622 add_device_config(DEV_DEBUGCON
, optarg
);
3624 case QEMU_OPTION_loadvm
:
3627 case QEMU_OPTION_full_screen
:
3630 case QEMU_OPTION_no_frame
:
3633 case QEMU_OPTION_alt_grab
:
3636 case QEMU_OPTION_ctrl_grab
:
3639 case QEMU_OPTION_no_quit
:
3642 case QEMU_OPTION_sdl
:
3644 display_type
= DT_SDL
;
3647 error_report("SDL support is disabled");
3650 case QEMU_OPTION_pidfile
:
3653 case QEMU_OPTION_win2k_hack
:
3654 win2k_install_hack
= 1;
3656 case QEMU_OPTION_rtc_td_hack
: {
3657 static GlobalProperty slew_lost_ticks
= {
3658 .driver
= "mc146818rtc",
3659 .property
= "lost_tick_policy",
3663 qdev_prop_register_global(&slew_lost_ticks
);
3666 case QEMU_OPTION_acpitable
:
3667 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3672 acpi_table_add(opts
, &error_fatal
);
3674 case QEMU_OPTION_smbios
:
3675 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3680 smbios_entry_add(opts
, &error_fatal
);
3682 case QEMU_OPTION_fwcfg
:
3683 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3689 case QEMU_OPTION_enable_kvm
:
3690 olist
= qemu_find_opts("machine");
3691 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3693 case QEMU_OPTION_enable_hax
:
3694 olist
= qemu_find_opts("machine");
3695 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3698 case QEMU_OPTION_machine
:
3699 olist
= qemu_find_opts("machine");
3700 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3705 case QEMU_OPTION_no_kvm
:
3706 olist
= qemu_find_opts("machine");
3707 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3709 case QEMU_OPTION_no_kvm_pit
: {
3710 error_report("warning: ignoring deprecated option");
3713 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3714 static GlobalProperty kvm_pit_lost_tick_policy
= {
3715 .driver
= "kvm-pit",
3716 .property
= "lost_tick_policy",
3720 error_report("warning: deprecated, replaced by "
3721 "-global kvm-pit.lost_tick_policy=discard");
3722 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3725 case QEMU_OPTION_usb
:
3726 olist
= qemu_find_opts("machine");
3727 qemu_opts_parse_noisily(olist
, "usb=on", false);
3729 case QEMU_OPTION_usbdevice
:
3730 olist
= qemu_find_opts("machine");
3731 qemu_opts_parse_noisily(olist
, "usb=on", false);
3732 add_device_config(DEV_USB
, optarg
);
3734 case QEMU_OPTION_device
:
3735 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3740 case QEMU_OPTION_smp
:
3741 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3746 case QEMU_OPTION_vnc
:
3747 vnc_parse(optarg
, &error_fatal
);
3749 case QEMU_OPTION_no_acpi
:
3752 case QEMU_OPTION_no_hpet
:
3755 case QEMU_OPTION_balloon
:
3756 if (balloon_parse(optarg
) < 0) {
3757 error_report("unknown -balloon argument %s", optarg
);
3761 case QEMU_OPTION_no_reboot
:
3764 case QEMU_OPTION_no_shutdown
:
3767 case QEMU_OPTION_show_cursor
:
3770 case QEMU_OPTION_uuid
:
3771 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3772 error_report("failed to parse UUID string: wrong format");
3775 qemu_uuid_set
= true;
3777 case QEMU_OPTION_option_rom
:
3778 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3779 error_report("too many option ROMs");
3782 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3787 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3788 option_rom
[nb_option_roms
].bootindex
=
3789 qemu_opt_get_number(opts
, "bootindex", -1);
3790 if (!option_rom
[nb_option_roms
].name
) {
3791 error_report("Option ROM file is not specified");
3796 case QEMU_OPTION_semihosting
:
3797 semihosting
.enabled
= true;
3798 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3800 case QEMU_OPTION_semihosting_config
:
3801 semihosting
.enabled
= true;
3802 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3805 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3807 const char *target
= qemu_opt_get(opts
, "target");
3808 if (target
!= NULL
) {
3809 if (strcmp("native", target
) == 0) {
3810 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3811 } else if (strcmp("gdb", target
) == 0) {
3812 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3813 } else if (strcmp("auto", target
) == 0) {
3814 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3816 error_report("unsupported semihosting-config %s",
3821 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3823 /* Set semihosting argument count and vector */
3824 qemu_opt_foreach(opts
, add_semihosting_arg
,
3825 &semihosting
, NULL
);
3827 error_report("unsupported semihosting-config %s", optarg
);
3831 case QEMU_OPTION_tdf
:
3832 error_report("warning: ignoring deprecated option");
3834 case QEMU_OPTION_name
:
3835 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3841 case QEMU_OPTION_prom_env
:
3842 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3843 error_report("too many prom variables");
3846 prom_envs
[nb_prom_envs
] = optarg
;
3849 case QEMU_OPTION_old_param
:
3852 case QEMU_OPTION_clock
:
3853 /* Clock options no longer exist. Keep this option for
3854 * backward compatibility.
3857 case QEMU_OPTION_startdate
:
3858 configure_rtc_date_offset(optarg
, 1);
3860 case QEMU_OPTION_rtc
:
3861 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3866 configure_rtc(opts
);
3868 case QEMU_OPTION_tb_size
:
3869 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3870 if (tcg_tb_size
< 0) {
3874 case QEMU_OPTION_icount
:
3875 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3881 case QEMU_OPTION_incoming
:
3883 runstate_set(RUN_STATE_INMIGRATE
);
3887 case QEMU_OPTION_nodefaults
:
3890 case QEMU_OPTION_xen_domid
:
3891 if (!(xen_available())) {
3892 error_report("Option not supported for this target");
3895 xen_domid
= atoi(optarg
);
3897 case QEMU_OPTION_xen_create
:
3898 if (!(xen_available())) {
3899 error_report("Option not supported for this target");
3902 xen_mode
= XEN_CREATE
;
3904 case QEMU_OPTION_xen_attach
:
3905 if (!(xen_available())) {
3906 error_report("Option not supported for this target");
3909 xen_mode
= XEN_ATTACH
;
3911 case QEMU_OPTION_trace
:
3913 trace_file
= trace_opt_parse(optarg
);
3915 case QEMU_OPTION_readconfig
:
3917 int ret
= qemu_read_config_file(optarg
);
3919 error_report("read config %s: %s", optarg
,
3925 case QEMU_OPTION_spice
:
3926 olist
= qemu_find_opts("spice");
3928 error_report("spice support is disabled");
3931 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3937 case QEMU_OPTION_writeconfig
:
3940 if (strcmp(optarg
, "-") == 0) {
3943 fp
= fopen(optarg
, "w");
3945 error_report("open %s: %s", optarg
,
3950 qemu_config_write(fp
);
3956 case QEMU_OPTION_qtest
:
3957 qtest_chrdev
= optarg
;
3959 case QEMU_OPTION_qtest_log
:
3962 case QEMU_OPTION_sandbox
:
3963 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
3969 case QEMU_OPTION_add_fd
:
3971 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3977 error_report("File descriptor passing is disabled on this "
3982 case QEMU_OPTION_object
:
3983 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
3989 case QEMU_OPTION_realtime
:
3990 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
3995 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
3997 case QEMU_OPTION_msg
:
3998 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4003 configure_msg(opts
);
4005 case QEMU_OPTION_dump_vmstate
:
4006 if (vmstate_dump_file
) {
4007 error_report("only one '-dump-vmstate' "
4008 "option may be given");
4011 vmstate_dump_file
= fopen(optarg
, "w");
4012 if (vmstate_dump_file
== NULL
) {
4013 error_report("open %s: %s", optarg
, strerror(errno
));
4018 os_parse_cmd_args(popt
->index
, optarg
);
4023 * Clear error location left behind by the loop.
4024 * Best done right after the loop. Do not insert code here!
4028 replay_configure(icount_opts
);
4030 machine_class
= select_machine();
4032 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4036 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4037 error_report("could not acquire pid file: %s", strerror(errno
));
4041 if (qemu_init_main_loop(&main_loop_err
)) {
4042 error_report_err(main_loop_err
);
4046 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4047 parse_sandbox
, NULL
, NULL
)) {
4051 if (qemu_opts_foreach(qemu_find_opts("name"),
4052 parse_name
, NULL
, NULL
)) {
4057 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4058 parse_add_fd
, NULL
, NULL
)) {
4062 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4063 cleanup_add_fd
, NULL
, NULL
)) {
4068 current_machine
= MACHINE(object_new(object_class_get_name(
4069 OBJECT_CLASS(machine_class
))));
4070 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4073 object_property_add_child(object_get_root(), "machine",
4074 OBJECT(current_machine
), &error_abort
);
4076 if (machine_class
->minimum_page_bits
) {
4077 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4078 /* This would be a board error: specifying a minimum smaller than
4079 * a target's compile-time fixed setting.
4081 g_assert_not_reached();
4085 cpu_exec_init_all();
4087 if (machine_class
->hw_version
) {
4088 qemu_set_hw_version(machine_class
->hw_version
);
4091 if (cpu_model
&& is_help_option(cpu_model
)) {
4092 list_cpus(stdout
, &fprintf
, cpu_model
);
4096 if (!trace_init_backends()) {
4099 trace_init_file(trace_file
);
4101 /* Open the logfile at this point and set the log mask if necessary.
4104 qemu_set_log_filename(log_file
, &error_fatal
);
4109 mask
= qemu_str_to_log_mask(log_mask
);
4111 qemu_print_log_usage(stdout
);
4119 /* If no data_dir is specified then try to find it relative to the
4121 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4122 data_dir
[data_dir_idx
] = os_find_datadir();
4123 if (data_dir
[data_dir_idx
] != NULL
) {
4127 /* If all else fails use the install path specified when building. */
4128 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4129 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4132 /* -L help lists the data directories and exits. */
4133 if (list_data_dirs
) {
4134 for (i
= 0; i
< data_dir_idx
; i
++) {
4135 printf("%s\n", data_dir
[i
]);
4140 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4142 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4143 if (max_cpus
> machine_class
->max_cpus
) {
4144 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4145 "supported by machine '%s' (%d)", max_cpus
,
4146 machine_class
->name
, machine_class
->max_cpus
);
4151 * Get the default machine options from the machine if it is not already
4152 * specified either by the configuration file or by the command line.
4154 if (machine_class
->default_machine_opts
) {
4155 qemu_opts_set_defaults(qemu_find_opts("machine"),
4156 machine_class
->default_machine_opts
, 0);
4159 qemu_opts_foreach(qemu_find_opts("device"),
4160 default_driver_check
, NULL
, NULL
);
4161 qemu_opts_foreach(qemu_find_opts("global"),
4162 default_driver_check
, NULL
, NULL
);
4164 if (!vga_model
&& !default_vga
) {
4165 vga_interface_type
= VGA_DEVICE
;
4167 if (!has_defaults
|| machine_class
->no_serial
) {
4170 if (!has_defaults
|| machine_class
->no_parallel
) {
4171 default_parallel
= 0;
4173 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4174 default_virtcon
= 0;
4176 if (!has_defaults
|| !machine_class
->use_sclp
) {
4179 if (!has_defaults
|| machine_class
->no_floppy
) {
4182 if (!has_defaults
|| machine_class
->no_cdrom
) {
4185 if (!has_defaults
|| machine_class
->no_sdcard
) {
4188 if (!has_defaults
) {
4189 default_monitor
= 0;
4194 if (is_daemonized()) {
4195 /* According to documentation and historically, -nographic redirects
4196 * serial port, parallel port and monitor to stdio, which does not work
4197 * with -daemonize. We can redirect these to null instead, but since
4198 * -nographic is legacy, let's just error out.
4199 * We disallow -nographic only if all other ports are not redirected
4200 * explicitly, to not break existing legacy setups which uses
4201 * -nographic _and_ redirects all ports explicitly - this is valid
4202 * usage, -nographic is just a no-op in this case.
4205 && (default_parallel
|| default_serial
4206 || default_monitor
|| default_virtcon
)) {
4207 error_report("-nographic cannot be used with -daemonize");
4210 #ifdef CONFIG_CURSES
4211 if (display_type
== DT_CURSES
) {
4212 error_report("curses display cannot be used with -daemonize");
4219 if (default_parallel
)
4220 add_device_config(DEV_PARALLEL
, "null");
4221 if (default_serial
&& default_monitor
) {
4222 add_device_config(DEV_SERIAL
, "mon:stdio");
4223 } else if (default_virtcon
&& default_monitor
) {
4224 add_device_config(DEV_VIRTCON
, "mon:stdio");
4225 } else if (default_sclp
&& default_monitor
) {
4226 add_device_config(DEV_SCLP
, "mon:stdio");
4229 add_device_config(DEV_SERIAL
, "stdio");
4230 if (default_virtcon
)
4231 add_device_config(DEV_VIRTCON
, "stdio");
4233 add_device_config(DEV_SCLP
, "stdio");
4235 if (default_monitor
)
4236 monitor_parse("stdio", "readline", false);
4240 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4241 if (default_parallel
)
4242 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4243 if (default_monitor
)
4244 monitor_parse("vc:80Cx24C", "readline", false);
4245 if (default_virtcon
)
4246 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4248 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4252 #if defined(CONFIG_VNC)
4253 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4257 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4258 #if defined(CONFIG_GTK)
4259 display_type
= DT_GTK
;
4260 #elif defined(CONFIG_SDL)
4261 display_type
= DT_SDL
;
4262 #elif defined(CONFIG_COCOA)
4263 display_type
= DT_COCOA
;
4264 #elif defined(CONFIG_VNC)
4265 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4267 display_type
= DT_NONE
;
4271 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4272 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4273 "for SDL, ignoring option");
4275 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4276 error_report("-no-quit is only valid for GTK and SDL, "
4280 if (display_type
== DT_GTK
) {
4281 early_gtk_display_init(request_opengl
);
4284 if (display_type
== DT_SDL
) {
4285 sdl_display_early_init(request_opengl
);
4288 if (request_opengl
== 1 && display_opengl
== 0) {
4289 #if defined(CONFIG_OPENGL)
4290 error_report("OpenGL is not supported by the display");
4292 error_report("OpenGL support is disabled");
4300 if (qemu_opts_foreach(qemu_find_opts("object"),
4301 user_creatable_add_opts_foreach
,
4302 object_create_initial
, NULL
)) {
4306 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4307 chardev_init_func
, NULL
, NULL
)) {
4311 #ifdef CONFIG_VIRTFS
4312 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4313 fsdev_init_func
, NULL
, NULL
)) {
4318 if (qemu_opts_foreach(qemu_find_opts("device"),
4319 device_help_func
, NULL
, NULL
)) {
4323 machine_opts
= qemu_get_machine_opts();
4324 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4326 object_unref(OBJECT(current_machine
));
4330 configure_accelerator(current_machine
);
4333 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4336 machine_opts
= qemu_get_machine_opts();
4337 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4338 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4339 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4340 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4342 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4344 boot_order
= qemu_opt_get(opts
, "order");
4346 validate_bootdevices(boot_order
, &error_fatal
);
4349 boot_once
= qemu_opt_get(opts
, "once");
4351 validate_bootdevices(boot_once
, &error_fatal
);
4354 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4355 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4359 boot_order
= machine_class
->default_boot_order
;
4362 if (!kernel_cmdline
) {
4363 kernel_cmdline
= "";
4364 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4367 linux_boot
= (kernel_filename
!= NULL
);
4369 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4370 error_report("-append only allowed with -kernel option");
4374 if (!linux_boot
&& initrd_filename
!= NULL
) {
4375 error_report("-initrd only allowed with -kernel option");
4379 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4380 /* fall back to the -kernel/-append */
4381 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4384 os_set_line_buffering();
4386 /* spice needs the timers to be initialized by this point */
4391 if (!tcg_enabled()) {
4392 error_report("-icount is not allowed with hardware virtualization");
4395 configure_icount(icount_opts
, &error_abort
);
4396 qemu_opts_del(icount_opts
);
4400 QemuOptsList
*net
= qemu_find_opts("net");
4401 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4403 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4409 if (net_init_clients() < 0) {
4413 if (qemu_opts_foreach(qemu_find_opts("object"),
4414 user_creatable_add_opts_foreach
,
4415 object_create_delayed
, NULL
)) {
4420 if (tpm_init() < 0) {
4425 /* init the bluetooth world */
4426 if (foreach_device_config(DEV_BT
, bt_parse
))
4429 if (!xen_enabled()) {
4430 /* On 32-bit hosts, QEMU is limited by virtual address space */
4431 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4432 error_report("at most 2047 MB RAM can be simulated");
4440 /* If the currently selected machine wishes to override the units-per-bus
4441 * property of its default HBA interface type, do so now. */
4442 if (machine_class
->units_per_default_bus
) {
4443 override_max_devs(machine_class
->block_default_type
,
4444 machine_class
->units_per_default_bus
);
4447 /* open the virtual block devices */
4448 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4449 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4452 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4453 &machine_class
->block_default_type
, NULL
)) {
4457 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4459 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4460 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4462 parse_numa_opts(machine_class
);
4464 if (qemu_opts_foreach(qemu_find_opts("mon"),
4465 mon_init_func
, NULL
, NULL
)) {
4469 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4471 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4473 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4475 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4478 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4481 /* If no default VGA is requested, the default is "none". */
4483 if (machine_class
->default_display
) {
4484 vga_model
= machine_class
->default_display
;
4485 } else if (vga_interface_available(VGA_CIRRUS
)) {
4486 vga_model
= "cirrus";
4487 } else if (vga_interface_available(VGA_STD
)) {
4492 select_vgahw(vga_model
);
4496 i
= select_watchdog(watchdog
);
4498 exit (i
== 1 ? 1 : 0);
4501 machine_register_compat_props(current_machine
);
4503 qemu_opts_foreach(qemu_find_opts("global"),
4504 global_init_func
, NULL
, NULL
);
4506 /* This checkpoint is required by replay to separate prior clock
4507 reading from the other reads, because timer polling functions query
4508 clock values from the log. */
4509 replay_checkpoint(CHECKPOINT_INIT
);
4510 qdev_machine_init();
4512 current_machine
->ram_size
= ram_size
;
4513 current_machine
->maxram_size
= maxram_size
;
4514 current_machine
->ram_slots
= ram_slots
;
4515 current_machine
->boot_order
= boot_order
;
4516 current_machine
->cpu_model
= cpu_model
;
4518 machine_class
->init(current_machine
);
4524 cpu_synchronize_all_post_init();
4526 if (hax_enabled()) {
4530 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4531 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4535 /* init USB devices */
4536 if (machine_usb(current_machine
)) {
4537 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4541 /* Check if IGD GFX passthrough. */
4544 /* init generic devices */
4545 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4546 if (qemu_opts_foreach(qemu_find_opts("device"),
4547 device_init_func
, NULL
, NULL
)) {
4551 numa_post_machine_init();
4553 rom_reset_order_override();
4555 /* Did we create any drives that we failed to create a device for? */
4556 drive_check_orphaned();
4558 /* Don't warn about the default network setup that you get if
4559 * no command line -net or -netdev options are specified. There
4560 * are two cases that we would otherwise complain about:
4561 * (1) board doesn't support a NIC but the implicit "-net nic"
4563 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4564 * sets up a nic that isn't connected to anything.
4567 net_check_clients();
4572 qemu_boot_set(boot_once
, &error_fatal
);
4573 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4576 ds
= init_displaystate();
4578 /* init local displays */
4579 switch (display_type
) {
4581 curses_display_init(ds
, full_screen
);
4584 sdl_display_init(ds
, full_screen
, no_frame
);
4587 cocoa_display_init(ds
, full_screen
);
4590 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4596 /* must be after terminal init, SDL library changes signal handlers */
4597 os_setup_signal_handling();
4599 /* init remote displays */
4601 qemu_opts_foreach(qemu_find_opts("vnc"),
4602 vnc_init_func
, NULL
, NULL
);
4606 qemu_spice_display_init();
4609 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4613 qdev_machine_creation_done();
4615 /* TODO: once all bus devices are qdevified, this should be done
4616 * when bus is created by qdev.c */
4617 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4618 qemu_run_machine_init_done_notifiers();
4620 if (rom_check_and_register_reset() != 0) {
4621 error_report("rom check and register reset failed");
4627 /* This checkpoint is required by replay to separate prior clock
4628 reading from the other reads, because timer polling functions query
4629 clock values from the log. */
4630 replay_checkpoint(CHECKPOINT_RESET
);
4631 qemu_system_reset(VMRESET_SILENT
);
4632 register_global_state();
4634 if (load_vmstate(loadvm
) < 0) {
4639 qdev_prop_check_globals();
4640 if (vmstate_dump_file
) {
4642 dump_vmstate_json_to_file(vmstate_dump_file
);
4647 Error
*local_err
= NULL
;
4648 qemu_start_incoming_migration(incoming
, &local_err
);
4650 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4653 } else if (autostart
) {
4660 replay_disable_events();
4661 iothread_stop_all();
4667 /* vhost-user must be cleaned up before chardevs. */