4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "qemu/osdep.h"
25 #include "qemu-version.h"
26 #include "qemu/cutils.h"
27 #include "qemu/help_option.h"
28 #include "qemu/uuid.h"
31 #include "sysemu/seccomp.h"
34 #if defined(CONFIG_VDE)
35 #include <libvdeplug.h>
39 #if defined(__APPLE__) || defined(main)
41 int qemu_main(int argc
, char **argv
);
42 int main(int argc
, char **argv
)
44 return qemu_main(argc
, argv
);
47 #define main qemu_main
49 #endif /* CONFIG_SDL */
53 #define main qemu_main
54 #endif /* CONFIG_COCOA */
57 #include "qemu/error-report.h"
58 #include "qemu/sockets.h"
60 #include "hw/boards.h"
61 #include "sysemu/accel.h"
63 #include "hw/i386/pc.h"
64 #include "hw/isa/isa.h"
66 #include "sysemu/watchdog.h"
67 #include "hw/smbios/smbios.h"
68 #include "hw/xen/xen.h"
70 #include "hw/loader.h"
71 #include "monitor/qdev.h"
72 #include "sysemu/bt.h"
74 #include "net/slirp.h"
75 #include "monitor/monitor.h"
76 #include "ui/console.h"
78 #include "sysemu/sysemu.h"
79 #include "sysemu/numa.h"
80 #include "exec/gdbstub.h"
81 #include "qemu/timer.h"
82 #include "sysemu/char.h"
83 #include "qemu/bitmap.h"
85 #include "sysemu/blockdev.h"
86 #include "hw/block/block.h"
87 #include "migration/block.h"
88 #include "sysemu/tpm.h"
89 #include "sysemu/dma.h"
90 #include "audio/audio.h"
91 #include "migration/migration.h"
92 #include "sysemu/cpus.h"
93 #include "migration/colo.h"
94 #include "sysemu/kvm.h"
95 #include "sysemu/hax.h"
96 #include "qapi/qmp/qjson.h"
97 #include "qemu/option.h"
98 #include "qemu/config-file.h"
99 #include "qemu-options.h"
100 #include "qmp-commands.h"
101 #include "qemu/main-loop.h"
103 #include "fsdev/qemu-fsdev.h"
105 #include "sysemu/qtest.h"
107 #include "disas/disas.h"
110 #include "slirp/libslirp.h"
113 #include "trace/control.h"
114 #include "qemu/queue.h"
115 #include "sysemu/arch_init.h"
117 #include "ui/qemu-spice.h"
118 #include "qapi/string-input-visitor.h"
119 #include "qapi/opts-visitor.h"
120 #include "qom/object_interfaces.h"
121 #include "qapi-event.h"
122 #include "exec/semihost.h"
123 #include "crypto/init.h"
124 #include "sysemu/replay.h"
125 #include "qapi/qmp/qerror.h"
126 #include "sysemu/iothread.h"
128 #define MAX_VIRTIO_CONSOLES 1
129 #define MAX_SCLP_CONSOLES 1
131 static const char *data_dir
[16];
132 static int data_dir_idx
;
133 const char *bios_name
= NULL
;
134 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
135 int request_opengl
= -1;
137 const char* keyboard_layout
= NULL
;
139 const char *mem_path
= NULL
;
140 int mem_prealloc
= 0; /* force preallocation of physical target memory */
141 bool enable_mlock
= false;
143 NICInfo nd_table
[MAX_NICS
];
145 static int rtc_utc
= 1;
146 static int rtc_date_offset
= -1; /* -1 means no change */
147 QEMUClockType rtc_clock
;
148 int vga_interface_type
= VGA_NONE
;
149 static int full_screen
= 0;
150 static int no_frame
= 0;
152 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.
193 /* Trace unassigned memory or i/o accesses. */
194 bool trace_unassigned
;
196 static NotifierList exit_notifiers
=
197 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
199 static NotifierList machine_init_done_notifiers
=
200 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
204 enum xen_mode xen_mode
= XEN_EMULATE
;
206 static int has_defaults
= 1;
207 static int default_serial
= 1;
208 static int default_parallel
= 1;
209 static int default_virtcon
= 1;
210 static int default_sclp
= 1;
211 static int default_monitor
= 1;
212 static int default_floppy
= 1;
213 static int default_cdrom
= 1;
214 static int default_sdcard
= 1;
215 static int default_vga
= 1;
216 static int default_net
= 1;
222 { .driver
= "isa-serial", .flag
= &default_serial
},
223 { .driver
= "isa-parallel", .flag
= &default_parallel
},
224 { .driver
= "isa-fdc", .flag
= &default_floppy
},
225 { .driver
= "floppy", .flag
= &default_floppy
},
226 { .driver
= "ide-cd", .flag
= &default_cdrom
},
227 { .driver
= "ide-hd", .flag
= &default_cdrom
},
228 { .driver
= "ide-drive", .flag
= &default_cdrom
},
229 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
230 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
231 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
232 { .driver
= "VGA", .flag
= &default_vga
},
233 { .driver
= "isa-vga", .flag
= &default_vga
},
234 { .driver
= "cirrus-vga", .flag
= &default_vga
},
235 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
236 { .driver
= "vmware-svga", .flag
= &default_vga
},
237 { .driver
= "qxl-vga", .flag
= &default_vga
},
238 { .driver
= "virtio-vga", .flag
= &default_vga
},
241 static QemuOptsList qemu_rtc_opts
= {
243 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
247 .type
= QEMU_OPT_STRING
,
250 .type
= QEMU_OPT_STRING
,
253 .type
= QEMU_OPT_STRING
,
255 { /* end of list */ }
259 static QemuOptsList qemu_sandbox_opts
= {
261 .implied_opt_name
= "enable",
262 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
266 .type
= QEMU_OPT_BOOL
,
268 { /* end of list */ }
272 static QemuOptsList qemu_option_rom_opts
= {
273 .name
= "option-rom",
274 .implied_opt_name
= "romfile",
275 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
279 .type
= QEMU_OPT_NUMBER
,
282 .type
= QEMU_OPT_STRING
,
284 { /* end of list */ }
288 static QemuOptsList qemu_machine_opts
= {
290 .implied_opt_name
= "type",
292 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
295 * no elements => accept any
296 * sanity checking will happen later
297 * when setting machine properties
303 static QemuOptsList qemu_boot_opts
= {
305 .implied_opt_name
= "order",
307 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
311 .type
= QEMU_OPT_STRING
,
314 .type
= QEMU_OPT_STRING
,
317 .type
= QEMU_OPT_BOOL
,
320 .type
= QEMU_OPT_STRING
,
322 .name
= "splash-time",
323 .type
= QEMU_OPT_STRING
,
325 .name
= "reboot-timeout",
326 .type
= QEMU_OPT_STRING
,
329 .type
= QEMU_OPT_BOOL
,
335 static QemuOptsList qemu_add_fd_opts
= {
337 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
341 .type
= QEMU_OPT_NUMBER
,
342 .help
= "file descriptor of which a duplicate is added to fd set",
345 .type
= QEMU_OPT_NUMBER
,
346 .help
= "ID of the fd set to add fd to",
349 .type
= QEMU_OPT_STRING
,
350 .help
= "free-form string used to describe fd",
352 { /* end of list */ }
356 static QemuOptsList qemu_object_opts
= {
358 .implied_opt_name
= "qom-type",
359 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
365 static QemuOptsList qemu_tpmdev_opts
= {
367 .implied_opt_name
= "type",
368 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
370 /* options are defined in the TPM backends */
371 { /* end of list */ }
375 static QemuOptsList qemu_realtime_opts
= {
377 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
381 .type
= QEMU_OPT_BOOL
,
383 { /* end of list */ }
387 static QemuOptsList qemu_msg_opts
= {
389 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
393 .type
= QEMU_OPT_BOOL
,
395 { /* end of list */ }
399 static QemuOptsList qemu_name_opts
= {
401 .implied_opt_name
= "guest",
403 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
407 .type
= QEMU_OPT_STRING
,
408 .help
= "Sets the name of the guest.\n"
409 "This name will be displayed in the SDL window caption.\n"
410 "The name will also be used for the VNC server",
413 .type
= QEMU_OPT_STRING
,
414 .help
= "Sets the name of the QEMU process, as shown in top etc",
416 .name
= "debug-threads",
417 .type
= QEMU_OPT_BOOL
,
418 .help
= "When enabled, name the individual threads; defaults off.\n"
419 "NOTE: The thread names are for debugging and not a\n"
422 { /* End of list */ }
426 static QemuOptsList qemu_mem_opts
= {
428 .implied_opt_name
= "size",
429 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
434 .type
= QEMU_OPT_SIZE
,
438 .type
= QEMU_OPT_NUMBER
,
442 .type
= QEMU_OPT_SIZE
,
444 { /* end of list */ }
448 static QemuOptsList qemu_icount_opts
= {
450 .implied_opt_name
= "shift",
452 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
456 .type
= QEMU_OPT_STRING
,
459 .type
= QEMU_OPT_BOOL
,
462 .type
= QEMU_OPT_BOOL
,
465 .type
= QEMU_OPT_STRING
,
468 .type
= QEMU_OPT_STRING
,
470 { /* end of list */ }
474 static QemuOptsList qemu_semihosting_config_opts
= {
475 .name
= "semihosting-config",
476 .implied_opt_name
= "enable",
477 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
481 .type
= QEMU_OPT_BOOL
,
484 .type
= QEMU_OPT_STRING
,
487 .type
= QEMU_OPT_STRING
,
489 { /* end of list */ }
493 static QemuOptsList qemu_fw_cfg_opts
= {
495 .implied_opt_name
= "name",
496 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
500 .type
= QEMU_OPT_STRING
,
501 .help
= "Sets the fw_cfg name of the blob to be inserted",
504 .type
= QEMU_OPT_STRING
,
505 .help
= "Sets the name of the file from which\n"
506 "the fw_cfg blob will be loaded",
509 .type
= QEMU_OPT_STRING
,
510 .help
= "Sets content of the blob to be inserted from a string",
512 { /* end of list */ }
516 #ifdef CONFIG_LIBISCSI
517 static QemuOptsList qemu_iscsi_opts
= {
519 .head
= QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts
.head
),
523 .type
= QEMU_OPT_STRING
,
524 .help
= "username for CHAP authentication to target",
527 .type
= QEMU_OPT_STRING
,
528 .help
= "password for CHAP authentication to target",
530 .name
= "password-secret",
531 .type
= QEMU_OPT_STRING
,
532 .help
= "ID of the secret providing password for CHAP "
533 "authentication to target",
535 .name
= "header-digest",
536 .type
= QEMU_OPT_STRING
,
537 .help
= "HeaderDigest setting. "
538 "{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
540 .name
= "initiator-name",
541 .type
= QEMU_OPT_STRING
,
542 .help
= "Initiator iqn name to use when connecting",
545 .type
= QEMU_OPT_NUMBER
,
546 .help
= "Request timeout in seconds (default 0 = no timeout)",
548 { /* end of list */ }
554 * Get machine options
556 * Returns: machine options (never null).
558 QemuOpts
*qemu_get_machine_opts(void)
560 return qemu_find_opts_singleton("machine");
563 const char *qemu_get_vm_name(void)
568 static void res_free(void)
570 g_free(boot_splash_filedata
);
571 boot_splash_filedata
= NULL
;
574 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
576 const char *driver
= qemu_opt_get(opts
, "driver");
581 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
582 if (strcmp(default_list
[i
].driver
, driver
) != 0)
584 *(default_list
[i
].flag
) = 0;
589 /***********************************************************/
592 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
594 /* We use RUN_STATE__MAX but any invalid value will do */
595 static RunState vmstop_requested
= RUN_STATE__MAX
;
596 static QemuMutex vmstop_lock
;
601 } RunStateTransition
;
603 static const RunStateTransition runstate_transitions_def
[] = {
605 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
606 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
607 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
609 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
610 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
611 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
612 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
613 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
614 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
615 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
616 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
617 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
618 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
619 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
620 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
622 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
623 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
624 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
626 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
627 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
628 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
630 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
631 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
632 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
633 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
635 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
636 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
637 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
639 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
640 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
641 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
643 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
644 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
645 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
646 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
648 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
649 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
651 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
653 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
654 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
655 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
656 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
657 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
658 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
659 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
660 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
661 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
662 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
663 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
665 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
667 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
668 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
669 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
671 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
672 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
673 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
674 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
675 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
676 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
678 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
679 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
680 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
681 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
683 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
684 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
685 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
687 { RUN_STATE__MAX
, RUN_STATE__MAX
},
690 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
692 bool runstate_check(RunState state
)
694 return current_run_state
== state
;
697 bool runstate_store(char *str
, size_t size
)
699 const char *state
= RunState_lookup
[current_run_state
];
700 size_t len
= strlen(state
) + 1;
705 memcpy(str
, state
, len
);
709 static void runstate_init(void)
711 const RunStateTransition
*p
;
713 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
714 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
715 runstate_valid_transitions
[p
->from
][p
->to
] = true;
718 qemu_mutex_init(&vmstop_lock
);
721 /* This function will abort() on invalid state transitions */
722 void runstate_set(RunState new_state
)
724 assert(new_state
< RUN_STATE__MAX
);
726 if (current_run_state
== new_state
) {
730 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
731 error_report("invalid runstate transition: '%s' -> '%s'",
732 RunState_lookup
[current_run_state
],
733 RunState_lookup
[new_state
]);
736 trace_runstate_set(new_state
);
737 current_run_state
= new_state
;
740 int runstate_is_running(void)
742 return runstate_check(RUN_STATE_RUNNING
);
745 bool runstate_needs_reset(void)
747 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
748 runstate_check(RUN_STATE_SHUTDOWN
);
751 StatusInfo
*qmp_query_status(Error
**errp
)
753 StatusInfo
*info
= g_malloc0(sizeof(*info
));
755 info
->running
= runstate_is_running();
756 info
->singlestep
= singlestep
;
757 info
->status
= current_run_state
;
762 static bool qemu_vmstop_requested(RunState
*r
)
764 qemu_mutex_lock(&vmstop_lock
);
765 *r
= vmstop_requested
;
766 vmstop_requested
= RUN_STATE__MAX
;
767 qemu_mutex_unlock(&vmstop_lock
);
768 return *r
< RUN_STATE__MAX
;
771 void qemu_system_vmstop_request_prepare(void)
773 qemu_mutex_lock(&vmstop_lock
);
776 void qemu_system_vmstop_request(RunState state
)
778 vmstop_requested
= state
;
779 qemu_mutex_unlock(&vmstop_lock
);
787 qemu_vmstop_requested(&requested
);
788 if (runstate_is_running() && requested
== RUN_STATE__MAX
) {
792 /* Ensure that a STOP/RESUME pair of events is emitted if a
793 * vmstop request was pending. The BLOCK_IO_ERROR event, for
794 * example, according to documentation is always followed by
797 if (runstate_is_running()) {
798 qapi_event_send_stop(&error_abort
);
800 replay_enable_events();
802 runstate_set(RUN_STATE_RUNNING
);
803 vm_state_notify(1, RUN_STATE_RUNNING
);
807 qapi_event_send_resume(&error_abort
);
811 /***********************************************************/
812 /* real time host monotonic timer */
814 static time_t qemu_time(void)
816 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
819 /***********************************************************/
820 /* host time/date access */
821 void qemu_get_timedate(struct tm
*tm
, int offset
)
823 time_t ti
= qemu_time();
826 if (rtc_date_offset
== -1) {
830 localtime_r(&ti
, tm
);
832 ti
-= rtc_date_offset
;
837 int qemu_timedate_diff(struct tm
*tm
)
841 if (rtc_date_offset
== -1)
843 seconds
= mktimegm(tm
);
846 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
847 seconds
= mktime(&tmp
);
850 seconds
= mktimegm(tm
) + rtc_date_offset
;
852 return seconds
- qemu_time();
855 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
857 time_t rtc_start_date
;
860 if (!strcmp(startdate
, "now") && legacy
) {
861 rtc_date_offset
= -1;
863 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
871 } else if (sscanf(startdate
, "%d-%d-%d",
883 rtc_start_date
= mktimegm(&tm
);
884 if (rtc_start_date
== -1) {
886 error_report("invalid date format");
887 error_printf("valid formats: "
888 "'2006-06-17T16:01:21' or '2006-06-17'\n");
891 rtc_date_offset
= qemu_time() - rtc_start_date
;
895 static void configure_rtc(QemuOpts
*opts
)
899 value
= qemu_opt_get(opts
, "base");
901 if (!strcmp(value
, "utc")) {
903 } else if (!strcmp(value
, "localtime")) {
904 Error
*blocker
= NULL
;
906 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
907 "-rtc base=localtime");
908 replay_add_blocker(blocker
);
910 configure_rtc_date_offset(value
, 0);
913 value
= qemu_opt_get(opts
, "clock");
915 if (!strcmp(value
, "host")) {
916 rtc_clock
= QEMU_CLOCK_HOST
;
917 } else if (!strcmp(value
, "rt")) {
918 rtc_clock
= QEMU_CLOCK_REALTIME
;
919 } else if (!strcmp(value
, "vm")) {
920 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
922 error_report("invalid option value '%s'", value
);
926 value
= qemu_opt_get(opts
, "driftfix");
928 if (!strcmp(value
, "slew")) {
929 static GlobalProperty slew_lost_ticks
= {
930 .driver
= "mc146818rtc",
931 .property
= "lost_tick_policy",
935 qdev_prop_register_global(&slew_lost_ticks
);
936 } else if (!strcmp(value
, "none")) {
937 /* discard is default */
939 error_report("invalid option value '%s'", value
);
945 /***********************************************************/
946 /* Bluetooth support */
949 static struct HCIInfo
*hci_table
[MAX_NICS
];
951 struct HCIInfo
*qemu_next_hci(void)
953 if (cur_hci
== nb_hcis
)
956 return hci_table
[cur_hci
++];
959 static int bt_hci_parse(const char *str
)
964 if (nb_hcis
>= MAX_NICS
) {
965 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
978 bdaddr
.b
[5] = 0x56 + nb_hcis
;
979 hci
->bdaddr_set(hci
, bdaddr
.b
);
981 hci_table
[nb_hcis
++] = hci
;
986 static void bt_vhci_add(int vlan_id
)
988 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
991 error_report("warning: adding a VHCI to an empty scatternet %i",
994 bt_vhci_init(bt_new_hci(vlan
));
997 static struct bt_device_s
*bt_device_add(const char *opt
)
999 struct bt_scatternet_s
*vlan
;
1001 char *endp
= strstr(opt
, ",vlan=");
1002 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
1005 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
1008 vlan_id
= strtol(endp
+ 6, &endp
, 0);
1010 error_report("unrecognised bluetooth vlan Id");
1015 vlan
= qemu_find_bt_vlan(vlan_id
);
1018 error_report("warning: adding a slave device to an empty scatternet %i",
1021 if (!strcmp(devname
, "keyboard"))
1022 return bt_keyboard_init(vlan
);
1024 error_report("unsupported bluetooth device '%s'", devname
);
1028 static int bt_parse(const char *opt
)
1030 const char *endp
, *p
;
1033 if (strstart(opt
, "hci", &endp
)) {
1034 if (!*endp
|| *endp
== ',') {
1036 if (!strstart(endp
, ",vlan=", 0))
1039 return bt_hci_parse(opt
);
1041 } else if (strstart(opt
, "vhci", &endp
)) {
1042 if (!*endp
|| *endp
== ',') {
1044 if (strstart(endp
, ",vlan=", &p
)) {
1045 vlan
= strtol(p
, (char **) &endp
, 0);
1047 error_report("bad scatternet '%s'", p
);
1051 error_report("bad parameter '%s'", endp
+ 1);
1060 } else if (strstart(opt
, "device:", &endp
))
1061 return !bt_device_add(endp
);
1063 error_report("bad bluetooth parameter '%s'", opt
);
1067 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1069 /* FIXME: change this to true for 1.3 */
1070 if (qemu_opt_get_bool(opts
, "enable", false)) {
1071 #ifdef CONFIG_SECCOMP
1072 if (seccomp_start() < 0) {
1073 error_report("failed to install seccomp syscall filter "
1078 error_report("seccomp support is disabled");
1086 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1088 const char *proc_name
;
1090 if (qemu_opt_get(opts
, "debug-threads")) {
1091 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1093 qemu_name
= qemu_opt_get(opts
, "guest");
1095 proc_name
= qemu_opt_get(opts
, "process");
1097 os_set_proc_name(proc_name
);
1103 bool defaults_enabled(void)
1105 return has_defaults
;
1109 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1111 int fd
, dupfd
, flags
;
1113 const char *fd_opaque
= NULL
;
1116 fd
= qemu_opt_get_number(opts
, "fd", -1);
1117 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1118 fd_opaque
= qemu_opt_get(opts
, "opaque");
1121 error_report("fd option is required and must be non-negative");
1125 if (fd
<= STDERR_FILENO
) {
1126 error_report("fd cannot be a standard I/O stream");
1131 * All fds inherited across exec() necessarily have FD_CLOEXEC
1132 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1134 flags
= fcntl(fd
, F_GETFD
);
1135 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1136 error_report("fd is not valid or already in use");
1141 error_report("set option is required and must be non-negative");
1145 #ifdef F_DUPFD_CLOEXEC
1146 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1150 qemu_set_cloexec(dupfd
);
1154 error_report("error duplicating fd: %s", strerror(errno
));
1158 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1159 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1166 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1170 fd
= qemu_opt_get_number(opts
, "fd", -1);
1177 /***********************************************************/
1178 /* QEMU Block devices */
1180 #define HD_OPTS "media=disk"
1181 #define CDROM_OPTS "media=cdrom"
1183 #define PFLASH_OPTS ""
1187 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1189 BlockInterfaceType
*block_default_type
= opaque
;
1191 return drive_new(opts
, *block_default_type
) == NULL
;
1194 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1196 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1197 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1202 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1203 int index
, const char *optstr
)
1208 if (!enable
|| drive_get_by_index(type
, index
)) {
1212 opts
= drive_add(type
, index
, NULL
, optstr
);
1214 drive_enable_snapshot(NULL
, opts
, NULL
);
1217 dinfo
= drive_new(opts
, type
);
1221 dinfo
->is_default
= true;
1225 static QemuOptsList qemu_smp_opts
= {
1227 .implied_opt_name
= "cpus",
1228 .merge_lists
= true,
1229 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1233 .type
= QEMU_OPT_NUMBER
,
1236 .type
= QEMU_OPT_NUMBER
,
1239 .type
= QEMU_OPT_NUMBER
,
1242 .type
= QEMU_OPT_NUMBER
,
1245 .type
= QEMU_OPT_NUMBER
,
1247 { /*End of list */ }
1251 static void smp_parse(QemuOpts
*opts
)
1254 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1255 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1256 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1257 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1259 /* compute missing values, prefer sockets over cores over threads */
1260 if (cpus
== 0 || sockets
== 0) {
1261 sockets
= sockets
> 0 ? sockets
: 1;
1262 cores
= cores
> 0 ? cores
: 1;
1263 threads
= threads
> 0 ? threads
: 1;
1265 cpus
= cores
* threads
* sockets
;
1267 } else if (cores
== 0) {
1268 threads
= threads
> 0 ? threads
: 1;
1269 cores
= cpus
/ (sockets
* threads
);
1270 cores
= cores
> 0 ? cores
: 1;
1271 } else if (threads
== 0) {
1272 threads
= cpus
/ (cores
* sockets
);
1273 threads
= threads
> 0 ? threads
: 1;
1274 } else if (sockets
* cores
* threads
< cpus
) {
1275 error_report("cpu topology: "
1276 "sockets (%u) * cores (%u) * threads (%u) < "
1278 sockets
, cores
, threads
, cpus
);
1282 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1284 if (max_cpus
> MAX_CPUMASK_BITS
) {
1285 error_report("unsupported number of maxcpus");
1289 if (max_cpus
< cpus
) {
1290 error_report("maxcpus must be equal to or greater than smp");
1294 if (sockets
* cores
* threads
> max_cpus
) {
1295 error_report("cpu topology: "
1296 "sockets (%u) * cores (%u) * threads (%u) > "
1298 sockets
, cores
, threads
, max_cpus
);
1304 smp_threads
= threads
;
1308 Error
*blocker
= NULL
;
1309 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1310 replay_add_blocker(blocker
);
1314 static void realtime_init(void)
1317 if (os_mlock() < 0) {
1318 error_report("locking memory failed");
1325 static void configure_msg(QemuOpts
*opts
)
1327 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1330 /***********************************************************/
1333 typedef struct SemihostingConfig
{
1335 SemihostingTarget target
;
1338 const char *cmdline
; /* concatenated argv */
1339 } SemihostingConfig
;
1341 static SemihostingConfig semihosting
;
1343 bool semihosting_enabled(void)
1345 return semihosting
.enabled
;
1348 SemihostingTarget
semihosting_get_target(void)
1350 return semihosting
.target
;
1353 const char *semihosting_get_arg(int i
)
1355 if (i
>= semihosting
.argc
) {
1358 return semihosting
.argv
[i
];
1361 int semihosting_get_argc(void)
1363 return semihosting
.argc
;
1366 const char *semihosting_get_cmdline(void)
1368 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1369 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1371 return semihosting
.cmdline
;
1374 static int add_semihosting_arg(void *opaque
,
1375 const char *name
, const char *val
,
1378 SemihostingConfig
*s
= opaque
;
1379 if (strcmp(name
, "arg") == 0) {
1381 /* one extra element as g_strjoinv() expects NULL-terminated array */
1382 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1383 s
->argv
[s
->argc
- 1] = val
;
1384 s
->argv
[s
->argc
] = NULL
;
1389 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1390 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1395 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1397 /* split -append and initialize argv[1..n] */
1398 cmd_token
= strtok(g_strdup(cmd
), " ");
1400 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1401 cmd_token
= strtok(NULL
, " ");
1405 /* Now we still need this for compatibility with XEN. */
1406 bool has_igd_gfx_passthru
;
1407 static void igd_gfx_passthru(void)
1409 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1412 /***********************************************************/
1415 static int usb_device_add(const char *devname
)
1417 USBDevice
*dev
= NULL
;
1418 #ifndef CONFIG_LINUX
1422 if (!machine_usb(current_machine
)) {
1426 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1427 dev
= usbdevice_create(devname
);
1431 /* the other ones */
1432 #ifndef CONFIG_LINUX
1433 /* only the linux version is qdev-ified, usb-bsd still needs this */
1434 if (strstart(devname
, "host:", &p
)) {
1435 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1445 static int usb_device_del(const char *devname
)
1450 if (strstart(devname
, "host:", &p
)) {
1454 if (!machine_usb(current_machine
)) {
1458 p
= strchr(devname
, '.');
1461 bus_num
= strtoul(devname
, NULL
, 0);
1462 addr
= strtoul(p
+ 1, NULL
, 0);
1464 return usb_device_delete_addr(bus_num
, addr
);
1467 static int usb_parse(const char *cmdline
)
1470 r
= usb_device_add(cmdline
);
1472 error_report("could not add USB device '%s'", cmdline
);
1477 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1479 const char *devname
= qdict_get_str(qdict
, "devname");
1480 if (usb_device_add(devname
) < 0) {
1481 error_report("could not add USB device '%s'", devname
);
1485 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1487 const char *devname
= qdict_get_str(qdict
, "devname");
1488 if (usb_device_del(devname
) < 0) {
1489 error_report("could not delete USB device '%s'", devname
);
1493 /***********************************************************/
1494 /* machine registration */
1496 MachineState
*current_machine
;
1498 static MachineClass
*find_machine(const char *name
)
1500 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1501 MachineClass
*mc
= NULL
;
1503 for (el
= machines
; el
; el
= el
->next
) {
1504 MachineClass
*temp
= el
->data
;
1506 if (!strcmp(temp
->name
, name
)) {
1511 !strcmp(temp
->alias
, name
)) {
1517 g_slist_free(machines
);
1521 MachineClass
*find_default_machine(void)
1523 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1524 MachineClass
*mc
= NULL
;
1526 for (el
= machines
; el
; el
= el
->next
) {
1527 MachineClass
*temp
= el
->data
;
1529 if (temp
->is_default
) {
1535 g_slist_free(machines
);
1539 MachineInfoList
*qmp_query_machines(Error
**errp
)
1541 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1542 MachineInfoList
*mach_list
= NULL
;
1544 for (el
= machines
; el
; el
= el
->next
) {
1545 MachineClass
*mc
= el
->data
;
1546 MachineInfoList
*entry
;
1549 info
= g_malloc0(sizeof(*info
));
1550 if (mc
->is_default
) {
1551 info
->has_is_default
= true;
1552 info
->is_default
= true;
1556 info
->has_alias
= true;
1557 info
->alias
= g_strdup(mc
->alias
);
1560 info
->name
= g_strdup(mc
->name
);
1561 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1562 info
->hotpluggable_cpus
= !!mc
->query_hotpluggable_cpus
;
1564 entry
= g_malloc0(sizeof(*entry
));
1565 entry
->value
= info
;
1566 entry
->next
= mach_list
;
1570 g_slist_free(machines
);
1574 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1576 ObjectProperty
*prop
;
1577 ObjectPropertyIterator iter
;
1579 if (!qemu_opt_has_help_opt(opts
)) {
1583 object_property_iter_init(&iter
, OBJECT(machine
));
1584 while ((prop
= object_property_iter_next(&iter
))) {
1589 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1590 prop
->name
, prop
->type
);
1591 if (prop
->description
) {
1592 error_printf(" (%s)\n", prop
->description
);
1601 /***********************************************************/
1602 /* main execution loop */
1604 struct vm_change_state_entry
{
1605 VMChangeStateHandler
*cb
;
1607 QLIST_ENTRY (vm_change_state_entry
) entries
;
1610 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1612 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1615 VMChangeStateEntry
*e
;
1617 e
= g_malloc0(sizeof (*e
));
1621 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1625 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1627 QLIST_REMOVE (e
, entries
);
1631 void vm_state_notify(int running
, RunState state
)
1633 VMChangeStateEntry
*e
, *next
;
1635 trace_vm_state_notify(running
, state
);
1637 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1638 e
->cb(e
->opaque
, running
, state
);
1642 /* reset/shutdown handler */
1644 typedef struct QEMUResetEntry
{
1645 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1646 QEMUResetHandler
*func
;
1650 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1651 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1652 static int reset_requested
;
1653 static int shutdown_requested
, shutdown_signal
= -1;
1654 static pid_t shutdown_pid
;
1655 static int powerdown_requested
;
1656 static int debug_requested
;
1657 static int suspend_requested
;
1658 static WakeupReason wakeup_reason
;
1659 static NotifierList powerdown_notifiers
=
1660 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1661 static NotifierList suspend_notifiers
=
1662 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1663 static NotifierList wakeup_notifiers
=
1664 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1665 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1667 int qemu_shutdown_requested_get(void)
1669 return shutdown_requested
;
1672 int qemu_reset_requested_get(void)
1674 return reset_requested
;
1677 static int qemu_shutdown_requested(void)
1679 return atomic_xchg(&shutdown_requested
, 0);
1682 static void qemu_kill_report(void)
1684 if (!qtest_driver() && shutdown_signal
!= -1) {
1685 if (shutdown_pid
== 0) {
1686 /* This happens for eg ^C at the terminal, so it's worth
1687 * avoiding printing an odd message in that case.
1689 error_report("terminating on signal %d", shutdown_signal
);
1691 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1693 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1694 shutdown_signal
, shutdown_pid
,
1695 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1696 g_free(shutdown_cmd
);
1698 shutdown_signal
= -1;
1702 static int qemu_reset_requested(void)
1704 int r
= reset_requested
;
1705 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1706 reset_requested
= 0;
1712 static int qemu_suspend_requested(void)
1714 int r
= suspend_requested
;
1715 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1716 suspend_requested
= 0;
1722 static WakeupReason
qemu_wakeup_requested(void)
1724 return wakeup_reason
;
1727 static int qemu_powerdown_requested(void)
1729 int r
= powerdown_requested
;
1730 powerdown_requested
= 0;
1734 static int qemu_debug_requested(void)
1736 int r
= debug_requested
;
1737 debug_requested
= 0;
1741 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1743 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1746 re
->opaque
= opaque
;
1747 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1750 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1754 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1755 if (re
->func
== func
&& re
->opaque
== opaque
) {
1756 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1763 void qemu_devices_reset(void)
1765 QEMUResetEntry
*re
, *nre
;
1767 /* reset all devices */
1768 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1769 re
->func(re
->opaque
);
1773 void qemu_system_reset(bool report
)
1777 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1779 cpu_synchronize_all_states();
1781 if (mc
&& mc
->reset
) {
1784 qemu_devices_reset();
1787 qapi_event_send_reset(&error_abort
);
1789 cpu_synchronize_all_post_reset();
1792 void qemu_system_guest_panicked(void)
1795 current_cpu
->crash_occurred
= true;
1797 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
, &error_abort
);
1798 vm_stop(RUN_STATE_GUEST_PANICKED
);
1800 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1802 qemu_system_shutdown_request();
1806 void qemu_system_reset_request(void)
1809 shutdown_requested
= 1;
1811 reset_requested
= 1;
1814 qemu_notify_event();
1817 static void qemu_system_suspend(void)
1820 notifier_list_notify(&suspend_notifiers
, NULL
);
1821 runstate_set(RUN_STATE_SUSPENDED
);
1822 qapi_event_send_suspend(&error_abort
);
1825 void qemu_system_suspend_request(void)
1827 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1830 suspend_requested
= 1;
1832 qemu_notify_event();
1835 void qemu_register_suspend_notifier(Notifier
*notifier
)
1837 notifier_list_add(&suspend_notifiers
, notifier
);
1840 void qemu_system_wakeup_request(WakeupReason reason
)
1842 trace_system_wakeup_request(reason
);
1844 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1847 if (!(wakeup_reason_mask
& (1 << reason
))) {
1850 runstate_set(RUN_STATE_RUNNING
);
1851 wakeup_reason
= reason
;
1852 qemu_notify_event();
1855 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1858 wakeup_reason_mask
|= (1 << reason
);
1860 wakeup_reason_mask
&= ~(1 << reason
);
1864 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1866 notifier_list_add(&wakeup_notifiers
, notifier
);
1869 void qemu_system_killed(int signal
, pid_t pid
)
1871 shutdown_signal
= signal
;
1875 /* Cannot call qemu_system_shutdown_request directly because
1876 * we are in a signal handler.
1878 shutdown_requested
= 1;
1879 qemu_notify_event();
1882 void qemu_system_shutdown_request(void)
1884 trace_qemu_system_shutdown_request();
1885 replay_shutdown_request();
1886 shutdown_requested
= 1;
1887 qemu_notify_event();
1890 static void qemu_system_powerdown(void)
1892 qapi_event_send_powerdown(&error_abort
);
1893 notifier_list_notify(&powerdown_notifiers
, NULL
);
1896 void qemu_system_powerdown_request(void)
1898 trace_qemu_system_powerdown_request();
1899 powerdown_requested
= 1;
1900 qemu_notify_event();
1903 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1905 notifier_list_add(&powerdown_notifiers
, notifier
);
1908 void qemu_system_debug_request(void)
1910 debug_requested
= 1;
1911 qemu_notify_event();
1914 static bool main_loop_should_exit(void)
1917 if (qemu_debug_requested()) {
1918 vm_stop(RUN_STATE_DEBUG
);
1920 if (qemu_suspend_requested()) {
1921 qemu_system_suspend();
1923 if (qemu_shutdown_requested()) {
1925 qapi_event_send_shutdown(&error_abort
);
1927 vm_stop(RUN_STATE_SHUTDOWN
);
1932 if (qemu_reset_requested()) {
1934 qemu_system_reset(VMRESET_REPORT
);
1936 if (!runstate_check(RUN_STATE_RUNNING
) &&
1937 !runstate_check(RUN_STATE_INMIGRATE
)) {
1938 runstate_set(RUN_STATE_PRELAUNCH
);
1941 if (qemu_wakeup_requested()) {
1943 qemu_system_reset(VMRESET_SILENT
);
1944 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1945 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1947 qapi_event_send_wakeup(&error_abort
);
1949 if (qemu_powerdown_requested()) {
1950 qemu_system_powerdown();
1952 if (qemu_vmstop_requested(&r
)) {
1958 static void main_loop(void)
1962 #ifdef CONFIG_PROFILER
1966 nonblocking
= tcg_enabled() && last_io
> 0;
1967 #ifdef CONFIG_PROFILER
1968 ti
= profile_getclock();
1970 last_io
= main_loop_wait(nonblocking
);
1971 #ifdef CONFIG_PROFILER
1972 dev_time
+= profile_getclock() - ti
;
1974 } while (!main_loop_should_exit());
1977 static void version(void)
1979 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1980 QEMU_COPYRIGHT
"\n");
1983 static void QEMU_NORETURN
help(int exitcode
)
1986 printf("usage: %s [options] [disk_image]\n\n"
1987 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1988 error_get_progname());
1990 #define QEMU_OPTIONS_GENERATE_HELP
1991 #include "qemu-options-wrapper.h"
1993 printf("\nDuring emulation, the following keys are useful:\n"
1994 "ctrl-alt-f toggle full screen\n"
1995 "ctrl-alt-n switch to virtual console 'n'\n"
1996 "ctrl-alt toggle mouse and keyboard grab\n"
1998 "When using -nographic, press 'ctrl-a h' to get some help.\n");
2003 #define HAS_ARG 0x0001
2005 typedef struct QEMUOption
{
2012 static const QEMUOption qemu_options
[] = {
2013 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
2014 #define QEMU_OPTIONS_GENERATE_OPTIONS
2015 #include "qemu-options-wrapper.h"
2019 typedef struct VGAInterfaceInfo
{
2020 const char *opt_name
; /* option name */
2021 const char *name
; /* human-readable name */
2022 /* Class names indicating that support is available.
2023 * If no class is specified, the interface is always available */
2024 const char *class_names
[2];
2027 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
2033 .name
= "standard VGA",
2034 .class_names
= { "VGA", "isa-vga" },
2037 .opt_name
= "cirrus",
2038 .name
= "Cirrus VGA",
2039 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
2042 .opt_name
= "vmware",
2043 .name
= "VMWare SVGA",
2044 .class_names
= { "vmware-svga" },
2047 .opt_name
= "virtio",
2048 .name
= "Virtio VGA",
2049 .class_names
= { "virtio-vga" },
2054 .class_names
= { "qxl-vga" },
2058 .name
= "TCX framebuffer",
2059 .class_names
= { "SUNW,tcx" },
2063 .name
= "CG3 framebuffer",
2064 .class_names
= { "cgthree" },
2067 .opt_name
= "xenfb",
2071 static bool vga_interface_available(VGAInterfaceType t
)
2073 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2075 assert(t
< VGA_TYPE_MAX
);
2076 return !ti
->class_names
[0] ||
2077 object_class_by_name(ti
->class_names
[0]) ||
2078 object_class_by_name(ti
->class_names
[1]);
2081 static void select_vgahw(const char *p
)
2086 assert(vga_interface_type
== VGA_NONE
);
2087 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2088 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2089 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2090 if (!vga_interface_available(t
)) {
2091 error_report("%s not available", ti
->name
);
2094 vga_interface_type
= t
;
2098 if (t
== VGA_TYPE_MAX
) {
2100 error_report("unknown vga type: %s", p
);
2104 const char *nextopt
;
2106 if (strstart(opts
, ",retrace=", &nextopt
)) {
2108 if (strstart(opts
, "dumb", &nextopt
))
2109 vga_retrace_method
= VGA_RETRACE_DUMB
;
2110 else if (strstart(opts
, "precise", &nextopt
))
2111 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2112 else goto invalid_vga
;
2113 } else goto invalid_vga
;
2118 typedef enum DisplayType
{
2127 static DisplayType
select_display(const char *p
)
2130 DisplayType display
= DT_DEFAULT
;
2132 if (strstart(p
, "sdl", &opts
)) {
2136 const char *nextopt
;
2138 if (strstart(opts
, ",frame=", &nextopt
)) {
2140 if (strstart(opts
, "on", &nextopt
)) {
2142 } else if (strstart(opts
, "off", &nextopt
)) {
2145 goto invalid_sdl_args
;
2147 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2149 if (strstart(opts
, "on", &nextopt
)) {
2151 } else if (strstart(opts
, "off", &nextopt
)) {
2154 goto invalid_sdl_args
;
2156 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2158 if (strstart(opts
, "on", &nextopt
)) {
2160 } else if (strstart(opts
, "off", &nextopt
)) {
2163 goto invalid_sdl_args
;
2165 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2167 if (strstart(opts
, "on", &nextopt
)) {
2169 } else if (strstart(opts
, "off", &nextopt
)) {
2172 goto invalid_sdl_args
;
2174 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2176 if (strstart(opts
, "on", &nextopt
)) {
2178 } else if (strstart(opts
, "off", &nextopt
)) {
2181 goto invalid_sdl_args
;
2185 error_report("invalid SDL option string");
2191 error_report("SDL support is disabled");
2194 } else if (strstart(p
, "vnc", &opts
)) {
2196 vnc_parse(opts
+ 1, &error_fatal
);
2198 error_report("VNC requires a display argument vnc=<display>");
2201 } else if (strstart(p
, "curses", &opts
)) {
2202 #ifdef CONFIG_CURSES
2203 display
= DT_CURSES
;
2205 error_report("curses support is disabled");
2208 } else if (strstart(p
, "gtk", &opts
)) {
2212 const char *nextopt
;
2214 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2216 if (strstart(opts
, "on", &nextopt
)) {
2217 grab_on_hover
= true;
2218 } else if (strstart(opts
, "off", &nextopt
)) {
2219 grab_on_hover
= false;
2221 goto invalid_gtk_args
;
2223 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2225 if (strstart(opts
, "on", &nextopt
)) {
2227 } else if (strstart(opts
, "off", &nextopt
)) {
2230 goto invalid_gtk_args
;
2234 error_report("invalid GTK option string");
2240 error_report("GTK support is disabled");
2243 } else if (strstart(p
, "none", &opts
)) {
2246 error_report("unknown display type");
2253 static int balloon_parse(const char *arg
)
2257 if (strcmp(arg
, "none") == 0) {
2261 if (!strncmp(arg
, "virtio", 6)) {
2262 if (arg
[6] == ',') {
2263 /* have params -> parse them */
2264 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2269 /* create empty opts */
2270 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2273 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2280 #if defined(CONFIG_RUBY)
2281 /* Ruby interface for QEMU. See README.EXT for programming example. */
2285 static VALUE
qemu_open(int argc
, VALUE
*argv
, VALUE klass
)
2288 for (i
= 0; i
< argc
; i
++) {
2289 argv
[i
] = StringValue(argv
[i
]);
2290 fprintf(stderr
, "argv[%d] = %s\n", i
, StringValuePtr(argv
[i
]));
2292 //~ if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
2293 //~ mode = 0666; /* default value */
2295 return INT2FIX(argc
);
2298 void Init_qemu(void)
2300 printf("%s\n", __func__
);
2301 VALUE cQEMU
= rb_define_class("QEMU", rb_cObject
);
2302 rb_define_singleton_method(cQEMU
, "run", qemu_open
, -1);
2307 #endif /* CONFIG_RUBY */
2309 #if defined(CONFIG_DLL)
2310 BOOL APIENTRY
DllMain(HINSTANCE hModule
, DWORD ul_reason_for_call
, LPVOID data
)
2314 #endif /* CONFIG_DLL */
2316 char *qemu_find_file(int type
, const char *name
)
2322 /* Try the name as a straight path first */
2323 if (access(name
, R_OK
) == 0) {
2324 trace_load_file(name
, name
);
2325 return g_strdup(name
);
2329 case QEMU_FILE_TYPE_BIOS
:
2332 case QEMU_FILE_TYPE_KEYMAP
:
2333 subdir
= "keymaps/";
2339 for (i
= 0; i
< data_dir_idx
; i
++) {
2340 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2341 if (access(buf
, R_OK
) == 0) {
2342 trace_load_file(name
, buf
);
2350 static inline bool nonempty_str(const char *str
)
2355 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2359 const char *name
, *file
, *str
;
2360 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2362 if (fw_cfg
== NULL
) {
2363 error_report("fw_cfg device not available");
2366 name
= qemu_opt_get(opts
, "name");
2367 file
= qemu_opt_get(opts
, "file");
2368 str
= qemu_opt_get(opts
, "string");
2370 /* we need name and either a file or the content string */
2371 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2372 error_report("invalid argument(s)");
2375 if (nonempty_str(file
) && nonempty_str(str
)) {
2376 error_report("file and string are mutually exclusive");
2379 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2380 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2383 if (strncmp(name
, "opt/", 4) != 0) {
2384 error_report("warning: externally provided fw_cfg item names "
2385 "should be prefixed with \"opt/\"");
2387 if (nonempty_str(str
)) {
2388 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2389 buf
= g_memdup(str
, size
);
2391 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2392 error_report("can't load %s", file
);
2396 /* For legacy, keep user files in a specific global order. */
2397 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2398 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2399 fw_cfg_reset_order_override(fw_cfg
);
2403 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2405 return qdev_device_help(opts
);
2408 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2413 dev
= qdev_device_add(opts
, &err
);
2415 error_report_err(err
);
2418 object_unref(OBJECT(dev
));
2422 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2424 Error
*local_err
= NULL
;
2426 qemu_chr_new_from_opts(opts
, &local_err
);
2428 error_report_err(local_err
);
2434 #ifdef CONFIG_VIRTFS
2435 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2437 return qemu_fsdev_add(opts
);
2441 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2443 CharDriverState
*chr
;
2444 const char *chardev
;
2448 mode
= qemu_opt_get(opts
, "mode");
2452 if (strcmp(mode
, "readline") == 0) {
2453 flags
= MONITOR_USE_READLINE
;
2454 } else if (strcmp(mode
, "control") == 0) {
2455 flags
= MONITOR_USE_CONTROL
;
2457 error_report("unknown monitor mode \"%s\"", mode
);
2461 if (qemu_opt_get_bool(opts
, "pretty", 0))
2462 flags
|= MONITOR_USE_PRETTY
;
2464 if (qemu_opt_get_bool(opts
, "default", 0)) {
2465 error_report("option 'default' does nothing and is deprecated");
2468 chardev
= qemu_opt_get(opts
, "chardev");
2469 chr
= qemu_chr_find(chardev
);
2471 error_report("chardev \"%s\" not found", chardev
);
2475 monitor_init(chr
, flags
);
2479 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2481 static int monitor_device_index
= 0;
2486 if (strstart(optarg
, "chardev:", &p
)) {
2487 snprintf(label
, sizeof(label
), "%s", p
);
2489 snprintf(label
, sizeof(label
), "compat_monitor%d",
2490 monitor_device_index
);
2491 opts
= qemu_chr_parse_compat(label
, optarg
);
2493 error_report("parse error: %s", optarg
);
2498 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2499 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2500 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2501 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2502 monitor_device_index
++;
2505 struct device_config
{
2507 DEV_USB
, /* -usbdevice */
2509 DEV_SERIAL
, /* -serial */
2510 DEV_PARALLEL
, /* -parallel */
2511 DEV_VIRTCON
, /* -virtioconsole */
2512 DEV_DEBUGCON
, /* -debugcon */
2513 DEV_GDB
, /* -gdb, -s */
2514 DEV_SCLP
, /* s390 sclp */
2516 const char *cmdline
;
2518 QTAILQ_ENTRY(device_config
) next
;
2521 static QTAILQ_HEAD(, device_config
) device_configs
=
2522 QTAILQ_HEAD_INITIALIZER(device_configs
);
2524 static void add_device_config(int type
, const char *cmdline
)
2526 struct device_config
*conf
;
2528 conf
= g_malloc0(sizeof(*conf
));
2530 conf
->cmdline
= cmdline
;
2531 loc_save(&conf
->loc
);
2532 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2535 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2537 struct device_config
*conf
;
2540 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2541 if (conf
->type
!= type
)
2543 loc_push_restore(&conf
->loc
);
2544 rc
= func(conf
->cmdline
);
2545 loc_pop(&conf
->loc
);
2553 static int serial_parse(const char *devname
)
2555 static int index
= 0;
2558 if (strcmp(devname
, "none") == 0)
2560 if (index
== MAX_SERIAL_PORTS
) {
2561 error_report("too many serial ports");
2564 snprintf(label
, sizeof(label
), "serial%d", index
);
2565 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2566 if (!serial_hds
[index
]) {
2567 error_report("could not connect serial device"
2568 " to character backend '%s'", devname
);
2575 static int parallel_parse(const char *devname
)
2577 static int index
= 0;
2580 if (strcmp(devname
, "none") == 0)
2582 if (index
== MAX_PARALLEL_PORTS
) {
2583 error_report("too many parallel ports");
2586 snprintf(label
, sizeof(label
), "parallel%d", index
);
2587 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2588 if (!parallel_hds
[index
]) {
2589 error_report("could not connect parallel device"
2590 " to character backend '%s'", devname
);
2597 static int virtcon_parse(const char *devname
)
2599 QemuOptsList
*device
= qemu_find_opts("device");
2600 static int index
= 0;
2602 QemuOpts
*bus_opts
, *dev_opts
;
2604 if (strcmp(devname
, "none") == 0)
2606 if (index
== MAX_VIRTIO_CONSOLES
) {
2607 error_report("too many virtio consoles");
2611 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2612 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2614 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2615 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2617 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2618 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2619 if (!virtcon_hds
[index
]) {
2620 error_report("could not connect virtio console"
2621 " to character backend '%s'", devname
);
2624 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2630 static int sclp_parse(const char *devname
)
2632 QemuOptsList
*device
= qemu_find_opts("device");
2633 static int index
= 0;
2637 if (strcmp(devname
, "none") == 0) {
2640 if (index
== MAX_SCLP_CONSOLES
) {
2641 error_report("too many sclp consoles");
2645 assert(arch_type
== QEMU_ARCH_S390X
);
2647 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2648 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2650 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2651 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2652 if (!sclp_hds
[index
]) {
2653 error_report("could not connect sclp console"
2654 " to character backend '%s'", devname
);
2657 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2663 static int debugcon_parse(const char *devname
)
2667 if (!qemu_chr_new("debugcon", devname
)) {
2670 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2672 error_report("already have a debugcon device");
2675 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2676 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2680 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2682 const MachineClass
*mc1
= a
, *mc2
= b
;
2685 if (mc1
->family
== NULL
) {
2686 if (mc2
->family
== NULL
) {
2687 /* Compare standalone machine types against each other; they sort
2688 * in increasing order.
2690 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2691 object_class_get_name(OBJECT_CLASS(mc2
)));
2694 /* Standalone machine types sort after families. */
2698 if (mc2
->family
== NULL
) {
2699 /* Families sort before standalone machine types. */
2703 /* Families sort between each other alphabetically increasingly. */
2704 res
= strcmp(mc1
->family
, mc2
->family
);
2709 /* Within the same family, machine types sort in decreasing order. */
2710 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2711 object_class_get_name(OBJECT_CLASS(mc1
)));
2714 static MachineClass
*machine_parse(const char *name
)
2716 MachineClass
*mc
= NULL
;
2717 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2720 mc
= find_machine(name
);
2723 g_slist_free(machines
);
2726 if (name
&& !is_help_option(name
)) {
2727 error_report("unsupported machine type");
2728 error_printf("Use -machine help to list supported machines\n");
2730 printf("Supported machines are:\n");
2731 machines
= g_slist_sort(machines
, machine_class_cmp
);
2732 for (el
= machines
; el
; el
= el
->next
) {
2733 MachineClass
*mc
= el
->data
;
2735 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2737 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2738 mc
->is_default
? " (default)" : "");
2742 g_slist_free(machines
);
2743 exit(!name
|| !is_help_option(name
));
2746 void qemu_add_exit_notifier(Notifier
*notify
)
2748 notifier_list_add(&exit_notifiers
, notify
);
2751 void qemu_remove_exit_notifier(Notifier
*notify
)
2753 notifier_remove(notify
);
2756 static void qemu_run_exit_notifiers(void)
2758 notifier_list_notify(&exit_notifiers
, NULL
);
2761 static bool machine_init_done
;
2763 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2765 notifier_list_add(&machine_init_done_notifiers
, notify
);
2766 if (machine_init_done
) {
2767 notify
->notify(notify
, NULL
);
2771 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2773 notifier_remove(notify
);
2776 static void qemu_run_machine_init_done_notifiers(void)
2778 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2779 machine_init_done
= true;
2782 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2783 const char **poptarg
, int *poptind
)
2785 const QEMUOption
*popt
;
2786 int optind
= *poptind
;
2787 char *r
= argv
[optind
];
2790 loc_set_cmdline(argv
, optind
, 1);
2792 /* Treat --foo the same as -foo. */
2795 popt
= qemu_options
;
2798 error_report("invalid option");
2801 if (!strcmp(popt
->name
, r
+ 1))
2805 if (popt
->flags
& HAS_ARG
) {
2806 if (optind
>= argc
) {
2807 error_report("requires an argument");
2810 optarg
= argv
[optind
++];
2811 loc_set_cmdline(argv
, optind
- 2, 2);
2822 static MachineClass
*select_machine(void)
2824 MachineClass
*machine_class
= find_default_machine();
2829 loc_push_none(&loc
);
2831 opts
= qemu_get_machine_opts();
2832 qemu_opts_loc_restore(opts
);
2834 optarg
= qemu_opt_get(opts
, "type");
2836 machine_class
= machine_parse(optarg
);
2839 if (!machine_class
) {
2840 error_report("No machine specified, and there is no default");
2841 error_printf("Use -machine help to list supported machines\n");
2846 return machine_class
;
2849 static int machine_set_property(void *opaque
,
2850 const char *name
, const char *value
,
2853 Object
*obj
= OBJECT(opaque
);
2854 Error
*local_err
= NULL
;
2857 if (strcmp(name
, "type") == 0) {
2861 qom_name
= g_strdup(name
);
2862 for (p
= qom_name
; *p
; p
++) {
2868 object_property_parse(obj
, value
, qom_name
, &local_err
);
2872 error_report_err(local_err
);
2881 * Initial object creation happens before all other
2882 * QEMU data types are created. The majority of objects
2883 * can be created at this point. The rng-egd object
2884 * cannot be created here, as it depends on the chardev
2887 static bool object_create_initial(const char *type
)
2889 if (g_str_equal(type
, "rng-egd")) {
2894 * return false for concrete netfilters since
2895 * they depend on netdevs already existing
2897 if (g_str_equal(type
, "filter-buffer") ||
2898 g_str_equal(type
, "filter-dump") ||
2899 g_str_equal(type
, "filter-mirror") ||
2900 g_str_equal(type
, "filter-redirector") ||
2901 g_str_equal(type
, "colo-compare") ||
2902 g_str_equal(type
, "filter-rewriter")) {
2906 /* Memory allocation by backends needs to be done
2907 * after configure_accelerator() (due to the tcg_enabled()
2908 * checks at memory_region_init_*()).
2910 * Also, allocation of large amounts of memory may delay
2911 * chardev initialization for too long, and trigger timeouts
2912 * on software that waits for a monitor socket to be created
2915 if (g_str_has_prefix(type
, "memory-backend-")) {
2924 * The remainder of object creation happens after the
2925 * creation of chardev, fsdev, net clients and device data types.
2927 static bool object_create_delayed(const char *type
)
2929 return !object_create_initial(type
);
2933 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2937 const char *mem_str
;
2938 const char *maxmem_str
, *slots_str
;
2939 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2940 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2943 loc_push_none(&loc
);
2944 qemu_opts_loc_restore(opts
);
2947 mem_str
= qemu_opt_get(opts
, "size");
2950 error_report("missing 'size' option value");
2954 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2956 /* Fix up legacy suffix-less format */
2957 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2958 uint64_t overflow_check
= sz
;
2961 if ((sz
>> 20) != overflow_check
) {
2962 error_report("too large 'size' option value");
2968 /* backward compatibility behaviour for case "-m 0" */
2970 sz
= default_ram_size
;
2973 sz
= QEMU_ALIGN_UP(sz
, 8192);
2975 if (ram_size
!= sz
) {
2976 error_report("ram size too large");
2980 /* store value for the future use */
2981 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2982 *maxram_size
= ram_size
;
2984 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2985 slots_str
= qemu_opt_get(opts
, "slots");
2986 if (maxmem_str
&& slots_str
) {
2989 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2990 slots
= qemu_opt_get_number(opts
, "slots", 0);
2991 if (sz
< ram_size
) {
2992 error_report("invalid value of -m option maxmem: "
2993 "maximum memory size (0x%" PRIx64
") must be at least "
2994 "the initial memory size (0x" RAM_ADDR_FMT
")",
2997 } else if (sz
> ram_size
) {
2999 error_report("invalid value of -m option: maxmem was "
3000 "specified, but no hotplug slots were specified");
3004 error_report("invalid value of -m option maxmem: "
3005 "memory slots were specified but maximum memory size "
3006 "(0x%" PRIx64
") is equal to the initial memory size "
3007 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
3013 } else if ((!maxmem_str
&& slots_str
) ||
3014 (maxmem_str
&& !slots_str
)) {
3015 error_report("invalid -m option value: missing "
3016 "'%s' option", slots_str
? "maxmem" : "slots");
3023 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
3027 g
= g_malloc0(sizeof(*g
));
3028 g
->driver
= qemu_opt_get(opts
, "driver");
3029 g
->property
= qemu_opt_get(opts
, "property");
3030 g
->value
= qemu_opt_get(opts
, "value");
3031 g
->user_provided
= true;
3032 g
->errp
= &error_fatal
;
3033 qdev_prop_register_global(g
);
3037 int main(int argc
, char **argv
)
3040 int snapshot
, linux_boot
;
3041 const char *initrd_filename
;
3042 const char *kernel_filename
, *kernel_cmdline
;
3043 const char *boot_order
= NULL
;
3044 const char *boot_once
= NULL
;
3046 int cyls
, heads
, secs
, translation
;
3047 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
3048 QemuOptsList
*olist
;
3051 const char *loadvm
= NULL
;
3052 MachineClass
*machine_class
;
3053 const char *cpu_model
;
3054 const char *vga_model
= NULL
;
3055 const char *qtest_chrdev
= NULL
;
3056 const char *qtest_log
= NULL
;
3057 const char *pid_file
= NULL
;
3058 const char *incoming
= NULL
;
3059 bool defconfig
= true;
3060 bool userconfig
= true;
3061 bool nographic
= false;
3062 DisplayType display_type
= DT_DEFAULT
;
3063 int display_remote
= 0;
3064 const char *log_mask
= NULL
;
3065 const char *log_file
= NULL
;
3066 char *trace_file
= NULL
;
3067 ram_addr_t maxram_size
;
3068 uint64_t ram_slots
= 0;
3069 FILE *vmstate_dump_file
= NULL
;
3070 Error
*main_loop_err
= NULL
;
3072 bool list_data_dirs
= false;
3074 module_call_init(MODULE_INIT_TRACE
);
3076 qemu_init_cpu_list();
3077 qemu_init_cpu_loop();
3078 qemu_mutex_lock_iothread();
3080 atexit(qemu_run_exit_notifiers
);
3081 error_set_progname(argv
[0]);
3082 qemu_init_exec_dir(argv
[0]);
3084 module_call_init(MODULE_INIT_QOM
);
3085 module_call_init(MODULE_INIT_QAPI
);
3087 qemu_add_opts(&qemu_drive_opts
);
3088 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3089 qemu_add_drive_opts(&qemu_common_drive_opts
);
3090 qemu_add_drive_opts(&qemu_drive_opts
);
3091 qemu_add_drive_opts(&bdrv_runtime_opts
);
3092 qemu_add_opts(&qemu_chardev_opts
);
3093 qemu_add_opts(&qemu_device_opts
);
3094 qemu_add_opts(&qemu_netdev_opts
);
3095 qemu_add_opts(&qemu_net_opts
);
3096 qemu_add_opts(&qemu_rtc_opts
);
3097 qemu_add_opts(&qemu_global_opts
);
3098 qemu_add_opts(&qemu_mon_opts
);
3099 qemu_add_opts(&qemu_trace_opts
);
3100 qemu_add_opts(&qemu_option_rom_opts
);
3101 qemu_add_opts(&qemu_machine_opts
);
3102 qemu_add_opts(&qemu_mem_opts
);
3103 qemu_add_opts(&qemu_smp_opts
);
3104 qemu_add_opts(&qemu_boot_opts
);
3105 qemu_add_opts(&qemu_sandbox_opts
);
3106 qemu_add_opts(&qemu_add_fd_opts
);
3107 qemu_add_opts(&qemu_object_opts
);
3108 qemu_add_opts(&qemu_tpmdev_opts
);
3109 qemu_add_opts(&qemu_realtime_opts
);
3110 qemu_add_opts(&qemu_msg_opts
);
3111 qemu_add_opts(&qemu_name_opts
);
3112 qemu_add_opts(&qemu_numa_opts
);
3113 qemu_add_opts(&qemu_icount_opts
);
3114 qemu_add_opts(&qemu_semihosting_config_opts
);
3115 qemu_add_opts(&qemu_fw_cfg_opts
);
3116 #ifdef CONFIG_LIBISCSI
3117 qemu_add_opts(&qemu_iscsi_opts
);
3119 module_call_init(MODULE_INIT_OPTS
);
3123 if (qcrypto_init(&err
) < 0) {
3124 error_reportf_err(err
, "cannot initialize crypto: ");
3127 rtc_clock
= QEMU_CLOCK_HOST
;
3129 QLIST_INIT (&vm_change_state_head
);
3130 os_setup_early_signal_handling();
3134 cyls
= heads
= secs
= 0;
3135 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3139 bdrv_init_with_whitelist();
3143 /* first pass of option parsing */
3145 while (optind
< argc
) {
3146 if (argv
[optind
][0] != '-') {
3150 const QEMUOption
*popt
;
3152 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3153 switch (popt
->index
) {
3154 case QEMU_OPTION_nodefconfig
:
3157 case QEMU_OPTION_nouserconfig
:
3166 ret
= qemu_read_default_config_files(userconfig
);
3172 /* second pass of option parsing */
3177 if (argv
[optind
][0] != '-') {
3178 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3180 const QEMUOption
*popt
;
3182 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3183 if (!(popt
->arch_mask
& arch_type
)) {
3184 error_report("Option not supported for this target");
3187 switch(popt
->index
) {
3188 case QEMU_OPTION_no_kvm_irqchip
: {
3189 olist
= qemu_find_opts("machine");
3190 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3193 case QEMU_OPTION_cpu
:
3194 /* hw initialization will check this */
3197 case QEMU_OPTION_hda
:
3201 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3203 snprintf(buf
, sizeof(buf
),
3204 "%s,cyls=%d,heads=%d,secs=%d%s",
3205 HD_OPTS
, cyls
, heads
, secs
,
3206 translation
== BIOS_ATA_TRANSLATION_LBA
?
3208 translation
== BIOS_ATA_TRANSLATION_NONE
?
3209 ",trans=none" : "");
3210 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3213 case QEMU_OPTION_hdb
:
3214 case QEMU_OPTION_hdc
:
3215 case QEMU_OPTION_hdd
:
3216 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3219 case QEMU_OPTION_drive
:
3220 if (drive_def(optarg
) == NULL
) {
3224 case QEMU_OPTION_set
:
3225 if (qemu_set_option(optarg
) != 0)
3228 case QEMU_OPTION_global
:
3229 if (qemu_global_option(optarg
) != 0)
3232 case QEMU_OPTION_mtdblock
:
3233 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3235 case QEMU_OPTION_sd
:
3236 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3238 case QEMU_OPTION_pflash
:
3239 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3241 case QEMU_OPTION_snapshot
:
3244 case QEMU_OPTION_hdachs
:
3248 cyls
= strtol(p
, (char **)&p
, 0);
3249 if (cyls
< 1 || cyls
> 16383)
3254 heads
= strtol(p
, (char **)&p
, 0);
3255 if (heads
< 1 || heads
> 16)
3260 secs
= strtol(p
, (char **)&p
, 0);
3261 if (secs
< 1 || secs
> 63)
3265 if (!strcmp(p
, "large")) {
3266 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3267 } else if (!strcmp(p
, "rechs")) {
3268 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3269 } else if (!strcmp(p
, "none")) {
3270 translation
= BIOS_ATA_TRANSLATION_NONE
;
3271 } else if (!strcmp(p
, "lba")) {
3272 translation
= BIOS_ATA_TRANSLATION_LBA
;
3273 } else if (!strcmp(p
, "auto")) {
3274 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3278 } else if (*p
!= '\0') {
3280 error_report("invalid physical CHS format");
3283 if (hda_opts
!= NULL
) {
3284 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3286 qemu_opt_set_number(hda_opts
, "heads", heads
,
3288 qemu_opt_set_number(hda_opts
, "secs", secs
,
3290 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3291 qemu_opt_set(hda_opts
, "trans", "large",
3293 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3294 qemu_opt_set(hda_opts
, "trans", "rechs",
3296 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3297 qemu_opt_set(hda_opts
, "trans", "lba",
3299 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3300 qemu_opt_set(hda_opts
, "trans", "none",
3306 case QEMU_OPTION_numa
:
3307 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3313 case QEMU_OPTION_display
:
3314 display_type
= select_display(optarg
);
3316 case QEMU_OPTION_nographic
:
3317 olist
= qemu_find_opts("machine");
3318 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3320 display_type
= DT_NONE
;
3322 case QEMU_OPTION_curses
:
3323 #ifdef CONFIG_CURSES
3324 display_type
= DT_CURSES
;
3326 error_report("curses support is disabled");
3330 case QEMU_OPTION_portrait
:
3331 graphic_rotate
= 90;
3333 case QEMU_OPTION_rotate
:
3334 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3335 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3336 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3337 error_report("only 90, 180, 270 deg rotation is available");
3341 case QEMU_OPTION_kernel
:
3342 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3345 case QEMU_OPTION_initrd
:
3346 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3349 case QEMU_OPTION_append
:
3350 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3353 case QEMU_OPTION_dtb
:
3354 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3357 case QEMU_OPTION_cdrom
:
3358 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3360 case QEMU_OPTION_boot
:
3361 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3367 case QEMU_OPTION_fda
:
3368 case QEMU_OPTION_fdb
:
3369 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3372 case QEMU_OPTION_no_fd_bootchk
:
3375 case QEMU_OPTION_netdev
:
3377 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3381 case QEMU_OPTION_net
:
3383 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3387 #ifdef CONFIG_LIBISCSI
3388 case QEMU_OPTION_iscsi
:
3389 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3397 case QEMU_OPTION_tftp
:
3398 error_report("The -tftp option is deprecated. "
3399 "Please use '-netdev user,tftp=...' instead.");
3400 legacy_tftp_prefix
= optarg
;
3402 case QEMU_OPTION_bootp
:
3403 error_report("The -bootp option is deprecated. "
3404 "Please use '-netdev user,bootfile=...' instead.");
3405 legacy_bootp_filename
= optarg
;
3407 case QEMU_OPTION_redir
:
3408 error_report("The -redir option is deprecated. "
3409 "Please use '-netdev user,hostfwd=...' instead.");
3410 if (net_slirp_redir(optarg
) < 0)
3414 case QEMU_OPTION_bt
:
3415 add_device_config(DEV_BT
, optarg
);
3417 case QEMU_OPTION_audio_help
:
3421 case QEMU_OPTION_soundhw
:
3422 select_soundhw (optarg
);
3427 case QEMU_OPTION_version
:
3432 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3439 case QEMU_OPTION_tpmdev
:
3440 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3445 case QEMU_OPTION_mempath
:
3448 case QEMU_OPTION_mem_prealloc
:
3457 case QEMU_OPTION_DFILTER
:
3458 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3461 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3463 case QEMU_OPTION_gdb
:
3464 add_device_config(DEV_GDB
, optarg
);
3467 if (is_help_option(optarg
)) {
3468 list_data_dirs
= true;
3469 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3470 data_dir
[data_dir_idx
++] = optarg
;
3473 case QEMU_OPTION_bios
:
3474 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3477 case QEMU_OPTION_singlestep
:
3484 keyboard_layout
= optarg
;
3486 case QEMU_OPTION_localtime
:
3489 case QEMU_OPTION_vga
:
3498 w
= strtol(p
, (char **)&p
, 10);
3501 error_report("invalid resolution or depth");
3507 h
= strtol(p
, (char **)&p
, 10);
3512 depth
= strtol(p
, (char **)&p
, 10);
3513 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3514 depth
!= 24 && depth
!= 32)
3516 } else if (*p
== '\0') {
3517 depth
= graphic_depth
;
3524 graphic_depth
= depth
;
3527 case QEMU_OPTION_echr
:
3530 term_escape_char
= strtol(optarg
, &r
, 0);
3532 printf("Bad argument to echr\n");
3535 case QEMU_OPTION_monitor
:
3536 default_monitor
= 0;
3537 if (strncmp(optarg
, "none", 4)) {
3538 monitor_parse(optarg
, "readline", false);
3541 case QEMU_OPTION_qmp
:
3542 monitor_parse(optarg
, "control", false);
3543 default_monitor
= 0;
3545 case QEMU_OPTION_qmp_pretty
:
3546 monitor_parse(optarg
, "control", true);
3547 default_monitor
= 0;
3549 case QEMU_OPTION_mon
:
3550 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3555 default_monitor
= 0;
3557 case QEMU_OPTION_chardev
:
3558 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3564 case QEMU_OPTION_fsdev
:
3565 olist
= qemu_find_opts("fsdev");
3567 error_report("fsdev support is disabled");
3570 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3575 case QEMU_OPTION_virtfs
: {
3578 const char *writeout
, *sock_fd
, *socket
;
3580 olist
= qemu_find_opts("virtfs");
3582 error_report("virtfs support is disabled");
3585 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3590 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3591 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3592 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3595 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3596 qemu_opt_get(opts
, "mount_tag"),
3599 error_report("duplicate fsdev id: %s",
3600 qemu_opt_get(opts
, "mount_tag"));
3604 writeout
= qemu_opt_get(opts
, "writeout");
3606 #ifdef CONFIG_SYNC_FILE_RANGE
3607 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3609 error_report("writeout=immediate not supported "
3610 "on this platform");
3614 qemu_opt_set(fsdev
, "fsdriver",
3615 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3616 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3618 qemu_opt_set(fsdev
, "security_model",
3619 qemu_opt_get(opts
, "security_model"),
3621 socket
= qemu_opt_get(opts
, "socket");
3623 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3625 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3627 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3630 qemu_opt_set_bool(fsdev
, "readonly",
3631 qemu_opt_get_bool(opts
, "readonly", 0),
3633 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3635 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3636 qemu_opt_set(device
, "fsdev",
3637 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3638 qemu_opt_set(device
, "mount_tag",
3639 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3642 case QEMU_OPTION_virtfs_synth
: {
3646 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3649 error_report("duplicate option: %s", "virtfs_synth");
3652 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3654 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3656 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3657 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3658 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3661 case QEMU_OPTION_serial
:
3662 add_device_config(DEV_SERIAL
, optarg
);
3664 if (strncmp(optarg
, "mon:", 4) == 0) {
3665 default_monitor
= 0;
3668 case QEMU_OPTION_watchdog
:
3670 error_report("only one watchdog option may be given");
3675 case QEMU_OPTION_watchdog_action
:
3676 if (select_watchdog_action(optarg
) == -1) {
3677 error_report("unknown -watchdog-action parameter");
3681 case QEMU_OPTION_virtiocon
:
3682 add_device_config(DEV_VIRTCON
, optarg
);
3683 default_virtcon
= 0;
3684 if (strncmp(optarg
, "mon:", 4) == 0) {
3685 default_monitor
= 0;
3688 case QEMU_OPTION_parallel
:
3689 add_device_config(DEV_PARALLEL
, optarg
);
3690 default_parallel
= 0;
3691 if (strncmp(optarg
, "mon:", 4) == 0) {
3692 default_monitor
= 0;
3695 case QEMU_OPTION_debugcon
:
3696 add_device_config(DEV_DEBUGCON
, optarg
);
3698 case QEMU_OPTION_loadvm
:
3701 case QEMU_OPTION_full_screen
:
3704 case QEMU_OPTION_no_frame
:
3707 case QEMU_OPTION_alt_grab
:
3710 case QEMU_OPTION_ctrl_grab
:
3713 case QEMU_OPTION_no_quit
:
3716 case QEMU_OPTION_sdl
:
3718 display_type
= DT_SDL
;
3721 error_report("SDL support is disabled");
3724 case QEMU_OPTION_pidfile
:
3727 case QEMU_OPTION_win2k_hack
:
3728 win2k_install_hack
= 1;
3730 case QEMU_OPTION_rtc_td_hack
: {
3731 static GlobalProperty slew_lost_ticks
= {
3732 .driver
= "mc146818rtc",
3733 .property
= "lost_tick_policy",
3737 qdev_prop_register_global(&slew_lost_ticks
);
3740 case QEMU_OPTION_acpitable
:
3741 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3746 do_acpitable_option(opts
);
3748 case QEMU_OPTION_smbios
:
3749 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3754 do_smbios_option(opts
);
3756 case QEMU_OPTION_fwcfg
:
3757 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3763 case QEMU_OPTION_enable_kvm
:
3764 olist
= qemu_find_opts("machine");
3765 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3767 case QEMU_OPTION_enable_hax
:
3768 olist
= qemu_find_opts("machine");
3769 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3772 case QEMU_OPTION_machine
:
3773 olist
= qemu_find_opts("machine");
3774 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3779 case QEMU_OPTION_no_kvm
:
3780 olist
= qemu_find_opts("machine");
3781 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3783 case QEMU_OPTION_no_kvm_pit
: {
3784 error_report("warning: ignoring deprecated option");
3787 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3788 static GlobalProperty kvm_pit_lost_tick_policy
= {
3789 .driver
= "kvm-pit",
3790 .property
= "lost_tick_policy",
3794 error_report("warning: deprecated, replaced by "
3795 "-global kvm-pit.lost_tick_policy=discard");
3796 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3799 case QEMU_OPTION_usb
:
3800 olist
= qemu_find_opts("machine");
3801 qemu_opts_parse_noisily(olist
, "usb=on", false);
3803 case QEMU_OPTION_usbdevice
:
3804 olist
= qemu_find_opts("machine");
3805 qemu_opts_parse_noisily(olist
, "usb=on", false);
3806 add_device_config(DEV_USB
, optarg
);
3808 case QEMU_OPTION_device
:
3809 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3814 case QEMU_OPTION_smp
:
3815 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3820 case QEMU_OPTION_vnc
:
3821 vnc_parse(optarg
, &error_fatal
);
3823 case QEMU_OPTION_no_acpi
:
3826 case QEMU_OPTION_no_hpet
:
3829 case QEMU_OPTION_balloon
:
3830 if (balloon_parse(optarg
) < 0) {
3831 error_report("unknown -balloon argument %s", optarg
);
3835 case QEMU_OPTION_no_reboot
:
3838 case QEMU_OPTION_no_shutdown
:
3841 case QEMU_OPTION_show_cursor
:
3844 case QEMU_OPTION_uuid
:
3845 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3846 error_report("failed to parse UUID string: wrong format");
3849 qemu_uuid_set
= true;
3851 case QEMU_OPTION_option_rom
:
3852 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3853 error_report("too many option ROMs");
3856 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3861 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3862 option_rom
[nb_option_roms
].bootindex
=
3863 qemu_opt_get_number(opts
, "bootindex", -1);
3864 if (!option_rom
[nb_option_roms
].name
) {
3865 error_report("Option ROM file is not specified");
3870 case QEMU_OPTION_semihosting
:
3871 semihosting
.enabled
= true;
3872 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3874 case QEMU_OPTION_semihosting_config
:
3875 semihosting
.enabled
= true;
3876 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3879 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3881 const char *target
= qemu_opt_get(opts
, "target");
3882 if (target
!= NULL
) {
3883 if (strcmp("native", target
) == 0) {
3884 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3885 } else if (strcmp("gdb", target
) == 0) {
3886 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3887 } else if (strcmp("auto", target
) == 0) {
3888 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3890 error_report("unsupported semihosting-config %s",
3895 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3897 /* Set semihosting argument count and vector */
3898 qemu_opt_foreach(opts
, add_semihosting_arg
,
3899 &semihosting
, NULL
);
3901 error_report("unsupported semihosting-config %s", optarg
);
3905 case QEMU_OPTION_tdf
:
3906 error_report("warning: ignoring deprecated option");
3908 case QEMU_OPTION_name
:
3909 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3915 case QEMU_OPTION_prom_env
:
3916 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3917 error_report("too many prom variables");
3920 prom_envs
[nb_prom_envs
] = optarg
;
3923 case QEMU_OPTION_old_param
:
3926 case QEMU_OPTION_clock
:
3927 /* Clock options no longer exist. Keep this option for
3928 * backward compatibility.
3931 case QEMU_OPTION_startdate
:
3932 configure_rtc_date_offset(optarg
, 1);
3934 case QEMU_OPTION_rtc
:
3935 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3940 configure_rtc(opts
);
3942 case QEMU_OPTION_tb_size
:
3943 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3944 if (tcg_tb_size
< 0) {
3948 case QEMU_OPTION_icount
:
3949 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3955 case QEMU_OPTION_incoming
:
3957 runstate_set(RUN_STATE_INMIGRATE
);
3961 case QEMU_OPTION_nodefaults
:
3964 case QEMU_OPTION_xen_domid
:
3965 if (!(xen_available())) {
3966 error_report("Option not supported for this target");
3969 xen_domid
= atoi(optarg
);
3971 case QEMU_OPTION_xen_create
:
3972 if (!(xen_available())) {
3973 error_report("Option not supported for this target");
3976 xen_mode
= XEN_CREATE
;
3978 case QEMU_OPTION_xen_attach
:
3979 if (!(xen_available())) {
3980 error_report("Option not supported for this target");
3983 xen_mode
= XEN_ATTACH
;
3985 case QEMU_OPTION_trace
:
3987 trace_file
= trace_opt_parse(optarg
);
3989 case QEMU_OPTION_trace_unassigned
:
3990 trace_unassigned
= true;
3992 case QEMU_OPTION_readconfig
:
3994 int ret
= qemu_read_config_file(optarg
);
3996 error_report("read config %s: %s", optarg
,
4002 case QEMU_OPTION_spice
:
4003 olist
= qemu_find_opts("spice");
4005 error_report("spice support is disabled");
4008 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
4014 case QEMU_OPTION_writeconfig
:
4017 if (strcmp(optarg
, "-") == 0) {
4020 fp
= fopen(optarg
, "w");
4022 error_report("open %s: %s", optarg
,
4027 qemu_config_write(fp
);
4033 case QEMU_OPTION_qtest
:
4034 qtest_chrdev
= optarg
;
4036 case QEMU_OPTION_qtest_log
:
4039 case QEMU_OPTION_sandbox
:
4040 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4046 case QEMU_OPTION_add_fd
:
4048 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4054 error_report("File descriptor passing is disabled on this "
4059 case QEMU_OPTION_object
:
4060 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
4066 case QEMU_OPTION_realtime
:
4067 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4072 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4074 case QEMU_OPTION_msg
:
4075 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4080 configure_msg(opts
);
4082 case QEMU_OPTION_dump_vmstate
:
4083 if (vmstate_dump_file
) {
4084 error_report("only one '-dump-vmstate' "
4085 "option may be given");
4088 vmstate_dump_file
= fopen(optarg
, "w");
4089 if (vmstate_dump_file
== NULL
) {
4090 error_report("open %s: %s", optarg
, strerror(errno
));
4095 os_parse_cmd_args(popt
->index
, optarg
);
4100 * Clear error location left behind by the loop.
4101 * Best done right after the loop. Do not insert code here!
4105 replay_configure(icount_opts
);
4107 machine_class
= select_machine();
4109 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4113 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4114 error_report("could not acquire pid file: %s", strerror(errno
));
4118 if (qemu_init_main_loop(&main_loop_err
)) {
4119 error_report_err(main_loop_err
);
4123 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4124 parse_sandbox
, NULL
, NULL
)) {
4128 if (qemu_opts_foreach(qemu_find_opts("name"),
4129 parse_name
, NULL
, NULL
)) {
4134 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4135 parse_add_fd
, NULL
, NULL
)) {
4139 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4140 cleanup_add_fd
, NULL
, NULL
)) {
4145 current_machine
= MACHINE(object_new(object_class_get_name(
4146 OBJECT_CLASS(machine_class
))));
4147 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4150 object_property_add_child(object_get_root(), "machine",
4151 OBJECT(current_machine
), &error_abort
);
4153 if (machine_class
->minimum_page_bits
) {
4154 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4155 /* This would be a board error: specifying a minimum smaller than
4156 * a target's compile-time fixed setting.
4158 g_assert_not_reached();
4162 cpu_exec_init_all();
4164 if (machine_class
->hw_version
) {
4165 qemu_set_hw_version(machine_class
->hw_version
);
4168 if (cpu_model
&& is_help_option(cpu_model
)) {
4169 list_cpus(stdout
, &fprintf
, cpu_model
);
4173 if (!trace_init_backends()) {
4176 trace_init_file(trace_file
);
4178 /* Open the logfile at this point and set the log mask if necessary.
4181 qemu_set_log_filename(log_file
, &error_fatal
);
4186 mask
= qemu_str_to_log_mask(log_mask
);
4188 qemu_print_log_usage(stdout
);
4196 /* If no data_dir is specified then try to find it relative to the
4198 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4199 data_dir
[data_dir_idx
] = os_find_datadir();
4200 if (data_dir
[data_dir_idx
] != NULL
) {
4204 /* If all else fails use the install path specified when building. */
4205 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4206 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4209 /* -L help lists the data directories and exits. */
4210 if (list_data_dirs
) {
4211 for (i
= 0; i
< data_dir_idx
; i
++) {
4212 printf("%s\n", data_dir
[i
]);
4217 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4219 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4220 if (max_cpus
> machine_class
->max_cpus
) {
4221 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4222 "supported by machine '%s' (%d)", max_cpus
,
4223 machine_class
->name
, machine_class
->max_cpus
);
4228 * Get the default machine options from the machine if it is not already
4229 * specified either by the configuration file or by the command line.
4231 if (machine_class
->default_machine_opts
) {
4232 qemu_opts_set_defaults(qemu_find_opts("machine"),
4233 machine_class
->default_machine_opts
, 0);
4236 qemu_opts_foreach(qemu_find_opts("device"),
4237 default_driver_check
, NULL
, NULL
);
4238 qemu_opts_foreach(qemu_find_opts("global"),
4239 default_driver_check
, NULL
, NULL
);
4241 if (!vga_model
&& !default_vga
) {
4242 vga_interface_type
= VGA_DEVICE
;
4244 if (!has_defaults
|| machine_class
->no_serial
) {
4247 if (!has_defaults
|| machine_class
->no_parallel
) {
4248 default_parallel
= 0;
4250 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4251 default_virtcon
= 0;
4253 if (!has_defaults
|| !machine_class
->use_sclp
) {
4256 if (!has_defaults
|| machine_class
->no_floppy
) {
4259 if (!has_defaults
|| machine_class
->no_cdrom
) {
4262 if (!has_defaults
|| machine_class
->no_sdcard
) {
4265 if (!has_defaults
) {
4266 default_monitor
= 0;
4271 if (is_daemonized()) {
4272 /* According to documentation and historically, -nographic redirects
4273 * serial port, parallel port and monitor to stdio, which does not work
4274 * with -daemonize. We can redirect these to null instead, but since
4275 * -nographic is legacy, let's just error out.
4276 * We disallow -nographic only if all other ports are not redirected
4277 * explicitly, to not break existing legacy setups which uses
4278 * -nographic _and_ redirects all ports explicitly - this is valid
4279 * usage, -nographic is just a no-op in this case.
4282 && (default_parallel
|| default_serial
4283 || default_monitor
|| default_virtcon
)) {
4284 error_report("-nographic cannot be used with -daemonize");
4287 #ifdef CONFIG_CURSES
4288 if (display_type
== DT_CURSES
) {
4289 error_report("curses display cannot be used with -daemonize");
4296 if (default_parallel
)
4297 add_device_config(DEV_PARALLEL
, "null");
4298 if (default_serial
&& default_monitor
) {
4299 add_device_config(DEV_SERIAL
, "mon:stdio");
4300 } else if (default_virtcon
&& default_monitor
) {
4301 add_device_config(DEV_VIRTCON
, "mon:stdio");
4302 } else if (default_sclp
&& default_monitor
) {
4303 add_device_config(DEV_SCLP
, "mon:stdio");
4306 add_device_config(DEV_SERIAL
, "stdio");
4307 if (default_virtcon
)
4308 add_device_config(DEV_VIRTCON
, "stdio");
4310 add_device_config(DEV_SCLP
, "stdio");
4312 if (default_monitor
)
4313 monitor_parse("stdio", "readline", false);
4317 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4318 if (default_parallel
)
4319 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4320 if (default_monitor
)
4321 monitor_parse("vc:80Cx24C", "readline", false);
4322 if (default_virtcon
)
4323 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4325 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4329 #if defined(CONFIG_VNC)
4330 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4334 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4335 #if defined(CONFIG_GTK)
4336 display_type
= DT_GTK
;
4337 #elif defined(CONFIG_SDL)
4338 display_type
= DT_SDL
;
4339 #elif defined(CONFIG_COCOA)
4340 display_type
= DT_COCOA
;
4341 #elif defined(CONFIG_VNC)
4342 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4344 display_type
= DT_NONE
;
4348 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4349 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4350 "for SDL, ignoring option");
4352 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4353 error_report("-no-quit is only valid for GTK and SDL, "
4357 if (display_type
== DT_GTK
) {
4358 early_gtk_display_init(request_opengl
);
4361 if (display_type
== DT_SDL
) {
4362 sdl_display_early_init(request_opengl
);
4365 if (request_opengl
== 1 && display_opengl
== 0) {
4366 #if defined(CONFIG_OPENGL)
4367 error_report("OpenGL is not supported by the display");
4369 error_report("OpenGL support is disabled");
4377 if (qemu_opts_foreach(qemu_find_opts("object"),
4378 user_creatable_add_opts_foreach
,
4379 object_create_initial
, NULL
)) {
4383 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4384 chardev_init_func
, NULL
, NULL
)) {
4388 #ifdef CONFIG_VIRTFS
4389 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4390 fsdev_init_func
, NULL
, NULL
)) {
4395 if (qemu_opts_foreach(qemu_find_opts("device"),
4396 device_help_func
, NULL
, NULL
)) {
4400 machine_opts
= qemu_get_machine_opts();
4401 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4403 object_unref(OBJECT(current_machine
));
4407 configure_accelerator(current_machine
);
4410 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4413 machine_opts
= qemu_get_machine_opts();
4414 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4415 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4416 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4417 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4419 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4421 boot_order
= qemu_opt_get(opts
, "order");
4423 validate_bootdevices(boot_order
, &error_fatal
);
4426 boot_once
= qemu_opt_get(opts
, "once");
4428 validate_bootdevices(boot_once
, &error_fatal
);
4431 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4432 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4436 boot_order
= machine_class
->default_boot_order
;
4439 if (!kernel_cmdline
) {
4440 kernel_cmdline
= "";
4441 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4444 linux_boot
= (kernel_filename
!= NULL
);
4446 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4447 error_report("-append only allowed with -kernel option");
4451 if (!linux_boot
&& initrd_filename
!= NULL
) {
4452 error_report("-initrd only allowed with -kernel option");
4456 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4457 /* fall back to the -kernel/-append */
4458 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4461 os_set_line_buffering();
4463 /* spice needs the timers to be initialized by this point */
4468 if (!tcg_enabled()) {
4469 error_report("-icount is not allowed with hardware virtualization");
4472 configure_icount(icount_opts
, &error_abort
);
4473 qemu_opts_del(icount_opts
);
4477 QemuOptsList
*net
= qemu_find_opts("net");
4478 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4480 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4486 if (net_init_clients() < 0) {
4490 if (qemu_opts_foreach(qemu_find_opts("object"),
4491 user_creatable_add_opts_foreach
,
4492 object_create_delayed
, NULL
)) {
4497 if (tpm_init() < 0) {
4502 /* init the bluetooth world */
4503 if (foreach_device_config(DEV_BT
, bt_parse
))
4506 if (!xen_enabled()) {
4507 /* On 32-bit hosts, QEMU is limited by virtual address space */
4508 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4509 error_report("at most 2047 MB RAM can be simulated");
4517 /* If the currently selected machine wishes to override the units-per-bus
4518 * property of its default HBA interface type, do so now. */
4519 if (machine_class
->units_per_default_bus
) {
4520 override_max_devs(machine_class
->block_default_type
,
4521 machine_class
->units_per_default_bus
);
4524 /* open the virtual block devices */
4525 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4526 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4529 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4530 &machine_class
->block_default_type
, NULL
)) {
4534 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4536 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4537 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4539 parse_numa_opts(machine_class
);
4541 if (qemu_opts_foreach(qemu_find_opts("mon"),
4542 mon_init_func
, NULL
, NULL
)) {
4546 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4548 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4550 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4552 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4555 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4558 /* If no default VGA is requested, the default is "none". */
4560 if (machine_class
->default_display
) {
4561 vga_model
= machine_class
->default_display
;
4562 } else if (vga_interface_available(VGA_CIRRUS
)) {
4563 vga_model
= "cirrus";
4564 } else if (vga_interface_available(VGA_STD
)) {
4569 select_vgahw(vga_model
);
4573 i
= select_watchdog(watchdog
);
4575 exit (i
== 1 ? 1 : 0);
4578 machine_register_compat_props(current_machine
);
4580 qemu_opts_foreach(qemu_find_opts("global"),
4581 global_init_func
, NULL
, NULL
);
4583 /* This checkpoint is required by replay to separate prior clock
4584 reading from the other reads, because timer polling functions query
4585 clock values from the log. */
4586 replay_checkpoint(CHECKPOINT_INIT
);
4587 qdev_machine_init();
4589 current_machine
->ram_size
= ram_size
;
4590 current_machine
->maxram_size
= maxram_size
;
4591 current_machine
->ram_slots
= ram_slots
;
4592 current_machine
->boot_order
= boot_order
;
4593 current_machine
->cpu_model
= cpu_model
;
4595 machine_class
->init(current_machine
);
4601 cpu_synchronize_all_post_init();
4603 numa_post_machine_init();
4605 if (hax_enabled()) {
4609 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4610 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4614 /* init USB devices */
4615 if (machine_usb(current_machine
)) {
4616 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4620 /* Check if IGD GFX passthrough. */
4623 /* init generic devices */
4624 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4625 if (qemu_opts_foreach(qemu_find_opts("device"),
4626 device_init_func
, NULL
, NULL
)) {
4629 rom_reset_order_override();
4631 /* Did we create any drives that we failed to create a device for? */
4632 drive_check_orphaned();
4634 /* Don't warn about the default network setup that you get if
4635 * no command line -net or -netdev options are specified. There
4636 * are two cases that we would otherwise complain about:
4637 * (1) board doesn't support a NIC but the implicit "-net nic"
4639 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4640 * sets up a nic that isn't connected to anything.
4643 net_check_clients();
4648 qemu_boot_set(boot_once
, &error_fatal
);
4649 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4652 ds
= init_displaystate();
4654 /* init local displays */
4655 switch (display_type
) {
4657 curses_display_init(ds
, full_screen
);
4660 sdl_display_init(ds
, full_screen
, no_frame
);
4663 cocoa_display_init(ds
, full_screen
);
4666 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4672 /* must be after terminal init, SDL library changes signal handlers */
4673 os_setup_signal_handling();
4675 /* init remote displays */
4677 qemu_opts_foreach(qemu_find_opts("vnc"),
4678 vnc_init_func
, NULL
, NULL
);
4682 qemu_spice_display_init();
4685 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4689 qdev_machine_creation_done();
4691 /* TODO: once all bus devices are qdevified, this should be done
4692 * when bus is created by qdev.c */
4693 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4694 qemu_run_machine_init_done_notifiers();
4696 if (rom_check_and_register_reset() != 0) {
4697 error_report("rom check and register reset failed");
4703 /* This checkpoint is required by replay to separate prior clock
4704 reading from the other reads, because timer polling functions query
4705 clock values from the log. */
4706 replay_checkpoint(CHECKPOINT_RESET
);
4707 qemu_system_reset(VMRESET_SILENT
);
4708 register_global_state();
4710 if (load_vmstate(loadvm
) < 0) {
4715 qdev_prop_check_globals();
4716 if (vmstate_dump_file
) {
4718 dump_vmstate_json_to_file(vmstate_dump_file
);
4723 Error
*local_err
= NULL
;
4724 qemu_start_incoming_migration(incoming
, &local_err
);
4726 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4729 } else if (autostart
) {
4736 replay_disable_events();
4737 iothread_stop_all();
4743 /* vhost-user must be cleaned up before chardevs. */