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)
40 #define SDL_MAIN_HANDLED
42 #if SDL_MAJOR_VERSION == 1
43 int qemu_main(int argc
, char **argv
);
44 int main(int argc
, char **argv
)
46 return qemu_main(argc
, argv
);
49 #define main qemu_main
50 #elif SDL_MAJOR_VERSION == 2
53 #error undefined SDL version
56 #endif /* CONFIG_SDL */
60 #define main qemu_main
61 #endif /* CONFIG_COCOA */
64 #include "qemu/error-report.h"
65 #include "qemu/sockets.h"
67 #include "hw/boards.h"
68 #include "sysemu/accel.h"
70 #include "hw/i386/pc.h"
71 #include "hw/isa/isa.h"
73 #include "sysemu/watchdog.h"
74 #include "hw/smbios/smbios.h"
75 #include "hw/acpi/acpi.h"
76 #include "hw/xen/xen.h"
78 #include "hw/loader.h"
79 #include "monitor/qdev.h"
80 #include "sysemu/bt.h"
82 #include "net/slirp.h"
83 #include "monitor/monitor.h"
84 #include "ui/console.h"
86 #include "sysemu/sysemu.h"
87 #include "sysemu/numa.h"
88 #include "exec/gdbstub.h"
89 #include "qemu/timer.h"
90 #include "sysemu/char.h"
91 #include "qemu/bitmap.h"
93 #include "sysemu/blockdev.h"
94 #include "hw/block/block.h"
95 #include "migration/block.h"
96 #include "sysemu/tpm.h"
97 #include "sysemu/dma.h"
98 #include "audio/audio.h"
99 #include "migration/migration.h"
100 #include "sysemu/cpus.h"
101 #include "migration/colo.h"
102 #include "sysemu/kvm.h"
103 #include "sysemu/hax.h"
104 #include "qapi/qmp/qjson.h"
105 #include "qemu/option.h"
106 #include "qemu/config-file.h"
107 #include "qemu-options.h"
108 #include "qmp-commands.h"
109 #include "qemu/main-loop.h"
111 #include "fsdev/qemu-fsdev.h"
113 #include "sysemu/qtest.h"
115 #include "disas/disas.h"
118 #include "slirp/libslirp.h"
121 #include "trace/control.h"
122 #include "qemu/queue.h"
123 #include "sysemu/arch_init.h"
125 #include "ui/qemu-spice.h"
126 #include "qapi/string-input-visitor.h"
127 #include "qapi/opts-visitor.h"
128 #include "qom/object_interfaces.h"
129 #include "qapi-event.h"
130 #include "exec/semihost.h"
131 #include "crypto/init.h"
132 #include "sysemu/replay.h"
133 #include "qapi/qmp/qerror.h"
134 #include "sysemu/iothread.h"
136 #define MAX_VIRTIO_CONSOLES 1
137 #define MAX_SCLP_CONSOLES 1
139 static const char *data_dir
[16];
140 static int data_dir_idx
;
141 const char *bios_name
= NULL
;
142 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
143 int request_opengl
= -1;
145 const char* keyboard_layout
= NULL
;
147 const char *mem_path
= NULL
;
148 int mem_prealloc
= 0; /* force preallocation of physical target memory */
149 bool enable_mlock
= false;
151 NICInfo nd_table
[MAX_NICS
];
153 static int rtc_utc
= 1;
154 static int rtc_date_offset
= -1; /* -1 means no change */
155 QEMUClockType rtc_clock
;
156 int vga_interface_type
= VGA_NONE
;
157 static int full_screen
= 0;
158 static int no_frame
= 0;
160 static bool grab_on_hover
;
161 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
162 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
163 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
164 CharDriverState
*sclp_hds
[MAX_SCLP_CONSOLES
];
165 int win2k_install_hack
= 0;
171 int acpi_enabled
= 1;
174 static int no_reboot
;
177 int graphic_rotate
= 0;
178 const char *watchdog
;
179 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
182 const char *qemu_name
;
185 unsigned int nb_prom_envs
= 0;
186 const char *prom_envs
[MAX_PROM_ENVS
];
189 uint8_t *boot_splash_filedata
;
190 size_t boot_splash_filedata_size
;
191 uint8_t qemu_extra_params_fw
[2];
193 int icount_align_option
;
195 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
196 * little-endian "wire format" described in the SMBIOS 2.6 specification.
201 /* Trace unassigned memory or i/o accesses. */
202 bool trace_unassigned
;
204 static NotifierList exit_notifiers
=
205 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
207 static NotifierList machine_init_done_notifiers
=
208 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
212 enum xen_mode xen_mode
= XEN_EMULATE
;
214 static int has_defaults
= 1;
215 static int default_serial
= 1;
216 static int default_parallel
= 1;
217 static int default_virtcon
= 1;
218 static int default_sclp
= 1;
219 static int default_monitor
= 1;
220 static int default_floppy
= 1;
221 static int default_cdrom
= 1;
222 static int default_sdcard
= 1;
223 static int default_vga
= 1;
224 static int default_net
= 1;
230 { .driver
= "isa-serial", .flag
= &default_serial
},
231 { .driver
= "isa-parallel", .flag
= &default_parallel
},
232 { .driver
= "isa-fdc", .flag
= &default_floppy
},
233 { .driver
= "floppy", .flag
= &default_floppy
},
234 { .driver
= "ide-cd", .flag
= &default_cdrom
},
235 { .driver
= "ide-hd", .flag
= &default_cdrom
},
236 { .driver
= "ide-drive", .flag
= &default_cdrom
},
237 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
238 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
239 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
240 { .driver
= "VGA", .flag
= &default_vga
},
241 { .driver
= "isa-vga", .flag
= &default_vga
},
242 { .driver
= "cirrus-vga", .flag
= &default_vga
},
243 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
244 { .driver
= "vmware-svga", .flag
= &default_vga
},
245 { .driver
= "qxl-vga", .flag
= &default_vga
},
246 { .driver
= "virtio-vga", .flag
= &default_vga
},
249 static QemuOptsList qemu_rtc_opts
= {
251 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
255 .type
= QEMU_OPT_STRING
,
258 .type
= QEMU_OPT_STRING
,
261 .type
= QEMU_OPT_STRING
,
263 { /* end of list */ }
267 static QemuOptsList qemu_sandbox_opts
= {
269 .implied_opt_name
= "enable",
270 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
274 .type
= QEMU_OPT_BOOL
,
276 { /* end of list */ }
280 static QemuOptsList qemu_option_rom_opts
= {
281 .name
= "option-rom",
282 .implied_opt_name
= "romfile",
283 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
287 .type
= QEMU_OPT_NUMBER
,
290 .type
= QEMU_OPT_STRING
,
292 { /* end of list */ }
296 static QemuOptsList qemu_machine_opts
= {
298 .implied_opt_name
= "type",
300 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
303 * no elements => accept any
304 * sanity checking will happen later
305 * when setting machine properties
311 static QemuOptsList qemu_boot_opts
= {
313 .implied_opt_name
= "order",
315 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
319 .type
= QEMU_OPT_STRING
,
322 .type
= QEMU_OPT_STRING
,
325 .type
= QEMU_OPT_BOOL
,
328 .type
= QEMU_OPT_STRING
,
330 .name
= "splash-time",
331 .type
= QEMU_OPT_STRING
,
333 .name
= "reboot-timeout",
334 .type
= QEMU_OPT_STRING
,
337 .type
= QEMU_OPT_BOOL
,
343 static QemuOptsList qemu_add_fd_opts
= {
345 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
349 .type
= QEMU_OPT_NUMBER
,
350 .help
= "file descriptor of which a duplicate is added to fd set",
353 .type
= QEMU_OPT_NUMBER
,
354 .help
= "ID of the fd set to add fd to",
357 .type
= QEMU_OPT_STRING
,
358 .help
= "free-form string used to describe fd",
360 { /* end of list */ }
364 static QemuOptsList qemu_object_opts
= {
366 .implied_opt_name
= "qom-type",
367 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
373 static QemuOptsList qemu_tpmdev_opts
= {
375 .implied_opt_name
= "type",
376 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
378 /* options are defined in the TPM backends */
379 { /* end of list */ }
383 static QemuOptsList qemu_realtime_opts
= {
385 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
389 .type
= QEMU_OPT_BOOL
,
391 { /* end of list */ }
395 static QemuOptsList qemu_msg_opts
= {
397 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
401 .type
= QEMU_OPT_BOOL
,
403 { /* end of list */ }
407 static QemuOptsList qemu_name_opts
= {
409 .implied_opt_name
= "guest",
411 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
415 .type
= QEMU_OPT_STRING
,
416 .help
= "Sets the name of the guest.\n"
417 "This name will be displayed in the SDL window caption.\n"
418 "The name will also be used for the VNC server",
421 .type
= QEMU_OPT_STRING
,
422 .help
= "Sets the name of the QEMU process, as shown in top etc",
424 .name
= "debug-threads",
425 .type
= QEMU_OPT_BOOL
,
426 .help
= "When enabled, name the individual threads; defaults off.\n"
427 "NOTE: The thread names are for debugging and not a\n"
430 { /* End of list */ }
434 static QemuOptsList qemu_mem_opts
= {
436 .implied_opt_name
= "size",
437 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
442 .type
= QEMU_OPT_SIZE
,
446 .type
= QEMU_OPT_NUMBER
,
450 .type
= QEMU_OPT_SIZE
,
452 { /* end of list */ }
456 static QemuOptsList qemu_icount_opts
= {
458 .implied_opt_name
= "shift",
460 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
464 .type
= QEMU_OPT_STRING
,
467 .type
= QEMU_OPT_BOOL
,
470 .type
= QEMU_OPT_BOOL
,
473 .type
= QEMU_OPT_STRING
,
476 .type
= QEMU_OPT_STRING
,
478 { /* end of list */ }
482 static QemuOptsList qemu_semihosting_config_opts
= {
483 .name
= "semihosting-config",
484 .implied_opt_name
= "enable",
485 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
489 .type
= QEMU_OPT_BOOL
,
492 .type
= QEMU_OPT_STRING
,
495 .type
= QEMU_OPT_STRING
,
497 { /* end of list */ }
501 static QemuOptsList qemu_fw_cfg_opts
= {
503 .implied_opt_name
= "name",
504 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
508 .type
= QEMU_OPT_STRING
,
509 .help
= "Sets the fw_cfg name of the blob to be inserted",
512 .type
= QEMU_OPT_STRING
,
513 .help
= "Sets the name of the file from which\n"
514 "the fw_cfg blob will be loaded",
517 .type
= QEMU_OPT_STRING
,
518 .help
= "Sets content of the blob to be inserted from a string",
520 { /* end of list */ }
524 #ifdef CONFIG_LIBISCSI
525 static QemuOptsList qemu_iscsi_opts
= {
527 .head
= QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts
.head
),
531 .type
= QEMU_OPT_STRING
,
532 .help
= "username for CHAP authentication to target",
535 .type
= QEMU_OPT_STRING
,
536 .help
= "password for CHAP authentication to target",
538 .name
= "password-secret",
539 .type
= QEMU_OPT_STRING
,
540 .help
= "ID of the secret providing password for CHAP "
541 "authentication to target",
543 .name
= "header-digest",
544 .type
= QEMU_OPT_STRING
,
545 .help
= "HeaderDigest setting. "
546 "{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
548 .name
= "initiator-name",
549 .type
= QEMU_OPT_STRING
,
550 .help
= "Initiator iqn name to use when connecting",
553 .type
= QEMU_OPT_NUMBER
,
554 .help
= "Request timeout in seconds (default 0 = no timeout)",
556 { /* end of list */ }
562 * Get machine options
564 * Returns: machine options (never null).
566 QemuOpts
*qemu_get_machine_opts(void)
568 return qemu_find_opts_singleton("machine");
571 const char *qemu_get_vm_name(void)
576 static void res_free(void)
578 g_free(boot_splash_filedata
);
579 boot_splash_filedata
= NULL
;
582 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
584 const char *driver
= qemu_opt_get(opts
, "driver");
589 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
590 if (strcmp(default_list
[i
].driver
, driver
) != 0)
592 *(default_list
[i
].flag
) = 0;
597 /***********************************************************/
600 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
602 /* We use RUN_STATE__MAX but any invalid value will do */
603 static RunState vmstop_requested
= RUN_STATE__MAX
;
604 static QemuMutex vmstop_lock
;
609 } RunStateTransition
;
611 static const RunStateTransition runstate_transitions_def
[] = {
613 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
614 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
615 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
617 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
618 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
619 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
620 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
621 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
622 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
623 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
624 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
625 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
626 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
627 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
628 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
630 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
631 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
632 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
634 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
635 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
636 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
638 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
639 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
640 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
641 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
643 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
644 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
645 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
647 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
648 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
649 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
651 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
652 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
653 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
654 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
656 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
657 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
659 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
661 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
662 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
663 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
664 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
665 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
666 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
667 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
668 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
669 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
670 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
671 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
673 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
675 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
676 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
677 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
679 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
680 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
681 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
682 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
683 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
684 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
686 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
687 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
688 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
689 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
691 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
692 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
693 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
695 { RUN_STATE__MAX
, RUN_STATE__MAX
},
698 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
700 bool runstate_check(RunState state
)
702 return current_run_state
== state
;
705 bool runstate_store(char *str
, size_t size
)
707 const char *state
= RunState_lookup
[current_run_state
];
708 size_t len
= strlen(state
) + 1;
713 memcpy(str
, state
, len
);
717 static void runstate_init(void)
719 const RunStateTransition
*p
;
721 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
722 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
723 runstate_valid_transitions
[p
->from
][p
->to
] = true;
726 qemu_mutex_init(&vmstop_lock
);
729 /* This function will abort() on invalid state transitions */
730 void runstate_set(RunState new_state
)
732 assert(new_state
< RUN_STATE__MAX
);
734 if (current_run_state
== new_state
) {
738 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
739 error_report("invalid runstate transition: '%s' -> '%s'",
740 RunState_lookup
[current_run_state
],
741 RunState_lookup
[new_state
]);
744 trace_runstate_set(new_state
);
745 current_run_state
= new_state
;
748 int runstate_is_running(void)
750 return runstate_check(RUN_STATE_RUNNING
);
753 bool runstate_needs_reset(void)
755 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
756 runstate_check(RUN_STATE_SHUTDOWN
);
759 StatusInfo
*qmp_query_status(Error
**errp
)
761 StatusInfo
*info
= g_malloc0(sizeof(*info
));
763 info
->running
= runstate_is_running();
764 info
->singlestep
= singlestep
;
765 info
->status
= current_run_state
;
770 static bool qemu_vmstop_requested(RunState
*r
)
772 qemu_mutex_lock(&vmstop_lock
);
773 *r
= vmstop_requested
;
774 vmstop_requested
= RUN_STATE__MAX
;
775 qemu_mutex_unlock(&vmstop_lock
);
776 return *r
< RUN_STATE__MAX
;
779 void qemu_system_vmstop_request_prepare(void)
781 qemu_mutex_lock(&vmstop_lock
);
784 void qemu_system_vmstop_request(RunState state
)
786 vmstop_requested
= state
;
787 qemu_mutex_unlock(&vmstop_lock
);
795 qemu_vmstop_requested(&requested
);
796 if (runstate_is_running() && requested
== RUN_STATE__MAX
) {
800 /* Ensure that a STOP/RESUME pair of events is emitted if a
801 * vmstop request was pending. The BLOCK_IO_ERROR event, for
802 * example, according to documentation is always followed by
805 if (runstate_is_running()) {
806 qapi_event_send_stop(&error_abort
);
808 replay_enable_events();
810 runstate_set(RUN_STATE_RUNNING
);
811 vm_state_notify(1, RUN_STATE_RUNNING
);
815 qapi_event_send_resume(&error_abort
);
819 /***********************************************************/
820 /* real time host monotonic timer */
822 static time_t qemu_time(void)
824 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
827 /***********************************************************/
828 /* host time/date access */
829 void qemu_get_timedate(struct tm
*tm
, int offset
)
831 time_t ti
= qemu_time();
834 if (rtc_date_offset
== -1) {
838 localtime_r(&ti
, tm
);
840 ti
-= rtc_date_offset
;
845 int qemu_timedate_diff(struct tm
*tm
)
849 if (rtc_date_offset
== -1)
851 seconds
= mktimegm(tm
);
854 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
855 seconds
= mktime(&tmp
);
858 seconds
= mktimegm(tm
) + rtc_date_offset
;
860 return seconds
- qemu_time();
863 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
865 time_t rtc_start_date
;
868 if (!strcmp(startdate
, "now") && legacy
) {
869 rtc_date_offset
= -1;
871 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
879 } else if (sscanf(startdate
, "%d-%d-%d",
891 rtc_start_date
= mktimegm(&tm
);
892 if (rtc_start_date
== -1) {
894 error_report("invalid date format");
895 error_printf("valid formats: "
896 "'2006-06-17T16:01:21' or '2006-06-17'\n");
899 rtc_date_offset
= qemu_time() - rtc_start_date
;
903 static void configure_rtc(QemuOpts
*opts
)
907 value
= qemu_opt_get(opts
, "base");
909 if (!strcmp(value
, "utc")) {
911 } else if (!strcmp(value
, "localtime")) {
912 Error
*blocker
= NULL
;
914 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
915 "-rtc base=localtime");
916 replay_add_blocker(blocker
);
918 configure_rtc_date_offset(value
, 0);
921 value
= qemu_opt_get(opts
, "clock");
923 if (!strcmp(value
, "host")) {
924 rtc_clock
= QEMU_CLOCK_HOST
;
925 } else if (!strcmp(value
, "rt")) {
926 rtc_clock
= QEMU_CLOCK_REALTIME
;
927 } else if (!strcmp(value
, "vm")) {
928 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
930 error_report("invalid option value '%s'", value
);
934 value
= qemu_opt_get(opts
, "driftfix");
936 if (!strcmp(value
, "slew")) {
937 static GlobalProperty slew_lost_ticks
= {
938 .driver
= "mc146818rtc",
939 .property
= "lost_tick_policy",
943 qdev_prop_register_global(&slew_lost_ticks
);
944 } else if (!strcmp(value
, "none")) {
945 /* discard is default */
947 error_report("invalid option value '%s'", value
);
953 /***********************************************************/
954 /* Bluetooth support */
957 static struct HCIInfo
*hci_table
[MAX_NICS
];
959 struct HCIInfo
*qemu_next_hci(void)
961 if (cur_hci
== nb_hcis
)
964 return hci_table
[cur_hci
++];
967 static int bt_hci_parse(const char *str
)
972 if (nb_hcis
>= MAX_NICS
) {
973 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
986 bdaddr
.b
[5] = 0x56 + nb_hcis
;
987 hci
->bdaddr_set(hci
, bdaddr
.b
);
989 hci_table
[nb_hcis
++] = hci
;
994 static void bt_vhci_add(int vlan_id
)
996 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
999 error_report("warning: adding a VHCI to an empty scatternet %i",
1002 bt_vhci_init(bt_new_hci(vlan
));
1005 static struct bt_device_s
*bt_device_add(const char *opt
)
1007 struct bt_scatternet_s
*vlan
;
1009 char *endp
= strstr(opt
, ",vlan=");
1010 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
1013 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
1016 vlan_id
= strtol(endp
+ 6, &endp
, 0);
1018 error_report("unrecognised bluetooth vlan Id");
1023 vlan
= qemu_find_bt_vlan(vlan_id
);
1026 error_report("warning: adding a slave device to an empty scatternet %i",
1029 if (!strcmp(devname
, "keyboard"))
1030 return bt_keyboard_init(vlan
);
1032 error_report("unsupported bluetooth device '%s'", devname
);
1036 static int bt_parse(const char *opt
)
1038 const char *endp
, *p
;
1041 if (strstart(opt
, "hci", &endp
)) {
1042 if (!*endp
|| *endp
== ',') {
1044 if (!strstart(endp
, ",vlan=", 0))
1047 return bt_hci_parse(opt
);
1049 } else if (strstart(opt
, "vhci", &endp
)) {
1050 if (!*endp
|| *endp
== ',') {
1052 if (strstart(endp
, ",vlan=", &p
)) {
1053 vlan
= strtol(p
, (char **) &endp
, 0);
1055 error_report("bad scatternet '%s'", p
);
1059 error_report("bad parameter '%s'", endp
+ 1);
1068 } else if (strstart(opt
, "device:", &endp
))
1069 return !bt_device_add(endp
);
1071 error_report("bad bluetooth parameter '%s'", opt
);
1075 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1077 /* FIXME: change this to true for 1.3 */
1078 if (qemu_opt_get_bool(opts
, "enable", false)) {
1079 #ifdef CONFIG_SECCOMP
1080 if (seccomp_start() < 0) {
1081 error_report("failed to install seccomp syscall filter "
1086 error_report("seccomp support is disabled");
1094 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1096 const char *proc_name
;
1098 if (qemu_opt_get(opts
, "debug-threads")) {
1099 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1101 qemu_name
= qemu_opt_get(opts
, "guest");
1103 proc_name
= qemu_opt_get(opts
, "process");
1105 os_set_proc_name(proc_name
);
1111 bool defaults_enabled(void)
1113 return has_defaults
;
1117 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1119 int fd
, dupfd
, flags
;
1121 const char *fd_opaque
= NULL
;
1124 fd
= qemu_opt_get_number(opts
, "fd", -1);
1125 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1126 fd_opaque
= qemu_opt_get(opts
, "opaque");
1129 error_report("fd option is required and must be non-negative");
1133 if (fd
<= STDERR_FILENO
) {
1134 error_report("fd cannot be a standard I/O stream");
1139 * All fds inherited across exec() necessarily have FD_CLOEXEC
1140 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1142 flags
= fcntl(fd
, F_GETFD
);
1143 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1144 error_report("fd is not valid or already in use");
1149 error_report("set option is required and must be non-negative");
1153 #ifdef F_DUPFD_CLOEXEC
1154 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1158 qemu_set_cloexec(dupfd
);
1162 error_report("error duplicating fd: %s", strerror(errno
));
1166 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1167 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1174 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1178 fd
= qemu_opt_get_number(opts
, "fd", -1);
1185 /***********************************************************/
1186 /* QEMU Block devices */
1188 #define HD_OPTS "media=disk"
1189 #define CDROM_OPTS "media=cdrom"
1191 #define PFLASH_OPTS ""
1195 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1197 BlockInterfaceType
*block_default_type
= opaque
;
1199 return drive_new(opts
, *block_default_type
) == NULL
;
1202 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1204 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1205 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1210 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1211 int index
, const char *optstr
)
1216 if (!enable
|| drive_get_by_index(type
, index
)) {
1220 opts
= drive_add(type
, index
, NULL
, optstr
);
1222 drive_enable_snapshot(NULL
, opts
, NULL
);
1225 dinfo
= drive_new(opts
, type
);
1229 dinfo
->is_default
= true;
1233 static QemuOptsList qemu_smp_opts
= {
1235 .implied_opt_name
= "cpus",
1236 .merge_lists
= true,
1237 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1241 .type
= QEMU_OPT_NUMBER
,
1244 .type
= QEMU_OPT_NUMBER
,
1247 .type
= QEMU_OPT_NUMBER
,
1250 .type
= QEMU_OPT_NUMBER
,
1253 .type
= QEMU_OPT_NUMBER
,
1255 { /*End of list */ }
1259 static void smp_parse(QemuOpts
*opts
)
1262 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1263 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1264 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1265 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1267 /* compute missing values, prefer sockets over cores over threads */
1268 if (cpus
== 0 || sockets
== 0) {
1269 sockets
= sockets
> 0 ? sockets
: 1;
1270 cores
= cores
> 0 ? cores
: 1;
1271 threads
= threads
> 0 ? threads
: 1;
1273 cpus
= cores
* threads
* sockets
;
1275 } else if (cores
== 0) {
1276 threads
= threads
> 0 ? threads
: 1;
1277 cores
= cpus
/ (sockets
* threads
);
1278 cores
= cores
> 0 ? cores
: 1;
1279 } else if (threads
== 0) {
1280 threads
= cpus
/ (cores
* sockets
);
1281 threads
= threads
> 0 ? threads
: 1;
1282 } else if (sockets
* cores
* threads
< cpus
) {
1283 error_report("cpu topology: "
1284 "sockets (%u) * cores (%u) * threads (%u) < "
1286 sockets
, cores
, threads
, cpus
);
1290 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1292 if (max_cpus
< cpus
) {
1293 error_report("maxcpus must be equal to or greater than smp");
1297 if (sockets
* cores
* threads
> max_cpus
) {
1298 error_report("cpu topology: "
1299 "sockets (%u) * cores (%u) * threads (%u) > "
1301 sockets
, cores
, threads
, max_cpus
);
1307 smp_threads
= threads
;
1311 Error
*blocker
= NULL
;
1312 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1313 replay_add_blocker(blocker
);
1317 static void realtime_init(void)
1320 if (os_mlock() < 0) {
1321 error_report("locking memory failed");
1328 static void configure_msg(QemuOpts
*opts
)
1330 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1333 /***********************************************************/
1336 typedef struct SemihostingConfig
{
1338 SemihostingTarget target
;
1341 const char *cmdline
; /* concatenated argv */
1342 } SemihostingConfig
;
1344 static SemihostingConfig semihosting
;
1346 bool semihosting_enabled(void)
1348 return semihosting
.enabled
;
1351 SemihostingTarget
semihosting_get_target(void)
1353 return semihosting
.target
;
1356 const char *semihosting_get_arg(int i
)
1358 if (i
>= semihosting
.argc
) {
1361 return semihosting
.argv
[i
];
1364 int semihosting_get_argc(void)
1366 return semihosting
.argc
;
1369 const char *semihosting_get_cmdline(void)
1371 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1372 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1374 return semihosting
.cmdline
;
1377 static int add_semihosting_arg(void *opaque
,
1378 const char *name
, const char *val
,
1381 SemihostingConfig
*s
= opaque
;
1382 if (strcmp(name
, "arg") == 0) {
1384 /* one extra element as g_strjoinv() expects NULL-terminated array */
1385 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1386 s
->argv
[s
->argc
- 1] = val
;
1387 s
->argv
[s
->argc
] = NULL
;
1392 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1393 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1398 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1400 /* split -append and initialize argv[1..n] */
1401 cmd_token
= strtok(g_strdup(cmd
), " ");
1403 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1404 cmd_token
= strtok(NULL
, " ");
1408 /* Now we still need this for compatibility with XEN. */
1409 bool has_igd_gfx_passthru
;
1410 static void igd_gfx_passthru(void)
1412 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1415 /***********************************************************/
1418 static int usb_device_add(const char *devname
)
1420 USBDevice
*dev
= NULL
;
1421 #ifndef CONFIG_LINUX
1425 if (!machine_usb(current_machine
)) {
1429 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1430 dev
= usbdevice_create(devname
);
1434 /* the other ones */
1435 #ifndef CONFIG_LINUX
1436 /* only the linux version is qdev-ified, usb-bsd still needs this */
1437 if (strstart(devname
, "host:", &p
)) {
1438 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1448 static int usb_device_del(const char *devname
)
1453 if (strstart(devname
, "host:", &p
)) {
1457 if (!machine_usb(current_machine
)) {
1461 p
= strchr(devname
, '.');
1464 bus_num
= strtoul(devname
, NULL
, 0);
1465 addr
= strtoul(p
+ 1, NULL
, 0);
1467 return usb_device_delete_addr(bus_num
, addr
);
1470 static int usb_parse(const char *cmdline
)
1473 r
= usb_device_add(cmdline
);
1475 error_report("could not add USB device '%s'", cmdline
);
1480 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1482 const char *devname
= qdict_get_str(qdict
, "devname");
1483 if (usb_device_add(devname
) < 0) {
1484 error_report("could not add USB device '%s'", devname
);
1488 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1490 const char *devname
= qdict_get_str(qdict
, "devname");
1491 if (usb_device_del(devname
) < 0) {
1492 error_report("could not delete USB device '%s'", devname
);
1496 /***********************************************************/
1497 /* machine registration */
1499 MachineState
*current_machine
;
1501 static MachineClass
*find_machine(const char *name
)
1503 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1504 MachineClass
*mc
= NULL
;
1506 for (el
= machines
; el
; el
= el
->next
) {
1507 MachineClass
*temp
= el
->data
;
1509 if (!strcmp(temp
->name
, name
)) {
1514 !strcmp(temp
->alias
, name
)) {
1520 g_slist_free(machines
);
1524 MachineClass
*find_default_machine(void)
1526 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1527 MachineClass
*mc
= NULL
;
1529 for (el
= machines
; el
; el
= el
->next
) {
1530 MachineClass
*temp
= el
->data
;
1532 if (temp
->is_default
) {
1538 g_slist_free(machines
);
1542 MachineInfoList
*qmp_query_machines(Error
**errp
)
1544 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1545 MachineInfoList
*mach_list
= NULL
;
1547 for (el
= machines
; el
; el
= el
->next
) {
1548 MachineClass
*mc
= el
->data
;
1549 MachineInfoList
*entry
;
1552 info
= g_malloc0(sizeof(*info
));
1553 if (mc
->is_default
) {
1554 info
->has_is_default
= true;
1555 info
->is_default
= true;
1559 info
->has_alias
= true;
1560 info
->alias
= g_strdup(mc
->alias
);
1563 info
->name
= g_strdup(mc
->name
);
1564 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1565 info
->hotpluggable_cpus
= !!mc
->query_hotpluggable_cpus
;
1567 entry
= g_malloc0(sizeof(*entry
));
1568 entry
->value
= info
;
1569 entry
->next
= mach_list
;
1573 g_slist_free(machines
);
1577 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1579 ObjectProperty
*prop
;
1580 ObjectPropertyIterator iter
;
1582 if (!qemu_opt_has_help_opt(opts
)) {
1586 object_property_iter_init(&iter
, OBJECT(machine
));
1587 while ((prop
= object_property_iter_next(&iter
))) {
1592 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1593 prop
->name
, prop
->type
);
1594 if (prop
->description
) {
1595 error_printf(" (%s)\n", prop
->description
);
1604 /***********************************************************/
1605 /* main execution loop */
1607 struct vm_change_state_entry
{
1608 VMChangeStateHandler
*cb
;
1610 QLIST_ENTRY (vm_change_state_entry
) entries
;
1613 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1615 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1618 VMChangeStateEntry
*e
;
1620 e
= g_malloc0(sizeof (*e
));
1624 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1628 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1630 QLIST_REMOVE (e
, entries
);
1634 void vm_state_notify(int running
, RunState state
)
1636 VMChangeStateEntry
*e
, *next
;
1638 trace_vm_state_notify(running
, state
);
1640 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1641 e
->cb(e
->opaque
, running
, state
);
1645 static int reset_requested
;
1646 static int shutdown_requested
, shutdown_signal
= -1;
1647 static pid_t shutdown_pid
;
1648 static int powerdown_requested
;
1649 static int debug_requested
;
1650 static int suspend_requested
;
1651 static WakeupReason wakeup_reason
;
1652 static NotifierList powerdown_notifiers
=
1653 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1654 static NotifierList suspend_notifiers
=
1655 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1656 static NotifierList wakeup_notifiers
=
1657 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1658 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1660 int qemu_shutdown_requested_get(void)
1662 return shutdown_requested
;
1665 int qemu_reset_requested_get(void)
1667 return reset_requested
;
1670 static int qemu_shutdown_requested(void)
1672 return atomic_xchg(&shutdown_requested
, 0);
1675 static void qemu_kill_report(void)
1677 if (!qtest_driver() && shutdown_signal
!= -1) {
1678 if (shutdown_pid
== 0) {
1679 /* This happens for eg ^C at the terminal, so it's worth
1680 * avoiding printing an odd message in that case.
1682 error_report("terminating on signal %d", shutdown_signal
);
1684 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1686 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1687 shutdown_signal
, shutdown_pid
,
1688 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1689 g_free(shutdown_cmd
);
1691 shutdown_signal
= -1;
1695 static int qemu_reset_requested(void)
1697 int r
= reset_requested
;
1698 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1699 reset_requested
= 0;
1705 static int qemu_suspend_requested(void)
1707 int r
= suspend_requested
;
1708 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1709 suspend_requested
= 0;
1715 static WakeupReason
qemu_wakeup_requested(void)
1717 return wakeup_reason
;
1720 static int qemu_powerdown_requested(void)
1722 int r
= powerdown_requested
;
1723 powerdown_requested
= 0;
1727 static int qemu_debug_requested(void)
1729 int r
= debug_requested
;
1730 debug_requested
= 0;
1734 void qemu_system_reset(bool report
)
1738 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1740 cpu_synchronize_all_states();
1742 if (mc
&& mc
->reset
) {
1745 qemu_devices_reset();
1748 qapi_event_send_reset(&error_abort
);
1750 cpu_synchronize_all_post_reset();
1753 void qemu_system_guest_panicked(void)
1756 current_cpu
->crash_occurred
= true;
1758 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
, &error_abort
);
1759 vm_stop(RUN_STATE_GUEST_PANICKED
);
1761 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1763 qemu_system_shutdown_request();
1767 void qemu_system_reset_request(void)
1770 shutdown_requested
= 1;
1772 reset_requested
= 1;
1775 qemu_notify_event();
1778 static void qemu_system_suspend(void)
1781 notifier_list_notify(&suspend_notifiers
, NULL
);
1782 runstate_set(RUN_STATE_SUSPENDED
);
1783 qapi_event_send_suspend(&error_abort
);
1786 void qemu_system_suspend_request(void)
1788 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1791 suspend_requested
= 1;
1793 qemu_notify_event();
1796 void qemu_register_suspend_notifier(Notifier
*notifier
)
1798 notifier_list_add(&suspend_notifiers
, notifier
);
1801 void qemu_system_wakeup_request(WakeupReason reason
)
1803 trace_system_wakeup_request(reason
);
1805 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1808 if (!(wakeup_reason_mask
& (1 << reason
))) {
1811 runstate_set(RUN_STATE_RUNNING
);
1812 wakeup_reason
= reason
;
1813 qemu_notify_event();
1816 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1819 wakeup_reason_mask
|= (1 << reason
);
1821 wakeup_reason_mask
&= ~(1 << reason
);
1825 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1827 notifier_list_add(&wakeup_notifiers
, notifier
);
1830 void qemu_system_killed(int signal
, pid_t pid
)
1832 shutdown_signal
= signal
;
1836 /* Cannot call qemu_system_shutdown_request directly because
1837 * we are in a signal handler.
1839 shutdown_requested
= 1;
1840 qemu_notify_event();
1843 void qemu_system_shutdown_request(void)
1845 trace_qemu_system_shutdown_request();
1846 replay_shutdown_request();
1847 shutdown_requested
= 1;
1848 qemu_notify_event();
1851 static void qemu_system_powerdown(void)
1853 qapi_event_send_powerdown(&error_abort
);
1854 notifier_list_notify(&powerdown_notifiers
, NULL
);
1857 void qemu_system_powerdown_request(void)
1859 trace_qemu_system_powerdown_request();
1860 powerdown_requested
= 1;
1861 qemu_notify_event();
1864 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1866 notifier_list_add(&powerdown_notifiers
, notifier
);
1869 void qemu_system_debug_request(void)
1871 debug_requested
= 1;
1872 qemu_notify_event();
1875 static bool main_loop_should_exit(void)
1878 if (qemu_debug_requested()) {
1879 vm_stop(RUN_STATE_DEBUG
);
1881 if (qemu_suspend_requested()) {
1882 qemu_system_suspend();
1884 if (qemu_shutdown_requested()) {
1886 qapi_event_send_shutdown(&error_abort
);
1888 vm_stop(RUN_STATE_SHUTDOWN
);
1893 if (qemu_reset_requested()) {
1895 qemu_system_reset(VMRESET_REPORT
);
1897 if (!runstate_check(RUN_STATE_RUNNING
) &&
1898 !runstate_check(RUN_STATE_INMIGRATE
)) {
1899 runstate_set(RUN_STATE_PRELAUNCH
);
1902 if (qemu_wakeup_requested()) {
1904 qemu_system_reset(VMRESET_SILENT
);
1905 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1906 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1908 qapi_event_send_wakeup(&error_abort
);
1910 if (qemu_powerdown_requested()) {
1911 qemu_system_powerdown();
1913 if (qemu_vmstop_requested(&r
)) {
1919 static void main_loop(void)
1923 #ifdef CONFIG_PROFILER
1927 nonblocking
= tcg_enabled() && last_io
> 0;
1928 #ifdef CONFIG_PROFILER
1929 ti
= profile_getclock();
1931 last_io
= main_loop_wait(nonblocking
);
1932 #ifdef CONFIG_PROFILER
1933 dev_time
+= profile_getclock() - ti
;
1935 } while (!main_loop_should_exit());
1938 static void version(void)
1940 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1941 QEMU_COPYRIGHT
"\n");
1944 static void QEMU_NORETURN
help(int exitcode
)
1947 printf("usage: %s [options] [disk_image]\n\n"
1948 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1949 error_get_progname());
1951 #define QEMU_OPTIONS_GENERATE_HELP
1952 #include "qemu-options-wrapper.h"
1954 printf("\nDuring emulation, the following keys are useful:\n"
1955 "ctrl-alt-f toggle full screen\n"
1956 "ctrl-alt-n switch to virtual console 'n'\n"
1957 "ctrl-alt toggle mouse and keyboard grab\n"
1959 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1964 #define HAS_ARG 0x0001
1966 typedef struct QEMUOption
{
1973 static const QEMUOption qemu_options
[] = {
1974 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1975 #define QEMU_OPTIONS_GENERATE_OPTIONS
1976 #include "qemu-options-wrapper.h"
1980 typedef struct VGAInterfaceInfo
{
1981 const char *opt_name
; /* option name */
1982 const char *name
; /* human-readable name */
1983 /* Class names indicating that support is available.
1984 * If no class is specified, the interface is always available */
1985 const char *class_names
[2];
1988 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1994 .name
= "standard VGA",
1995 .class_names
= { "VGA", "isa-vga" },
1998 .opt_name
= "cirrus",
1999 .name
= "Cirrus VGA",
2000 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
2003 .opt_name
= "vmware",
2004 .name
= "VMWare SVGA",
2005 .class_names
= { "vmware-svga" },
2008 .opt_name
= "virtio",
2009 .name
= "Virtio VGA",
2010 .class_names
= { "virtio-vga" },
2015 .class_names
= { "qxl-vga" },
2019 .name
= "TCX framebuffer",
2020 .class_names
= { "SUNW,tcx" },
2024 .name
= "CG3 framebuffer",
2025 .class_names
= { "cgthree" },
2028 .opt_name
= "xenfb",
2032 static bool vga_interface_available(VGAInterfaceType t
)
2034 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2036 assert(t
< VGA_TYPE_MAX
);
2037 return !ti
->class_names
[0] ||
2038 object_class_by_name(ti
->class_names
[0]) ||
2039 object_class_by_name(ti
->class_names
[1]);
2042 static void select_vgahw(const char *p
)
2047 assert(vga_interface_type
== VGA_NONE
);
2048 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2049 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2050 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2051 if (!vga_interface_available(t
)) {
2052 error_report("%s not available", ti
->name
);
2055 vga_interface_type
= t
;
2059 if (t
== VGA_TYPE_MAX
) {
2061 error_report("unknown vga type: %s", p
);
2065 const char *nextopt
;
2067 if (strstart(opts
, ",retrace=", &nextopt
)) {
2069 if (strstart(opts
, "dumb", &nextopt
))
2070 vga_retrace_method
= VGA_RETRACE_DUMB
;
2071 else if (strstart(opts
, "precise", &nextopt
))
2072 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2073 else goto invalid_vga
;
2074 } else goto invalid_vga
;
2079 typedef enum DisplayType
{
2088 static DisplayType
select_display(const char *p
)
2091 DisplayType display
= DT_DEFAULT
;
2093 if (strstart(p
, "sdl", &opts
)) {
2097 const char *nextopt
;
2099 if (strstart(opts
, ",frame=", &nextopt
)) {
2101 if (strstart(opts
, "on", &nextopt
)) {
2103 } else if (strstart(opts
, "off", &nextopt
)) {
2106 goto invalid_sdl_args
;
2108 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2110 if (strstart(opts
, "on", &nextopt
)) {
2112 } else if (strstart(opts
, "off", &nextopt
)) {
2115 goto invalid_sdl_args
;
2117 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2119 if (strstart(opts
, "on", &nextopt
)) {
2121 } else if (strstart(opts
, "off", &nextopt
)) {
2124 goto invalid_sdl_args
;
2126 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2128 if (strstart(opts
, "on", &nextopt
)) {
2130 } else if (strstart(opts
, "off", &nextopt
)) {
2133 goto invalid_sdl_args
;
2135 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2137 if (strstart(opts
, "on", &nextopt
)) {
2139 } else if (strstart(opts
, "off", &nextopt
)) {
2142 goto invalid_sdl_args
;
2146 error_report("invalid SDL option string");
2152 error_report("SDL support is disabled");
2155 } else if (strstart(p
, "vnc", &opts
)) {
2157 vnc_parse(opts
+ 1, &error_fatal
);
2159 error_report("VNC requires a display argument vnc=<display>");
2162 } else if (strstart(p
, "curses", &opts
)) {
2163 #ifdef CONFIG_CURSES
2164 display
= DT_CURSES
;
2166 error_report("curses support is disabled");
2169 } else if (strstart(p
, "gtk", &opts
)) {
2173 const char *nextopt
;
2175 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2177 if (strstart(opts
, "on", &nextopt
)) {
2178 grab_on_hover
= true;
2179 } else if (strstart(opts
, "off", &nextopt
)) {
2180 grab_on_hover
= false;
2182 goto invalid_gtk_args
;
2184 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2186 if (strstart(opts
, "on", &nextopt
)) {
2188 } else if (strstart(opts
, "off", &nextopt
)) {
2191 goto invalid_gtk_args
;
2195 error_report("invalid GTK option string");
2201 error_report("GTK support is disabled");
2204 } else if (strstart(p
, "none", &opts
)) {
2207 error_report("unknown display type");
2214 static int balloon_parse(const char *arg
)
2218 if (strcmp(arg
, "none") == 0) {
2222 if (!strncmp(arg
, "virtio", 6)) {
2223 if (arg
[6] == ',') {
2224 /* have params -> parse them */
2225 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2230 /* create empty opts */
2231 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2234 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2241 #if defined(CONFIG_RUBY)
2242 /* Ruby interface for QEMU. See README.EXT for programming example. */
2246 static VALUE
qemu_open(int argc
, VALUE
*argv
, VALUE klass
)
2249 for (i
= 0; i
< argc
; i
++) {
2250 argv
[i
] = StringValue(argv
[i
]);
2251 fprintf(stderr
, "argv[%d] = %s\n", i
, StringValuePtr(argv
[i
]));
2253 //~ if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
2254 //~ mode = 0666; /* default value */
2256 return INT2FIX(argc
);
2259 void Init_qemu(void)
2261 printf("%s\n", __func__
);
2262 VALUE cQEMU
= rb_define_class("QEMU", rb_cObject
);
2263 rb_define_singleton_method(cQEMU
, "run", qemu_open
, -1);
2268 #endif /* CONFIG_RUBY */
2270 #if defined(CONFIG_DLL)
2271 BOOL APIENTRY
DllMain(HINSTANCE hModule
, DWORD ul_reason_for_call
, LPVOID data
)
2275 #endif /* CONFIG_DLL */
2277 char *qemu_find_file(int type
, const char *name
)
2283 /* Try the name as a straight path first */
2284 if (access(name
, R_OK
) == 0) {
2285 trace_load_file(name
, name
);
2286 return g_strdup(name
);
2290 case QEMU_FILE_TYPE_BIOS
:
2293 case QEMU_FILE_TYPE_KEYMAP
:
2294 subdir
= "keymaps/";
2300 for (i
= 0; i
< data_dir_idx
; i
++) {
2301 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2302 if (access(buf
, R_OK
) == 0) {
2303 trace_load_file(name
, buf
);
2311 static inline bool nonempty_str(const char *str
)
2316 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2320 const char *name
, *file
, *str
;
2321 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2323 if (fw_cfg
== NULL
) {
2324 error_report("fw_cfg device not available");
2327 name
= qemu_opt_get(opts
, "name");
2328 file
= qemu_opt_get(opts
, "file");
2329 str
= qemu_opt_get(opts
, "string");
2331 /* we need name and either a file or the content string */
2332 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2333 error_report("invalid argument(s)");
2336 if (nonempty_str(file
) && nonempty_str(str
)) {
2337 error_report("file and string are mutually exclusive");
2340 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2341 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2344 if (strncmp(name
, "opt/", 4) != 0) {
2345 error_report("warning: externally provided fw_cfg item names "
2346 "should be prefixed with \"opt/\"");
2348 if (nonempty_str(str
)) {
2349 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2350 buf
= g_memdup(str
, size
);
2352 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2353 error_report("can't load %s", file
);
2357 /* For legacy, keep user files in a specific global order. */
2358 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2359 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2360 fw_cfg_reset_order_override(fw_cfg
);
2364 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2366 return qdev_device_help(opts
);
2369 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2374 dev
= qdev_device_add(opts
, &err
);
2376 error_report_err(err
);
2379 object_unref(OBJECT(dev
));
2383 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2385 Error
*local_err
= NULL
;
2387 qemu_chr_new_from_opts(opts
, &local_err
);
2389 error_report_err(local_err
);
2395 #ifdef CONFIG_VIRTFS
2396 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2398 return qemu_fsdev_add(opts
);
2402 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2404 CharDriverState
*chr
;
2405 const char *chardev
;
2409 mode
= qemu_opt_get(opts
, "mode");
2413 if (strcmp(mode
, "readline") == 0) {
2414 flags
= MONITOR_USE_READLINE
;
2415 } else if (strcmp(mode
, "control") == 0) {
2416 flags
= MONITOR_USE_CONTROL
;
2418 error_report("unknown monitor mode \"%s\"", mode
);
2422 if (qemu_opt_get_bool(opts
, "pretty", 0))
2423 flags
|= MONITOR_USE_PRETTY
;
2425 if (qemu_opt_get_bool(opts
, "default", 0)) {
2426 error_report("option 'default' does nothing and is deprecated");
2429 chardev
= qemu_opt_get(opts
, "chardev");
2430 chr
= qemu_chr_find(chardev
);
2432 error_report("chardev \"%s\" not found", chardev
);
2436 monitor_init(chr
, flags
);
2440 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2442 static int monitor_device_index
= 0;
2447 if (strstart(optarg
, "chardev:", &p
)) {
2448 snprintf(label
, sizeof(label
), "%s", p
);
2450 snprintf(label
, sizeof(label
), "compat_monitor%d",
2451 monitor_device_index
);
2452 opts
= qemu_chr_parse_compat(label
, optarg
);
2454 error_report("parse error: %s", optarg
);
2459 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2460 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2461 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2462 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2463 monitor_device_index
++;
2466 struct device_config
{
2468 DEV_USB
, /* -usbdevice */
2470 DEV_SERIAL
, /* -serial */
2471 DEV_PARALLEL
, /* -parallel */
2472 DEV_VIRTCON
, /* -virtioconsole */
2473 DEV_DEBUGCON
, /* -debugcon */
2474 DEV_GDB
, /* -gdb, -s */
2475 DEV_SCLP
, /* s390 sclp */
2477 const char *cmdline
;
2479 QTAILQ_ENTRY(device_config
) next
;
2482 static QTAILQ_HEAD(, device_config
) device_configs
=
2483 QTAILQ_HEAD_INITIALIZER(device_configs
);
2485 static void add_device_config(int type
, const char *cmdline
)
2487 struct device_config
*conf
;
2489 conf
= g_malloc0(sizeof(*conf
));
2491 conf
->cmdline
= cmdline
;
2492 loc_save(&conf
->loc
);
2493 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2496 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2498 struct device_config
*conf
;
2501 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2502 if (conf
->type
!= type
)
2504 loc_push_restore(&conf
->loc
);
2505 rc
= func(conf
->cmdline
);
2506 loc_pop(&conf
->loc
);
2514 static int serial_parse(const char *devname
)
2516 static int index
= 0;
2519 if (strcmp(devname
, "none") == 0)
2521 if (index
== MAX_SERIAL_PORTS
) {
2522 error_report("too many serial ports");
2525 snprintf(label
, sizeof(label
), "serial%d", index
);
2526 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2527 if (!serial_hds
[index
]) {
2528 error_report("could not connect serial device"
2529 " to character backend '%s'", devname
);
2536 static int parallel_parse(const char *devname
)
2538 static int index
= 0;
2541 if (strcmp(devname
, "none") == 0)
2543 if (index
== MAX_PARALLEL_PORTS
) {
2544 error_report("too many parallel ports");
2547 snprintf(label
, sizeof(label
), "parallel%d", index
);
2548 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2549 if (!parallel_hds
[index
]) {
2550 error_report("could not connect parallel device"
2551 " to character backend '%s'", devname
);
2558 static int virtcon_parse(const char *devname
)
2560 QemuOptsList
*device
= qemu_find_opts("device");
2561 static int index
= 0;
2563 QemuOpts
*bus_opts
, *dev_opts
;
2565 if (strcmp(devname
, "none") == 0)
2567 if (index
== MAX_VIRTIO_CONSOLES
) {
2568 error_report("too many virtio consoles");
2572 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2573 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2575 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2576 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2578 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2579 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2580 if (!virtcon_hds
[index
]) {
2581 error_report("could not connect virtio console"
2582 " to character backend '%s'", devname
);
2585 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2591 static int sclp_parse(const char *devname
)
2593 QemuOptsList
*device
= qemu_find_opts("device");
2594 static int index
= 0;
2598 if (strcmp(devname
, "none") == 0) {
2601 if (index
== MAX_SCLP_CONSOLES
) {
2602 error_report("too many sclp consoles");
2606 assert(arch_type
== QEMU_ARCH_S390X
);
2608 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2609 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2611 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2612 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2613 if (!sclp_hds
[index
]) {
2614 error_report("could not connect sclp console"
2615 " to character backend '%s'", devname
);
2618 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2624 static int debugcon_parse(const char *devname
)
2628 if (!qemu_chr_new("debugcon", devname
)) {
2631 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2633 error_report("already have a debugcon device");
2636 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2637 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2641 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2643 const MachineClass
*mc1
= a
, *mc2
= b
;
2646 if (mc1
->family
== NULL
) {
2647 if (mc2
->family
== NULL
) {
2648 /* Compare standalone machine types against each other; they sort
2649 * in increasing order.
2651 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2652 object_class_get_name(OBJECT_CLASS(mc2
)));
2655 /* Standalone machine types sort after families. */
2659 if (mc2
->family
== NULL
) {
2660 /* Families sort before standalone machine types. */
2664 /* Families sort between each other alphabetically increasingly. */
2665 res
= strcmp(mc1
->family
, mc2
->family
);
2670 /* Within the same family, machine types sort in decreasing order. */
2671 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2672 object_class_get_name(OBJECT_CLASS(mc1
)));
2675 static MachineClass
*machine_parse(const char *name
)
2677 MachineClass
*mc
= NULL
;
2678 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2681 mc
= find_machine(name
);
2684 g_slist_free(machines
);
2687 if (name
&& !is_help_option(name
)) {
2688 error_report("unsupported machine type");
2689 error_printf("Use -machine help to list supported machines\n");
2691 printf("Supported machines are:\n");
2692 machines
= g_slist_sort(machines
, machine_class_cmp
);
2693 for (el
= machines
; el
; el
= el
->next
) {
2694 MachineClass
*mc
= el
->data
;
2696 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2698 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2699 mc
->is_default
? " (default)" : "");
2703 g_slist_free(machines
);
2704 exit(!name
|| !is_help_option(name
));
2707 void qemu_add_exit_notifier(Notifier
*notify
)
2709 notifier_list_add(&exit_notifiers
, notify
);
2712 void qemu_remove_exit_notifier(Notifier
*notify
)
2714 notifier_remove(notify
);
2717 static void qemu_run_exit_notifiers(void)
2719 notifier_list_notify(&exit_notifiers
, NULL
);
2722 static bool machine_init_done
;
2724 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2726 notifier_list_add(&machine_init_done_notifiers
, notify
);
2727 if (machine_init_done
) {
2728 notify
->notify(notify
, NULL
);
2732 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2734 notifier_remove(notify
);
2737 static void qemu_run_machine_init_done_notifiers(void)
2739 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2740 machine_init_done
= true;
2743 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2744 const char **poptarg
, int *poptind
)
2746 const QEMUOption
*popt
;
2747 int optind
= *poptind
;
2748 char *r
= argv
[optind
];
2751 loc_set_cmdline(argv
, optind
, 1);
2753 /* Treat --foo the same as -foo. */
2756 popt
= qemu_options
;
2759 error_report("invalid option");
2762 if (!strcmp(popt
->name
, r
+ 1))
2766 if (popt
->flags
& HAS_ARG
) {
2767 if (optind
>= argc
) {
2768 error_report("requires an argument");
2771 optarg
= argv
[optind
++];
2772 loc_set_cmdline(argv
, optind
- 2, 2);
2783 static MachineClass
*select_machine(void)
2785 MachineClass
*machine_class
= find_default_machine();
2790 loc_push_none(&loc
);
2792 opts
= qemu_get_machine_opts();
2793 qemu_opts_loc_restore(opts
);
2795 optarg
= qemu_opt_get(opts
, "type");
2797 machine_class
= machine_parse(optarg
);
2800 if (!machine_class
) {
2801 error_report("No machine specified, and there is no default");
2802 error_printf("Use -machine help to list supported machines\n");
2807 return machine_class
;
2810 static int machine_set_property(void *opaque
,
2811 const char *name
, const char *value
,
2814 Object
*obj
= OBJECT(opaque
);
2815 Error
*local_err
= NULL
;
2818 if (strcmp(name
, "type") == 0) {
2822 qom_name
= g_strdup(name
);
2823 for (p
= qom_name
; *p
; p
++) {
2829 object_property_parse(obj
, value
, qom_name
, &local_err
);
2833 error_report_err(local_err
);
2842 * Initial object creation happens before all other
2843 * QEMU data types are created. The majority of objects
2844 * can be created at this point. The rng-egd object
2845 * cannot be created here, as it depends on the chardev
2848 static bool object_create_initial(const char *type
)
2850 if (g_str_equal(type
, "rng-egd")) {
2855 * return false for concrete netfilters since
2856 * they depend on netdevs already existing
2858 if (g_str_equal(type
, "filter-buffer") ||
2859 g_str_equal(type
, "filter-dump") ||
2860 g_str_equal(type
, "filter-mirror") ||
2861 g_str_equal(type
, "filter-redirector") ||
2862 g_str_equal(type
, "colo-compare") ||
2863 g_str_equal(type
, "filter-rewriter") ||
2864 g_str_equal(type
, "filter-replay")) {
2868 /* Memory allocation by backends needs to be done
2869 * after configure_accelerator() (due to the tcg_enabled()
2870 * checks at memory_region_init_*()).
2872 * Also, allocation of large amounts of memory may delay
2873 * chardev initialization for too long, and trigger timeouts
2874 * on software that waits for a monitor socket to be created
2877 if (g_str_has_prefix(type
, "memory-backend-")) {
2886 * The remainder of object creation happens after the
2887 * creation of chardev, fsdev, net clients and device data types.
2889 static bool object_create_delayed(const char *type
)
2891 return !object_create_initial(type
);
2895 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2899 const char *mem_str
;
2900 const char *maxmem_str
, *slots_str
;
2901 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2902 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2905 loc_push_none(&loc
);
2906 qemu_opts_loc_restore(opts
);
2909 mem_str
= qemu_opt_get(opts
, "size");
2912 error_report("missing 'size' option value");
2916 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2918 /* Fix up legacy suffix-less format */
2919 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2920 uint64_t overflow_check
= sz
;
2923 if ((sz
>> 20) != overflow_check
) {
2924 error_report("too large 'size' option value");
2930 /* backward compatibility behaviour for case "-m 0" */
2932 sz
= default_ram_size
;
2935 sz
= QEMU_ALIGN_UP(sz
, 8192);
2937 if (ram_size
!= sz
) {
2938 error_report("ram size too large");
2942 /* store value for the future use */
2943 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2944 *maxram_size
= ram_size
;
2946 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2947 slots_str
= qemu_opt_get(opts
, "slots");
2948 if (maxmem_str
&& slots_str
) {
2951 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2952 slots
= qemu_opt_get_number(opts
, "slots", 0);
2953 if (sz
< ram_size
) {
2954 error_report("invalid value of -m option maxmem: "
2955 "maximum memory size (0x%" PRIx64
") must be at least "
2956 "the initial memory size (0x" RAM_ADDR_FMT
")",
2959 } else if (sz
> ram_size
) {
2961 error_report("invalid value of -m option: maxmem was "
2962 "specified, but no hotplug slots were specified");
2966 error_report("invalid value of -m option maxmem: "
2967 "memory slots were specified but maximum memory size "
2968 "(0x%" PRIx64
") is equal to the initial memory size "
2969 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2975 } else if ((!maxmem_str
&& slots_str
) ||
2976 (maxmem_str
&& !slots_str
)) {
2977 error_report("invalid -m option value: missing "
2978 "'%s' option", slots_str
? "maxmem" : "slots");
2985 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2989 g
= g_malloc0(sizeof(*g
));
2990 g
->driver
= qemu_opt_get(opts
, "driver");
2991 g
->property
= qemu_opt_get(opts
, "property");
2992 g
->value
= qemu_opt_get(opts
, "value");
2993 g
->user_provided
= true;
2994 g
->errp
= &error_fatal
;
2995 qdev_prop_register_global(g
);
2999 int main(int argc
, char **argv
)
3002 int snapshot
, linux_boot
;
3003 const char *initrd_filename
;
3004 const char *kernel_filename
, *kernel_cmdline
;
3005 const char *boot_order
= NULL
;
3006 const char *boot_once
= NULL
;
3008 int cyls
, heads
, secs
, translation
;
3009 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
3010 QemuOptsList
*olist
;
3013 const char *loadvm
= NULL
;
3014 MachineClass
*machine_class
;
3015 const char *cpu_model
;
3016 const char *vga_model
= NULL
;
3017 const char *qtest_chrdev
= NULL
;
3018 const char *qtest_log
= NULL
;
3019 const char *pid_file
= NULL
;
3020 const char *incoming
= NULL
;
3021 bool defconfig
= true;
3022 bool userconfig
= true;
3023 bool nographic
= false;
3024 DisplayType display_type
= DT_DEFAULT
;
3025 int display_remote
= 0;
3026 const char *log_mask
= NULL
;
3027 const char *log_file
= NULL
;
3028 char *trace_file
= NULL
;
3029 ram_addr_t maxram_size
;
3030 uint64_t ram_slots
= 0;
3031 FILE *vmstate_dump_file
= NULL
;
3032 Error
*main_loop_err
= NULL
;
3034 bool list_data_dirs
= false;
3036 module_call_init(MODULE_INIT_TRACE
);
3038 qemu_init_cpu_list();
3039 qemu_init_cpu_loop();
3040 qemu_mutex_lock_iothread();
3042 atexit(qemu_run_exit_notifiers
);
3043 error_set_progname(argv
[0]);
3044 qemu_init_exec_dir(argv
[0]);
3046 module_call_init(MODULE_INIT_QOM
);
3047 module_call_init(MODULE_INIT_QAPI
);
3049 qemu_add_opts(&qemu_drive_opts
);
3050 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3051 qemu_add_drive_opts(&qemu_common_drive_opts
);
3052 qemu_add_drive_opts(&qemu_drive_opts
);
3053 qemu_add_drive_opts(&bdrv_runtime_opts
);
3054 qemu_add_opts(&qemu_chardev_opts
);
3055 qemu_add_opts(&qemu_device_opts
);
3056 qemu_add_opts(&qemu_netdev_opts
);
3057 qemu_add_opts(&qemu_net_opts
);
3058 qemu_add_opts(&qemu_rtc_opts
);
3059 qemu_add_opts(&qemu_global_opts
);
3060 qemu_add_opts(&qemu_mon_opts
);
3061 qemu_add_opts(&qemu_trace_opts
);
3062 qemu_add_opts(&qemu_option_rom_opts
);
3063 qemu_add_opts(&qemu_machine_opts
);
3064 qemu_add_opts(&qemu_mem_opts
);
3065 qemu_add_opts(&qemu_smp_opts
);
3066 qemu_add_opts(&qemu_boot_opts
);
3067 qemu_add_opts(&qemu_sandbox_opts
);
3068 qemu_add_opts(&qemu_add_fd_opts
);
3069 qemu_add_opts(&qemu_object_opts
);
3070 qemu_add_opts(&qemu_tpmdev_opts
);
3071 qemu_add_opts(&qemu_realtime_opts
);
3072 qemu_add_opts(&qemu_msg_opts
);
3073 qemu_add_opts(&qemu_name_opts
);
3074 qemu_add_opts(&qemu_numa_opts
);
3075 qemu_add_opts(&qemu_icount_opts
);
3076 qemu_add_opts(&qemu_semihosting_config_opts
);
3077 qemu_add_opts(&qemu_fw_cfg_opts
);
3078 #ifdef CONFIG_LIBISCSI
3079 qemu_add_opts(&qemu_iscsi_opts
);
3081 module_call_init(MODULE_INIT_OPTS
);
3085 if (qcrypto_init(&err
) < 0) {
3086 error_reportf_err(err
, "cannot initialize crypto: ");
3089 rtc_clock
= QEMU_CLOCK_HOST
;
3091 QLIST_INIT (&vm_change_state_head
);
3092 os_setup_early_signal_handling();
3096 cyls
= heads
= secs
= 0;
3097 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3101 bdrv_init_with_whitelist();
3105 /* first pass of option parsing */
3107 while (optind
< argc
) {
3108 if (argv
[optind
][0] != '-') {
3112 const QEMUOption
*popt
;
3114 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3115 switch (popt
->index
) {
3116 case QEMU_OPTION_nodefconfig
:
3119 case QEMU_OPTION_nouserconfig
:
3128 ret
= qemu_read_default_config_files(userconfig
);
3134 /* second pass of option parsing */
3139 if (argv
[optind
][0] != '-') {
3140 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3142 const QEMUOption
*popt
;
3144 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3145 if (!(popt
->arch_mask
& arch_type
)) {
3146 error_report("Option not supported for this target");
3149 switch(popt
->index
) {
3150 case QEMU_OPTION_no_kvm_irqchip
: {
3151 olist
= qemu_find_opts("machine");
3152 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3155 case QEMU_OPTION_cpu
:
3156 /* hw initialization will check this */
3159 case QEMU_OPTION_hda
:
3163 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3165 snprintf(buf
, sizeof(buf
),
3166 "%s,cyls=%d,heads=%d,secs=%d%s",
3167 HD_OPTS
, cyls
, heads
, secs
,
3168 translation
== BIOS_ATA_TRANSLATION_LBA
?
3170 translation
== BIOS_ATA_TRANSLATION_NONE
?
3171 ",trans=none" : "");
3172 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3175 case QEMU_OPTION_hdb
:
3176 case QEMU_OPTION_hdc
:
3177 case QEMU_OPTION_hdd
:
3178 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3181 case QEMU_OPTION_drive
:
3182 if (drive_def(optarg
) == NULL
) {
3186 case QEMU_OPTION_set
:
3187 if (qemu_set_option(optarg
) != 0)
3190 case QEMU_OPTION_global
:
3191 if (qemu_global_option(optarg
) != 0)
3194 case QEMU_OPTION_mtdblock
:
3195 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3197 case QEMU_OPTION_sd
:
3198 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3200 case QEMU_OPTION_pflash
:
3201 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3203 case QEMU_OPTION_snapshot
:
3206 case QEMU_OPTION_hdachs
:
3210 cyls
= strtol(p
, (char **)&p
, 0);
3211 if (cyls
< 1 || cyls
> 16383)
3216 heads
= strtol(p
, (char **)&p
, 0);
3217 if (heads
< 1 || heads
> 16)
3222 secs
= strtol(p
, (char **)&p
, 0);
3223 if (secs
< 1 || secs
> 63)
3227 if (!strcmp(p
, "large")) {
3228 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3229 } else if (!strcmp(p
, "rechs")) {
3230 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3231 } else if (!strcmp(p
, "none")) {
3232 translation
= BIOS_ATA_TRANSLATION_NONE
;
3233 } else if (!strcmp(p
, "lba")) {
3234 translation
= BIOS_ATA_TRANSLATION_LBA
;
3235 } else if (!strcmp(p
, "auto")) {
3236 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3240 } else if (*p
!= '\0') {
3242 error_report("invalid physical CHS format");
3245 if (hda_opts
!= NULL
) {
3246 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3248 qemu_opt_set_number(hda_opts
, "heads", heads
,
3250 qemu_opt_set_number(hda_opts
, "secs", secs
,
3252 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3253 qemu_opt_set(hda_opts
, "trans", "large",
3255 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3256 qemu_opt_set(hda_opts
, "trans", "rechs",
3258 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3259 qemu_opt_set(hda_opts
, "trans", "lba",
3261 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3262 qemu_opt_set(hda_opts
, "trans", "none",
3268 case QEMU_OPTION_numa
:
3269 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3275 case QEMU_OPTION_display
:
3276 display_type
= select_display(optarg
);
3278 case QEMU_OPTION_nographic
:
3279 olist
= qemu_find_opts("machine");
3280 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3282 display_type
= DT_NONE
;
3284 case QEMU_OPTION_curses
:
3285 #ifdef CONFIG_CURSES
3286 display_type
= DT_CURSES
;
3288 error_report("curses support is disabled");
3292 case QEMU_OPTION_portrait
:
3293 graphic_rotate
= 90;
3295 case QEMU_OPTION_rotate
:
3296 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3297 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3298 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3299 error_report("only 90, 180, 270 deg rotation is available");
3303 case QEMU_OPTION_kernel
:
3304 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3307 case QEMU_OPTION_initrd
:
3308 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3311 case QEMU_OPTION_append
:
3312 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3315 case QEMU_OPTION_dtb
:
3316 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3319 case QEMU_OPTION_cdrom
:
3320 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3322 case QEMU_OPTION_boot
:
3323 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3329 case QEMU_OPTION_fda
:
3330 case QEMU_OPTION_fdb
:
3331 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3334 case QEMU_OPTION_no_fd_bootchk
:
3337 case QEMU_OPTION_netdev
:
3339 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3343 case QEMU_OPTION_net
:
3345 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3349 #ifdef CONFIG_LIBISCSI
3350 case QEMU_OPTION_iscsi
:
3351 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3359 case QEMU_OPTION_tftp
:
3360 error_report("The -tftp option is deprecated. "
3361 "Please use '-netdev user,tftp=...' instead.");
3362 legacy_tftp_prefix
= optarg
;
3364 case QEMU_OPTION_bootp
:
3365 error_report("The -bootp option is deprecated. "
3366 "Please use '-netdev user,bootfile=...' instead.");
3367 legacy_bootp_filename
= optarg
;
3369 case QEMU_OPTION_redir
:
3370 error_report("The -redir option is deprecated. "
3371 "Please use '-netdev user,hostfwd=...' instead.");
3372 if (net_slirp_redir(optarg
) < 0)
3376 case QEMU_OPTION_bt
:
3377 add_device_config(DEV_BT
, optarg
);
3379 case QEMU_OPTION_audio_help
:
3383 case QEMU_OPTION_soundhw
:
3384 select_soundhw (optarg
);
3389 case QEMU_OPTION_version
:
3394 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3401 case QEMU_OPTION_tpmdev
:
3402 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3407 case QEMU_OPTION_mempath
:
3410 case QEMU_OPTION_mem_prealloc
:
3419 case QEMU_OPTION_DFILTER
:
3420 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3423 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3425 case QEMU_OPTION_gdb
:
3426 add_device_config(DEV_GDB
, optarg
);
3429 if (is_help_option(optarg
)) {
3430 list_data_dirs
= true;
3431 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3432 data_dir
[data_dir_idx
++] = optarg
;
3435 case QEMU_OPTION_bios
:
3436 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3439 case QEMU_OPTION_singlestep
:
3446 keyboard_layout
= optarg
;
3448 case QEMU_OPTION_localtime
:
3451 case QEMU_OPTION_vga
:
3460 w
= strtol(p
, (char **)&p
, 10);
3463 error_report("invalid resolution or depth");
3469 h
= strtol(p
, (char **)&p
, 10);
3474 depth
= strtol(p
, (char **)&p
, 10);
3475 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3476 depth
!= 24 && depth
!= 32)
3478 } else if (*p
== '\0') {
3479 depth
= graphic_depth
;
3486 graphic_depth
= depth
;
3489 case QEMU_OPTION_echr
:
3492 term_escape_char
= strtol(optarg
, &r
, 0);
3494 printf("Bad argument to echr\n");
3497 case QEMU_OPTION_monitor
:
3498 default_monitor
= 0;
3499 if (strncmp(optarg
, "none", 4)) {
3500 monitor_parse(optarg
, "readline", false);
3503 case QEMU_OPTION_qmp
:
3504 monitor_parse(optarg
, "control", false);
3505 default_monitor
= 0;
3507 case QEMU_OPTION_qmp_pretty
:
3508 monitor_parse(optarg
, "control", true);
3509 default_monitor
= 0;
3511 case QEMU_OPTION_mon
:
3512 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3517 default_monitor
= 0;
3519 case QEMU_OPTION_chardev
:
3520 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3526 case QEMU_OPTION_fsdev
:
3527 olist
= qemu_find_opts("fsdev");
3529 error_report("fsdev support is disabled");
3532 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3537 case QEMU_OPTION_virtfs
: {
3540 const char *writeout
, *sock_fd
, *socket
;
3542 olist
= qemu_find_opts("virtfs");
3544 error_report("virtfs support is disabled");
3547 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3552 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3553 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3554 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3557 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3558 qemu_opt_get(opts
, "mount_tag"),
3561 error_report("duplicate fsdev id: %s",
3562 qemu_opt_get(opts
, "mount_tag"));
3566 writeout
= qemu_opt_get(opts
, "writeout");
3568 #ifdef CONFIG_SYNC_FILE_RANGE
3569 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3571 error_report("writeout=immediate not supported "
3572 "on this platform");
3576 qemu_opt_set(fsdev
, "fsdriver",
3577 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3578 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3580 qemu_opt_set(fsdev
, "security_model",
3581 qemu_opt_get(opts
, "security_model"),
3583 socket
= qemu_opt_get(opts
, "socket");
3585 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3587 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3589 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3592 qemu_opt_set_bool(fsdev
, "readonly",
3593 qemu_opt_get_bool(opts
, "readonly", 0),
3595 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3597 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3598 qemu_opt_set(device
, "fsdev",
3599 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3600 qemu_opt_set(device
, "mount_tag",
3601 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3604 case QEMU_OPTION_virtfs_synth
: {
3608 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3611 error_report("duplicate option: %s", "virtfs_synth");
3614 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3616 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3618 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3619 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3620 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3623 case QEMU_OPTION_serial
:
3624 add_device_config(DEV_SERIAL
, optarg
);
3626 if (strncmp(optarg
, "mon:", 4) == 0) {
3627 default_monitor
= 0;
3630 case QEMU_OPTION_watchdog
:
3632 error_report("only one watchdog option may be given");
3637 case QEMU_OPTION_watchdog_action
:
3638 if (select_watchdog_action(optarg
) == -1) {
3639 error_report("unknown -watchdog-action parameter");
3643 case QEMU_OPTION_virtiocon
:
3644 add_device_config(DEV_VIRTCON
, optarg
);
3645 default_virtcon
= 0;
3646 if (strncmp(optarg
, "mon:", 4) == 0) {
3647 default_monitor
= 0;
3650 case QEMU_OPTION_parallel
:
3651 add_device_config(DEV_PARALLEL
, optarg
);
3652 default_parallel
= 0;
3653 if (strncmp(optarg
, "mon:", 4) == 0) {
3654 default_monitor
= 0;
3657 case QEMU_OPTION_debugcon
:
3658 add_device_config(DEV_DEBUGCON
, optarg
);
3660 case QEMU_OPTION_loadvm
:
3663 case QEMU_OPTION_full_screen
:
3666 case QEMU_OPTION_no_frame
:
3669 case QEMU_OPTION_alt_grab
:
3672 case QEMU_OPTION_ctrl_grab
:
3675 case QEMU_OPTION_no_quit
:
3678 case QEMU_OPTION_sdl
:
3680 display_type
= DT_SDL
;
3683 error_report("SDL support is disabled");
3686 case QEMU_OPTION_pidfile
:
3689 case QEMU_OPTION_win2k_hack
:
3690 win2k_install_hack
= 1;
3692 case QEMU_OPTION_rtc_td_hack
: {
3693 static GlobalProperty slew_lost_ticks
= {
3694 .driver
= "mc146818rtc",
3695 .property
= "lost_tick_policy",
3699 qdev_prop_register_global(&slew_lost_ticks
);
3702 case QEMU_OPTION_acpitable
:
3703 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3708 acpi_table_add(opts
, &error_fatal
);
3710 case QEMU_OPTION_smbios
:
3711 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3716 smbios_entry_add(opts
, &error_fatal
);
3718 case QEMU_OPTION_fwcfg
:
3719 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3725 case QEMU_OPTION_enable_kvm
:
3726 olist
= qemu_find_opts("machine");
3727 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3729 case QEMU_OPTION_enable_hax
:
3730 olist
= qemu_find_opts("machine");
3731 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3734 case QEMU_OPTION_machine
:
3735 olist
= qemu_find_opts("machine");
3736 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3741 case QEMU_OPTION_no_kvm
:
3742 olist
= qemu_find_opts("machine");
3743 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3745 case QEMU_OPTION_no_kvm_pit
: {
3746 error_report("warning: ignoring deprecated option");
3749 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3750 static GlobalProperty kvm_pit_lost_tick_policy
= {
3751 .driver
= "kvm-pit",
3752 .property
= "lost_tick_policy",
3756 error_report("warning: deprecated, replaced by "
3757 "-global kvm-pit.lost_tick_policy=discard");
3758 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3761 case QEMU_OPTION_usb
:
3762 olist
= qemu_find_opts("machine");
3763 qemu_opts_parse_noisily(olist
, "usb=on", false);
3765 case QEMU_OPTION_usbdevice
:
3766 olist
= qemu_find_opts("machine");
3767 qemu_opts_parse_noisily(olist
, "usb=on", false);
3768 add_device_config(DEV_USB
, optarg
);
3770 case QEMU_OPTION_device
:
3771 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3776 case QEMU_OPTION_smp
:
3777 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3782 case QEMU_OPTION_vnc
:
3783 vnc_parse(optarg
, &error_fatal
);
3785 case QEMU_OPTION_no_acpi
:
3788 case QEMU_OPTION_no_hpet
:
3791 case QEMU_OPTION_balloon
:
3792 if (balloon_parse(optarg
) < 0) {
3793 error_report("unknown -balloon argument %s", optarg
);
3797 case QEMU_OPTION_no_reboot
:
3800 case QEMU_OPTION_no_shutdown
:
3803 case QEMU_OPTION_show_cursor
:
3806 case QEMU_OPTION_uuid
:
3807 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3808 error_report("failed to parse UUID string: wrong format");
3811 qemu_uuid_set
= true;
3813 case QEMU_OPTION_option_rom
:
3814 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3815 error_report("too many option ROMs");
3818 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3823 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3824 option_rom
[nb_option_roms
].bootindex
=
3825 qemu_opt_get_number(opts
, "bootindex", -1);
3826 if (!option_rom
[nb_option_roms
].name
) {
3827 error_report("Option ROM file is not specified");
3832 case QEMU_OPTION_semihosting
:
3833 semihosting
.enabled
= true;
3834 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3836 case QEMU_OPTION_semihosting_config
:
3837 semihosting
.enabled
= true;
3838 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3841 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3843 const char *target
= qemu_opt_get(opts
, "target");
3844 if (target
!= NULL
) {
3845 if (strcmp("native", target
) == 0) {
3846 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3847 } else if (strcmp("gdb", target
) == 0) {
3848 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3849 } else if (strcmp("auto", target
) == 0) {
3850 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3852 error_report("unsupported semihosting-config %s",
3857 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3859 /* Set semihosting argument count and vector */
3860 qemu_opt_foreach(opts
, add_semihosting_arg
,
3861 &semihosting
, NULL
);
3863 error_report("unsupported semihosting-config %s", optarg
);
3867 case QEMU_OPTION_tdf
:
3868 error_report("warning: ignoring deprecated option");
3870 case QEMU_OPTION_name
:
3871 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3877 case QEMU_OPTION_prom_env
:
3878 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3879 error_report("too many prom variables");
3882 prom_envs
[nb_prom_envs
] = optarg
;
3885 case QEMU_OPTION_old_param
:
3888 case QEMU_OPTION_clock
:
3889 /* Clock options no longer exist. Keep this option for
3890 * backward compatibility.
3893 case QEMU_OPTION_startdate
:
3894 configure_rtc_date_offset(optarg
, 1);
3896 case QEMU_OPTION_rtc
:
3897 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3902 configure_rtc(opts
);
3904 case QEMU_OPTION_tb_size
:
3905 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3906 if (tcg_tb_size
< 0) {
3910 case QEMU_OPTION_icount
:
3911 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3917 case QEMU_OPTION_incoming
:
3919 runstate_set(RUN_STATE_INMIGRATE
);
3923 case QEMU_OPTION_nodefaults
:
3926 case QEMU_OPTION_xen_domid
:
3927 if (!(xen_available())) {
3928 error_report("Option not supported for this target");
3931 xen_domid
= atoi(optarg
);
3933 case QEMU_OPTION_xen_create
:
3934 if (!(xen_available())) {
3935 error_report("Option not supported for this target");
3938 xen_mode
= XEN_CREATE
;
3940 case QEMU_OPTION_xen_attach
:
3941 if (!(xen_available())) {
3942 error_report("Option not supported for this target");
3945 xen_mode
= XEN_ATTACH
;
3947 case QEMU_OPTION_trace
:
3949 trace_file
= trace_opt_parse(optarg
);
3951 case QEMU_OPTION_trace_unassigned
:
3952 trace_unassigned
= true;
3954 case QEMU_OPTION_readconfig
:
3956 int ret
= qemu_read_config_file(optarg
);
3958 error_report("read config %s: %s", optarg
,
3964 case QEMU_OPTION_spice
:
3965 olist
= qemu_find_opts("spice");
3967 error_report("spice support is disabled");
3970 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3976 case QEMU_OPTION_writeconfig
:
3979 if (strcmp(optarg
, "-") == 0) {
3982 fp
= fopen(optarg
, "w");
3984 error_report("open %s: %s", optarg
,
3989 qemu_config_write(fp
);
3995 case QEMU_OPTION_qtest
:
3996 qtest_chrdev
= optarg
;
3998 case QEMU_OPTION_qtest_log
:
4001 case QEMU_OPTION_sandbox
:
4002 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4008 case QEMU_OPTION_add_fd
:
4010 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4016 error_report("File descriptor passing is disabled on this "
4021 case QEMU_OPTION_object
:
4022 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
4028 case QEMU_OPTION_realtime
:
4029 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4034 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4036 case QEMU_OPTION_msg
:
4037 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4042 configure_msg(opts
);
4044 case QEMU_OPTION_dump_vmstate
:
4045 if (vmstate_dump_file
) {
4046 error_report("only one '-dump-vmstate' "
4047 "option may be given");
4050 vmstate_dump_file
= fopen(optarg
, "w");
4051 if (vmstate_dump_file
== NULL
) {
4052 error_report("open %s: %s", optarg
, strerror(errno
));
4057 os_parse_cmd_args(popt
->index
, optarg
);
4062 * Clear error location left behind by the loop.
4063 * Best done right after the loop. Do not insert code here!
4067 replay_configure(icount_opts
);
4069 machine_class
= select_machine();
4071 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4075 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4076 error_report("could not acquire pid file: %s", strerror(errno
));
4080 if (qemu_init_main_loop(&main_loop_err
)) {
4081 error_report_err(main_loop_err
);
4085 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4086 parse_sandbox
, NULL
, NULL
)) {
4090 if (qemu_opts_foreach(qemu_find_opts("name"),
4091 parse_name
, NULL
, NULL
)) {
4096 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4097 parse_add_fd
, NULL
, NULL
)) {
4101 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4102 cleanup_add_fd
, NULL
, NULL
)) {
4107 current_machine
= MACHINE(object_new(object_class_get_name(
4108 OBJECT_CLASS(machine_class
))));
4109 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4112 object_property_add_child(object_get_root(), "machine",
4113 OBJECT(current_machine
), &error_abort
);
4115 if (machine_class
->minimum_page_bits
) {
4116 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4117 /* This would be a board error: specifying a minimum smaller than
4118 * a target's compile-time fixed setting.
4120 g_assert_not_reached();
4124 cpu_exec_init_all();
4126 if (machine_class
->hw_version
) {
4127 qemu_set_hw_version(machine_class
->hw_version
);
4130 if (cpu_model
&& is_help_option(cpu_model
)) {
4131 list_cpus(stdout
, &fprintf
, cpu_model
);
4135 if (!trace_init_backends()) {
4138 trace_init_file(trace_file
);
4140 /* Open the logfile at this point and set the log mask if necessary.
4143 qemu_set_log_filename(log_file
, &error_fatal
);
4148 mask
= qemu_str_to_log_mask(log_mask
);
4150 qemu_print_log_usage(stdout
);
4158 /* If no data_dir is specified then try to find it relative to the
4160 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4161 data_dir
[data_dir_idx
] = os_find_datadir();
4162 if (data_dir
[data_dir_idx
] != NULL
) {
4166 /* If all else fails use the install path specified when building. */
4167 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4168 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4171 /* -L help lists the data directories and exits. */
4172 if (list_data_dirs
) {
4173 for (i
= 0; i
< data_dir_idx
; i
++) {
4174 printf("%s\n", data_dir
[i
]);
4179 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4181 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4182 if (max_cpus
> machine_class
->max_cpus
) {
4183 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4184 "supported by machine '%s' (%d)", max_cpus
,
4185 machine_class
->name
, machine_class
->max_cpus
);
4190 * Get the default machine options from the machine if it is not already
4191 * specified either by the configuration file or by the command line.
4193 if (machine_class
->default_machine_opts
) {
4194 qemu_opts_set_defaults(qemu_find_opts("machine"),
4195 machine_class
->default_machine_opts
, 0);
4198 qemu_opts_foreach(qemu_find_opts("device"),
4199 default_driver_check
, NULL
, NULL
);
4200 qemu_opts_foreach(qemu_find_opts("global"),
4201 default_driver_check
, NULL
, NULL
);
4203 if (!vga_model
&& !default_vga
) {
4204 vga_interface_type
= VGA_DEVICE
;
4206 if (!has_defaults
|| machine_class
->no_serial
) {
4209 if (!has_defaults
|| machine_class
->no_parallel
) {
4210 default_parallel
= 0;
4212 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4213 default_virtcon
= 0;
4215 if (!has_defaults
|| !machine_class
->use_sclp
) {
4218 if (!has_defaults
|| machine_class
->no_floppy
) {
4221 if (!has_defaults
|| machine_class
->no_cdrom
) {
4224 if (!has_defaults
|| machine_class
->no_sdcard
) {
4227 if (!has_defaults
) {
4228 default_monitor
= 0;
4233 if (is_daemonized()) {
4234 /* According to documentation and historically, -nographic redirects
4235 * serial port, parallel port and monitor to stdio, which does not work
4236 * with -daemonize. We can redirect these to null instead, but since
4237 * -nographic is legacy, let's just error out.
4238 * We disallow -nographic only if all other ports are not redirected
4239 * explicitly, to not break existing legacy setups which uses
4240 * -nographic _and_ redirects all ports explicitly - this is valid
4241 * usage, -nographic is just a no-op in this case.
4244 && (default_parallel
|| default_serial
4245 || default_monitor
|| default_virtcon
)) {
4246 error_report("-nographic cannot be used with -daemonize");
4249 #ifdef CONFIG_CURSES
4250 if (display_type
== DT_CURSES
) {
4251 error_report("curses display cannot be used with -daemonize");
4258 if (default_parallel
)
4259 add_device_config(DEV_PARALLEL
, "null");
4260 if (default_serial
&& default_monitor
) {
4261 add_device_config(DEV_SERIAL
, "mon:stdio");
4262 } else if (default_virtcon
&& default_monitor
) {
4263 add_device_config(DEV_VIRTCON
, "mon:stdio");
4264 } else if (default_sclp
&& default_monitor
) {
4265 add_device_config(DEV_SCLP
, "mon:stdio");
4268 add_device_config(DEV_SERIAL
, "stdio");
4269 if (default_virtcon
)
4270 add_device_config(DEV_VIRTCON
, "stdio");
4272 add_device_config(DEV_SCLP
, "stdio");
4274 if (default_monitor
)
4275 monitor_parse("stdio", "readline", false);
4279 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4280 if (default_parallel
)
4281 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4282 if (default_monitor
)
4283 monitor_parse("vc:80Cx24C", "readline", false);
4284 if (default_virtcon
)
4285 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4287 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4291 #if defined(CONFIG_VNC)
4292 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4296 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4297 #if defined(CONFIG_GTK)
4298 display_type
= DT_GTK
;
4299 #elif defined(CONFIG_SDL)
4300 display_type
= DT_SDL
;
4301 #elif defined(CONFIG_COCOA)
4302 display_type
= DT_COCOA
;
4303 #elif defined(CONFIG_VNC)
4304 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4306 display_type
= DT_NONE
;
4310 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4311 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4312 "for SDL, ignoring option");
4314 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4315 error_report("-no-quit is only valid for GTK and SDL, "
4319 if (display_type
== DT_GTK
) {
4320 early_gtk_display_init(request_opengl
);
4323 if (display_type
== DT_SDL
) {
4324 sdl_display_early_init(request_opengl
);
4327 if (request_opengl
== 1 && display_opengl
== 0) {
4328 #if defined(CONFIG_OPENGL)
4329 error_report("OpenGL is not supported by the display");
4331 error_report("OpenGL support is disabled");
4339 if (qemu_opts_foreach(qemu_find_opts("object"),
4340 user_creatable_add_opts_foreach
,
4341 object_create_initial
, NULL
)) {
4345 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4346 chardev_init_func
, NULL
, NULL
)) {
4350 #ifdef CONFIG_VIRTFS
4351 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4352 fsdev_init_func
, NULL
, NULL
)) {
4357 if (qemu_opts_foreach(qemu_find_opts("device"),
4358 device_help_func
, NULL
, NULL
)) {
4362 machine_opts
= qemu_get_machine_opts();
4363 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4365 object_unref(OBJECT(current_machine
));
4369 configure_accelerator(current_machine
);
4372 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4375 machine_opts
= qemu_get_machine_opts();
4376 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4377 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4378 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4379 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4381 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4383 boot_order
= qemu_opt_get(opts
, "order");
4385 validate_bootdevices(boot_order
, &error_fatal
);
4388 boot_once
= qemu_opt_get(opts
, "once");
4390 validate_bootdevices(boot_once
, &error_fatal
);
4393 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4394 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4398 boot_order
= machine_class
->default_boot_order
;
4401 if (!kernel_cmdline
) {
4402 kernel_cmdline
= "";
4403 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4406 linux_boot
= (kernel_filename
!= NULL
);
4408 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4409 error_report("-append only allowed with -kernel option");
4413 if (!linux_boot
&& initrd_filename
!= NULL
) {
4414 error_report("-initrd only allowed with -kernel option");
4418 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4419 /* fall back to the -kernel/-append */
4420 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4423 os_set_line_buffering();
4425 /* spice needs the timers to be initialized by this point */
4430 if (!tcg_enabled()) {
4431 error_report("-icount is not allowed with hardware virtualization");
4434 configure_icount(icount_opts
, &error_abort
);
4435 qemu_opts_del(icount_opts
);
4439 QemuOptsList
*net
= qemu_find_opts("net");
4440 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4442 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4448 if (net_init_clients() < 0) {
4452 if (qemu_opts_foreach(qemu_find_opts("object"),
4453 user_creatable_add_opts_foreach
,
4454 object_create_delayed
, NULL
)) {
4459 if (tpm_init() < 0) {
4464 /* init the bluetooth world */
4465 if (foreach_device_config(DEV_BT
, bt_parse
))
4468 if (!xen_enabled()) {
4469 /* On 32-bit hosts, QEMU is limited by virtual address space */
4470 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4471 error_report("at most 2047 MB RAM can be simulated");
4479 /* If the currently selected machine wishes to override the units-per-bus
4480 * property of its default HBA interface type, do so now. */
4481 if (machine_class
->units_per_default_bus
) {
4482 override_max_devs(machine_class
->block_default_type
,
4483 machine_class
->units_per_default_bus
);
4486 /* open the virtual block devices */
4487 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4488 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4491 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4492 &machine_class
->block_default_type
, NULL
)) {
4496 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4498 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4499 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4501 parse_numa_opts(machine_class
);
4503 if (qemu_opts_foreach(qemu_find_opts("mon"),
4504 mon_init_func
, NULL
, NULL
)) {
4508 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4510 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4512 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4514 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4517 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4520 /* If no default VGA is requested, the default is "none". */
4522 if (machine_class
->default_display
) {
4523 vga_model
= machine_class
->default_display
;
4524 } else if (vga_interface_available(VGA_CIRRUS
)) {
4525 vga_model
= "cirrus";
4526 } else if (vga_interface_available(VGA_STD
)) {
4531 select_vgahw(vga_model
);
4535 i
= select_watchdog(watchdog
);
4537 exit (i
== 1 ? 1 : 0);
4540 machine_register_compat_props(current_machine
);
4542 qemu_opts_foreach(qemu_find_opts("global"),
4543 global_init_func
, NULL
, NULL
);
4545 /* This checkpoint is required by replay to separate prior clock
4546 reading from the other reads, because timer polling functions query
4547 clock values from the log. */
4548 replay_checkpoint(CHECKPOINT_INIT
);
4549 qdev_machine_init();
4551 current_machine
->ram_size
= ram_size
;
4552 current_machine
->maxram_size
= maxram_size
;
4553 current_machine
->ram_slots
= ram_slots
;
4554 current_machine
->boot_order
= boot_order
;
4555 current_machine
->cpu_model
= cpu_model
;
4557 machine_class
->init(current_machine
);
4563 cpu_synchronize_all_post_init();
4565 numa_post_machine_init();
4567 if (hax_enabled()) {
4571 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4572 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4576 /* init USB devices */
4577 if (machine_usb(current_machine
)) {
4578 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4582 /* Check if IGD GFX passthrough. */
4585 /* init generic devices */
4586 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4587 if (qemu_opts_foreach(qemu_find_opts("device"),
4588 device_init_func
, NULL
, NULL
)) {
4591 rom_reset_order_override();
4593 /* Did we create any drives that we failed to create a device for? */
4594 drive_check_orphaned();
4596 /* Don't warn about the default network setup that you get if
4597 * no command line -net or -netdev options are specified. There
4598 * are two cases that we would otherwise complain about:
4599 * (1) board doesn't support a NIC but the implicit "-net nic"
4601 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4602 * sets up a nic that isn't connected to anything.
4605 net_check_clients();
4610 qemu_boot_set(boot_once
, &error_fatal
);
4611 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4614 ds
= init_displaystate();
4616 /* init local displays */
4617 switch (display_type
) {
4619 curses_display_init(ds
, full_screen
);
4622 sdl_display_init(ds
, full_screen
, no_frame
);
4625 cocoa_display_init(ds
, full_screen
);
4628 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4634 /* must be after terminal init, SDL library changes signal handlers */
4635 os_setup_signal_handling();
4637 /* init remote displays */
4639 qemu_opts_foreach(qemu_find_opts("vnc"),
4640 vnc_init_func
, NULL
, NULL
);
4644 qemu_spice_display_init();
4647 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4651 qdev_machine_creation_done();
4653 /* TODO: once all bus devices are qdevified, this should be done
4654 * when bus is created by qdev.c */
4655 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4656 qemu_run_machine_init_done_notifiers();
4658 if (rom_check_and_register_reset() != 0) {
4659 error_report("rom check and register reset failed");
4665 /* This checkpoint is required by replay to separate prior clock
4666 reading from the other reads, because timer polling functions query
4667 clock values from the log. */
4668 replay_checkpoint(CHECKPOINT_RESET
);
4669 qemu_system_reset(VMRESET_SILENT
);
4670 register_global_state();
4672 if (load_vmstate(loadvm
) < 0) {
4677 qdev_prop_check_globals();
4678 if (vmstate_dump_file
) {
4680 dump_vmstate_json_to_file(vmstate_dump_file
);
4685 Error
*local_err
= NULL
;
4686 qemu_start_incoming_migration(incoming
, &local_err
);
4688 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4691 } else if (autostart
) {
4698 replay_disable_events();
4699 iothread_stop_all();
4705 /* vhost-user must be cleaned up before chardevs. */