4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "qemu/osdep.h"
25 #include "qemu/cutils.h"
26 #include "qemu/help_option.h"
29 #include "sysemu/seccomp.h"
32 #if defined(CONFIG_VDE)
33 #include <libvdeplug.h>
37 #if defined(__APPLE__) || defined(main)
39 int qemu_main(int argc
, char **argv
);
40 int main(int argc
, char **argv
)
42 return qemu_main(argc
, argv
);
45 #define main qemu_main
47 #endif /* CONFIG_SDL */
51 #define main qemu_main
52 #endif /* CONFIG_COCOA */
56 #include "qemu/error-report.h"
57 #include "qemu/sockets.h"
59 #include "hw/boards.h"
60 #include "sysemu/accel.h"
62 #include "hw/i386/pc.h"
63 #include "hw/isa/isa.h"
65 #include "sysemu/watchdog.h"
66 #include "hw/smbios/smbios.h"
67 #include "hw/xen/xen.h"
69 #include "hw/loader.h"
70 #include "monitor/qdev.h"
71 #include "sysemu/bt.h"
73 #include "net/slirp.h"
74 #include "monitor/monitor.h"
75 #include "ui/console.h"
77 #include "sysemu/sysemu.h"
78 #include "sysemu/numa.h"
79 #include "exec/gdbstub.h"
80 #include "qemu/timer.h"
81 #include "sysemu/char.h"
82 #include "qemu/bitmap.h"
83 #include "sysemu/blockdev.h"
84 #include "hw/block/block.h"
85 #include "migration/block.h"
86 #include "sysemu/tpm.h"
87 #include "sysemu/dma.h"
88 #include "audio/audio.h"
89 #include "migration/migration.h"
90 #include "sysemu/kvm.h"
91 #include "qapi/qmp/qjson.h"
92 #include "qemu/option.h"
93 #include "qemu/config-file.h"
94 #include "qemu-options.h"
95 #include "qmp-commands.h"
96 #include "qemu/main-loop.h"
98 #include "fsdev/qemu-fsdev.h"
100 #include "sysemu/qtest.h"
102 #include "disas/disas.h"
105 #include "slirp/libslirp.h"
108 #include "trace/control.h"
109 #include "qemu/queue.h"
110 #include "sysemu/cpus.h"
111 #include "sysemu/arch_init.h"
113 #include "ui/qemu-spice.h"
114 #include "qapi/string-input-visitor.h"
115 #include "qapi/opts-visitor.h"
116 #include "qom/object_interfaces.h"
117 #include "qapi-event.h"
118 #include "exec/semihost.h"
119 #include "crypto/init.h"
120 #include "sysemu/replay.h"
121 #include "qapi/qmp/qerror.h"
123 #define MAX_VIRTIO_CONSOLES 1
124 #define MAX_SCLP_CONSOLES 1
126 static const char *data_dir
[16];
127 static int data_dir_idx
;
128 const char *bios_name
= NULL
;
129 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
130 DisplayType display_type
= DT_DEFAULT
;
131 int request_opengl
= -1;
133 static int display_remote
;
134 const char* keyboard_layout
= NULL
;
136 const char *mem_path
= NULL
;
137 int mem_prealloc
= 0; /* force preallocation of physical target memory */
138 bool enable_mlock
= false;
140 NICInfo nd_table
[MAX_NICS
];
142 static int rtc_utc
= 1;
143 static int rtc_date_offset
= -1; /* -1 means no change */
144 QEMUClockType rtc_clock
;
145 int vga_interface_type
= VGA_NONE
;
146 static int full_screen
= 0;
147 static int no_frame
= 0;
150 static bool grab_on_hover
;
152 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
153 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
154 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
155 CharDriverState
*sclp_hds
[MAX_SCLP_CONSOLES
];
156 int win2k_install_hack
= 0;
162 int acpi_enabled
= 1;
165 static int no_reboot
;
168 int graphic_rotate
= 0;
169 const char *watchdog
;
170 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
173 const char *qemu_name
;
176 unsigned int nb_prom_envs
= 0;
177 const char *prom_envs
[MAX_PROM_ENVS
];
180 uint8_t *boot_splash_filedata
;
181 size_t boot_splash_filedata_size
;
182 uint8_t qemu_extra_params_fw
[2];
184 int icount_align_option
;
186 /* The bytes in qemu_uuid[] are in the order specified by RFC4122, _not_ in the
187 * little-endian "wire format" described in the SMBIOS 2.6 specification.
189 uint8_t qemu_uuid
[16];
192 /* Trace unassigned memory or i/o accesses. */
193 bool trace_unassigned
;
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;
220 { .driver
= "isa-serial", .flag
= &default_serial
},
221 { .driver
= "isa-parallel", .flag
= &default_parallel
},
222 { .driver
= "isa-fdc", .flag
= &default_floppy
},
223 { .driver
= "ide-cd", .flag
= &default_cdrom
},
224 { .driver
= "ide-hd", .flag
= &default_cdrom
},
225 { .driver
= "ide-drive", .flag
= &default_cdrom
},
226 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
227 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
228 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
229 { .driver
= "VGA", .flag
= &default_vga
},
230 { .driver
= "isa-vga", .flag
= &default_vga
},
231 { .driver
= "cirrus-vga", .flag
= &default_vga
},
232 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
233 { .driver
= "vmware-svga", .flag
= &default_vga
},
234 { .driver
= "qxl-vga", .flag
= &default_vga
},
235 { .driver
= "virtio-vga", .flag
= &default_vga
},
238 static QemuOptsList qemu_rtc_opts
= {
240 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
244 .type
= QEMU_OPT_STRING
,
247 .type
= QEMU_OPT_STRING
,
250 .type
= QEMU_OPT_STRING
,
252 { /* end of list */ }
256 static QemuOptsList qemu_sandbox_opts
= {
258 .implied_opt_name
= "enable",
259 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
263 .type
= QEMU_OPT_BOOL
,
265 { /* end of list */ }
269 static QemuOptsList qemu_trace_opts
= {
271 .implied_opt_name
= "enable",
272 .head
= QTAILQ_HEAD_INITIALIZER(qemu_trace_opts
.head
),
276 .type
= QEMU_OPT_STRING
,
280 .type
= QEMU_OPT_STRING
,
283 .type
= QEMU_OPT_STRING
,
285 { /* end of list */ }
289 static QemuOptsList qemu_option_rom_opts
= {
290 .name
= "option-rom",
291 .implied_opt_name
= "romfile",
292 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
296 .type
= QEMU_OPT_NUMBER
,
299 .type
= QEMU_OPT_STRING
,
301 { /* end of list */ }
305 static QemuOptsList qemu_machine_opts
= {
307 .implied_opt_name
= "type",
309 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
312 * no elements => accept any
313 * sanity checking will happen later
314 * when setting machine properties
320 static QemuOptsList qemu_boot_opts
= {
322 .implied_opt_name
= "order",
324 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
328 .type
= QEMU_OPT_STRING
,
331 .type
= QEMU_OPT_STRING
,
334 .type
= QEMU_OPT_BOOL
,
337 .type
= QEMU_OPT_STRING
,
339 .name
= "splash-time",
340 .type
= QEMU_OPT_STRING
,
342 .name
= "reboot-timeout",
343 .type
= QEMU_OPT_STRING
,
346 .type
= QEMU_OPT_BOOL
,
352 static QemuOptsList qemu_add_fd_opts
= {
354 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
358 .type
= QEMU_OPT_NUMBER
,
359 .help
= "file descriptor of which a duplicate is added to fd set",
362 .type
= QEMU_OPT_NUMBER
,
363 .help
= "ID of the fd set to add fd to",
366 .type
= QEMU_OPT_STRING
,
367 .help
= "free-form string used to describe fd",
369 { /* end of list */ }
373 static QemuOptsList qemu_object_opts
= {
375 .implied_opt_name
= "qom-type",
376 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
382 static QemuOptsList qemu_tpmdev_opts
= {
384 .implied_opt_name
= "type",
385 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
387 /* options are defined in the TPM backends */
388 { /* end of list */ }
392 static QemuOptsList qemu_realtime_opts
= {
394 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
398 .type
= QEMU_OPT_BOOL
,
400 { /* end of list */ }
404 static QemuOptsList qemu_msg_opts
= {
406 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
410 .type
= QEMU_OPT_BOOL
,
412 { /* end of list */ }
416 static QemuOptsList qemu_name_opts
= {
418 .implied_opt_name
= "guest",
420 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
424 .type
= QEMU_OPT_STRING
,
425 .help
= "Sets the name of the guest.\n"
426 "This name will be displayed in the SDL window caption.\n"
427 "The name will also be used for the VNC server",
430 .type
= QEMU_OPT_STRING
,
431 .help
= "Sets the name of the QEMU process, as shown in top etc",
433 .name
= "debug-threads",
434 .type
= QEMU_OPT_BOOL
,
435 .help
= "When enabled, name the individual threads; defaults off.\n"
436 "NOTE: The thread names are for debugging and not a\n"
439 { /* End of list */ }
443 static QemuOptsList qemu_mem_opts
= {
445 .implied_opt_name
= "size",
446 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
451 .type
= QEMU_OPT_SIZE
,
455 .type
= QEMU_OPT_NUMBER
,
459 .type
= QEMU_OPT_SIZE
,
461 { /* end of list */ }
465 static QemuOptsList qemu_icount_opts
= {
467 .implied_opt_name
= "shift",
469 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
473 .type
= QEMU_OPT_STRING
,
476 .type
= QEMU_OPT_BOOL
,
479 .type
= QEMU_OPT_BOOL
,
482 .type
= QEMU_OPT_STRING
,
485 .type
= QEMU_OPT_STRING
,
487 { /* end of list */ }
491 static QemuOptsList qemu_semihosting_config_opts
= {
492 .name
= "semihosting-config",
493 .implied_opt_name
= "enable",
494 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
498 .type
= QEMU_OPT_BOOL
,
501 .type
= QEMU_OPT_STRING
,
504 .type
= QEMU_OPT_STRING
,
506 { /* end of list */ }
510 static QemuOptsList qemu_fw_cfg_opts
= {
512 .implied_opt_name
= "name",
513 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
517 .type
= QEMU_OPT_STRING
,
518 .help
= "Sets the fw_cfg name of the blob to be inserted",
521 .type
= QEMU_OPT_STRING
,
522 .help
= "Sets the name of the file from which\n"
523 "the fw_cfg blob will be loaded",
526 .type
= QEMU_OPT_STRING
,
527 .help
= "Sets content of the blob to be inserted from a string",
529 { /* end of list */ }
534 * Get machine options
536 * Returns: machine options (never null).
538 QemuOpts
*qemu_get_machine_opts(void)
540 return qemu_find_opts_singleton("machine");
543 const char *qemu_get_vm_name(void)
548 static void res_free(void)
550 g_free(boot_splash_filedata
);
551 boot_splash_filedata
= NULL
;
554 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
556 const char *driver
= qemu_opt_get(opts
, "driver");
561 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
562 if (strcmp(default_list
[i
].driver
, driver
) != 0)
564 *(default_list
[i
].flag
) = 0;
569 /***********************************************************/
572 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
574 /* We use RUN_STATE__MAX but any invalid value will do */
575 static RunState vmstop_requested
= RUN_STATE__MAX
;
576 static QemuMutex vmstop_lock
;
581 } RunStateTransition
;
583 static const RunStateTransition runstate_transitions_def
[] = {
585 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
586 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
587 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
589 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
590 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
591 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
592 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
593 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
594 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
595 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
596 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
597 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
598 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
599 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
601 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
602 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
603 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
605 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
606 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
607 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
609 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
610 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
611 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
613 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
614 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
615 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
617 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
618 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
619 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
621 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
622 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
623 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
625 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
626 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
628 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
629 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
630 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
631 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
632 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
633 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
634 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
635 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
636 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
637 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
639 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
641 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
642 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
643 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
645 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
646 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
647 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
648 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
649 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
651 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
652 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
653 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
655 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
656 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
657 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
659 { RUN_STATE__MAX
, RUN_STATE__MAX
},
662 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
664 bool runstate_check(RunState state
)
666 return current_run_state
== state
;
669 bool runstate_store(char *str
, size_t size
)
671 const char *state
= RunState_lookup
[current_run_state
];
672 size_t len
= strlen(state
) + 1;
677 memcpy(str
, state
, len
);
681 static void runstate_init(void)
683 const RunStateTransition
*p
;
685 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
686 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
687 runstate_valid_transitions
[p
->from
][p
->to
] = true;
690 qemu_mutex_init(&vmstop_lock
);
693 /* This function will abort() on invalid state transitions */
694 void runstate_set(RunState new_state
)
696 assert(new_state
< RUN_STATE__MAX
);
698 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
699 error_report("invalid runstate transition: '%s' -> '%s'",
700 RunState_lookup
[current_run_state
],
701 RunState_lookup
[new_state
]);
704 trace_runstate_set(new_state
);
705 current_run_state
= new_state
;
708 int runstate_is_running(void)
710 return runstate_check(RUN_STATE_RUNNING
);
713 bool runstate_needs_reset(void)
715 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
716 runstate_check(RUN_STATE_SHUTDOWN
);
719 StatusInfo
*qmp_query_status(Error
**errp
)
721 StatusInfo
*info
= g_malloc0(sizeof(*info
));
723 info
->running
= runstate_is_running();
724 info
->singlestep
= singlestep
;
725 info
->status
= current_run_state
;
730 static bool qemu_vmstop_requested(RunState
*r
)
732 qemu_mutex_lock(&vmstop_lock
);
733 *r
= vmstop_requested
;
734 vmstop_requested
= RUN_STATE__MAX
;
735 qemu_mutex_unlock(&vmstop_lock
);
736 return *r
< RUN_STATE__MAX
;
739 void qemu_system_vmstop_request_prepare(void)
741 qemu_mutex_lock(&vmstop_lock
);
744 void qemu_system_vmstop_request(RunState state
)
746 vmstop_requested
= state
;
747 qemu_mutex_unlock(&vmstop_lock
);
755 qemu_vmstop_requested(&requested
);
756 if (runstate_is_running() && requested
== RUN_STATE__MAX
) {
760 /* Ensure that a STOP/RESUME pair of events is emitted if a
761 * vmstop request was pending. The BLOCK_IO_ERROR event, for
762 * example, according to documentation is always followed by
765 if (runstate_is_running()) {
766 qapi_event_send_stop(&error_abort
);
769 runstate_set(RUN_STATE_RUNNING
);
770 vm_state_notify(1, RUN_STATE_RUNNING
);
774 qapi_event_send_resume(&error_abort
);
778 /***********************************************************/
779 /* real time host monotonic timer */
781 static time_t qemu_time(void)
783 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
786 /***********************************************************/
787 /* host time/date access */
788 void qemu_get_timedate(struct tm
*tm
, int offset
)
790 time_t ti
= qemu_time();
793 if (rtc_date_offset
== -1) {
797 localtime_r(&ti
, tm
);
799 ti
-= rtc_date_offset
;
804 int qemu_timedate_diff(struct tm
*tm
)
808 if (rtc_date_offset
== -1)
810 seconds
= mktimegm(tm
);
813 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
814 seconds
= mktime(&tmp
);
817 seconds
= mktimegm(tm
) + rtc_date_offset
;
819 return seconds
- qemu_time();
822 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
824 time_t rtc_start_date
;
827 if (!strcmp(startdate
, "now") && legacy
) {
828 rtc_date_offset
= -1;
830 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
838 } else if (sscanf(startdate
, "%d-%d-%d",
850 rtc_start_date
= mktimegm(&tm
);
851 if (rtc_start_date
== -1) {
853 error_report("invalid date format");
854 error_printf("valid formats: "
855 "'2006-06-17T16:01:21' or '2006-06-17'\n");
858 rtc_date_offset
= qemu_time() - rtc_start_date
;
862 static void configure_rtc(QemuOpts
*opts
)
866 value
= qemu_opt_get(opts
, "base");
868 if (!strcmp(value
, "utc")) {
870 } else if (!strcmp(value
, "localtime")) {
871 Error
*blocker
= NULL
;
873 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
874 "-rtc base=localtime");
875 replay_add_blocker(blocker
);
877 configure_rtc_date_offset(value
, 0);
880 value
= qemu_opt_get(opts
, "clock");
882 if (!strcmp(value
, "host")) {
883 rtc_clock
= QEMU_CLOCK_HOST
;
884 } else if (!strcmp(value
, "rt")) {
885 rtc_clock
= QEMU_CLOCK_REALTIME
;
886 } else if (!strcmp(value
, "vm")) {
887 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
889 error_report("invalid option value '%s'", value
);
893 value
= qemu_opt_get(opts
, "driftfix");
895 if (!strcmp(value
, "slew")) {
896 static GlobalProperty slew_lost_ticks
[] = {
898 .driver
= "mc146818rtc",
899 .property
= "lost_tick_policy",
902 { /* end of list */ }
905 qdev_prop_register_global_list(slew_lost_ticks
);
906 } else if (!strcmp(value
, "none")) {
907 /* discard is default */
909 error_report("invalid option value '%s'", value
);
915 /***********************************************************/
916 /* Bluetooth support */
919 static struct HCIInfo
*hci_table
[MAX_NICS
];
921 struct HCIInfo
*qemu_next_hci(void)
923 if (cur_hci
== nb_hcis
)
926 return hci_table
[cur_hci
++];
929 static int bt_hci_parse(const char *str
)
934 if (nb_hcis
>= MAX_NICS
) {
935 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
948 bdaddr
.b
[5] = 0x56 + nb_hcis
;
949 hci
->bdaddr_set(hci
, bdaddr
.b
);
951 hci_table
[nb_hcis
++] = hci
;
956 static void bt_vhci_add(int vlan_id
)
958 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
961 error_report("warning: adding a VHCI to an empty scatternet %i",
964 bt_vhci_init(bt_new_hci(vlan
));
967 static struct bt_device_s
*bt_device_add(const char *opt
)
969 struct bt_scatternet_s
*vlan
;
971 char *endp
= strstr(opt
, ",vlan=");
972 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
975 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
978 vlan_id
= strtol(endp
+ 6, &endp
, 0);
980 error_report("unrecognised bluetooth vlan Id");
985 vlan
= qemu_find_bt_vlan(vlan_id
);
988 error_report("warning: adding a slave device to an empty scatternet %i",
991 if (!strcmp(devname
, "keyboard"))
992 return bt_keyboard_init(vlan
);
994 error_report("unsupported bluetooth device '%s'", devname
);
998 static int bt_parse(const char *opt
)
1000 const char *endp
, *p
;
1003 if (strstart(opt
, "hci", &endp
)) {
1004 if (!*endp
|| *endp
== ',') {
1006 if (!strstart(endp
, ",vlan=", 0))
1009 return bt_hci_parse(opt
);
1011 } else if (strstart(opt
, "vhci", &endp
)) {
1012 if (!*endp
|| *endp
== ',') {
1014 if (strstart(endp
, ",vlan=", &p
)) {
1015 vlan
= strtol(p
, (char **) &endp
, 0);
1017 error_report("bad scatternet '%s'", p
);
1021 error_report("bad parameter '%s'", endp
+ 1);
1030 } else if (strstart(opt
, "device:", &endp
))
1031 return !bt_device_add(endp
);
1033 error_report("bad bluetooth parameter '%s'", opt
);
1037 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1039 /* FIXME: change this to true for 1.3 */
1040 if (qemu_opt_get_bool(opts
, "enable", false)) {
1041 #ifdef CONFIG_SECCOMP
1042 if (seccomp_start() < 0) {
1043 error_report("failed to install seccomp syscall filter "
1048 error_report("seccomp support is disabled");
1056 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1058 const char *proc_name
;
1060 if (qemu_opt_get(opts
, "debug-threads")) {
1061 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1063 qemu_name
= qemu_opt_get(opts
, "guest");
1065 proc_name
= qemu_opt_get(opts
, "process");
1067 os_set_proc_name(proc_name
);
1073 bool defaults_enabled(void)
1075 return has_defaults
;
1078 bool usb_enabled(void)
1080 return machine_usb(current_machine
);
1084 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1086 int fd
, dupfd
, flags
;
1088 const char *fd_opaque
= NULL
;
1091 fd
= qemu_opt_get_number(opts
, "fd", -1);
1092 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1093 fd_opaque
= qemu_opt_get(opts
, "opaque");
1096 error_report("fd option is required and must be non-negative");
1100 if (fd
<= STDERR_FILENO
) {
1101 error_report("fd cannot be a standard I/O stream");
1106 * All fds inherited across exec() necessarily have FD_CLOEXEC
1107 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1109 flags
= fcntl(fd
, F_GETFD
);
1110 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1111 error_report("fd is not valid or already in use");
1116 error_report("set option is required and must be non-negative");
1120 #ifdef F_DUPFD_CLOEXEC
1121 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1125 qemu_set_cloexec(dupfd
);
1129 error_report("error duplicating fd: %s", strerror(errno
));
1133 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1134 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1141 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1145 fd
= qemu_opt_get_number(opts
, "fd", -1);
1152 /***********************************************************/
1153 /* QEMU Block devices */
1155 #define HD_OPTS "media=disk"
1156 #define CDROM_OPTS "media=cdrom"
1158 #define PFLASH_OPTS ""
1162 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1164 BlockInterfaceType
*block_default_type
= opaque
;
1166 return drive_new(opts
, *block_default_type
) == NULL
;
1169 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1171 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1172 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1177 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1178 int index
, const char *optstr
)
1183 if (!enable
|| drive_get_by_index(type
, index
)) {
1187 opts
= drive_add(type
, index
, NULL
, optstr
);
1189 drive_enable_snapshot(NULL
, opts
, NULL
);
1192 dinfo
= drive_new(opts
, type
);
1196 dinfo
->is_default
= true;
1200 static QemuOptsList qemu_smp_opts
= {
1202 .implied_opt_name
= "cpus",
1203 .merge_lists
= true,
1204 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1208 .type
= QEMU_OPT_NUMBER
,
1211 .type
= QEMU_OPT_NUMBER
,
1214 .type
= QEMU_OPT_NUMBER
,
1217 .type
= QEMU_OPT_NUMBER
,
1220 .type
= QEMU_OPT_NUMBER
,
1222 { /*End of list */ }
1226 static void smp_parse(QemuOpts
*opts
)
1230 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1231 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1232 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1233 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1235 /* compute missing values, prefer sockets over cores over threads */
1236 if (cpus
== 0 || sockets
== 0) {
1237 sockets
= sockets
> 0 ? sockets
: 1;
1238 cores
= cores
> 0 ? cores
: 1;
1239 threads
= threads
> 0 ? threads
: 1;
1241 cpus
= cores
* threads
* sockets
;
1243 } else if (cores
== 0) {
1244 threads
= threads
> 0 ? threads
: 1;
1245 cores
= cpus
/ (sockets
* threads
);
1246 } else if (threads
== 0) {
1247 threads
= cpus
/ (cores
* sockets
);
1248 } else if (sockets
* cores
* threads
< cpus
) {
1249 error_report("cpu topology: "
1250 "sockets (%u) * cores (%u) * threads (%u) < "
1252 sockets
, cores
, threads
, cpus
);
1256 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1257 if (sockets
* cores
* threads
> max_cpus
) {
1258 error_report("cpu topology: "
1259 "sockets (%u) * cores (%u) * threads (%u) > "
1261 sockets
, cores
, threads
, max_cpus
);
1266 smp_cores
= cores
> 0 ? cores
: 1;
1267 smp_threads
= threads
> 0 ? threads
: 1;
1271 if (max_cpus
== 0) {
1272 max_cpus
= smp_cpus
;
1275 if (max_cpus
> MAX_CPUMASK_BITS
) {
1276 error_report("unsupported number of maxcpus");
1279 if (max_cpus
< smp_cpus
) {
1280 error_report("maxcpus must be equal to or greater than smp");
1284 if (smp_cpus
> 1 || smp_cores
> 1 || smp_threads
> 1) {
1285 Error
*blocker
= NULL
;
1286 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1287 replay_add_blocker(blocker
);
1291 static void realtime_init(void)
1294 if (os_mlock() < 0) {
1295 error_report("locking memory failed");
1302 static void configure_msg(QemuOpts
*opts
)
1304 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1307 /***********************************************************/
1310 typedef struct SemihostingConfig
{
1312 SemihostingTarget target
;
1315 const char *cmdline
; /* concatenated argv */
1316 } SemihostingConfig
;
1318 static SemihostingConfig semihosting
;
1320 bool semihosting_enabled(void)
1322 return semihosting
.enabled
;
1325 SemihostingTarget
semihosting_get_target(void)
1327 return semihosting
.target
;
1330 const char *semihosting_get_arg(int i
)
1332 if (i
>= semihosting
.argc
) {
1335 return semihosting
.argv
[i
];
1338 int semihosting_get_argc(void)
1340 return semihosting
.argc
;
1343 const char *semihosting_get_cmdline(void)
1345 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1346 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1348 return semihosting
.cmdline
;
1351 static int add_semihosting_arg(void *opaque
,
1352 const char *name
, const char *val
,
1355 SemihostingConfig
*s
= opaque
;
1356 if (strcmp(name
, "arg") == 0) {
1358 /* one extra element as g_strjoinv() expects NULL-terminated array */
1359 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1360 s
->argv
[s
->argc
- 1] = val
;
1361 s
->argv
[s
->argc
] = NULL
;
1366 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1367 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1372 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1374 /* split -append and initialize argv[1..n] */
1375 cmd_token
= strtok(g_strdup(cmd
), " ");
1377 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1378 cmd_token
= strtok(NULL
, " ");
1382 /* Now we still need this for compatibility with XEN. */
1383 bool has_igd_gfx_passthru
;
1384 static void igd_gfx_passthru(void)
1386 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1389 /***********************************************************/
1392 static int usb_device_add(const char *devname
)
1394 USBDevice
*dev
= NULL
;
1395 #ifndef CONFIG_LINUX
1399 if (!usb_enabled()) {
1403 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1404 dev
= usbdevice_create(devname
);
1408 /* the other ones */
1409 #ifndef CONFIG_LINUX
1410 /* only the linux version is qdev-ified, usb-bsd still needs this */
1411 if (strstart(devname
, "host:", &p
)) {
1412 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1422 static int usb_device_del(const char *devname
)
1427 if (strstart(devname
, "host:", &p
)) {
1431 if (!usb_enabled()) {
1435 p
= strchr(devname
, '.');
1438 bus_num
= strtoul(devname
, NULL
, 0);
1439 addr
= strtoul(p
+ 1, NULL
, 0);
1441 return usb_device_delete_addr(bus_num
, addr
);
1444 static int usb_parse(const char *cmdline
)
1447 r
= usb_device_add(cmdline
);
1449 error_report("could not add USB device '%s'", cmdline
);
1454 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1456 const char *devname
= qdict_get_str(qdict
, "devname");
1457 if (usb_device_add(devname
) < 0) {
1458 error_report("could not add USB device '%s'", devname
);
1462 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1464 const char *devname
= qdict_get_str(qdict
, "devname");
1465 if (usb_device_del(devname
) < 0) {
1466 error_report("could not delete USB device '%s'", devname
);
1470 /***********************************************************/
1471 /* machine registration */
1473 MachineState
*current_machine
;
1475 static MachineClass
*find_machine(const char *name
)
1477 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1478 MachineClass
*mc
= NULL
;
1480 for (el
= machines
; el
; el
= el
->next
) {
1481 MachineClass
*temp
= el
->data
;
1483 if (!strcmp(temp
->name
, name
)) {
1488 !strcmp(temp
->alias
, name
)) {
1494 g_slist_free(machines
);
1498 MachineClass
*find_default_machine(void)
1500 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1501 MachineClass
*mc
= NULL
;
1503 for (el
= machines
; el
; el
= el
->next
) {
1504 MachineClass
*temp
= el
->data
;
1506 if (temp
->is_default
) {
1512 g_slist_free(machines
);
1516 MachineInfoList
*qmp_query_machines(Error
**errp
)
1518 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1519 MachineInfoList
*mach_list
= NULL
;
1521 for (el
= machines
; el
; el
= el
->next
) {
1522 MachineClass
*mc
= el
->data
;
1523 MachineInfoList
*entry
;
1526 info
= g_malloc0(sizeof(*info
));
1527 if (mc
->is_default
) {
1528 info
->has_is_default
= true;
1529 info
->is_default
= true;
1533 info
->has_alias
= true;
1534 info
->alias
= g_strdup(mc
->alias
);
1537 info
->name
= g_strdup(mc
->name
);
1538 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1540 entry
= g_malloc0(sizeof(*entry
));
1541 entry
->value
= info
;
1542 entry
->next
= mach_list
;
1546 g_slist_free(machines
);
1550 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1552 ObjectProperty
*prop
;
1553 ObjectPropertyIterator iter
;
1555 if (!qemu_opt_has_help_opt(opts
)) {
1559 object_property_iter_init(&iter
, OBJECT(machine
));
1560 while ((prop
= object_property_iter_next(&iter
))) {
1565 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1566 prop
->name
, prop
->type
);
1567 if (prop
->description
) {
1568 error_printf(" (%s)\n", prop
->description
);
1577 /***********************************************************/
1578 /* main execution loop */
1580 struct vm_change_state_entry
{
1581 VMChangeStateHandler
*cb
;
1583 QLIST_ENTRY (vm_change_state_entry
) entries
;
1586 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1588 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1591 VMChangeStateEntry
*e
;
1593 e
= g_malloc0(sizeof (*e
));
1597 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1601 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1603 QLIST_REMOVE (e
, entries
);
1607 void vm_state_notify(int running
, RunState state
)
1609 VMChangeStateEntry
*e
, *next
;
1611 trace_vm_state_notify(running
, state
);
1613 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1614 e
->cb(e
->opaque
, running
, state
);
1618 /* reset/shutdown handler */
1620 typedef struct QEMUResetEntry
{
1621 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1622 QEMUResetHandler
*func
;
1626 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1627 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1628 static int reset_requested
;
1629 static int shutdown_requested
, shutdown_signal
= -1;
1630 static pid_t shutdown_pid
;
1631 static int powerdown_requested
;
1632 static int debug_requested
;
1633 static int suspend_requested
;
1634 static WakeupReason wakeup_reason
;
1635 static NotifierList powerdown_notifiers
=
1636 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1637 static NotifierList suspend_notifiers
=
1638 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1639 static NotifierList wakeup_notifiers
=
1640 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1641 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1643 int qemu_shutdown_requested_get(void)
1645 return shutdown_requested
;
1648 int qemu_reset_requested_get(void)
1650 return reset_requested
;
1653 static int qemu_shutdown_requested(void)
1655 return atomic_xchg(&shutdown_requested
, 0);
1658 static void qemu_kill_report(void)
1660 if (!qtest_driver() && shutdown_signal
!= -1) {
1661 if (shutdown_pid
== 0) {
1662 /* This happens for eg ^C at the terminal, so it's worth
1663 * avoiding printing an odd message in that case.
1665 error_report("terminating on signal %d", shutdown_signal
);
1667 error_report("terminating on signal %d from pid " FMT_pid
,
1668 shutdown_signal
, shutdown_pid
);
1670 shutdown_signal
= -1;
1674 static int qemu_reset_requested(void)
1676 int r
= reset_requested
;
1677 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1678 reset_requested
= 0;
1684 static int qemu_suspend_requested(void)
1686 int r
= suspend_requested
;
1687 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1688 suspend_requested
= 0;
1694 static WakeupReason
qemu_wakeup_requested(void)
1696 return wakeup_reason
;
1699 static int qemu_powerdown_requested(void)
1701 int r
= powerdown_requested
;
1702 powerdown_requested
= 0;
1706 static int qemu_debug_requested(void)
1708 int r
= debug_requested
;
1709 debug_requested
= 0;
1713 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1715 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1718 re
->opaque
= opaque
;
1719 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1722 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1726 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1727 if (re
->func
== func
&& re
->opaque
== opaque
) {
1728 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1735 void qemu_devices_reset(void)
1737 QEMUResetEntry
*re
, *nre
;
1739 /* reset all devices */
1740 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1741 re
->func(re
->opaque
);
1745 void qemu_system_reset(bool report
)
1749 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1751 cpu_synchronize_all_states();
1753 if (mc
&& mc
->reset
) {
1756 qemu_devices_reset();
1759 qapi_event_send_reset(&error_abort
);
1761 cpu_synchronize_all_post_reset();
1764 void qemu_system_guest_panicked(void)
1767 current_cpu
->crash_occurred
= true;
1769 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
, &error_abort
);
1770 vm_stop(RUN_STATE_GUEST_PANICKED
);
1773 void qemu_system_reset_request(void)
1776 shutdown_requested
= 1;
1778 reset_requested
= 1;
1781 qemu_notify_event();
1784 static void qemu_system_suspend(void)
1787 notifier_list_notify(&suspend_notifiers
, NULL
);
1788 runstate_set(RUN_STATE_SUSPENDED
);
1789 qapi_event_send_suspend(&error_abort
);
1792 void qemu_system_suspend_request(void)
1794 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1797 suspend_requested
= 1;
1799 qemu_notify_event();
1802 void qemu_register_suspend_notifier(Notifier
*notifier
)
1804 notifier_list_add(&suspend_notifiers
, notifier
);
1807 void qemu_system_wakeup_request(WakeupReason reason
)
1809 trace_system_wakeup_request(reason
);
1811 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1814 if (!(wakeup_reason_mask
& (1 << reason
))) {
1817 runstate_set(RUN_STATE_RUNNING
);
1818 wakeup_reason
= reason
;
1819 qemu_notify_event();
1822 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1825 wakeup_reason_mask
|= (1 << reason
);
1827 wakeup_reason_mask
&= ~(1 << reason
);
1831 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1833 notifier_list_add(&wakeup_notifiers
, notifier
);
1836 void qemu_system_killed(int signal
, pid_t pid
)
1838 shutdown_signal
= signal
;
1842 /* Cannot call qemu_system_shutdown_request directly because
1843 * we are in a signal handler.
1845 shutdown_requested
= 1;
1846 qemu_notify_event();
1849 void qemu_system_shutdown_request(void)
1851 trace_qemu_system_shutdown_request();
1852 replay_shutdown_request();
1853 shutdown_requested
= 1;
1854 qemu_notify_event();
1857 static void qemu_system_powerdown(void)
1859 qapi_event_send_powerdown(&error_abort
);
1860 notifier_list_notify(&powerdown_notifiers
, NULL
);
1863 void qemu_system_powerdown_request(void)
1865 trace_qemu_system_powerdown_request();
1866 powerdown_requested
= 1;
1867 qemu_notify_event();
1870 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1872 notifier_list_add(&powerdown_notifiers
, notifier
);
1875 void qemu_system_debug_request(void)
1877 debug_requested
= 1;
1878 qemu_notify_event();
1881 static bool main_loop_should_exit(void)
1884 if (qemu_debug_requested()) {
1885 vm_stop(RUN_STATE_DEBUG
);
1887 if (qemu_suspend_requested()) {
1888 qemu_system_suspend();
1890 if (qemu_shutdown_requested()) {
1892 qapi_event_send_shutdown(&error_abort
);
1894 vm_stop(RUN_STATE_SHUTDOWN
);
1899 if (qemu_reset_requested()) {
1901 qemu_system_reset(VMRESET_REPORT
);
1903 if (!runstate_check(RUN_STATE_RUNNING
) &&
1904 !runstate_check(RUN_STATE_INMIGRATE
)) {
1905 runstate_set(RUN_STATE_PRELAUNCH
);
1908 if (qemu_wakeup_requested()) {
1910 qemu_system_reset(VMRESET_SILENT
);
1911 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1912 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1914 qapi_event_send_wakeup(&error_abort
);
1916 if (qemu_powerdown_requested()) {
1917 qemu_system_powerdown();
1919 if (qemu_vmstop_requested(&r
)) {
1925 static void main_loop(void)
1929 #ifdef CONFIG_PROFILER
1933 nonblocking
= !kvm_enabled() && !xen_enabled() && last_io
> 0;
1934 #ifdef CONFIG_PROFILER
1935 ti
= profile_getclock();
1937 last_io
= main_loop_wait(nonblocking
);
1938 #ifdef CONFIG_PROFILER
1939 dev_time
+= profile_getclock() - ti
;
1941 } while (!main_loop_should_exit());
1944 static void version(void)
1946 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1949 static void QEMU_NORETURN
help(int exitcode
)
1952 printf("usage: %s [options] [disk_image]\n\n"
1953 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1954 error_get_progname());
1956 #define QEMU_OPTIONS_GENERATE_HELP
1957 #include "qemu-options-wrapper.h"
1959 printf("\nDuring emulation, the following keys are useful:\n"
1960 "ctrl-alt-f toggle full screen\n"
1961 "ctrl-alt-n switch to virtual console 'n'\n"
1962 "ctrl-alt toggle mouse and keyboard grab\n"
1964 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1969 #define HAS_ARG 0x0001
1971 typedef struct QEMUOption
{
1978 static const QEMUOption qemu_options
[] = {
1979 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1980 #define QEMU_OPTIONS_GENERATE_OPTIONS
1981 #include "qemu-options-wrapper.h"
1985 static bool vga_available(void)
1987 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
1990 static bool cirrus_vga_available(void)
1992 return object_class_by_name("cirrus-vga")
1993 || object_class_by_name("isa-cirrus-vga");
1996 static bool vmware_vga_available(void)
1998 return object_class_by_name("vmware-svga");
2001 static bool qxl_vga_available(void)
2003 return object_class_by_name("qxl-vga");
2006 static bool tcx_vga_available(void)
2008 return object_class_by_name("SUNW,tcx");
2011 static bool cg3_vga_available(void)
2013 return object_class_by_name("cgthree");
2016 static bool virtio_vga_available(void)
2018 return object_class_by_name("virtio-vga");
2021 static void select_vgahw (const char *p
)
2025 assert(vga_interface_type
== VGA_NONE
);
2026 if (strstart(p
, "std", &opts
)) {
2027 if (vga_available()) {
2028 vga_interface_type
= VGA_STD
;
2030 error_report("standard VGA not available");
2033 } else if (strstart(p
, "cirrus", &opts
)) {
2034 if (cirrus_vga_available()) {
2035 vga_interface_type
= VGA_CIRRUS
;
2037 error_report("Cirrus VGA not available");
2040 } else if (strstart(p
, "vmware", &opts
)) {
2041 if (vmware_vga_available()) {
2042 vga_interface_type
= VGA_VMWARE
;
2044 error_report("VMWare SVGA not available");
2047 } else if (strstart(p
, "virtio", &opts
)) {
2048 if (virtio_vga_available()) {
2049 vga_interface_type
= VGA_VIRTIO
;
2051 error_report("Virtio VGA not available");
2054 } else if (strstart(p
, "xenfb", &opts
)) {
2055 vga_interface_type
= VGA_XENFB
;
2056 } else if (strstart(p
, "qxl", &opts
)) {
2057 if (qxl_vga_available()) {
2058 vga_interface_type
= VGA_QXL
;
2060 error_report("QXL VGA not available");
2063 } else if (strstart(p
, "tcx", &opts
)) {
2064 if (tcx_vga_available()) {
2065 vga_interface_type
= VGA_TCX
;
2067 error_report("TCX framebuffer not available");
2070 } else if (strstart(p
, "cg3", &opts
)) {
2071 if (cg3_vga_available()) {
2072 vga_interface_type
= VGA_CG3
;
2074 error_report("CG3 framebuffer not available");
2077 } else if (!strstart(p
, "none", &opts
)) {
2079 error_report("unknown vga type: %s", p
);
2083 const char *nextopt
;
2085 if (strstart(opts
, ",retrace=", &nextopt
)) {
2087 if (strstart(opts
, "dumb", &nextopt
))
2088 vga_retrace_method
= VGA_RETRACE_DUMB
;
2089 else if (strstart(opts
, "precise", &nextopt
))
2090 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2091 else goto invalid_vga
;
2092 } else goto invalid_vga
;
2097 static DisplayType
select_display(const char *p
)
2100 DisplayType display
= DT_DEFAULT
;
2102 if (strstart(p
, "sdl", &opts
)) {
2106 const char *nextopt
;
2108 if (strstart(opts
, ",frame=", &nextopt
)) {
2110 if (strstart(opts
, "on", &nextopt
)) {
2112 } else if (strstart(opts
, "off", &nextopt
)) {
2115 goto invalid_sdl_args
;
2117 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2119 if (strstart(opts
, "on", &nextopt
)) {
2121 } else if (strstart(opts
, "off", &nextopt
)) {
2124 goto invalid_sdl_args
;
2126 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2128 if (strstart(opts
, "on", &nextopt
)) {
2130 } else if (strstart(opts
, "off", &nextopt
)) {
2133 goto invalid_sdl_args
;
2135 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2137 if (strstart(opts
, "on", &nextopt
)) {
2139 } else if (strstart(opts
, "off", &nextopt
)) {
2142 goto invalid_sdl_args
;
2144 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2146 if (strstart(opts
, "on", &nextopt
)) {
2148 } else if (strstart(opts
, "off", &nextopt
)) {
2151 goto invalid_sdl_args
;
2155 error_report("invalid SDL option string");
2161 error_report("SDL support is disabled");
2164 } else if (strstart(p
, "vnc", &opts
)) {
2168 if (vnc_parse(opts
+ 1, &err
) == NULL
) {
2169 error_report_err(err
);
2173 error_report("VNC requires a display argument vnc=<display>");
2177 error_report("VNC support is disabled");
2180 } else if (strstart(p
, "curses", &opts
)) {
2181 #ifdef CONFIG_CURSES
2182 display
= DT_CURSES
;
2184 error_report("curses support is disabled");
2187 } else if (strstart(p
, "gtk", &opts
)) {
2191 const char *nextopt
;
2193 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2195 if (strstart(opts
, "on", &nextopt
)) {
2196 grab_on_hover
= true;
2197 } else if (strstart(opts
, "off", &nextopt
)) {
2198 grab_on_hover
= false;
2200 goto invalid_gtk_args
;
2202 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2204 if (strstart(opts
, "on", &nextopt
)) {
2206 } else if (strstart(opts
, "off", &nextopt
)) {
2209 goto invalid_gtk_args
;
2213 error_report("invalid GTK option string");
2219 error_report("GTK support is disabled");
2222 } else if (strstart(p
, "none", &opts
)) {
2225 error_report("unknown display type");
2232 static int balloon_parse(const char *arg
)
2236 if (strcmp(arg
, "none") == 0) {
2240 if (!strncmp(arg
, "virtio", 6)) {
2241 if (arg
[6] == ',') {
2242 /* have params -> parse them */
2243 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2248 /* create empty opts */
2249 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2252 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2259 #if defined(CONFIG_RUBY)
2260 /* Ruby interface for QEMU. See README.EXT for programming example. */
2264 static VALUE
qemu_open(int argc
, VALUE
*argv
, VALUE klass
)
2267 for (i
= 0; i
< argc
; i
++) {
2268 argv
[i
] = StringValue(argv
[i
]);
2269 fprintf(stderr
, "argv[%d] = %s\n", i
, StringValuePtr(argv
[i
]));
2271 //~ if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
2272 //~ mode = 0666; /* default value */
2274 return INT2FIX(argc
);
2277 void Init_qemu(void)
2279 printf("%s\n", __func__
);
2280 VALUE cQEMU
= rb_define_class("QEMU", rb_cObject
);
2281 rb_define_singleton_method(cQEMU
, "run", qemu_open
, -1);
2286 #endif /* CONFIG_RUBY */
2288 #if defined(CONFIG_DLL)
2289 BOOL APIENTRY
DllMain(HINSTANCE hModule
, DWORD ul_reason_for_call
, LPVOID data
)
2293 #endif /* CONFIG_DLL */
2295 char *qemu_find_file(int type
, const char *name
)
2301 /* Try the name as a straight path first */
2302 if (access(name
, R_OK
) == 0) {
2303 trace_load_file(name
, name
);
2304 return g_strdup(name
);
2308 case QEMU_FILE_TYPE_BIOS
:
2311 case QEMU_FILE_TYPE_KEYMAP
:
2312 subdir
= "keymaps/";
2318 for (i
= 0; i
< data_dir_idx
; i
++) {
2319 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2320 if (access(buf
, R_OK
) == 0) {
2321 trace_load_file(name
, buf
);
2329 static inline bool nonempty_str(const char *str
)
2334 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2338 const char *name
, *file
, *str
;
2339 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2341 if (fw_cfg
== NULL
) {
2342 error_report("fw_cfg device not available");
2345 name
= qemu_opt_get(opts
, "name");
2346 file
= qemu_opt_get(opts
, "file");
2347 str
= qemu_opt_get(opts
, "string");
2349 /* we need name and either a file or the content string */
2350 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2351 error_report("invalid argument(s)");
2354 if (nonempty_str(file
) && nonempty_str(str
)) {
2355 error_report("file and string are mutually exclusive");
2358 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2359 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2362 if (strncmp(name
, "opt/", 4) != 0) {
2363 error_report("warning: externally provided fw_cfg item names "
2364 "should be prefixed with \"opt/\"");
2366 if (nonempty_str(str
)) {
2367 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2368 buf
= g_memdup(str
, size
);
2370 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2371 error_report("can't load %s", file
);
2375 /* For legacy, keep user files in a specific global order. */
2376 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2377 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2378 fw_cfg_reset_order_override(fw_cfg
);
2382 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2384 return qdev_device_help(opts
);
2387 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2392 dev
= qdev_device_add(opts
, &err
);
2394 error_report_err(err
);
2397 object_unref(OBJECT(dev
));
2401 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2403 Error
*local_err
= NULL
;
2405 qemu_chr_new_from_opts(opts
, NULL
, &local_err
);
2407 error_report_err(local_err
);
2413 #ifdef CONFIG_VIRTFS
2414 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2417 ret
= qemu_fsdev_add(opts
);
2423 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2425 CharDriverState
*chr
;
2426 const char *chardev
;
2430 mode
= qemu_opt_get(opts
, "mode");
2434 if (strcmp(mode
, "readline") == 0) {
2435 flags
= MONITOR_USE_READLINE
;
2436 } else if (strcmp(mode
, "control") == 0) {
2437 flags
= MONITOR_USE_CONTROL
;
2439 error_report("unknown monitor mode \"%s\"", mode
);
2443 if (qemu_opt_get_bool(opts
, "pretty", 0))
2444 flags
|= MONITOR_USE_PRETTY
;
2446 if (qemu_opt_get_bool(opts
, "default", 0))
2447 flags
|= MONITOR_IS_DEFAULT
;
2449 chardev
= qemu_opt_get(opts
, "chardev");
2450 chr
= qemu_chr_find(chardev
);
2452 error_report("chardev \"%s\" not found", chardev
);
2456 qemu_chr_fe_claim_no_fail(chr
);
2457 monitor_init(chr
, flags
);
2461 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2463 static int monitor_device_index
= 0;
2464 Error
*local_err
= NULL
;
2470 if (strstart(optarg
, "chardev:", &p
)) {
2471 snprintf(label
, sizeof(label
), "%s", p
);
2473 snprintf(label
, sizeof(label
), "compat_monitor%d",
2474 monitor_device_index
);
2475 if (monitor_device_index
== 0) {
2478 opts
= qemu_chr_parse_compat(label
, optarg
);
2480 error_report("parse error: %s", optarg
);
2485 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &local_err
);
2487 error_report_err(local_err
);
2490 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2491 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2492 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2494 qemu_opt_set(opts
, "default", "on", &error_abort
);
2495 monitor_device_index
++;
2498 struct device_config
{
2500 DEV_USB
, /* -usbdevice */
2502 DEV_SERIAL
, /* -serial */
2503 DEV_PARALLEL
, /* -parallel */
2504 DEV_VIRTCON
, /* -virtioconsole */
2505 DEV_DEBUGCON
, /* -debugcon */
2506 DEV_GDB
, /* -gdb, -s */
2507 DEV_SCLP
, /* s390 sclp */
2509 const char *cmdline
;
2511 QTAILQ_ENTRY(device_config
) next
;
2514 static QTAILQ_HEAD(, device_config
) device_configs
=
2515 QTAILQ_HEAD_INITIALIZER(device_configs
);
2517 static void add_device_config(int type
, const char *cmdline
)
2519 struct device_config
*conf
;
2521 conf
= g_malloc0(sizeof(*conf
));
2523 conf
->cmdline
= cmdline
;
2524 loc_save(&conf
->loc
);
2525 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2528 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2530 struct device_config
*conf
;
2533 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2534 if (conf
->type
!= type
)
2536 loc_push_restore(&conf
->loc
);
2537 rc
= func(conf
->cmdline
);
2538 loc_pop(&conf
->loc
);
2546 static int serial_parse(const char *devname
)
2548 static int index
= 0;
2551 if (strcmp(devname
, "none") == 0)
2553 if (index
== MAX_SERIAL_PORTS
) {
2554 error_report("too many serial ports");
2557 snprintf(label
, sizeof(label
), "serial%d", index
);
2558 serial_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2559 if (!serial_hds
[index
]) {
2560 error_report("could not connect serial device"
2561 " to character backend '%s'", devname
);
2568 static int parallel_parse(const char *devname
)
2570 static int index
= 0;
2573 if (strcmp(devname
, "none") == 0)
2575 if (index
== MAX_PARALLEL_PORTS
) {
2576 error_report("too many parallel ports");
2579 snprintf(label
, sizeof(label
), "parallel%d", index
);
2580 parallel_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2581 if (!parallel_hds
[index
]) {
2582 error_report("could not connect parallel device"
2583 " to character backend '%s'", devname
);
2590 static int virtcon_parse(const char *devname
)
2592 QemuOptsList
*device
= qemu_find_opts("device");
2593 static int index
= 0;
2595 QemuOpts
*bus_opts
, *dev_opts
;
2597 if (strcmp(devname
, "none") == 0)
2599 if (index
== MAX_VIRTIO_CONSOLES
) {
2600 error_report("too many virtio consoles");
2604 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2605 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2607 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2608 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2610 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2611 virtcon_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2612 if (!virtcon_hds
[index
]) {
2613 error_report("could not connect virtio console"
2614 " to character backend '%s'", devname
);
2617 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2623 static int sclp_parse(const char *devname
)
2625 QemuOptsList
*device
= qemu_find_opts("device");
2626 static int index
= 0;
2630 if (strcmp(devname
, "none") == 0) {
2633 if (index
== MAX_SCLP_CONSOLES
) {
2634 error_report("too many sclp consoles");
2638 assert(arch_type
== QEMU_ARCH_S390X
);
2640 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2641 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2643 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2644 sclp_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2645 if (!sclp_hds
[index
]) {
2646 error_report("could not connect sclp console"
2647 " to character backend '%s'", devname
);
2650 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2656 static int debugcon_parse(const char *devname
)
2660 if (!qemu_chr_new("debugcon", devname
, NULL
)) {
2663 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2665 error_report("already have a debugcon device");
2668 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2669 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2673 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2675 const MachineClass
*mc1
= a
, *mc2
= b
;
2678 if (mc1
->family
== NULL
) {
2679 if (mc2
->family
== NULL
) {
2680 /* Compare standalone machine types against each other; they sort
2681 * in increasing order.
2683 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2684 object_class_get_name(OBJECT_CLASS(mc2
)));
2687 /* Standalone machine types sort after families. */
2691 if (mc2
->family
== NULL
) {
2692 /* Families sort before standalone machine types. */
2696 /* Families sort between each other alphabetically increasingly. */
2697 res
= strcmp(mc1
->family
, mc2
->family
);
2702 /* Within the same family, machine types sort in decreasing order. */
2703 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2704 object_class_get_name(OBJECT_CLASS(mc1
)));
2707 static MachineClass
*machine_parse(const char *name
)
2709 MachineClass
*mc
= NULL
;
2710 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2713 mc
= find_machine(name
);
2716 g_slist_free(machines
);
2719 if (name
&& !is_help_option(name
)) {
2720 error_report("unsupported machine type");
2721 error_printf("Use -machine help to list supported machines\n");
2723 printf("Supported machines are:\n");
2724 machines
= g_slist_sort(machines
, machine_class_cmp
);
2725 for (el
= machines
; el
; el
= el
->next
) {
2726 MachineClass
*mc
= el
->data
;
2728 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2730 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2731 mc
->is_default
? " (default)" : "");
2735 g_slist_free(machines
);
2736 exit(!name
|| !is_help_option(name
));
2739 void qemu_add_exit_notifier(Notifier
*notify
)
2741 notifier_list_add(&exit_notifiers
, notify
);
2744 void qemu_remove_exit_notifier(Notifier
*notify
)
2746 notifier_remove(notify
);
2749 static void qemu_run_exit_notifiers(void)
2751 notifier_list_notify(&exit_notifiers
, NULL
);
2754 static bool machine_init_done
;
2756 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2758 notifier_list_add(&machine_init_done_notifiers
, notify
);
2759 if (machine_init_done
) {
2760 notify
->notify(notify
, NULL
);
2764 static void qemu_run_machine_init_done_notifiers(void)
2766 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2767 machine_init_done
= true;
2770 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2771 const char **poptarg
, int *poptind
)
2773 const QEMUOption
*popt
;
2774 int optind
= *poptind
;
2775 char *r
= argv
[optind
];
2778 loc_set_cmdline(argv
, optind
, 1);
2780 /* Treat --foo the same as -foo. */
2783 popt
= qemu_options
;
2786 error_report("invalid option");
2789 if (!strcmp(popt
->name
, r
+ 1))
2793 if (popt
->flags
& HAS_ARG
) {
2794 if (optind
>= argc
) {
2795 error_report("requires an argument");
2798 optarg
= argv
[optind
++];
2799 loc_set_cmdline(argv
, optind
- 2, 2);
2810 static MachineClass
*select_machine(void)
2812 MachineClass
*machine_class
= find_default_machine();
2817 loc_push_none(&loc
);
2819 opts
= qemu_get_machine_opts();
2820 qemu_opts_loc_restore(opts
);
2822 optarg
= qemu_opt_get(opts
, "type");
2824 machine_class
= machine_parse(optarg
);
2827 if (!machine_class
) {
2828 error_report("No machine specified, and there is no default");
2829 error_printf("Use -machine help to list supported machines\n");
2834 return machine_class
;
2837 static int machine_set_property(void *opaque
,
2838 const char *name
, const char *value
,
2841 Object
*obj
= OBJECT(opaque
);
2842 Error
*local_err
= NULL
;
2845 if (strcmp(name
, "type") == 0) {
2849 qom_name
= g_strdup(name
);
2857 object_property_parse(obj
, value
, qom_name
, &local_err
);
2861 error_report_err(local_err
);
2870 * Initial object creation happens before all other
2871 * QEMU data types are created. The majority of objects
2872 * can be created at this point. The rng-egd object
2873 * cannot be created here, as it depends on the chardev
2876 static bool object_create_initial(const char *type
)
2878 if (g_str_equal(type
, "rng-egd")) {
2883 * return false for concrete netfilters since
2884 * they depend on netdevs already existing
2886 if (g_str_equal(type
, "filter-buffer") ||
2887 g_str_equal(type
, "filter-dump") ||
2888 g_str_equal(type
, "filter-mirror") ||
2889 g_str_equal(type
, "filter-redirector")) {
2898 * The remainder of object creation happens after the
2899 * creation of chardev, fsdev, net clients and device data types.
2901 static bool object_create_delayed(const char *type
)
2903 return !object_create_initial(type
);
2907 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2911 const char *mem_str
;
2912 const char *maxmem_str
, *slots_str
;
2913 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2914 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2917 loc_push_none(&loc
);
2918 qemu_opts_loc_restore(opts
);
2921 mem_str
= qemu_opt_get(opts
, "size");
2924 error_report("missing 'size' option value");
2928 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2930 /* Fix up legacy suffix-less format */
2931 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2932 uint64_t overflow_check
= sz
;
2935 if ((sz
>> 20) != overflow_check
) {
2936 error_report("too large 'size' option value");
2942 /* backward compatibility behaviour for case "-m 0" */
2944 sz
= default_ram_size
;
2947 sz
= QEMU_ALIGN_UP(sz
, 8192);
2949 if (ram_size
!= sz
) {
2950 error_report("ram size too large");
2954 /* store value for the future use */
2955 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2956 *maxram_size
= ram_size
;
2958 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2959 slots_str
= qemu_opt_get(opts
, "slots");
2960 if (maxmem_str
&& slots_str
) {
2963 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2964 slots
= qemu_opt_get_number(opts
, "slots", 0);
2965 if (sz
< ram_size
) {
2966 error_report("invalid value of -m option maxmem: "
2967 "maximum memory size (0x%" PRIx64
") must be at least "
2968 "the initial memory size (0x" RAM_ADDR_FMT
")",
2971 } else if (sz
> ram_size
) {
2973 error_report("invalid value of -m option: maxmem was "
2974 "specified, but no hotplug slots were specified");
2978 error_report("invalid value of -m option maxmem: "
2979 "memory slots were specified but maximum memory size "
2980 "(0x%" PRIx64
") is equal to the initial memory size "
2981 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2987 } else if ((!maxmem_str
&& slots_str
) ||
2988 (maxmem_str
&& !slots_str
)) {
2989 error_report("invalid -m option value: missing "
2990 "'%s' option", slots_str
? "maxmem" : "slots");
2997 int main(int argc
, char **argv
)
3000 int snapshot
, linux_boot
;
3001 const char *initrd_filename
;
3002 const char *kernel_filename
, *kernel_cmdline
;
3003 const char *boot_order
= NULL
;
3004 const char *boot_once
= NULL
;
3006 int cyls
, heads
, secs
, translation
;
3007 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
3008 QemuOptsList
*olist
;
3011 const char *loadvm
= NULL
;
3012 MachineClass
*machine_class
;
3013 const char *cpu_model
;
3014 const char *vga_model
= NULL
;
3015 const char *qtest_chrdev
= NULL
;
3016 const char *qtest_log
= NULL
;
3017 const char *pid_file
= NULL
;
3018 const char *incoming
= NULL
;
3020 int show_vnc_port
= 0;
3022 bool defconfig
= true;
3023 bool userconfig
= true;
3024 const char *log_mask
= NULL
;
3025 const char *log_file
= NULL
;
3026 char *trace_file
= NULL
;
3027 ram_addr_t maxram_size
;
3028 uint64_t ram_slots
= 0;
3029 FILE *vmstate_dump_file
= NULL
;
3030 Error
*main_loop_err
= NULL
;
3033 qemu_init_cpu_loop();
3034 qemu_mutex_lock_iothread();
3036 atexit(qemu_run_exit_notifiers
);
3037 error_set_progname(argv
[0]);
3038 qemu_init_exec_dir(argv
[0]);
3040 module_call_init(MODULE_INIT_QOM
);
3042 qemu_add_opts(&qemu_drive_opts
);
3043 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3044 qemu_add_drive_opts(&qemu_common_drive_opts
);
3045 qemu_add_drive_opts(&qemu_drive_opts
);
3046 qemu_add_opts(&qemu_chardev_opts
);
3047 qemu_add_opts(&qemu_device_opts
);
3048 qemu_add_opts(&qemu_netdev_opts
);
3049 qemu_add_opts(&qemu_net_opts
);
3050 qemu_add_opts(&qemu_rtc_opts
);
3051 qemu_add_opts(&qemu_global_opts
);
3052 qemu_add_opts(&qemu_mon_opts
);
3053 qemu_add_opts(&qemu_trace_opts
);
3054 qemu_add_opts(&qemu_option_rom_opts
);
3055 qemu_add_opts(&qemu_machine_opts
);
3056 qemu_add_opts(&qemu_mem_opts
);
3057 qemu_add_opts(&qemu_smp_opts
);
3058 qemu_add_opts(&qemu_boot_opts
);
3059 qemu_add_opts(&qemu_sandbox_opts
);
3060 qemu_add_opts(&qemu_add_fd_opts
);
3061 qemu_add_opts(&qemu_object_opts
);
3062 qemu_add_opts(&qemu_tpmdev_opts
);
3063 qemu_add_opts(&qemu_realtime_opts
);
3064 qemu_add_opts(&qemu_msg_opts
);
3065 qemu_add_opts(&qemu_name_opts
);
3066 qemu_add_opts(&qemu_numa_opts
);
3067 qemu_add_opts(&qemu_icount_opts
);
3068 qemu_add_opts(&qemu_semihosting_config_opts
);
3069 qemu_add_opts(&qemu_fw_cfg_opts
);
3070 module_call_init(MODULE_INIT_OPTS
);
3074 if (qcrypto_init(&err
) < 0) {
3075 error_reportf_err(err
, "cannot initialize crypto: ");
3078 rtc_clock
= QEMU_CLOCK_HOST
;
3080 QLIST_INIT (&vm_change_state_head
);
3081 os_setup_early_signal_handling();
3085 cyls
= heads
= secs
= 0;
3086 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3090 bdrv_init_with_whitelist();
3094 /* first pass of option parsing */
3096 while (optind
< argc
) {
3097 if (argv
[optind
][0] != '-') {
3101 const QEMUOption
*popt
;
3103 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3104 switch (popt
->index
) {
3105 case QEMU_OPTION_nodefconfig
:
3108 case QEMU_OPTION_nouserconfig
:
3117 ret
= qemu_read_default_config_files(userconfig
);
3123 /* second pass of option parsing */
3128 if (argv
[optind
][0] != '-') {
3129 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3131 const QEMUOption
*popt
;
3133 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3134 if (!(popt
->arch_mask
& arch_type
)) {
3135 printf("Option %s not supported for this target\n", popt
->name
);
3138 switch(popt
->index
) {
3139 case QEMU_OPTION_no_kvm_irqchip
: {
3140 olist
= qemu_find_opts("machine");
3141 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3144 case QEMU_OPTION_cpu
:
3145 /* hw initialization will check this */
3148 case QEMU_OPTION_hda
:
3152 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3154 snprintf(buf
, sizeof(buf
),
3155 "%s,cyls=%d,heads=%d,secs=%d%s",
3156 HD_OPTS
, cyls
, heads
, secs
,
3157 translation
== BIOS_ATA_TRANSLATION_LBA
?
3159 translation
== BIOS_ATA_TRANSLATION_NONE
?
3160 ",trans=none" : "");
3161 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3164 case QEMU_OPTION_hdb
:
3165 case QEMU_OPTION_hdc
:
3166 case QEMU_OPTION_hdd
:
3167 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3170 case QEMU_OPTION_drive
:
3171 if (drive_def(optarg
) == NULL
) {
3175 case QEMU_OPTION_set
:
3176 if (qemu_set_option(optarg
) != 0)
3179 case QEMU_OPTION_global
:
3180 if (qemu_global_option(optarg
) != 0)
3183 case QEMU_OPTION_mtdblock
:
3184 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3186 case QEMU_OPTION_sd
:
3187 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3189 case QEMU_OPTION_pflash
:
3190 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3192 case QEMU_OPTION_snapshot
:
3195 case QEMU_OPTION_hdachs
:
3199 cyls
= strtol(p
, (char **)&p
, 0);
3200 if (cyls
< 1 || cyls
> 16383)
3205 heads
= strtol(p
, (char **)&p
, 0);
3206 if (heads
< 1 || heads
> 16)
3211 secs
= strtol(p
, (char **)&p
, 0);
3212 if (secs
< 1 || secs
> 63)
3216 if (!strcmp(p
, "large")) {
3217 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3218 } else if (!strcmp(p
, "rechs")) {
3219 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3220 } else if (!strcmp(p
, "none")) {
3221 translation
= BIOS_ATA_TRANSLATION_NONE
;
3222 } else if (!strcmp(p
, "lba")) {
3223 translation
= BIOS_ATA_TRANSLATION_LBA
;
3224 } else if (!strcmp(p
, "auto")) {
3225 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3229 } else if (*p
!= '\0') {
3231 error_report("invalid physical CHS format");
3234 if (hda_opts
!= NULL
) {
3235 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3237 qemu_opt_set_number(hda_opts
, "heads", heads
,
3239 qemu_opt_set_number(hda_opts
, "secs", secs
,
3241 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3242 qemu_opt_set(hda_opts
, "trans", "large",
3244 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3245 qemu_opt_set(hda_opts
, "trans", "rechs",
3247 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3248 qemu_opt_set(hda_opts
, "trans", "lba",
3250 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3251 qemu_opt_set(hda_opts
, "trans", "none",
3257 case QEMU_OPTION_numa
:
3258 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3264 case QEMU_OPTION_display
:
3265 display_type
= select_display(optarg
);
3267 case QEMU_OPTION_nographic
:
3268 display_type
= DT_NOGRAPHIC
;
3270 case QEMU_OPTION_curses
:
3271 #ifdef CONFIG_CURSES
3272 display_type
= DT_CURSES
;
3274 error_report("curses support is disabled");
3278 case QEMU_OPTION_portrait
:
3279 graphic_rotate
= 90;
3281 case QEMU_OPTION_rotate
:
3282 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3283 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3284 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3285 error_report("only 90, 180, 270 deg rotation is available");
3289 case QEMU_OPTION_kernel
:
3290 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3293 case QEMU_OPTION_initrd
:
3294 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3297 case QEMU_OPTION_append
:
3298 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3301 case QEMU_OPTION_dtb
:
3302 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3305 case QEMU_OPTION_cdrom
:
3306 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3308 case QEMU_OPTION_boot
:
3309 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3315 case QEMU_OPTION_fda
:
3316 case QEMU_OPTION_fdb
:
3317 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3320 case QEMU_OPTION_no_fd_bootchk
:
3323 case QEMU_OPTION_netdev
:
3324 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3328 case QEMU_OPTION_net
:
3329 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3333 #ifdef CONFIG_LIBISCSI
3334 case QEMU_OPTION_iscsi
:
3335 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3343 case QEMU_OPTION_tftp
:
3344 error_report("The -tftp option is deprecated. "
3345 "Please use '-netdev user,tftp=...' instead.");
3346 legacy_tftp_prefix
= optarg
;
3348 case QEMU_OPTION_bootp
:
3349 error_report("The -bootp option is deprecated. "
3350 "Please use '-netdev user,bootfile=...' instead.");
3351 legacy_bootp_filename
= optarg
;
3353 case QEMU_OPTION_redir
:
3354 error_report("The -redir option is deprecated. "
3355 "Please use '-netdev user,hostfwd=...' instead.");
3356 if (net_slirp_redir(optarg
) < 0)
3360 case QEMU_OPTION_bt
:
3361 add_device_config(DEV_BT
, optarg
);
3363 case QEMU_OPTION_audio_help
:
3367 case QEMU_OPTION_soundhw
:
3368 select_soundhw (optarg
);
3373 case QEMU_OPTION_version
:
3378 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3385 case QEMU_OPTION_tpmdev
:
3386 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3391 case QEMU_OPTION_mempath
:
3394 case QEMU_OPTION_mem_prealloc
:
3403 case QEMU_OPTION_DFILTER
:
3404 qemu_set_dfilter_ranges(optarg
);
3407 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3409 case QEMU_OPTION_gdb
:
3410 add_device_config(DEV_GDB
, optarg
);
3413 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3414 data_dir
[data_dir_idx
++] = optarg
;
3417 case QEMU_OPTION_bios
:
3418 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3421 case QEMU_OPTION_singlestep
:
3428 keyboard_layout
= optarg
;
3430 case QEMU_OPTION_localtime
:
3433 case QEMU_OPTION_vga
:
3442 w
= strtol(p
, (char **)&p
, 10);
3445 error_report("invalid resolution or depth");
3451 h
= strtol(p
, (char **)&p
, 10);
3456 depth
= strtol(p
, (char **)&p
, 10);
3457 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3458 depth
!= 24 && depth
!= 32)
3460 } else if (*p
== '\0') {
3461 depth
= graphic_depth
;
3468 graphic_depth
= depth
;
3471 case QEMU_OPTION_echr
:
3474 term_escape_char
= strtol(optarg
, &r
, 0);
3476 printf("Bad argument to echr\n");
3479 case QEMU_OPTION_monitor
:
3480 default_monitor
= 0;
3481 if (strncmp(optarg
, "none", 4)) {
3482 monitor_parse(optarg
, "readline", false);
3485 case QEMU_OPTION_qmp
:
3486 monitor_parse(optarg
, "control", false);
3487 default_monitor
= 0;
3489 case QEMU_OPTION_qmp_pretty
:
3490 monitor_parse(optarg
, "control", true);
3491 default_monitor
= 0;
3493 case QEMU_OPTION_mon
:
3494 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3499 default_monitor
= 0;
3501 case QEMU_OPTION_chardev
:
3502 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3508 case QEMU_OPTION_fsdev
:
3509 olist
= qemu_find_opts("fsdev");
3511 error_report("fsdev support is disabled");
3514 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3519 case QEMU_OPTION_virtfs
: {
3522 const char *writeout
, *sock_fd
, *socket
;
3524 olist
= qemu_find_opts("virtfs");
3526 error_report("virtfs support is disabled");
3529 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3534 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3535 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3536 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3539 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3540 qemu_opt_get(opts
, "mount_tag"),
3543 error_report("duplicate fsdev id: %s",
3544 qemu_opt_get(opts
, "mount_tag"));
3548 writeout
= qemu_opt_get(opts
, "writeout");
3550 #ifdef CONFIG_SYNC_FILE_RANGE
3551 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3553 error_report("writeout=immediate not supported "
3554 "on this platform");
3558 qemu_opt_set(fsdev
, "fsdriver",
3559 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3560 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3562 qemu_opt_set(fsdev
, "security_model",
3563 qemu_opt_get(opts
, "security_model"),
3565 socket
= qemu_opt_get(opts
, "socket");
3567 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3569 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3571 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3574 qemu_opt_set_bool(fsdev
, "readonly",
3575 qemu_opt_get_bool(opts
, "readonly", 0),
3577 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3579 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3580 qemu_opt_set(device
, "fsdev",
3581 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3582 qemu_opt_set(device
, "mount_tag",
3583 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3586 case QEMU_OPTION_virtfs_synth
: {
3590 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3593 error_report("duplicate option: %s", "virtfs_synth");
3596 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3598 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3600 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3601 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3602 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3605 case QEMU_OPTION_serial
:
3606 add_device_config(DEV_SERIAL
, optarg
);
3608 if (strncmp(optarg
, "mon:", 4) == 0) {
3609 default_monitor
= 0;
3612 case QEMU_OPTION_watchdog
:
3614 error_report("only one watchdog option may be given");
3619 case QEMU_OPTION_watchdog_action
:
3620 if (select_watchdog_action(optarg
) == -1) {
3621 error_report("unknown -watchdog-action parameter");
3625 case QEMU_OPTION_virtiocon
:
3626 add_device_config(DEV_VIRTCON
, optarg
);
3627 default_virtcon
= 0;
3628 if (strncmp(optarg
, "mon:", 4) == 0) {
3629 default_monitor
= 0;
3632 case QEMU_OPTION_parallel
:
3633 add_device_config(DEV_PARALLEL
, optarg
);
3634 default_parallel
= 0;
3635 if (strncmp(optarg
, "mon:", 4) == 0) {
3636 default_monitor
= 0;
3639 case QEMU_OPTION_debugcon
:
3640 add_device_config(DEV_DEBUGCON
, optarg
);
3642 case QEMU_OPTION_loadvm
:
3645 case QEMU_OPTION_full_screen
:
3648 case QEMU_OPTION_no_frame
:
3651 case QEMU_OPTION_alt_grab
:
3654 case QEMU_OPTION_ctrl_grab
:
3657 case QEMU_OPTION_no_quit
:
3660 case QEMU_OPTION_sdl
:
3662 display_type
= DT_SDL
;
3665 error_report("SDL support is disabled");
3668 case QEMU_OPTION_pidfile
:
3671 case QEMU_OPTION_win2k_hack
:
3672 win2k_install_hack
= 1;
3674 case QEMU_OPTION_rtc_td_hack
: {
3675 static GlobalProperty slew_lost_ticks
[] = {
3677 .driver
= "mc146818rtc",
3678 .property
= "lost_tick_policy",
3681 { /* end of list */ }
3684 qdev_prop_register_global_list(slew_lost_ticks
);
3687 case QEMU_OPTION_acpitable
:
3688 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3693 do_acpitable_option(opts
);
3695 case QEMU_OPTION_smbios
:
3696 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3701 do_smbios_option(opts
);
3703 case QEMU_OPTION_fwcfg
:
3704 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3710 case QEMU_OPTION_enable_kvm
:
3711 olist
= qemu_find_opts("machine");
3712 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3715 case QEMU_OPTION_machine
:
3716 olist
= qemu_find_opts("machine");
3717 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3722 case QEMU_OPTION_no_kvm
:
3723 olist
= qemu_find_opts("machine");
3724 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3726 case QEMU_OPTION_no_kvm_pit
: {
3727 error_report("warning: ignoring deprecated option");
3730 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3731 static GlobalProperty kvm_pit_lost_tick_policy
[] = {
3733 .driver
= "kvm-pit",
3734 .property
= "lost_tick_policy",
3737 { /* end of list */ }
3740 error_report("warning: deprecated, replaced by "
3741 "-global kvm-pit.lost_tick_policy=discard");
3742 qdev_prop_register_global_list(kvm_pit_lost_tick_policy
);
3745 case QEMU_OPTION_usb
:
3746 olist
= qemu_find_opts("machine");
3747 qemu_opts_parse_noisily(olist
, "usb=on", false);
3749 case QEMU_OPTION_usbdevice
:
3750 olist
= qemu_find_opts("machine");
3751 qemu_opts_parse_noisily(olist
, "usb=on", false);
3752 add_device_config(DEV_USB
, optarg
);
3754 case QEMU_OPTION_device
:
3755 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3760 case QEMU_OPTION_smp
:
3761 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3766 case QEMU_OPTION_vnc
:
3769 Error
*local_err
= NULL
;
3771 if (vnc_parse(optarg
, &local_err
) == NULL
) {
3772 error_report_err(local_err
);
3776 error_report("VNC support is disabled");
3781 case QEMU_OPTION_no_acpi
:
3784 case QEMU_OPTION_no_hpet
:
3787 case QEMU_OPTION_balloon
:
3788 if (balloon_parse(optarg
) < 0) {
3789 error_report("unknown -balloon argument %s", optarg
);
3793 case QEMU_OPTION_no_reboot
:
3796 case QEMU_OPTION_no_shutdown
:
3799 case QEMU_OPTION_show_cursor
:
3802 case QEMU_OPTION_uuid
:
3803 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
3804 error_report("failed to parse UUID string: wrong format");
3807 qemu_uuid_set
= true;
3809 case QEMU_OPTION_option_rom
:
3810 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3811 error_report("too many option ROMs");
3814 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3819 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3820 option_rom
[nb_option_roms
].bootindex
=
3821 qemu_opt_get_number(opts
, "bootindex", -1);
3822 if (!option_rom
[nb_option_roms
].name
) {
3823 error_report("Option ROM file is not specified");
3828 case QEMU_OPTION_semihosting
:
3829 semihosting
.enabled
= true;
3830 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3832 case QEMU_OPTION_semihosting_config
:
3833 semihosting
.enabled
= true;
3834 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3837 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3839 const char *target
= qemu_opt_get(opts
, "target");
3840 if (target
!= NULL
) {
3841 if (strcmp("native", target
) == 0) {
3842 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3843 } else if (strcmp("gdb", target
) == 0) {
3844 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3845 } else if (strcmp("auto", target
) == 0) {
3846 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3848 error_report("unsupported semihosting-config %s",
3853 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3855 /* Set semihosting argument count and vector */
3856 qemu_opt_foreach(opts
, add_semihosting_arg
,
3857 &semihosting
, NULL
);
3859 error_report("unsupported semihosting-config %s", optarg
);
3863 case QEMU_OPTION_tdf
:
3864 error_report("warning: ignoring deprecated option");
3866 case QEMU_OPTION_name
:
3867 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3873 case QEMU_OPTION_prom_env
:
3874 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3875 error_report("too many prom variables");
3878 prom_envs
[nb_prom_envs
] = optarg
;
3881 case QEMU_OPTION_old_param
:
3884 case QEMU_OPTION_clock
:
3885 /* Clock options no longer exist. Keep this option for
3886 * backward compatibility.
3889 case QEMU_OPTION_startdate
:
3890 configure_rtc_date_offset(optarg
, 1);
3892 case QEMU_OPTION_rtc
:
3893 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3898 configure_rtc(opts
);
3900 case QEMU_OPTION_tb_size
:
3901 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3902 if (tcg_tb_size
< 0) {
3906 case QEMU_OPTION_icount
:
3907 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3913 case QEMU_OPTION_incoming
:
3915 runstate_set(RUN_STATE_INMIGRATE
);
3919 case QEMU_OPTION_nodefaults
:
3922 case QEMU_OPTION_xen_domid
:
3923 if (!(xen_available())) {
3924 printf("Option %s not supported for this target\n", popt
->name
);
3927 xen_domid
= atoi(optarg
);
3929 case QEMU_OPTION_xen_create
:
3930 if (!(xen_available())) {
3931 printf("Option %s not supported for this target\n", popt
->name
);
3934 xen_mode
= XEN_CREATE
;
3936 case QEMU_OPTION_xen_attach
:
3937 if (!(xen_available())) {
3938 printf("Option %s not supported for this target\n", popt
->name
);
3941 xen_mode
= XEN_ATTACH
;
3943 case QEMU_OPTION_trace
:
3945 opts
= qemu_opts_parse_noisily(qemu_find_opts("trace"),
3950 if (qemu_opt_get(opts
, "enable")) {
3951 trace_enable_events(qemu_opt_get(opts
, "enable"));
3953 trace_init_events(qemu_opt_get(opts
, "events"));
3957 trace_file
= g_strdup(qemu_opt_get(opts
, "file"));
3958 qemu_opts_del(opts
);
3961 case QEMU_OPTION_trace_unassigned
:
3962 trace_unassigned
= true;
3964 case QEMU_OPTION_readconfig
:
3966 int ret
= qemu_read_config_file(optarg
);
3968 error_report("read config %s: %s", optarg
,
3974 case QEMU_OPTION_spice
:
3975 olist
= qemu_find_opts("spice");
3977 error_report("spice support is disabled");
3980 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3986 case QEMU_OPTION_writeconfig
:
3989 if (strcmp(optarg
, "-") == 0) {
3992 fp
= fopen(optarg
, "w");
3994 error_report("open %s: %s", optarg
,
3999 qemu_config_write(fp
);
4005 case QEMU_OPTION_qtest
:
4006 qtest_chrdev
= optarg
;
4008 case QEMU_OPTION_qtest_log
:
4011 case QEMU_OPTION_sandbox
:
4012 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4018 case QEMU_OPTION_add_fd
:
4020 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4026 error_report("File descriptor passing is disabled on this "
4031 case QEMU_OPTION_object
:
4032 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
4038 case QEMU_OPTION_realtime
:
4039 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4044 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4046 case QEMU_OPTION_msg
:
4047 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4052 configure_msg(opts
);
4054 case QEMU_OPTION_dump_vmstate
:
4055 if (vmstate_dump_file
) {
4056 error_report("only one '-dump-vmstate' "
4057 "option may be given");
4060 vmstate_dump_file
= fopen(optarg
, "w");
4061 if (vmstate_dump_file
== NULL
) {
4062 error_report("open %s: %s", optarg
, strerror(errno
));
4067 os_parse_cmd_args(popt
->index
, optarg
);
4072 * Clear error location left behind by the loop.
4073 * Best done right after the loop. Do not insert code here!
4077 replay_configure(icount_opts
);
4079 machine_class
= select_machine();
4081 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4085 if (qemu_init_main_loop(&main_loop_err
)) {
4086 error_report_err(main_loop_err
);
4090 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4091 parse_sandbox
, NULL
, NULL
)) {
4095 if (qemu_opts_foreach(qemu_find_opts("name"),
4096 parse_name
, NULL
, NULL
)) {
4101 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4102 parse_add_fd
, NULL
, NULL
)) {
4106 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4107 cleanup_add_fd
, NULL
, NULL
)) {
4112 current_machine
= MACHINE(object_new(object_class_get_name(
4113 OBJECT_CLASS(machine_class
))));
4114 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4117 object_property_add_child(object_get_root(), "machine",
4118 OBJECT(current_machine
), &error_abort
);
4119 cpu_exec_init_all();
4121 if (machine_class
->hw_version
) {
4122 qemu_set_hw_version(machine_class
->hw_version
);
4125 /* Init CPU def lists, based on config
4126 * - Must be called after all the qemu_read_config_file() calls
4127 * - Must be called before list_cpus()
4128 * - Must be called before machine_class->init()
4132 if (cpu_model
&& is_help_option(cpu_model
)) {
4133 list_cpus(stdout
, &fprintf
, cpu_model
);
4137 if (!trace_init_backends()) {
4140 trace_init_file(trace_file
);
4142 /* Open the logfile at this point and set the log mask if necessary.
4145 qemu_set_log_filename(log_file
);
4150 mask
= qemu_str_to_log_mask(log_mask
);
4152 qemu_print_log_usage(stdout
);
4160 /* If no data_dir is specified then try to find it relative to the
4162 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4163 data_dir
[data_dir_idx
] = os_find_datadir();
4164 if (data_dir
[data_dir_idx
] != NULL
) {
4168 /* If all else fails use the install path specified when building. */
4169 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4170 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4173 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4175 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4176 if (max_cpus
> machine_class
->max_cpus
) {
4177 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4178 "supported by machine '%s' (%d)", max_cpus
,
4179 machine_class
->name
, machine_class
->max_cpus
);
4184 * Get the default machine options from the machine if it is not already
4185 * specified either by the configuration file or by the command line.
4187 if (machine_class
->default_machine_opts
) {
4188 qemu_opts_set_defaults(qemu_find_opts("machine"),
4189 machine_class
->default_machine_opts
, 0);
4192 qemu_opts_foreach(qemu_find_opts("device"),
4193 default_driver_check
, NULL
, NULL
);
4194 qemu_opts_foreach(qemu_find_opts("global"),
4195 default_driver_check
, NULL
, NULL
);
4197 if (!vga_model
&& !default_vga
) {
4198 vga_interface_type
= VGA_DEVICE
;
4200 if (!has_defaults
|| machine_class
->no_serial
) {
4203 if (!has_defaults
|| machine_class
->no_parallel
) {
4204 default_parallel
= 0;
4206 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4207 default_virtcon
= 0;
4209 if (!has_defaults
|| !machine_class
->use_sclp
) {
4212 if (!has_defaults
|| machine_class
->no_floppy
) {
4215 if (!has_defaults
|| machine_class
->no_cdrom
) {
4218 if (!has_defaults
|| machine_class
->no_sdcard
) {
4221 if (!has_defaults
) {
4222 default_monitor
= 0;
4227 if (is_daemonized()) {
4228 /* According to documentation and historically, -nographic redirects
4229 * serial port, parallel port and monitor to stdio, which does not work
4230 * with -daemonize. We can redirect these to null instead, but since
4231 * -nographic is legacy, let's just error out.
4232 * We disallow -nographic only if all other ports are not redirected
4233 * explicitly, to not break existing legacy setups which uses
4234 * -nographic _and_ redirects all ports explicitly - this is valid
4235 * usage, -nographic is just a no-op in this case.
4237 if (display_type
== DT_NOGRAPHIC
4238 && (default_parallel
|| default_serial
4239 || default_monitor
|| default_virtcon
)) {
4240 error_report("-nographic cannot be used with -daemonize");
4243 #ifdef CONFIG_CURSES
4244 if (display_type
== DT_CURSES
) {
4245 error_report("curses display cannot be used with -daemonize");
4251 if (display_type
== DT_NOGRAPHIC
) {
4252 if (default_parallel
)
4253 add_device_config(DEV_PARALLEL
, "null");
4254 if (default_serial
&& default_monitor
) {
4255 add_device_config(DEV_SERIAL
, "mon:stdio");
4256 } else if (default_virtcon
&& default_monitor
) {
4257 add_device_config(DEV_VIRTCON
, "mon:stdio");
4258 } else if (default_sclp
&& default_monitor
) {
4259 add_device_config(DEV_SCLP
, "mon:stdio");
4262 add_device_config(DEV_SERIAL
, "stdio");
4263 if (default_virtcon
)
4264 add_device_config(DEV_VIRTCON
, "stdio");
4266 add_device_config(DEV_SCLP
, "stdio");
4268 if (default_monitor
)
4269 monitor_parse("stdio", "readline", false);
4273 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4274 if (default_parallel
)
4275 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4276 if (default_monitor
)
4277 monitor_parse("vc:80Cx24C", "readline", false);
4278 if (default_virtcon
)
4279 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4281 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4285 #if defined(CONFIG_VNC)
4286 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4290 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4291 #if defined(CONFIG_GTK)
4292 display_type
= DT_GTK
;
4293 #elif defined(CONFIG_SDL) || defined(CONFIG_COCOA)
4294 display_type
= DT_SDL
;
4295 #elif defined(CONFIG_VNC)
4296 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4299 display_type
= DT_NONE
;
4303 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4304 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4305 "for SDL, ignoring option");
4307 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4308 error_report("-no-quit is only valid for GTK and SDL, "
4312 #if defined(CONFIG_GTK)
4313 if (display_type
== DT_GTK
) {
4314 early_gtk_display_init(request_opengl
);
4317 #if defined(CONFIG_SDL)
4318 if (display_type
== DT_SDL
) {
4319 sdl_display_early_init(request_opengl
);
4322 if (request_opengl
== 1 && display_opengl
== 0) {
4323 #if defined(CONFIG_OPENGL)
4324 error_report("OpenGL is not supported by the display");
4326 error_report("OpenGL support is disabled");
4334 if (qemu_opts_foreach(qemu_find_opts("object"),
4335 user_creatable_add_opts_foreach
,
4336 object_create_initial
, NULL
)) {
4340 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4341 chardev_init_func
, NULL
, NULL
)) {
4345 #ifdef CONFIG_VIRTFS
4346 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4347 fsdev_init_func
, NULL
, NULL
)) {
4352 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4353 error_report("could not acquire pid file: %s", strerror(errno
));
4357 if (qemu_opts_foreach(qemu_find_opts("device"),
4358 device_help_func
, NULL
, NULL
)) {
4362 machine_opts
= qemu_get_machine_opts();
4363 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4365 object_unref(OBJECT(current_machine
));
4369 configure_accelerator(current_machine
);
4372 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4375 machine_opts
= qemu_get_machine_opts();
4376 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4377 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4378 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4379 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4381 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4383 boot_order
= qemu_opt_get(opts
, "order");
4385 validate_bootdevices(boot_order
, &error_fatal
);
4388 boot_once
= qemu_opt_get(opts
, "once");
4390 validate_bootdevices(boot_once
, &error_fatal
);
4393 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4394 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4398 boot_order
= machine_class
->default_boot_order
;
4401 if (!kernel_cmdline
) {
4402 kernel_cmdline
= "";
4403 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4406 linux_boot
= (kernel_filename
!= NULL
);
4408 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4409 error_report("-append only allowed with -kernel option");
4413 if (!linux_boot
&& initrd_filename
!= NULL
) {
4414 error_report("-initrd only allowed with -kernel option");
4418 if (!linux_boot
&& qemu_opt_get(machine_opts
, "dtb")) {
4419 error_report("-dtb only allowed with -kernel option");
4423 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4424 /* fall back to the -kernel/-append */
4425 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4428 os_set_line_buffering();
4431 /* spice needs the timers to be initialized by this point */
4437 if (kvm_enabled() || xen_enabled()) {
4438 error_report("-icount is not allowed with kvm or xen");
4441 configure_icount(icount_opts
, &error_abort
);
4442 qemu_opts_del(icount_opts
);
4445 /* clean up network at qemu process termination */
4446 atexit(&net_cleanup
);
4448 if (net_init_clients() < 0) {
4452 if (qemu_opts_foreach(qemu_find_opts("object"),
4453 user_creatable_add_opts_foreach
,
4454 object_create_delayed
, NULL
)) {
4459 if (tpm_init() < 0) {
4464 /* init the bluetooth world */
4465 if (foreach_device_config(DEV_BT
, bt_parse
))
4468 if (!xen_enabled()) {
4469 /* On 32-bit hosts, QEMU is limited by virtual address space */
4470 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4471 error_report("at most 2047 MB RAM can be simulated");
4479 /* If the currently selected machine wishes to override the units-per-bus
4480 * property of its default HBA interface type, do so now. */
4481 if (machine_class
->units_per_default_bus
) {
4482 override_max_devs(machine_class
->block_default_type
,
4483 machine_class
->units_per_default_bus
);
4486 /* open the virtual block devices */
4487 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4488 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4491 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4492 &machine_class
->block_default_type
, NULL
)) {
4496 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4498 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4499 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4501 parse_numa_opts(machine_class
);
4503 if (qemu_opts_foreach(qemu_find_opts("mon"),
4504 mon_init_func
, NULL
, NULL
)) {
4508 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4510 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4512 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4514 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4517 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4520 /* If no default VGA is requested, the default is "none". */
4522 if (machine_class
->default_display
) {
4523 vga_model
= machine_class
->default_display
;
4524 } else if (cirrus_vga_available()) {
4525 vga_model
= "cirrus";
4526 } else if (vga_available()) {
4531 select_vgahw(vga_model
);
4535 i
= select_watchdog(watchdog
);
4537 exit (i
== 1 ? 1 : 0);
4540 if (machine_class
->compat_props
) {
4541 qdev_prop_register_global_list(machine_class
->compat_props
);
4545 /* This checkpoint is required by replay to separate prior clock
4546 reading from the other reads, because timer polling functions query
4547 clock values from the log. */
4548 replay_checkpoint(CHECKPOINT_INIT
);
4549 qdev_machine_init();
4551 current_machine
->ram_size
= ram_size
;
4552 current_machine
->maxram_size
= maxram_size
;
4553 current_machine
->ram_slots
= ram_slots
;
4554 current_machine
->boot_order
= boot_order
;
4555 current_machine
->cpu_model
= cpu_model
;
4557 machine_class
->init(current_machine
);
4563 cpu_synchronize_all_post_init();
4565 numa_post_machine_init();
4567 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4568 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4572 /* init USB devices */
4573 if (usb_enabled()) {
4574 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4578 /* Check if IGD GFX passthrough. */
4581 /* init generic devices */
4582 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4583 if (qemu_opts_foreach(qemu_find_opts("device"),
4584 device_init_func
, NULL
, NULL
)) {
4587 rom_reset_order_override();
4589 /* Did we create any drives that we failed to create a device for? */
4590 drive_check_orphaned();
4592 net_check_clients();
4595 qemu_boot_set(boot_once
, &error_fatal
);
4596 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4599 ds
= init_displaystate();
4601 /* init local displays */
4602 switch (display_type
) {
4604 (void)ds
; /* avoid warning if no display is configured */
4606 #if defined(CONFIG_CURSES)
4608 curses_display_init(ds
, full_screen
);
4611 #if defined(CONFIG_SDL)
4613 sdl_display_init(ds
, full_screen
, no_frame
);
4615 #elif defined(CONFIG_COCOA)
4617 cocoa_display_init(ds
, full_screen
);
4620 #if defined(CONFIG_GTK)
4622 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4629 /* must be after terminal init, SDL library changes signal handlers */
4630 os_setup_signal_handling();
4633 /* init remote displays */
4634 qemu_opts_foreach(qemu_find_opts("vnc"),
4635 vnc_init_func
, NULL
, NULL
);
4636 if (show_vnc_port
) {
4637 char *ret
= vnc_display_local_addr("default");
4638 printf("VNC server running on '%s'\n", ret
);
4644 qemu_spice_display_init();
4648 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4652 qdev_machine_creation_done();
4654 /* TODO: once all bus devices are qdevified, this should be done
4655 * when bus is created by qdev.c */
4656 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4657 qemu_run_machine_init_done_notifiers();
4659 if (rom_check_and_register_reset() != 0) {
4660 error_report("rom check and register reset failed");
4666 /* This checkpoint is required by replay to separate prior clock
4667 reading from the other reads, because timer polling functions query
4668 clock values from the log. */
4669 replay_checkpoint(CHECKPOINT_RESET
);
4670 qemu_system_reset(VMRESET_SILENT
);
4671 register_global_state();
4673 if (load_vmstate(loadvm
) < 0) {
4678 qdev_prop_check_globals();
4679 if (vmstate_dump_file
) {
4681 dump_vmstate_json_to_file(vmstate_dump_file
);
4686 Error
*local_err
= NULL
;
4687 qemu_start_incoming_migration(incoming
, &local_err
);
4689 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4692 } else if (autostart
) {
4699 replay_disable_events();