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"
30 #include "sysemu/seccomp.h"
33 #if defined(CONFIG_VDE)
34 #include <libvdeplug.h>
38 #if defined(__APPLE__) || defined(main)
40 int qemu_main(int argc
, char **argv
, char **envp
);
41 int main(int argc
, char **argv
)
43 return qemu_main(argc
, argv
, NULL
);
46 #define main qemu_main
48 #endif /* CONFIG_SDL */
52 #define main qemu_main
53 #endif /* CONFIG_COCOA */
56 #include "qemu/error-report.h"
57 #include "qemu/sockets.h"
59 #include "hw/boards.h"
60 #include "sysemu/accel.h"
62 #include "hw/i386/pc.h"
63 #include "hw/isa/isa.h"
65 #include "sysemu/watchdog.h"
66 #include "hw/smbios/smbios.h"
67 #include "hw/xen/xen.h"
69 #include "hw/loader.h"
70 #include "monitor/qdev.h"
71 #include "sysemu/bt.h"
73 #include "net/slirp.h"
74 #include "monitor/monitor.h"
75 #include "ui/console.h"
77 #include "sysemu/sysemu.h"
78 #include "sysemu/numa.h"
79 #include "exec/gdbstub.h"
80 #include "qemu/timer.h"
81 #include "sysemu/char.h"
82 #include "qemu/bitmap.h"
84 #include "sysemu/blockdev.h"
85 #include "hw/block/block.h"
86 #include "migration/block.h"
87 #include "sysemu/tpm.h"
88 #include "sysemu/dma.h"
89 #include "audio/audio.h"
90 #include "migration/migration.h"
91 #include "sysemu/cpus.h"
92 #include "sysemu/kvm.h"
93 #include "qapi/qmp/qjson.h"
94 #include "qemu/option.h"
95 #include "qemu/config-file.h"
96 #include "qemu-options.h"
97 #include "qmp-commands.h"
98 #include "qemu/main-loop.h"
100 #include "fsdev/qemu-fsdev.h"
102 #include "sysemu/qtest.h"
104 #include "disas/disas.h"
107 #include "slirp/libslirp.h"
110 #include "trace/control.h"
111 #include "qemu/queue.h"
112 #include "sysemu/cpus.h"
113 #include "sysemu/arch_init.h"
115 #include "ui/qemu-spice.h"
116 #include "qapi/string-input-visitor.h"
117 #include "qapi/opts-visitor.h"
118 #include "qom/object_interfaces.h"
119 #include "qapi-event.h"
120 #include "exec/semihost.h"
121 #include "crypto/init.h"
122 #include "sysemu/replay.h"
123 #include "qapi/qmp/qerror.h"
124 #include "sysemu/iothread.h"
126 #define MAX_VIRTIO_CONSOLES 1
127 #define MAX_SCLP_CONSOLES 1
129 static const char *data_dir
[16];
130 static int data_dir_idx
;
131 const char *bios_name
= NULL
;
132 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
133 int request_opengl
= -1;
135 const char* keyboard_layout
= NULL
;
137 const char *mem_path
= NULL
;
138 int mem_prealloc
= 0; /* force preallocation of physical target memory */
139 bool enable_mlock
= false;
141 NICInfo nd_table
[MAX_NICS
];
143 static int rtc_utc
= 1;
144 static int rtc_date_offset
= -1; /* -1 means no change */
145 QEMUClockType rtc_clock
;
146 int vga_interface_type
= VGA_NONE
;
147 static int full_screen
= 0;
148 static int no_frame
= 0;
150 static bool grab_on_hover
;
151 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
152 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
153 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
154 CharDriverState
*sclp_hds
[MAX_SCLP_CONSOLES
];
155 int win2k_install_hack
= 0;
161 int acpi_enabled
= 1;
164 static int no_reboot
;
167 int graphic_rotate
= 0;
168 const char *watchdog
;
169 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
172 const char *qemu_name
;
175 unsigned int nb_prom_envs
= 0;
176 const char *prom_envs
[MAX_PROM_ENVS
];
179 uint8_t *boot_splash_filedata
;
180 size_t boot_splash_filedata_size
;
181 uint8_t qemu_extra_params_fw
[2];
183 int icount_align_option
;
185 /* The bytes in qemu_uuid[] are in the order specified by RFC4122, _not_ in the
186 * little-endian "wire format" described in the SMBIOS 2.6 specification.
188 uint8_t qemu_uuid
[16];
191 static NotifierList exit_notifiers
=
192 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
194 static NotifierList machine_init_done_notifiers
=
195 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
199 enum xen_mode xen_mode
= XEN_EMULATE
;
201 static int has_defaults
= 1;
202 static int default_serial
= 1;
203 static int default_parallel
= 1;
204 static int default_virtcon
= 1;
205 static int default_sclp
= 1;
206 static int default_monitor
= 1;
207 static int default_floppy
= 1;
208 static int default_cdrom
= 1;
209 static int default_sdcard
= 1;
210 static int default_vga
= 1;
211 static int default_net
= 1;
217 { .driver
= "isa-serial", .flag
= &default_serial
},
218 { .driver
= "isa-parallel", .flag
= &default_parallel
},
219 { .driver
= "isa-fdc", .flag
= &default_floppy
},
220 { .driver
= "ide-cd", .flag
= &default_cdrom
},
221 { .driver
= "ide-hd", .flag
= &default_cdrom
},
222 { .driver
= "ide-drive", .flag
= &default_cdrom
},
223 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
224 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
225 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
226 { .driver
= "VGA", .flag
= &default_vga
},
227 { .driver
= "isa-vga", .flag
= &default_vga
},
228 { .driver
= "cirrus-vga", .flag
= &default_vga
},
229 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
230 { .driver
= "vmware-svga", .flag
= &default_vga
},
231 { .driver
= "qxl-vga", .flag
= &default_vga
},
232 { .driver
= "virtio-vga", .flag
= &default_vga
},
235 static QemuOptsList qemu_rtc_opts
= {
237 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
241 .type
= QEMU_OPT_STRING
,
244 .type
= QEMU_OPT_STRING
,
247 .type
= QEMU_OPT_STRING
,
249 { /* end of list */ }
253 static QemuOptsList qemu_sandbox_opts
= {
255 .implied_opt_name
= "enable",
256 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
260 .type
= QEMU_OPT_BOOL
,
262 { /* end of list */ }
266 static QemuOptsList qemu_option_rom_opts
= {
267 .name
= "option-rom",
268 .implied_opt_name
= "romfile",
269 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
273 .type
= QEMU_OPT_NUMBER
,
276 .type
= QEMU_OPT_STRING
,
278 { /* end of list */ }
282 static QemuOptsList qemu_machine_opts
= {
284 .implied_opt_name
= "type",
286 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
289 * no elements => accept any
290 * sanity checking will happen later
291 * when setting machine properties
297 static QemuOptsList qemu_boot_opts
= {
299 .implied_opt_name
= "order",
301 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
305 .type
= QEMU_OPT_STRING
,
308 .type
= QEMU_OPT_STRING
,
311 .type
= QEMU_OPT_BOOL
,
314 .type
= QEMU_OPT_STRING
,
316 .name
= "splash-time",
317 .type
= QEMU_OPT_STRING
,
319 .name
= "reboot-timeout",
320 .type
= QEMU_OPT_STRING
,
323 .type
= QEMU_OPT_BOOL
,
329 static QemuOptsList qemu_add_fd_opts
= {
331 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
335 .type
= QEMU_OPT_NUMBER
,
336 .help
= "file descriptor of which a duplicate is added to fd set",
339 .type
= QEMU_OPT_NUMBER
,
340 .help
= "ID of the fd set to add fd to",
343 .type
= QEMU_OPT_STRING
,
344 .help
= "free-form string used to describe fd",
346 { /* end of list */ }
350 static QemuOptsList qemu_object_opts
= {
352 .implied_opt_name
= "qom-type",
353 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
359 static QemuOptsList qemu_tpmdev_opts
= {
361 .implied_opt_name
= "type",
362 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
364 /* options are defined in the TPM backends */
365 { /* end of list */ }
369 static QemuOptsList qemu_realtime_opts
= {
371 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
375 .type
= QEMU_OPT_BOOL
,
377 { /* end of list */ }
381 static QemuOptsList qemu_msg_opts
= {
383 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
387 .type
= QEMU_OPT_BOOL
,
389 { /* end of list */ }
393 static QemuOptsList qemu_name_opts
= {
395 .implied_opt_name
= "guest",
397 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
401 .type
= QEMU_OPT_STRING
,
402 .help
= "Sets the name of the guest.\n"
403 "This name will be displayed in the SDL window caption.\n"
404 "The name will also be used for the VNC server",
407 .type
= QEMU_OPT_STRING
,
408 .help
= "Sets the name of the QEMU process, as shown in top etc",
410 .name
= "debug-threads",
411 .type
= QEMU_OPT_BOOL
,
412 .help
= "When enabled, name the individual threads; defaults off.\n"
413 "NOTE: The thread names are for debugging and not a\n"
416 { /* End of list */ }
420 static QemuOptsList qemu_mem_opts
= {
422 .implied_opt_name
= "size",
423 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
428 .type
= QEMU_OPT_SIZE
,
432 .type
= QEMU_OPT_NUMBER
,
436 .type
= QEMU_OPT_SIZE
,
438 { /* end of list */ }
442 static QemuOptsList qemu_icount_opts
= {
444 .implied_opt_name
= "shift",
446 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
450 .type
= QEMU_OPT_STRING
,
453 .type
= QEMU_OPT_BOOL
,
456 .type
= QEMU_OPT_BOOL
,
459 .type
= QEMU_OPT_STRING
,
462 .type
= QEMU_OPT_STRING
,
464 { /* end of list */ }
468 static QemuOptsList qemu_semihosting_config_opts
= {
469 .name
= "semihosting-config",
470 .implied_opt_name
= "enable",
471 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
475 .type
= QEMU_OPT_BOOL
,
478 .type
= QEMU_OPT_STRING
,
481 .type
= QEMU_OPT_STRING
,
483 { /* end of list */ }
487 static QemuOptsList qemu_fw_cfg_opts
= {
489 .implied_opt_name
= "name",
490 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
494 .type
= QEMU_OPT_STRING
,
495 .help
= "Sets the fw_cfg name of the blob to be inserted",
498 .type
= QEMU_OPT_STRING
,
499 .help
= "Sets the name of the file from which\n"
500 "the fw_cfg blob will be loaded",
503 .type
= QEMU_OPT_STRING
,
504 .help
= "Sets content of the blob to be inserted from a string",
506 { /* end of list */ }
511 * Get machine options
513 * Returns: machine options (never null).
515 QemuOpts
*qemu_get_machine_opts(void)
517 return qemu_find_opts_singleton("machine");
520 const char *qemu_get_vm_name(void)
525 static void res_free(void)
527 g_free(boot_splash_filedata
);
528 boot_splash_filedata
= NULL
;
531 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
533 const char *driver
= qemu_opt_get(opts
, "driver");
538 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
539 if (strcmp(default_list
[i
].driver
, driver
) != 0)
541 *(default_list
[i
].flag
) = 0;
546 /***********************************************************/
549 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
551 /* We use RUN_STATE__MAX but any invalid value will do */
552 static RunState vmstop_requested
= RUN_STATE__MAX
;
553 static QemuMutex vmstop_lock
;
558 } RunStateTransition
;
560 static const RunStateTransition runstate_transitions_def
[] = {
562 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
563 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
564 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
566 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
567 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
568 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
569 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
570 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
571 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
572 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
573 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
574 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
575 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
576 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
578 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
579 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
580 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
582 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
583 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
584 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
586 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
587 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
588 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
590 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
591 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
592 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
594 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
595 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
596 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
598 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
599 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
600 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
602 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
603 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
605 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
606 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
607 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
608 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
609 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
610 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
611 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
612 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
613 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
614 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
616 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
618 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
619 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
620 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
622 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
623 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
624 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
625 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
626 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
628 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
629 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
630 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
632 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
633 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
634 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
636 { RUN_STATE__MAX
, RUN_STATE__MAX
},
639 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
641 bool runstate_check(RunState state
)
643 return current_run_state
== state
;
646 bool runstate_store(char *str
, size_t size
)
648 const char *state
= RunState_lookup
[current_run_state
];
649 size_t len
= strlen(state
) + 1;
654 memcpy(str
, state
, len
);
658 static void runstate_init(void)
660 const RunStateTransition
*p
;
662 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
663 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
664 runstate_valid_transitions
[p
->from
][p
->to
] = true;
667 qemu_mutex_init(&vmstop_lock
);
670 /* This function will abort() on invalid state transitions */
671 void runstate_set(RunState new_state
)
673 assert(new_state
< RUN_STATE__MAX
);
675 if (current_run_state
== new_state
) {
679 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
680 error_report("invalid runstate transition: '%s' -> '%s'",
681 RunState_lookup
[current_run_state
],
682 RunState_lookup
[new_state
]);
685 trace_runstate_set(new_state
);
686 current_run_state
= new_state
;
689 int runstate_is_running(void)
691 return runstate_check(RUN_STATE_RUNNING
);
694 bool runstate_needs_reset(void)
696 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
697 runstate_check(RUN_STATE_SHUTDOWN
);
700 StatusInfo
*qmp_query_status(Error
**errp
)
702 StatusInfo
*info
= g_malloc0(sizeof(*info
));
704 info
->running
= runstate_is_running();
705 info
->singlestep
= singlestep
;
706 info
->status
= current_run_state
;
711 static bool qemu_vmstop_requested(RunState
*r
)
713 qemu_mutex_lock(&vmstop_lock
);
714 *r
= vmstop_requested
;
715 vmstop_requested
= RUN_STATE__MAX
;
716 qemu_mutex_unlock(&vmstop_lock
);
717 return *r
< RUN_STATE__MAX
;
720 void qemu_system_vmstop_request_prepare(void)
722 qemu_mutex_lock(&vmstop_lock
);
725 void qemu_system_vmstop_request(RunState state
)
727 vmstop_requested
= state
;
728 qemu_mutex_unlock(&vmstop_lock
);
736 qemu_vmstop_requested(&requested
);
737 if (runstate_is_running() && requested
== RUN_STATE__MAX
) {
741 /* Ensure that a STOP/RESUME pair of events is emitted if a
742 * vmstop request was pending. The BLOCK_IO_ERROR event, for
743 * example, according to documentation is always followed by
746 if (runstate_is_running()) {
747 qapi_event_send_stop(&error_abort
);
750 runstate_set(RUN_STATE_RUNNING
);
751 vm_state_notify(1, RUN_STATE_RUNNING
);
755 qapi_event_send_resume(&error_abort
);
759 /***********************************************************/
760 /* real time host monotonic timer */
762 static time_t qemu_time(void)
764 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
767 /***********************************************************/
768 /* host time/date access */
769 void qemu_get_timedate(struct tm
*tm
, int offset
)
771 time_t ti
= qemu_time();
774 if (rtc_date_offset
== -1) {
778 localtime_r(&ti
, tm
);
780 ti
-= rtc_date_offset
;
785 int qemu_timedate_diff(struct tm
*tm
)
789 if (rtc_date_offset
== -1)
791 seconds
= mktimegm(tm
);
794 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
795 seconds
= mktime(&tmp
);
798 seconds
= mktimegm(tm
) + rtc_date_offset
;
800 return seconds
- qemu_time();
803 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
805 time_t rtc_start_date
;
808 if (!strcmp(startdate
, "now") && legacy
) {
809 rtc_date_offset
= -1;
811 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
819 } else if (sscanf(startdate
, "%d-%d-%d",
831 rtc_start_date
= mktimegm(&tm
);
832 if (rtc_start_date
== -1) {
834 error_report("invalid date format");
835 error_printf("valid formats: "
836 "'2006-06-17T16:01:21' or '2006-06-17'\n");
839 rtc_date_offset
= qemu_time() - rtc_start_date
;
843 static void configure_rtc(QemuOpts
*opts
)
847 value
= qemu_opt_get(opts
, "base");
849 if (!strcmp(value
, "utc")) {
851 } else if (!strcmp(value
, "localtime")) {
852 Error
*blocker
= NULL
;
854 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
855 "-rtc base=localtime");
856 replay_add_blocker(blocker
);
858 configure_rtc_date_offset(value
, 0);
861 value
= qemu_opt_get(opts
, "clock");
863 if (!strcmp(value
, "host")) {
864 rtc_clock
= QEMU_CLOCK_HOST
;
865 } else if (!strcmp(value
, "rt")) {
866 rtc_clock
= QEMU_CLOCK_REALTIME
;
867 } else if (!strcmp(value
, "vm")) {
868 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
870 error_report("invalid option value '%s'", value
);
874 value
= qemu_opt_get(opts
, "driftfix");
876 if (!strcmp(value
, "slew")) {
877 static GlobalProperty slew_lost_ticks
= {
878 .driver
= "mc146818rtc",
879 .property
= "lost_tick_policy",
883 qdev_prop_register_global(&slew_lost_ticks
);
884 } else if (!strcmp(value
, "none")) {
885 /* discard is default */
887 error_report("invalid option value '%s'", value
);
893 /***********************************************************/
894 /* Bluetooth support */
897 static struct HCIInfo
*hci_table
[MAX_NICS
];
899 struct HCIInfo
*qemu_next_hci(void)
901 if (cur_hci
== nb_hcis
)
904 return hci_table
[cur_hci
++];
907 static int bt_hci_parse(const char *str
)
912 if (nb_hcis
>= MAX_NICS
) {
913 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
926 bdaddr
.b
[5] = 0x56 + nb_hcis
;
927 hci
->bdaddr_set(hci
, bdaddr
.b
);
929 hci_table
[nb_hcis
++] = hci
;
934 static void bt_vhci_add(int vlan_id
)
936 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
939 error_report("warning: adding a VHCI to an empty scatternet %i",
942 bt_vhci_init(bt_new_hci(vlan
));
945 static struct bt_device_s
*bt_device_add(const char *opt
)
947 struct bt_scatternet_s
*vlan
;
949 char *endp
= strstr(opt
, ",vlan=");
950 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
953 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
956 vlan_id
= strtol(endp
+ 6, &endp
, 0);
958 error_report("unrecognised bluetooth vlan Id");
963 vlan
= qemu_find_bt_vlan(vlan_id
);
966 error_report("warning: adding a slave device to an empty scatternet %i",
969 if (!strcmp(devname
, "keyboard"))
970 return bt_keyboard_init(vlan
);
972 error_report("unsupported bluetooth device '%s'", devname
);
976 static int bt_parse(const char *opt
)
978 const char *endp
, *p
;
981 if (strstart(opt
, "hci", &endp
)) {
982 if (!*endp
|| *endp
== ',') {
984 if (!strstart(endp
, ",vlan=", 0))
987 return bt_hci_parse(opt
);
989 } else if (strstart(opt
, "vhci", &endp
)) {
990 if (!*endp
|| *endp
== ',') {
992 if (strstart(endp
, ",vlan=", &p
)) {
993 vlan
= strtol(p
, (char **) &endp
, 0);
995 error_report("bad scatternet '%s'", p
);
999 error_report("bad parameter '%s'", endp
+ 1);
1008 } else if (strstart(opt
, "device:", &endp
))
1009 return !bt_device_add(endp
);
1011 error_report("bad bluetooth parameter '%s'", opt
);
1015 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1017 /* FIXME: change this to true for 1.3 */
1018 if (qemu_opt_get_bool(opts
, "enable", false)) {
1019 #ifdef CONFIG_SECCOMP
1020 if (seccomp_start() < 0) {
1021 error_report("failed to install seccomp syscall filter "
1026 error_report("seccomp support is disabled");
1034 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1036 const char *proc_name
;
1038 if (qemu_opt_get(opts
, "debug-threads")) {
1039 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1041 qemu_name
= qemu_opt_get(opts
, "guest");
1043 proc_name
= qemu_opt_get(opts
, "process");
1045 os_set_proc_name(proc_name
);
1051 bool defaults_enabled(void)
1053 return has_defaults
;
1057 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1059 int fd
, dupfd
, flags
;
1061 const char *fd_opaque
= NULL
;
1064 fd
= qemu_opt_get_number(opts
, "fd", -1);
1065 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1066 fd_opaque
= qemu_opt_get(opts
, "opaque");
1069 error_report("fd option is required and must be non-negative");
1073 if (fd
<= STDERR_FILENO
) {
1074 error_report("fd cannot be a standard I/O stream");
1079 * All fds inherited across exec() necessarily have FD_CLOEXEC
1080 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1082 flags
= fcntl(fd
, F_GETFD
);
1083 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1084 error_report("fd is not valid or already in use");
1089 error_report("set option is required and must be non-negative");
1093 #ifdef F_DUPFD_CLOEXEC
1094 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1098 qemu_set_cloexec(dupfd
);
1102 error_report("error duplicating fd: %s", strerror(errno
));
1106 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1107 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1114 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1118 fd
= qemu_opt_get_number(opts
, "fd", -1);
1125 /***********************************************************/
1126 /* QEMU Block devices */
1128 #define HD_OPTS "media=disk"
1129 #define CDROM_OPTS "media=cdrom"
1131 #define PFLASH_OPTS ""
1135 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1137 BlockInterfaceType
*block_default_type
= opaque
;
1139 return drive_new(opts
, *block_default_type
) == NULL
;
1142 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1144 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1145 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1150 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1151 int index
, const char *optstr
)
1156 if (!enable
|| drive_get_by_index(type
, index
)) {
1160 opts
= drive_add(type
, index
, NULL
, optstr
);
1162 drive_enable_snapshot(NULL
, opts
, NULL
);
1165 dinfo
= drive_new(opts
, type
);
1169 dinfo
->is_default
= true;
1173 static QemuOptsList qemu_smp_opts
= {
1175 .implied_opt_name
= "cpus",
1176 .merge_lists
= true,
1177 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1181 .type
= QEMU_OPT_NUMBER
,
1184 .type
= QEMU_OPT_NUMBER
,
1187 .type
= QEMU_OPT_NUMBER
,
1190 .type
= QEMU_OPT_NUMBER
,
1193 .type
= QEMU_OPT_NUMBER
,
1195 { /*End of list */ }
1199 static void smp_parse(QemuOpts
*opts
)
1202 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1203 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1204 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1205 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1207 /* compute missing values, prefer sockets over cores over threads */
1208 if (cpus
== 0 || sockets
== 0) {
1209 sockets
= sockets
> 0 ? sockets
: 1;
1210 cores
= cores
> 0 ? cores
: 1;
1211 threads
= threads
> 0 ? threads
: 1;
1213 cpus
= cores
* threads
* sockets
;
1215 } else if (cores
== 0) {
1216 threads
= threads
> 0 ? threads
: 1;
1217 cores
= cpus
/ (sockets
* threads
);
1218 cores
= cores
> 0 ? cores
: 1;
1219 } else if (threads
== 0) {
1220 threads
= cpus
/ (cores
* sockets
);
1221 threads
= threads
> 0 ? threads
: 1;
1222 } else if (sockets
* cores
* threads
< cpus
) {
1223 error_report("cpu topology: "
1224 "sockets (%u) * cores (%u) * threads (%u) < "
1226 sockets
, cores
, threads
, cpus
);
1230 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1232 if (max_cpus
> MAX_CPUMASK_BITS
) {
1233 error_report("unsupported number of maxcpus");
1237 if (max_cpus
< cpus
) {
1238 error_report("maxcpus must be equal to or greater than smp");
1242 if (sockets
* cores
* threads
> max_cpus
) {
1243 error_report("cpu topology: "
1244 "sockets (%u) * cores (%u) * threads (%u) > "
1246 sockets
, cores
, threads
, max_cpus
);
1252 smp_threads
= threads
;
1256 Error
*blocker
= NULL
;
1257 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1258 replay_add_blocker(blocker
);
1262 static void realtime_init(void)
1265 if (os_mlock() < 0) {
1266 error_report("locking memory failed");
1273 static void configure_msg(QemuOpts
*opts
)
1275 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1278 /***********************************************************/
1281 typedef struct SemihostingConfig
{
1283 SemihostingTarget target
;
1286 const char *cmdline
; /* concatenated argv */
1287 } SemihostingConfig
;
1289 static SemihostingConfig semihosting
;
1291 bool semihosting_enabled(void)
1293 return semihosting
.enabled
;
1296 SemihostingTarget
semihosting_get_target(void)
1298 return semihosting
.target
;
1301 const char *semihosting_get_arg(int i
)
1303 if (i
>= semihosting
.argc
) {
1306 return semihosting
.argv
[i
];
1309 int semihosting_get_argc(void)
1311 return semihosting
.argc
;
1314 const char *semihosting_get_cmdline(void)
1316 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1317 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1319 return semihosting
.cmdline
;
1322 static int add_semihosting_arg(void *opaque
,
1323 const char *name
, const char *val
,
1326 SemihostingConfig
*s
= opaque
;
1327 if (strcmp(name
, "arg") == 0) {
1329 /* one extra element as g_strjoinv() expects NULL-terminated array */
1330 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1331 s
->argv
[s
->argc
- 1] = val
;
1332 s
->argv
[s
->argc
] = NULL
;
1337 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1338 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1343 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1345 /* split -append and initialize argv[1..n] */
1346 cmd_token
= strtok(g_strdup(cmd
), " ");
1348 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1349 cmd_token
= strtok(NULL
, " ");
1353 /* Now we still need this for compatibility with XEN. */
1354 bool has_igd_gfx_passthru
;
1355 static void igd_gfx_passthru(void)
1357 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1360 /***********************************************************/
1363 static int usb_device_add(const char *devname
)
1365 USBDevice
*dev
= NULL
;
1366 #ifndef CONFIG_LINUX
1370 if (!machine_usb(current_machine
)) {
1374 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1375 dev
= usbdevice_create(devname
);
1379 /* the other ones */
1380 #ifndef CONFIG_LINUX
1381 /* only the linux version is qdev-ified, usb-bsd still needs this */
1382 if (strstart(devname
, "host:", &p
)) {
1383 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1393 static int usb_device_del(const char *devname
)
1398 if (strstart(devname
, "host:", &p
)) {
1402 if (!machine_usb(current_machine
)) {
1406 p
= strchr(devname
, '.');
1409 bus_num
= strtoul(devname
, NULL
, 0);
1410 addr
= strtoul(p
+ 1, NULL
, 0);
1412 return usb_device_delete_addr(bus_num
, addr
);
1415 static int usb_parse(const char *cmdline
)
1418 r
= usb_device_add(cmdline
);
1420 error_report("could not add USB device '%s'", cmdline
);
1425 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1427 const char *devname
= qdict_get_str(qdict
, "devname");
1428 if (usb_device_add(devname
) < 0) {
1429 error_report("could not add USB device '%s'", devname
);
1433 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1435 const char *devname
= qdict_get_str(qdict
, "devname");
1436 if (usb_device_del(devname
) < 0) {
1437 error_report("could not delete USB device '%s'", devname
);
1441 /***********************************************************/
1442 /* machine registration */
1444 MachineState
*current_machine
;
1446 static MachineClass
*find_machine(const char *name
)
1448 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1449 MachineClass
*mc
= NULL
;
1451 for (el
= machines
; el
; el
= el
->next
) {
1452 MachineClass
*temp
= el
->data
;
1454 if (!strcmp(temp
->name
, name
)) {
1459 !strcmp(temp
->alias
, name
)) {
1465 g_slist_free(machines
);
1469 MachineClass
*find_default_machine(void)
1471 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1472 MachineClass
*mc
= NULL
;
1474 for (el
= machines
; el
; el
= el
->next
) {
1475 MachineClass
*temp
= el
->data
;
1477 if (temp
->is_default
) {
1483 g_slist_free(machines
);
1487 MachineInfoList
*qmp_query_machines(Error
**errp
)
1489 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1490 MachineInfoList
*mach_list
= NULL
;
1492 for (el
= machines
; el
; el
= el
->next
) {
1493 MachineClass
*mc
= el
->data
;
1494 MachineInfoList
*entry
;
1497 info
= g_malloc0(sizeof(*info
));
1498 if (mc
->is_default
) {
1499 info
->has_is_default
= true;
1500 info
->is_default
= true;
1504 info
->has_alias
= true;
1505 info
->alias
= g_strdup(mc
->alias
);
1508 info
->name
= g_strdup(mc
->name
);
1509 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1510 info
->hotpluggable_cpus
= !!mc
->query_hotpluggable_cpus
;
1512 entry
= g_malloc0(sizeof(*entry
));
1513 entry
->value
= info
;
1514 entry
->next
= mach_list
;
1518 g_slist_free(machines
);
1522 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1524 ObjectProperty
*prop
;
1525 ObjectPropertyIterator iter
;
1527 if (!qemu_opt_has_help_opt(opts
)) {
1531 object_property_iter_init(&iter
, OBJECT(machine
));
1532 while ((prop
= object_property_iter_next(&iter
))) {
1537 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1538 prop
->name
, prop
->type
);
1539 if (prop
->description
) {
1540 error_printf(" (%s)\n", prop
->description
);
1549 /***********************************************************/
1550 /* main execution loop */
1552 struct vm_change_state_entry
{
1553 VMChangeStateHandler
*cb
;
1555 QLIST_ENTRY (vm_change_state_entry
) entries
;
1558 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1560 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1563 VMChangeStateEntry
*e
;
1565 e
= g_malloc0(sizeof (*e
));
1569 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1573 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1575 QLIST_REMOVE (e
, entries
);
1579 void vm_state_notify(int running
, RunState state
)
1581 VMChangeStateEntry
*e
, *next
;
1583 trace_vm_state_notify(running
, state
);
1585 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1586 e
->cb(e
->opaque
, running
, state
);
1590 /* reset/shutdown handler */
1592 typedef struct QEMUResetEntry
{
1593 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1594 QEMUResetHandler
*func
;
1598 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1599 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1600 static int reset_requested
;
1601 static int shutdown_requested
, shutdown_signal
= -1;
1602 static pid_t shutdown_pid
;
1603 static int powerdown_requested
;
1604 static int debug_requested
;
1605 static int suspend_requested
;
1606 static WakeupReason wakeup_reason
;
1607 static NotifierList powerdown_notifiers
=
1608 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1609 static NotifierList suspend_notifiers
=
1610 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1611 static NotifierList wakeup_notifiers
=
1612 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1613 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1615 int qemu_shutdown_requested_get(void)
1617 return shutdown_requested
;
1620 int qemu_reset_requested_get(void)
1622 return reset_requested
;
1625 static int qemu_shutdown_requested(void)
1627 return atomic_xchg(&shutdown_requested
, 0);
1630 static void qemu_kill_report(void)
1632 if (!qtest_driver() && shutdown_signal
!= -1) {
1633 if (shutdown_pid
== 0) {
1634 /* This happens for eg ^C at the terminal, so it's worth
1635 * avoiding printing an odd message in that case.
1637 error_report("terminating on signal %d", shutdown_signal
);
1639 error_report("terminating on signal %d from pid " FMT_pid
,
1640 shutdown_signal
, shutdown_pid
);
1642 shutdown_signal
= -1;
1646 static int qemu_reset_requested(void)
1648 int r
= reset_requested
;
1649 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1650 reset_requested
= 0;
1656 static int qemu_suspend_requested(void)
1658 int r
= suspend_requested
;
1659 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1660 suspend_requested
= 0;
1666 static WakeupReason
qemu_wakeup_requested(void)
1668 return wakeup_reason
;
1671 static int qemu_powerdown_requested(void)
1673 int r
= powerdown_requested
;
1674 powerdown_requested
= 0;
1678 static int qemu_debug_requested(void)
1680 int r
= debug_requested
;
1681 debug_requested
= 0;
1685 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1687 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1690 re
->opaque
= opaque
;
1691 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1694 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1698 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1699 if (re
->func
== func
&& re
->opaque
== opaque
) {
1700 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1707 void qemu_devices_reset(void)
1709 QEMUResetEntry
*re
, *nre
;
1711 /* reset all devices */
1712 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1713 re
->func(re
->opaque
);
1717 void qemu_system_reset(bool report
)
1721 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1723 cpu_synchronize_all_states();
1725 if (mc
&& mc
->reset
) {
1728 qemu_devices_reset();
1731 qapi_event_send_reset(&error_abort
);
1733 cpu_synchronize_all_post_reset();
1736 void qemu_system_guest_panicked(void)
1739 current_cpu
->crash_occurred
= true;
1741 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
, &error_abort
);
1742 vm_stop(RUN_STATE_GUEST_PANICKED
);
1745 void qemu_system_reset_request(void)
1748 shutdown_requested
= 1;
1750 reset_requested
= 1;
1753 qemu_notify_event();
1756 static void qemu_system_suspend(void)
1759 notifier_list_notify(&suspend_notifiers
, NULL
);
1760 runstate_set(RUN_STATE_SUSPENDED
);
1761 qapi_event_send_suspend(&error_abort
);
1764 void qemu_system_suspend_request(void)
1766 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1769 suspend_requested
= 1;
1771 qemu_notify_event();
1774 void qemu_register_suspend_notifier(Notifier
*notifier
)
1776 notifier_list_add(&suspend_notifiers
, notifier
);
1779 void qemu_system_wakeup_request(WakeupReason reason
)
1781 trace_system_wakeup_request(reason
);
1783 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1786 if (!(wakeup_reason_mask
& (1 << reason
))) {
1789 runstate_set(RUN_STATE_RUNNING
);
1790 wakeup_reason
= reason
;
1791 qemu_notify_event();
1794 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1797 wakeup_reason_mask
|= (1 << reason
);
1799 wakeup_reason_mask
&= ~(1 << reason
);
1803 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1805 notifier_list_add(&wakeup_notifiers
, notifier
);
1808 void qemu_system_killed(int signal
, pid_t pid
)
1810 shutdown_signal
= signal
;
1814 /* Cannot call qemu_system_shutdown_request directly because
1815 * we are in a signal handler.
1817 shutdown_requested
= 1;
1818 qemu_notify_event();
1821 void qemu_system_shutdown_request(void)
1823 trace_qemu_system_shutdown_request();
1824 replay_shutdown_request();
1825 shutdown_requested
= 1;
1826 qemu_notify_event();
1829 static void qemu_system_powerdown(void)
1831 qapi_event_send_powerdown(&error_abort
);
1832 notifier_list_notify(&powerdown_notifiers
, NULL
);
1835 void qemu_system_powerdown_request(void)
1837 trace_qemu_system_powerdown_request();
1838 powerdown_requested
= 1;
1839 qemu_notify_event();
1842 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1844 notifier_list_add(&powerdown_notifiers
, notifier
);
1847 void qemu_system_debug_request(void)
1849 debug_requested
= 1;
1850 qemu_notify_event();
1853 static bool main_loop_should_exit(void)
1856 if (qemu_debug_requested()) {
1857 vm_stop(RUN_STATE_DEBUG
);
1859 if (qemu_suspend_requested()) {
1860 qemu_system_suspend();
1862 if (qemu_shutdown_requested()) {
1864 qapi_event_send_shutdown(&error_abort
);
1866 vm_stop(RUN_STATE_SHUTDOWN
);
1871 if (qemu_reset_requested()) {
1873 qemu_system_reset(VMRESET_REPORT
);
1875 if (!runstate_check(RUN_STATE_RUNNING
) &&
1876 !runstate_check(RUN_STATE_INMIGRATE
)) {
1877 runstate_set(RUN_STATE_PRELAUNCH
);
1880 if (qemu_wakeup_requested()) {
1882 qemu_system_reset(VMRESET_SILENT
);
1883 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1884 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1886 qapi_event_send_wakeup(&error_abort
);
1888 if (qemu_powerdown_requested()) {
1889 qemu_system_powerdown();
1891 if (qemu_vmstop_requested(&r
)) {
1897 static void main_loop(void)
1901 #ifdef CONFIG_PROFILER
1905 nonblocking
= !kvm_enabled() && !xen_enabled() && last_io
> 0;
1906 #ifdef CONFIG_PROFILER
1907 ti
= profile_getclock();
1909 last_io
= main_loop_wait(nonblocking
);
1910 #ifdef CONFIG_PROFILER
1911 dev_time
+= profile_getclock() - ti
;
1913 } while (!main_loop_should_exit());
1916 static void version(void)
1918 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", "
1919 QEMU_COPYRIGHT
"\n");
1922 static void help(int exitcode
)
1925 printf("usage: %s [options] [disk_image]\n\n"
1926 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1927 error_get_progname());
1929 #define QEMU_OPTIONS_GENERATE_HELP
1930 #include "qemu-options-wrapper.h"
1932 printf("\nDuring emulation, the following keys are useful:\n"
1933 "ctrl-alt-f toggle full screen\n"
1934 "ctrl-alt-n switch to virtual console 'n'\n"
1935 "ctrl-alt toggle mouse and keyboard grab\n"
1937 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1942 #define HAS_ARG 0x0001
1944 typedef struct QEMUOption
{
1951 static const QEMUOption qemu_options
[] = {
1952 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1953 #define QEMU_OPTIONS_GENERATE_OPTIONS
1954 #include "qemu-options-wrapper.h"
1958 typedef struct VGAInterfaceInfo
{
1959 const char *opt_name
; /* option name */
1960 const char *name
; /* human-readable name */
1961 /* Class names indicating that support is available.
1962 * If no class is specified, the interface is always available */
1963 const char *class_names
[2];
1966 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1972 .name
= "standard VGA",
1973 .class_names
= { "VGA", "isa-vga" },
1976 .opt_name
= "cirrus",
1977 .name
= "Cirrus VGA",
1978 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1981 .opt_name
= "vmware",
1982 .name
= "VMWare SVGA",
1983 .class_names
= { "vmware-svga" },
1986 .opt_name
= "virtio",
1987 .name
= "Virtio VGA",
1988 .class_names
= { "virtio-vga" },
1993 .class_names
= { "qxl-vga" },
1997 .name
= "TCX framebuffer",
1998 .class_names
= { "SUNW,tcx" },
2002 .name
= "CG3 framebuffer",
2003 .class_names
= { "cgthree" },
2006 .opt_name
= "xenfb",
2010 static bool vga_interface_available(VGAInterfaceType t
)
2012 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2014 assert(t
< VGA_TYPE_MAX
);
2015 return !ti
->class_names
[0] ||
2016 object_class_by_name(ti
->class_names
[0]) ||
2017 object_class_by_name(ti
->class_names
[1]);
2020 static void select_vgahw(const char *p
)
2025 assert(vga_interface_type
== VGA_NONE
);
2026 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2027 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2028 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2029 if (!vga_interface_available(t
)) {
2030 error_report("%s not available", ti
->name
);
2033 vga_interface_type
= t
;
2037 if (t
== VGA_TYPE_MAX
) {
2039 error_report("unknown vga type: %s", p
);
2043 const char *nextopt
;
2045 if (strstart(opts
, ",retrace=", &nextopt
)) {
2047 if (strstart(opts
, "dumb", &nextopt
))
2048 vga_retrace_method
= VGA_RETRACE_DUMB
;
2049 else if (strstart(opts
, "precise", &nextopt
))
2050 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2051 else goto invalid_vga
;
2052 } else goto invalid_vga
;
2057 typedef enum DisplayType
{
2066 static DisplayType
select_display(const char *p
)
2069 DisplayType display
= DT_DEFAULT
;
2071 if (strstart(p
, "sdl", &opts
)) {
2075 const char *nextopt
;
2077 if (strstart(opts
, ",frame=", &nextopt
)) {
2079 if (strstart(opts
, "on", &nextopt
)) {
2081 } else if (strstart(opts
, "off", &nextopt
)) {
2084 goto invalid_sdl_args
;
2086 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2088 if (strstart(opts
, "on", &nextopt
)) {
2090 } else if (strstart(opts
, "off", &nextopt
)) {
2093 goto invalid_sdl_args
;
2095 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2097 if (strstart(opts
, "on", &nextopt
)) {
2099 } else if (strstart(opts
, "off", &nextopt
)) {
2102 goto invalid_sdl_args
;
2104 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2106 if (strstart(opts
, "on", &nextopt
)) {
2108 } else if (strstart(opts
, "off", &nextopt
)) {
2111 goto invalid_sdl_args
;
2113 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2115 if (strstart(opts
, "on", &nextopt
)) {
2117 } else if (strstart(opts
, "off", &nextopt
)) {
2120 goto invalid_sdl_args
;
2124 error_report("invalid SDL option string");
2130 error_report("SDL support is disabled");
2133 } else if (strstart(p
, "vnc", &opts
)) {
2135 vnc_parse(opts
+ 1, &error_fatal
);
2137 error_report("VNC requires a display argument vnc=<display>");
2140 } else if (strstart(p
, "curses", &opts
)) {
2141 #ifdef CONFIG_CURSES
2142 display
= DT_CURSES
;
2144 error_report("curses support is disabled");
2147 } else if (strstart(p
, "gtk", &opts
)) {
2151 const char *nextopt
;
2153 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2155 if (strstart(opts
, "on", &nextopt
)) {
2156 grab_on_hover
= true;
2157 } else if (strstart(opts
, "off", &nextopt
)) {
2158 grab_on_hover
= false;
2160 goto invalid_gtk_args
;
2162 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2164 if (strstart(opts
, "on", &nextopt
)) {
2166 } else if (strstart(opts
, "off", &nextopt
)) {
2169 goto invalid_gtk_args
;
2173 error_report("invalid GTK option string");
2179 error_report("GTK support is disabled");
2182 } else if (strstart(p
, "none", &opts
)) {
2185 error_report("unknown display type");
2192 static int balloon_parse(const char *arg
)
2196 if (strcmp(arg
, "none") == 0) {
2200 if (!strncmp(arg
, "virtio", 6)) {
2201 if (arg
[6] == ',') {
2202 /* have params -> parse them */
2203 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2208 /* create empty opts */
2209 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2212 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2219 char *qemu_find_file(int type
, const char *name
)
2225 /* Try the name as a straight path first */
2226 if (access(name
, R_OK
) == 0) {
2227 trace_load_file(name
, name
);
2228 return g_strdup(name
);
2232 case QEMU_FILE_TYPE_BIOS
:
2235 case QEMU_FILE_TYPE_KEYMAP
:
2236 subdir
= "keymaps/";
2242 for (i
= 0; i
< data_dir_idx
; i
++) {
2243 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2244 if (access(buf
, R_OK
) == 0) {
2245 trace_load_file(name
, buf
);
2253 static inline bool nonempty_str(const char *str
)
2258 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2262 const char *name
, *file
, *str
;
2263 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2265 if (fw_cfg
== NULL
) {
2266 error_report("fw_cfg device not available");
2269 name
= qemu_opt_get(opts
, "name");
2270 file
= qemu_opt_get(opts
, "file");
2271 str
= qemu_opt_get(opts
, "string");
2273 /* we need name and either a file or the content string */
2274 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2275 error_report("invalid argument(s)");
2278 if (nonempty_str(file
) && nonempty_str(str
)) {
2279 error_report("file and string are mutually exclusive");
2282 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2283 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2286 if (strncmp(name
, "opt/", 4) != 0) {
2287 error_report("warning: externally provided fw_cfg item names "
2288 "should be prefixed with \"opt/\"");
2290 if (nonempty_str(str
)) {
2291 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2292 buf
= g_memdup(str
, size
);
2294 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2295 error_report("can't load %s", file
);
2299 /* For legacy, keep user files in a specific global order. */
2300 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2301 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2302 fw_cfg_reset_order_override(fw_cfg
);
2306 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2308 return qdev_device_help(opts
);
2311 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2316 dev
= qdev_device_add(opts
, &err
);
2318 error_report_err(err
);
2321 object_unref(OBJECT(dev
));
2325 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2327 Error
*local_err
= NULL
;
2329 qemu_chr_new_from_opts(opts
, NULL
, &local_err
);
2331 error_report_err(local_err
);
2337 #ifdef CONFIG_VIRTFS
2338 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2340 return qemu_fsdev_add(opts
);
2344 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2346 CharDriverState
*chr
;
2347 const char *chardev
;
2351 mode
= qemu_opt_get(opts
, "mode");
2355 if (strcmp(mode
, "readline") == 0) {
2356 flags
= MONITOR_USE_READLINE
;
2357 } else if (strcmp(mode
, "control") == 0) {
2358 flags
= MONITOR_USE_CONTROL
;
2360 error_report("unknown monitor mode \"%s\"", mode
);
2364 if (qemu_opt_get_bool(opts
, "pretty", 0))
2365 flags
|= MONITOR_USE_PRETTY
;
2367 if (qemu_opt_get_bool(opts
, "default", 0))
2368 flags
|= MONITOR_IS_DEFAULT
;
2370 chardev
= qemu_opt_get(opts
, "chardev");
2371 chr
= qemu_chr_find(chardev
);
2373 error_report("chardev \"%s\" not found", chardev
);
2377 qemu_chr_fe_claim_no_fail(chr
);
2378 monitor_init(chr
, flags
);
2382 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2384 static int monitor_device_index
= 0;
2390 if (strstart(optarg
, "chardev:", &p
)) {
2391 snprintf(label
, sizeof(label
), "%s", p
);
2393 snprintf(label
, sizeof(label
), "compat_monitor%d",
2394 monitor_device_index
);
2395 if (monitor_device_index
== 0) {
2398 opts
= qemu_chr_parse_compat(label
, optarg
);
2400 error_report("parse error: %s", optarg
);
2405 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2406 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2407 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2408 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2410 qemu_opt_set(opts
, "default", "on", &error_abort
);
2411 monitor_device_index
++;
2414 struct device_config
{
2416 DEV_USB
, /* -usbdevice */
2418 DEV_SERIAL
, /* -serial */
2419 DEV_PARALLEL
, /* -parallel */
2420 DEV_VIRTCON
, /* -virtioconsole */
2421 DEV_DEBUGCON
, /* -debugcon */
2422 DEV_GDB
, /* -gdb, -s */
2423 DEV_SCLP
, /* s390 sclp */
2425 const char *cmdline
;
2427 QTAILQ_ENTRY(device_config
) next
;
2430 static QTAILQ_HEAD(, device_config
) device_configs
=
2431 QTAILQ_HEAD_INITIALIZER(device_configs
);
2433 static void add_device_config(int type
, const char *cmdline
)
2435 struct device_config
*conf
;
2437 conf
= g_malloc0(sizeof(*conf
));
2439 conf
->cmdline
= cmdline
;
2440 loc_save(&conf
->loc
);
2441 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2444 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2446 struct device_config
*conf
;
2449 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2450 if (conf
->type
!= type
)
2452 loc_push_restore(&conf
->loc
);
2453 rc
= func(conf
->cmdline
);
2454 loc_pop(&conf
->loc
);
2462 static int serial_parse(const char *devname
)
2464 static int index
= 0;
2467 if (strcmp(devname
, "none") == 0)
2469 if (index
== MAX_SERIAL_PORTS
) {
2470 error_report("too many serial ports");
2473 snprintf(label
, sizeof(label
), "serial%d", index
);
2474 serial_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2475 if (!serial_hds
[index
]) {
2476 error_report("could not connect serial device"
2477 " to character backend '%s'", devname
);
2484 static int parallel_parse(const char *devname
)
2486 static int index
= 0;
2489 if (strcmp(devname
, "none") == 0)
2491 if (index
== MAX_PARALLEL_PORTS
) {
2492 error_report("too many parallel ports");
2495 snprintf(label
, sizeof(label
), "parallel%d", index
);
2496 parallel_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2497 if (!parallel_hds
[index
]) {
2498 error_report("could not connect parallel device"
2499 " to character backend '%s'", devname
);
2506 static int virtcon_parse(const char *devname
)
2508 QemuOptsList
*device
= qemu_find_opts("device");
2509 static int index
= 0;
2511 QemuOpts
*bus_opts
, *dev_opts
;
2513 if (strcmp(devname
, "none") == 0)
2515 if (index
== MAX_VIRTIO_CONSOLES
) {
2516 error_report("too many virtio consoles");
2520 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2521 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2523 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2524 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2526 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2527 virtcon_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2528 if (!virtcon_hds
[index
]) {
2529 error_report("could not connect virtio console"
2530 " to character backend '%s'", devname
);
2533 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2539 static int sclp_parse(const char *devname
)
2541 QemuOptsList
*device
= qemu_find_opts("device");
2542 static int index
= 0;
2546 if (strcmp(devname
, "none") == 0) {
2549 if (index
== MAX_SCLP_CONSOLES
) {
2550 error_report("too many sclp consoles");
2554 assert(arch_type
== QEMU_ARCH_S390X
);
2556 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2557 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2559 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2560 sclp_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2561 if (!sclp_hds
[index
]) {
2562 error_report("could not connect sclp console"
2563 " to character backend '%s'", devname
);
2566 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2572 static int debugcon_parse(const char *devname
)
2576 if (!qemu_chr_new("debugcon", devname
, NULL
)) {
2579 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2581 error_report("already have a debugcon device");
2584 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2585 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2589 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2591 const MachineClass
*mc1
= a
, *mc2
= b
;
2594 if (mc1
->family
== NULL
) {
2595 if (mc2
->family
== NULL
) {
2596 /* Compare standalone machine types against each other; they sort
2597 * in increasing order.
2599 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2600 object_class_get_name(OBJECT_CLASS(mc2
)));
2603 /* Standalone machine types sort after families. */
2607 if (mc2
->family
== NULL
) {
2608 /* Families sort before standalone machine types. */
2612 /* Families sort between each other alphabetically increasingly. */
2613 res
= strcmp(mc1
->family
, mc2
->family
);
2618 /* Within the same family, machine types sort in decreasing order. */
2619 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2620 object_class_get_name(OBJECT_CLASS(mc1
)));
2623 static MachineClass
*machine_parse(const char *name
)
2625 MachineClass
*mc
= NULL
;
2626 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2629 mc
= find_machine(name
);
2632 g_slist_free(machines
);
2635 if (name
&& !is_help_option(name
)) {
2636 error_report("unsupported machine type");
2637 error_printf("Use -machine help to list supported machines\n");
2639 printf("Supported machines are:\n");
2640 machines
= g_slist_sort(machines
, machine_class_cmp
);
2641 for (el
= machines
; el
; el
= el
->next
) {
2642 MachineClass
*mc
= el
->data
;
2644 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2646 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2647 mc
->is_default
? " (default)" : "");
2651 g_slist_free(machines
);
2652 exit(!name
|| !is_help_option(name
));
2655 void qemu_add_exit_notifier(Notifier
*notify
)
2657 notifier_list_add(&exit_notifiers
, notify
);
2660 void qemu_remove_exit_notifier(Notifier
*notify
)
2662 notifier_remove(notify
);
2665 static void qemu_run_exit_notifiers(void)
2667 notifier_list_notify(&exit_notifiers
, NULL
);
2670 static bool machine_init_done
;
2672 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2674 notifier_list_add(&machine_init_done_notifiers
, notify
);
2675 if (machine_init_done
) {
2676 notify
->notify(notify
, NULL
);
2680 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2682 notifier_remove(notify
);
2685 static void qemu_run_machine_init_done_notifiers(void)
2687 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2688 machine_init_done
= true;
2691 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2692 const char **poptarg
, int *poptind
)
2694 const QEMUOption
*popt
;
2695 int optind
= *poptind
;
2696 char *r
= argv
[optind
];
2699 loc_set_cmdline(argv
, optind
, 1);
2701 /* Treat --foo the same as -foo. */
2704 popt
= qemu_options
;
2707 error_report("invalid option");
2710 if (!strcmp(popt
->name
, r
+ 1))
2714 if (popt
->flags
& HAS_ARG
) {
2715 if (optind
>= argc
) {
2716 error_report("requires an argument");
2719 optarg
= argv
[optind
++];
2720 loc_set_cmdline(argv
, optind
- 2, 2);
2731 static MachineClass
*select_machine(void)
2733 MachineClass
*machine_class
= find_default_machine();
2738 loc_push_none(&loc
);
2740 opts
= qemu_get_machine_opts();
2741 qemu_opts_loc_restore(opts
);
2743 optarg
= qemu_opt_get(opts
, "type");
2745 machine_class
= machine_parse(optarg
);
2748 if (!machine_class
) {
2749 error_report("No machine specified, and there is no default");
2750 error_printf("Use -machine help to list supported machines\n");
2755 return machine_class
;
2758 static int machine_set_property(void *opaque
,
2759 const char *name
, const char *value
,
2762 Object
*obj
= OBJECT(opaque
);
2763 Error
*local_err
= NULL
;
2766 if (strcmp(name
, "type") == 0) {
2770 qom_name
= g_strdup(name
);
2778 object_property_parse(obj
, value
, qom_name
, &local_err
);
2782 error_report_err(local_err
);
2791 * Initial object creation happens before all other
2792 * QEMU data types are created. The majority of objects
2793 * can be created at this point. The rng-egd object
2794 * cannot be created here, as it depends on the chardev
2797 static bool object_create_initial(const char *type
)
2799 if (g_str_equal(type
, "rng-egd")) {
2804 * return false for concrete netfilters since
2805 * they depend on netdevs already existing
2807 if (g_str_equal(type
, "filter-buffer") ||
2808 g_str_equal(type
, "filter-dump") ||
2809 g_str_equal(type
, "filter-mirror") ||
2810 g_str_equal(type
, "filter-redirector")) {
2814 /* Memory allocation by backends needs to be done
2815 * after configure_accelerator() (due to the tcg_enabled()
2816 * checks at memory_region_init_*()).
2818 * Also, allocation of large amounts of memory may delay
2819 * chardev initialization for too long, and trigger timeouts
2820 * on software that waits for a monitor socket to be created
2823 if (g_str_has_prefix(type
, "memory-backend-")) {
2832 * The remainder of object creation happens after the
2833 * creation of chardev, fsdev, net clients and device data types.
2835 static bool object_create_delayed(const char *type
)
2837 return !object_create_initial(type
);
2841 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2845 const char *mem_str
;
2846 const char *maxmem_str
, *slots_str
;
2847 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2848 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2851 loc_push_none(&loc
);
2852 qemu_opts_loc_restore(opts
);
2855 mem_str
= qemu_opt_get(opts
, "size");
2858 error_report("missing 'size' option value");
2862 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2864 /* Fix up legacy suffix-less format */
2865 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2866 uint64_t overflow_check
= sz
;
2869 if ((sz
>> 20) != overflow_check
) {
2870 error_report("too large 'size' option value");
2876 /* backward compatibility behaviour for case "-m 0" */
2878 sz
= default_ram_size
;
2881 sz
= QEMU_ALIGN_UP(sz
, 8192);
2883 if (ram_size
!= sz
) {
2884 error_report("ram size too large");
2888 /* store value for the future use */
2889 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2890 *maxram_size
= ram_size
;
2892 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2893 slots_str
= qemu_opt_get(opts
, "slots");
2894 if (maxmem_str
&& slots_str
) {
2897 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2898 slots
= qemu_opt_get_number(opts
, "slots", 0);
2899 if (sz
< ram_size
) {
2900 error_report("invalid value of -m option maxmem: "
2901 "maximum memory size (0x%" PRIx64
") must be at least "
2902 "the initial memory size (0x" RAM_ADDR_FMT
")",
2905 } else if (sz
> ram_size
) {
2907 error_report("invalid value of -m option: maxmem was "
2908 "specified, but no hotplug slots were specified");
2912 error_report("invalid value of -m option maxmem: "
2913 "memory slots were specified but maximum memory size "
2914 "(0x%" PRIx64
") is equal to the initial memory size "
2915 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2921 } else if ((!maxmem_str
&& slots_str
) ||
2922 (maxmem_str
&& !slots_str
)) {
2923 error_report("invalid -m option value: missing "
2924 "'%s' option", slots_str
? "maxmem" : "slots");
2931 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2935 g
= g_malloc0(sizeof(*g
));
2936 g
->driver
= qemu_opt_get(opts
, "driver");
2937 g
->property
= qemu_opt_get(opts
, "property");
2938 g
->value
= qemu_opt_get(opts
, "value");
2939 g
->user_provided
= true;
2940 g
->errp
= &error_fatal
;
2941 qdev_prop_register_global(g
);
2945 int main(int argc
, char **argv
, char **envp
)
2948 int snapshot
, linux_boot
;
2949 const char *initrd_filename
;
2950 const char *kernel_filename
, *kernel_cmdline
;
2951 const char *boot_order
= NULL
;
2952 const char *boot_once
= NULL
;
2954 int cyls
, heads
, secs
, translation
;
2955 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
2956 QemuOptsList
*olist
;
2959 const char *loadvm
= NULL
;
2960 MachineClass
*machine_class
;
2961 const char *cpu_model
;
2962 const char *vga_model
= NULL
;
2963 const char *qtest_chrdev
= NULL
;
2964 const char *qtest_log
= NULL
;
2965 const char *pid_file
= NULL
;
2966 const char *incoming
= NULL
;
2967 bool defconfig
= true;
2968 bool userconfig
= true;
2969 bool nographic
= false;
2970 DisplayType display_type
= DT_DEFAULT
;
2971 int display_remote
= 0;
2972 const char *log_mask
= NULL
;
2973 const char *log_file
= NULL
;
2974 char *trace_file
= NULL
;
2975 ram_addr_t maxram_size
;
2976 uint64_t ram_slots
= 0;
2977 FILE *vmstate_dump_file
= NULL
;
2978 Error
*main_loop_err
= NULL
;
2980 bool list_data_dirs
= false;
2982 qemu_init_cpu_loop();
2983 qemu_mutex_lock_iothread();
2985 atexit(qemu_run_exit_notifiers
);
2986 error_set_progname(argv
[0]);
2987 qemu_init_exec_dir(argv
[0]);
2989 module_call_init(MODULE_INIT_QOM
);
2991 qemu_add_opts(&qemu_drive_opts
);
2992 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2993 qemu_add_drive_opts(&qemu_common_drive_opts
);
2994 qemu_add_drive_opts(&qemu_drive_opts
);
2995 qemu_add_opts(&qemu_chardev_opts
);
2996 qemu_add_opts(&qemu_device_opts
);
2997 qemu_add_opts(&qemu_netdev_opts
);
2998 qemu_add_opts(&qemu_net_opts
);
2999 qemu_add_opts(&qemu_rtc_opts
);
3000 qemu_add_opts(&qemu_global_opts
);
3001 qemu_add_opts(&qemu_mon_opts
);
3002 qemu_add_opts(&qemu_trace_opts
);
3003 qemu_add_opts(&qemu_option_rom_opts
);
3004 qemu_add_opts(&qemu_machine_opts
);
3005 qemu_add_opts(&qemu_mem_opts
);
3006 qemu_add_opts(&qemu_smp_opts
);
3007 qemu_add_opts(&qemu_boot_opts
);
3008 qemu_add_opts(&qemu_sandbox_opts
);
3009 qemu_add_opts(&qemu_add_fd_opts
);
3010 qemu_add_opts(&qemu_object_opts
);
3011 qemu_add_opts(&qemu_tpmdev_opts
);
3012 qemu_add_opts(&qemu_realtime_opts
);
3013 qemu_add_opts(&qemu_msg_opts
);
3014 qemu_add_opts(&qemu_name_opts
);
3015 qemu_add_opts(&qemu_numa_opts
);
3016 qemu_add_opts(&qemu_icount_opts
);
3017 qemu_add_opts(&qemu_semihosting_config_opts
);
3018 qemu_add_opts(&qemu_fw_cfg_opts
);
3019 module_call_init(MODULE_INIT_OPTS
);
3023 if (qcrypto_init(&err
) < 0) {
3024 error_reportf_err(err
, "cannot initialize crypto: ");
3027 rtc_clock
= QEMU_CLOCK_HOST
;
3029 QLIST_INIT (&vm_change_state_head
);
3030 os_setup_early_signal_handling();
3034 cyls
= heads
= secs
= 0;
3035 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3039 bdrv_init_with_whitelist();
3043 /* first pass of option parsing */
3045 while (optind
< argc
) {
3046 if (argv
[optind
][0] != '-') {
3050 const QEMUOption
*popt
;
3052 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3053 switch (popt
->index
) {
3054 case QEMU_OPTION_nodefconfig
:
3057 case QEMU_OPTION_nouserconfig
:
3066 ret
= qemu_read_default_config_files(userconfig
);
3072 /* second pass of option parsing */
3077 if (argv
[optind
][0] != '-') {
3078 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3080 const QEMUOption
*popt
;
3082 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3083 if (!(popt
->arch_mask
& arch_type
)) {
3084 error_report("Option not supported for this target");
3087 switch(popt
->index
) {
3088 case QEMU_OPTION_no_kvm_irqchip
: {
3089 olist
= qemu_find_opts("machine");
3090 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3093 case QEMU_OPTION_cpu
:
3094 /* hw initialization will check this */
3097 case QEMU_OPTION_hda
:
3101 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3103 snprintf(buf
, sizeof(buf
),
3104 "%s,cyls=%d,heads=%d,secs=%d%s",
3105 HD_OPTS
, cyls
, heads
, secs
,
3106 translation
== BIOS_ATA_TRANSLATION_LBA
?
3108 translation
== BIOS_ATA_TRANSLATION_NONE
?
3109 ",trans=none" : "");
3110 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3113 case QEMU_OPTION_hdb
:
3114 case QEMU_OPTION_hdc
:
3115 case QEMU_OPTION_hdd
:
3116 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3119 case QEMU_OPTION_drive
:
3120 if (drive_def(optarg
) == NULL
) {
3124 case QEMU_OPTION_set
:
3125 if (qemu_set_option(optarg
) != 0)
3128 case QEMU_OPTION_global
:
3129 if (qemu_global_option(optarg
) != 0)
3132 case QEMU_OPTION_mtdblock
:
3133 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3135 case QEMU_OPTION_sd
:
3136 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3138 case QEMU_OPTION_pflash
:
3139 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3141 case QEMU_OPTION_snapshot
:
3144 case QEMU_OPTION_hdachs
:
3148 cyls
= strtol(p
, (char **)&p
, 0);
3149 if (cyls
< 1 || cyls
> 16383)
3154 heads
= strtol(p
, (char **)&p
, 0);
3155 if (heads
< 1 || heads
> 16)
3160 secs
= strtol(p
, (char **)&p
, 0);
3161 if (secs
< 1 || secs
> 63)
3165 if (!strcmp(p
, "large")) {
3166 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3167 } else if (!strcmp(p
, "rechs")) {
3168 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3169 } else if (!strcmp(p
, "none")) {
3170 translation
= BIOS_ATA_TRANSLATION_NONE
;
3171 } else if (!strcmp(p
, "lba")) {
3172 translation
= BIOS_ATA_TRANSLATION_LBA
;
3173 } else if (!strcmp(p
, "auto")) {
3174 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3178 } else if (*p
!= '\0') {
3180 error_report("invalid physical CHS format");
3183 if (hda_opts
!= NULL
) {
3184 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3186 qemu_opt_set_number(hda_opts
, "heads", heads
,
3188 qemu_opt_set_number(hda_opts
, "secs", secs
,
3190 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3191 qemu_opt_set(hda_opts
, "trans", "large",
3193 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3194 qemu_opt_set(hda_opts
, "trans", "rechs",
3196 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3197 qemu_opt_set(hda_opts
, "trans", "lba",
3199 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3200 qemu_opt_set(hda_opts
, "trans", "none",
3206 case QEMU_OPTION_numa
:
3207 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3213 case QEMU_OPTION_display
:
3214 display_type
= select_display(optarg
);
3216 case QEMU_OPTION_nographic
:
3217 olist
= qemu_find_opts("machine");
3218 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3220 display_type
= DT_NONE
;
3222 case QEMU_OPTION_curses
:
3223 #ifdef CONFIG_CURSES
3224 display_type
= DT_CURSES
;
3226 error_report("curses support is disabled");
3230 case QEMU_OPTION_portrait
:
3231 graphic_rotate
= 90;
3233 case QEMU_OPTION_rotate
:
3234 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3235 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3236 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3237 error_report("only 90, 180, 270 deg rotation is available");
3241 case QEMU_OPTION_kernel
:
3242 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3245 case QEMU_OPTION_initrd
:
3246 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3249 case QEMU_OPTION_append
:
3250 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3253 case QEMU_OPTION_dtb
:
3254 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3257 case QEMU_OPTION_cdrom
:
3258 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3260 case QEMU_OPTION_boot
:
3261 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3267 case QEMU_OPTION_fda
:
3268 case QEMU_OPTION_fdb
:
3269 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3272 case QEMU_OPTION_no_fd_bootchk
:
3275 case QEMU_OPTION_netdev
:
3277 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3281 case QEMU_OPTION_net
:
3283 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3287 #ifdef CONFIG_LIBISCSI
3288 case QEMU_OPTION_iscsi
:
3289 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3297 case QEMU_OPTION_tftp
:
3298 error_report("The -tftp option is deprecated. "
3299 "Please use '-netdev user,tftp=...' instead.");
3300 legacy_tftp_prefix
= optarg
;
3302 case QEMU_OPTION_bootp
:
3303 error_report("The -bootp option is deprecated. "
3304 "Please use '-netdev user,bootfile=...' instead.");
3305 legacy_bootp_filename
= optarg
;
3307 case QEMU_OPTION_redir
:
3308 error_report("The -redir option is deprecated. "
3309 "Please use '-netdev user,hostfwd=...' instead.");
3310 if (net_slirp_redir(optarg
) < 0)
3314 case QEMU_OPTION_bt
:
3315 add_device_config(DEV_BT
, optarg
);
3317 case QEMU_OPTION_audio_help
:
3321 case QEMU_OPTION_soundhw
:
3322 select_soundhw (optarg
);
3327 case QEMU_OPTION_version
:
3332 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3339 case QEMU_OPTION_tpmdev
:
3340 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3345 case QEMU_OPTION_mempath
:
3348 case QEMU_OPTION_mem_prealloc
:
3357 case QEMU_OPTION_DFILTER
:
3358 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3361 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3363 case QEMU_OPTION_gdb
:
3364 add_device_config(DEV_GDB
, optarg
);
3367 if (is_help_option(optarg
)) {
3368 list_data_dirs
= true;
3369 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3370 data_dir
[data_dir_idx
++] = optarg
;
3373 case QEMU_OPTION_bios
:
3374 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3377 case QEMU_OPTION_singlestep
:
3384 keyboard_layout
= optarg
;
3386 case QEMU_OPTION_localtime
:
3389 case QEMU_OPTION_vga
:
3398 w
= strtol(p
, (char **)&p
, 10);
3401 error_report("invalid resolution or depth");
3407 h
= strtol(p
, (char **)&p
, 10);
3412 depth
= strtol(p
, (char **)&p
, 10);
3413 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3414 depth
!= 24 && depth
!= 32)
3416 } else if (*p
== '\0') {
3417 depth
= graphic_depth
;
3424 graphic_depth
= depth
;
3427 case QEMU_OPTION_echr
:
3430 term_escape_char
= strtol(optarg
, &r
, 0);
3432 printf("Bad argument to echr\n");
3435 case QEMU_OPTION_monitor
:
3436 default_monitor
= 0;
3437 if (strncmp(optarg
, "none", 4)) {
3438 monitor_parse(optarg
, "readline", false);
3441 case QEMU_OPTION_qmp
:
3442 monitor_parse(optarg
, "control", false);
3443 default_monitor
= 0;
3445 case QEMU_OPTION_qmp_pretty
:
3446 monitor_parse(optarg
, "control", true);
3447 default_monitor
= 0;
3449 case QEMU_OPTION_mon
:
3450 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3455 default_monitor
= 0;
3457 case QEMU_OPTION_chardev
:
3458 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3464 case QEMU_OPTION_fsdev
:
3465 olist
= qemu_find_opts("fsdev");
3467 error_report("fsdev support is disabled");
3470 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3475 case QEMU_OPTION_virtfs
: {
3478 const char *writeout
, *sock_fd
, *socket
;
3480 olist
= qemu_find_opts("virtfs");
3482 error_report("virtfs support is disabled");
3485 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3490 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3491 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3492 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3495 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3496 qemu_opt_get(opts
, "mount_tag"),
3499 error_report("duplicate fsdev id: %s",
3500 qemu_opt_get(opts
, "mount_tag"));
3504 writeout
= qemu_opt_get(opts
, "writeout");
3506 #ifdef CONFIG_SYNC_FILE_RANGE
3507 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3509 error_report("writeout=immediate not supported "
3510 "on this platform");
3514 qemu_opt_set(fsdev
, "fsdriver",
3515 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3516 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3518 qemu_opt_set(fsdev
, "security_model",
3519 qemu_opt_get(opts
, "security_model"),
3521 socket
= qemu_opt_get(opts
, "socket");
3523 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3525 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3527 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3530 qemu_opt_set_bool(fsdev
, "readonly",
3531 qemu_opt_get_bool(opts
, "readonly", 0),
3533 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3535 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3536 qemu_opt_set(device
, "fsdev",
3537 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3538 qemu_opt_set(device
, "mount_tag",
3539 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3542 case QEMU_OPTION_virtfs_synth
: {
3546 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3549 error_report("duplicate option: %s", "virtfs_synth");
3552 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3554 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3556 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3557 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3558 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3561 case QEMU_OPTION_serial
:
3562 add_device_config(DEV_SERIAL
, optarg
);
3564 if (strncmp(optarg
, "mon:", 4) == 0) {
3565 default_monitor
= 0;
3568 case QEMU_OPTION_watchdog
:
3570 error_report("only one watchdog option may be given");
3575 case QEMU_OPTION_watchdog_action
:
3576 if (select_watchdog_action(optarg
) == -1) {
3577 error_report("unknown -watchdog-action parameter");
3581 case QEMU_OPTION_virtiocon
:
3582 add_device_config(DEV_VIRTCON
, optarg
);
3583 default_virtcon
= 0;
3584 if (strncmp(optarg
, "mon:", 4) == 0) {
3585 default_monitor
= 0;
3588 case QEMU_OPTION_parallel
:
3589 add_device_config(DEV_PARALLEL
, optarg
);
3590 default_parallel
= 0;
3591 if (strncmp(optarg
, "mon:", 4) == 0) {
3592 default_monitor
= 0;
3595 case QEMU_OPTION_debugcon
:
3596 add_device_config(DEV_DEBUGCON
, optarg
);
3598 case QEMU_OPTION_loadvm
:
3601 case QEMU_OPTION_full_screen
:
3604 case QEMU_OPTION_no_frame
:
3607 case QEMU_OPTION_alt_grab
:
3610 case QEMU_OPTION_ctrl_grab
:
3613 case QEMU_OPTION_no_quit
:
3616 case QEMU_OPTION_sdl
:
3618 display_type
= DT_SDL
;
3621 error_report("SDL support is disabled");
3624 case QEMU_OPTION_pidfile
:
3627 case QEMU_OPTION_win2k_hack
:
3628 win2k_install_hack
= 1;
3630 case QEMU_OPTION_rtc_td_hack
: {
3631 static GlobalProperty slew_lost_ticks
= {
3632 .driver
= "mc146818rtc",
3633 .property
= "lost_tick_policy",
3637 qdev_prop_register_global(&slew_lost_ticks
);
3640 case QEMU_OPTION_acpitable
:
3641 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3646 do_acpitable_option(opts
);
3648 case QEMU_OPTION_smbios
:
3649 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3654 do_smbios_option(opts
);
3656 case QEMU_OPTION_fwcfg
:
3657 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3663 case QEMU_OPTION_enable_kvm
:
3664 olist
= qemu_find_opts("machine");
3665 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3668 case QEMU_OPTION_machine
:
3669 olist
= qemu_find_opts("machine");
3670 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3675 case QEMU_OPTION_no_kvm
:
3676 olist
= qemu_find_opts("machine");
3677 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3679 case QEMU_OPTION_no_kvm_pit
: {
3680 error_report("warning: ignoring deprecated option");
3683 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3684 static GlobalProperty kvm_pit_lost_tick_policy
= {
3685 .driver
= "kvm-pit",
3686 .property
= "lost_tick_policy",
3690 error_report("warning: deprecated, replaced by "
3691 "-global kvm-pit.lost_tick_policy=discard");
3692 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3695 case QEMU_OPTION_usb
:
3696 olist
= qemu_find_opts("machine");
3697 qemu_opts_parse_noisily(olist
, "usb=on", false);
3699 case QEMU_OPTION_usbdevice
:
3700 olist
= qemu_find_opts("machine");
3701 qemu_opts_parse_noisily(olist
, "usb=on", false);
3702 add_device_config(DEV_USB
, optarg
);
3704 case QEMU_OPTION_device
:
3705 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3710 case QEMU_OPTION_smp
:
3711 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3716 case QEMU_OPTION_vnc
:
3717 vnc_parse(optarg
, &error_fatal
);
3719 case QEMU_OPTION_no_acpi
:
3722 case QEMU_OPTION_no_hpet
:
3725 case QEMU_OPTION_balloon
:
3726 if (balloon_parse(optarg
) < 0) {
3727 error_report("unknown -balloon argument %s", optarg
);
3731 case QEMU_OPTION_no_reboot
:
3734 case QEMU_OPTION_no_shutdown
:
3737 case QEMU_OPTION_show_cursor
:
3740 case QEMU_OPTION_uuid
:
3741 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
3742 error_report("failed to parse UUID string: wrong format");
3745 qemu_uuid_set
= true;
3747 case QEMU_OPTION_option_rom
:
3748 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3749 error_report("too many option ROMs");
3752 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3757 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3758 option_rom
[nb_option_roms
].bootindex
=
3759 qemu_opt_get_number(opts
, "bootindex", -1);
3760 if (!option_rom
[nb_option_roms
].name
) {
3761 error_report("Option ROM file is not specified");
3766 case QEMU_OPTION_semihosting
:
3767 semihosting
.enabled
= true;
3768 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3770 case QEMU_OPTION_semihosting_config
:
3771 semihosting
.enabled
= true;
3772 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3775 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3777 const char *target
= qemu_opt_get(opts
, "target");
3778 if (target
!= NULL
) {
3779 if (strcmp("native", target
) == 0) {
3780 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3781 } else if (strcmp("gdb", target
) == 0) {
3782 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3783 } else if (strcmp("auto", target
) == 0) {
3784 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3786 error_report("unsupported semihosting-config %s",
3791 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3793 /* Set semihosting argument count and vector */
3794 qemu_opt_foreach(opts
, add_semihosting_arg
,
3795 &semihosting
, NULL
);
3797 error_report("unsupported semihosting-config %s", optarg
);
3801 case QEMU_OPTION_tdf
:
3802 error_report("warning: ignoring deprecated option");
3804 case QEMU_OPTION_name
:
3805 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3811 case QEMU_OPTION_prom_env
:
3812 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3813 error_report("too many prom variables");
3816 prom_envs
[nb_prom_envs
] = optarg
;
3819 case QEMU_OPTION_old_param
:
3822 case QEMU_OPTION_clock
:
3823 /* Clock options no longer exist. Keep this option for
3824 * backward compatibility.
3827 case QEMU_OPTION_startdate
:
3828 configure_rtc_date_offset(optarg
, 1);
3830 case QEMU_OPTION_rtc
:
3831 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3836 configure_rtc(opts
);
3838 case QEMU_OPTION_tb_size
:
3839 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3840 if (tcg_tb_size
< 0) {
3844 case QEMU_OPTION_icount
:
3845 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3851 case QEMU_OPTION_incoming
:
3853 runstate_set(RUN_STATE_INMIGRATE
);
3857 case QEMU_OPTION_nodefaults
:
3860 case QEMU_OPTION_xen_domid
:
3861 if (!(xen_available())) {
3862 error_report("Option not supported for this target");
3865 xen_domid
= atoi(optarg
);
3867 case QEMU_OPTION_xen_create
:
3868 if (!(xen_available())) {
3869 error_report("Option not supported for this target");
3872 xen_mode
= XEN_CREATE
;
3874 case QEMU_OPTION_xen_attach
:
3875 if (!(xen_available())) {
3876 error_report("Option not supported for this target");
3879 xen_mode
= XEN_ATTACH
;
3881 case QEMU_OPTION_trace
:
3883 trace_file
= trace_opt_parse(optarg
);
3885 case QEMU_OPTION_readconfig
:
3887 int ret
= qemu_read_config_file(optarg
);
3889 error_report("read config %s: %s", optarg
,
3895 case QEMU_OPTION_spice
:
3896 olist
= qemu_find_opts("spice");
3898 error_report("spice support is disabled");
3901 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3907 case QEMU_OPTION_writeconfig
:
3910 if (strcmp(optarg
, "-") == 0) {
3913 fp
= fopen(optarg
, "w");
3915 error_report("open %s: %s", optarg
,
3920 qemu_config_write(fp
);
3926 case QEMU_OPTION_qtest
:
3927 qtest_chrdev
= optarg
;
3929 case QEMU_OPTION_qtest_log
:
3932 case QEMU_OPTION_sandbox
:
3933 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
3939 case QEMU_OPTION_add_fd
:
3941 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3947 error_report("File descriptor passing is disabled on this "
3952 case QEMU_OPTION_object
:
3953 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
3959 case QEMU_OPTION_realtime
:
3960 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
3965 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
3967 case QEMU_OPTION_msg
:
3968 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3973 configure_msg(opts
);
3975 case QEMU_OPTION_dump_vmstate
:
3976 if (vmstate_dump_file
) {
3977 error_report("only one '-dump-vmstate' "
3978 "option may be given");
3981 vmstate_dump_file
= fopen(optarg
, "w");
3982 if (vmstate_dump_file
== NULL
) {
3983 error_report("open %s: %s", optarg
, strerror(errno
));
3988 os_parse_cmd_args(popt
->index
, optarg
);
3993 * Clear error location left behind by the loop.
3994 * Best done right after the loop. Do not insert code here!
3998 replay_configure(icount_opts
);
4000 machine_class
= select_machine();
4002 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4006 if (qemu_init_main_loop(&main_loop_err
)) {
4007 error_report_err(main_loop_err
);
4011 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4012 parse_sandbox
, NULL
, NULL
)) {
4016 if (qemu_opts_foreach(qemu_find_opts("name"),
4017 parse_name
, NULL
, NULL
)) {
4022 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4023 parse_add_fd
, NULL
, NULL
)) {
4027 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4028 cleanup_add_fd
, NULL
, NULL
)) {
4033 current_machine
= MACHINE(object_new(object_class_get_name(
4034 OBJECT_CLASS(machine_class
))));
4035 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4038 object_property_add_child(object_get_root(), "machine",
4039 OBJECT(current_machine
), &error_abort
);
4040 cpu_exec_init_all();
4042 if (machine_class
->hw_version
) {
4043 qemu_set_hw_version(machine_class
->hw_version
);
4046 if (cpu_model
&& is_help_option(cpu_model
)) {
4047 list_cpus(stdout
, &fprintf
, cpu_model
);
4051 if (!trace_init_backends()) {
4054 trace_init_file(trace_file
);
4056 /* Open the logfile at this point and set the log mask if necessary.
4059 qemu_set_log_filename(log_file
, &error_fatal
);
4064 mask
= qemu_str_to_log_mask(log_mask
);
4066 qemu_print_log_usage(stdout
);
4074 /* If no data_dir is specified then try to find it relative to the
4076 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4077 data_dir
[data_dir_idx
] = os_find_datadir();
4078 if (data_dir
[data_dir_idx
] != NULL
) {
4082 /* If all else fails use the install path specified when building. */
4083 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4084 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4087 /* -L help lists the data directories and exits. */
4088 if (list_data_dirs
) {
4089 for (i
= 0; i
< data_dir_idx
; i
++) {
4090 printf("%s\n", data_dir
[i
]);
4095 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4097 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4098 if (max_cpus
> machine_class
->max_cpus
) {
4099 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4100 "supported by machine '%s' (%d)", max_cpus
,
4101 machine_class
->name
, machine_class
->max_cpus
);
4106 * Get the default machine options from the machine if it is not already
4107 * specified either by the configuration file or by the command line.
4109 if (machine_class
->default_machine_opts
) {
4110 qemu_opts_set_defaults(qemu_find_opts("machine"),
4111 machine_class
->default_machine_opts
, 0);
4114 qemu_opts_foreach(qemu_find_opts("device"),
4115 default_driver_check
, NULL
, NULL
);
4116 qemu_opts_foreach(qemu_find_opts("global"),
4117 default_driver_check
, NULL
, NULL
);
4119 if (!vga_model
&& !default_vga
) {
4120 vga_interface_type
= VGA_DEVICE
;
4122 if (!has_defaults
|| machine_class
->no_serial
) {
4125 if (!has_defaults
|| machine_class
->no_parallel
) {
4126 default_parallel
= 0;
4128 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4129 default_virtcon
= 0;
4131 if (!has_defaults
|| !machine_class
->use_sclp
) {
4134 if (!has_defaults
|| machine_class
->no_floppy
) {
4137 if (!has_defaults
|| machine_class
->no_cdrom
) {
4140 if (!has_defaults
|| machine_class
->no_sdcard
) {
4143 if (!has_defaults
) {
4144 default_monitor
= 0;
4149 if (is_daemonized()) {
4150 /* According to documentation and historically, -nographic redirects
4151 * serial port, parallel port and monitor to stdio, which does not work
4152 * with -daemonize. We can redirect these to null instead, but since
4153 * -nographic is legacy, let's just error out.
4154 * We disallow -nographic only if all other ports are not redirected
4155 * explicitly, to not break existing legacy setups which uses
4156 * -nographic _and_ redirects all ports explicitly - this is valid
4157 * usage, -nographic is just a no-op in this case.
4160 && (default_parallel
|| default_serial
4161 || default_monitor
|| default_virtcon
)) {
4162 error_report("-nographic cannot be used with -daemonize");
4165 #ifdef CONFIG_CURSES
4166 if (display_type
== DT_CURSES
) {
4167 error_report("curses display cannot be used with -daemonize");
4174 if (default_parallel
)
4175 add_device_config(DEV_PARALLEL
, "null");
4176 if (default_serial
&& default_monitor
) {
4177 add_device_config(DEV_SERIAL
, "mon:stdio");
4178 } else if (default_virtcon
&& default_monitor
) {
4179 add_device_config(DEV_VIRTCON
, "mon:stdio");
4180 } else if (default_sclp
&& default_monitor
) {
4181 add_device_config(DEV_SCLP
, "mon:stdio");
4184 add_device_config(DEV_SERIAL
, "stdio");
4185 if (default_virtcon
)
4186 add_device_config(DEV_VIRTCON
, "stdio");
4188 add_device_config(DEV_SCLP
, "stdio");
4190 if (default_monitor
)
4191 monitor_parse("stdio", "readline", false);
4195 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4196 if (default_parallel
)
4197 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4198 if (default_monitor
)
4199 monitor_parse("vc:80Cx24C", "readline", false);
4200 if (default_virtcon
)
4201 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4203 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4207 #if defined(CONFIG_VNC)
4208 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4212 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4213 #if defined(CONFIG_GTK)
4214 display_type
= DT_GTK
;
4215 #elif defined(CONFIG_SDL)
4216 display_type
= DT_SDL
;
4217 #elif defined(CONFIG_COCOA)
4218 display_type
= DT_COCOA
;
4219 #elif defined(CONFIG_VNC)
4220 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4222 display_type
= DT_NONE
;
4226 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4227 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4228 "for SDL, ignoring option");
4230 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4231 error_report("-no-quit is only valid for GTK and SDL, "
4235 if (display_type
== DT_GTK
) {
4236 early_gtk_display_init(request_opengl
);
4239 if (display_type
== DT_SDL
) {
4240 sdl_display_early_init(request_opengl
);
4243 if (request_opengl
== 1 && display_opengl
== 0) {
4244 #if defined(CONFIG_OPENGL)
4245 error_report("OpenGL is not supported by the display");
4247 error_report("OpenGL support is disabled");
4255 if (qemu_opts_foreach(qemu_find_opts("object"),
4256 user_creatable_add_opts_foreach
,
4257 object_create_initial
, NULL
)) {
4261 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4262 chardev_init_func
, NULL
, NULL
)) {
4266 #ifdef CONFIG_VIRTFS
4267 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4268 fsdev_init_func
, NULL
, NULL
)) {
4273 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4274 error_report("could not acquire pid file: %s", strerror(errno
));
4278 if (qemu_opts_foreach(qemu_find_opts("device"),
4279 device_help_func
, NULL
, NULL
)) {
4283 machine_opts
= qemu_get_machine_opts();
4284 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4286 object_unref(OBJECT(current_machine
));
4290 configure_accelerator(current_machine
);
4293 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4296 machine_opts
= qemu_get_machine_opts();
4297 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4298 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4299 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4300 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4302 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4304 boot_order
= qemu_opt_get(opts
, "order");
4306 validate_bootdevices(boot_order
, &error_fatal
);
4309 boot_once
= qemu_opt_get(opts
, "once");
4311 validate_bootdevices(boot_once
, &error_fatal
);
4314 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4315 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4319 boot_order
= machine_class
->default_boot_order
;
4322 if (!kernel_cmdline
) {
4323 kernel_cmdline
= "";
4324 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4327 linux_boot
= (kernel_filename
!= NULL
);
4329 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4330 error_report("-append only allowed with -kernel option");
4334 if (!linux_boot
&& initrd_filename
!= NULL
) {
4335 error_report("-initrd only allowed with -kernel option");
4339 if (!linux_boot
&& qemu_opt_get(machine_opts
, "dtb")) {
4340 error_report("-dtb only allowed with -kernel option");
4344 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4345 /* fall back to the -kernel/-append */
4346 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4349 os_set_line_buffering();
4351 /* spice needs the timers to be initialized by this point */
4356 if (kvm_enabled() || xen_enabled()) {
4357 error_report("-icount is not allowed with kvm or xen");
4360 configure_icount(icount_opts
, &error_abort
);
4361 qemu_opts_del(icount_opts
);
4365 QemuOptsList
*net
= qemu_find_opts("net");
4366 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4368 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4372 if (net_init_clients() < 0) {
4376 if (qemu_opts_foreach(qemu_find_opts("object"),
4377 user_creatable_add_opts_foreach
,
4378 object_create_delayed
, NULL
)) {
4383 if (tpm_init() < 0) {
4388 /* init the bluetooth world */
4389 if (foreach_device_config(DEV_BT
, bt_parse
))
4392 if (!xen_enabled()) {
4393 /* On 32-bit hosts, QEMU is limited by virtual address space */
4394 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4395 error_report("at most 2047 MB RAM can be simulated");
4403 /* If the currently selected machine wishes to override the units-per-bus
4404 * property of its default HBA interface type, do so now. */
4405 if (machine_class
->units_per_default_bus
) {
4406 override_max_devs(machine_class
->block_default_type
,
4407 machine_class
->units_per_default_bus
);
4410 /* open the virtual block devices */
4411 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4412 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4415 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4416 &machine_class
->block_default_type
, NULL
)) {
4420 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4422 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4423 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4425 parse_numa_opts(machine_class
);
4427 if (qemu_opts_foreach(qemu_find_opts("mon"),
4428 mon_init_func
, NULL
, NULL
)) {
4432 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4434 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4436 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4438 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4441 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4444 /* If no default VGA is requested, the default is "none". */
4446 if (machine_class
->default_display
) {
4447 vga_model
= machine_class
->default_display
;
4448 } else if (vga_interface_available(VGA_CIRRUS
)) {
4449 vga_model
= "cirrus";
4450 } else if (vga_interface_available(VGA_STD
)) {
4455 select_vgahw(vga_model
);
4459 i
= select_watchdog(watchdog
);
4461 exit (i
== 1 ? 1 : 0);
4464 machine_register_compat_props(current_machine
);
4466 qemu_opts_foreach(qemu_find_opts("global"),
4467 global_init_func
, NULL
, NULL
);
4469 /* This checkpoint is required by replay to separate prior clock
4470 reading from the other reads, because timer polling functions query
4471 clock values from the log. */
4472 replay_checkpoint(CHECKPOINT_INIT
);
4473 qdev_machine_init();
4475 current_machine
->ram_size
= ram_size
;
4476 current_machine
->maxram_size
= maxram_size
;
4477 current_machine
->ram_slots
= ram_slots
;
4478 current_machine
->boot_order
= boot_order
;
4479 current_machine
->cpu_model
= cpu_model
;
4481 machine_class
->init(current_machine
);
4487 cpu_synchronize_all_post_init();
4489 numa_post_machine_init();
4491 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4492 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4496 /* init USB devices */
4497 if (machine_usb(current_machine
)) {
4498 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4502 /* Check if IGD GFX passthrough. */
4505 /* init generic devices */
4506 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4507 if (qemu_opts_foreach(qemu_find_opts("device"),
4508 device_init_func
, NULL
, NULL
)) {
4511 rom_reset_order_override();
4513 /* Did we create any drives that we failed to create a device for? */
4514 drive_check_orphaned();
4516 /* Don't warn about the default network setup that you get if
4517 * no command line -net or -netdev options are specified. There
4518 * are two cases that we would otherwise complain about:
4519 * (1) board doesn't support a NIC but the implicit "-net nic"
4521 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4522 * sets up a nic that isn't connected to anything.
4525 net_check_clients();
4530 qemu_boot_set(boot_once
, &error_fatal
);
4531 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4534 ds
= init_displaystate();
4536 /* init local displays */
4537 switch (display_type
) {
4539 curses_display_init(ds
, full_screen
);
4542 sdl_display_init(ds
, full_screen
, no_frame
);
4545 cocoa_display_init(ds
, full_screen
);
4548 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4554 /* must be after terminal init, SDL library changes signal handlers */
4555 os_setup_signal_handling();
4557 /* init remote displays */
4559 qemu_opts_foreach(qemu_find_opts("vnc"),
4560 vnc_init_func
, NULL
, NULL
);
4564 qemu_spice_display_init();
4567 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4571 qdev_machine_creation_done();
4573 /* TODO: once all bus devices are qdevified, this should be done
4574 * when bus is created by qdev.c */
4575 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4576 qemu_run_machine_init_done_notifiers();
4578 if (rom_check_and_register_reset() != 0) {
4579 error_report("rom check and register reset failed");
4585 /* This checkpoint is required by replay to separate prior clock
4586 reading from the other reads, because timer polling functions query
4587 clock values from the log. */
4588 replay_checkpoint(CHECKPOINT_RESET
);
4589 qemu_system_reset(VMRESET_SILENT
);
4590 register_global_state();
4592 if (load_vmstate(loadvm
) < 0) {
4597 qdev_prop_check_globals();
4598 if (vmstate_dump_file
) {
4600 dump_vmstate_json_to_file(vmstate_dump_file
);
4605 Error
*local_err
= NULL
;
4606 qemu_start_incoming_migration(incoming
, &local_err
);
4608 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4611 } else if (autostart
) {
4617 trace_init_vcpu_events();
4619 replay_disable_events();
4620 iothread_stop_all();
4626 /* vhost-user must be cleaned up before chardevs. */