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
31 #include "config-host.h"
34 #include "sysemu/seccomp.h"
37 #if defined(CONFIG_VDE)
38 #include <libvdeplug.h>
42 #if defined(__APPLE__) || defined(main)
44 int qemu_main(int argc
, char **argv
);
45 int main(int argc
, char **argv
)
47 return qemu_main(argc
, argv
);
50 #define main qemu_main
52 #endif /* CONFIG_SDL */
56 #define main qemu_main
57 #endif /* CONFIG_COCOA */
61 #include "qemu/error-report.h"
62 #include "qemu/sockets.h"
64 #include "hw/boards.h"
65 #include "sysemu/accel.h"
67 #include "hw/i386/pc.h"
68 #include "hw/isa/isa.h"
70 #include "sysemu/watchdog.h"
71 #include "hw/smbios/smbios.h"
72 #include "hw/xen/xen.h"
74 #include "hw/loader.h"
75 #include "monitor/qdev.h"
76 #include "sysemu/bt.h"
78 #include "net/slirp.h"
79 #include "monitor/monitor.h"
80 #include "ui/console.h"
81 #include "sysemu/sysemu.h"
82 #include "sysemu/numa.h"
83 #include "exec/gdbstub.h"
84 #include "qemu/timer.h"
85 #include "sysemu/char.h"
86 #include "qemu/bitmap.h"
87 #include "sysemu/blockdev.h"
88 #include "hw/block/block.h"
89 #include "migration/block.h"
90 #include "sysemu/tpm.h"
91 #include "sysemu/dma.h"
92 #include "audio/audio.h"
93 #include "migration/migration.h"
94 #include "sysemu/kvm.h"
95 #include "qapi/qmp/qjson.h"
96 #include "qemu/option.h"
97 #include "qemu/config-file.h"
98 #include "qemu-options.h"
99 #include "qmp-commands.h"
100 #include "qemu/main-loop.h"
102 #include "fsdev/qemu-fsdev.h"
104 #include "sysemu/qtest.h"
106 #include "disas/disas.h"
109 #include "slirp/libslirp.h"
112 #include "trace/control.h"
113 #include "qemu/queue.h"
114 #include "sysemu/cpus.h"
115 #include "sysemu/arch_init.h"
116 #include "qemu/osdep.h"
118 #include "ui/qemu-spice.h"
119 #include "qapi/string-input-visitor.h"
120 #include "qapi/opts-visitor.h"
121 #include "qom/object_interfaces.h"
122 #include "qapi-event.h"
123 #include "exec/semihost.h"
124 #include "crypto/init.h"
125 #include "sysemu/replay.h"
126 #include "qapi/qmp/qerror.h"
128 #define MAX_VIRTIO_CONSOLES 1
129 #define MAX_SCLP_CONSOLES 1
131 static const char *data_dir
[16];
132 static int data_dir_idx
;
133 const char *bios_name
= NULL
;
134 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
135 DisplayType display_type
= DT_DEFAULT
;
136 int request_opengl
= -1;
138 static int display_remote
;
139 const char* keyboard_layout
= NULL
;
141 const char *mem_path
= NULL
;
142 int mem_prealloc
= 0; /* force preallocation of physical target memory */
143 bool enable_mlock
= false;
145 NICInfo nd_table
[MAX_NICS
];
147 static int rtc_utc
= 1;
148 static int rtc_date_offset
= -1; /* -1 means no change */
149 QEMUClockType rtc_clock
;
150 int vga_interface_type
= VGA_NONE
;
151 static int full_screen
= 0;
152 static int no_frame
= 0;
155 static bool grab_on_hover
;
157 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
158 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
159 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
160 CharDriverState
*sclp_hds
[MAX_SCLP_CONSOLES
];
161 int win2k_install_hack
= 0;
167 int acpi_enabled
= 1;
170 static int no_reboot
;
173 int graphic_rotate
= 0;
174 const char *watchdog
;
175 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
178 const char *qemu_name
;
181 unsigned int nb_prom_envs
= 0;
182 const char *prom_envs
[MAX_PROM_ENVS
];
185 uint8_t *boot_splash_filedata
;
186 size_t boot_splash_filedata_size
;
187 uint8_t qemu_extra_params_fw
[2];
189 int icount_align_option
;
191 /* The bytes in qemu_uuid[] are in the order specified by RFC4122, _not_ in the
192 * little-endian "wire format" described in the SMBIOS 2.6 specification.
194 uint8_t qemu_uuid
[16];
197 /* Trace unassigned memory or i/o accesses. */
198 bool trace_unassigned
;
200 static NotifierList exit_notifiers
=
201 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
203 static NotifierList machine_init_done_notifiers
=
204 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
208 enum xen_mode xen_mode
= XEN_EMULATE
;
210 static int has_defaults
= 1;
211 static int default_serial
= 1;
212 static int default_parallel
= 1;
213 static int default_virtcon
= 1;
214 static int default_sclp
= 1;
215 static int default_monitor
= 1;
216 static int default_floppy
= 1;
217 static int default_cdrom
= 1;
218 static int default_sdcard
= 1;
219 static int default_vga
= 1;
225 { .driver
= "isa-serial", .flag
= &default_serial
},
226 { .driver
= "isa-parallel", .flag
= &default_parallel
},
227 { .driver
= "isa-fdc", .flag
= &default_floppy
},
228 { .driver
= "ide-cd", .flag
= &default_cdrom
},
229 { .driver
= "ide-hd", .flag
= &default_cdrom
},
230 { .driver
= "ide-drive", .flag
= &default_cdrom
},
231 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
232 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
233 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
234 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
235 { .driver
= "VGA", .flag
= &default_vga
},
236 { .driver
= "isa-vga", .flag
= &default_vga
},
237 { .driver
= "cirrus-vga", .flag
= &default_vga
},
238 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
239 { .driver
= "vmware-svga", .flag
= &default_vga
},
240 { .driver
= "qxl-vga", .flag
= &default_vga
},
241 { .driver
= "virtio-vga", .flag
= &default_vga
},
244 static QemuOptsList qemu_rtc_opts
= {
246 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
250 .type
= QEMU_OPT_STRING
,
253 .type
= QEMU_OPT_STRING
,
256 .type
= QEMU_OPT_STRING
,
258 { /* end of list */ }
262 static QemuOptsList qemu_sandbox_opts
= {
264 .implied_opt_name
= "enable",
265 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
269 .type
= QEMU_OPT_BOOL
,
271 { /* end of list */ }
275 static QemuOptsList qemu_trace_opts
= {
277 .implied_opt_name
= "trace",
278 .head
= QTAILQ_HEAD_INITIALIZER(qemu_trace_opts
.head
),
282 .type
= QEMU_OPT_STRING
,
285 .type
= QEMU_OPT_STRING
,
287 { /* end of list */ }
291 static QemuOptsList qemu_option_rom_opts
= {
292 .name
= "option-rom",
293 .implied_opt_name
= "romfile",
294 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
298 .type
= QEMU_OPT_NUMBER
,
301 .type
= QEMU_OPT_STRING
,
303 { /* end of list */ }
307 static QemuOptsList qemu_machine_opts
= {
309 .implied_opt_name
= "type",
311 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
314 * no elements => accept any
315 * sanity checking will happen later
316 * when setting machine properties
322 static QemuOptsList qemu_boot_opts
= {
324 .implied_opt_name
= "order",
326 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
330 .type
= QEMU_OPT_STRING
,
333 .type
= QEMU_OPT_STRING
,
336 .type
= QEMU_OPT_BOOL
,
339 .type
= QEMU_OPT_STRING
,
341 .name
= "splash-time",
342 .type
= QEMU_OPT_STRING
,
344 .name
= "reboot-timeout",
345 .type
= QEMU_OPT_STRING
,
348 .type
= QEMU_OPT_BOOL
,
354 static QemuOptsList qemu_add_fd_opts
= {
356 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
360 .type
= QEMU_OPT_NUMBER
,
361 .help
= "file descriptor of which a duplicate is added to fd set",
364 .type
= QEMU_OPT_NUMBER
,
365 .help
= "ID of the fd set to add fd to",
368 .type
= QEMU_OPT_STRING
,
369 .help
= "free-form string used to describe fd",
371 { /* end of list */ }
375 static QemuOptsList qemu_object_opts
= {
377 .implied_opt_name
= "qom-type",
378 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
384 static QemuOptsList qemu_tpmdev_opts
= {
386 .implied_opt_name
= "type",
387 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
389 /* options are defined in the TPM backends */
390 { /* end of list */ }
394 static QemuOptsList qemu_realtime_opts
= {
396 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
400 .type
= QEMU_OPT_BOOL
,
402 { /* end of list */ }
406 static QemuOptsList qemu_msg_opts
= {
408 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
412 .type
= QEMU_OPT_BOOL
,
414 { /* end of list */ }
418 static QemuOptsList qemu_name_opts
= {
420 .implied_opt_name
= "guest",
422 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
426 .type
= QEMU_OPT_STRING
,
427 .help
= "Sets the name of the guest.\n"
428 "This name will be displayed in the SDL window caption.\n"
429 "The name will also be used for the VNC server",
432 .type
= QEMU_OPT_STRING
,
433 .help
= "Sets the name of the QEMU process, as shown in top etc",
435 .name
= "debug-threads",
436 .type
= QEMU_OPT_BOOL
,
437 .help
= "When enabled, name the individual threads; defaults off.\n"
438 "NOTE: The thread names are for debugging and not a\n"
441 { /* End of list */ }
445 static QemuOptsList qemu_mem_opts
= {
447 .implied_opt_name
= "size",
448 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
453 .type
= QEMU_OPT_SIZE
,
457 .type
= QEMU_OPT_NUMBER
,
461 .type
= QEMU_OPT_SIZE
,
463 { /* end of list */ }
467 static QemuOptsList qemu_icount_opts
= {
469 .implied_opt_name
= "shift",
471 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
475 .type
= QEMU_OPT_STRING
,
478 .type
= QEMU_OPT_BOOL
,
481 .type
= QEMU_OPT_BOOL
,
484 .type
= QEMU_OPT_STRING
,
487 .type
= QEMU_OPT_STRING
,
489 { /* end of list */ }
493 static QemuOptsList qemu_semihosting_config_opts
= {
494 .name
= "semihosting-config",
495 .implied_opt_name
= "enable",
496 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
500 .type
= QEMU_OPT_BOOL
,
503 .type
= QEMU_OPT_STRING
,
506 .type
= QEMU_OPT_STRING
,
508 { /* end of list */ }
512 static QemuOptsList qemu_fw_cfg_opts
= {
514 .implied_opt_name
= "name",
515 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
519 .type
= QEMU_OPT_STRING
,
520 .help
= "Sets the fw_cfg name of the blob to be inserted",
523 .type
= QEMU_OPT_STRING
,
524 .help
= "Sets the name of the file from which\n"
525 "the fw_cfg blob will be loaded",
528 .type
= QEMU_OPT_STRING
,
529 .help
= "Sets content of the blob to be inserted from a string",
531 { /* end of list */ }
536 * Get machine options
538 * Returns: machine options (never null).
540 QemuOpts
*qemu_get_machine_opts(void)
542 return qemu_find_opts_singleton("machine");
545 const char *qemu_get_vm_name(void)
550 static void res_free(void)
552 g_free(boot_splash_filedata
);
553 boot_splash_filedata
= NULL
;
556 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
558 const char *driver
= qemu_opt_get(opts
, "driver");
563 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
564 if (strcmp(default_list
[i
].driver
, driver
) != 0)
566 *(default_list
[i
].flag
) = 0;
571 /***********************************************************/
574 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
576 /* We use RUN_STATE_MAX but any invalid value will do */
577 static RunState vmstop_requested
= RUN_STATE_MAX
;
578 static QemuMutex vmstop_lock
;
583 } RunStateTransition
;
585 static const RunStateTransition runstate_transitions_def
[] = {
587 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
588 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
590 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
591 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
592 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
593 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
594 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
595 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
596 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
597 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
598 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
600 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
601 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
603 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
604 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
606 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
607 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
609 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
610 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
612 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
613 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
614 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
616 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
617 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
619 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
621 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
622 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
623 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
624 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
625 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
626 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
627 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
628 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
629 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
630 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
632 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
634 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
635 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
637 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
638 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
639 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
640 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
642 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
643 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
645 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
646 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
648 { RUN_STATE_MAX
, RUN_STATE_MAX
},
651 static bool runstate_valid_transitions
[RUN_STATE_MAX
][RUN_STATE_MAX
];
653 bool runstate_check(RunState state
)
655 return current_run_state
== state
;
658 bool runstate_store(char *str
, size_t size
)
660 const char *state
= RunState_lookup
[current_run_state
];
661 size_t len
= strlen(state
) + 1;
666 memcpy(str
, state
, len
);
670 static void runstate_init(void)
672 const RunStateTransition
*p
;
674 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
675 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE_MAX
; p
++) {
676 runstate_valid_transitions
[p
->from
][p
->to
] = true;
679 qemu_mutex_init(&vmstop_lock
);
682 /* This function will abort() on invalid state transitions */
683 void runstate_set(RunState new_state
)
685 assert(new_state
< RUN_STATE_MAX
);
687 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
688 error_report("invalid runstate transition: '%s' -> '%s'",
689 RunState_lookup
[current_run_state
],
690 RunState_lookup
[new_state
]);
693 trace_runstate_set(new_state
);
694 current_run_state
= new_state
;
697 int runstate_is_running(void)
699 return runstate_check(RUN_STATE_RUNNING
);
702 bool runstate_needs_reset(void)
704 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
705 runstate_check(RUN_STATE_SHUTDOWN
);
708 StatusInfo
*qmp_query_status(Error
**errp
)
710 StatusInfo
*info
= g_malloc0(sizeof(*info
));
712 info
->running
= runstate_is_running();
713 info
->singlestep
= singlestep
;
714 info
->status
= current_run_state
;
719 static bool qemu_vmstop_requested(RunState
*r
)
721 qemu_mutex_lock(&vmstop_lock
);
722 *r
= vmstop_requested
;
723 vmstop_requested
= RUN_STATE_MAX
;
724 qemu_mutex_unlock(&vmstop_lock
);
725 return *r
< RUN_STATE_MAX
;
728 void qemu_system_vmstop_request_prepare(void)
730 qemu_mutex_lock(&vmstop_lock
);
733 void qemu_system_vmstop_request(RunState state
)
735 vmstop_requested
= state
;
736 qemu_mutex_unlock(&vmstop_lock
);
744 qemu_vmstop_requested(&requested
);
745 if (runstate_is_running() && requested
== RUN_STATE_MAX
) {
749 /* Ensure that a STOP/RESUME pair of events is emitted if a
750 * vmstop request was pending. The BLOCK_IO_ERROR event, for
751 * example, according to documentation is always followed by
754 if (runstate_is_running()) {
755 qapi_event_send_stop(&error_abort
);
758 runstate_set(RUN_STATE_RUNNING
);
759 vm_state_notify(1, RUN_STATE_RUNNING
);
763 qapi_event_send_resume(&error_abort
);
767 /***********************************************************/
768 /* real time host monotonic timer */
770 static time_t qemu_time(void)
772 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
775 /***********************************************************/
776 /* host time/date access */
777 void qemu_get_timedate(struct tm
*tm
, int offset
)
779 time_t ti
= qemu_time();
782 if (rtc_date_offset
== -1) {
786 localtime_r(&ti
, tm
);
788 ti
-= rtc_date_offset
;
793 int qemu_timedate_diff(struct tm
*tm
)
797 if (rtc_date_offset
== -1)
799 seconds
= mktimegm(tm
);
802 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
803 seconds
= mktime(&tmp
);
806 seconds
= mktimegm(tm
) + rtc_date_offset
;
808 return seconds
- qemu_time();
811 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
813 time_t rtc_start_date
;
816 if (!strcmp(startdate
, "now") && legacy
) {
817 rtc_date_offset
= -1;
819 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
827 } else if (sscanf(startdate
, "%d-%d-%d",
839 rtc_start_date
= mktimegm(&tm
);
840 if (rtc_start_date
== -1) {
842 error_report("invalid date format");
843 error_printf("valid formats: "
844 "'2006-06-17T16:01:21' or '2006-06-17'\n");
847 rtc_date_offset
= qemu_time() - rtc_start_date
;
851 static void configure_rtc(QemuOpts
*opts
)
855 value
= qemu_opt_get(opts
, "base");
857 if (!strcmp(value
, "utc")) {
859 } else if (!strcmp(value
, "localtime")) {
860 Error
*blocker
= NULL
;
862 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
863 "-rtc base=localtime");
864 replay_add_blocker(blocker
);
866 configure_rtc_date_offset(value
, 0);
869 value
= qemu_opt_get(opts
, "clock");
871 if (!strcmp(value
, "host")) {
872 rtc_clock
= QEMU_CLOCK_HOST
;
873 } else if (!strcmp(value
, "rt")) {
874 rtc_clock
= QEMU_CLOCK_REALTIME
;
875 } else if (!strcmp(value
, "vm")) {
876 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
878 error_report("invalid option value '%s'", value
);
882 value
= qemu_opt_get(opts
, "driftfix");
884 if (!strcmp(value
, "slew")) {
885 static GlobalProperty slew_lost_ticks
[] = {
887 .driver
= "mc146818rtc",
888 .property
= "lost_tick_policy",
891 { /* end of list */ }
894 qdev_prop_register_global_list(slew_lost_ticks
);
895 } else if (!strcmp(value
, "none")) {
896 /* discard is default */
898 error_report("invalid option value '%s'", value
);
904 /***********************************************************/
905 /* Bluetooth support */
908 static struct HCIInfo
*hci_table
[MAX_NICS
];
910 struct HCIInfo
*qemu_next_hci(void)
912 if (cur_hci
== nb_hcis
)
915 return hci_table
[cur_hci
++];
918 static int bt_hci_parse(const char *str
)
923 if (nb_hcis
>= MAX_NICS
) {
924 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
937 bdaddr
.b
[5] = 0x56 + nb_hcis
;
938 hci
->bdaddr_set(hci
, bdaddr
.b
);
940 hci_table
[nb_hcis
++] = hci
;
945 static void bt_vhci_add(int vlan_id
)
947 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
950 error_report("warning: adding a VHCI to an empty scatternet %i",
953 bt_vhci_init(bt_new_hci(vlan
));
956 static struct bt_device_s
*bt_device_add(const char *opt
)
958 struct bt_scatternet_s
*vlan
;
960 char *endp
= strstr(opt
, ",vlan=");
961 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
964 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
967 vlan_id
= strtol(endp
+ 6, &endp
, 0);
969 error_report("unrecognised bluetooth vlan Id");
974 vlan
= qemu_find_bt_vlan(vlan_id
);
977 error_report("warning: adding a slave device to an empty scatternet %i",
980 if (!strcmp(devname
, "keyboard"))
981 return bt_keyboard_init(vlan
);
983 error_report("unsupported bluetooth device '%s'", devname
);
987 static int bt_parse(const char *opt
)
989 const char *endp
, *p
;
992 if (strstart(opt
, "hci", &endp
)) {
993 if (!*endp
|| *endp
== ',') {
995 if (!strstart(endp
, ",vlan=", 0))
998 return bt_hci_parse(opt
);
1000 } else if (strstart(opt
, "vhci", &endp
)) {
1001 if (!*endp
|| *endp
== ',') {
1003 if (strstart(endp
, ",vlan=", &p
)) {
1004 vlan
= strtol(p
, (char **) &endp
, 0);
1006 error_report("bad scatternet '%s'", p
);
1010 error_report("bad parameter '%s'", endp
+ 1);
1019 } else if (strstart(opt
, "device:", &endp
))
1020 return !bt_device_add(endp
);
1022 error_report("bad bluetooth parameter '%s'", opt
);
1026 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1028 /* FIXME: change this to true for 1.3 */
1029 if (qemu_opt_get_bool(opts
, "enable", false)) {
1030 #ifdef CONFIG_SECCOMP
1031 if (seccomp_start() < 0) {
1032 error_report("failed to install seccomp syscall filter "
1037 error_report("seccomp support is disabled");
1045 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1047 const char *proc_name
;
1049 if (qemu_opt_get(opts
, "debug-threads")) {
1050 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1052 qemu_name
= qemu_opt_get(opts
, "guest");
1054 proc_name
= qemu_opt_get(opts
, "process");
1056 os_set_proc_name(proc_name
);
1062 bool defaults_enabled(void)
1064 return has_defaults
;
1067 bool usb_enabled(void)
1069 return machine_usb(current_machine
);
1073 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1075 int fd
, dupfd
, flags
;
1077 const char *fd_opaque
= NULL
;
1080 fd
= qemu_opt_get_number(opts
, "fd", -1);
1081 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1082 fd_opaque
= qemu_opt_get(opts
, "opaque");
1085 error_report("fd option is required and must be non-negative");
1089 if (fd
<= STDERR_FILENO
) {
1090 error_report("fd cannot be a standard I/O stream");
1095 * All fds inherited across exec() necessarily have FD_CLOEXEC
1096 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1098 flags
= fcntl(fd
, F_GETFD
);
1099 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1100 error_report("fd is not valid or already in use");
1105 error_report("set option is required and must be non-negative");
1109 #ifdef F_DUPFD_CLOEXEC
1110 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1114 qemu_set_cloexec(dupfd
);
1118 error_report("error duplicating fd: %s", strerror(errno
));
1122 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1123 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1130 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1134 fd
= qemu_opt_get_number(opts
, "fd", -1);
1141 /***********************************************************/
1142 /* QEMU Block devices */
1144 #define HD_OPTS "media=disk"
1145 #define CDROM_OPTS "media=cdrom"
1147 #define PFLASH_OPTS ""
1151 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1153 BlockInterfaceType
*block_default_type
= opaque
;
1155 return drive_new(opts
, *block_default_type
) == NULL
;
1158 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1160 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1161 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1166 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1167 int index
, const char *optstr
)
1172 if (!enable
|| drive_get_by_index(type
, index
)) {
1176 opts
= drive_add(type
, index
, NULL
, optstr
);
1178 drive_enable_snapshot(NULL
, opts
, NULL
);
1181 dinfo
= drive_new(opts
, type
);
1185 dinfo
->is_default
= true;
1189 static QemuOptsList qemu_smp_opts
= {
1191 .implied_opt_name
= "cpus",
1192 .merge_lists
= true,
1193 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1197 .type
= QEMU_OPT_NUMBER
,
1200 .type
= QEMU_OPT_NUMBER
,
1203 .type
= QEMU_OPT_NUMBER
,
1206 .type
= QEMU_OPT_NUMBER
,
1209 .type
= QEMU_OPT_NUMBER
,
1211 { /*End of list */ }
1215 static void smp_parse(QemuOpts
*opts
)
1219 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1220 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1221 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1222 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1224 /* compute missing values, prefer sockets over cores over threads */
1225 if (cpus
== 0 || sockets
== 0) {
1226 sockets
= sockets
> 0 ? sockets
: 1;
1227 cores
= cores
> 0 ? cores
: 1;
1228 threads
= threads
> 0 ? threads
: 1;
1230 cpus
= cores
* threads
* sockets
;
1232 } else if (cores
== 0) {
1233 threads
= threads
> 0 ? threads
: 1;
1234 cores
= cpus
/ (sockets
* threads
);
1235 } else if (threads
== 0) {
1236 threads
= cpus
/ (cores
* sockets
);
1237 } else if (sockets
* cores
* threads
< cpus
) {
1238 error_report("cpu topology: "
1239 "sockets (%u) * cores (%u) * threads (%u) < "
1241 sockets
, cores
, threads
, cpus
);
1245 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1246 if (sockets
* cores
* threads
> max_cpus
) {
1247 error_report("cpu topology: "
1248 "sockets (%u) * cores (%u) * threads (%u) > "
1250 sockets
, cores
, threads
, max_cpus
);
1255 smp_cores
= cores
> 0 ? cores
: 1;
1256 smp_threads
= threads
> 0 ? threads
: 1;
1260 if (max_cpus
== 0) {
1261 max_cpus
= smp_cpus
;
1264 if (max_cpus
> MAX_CPUMASK_BITS
) {
1265 error_report("unsupported number of maxcpus");
1268 if (max_cpus
< smp_cpus
) {
1269 error_report("maxcpus must be equal to or greater than smp");
1273 if (smp_cpus
> 1 || smp_cores
> 1 || smp_threads
> 1) {
1274 Error
*blocker
= NULL
;
1275 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1276 replay_add_blocker(blocker
);
1280 static void realtime_init(void)
1283 if (os_mlock() < 0) {
1284 error_report("locking memory failed");
1291 static void configure_msg(QemuOpts
*opts
)
1293 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1296 /***********************************************************/
1299 typedef struct SemihostingConfig
{
1301 SemihostingTarget target
;
1304 const char *cmdline
; /* concatenated argv */
1305 } SemihostingConfig
;
1307 static SemihostingConfig semihosting
;
1309 bool semihosting_enabled(void)
1311 return semihosting
.enabled
;
1314 SemihostingTarget
semihosting_get_target(void)
1316 return semihosting
.target
;
1319 const char *semihosting_get_arg(int i
)
1321 if (i
>= semihosting
.argc
) {
1324 return semihosting
.argv
[i
];
1327 int semihosting_get_argc(void)
1329 return semihosting
.argc
;
1332 const char *semihosting_get_cmdline(void)
1334 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1335 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1337 return semihosting
.cmdline
;
1340 static int add_semihosting_arg(void *opaque
,
1341 const char *name
, const char *val
,
1344 SemihostingConfig
*s
= opaque
;
1345 if (strcmp(name
, "arg") == 0) {
1347 /* one extra element as g_strjoinv() expects NULL-terminated array */
1348 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1349 s
->argv
[s
->argc
- 1] = val
;
1350 s
->argv
[s
->argc
] = NULL
;
1355 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1356 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1361 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1363 /* split -append and initialize argv[1..n] */
1364 cmd_token
= strtok(g_strdup(cmd
), " ");
1366 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1367 cmd_token
= strtok(NULL
, " ");
1371 /* Now we still need this for compatibility with XEN. */
1372 bool has_igd_gfx_passthru
;
1373 static void igd_gfx_passthru(void)
1375 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1378 /***********************************************************/
1381 static int usb_device_add(const char *devname
)
1383 USBDevice
*dev
= NULL
;
1384 #ifndef CONFIG_LINUX
1388 if (!usb_enabled()) {
1392 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1393 dev
= usbdevice_create(devname
);
1397 /* the other ones */
1398 #ifndef CONFIG_LINUX
1399 /* only the linux version is qdev-ified, usb-bsd still needs this */
1400 if (strstart(devname
, "host:", &p
)) {
1401 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1411 static int usb_device_del(const char *devname
)
1416 if (strstart(devname
, "host:", &p
)) {
1420 if (!usb_enabled()) {
1424 p
= strchr(devname
, '.');
1427 bus_num
= strtoul(devname
, NULL
, 0);
1428 addr
= strtoul(p
+ 1, NULL
, 0);
1430 return usb_device_delete_addr(bus_num
, addr
);
1433 static int usb_parse(const char *cmdline
)
1436 r
= usb_device_add(cmdline
);
1438 error_report("could not add USB device '%s'", cmdline
);
1443 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1445 const char *devname
= qdict_get_str(qdict
, "devname");
1446 if (usb_device_add(devname
) < 0) {
1447 error_report("could not add USB device '%s'", devname
);
1451 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1453 const char *devname
= qdict_get_str(qdict
, "devname");
1454 if (usb_device_del(devname
) < 0) {
1455 error_report("could not delete USB device '%s'", devname
);
1459 /***********************************************************/
1460 /* machine registration */
1462 MachineState
*current_machine
;
1464 static MachineClass
*find_machine(const char *name
)
1466 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1467 MachineClass
*mc
= NULL
;
1469 for (el
= machines
; el
; el
= el
->next
) {
1470 MachineClass
*temp
= el
->data
;
1472 if (!strcmp(temp
->name
, name
)) {
1477 !strcmp(temp
->alias
, name
)) {
1483 g_slist_free(machines
);
1487 MachineClass
*find_default_machine(void)
1489 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1490 MachineClass
*mc
= NULL
;
1492 for (el
= machines
; el
; el
= el
->next
) {
1493 MachineClass
*temp
= el
->data
;
1495 if (temp
->is_default
) {
1501 g_slist_free(machines
);
1505 MachineInfoList
*qmp_query_machines(Error
**errp
)
1507 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1508 MachineInfoList
*mach_list
= NULL
;
1510 for (el
= machines
; el
; el
= el
->next
) {
1511 MachineClass
*mc
= el
->data
;
1512 MachineInfoList
*entry
;
1515 info
= g_malloc0(sizeof(*info
));
1516 if (mc
->is_default
) {
1517 info
->has_is_default
= true;
1518 info
->is_default
= true;
1522 info
->has_alias
= true;
1523 info
->alias
= g_strdup(mc
->alias
);
1526 info
->name
= g_strdup(mc
->name
);
1527 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1529 entry
= g_malloc0(sizeof(*entry
));
1530 entry
->value
= info
;
1531 entry
->next
= mach_list
;
1535 g_slist_free(machines
);
1539 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1541 ObjectProperty
*prop
;
1543 if (!qemu_opt_has_help_opt(opts
)) {
1547 QTAILQ_FOREACH(prop
, &OBJECT(machine
)->properties
, node
) {
1552 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1553 prop
->name
, prop
->type
);
1554 if (prop
->description
) {
1555 error_printf(" (%s)\n", prop
->description
);
1564 /***********************************************************/
1565 /* main execution loop */
1567 struct vm_change_state_entry
{
1568 VMChangeStateHandler
*cb
;
1570 QLIST_ENTRY (vm_change_state_entry
) entries
;
1573 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1575 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1578 VMChangeStateEntry
*e
;
1580 e
= g_malloc0(sizeof (*e
));
1584 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1588 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1590 QLIST_REMOVE (e
, entries
);
1594 void vm_state_notify(int running
, RunState state
)
1596 VMChangeStateEntry
*e
, *next
;
1598 trace_vm_state_notify(running
, state
);
1600 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1601 e
->cb(e
->opaque
, running
, state
);
1605 /* reset/shutdown handler */
1607 typedef struct QEMUResetEntry
{
1608 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1609 QEMUResetHandler
*func
;
1613 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1614 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1615 static int reset_requested
;
1616 static int shutdown_requested
, shutdown_signal
= -1;
1617 static pid_t shutdown_pid
;
1618 static int powerdown_requested
;
1619 static int debug_requested
;
1620 static int suspend_requested
;
1621 static WakeupReason wakeup_reason
;
1622 static NotifierList powerdown_notifiers
=
1623 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1624 static NotifierList suspend_notifiers
=
1625 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1626 static NotifierList wakeup_notifiers
=
1627 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1628 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1630 int qemu_shutdown_requested_get(void)
1632 return shutdown_requested
;
1635 int qemu_reset_requested_get(void)
1637 return reset_requested
;
1640 static int qemu_shutdown_requested(void)
1642 return atomic_xchg(&shutdown_requested
, 0);
1645 static void qemu_kill_report(void)
1647 if (!qtest_driver() && shutdown_signal
!= -1) {
1648 if (shutdown_pid
== 0) {
1649 /* This happens for eg ^C at the terminal, so it's worth
1650 * avoiding printing an odd message in that case.
1652 error_report("terminating on signal %d", shutdown_signal
);
1654 error_report("terminating on signal %d from pid " FMT_pid
,
1655 shutdown_signal
, shutdown_pid
);
1657 shutdown_signal
= -1;
1661 static int qemu_reset_requested(void)
1663 int r
= reset_requested
;
1664 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1665 reset_requested
= 0;
1671 static int qemu_suspend_requested(void)
1673 int r
= suspend_requested
;
1674 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1675 suspend_requested
= 0;
1681 static WakeupReason
qemu_wakeup_requested(void)
1683 return wakeup_reason
;
1686 static int qemu_powerdown_requested(void)
1688 int r
= powerdown_requested
;
1689 powerdown_requested
= 0;
1693 static int qemu_debug_requested(void)
1695 int r
= debug_requested
;
1696 debug_requested
= 0;
1700 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1702 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1705 re
->opaque
= opaque
;
1706 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1709 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1713 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1714 if (re
->func
== func
&& re
->opaque
== opaque
) {
1715 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1722 void qemu_devices_reset(void)
1724 QEMUResetEntry
*re
, *nre
;
1726 /* reset all devices */
1727 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1728 re
->func(re
->opaque
);
1732 void qemu_system_reset(bool report
)
1736 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1738 if (mc
&& mc
->reset
) {
1741 qemu_devices_reset();
1744 qapi_event_send_reset(&error_abort
);
1746 cpu_synchronize_all_post_reset();
1749 void qemu_system_guest_panicked(void)
1752 current_cpu
->crash_occurred
= true;
1754 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
, &error_abort
);
1755 vm_stop(RUN_STATE_GUEST_PANICKED
);
1758 void qemu_system_reset_request(void)
1761 shutdown_requested
= 1;
1763 reset_requested
= 1;
1766 qemu_notify_event();
1769 static void qemu_system_suspend(void)
1772 notifier_list_notify(&suspend_notifiers
, NULL
);
1773 runstate_set(RUN_STATE_SUSPENDED
);
1774 qapi_event_send_suspend(&error_abort
);
1777 void qemu_system_suspend_request(void)
1779 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1782 suspend_requested
= 1;
1784 qemu_notify_event();
1787 void qemu_register_suspend_notifier(Notifier
*notifier
)
1789 notifier_list_add(&suspend_notifiers
, notifier
);
1792 void qemu_system_wakeup_request(WakeupReason reason
)
1794 trace_system_wakeup_request(reason
);
1796 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1799 if (!(wakeup_reason_mask
& (1 << reason
))) {
1802 runstate_set(RUN_STATE_RUNNING
);
1803 wakeup_reason
= reason
;
1804 qemu_notify_event();
1807 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1810 wakeup_reason_mask
|= (1 << reason
);
1812 wakeup_reason_mask
&= ~(1 << reason
);
1816 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1818 notifier_list_add(&wakeup_notifiers
, notifier
);
1821 void qemu_system_killed(int signal
, pid_t pid
)
1823 shutdown_signal
= signal
;
1827 /* Cannot call qemu_system_shutdown_request directly because
1828 * we are in a signal handler.
1830 shutdown_requested
= 1;
1831 qemu_notify_event();
1834 void qemu_system_shutdown_request(void)
1836 trace_qemu_system_shutdown_request();
1837 replay_shutdown_request();
1838 shutdown_requested
= 1;
1839 qemu_notify_event();
1842 static void qemu_system_powerdown(void)
1844 qapi_event_send_powerdown(&error_abort
);
1845 notifier_list_notify(&powerdown_notifiers
, NULL
);
1848 void qemu_system_powerdown_request(void)
1850 trace_qemu_system_powerdown_request();
1851 powerdown_requested
= 1;
1852 qemu_notify_event();
1855 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1857 notifier_list_add(&powerdown_notifiers
, notifier
);
1860 void qemu_system_debug_request(void)
1862 debug_requested
= 1;
1863 qemu_notify_event();
1866 static bool main_loop_should_exit(void)
1869 if (qemu_debug_requested()) {
1870 vm_stop(RUN_STATE_DEBUG
);
1872 if (qemu_suspend_requested()) {
1873 qemu_system_suspend();
1875 if (qemu_shutdown_requested()) {
1877 qapi_event_send_shutdown(&error_abort
);
1879 vm_stop(RUN_STATE_SHUTDOWN
);
1884 if (qemu_reset_requested()) {
1886 cpu_synchronize_all_states();
1887 qemu_system_reset(VMRESET_REPORT
);
1889 if (runstate_needs_reset()) {
1890 runstate_set(RUN_STATE_PAUSED
);
1893 if (qemu_wakeup_requested()) {
1895 cpu_synchronize_all_states();
1896 qemu_system_reset(VMRESET_SILENT
);
1897 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1898 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1900 qapi_event_send_wakeup(&error_abort
);
1902 if (qemu_powerdown_requested()) {
1903 qemu_system_powerdown();
1905 if (qemu_vmstop_requested(&r
)) {
1911 static void main_loop(void)
1915 #ifdef CONFIG_PROFILER
1919 nonblocking
= !kvm_enabled() && !xen_enabled() && last_io
> 0;
1920 #ifdef CONFIG_PROFILER
1921 ti
= profile_getclock();
1923 last_io
= main_loop_wait(nonblocking
);
1924 #ifdef CONFIG_PROFILER
1925 dev_time
+= profile_getclock() - ti
;
1927 } while (!main_loop_should_exit());
1930 static void version(void)
1932 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1935 static void QEMU_NORETURN
help(int exitcode
)
1938 printf("usage: %s [options] [disk_image]\n\n"
1939 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1940 error_get_progname());
1942 #define QEMU_OPTIONS_GENERATE_HELP
1943 #include "qemu-options-wrapper.h"
1945 printf("\nDuring emulation, the following keys are useful:\n"
1946 "ctrl-alt-f toggle full screen\n"
1947 "ctrl-alt-n switch to virtual console 'n'\n"
1948 "ctrl-alt toggle mouse and keyboard grab\n"
1950 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1955 #define HAS_ARG 0x0001
1957 typedef struct QEMUOption
{
1964 static const QEMUOption qemu_options
[] = {
1965 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1966 #define QEMU_OPTIONS_GENERATE_OPTIONS
1967 #include "qemu-options-wrapper.h"
1971 static bool vga_available(void)
1973 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
1976 static bool cirrus_vga_available(void)
1978 return object_class_by_name("cirrus-vga")
1979 || object_class_by_name("isa-cirrus-vga");
1982 static bool vmware_vga_available(void)
1984 return object_class_by_name("vmware-svga");
1987 static bool qxl_vga_available(void)
1989 return object_class_by_name("qxl-vga");
1992 static bool tcx_vga_available(void)
1994 return object_class_by_name("SUNW,tcx");
1997 static bool cg3_vga_available(void)
1999 return object_class_by_name("cgthree");
2002 static bool virtio_vga_available(void)
2004 return object_class_by_name("virtio-vga");
2007 static void select_vgahw (const char *p
)
2011 assert(vga_interface_type
== VGA_NONE
);
2012 if (strstart(p
, "std", &opts
)) {
2013 if (vga_available()) {
2014 vga_interface_type
= VGA_STD
;
2016 error_report("standard VGA not available");
2019 } else if (strstart(p
, "cirrus", &opts
)) {
2020 if (cirrus_vga_available()) {
2021 vga_interface_type
= VGA_CIRRUS
;
2023 error_report("Cirrus VGA not available");
2026 } else if (strstart(p
, "vmware", &opts
)) {
2027 if (vmware_vga_available()) {
2028 vga_interface_type
= VGA_VMWARE
;
2030 error_report("VMWare SVGA not available");
2033 } else if (strstart(p
, "virtio", &opts
)) {
2034 if (virtio_vga_available()) {
2035 vga_interface_type
= VGA_VIRTIO
;
2037 error_report("Virtio VGA not available");
2040 } else if (strstart(p
, "xenfb", &opts
)) {
2041 vga_interface_type
= VGA_XENFB
;
2042 } else if (strstart(p
, "qxl", &opts
)) {
2043 if (qxl_vga_available()) {
2044 vga_interface_type
= VGA_QXL
;
2046 error_report("QXL VGA not available");
2049 } else if (strstart(p
, "tcx", &opts
)) {
2050 if (tcx_vga_available()) {
2051 vga_interface_type
= VGA_TCX
;
2053 error_report("TCX framebuffer not available");
2056 } else if (strstart(p
, "cg3", &opts
)) {
2057 if (cg3_vga_available()) {
2058 vga_interface_type
= VGA_CG3
;
2060 error_report("CG3 framebuffer not available");
2063 } else if (!strstart(p
, "none", &opts
)) {
2065 error_report("unknown vga type: %s", p
);
2069 const char *nextopt
;
2071 if (strstart(opts
, ",retrace=", &nextopt
)) {
2073 if (strstart(opts
, "dumb", &nextopt
))
2074 vga_retrace_method
= VGA_RETRACE_DUMB
;
2075 else if (strstart(opts
, "precise", &nextopt
))
2076 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2077 else goto invalid_vga
;
2078 } else goto invalid_vga
;
2083 static DisplayType
select_display(const char *p
)
2086 DisplayType display
= DT_DEFAULT
;
2088 if (strstart(p
, "sdl", &opts
)) {
2092 const char *nextopt
;
2094 if (strstart(opts
, ",frame=", &nextopt
)) {
2096 if (strstart(opts
, "on", &nextopt
)) {
2098 } else if (strstart(opts
, "off", &nextopt
)) {
2101 goto invalid_sdl_args
;
2103 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2105 if (strstart(opts
, "on", &nextopt
)) {
2107 } else if (strstart(opts
, "off", &nextopt
)) {
2110 goto invalid_sdl_args
;
2112 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2114 if (strstart(opts
, "on", &nextopt
)) {
2116 } else if (strstart(opts
, "off", &nextopt
)) {
2119 goto invalid_sdl_args
;
2121 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2123 if (strstart(opts
, "on", &nextopt
)) {
2125 } else if (strstart(opts
, "off", &nextopt
)) {
2128 goto invalid_sdl_args
;
2130 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2132 if (strstart(opts
, "on", &nextopt
)) {
2134 } else if (strstart(opts
, "off", &nextopt
)) {
2137 goto invalid_sdl_args
;
2141 error_report("invalid SDL option string");
2147 error_report("SDL support is disabled");
2150 } else if (strstart(p
, "vnc", &opts
)) {
2154 if (vnc_parse(opts
+ 1, &err
) == NULL
) {
2155 error_report_err(err
);
2159 error_report("VNC requires a display argument vnc=<display>");
2163 error_report("VNC support is disabled");
2166 } else if (strstart(p
, "curses", &opts
)) {
2167 #ifdef CONFIG_CURSES
2168 display
= DT_CURSES
;
2170 error_report("curses support is disabled");
2173 } else if (strstart(p
, "gtk", &opts
)) {
2177 const char *nextopt
;
2179 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2181 if (strstart(opts
, "on", &nextopt
)) {
2182 grab_on_hover
= true;
2183 } else if (strstart(opts
, "off", &nextopt
)) {
2184 grab_on_hover
= false;
2186 goto invalid_gtk_args
;
2188 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2190 if (strstart(opts
, "on", &nextopt
)) {
2192 } else if (strstart(opts
, "off", &nextopt
)) {
2195 goto invalid_gtk_args
;
2199 error_report("invalid GTK option string");
2205 error_report("GTK support is disabled");
2208 } else if (strstart(p
, "none", &opts
)) {
2211 error_report("unknown display type");
2218 static int balloon_parse(const char *arg
)
2222 if (strcmp(arg
, "none") == 0) {
2226 if (!strncmp(arg
, "virtio", 6)) {
2227 if (arg
[6] == ',') {
2228 /* have params -> parse them */
2229 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2234 /* create empty opts */
2235 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2238 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2245 #if defined(CONFIG_RUBY)
2246 /* Ruby interface for QEMU. See README.EXT for programming example. */
2250 static VALUE
qemu_open(int argc
, VALUE
*argv
, VALUE klass
)
2253 for (i
= 0; i
< argc
; i
++) {
2254 argv
[i
] = StringValue(argv
[i
]);
2255 fprintf(stderr
, "argv[%d] = %s\n", i
, StringValuePtr(argv
[i
]));
2257 //~ if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
2258 //~ mode = 0666; /* default value */
2260 return INT2FIX(argc
);
2263 void Init_qemu(void)
2265 printf("%s\n", __func__
);
2266 VALUE cQEMU
= rb_define_class("QEMU", rb_cObject
);
2267 rb_define_singleton_method(cQEMU
, "run", qemu_open
, -1);
2272 #endif /* CONFIG_RUBY */
2274 #if defined(CONFIG_DLL)
2275 BOOL APIENTRY
DllMain(HINSTANCE hModule
, DWORD ul_reason_for_call
, LPVOID data
)
2279 #endif /* CONFIG_DLL */
2281 char *qemu_find_file(int type
, const char *name
)
2287 /* Try the name as a straight path first */
2288 if (access(name
, R_OK
) == 0) {
2289 trace_load_file(name
, name
);
2290 return g_strdup(name
);
2294 case QEMU_FILE_TYPE_BIOS
:
2297 case QEMU_FILE_TYPE_KEYMAP
:
2298 subdir
= "keymaps/";
2304 for (i
= 0; i
< data_dir_idx
; i
++) {
2305 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2306 if (access(buf
, R_OK
) == 0) {
2307 trace_load_file(name
, buf
);
2315 static inline bool nonempty_str(const char *str
)
2320 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2324 const char *name
, *file
, *str
;
2326 if (opaque
== NULL
) {
2327 error_report("fw_cfg device not available");
2330 name
= qemu_opt_get(opts
, "name");
2331 file
= qemu_opt_get(opts
, "file");
2332 str
= qemu_opt_get(opts
, "string");
2334 /* we need name and either a file or the content string */
2335 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2336 error_report("invalid argument(s)");
2339 if (nonempty_str(file
) && nonempty_str(str
)) {
2340 error_report("file and string are mutually exclusive");
2343 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2344 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2347 if (strncmp(name
, "opt/", 4) != 0) {
2348 error_report("warning: externally provided fw_cfg item names "
2349 "should be prefixed with \"opt/\"");
2351 if (nonempty_str(str
)) {
2352 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2353 buf
= g_memdup(str
, size
);
2355 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2356 error_report("can't load %s", file
);
2360 fw_cfg_add_file((FWCfgState
*)opaque
, name
, buf
, size
);
2364 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2366 return qdev_device_help(opts
);
2369 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2374 dev
= qdev_device_add(opts
, &err
);
2376 error_report_err(err
);
2379 object_unref(OBJECT(dev
));
2383 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2385 Error
*local_err
= NULL
;
2387 qemu_chr_new_from_opts(opts
, NULL
, &local_err
);
2389 error_report_err(local_err
);
2395 #ifdef CONFIG_VIRTFS
2396 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2399 ret
= qemu_fsdev_add(opts
);
2405 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2407 CharDriverState
*chr
;
2408 const char *chardev
;
2412 mode
= qemu_opt_get(opts
, "mode");
2416 if (strcmp(mode
, "readline") == 0) {
2417 flags
= MONITOR_USE_READLINE
;
2418 } else if (strcmp(mode
, "control") == 0) {
2419 flags
= MONITOR_USE_CONTROL
;
2421 error_report("unknown monitor mode \"%s\"", mode
);
2425 if (qemu_opt_get_bool(opts
, "pretty", 0))
2426 flags
|= MONITOR_USE_PRETTY
;
2428 if (qemu_opt_get_bool(opts
, "default", 0))
2429 flags
|= MONITOR_IS_DEFAULT
;
2431 chardev
= qemu_opt_get(opts
, "chardev");
2432 chr
= qemu_chr_find(chardev
);
2434 error_report("chardev \"%s\" not found", chardev
);
2438 qemu_chr_fe_claim_no_fail(chr
);
2439 monitor_init(chr
, flags
);
2443 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2445 static int monitor_device_index
= 0;
2446 Error
*local_err
= NULL
;
2452 if (strstart(optarg
, "chardev:", &p
)) {
2453 snprintf(label
, sizeof(label
), "%s", p
);
2455 snprintf(label
, sizeof(label
), "compat_monitor%d",
2456 monitor_device_index
);
2457 if (monitor_device_index
== 0) {
2460 opts
= qemu_chr_parse_compat(label
, optarg
);
2462 error_report("parse error: %s", optarg
);
2467 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &local_err
);
2469 error_report_err(local_err
);
2472 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2473 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2474 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2476 qemu_opt_set(opts
, "default", "on", &error_abort
);
2477 monitor_device_index
++;
2480 struct device_config
{
2482 DEV_USB
, /* -usbdevice */
2484 DEV_SERIAL
, /* -serial */
2485 DEV_PARALLEL
, /* -parallel */
2486 DEV_VIRTCON
, /* -virtioconsole */
2487 DEV_DEBUGCON
, /* -debugcon */
2488 DEV_GDB
, /* -gdb, -s */
2489 DEV_SCLP
, /* s390 sclp */
2491 const char *cmdline
;
2493 QTAILQ_ENTRY(device_config
) next
;
2496 static QTAILQ_HEAD(, device_config
) device_configs
=
2497 QTAILQ_HEAD_INITIALIZER(device_configs
);
2499 static void add_device_config(int type
, const char *cmdline
)
2501 struct device_config
*conf
;
2503 conf
= g_malloc0(sizeof(*conf
));
2505 conf
->cmdline
= cmdline
;
2506 loc_save(&conf
->loc
);
2507 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2510 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2512 struct device_config
*conf
;
2515 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2516 if (conf
->type
!= type
)
2518 loc_push_restore(&conf
->loc
);
2519 rc
= func(conf
->cmdline
);
2520 loc_pop(&conf
->loc
);
2528 static int serial_parse(const char *devname
)
2530 static int index
= 0;
2533 if (strcmp(devname
, "none") == 0)
2535 if (index
== MAX_SERIAL_PORTS
) {
2536 error_report("too many serial ports");
2539 snprintf(label
, sizeof(label
), "serial%d", index
);
2540 serial_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2541 if (!serial_hds
[index
]) {
2542 error_report("could not connect serial device"
2543 " to character backend '%s'", devname
);
2550 static int parallel_parse(const char *devname
)
2552 static int index
= 0;
2555 if (strcmp(devname
, "none") == 0)
2557 if (index
== MAX_PARALLEL_PORTS
) {
2558 error_report("too many parallel ports");
2561 snprintf(label
, sizeof(label
), "parallel%d", index
);
2562 parallel_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2563 if (!parallel_hds
[index
]) {
2564 error_report("could not connect parallel device"
2565 " to character backend '%s'", devname
);
2572 static int virtcon_parse(const char *devname
)
2574 QemuOptsList
*device
= qemu_find_opts("device");
2575 static int index
= 0;
2577 QemuOpts
*bus_opts
, *dev_opts
;
2579 if (strcmp(devname
, "none") == 0)
2581 if (index
== MAX_VIRTIO_CONSOLES
) {
2582 error_report("too many virtio consoles");
2586 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2587 if (arch_type
== QEMU_ARCH_S390X
) {
2588 qemu_opt_set(bus_opts
, "driver", "virtio-serial-s390", &error_abort
);
2590 qemu_opt_set(bus_opts
, "driver", "virtio-serial-pci", &error_abort
);
2593 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2594 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2596 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2597 virtcon_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2598 if (!virtcon_hds
[index
]) {
2599 error_report("could not connect virtio console"
2600 " to character backend '%s'", devname
);
2603 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2609 static int sclp_parse(const char *devname
)
2611 QemuOptsList
*device
= qemu_find_opts("device");
2612 static int index
= 0;
2616 if (strcmp(devname
, "none") == 0) {
2619 if (index
== MAX_SCLP_CONSOLES
) {
2620 error_report("too many sclp consoles");
2624 assert(arch_type
== QEMU_ARCH_S390X
);
2626 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2627 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2629 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2630 sclp_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2631 if (!sclp_hds
[index
]) {
2632 error_report("could not connect sclp console"
2633 " to character backend '%s'", devname
);
2636 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2642 static int debugcon_parse(const char *devname
)
2646 if (!qemu_chr_new("debugcon", devname
, NULL
)) {
2649 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2651 error_report("already have a debugcon device");
2654 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2655 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2659 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2661 const MachineClass
*mc1
= a
, *mc2
= b
;
2664 if (mc1
->family
== NULL
) {
2665 if (mc2
->family
== NULL
) {
2666 /* Compare standalone machine types against each other; they sort
2667 * in increasing order.
2669 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2670 object_class_get_name(OBJECT_CLASS(mc2
)));
2673 /* Standalone machine types sort after families. */
2677 if (mc2
->family
== NULL
) {
2678 /* Families sort before standalone machine types. */
2682 /* Families sort between each other alphabetically increasingly. */
2683 res
= strcmp(mc1
->family
, mc2
->family
);
2688 /* Within the same family, machine types sort in decreasing order. */
2689 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2690 object_class_get_name(OBJECT_CLASS(mc1
)));
2693 static MachineClass
*machine_parse(const char *name
)
2695 MachineClass
*mc
= NULL
;
2696 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2699 mc
= find_machine(name
);
2702 g_slist_free(machines
);
2705 if (name
&& !is_help_option(name
)) {
2706 error_report("unsupported machine type");
2707 error_printf("Use -machine help to list supported machines\n");
2709 printf("Supported machines are:\n");
2710 machines
= g_slist_sort(machines
, machine_class_cmp
);
2711 for (el
= machines
; el
; el
= el
->next
) {
2712 MachineClass
*mc
= el
->data
;
2714 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2716 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2717 mc
->is_default
? " (default)" : "");
2721 g_slist_free(machines
);
2722 exit(!name
|| !is_help_option(name
));
2725 void qemu_add_exit_notifier(Notifier
*notify
)
2727 notifier_list_add(&exit_notifiers
, notify
);
2730 void qemu_remove_exit_notifier(Notifier
*notify
)
2732 notifier_remove(notify
);
2735 static void qemu_run_exit_notifiers(void)
2737 notifier_list_notify(&exit_notifiers
, NULL
);
2740 static bool machine_init_done
;
2742 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2744 notifier_list_add(&machine_init_done_notifiers
, notify
);
2745 if (machine_init_done
) {
2746 notify
->notify(notify
, NULL
);
2750 static void qemu_run_machine_init_done_notifiers(void)
2752 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2753 machine_init_done
= true;
2756 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2757 const char **poptarg
, int *poptind
)
2759 const QEMUOption
*popt
;
2760 int optind
= *poptind
;
2761 char *r
= argv
[optind
];
2764 loc_set_cmdline(argv
, optind
, 1);
2766 /* Treat --foo the same as -foo. */
2769 popt
= qemu_options
;
2772 error_report("invalid option");
2775 if (!strcmp(popt
->name
, r
+ 1))
2779 if (popt
->flags
& HAS_ARG
) {
2780 if (optind
>= argc
) {
2781 error_report("requires an argument");
2784 optarg
= argv
[optind
++];
2785 loc_set_cmdline(argv
, optind
- 2, 2);
2796 static int machine_set_property(void *opaque
,
2797 const char *name
, const char *value
,
2800 Object
*obj
= OBJECT(opaque
);
2801 Error
*local_err
= NULL
;
2804 if (strcmp(name
, "type") == 0) {
2808 qom_name
= g_strdup(name
);
2816 object_property_parse(obj
, value
, qom_name
, &local_err
);
2820 error_report_err(local_err
);
2829 * Initial object creation happens before all other
2830 * QEMU data types are created. The majority of objects
2831 * can be created at this point. The rng-egd object
2832 * cannot be created here, as it depends on the chardev
2835 static bool object_create_initial(const char *type
)
2837 if (g_str_equal(type
, "rng-egd")) {
2842 * return false for concrete netfilters since
2843 * they depend on netdevs already existing
2845 if (g_str_equal(type
, "filter-buffer") ||
2846 g_str_equal(type
, "filter-dump")) {
2855 * The remainder of object creation happens after the
2856 * creation of chardev, fsdev, net clients and device data types.
2858 static bool object_create_delayed(const char *type
)
2860 return !object_create_initial(type
);
2864 static int object_create(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2872 bool (*type_predicate
)(const char *) = opaque
;
2874 ov
= opts_visitor_new(opts
);
2875 pdict
= qemu_opts_to_qdict(opts
, NULL
);
2877 visit_start_struct(opts_get_visitor(ov
), &dummy
, NULL
, NULL
, 0, &err
);
2882 qdict_del(pdict
, "qom-type");
2883 visit_type_str(opts_get_visitor(ov
), &type
, "qom-type", &err
);
2887 if (!type_predicate(type
)) {
2891 qdict_del(pdict
, "id");
2892 visit_type_str(opts_get_visitor(ov
), &id
, "id", &err
);
2897 object_add(type
, id
, pdict
, opts_get_visitor(ov
), &err
);
2901 visit_end_struct(opts_get_visitor(ov
), &err
);
2903 qmp_object_del(id
, NULL
);
2907 opts_visitor_cleanup(ov
);
2914 error_report_err(err
);
2920 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2924 const char *mem_str
;
2925 const char *maxmem_str
, *slots_str
;
2926 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2927 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2930 mem_str
= qemu_opt_get(opts
, "size");
2933 error_report("missing 'size' option value");
2937 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2939 /* Fix up legacy suffix-less format */
2940 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2941 uint64_t overflow_check
= sz
;
2944 if ((sz
>> 20) != overflow_check
) {
2945 error_report("too large 'size' option value");
2951 /* backward compatibility behaviour for case "-m 0" */
2953 sz
= default_ram_size
;
2956 sz
= QEMU_ALIGN_UP(sz
, 8192);
2958 if (ram_size
!= sz
) {
2959 error_report("ram size too large");
2963 /* store value for the future use */
2964 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2965 *maxram_size
= ram_size
;
2967 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2968 slots_str
= qemu_opt_get(opts
, "slots");
2969 if (maxmem_str
&& slots_str
) {
2972 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2973 slots
= qemu_opt_get_number(opts
, "slots", 0);
2974 if (sz
< ram_size
) {
2975 error_report("invalid value of -m option maxmem: "
2976 "maximum memory size (0x%" PRIx64
") must be at least "
2977 "the initial memory size (0x" RAM_ADDR_FMT
")",
2980 } else if (sz
> ram_size
) {
2982 error_report("invalid value of -m option: maxmem was "
2983 "specified, but no hotplug slots were specified");
2987 error_report("invalid value of -m option maxmem: "
2988 "memory slots were specified but maximum memory size "
2989 "(0x%" PRIx64
") is equal to the initial memory size "
2990 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2996 } else if ((!maxmem_str
&& slots_str
) ||
2997 (maxmem_str
&& !slots_str
)) {
2998 error_report("invalid -m option value: missing "
2999 "'%s' option", slots_str
? "maxmem" : "slots");
3004 int main(int argc
, char **argv
)
3007 int snapshot
, linux_boot
;
3008 const char *initrd_filename
;
3009 const char *kernel_filename
, *kernel_cmdline
;
3010 const char *boot_order
= NULL
;
3011 const char *boot_once
= NULL
;
3013 int cyls
, heads
, secs
, translation
;
3014 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
3015 QemuOptsList
*olist
;
3018 const char *loadvm
= NULL
;
3019 MachineClass
*machine_class
;
3020 const char *cpu_model
;
3021 const char *vga_model
= NULL
;
3022 const char *qtest_chrdev
= NULL
;
3023 const char *qtest_log
= NULL
;
3024 const char *pid_file
= NULL
;
3025 const char *incoming
= NULL
;
3027 int show_vnc_port
= 0;
3029 bool defconfig
= true;
3030 bool userconfig
= true;
3031 const char *log_mask
= NULL
;
3032 const char *log_file
= NULL
;
3033 const char *trace_events
= NULL
;
3034 const char *trace_file
= NULL
;
3035 ram_addr_t maxram_size
;
3036 uint64_t ram_slots
= 0;
3037 FILE *vmstate_dump_file
= NULL
;
3038 Error
*main_loop_err
= NULL
;
3041 qemu_init_cpu_loop();
3042 qemu_mutex_lock_iothread();
3044 atexit(qemu_run_exit_notifiers
);
3045 error_set_progname(argv
[0]);
3046 qemu_init_exec_dir(argv
[0]);
3048 module_call_init(MODULE_INIT_QOM
);
3050 qemu_add_opts(&qemu_drive_opts
);
3051 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3052 qemu_add_drive_opts(&qemu_common_drive_opts
);
3053 qemu_add_drive_opts(&qemu_drive_opts
);
3054 qemu_add_opts(&qemu_chardev_opts
);
3055 qemu_add_opts(&qemu_device_opts
);
3056 qemu_add_opts(&qemu_netdev_opts
);
3057 qemu_add_opts(&qemu_net_opts
);
3058 qemu_add_opts(&qemu_rtc_opts
);
3059 qemu_add_opts(&qemu_global_opts
);
3060 qemu_add_opts(&qemu_mon_opts
);
3061 qemu_add_opts(&qemu_trace_opts
);
3062 qemu_add_opts(&qemu_option_rom_opts
);
3063 qemu_add_opts(&qemu_machine_opts
);
3064 qemu_add_opts(&qemu_mem_opts
);
3065 qemu_add_opts(&qemu_smp_opts
);
3066 qemu_add_opts(&qemu_boot_opts
);
3067 qemu_add_opts(&qemu_sandbox_opts
);
3068 qemu_add_opts(&qemu_add_fd_opts
);
3069 qemu_add_opts(&qemu_object_opts
);
3070 qemu_add_opts(&qemu_tpmdev_opts
);
3071 qemu_add_opts(&qemu_realtime_opts
);
3072 qemu_add_opts(&qemu_msg_opts
);
3073 qemu_add_opts(&qemu_name_opts
);
3074 qemu_add_opts(&qemu_numa_opts
);
3075 qemu_add_opts(&qemu_icount_opts
);
3076 qemu_add_opts(&qemu_semihosting_config_opts
);
3077 qemu_add_opts(&qemu_fw_cfg_opts
);
3081 if (qcrypto_init(&err
) < 0) {
3082 error_report("cannot initialize crypto: %s", error_get_pretty(err
));
3085 rtc_clock
= QEMU_CLOCK_HOST
;
3087 QLIST_INIT (&vm_change_state_head
);
3088 os_setup_early_signal_handling();
3090 module_call_init(MODULE_INIT_MACHINE
);
3092 optarg
= strrchr(argv
[0], '/');
3094 machine_class
= find_machine(optarg
+ 1);
3096 if (!machine_class
) {
3097 machine_class
= find_default_machine();
3101 cyls
= heads
= secs
= 0;
3102 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3106 bdrv_init_with_whitelist();
3110 /* first pass of option parsing */
3112 while (optind
< argc
) {
3113 if (argv
[optind
][0] != '-') {
3117 const QEMUOption
*popt
;
3119 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3120 switch (popt
->index
) {
3121 case QEMU_OPTION_nodefconfig
:
3124 case QEMU_OPTION_nouserconfig
:
3133 ret
= qemu_read_default_config_files(userconfig
);
3139 /* second pass of option parsing */
3144 if (argv
[optind
][0] != '-') {
3145 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3147 const QEMUOption
*popt
;
3149 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3150 if (!(popt
->arch_mask
& arch_type
)) {
3151 printf("Option %s not supported for this target\n", popt
->name
);
3154 switch(popt
->index
) {
3155 case QEMU_OPTION_no_kvm_irqchip
: {
3156 olist
= qemu_find_opts("machine");
3157 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3160 case QEMU_OPTION_cpu
:
3161 /* hw initialization will check this */
3164 case QEMU_OPTION_hda
:
3168 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3170 snprintf(buf
, sizeof(buf
),
3171 "%s,cyls=%d,heads=%d,secs=%d%s",
3172 HD_OPTS
, cyls
, heads
, secs
,
3173 translation
== BIOS_ATA_TRANSLATION_LBA
?
3175 translation
== BIOS_ATA_TRANSLATION_NONE
?
3176 ",trans=none" : "");
3177 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3180 case QEMU_OPTION_hdb
:
3181 case QEMU_OPTION_hdc
:
3182 case QEMU_OPTION_hdd
:
3183 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3186 case QEMU_OPTION_drive
:
3187 if (drive_def(optarg
) == NULL
) {
3191 case QEMU_OPTION_set
:
3192 if (qemu_set_option(optarg
) != 0)
3195 case QEMU_OPTION_global
:
3196 if (qemu_global_option(optarg
) != 0)
3199 case QEMU_OPTION_mtdblock
:
3200 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3202 case QEMU_OPTION_sd
:
3203 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3205 case QEMU_OPTION_pflash
:
3206 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3208 case QEMU_OPTION_snapshot
:
3211 case QEMU_OPTION_hdachs
:
3215 cyls
= strtol(p
, (char **)&p
, 0);
3216 if (cyls
< 1 || cyls
> 16383)
3221 heads
= strtol(p
, (char **)&p
, 0);
3222 if (heads
< 1 || heads
> 16)
3227 secs
= strtol(p
, (char **)&p
, 0);
3228 if (secs
< 1 || secs
> 63)
3232 if (!strcmp(p
, "large")) {
3233 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3234 } else if (!strcmp(p
, "rechs")) {
3235 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3236 } else if (!strcmp(p
, "none")) {
3237 translation
= BIOS_ATA_TRANSLATION_NONE
;
3238 } else if (!strcmp(p
, "lba")) {
3239 translation
= BIOS_ATA_TRANSLATION_LBA
;
3240 } else if (!strcmp(p
, "auto")) {
3241 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3245 } else if (*p
!= '\0') {
3247 error_report("invalid physical CHS format");
3250 if (hda_opts
!= NULL
) {
3251 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3253 qemu_opt_set_number(hda_opts
, "heads", heads
,
3255 qemu_opt_set_number(hda_opts
, "secs", secs
,
3257 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3258 qemu_opt_set(hda_opts
, "trans", "large",
3260 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3261 qemu_opt_set(hda_opts
, "trans", "rechs",
3263 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3264 qemu_opt_set(hda_opts
, "trans", "lba",
3266 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3267 qemu_opt_set(hda_opts
, "trans", "none",
3273 case QEMU_OPTION_numa
:
3274 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3280 case QEMU_OPTION_display
:
3281 display_type
= select_display(optarg
);
3283 case QEMU_OPTION_nographic
:
3284 display_type
= DT_NOGRAPHIC
;
3286 case QEMU_OPTION_curses
:
3287 #ifdef CONFIG_CURSES
3288 display_type
= DT_CURSES
;
3290 error_report("curses support is disabled");
3294 case QEMU_OPTION_portrait
:
3295 graphic_rotate
= 90;
3297 case QEMU_OPTION_rotate
:
3298 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3299 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3300 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3301 error_report("only 90, 180, 270 deg rotation is available");
3305 case QEMU_OPTION_kernel
:
3306 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3309 case QEMU_OPTION_initrd
:
3310 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3313 case QEMU_OPTION_append
:
3314 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3317 case QEMU_OPTION_dtb
:
3318 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3321 case QEMU_OPTION_cdrom
:
3322 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3324 case QEMU_OPTION_boot
:
3325 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3331 case QEMU_OPTION_fda
:
3332 case QEMU_OPTION_fdb
:
3333 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3336 case QEMU_OPTION_no_fd_bootchk
:
3339 case QEMU_OPTION_netdev
:
3340 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3344 case QEMU_OPTION_net
:
3345 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3349 #ifdef CONFIG_LIBISCSI
3350 case QEMU_OPTION_iscsi
:
3351 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3359 case QEMU_OPTION_tftp
:
3360 legacy_tftp_prefix
= optarg
;
3362 case QEMU_OPTION_bootp
:
3363 legacy_bootp_filename
= optarg
;
3365 case QEMU_OPTION_redir
:
3366 if (net_slirp_redir(optarg
) < 0)
3370 case QEMU_OPTION_bt
:
3371 add_device_config(DEV_BT
, optarg
);
3373 case QEMU_OPTION_audio_help
:
3377 case QEMU_OPTION_soundhw
:
3378 select_soundhw (optarg
);
3383 case QEMU_OPTION_version
:
3388 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3395 case QEMU_OPTION_tpmdev
:
3396 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3401 case QEMU_OPTION_mempath
:
3404 case QEMU_OPTION_mem_prealloc
:
3414 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3416 case QEMU_OPTION_gdb
:
3417 add_device_config(DEV_GDB
, optarg
);
3420 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3421 data_dir
[data_dir_idx
++] = optarg
;
3424 case QEMU_OPTION_bios
:
3425 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3428 case QEMU_OPTION_singlestep
:
3435 keyboard_layout
= optarg
;
3437 case QEMU_OPTION_localtime
:
3440 case QEMU_OPTION_vga
:
3449 w
= strtol(p
, (char **)&p
, 10);
3452 error_report("invalid resolution or depth");
3458 h
= strtol(p
, (char **)&p
, 10);
3463 depth
= strtol(p
, (char **)&p
, 10);
3464 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3465 depth
!= 24 && depth
!= 32)
3467 } else if (*p
== '\0') {
3468 depth
= graphic_depth
;
3475 graphic_depth
= depth
;
3478 case QEMU_OPTION_echr
:
3481 term_escape_char
= strtol(optarg
, &r
, 0);
3483 printf("Bad argument to echr\n");
3486 case QEMU_OPTION_monitor
:
3487 default_monitor
= 0;
3488 if (strncmp(optarg
, "none", 4)) {
3489 monitor_parse(optarg
, "readline", false);
3492 case QEMU_OPTION_qmp
:
3493 monitor_parse(optarg
, "control", false);
3494 default_monitor
= 0;
3496 case QEMU_OPTION_qmp_pretty
:
3497 monitor_parse(optarg
, "control", true);
3498 default_monitor
= 0;
3500 case QEMU_OPTION_mon
:
3501 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3506 default_monitor
= 0;
3508 case QEMU_OPTION_chardev
:
3509 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3515 case QEMU_OPTION_fsdev
:
3516 olist
= qemu_find_opts("fsdev");
3518 error_report("fsdev support is disabled");
3521 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3526 case QEMU_OPTION_virtfs
: {
3529 const char *writeout
, *sock_fd
, *socket
;
3531 olist
= qemu_find_opts("virtfs");
3533 error_report("virtfs support is disabled");
3536 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3541 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3542 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3543 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3546 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3547 qemu_opt_get(opts
, "mount_tag"),
3550 error_report("duplicate fsdev id: %s",
3551 qemu_opt_get(opts
, "mount_tag"));
3555 writeout
= qemu_opt_get(opts
, "writeout");
3557 #ifdef CONFIG_SYNC_FILE_RANGE
3558 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3560 error_report("writeout=immediate not supported "
3561 "on this platform");
3565 qemu_opt_set(fsdev
, "fsdriver",
3566 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3567 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3569 qemu_opt_set(fsdev
, "security_model",
3570 qemu_opt_get(opts
, "security_model"),
3572 socket
= qemu_opt_get(opts
, "socket");
3574 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3576 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3578 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3581 qemu_opt_set_bool(fsdev
, "readonly",
3582 qemu_opt_get_bool(opts
, "readonly", 0),
3584 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3586 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3587 qemu_opt_set(device
, "fsdev",
3588 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3589 qemu_opt_set(device
, "mount_tag",
3590 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3593 case QEMU_OPTION_virtfs_synth
: {
3597 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3600 error_report("duplicate option: %s", "virtfs_synth");
3603 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3605 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3607 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3608 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3609 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3612 case QEMU_OPTION_serial
:
3613 add_device_config(DEV_SERIAL
, optarg
);
3615 if (strncmp(optarg
, "mon:", 4) == 0) {
3616 default_monitor
= 0;
3619 case QEMU_OPTION_watchdog
:
3621 error_report("only one watchdog option may be given");
3626 case QEMU_OPTION_watchdog_action
:
3627 if (select_watchdog_action(optarg
) == -1) {
3628 error_report("unknown -watchdog-action parameter");
3632 case QEMU_OPTION_virtiocon
:
3633 add_device_config(DEV_VIRTCON
, optarg
);
3634 default_virtcon
= 0;
3635 if (strncmp(optarg
, "mon:", 4) == 0) {
3636 default_monitor
= 0;
3639 case QEMU_OPTION_parallel
:
3640 add_device_config(DEV_PARALLEL
, optarg
);
3641 default_parallel
= 0;
3642 if (strncmp(optarg
, "mon:", 4) == 0) {
3643 default_monitor
= 0;
3646 case QEMU_OPTION_debugcon
:
3647 add_device_config(DEV_DEBUGCON
, optarg
);
3649 case QEMU_OPTION_loadvm
:
3652 case QEMU_OPTION_full_screen
:
3655 case QEMU_OPTION_no_frame
:
3658 case QEMU_OPTION_alt_grab
:
3661 case QEMU_OPTION_ctrl_grab
:
3664 case QEMU_OPTION_no_quit
:
3667 case QEMU_OPTION_sdl
:
3669 display_type
= DT_SDL
;
3672 error_report("SDL support is disabled");
3675 case QEMU_OPTION_pidfile
:
3678 case QEMU_OPTION_win2k_hack
:
3679 win2k_install_hack
= 1;
3681 case QEMU_OPTION_rtc_td_hack
: {
3682 static GlobalProperty slew_lost_ticks
[] = {
3684 .driver
= "mc146818rtc",
3685 .property
= "lost_tick_policy",
3688 { /* end of list */ }
3691 qdev_prop_register_global_list(slew_lost_ticks
);
3694 case QEMU_OPTION_acpitable
:
3695 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3700 do_acpitable_option(opts
);
3702 case QEMU_OPTION_smbios
:
3703 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3708 do_smbios_option(opts
);
3710 case QEMU_OPTION_fwcfg
:
3711 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3717 case QEMU_OPTION_enable_kvm
:
3718 olist
= qemu_find_opts("machine");
3719 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3722 case QEMU_OPTION_machine
:
3723 olist
= qemu_find_opts("machine");
3724 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3729 case QEMU_OPTION_no_kvm
:
3730 olist
= qemu_find_opts("machine");
3731 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3733 case QEMU_OPTION_no_kvm_pit
: {
3734 error_report("warning: ignoring deprecated option");
3737 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3738 static GlobalProperty kvm_pit_lost_tick_policy
[] = {
3740 .driver
= "kvm-pit",
3741 .property
= "lost_tick_policy",
3744 { /* end of list */ }
3747 error_report("warning: deprecated, replaced by "
3748 "-global kvm-pit.lost_tick_policy=discard");
3749 qdev_prop_register_global_list(kvm_pit_lost_tick_policy
);
3752 case QEMU_OPTION_usb
:
3753 olist
= qemu_find_opts("machine");
3754 qemu_opts_parse_noisily(olist
, "usb=on", false);
3756 case QEMU_OPTION_usbdevice
:
3757 olist
= qemu_find_opts("machine");
3758 qemu_opts_parse_noisily(olist
, "usb=on", false);
3759 add_device_config(DEV_USB
, optarg
);
3761 case QEMU_OPTION_device
:
3762 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3767 case QEMU_OPTION_smp
:
3768 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3773 case QEMU_OPTION_vnc
:
3776 Error
*local_err
= NULL
;
3778 if (vnc_parse(optarg
, &local_err
) == NULL
) {
3779 error_report_err(local_err
);
3783 error_report("VNC support is disabled");
3788 case QEMU_OPTION_no_acpi
:
3791 case QEMU_OPTION_no_hpet
:
3794 case QEMU_OPTION_balloon
:
3795 if (balloon_parse(optarg
) < 0) {
3796 error_report("unknown -balloon argument %s", optarg
);
3800 case QEMU_OPTION_no_reboot
:
3803 case QEMU_OPTION_no_shutdown
:
3806 case QEMU_OPTION_show_cursor
:
3809 case QEMU_OPTION_uuid
:
3810 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
3811 error_report("failed to parse UUID string: wrong format");
3814 qemu_uuid_set
= true;
3816 case QEMU_OPTION_option_rom
:
3817 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3818 error_report("too many option ROMs");
3821 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3826 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3827 option_rom
[nb_option_roms
].bootindex
=
3828 qemu_opt_get_number(opts
, "bootindex", -1);
3829 if (!option_rom
[nb_option_roms
].name
) {
3830 error_report("Option ROM file is not specified");
3835 case QEMU_OPTION_semihosting
:
3836 semihosting
.enabled
= true;
3837 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3839 case QEMU_OPTION_semihosting_config
:
3840 semihosting
.enabled
= true;
3841 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3844 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3846 const char *target
= qemu_opt_get(opts
, "target");
3847 if (target
!= NULL
) {
3848 if (strcmp("native", target
) == 0) {
3849 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3850 } else if (strcmp("gdb", target
) == 0) {
3851 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3852 } else if (strcmp("auto", target
) == 0) {
3853 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3855 error_report("unsupported semihosting-config %s",
3860 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3862 /* Set semihosting argument count and vector */
3863 qemu_opt_foreach(opts
, add_semihosting_arg
,
3864 &semihosting
, NULL
);
3866 error_report("unsupported semihosting-config %s", optarg
);
3870 case QEMU_OPTION_tdf
:
3871 error_report("warning: ignoring deprecated option");
3873 case QEMU_OPTION_name
:
3874 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3880 case QEMU_OPTION_prom_env
:
3881 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3882 error_report("too many prom variables");
3885 prom_envs
[nb_prom_envs
] = optarg
;
3888 case QEMU_OPTION_old_param
:
3891 case QEMU_OPTION_clock
:
3892 /* Clock options no longer exist. Keep this option for
3893 * backward compatibility.
3896 case QEMU_OPTION_startdate
:
3897 configure_rtc_date_offset(optarg
, 1);
3899 case QEMU_OPTION_rtc
:
3900 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3905 configure_rtc(opts
);
3907 case QEMU_OPTION_tb_size
:
3908 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3909 if (tcg_tb_size
< 0) {
3913 case QEMU_OPTION_icount
:
3914 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3920 case QEMU_OPTION_incoming
:
3922 runstate_set(RUN_STATE_INMIGRATE
);
3926 case QEMU_OPTION_nodefaults
:
3929 case QEMU_OPTION_xen_domid
:
3930 if (!(xen_available())) {
3931 printf("Option %s not supported for this target\n", popt
->name
);
3934 xen_domid
= atoi(optarg
);
3936 case QEMU_OPTION_xen_create
:
3937 if (!(xen_available())) {
3938 printf("Option %s not supported for this target\n", popt
->name
);
3941 xen_mode
= XEN_CREATE
;
3943 case QEMU_OPTION_xen_attach
:
3944 if (!(xen_available())) {
3945 printf("Option %s not supported for this target\n", popt
->name
);
3948 xen_mode
= XEN_ATTACH
;
3950 case QEMU_OPTION_trace
:
3952 opts
= qemu_opts_parse_noisily(qemu_find_opts("trace"),
3957 trace_events
= qemu_opt_get(opts
, "events");
3958 trace_file
= qemu_opt_get(opts
, "file");
3961 case QEMU_OPTION_trace_unassigned
:
3962 trace_unassigned
= true;
3964 case QEMU_OPTION_readconfig
:
3966 int ret
= qemu_read_config_file(optarg
);
3968 error_report("read config %s: %s", optarg
,
3974 case QEMU_OPTION_spice
:
3975 olist
= qemu_find_opts("spice");
3977 error_report("spice support is disabled");
3980 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3986 case QEMU_OPTION_writeconfig
:
3989 if (strcmp(optarg
, "-") == 0) {
3992 fp
= fopen(optarg
, "w");
3994 error_report("open %s: %s", optarg
,
3999 qemu_config_write(fp
);
4005 case QEMU_OPTION_qtest
:
4006 qtest_chrdev
= optarg
;
4008 case QEMU_OPTION_qtest_log
:
4011 case QEMU_OPTION_sandbox
:
4012 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4018 case QEMU_OPTION_add_fd
:
4020 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4026 error_report("File descriptor passing is disabled on this "
4031 case QEMU_OPTION_object
:
4032 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
4038 case QEMU_OPTION_realtime
:
4039 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4044 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4046 case QEMU_OPTION_msg
:
4047 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4052 configure_msg(opts
);
4054 case QEMU_OPTION_dump_vmstate
:
4055 if (vmstate_dump_file
) {
4056 error_report("only one '-dump-vmstate' "
4057 "option may be given");
4060 vmstate_dump_file
= fopen(optarg
, "w");
4061 if (vmstate_dump_file
== NULL
) {
4062 error_report("open %s: %s", optarg
, strerror(errno
));
4067 os_parse_cmd_args(popt
->index
, optarg
);
4072 replay_configure(icount_opts
);
4074 opts
= qemu_get_machine_opts();
4075 optarg
= qemu_opt_get(opts
, "type");
4077 machine_class
= machine_parse(optarg
);
4080 if (machine_class
== NULL
) {
4081 error_report("No machine specified, and there is no default");
4082 error_printf("Use -machine help to list supported machines\n");
4086 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4092 if (qemu_init_main_loop(&main_loop_err
)) {
4093 error_report_err(main_loop_err
);
4097 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4098 parse_sandbox
, NULL
, NULL
)) {
4102 if (qemu_opts_foreach(qemu_find_opts("name"),
4103 parse_name
, NULL
, NULL
)) {
4108 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4109 parse_add_fd
, NULL
, NULL
)) {
4113 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4114 cleanup_add_fd
, NULL
, NULL
)) {
4119 current_machine
= MACHINE(object_new(object_class_get_name(
4120 OBJECT_CLASS(machine_class
))));
4121 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4124 object_property_add_child(object_get_root(), "machine",
4125 OBJECT(current_machine
), &error_abort
);
4126 cpu_exec_init_all();
4128 if (machine_class
->hw_version
) {
4129 qemu_set_hw_version(machine_class
->hw_version
);
4132 /* Init CPU def lists, based on config
4133 * - Must be called after all the qemu_read_config_file() calls
4134 * - Must be called before list_cpus()
4135 * - Must be called before machine->init()
4139 if (cpu_model
&& is_help_option(cpu_model
)) {
4140 list_cpus(stdout
, &fprintf
, cpu_model
);
4144 /* Open the logfile at this point and set the log mask if necessary.
4147 qemu_set_log_filename(log_file
);
4152 mask
= qemu_str_to_log_mask(log_mask
);
4154 qemu_print_log_usage(stdout
);
4160 if (!is_daemonized()) {
4161 if (!trace_init_backends(trace_events
, trace_file
)) {
4166 /* If no data_dir is specified then try to find it relative to the
4168 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4169 data_dir
[data_dir_idx
] = os_find_datadir();
4170 if (data_dir
[data_dir_idx
] != NULL
) {
4174 /* If all else fails use the install path specified when building. */
4175 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4176 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4179 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4181 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4182 if (max_cpus
> machine_class
->max_cpus
) {
4183 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4184 "supported by machine '%s' (%d)", max_cpus
,
4185 machine_class
->name
, machine_class
->max_cpus
);
4190 * Get the default machine options from the machine if it is not already
4191 * specified either by the configuration file or by the command line.
4193 if (machine_class
->default_machine_opts
) {
4194 qemu_opts_set_defaults(qemu_find_opts("machine"),
4195 machine_class
->default_machine_opts
, 0);
4198 qemu_opts_foreach(qemu_find_opts("device"),
4199 default_driver_check
, NULL
, NULL
);
4200 qemu_opts_foreach(qemu_find_opts("global"),
4201 default_driver_check
, NULL
, NULL
);
4203 if (!vga_model
&& !default_vga
) {
4204 vga_interface_type
= VGA_DEVICE
;
4206 if (!has_defaults
|| machine_class
->no_serial
) {
4209 if (!has_defaults
|| machine_class
->no_parallel
) {
4210 default_parallel
= 0;
4212 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4213 default_virtcon
= 0;
4215 if (!has_defaults
|| !machine_class
->use_sclp
) {
4218 if (!has_defaults
|| machine_class
->no_floppy
) {
4221 if (!has_defaults
|| machine_class
->no_cdrom
) {
4224 if (!has_defaults
|| machine_class
->no_sdcard
) {
4227 if (!has_defaults
) {
4228 default_monitor
= 0;
4233 if (is_daemonized()) {
4234 /* According to documentation and historically, -nographic redirects
4235 * serial port, parallel port and monitor to stdio, which does not work
4236 * with -daemonize. We can redirect these to null instead, but since
4237 * -nographic is legacy, let's just error out.
4238 * We disallow -nographic only if all other ports are not redirected
4239 * explicitly, to not break existing legacy setups which uses
4240 * -nographic _and_ redirects all ports explicitly - this is valid
4241 * usage, -nographic is just a no-op in this case.
4243 if (display_type
== DT_NOGRAPHIC
4244 && (default_parallel
|| default_serial
4245 || default_monitor
|| default_virtcon
)) {
4246 error_report("-nographic cannot be used with -daemonize");
4249 #ifdef CONFIG_CURSES
4250 if (display_type
== DT_CURSES
) {
4251 error_report("curses display cannot be used with -daemonize");
4257 if (display_type
== DT_NOGRAPHIC
) {
4258 if (default_parallel
)
4259 add_device_config(DEV_PARALLEL
, "null");
4260 if (default_serial
&& default_monitor
) {
4261 add_device_config(DEV_SERIAL
, "mon:stdio");
4262 } else if (default_virtcon
&& default_monitor
) {
4263 add_device_config(DEV_VIRTCON
, "mon:stdio");
4264 } else if (default_sclp
&& default_monitor
) {
4265 add_device_config(DEV_SCLP
, "mon:stdio");
4268 add_device_config(DEV_SERIAL
, "stdio");
4269 if (default_virtcon
)
4270 add_device_config(DEV_VIRTCON
, "stdio");
4272 add_device_config(DEV_SCLP
, "stdio");
4274 if (default_monitor
)
4275 monitor_parse("stdio", "readline", false);
4279 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4280 if (default_parallel
)
4281 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4282 if (default_monitor
)
4283 monitor_parse("vc:80Cx24C", "readline", false);
4284 if (default_virtcon
)
4285 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4287 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4291 #if defined(CONFIG_VNC)
4292 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4296 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4297 #if defined(CONFIG_GTK)
4298 display_type
= DT_GTK
;
4299 #elif defined(CONFIG_SDL) || defined(CONFIG_COCOA)
4300 display_type
= DT_SDL
;
4301 #elif defined(CONFIG_VNC)
4302 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4305 display_type
= DT_NONE
;
4309 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4310 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4311 "for SDL, ignoring option");
4313 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4314 error_report("-no-quit is only valid for GTK and SDL, "
4318 #if defined(CONFIG_GTK)
4319 if (display_type
== DT_GTK
) {
4320 early_gtk_display_init(request_opengl
);
4323 #if defined(CONFIG_SDL)
4324 if (display_type
== DT_SDL
) {
4325 sdl_display_early_init(request_opengl
);
4328 if (request_opengl
== 1 && display_opengl
== 0) {
4329 #if defined(CONFIG_OPENGL)
4330 error_report("OpenGL is not supported by the display");
4332 error_report("OpenGL support is disabled");
4340 if (qemu_opts_foreach(qemu_find_opts("object"),
4342 object_create_initial
, NULL
)) {
4346 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4347 chardev_init_func
, NULL
, NULL
)) {
4351 #ifdef CONFIG_VIRTFS
4352 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4353 fsdev_init_func
, NULL
, NULL
)) {
4358 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4359 error_report("could not acquire pid file: %s", strerror(errno
));
4363 if (qemu_opts_foreach(qemu_find_opts("device"),
4364 device_help_func
, NULL
, NULL
)) {
4368 machine_opts
= qemu_get_machine_opts();
4369 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4371 object_unref(OBJECT(current_machine
));
4375 configure_accelerator(current_machine
);
4378 Error
*local_err
= NULL
;
4379 qtest_init(qtest_chrdev
, qtest_log
, &local_err
);
4381 error_report_err(local_err
);
4386 machine_opts
= qemu_get_machine_opts();
4387 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4388 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4389 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4390 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4392 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4394 Error
*local_err
= NULL
;
4396 boot_order
= qemu_opt_get(opts
, "order");
4398 validate_bootdevices(boot_order
, &local_err
);
4400 error_report_err(local_err
);
4405 boot_once
= qemu_opt_get(opts
, "once");
4407 validate_bootdevices(boot_once
, &local_err
);
4409 error_report_err(local_err
);
4414 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4415 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4419 boot_order
= machine_class
->default_boot_order
;
4422 if (!kernel_cmdline
) {
4423 kernel_cmdline
= "";
4424 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4427 linux_boot
= (kernel_filename
!= NULL
);
4429 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4430 error_report("-append only allowed with -kernel option");
4434 if (!linux_boot
&& initrd_filename
!= NULL
) {
4435 error_report("-initrd only allowed with -kernel option");
4439 if (!linux_boot
&& qemu_opt_get(machine_opts
, "dtb")) {
4440 error_report("-dtb only allowed with -kernel option");
4444 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4445 /* fall back to the -kernel/-append */
4446 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4449 os_set_line_buffering();
4452 /* spice needs the timers to be initialized by this point */
4458 if (kvm_enabled() || xen_enabled()) {
4459 error_report("-icount is not allowed with kvm or xen");
4462 configure_icount(icount_opts
, &error_abort
);
4463 qemu_opts_del(icount_opts
);
4466 /* clean up network at qemu process termination */
4467 atexit(&net_cleanup
);
4469 if (net_init_clients() < 0) {
4473 if (qemu_opts_foreach(qemu_find_opts("object"),
4475 object_create_delayed
, NULL
)) {
4480 if (tpm_init() < 0) {
4485 /* init the bluetooth world */
4486 if (foreach_device_config(DEV_BT
, bt_parse
))
4489 if (!xen_enabled()) {
4490 /* On 32-bit hosts, QEMU is limited by virtual address space */
4491 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4492 error_report("at most 2047 MB RAM can be simulated");
4500 /* If the currently selected machine wishes to override the units-per-bus
4501 * property of its default HBA interface type, do so now. */
4502 if (machine_class
->units_per_default_bus
) {
4503 override_max_devs(machine_class
->block_default_type
,
4504 machine_class
->units_per_default_bus
);
4507 /* open the virtual block devices */
4508 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4509 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4512 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4513 &machine_class
->block_default_type
, NULL
)) {
4517 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4519 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4520 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4522 parse_numa_opts(machine_class
);
4524 if (qemu_opts_foreach(qemu_find_opts("mon"),
4525 mon_init_func
, NULL
, NULL
)) {
4529 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4531 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4533 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4535 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4538 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4541 /* If no default VGA is requested, the default is "none". */
4543 if (machine_class
->default_display
) {
4544 vga_model
= machine_class
->default_display
;
4545 } else if (cirrus_vga_available()) {
4546 vga_model
= "cirrus";
4547 } else if (vga_available()) {
4552 select_vgahw(vga_model
);
4556 i
= select_watchdog(watchdog
);
4558 exit (i
== 1 ? 1 : 0);
4561 if (machine_class
->compat_props
) {
4562 qdev_prop_register_global_list(machine_class
->compat_props
);
4566 /* This checkpoint is required by replay to separate prior clock
4567 reading from the other reads, because timer polling functions query
4568 clock values from the log. */
4569 replay_checkpoint(CHECKPOINT_INIT
);
4570 qdev_machine_init();
4572 current_machine
->ram_size
= ram_size
;
4573 current_machine
->maxram_size
= maxram_size
;
4574 current_machine
->ram_slots
= ram_slots
;
4575 current_machine
->boot_order
= boot_order
;
4576 current_machine
->cpu_model
= cpu_model
;
4578 machine_class
->init(current_machine
);
4584 cpu_synchronize_all_post_init();
4586 numa_post_machine_init();
4588 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4589 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4593 /* init USB devices */
4594 if (usb_enabled()) {
4595 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4599 /* Check if IGD GFX passthrough. */
4602 /* init generic devices */
4603 if (qemu_opts_foreach(qemu_find_opts("device"),
4604 device_init_func
, NULL
, NULL
)) {
4608 /* Did we create any drives that we failed to create a device for? */
4609 drive_check_orphaned();
4611 net_check_clients();
4614 Error
*local_err
= NULL
;
4615 qemu_boot_set(boot_once
, &local_err
);
4617 error_report("%s", error_get_pretty(local_err
));
4620 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4623 ds
= init_displaystate();
4625 /* init local displays */
4626 switch (display_type
) {
4628 (void)ds
; /* avoid warning if no display is configured */
4630 #if defined(CONFIG_CURSES)
4632 curses_display_init(ds
, full_screen
);
4635 #if defined(CONFIG_SDL)
4637 sdl_display_init(ds
, full_screen
, no_frame
);
4639 #elif defined(CONFIG_COCOA)
4641 cocoa_display_init(ds
, full_screen
);
4644 #if defined(CONFIG_GTK)
4646 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4653 /* must be after terminal init, SDL library changes signal handlers */
4654 os_setup_signal_handling();
4657 /* init remote displays */
4658 qemu_opts_foreach(qemu_find_opts("vnc"),
4659 vnc_init_func
, NULL
, NULL
);
4660 if (show_vnc_port
) {
4661 char *ret
= vnc_display_local_addr("default");
4662 printf("VNC server running on '%s'\n", ret
);
4668 qemu_spice_display_init();
4672 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4676 qdev_machine_creation_done();
4678 /* TODO: once all bus devices are qdevified, this should be done
4679 * when bus is created by qdev.c */
4680 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4681 qemu_run_machine_init_done_notifiers();
4683 if (rom_check_and_register_reset() != 0) {
4684 error_report("rom check and register reset failed");
4690 /* This checkpoint is required by replay to separate prior clock
4691 reading from the other reads, because timer polling functions query
4692 clock values from the log. */
4693 replay_checkpoint(CHECKPOINT_RESET
);
4694 qemu_system_reset(VMRESET_SILENT
);
4695 register_global_state();
4697 if (load_vmstate(loadvm
) < 0) {
4702 qdev_prop_check_globals();
4703 if (vmstate_dump_file
) {
4705 dump_vmstate_json_to_file(vmstate_dump_file
);
4710 Error
*local_err
= NULL
;
4711 qemu_start_incoming_migration(incoming
, &local_err
);
4713 error_report("-incoming %s: %s", incoming
,
4714 error_get_pretty(local_err
));
4715 error_free(local_err
);
4718 } else if (autostart
) {
4724 if (is_daemonized()) {
4725 if (!trace_init_backends(trace_events
, trace_file
)) {
4731 replay_disable_events();