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 int main(int argc
, char **argv
, char **envp
)
2956 int snapshot
, linux_boot
;
2957 const char *initrd_filename
;
2958 const char *kernel_filename
, *kernel_cmdline
;
2959 const char *boot_order
= NULL
;
2960 const char *boot_once
= NULL
;
2962 int cyls
, heads
, secs
, translation
;
2963 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
2964 QemuOptsList
*olist
;
2967 const char *loadvm
= NULL
;
2968 MachineClass
*machine_class
;
2969 const char *cpu_model
;
2970 const char *vga_model
= NULL
;
2971 const char *qtest_chrdev
= NULL
;
2972 const char *qtest_log
= NULL
;
2973 const char *pid_file
= NULL
;
2974 const char *incoming
= NULL
;
2975 bool defconfig
= true;
2976 bool userconfig
= true;
2977 bool nographic
= false;
2978 DisplayType display_type
= DT_DEFAULT
;
2979 int display_remote
= 0;
2980 const char *log_mask
= NULL
;
2981 const char *log_file
= NULL
;
2982 char *trace_file
= NULL
;
2983 ram_addr_t maxram_size
;
2984 uint64_t ram_slots
= 0;
2985 FILE *vmstate_dump_file
= NULL
;
2986 Error
*main_loop_err
= NULL
;
2988 bool list_data_dirs
= false;
2990 module_call_init(MODULE_INIT_TRACE
);
2992 qemu_init_cpu_list();
2993 qemu_init_cpu_loop();
2994 qemu_mutex_lock_iothread();
2996 atexit(qemu_run_exit_notifiers
);
2997 error_set_progname(argv
[0]);
2998 qemu_init_exec_dir(argv
[0]);
3000 module_call_init(MODULE_INIT_QOM
);
3001 module_call_init(MODULE_INIT_QAPI
);
3003 qemu_add_opts(&qemu_drive_opts
);
3004 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3005 qemu_add_drive_opts(&qemu_common_drive_opts
);
3006 qemu_add_drive_opts(&qemu_drive_opts
);
3007 qemu_add_drive_opts(&bdrv_runtime_opts
);
3008 qemu_add_opts(&qemu_chardev_opts
);
3009 qemu_add_opts(&qemu_device_opts
);
3010 qemu_add_opts(&qemu_netdev_opts
);
3011 qemu_add_opts(&qemu_net_opts
);
3012 qemu_add_opts(&qemu_rtc_opts
);
3013 qemu_add_opts(&qemu_global_opts
);
3014 qemu_add_opts(&qemu_mon_opts
);
3015 qemu_add_opts(&qemu_trace_opts
);
3016 qemu_add_opts(&qemu_option_rom_opts
);
3017 qemu_add_opts(&qemu_machine_opts
);
3018 qemu_add_opts(&qemu_mem_opts
);
3019 qemu_add_opts(&qemu_smp_opts
);
3020 qemu_add_opts(&qemu_boot_opts
);
3021 qemu_add_opts(&qemu_sandbox_opts
);
3022 qemu_add_opts(&qemu_add_fd_opts
);
3023 qemu_add_opts(&qemu_object_opts
);
3024 qemu_add_opts(&qemu_tpmdev_opts
);
3025 qemu_add_opts(&qemu_realtime_opts
);
3026 qemu_add_opts(&qemu_msg_opts
);
3027 qemu_add_opts(&qemu_name_opts
);
3028 qemu_add_opts(&qemu_numa_opts
);
3029 qemu_add_opts(&qemu_icount_opts
);
3030 qemu_add_opts(&qemu_semihosting_config_opts
);
3031 qemu_add_opts(&qemu_fw_cfg_opts
);
3032 #ifdef CONFIG_LIBISCSI
3033 qemu_add_opts(&qemu_iscsi_opts
);
3035 module_call_init(MODULE_INIT_OPTS
);
3039 if (qcrypto_init(&err
) < 0) {
3040 error_reportf_err(err
, "cannot initialize crypto: ");
3043 rtc_clock
= QEMU_CLOCK_HOST
;
3045 QLIST_INIT (&vm_change_state_head
);
3046 os_setup_early_signal_handling();
3050 cyls
= heads
= secs
= 0;
3051 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3055 bdrv_init_with_whitelist();
3059 /* first pass of option parsing */
3061 while (optind
< argc
) {
3062 if (argv
[optind
][0] != '-') {
3066 const QEMUOption
*popt
;
3068 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3069 switch (popt
->index
) {
3070 case QEMU_OPTION_nodefconfig
:
3073 case QEMU_OPTION_nouserconfig
:
3082 ret
= qemu_read_default_config_files(userconfig
);
3088 /* second pass of option parsing */
3093 if (argv
[optind
][0] != '-') {
3094 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3096 const QEMUOption
*popt
;
3098 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3099 if (!(popt
->arch_mask
& arch_type
)) {
3100 error_report("Option not supported for this target");
3103 switch(popt
->index
) {
3104 case QEMU_OPTION_no_kvm_irqchip
: {
3105 olist
= qemu_find_opts("machine");
3106 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3109 case QEMU_OPTION_cpu
:
3110 /* hw initialization will check this */
3113 case QEMU_OPTION_hda
:
3117 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3119 snprintf(buf
, sizeof(buf
),
3120 "%s,cyls=%d,heads=%d,secs=%d%s",
3121 HD_OPTS
, cyls
, heads
, secs
,
3122 translation
== BIOS_ATA_TRANSLATION_LBA
?
3124 translation
== BIOS_ATA_TRANSLATION_NONE
?
3125 ",trans=none" : "");
3126 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3129 case QEMU_OPTION_hdb
:
3130 case QEMU_OPTION_hdc
:
3131 case QEMU_OPTION_hdd
:
3132 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3135 case QEMU_OPTION_drive
:
3136 if (drive_def(optarg
) == NULL
) {
3140 case QEMU_OPTION_set
:
3141 if (qemu_set_option(optarg
) != 0)
3144 case QEMU_OPTION_global
:
3145 if (qemu_global_option(optarg
) != 0)
3148 case QEMU_OPTION_mtdblock
:
3149 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3151 case QEMU_OPTION_sd
:
3152 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3154 case QEMU_OPTION_pflash
:
3155 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3157 case QEMU_OPTION_snapshot
:
3160 case QEMU_OPTION_hdachs
:
3164 cyls
= strtol(p
, (char **)&p
, 0);
3165 if (cyls
< 1 || cyls
> 16383)
3170 heads
= strtol(p
, (char **)&p
, 0);
3171 if (heads
< 1 || heads
> 16)
3176 secs
= strtol(p
, (char **)&p
, 0);
3177 if (secs
< 1 || secs
> 63)
3181 if (!strcmp(p
, "large")) {
3182 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3183 } else if (!strcmp(p
, "rechs")) {
3184 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3185 } else if (!strcmp(p
, "none")) {
3186 translation
= BIOS_ATA_TRANSLATION_NONE
;
3187 } else if (!strcmp(p
, "lba")) {
3188 translation
= BIOS_ATA_TRANSLATION_LBA
;
3189 } else if (!strcmp(p
, "auto")) {
3190 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3194 } else if (*p
!= '\0') {
3196 error_report("invalid physical CHS format");
3199 if (hda_opts
!= NULL
) {
3200 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3202 qemu_opt_set_number(hda_opts
, "heads", heads
,
3204 qemu_opt_set_number(hda_opts
, "secs", secs
,
3206 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3207 qemu_opt_set(hda_opts
, "trans", "large",
3209 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3210 qemu_opt_set(hda_opts
, "trans", "rechs",
3212 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3213 qemu_opt_set(hda_opts
, "trans", "lba",
3215 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3216 qemu_opt_set(hda_opts
, "trans", "none",
3222 case QEMU_OPTION_numa
:
3223 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3229 case QEMU_OPTION_display
:
3230 display_type
= select_display(optarg
);
3232 case QEMU_OPTION_nographic
:
3233 olist
= qemu_find_opts("machine");
3234 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3236 display_type
= DT_NONE
;
3238 case QEMU_OPTION_curses
:
3239 #ifdef CONFIG_CURSES
3240 display_type
= DT_CURSES
;
3242 error_report("curses support is disabled");
3246 case QEMU_OPTION_portrait
:
3247 graphic_rotate
= 90;
3249 case QEMU_OPTION_rotate
:
3250 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3251 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3252 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3253 error_report("only 90, 180, 270 deg rotation is available");
3257 case QEMU_OPTION_kernel
:
3258 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3261 case QEMU_OPTION_initrd
:
3262 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3265 case QEMU_OPTION_append
:
3266 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3269 case QEMU_OPTION_dtb
:
3270 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3273 case QEMU_OPTION_cdrom
:
3274 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3276 case QEMU_OPTION_boot
:
3277 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3283 case QEMU_OPTION_fda
:
3284 case QEMU_OPTION_fdb
:
3285 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3288 case QEMU_OPTION_no_fd_bootchk
:
3291 case QEMU_OPTION_netdev
:
3293 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3297 case QEMU_OPTION_net
:
3299 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3303 #ifdef CONFIG_LIBISCSI
3304 case QEMU_OPTION_iscsi
:
3305 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3313 case QEMU_OPTION_tftp
:
3314 error_report("The -tftp option is deprecated. "
3315 "Please use '-netdev user,tftp=...' instead.");
3316 legacy_tftp_prefix
= optarg
;
3318 case QEMU_OPTION_bootp
:
3319 error_report("The -bootp option is deprecated. "
3320 "Please use '-netdev user,bootfile=...' instead.");
3321 legacy_bootp_filename
= optarg
;
3323 case QEMU_OPTION_redir
:
3324 error_report("The -redir option is deprecated. "
3325 "Please use '-netdev user,hostfwd=...' instead.");
3326 if (net_slirp_redir(optarg
) < 0)
3330 case QEMU_OPTION_bt
:
3331 add_device_config(DEV_BT
, optarg
);
3333 case QEMU_OPTION_audio_help
:
3337 case QEMU_OPTION_soundhw
:
3338 select_soundhw (optarg
);
3343 case QEMU_OPTION_version
:
3348 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3355 case QEMU_OPTION_tpmdev
:
3356 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3361 case QEMU_OPTION_mempath
:
3364 case QEMU_OPTION_mem_prealloc
:
3373 case QEMU_OPTION_DFILTER
:
3374 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3377 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3379 case QEMU_OPTION_gdb
:
3380 add_device_config(DEV_GDB
, optarg
);
3383 if (is_help_option(optarg
)) {
3384 list_data_dirs
= true;
3385 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3386 data_dir
[data_dir_idx
++] = optarg
;
3389 case QEMU_OPTION_bios
:
3390 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3393 case QEMU_OPTION_singlestep
:
3400 keyboard_layout
= optarg
;
3402 case QEMU_OPTION_localtime
:
3405 case QEMU_OPTION_vga
:
3414 w
= strtol(p
, (char **)&p
, 10);
3417 error_report("invalid resolution or depth");
3423 h
= strtol(p
, (char **)&p
, 10);
3428 depth
= strtol(p
, (char **)&p
, 10);
3429 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3430 depth
!= 24 && depth
!= 32)
3432 } else if (*p
== '\0') {
3433 depth
= graphic_depth
;
3440 graphic_depth
= depth
;
3443 case QEMU_OPTION_echr
:
3446 term_escape_char
= strtol(optarg
, &r
, 0);
3448 printf("Bad argument to echr\n");
3451 case QEMU_OPTION_monitor
:
3452 default_monitor
= 0;
3453 if (strncmp(optarg
, "none", 4)) {
3454 monitor_parse(optarg
, "readline", false);
3457 case QEMU_OPTION_qmp
:
3458 monitor_parse(optarg
, "control", false);
3459 default_monitor
= 0;
3461 case QEMU_OPTION_qmp_pretty
:
3462 monitor_parse(optarg
, "control", true);
3463 default_monitor
= 0;
3465 case QEMU_OPTION_mon
:
3466 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3471 default_monitor
= 0;
3473 case QEMU_OPTION_chardev
:
3474 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3480 case QEMU_OPTION_fsdev
:
3481 olist
= qemu_find_opts("fsdev");
3483 error_report("fsdev support is disabled");
3486 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3491 case QEMU_OPTION_virtfs
: {
3494 const char *writeout
, *sock_fd
, *socket
;
3496 olist
= qemu_find_opts("virtfs");
3498 error_report("virtfs support is disabled");
3501 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3506 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3507 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3508 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3511 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3512 qemu_opt_get(opts
, "mount_tag"),
3515 error_report("duplicate fsdev id: %s",
3516 qemu_opt_get(opts
, "mount_tag"));
3520 writeout
= qemu_opt_get(opts
, "writeout");
3522 #ifdef CONFIG_SYNC_FILE_RANGE
3523 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3525 error_report("writeout=immediate not supported "
3526 "on this platform");
3530 qemu_opt_set(fsdev
, "fsdriver",
3531 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3532 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3534 qemu_opt_set(fsdev
, "security_model",
3535 qemu_opt_get(opts
, "security_model"),
3537 socket
= qemu_opt_get(opts
, "socket");
3539 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3541 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3543 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3546 qemu_opt_set_bool(fsdev
, "readonly",
3547 qemu_opt_get_bool(opts
, "readonly", 0),
3549 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3551 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3552 qemu_opt_set(device
, "fsdev",
3553 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3554 qemu_opt_set(device
, "mount_tag",
3555 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3558 case QEMU_OPTION_virtfs_synth
: {
3562 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3565 error_report("duplicate option: %s", "virtfs_synth");
3568 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3570 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3572 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3573 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3574 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3577 case QEMU_OPTION_serial
:
3578 add_device_config(DEV_SERIAL
, optarg
);
3580 if (strncmp(optarg
, "mon:", 4) == 0) {
3581 default_monitor
= 0;
3584 case QEMU_OPTION_watchdog
:
3586 error_report("only one watchdog option may be given");
3591 case QEMU_OPTION_watchdog_action
:
3592 if (select_watchdog_action(optarg
) == -1) {
3593 error_report("unknown -watchdog-action parameter");
3597 case QEMU_OPTION_virtiocon
:
3598 add_device_config(DEV_VIRTCON
, optarg
);
3599 default_virtcon
= 0;
3600 if (strncmp(optarg
, "mon:", 4) == 0) {
3601 default_monitor
= 0;
3604 case QEMU_OPTION_parallel
:
3605 add_device_config(DEV_PARALLEL
, optarg
);
3606 default_parallel
= 0;
3607 if (strncmp(optarg
, "mon:", 4) == 0) {
3608 default_monitor
= 0;
3611 case QEMU_OPTION_debugcon
:
3612 add_device_config(DEV_DEBUGCON
, optarg
);
3614 case QEMU_OPTION_loadvm
:
3617 case QEMU_OPTION_full_screen
:
3620 case QEMU_OPTION_no_frame
:
3623 case QEMU_OPTION_alt_grab
:
3626 case QEMU_OPTION_ctrl_grab
:
3629 case QEMU_OPTION_no_quit
:
3632 case QEMU_OPTION_sdl
:
3634 display_type
= DT_SDL
;
3637 error_report("SDL support is disabled");
3640 case QEMU_OPTION_pidfile
:
3643 case QEMU_OPTION_win2k_hack
:
3644 win2k_install_hack
= 1;
3646 case QEMU_OPTION_rtc_td_hack
: {
3647 static GlobalProperty slew_lost_ticks
= {
3648 .driver
= "mc146818rtc",
3649 .property
= "lost_tick_policy",
3653 qdev_prop_register_global(&slew_lost_ticks
);
3656 case QEMU_OPTION_acpitable
:
3657 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3662 acpi_table_add(opts
, &error_fatal
);
3664 case QEMU_OPTION_smbios
:
3665 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3670 smbios_entry_add(opts
, &error_fatal
);
3672 case QEMU_OPTION_fwcfg
:
3673 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3679 case QEMU_OPTION_enable_kvm
:
3680 olist
= qemu_find_opts("machine");
3681 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3683 case QEMU_OPTION_enable_hax
:
3684 olist
= qemu_find_opts("machine");
3685 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3688 case QEMU_OPTION_machine
:
3689 olist
= qemu_find_opts("machine");
3690 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3695 case QEMU_OPTION_no_kvm
:
3696 olist
= qemu_find_opts("machine");
3697 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3699 case QEMU_OPTION_no_kvm_pit
: {
3700 error_report("warning: ignoring deprecated option");
3703 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3704 static GlobalProperty kvm_pit_lost_tick_policy
= {
3705 .driver
= "kvm-pit",
3706 .property
= "lost_tick_policy",
3710 error_report("warning: deprecated, replaced by "
3711 "-global kvm-pit.lost_tick_policy=discard");
3712 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3715 case QEMU_OPTION_usb
:
3716 olist
= qemu_find_opts("machine");
3717 qemu_opts_parse_noisily(olist
, "usb=on", false);
3719 case QEMU_OPTION_usbdevice
:
3720 olist
= qemu_find_opts("machine");
3721 qemu_opts_parse_noisily(olist
, "usb=on", false);
3722 add_device_config(DEV_USB
, optarg
);
3724 case QEMU_OPTION_device
:
3725 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3730 case QEMU_OPTION_smp
:
3731 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3736 case QEMU_OPTION_vnc
:
3737 vnc_parse(optarg
, &error_fatal
);
3739 case QEMU_OPTION_no_acpi
:
3742 case QEMU_OPTION_no_hpet
:
3745 case QEMU_OPTION_balloon
:
3746 if (balloon_parse(optarg
) < 0) {
3747 error_report("unknown -balloon argument %s", optarg
);
3751 case QEMU_OPTION_no_reboot
:
3754 case QEMU_OPTION_no_shutdown
:
3757 case QEMU_OPTION_show_cursor
:
3760 case QEMU_OPTION_uuid
:
3761 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3762 error_report("failed to parse UUID string: wrong format");
3765 qemu_uuid_set
= true;
3767 case QEMU_OPTION_option_rom
:
3768 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3769 error_report("too many option ROMs");
3772 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3777 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3778 option_rom
[nb_option_roms
].bootindex
=
3779 qemu_opt_get_number(opts
, "bootindex", -1);
3780 if (!option_rom
[nb_option_roms
].name
) {
3781 error_report("Option ROM file is not specified");
3786 case QEMU_OPTION_semihosting
:
3787 semihosting
.enabled
= true;
3788 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3790 case QEMU_OPTION_semihosting_config
:
3791 semihosting
.enabled
= true;
3792 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3795 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3797 const char *target
= qemu_opt_get(opts
, "target");
3798 if (target
!= NULL
) {
3799 if (strcmp("native", target
) == 0) {
3800 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3801 } else if (strcmp("gdb", target
) == 0) {
3802 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3803 } else if (strcmp("auto", target
) == 0) {
3804 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3806 error_report("unsupported semihosting-config %s",
3811 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3813 /* Set semihosting argument count and vector */
3814 qemu_opt_foreach(opts
, add_semihosting_arg
,
3815 &semihosting
, NULL
);
3817 error_report("unsupported semihosting-config %s", optarg
);
3821 case QEMU_OPTION_tdf
:
3822 error_report("warning: ignoring deprecated option");
3824 case QEMU_OPTION_name
:
3825 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3831 case QEMU_OPTION_prom_env
:
3832 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3833 error_report("too many prom variables");
3836 prom_envs
[nb_prom_envs
] = optarg
;
3839 case QEMU_OPTION_old_param
:
3842 case QEMU_OPTION_clock
:
3843 /* Clock options no longer exist. Keep this option for
3844 * backward compatibility.
3847 case QEMU_OPTION_startdate
:
3848 configure_rtc_date_offset(optarg
, 1);
3850 case QEMU_OPTION_rtc
:
3851 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3856 configure_rtc(opts
);
3858 case QEMU_OPTION_tb_size
:
3859 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3860 if (tcg_tb_size
< 0) {
3864 case QEMU_OPTION_icount
:
3865 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3871 case QEMU_OPTION_incoming
:
3873 runstate_set(RUN_STATE_INMIGRATE
);
3877 case QEMU_OPTION_nodefaults
:
3880 case QEMU_OPTION_xen_domid
:
3881 if (!(xen_available())) {
3882 error_report("Option not supported for this target");
3885 xen_domid
= atoi(optarg
);
3887 case QEMU_OPTION_xen_create
:
3888 if (!(xen_available())) {
3889 error_report("Option not supported for this target");
3892 xen_mode
= XEN_CREATE
;
3894 case QEMU_OPTION_xen_attach
:
3895 if (!(xen_available())) {
3896 error_report("Option not supported for this target");
3899 xen_mode
= XEN_ATTACH
;
3901 case QEMU_OPTION_trace
:
3903 trace_file
= trace_opt_parse(optarg
);
3905 case QEMU_OPTION_readconfig
:
3907 int ret
= qemu_read_config_file(optarg
);
3909 error_report("read config %s: %s", optarg
,
3915 case QEMU_OPTION_spice
:
3916 olist
= qemu_find_opts("spice");
3918 error_report("spice support is disabled");
3921 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3927 case QEMU_OPTION_writeconfig
:
3930 if (strcmp(optarg
, "-") == 0) {
3933 fp
= fopen(optarg
, "w");
3935 error_report("open %s: %s", optarg
,
3940 qemu_config_write(fp
);
3946 case QEMU_OPTION_qtest
:
3947 qtest_chrdev
= optarg
;
3949 case QEMU_OPTION_qtest_log
:
3952 case QEMU_OPTION_sandbox
:
3953 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
3959 case QEMU_OPTION_add_fd
:
3961 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3967 error_report("File descriptor passing is disabled on this "
3972 case QEMU_OPTION_object
:
3973 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
3979 case QEMU_OPTION_realtime
:
3980 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
3985 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
3987 case QEMU_OPTION_msg
:
3988 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3993 configure_msg(opts
);
3995 case QEMU_OPTION_dump_vmstate
:
3996 if (vmstate_dump_file
) {
3997 error_report("only one '-dump-vmstate' "
3998 "option may be given");
4001 vmstate_dump_file
= fopen(optarg
, "w");
4002 if (vmstate_dump_file
== NULL
) {
4003 error_report("open %s: %s", optarg
, strerror(errno
));
4008 os_parse_cmd_args(popt
->index
, optarg
);
4013 * Clear error location left behind by the loop.
4014 * Best done right after the loop. Do not insert code here!
4018 replay_configure(icount_opts
);
4020 machine_class
= select_machine();
4022 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4026 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4027 error_report("could not acquire pid file: %s", strerror(errno
));
4031 if (qemu_init_main_loop(&main_loop_err
)) {
4032 error_report_err(main_loop_err
);
4036 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4037 parse_sandbox
, NULL
, NULL
)) {
4041 if (qemu_opts_foreach(qemu_find_opts("name"),
4042 parse_name
, NULL
, NULL
)) {
4047 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4048 parse_add_fd
, NULL
, NULL
)) {
4052 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4053 cleanup_add_fd
, NULL
, NULL
)) {
4058 current_machine
= MACHINE(object_new(object_class_get_name(
4059 OBJECT_CLASS(machine_class
))));
4060 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4063 object_property_add_child(object_get_root(), "machine",
4064 OBJECT(current_machine
), &error_abort
);
4066 if (machine_class
->minimum_page_bits
) {
4067 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4068 /* This would be a board error: specifying a minimum smaller than
4069 * a target's compile-time fixed setting.
4071 g_assert_not_reached();
4075 cpu_exec_init_all();
4077 if (machine_class
->hw_version
) {
4078 qemu_set_hw_version(machine_class
->hw_version
);
4081 if (cpu_model
&& is_help_option(cpu_model
)) {
4082 list_cpus(stdout
, &fprintf
, cpu_model
);
4086 if (!trace_init_backends()) {
4089 trace_init_file(trace_file
);
4091 /* Open the logfile at this point and set the log mask if necessary.
4094 qemu_set_log_filename(log_file
, &error_fatal
);
4099 mask
= qemu_str_to_log_mask(log_mask
);
4101 qemu_print_log_usage(stdout
);
4109 /* If no data_dir is specified then try to find it relative to the
4111 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4112 data_dir
[data_dir_idx
] = os_find_datadir();
4113 if (data_dir
[data_dir_idx
] != NULL
) {
4117 /* If all else fails use the install path specified when building. */
4118 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4119 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4122 /* -L help lists the data directories and exits. */
4123 if (list_data_dirs
) {
4124 for (i
= 0; i
< data_dir_idx
; i
++) {
4125 printf("%s\n", data_dir
[i
]);
4130 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4132 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4133 if (max_cpus
> machine_class
->max_cpus
) {
4134 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4135 "supported by machine '%s' (%d)", max_cpus
,
4136 machine_class
->name
, machine_class
->max_cpus
);
4141 * Get the default machine options from the machine if it is not already
4142 * specified either by the configuration file or by the command line.
4144 if (machine_class
->default_machine_opts
) {
4145 qemu_opts_set_defaults(qemu_find_opts("machine"),
4146 machine_class
->default_machine_opts
, 0);
4149 qemu_opts_foreach(qemu_find_opts("device"),
4150 default_driver_check
, NULL
, NULL
);
4151 qemu_opts_foreach(qemu_find_opts("global"),
4152 default_driver_check
, NULL
, NULL
);
4154 if (!vga_model
&& !default_vga
) {
4155 vga_interface_type
= VGA_DEVICE
;
4157 if (!has_defaults
|| machine_class
->no_serial
) {
4160 if (!has_defaults
|| machine_class
->no_parallel
) {
4161 default_parallel
= 0;
4163 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4164 default_virtcon
= 0;
4166 if (!has_defaults
|| !machine_class
->use_sclp
) {
4169 if (!has_defaults
|| machine_class
->no_floppy
) {
4172 if (!has_defaults
|| machine_class
->no_cdrom
) {
4175 if (!has_defaults
|| machine_class
->no_sdcard
) {
4178 if (!has_defaults
) {
4179 default_monitor
= 0;
4184 if (is_daemonized()) {
4185 /* According to documentation and historically, -nographic redirects
4186 * serial port, parallel port and monitor to stdio, which does not work
4187 * with -daemonize. We can redirect these to null instead, but since
4188 * -nographic is legacy, let's just error out.
4189 * We disallow -nographic only if all other ports are not redirected
4190 * explicitly, to not break existing legacy setups which uses
4191 * -nographic _and_ redirects all ports explicitly - this is valid
4192 * usage, -nographic is just a no-op in this case.
4195 && (default_parallel
|| default_serial
4196 || default_monitor
|| default_virtcon
)) {
4197 error_report("-nographic cannot be used with -daemonize");
4200 #ifdef CONFIG_CURSES
4201 if (display_type
== DT_CURSES
) {
4202 error_report("curses display cannot be used with -daemonize");
4209 if (default_parallel
)
4210 add_device_config(DEV_PARALLEL
, "null");
4211 if (default_serial
&& default_monitor
) {
4212 add_device_config(DEV_SERIAL
, "mon:stdio");
4213 } else if (default_virtcon
&& default_monitor
) {
4214 add_device_config(DEV_VIRTCON
, "mon:stdio");
4215 } else if (default_sclp
&& default_monitor
) {
4216 add_device_config(DEV_SCLP
, "mon:stdio");
4219 add_device_config(DEV_SERIAL
, "stdio");
4220 if (default_virtcon
)
4221 add_device_config(DEV_VIRTCON
, "stdio");
4223 add_device_config(DEV_SCLP
, "stdio");
4225 if (default_monitor
)
4226 monitor_parse("stdio", "readline", false);
4230 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4231 if (default_parallel
)
4232 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4233 if (default_monitor
)
4234 monitor_parse("vc:80Cx24C", "readline", false);
4235 if (default_virtcon
)
4236 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4238 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4242 #if defined(CONFIG_VNC)
4243 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4247 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4248 #if defined(CONFIG_GTK)
4249 display_type
= DT_GTK
;
4250 #elif defined(CONFIG_SDL)
4251 display_type
= DT_SDL
;
4252 #elif defined(CONFIG_COCOA)
4253 display_type
= DT_COCOA
;
4254 #elif defined(CONFIG_VNC)
4255 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4257 display_type
= DT_NONE
;
4261 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4262 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4263 "for SDL, ignoring option");
4265 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4266 error_report("-no-quit is only valid for GTK and SDL, "
4270 if (display_type
== DT_GTK
) {
4271 early_gtk_display_init(request_opengl
);
4274 if (display_type
== DT_SDL
) {
4275 sdl_display_early_init(request_opengl
);
4278 if (request_opengl
== 1 && display_opengl
== 0) {
4279 #if defined(CONFIG_OPENGL)
4280 error_report("OpenGL is not supported by the display");
4282 error_report("OpenGL support is disabled");
4290 if (qemu_opts_foreach(qemu_find_opts("object"),
4291 user_creatable_add_opts_foreach
,
4292 object_create_initial
, NULL
)) {
4296 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4297 chardev_init_func
, NULL
, NULL
)) {
4301 #ifdef CONFIG_VIRTFS
4302 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4303 fsdev_init_func
, NULL
, NULL
)) {
4308 if (qemu_opts_foreach(qemu_find_opts("device"),
4309 device_help_func
, NULL
, NULL
)) {
4313 machine_opts
= qemu_get_machine_opts();
4314 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4316 object_unref(OBJECT(current_machine
));
4320 configure_accelerator(current_machine
);
4323 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4326 machine_opts
= qemu_get_machine_opts();
4327 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4328 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4329 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4330 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4332 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4334 boot_order
= qemu_opt_get(opts
, "order");
4336 validate_bootdevices(boot_order
, &error_fatal
);
4339 boot_once
= qemu_opt_get(opts
, "once");
4341 validate_bootdevices(boot_once
, &error_fatal
);
4344 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4345 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4349 boot_order
= machine_class
->default_boot_order
;
4352 if (!kernel_cmdline
) {
4353 kernel_cmdline
= "";
4354 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4357 linux_boot
= (kernel_filename
!= NULL
);
4359 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4360 error_report("-append only allowed with -kernel option");
4364 if (!linux_boot
&& initrd_filename
!= NULL
) {
4365 error_report("-initrd only allowed with -kernel option");
4369 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4370 /* fall back to the -kernel/-append */
4371 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4374 os_set_line_buffering();
4376 /* spice needs the timers to be initialized by this point */
4381 if (!tcg_enabled()) {
4382 error_report("-icount is not allowed with hardware virtualization");
4385 configure_icount(icount_opts
, &error_abort
);
4386 qemu_opts_del(icount_opts
);
4390 QemuOptsList
*net
= qemu_find_opts("net");
4391 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4393 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4399 if (net_init_clients() < 0) {
4403 if (qemu_opts_foreach(qemu_find_opts("object"),
4404 user_creatable_add_opts_foreach
,
4405 object_create_delayed
, NULL
)) {
4410 if (tpm_init() < 0) {
4415 /* init the bluetooth world */
4416 if (foreach_device_config(DEV_BT
, bt_parse
))
4419 if (!xen_enabled()) {
4420 /* On 32-bit hosts, QEMU is limited by virtual address space */
4421 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4422 error_report("at most 2047 MB RAM can be simulated");
4430 /* If the currently selected machine wishes to override the units-per-bus
4431 * property of its default HBA interface type, do so now. */
4432 if (machine_class
->units_per_default_bus
) {
4433 override_max_devs(machine_class
->block_default_type
,
4434 machine_class
->units_per_default_bus
);
4437 /* open the virtual block devices */
4438 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4439 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4442 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4443 &machine_class
->block_default_type
, NULL
)) {
4447 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4449 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4450 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4452 parse_numa_opts(machine_class
);
4454 if (qemu_opts_foreach(qemu_find_opts("mon"),
4455 mon_init_func
, NULL
, NULL
)) {
4459 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4461 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4463 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4465 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4468 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4471 /* If no default VGA is requested, the default is "none". */
4473 if (machine_class
->default_display
) {
4474 vga_model
= machine_class
->default_display
;
4475 } else if (vga_interface_available(VGA_CIRRUS
)) {
4476 vga_model
= "cirrus";
4477 } else if (vga_interface_available(VGA_STD
)) {
4482 select_vgahw(vga_model
);
4486 i
= select_watchdog(watchdog
);
4488 exit (i
== 1 ? 1 : 0);
4491 machine_register_compat_props(current_machine
);
4493 qemu_opts_foreach(qemu_find_opts("global"),
4494 global_init_func
, NULL
, NULL
);
4496 /* This checkpoint is required by replay to separate prior clock
4497 reading from the other reads, because timer polling functions query
4498 clock values from the log. */
4499 replay_checkpoint(CHECKPOINT_INIT
);
4500 qdev_machine_init();
4502 current_machine
->ram_size
= ram_size
;
4503 current_machine
->maxram_size
= maxram_size
;
4504 current_machine
->ram_slots
= ram_slots
;
4505 current_machine
->boot_order
= boot_order
;
4506 current_machine
->cpu_model
= cpu_model
;
4508 machine_class
->init(current_machine
);
4514 cpu_synchronize_all_post_init();
4516 numa_post_machine_init();
4518 if (hax_enabled()) {
4522 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4523 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4527 /* init USB devices */
4528 if (machine_usb(current_machine
)) {
4529 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4533 /* Check if IGD GFX passthrough. */
4536 /* init generic devices */
4537 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4538 if (qemu_opts_foreach(qemu_find_opts("device"),
4539 device_init_func
, NULL
, NULL
)) {
4542 rom_reset_order_override();
4544 /* Did we create any drives that we failed to create a device for? */
4545 drive_check_orphaned();
4547 /* Don't warn about the default network setup that you get if
4548 * no command line -net or -netdev options are specified. There
4549 * are two cases that we would otherwise complain about:
4550 * (1) board doesn't support a NIC but the implicit "-net nic"
4552 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4553 * sets up a nic that isn't connected to anything.
4556 net_check_clients();
4561 qemu_boot_set(boot_once
, &error_fatal
);
4562 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4565 ds
= init_displaystate();
4567 /* init local displays */
4568 switch (display_type
) {
4570 curses_display_init(ds
, full_screen
);
4573 sdl_display_init(ds
, full_screen
, no_frame
);
4576 cocoa_display_init(ds
, full_screen
);
4579 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4585 /* must be after terminal init, SDL library changes signal handlers */
4586 os_setup_signal_handling();
4588 /* init remote displays */
4590 qemu_opts_foreach(qemu_find_opts("vnc"),
4591 vnc_init_func
, NULL
, NULL
);
4595 qemu_spice_display_init();
4598 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4602 qdev_machine_creation_done();
4604 /* TODO: once all bus devices are qdevified, this should be done
4605 * when bus is created by qdev.c */
4606 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4607 qemu_run_machine_init_done_notifiers();
4609 if (rom_check_and_register_reset() != 0) {
4610 error_report("rom check and register reset failed");
4616 /* This checkpoint is required by replay to separate prior clock
4617 reading from the other reads, because timer polling functions query
4618 clock values from the log. */
4619 replay_checkpoint(CHECKPOINT_RESET
);
4620 qemu_system_reset(VMRESET_SILENT
);
4621 register_global_state();
4623 if (load_vmstate(loadvm
) < 0) {
4628 qdev_prop_check_globals();
4629 if (vmstate_dump_file
) {
4631 dump_vmstate_json_to_file(vmstate_dump_file
);
4636 Error
*local_err
= NULL
;
4637 qemu_start_incoming_migration(incoming
, &local_err
);
4639 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4642 } else if (autostart
) {
4649 replay_disable_events();
4650 iothread_stop_all();
4656 /* vhost-user must be cleaned up before chardevs. */