4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "qemu/osdep.h"
25 #include "qemu/cutils.h"
26 #include "qemu/help_option.h"
29 #include "sysemu/seccomp.h"
32 #if defined(CONFIG_VDE)
33 #include <libvdeplug.h>
37 #if defined(__APPLE__) || defined(main)
39 int qemu_main(int argc
, char **argv
, char **envp
);
40 int main(int argc
, char **argv
)
42 return qemu_main(argc
, argv
, NULL
);
45 #define main qemu_main
47 #endif /* CONFIG_SDL */
51 #define main qemu_main
52 #endif /* CONFIG_COCOA */
56 #include "qemu/error-report.h"
57 #include "qemu/sockets.h"
59 #include "hw/boards.h"
60 #include "sysemu/accel.h"
62 #include "hw/i386/pc.h"
63 #include "hw/isa/isa.h"
65 #include "sysemu/watchdog.h"
66 #include "hw/smbios/smbios.h"
67 #include "hw/xen/xen.h"
69 #include "hw/loader.h"
70 #include "monitor/qdev.h"
71 #include "sysemu/bt.h"
73 #include "net/slirp.h"
74 #include "monitor/monitor.h"
75 #include "ui/console.h"
77 #include "sysemu/sysemu.h"
78 #include "sysemu/numa.h"
79 #include "exec/gdbstub.h"
80 #include "qemu/timer.h"
81 #include "sysemu/char.h"
82 #include "qemu/bitmap.h"
83 #include "sysemu/blockdev.h"
84 #include "hw/block/block.h"
85 #include "migration/block.h"
86 #include "sysemu/tpm.h"
87 #include "sysemu/dma.h"
88 #include "audio/audio.h"
89 #include "migration/migration.h"
90 #include "sysemu/cpus.h"
91 #include "sysemu/kvm.h"
92 #include "qapi/qmp/qjson.h"
93 #include "qemu/option.h"
94 #include "qemu/config-file.h"
95 #include "qemu-options.h"
96 #include "qmp-commands.h"
97 #include "qemu/main-loop.h"
99 #include "fsdev/qemu-fsdev.h"
101 #include "sysemu/qtest.h"
103 #include "disas/disas.h"
106 #include "slirp/libslirp.h"
109 #include "trace/control.h"
110 #include "qemu/queue.h"
111 #include "sysemu/cpus.h"
112 #include "sysemu/arch_init.h"
114 #include "ui/qemu-spice.h"
115 #include "qapi/string-input-visitor.h"
116 #include "qapi/opts-visitor.h"
117 #include "qom/object_interfaces.h"
118 #include "qapi-event.h"
119 #include "exec/semihost.h"
120 #include "crypto/init.h"
121 #include "sysemu/replay.h"
122 #include "qapi/qmp/qerror.h"
124 #define MAX_VIRTIO_CONSOLES 1
125 #define MAX_SCLP_CONSOLES 1
127 static const char *data_dir
[16];
128 static int data_dir_idx
;
129 const char *bios_name
= NULL
;
130 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
131 DisplayType display_type
= DT_DEFAULT
;
132 int request_opengl
= -1;
134 static int display_remote
;
135 const char* keyboard_layout
= NULL
;
137 const char *mem_path
= NULL
;
138 int mem_prealloc
= 0; /* force preallocation of physical target memory */
139 bool enable_mlock
= false;
141 NICInfo nd_table
[MAX_NICS
];
143 static int rtc_utc
= 1;
144 static int rtc_date_offset
= -1; /* -1 means no change */
145 QEMUClockType rtc_clock
;
146 int vga_interface_type
= VGA_NONE
;
147 static int full_screen
= 0;
148 static int no_frame
= 0;
151 static bool grab_on_hover
;
153 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
154 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
155 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
156 CharDriverState
*sclp_hds
[MAX_SCLP_CONSOLES
];
157 int win2k_install_hack
= 0;
163 int acpi_enabled
= 1;
166 static int no_reboot
;
169 int graphic_rotate
= 0;
170 const char *watchdog
;
171 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
174 const char *qemu_name
;
177 unsigned int nb_prom_envs
= 0;
178 const char *prom_envs
[MAX_PROM_ENVS
];
181 uint8_t *boot_splash_filedata
;
182 size_t boot_splash_filedata_size
;
183 uint8_t qemu_extra_params_fw
[2];
185 int icount_align_option
;
187 /* The bytes in qemu_uuid[] are in the order specified by RFC4122, _not_ in the
188 * little-endian "wire format" described in the SMBIOS 2.6 specification.
190 uint8_t qemu_uuid
[16];
193 static NotifierList exit_notifiers
=
194 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
196 static NotifierList machine_init_done_notifiers
=
197 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
201 enum xen_mode xen_mode
= XEN_EMULATE
;
203 static int has_defaults
= 1;
204 static int default_serial
= 1;
205 static int default_parallel
= 1;
206 static int default_virtcon
= 1;
207 static int default_sclp
= 1;
208 static int default_monitor
= 1;
209 static int default_floppy
= 1;
210 static int default_cdrom
= 1;
211 static int default_sdcard
= 1;
212 static int default_vga
= 1;
218 { .driver
= "isa-serial", .flag
= &default_serial
},
219 { .driver
= "isa-parallel", .flag
= &default_parallel
},
220 { .driver
= "isa-fdc", .flag
= &default_floppy
},
221 { .driver
= "ide-cd", .flag
= &default_cdrom
},
222 { .driver
= "ide-hd", .flag
= &default_cdrom
},
223 { .driver
= "ide-drive", .flag
= &default_cdrom
},
224 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
225 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
226 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
227 { .driver
= "VGA", .flag
= &default_vga
},
228 { .driver
= "isa-vga", .flag
= &default_vga
},
229 { .driver
= "cirrus-vga", .flag
= &default_vga
},
230 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
231 { .driver
= "vmware-svga", .flag
= &default_vga
},
232 { .driver
= "qxl-vga", .flag
= &default_vga
},
233 { .driver
= "virtio-vga", .flag
= &default_vga
},
236 static QemuOptsList qemu_rtc_opts
= {
238 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
242 .type
= QEMU_OPT_STRING
,
245 .type
= QEMU_OPT_STRING
,
248 .type
= QEMU_OPT_STRING
,
250 { /* end of list */ }
254 static QemuOptsList qemu_sandbox_opts
= {
256 .implied_opt_name
= "enable",
257 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
261 .type
= QEMU_OPT_BOOL
,
263 { /* end of list */ }
267 static QemuOptsList qemu_trace_opts
= {
269 .implied_opt_name
= "enable",
270 .head
= QTAILQ_HEAD_INITIALIZER(qemu_trace_opts
.head
),
274 .type
= QEMU_OPT_STRING
,
278 .type
= QEMU_OPT_STRING
,
281 .type
= QEMU_OPT_STRING
,
283 { /* end of list */ }
287 static QemuOptsList qemu_option_rom_opts
= {
288 .name
= "option-rom",
289 .implied_opt_name
= "romfile",
290 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
294 .type
= QEMU_OPT_NUMBER
,
297 .type
= QEMU_OPT_STRING
,
299 { /* end of list */ }
303 static QemuOptsList qemu_machine_opts
= {
305 .implied_opt_name
= "type",
307 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
310 * no elements => accept any
311 * sanity checking will happen later
312 * when setting machine properties
318 static QemuOptsList qemu_boot_opts
= {
320 .implied_opt_name
= "order",
322 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
326 .type
= QEMU_OPT_STRING
,
329 .type
= QEMU_OPT_STRING
,
332 .type
= QEMU_OPT_BOOL
,
335 .type
= QEMU_OPT_STRING
,
337 .name
= "splash-time",
338 .type
= QEMU_OPT_STRING
,
340 .name
= "reboot-timeout",
341 .type
= QEMU_OPT_STRING
,
344 .type
= QEMU_OPT_BOOL
,
350 static QemuOptsList qemu_add_fd_opts
= {
352 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
356 .type
= QEMU_OPT_NUMBER
,
357 .help
= "file descriptor of which a duplicate is added to fd set",
360 .type
= QEMU_OPT_NUMBER
,
361 .help
= "ID of the fd set to add fd to",
364 .type
= QEMU_OPT_STRING
,
365 .help
= "free-form string used to describe fd",
367 { /* end of list */ }
371 static QemuOptsList qemu_object_opts
= {
373 .implied_opt_name
= "qom-type",
374 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
380 static QemuOptsList qemu_tpmdev_opts
= {
382 .implied_opt_name
= "type",
383 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
385 /* options are defined in the TPM backends */
386 { /* end of list */ }
390 static QemuOptsList qemu_realtime_opts
= {
392 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
396 .type
= QEMU_OPT_BOOL
,
398 { /* end of list */ }
402 static QemuOptsList qemu_msg_opts
= {
404 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
408 .type
= QEMU_OPT_BOOL
,
410 { /* end of list */ }
414 static QemuOptsList qemu_name_opts
= {
416 .implied_opt_name
= "guest",
418 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
422 .type
= QEMU_OPT_STRING
,
423 .help
= "Sets the name of the guest.\n"
424 "This name will be displayed in the SDL window caption.\n"
425 "The name will also be used for the VNC server",
428 .type
= QEMU_OPT_STRING
,
429 .help
= "Sets the name of the QEMU process, as shown in top etc",
431 .name
= "debug-threads",
432 .type
= QEMU_OPT_BOOL
,
433 .help
= "When enabled, name the individual threads; defaults off.\n"
434 "NOTE: The thread names are for debugging and not a\n"
437 { /* End of list */ }
441 static QemuOptsList qemu_mem_opts
= {
443 .implied_opt_name
= "size",
444 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
449 .type
= QEMU_OPT_SIZE
,
453 .type
= QEMU_OPT_NUMBER
,
457 .type
= QEMU_OPT_SIZE
,
459 { /* end of list */ }
463 static QemuOptsList qemu_icount_opts
= {
465 .implied_opt_name
= "shift",
467 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
471 .type
= QEMU_OPT_STRING
,
474 .type
= QEMU_OPT_BOOL
,
477 .type
= QEMU_OPT_BOOL
,
480 .type
= QEMU_OPT_STRING
,
483 .type
= QEMU_OPT_STRING
,
485 { /* end of list */ }
489 static QemuOptsList qemu_semihosting_config_opts
= {
490 .name
= "semihosting-config",
491 .implied_opt_name
= "enable",
492 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
496 .type
= QEMU_OPT_BOOL
,
499 .type
= QEMU_OPT_STRING
,
502 .type
= QEMU_OPT_STRING
,
504 { /* end of list */ }
508 static QemuOptsList qemu_fw_cfg_opts
= {
510 .implied_opt_name
= "name",
511 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
515 .type
= QEMU_OPT_STRING
,
516 .help
= "Sets the fw_cfg name of the blob to be inserted",
519 .type
= QEMU_OPT_STRING
,
520 .help
= "Sets the name of the file from which\n"
521 "the fw_cfg blob will be loaded",
524 .type
= QEMU_OPT_STRING
,
525 .help
= "Sets content of the blob to be inserted from a string",
527 { /* end of list */ }
532 * Get machine options
534 * Returns: machine options (never null).
536 QemuOpts
*qemu_get_machine_opts(void)
538 return qemu_find_opts_singleton("machine");
541 const char *qemu_get_vm_name(void)
546 static void res_free(void)
548 g_free(boot_splash_filedata
);
549 boot_splash_filedata
= NULL
;
552 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
554 const char *driver
= qemu_opt_get(opts
, "driver");
559 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
560 if (strcmp(default_list
[i
].driver
, driver
) != 0)
562 *(default_list
[i
].flag
) = 0;
567 /***********************************************************/
570 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
572 /* We use RUN_STATE__MAX but any invalid value will do */
573 static RunState vmstop_requested
= RUN_STATE__MAX
;
574 static QemuMutex vmstop_lock
;
579 } RunStateTransition
;
581 static const RunStateTransition runstate_transitions_def
[] = {
583 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
584 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
585 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
587 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
588 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
589 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
590 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
591 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
592 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
593 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
594 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
595 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
596 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
597 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
599 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
600 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
601 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
603 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
604 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
605 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
607 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
608 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
609 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
611 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
612 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
613 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
615 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
616 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
617 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
619 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
620 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
621 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
623 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
624 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
626 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
627 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
628 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
629 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
630 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
631 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
632 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
633 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
634 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
635 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
637 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
639 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
640 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
641 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
643 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
644 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
645 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
646 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
647 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
649 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
650 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
651 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
653 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
654 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
655 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
657 { RUN_STATE__MAX
, RUN_STATE__MAX
},
660 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
662 bool runstate_check(RunState state
)
664 return current_run_state
== state
;
667 bool runstate_store(char *str
, size_t size
)
669 const char *state
= RunState_lookup
[current_run_state
];
670 size_t len
= strlen(state
) + 1;
675 memcpy(str
, state
, len
);
679 static void runstate_init(void)
681 const RunStateTransition
*p
;
683 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
684 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
685 runstate_valid_transitions
[p
->from
][p
->to
] = true;
688 qemu_mutex_init(&vmstop_lock
);
691 /* This function will abort() on invalid state transitions */
692 void runstate_set(RunState new_state
)
694 assert(new_state
< RUN_STATE__MAX
);
696 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
697 error_report("invalid runstate transition: '%s' -> '%s'",
698 RunState_lookup
[current_run_state
],
699 RunState_lookup
[new_state
]);
702 trace_runstate_set(new_state
);
703 current_run_state
= new_state
;
706 int runstate_is_running(void)
708 return runstate_check(RUN_STATE_RUNNING
);
711 bool runstate_needs_reset(void)
713 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
714 runstate_check(RUN_STATE_SHUTDOWN
);
717 StatusInfo
*qmp_query_status(Error
**errp
)
719 StatusInfo
*info
= g_malloc0(sizeof(*info
));
721 info
->running
= runstate_is_running();
722 info
->singlestep
= singlestep
;
723 info
->status
= current_run_state
;
728 static bool qemu_vmstop_requested(RunState
*r
)
730 qemu_mutex_lock(&vmstop_lock
);
731 *r
= vmstop_requested
;
732 vmstop_requested
= RUN_STATE__MAX
;
733 qemu_mutex_unlock(&vmstop_lock
);
734 return *r
< RUN_STATE__MAX
;
737 void qemu_system_vmstop_request_prepare(void)
739 qemu_mutex_lock(&vmstop_lock
);
742 void qemu_system_vmstop_request(RunState state
)
744 vmstop_requested
= state
;
745 qemu_mutex_unlock(&vmstop_lock
);
753 qemu_vmstop_requested(&requested
);
754 if (runstate_is_running() && requested
== RUN_STATE__MAX
) {
758 /* Ensure that a STOP/RESUME pair of events is emitted if a
759 * vmstop request was pending. The BLOCK_IO_ERROR event, for
760 * example, according to documentation is always followed by
763 if (runstate_is_running()) {
764 qapi_event_send_stop(&error_abort
);
767 runstate_set(RUN_STATE_RUNNING
);
768 vm_state_notify(1, RUN_STATE_RUNNING
);
772 qapi_event_send_resume(&error_abort
);
776 /***********************************************************/
777 /* real time host monotonic timer */
779 static time_t qemu_time(void)
781 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
784 /***********************************************************/
785 /* host time/date access */
786 void qemu_get_timedate(struct tm
*tm
, int offset
)
788 time_t ti
= qemu_time();
791 if (rtc_date_offset
== -1) {
795 localtime_r(&ti
, tm
);
797 ti
-= rtc_date_offset
;
802 int qemu_timedate_diff(struct tm
*tm
)
806 if (rtc_date_offset
== -1)
808 seconds
= mktimegm(tm
);
811 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
812 seconds
= mktime(&tmp
);
815 seconds
= mktimegm(tm
) + rtc_date_offset
;
817 return seconds
- qemu_time();
820 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
822 time_t rtc_start_date
;
825 if (!strcmp(startdate
, "now") && legacy
) {
826 rtc_date_offset
= -1;
828 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
836 } else if (sscanf(startdate
, "%d-%d-%d",
848 rtc_start_date
= mktimegm(&tm
);
849 if (rtc_start_date
== -1) {
851 error_report("invalid date format");
852 error_printf("valid formats: "
853 "'2006-06-17T16:01:21' or '2006-06-17'\n");
856 rtc_date_offset
= qemu_time() - rtc_start_date
;
860 static void configure_rtc(QemuOpts
*opts
)
864 value
= qemu_opt_get(opts
, "base");
866 if (!strcmp(value
, "utc")) {
868 } else if (!strcmp(value
, "localtime")) {
869 Error
*blocker
= NULL
;
871 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
872 "-rtc base=localtime");
873 replay_add_blocker(blocker
);
875 configure_rtc_date_offset(value
, 0);
878 value
= qemu_opt_get(opts
, "clock");
880 if (!strcmp(value
, "host")) {
881 rtc_clock
= QEMU_CLOCK_HOST
;
882 } else if (!strcmp(value
, "rt")) {
883 rtc_clock
= QEMU_CLOCK_REALTIME
;
884 } else if (!strcmp(value
, "vm")) {
885 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
887 error_report("invalid option value '%s'", value
);
891 value
= qemu_opt_get(opts
, "driftfix");
893 if (!strcmp(value
, "slew")) {
894 static GlobalProperty slew_lost_ticks
[] = {
896 .driver
= "mc146818rtc",
897 .property
= "lost_tick_policy",
900 { /* end of list */ }
903 qdev_prop_register_global_list(slew_lost_ticks
);
904 } else if (!strcmp(value
, "none")) {
905 /* discard is default */
907 error_report("invalid option value '%s'", value
);
913 /***********************************************************/
914 /* Bluetooth support */
917 static struct HCIInfo
*hci_table
[MAX_NICS
];
919 struct HCIInfo
*qemu_next_hci(void)
921 if (cur_hci
== nb_hcis
)
924 return hci_table
[cur_hci
++];
927 static int bt_hci_parse(const char *str
)
932 if (nb_hcis
>= MAX_NICS
) {
933 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
946 bdaddr
.b
[5] = 0x56 + nb_hcis
;
947 hci
->bdaddr_set(hci
, bdaddr
.b
);
949 hci_table
[nb_hcis
++] = hci
;
954 static void bt_vhci_add(int vlan_id
)
956 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
959 error_report("warning: adding a VHCI to an empty scatternet %i",
962 bt_vhci_init(bt_new_hci(vlan
));
965 static struct bt_device_s
*bt_device_add(const char *opt
)
967 struct bt_scatternet_s
*vlan
;
969 char *endp
= strstr(opt
, ",vlan=");
970 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
973 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
976 vlan_id
= strtol(endp
+ 6, &endp
, 0);
978 error_report("unrecognised bluetooth vlan Id");
983 vlan
= qemu_find_bt_vlan(vlan_id
);
986 error_report("warning: adding a slave device to an empty scatternet %i",
989 if (!strcmp(devname
, "keyboard"))
990 return bt_keyboard_init(vlan
);
992 error_report("unsupported bluetooth device '%s'", devname
);
996 static int bt_parse(const char *opt
)
998 const char *endp
, *p
;
1001 if (strstart(opt
, "hci", &endp
)) {
1002 if (!*endp
|| *endp
== ',') {
1004 if (!strstart(endp
, ",vlan=", 0))
1007 return bt_hci_parse(opt
);
1009 } else if (strstart(opt
, "vhci", &endp
)) {
1010 if (!*endp
|| *endp
== ',') {
1012 if (strstart(endp
, ",vlan=", &p
)) {
1013 vlan
= strtol(p
, (char **) &endp
, 0);
1015 error_report("bad scatternet '%s'", p
);
1019 error_report("bad parameter '%s'", endp
+ 1);
1028 } else if (strstart(opt
, "device:", &endp
))
1029 return !bt_device_add(endp
);
1031 error_report("bad bluetooth parameter '%s'", opt
);
1035 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1037 /* FIXME: change this to true for 1.3 */
1038 if (qemu_opt_get_bool(opts
, "enable", false)) {
1039 #ifdef CONFIG_SECCOMP
1040 if (seccomp_start() < 0) {
1041 error_report("failed to install seccomp syscall filter "
1046 error_report("seccomp support is disabled");
1054 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1056 const char *proc_name
;
1058 if (qemu_opt_get(opts
, "debug-threads")) {
1059 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1061 qemu_name
= qemu_opt_get(opts
, "guest");
1063 proc_name
= qemu_opt_get(opts
, "process");
1065 os_set_proc_name(proc_name
);
1071 bool defaults_enabled(void)
1073 return has_defaults
;
1076 bool usb_enabled(void)
1078 return machine_usb(current_machine
);
1082 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1084 int fd
, dupfd
, flags
;
1086 const char *fd_opaque
= NULL
;
1089 fd
= qemu_opt_get_number(opts
, "fd", -1);
1090 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1091 fd_opaque
= qemu_opt_get(opts
, "opaque");
1094 error_report("fd option is required and must be non-negative");
1098 if (fd
<= STDERR_FILENO
) {
1099 error_report("fd cannot be a standard I/O stream");
1104 * All fds inherited across exec() necessarily have FD_CLOEXEC
1105 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1107 flags
= fcntl(fd
, F_GETFD
);
1108 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1109 error_report("fd is not valid or already in use");
1114 error_report("set option is required and must be non-negative");
1118 #ifdef F_DUPFD_CLOEXEC
1119 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1123 qemu_set_cloexec(dupfd
);
1127 error_report("error duplicating fd: %s", strerror(errno
));
1131 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1132 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1139 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1143 fd
= qemu_opt_get_number(opts
, "fd", -1);
1150 /***********************************************************/
1151 /* QEMU Block devices */
1153 #define HD_OPTS "media=disk"
1154 #define CDROM_OPTS "media=cdrom"
1156 #define PFLASH_OPTS ""
1160 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1162 BlockInterfaceType
*block_default_type
= opaque
;
1164 return drive_new(opts
, *block_default_type
) == NULL
;
1167 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1169 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1170 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1175 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1176 int index
, const char *optstr
)
1181 if (!enable
|| drive_get_by_index(type
, index
)) {
1185 opts
= drive_add(type
, index
, NULL
, optstr
);
1187 drive_enable_snapshot(NULL
, opts
, NULL
);
1190 dinfo
= drive_new(opts
, type
);
1194 dinfo
->is_default
= true;
1198 static QemuOptsList qemu_smp_opts
= {
1200 .implied_opt_name
= "cpus",
1201 .merge_lists
= true,
1202 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1206 .type
= QEMU_OPT_NUMBER
,
1209 .type
= QEMU_OPT_NUMBER
,
1212 .type
= QEMU_OPT_NUMBER
,
1215 .type
= QEMU_OPT_NUMBER
,
1218 .type
= QEMU_OPT_NUMBER
,
1220 { /*End of list */ }
1224 static void smp_parse(QemuOpts
*opts
)
1228 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1229 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1230 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1231 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1233 /* compute missing values, prefer sockets over cores over threads */
1234 if (cpus
== 0 || sockets
== 0) {
1235 sockets
= sockets
> 0 ? sockets
: 1;
1236 cores
= cores
> 0 ? cores
: 1;
1237 threads
= threads
> 0 ? threads
: 1;
1239 cpus
= cores
* threads
* sockets
;
1241 } else if (cores
== 0) {
1242 threads
= threads
> 0 ? threads
: 1;
1243 cores
= cpus
/ (sockets
* threads
);
1244 } else if (threads
== 0) {
1245 threads
= cpus
/ (cores
* sockets
);
1246 } else if (sockets
* cores
* threads
< cpus
) {
1247 error_report("cpu topology: "
1248 "sockets (%u) * cores (%u) * threads (%u) < "
1250 sockets
, cores
, threads
, cpus
);
1254 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1255 if (sockets
* cores
* threads
> max_cpus
) {
1256 error_report("cpu topology: "
1257 "sockets (%u) * cores (%u) * threads (%u) > "
1259 sockets
, cores
, threads
, max_cpus
);
1264 smp_cores
= cores
> 0 ? cores
: 1;
1265 smp_threads
= threads
> 0 ? threads
: 1;
1269 if (max_cpus
== 0) {
1270 max_cpus
= smp_cpus
;
1273 if (max_cpus
> MAX_CPUMASK_BITS
) {
1274 error_report("unsupported number of maxcpus");
1277 if (max_cpus
< smp_cpus
) {
1278 error_report("maxcpus must be equal to or greater than smp");
1282 if (smp_cpus
> 1 || smp_cores
> 1 || smp_threads
> 1) {
1283 Error
*blocker
= NULL
;
1284 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1285 replay_add_blocker(blocker
);
1289 static void realtime_init(void)
1292 if (os_mlock() < 0) {
1293 error_report("locking memory failed");
1300 static void configure_msg(QemuOpts
*opts
)
1302 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1305 /***********************************************************/
1308 typedef struct SemihostingConfig
{
1310 SemihostingTarget target
;
1313 const char *cmdline
; /* concatenated argv */
1314 } SemihostingConfig
;
1316 static SemihostingConfig semihosting
;
1318 bool semihosting_enabled(void)
1320 return semihosting
.enabled
;
1323 SemihostingTarget
semihosting_get_target(void)
1325 return semihosting
.target
;
1328 const char *semihosting_get_arg(int i
)
1330 if (i
>= semihosting
.argc
) {
1333 return semihosting
.argv
[i
];
1336 int semihosting_get_argc(void)
1338 return semihosting
.argc
;
1341 const char *semihosting_get_cmdline(void)
1343 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1344 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1346 return semihosting
.cmdline
;
1349 static int add_semihosting_arg(void *opaque
,
1350 const char *name
, const char *val
,
1353 SemihostingConfig
*s
= opaque
;
1354 if (strcmp(name
, "arg") == 0) {
1356 /* one extra element as g_strjoinv() expects NULL-terminated array */
1357 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1358 s
->argv
[s
->argc
- 1] = val
;
1359 s
->argv
[s
->argc
] = NULL
;
1364 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1365 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1370 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1372 /* split -append and initialize argv[1..n] */
1373 cmd_token
= strtok(g_strdup(cmd
), " ");
1375 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1376 cmd_token
= strtok(NULL
, " ");
1380 /* Now we still need this for compatibility with XEN. */
1381 bool has_igd_gfx_passthru
;
1382 static void igd_gfx_passthru(void)
1384 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1387 /***********************************************************/
1390 static int usb_device_add(const char *devname
)
1392 USBDevice
*dev
= NULL
;
1393 #ifndef CONFIG_LINUX
1397 if (!usb_enabled()) {
1401 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1402 dev
= usbdevice_create(devname
);
1406 /* the other ones */
1407 #ifndef CONFIG_LINUX
1408 /* only the linux version is qdev-ified, usb-bsd still needs this */
1409 if (strstart(devname
, "host:", &p
)) {
1410 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1420 static int usb_device_del(const char *devname
)
1425 if (strstart(devname
, "host:", &p
)) {
1429 if (!usb_enabled()) {
1433 p
= strchr(devname
, '.');
1436 bus_num
= strtoul(devname
, NULL
, 0);
1437 addr
= strtoul(p
+ 1, NULL
, 0);
1439 return usb_device_delete_addr(bus_num
, addr
);
1442 static int usb_parse(const char *cmdline
)
1445 r
= usb_device_add(cmdline
);
1447 error_report("could not add USB device '%s'", cmdline
);
1452 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1454 const char *devname
= qdict_get_str(qdict
, "devname");
1455 if (usb_device_add(devname
) < 0) {
1456 error_report("could not add USB device '%s'", devname
);
1460 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1462 const char *devname
= qdict_get_str(qdict
, "devname");
1463 if (usb_device_del(devname
) < 0) {
1464 error_report("could not delete USB device '%s'", devname
);
1468 /***********************************************************/
1469 /* machine registration */
1471 MachineState
*current_machine
;
1473 static MachineClass
*find_machine(const char *name
)
1475 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1476 MachineClass
*mc
= NULL
;
1478 for (el
= machines
; el
; el
= el
->next
) {
1479 MachineClass
*temp
= el
->data
;
1481 if (!strcmp(temp
->name
, name
)) {
1486 !strcmp(temp
->alias
, name
)) {
1492 g_slist_free(machines
);
1496 MachineClass
*find_default_machine(void)
1498 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1499 MachineClass
*mc
= NULL
;
1501 for (el
= machines
; el
; el
= el
->next
) {
1502 MachineClass
*temp
= el
->data
;
1504 if (temp
->is_default
) {
1510 g_slist_free(machines
);
1514 MachineInfoList
*qmp_query_machines(Error
**errp
)
1516 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1517 MachineInfoList
*mach_list
= NULL
;
1519 for (el
= machines
; el
; el
= el
->next
) {
1520 MachineClass
*mc
= el
->data
;
1521 MachineInfoList
*entry
;
1524 info
= g_malloc0(sizeof(*info
));
1525 if (mc
->is_default
) {
1526 info
->has_is_default
= true;
1527 info
->is_default
= true;
1531 info
->has_alias
= true;
1532 info
->alias
= g_strdup(mc
->alias
);
1535 info
->name
= g_strdup(mc
->name
);
1536 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1538 entry
= g_malloc0(sizeof(*entry
));
1539 entry
->value
= info
;
1540 entry
->next
= mach_list
;
1544 g_slist_free(machines
);
1548 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1550 ObjectProperty
*prop
;
1551 ObjectPropertyIterator iter
;
1553 if (!qemu_opt_has_help_opt(opts
)) {
1557 object_property_iter_init(&iter
, OBJECT(machine
));
1558 while ((prop
= object_property_iter_next(&iter
))) {
1563 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1564 prop
->name
, prop
->type
);
1565 if (prop
->description
) {
1566 error_printf(" (%s)\n", prop
->description
);
1575 /***********************************************************/
1576 /* main execution loop */
1578 struct vm_change_state_entry
{
1579 VMChangeStateHandler
*cb
;
1581 QLIST_ENTRY (vm_change_state_entry
) entries
;
1584 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1586 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1589 VMChangeStateEntry
*e
;
1591 e
= g_malloc0(sizeof (*e
));
1595 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1599 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1601 QLIST_REMOVE (e
, entries
);
1605 void vm_state_notify(int running
, RunState state
)
1607 VMChangeStateEntry
*e
, *next
;
1609 trace_vm_state_notify(running
, state
);
1611 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1612 e
->cb(e
->opaque
, running
, state
);
1616 /* reset/shutdown handler */
1618 typedef struct QEMUResetEntry
{
1619 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1620 QEMUResetHandler
*func
;
1624 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1625 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1626 static int reset_requested
;
1627 static int shutdown_requested
, shutdown_signal
= -1;
1628 static pid_t shutdown_pid
;
1629 static int powerdown_requested
;
1630 static int debug_requested
;
1631 static int suspend_requested
;
1632 static WakeupReason wakeup_reason
;
1633 static NotifierList powerdown_notifiers
=
1634 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1635 static NotifierList suspend_notifiers
=
1636 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1637 static NotifierList wakeup_notifiers
=
1638 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1639 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1641 int qemu_shutdown_requested_get(void)
1643 return shutdown_requested
;
1646 int qemu_reset_requested_get(void)
1648 return reset_requested
;
1651 static int qemu_shutdown_requested(void)
1653 return atomic_xchg(&shutdown_requested
, 0);
1656 static void qemu_kill_report(void)
1658 if (!qtest_driver() && shutdown_signal
!= -1) {
1659 if (shutdown_pid
== 0) {
1660 /* This happens for eg ^C at the terminal, so it's worth
1661 * avoiding printing an odd message in that case.
1663 error_report("terminating on signal %d", shutdown_signal
);
1665 error_report("terminating on signal %d from pid " FMT_pid
,
1666 shutdown_signal
, shutdown_pid
);
1668 shutdown_signal
= -1;
1672 static int qemu_reset_requested(void)
1674 int r
= reset_requested
;
1675 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1676 reset_requested
= 0;
1682 static int qemu_suspend_requested(void)
1684 int r
= suspend_requested
;
1685 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1686 suspend_requested
= 0;
1692 static WakeupReason
qemu_wakeup_requested(void)
1694 return wakeup_reason
;
1697 static int qemu_powerdown_requested(void)
1699 int r
= powerdown_requested
;
1700 powerdown_requested
= 0;
1704 static int qemu_debug_requested(void)
1706 int r
= debug_requested
;
1707 debug_requested
= 0;
1711 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1713 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1716 re
->opaque
= opaque
;
1717 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1720 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1724 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1725 if (re
->func
== func
&& re
->opaque
== opaque
) {
1726 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1733 void qemu_devices_reset(void)
1735 QEMUResetEntry
*re
, *nre
;
1737 /* reset all devices */
1738 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1739 re
->func(re
->opaque
);
1743 void qemu_system_reset(bool report
)
1747 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1749 cpu_synchronize_all_states();
1751 if (mc
&& mc
->reset
) {
1754 qemu_devices_reset();
1757 qapi_event_send_reset(&error_abort
);
1759 cpu_synchronize_all_post_reset();
1762 void qemu_system_guest_panicked(void)
1765 current_cpu
->crash_occurred
= true;
1767 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
, &error_abort
);
1768 vm_stop(RUN_STATE_GUEST_PANICKED
);
1771 void qemu_system_reset_request(void)
1774 shutdown_requested
= 1;
1776 reset_requested
= 1;
1779 qemu_notify_event();
1782 static void qemu_system_suspend(void)
1785 notifier_list_notify(&suspend_notifiers
, NULL
);
1786 runstate_set(RUN_STATE_SUSPENDED
);
1787 qapi_event_send_suspend(&error_abort
);
1790 void qemu_system_suspend_request(void)
1792 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1795 suspend_requested
= 1;
1797 qemu_notify_event();
1800 void qemu_register_suspend_notifier(Notifier
*notifier
)
1802 notifier_list_add(&suspend_notifiers
, notifier
);
1805 void qemu_system_wakeup_request(WakeupReason reason
)
1807 trace_system_wakeup_request(reason
);
1809 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1812 if (!(wakeup_reason_mask
& (1 << reason
))) {
1815 runstate_set(RUN_STATE_RUNNING
);
1816 wakeup_reason
= reason
;
1817 qemu_notify_event();
1820 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1823 wakeup_reason_mask
|= (1 << reason
);
1825 wakeup_reason_mask
&= ~(1 << reason
);
1829 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1831 notifier_list_add(&wakeup_notifiers
, notifier
);
1834 void qemu_system_killed(int signal
, pid_t pid
)
1836 shutdown_signal
= signal
;
1840 /* Cannot call qemu_system_shutdown_request directly because
1841 * we are in a signal handler.
1843 shutdown_requested
= 1;
1844 qemu_notify_event();
1847 void qemu_system_shutdown_request(void)
1849 trace_qemu_system_shutdown_request();
1850 replay_shutdown_request();
1851 shutdown_requested
= 1;
1852 qemu_notify_event();
1855 static void qemu_system_powerdown(void)
1857 qapi_event_send_powerdown(&error_abort
);
1858 notifier_list_notify(&powerdown_notifiers
, NULL
);
1861 void qemu_system_powerdown_request(void)
1863 trace_qemu_system_powerdown_request();
1864 powerdown_requested
= 1;
1865 qemu_notify_event();
1868 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1870 notifier_list_add(&powerdown_notifiers
, notifier
);
1873 void qemu_system_debug_request(void)
1875 debug_requested
= 1;
1876 qemu_notify_event();
1879 static bool main_loop_should_exit(void)
1882 if (qemu_debug_requested()) {
1883 vm_stop(RUN_STATE_DEBUG
);
1885 if (qemu_suspend_requested()) {
1886 qemu_system_suspend();
1888 if (qemu_shutdown_requested()) {
1890 qapi_event_send_shutdown(&error_abort
);
1892 vm_stop(RUN_STATE_SHUTDOWN
);
1897 if (qemu_reset_requested()) {
1899 qemu_system_reset(VMRESET_REPORT
);
1901 if (!runstate_check(RUN_STATE_RUNNING
) &&
1902 !runstate_check(RUN_STATE_INMIGRATE
)) {
1903 runstate_set(RUN_STATE_PRELAUNCH
);
1906 if (qemu_wakeup_requested()) {
1908 qemu_system_reset(VMRESET_SILENT
);
1909 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1910 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1912 qapi_event_send_wakeup(&error_abort
);
1914 if (qemu_powerdown_requested()) {
1915 qemu_system_powerdown();
1917 if (qemu_vmstop_requested(&r
)) {
1923 static void main_loop(void)
1927 #ifdef CONFIG_PROFILER
1931 nonblocking
= !kvm_enabled() && !xen_enabled() && last_io
> 0;
1932 #ifdef CONFIG_PROFILER
1933 ti
= profile_getclock();
1935 last_io
= main_loop_wait(nonblocking
);
1936 #ifdef CONFIG_PROFILER
1937 dev_time
+= profile_getclock() - ti
;
1939 } while (!main_loop_should_exit());
1942 static void version(void)
1944 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1947 static void help(int exitcode
)
1950 printf("usage: %s [options] [disk_image]\n\n"
1951 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1952 error_get_progname());
1954 #define QEMU_OPTIONS_GENERATE_HELP
1955 #include "qemu-options-wrapper.h"
1957 printf("\nDuring emulation, the following keys are useful:\n"
1958 "ctrl-alt-f toggle full screen\n"
1959 "ctrl-alt-n switch to virtual console 'n'\n"
1960 "ctrl-alt toggle mouse and keyboard grab\n"
1962 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1967 #define HAS_ARG 0x0001
1969 typedef struct QEMUOption
{
1976 static const QEMUOption qemu_options
[] = {
1977 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1978 #define QEMU_OPTIONS_GENERATE_OPTIONS
1979 #include "qemu-options-wrapper.h"
1983 static bool vga_available(void)
1985 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
1988 static bool cirrus_vga_available(void)
1990 return object_class_by_name("cirrus-vga")
1991 || object_class_by_name("isa-cirrus-vga");
1994 static bool vmware_vga_available(void)
1996 return object_class_by_name("vmware-svga");
1999 static bool qxl_vga_available(void)
2001 return object_class_by_name("qxl-vga");
2004 static bool tcx_vga_available(void)
2006 return object_class_by_name("SUNW,tcx");
2009 static bool cg3_vga_available(void)
2011 return object_class_by_name("cgthree");
2014 static bool virtio_vga_available(void)
2016 return object_class_by_name("virtio-vga");
2019 static void select_vgahw (const char *p
)
2023 assert(vga_interface_type
== VGA_NONE
);
2024 if (strstart(p
, "std", &opts
)) {
2025 if (vga_available()) {
2026 vga_interface_type
= VGA_STD
;
2028 error_report("standard VGA not available");
2031 } else if (strstart(p
, "cirrus", &opts
)) {
2032 if (cirrus_vga_available()) {
2033 vga_interface_type
= VGA_CIRRUS
;
2035 error_report("Cirrus VGA not available");
2038 } else if (strstart(p
, "vmware", &opts
)) {
2039 if (vmware_vga_available()) {
2040 vga_interface_type
= VGA_VMWARE
;
2042 error_report("VMWare SVGA not available");
2045 } else if (strstart(p
, "virtio", &opts
)) {
2046 if (virtio_vga_available()) {
2047 vga_interface_type
= VGA_VIRTIO
;
2049 error_report("Virtio VGA not available");
2052 } else if (strstart(p
, "xenfb", &opts
)) {
2053 vga_interface_type
= VGA_XENFB
;
2054 } else if (strstart(p
, "qxl", &opts
)) {
2055 if (qxl_vga_available()) {
2056 vga_interface_type
= VGA_QXL
;
2058 error_report("QXL VGA not available");
2061 } else if (strstart(p
, "tcx", &opts
)) {
2062 if (tcx_vga_available()) {
2063 vga_interface_type
= VGA_TCX
;
2065 error_report("TCX framebuffer not available");
2068 } else if (strstart(p
, "cg3", &opts
)) {
2069 if (cg3_vga_available()) {
2070 vga_interface_type
= VGA_CG3
;
2072 error_report("CG3 framebuffer not available");
2075 } else if (!strstart(p
, "none", &opts
)) {
2077 error_report("unknown vga type: %s", p
);
2081 const char *nextopt
;
2083 if (strstart(opts
, ",retrace=", &nextopt
)) {
2085 if (strstart(opts
, "dumb", &nextopt
))
2086 vga_retrace_method
= VGA_RETRACE_DUMB
;
2087 else if (strstart(opts
, "precise", &nextopt
))
2088 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2089 else goto invalid_vga
;
2090 } else goto invalid_vga
;
2095 static DisplayType
select_display(const char *p
)
2098 DisplayType display
= DT_DEFAULT
;
2100 if (strstart(p
, "sdl", &opts
)) {
2104 const char *nextopt
;
2106 if (strstart(opts
, ",frame=", &nextopt
)) {
2108 if (strstart(opts
, "on", &nextopt
)) {
2110 } else if (strstart(opts
, "off", &nextopt
)) {
2113 goto invalid_sdl_args
;
2115 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2117 if (strstart(opts
, "on", &nextopt
)) {
2119 } else if (strstart(opts
, "off", &nextopt
)) {
2122 goto invalid_sdl_args
;
2124 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2126 if (strstart(opts
, "on", &nextopt
)) {
2128 } else if (strstart(opts
, "off", &nextopt
)) {
2131 goto invalid_sdl_args
;
2133 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2135 if (strstart(opts
, "on", &nextopt
)) {
2137 } else if (strstart(opts
, "off", &nextopt
)) {
2140 goto invalid_sdl_args
;
2142 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2144 if (strstart(opts
, "on", &nextopt
)) {
2146 } else if (strstart(opts
, "off", &nextopt
)) {
2149 goto invalid_sdl_args
;
2153 error_report("invalid SDL option string");
2159 error_report("SDL support is disabled");
2162 } else if (strstart(p
, "vnc", &opts
)) {
2166 if (vnc_parse(opts
+ 1, &err
) == NULL
) {
2167 error_report_err(err
);
2171 error_report("VNC requires a display argument vnc=<display>");
2175 error_report("VNC support is disabled");
2178 } else if (strstart(p
, "curses", &opts
)) {
2179 #ifdef CONFIG_CURSES
2180 display
= DT_CURSES
;
2182 error_report("curses support is disabled");
2185 } else if (strstart(p
, "gtk", &opts
)) {
2189 const char *nextopt
;
2191 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2193 if (strstart(opts
, "on", &nextopt
)) {
2194 grab_on_hover
= true;
2195 } else if (strstart(opts
, "off", &nextopt
)) {
2196 grab_on_hover
= false;
2198 goto invalid_gtk_args
;
2200 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2202 if (strstart(opts
, "on", &nextopt
)) {
2204 } else if (strstart(opts
, "off", &nextopt
)) {
2207 goto invalid_gtk_args
;
2211 error_report("invalid GTK option string");
2217 error_report("GTK support is disabled");
2220 } else if (strstart(p
, "none", &opts
)) {
2223 error_report("unknown display type");
2230 static int balloon_parse(const char *arg
)
2234 if (strcmp(arg
, "none") == 0) {
2238 if (!strncmp(arg
, "virtio", 6)) {
2239 if (arg
[6] == ',') {
2240 /* have params -> parse them */
2241 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2246 /* create empty opts */
2247 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2250 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2257 char *qemu_find_file(int type
, const char *name
)
2263 /* Try the name as a straight path first */
2264 if (access(name
, R_OK
) == 0) {
2265 trace_load_file(name
, name
);
2266 return g_strdup(name
);
2270 case QEMU_FILE_TYPE_BIOS
:
2273 case QEMU_FILE_TYPE_KEYMAP
:
2274 subdir
= "keymaps/";
2280 for (i
= 0; i
< data_dir_idx
; i
++) {
2281 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2282 if (access(buf
, R_OK
) == 0) {
2283 trace_load_file(name
, buf
);
2291 static inline bool nonempty_str(const char *str
)
2296 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2300 const char *name
, *file
, *str
;
2301 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2303 if (fw_cfg
== NULL
) {
2304 error_report("fw_cfg device not available");
2307 name
= qemu_opt_get(opts
, "name");
2308 file
= qemu_opt_get(opts
, "file");
2309 str
= qemu_opt_get(opts
, "string");
2311 /* we need name and either a file or the content string */
2312 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2313 error_report("invalid argument(s)");
2316 if (nonempty_str(file
) && nonempty_str(str
)) {
2317 error_report("file and string are mutually exclusive");
2320 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2321 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2324 if (strncmp(name
, "opt/", 4) != 0) {
2325 error_report("warning: externally provided fw_cfg item names "
2326 "should be prefixed with \"opt/\"");
2328 if (nonempty_str(str
)) {
2329 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2330 buf
= g_memdup(str
, size
);
2332 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2333 error_report("can't load %s", file
);
2337 /* For legacy, keep user files in a specific global order. */
2338 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2339 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2340 fw_cfg_reset_order_override(fw_cfg
);
2344 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2346 return qdev_device_help(opts
);
2349 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2354 dev
= qdev_device_add(opts
, &err
);
2356 error_report_err(err
);
2359 object_unref(OBJECT(dev
));
2363 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2365 Error
*local_err
= NULL
;
2367 qemu_chr_new_from_opts(opts
, NULL
, &local_err
);
2369 error_report_err(local_err
);
2375 #ifdef CONFIG_VIRTFS
2376 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2379 ret
= qemu_fsdev_add(opts
);
2385 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2387 CharDriverState
*chr
;
2388 const char *chardev
;
2392 mode
= qemu_opt_get(opts
, "mode");
2396 if (strcmp(mode
, "readline") == 0) {
2397 flags
= MONITOR_USE_READLINE
;
2398 } else if (strcmp(mode
, "control") == 0) {
2399 flags
= MONITOR_USE_CONTROL
;
2401 error_report("unknown monitor mode \"%s\"", mode
);
2405 if (qemu_opt_get_bool(opts
, "pretty", 0))
2406 flags
|= MONITOR_USE_PRETTY
;
2408 if (qemu_opt_get_bool(opts
, "default", 0))
2409 flags
|= MONITOR_IS_DEFAULT
;
2411 chardev
= qemu_opt_get(opts
, "chardev");
2412 chr
= qemu_chr_find(chardev
);
2414 error_report("chardev \"%s\" not found", chardev
);
2418 qemu_chr_fe_claim_no_fail(chr
);
2419 monitor_init(chr
, flags
);
2423 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2425 static int monitor_device_index
= 0;
2426 Error
*local_err
= NULL
;
2432 if (strstart(optarg
, "chardev:", &p
)) {
2433 snprintf(label
, sizeof(label
), "%s", p
);
2435 snprintf(label
, sizeof(label
), "compat_monitor%d",
2436 monitor_device_index
);
2437 if (monitor_device_index
== 0) {
2440 opts
= qemu_chr_parse_compat(label
, optarg
);
2442 error_report("parse error: %s", optarg
);
2447 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &local_err
);
2449 error_report_err(local_err
);
2452 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2453 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2454 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2456 qemu_opt_set(opts
, "default", "on", &error_abort
);
2457 monitor_device_index
++;
2460 struct device_config
{
2462 DEV_USB
, /* -usbdevice */
2464 DEV_SERIAL
, /* -serial */
2465 DEV_PARALLEL
, /* -parallel */
2466 DEV_VIRTCON
, /* -virtioconsole */
2467 DEV_DEBUGCON
, /* -debugcon */
2468 DEV_GDB
, /* -gdb, -s */
2469 DEV_SCLP
, /* s390 sclp */
2471 const char *cmdline
;
2473 QTAILQ_ENTRY(device_config
) next
;
2476 static QTAILQ_HEAD(, device_config
) device_configs
=
2477 QTAILQ_HEAD_INITIALIZER(device_configs
);
2479 static void add_device_config(int type
, const char *cmdline
)
2481 struct device_config
*conf
;
2483 conf
= g_malloc0(sizeof(*conf
));
2485 conf
->cmdline
= cmdline
;
2486 loc_save(&conf
->loc
);
2487 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2490 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2492 struct device_config
*conf
;
2495 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2496 if (conf
->type
!= type
)
2498 loc_push_restore(&conf
->loc
);
2499 rc
= func(conf
->cmdline
);
2500 loc_pop(&conf
->loc
);
2508 static int serial_parse(const char *devname
)
2510 static int index
= 0;
2513 if (strcmp(devname
, "none") == 0)
2515 if (index
== MAX_SERIAL_PORTS
) {
2516 error_report("too many serial ports");
2519 snprintf(label
, sizeof(label
), "serial%d", index
);
2520 serial_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2521 if (!serial_hds
[index
]) {
2522 error_report("could not connect serial device"
2523 " to character backend '%s'", devname
);
2530 static int parallel_parse(const char *devname
)
2532 static int index
= 0;
2535 if (strcmp(devname
, "none") == 0)
2537 if (index
== MAX_PARALLEL_PORTS
) {
2538 error_report("too many parallel ports");
2541 snprintf(label
, sizeof(label
), "parallel%d", index
);
2542 parallel_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2543 if (!parallel_hds
[index
]) {
2544 error_report("could not connect parallel device"
2545 " to character backend '%s'", devname
);
2552 static int virtcon_parse(const char *devname
)
2554 QemuOptsList
*device
= qemu_find_opts("device");
2555 static int index
= 0;
2557 QemuOpts
*bus_opts
, *dev_opts
;
2559 if (strcmp(devname
, "none") == 0)
2561 if (index
== MAX_VIRTIO_CONSOLES
) {
2562 error_report("too many virtio consoles");
2566 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2567 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2569 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2570 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2572 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2573 virtcon_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2574 if (!virtcon_hds
[index
]) {
2575 error_report("could not connect virtio console"
2576 " to character backend '%s'", devname
);
2579 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2585 static int sclp_parse(const char *devname
)
2587 QemuOptsList
*device
= qemu_find_opts("device");
2588 static int index
= 0;
2592 if (strcmp(devname
, "none") == 0) {
2595 if (index
== MAX_SCLP_CONSOLES
) {
2596 error_report("too many sclp consoles");
2600 assert(arch_type
== QEMU_ARCH_S390X
);
2602 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2603 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2605 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2606 sclp_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2607 if (!sclp_hds
[index
]) {
2608 error_report("could not connect sclp console"
2609 " to character backend '%s'", devname
);
2612 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2618 static int debugcon_parse(const char *devname
)
2622 if (!qemu_chr_new("debugcon", devname
, NULL
)) {
2625 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2627 error_report("already have a debugcon device");
2630 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2631 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2635 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2637 const MachineClass
*mc1
= a
, *mc2
= b
;
2640 if (mc1
->family
== NULL
) {
2641 if (mc2
->family
== NULL
) {
2642 /* Compare standalone machine types against each other; they sort
2643 * in increasing order.
2645 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2646 object_class_get_name(OBJECT_CLASS(mc2
)));
2649 /* Standalone machine types sort after families. */
2653 if (mc2
->family
== NULL
) {
2654 /* Families sort before standalone machine types. */
2658 /* Families sort between each other alphabetically increasingly. */
2659 res
= strcmp(mc1
->family
, mc2
->family
);
2664 /* Within the same family, machine types sort in decreasing order. */
2665 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2666 object_class_get_name(OBJECT_CLASS(mc1
)));
2669 static MachineClass
*machine_parse(const char *name
)
2671 MachineClass
*mc
= NULL
;
2672 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2675 mc
= find_machine(name
);
2678 g_slist_free(machines
);
2681 if (name
&& !is_help_option(name
)) {
2682 error_report("unsupported machine type");
2683 error_printf("Use -machine help to list supported machines\n");
2685 printf("Supported machines are:\n");
2686 machines
= g_slist_sort(machines
, machine_class_cmp
);
2687 for (el
= machines
; el
; el
= el
->next
) {
2688 MachineClass
*mc
= el
->data
;
2690 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2692 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2693 mc
->is_default
? " (default)" : "");
2697 g_slist_free(machines
);
2698 exit(!name
|| !is_help_option(name
));
2701 void qemu_add_exit_notifier(Notifier
*notify
)
2703 notifier_list_add(&exit_notifiers
, notify
);
2706 void qemu_remove_exit_notifier(Notifier
*notify
)
2708 notifier_remove(notify
);
2711 static void qemu_run_exit_notifiers(void)
2713 notifier_list_notify(&exit_notifiers
, NULL
);
2716 static bool machine_init_done
;
2718 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2720 notifier_list_add(&machine_init_done_notifiers
, notify
);
2721 if (machine_init_done
) {
2722 notify
->notify(notify
, NULL
);
2726 static void qemu_run_machine_init_done_notifiers(void)
2728 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2729 machine_init_done
= true;
2732 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2733 const char **poptarg
, int *poptind
)
2735 const QEMUOption
*popt
;
2736 int optind
= *poptind
;
2737 char *r
= argv
[optind
];
2740 loc_set_cmdline(argv
, optind
, 1);
2742 /* Treat --foo the same as -foo. */
2745 popt
= qemu_options
;
2748 error_report("invalid option");
2751 if (!strcmp(popt
->name
, r
+ 1))
2755 if (popt
->flags
& HAS_ARG
) {
2756 if (optind
>= argc
) {
2757 error_report("requires an argument");
2760 optarg
= argv
[optind
++];
2761 loc_set_cmdline(argv
, optind
- 2, 2);
2772 static MachineClass
*select_machine(void)
2774 MachineClass
*machine_class
= find_default_machine();
2779 loc_push_none(&loc
);
2781 opts
= qemu_get_machine_opts();
2782 qemu_opts_loc_restore(opts
);
2784 optarg
= qemu_opt_get(opts
, "type");
2786 machine_class
= machine_parse(optarg
);
2789 if (!machine_class
) {
2790 error_report("No machine specified, and there is no default");
2791 error_printf("Use -machine help to list supported machines\n");
2796 return machine_class
;
2799 static int machine_set_property(void *opaque
,
2800 const char *name
, const char *value
,
2803 Object
*obj
= OBJECT(opaque
);
2804 Error
*local_err
= NULL
;
2807 if (strcmp(name
, "type") == 0) {
2811 qom_name
= g_strdup(name
);
2819 object_property_parse(obj
, value
, qom_name
, &local_err
);
2823 error_report_err(local_err
);
2832 * Initial object creation happens before all other
2833 * QEMU data types are created. The majority of objects
2834 * can be created at this point. The rng-egd object
2835 * cannot be created here, as it depends on the chardev
2838 static bool object_create_initial(const char *type
)
2840 if (g_str_equal(type
, "rng-egd")) {
2845 * return false for concrete netfilters since
2846 * they depend on netdevs already existing
2848 if (g_str_equal(type
, "filter-buffer") ||
2849 g_str_equal(type
, "filter-dump") ||
2850 g_str_equal(type
, "filter-mirror") ||
2851 g_str_equal(type
, "filter-redirector")) {
2860 * The remainder of object creation happens after the
2861 * creation of chardev, fsdev, net clients and device data types.
2863 static bool object_create_delayed(const char *type
)
2865 return !object_create_initial(type
);
2869 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2873 const char *mem_str
;
2874 const char *maxmem_str
, *slots_str
;
2875 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2876 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2879 loc_push_none(&loc
);
2880 qemu_opts_loc_restore(opts
);
2883 mem_str
= qemu_opt_get(opts
, "size");
2886 error_report("missing 'size' option value");
2890 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2892 /* Fix up legacy suffix-less format */
2893 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2894 uint64_t overflow_check
= sz
;
2897 if ((sz
>> 20) != overflow_check
) {
2898 error_report("too large 'size' option value");
2904 /* backward compatibility behaviour for case "-m 0" */
2906 sz
= default_ram_size
;
2909 sz
= QEMU_ALIGN_UP(sz
, 8192);
2911 if (ram_size
!= sz
) {
2912 error_report("ram size too large");
2916 /* store value for the future use */
2917 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2918 *maxram_size
= ram_size
;
2920 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2921 slots_str
= qemu_opt_get(opts
, "slots");
2922 if (maxmem_str
&& slots_str
) {
2925 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2926 slots
= qemu_opt_get_number(opts
, "slots", 0);
2927 if (sz
< ram_size
) {
2928 error_report("invalid value of -m option maxmem: "
2929 "maximum memory size (0x%" PRIx64
") must be at least "
2930 "the initial memory size (0x" RAM_ADDR_FMT
")",
2933 } else if (sz
> ram_size
) {
2935 error_report("invalid value of -m option: maxmem was "
2936 "specified, but no hotplug slots were specified");
2940 error_report("invalid value of -m option maxmem: "
2941 "memory slots were specified but maximum memory size "
2942 "(0x%" PRIx64
") is equal to the initial memory size "
2943 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2949 } else if ((!maxmem_str
&& slots_str
) ||
2950 (maxmem_str
&& !slots_str
)) {
2951 error_report("invalid -m option value: missing "
2952 "'%s' option", slots_str
? "maxmem" : "slots");
2959 int main(int argc
, char **argv
, char **envp
)
2962 int snapshot
, linux_boot
;
2963 const char *initrd_filename
;
2964 const char *kernel_filename
, *kernel_cmdline
;
2965 const char *boot_order
= NULL
;
2966 const char *boot_once
= NULL
;
2968 int cyls
, heads
, secs
, translation
;
2969 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
2970 QemuOptsList
*olist
;
2973 const char *loadvm
= NULL
;
2974 MachineClass
*machine_class
;
2975 const char *cpu_model
;
2976 const char *vga_model
= NULL
;
2977 const char *qtest_chrdev
= NULL
;
2978 const char *qtest_log
= NULL
;
2979 const char *pid_file
= NULL
;
2980 const char *incoming
= NULL
;
2982 int show_vnc_port
= 0;
2984 bool defconfig
= true;
2985 bool userconfig
= true;
2986 const char *log_mask
= NULL
;
2987 const char *log_file
= NULL
;
2988 char *trace_file
= NULL
;
2989 ram_addr_t maxram_size
;
2990 uint64_t ram_slots
= 0;
2991 FILE *vmstate_dump_file
= NULL
;
2992 Error
*main_loop_err
= NULL
;
2995 qemu_init_cpu_loop();
2996 qemu_mutex_lock_iothread();
2998 atexit(qemu_run_exit_notifiers
);
2999 error_set_progname(argv
[0]);
3000 qemu_init_exec_dir(argv
[0]);
3002 module_call_init(MODULE_INIT_QOM
);
3004 qemu_add_opts(&qemu_drive_opts
);
3005 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3006 qemu_add_drive_opts(&qemu_common_drive_opts
);
3007 qemu_add_drive_opts(&qemu_drive_opts
);
3008 qemu_add_opts(&qemu_chardev_opts
);
3009 qemu_add_opts(&qemu_device_opts
);
3010 qemu_add_opts(&qemu_netdev_opts
);
3011 qemu_add_opts(&qemu_net_opts
);
3012 qemu_add_opts(&qemu_rtc_opts
);
3013 qemu_add_opts(&qemu_global_opts
);
3014 qemu_add_opts(&qemu_mon_opts
);
3015 qemu_add_opts(&qemu_trace_opts
);
3016 qemu_add_opts(&qemu_option_rom_opts
);
3017 qemu_add_opts(&qemu_machine_opts
);
3018 qemu_add_opts(&qemu_mem_opts
);
3019 qemu_add_opts(&qemu_smp_opts
);
3020 qemu_add_opts(&qemu_boot_opts
);
3021 qemu_add_opts(&qemu_sandbox_opts
);
3022 qemu_add_opts(&qemu_add_fd_opts
);
3023 qemu_add_opts(&qemu_object_opts
);
3024 qemu_add_opts(&qemu_tpmdev_opts
);
3025 qemu_add_opts(&qemu_realtime_opts
);
3026 qemu_add_opts(&qemu_msg_opts
);
3027 qemu_add_opts(&qemu_name_opts
);
3028 qemu_add_opts(&qemu_numa_opts
);
3029 qemu_add_opts(&qemu_icount_opts
);
3030 qemu_add_opts(&qemu_semihosting_config_opts
);
3031 qemu_add_opts(&qemu_fw_cfg_opts
);
3032 module_call_init(MODULE_INIT_OPTS
);
3036 if (qcrypto_init(&err
) < 0) {
3037 error_reportf_err(err
, "cannot initialize crypto: ");
3040 rtc_clock
= QEMU_CLOCK_HOST
;
3042 QLIST_INIT (&vm_change_state_head
);
3043 os_setup_early_signal_handling();
3047 cyls
= heads
= secs
= 0;
3048 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3052 bdrv_init_with_whitelist();
3056 /* first pass of option parsing */
3058 while (optind
< argc
) {
3059 if (argv
[optind
][0] != '-') {
3063 const QEMUOption
*popt
;
3065 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3066 switch (popt
->index
) {
3067 case QEMU_OPTION_nodefconfig
:
3070 case QEMU_OPTION_nouserconfig
:
3079 ret
= qemu_read_default_config_files(userconfig
);
3085 /* second pass of option parsing */
3090 if (argv
[optind
][0] != '-') {
3091 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3093 const QEMUOption
*popt
;
3095 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3096 if (!(popt
->arch_mask
& arch_type
)) {
3097 printf("Option %s not supported for this target\n", popt
->name
);
3100 switch(popt
->index
) {
3101 case QEMU_OPTION_no_kvm_irqchip
: {
3102 olist
= qemu_find_opts("machine");
3103 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3106 case QEMU_OPTION_cpu
:
3107 /* hw initialization will check this */
3110 case QEMU_OPTION_hda
:
3114 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3116 snprintf(buf
, sizeof(buf
),
3117 "%s,cyls=%d,heads=%d,secs=%d%s",
3118 HD_OPTS
, cyls
, heads
, secs
,
3119 translation
== BIOS_ATA_TRANSLATION_LBA
?
3121 translation
== BIOS_ATA_TRANSLATION_NONE
?
3122 ",trans=none" : "");
3123 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3126 case QEMU_OPTION_hdb
:
3127 case QEMU_OPTION_hdc
:
3128 case QEMU_OPTION_hdd
:
3129 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3132 case QEMU_OPTION_drive
:
3133 if (drive_def(optarg
) == NULL
) {
3137 case QEMU_OPTION_set
:
3138 if (qemu_set_option(optarg
) != 0)
3141 case QEMU_OPTION_global
:
3142 if (qemu_global_option(optarg
) != 0)
3145 case QEMU_OPTION_mtdblock
:
3146 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3148 case QEMU_OPTION_sd
:
3149 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3151 case QEMU_OPTION_pflash
:
3152 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3154 case QEMU_OPTION_snapshot
:
3157 case QEMU_OPTION_hdachs
:
3161 cyls
= strtol(p
, (char **)&p
, 0);
3162 if (cyls
< 1 || cyls
> 16383)
3167 heads
= strtol(p
, (char **)&p
, 0);
3168 if (heads
< 1 || heads
> 16)
3173 secs
= strtol(p
, (char **)&p
, 0);
3174 if (secs
< 1 || secs
> 63)
3178 if (!strcmp(p
, "large")) {
3179 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3180 } else if (!strcmp(p
, "rechs")) {
3181 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3182 } else if (!strcmp(p
, "none")) {
3183 translation
= BIOS_ATA_TRANSLATION_NONE
;
3184 } else if (!strcmp(p
, "lba")) {
3185 translation
= BIOS_ATA_TRANSLATION_LBA
;
3186 } else if (!strcmp(p
, "auto")) {
3187 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3191 } else if (*p
!= '\0') {
3193 error_report("invalid physical CHS format");
3196 if (hda_opts
!= NULL
) {
3197 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3199 qemu_opt_set_number(hda_opts
, "heads", heads
,
3201 qemu_opt_set_number(hda_opts
, "secs", secs
,
3203 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3204 qemu_opt_set(hda_opts
, "trans", "large",
3206 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3207 qemu_opt_set(hda_opts
, "trans", "rechs",
3209 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3210 qemu_opt_set(hda_opts
, "trans", "lba",
3212 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3213 qemu_opt_set(hda_opts
, "trans", "none",
3219 case QEMU_OPTION_numa
:
3220 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3226 case QEMU_OPTION_display
:
3227 display_type
= select_display(optarg
);
3229 case QEMU_OPTION_nographic
:
3230 display_type
= DT_NOGRAPHIC
;
3232 case QEMU_OPTION_curses
:
3233 #ifdef CONFIG_CURSES
3234 display_type
= DT_CURSES
;
3236 error_report("curses support is disabled");
3240 case QEMU_OPTION_portrait
:
3241 graphic_rotate
= 90;
3243 case QEMU_OPTION_rotate
:
3244 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3245 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3246 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3247 error_report("only 90, 180, 270 deg rotation is available");
3251 case QEMU_OPTION_kernel
:
3252 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3255 case QEMU_OPTION_initrd
:
3256 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3259 case QEMU_OPTION_append
:
3260 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3263 case QEMU_OPTION_dtb
:
3264 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3267 case QEMU_OPTION_cdrom
:
3268 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3270 case QEMU_OPTION_boot
:
3271 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3277 case QEMU_OPTION_fda
:
3278 case QEMU_OPTION_fdb
:
3279 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3282 case QEMU_OPTION_no_fd_bootchk
:
3285 case QEMU_OPTION_netdev
:
3286 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3290 case QEMU_OPTION_net
:
3291 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3295 #ifdef CONFIG_LIBISCSI
3296 case QEMU_OPTION_iscsi
:
3297 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3305 case QEMU_OPTION_tftp
:
3306 error_report("The -tftp option is deprecated. "
3307 "Please use '-netdev user,tftp=...' instead.");
3308 legacy_tftp_prefix
= optarg
;
3310 case QEMU_OPTION_bootp
:
3311 error_report("The -bootp option is deprecated. "
3312 "Please use '-netdev user,bootfile=...' instead.");
3313 legacy_bootp_filename
= optarg
;
3315 case QEMU_OPTION_redir
:
3316 error_report("The -redir option is deprecated. "
3317 "Please use '-netdev user,hostfwd=...' instead.");
3318 if (net_slirp_redir(optarg
) < 0)
3322 case QEMU_OPTION_bt
:
3323 add_device_config(DEV_BT
, optarg
);
3325 case QEMU_OPTION_audio_help
:
3329 case QEMU_OPTION_soundhw
:
3330 select_soundhw (optarg
);
3335 case QEMU_OPTION_version
:
3340 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3347 case QEMU_OPTION_tpmdev
:
3348 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3353 case QEMU_OPTION_mempath
:
3356 case QEMU_OPTION_mem_prealloc
:
3365 case QEMU_OPTION_DFILTER
:
3366 qemu_set_dfilter_ranges(optarg
);
3369 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3371 case QEMU_OPTION_gdb
:
3372 add_device_config(DEV_GDB
, optarg
);
3375 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3376 data_dir
[data_dir_idx
++] = optarg
;
3379 case QEMU_OPTION_bios
:
3380 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3383 case QEMU_OPTION_singlestep
:
3390 keyboard_layout
= optarg
;
3392 case QEMU_OPTION_localtime
:
3395 case QEMU_OPTION_vga
:
3404 w
= strtol(p
, (char **)&p
, 10);
3407 error_report("invalid resolution or depth");
3413 h
= strtol(p
, (char **)&p
, 10);
3418 depth
= strtol(p
, (char **)&p
, 10);
3419 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3420 depth
!= 24 && depth
!= 32)
3422 } else if (*p
== '\0') {
3423 depth
= graphic_depth
;
3430 graphic_depth
= depth
;
3433 case QEMU_OPTION_echr
:
3436 term_escape_char
= strtol(optarg
, &r
, 0);
3438 printf("Bad argument to echr\n");
3441 case QEMU_OPTION_monitor
:
3442 default_monitor
= 0;
3443 if (strncmp(optarg
, "none", 4)) {
3444 monitor_parse(optarg
, "readline", false);
3447 case QEMU_OPTION_qmp
:
3448 monitor_parse(optarg
, "control", false);
3449 default_monitor
= 0;
3451 case QEMU_OPTION_qmp_pretty
:
3452 monitor_parse(optarg
, "control", true);
3453 default_monitor
= 0;
3455 case QEMU_OPTION_mon
:
3456 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3461 default_monitor
= 0;
3463 case QEMU_OPTION_chardev
:
3464 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3470 case QEMU_OPTION_fsdev
:
3471 olist
= qemu_find_opts("fsdev");
3473 error_report("fsdev support is disabled");
3476 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3481 case QEMU_OPTION_virtfs
: {
3484 const char *writeout
, *sock_fd
, *socket
;
3486 olist
= qemu_find_opts("virtfs");
3488 error_report("virtfs support is disabled");
3491 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3496 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3497 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3498 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3501 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3502 qemu_opt_get(opts
, "mount_tag"),
3505 error_report("duplicate fsdev id: %s",
3506 qemu_opt_get(opts
, "mount_tag"));
3510 writeout
= qemu_opt_get(opts
, "writeout");
3512 #ifdef CONFIG_SYNC_FILE_RANGE
3513 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3515 error_report("writeout=immediate not supported "
3516 "on this platform");
3520 qemu_opt_set(fsdev
, "fsdriver",
3521 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3522 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3524 qemu_opt_set(fsdev
, "security_model",
3525 qemu_opt_get(opts
, "security_model"),
3527 socket
= qemu_opt_get(opts
, "socket");
3529 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3531 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3533 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3536 qemu_opt_set_bool(fsdev
, "readonly",
3537 qemu_opt_get_bool(opts
, "readonly", 0),
3539 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3541 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3542 qemu_opt_set(device
, "fsdev",
3543 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3544 qemu_opt_set(device
, "mount_tag",
3545 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3548 case QEMU_OPTION_virtfs_synth
: {
3552 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3555 error_report("duplicate option: %s", "virtfs_synth");
3558 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3560 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3562 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3563 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3564 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3567 case QEMU_OPTION_serial
:
3568 add_device_config(DEV_SERIAL
, optarg
);
3570 if (strncmp(optarg
, "mon:", 4) == 0) {
3571 default_monitor
= 0;
3574 case QEMU_OPTION_watchdog
:
3576 error_report("only one watchdog option may be given");
3581 case QEMU_OPTION_watchdog_action
:
3582 if (select_watchdog_action(optarg
) == -1) {
3583 error_report("unknown -watchdog-action parameter");
3587 case QEMU_OPTION_virtiocon
:
3588 add_device_config(DEV_VIRTCON
, optarg
);
3589 default_virtcon
= 0;
3590 if (strncmp(optarg
, "mon:", 4) == 0) {
3591 default_monitor
= 0;
3594 case QEMU_OPTION_parallel
:
3595 add_device_config(DEV_PARALLEL
, optarg
);
3596 default_parallel
= 0;
3597 if (strncmp(optarg
, "mon:", 4) == 0) {
3598 default_monitor
= 0;
3601 case QEMU_OPTION_debugcon
:
3602 add_device_config(DEV_DEBUGCON
, optarg
);
3604 case QEMU_OPTION_loadvm
:
3607 case QEMU_OPTION_full_screen
:
3610 case QEMU_OPTION_no_frame
:
3613 case QEMU_OPTION_alt_grab
:
3616 case QEMU_OPTION_ctrl_grab
:
3619 case QEMU_OPTION_no_quit
:
3622 case QEMU_OPTION_sdl
:
3624 display_type
= DT_SDL
;
3627 error_report("SDL support is disabled");
3630 case QEMU_OPTION_pidfile
:
3633 case QEMU_OPTION_win2k_hack
:
3634 win2k_install_hack
= 1;
3636 case QEMU_OPTION_rtc_td_hack
: {
3637 static GlobalProperty slew_lost_ticks
[] = {
3639 .driver
= "mc146818rtc",
3640 .property
= "lost_tick_policy",
3643 { /* end of list */ }
3646 qdev_prop_register_global_list(slew_lost_ticks
);
3649 case QEMU_OPTION_acpitable
:
3650 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3655 do_acpitable_option(opts
);
3657 case QEMU_OPTION_smbios
:
3658 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3663 do_smbios_option(opts
);
3665 case QEMU_OPTION_fwcfg
:
3666 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3672 case QEMU_OPTION_enable_kvm
:
3673 olist
= qemu_find_opts("machine");
3674 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3677 case QEMU_OPTION_machine
:
3678 olist
= qemu_find_opts("machine");
3679 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3684 case QEMU_OPTION_no_kvm
:
3685 olist
= qemu_find_opts("machine");
3686 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3688 case QEMU_OPTION_no_kvm_pit
: {
3689 error_report("warning: ignoring deprecated option");
3692 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3693 static GlobalProperty kvm_pit_lost_tick_policy
[] = {
3695 .driver
= "kvm-pit",
3696 .property
= "lost_tick_policy",
3699 { /* end of list */ }
3702 error_report("warning: deprecated, replaced by "
3703 "-global kvm-pit.lost_tick_policy=discard");
3704 qdev_prop_register_global_list(kvm_pit_lost_tick_policy
);
3707 case QEMU_OPTION_usb
:
3708 olist
= qemu_find_opts("machine");
3709 qemu_opts_parse_noisily(olist
, "usb=on", false);
3711 case QEMU_OPTION_usbdevice
:
3712 olist
= qemu_find_opts("machine");
3713 qemu_opts_parse_noisily(olist
, "usb=on", false);
3714 add_device_config(DEV_USB
, optarg
);
3716 case QEMU_OPTION_device
:
3717 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3722 case QEMU_OPTION_smp
:
3723 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3728 case QEMU_OPTION_vnc
:
3731 Error
*local_err
= NULL
;
3733 if (vnc_parse(optarg
, &local_err
) == NULL
) {
3734 error_report_err(local_err
);
3738 error_report("VNC support is disabled");
3743 case QEMU_OPTION_no_acpi
:
3746 case QEMU_OPTION_no_hpet
:
3749 case QEMU_OPTION_balloon
:
3750 if (balloon_parse(optarg
) < 0) {
3751 error_report("unknown -balloon argument %s", optarg
);
3755 case QEMU_OPTION_no_reboot
:
3758 case QEMU_OPTION_no_shutdown
:
3761 case QEMU_OPTION_show_cursor
:
3764 case QEMU_OPTION_uuid
:
3765 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
3766 error_report("failed to parse UUID string: wrong format");
3769 qemu_uuid_set
= true;
3771 case QEMU_OPTION_option_rom
:
3772 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3773 error_report("too many option ROMs");
3776 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3781 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3782 option_rom
[nb_option_roms
].bootindex
=
3783 qemu_opt_get_number(opts
, "bootindex", -1);
3784 if (!option_rom
[nb_option_roms
].name
) {
3785 error_report("Option ROM file is not specified");
3790 case QEMU_OPTION_semihosting
:
3791 semihosting
.enabled
= true;
3792 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3794 case QEMU_OPTION_semihosting_config
:
3795 semihosting
.enabled
= true;
3796 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3799 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3801 const char *target
= qemu_opt_get(opts
, "target");
3802 if (target
!= NULL
) {
3803 if (strcmp("native", target
) == 0) {
3804 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3805 } else if (strcmp("gdb", target
) == 0) {
3806 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3807 } else if (strcmp("auto", target
) == 0) {
3808 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3810 error_report("unsupported semihosting-config %s",
3815 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3817 /* Set semihosting argument count and vector */
3818 qemu_opt_foreach(opts
, add_semihosting_arg
,
3819 &semihosting
, NULL
);
3821 error_report("unsupported semihosting-config %s", optarg
);
3825 case QEMU_OPTION_tdf
:
3826 error_report("warning: ignoring deprecated option");
3828 case QEMU_OPTION_name
:
3829 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3835 case QEMU_OPTION_prom_env
:
3836 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3837 error_report("too many prom variables");
3840 prom_envs
[nb_prom_envs
] = optarg
;
3843 case QEMU_OPTION_old_param
:
3846 case QEMU_OPTION_clock
:
3847 /* Clock options no longer exist. Keep this option for
3848 * backward compatibility.
3851 case QEMU_OPTION_startdate
:
3852 configure_rtc_date_offset(optarg
, 1);
3854 case QEMU_OPTION_rtc
:
3855 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3860 configure_rtc(opts
);
3862 case QEMU_OPTION_tb_size
:
3863 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3864 if (tcg_tb_size
< 0) {
3868 case QEMU_OPTION_icount
:
3869 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3875 case QEMU_OPTION_incoming
:
3877 runstate_set(RUN_STATE_INMIGRATE
);
3881 case QEMU_OPTION_nodefaults
:
3884 case QEMU_OPTION_xen_domid
:
3885 if (!(xen_available())) {
3886 printf("Option %s not supported for this target\n", popt
->name
);
3889 xen_domid
= atoi(optarg
);
3891 case QEMU_OPTION_xen_create
:
3892 if (!(xen_available())) {
3893 printf("Option %s not supported for this target\n", popt
->name
);
3896 xen_mode
= XEN_CREATE
;
3898 case QEMU_OPTION_xen_attach
:
3899 if (!(xen_available())) {
3900 printf("Option %s not supported for this target\n", popt
->name
);
3903 xen_mode
= XEN_ATTACH
;
3905 case QEMU_OPTION_trace
:
3907 opts
= qemu_opts_parse_noisily(qemu_find_opts("trace"),
3912 if (qemu_opt_get(opts
, "enable")) {
3913 trace_enable_events(qemu_opt_get(opts
, "enable"));
3915 trace_init_events(qemu_opt_get(opts
, "events"));
3919 trace_file
= g_strdup(qemu_opt_get(opts
, "file"));
3920 qemu_opts_del(opts
);
3923 case QEMU_OPTION_readconfig
:
3925 int ret
= qemu_read_config_file(optarg
);
3927 error_report("read config %s: %s", optarg
,
3933 case QEMU_OPTION_spice
:
3934 olist
= qemu_find_opts("spice");
3936 error_report("spice support is disabled");
3939 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3945 case QEMU_OPTION_writeconfig
:
3948 if (strcmp(optarg
, "-") == 0) {
3951 fp
= fopen(optarg
, "w");
3953 error_report("open %s: %s", optarg
,
3958 qemu_config_write(fp
);
3964 case QEMU_OPTION_qtest
:
3965 qtest_chrdev
= optarg
;
3967 case QEMU_OPTION_qtest_log
:
3970 case QEMU_OPTION_sandbox
:
3971 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
3977 case QEMU_OPTION_add_fd
:
3979 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3985 error_report("File descriptor passing is disabled on this "
3990 case QEMU_OPTION_object
:
3991 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
3997 case QEMU_OPTION_realtime
:
3998 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4003 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4005 case QEMU_OPTION_msg
:
4006 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4011 configure_msg(opts
);
4013 case QEMU_OPTION_dump_vmstate
:
4014 if (vmstate_dump_file
) {
4015 error_report("only one '-dump-vmstate' "
4016 "option may be given");
4019 vmstate_dump_file
= fopen(optarg
, "w");
4020 if (vmstate_dump_file
== NULL
) {
4021 error_report("open %s: %s", optarg
, strerror(errno
));
4026 os_parse_cmd_args(popt
->index
, optarg
);
4031 * Clear error location left behind by the loop.
4032 * Best done right after the loop. Do not insert code here!
4036 replay_configure(icount_opts
);
4038 machine_class
= select_machine();
4040 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4044 if (qemu_init_main_loop(&main_loop_err
)) {
4045 error_report_err(main_loop_err
);
4049 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4050 parse_sandbox
, NULL
, NULL
)) {
4054 if (qemu_opts_foreach(qemu_find_opts("name"),
4055 parse_name
, NULL
, NULL
)) {
4060 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4061 parse_add_fd
, NULL
, NULL
)) {
4065 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4066 cleanup_add_fd
, NULL
, NULL
)) {
4071 current_machine
= MACHINE(object_new(object_class_get_name(
4072 OBJECT_CLASS(machine_class
))));
4073 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4076 object_property_add_child(object_get_root(), "machine",
4077 OBJECT(current_machine
), &error_abort
);
4078 cpu_exec_init_all();
4080 if (machine_class
->hw_version
) {
4081 qemu_set_hw_version(machine_class
->hw_version
);
4084 /* Init CPU def lists, based on config
4085 * - Must be called after all the qemu_read_config_file() calls
4086 * - Must be called before list_cpus()
4087 * - Must be called before machine_class->init()
4091 if (cpu_model
&& is_help_option(cpu_model
)) {
4092 list_cpus(stdout
, &fprintf
, cpu_model
);
4096 if (!trace_init_backends()) {
4099 trace_init_file(trace_file
);
4101 /* Open the logfile at this point and set the log mask if necessary.
4104 qemu_set_log_filename(log_file
);
4109 mask
= qemu_str_to_log_mask(log_mask
);
4111 qemu_print_log_usage(stdout
);
4119 /* If no data_dir is specified then try to find it relative to the
4121 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4122 data_dir
[data_dir_idx
] = os_find_datadir();
4123 if (data_dir
[data_dir_idx
] != NULL
) {
4127 /* If all else fails use the install path specified when building. */
4128 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4129 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4132 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4134 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4135 if (max_cpus
> machine_class
->max_cpus
) {
4136 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4137 "supported by machine '%s' (%d)", max_cpus
,
4138 machine_class
->name
, machine_class
->max_cpus
);
4143 * Get the default machine options from the machine if it is not already
4144 * specified either by the configuration file or by the command line.
4146 if (machine_class
->default_machine_opts
) {
4147 qemu_opts_set_defaults(qemu_find_opts("machine"),
4148 machine_class
->default_machine_opts
, 0);
4151 qemu_opts_foreach(qemu_find_opts("device"),
4152 default_driver_check
, NULL
, NULL
);
4153 qemu_opts_foreach(qemu_find_opts("global"),
4154 default_driver_check
, NULL
, NULL
);
4156 if (!vga_model
&& !default_vga
) {
4157 vga_interface_type
= VGA_DEVICE
;
4159 if (!has_defaults
|| machine_class
->no_serial
) {
4162 if (!has_defaults
|| machine_class
->no_parallel
) {
4163 default_parallel
= 0;
4165 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4166 default_virtcon
= 0;
4168 if (!has_defaults
|| !machine_class
->use_sclp
) {
4171 if (!has_defaults
|| machine_class
->no_floppy
) {
4174 if (!has_defaults
|| machine_class
->no_cdrom
) {
4177 if (!has_defaults
|| machine_class
->no_sdcard
) {
4180 if (!has_defaults
) {
4181 default_monitor
= 0;
4186 if (is_daemonized()) {
4187 /* According to documentation and historically, -nographic redirects
4188 * serial port, parallel port and monitor to stdio, which does not work
4189 * with -daemonize. We can redirect these to null instead, but since
4190 * -nographic is legacy, let's just error out.
4191 * We disallow -nographic only if all other ports are not redirected
4192 * explicitly, to not break existing legacy setups which uses
4193 * -nographic _and_ redirects all ports explicitly - this is valid
4194 * usage, -nographic is just a no-op in this case.
4196 if (display_type
== DT_NOGRAPHIC
4197 && (default_parallel
|| default_serial
4198 || default_monitor
|| default_virtcon
)) {
4199 error_report("-nographic cannot be used with -daemonize");
4202 #ifdef CONFIG_CURSES
4203 if (display_type
== DT_CURSES
) {
4204 error_report("curses display cannot be used with -daemonize");
4210 if (display_type
== DT_NOGRAPHIC
) {
4211 if (default_parallel
)
4212 add_device_config(DEV_PARALLEL
, "null");
4213 if (default_serial
&& default_monitor
) {
4214 add_device_config(DEV_SERIAL
, "mon:stdio");
4215 } else if (default_virtcon
&& default_monitor
) {
4216 add_device_config(DEV_VIRTCON
, "mon:stdio");
4217 } else if (default_sclp
&& default_monitor
) {
4218 add_device_config(DEV_SCLP
, "mon:stdio");
4221 add_device_config(DEV_SERIAL
, "stdio");
4222 if (default_virtcon
)
4223 add_device_config(DEV_VIRTCON
, "stdio");
4225 add_device_config(DEV_SCLP
, "stdio");
4227 if (default_monitor
)
4228 monitor_parse("stdio", "readline", false);
4232 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4233 if (default_parallel
)
4234 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4235 if (default_monitor
)
4236 monitor_parse("vc:80Cx24C", "readline", false);
4237 if (default_virtcon
)
4238 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4240 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4244 #if defined(CONFIG_VNC)
4245 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4249 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4250 #if defined(CONFIG_GTK)
4251 display_type
= DT_GTK
;
4252 #elif defined(CONFIG_SDL) || defined(CONFIG_COCOA)
4253 display_type
= DT_SDL
;
4254 #elif defined(CONFIG_VNC)
4255 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4258 display_type
= DT_NONE
;
4262 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4263 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4264 "for SDL, ignoring option");
4266 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4267 error_report("-no-quit is only valid for GTK and SDL, "
4271 #if defined(CONFIG_GTK)
4272 if (display_type
== DT_GTK
) {
4273 early_gtk_display_init(request_opengl
);
4276 #if defined(CONFIG_SDL)
4277 if (display_type
== DT_SDL
) {
4278 sdl_display_early_init(request_opengl
);
4281 if (request_opengl
== 1 && display_opengl
== 0) {
4282 #if defined(CONFIG_OPENGL)
4283 error_report("OpenGL is not supported by the display");
4285 error_report("OpenGL support is disabled");
4293 if (qemu_opts_foreach(qemu_find_opts("object"),
4294 user_creatable_add_opts_foreach
,
4295 object_create_initial
, NULL
)) {
4299 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4300 chardev_init_func
, NULL
, NULL
)) {
4304 #ifdef CONFIG_VIRTFS
4305 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4306 fsdev_init_func
, NULL
, NULL
)) {
4311 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4312 error_report("could not acquire pid file: %s", strerror(errno
));
4316 if (qemu_opts_foreach(qemu_find_opts("device"),
4317 device_help_func
, NULL
, NULL
)) {
4321 machine_opts
= qemu_get_machine_opts();
4322 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4324 object_unref(OBJECT(current_machine
));
4328 configure_accelerator(current_machine
);
4331 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4334 machine_opts
= qemu_get_machine_opts();
4335 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4336 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4337 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4338 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4340 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4342 boot_order
= qemu_opt_get(opts
, "order");
4344 validate_bootdevices(boot_order
, &error_fatal
);
4347 boot_once
= qemu_opt_get(opts
, "once");
4349 validate_bootdevices(boot_once
, &error_fatal
);
4352 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4353 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4357 boot_order
= machine_class
->default_boot_order
;
4360 if (!kernel_cmdline
) {
4361 kernel_cmdline
= "";
4362 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4365 linux_boot
= (kernel_filename
!= NULL
);
4367 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4368 error_report("-append only allowed with -kernel option");
4372 if (!linux_boot
&& initrd_filename
!= NULL
) {
4373 error_report("-initrd only allowed with -kernel option");
4377 if (!linux_boot
&& qemu_opt_get(machine_opts
, "dtb")) {
4378 error_report("-dtb only allowed with -kernel option");
4382 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4383 /* fall back to the -kernel/-append */
4384 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4387 os_set_line_buffering();
4390 /* spice needs the timers to be initialized by this point */
4396 if (kvm_enabled() || xen_enabled()) {
4397 error_report("-icount is not allowed with kvm or xen");
4400 configure_icount(icount_opts
, &error_abort
);
4401 qemu_opts_del(icount_opts
);
4404 /* clean up network at qemu process termination */
4405 atexit(&net_cleanup
);
4407 if (net_init_clients() < 0) {
4411 if (qemu_opts_foreach(qemu_find_opts("object"),
4412 user_creatable_add_opts_foreach
,
4413 object_create_delayed
, NULL
)) {
4418 if (tpm_init() < 0) {
4423 /* init the bluetooth world */
4424 if (foreach_device_config(DEV_BT
, bt_parse
))
4427 if (!xen_enabled()) {
4428 /* On 32-bit hosts, QEMU is limited by virtual address space */
4429 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4430 error_report("at most 2047 MB RAM can be simulated");
4438 /* If the currently selected machine wishes to override the units-per-bus
4439 * property of its default HBA interface type, do so now. */
4440 if (machine_class
->units_per_default_bus
) {
4441 override_max_devs(machine_class
->block_default_type
,
4442 machine_class
->units_per_default_bus
);
4445 /* open the virtual block devices */
4446 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4447 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4450 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4451 &machine_class
->block_default_type
, NULL
)) {
4455 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4457 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4458 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4460 parse_numa_opts(machine_class
);
4462 if (qemu_opts_foreach(qemu_find_opts("mon"),
4463 mon_init_func
, NULL
, NULL
)) {
4467 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4469 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4471 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4473 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4476 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4479 /* If no default VGA is requested, the default is "none". */
4481 if (machine_class
->default_display
) {
4482 vga_model
= machine_class
->default_display
;
4483 } else if (cirrus_vga_available()) {
4484 vga_model
= "cirrus";
4485 } else if (vga_available()) {
4490 select_vgahw(vga_model
);
4494 i
= select_watchdog(watchdog
);
4496 exit (i
== 1 ? 1 : 0);
4499 if (machine_class
->compat_props
) {
4500 qdev_prop_register_global_list(machine_class
->compat_props
);
4504 /* This checkpoint is required by replay to separate prior clock
4505 reading from the other reads, because timer polling functions query
4506 clock values from the log. */
4507 replay_checkpoint(CHECKPOINT_INIT
);
4508 qdev_machine_init();
4510 current_machine
->ram_size
= ram_size
;
4511 current_machine
->maxram_size
= maxram_size
;
4512 current_machine
->ram_slots
= ram_slots
;
4513 current_machine
->boot_order
= boot_order
;
4514 current_machine
->cpu_model
= cpu_model
;
4516 machine_class
->init(current_machine
);
4522 cpu_synchronize_all_post_init();
4524 numa_post_machine_init();
4526 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4527 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4531 /* init USB devices */
4532 if (usb_enabled()) {
4533 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4537 /* Check if IGD GFX passthrough. */
4540 /* init generic devices */
4541 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4542 if (qemu_opts_foreach(qemu_find_opts("device"),
4543 device_init_func
, NULL
, NULL
)) {
4546 rom_reset_order_override();
4548 /* Did we create any drives that we failed to create a device for? */
4549 drive_check_orphaned();
4551 net_check_clients();
4554 qemu_boot_set(boot_once
, &error_fatal
);
4555 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4558 ds
= init_displaystate();
4560 /* init local displays */
4561 switch (display_type
) {
4563 (void)ds
; /* avoid warning if no display is configured */
4565 #if defined(CONFIG_CURSES)
4567 curses_display_init(ds
, full_screen
);
4570 #if defined(CONFIG_SDL)
4572 sdl_display_init(ds
, full_screen
, no_frame
);
4574 #elif defined(CONFIG_COCOA)
4576 cocoa_display_init(ds
, full_screen
);
4579 #if defined(CONFIG_GTK)
4581 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4588 /* must be after terminal init, SDL library changes signal handlers */
4589 os_setup_signal_handling();
4592 /* init remote displays */
4593 qemu_opts_foreach(qemu_find_opts("vnc"),
4594 vnc_init_func
, NULL
, NULL
);
4595 if (show_vnc_port
) {
4596 char *ret
= vnc_display_local_addr("default");
4597 printf("VNC server running on '%s'\n", ret
);
4603 qemu_spice_display_init();
4607 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4611 qdev_machine_creation_done();
4613 /* TODO: once all bus devices are qdevified, this should be done
4614 * when bus is created by qdev.c */
4615 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4616 qemu_run_machine_init_done_notifiers();
4618 if (rom_check_and_register_reset() != 0) {
4619 error_report("rom check and register reset failed");
4625 /* This checkpoint is required by replay to separate prior clock
4626 reading from the other reads, because timer polling functions query
4627 clock values from the log. */
4628 replay_checkpoint(CHECKPOINT_RESET
);
4629 qemu_system_reset(VMRESET_SILENT
);
4630 register_global_state();
4632 if (load_vmstate(loadvm
) < 0) {
4637 qdev_prop_check_globals();
4638 if (vmstate_dump_file
) {
4640 dump_vmstate_json_to_file(vmstate_dump_file
);
4645 Error
*local_err
= NULL
;
4646 qemu_start_incoming_migration(incoming
, &local_err
);
4648 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4651 } else if (autostart
) {
4658 replay_disable_events();