4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "qemu/osdep.h"
25 #include "qemu-version.h"
26 #include "qemu/cutils.h"
27 #include "qemu/help_option.h"
28 #include "qemu/uuid.h"
31 #include "sysemu/seccomp.h"
34 #if defined(CONFIG_VDE)
35 #include <libvdeplug.h>
39 #if defined(__APPLE__) || defined(main)
41 int qemu_main(int argc
, char **argv
, char **envp
);
42 int main(int argc
, char **argv
)
44 return qemu_main(argc
, argv
, NULL
);
47 #define main qemu_main
49 #endif /* CONFIG_SDL */
53 #define main qemu_main
54 #endif /* CONFIG_COCOA */
57 #include "qemu/error-report.h"
58 #include "qemu/sockets.h"
60 #include "hw/boards.h"
61 #include "sysemu/accel.h"
63 #include "hw/i386/pc.h"
64 #include "hw/isa/isa.h"
66 #include "sysemu/watchdog.h"
67 #include "hw/smbios/smbios.h"
68 #include "hw/acpi/acpi.h"
69 #include "hw/xen/xen.h"
71 #include "hw/loader.h"
72 #include "monitor/qdev.h"
73 #include "sysemu/bt.h"
75 #include "net/slirp.h"
76 #include "monitor/monitor.h"
77 #include "ui/console.h"
79 #include "sysemu/sysemu.h"
80 #include "sysemu/numa.h"
81 #include "exec/gdbstub.h"
82 #include "qemu/timer.h"
83 #include "sysemu/char.h"
84 #include "qemu/bitmap.h"
86 #include "sysemu/blockdev.h"
87 #include "hw/block/block.h"
88 #include "migration/block.h"
89 #include "sysemu/tpm.h"
90 #include "sysemu/dma.h"
91 #include "audio/audio.h"
92 #include "migration/migration.h"
93 #include "sysemu/cpus.h"
94 #include "migration/colo.h"
95 #include "sysemu/kvm.h"
96 #include "sysemu/hax.h"
97 #include "qapi/qmp/qjson.h"
98 #include "qemu/option.h"
99 #include "qemu/config-file.h"
100 #include "qemu-options.h"
101 #include "qmp-commands.h"
102 #include "qemu/main-loop.h"
104 #include "fsdev/qemu-fsdev.h"
106 #include "sysemu/qtest.h"
108 #include "disas/disas.h"
111 #include "slirp/libslirp.h"
113 #include "trace-root.h"
114 #include "trace/control.h"
115 #include "qemu/queue.h"
116 #include "sysemu/arch_init.h"
118 #include "ui/qemu-spice.h"
119 #include "qapi/string-input-visitor.h"
120 #include "qapi/opts-visitor.h"
121 #include "qom/object_interfaces.h"
122 #include "qapi-event.h"
123 #include "exec/semihost.h"
124 #include "crypto/init.h"
125 #include "sysemu/replay.h"
126 #include "qapi/qmp/qerror.h"
127 #include "sysemu/iothread.h"
129 #define MAX_VIRTIO_CONSOLES 1
130 #define MAX_SCLP_CONSOLES 1
132 static const char *data_dir
[16];
133 static int data_dir_idx
;
134 const char *bios_name
= NULL
;
135 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
136 int request_opengl
= -1;
138 const char* keyboard_layout
= NULL
;
140 const char *mem_path
= NULL
;
141 int mem_prealloc
= 0; /* force preallocation of physical target memory */
142 bool enable_mlock
= false;
144 NICInfo nd_table
[MAX_NICS
];
146 static int rtc_utc
= 1;
147 static int rtc_date_offset
= -1; /* -1 means no change */
148 QEMUClockType rtc_clock
;
149 int vga_interface_type
= VGA_NONE
;
150 static int full_screen
= 0;
151 static int no_frame
= 0;
153 static bool grab_on_hover
;
154 Chardev
*serial_hds
[MAX_SERIAL_PORTS
];
155 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
156 Chardev
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
157 Chardev
*sclp_hds
[MAX_SCLP_CONSOLES
];
158 int win2k_install_hack
= 0;
164 int acpi_enabled
= 1;
167 static int no_reboot
;
170 int graphic_rotate
= 0;
171 const char *watchdog
;
172 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
175 const char *qemu_name
;
178 unsigned int nb_prom_envs
= 0;
179 const char *prom_envs
[MAX_PROM_ENVS
];
182 uint8_t *boot_splash_filedata
;
183 size_t boot_splash_filedata_size
;
184 uint8_t qemu_extra_params_fw
[2];
185 int only_migratable
; /* turn it off unless user states otherwise */
187 int icount_align_option
;
189 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
190 * little-endian "wire format" described in the SMBIOS 2.6 specification.
195 static NotifierList exit_notifiers
=
196 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
198 static NotifierList machine_init_done_notifiers
=
199 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
203 enum xen_mode xen_mode
= XEN_EMULATE
;
205 static int has_defaults
= 1;
206 static int default_serial
= 1;
207 static int default_parallel
= 1;
208 static int default_virtcon
= 1;
209 static int default_sclp
= 1;
210 static int default_monitor
= 1;
211 static int default_floppy
= 1;
212 static int default_cdrom
= 1;
213 static int default_sdcard
= 1;
214 static int default_vga
= 1;
215 static int default_net
= 1;
221 { .driver
= "isa-serial", .flag
= &default_serial
},
222 { .driver
= "isa-parallel", .flag
= &default_parallel
},
223 { .driver
= "isa-fdc", .flag
= &default_floppy
},
224 { .driver
= "floppy", .flag
= &default_floppy
},
225 { .driver
= "ide-cd", .flag
= &default_cdrom
},
226 { .driver
= "ide-hd", .flag
= &default_cdrom
},
227 { .driver
= "ide-drive", .flag
= &default_cdrom
},
228 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
229 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
230 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
231 { .driver
= "VGA", .flag
= &default_vga
},
232 { .driver
= "isa-vga", .flag
= &default_vga
},
233 { .driver
= "cirrus-vga", .flag
= &default_vga
},
234 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
235 { .driver
= "vmware-svga", .flag
= &default_vga
},
236 { .driver
= "qxl-vga", .flag
= &default_vga
},
237 { .driver
= "virtio-vga", .flag
= &default_vga
},
240 static QemuOptsList qemu_rtc_opts
= {
242 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
246 .type
= QEMU_OPT_STRING
,
249 .type
= QEMU_OPT_STRING
,
252 .type
= QEMU_OPT_STRING
,
254 { /* end of list */ }
258 static QemuOptsList qemu_sandbox_opts
= {
260 .implied_opt_name
= "enable",
261 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
265 .type
= QEMU_OPT_BOOL
,
267 { /* end of list */ }
271 static QemuOptsList qemu_option_rom_opts
= {
272 .name
= "option-rom",
273 .implied_opt_name
= "romfile",
274 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
278 .type
= QEMU_OPT_NUMBER
,
281 .type
= QEMU_OPT_STRING
,
283 { /* end of list */ }
287 static QemuOptsList qemu_machine_opts
= {
289 .implied_opt_name
= "type",
291 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
294 * no elements => accept any
295 * sanity checking will happen later
296 * when setting machine properties
302 static QemuOptsList qemu_boot_opts
= {
304 .implied_opt_name
= "order",
306 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
310 .type
= QEMU_OPT_STRING
,
313 .type
= QEMU_OPT_STRING
,
316 .type
= QEMU_OPT_BOOL
,
319 .type
= QEMU_OPT_STRING
,
321 .name
= "splash-time",
322 .type
= QEMU_OPT_STRING
,
324 .name
= "reboot-timeout",
325 .type
= QEMU_OPT_STRING
,
328 .type
= QEMU_OPT_BOOL
,
334 static QemuOptsList qemu_add_fd_opts
= {
336 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
340 .type
= QEMU_OPT_NUMBER
,
341 .help
= "file descriptor of which a duplicate is added to fd set",
344 .type
= QEMU_OPT_NUMBER
,
345 .help
= "ID of the fd set to add fd to",
348 .type
= QEMU_OPT_STRING
,
349 .help
= "free-form string used to describe fd",
351 { /* end of list */ }
355 static QemuOptsList qemu_object_opts
= {
357 .implied_opt_name
= "qom-type",
358 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
364 static QemuOptsList qemu_tpmdev_opts
= {
366 .implied_opt_name
= "type",
367 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
369 /* options are defined in the TPM backends */
370 { /* end of list */ }
374 static QemuOptsList qemu_realtime_opts
= {
376 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
380 .type
= QEMU_OPT_BOOL
,
382 { /* end of list */ }
386 static QemuOptsList qemu_msg_opts
= {
388 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
392 .type
= QEMU_OPT_BOOL
,
394 { /* end of list */ }
398 static QemuOptsList qemu_name_opts
= {
400 .implied_opt_name
= "guest",
402 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
406 .type
= QEMU_OPT_STRING
,
407 .help
= "Sets the name of the guest.\n"
408 "This name will be displayed in the SDL window caption.\n"
409 "The name will also be used for the VNC server",
412 .type
= QEMU_OPT_STRING
,
413 .help
= "Sets the name of the QEMU process, as shown in top etc",
415 .name
= "debug-threads",
416 .type
= QEMU_OPT_BOOL
,
417 .help
= "When enabled, name the individual threads; defaults off.\n"
418 "NOTE: The thread names are for debugging and not a\n"
421 { /* End of list */ }
425 static QemuOptsList qemu_mem_opts
= {
427 .implied_opt_name
= "size",
428 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
433 .type
= QEMU_OPT_SIZE
,
437 .type
= QEMU_OPT_NUMBER
,
441 .type
= QEMU_OPT_SIZE
,
443 { /* end of list */ }
447 static QemuOptsList qemu_icount_opts
= {
449 .implied_opt_name
= "shift",
451 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
455 .type
= QEMU_OPT_STRING
,
458 .type
= QEMU_OPT_BOOL
,
461 .type
= QEMU_OPT_BOOL
,
464 .type
= QEMU_OPT_STRING
,
467 .type
= QEMU_OPT_STRING
,
469 .name
= "rrsnapshot",
470 .type
= QEMU_OPT_STRING
,
472 { /* end of list */ }
476 static QemuOptsList qemu_semihosting_config_opts
= {
477 .name
= "semihosting-config",
478 .implied_opt_name
= "enable",
479 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
483 .type
= QEMU_OPT_BOOL
,
486 .type
= QEMU_OPT_STRING
,
489 .type
= QEMU_OPT_STRING
,
491 { /* end of list */ }
495 static QemuOptsList qemu_fw_cfg_opts
= {
497 .implied_opt_name
= "name",
498 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
502 .type
= QEMU_OPT_STRING
,
503 .help
= "Sets the fw_cfg name of the blob to be inserted",
506 .type
= QEMU_OPT_STRING
,
507 .help
= "Sets the name of the file from which\n"
508 "the fw_cfg blob will be loaded",
511 .type
= QEMU_OPT_STRING
,
512 .help
= "Sets content of the blob to be inserted from a string",
514 { /* end of list */ }
519 * Get machine options
521 * Returns: machine options (never null).
523 QemuOpts
*qemu_get_machine_opts(void)
525 return qemu_find_opts_singleton("machine");
528 const char *qemu_get_vm_name(void)
533 static void res_free(void)
535 g_free(boot_splash_filedata
);
536 boot_splash_filedata
= NULL
;
539 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
541 const char *driver
= qemu_opt_get(opts
, "driver");
546 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
547 if (strcmp(default_list
[i
].driver
, driver
) != 0)
549 *(default_list
[i
].flag
) = 0;
554 /***********************************************************/
557 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
559 /* We use RUN_STATE__MAX but any invalid value will do */
560 static RunState vmstop_requested
= RUN_STATE__MAX
;
561 static QemuMutex vmstop_lock
;
566 } RunStateTransition
;
568 static const RunStateTransition runstate_transitions_def
[] = {
570 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
571 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
572 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
574 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
575 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
576 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
577 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
578 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
579 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
580 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
581 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
582 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
583 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
584 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
585 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
587 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
588 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
589 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
591 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
592 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
593 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
595 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
596 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
597 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
598 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
600 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
601 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
602 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
604 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
605 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
606 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
608 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
609 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
610 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
611 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
613 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
614 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
616 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
618 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
619 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
620 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
621 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
622 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
623 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
624 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
625 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
626 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
627 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
628 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
630 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
632 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
633 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
634 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
636 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
637 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
638 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
639 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
640 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
641 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
643 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
644 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
645 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
646 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
648 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
649 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
650 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
652 { RUN_STATE__MAX
, RUN_STATE__MAX
},
655 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
657 bool runstate_check(RunState state
)
659 return current_run_state
== state
;
662 bool runstate_store(char *str
, size_t size
)
664 const char *state
= RunState_lookup
[current_run_state
];
665 size_t len
= strlen(state
) + 1;
670 memcpy(str
, state
, len
);
674 static void runstate_init(void)
676 const RunStateTransition
*p
;
678 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
679 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
680 runstate_valid_transitions
[p
->from
][p
->to
] = true;
683 qemu_mutex_init(&vmstop_lock
);
686 /* This function will abort() on invalid state transitions */
687 void runstate_set(RunState new_state
)
689 assert(new_state
< RUN_STATE__MAX
);
691 if (current_run_state
== new_state
) {
695 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
696 error_report("invalid runstate transition: '%s' -> '%s'",
697 RunState_lookup
[current_run_state
],
698 RunState_lookup
[new_state
]);
701 trace_runstate_set(new_state
);
702 current_run_state
= new_state
;
705 int runstate_is_running(void)
707 return runstate_check(RUN_STATE_RUNNING
);
710 bool runstate_needs_reset(void)
712 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
713 runstate_check(RUN_STATE_SHUTDOWN
);
716 StatusInfo
*qmp_query_status(Error
**errp
)
718 StatusInfo
*info
= g_malloc0(sizeof(*info
));
720 info
->running
= runstate_is_running();
721 info
->singlestep
= singlestep
;
722 info
->status
= current_run_state
;
727 bool qemu_vmstop_requested(RunState
*r
)
729 qemu_mutex_lock(&vmstop_lock
);
730 *r
= vmstop_requested
;
731 vmstop_requested
= RUN_STATE__MAX
;
732 qemu_mutex_unlock(&vmstop_lock
);
733 return *r
< RUN_STATE__MAX
;
736 void qemu_system_vmstop_request_prepare(void)
738 qemu_mutex_lock(&vmstop_lock
);
741 void qemu_system_vmstop_request(RunState state
)
743 vmstop_requested
= state
;
744 qemu_mutex_unlock(&vmstop_lock
);
748 /***********************************************************/
749 /* real time host monotonic timer */
751 static time_t qemu_time(void)
753 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
756 /***********************************************************/
757 /* host time/date access */
758 void qemu_get_timedate(struct tm
*tm
, int offset
)
760 time_t ti
= qemu_time();
763 if (rtc_date_offset
== -1) {
767 localtime_r(&ti
, tm
);
769 ti
-= rtc_date_offset
;
774 int qemu_timedate_diff(struct tm
*tm
)
778 if (rtc_date_offset
== -1)
780 seconds
= mktimegm(tm
);
783 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
784 seconds
= mktime(&tmp
);
787 seconds
= mktimegm(tm
) + rtc_date_offset
;
789 return seconds
- qemu_time();
792 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
794 time_t rtc_start_date
;
797 if (!strcmp(startdate
, "now") && legacy
) {
798 rtc_date_offset
= -1;
800 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
808 } else if (sscanf(startdate
, "%d-%d-%d",
820 rtc_start_date
= mktimegm(&tm
);
821 if (rtc_start_date
== -1) {
823 error_report("invalid date format");
824 error_printf("valid formats: "
825 "'2006-06-17T16:01:21' or '2006-06-17'\n");
828 rtc_date_offset
= qemu_time() - rtc_start_date
;
832 static void configure_rtc(QemuOpts
*opts
)
836 value
= qemu_opt_get(opts
, "base");
838 if (!strcmp(value
, "utc")) {
840 } else if (!strcmp(value
, "localtime")) {
841 Error
*blocker
= NULL
;
843 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
844 "-rtc base=localtime");
845 replay_add_blocker(blocker
);
847 configure_rtc_date_offset(value
, 0);
850 value
= qemu_opt_get(opts
, "clock");
852 if (!strcmp(value
, "host")) {
853 rtc_clock
= QEMU_CLOCK_HOST
;
854 } else if (!strcmp(value
, "rt")) {
855 rtc_clock
= QEMU_CLOCK_REALTIME
;
856 } else if (!strcmp(value
, "vm")) {
857 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
859 error_report("invalid option value '%s'", value
);
863 value
= qemu_opt_get(opts
, "driftfix");
865 if (!strcmp(value
, "slew")) {
866 static GlobalProperty slew_lost_ticks
= {
867 .driver
= "mc146818rtc",
868 .property
= "lost_tick_policy",
872 qdev_prop_register_global(&slew_lost_ticks
);
873 } else if (!strcmp(value
, "none")) {
874 /* discard is default */
876 error_report("invalid option value '%s'", value
);
882 /***********************************************************/
883 /* Bluetooth support */
886 static struct HCIInfo
*hci_table
[MAX_NICS
];
888 struct HCIInfo
*qemu_next_hci(void)
890 if (cur_hci
== nb_hcis
)
893 return hci_table
[cur_hci
++];
896 static int bt_hci_parse(const char *str
)
901 if (nb_hcis
>= MAX_NICS
) {
902 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
915 bdaddr
.b
[5] = 0x56 + nb_hcis
;
916 hci
->bdaddr_set(hci
, bdaddr
.b
);
918 hci_table
[nb_hcis
++] = hci
;
923 static void bt_vhci_add(int vlan_id
)
925 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
928 error_report("warning: adding a VHCI to an empty scatternet %i",
931 bt_vhci_init(bt_new_hci(vlan
));
934 static struct bt_device_s
*bt_device_add(const char *opt
)
936 struct bt_scatternet_s
*vlan
;
938 char *endp
= strstr(opt
, ",vlan=");
939 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
942 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
945 vlan_id
= strtol(endp
+ 6, &endp
, 0);
947 error_report("unrecognised bluetooth vlan Id");
952 vlan
= qemu_find_bt_vlan(vlan_id
);
955 error_report("warning: adding a slave device to an empty scatternet %i",
958 if (!strcmp(devname
, "keyboard"))
959 return bt_keyboard_init(vlan
);
961 error_report("unsupported bluetooth device '%s'", devname
);
965 static int bt_parse(const char *opt
)
967 const char *endp
, *p
;
970 if (strstart(opt
, "hci", &endp
)) {
971 if (!*endp
|| *endp
== ',') {
973 if (!strstart(endp
, ",vlan=", 0))
976 return bt_hci_parse(opt
);
978 } else if (strstart(opt
, "vhci", &endp
)) {
979 if (!*endp
|| *endp
== ',') {
981 if (strstart(endp
, ",vlan=", &p
)) {
982 vlan
= strtol(p
, (char **) &endp
, 0);
984 error_report("bad scatternet '%s'", p
);
988 error_report("bad parameter '%s'", endp
+ 1);
997 } else if (strstart(opt
, "device:", &endp
))
998 return !bt_device_add(endp
);
1000 error_report("bad bluetooth parameter '%s'", opt
);
1004 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1006 /* FIXME: change this to true for 1.3 */
1007 if (qemu_opt_get_bool(opts
, "enable", false)) {
1008 #ifdef CONFIG_SECCOMP
1009 if (seccomp_start() < 0) {
1010 error_report("failed to install seccomp syscall filter "
1015 error_report("seccomp support is disabled");
1023 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1025 const char *proc_name
;
1027 if (qemu_opt_get(opts
, "debug-threads")) {
1028 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1030 qemu_name
= qemu_opt_get(opts
, "guest");
1032 proc_name
= qemu_opt_get(opts
, "process");
1034 os_set_proc_name(proc_name
);
1040 bool defaults_enabled(void)
1042 return has_defaults
;
1046 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1048 int fd
, dupfd
, flags
;
1050 const char *fd_opaque
= NULL
;
1053 fd
= qemu_opt_get_number(opts
, "fd", -1);
1054 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1055 fd_opaque
= qemu_opt_get(opts
, "opaque");
1058 error_report("fd option is required and must be non-negative");
1062 if (fd
<= STDERR_FILENO
) {
1063 error_report("fd cannot be a standard I/O stream");
1068 * All fds inherited across exec() necessarily have FD_CLOEXEC
1069 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1071 flags
= fcntl(fd
, F_GETFD
);
1072 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1073 error_report("fd is not valid or already in use");
1078 error_report("set option is required and must be non-negative");
1082 #ifdef F_DUPFD_CLOEXEC
1083 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1087 qemu_set_cloexec(dupfd
);
1091 error_report("error duplicating fd: %s", strerror(errno
));
1095 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1096 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1103 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1107 fd
= qemu_opt_get_number(opts
, "fd", -1);
1114 /***********************************************************/
1115 /* QEMU Block devices */
1117 #define HD_OPTS "media=disk"
1118 #define CDROM_OPTS "media=cdrom"
1120 #define PFLASH_OPTS ""
1124 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1126 BlockInterfaceType
*block_default_type
= opaque
;
1128 return drive_new(opts
, *block_default_type
) == NULL
;
1131 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1133 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1134 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1139 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1140 int index
, const char *optstr
)
1145 if (!enable
|| drive_get_by_index(type
, index
)) {
1149 opts
= drive_add(type
, index
, NULL
, optstr
);
1151 drive_enable_snapshot(NULL
, opts
, NULL
);
1154 dinfo
= drive_new(opts
, type
);
1158 dinfo
->is_default
= true;
1162 static QemuOptsList qemu_smp_opts
= {
1164 .implied_opt_name
= "cpus",
1165 .merge_lists
= true,
1166 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1170 .type
= QEMU_OPT_NUMBER
,
1173 .type
= QEMU_OPT_NUMBER
,
1176 .type
= QEMU_OPT_NUMBER
,
1179 .type
= QEMU_OPT_NUMBER
,
1182 .type
= QEMU_OPT_NUMBER
,
1184 { /*End of list */ }
1188 static void smp_parse(QemuOpts
*opts
)
1191 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1192 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1193 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1194 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1196 /* compute missing values, prefer sockets over cores over threads */
1197 if (cpus
== 0 || sockets
== 0) {
1198 sockets
= sockets
> 0 ? sockets
: 1;
1199 cores
= cores
> 0 ? cores
: 1;
1200 threads
= threads
> 0 ? threads
: 1;
1202 cpus
= cores
* threads
* sockets
;
1204 } else if (cores
== 0) {
1205 threads
= threads
> 0 ? threads
: 1;
1206 cores
= cpus
/ (sockets
* threads
);
1207 cores
= cores
> 0 ? cores
: 1;
1208 } else if (threads
== 0) {
1209 threads
= cpus
/ (cores
* sockets
);
1210 threads
= threads
> 0 ? threads
: 1;
1211 } else if (sockets
* cores
* threads
< cpus
) {
1212 error_report("cpu topology: "
1213 "sockets (%u) * cores (%u) * threads (%u) < "
1215 sockets
, cores
, threads
, cpus
);
1219 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1221 if (max_cpus
< cpus
) {
1222 error_report("maxcpus must be equal to or greater than smp");
1226 if (sockets
* cores
* threads
> max_cpus
) {
1227 error_report("cpu topology: "
1228 "sockets (%u) * cores (%u) * threads (%u) > "
1230 sockets
, cores
, threads
, max_cpus
);
1236 smp_threads
= threads
;
1240 Error
*blocker
= NULL
;
1241 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1242 replay_add_blocker(blocker
);
1246 static void realtime_init(void)
1249 if (os_mlock() < 0) {
1250 error_report("locking memory failed");
1257 static void configure_msg(QemuOpts
*opts
)
1259 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1262 /***********************************************************/
1265 typedef struct SemihostingConfig
{
1267 SemihostingTarget target
;
1270 const char *cmdline
; /* concatenated argv */
1271 } SemihostingConfig
;
1273 static SemihostingConfig semihosting
;
1275 bool semihosting_enabled(void)
1277 return semihosting
.enabled
;
1280 SemihostingTarget
semihosting_get_target(void)
1282 return semihosting
.target
;
1285 const char *semihosting_get_arg(int i
)
1287 if (i
>= semihosting
.argc
) {
1290 return semihosting
.argv
[i
];
1293 int semihosting_get_argc(void)
1295 return semihosting
.argc
;
1298 const char *semihosting_get_cmdline(void)
1300 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1301 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1303 return semihosting
.cmdline
;
1306 static int add_semihosting_arg(void *opaque
,
1307 const char *name
, const char *val
,
1310 SemihostingConfig
*s
= opaque
;
1311 if (strcmp(name
, "arg") == 0) {
1313 /* one extra element as g_strjoinv() expects NULL-terminated array */
1314 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1315 s
->argv
[s
->argc
- 1] = val
;
1316 s
->argv
[s
->argc
] = NULL
;
1321 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1322 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1327 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1329 /* split -append and initialize argv[1..n] */
1330 cmd_token
= strtok(g_strdup(cmd
), " ");
1332 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1333 cmd_token
= strtok(NULL
, " ");
1337 /* Now we still need this for compatibility with XEN. */
1338 bool has_igd_gfx_passthru
;
1339 static void igd_gfx_passthru(void)
1341 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1344 /***********************************************************/
1347 static int usb_device_add(const char *devname
)
1349 USBDevice
*dev
= NULL
;
1350 #ifndef CONFIG_LINUX
1354 if (!machine_usb(current_machine
)) {
1358 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1359 dev
= usbdevice_create(devname
);
1363 /* the other ones */
1364 #ifndef CONFIG_LINUX
1365 /* only the linux version is qdev-ified, usb-bsd still needs this */
1366 if (strstart(devname
, "host:", &p
)) {
1367 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1377 static int usb_device_del(const char *devname
)
1382 if (strstart(devname
, "host:", &p
)) {
1386 if (!machine_usb(current_machine
)) {
1390 p
= strchr(devname
, '.');
1393 bus_num
= strtoul(devname
, NULL
, 0);
1394 addr
= strtoul(p
+ 1, NULL
, 0);
1396 return usb_device_delete_addr(bus_num
, addr
);
1399 static int usb_parse(const char *cmdline
)
1402 r
= usb_device_add(cmdline
);
1404 error_report("could not add USB device '%s'", cmdline
);
1409 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1411 const char *devname
= qdict_get_str(qdict
, "devname");
1412 if (usb_device_add(devname
) < 0) {
1413 error_report("could not add USB device '%s'", devname
);
1417 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1419 const char *devname
= qdict_get_str(qdict
, "devname");
1420 if (usb_device_del(devname
) < 0) {
1421 error_report("could not delete USB device '%s'", devname
);
1425 /***********************************************************/
1426 /* machine registration */
1428 MachineState
*current_machine
;
1430 static MachineClass
*find_machine(const char *name
)
1432 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1433 MachineClass
*mc
= NULL
;
1435 for (el
= machines
; el
; el
= el
->next
) {
1436 MachineClass
*temp
= el
->data
;
1438 if (!strcmp(temp
->name
, name
)) {
1443 !strcmp(temp
->alias
, name
)) {
1449 g_slist_free(machines
);
1453 MachineClass
*find_default_machine(void)
1455 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1456 MachineClass
*mc
= NULL
;
1458 for (el
= machines
; el
; el
= el
->next
) {
1459 MachineClass
*temp
= el
->data
;
1461 if (temp
->is_default
) {
1467 g_slist_free(machines
);
1471 MachineInfoList
*qmp_query_machines(Error
**errp
)
1473 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1474 MachineInfoList
*mach_list
= NULL
;
1476 for (el
= machines
; el
; el
= el
->next
) {
1477 MachineClass
*mc
= el
->data
;
1478 MachineInfoList
*entry
;
1481 info
= g_malloc0(sizeof(*info
));
1482 if (mc
->is_default
) {
1483 info
->has_is_default
= true;
1484 info
->is_default
= true;
1488 info
->has_alias
= true;
1489 info
->alias
= g_strdup(mc
->alias
);
1492 info
->name
= g_strdup(mc
->name
);
1493 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1494 info
->hotpluggable_cpus
= !!mc
->query_hotpluggable_cpus
;
1496 entry
= g_malloc0(sizeof(*entry
));
1497 entry
->value
= info
;
1498 entry
->next
= mach_list
;
1502 g_slist_free(machines
);
1506 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1508 ObjectProperty
*prop
;
1509 ObjectPropertyIterator iter
;
1511 if (!qemu_opt_has_help_opt(opts
)) {
1515 object_property_iter_init(&iter
, OBJECT(machine
));
1516 while ((prop
= object_property_iter_next(&iter
))) {
1521 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1522 prop
->name
, prop
->type
);
1523 if (prop
->description
) {
1524 error_printf(" (%s)\n", prop
->description
);
1533 /***********************************************************/
1534 /* main execution loop */
1536 struct vm_change_state_entry
{
1537 VMChangeStateHandler
*cb
;
1539 QLIST_ENTRY (vm_change_state_entry
) entries
;
1542 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1544 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1547 VMChangeStateEntry
*e
;
1549 e
= g_malloc0(sizeof (*e
));
1553 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1557 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1559 QLIST_REMOVE (e
, entries
);
1563 void vm_state_notify(int running
, RunState state
)
1565 VMChangeStateEntry
*e
, *next
;
1567 trace_vm_state_notify(running
, state
);
1569 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1570 e
->cb(e
->opaque
, running
, state
);
1574 static int reset_requested
;
1575 static int shutdown_requested
, shutdown_signal
= -1;
1576 static pid_t shutdown_pid
;
1577 static int powerdown_requested
;
1578 static int debug_requested
;
1579 static int suspend_requested
;
1580 static WakeupReason wakeup_reason
;
1581 static NotifierList powerdown_notifiers
=
1582 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1583 static NotifierList suspend_notifiers
=
1584 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1585 static NotifierList wakeup_notifiers
=
1586 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1587 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1589 int qemu_shutdown_requested_get(void)
1591 return shutdown_requested
;
1594 int qemu_reset_requested_get(void)
1596 return reset_requested
;
1599 static int qemu_shutdown_requested(void)
1601 return atomic_xchg(&shutdown_requested
, 0);
1604 static void qemu_kill_report(void)
1606 if (!qtest_driver() && shutdown_signal
!= -1) {
1607 if (shutdown_pid
== 0) {
1608 /* This happens for eg ^C at the terminal, so it's worth
1609 * avoiding printing an odd message in that case.
1611 error_report("terminating on signal %d", shutdown_signal
);
1613 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1615 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1616 shutdown_signal
, shutdown_pid
,
1617 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1618 g_free(shutdown_cmd
);
1620 shutdown_signal
= -1;
1624 static int qemu_reset_requested(void)
1626 int r
= reset_requested
;
1627 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1628 reset_requested
= 0;
1634 static int qemu_suspend_requested(void)
1636 int r
= suspend_requested
;
1637 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1638 suspend_requested
= 0;
1644 static WakeupReason
qemu_wakeup_requested(void)
1646 return wakeup_reason
;
1649 static int qemu_powerdown_requested(void)
1651 int r
= powerdown_requested
;
1652 powerdown_requested
= 0;
1656 static int qemu_debug_requested(void)
1658 int r
= debug_requested
;
1659 debug_requested
= 0;
1663 void qemu_system_reset(bool report
)
1667 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1669 cpu_synchronize_all_states();
1671 if (mc
&& mc
->reset
) {
1674 qemu_devices_reset();
1677 qapi_event_send_reset(&error_abort
);
1679 cpu_synchronize_all_post_reset();
1682 void qemu_system_guest_panicked(GuestPanicInformation
*info
)
1685 current_cpu
->crash_occurred
= true;
1687 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
,
1688 !!info
, info
, &error_abort
);
1689 vm_stop(RUN_STATE_GUEST_PANICKED
);
1691 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1692 !!info
, info
, &error_abort
);
1693 qemu_system_shutdown_request();
1697 qapi_free_GuestPanicInformation(info
);
1701 void qemu_system_reset_request(void)
1704 shutdown_requested
= 1;
1706 reset_requested
= 1;
1709 qemu_notify_event();
1712 static void qemu_system_suspend(void)
1715 notifier_list_notify(&suspend_notifiers
, NULL
);
1716 runstate_set(RUN_STATE_SUSPENDED
);
1717 qapi_event_send_suspend(&error_abort
);
1720 void qemu_system_suspend_request(void)
1722 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1725 suspend_requested
= 1;
1727 qemu_notify_event();
1730 void qemu_register_suspend_notifier(Notifier
*notifier
)
1732 notifier_list_add(&suspend_notifiers
, notifier
);
1735 void qemu_system_wakeup_request(WakeupReason reason
)
1737 trace_system_wakeup_request(reason
);
1739 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1742 if (!(wakeup_reason_mask
& (1 << reason
))) {
1745 runstate_set(RUN_STATE_RUNNING
);
1746 wakeup_reason
= reason
;
1747 qemu_notify_event();
1750 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1753 wakeup_reason_mask
|= (1 << reason
);
1755 wakeup_reason_mask
&= ~(1 << reason
);
1759 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1761 notifier_list_add(&wakeup_notifiers
, notifier
);
1764 void qemu_system_killed(int signal
, pid_t pid
)
1766 shutdown_signal
= signal
;
1770 /* Cannot call qemu_system_shutdown_request directly because
1771 * we are in a signal handler.
1773 shutdown_requested
= 1;
1774 qemu_notify_event();
1777 void qemu_system_shutdown_request(void)
1779 trace_qemu_system_shutdown_request();
1780 replay_shutdown_request();
1781 shutdown_requested
= 1;
1782 qemu_notify_event();
1785 static void qemu_system_powerdown(void)
1787 qapi_event_send_powerdown(&error_abort
);
1788 notifier_list_notify(&powerdown_notifiers
, NULL
);
1791 void qemu_system_powerdown_request(void)
1793 trace_qemu_system_powerdown_request();
1794 powerdown_requested
= 1;
1795 qemu_notify_event();
1798 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1800 notifier_list_add(&powerdown_notifiers
, notifier
);
1803 void qemu_system_debug_request(void)
1805 debug_requested
= 1;
1806 qemu_notify_event();
1809 static bool main_loop_should_exit(void)
1812 if (qemu_debug_requested()) {
1813 vm_stop(RUN_STATE_DEBUG
);
1815 if (qemu_suspend_requested()) {
1816 qemu_system_suspend();
1818 if (qemu_shutdown_requested()) {
1820 qapi_event_send_shutdown(&error_abort
);
1822 vm_stop(RUN_STATE_SHUTDOWN
);
1827 if (qemu_reset_requested()) {
1829 qemu_system_reset(VMRESET_REPORT
);
1831 if (!runstate_check(RUN_STATE_RUNNING
) &&
1832 !runstate_check(RUN_STATE_INMIGRATE
)) {
1833 runstate_set(RUN_STATE_PRELAUNCH
);
1836 if (qemu_wakeup_requested()) {
1838 qemu_system_reset(VMRESET_SILENT
);
1839 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1840 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1842 qapi_event_send_wakeup(&error_abort
);
1844 if (qemu_powerdown_requested()) {
1845 qemu_system_powerdown();
1847 if (qemu_vmstop_requested(&r
)) {
1853 static void main_loop(void)
1857 #ifdef CONFIG_PROFILER
1861 nonblocking
= tcg_enabled() && last_io
> 0;
1862 #ifdef CONFIG_PROFILER
1863 ti
= profile_getclock();
1865 last_io
= main_loop_wait(nonblocking
);
1866 #ifdef CONFIG_PROFILER
1867 dev_time
+= profile_getclock() - ti
;
1869 } while (!main_loop_should_exit());
1872 static void version(void)
1874 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1875 QEMU_COPYRIGHT
"\n");
1878 static void help(int exitcode
)
1881 printf("usage: %s [options] [disk_image]\n\n"
1882 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1883 error_get_progname());
1885 #define QEMU_OPTIONS_GENERATE_HELP
1886 #include "qemu-options-wrapper.h"
1888 printf("\nDuring emulation, the following keys are useful:\n"
1889 "ctrl-alt-f toggle full screen\n"
1890 "ctrl-alt-n switch to virtual console 'n'\n"
1891 "ctrl-alt toggle mouse and keyboard grab\n"
1893 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1898 #define HAS_ARG 0x0001
1900 typedef struct QEMUOption
{
1907 static const QEMUOption qemu_options
[] = {
1908 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1909 #define QEMU_OPTIONS_GENERATE_OPTIONS
1910 #include "qemu-options-wrapper.h"
1914 typedef struct VGAInterfaceInfo
{
1915 const char *opt_name
; /* option name */
1916 const char *name
; /* human-readable name */
1917 /* Class names indicating that support is available.
1918 * If no class is specified, the interface is always available */
1919 const char *class_names
[2];
1922 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1928 .name
= "standard VGA",
1929 .class_names
= { "VGA", "isa-vga" },
1932 .opt_name
= "cirrus",
1933 .name
= "Cirrus VGA",
1934 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1937 .opt_name
= "vmware",
1938 .name
= "VMWare SVGA",
1939 .class_names
= { "vmware-svga" },
1942 .opt_name
= "virtio",
1943 .name
= "Virtio VGA",
1944 .class_names
= { "virtio-vga" },
1949 .class_names
= { "qxl-vga" },
1953 .name
= "TCX framebuffer",
1954 .class_names
= { "SUNW,tcx" },
1958 .name
= "CG3 framebuffer",
1959 .class_names
= { "cgthree" },
1962 .opt_name
= "xenfb",
1966 static bool vga_interface_available(VGAInterfaceType t
)
1968 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
1970 assert(t
< VGA_TYPE_MAX
);
1971 return !ti
->class_names
[0] ||
1972 object_class_by_name(ti
->class_names
[0]) ||
1973 object_class_by_name(ti
->class_names
[1]);
1976 static void select_vgahw(const char *p
)
1981 assert(vga_interface_type
== VGA_NONE
);
1982 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
1983 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
1984 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
1985 if (!vga_interface_available(t
)) {
1986 error_report("%s not available", ti
->name
);
1989 vga_interface_type
= t
;
1993 if (t
== VGA_TYPE_MAX
) {
1995 error_report("unknown vga type: %s", p
);
1999 const char *nextopt
;
2001 if (strstart(opts
, ",retrace=", &nextopt
)) {
2003 if (strstart(opts
, "dumb", &nextopt
))
2004 vga_retrace_method
= VGA_RETRACE_DUMB
;
2005 else if (strstart(opts
, "precise", &nextopt
))
2006 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2007 else goto invalid_vga
;
2008 } else goto invalid_vga
;
2013 typedef enum DisplayType
{
2022 static DisplayType
select_display(const char *p
)
2025 DisplayType display
= DT_DEFAULT
;
2027 if (strstart(p
, "sdl", &opts
)) {
2031 const char *nextopt
;
2033 if (strstart(opts
, ",frame=", &nextopt
)) {
2035 if (strstart(opts
, "on", &nextopt
)) {
2037 } else if (strstart(opts
, "off", &nextopt
)) {
2040 goto invalid_sdl_args
;
2042 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2044 if (strstart(opts
, "on", &nextopt
)) {
2046 } else if (strstart(opts
, "off", &nextopt
)) {
2049 goto invalid_sdl_args
;
2051 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2053 if (strstart(opts
, "on", &nextopt
)) {
2055 } else if (strstart(opts
, "off", &nextopt
)) {
2058 goto invalid_sdl_args
;
2060 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2062 if (strstart(opts
, "on", &nextopt
)) {
2064 } else if (strstart(opts
, "off", &nextopt
)) {
2067 goto invalid_sdl_args
;
2069 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2071 if (strstart(opts
, "on", &nextopt
)) {
2073 } else if (strstart(opts
, "off", &nextopt
)) {
2076 goto invalid_sdl_args
;
2080 error_report("invalid SDL option string");
2086 error_report("SDL support is disabled");
2089 } else if (strstart(p
, "vnc", &opts
)) {
2091 vnc_parse(opts
+ 1, &error_fatal
);
2093 error_report("VNC requires a display argument vnc=<display>");
2096 } else if (strstart(p
, "curses", &opts
)) {
2097 #ifdef CONFIG_CURSES
2098 display
= DT_CURSES
;
2100 error_report("curses support is disabled");
2103 } else if (strstart(p
, "gtk", &opts
)) {
2107 const char *nextopt
;
2109 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2111 if (strstart(opts
, "on", &nextopt
)) {
2112 grab_on_hover
= true;
2113 } else if (strstart(opts
, "off", &nextopt
)) {
2114 grab_on_hover
= false;
2116 goto invalid_gtk_args
;
2118 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2120 if (strstart(opts
, "on", &nextopt
)) {
2122 } else if (strstart(opts
, "off", &nextopt
)) {
2125 goto invalid_gtk_args
;
2129 error_report("invalid GTK option string");
2135 error_report("GTK support is disabled");
2138 } else if (strstart(p
, "none", &opts
)) {
2141 error_report("unknown display type");
2148 static int balloon_parse(const char *arg
)
2152 if (strcmp(arg
, "none") == 0) {
2156 if (!strncmp(arg
, "virtio", 6)) {
2157 if (arg
[6] == ',') {
2158 /* have params -> parse them */
2159 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2164 /* create empty opts */
2165 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2168 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2175 char *qemu_find_file(int type
, const char *name
)
2181 /* Try the name as a straight path first */
2182 if (access(name
, R_OK
) == 0) {
2183 trace_load_file(name
, name
);
2184 return g_strdup(name
);
2188 case QEMU_FILE_TYPE_BIOS
:
2191 case QEMU_FILE_TYPE_KEYMAP
:
2192 subdir
= "keymaps/";
2198 for (i
= 0; i
< data_dir_idx
; i
++) {
2199 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2200 if (access(buf
, R_OK
) == 0) {
2201 trace_load_file(name
, buf
);
2209 static inline bool nonempty_str(const char *str
)
2214 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2218 const char *name
, *file
, *str
;
2219 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2221 if (fw_cfg
== NULL
) {
2222 error_report("fw_cfg device not available");
2225 name
= qemu_opt_get(opts
, "name");
2226 file
= qemu_opt_get(opts
, "file");
2227 str
= qemu_opt_get(opts
, "string");
2229 /* we need name and either a file or the content string */
2230 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2231 error_report("invalid argument(s)");
2234 if (nonempty_str(file
) && nonempty_str(str
)) {
2235 error_report("file and string are mutually exclusive");
2238 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2239 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2242 if (strncmp(name
, "opt/", 4) != 0) {
2243 error_report("warning: externally provided fw_cfg item names "
2244 "should be prefixed with \"opt/\"");
2246 if (nonempty_str(str
)) {
2247 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2248 buf
= g_memdup(str
, size
);
2250 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2251 error_report("can't load %s", file
);
2255 /* For legacy, keep user files in a specific global order. */
2256 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2257 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2258 fw_cfg_reset_order_override(fw_cfg
);
2262 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2264 return qdev_device_help(opts
);
2267 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2272 dev
= qdev_device_add(opts
, &err
);
2274 error_report_err(err
);
2277 object_unref(OBJECT(dev
));
2281 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2283 Error
*local_err
= NULL
;
2285 qemu_chr_new_from_opts(opts
, &local_err
);
2287 error_report_err(local_err
);
2293 #ifdef CONFIG_VIRTFS
2294 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2296 return qemu_fsdev_add(opts
);
2300 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2303 const char *chardev
;
2307 mode
= qemu_opt_get(opts
, "mode");
2311 if (strcmp(mode
, "readline") == 0) {
2312 flags
= MONITOR_USE_READLINE
;
2313 } else if (strcmp(mode
, "control") == 0) {
2314 flags
= MONITOR_USE_CONTROL
;
2316 error_report("unknown monitor mode \"%s\"", mode
);
2320 if (qemu_opt_get_bool(opts
, "pretty", 0))
2321 flags
|= MONITOR_USE_PRETTY
;
2323 if (qemu_opt_get_bool(opts
, "default", 0)) {
2324 error_report("option 'default' does nothing and is deprecated");
2327 chardev
= qemu_opt_get(opts
, "chardev");
2328 chr
= qemu_chr_find(chardev
);
2330 error_report("chardev \"%s\" not found", chardev
);
2334 monitor_init(chr
, flags
);
2338 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2340 static int monitor_device_index
= 0;
2345 if (strstart(optarg
, "chardev:", &p
)) {
2346 snprintf(label
, sizeof(label
), "%s", p
);
2348 snprintf(label
, sizeof(label
), "compat_monitor%d",
2349 monitor_device_index
);
2350 opts
= qemu_chr_parse_compat(label
, optarg
);
2352 error_report("parse error: %s", optarg
);
2357 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2358 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2359 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2360 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2361 monitor_device_index
++;
2364 struct device_config
{
2366 DEV_USB
, /* -usbdevice */
2368 DEV_SERIAL
, /* -serial */
2369 DEV_PARALLEL
, /* -parallel */
2370 DEV_VIRTCON
, /* -virtioconsole */
2371 DEV_DEBUGCON
, /* -debugcon */
2372 DEV_GDB
, /* -gdb, -s */
2373 DEV_SCLP
, /* s390 sclp */
2375 const char *cmdline
;
2377 QTAILQ_ENTRY(device_config
) next
;
2380 static QTAILQ_HEAD(, device_config
) device_configs
=
2381 QTAILQ_HEAD_INITIALIZER(device_configs
);
2383 static void add_device_config(int type
, const char *cmdline
)
2385 struct device_config
*conf
;
2387 conf
= g_malloc0(sizeof(*conf
));
2389 conf
->cmdline
= cmdline
;
2390 loc_save(&conf
->loc
);
2391 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2394 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2396 struct device_config
*conf
;
2399 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2400 if (conf
->type
!= type
)
2402 loc_push_restore(&conf
->loc
);
2403 rc
= func(conf
->cmdline
);
2404 loc_pop(&conf
->loc
);
2412 static int serial_parse(const char *devname
)
2414 static int index
= 0;
2417 if (strcmp(devname
, "none") == 0)
2419 if (index
== MAX_SERIAL_PORTS
) {
2420 error_report("too many serial ports");
2423 snprintf(label
, sizeof(label
), "serial%d", index
);
2424 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2425 if (!serial_hds
[index
]) {
2426 error_report("could not connect serial device"
2427 " to character backend '%s'", devname
);
2434 static int parallel_parse(const char *devname
)
2436 static int index
= 0;
2439 if (strcmp(devname
, "none") == 0)
2441 if (index
== MAX_PARALLEL_PORTS
) {
2442 error_report("too many parallel ports");
2445 snprintf(label
, sizeof(label
), "parallel%d", index
);
2446 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2447 if (!parallel_hds
[index
]) {
2448 error_report("could not connect parallel device"
2449 " to character backend '%s'", devname
);
2456 static int virtcon_parse(const char *devname
)
2458 QemuOptsList
*device
= qemu_find_opts("device");
2459 static int index
= 0;
2461 QemuOpts
*bus_opts
, *dev_opts
;
2463 if (strcmp(devname
, "none") == 0)
2465 if (index
== MAX_VIRTIO_CONSOLES
) {
2466 error_report("too many virtio consoles");
2470 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2471 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2473 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2474 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2476 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2477 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2478 if (!virtcon_hds
[index
]) {
2479 error_report("could not connect virtio console"
2480 " to character backend '%s'", devname
);
2483 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2489 static int sclp_parse(const char *devname
)
2491 QemuOptsList
*device
= qemu_find_opts("device");
2492 static int index
= 0;
2496 if (strcmp(devname
, "none") == 0) {
2499 if (index
== MAX_SCLP_CONSOLES
) {
2500 error_report("too many sclp consoles");
2504 assert(arch_type
== QEMU_ARCH_S390X
);
2506 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2507 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2509 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2510 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2511 if (!sclp_hds
[index
]) {
2512 error_report("could not connect sclp console"
2513 " to character backend '%s'", devname
);
2516 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2522 static int debugcon_parse(const char *devname
)
2526 if (!qemu_chr_new("debugcon", devname
)) {
2529 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2531 error_report("already have a debugcon device");
2534 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2535 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2539 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2541 const MachineClass
*mc1
= a
, *mc2
= b
;
2544 if (mc1
->family
== NULL
) {
2545 if (mc2
->family
== NULL
) {
2546 /* Compare standalone machine types against each other; they sort
2547 * in increasing order.
2549 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2550 object_class_get_name(OBJECT_CLASS(mc2
)));
2553 /* Standalone machine types sort after families. */
2557 if (mc2
->family
== NULL
) {
2558 /* Families sort before standalone machine types. */
2562 /* Families sort between each other alphabetically increasingly. */
2563 res
= strcmp(mc1
->family
, mc2
->family
);
2568 /* Within the same family, machine types sort in decreasing order. */
2569 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2570 object_class_get_name(OBJECT_CLASS(mc1
)));
2573 static MachineClass
*machine_parse(const char *name
)
2575 MachineClass
*mc
= NULL
;
2576 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2579 mc
= find_machine(name
);
2582 g_slist_free(machines
);
2585 if (name
&& !is_help_option(name
)) {
2586 error_report("unsupported machine type");
2587 error_printf("Use -machine help to list supported machines\n");
2589 printf("Supported machines are:\n");
2590 machines
= g_slist_sort(machines
, machine_class_cmp
);
2591 for (el
= machines
; el
; el
= el
->next
) {
2592 MachineClass
*mc
= el
->data
;
2594 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2596 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2597 mc
->is_default
? " (default)" : "");
2601 g_slist_free(machines
);
2602 exit(!name
|| !is_help_option(name
));
2605 void qemu_add_exit_notifier(Notifier
*notify
)
2607 notifier_list_add(&exit_notifiers
, notify
);
2610 void qemu_remove_exit_notifier(Notifier
*notify
)
2612 notifier_remove(notify
);
2615 static void qemu_run_exit_notifiers(void)
2617 notifier_list_notify(&exit_notifiers
, NULL
);
2620 static bool machine_init_done
;
2622 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2624 notifier_list_add(&machine_init_done_notifiers
, notify
);
2625 if (machine_init_done
) {
2626 notify
->notify(notify
, NULL
);
2630 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2632 notifier_remove(notify
);
2635 static void qemu_run_machine_init_done_notifiers(void)
2637 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2638 machine_init_done
= true;
2641 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2642 const char **poptarg
, int *poptind
)
2644 const QEMUOption
*popt
;
2645 int optind
= *poptind
;
2646 char *r
= argv
[optind
];
2649 loc_set_cmdline(argv
, optind
, 1);
2651 /* Treat --foo the same as -foo. */
2654 popt
= qemu_options
;
2657 error_report("invalid option");
2660 if (!strcmp(popt
->name
, r
+ 1))
2664 if (popt
->flags
& HAS_ARG
) {
2665 if (optind
>= argc
) {
2666 error_report("requires an argument");
2669 optarg
= argv
[optind
++];
2670 loc_set_cmdline(argv
, optind
- 2, 2);
2681 static MachineClass
*select_machine(void)
2683 MachineClass
*machine_class
= find_default_machine();
2688 loc_push_none(&loc
);
2690 opts
= qemu_get_machine_opts();
2691 qemu_opts_loc_restore(opts
);
2693 optarg
= qemu_opt_get(opts
, "type");
2695 machine_class
= machine_parse(optarg
);
2698 if (!machine_class
) {
2699 error_report("No machine specified, and there is no default");
2700 error_printf("Use -machine help to list supported machines\n");
2705 return machine_class
;
2708 static int machine_set_property(void *opaque
,
2709 const char *name
, const char *value
,
2712 Object
*obj
= OBJECT(opaque
);
2713 Error
*local_err
= NULL
;
2716 if (strcmp(name
, "type") == 0) {
2720 qom_name
= g_strdup(name
);
2721 for (p
= qom_name
; *p
; p
++) {
2727 object_property_parse(obj
, value
, qom_name
, &local_err
);
2731 error_report_err(local_err
);
2740 * Initial object creation happens before all other
2741 * QEMU data types are created. The majority of objects
2742 * can be created at this point. The rng-egd object
2743 * cannot be created here, as it depends on the chardev
2746 static bool object_create_initial(const char *type
)
2748 if (g_str_equal(type
, "rng-egd")) {
2753 * return false for concrete netfilters since
2754 * they depend on netdevs already existing
2756 if (g_str_equal(type
, "filter-buffer") ||
2757 g_str_equal(type
, "filter-dump") ||
2758 g_str_equal(type
, "filter-mirror") ||
2759 g_str_equal(type
, "filter-redirector") ||
2760 g_str_equal(type
, "colo-compare") ||
2761 g_str_equal(type
, "filter-rewriter") ||
2762 g_str_equal(type
, "filter-replay")) {
2766 /* Memory allocation by backends needs to be done
2767 * after configure_accelerator() (due to the tcg_enabled()
2768 * checks at memory_region_init_*()).
2770 * Also, allocation of large amounts of memory may delay
2771 * chardev initialization for too long, and trigger timeouts
2772 * on software that waits for a monitor socket to be created
2775 if (g_str_has_prefix(type
, "memory-backend-")) {
2784 * The remainder of object creation happens after the
2785 * creation of chardev, fsdev, net clients and device data types.
2787 static bool object_create_delayed(const char *type
)
2789 return !object_create_initial(type
);
2793 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2797 const char *mem_str
;
2798 const char *maxmem_str
, *slots_str
;
2799 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2800 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2803 loc_push_none(&loc
);
2804 qemu_opts_loc_restore(opts
);
2807 mem_str
= qemu_opt_get(opts
, "size");
2810 error_report("missing 'size' option value");
2814 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2816 /* Fix up legacy suffix-less format */
2817 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2818 uint64_t overflow_check
= sz
;
2821 if ((sz
>> 20) != overflow_check
) {
2822 error_report("too large 'size' option value");
2828 /* backward compatibility behaviour for case "-m 0" */
2830 sz
= default_ram_size
;
2833 sz
= QEMU_ALIGN_UP(sz
, 8192);
2835 if (ram_size
!= sz
) {
2836 error_report("ram size too large");
2840 /* store value for the future use */
2841 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2842 *maxram_size
= ram_size
;
2844 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2845 slots_str
= qemu_opt_get(opts
, "slots");
2846 if (maxmem_str
&& slots_str
) {
2849 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2850 slots
= qemu_opt_get_number(opts
, "slots", 0);
2851 if (sz
< ram_size
) {
2852 error_report("invalid value of -m option maxmem: "
2853 "maximum memory size (0x%" PRIx64
") must be at least "
2854 "the initial memory size (0x" RAM_ADDR_FMT
")",
2857 } else if (sz
> ram_size
) {
2859 error_report("invalid value of -m option: maxmem was "
2860 "specified, but no hotplug slots were specified");
2864 error_report("invalid value of -m option maxmem: "
2865 "memory slots were specified but maximum memory size "
2866 "(0x%" PRIx64
") is equal to the initial memory size "
2867 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2873 } else if ((!maxmem_str
&& slots_str
) ||
2874 (maxmem_str
&& !slots_str
)) {
2875 error_report("invalid -m option value: missing "
2876 "'%s' option", slots_str
? "maxmem" : "slots");
2883 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2887 g
= g_malloc0(sizeof(*g
));
2888 g
->driver
= qemu_opt_get(opts
, "driver");
2889 g
->property
= qemu_opt_get(opts
, "property");
2890 g
->value
= qemu_opt_get(opts
, "value");
2891 g
->user_provided
= true;
2892 g
->errp
= &error_fatal
;
2893 qdev_prop_register_global(g
);
2897 static int qemu_read_default_config_file(void)
2901 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2902 if (ret
< 0 && ret
!= -ENOENT
) {
2909 int main(int argc
, char **argv
, char **envp
)
2912 int snapshot
, linux_boot
;
2913 const char *initrd_filename
;
2914 const char *kernel_filename
, *kernel_cmdline
;
2915 const char *boot_order
= NULL
;
2916 const char *boot_once
= NULL
;
2918 int cyls
, heads
, secs
, translation
;
2919 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
2920 QemuOptsList
*olist
;
2923 const char *loadvm
= NULL
;
2924 MachineClass
*machine_class
;
2925 const char *cpu_model
;
2926 const char *vga_model
= NULL
;
2927 const char *qtest_chrdev
= NULL
;
2928 const char *qtest_log
= NULL
;
2929 const char *pid_file
= NULL
;
2930 const char *incoming
= NULL
;
2931 bool defconfig
= true;
2932 bool userconfig
= true;
2933 bool nographic
= false;
2934 DisplayType display_type
= DT_DEFAULT
;
2935 int display_remote
= 0;
2936 const char *log_mask
= NULL
;
2937 const char *log_file
= NULL
;
2938 char *trace_file
= NULL
;
2939 ram_addr_t maxram_size
;
2940 uint64_t ram_slots
= 0;
2941 FILE *vmstate_dump_file
= NULL
;
2942 Error
*main_loop_err
= NULL
;
2944 bool list_data_dirs
= false;
2946 module_call_init(MODULE_INIT_TRACE
);
2948 qemu_init_cpu_list();
2949 qemu_init_cpu_loop();
2950 qemu_mutex_lock_iothread();
2952 atexit(qemu_run_exit_notifiers
);
2953 error_set_progname(argv
[0]);
2954 qemu_init_exec_dir(argv
[0]);
2956 module_call_init(MODULE_INIT_QOM
);
2957 module_call_init(MODULE_INIT_QAPI
);
2959 qemu_add_opts(&qemu_drive_opts
);
2960 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2961 qemu_add_drive_opts(&qemu_common_drive_opts
);
2962 qemu_add_drive_opts(&qemu_drive_opts
);
2963 qemu_add_drive_opts(&bdrv_runtime_opts
);
2964 qemu_add_opts(&qemu_chardev_opts
);
2965 qemu_add_opts(&qemu_device_opts
);
2966 qemu_add_opts(&qemu_netdev_opts
);
2967 qemu_add_opts(&qemu_net_opts
);
2968 qemu_add_opts(&qemu_rtc_opts
);
2969 qemu_add_opts(&qemu_global_opts
);
2970 qemu_add_opts(&qemu_mon_opts
);
2971 qemu_add_opts(&qemu_trace_opts
);
2972 qemu_add_opts(&qemu_option_rom_opts
);
2973 qemu_add_opts(&qemu_machine_opts
);
2974 qemu_add_opts(&qemu_mem_opts
);
2975 qemu_add_opts(&qemu_smp_opts
);
2976 qemu_add_opts(&qemu_boot_opts
);
2977 qemu_add_opts(&qemu_sandbox_opts
);
2978 qemu_add_opts(&qemu_add_fd_opts
);
2979 qemu_add_opts(&qemu_object_opts
);
2980 qemu_add_opts(&qemu_tpmdev_opts
);
2981 qemu_add_opts(&qemu_realtime_opts
);
2982 qemu_add_opts(&qemu_msg_opts
);
2983 qemu_add_opts(&qemu_name_opts
);
2984 qemu_add_opts(&qemu_numa_opts
);
2985 qemu_add_opts(&qemu_icount_opts
);
2986 qemu_add_opts(&qemu_semihosting_config_opts
);
2987 qemu_add_opts(&qemu_fw_cfg_opts
);
2988 module_call_init(MODULE_INIT_OPTS
);
2992 if (qcrypto_init(&err
) < 0) {
2993 error_reportf_err(err
, "cannot initialize crypto: ");
2996 rtc_clock
= QEMU_CLOCK_HOST
;
2998 QLIST_INIT (&vm_change_state_head
);
2999 os_setup_early_signal_handling();
3003 cyls
= heads
= secs
= 0;
3004 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3008 bdrv_init_with_whitelist();
3012 /* first pass of option parsing */
3014 while (optind
< argc
) {
3015 if (argv
[optind
][0] != '-') {
3019 const QEMUOption
*popt
;
3021 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3022 switch (popt
->index
) {
3023 case QEMU_OPTION_nodefconfig
:
3026 case QEMU_OPTION_nouserconfig
:
3033 if (defconfig
&& userconfig
) {
3034 if (qemu_read_default_config_file() < 0) {
3039 /* second pass of option parsing */
3044 if (argv
[optind
][0] != '-') {
3045 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3047 const QEMUOption
*popt
;
3049 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3050 if (!(popt
->arch_mask
& arch_type
)) {
3051 error_report("Option not supported for this target");
3054 switch(popt
->index
) {
3055 case QEMU_OPTION_no_kvm_irqchip
: {
3056 olist
= qemu_find_opts("machine");
3057 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3060 case QEMU_OPTION_cpu
:
3061 /* hw initialization will check this */
3064 case QEMU_OPTION_hda
:
3068 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3070 snprintf(buf
, sizeof(buf
),
3071 "%s,cyls=%d,heads=%d,secs=%d%s",
3072 HD_OPTS
, cyls
, heads
, secs
,
3073 translation
== BIOS_ATA_TRANSLATION_LBA
?
3075 translation
== BIOS_ATA_TRANSLATION_NONE
?
3076 ",trans=none" : "");
3077 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3080 case QEMU_OPTION_hdb
:
3081 case QEMU_OPTION_hdc
:
3082 case QEMU_OPTION_hdd
:
3083 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3086 case QEMU_OPTION_drive
:
3087 if (drive_def(optarg
) == NULL
) {
3091 case QEMU_OPTION_set
:
3092 if (qemu_set_option(optarg
) != 0)
3095 case QEMU_OPTION_global
:
3096 if (qemu_global_option(optarg
) != 0)
3099 case QEMU_OPTION_mtdblock
:
3100 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3102 case QEMU_OPTION_sd
:
3103 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3105 case QEMU_OPTION_pflash
:
3106 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3108 case QEMU_OPTION_snapshot
:
3111 case QEMU_OPTION_hdachs
:
3115 cyls
= strtol(p
, (char **)&p
, 0);
3116 if (cyls
< 1 || cyls
> 16383)
3121 heads
= strtol(p
, (char **)&p
, 0);
3122 if (heads
< 1 || heads
> 16)
3127 secs
= strtol(p
, (char **)&p
, 0);
3128 if (secs
< 1 || secs
> 63)
3132 if (!strcmp(p
, "large")) {
3133 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3134 } else if (!strcmp(p
, "rechs")) {
3135 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3136 } else if (!strcmp(p
, "none")) {
3137 translation
= BIOS_ATA_TRANSLATION_NONE
;
3138 } else if (!strcmp(p
, "lba")) {
3139 translation
= BIOS_ATA_TRANSLATION_LBA
;
3140 } else if (!strcmp(p
, "auto")) {
3141 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3145 } else if (*p
!= '\0') {
3147 error_report("invalid physical CHS format");
3150 if (hda_opts
!= NULL
) {
3151 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3153 qemu_opt_set_number(hda_opts
, "heads", heads
,
3155 qemu_opt_set_number(hda_opts
, "secs", secs
,
3157 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3158 qemu_opt_set(hda_opts
, "trans", "large",
3160 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3161 qemu_opt_set(hda_opts
, "trans", "rechs",
3163 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3164 qemu_opt_set(hda_opts
, "trans", "lba",
3166 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3167 qemu_opt_set(hda_opts
, "trans", "none",
3173 case QEMU_OPTION_numa
:
3174 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3180 case QEMU_OPTION_display
:
3181 display_type
= select_display(optarg
);
3183 case QEMU_OPTION_nographic
:
3184 olist
= qemu_find_opts("machine");
3185 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3187 display_type
= DT_NONE
;
3189 case QEMU_OPTION_curses
:
3190 #ifdef CONFIG_CURSES
3191 display_type
= DT_CURSES
;
3193 error_report("curses support is disabled");
3197 case QEMU_OPTION_portrait
:
3198 graphic_rotate
= 90;
3200 case QEMU_OPTION_rotate
:
3201 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3202 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3203 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3204 error_report("only 90, 180, 270 deg rotation is available");
3208 case QEMU_OPTION_kernel
:
3209 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3212 case QEMU_OPTION_initrd
:
3213 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3216 case QEMU_OPTION_append
:
3217 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3220 case QEMU_OPTION_dtb
:
3221 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3224 case QEMU_OPTION_cdrom
:
3225 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3227 case QEMU_OPTION_boot
:
3228 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3234 case QEMU_OPTION_fda
:
3235 case QEMU_OPTION_fdb
:
3236 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3239 case QEMU_OPTION_no_fd_bootchk
:
3242 case QEMU_OPTION_netdev
:
3244 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3248 case QEMU_OPTION_net
:
3250 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3254 #ifdef CONFIG_LIBISCSI
3255 case QEMU_OPTION_iscsi
:
3256 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3264 case QEMU_OPTION_tftp
:
3265 error_report("The -tftp option is deprecated. "
3266 "Please use '-netdev user,tftp=...' instead.");
3267 legacy_tftp_prefix
= optarg
;
3269 case QEMU_OPTION_bootp
:
3270 error_report("The -bootp option is deprecated. "
3271 "Please use '-netdev user,bootfile=...' instead.");
3272 legacy_bootp_filename
= optarg
;
3274 case QEMU_OPTION_redir
:
3275 error_report("The -redir option is deprecated. "
3276 "Please use '-netdev user,hostfwd=...' instead.");
3277 if (net_slirp_redir(optarg
) < 0)
3281 case QEMU_OPTION_bt
:
3282 add_device_config(DEV_BT
, optarg
);
3284 case QEMU_OPTION_audio_help
:
3288 case QEMU_OPTION_soundhw
:
3289 select_soundhw (optarg
);
3294 case QEMU_OPTION_version
:
3299 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3306 case QEMU_OPTION_tpmdev
:
3307 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3312 case QEMU_OPTION_mempath
:
3315 case QEMU_OPTION_mem_prealloc
:
3324 case QEMU_OPTION_DFILTER
:
3325 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3328 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3330 case QEMU_OPTION_gdb
:
3331 add_device_config(DEV_GDB
, optarg
);
3334 if (is_help_option(optarg
)) {
3335 list_data_dirs
= true;
3336 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3337 data_dir
[data_dir_idx
++] = optarg
;
3340 case QEMU_OPTION_bios
:
3341 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3344 case QEMU_OPTION_singlestep
:
3351 keyboard_layout
= optarg
;
3353 case QEMU_OPTION_localtime
:
3356 case QEMU_OPTION_vga
:
3365 w
= strtol(p
, (char **)&p
, 10);
3368 error_report("invalid resolution or depth");
3374 h
= strtol(p
, (char **)&p
, 10);
3379 depth
= strtol(p
, (char **)&p
, 10);
3380 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3381 depth
!= 24 && depth
!= 32)
3383 } else if (*p
== '\0') {
3384 depth
= graphic_depth
;
3391 graphic_depth
= depth
;
3394 case QEMU_OPTION_echr
:
3397 term_escape_char
= strtol(optarg
, &r
, 0);
3399 printf("Bad argument to echr\n");
3402 case QEMU_OPTION_monitor
:
3403 default_monitor
= 0;
3404 if (strncmp(optarg
, "none", 4)) {
3405 monitor_parse(optarg
, "readline", false);
3408 case QEMU_OPTION_qmp
:
3409 monitor_parse(optarg
, "control", false);
3410 default_monitor
= 0;
3412 case QEMU_OPTION_qmp_pretty
:
3413 monitor_parse(optarg
, "control", true);
3414 default_monitor
= 0;
3416 case QEMU_OPTION_mon
:
3417 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3422 default_monitor
= 0;
3424 case QEMU_OPTION_chardev
:
3425 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3431 case QEMU_OPTION_fsdev
:
3432 olist
= qemu_find_opts("fsdev");
3434 error_report("fsdev support is disabled");
3437 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3442 case QEMU_OPTION_virtfs
: {
3445 const char *writeout
, *sock_fd
, *socket
;
3447 olist
= qemu_find_opts("virtfs");
3449 error_report("virtfs support is disabled");
3452 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3457 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3458 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3459 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3462 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3463 qemu_opt_get(opts
, "mount_tag"),
3466 error_report("duplicate fsdev id: %s",
3467 qemu_opt_get(opts
, "mount_tag"));
3471 writeout
= qemu_opt_get(opts
, "writeout");
3473 #ifdef CONFIG_SYNC_FILE_RANGE
3474 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3476 error_report("writeout=immediate not supported "
3477 "on this platform");
3481 qemu_opt_set(fsdev
, "fsdriver",
3482 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3483 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3485 qemu_opt_set(fsdev
, "security_model",
3486 qemu_opt_get(opts
, "security_model"),
3488 socket
= qemu_opt_get(opts
, "socket");
3490 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3492 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3494 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3497 qemu_opt_set_bool(fsdev
, "readonly",
3498 qemu_opt_get_bool(opts
, "readonly", 0),
3500 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3502 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3503 qemu_opt_set(device
, "fsdev",
3504 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3505 qemu_opt_set(device
, "mount_tag",
3506 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3509 case QEMU_OPTION_virtfs_synth
: {
3513 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3516 error_report("duplicate option: %s", "virtfs_synth");
3519 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3521 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3523 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3524 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3525 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3528 case QEMU_OPTION_serial
:
3529 add_device_config(DEV_SERIAL
, optarg
);
3531 if (strncmp(optarg
, "mon:", 4) == 0) {
3532 default_monitor
= 0;
3535 case QEMU_OPTION_watchdog
:
3537 error_report("only one watchdog option may be given");
3542 case QEMU_OPTION_watchdog_action
:
3543 if (select_watchdog_action(optarg
) == -1) {
3544 error_report("unknown -watchdog-action parameter");
3548 case QEMU_OPTION_virtiocon
:
3549 add_device_config(DEV_VIRTCON
, optarg
);
3550 default_virtcon
= 0;
3551 if (strncmp(optarg
, "mon:", 4) == 0) {
3552 default_monitor
= 0;
3555 case QEMU_OPTION_parallel
:
3556 add_device_config(DEV_PARALLEL
, optarg
);
3557 default_parallel
= 0;
3558 if (strncmp(optarg
, "mon:", 4) == 0) {
3559 default_monitor
= 0;
3562 case QEMU_OPTION_debugcon
:
3563 add_device_config(DEV_DEBUGCON
, optarg
);
3565 case QEMU_OPTION_loadvm
:
3568 case QEMU_OPTION_full_screen
:
3571 case QEMU_OPTION_no_frame
:
3574 case QEMU_OPTION_alt_grab
:
3577 case QEMU_OPTION_ctrl_grab
:
3580 case QEMU_OPTION_no_quit
:
3583 case QEMU_OPTION_sdl
:
3585 display_type
= DT_SDL
;
3588 error_report("SDL support is disabled");
3591 case QEMU_OPTION_pidfile
:
3594 case QEMU_OPTION_win2k_hack
:
3595 win2k_install_hack
= 1;
3597 case QEMU_OPTION_rtc_td_hack
: {
3598 static GlobalProperty slew_lost_ticks
= {
3599 .driver
= "mc146818rtc",
3600 .property
= "lost_tick_policy",
3604 qdev_prop_register_global(&slew_lost_ticks
);
3607 case QEMU_OPTION_acpitable
:
3608 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3613 acpi_table_add(opts
, &error_fatal
);
3615 case QEMU_OPTION_smbios
:
3616 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3621 smbios_entry_add(opts
, &error_fatal
);
3623 case QEMU_OPTION_fwcfg
:
3624 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3630 case QEMU_OPTION_enable_kvm
:
3631 olist
= qemu_find_opts("machine");
3632 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3634 case QEMU_OPTION_enable_hax
:
3635 olist
= qemu_find_opts("machine");
3636 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3639 case QEMU_OPTION_machine
:
3640 olist
= qemu_find_opts("machine");
3641 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3646 case QEMU_OPTION_no_kvm
:
3647 olist
= qemu_find_opts("machine");
3648 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3650 case QEMU_OPTION_no_kvm_pit
: {
3651 error_report("warning: ignoring deprecated option");
3654 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3655 static GlobalProperty kvm_pit_lost_tick_policy
= {
3656 .driver
= "kvm-pit",
3657 .property
= "lost_tick_policy",
3661 error_report("warning: deprecated, replaced by "
3662 "-global kvm-pit.lost_tick_policy=discard");
3663 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3666 case QEMU_OPTION_usb
:
3667 olist
= qemu_find_opts("machine");
3668 qemu_opts_parse_noisily(olist
, "usb=on", false);
3670 case QEMU_OPTION_usbdevice
:
3671 olist
= qemu_find_opts("machine");
3672 qemu_opts_parse_noisily(olist
, "usb=on", false);
3673 add_device_config(DEV_USB
, optarg
);
3675 case QEMU_OPTION_device
:
3676 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3681 case QEMU_OPTION_smp
:
3682 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3687 case QEMU_OPTION_vnc
:
3688 vnc_parse(optarg
, &error_fatal
);
3690 case QEMU_OPTION_no_acpi
:
3693 case QEMU_OPTION_no_hpet
:
3696 case QEMU_OPTION_balloon
:
3697 if (balloon_parse(optarg
) < 0) {
3698 error_report("unknown -balloon argument %s", optarg
);
3702 case QEMU_OPTION_no_reboot
:
3705 case QEMU_OPTION_no_shutdown
:
3708 case QEMU_OPTION_show_cursor
:
3711 case QEMU_OPTION_uuid
:
3712 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3713 error_report("failed to parse UUID string: wrong format");
3716 qemu_uuid_set
= true;
3718 case QEMU_OPTION_option_rom
:
3719 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3720 error_report("too many option ROMs");
3723 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3728 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3729 option_rom
[nb_option_roms
].bootindex
=
3730 qemu_opt_get_number(opts
, "bootindex", -1);
3731 if (!option_rom
[nb_option_roms
].name
) {
3732 error_report("Option ROM file is not specified");
3737 case QEMU_OPTION_semihosting
:
3738 semihosting
.enabled
= true;
3739 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3741 case QEMU_OPTION_semihosting_config
:
3742 semihosting
.enabled
= true;
3743 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3746 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3748 const char *target
= qemu_opt_get(opts
, "target");
3749 if (target
!= NULL
) {
3750 if (strcmp("native", target
) == 0) {
3751 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3752 } else if (strcmp("gdb", target
) == 0) {
3753 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3754 } else if (strcmp("auto", target
) == 0) {
3755 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3757 error_report("unsupported semihosting-config %s",
3762 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3764 /* Set semihosting argument count and vector */
3765 qemu_opt_foreach(opts
, add_semihosting_arg
,
3766 &semihosting
, NULL
);
3768 error_report("unsupported semihosting-config %s", optarg
);
3772 case QEMU_OPTION_tdf
:
3773 error_report("warning: ignoring deprecated option");
3775 case QEMU_OPTION_name
:
3776 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3782 case QEMU_OPTION_prom_env
:
3783 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3784 error_report("too many prom variables");
3787 prom_envs
[nb_prom_envs
] = optarg
;
3790 case QEMU_OPTION_old_param
:
3793 case QEMU_OPTION_clock
:
3794 /* Clock options no longer exist. Keep this option for
3795 * backward compatibility.
3798 case QEMU_OPTION_startdate
:
3799 configure_rtc_date_offset(optarg
, 1);
3801 case QEMU_OPTION_rtc
:
3802 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3807 configure_rtc(opts
);
3809 case QEMU_OPTION_tb_size
:
3810 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3811 if (tcg_tb_size
< 0) {
3815 case QEMU_OPTION_icount
:
3816 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3822 case QEMU_OPTION_incoming
:
3824 runstate_set(RUN_STATE_INMIGRATE
);
3828 case QEMU_OPTION_only_migratable
:
3829 only_migratable
= 1;
3831 case QEMU_OPTION_nodefaults
:
3834 case QEMU_OPTION_xen_domid
:
3835 if (!(xen_available())) {
3836 error_report("Option not supported for this target");
3839 xen_domid
= atoi(optarg
);
3841 case QEMU_OPTION_xen_create
:
3842 if (!(xen_available())) {
3843 error_report("Option not supported for this target");
3846 xen_mode
= XEN_CREATE
;
3848 case QEMU_OPTION_xen_attach
:
3849 if (!(xen_available())) {
3850 error_report("Option not supported for this target");
3853 xen_mode
= XEN_ATTACH
;
3855 case QEMU_OPTION_trace
:
3857 trace_file
= trace_opt_parse(optarg
);
3859 case QEMU_OPTION_readconfig
:
3861 int ret
= qemu_read_config_file(optarg
);
3863 error_report("read config %s: %s", optarg
,
3869 case QEMU_OPTION_spice
:
3870 olist
= qemu_find_opts("spice");
3872 error_report("spice support is disabled");
3875 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3881 case QEMU_OPTION_writeconfig
:
3884 if (strcmp(optarg
, "-") == 0) {
3887 fp
= fopen(optarg
, "w");
3889 error_report("open %s: %s", optarg
,
3894 qemu_config_write(fp
);
3900 case QEMU_OPTION_qtest
:
3901 qtest_chrdev
= optarg
;
3903 case QEMU_OPTION_qtest_log
:
3906 case QEMU_OPTION_sandbox
:
3907 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
3913 case QEMU_OPTION_add_fd
:
3915 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3921 error_report("File descriptor passing is disabled on this "
3926 case QEMU_OPTION_object
:
3927 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
3933 case QEMU_OPTION_realtime
:
3934 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
3939 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
3941 case QEMU_OPTION_msg
:
3942 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3947 configure_msg(opts
);
3949 case QEMU_OPTION_dump_vmstate
:
3950 if (vmstate_dump_file
) {
3951 error_report("only one '-dump-vmstate' "
3952 "option may be given");
3955 vmstate_dump_file
= fopen(optarg
, "w");
3956 if (vmstate_dump_file
== NULL
) {
3957 error_report("open %s: %s", optarg
, strerror(errno
));
3962 os_parse_cmd_args(popt
->index
, optarg
);
3967 * Clear error location left behind by the loop.
3968 * Best done right after the loop. Do not insert code here!
3972 replay_configure(icount_opts
);
3974 machine_class
= select_machine();
3976 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
3980 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
3981 error_report("could not acquire pid file: %s", strerror(errno
));
3985 if (qemu_init_main_loop(&main_loop_err
)) {
3986 error_report_err(main_loop_err
);
3990 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
3991 parse_sandbox
, NULL
, NULL
)) {
3995 if (qemu_opts_foreach(qemu_find_opts("name"),
3996 parse_name
, NULL
, NULL
)) {
4001 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4002 parse_add_fd
, NULL
, NULL
)) {
4006 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4007 cleanup_add_fd
, NULL
, NULL
)) {
4012 current_machine
= MACHINE(object_new(object_class_get_name(
4013 OBJECT_CLASS(machine_class
))));
4014 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4017 object_property_add_child(object_get_root(), "machine",
4018 OBJECT(current_machine
), &error_abort
);
4020 if (machine_class
->minimum_page_bits
) {
4021 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4022 /* This would be a board error: specifying a minimum smaller than
4023 * a target's compile-time fixed setting.
4025 g_assert_not_reached();
4029 cpu_exec_init_all();
4031 if (machine_class
->hw_version
) {
4032 qemu_set_hw_version(machine_class
->hw_version
);
4035 if (cpu_model
&& is_help_option(cpu_model
)) {
4036 list_cpus(stdout
, &fprintf
, cpu_model
);
4040 if (!trace_init_backends()) {
4043 trace_init_file(trace_file
);
4045 /* Open the logfile at this point and set the log mask if necessary.
4048 qemu_set_log_filename(log_file
, &error_fatal
);
4053 mask
= qemu_str_to_log_mask(log_mask
);
4055 qemu_print_log_usage(stdout
);
4063 /* If no data_dir is specified then try to find it relative to the
4065 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4066 data_dir
[data_dir_idx
] = os_find_datadir();
4067 if (data_dir
[data_dir_idx
] != NULL
) {
4071 /* If all else fails use the install path specified when building. */
4072 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4073 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4076 /* -L help lists the data directories and exits. */
4077 if (list_data_dirs
) {
4078 for (i
= 0; i
< data_dir_idx
; i
++) {
4079 printf("%s\n", data_dir
[i
]);
4084 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4086 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4087 if (max_cpus
> machine_class
->max_cpus
) {
4088 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4089 "supported by machine '%s' (%d)", max_cpus
,
4090 machine_class
->name
, machine_class
->max_cpus
);
4095 * Get the default machine options from the machine if it is not already
4096 * specified either by the configuration file or by the command line.
4098 if (machine_class
->default_machine_opts
) {
4099 qemu_opts_set_defaults(qemu_find_opts("machine"),
4100 machine_class
->default_machine_opts
, 0);
4103 qemu_opts_foreach(qemu_find_opts("device"),
4104 default_driver_check
, NULL
, NULL
);
4105 qemu_opts_foreach(qemu_find_opts("global"),
4106 default_driver_check
, NULL
, NULL
);
4108 if (!vga_model
&& !default_vga
) {
4109 vga_interface_type
= VGA_DEVICE
;
4111 if (!has_defaults
|| machine_class
->no_serial
) {
4114 if (!has_defaults
|| machine_class
->no_parallel
) {
4115 default_parallel
= 0;
4117 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4118 default_virtcon
= 0;
4120 if (!has_defaults
|| !machine_class
->use_sclp
) {
4123 if (!has_defaults
|| machine_class
->no_floppy
) {
4126 if (!has_defaults
|| machine_class
->no_cdrom
) {
4129 if (!has_defaults
|| machine_class
->no_sdcard
) {
4132 if (!has_defaults
) {
4133 default_monitor
= 0;
4138 if (is_daemonized()) {
4139 /* According to documentation and historically, -nographic redirects
4140 * serial port, parallel port and monitor to stdio, which does not work
4141 * with -daemonize. We can redirect these to null instead, but since
4142 * -nographic is legacy, let's just error out.
4143 * We disallow -nographic only if all other ports are not redirected
4144 * explicitly, to not break existing legacy setups which uses
4145 * -nographic _and_ redirects all ports explicitly - this is valid
4146 * usage, -nographic is just a no-op in this case.
4149 && (default_parallel
|| default_serial
4150 || default_monitor
|| default_virtcon
)) {
4151 error_report("-nographic cannot be used with -daemonize");
4154 #ifdef CONFIG_CURSES
4155 if (display_type
== DT_CURSES
) {
4156 error_report("curses display cannot be used with -daemonize");
4163 if (default_parallel
)
4164 add_device_config(DEV_PARALLEL
, "null");
4165 if (default_serial
&& default_monitor
) {
4166 add_device_config(DEV_SERIAL
, "mon:stdio");
4167 } else if (default_virtcon
&& default_monitor
) {
4168 add_device_config(DEV_VIRTCON
, "mon:stdio");
4169 } else if (default_sclp
&& default_monitor
) {
4170 add_device_config(DEV_SCLP
, "mon:stdio");
4173 add_device_config(DEV_SERIAL
, "stdio");
4174 if (default_virtcon
)
4175 add_device_config(DEV_VIRTCON
, "stdio");
4177 add_device_config(DEV_SCLP
, "stdio");
4179 if (default_monitor
)
4180 monitor_parse("stdio", "readline", false);
4184 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4185 if (default_parallel
)
4186 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4187 if (default_monitor
)
4188 monitor_parse("vc:80Cx24C", "readline", false);
4189 if (default_virtcon
)
4190 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4192 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4196 #if defined(CONFIG_VNC)
4197 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4201 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4202 #if defined(CONFIG_GTK)
4203 display_type
= DT_GTK
;
4204 #elif defined(CONFIG_SDL)
4205 display_type
= DT_SDL
;
4206 #elif defined(CONFIG_COCOA)
4207 display_type
= DT_COCOA
;
4208 #elif defined(CONFIG_VNC)
4209 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4211 display_type
= DT_NONE
;
4215 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4216 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4217 "for SDL, ignoring option");
4219 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4220 error_report("-no-quit is only valid for GTK and SDL, "
4224 if (display_type
== DT_GTK
) {
4225 early_gtk_display_init(request_opengl
);
4228 if (display_type
== DT_SDL
) {
4229 sdl_display_early_init(request_opengl
);
4232 qemu_console_early_init();
4234 if (request_opengl
== 1 && display_opengl
== 0) {
4235 #if defined(CONFIG_OPENGL)
4236 error_report("OpenGL is not supported by the display");
4238 error_report("OpenGL support is disabled");
4246 if (qemu_opts_foreach(qemu_find_opts("object"),
4247 user_creatable_add_opts_foreach
,
4248 object_create_initial
, NULL
)) {
4252 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4253 chardev_init_func
, NULL
, NULL
)) {
4257 #ifdef CONFIG_VIRTFS
4258 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4259 fsdev_init_func
, NULL
, NULL
)) {
4264 if (qemu_opts_foreach(qemu_find_opts("device"),
4265 device_help_func
, NULL
, NULL
)) {
4269 machine_opts
= qemu_get_machine_opts();
4270 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4272 object_unref(OBJECT(current_machine
));
4276 configure_accelerator(current_machine
);
4279 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4282 machine_opts
= qemu_get_machine_opts();
4283 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4284 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4285 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4286 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4288 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4290 boot_order
= qemu_opt_get(opts
, "order");
4292 validate_bootdevices(boot_order
, &error_fatal
);
4295 boot_once
= qemu_opt_get(opts
, "once");
4297 validate_bootdevices(boot_once
, &error_fatal
);
4300 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4301 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4305 boot_order
= machine_class
->default_boot_order
;
4308 if (!kernel_cmdline
) {
4309 kernel_cmdline
= "";
4310 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4313 linux_boot
= (kernel_filename
!= NULL
);
4315 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4316 error_report("-append only allowed with -kernel option");
4320 if (!linux_boot
&& initrd_filename
!= NULL
) {
4321 error_report("-initrd only allowed with -kernel option");
4325 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4326 /* fall back to the -kernel/-append */
4327 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4330 os_set_line_buffering();
4332 /* spice needs the timers to be initialized by this point */
4337 if (!tcg_enabled()) {
4338 error_report("-icount is not allowed with hardware virtualization");
4341 configure_icount(icount_opts
, &error_abort
);
4342 qemu_opts_del(icount_opts
);
4346 QemuOptsList
*net
= qemu_find_opts("net");
4347 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4349 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4355 if (net_init_clients() < 0) {
4359 if (qemu_opts_foreach(qemu_find_opts("object"),
4360 user_creatable_add_opts_foreach
,
4361 object_create_delayed
, NULL
)) {
4366 if (tpm_init() < 0) {
4371 /* init the bluetooth world */
4372 if (foreach_device_config(DEV_BT
, bt_parse
))
4375 if (!xen_enabled()) {
4376 /* On 32-bit hosts, QEMU is limited by virtual address space */
4377 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4378 error_report("at most 2047 MB RAM can be simulated");
4386 /* If the currently selected machine wishes to override the units-per-bus
4387 * property of its default HBA interface type, do so now. */
4388 if (machine_class
->units_per_default_bus
) {
4389 override_max_devs(machine_class
->block_default_type
,
4390 machine_class
->units_per_default_bus
);
4393 /* open the virtual block devices */
4394 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4395 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4398 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4399 &machine_class
->block_default_type
, NULL
)) {
4403 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4405 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4406 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4408 parse_numa_opts(machine_class
);
4410 if (qemu_opts_foreach(qemu_find_opts("mon"),
4411 mon_init_func
, NULL
, NULL
)) {
4415 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4417 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4419 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4421 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4424 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4427 /* If no default VGA is requested, the default is "none". */
4429 if (machine_class
->default_display
) {
4430 vga_model
= machine_class
->default_display
;
4431 } else if (vga_interface_available(VGA_CIRRUS
)) {
4432 vga_model
= "cirrus";
4433 } else if (vga_interface_available(VGA_STD
)) {
4438 select_vgahw(vga_model
);
4442 i
= select_watchdog(watchdog
);
4444 exit (i
== 1 ? 1 : 0);
4447 machine_register_compat_props(current_machine
);
4449 qemu_opts_foreach(qemu_find_opts("global"),
4450 global_init_func
, NULL
, NULL
);
4452 /* This checkpoint is required by replay to separate prior clock
4453 reading from the other reads, because timer polling functions query
4454 clock values from the log. */
4455 replay_checkpoint(CHECKPOINT_INIT
);
4456 qdev_machine_init();
4458 current_machine
->ram_size
= ram_size
;
4459 current_machine
->maxram_size
= maxram_size
;
4460 current_machine
->ram_slots
= ram_slots
;
4461 current_machine
->boot_order
= boot_order
;
4462 current_machine
->cpu_model
= cpu_model
;
4464 machine_class
->init(current_machine
);
4470 if (hax_enabled()) {
4474 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4475 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4479 /* init USB devices */
4480 if (machine_usb(current_machine
)) {
4481 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4485 /* Check if IGD GFX passthrough. */
4488 /* init generic devices */
4489 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4490 if (qemu_opts_foreach(qemu_find_opts("device"),
4491 device_init_func
, NULL
, NULL
)) {
4495 cpu_synchronize_all_post_init();
4497 numa_post_machine_init();
4499 rom_reset_order_override();
4501 /* Did we create any drives that we failed to create a device for? */
4502 drive_check_orphaned();
4504 /* Don't warn about the default network setup that you get if
4505 * no command line -net or -netdev options are specified. There
4506 * are two cases that we would otherwise complain about:
4507 * (1) board doesn't support a NIC but the implicit "-net nic"
4509 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4510 * sets up a nic that isn't connected to anything.
4513 net_check_clients();
4518 qemu_boot_set(boot_once
, &error_fatal
);
4519 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4522 ds
= init_displaystate();
4524 /* init local displays */
4525 switch (display_type
) {
4527 curses_display_init(ds
, full_screen
);
4530 sdl_display_init(ds
, full_screen
, no_frame
);
4533 cocoa_display_init(ds
, full_screen
);
4536 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4542 /* must be after terminal init, SDL library changes signal handlers */
4543 os_setup_signal_handling();
4545 /* init remote displays */
4547 qemu_opts_foreach(qemu_find_opts("vnc"),
4548 vnc_init_func
, NULL
, NULL
);
4552 qemu_spice_display_init();
4555 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4559 qdev_machine_creation_done();
4561 /* TODO: once all bus devices are qdevified, this should be done
4562 * when bus is created by qdev.c */
4563 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4564 qemu_run_machine_init_done_notifiers();
4566 if (rom_check_and_register_reset() != 0) {
4567 error_report("rom check and register reset failed");
4573 /* This checkpoint is required by replay to separate prior clock
4574 reading from the other reads, because timer polling functions query
4575 clock values from the log. */
4576 replay_checkpoint(CHECKPOINT_RESET
);
4577 qemu_system_reset(VMRESET_SILENT
);
4578 register_global_state();
4579 if (replay_mode
!= REPLAY_MODE_NONE
) {
4580 replay_vmstate_init();
4581 } else if (loadvm
) {
4582 if (load_vmstate(loadvm
) < 0) {
4587 qdev_prop_check_globals();
4588 if (vmstate_dump_file
) {
4590 dump_vmstate_json_to_file(vmstate_dump_file
);
4595 Error
*local_err
= NULL
;
4596 qemu_start_incoming_migration(incoming
, &local_err
);
4598 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4601 } else if (autostart
) {
4608 replay_disable_events();
4609 iothread_stop_all();
4615 /* vhost-user must be cleaned up before chardevs. */