4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "qemu/osdep.h"
25 #include "qemu-version.h"
26 #include "qemu/cutils.h"
27 #include "qemu/help_option.h"
28 #include "qemu/uuid.h"
31 #include "sysemu/seccomp.h"
34 #if defined(CONFIG_VDE)
35 #include <libvdeplug.h>
39 #if defined(__APPLE__) || defined(main)
41 int qemu_main(int argc
, char **argv
, char **envp
);
42 int main(int argc
, char **argv
)
44 return qemu_main(argc
, argv
, NULL
);
47 #define main qemu_main
49 #endif /* CONFIG_SDL */
53 #define main qemu_main
54 #endif /* CONFIG_COCOA */
57 #include "qemu/error-report.h"
58 #include "qemu/sockets.h"
60 #include "hw/boards.h"
61 #include "sysemu/accel.h"
63 #include "hw/i386/pc.h"
64 #include "hw/isa/isa.h"
65 #include "hw/scsi/scsi.h"
67 #include "sysemu/watchdog.h"
68 #include "hw/smbios/smbios.h"
69 #include "hw/acpi/acpi.h"
70 #include "hw/xen/xen.h"
72 #include "hw/loader.h"
73 #include "monitor/qdev.h"
74 #include "sysemu/bt.h"
76 #include "net/slirp.h"
77 #include "monitor/monitor.h"
78 #include "ui/console.h"
80 #include "sysemu/sysemu.h"
81 #include "sysemu/numa.h"
82 #include "exec/gdbstub.h"
83 #include "qemu/timer.h"
84 #include "sysemu/char.h"
85 #include "qemu/bitmap.h"
87 #include "sysemu/blockdev.h"
88 #include "hw/block/block.h"
89 #include "migration/block.h"
90 #include "sysemu/tpm.h"
91 #include "sysemu/dma.h"
92 #include "audio/audio.h"
93 #include "migration/migration.h"
94 #include "sysemu/cpus.h"
95 #include "migration/colo.h"
96 #include "sysemu/kvm.h"
97 #include "sysemu/hax.h"
98 #include "qapi/qmp/qjson.h"
99 #include "qemu/option.h"
100 #include "qemu/config-file.h"
101 #include "qemu-options.h"
102 #include "qmp-commands.h"
103 #include "qemu/main-loop.h"
105 #include "fsdev/qemu-fsdev.h"
107 #include "sysemu/qtest.h"
109 #include "disas/disas.h"
112 #include "slirp/libslirp.h"
114 #include "trace-root.h"
115 #include "trace/control.h"
116 #include "qemu/queue.h"
117 #include "sysemu/arch_init.h"
119 #include "ui/qemu-spice.h"
120 #include "qapi/string-input-visitor.h"
121 #include "qapi/opts-visitor.h"
122 #include "qom/object_interfaces.h"
123 #include "qapi-event.h"
124 #include "exec/semihost.h"
125 #include "crypto/init.h"
126 #include "sysemu/replay.h"
127 #include "qapi/qmp/qerror.h"
128 #include "sysemu/iothread.h"
130 #define MAX_VIRTIO_CONSOLES 1
131 #define MAX_SCLP_CONSOLES 1
133 static const char *data_dir
[16];
134 static int data_dir_idx
;
135 const char *bios_name
= NULL
;
136 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
137 int request_opengl
= -1;
139 const char* keyboard_layout
= NULL
;
141 const char *mem_path
= NULL
;
142 int mem_prealloc
= 0; /* force preallocation of physical target memory */
143 bool enable_mlock
= false;
145 NICInfo nd_table
[MAX_NICS
];
147 static int rtc_utc
= 1;
148 static int rtc_date_offset
= -1; /* -1 means no change */
149 QEMUClockType rtc_clock
;
150 int vga_interface_type
= VGA_NONE
;
151 static int full_screen
= 0;
152 static int no_frame
= 0;
154 static bool grab_on_hover
;
155 Chardev
*serial_hds
[MAX_SERIAL_PORTS
];
156 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
157 Chardev
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
158 Chardev
*sclp_hds
[MAX_SCLP_CONSOLES
];
159 int win2k_install_hack
= 0;
165 int acpi_enabled
= 1;
168 static int no_reboot
;
171 int graphic_rotate
= 0;
172 const char *watchdog
;
173 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
176 const char *qemu_name
;
179 unsigned int nb_prom_envs
= 0;
180 const char *prom_envs
[MAX_PROM_ENVS
];
183 uint8_t *boot_splash_filedata
;
184 size_t boot_splash_filedata_size
;
185 uint8_t qemu_extra_params_fw
[2];
186 int only_migratable
; /* turn it off unless user states otherwise */
188 int icount_align_option
;
190 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
191 * little-endian "wire format" described in the SMBIOS 2.6 specification.
196 static NotifierList exit_notifiers
=
197 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
199 static NotifierList machine_init_done_notifiers
=
200 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
204 enum xen_mode xen_mode
= XEN_EMULATE
;
206 static int has_defaults
= 1;
207 static int default_serial
= 1;
208 static int default_parallel
= 1;
209 static int default_virtcon
= 1;
210 static int default_sclp
= 1;
211 static int default_monitor
= 1;
212 static int default_floppy
= 1;
213 static int default_cdrom
= 1;
214 static int default_sdcard
= 1;
215 static int default_vga
= 1;
216 static int default_net
= 1;
222 { .driver
= "isa-serial", .flag
= &default_serial
},
223 { .driver
= "isa-parallel", .flag
= &default_parallel
},
224 { .driver
= "isa-fdc", .flag
= &default_floppy
},
225 { .driver
= "floppy", .flag
= &default_floppy
},
226 { .driver
= "ide-cd", .flag
= &default_cdrom
},
227 { .driver
= "ide-hd", .flag
= &default_cdrom
},
228 { .driver
= "ide-drive", .flag
= &default_cdrom
},
229 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
230 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
231 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
232 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
233 { .driver
= "VGA", .flag
= &default_vga
},
234 { .driver
= "isa-vga", .flag
= &default_vga
},
235 { .driver
= "cirrus-vga", .flag
= &default_vga
},
236 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
237 { .driver
= "vmware-svga", .flag
= &default_vga
},
238 { .driver
= "qxl-vga", .flag
= &default_vga
},
239 { .driver
= "virtio-vga", .flag
= &default_vga
},
242 static QemuOptsList qemu_rtc_opts
= {
244 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
248 .type
= QEMU_OPT_STRING
,
251 .type
= QEMU_OPT_STRING
,
254 .type
= QEMU_OPT_STRING
,
256 { /* end of list */ }
260 static QemuOptsList qemu_sandbox_opts
= {
262 .implied_opt_name
= "enable",
263 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
267 .type
= QEMU_OPT_BOOL
,
269 { /* end of list */ }
273 static QemuOptsList qemu_option_rom_opts
= {
274 .name
= "option-rom",
275 .implied_opt_name
= "romfile",
276 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
280 .type
= QEMU_OPT_NUMBER
,
283 .type
= QEMU_OPT_STRING
,
285 { /* end of list */ }
289 static QemuOptsList qemu_machine_opts
= {
291 .implied_opt_name
= "type",
293 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
296 * no elements => accept any
297 * sanity checking will happen later
298 * when setting machine properties
304 static QemuOptsList qemu_accel_opts
= {
306 .implied_opt_name
= "accel",
307 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
312 .type
= QEMU_OPT_STRING
,
313 .help
= "Select the type of accelerator",
317 .type
= QEMU_OPT_STRING
,
318 .help
= "Enable/disable multi-threaded TCG",
320 { /* end of list */ }
324 static QemuOptsList qemu_boot_opts
= {
326 .implied_opt_name
= "order",
328 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
332 .type
= QEMU_OPT_STRING
,
335 .type
= QEMU_OPT_STRING
,
338 .type
= QEMU_OPT_BOOL
,
341 .type
= QEMU_OPT_STRING
,
343 .name
= "splash-time",
344 .type
= QEMU_OPT_STRING
,
346 .name
= "reboot-timeout",
347 .type
= QEMU_OPT_STRING
,
350 .type
= QEMU_OPT_BOOL
,
356 static QemuOptsList qemu_add_fd_opts
= {
358 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
362 .type
= QEMU_OPT_NUMBER
,
363 .help
= "file descriptor of which a duplicate is added to fd set",
366 .type
= QEMU_OPT_NUMBER
,
367 .help
= "ID of the fd set to add fd to",
370 .type
= QEMU_OPT_STRING
,
371 .help
= "free-form string used to describe fd",
373 { /* end of list */ }
377 static QemuOptsList qemu_object_opts
= {
379 .implied_opt_name
= "qom-type",
380 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
386 static QemuOptsList qemu_tpmdev_opts
= {
388 .implied_opt_name
= "type",
389 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
391 /* options are defined in the TPM backends */
392 { /* end of list */ }
396 static QemuOptsList qemu_realtime_opts
= {
398 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
402 .type
= QEMU_OPT_BOOL
,
404 { /* end of list */ }
408 static QemuOptsList qemu_msg_opts
= {
410 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
414 .type
= QEMU_OPT_BOOL
,
416 { /* end of list */ }
420 static QemuOptsList qemu_name_opts
= {
422 .implied_opt_name
= "guest",
424 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
428 .type
= QEMU_OPT_STRING
,
429 .help
= "Sets the name of the guest.\n"
430 "This name will be displayed in the SDL window caption.\n"
431 "The name will also be used for the VNC server",
434 .type
= QEMU_OPT_STRING
,
435 .help
= "Sets the name of the QEMU process, as shown in top etc",
437 .name
= "debug-threads",
438 .type
= QEMU_OPT_BOOL
,
439 .help
= "When enabled, name the individual threads; defaults off.\n"
440 "NOTE: The thread names are for debugging and not a\n"
443 { /* End of list */ }
447 static QemuOptsList qemu_mem_opts
= {
449 .implied_opt_name
= "size",
450 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
455 .type
= QEMU_OPT_SIZE
,
459 .type
= QEMU_OPT_NUMBER
,
463 .type
= QEMU_OPT_SIZE
,
465 { /* end of list */ }
469 static QemuOptsList qemu_icount_opts
= {
471 .implied_opt_name
= "shift",
473 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
477 .type
= QEMU_OPT_STRING
,
480 .type
= QEMU_OPT_BOOL
,
483 .type
= QEMU_OPT_BOOL
,
486 .type
= QEMU_OPT_STRING
,
489 .type
= QEMU_OPT_STRING
,
491 .name
= "rrsnapshot",
492 .type
= QEMU_OPT_STRING
,
494 { /* end of list */ }
498 static QemuOptsList qemu_semihosting_config_opts
= {
499 .name
= "semihosting-config",
500 .implied_opt_name
= "enable",
501 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
505 .type
= QEMU_OPT_BOOL
,
508 .type
= QEMU_OPT_STRING
,
511 .type
= QEMU_OPT_STRING
,
513 { /* end of list */ }
517 static QemuOptsList qemu_fw_cfg_opts
= {
519 .implied_opt_name
= "name",
520 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
524 .type
= QEMU_OPT_STRING
,
525 .help
= "Sets the fw_cfg name of the blob to be inserted",
528 .type
= QEMU_OPT_STRING
,
529 .help
= "Sets the name of the file from which\n"
530 "the fw_cfg blob will be loaded",
533 .type
= QEMU_OPT_STRING
,
534 .help
= "Sets content of the blob to be inserted from a string",
536 { /* end of list */ }
541 * Get machine options
543 * Returns: machine options (never null).
545 QemuOpts
*qemu_get_machine_opts(void)
547 return qemu_find_opts_singleton("machine");
550 const char *qemu_get_vm_name(void)
555 static void res_free(void)
557 g_free(boot_splash_filedata
);
558 boot_splash_filedata
= NULL
;
561 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
563 const char *driver
= qemu_opt_get(opts
, "driver");
568 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
569 if (strcmp(default_list
[i
].driver
, driver
) != 0)
571 *(default_list
[i
].flag
) = 0;
576 /***********************************************************/
579 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
581 /* We use RUN_STATE__MAX but any invalid value will do */
582 static RunState vmstop_requested
= RUN_STATE__MAX
;
583 static QemuMutex vmstop_lock
;
588 } RunStateTransition
;
590 static const RunStateTransition runstate_transitions_def
[] = {
592 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
593 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
594 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
596 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
597 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
598 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
599 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
600 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
601 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
602 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
603 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
604 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
605 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
606 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
607 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
609 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
610 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
611 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
613 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
614 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
615 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
617 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
618 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
619 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
620 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
622 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
623 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
624 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
626 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
627 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
628 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
630 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
631 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
632 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
633 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
635 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
636 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
638 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
640 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
641 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
642 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
643 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
644 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
645 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
646 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
647 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
648 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
649 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
650 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
652 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
654 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
655 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
656 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
658 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
659 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
660 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
661 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
662 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
663 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
665 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
666 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
667 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
668 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
670 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
671 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
672 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
674 { RUN_STATE__MAX
, RUN_STATE__MAX
},
677 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
679 bool runstate_check(RunState state
)
681 return current_run_state
== state
;
684 bool runstate_store(char *str
, size_t size
)
686 const char *state
= RunState_lookup
[current_run_state
];
687 size_t len
= strlen(state
) + 1;
692 memcpy(str
, state
, len
);
696 static void runstate_init(void)
698 const RunStateTransition
*p
;
700 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
701 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
702 runstate_valid_transitions
[p
->from
][p
->to
] = true;
705 qemu_mutex_init(&vmstop_lock
);
708 /* This function will abort() on invalid state transitions */
709 void runstate_set(RunState new_state
)
711 assert(new_state
< RUN_STATE__MAX
);
713 if (current_run_state
== new_state
) {
717 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
718 error_report("invalid runstate transition: '%s' -> '%s'",
719 RunState_lookup
[current_run_state
],
720 RunState_lookup
[new_state
]);
723 trace_runstate_set(new_state
);
724 current_run_state
= new_state
;
727 int runstate_is_running(void)
729 return runstate_check(RUN_STATE_RUNNING
);
732 bool runstate_needs_reset(void)
734 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
735 runstate_check(RUN_STATE_SHUTDOWN
);
738 StatusInfo
*qmp_query_status(Error
**errp
)
740 StatusInfo
*info
= g_malloc0(sizeof(*info
));
742 info
->running
= runstate_is_running();
743 info
->singlestep
= singlestep
;
744 info
->status
= current_run_state
;
749 bool qemu_vmstop_requested(RunState
*r
)
751 qemu_mutex_lock(&vmstop_lock
);
752 *r
= vmstop_requested
;
753 vmstop_requested
= RUN_STATE__MAX
;
754 qemu_mutex_unlock(&vmstop_lock
);
755 return *r
< RUN_STATE__MAX
;
758 void qemu_system_vmstop_request_prepare(void)
760 qemu_mutex_lock(&vmstop_lock
);
763 void qemu_system_vmstop_request(RunState state
)
765 vmstop_requested
= state
;
766 qemu_mutex_unlock(&vmstop_lock
);
770 /***********************************************************/
771 /* real time host monotonic timer */
773 static time_t qemu_time(void)
775 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
778 /***********************************************************/
779 /* host time/date access */
780 void qemu_get_timedate(struct tm
*tm
, int offset
)
782 time_t ti
= qemu_time();
785 if (rtc_date_offset
== -1) {
789 localtime_r(&ti
, tm
);
791 ti
-= rtc_date_offset
;
796 int qemu_timedate_diff(struct tm
*tm
)
800 if (rtc_date_offset
== -1)
802 seconds
= mktimegm(tm
);
805 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
806 seconds
= mktime(&tmp
);
809 seconds
= mktimegm(tm
) + rtc_date_offset
;
811 return seconds
- qemu_time();
814 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
816 time_t rtc_start_date
;
819 if (!strcmp(startdate
, "now") && legacy
) {
820 rtc_date_offset
= -1;
822 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
830 } else if (sscanf(startdate
, "%d-%d-%d",
842 rtc_start_date
= mktimegm(&tm
);
843 if (rtc_start_date
== -1) {
845 error_report("invalid date format");
846 error_printf("valid formats: "
847 "'2006-06-17T16:01:21' or '2006-06-17'\n");
850 rtc_date_offset
= qemu_time() - rtc_start_date
;
854 static void configure_rtc(QemuOpts
*opts
)
858 value
= qemu_opt_get(opts
, "base");
860 if (!strcmp(value
, "utc")) {
862 } else if (!strcmp(value
, "localtime")) {
863 Error
*blocker
= NULL
;
865 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
866 "-rtc base=localtime");
867 replay_add_blocker(blocker
);
869 configure_rtc_date_offset(value
, 0);
872 value
= qemu_opt_get(opts
, "clock");
874 if (!strcmp(value
, "host")) {
875 rtc_clock
= QEMU_CLOCK_HOST
;
876 } else if (!strcmp(value
, "rt")) {
877 rtc_clock
= QEMU_CLOCK_REALTIME
;
878 } else if (!strcmp(value
, "vm")) {
879 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
881 error_report("invalid option value '%s'", value
);
885 value
= qemu_opt_get(opts
, "driftfix");
887 if (!strcmp(value
, "slew")) {
888 static GlobalProperty slew_lost_ticks
= {
889 .driver
= "mc146818rtc",
890 .property
= "lost_tick_policy",
894 qdev_prop_register_global(&slew_lost_ticks
);
895 } else if (!strcmp(value
, "none")) {
896 /* discard is default */
898 error_report("invalid option value '%s'", value
);
904 /***********************************************************/
905 /* Bluetooth support */
908 static struct HCIInfo
*hci_table
[MAX_NICS
];
910 struct HCIInfo
*qemu_next_hci(void)
912 if (cur_hci
== nb_hcis
)
915 return hci_table
[cur_hci
++];
918 static int bt_hci_parse(const char *str
)
923 if (nb_hcis
>= MAX_NICS
) {
924 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
937 bdaddr
.b
[5] = 0x56 + nb_hcis
;
938 hci
->bdaddr_set(hci
, bdaddr
.b
);
940 hci_table
[nb_hcis
++] = hci
;
945 static void bt_vhci_add(int vlan_id
)
947 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
950 error_report("warning: adding a VHCI to an empty scatternet %i",
953 bt_vhci_init(bt_new_hci(vlan
));
956 static struct bt_device_s
*bt_device_add(const char *opt
)
958 struct bt_scatternet_s
*vlan
;
960 char *endp
= strstr(opt
, ",vlan=");
961 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
964 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
967 vlan_id
= strtol(endp
+ 6, &endp
, 0);
969 error_report("unrecognised bluetooth vlan Id");
974 vlan
= qemu_find_bt_vlan(vlan_id
);
977 error_report("warning: adding a slave device to an empty scatternet %i",
980 if (!strcmp(devname
, "keyboard"))
981 return bt_keyboard_init(vlan
);
983 error_report("unsupported bluetooth device '%s'", devname
);
987 static int bt_parse(const char *opt
)
989 const char *endp
, *p
;
992 if (strstart(opt
, "hci", &endp
)) {
993 if (!*endp
|| *endp
== ',') {
995 if (!strstart(endp
, ",vlan=", 0))
998 return bt_hci_parse(opt
);
1000 } else if (strstart(opt
, "vhci", &endp
)) {
1001 if (!*endp
|| *endp
== ',') {
1003 if (strstart(endp
, ",vlan=", &p
)) {
1004 vlan
= strtol(p
, (char **) &endp
, 0);
1006 error_report("bad scatternet '%s'", p
);
1010 error_report("bad parameter '%s'", endp
+ 1);
1019 } else if (strstart(opt
, "device:", &endp
))
1020 return !bt_device_add(endp
);
1022 error_report("bad bluetooth parameter '%s'", opt
);
1026 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1028 /* FIXME: change this to true for 1.3 */
1029 if (qemu_opt_get_bool(opts
, "enable", false)) {
1030 #ifdef CONFIG_SECCOMP
1031 if (seccomp_start() < 0) {
1032 error_report("failed to install seccomp syscall filter "
1037 error_report("seccomp support is disabled");
1045 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1047 const char *proc_name
;
1049 if (qemu_opt_get(opts
, "debug-threads")) {
1050 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1052 qemu_name
= qemu_opt_get(opts
, "guest");
1054 proc_name
= qemu_opt_get(opts
, "process");
1056 os_set_proc_name(proc_name
);
1062 bool defaults_enabled(void)
1064 return has_defaults
;
1068 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1070 int fd
, dupfd
, flags
;
1072 const char *fd_opaque
= NULL
;
1075 fd
= qemu_opt_get_number(opts
, "fd", -1);
1076 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1077 fd_opaque
= qemu_opt_get(opts
, "opaque");
1080 error_report("fd option is required and must be non-negative");
1084 if (fd
<= STDERR_FILENO
) {
1085 error_report("fd cannot be a standard I/O stream");
1090 * All fds inherited across exec() necessarily have FD_CLOEXEC
1091 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1093 flags
= fcntl(fd
, F_GETFD
);
1094 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1095 error_report("fd is not valid or already in use");
1100 error_report("set option is required and must be non-negative");
1104 #ifdef F_DUPFD_CLOEXEC
1105 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1109 qemu_set_cloexec(dupfd
);
1113 error_report("error duplicating fd: %s", strerror(errno
));
1117 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1118 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1125 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1129 fd
= qemu_opt_get_number(opts
, "fd", -1);
1136 /***********************************************************/
1137 /* QEMU Block devices */
1139 #define HD_OPTS "media=disk"
1140 #define CDROM_OPTS "media=cdrom"
1142 #define PFLASH_OPTS ""
1146 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1148 BlockInterfaceType
*block_default_type
= opaque
;
1150 return drive_new(opts
, *block_default_type
) == NULL
;
1153 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1155 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1156 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1161 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1162 int index
, const char *optstr
)
1167 if (!enable
|| drive_get_by_index(type
, index
)) {
1171 opts
= drive_add(type
, index
, NULL
, optstr
);
1173 drive_enable_snapshot(NULL
, opts
, NULL
);
1176 dinfo
= drive_new(opts
, type
);
1180 dinfo
->is_default
= true;
1184 static QemuOptsList qemu_smp_opts
= {
1186 .implied_opt_name
= "cpus",
1187 .merge_lists
= true,
1188 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1192 .type
= QEMU_OPT_NUMBER
,
1195 .type
= QEMU_OPT_NUMBER
,
1198 .type
= QEMU_OPT_NUMBER
,
1201 .type
= QEMU_OPT_NUMBER
,
1204 .type
= QEMU_OPT_NUMBER
,
1206 { /*End of list */ }
1210 static void smp_parse(QemuOpts
*opts
)
1213 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1214 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1215 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1216 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1218 /* compute missing values, prefer sockets over cores over threads */
1219 if (cpus
== 0 || sockets
== 0) {
1220 sockets
= sockets
> 0 ? sockets
: 1;
1221 cores
= cores
> 0 ? cores
: 1;
1222 threads
= threads
> 0 ? threads
: 1;
1224 cpus
= cores
* threads
* sockets
;
1226 } else if (cores
== 0) {
1227 threads
= threads
> 0 ? threads
: 1;
1228 cores
= cpus
/ (sockets
* threads
);
1229 cores
= cores
> 0 ? cores
: 1;
1230 } else if (threads
== 0) {
1231 threads
= cpus
/ (cores
* sockets
);
1232 threads
= threads
> 0 ? threads
: 1;
1233 } else if (sockets
* cores
* threads
< cpus
) {
1234 error_report("cpu topology: "
1235 "sockets (%u) * cores (%u) * threads (%u) < "
1237 sockets
, cores
, threads
, cpus
);
1241 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1243 if (max_cpus
< cpus
) {
1244 error_report("maxcpus must be equal to or greater than smp");
1248 if (sockets
* cores
* threads
> max_cpus
) {
1249 error_report("cpu topology: "
1250 "sockets (%u) * cores (%u) * threads (%u) > "
1252 sockets
, cores
, threads
, max_cpus
);
1258 smp_threads
= threads
;
1262 Error
*blocker
= NULL
;
1263 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1264 replay_add_blocker(blocker
);
1268 static void realtime_init(void)
1271 if (os_mlock() < 0) {
1272 error_report("locking memory failed");
1279 static void configure_msg(QemuOpts
*opts
)
1281 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1284 /***********************************************************/
1287 typedef struct SemihostingConfig
{
1289 SemihostingTarget target
;
1292 const char *cmdline
; /* concatenated argv */
1293 } SemihostingConfig
;
1295 static SemihostingConfig semihosting
;
1297 bool semihosting_enabled(void)
1299 return semihosting
.enabled
;
1302 SemihostingTarget
semihosting_get_target(void)
1304 return semihosting
.target
;
1307 const char *semihosting_get_arg(int i
)
1309 if (i
>= semihosting
.argc
) {
1312 return semihosting
.argv
[i
];
1315 int semihosting_get_argc(void)
1317 return semihosting
.argc
;
1320 const char *semihosting_get_cmdline(void)
1322 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1323 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1325 return semihosting
.cmdline
;
1328 static int add_semihosting_arg(void *opaque
,
1329 const char *name
, const char *val
,
1332 SemihostingConfig
*s
= opaque
;
1333 if (strcmp(name
, "arg") == 0) {
1335 /* one extra element as g_strjoinv() expects NULL-terminated array */
1336 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1337 s
->argv
[s
->argc
- 1] = val
;
1338 s
->argv
[s
->argc
] = NULL
;
1343 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1344 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1349 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1351 /* split -append and initialize argv[1..n] */
1352 cmd_token
= strtok(g_strdup(cmd
), " ");
1354 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1355 cmd_token
= strtok(NULL
, " ");
1359 /* Now we still need this for compatibility with XEN. */
1360 bool has_igd_gfx_passthru
;
1361 static void igd_gfx_passthru(void)
1363 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1366 /***********************************************************/
1369 static int usb_device_add(const char *devname
)
1371 USBDevice
*dev
= NULL
;
1372 #ifndef CONFIG_LINUX
1376 if (!machine_usb(current_machine
)) {
1380 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1381 dev
= usbdevice_create(devname
);
1385 /* the other ones */
1386 #ifndef CONFIG_LINUX
1387 /* only the linux version is qdev-ified, usb-bsd still needs this */
1388 if (strstart(devname
, "host:", &p
)) {
1389 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1399 static int usb_device_del(const char *devname
)
1404 if (strstart(devname
, "host:", &p
)) {
1408 if (!machine_usb(current_machine
)) {
1412 p
= strchr(devname
, '.');
1415 bus_num
= strtoul(devname
, NULL
, 0);
1416 addr
= strtoul(p
+ 1, NULL
, 0);
1418 return usb_device_delete_addr(bus_num
, addr
);
1421 static int usb_parse(const char *cmdline
)
1424 r
= usb_device_add(cmdline
);
1426 error_report("could not add USB device '%s'", cmdline
);
1431 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1433 const char *devname
= qdict_get_str(qdict
, "devname");
1434 if (usb_device_add(devname
) < 0) {
1435 error_report("could not add USB device '%s'", devname
);
1439 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1441 const char *devname
= qdict_get_str(qdict
, "devname");
1442 if (usb_device_del(devname
) < 0) {
1443 error_report("could not delete USB device '%s'", devname
);
1447 /***********************************************************/
1448 /* machine registration */
1450 MachineState
*current_machine
;
1452 static MachineClass
*find_machine(const char *name
)
1454 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1455 MachineClass
*mc
= NULL
;
1457 for (el
= machines
; el
; el
= el
->next
) {
1458 MachineClass
*temp
= el
->data
;
1460 if (!strcmp(temp
->name
, name
)) {
1465 !strcmp(temp
->alias
, name
)) {
1471 g_slist_free(machines
);
1475 MachineClass
*find_default_machine(void)
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 (temp
->is_default
) {
1489 g_slist_free(machines
);
1493 MachineInfoList
*qmp_query_machines(Error
**errp
)
1495 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1496 MachineInfoList
*mach_list
= NULL
;
1498 for (el
= machines
; el
; el
= el
->next
) {
1499 MachineClass
*mc
= el
->data
;
1500 MachineInfoList
*entry
;
1503 info
= g_malloc0(sizeof(*info
));
1504 if (mc
->is_default
) {
1505 info
->has_is_default
= true;
1506 info
->is_default
= true;
1510 info
->has_alias
= true;
1511 info
->alias
= g_strdup(mc
->alias
);
1514 info
->name
= g_strdup(mc
->name
);
1515 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1516 info
->hotpluggable_cpus
= mc
->has_hotpluggable_cpus
;
1518 entry
= g_malloc0(sizeof(*entry
));
1519 entry
->value
= info
;
1520 entry
->next
= mach_list
;
1524 g_slist_free(machines
);
1528 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1530 ObjectProperty
*prop
;
1531 ObjectPropertyIterator iter
;
1533 if (!qemu_opt_has_help_opt(opts
)) {
1537 object_property_iter_init(&iter
, OBJECT(machine
));
1538 while ((prop
= object_property_iter_next(&iter
))) {
1543 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1544 prop
->name
, prop
->type
);
1545 if (prop
->description
) {
1546 error_printf(" (%s)\n", prop
->description
);
1555 /***********************************************************/
1556 /* main execution loop */
1558 struct vm_change_state_entry
{
1559 VMChangeStateHandler
*cb
;
1561 QLIST_ENTRY (vm_change_state_entry
) entries
;
1564 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1566 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1569 VMChangeStateEntry
*e
;
1571 e
= g_malloc0(sizeof (*e
));
1575 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1579 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1581 QLIST_REMOVE (e
, entries
);
1585 void vm_state_notify(int running
, RunState state
)
1587 VMChangeStateEntry
*e
, *next
;
1589 trace_vm_state_notify(running
, state
);
1591 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1592 e
->cb(e
->opaque
, running
, state
);
1596 static int reset_requested
;
1597 static int shutdown_requested
, shutdown_signal
= -1;
1598 static pid_t shutdown_pid
;
1599 static int powerdown_requested
;
1600 static int debug_requested
;
1601 static int suspend_requested
;
1602 static WakeupReason wakeup_reason
;
1603 static NotifierList powerdown_notifiers
=
1604 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1605 static NotifierList suspend_notifiers
=
1606 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1607 static NotifierList wakeup_notifiers
=
1608 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1609 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1611 int qemu_shutdown_requested_get(void)
1613 return shutdown_requested
;
1616 int qemu_reset_requested_get(void)
1618 return reset_requested
;
1621 static int qemu_shutdown_requested(void)
1623 return atomic_xchg(&shutdown_requested
, 0);
1626 static void qemu_kill_report(void)
1628 if (!qtest_driver() && shutdown_signal
!= -1) {
1629 if (shutdown_pid
== 0) {
1630 /* This happens for eg ^C at the terminal, so it's worth
1631 * avoiding printing an odd message in that case.
1633 error_report("terminating on signal %d", shutdown_signal
);
1635 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1637 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1638 shutdown_signal
, shutdown_pid
,
1639 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1640 g_free(shutdown_cmd
);
1642 shutdown_signal
= -1;
1646 static int qemu_reset_requested(void)
1648 int r
= reset_requested
;
1649 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1650 reset_requested
= 0;
1656 static int qemu_suspend_requested(void)
1658 int r
= suspend_requested
;
1659 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1660 suspend_requested
= 0;
1666 static WakeupReason
qemu_wakeup_requested(void)
1668 return wakeup_reason
;
1671 static int qemu_powerdown_requested(void)
1673 int r
= powerdown_requested
;
1674 powerdown_requested
= 0;
1678 static int qemu_debug_requested(void)
1680 int r
= debug_requested
;
1681 debug_requested
= 0;
1685 void qemu_system_reset(bool report
)
1689 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1691 cpu_synchronize_all_states();
1693 if (mc
&& mc
->reset
) {
1696 qemu_devices_reset();
1699 qapi_event_send_reset(&error_abort
);
1701 cpu_synchronize_all_post_reset();
1704 void qemu_system_guest_panicked(GuestPanicInformation
*info
)
1706 qemu_log_mask(LOG_GUEST_ERROR
, "Guest crashed\n");
1709 current_cpu
->crash_occurred
= true;
1711 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
,
1712 !!info
, info
, &error_abort
);
1713 vm_stop(RUN_STATE_GUEST_PANICKED
);
1715 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1716 !!info
, info
, &error_abort
);
1717 qemu_system_shutdown_request();
1721 if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_HYPER_V
) {
1722 qemu_log_mask(LOG_GUEST_ERROR
, "HV crash parameters: (%#"PRIx64
1723 " %#"PRIx64
" %#"PRIx64
" %#"PRIx64
" %#"PRIx64
")\n",
1724 info
->u
.hyper_v
.arg1
,
1725 info
->u
.hyper_v
.arg2
,
1726 info
->u
.hyper_v
.arg3
,
1727 info
->u
.hyper_v
.arg4
,
1728 info
->u
.hyper_v
.arg5
);
1730 qapi_free_GuestPanicInformation(info
);
1734 void qemu_system_reset_request(void)
1737 shutdown_requested
= 1;
1739 reset_requested
= 1;
1742 qemu_notify_event();
1745 static void qemu_system_suspend(void)
1748 notifier_list_notify(&suspend_notifiers
, NULL
);
1749 runstate_set(RUN_STATE_SUSPENDED
);
1750 qapi_event_send_suspend(&error_abort
);
1753 void qemu_system_suspend_request(void)
1755 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1758 suspend_requested
= 1;
1760 qemu_notify_event();
1763 void qemu_register_suspend_notifier(Notifier
*notifier
)
1765 notifier_list_add(&suspend_notifiers
, notifier
);
1768 void qemu_system_wakeup_request(WakeupReason reason
)
1770 trace_system_wakeup_request(reason
);
1772 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1775 if (!(wakeup_reason_mask
& (1 << reason
))) {
1778 runstate_set(RUN_STATE_RUNNING
);
1779 wakeup_reason
= reason
;
1780 qemu_notify_event();
1783 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1786 wakeup_reason_mask
|= (1 << reason
);
1788 wakeup_reason_mask
&= ~(1 << reason
);
1792 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1794 notifier_list_add(&wakeup_notifiers
, notifier
);
1797 void qemu_system_killed(int signal
, pid_t pid
)
1799 shutdown_signal
= signal
;
1803 /* Cannot call qemu_system_shutdown_request directly because
1804 * we are in a signal handler.
1806 shutdown_requested
= 1;
1807 qemu_notify_event();
1810 void qemu_system_shutdown_request(void)
1812 trace_qemu_system_shutdown_request();
1813 replay_shutdown_request();
1814 shutdown_requested
= 1;
1815 qemu_notify_event();
1818 static void qemu_system_powerdown(void)
1820 qapi_event_send_powerdown(&error_abort
);
1821 notifier_list_notify(&powerdown_notifiers
, NULL
);
1824 void qemu_system_powerdown_request(void)
1826 trace_qemu_system_powerdown_request();
1827 powerdown_requested
= 1;
1828 qemu_notify_event();
1831 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1833 notifier_list_add(&powerdown_notifiers
, notifier
);
1836 void qemu_system_debug_request(void)
1838 debug_requested
= 1;
1839 qemu_notify_event();
1842 static bool main_loop_should_exit(void)
1845 if (qemu_debug_requested()) {
1846 vm_stop(RUN_STATE_DEBUG
);
1848 if (qemu_suspend_requested()) {
1849 qemu_system_suspend();
1851 if (qemu_shutdown_requested()) {
1853 qapi_event_send_shutdown(&error_abort
);
1855 vm_stop(RUN_STATE_SHUTDOWN
);
1860 if (qemu_reset_requested()) {
1862 qemu_system_reset(VMRESET_REPORT
);
1864 if (!runstate_check(RUN_STATE_RUNNING
) &&
1865 !runstate_check(RUN_STATE_INMIGRATE
)) {
1866 runstate_set(RUN_STATE_PRELAUNCH
);
1869 if (qemu_wakeup_requested()) {
1871 qemu_system_reset(VMRESET_SILENT
);
1872 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1873 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1875 qapi_event_send_wakeup(&error_abort
);
1877 if (qemu_powerdown_requested()) {
1878 qemu_system_powerdown();
1880 if (qemu_vmstop_requested(&r
)) {
1886 static void main_loop(void)
1890 #ifdef CONFIG_PROFILER
1894 nonblocking
= tcg_enabled() && last_io
> 0;
1895 #ifdef CONFIG_PROFILER
1896 ti
= profile_getclock();
1898 last_io
= main_loop_wait(nonblocking
);
1899 #ifdef CONFIG_PROFILER
1900 dev_time
+= profile_getclock() - ti
;
1902 } while (!main_loop_should_exit());
1905 static void version(void)
1907 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1908 QEMU_COPYRIGHT
"\n");
1911 static void help(int exitcode
)
1914 printf("usage: %s [options] [disk_image]\n\n"
1915 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1916 error_get_progname());
1918 #define QEMU_OPTIONS_GENERATE_HELP
1919 #include "qemu-options-wrapper.h"
1921 printf("\nDuring emulation, the following keys are useful:\n"
1922 "ctrl-alt-f toggle full screen\n"
1923 "ctrl-alt-n switch to virtual console 'n'\n"
1924 "ctrl-alt toggle mouse and keyboard grab\n"
1926 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1931 #define HAS_ARG 0x0001
1933 typedef struct QEMUOption
{
1940 static const QEMUOption qemu_options
[] = {
1941 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1942 #define QEMU_OPTIONS_GENERATE_OPTIONS
1943 #include "qemu-options-wrapper.h"
1947 typedef struct VGAInterfaceInfo
{
1948 const char *opt_name
; /* option name */
1949 const char *name
; /* human-readable name */
1950 /* Class names indicating that support is available.
1951 * If no class is specified, the interface is always available */
1952 const char *class_names
[2];
1955 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1961 .name
= "standard VGA",
1962 .class_names
= { "VGA", "isa-vga" },
1965 .opt_name
= "cirrus",
1966 .name
= "Cirrus VGA",
1967 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1970 .opt_name
= "vmware",
1971 .name
= "VMWare SVGA",
1972 .class_names
= { "vmware-svga" },
1975 .opt_name
= "virtio",
1976 .name
= "Virtio VGA",
1977 .class_names
= { "virtio-vga" },
1982 .class_names
= { "qxl-vga" },
1986 .name
= "TCX framebuffer",
1987 .class_names
= { "SUNW,tcx" },
1991 .name
= "CG3 framebuffer",
1992 .class_names
= { "cgthree" },
1995 .opt_name
= "xenfb",
1999 static bool vga_interface_available(VGAInterfaceType t
)
2001 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2003 assert(t
< VGA_TYPE_MAX
);
2004 return !ti
->class_names
[0] ||
2005 object_class_by_name(ti
->class_names
[0]) ||
2006 object_class_by_name(ti
->class_names
[1]);
2009 static void select_vgahw(const char *p
)
2014 assert(vga_interface_type
== VGA_NONE
);
2015 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2016 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2017 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2018 if (!vga_interface_available(t
)) {
2019 error_report("%s not available", ti
->name
);
2022 vga_interface_type
= t
;
2026 if (t
== VGA_TYPE_MAX
) {
2028 error_report("unknown vga type: %s", p
);
2032 const char *nextopt
;
2034 if (strstart(opts
, ",retrace=", &nextopt
)) {
2036 if (strstart(opts
, "dumb", &nextopt
))
2037 vga_retrace_method
= VGA_RETRACE_DUMB
;
2038 else if (strstart(opts
, "precise", &nextopt
))
2039 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2040 else goto invalid_vga
;
2041 } else goto invalid_vga
;
2046 typedef enum DisplayType
{
2055 static DisplayType
select_display(const char *p
)
2058 DisplayType display
= DT_DEFAULT
;
2060 if (strstart(p
, "sdl", &opts
)) {
2064 const char *nextopt
;
2066 if (strstart(opts
, ",frame=", &nextopt
)) {
2068 if (strstart(opts
, "on", &nextopt
)) {
2070 } else if (strstart(opts
, "off", &nextopt
)) {
2073 goto invalid_sdl_args
;
2075 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2077 if (strstart(opts
, "on", &nextopt
)) {
2079 } else if (strstart(opts
, "off", &nextopt
)) {
2082 goto invalid_sdl_args
;
2084 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2086 if (strstart(opts
, "on", &nextopt
)) {
2088 } else if (strstart(opts
, "off", &nextopt
)) {
2091 goto invalid_sdl_args
;
2093 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2095 if (strstart(opts
, "on", &nextopt
)) {
2097 } else if (strstart(opts
, "off", &nextopt
)) {
2100 goto invalid_sdl_args
;
2102 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2104 if (strstart(opts
, "on", &nextopt
)) {
2106 } else if (strstart(opts
, "off", &nextopt
)) {
2109 goto invalid_sdl_args
;
2113 error_report("invalid SDL option string");
2119 error_report("SDL support is disabled");
2122 } else if (strstart(p
, "vnc", &opts
)) {
2124 vnc_parse(opts
+ 1, &error_fatal
);
2126 error_report("VNC requires a display argument vnc=<display>");
2129 } else if (strstart(p
, "curses", &opts
)) {
2130 #ifdef CONFIG_CURSES
2131 display
= DT_CURSES
;
2133 error_report("curses support is disabled");
2136 } else if (strstart(p
, "gtk", &opts
)) {
2140 const char *nextopt
;
2142 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2144 if (strstart(opts
, "on", &nextopt
)) {
2145 grab_on_hover
= true;
2146 } else if (strstart(opts
, "off", &nextopt
)) {
2147 grab_on_hover
= false;
2149 goto invalid_gtk_args
;
2151 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2153 if (strstart(opts
, "on", &nextopt
)) {
2155 } else if (strstart(opts
, "off", &nextopt
)) {
2158 goto invalid_gtk_args
;
2162 error_report("invalid GTK option string");
2168 error_report("GTK support is disabled");
2171 } else if (strstart(p
, "none", &opts
)) {
2174 error_report("unknown display type");
2181 static int balloon_parse(const char *arg
)
2185 if (strcmp(arg
, "none") == 0) {
2189 if (!strncmp(arg
, "virtio", 6)) {
2190 if (arg
[6] == ',') {
2191 /* have params -> parse them */
2192 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2197 /* create empty opts */
2198 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2201 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2208 char *qemu_find_file(int type
, const char *name
)
2214 /* Try the name as a straight path first */
2215 if (access(name
, R_OK
) == 0) {
2216 trace_load_file(name
, name
);
2217 return g_strdup(name
);
2221 case QEMU_FILE_TYPE_BIOS
:
2224 case QEMU_FILE_TYPE_KEYMAP
:
2225 subdir
= "keymaps/";
2231 for (i
= 0; i
< data_dir_idx
; i
++) {
2232 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2233 if (access(buf
, R_OK
) == 0) {
2234 trace_load_file(name
, buf
);
2242 static inline bool nonempty_str(const char *str
)
2247 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2251 const char *name
, *file
, *str
;
2252 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2254 if (fw_cfg
== NULL
) {
2255 error_report("fw_cfg device not available");
2258 name
= qemu_opt_get(opts
, "name");
2259 file
= qemu_opt_get(opts
, "file");
2260 str
= qemu_opt_get(opts
, "string");
2262 /* we need name and either a file or the content string */
2263 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2264 error_report("invalid argument(s)");
2267 if (nonempty_str(file
) && nonempty_str(str
)) {
2268 error_report("file and string are mutually exclusive");
2271 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2272 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2275 if (strncmp(name
, "opt/", 4) != 0) {
2276 error_report("warning: externally provided fw_cfg item names "
2277 "should be prefixed with \"opt/\"");
2279 if (nonempty_str(str
)) {
2280 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2281 buf
= g_memdup(str
, size
);
2283 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2284 error_report("can't load %s", file
);
2288 /* For legacy, keep user files in a specific global order. */
2289 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2290 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2291 fw_cfg_reset_order_override(fw_cfg
);
2295 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2297 return qdev_device_help(opts
);
2300 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2305 dev
= qdev_device_add(opts
, &err
);
2307 error_report_err(err
);
2310 object_unref(OBJECT(dev
));
2314 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2316 Error
*local_err
= NULL
;
2318 qemu_chr_new_from_opts(opts
, &local_err
);
2320 error_report_err(local_err
);
2326 #ifdef CONFIG_VIRTFS
2327 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2329 return qemu_fsdev_add(opts
);
2333 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2336 const char *chardev
;
2340 mode
= qemu_opt_get(opts
, "mode");
2344 if (strcmp(mode
, "readline") == 0) {
2345 flags
= MONITOR_USE_READLINE
;
2346 } else if (strcmp(mode
, "control") == 0) {
2347 flags
= MONITOR_USE_CONTROL
;
2349 error_report("unknown monitor mode \"%s\"", mode
);
2353 if (qemu_opt_get_bool(opts
, "pretty", 0))
2354 flags
|= MONITOR_USE_PRETTY
;
2356 if (qemu_opt_get_bool(opts
, "default", 0)) {
2357 error_report("option 'default' does nothing and is deprecated");
2360 chardev
= qemu_opt_get(opts
, "chardev");
2361 chr
= qemu_chr_find(chardev
);
2363 error_report("chardev \"%s\" not found", chardev
);
2367 monitor_init(chr
, flags
);
2371 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2373 static int monitor_device_index
= 0;
2378 if (strstart(optarg
, "chardev:", &p
)) {
2379 snprintf(label
, sizeof(label
), "%s", p
);
2381 snprintf(label
, sizeof(label
), "compat_monitor%d",
2382 monitor_device_index
);
2383 opts
= qemu_chr_parse_compat(label
, optarg
);
2385 error_report("parse error: %s", optarg
);
2390 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2391 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2392 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2393 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2394 monitor_device_index
++;
2397 struct device_config
{
2399 DEV_USB
, /* -usbdevice */
2401 DEV_SERIAL
, /* -serial */
2402 DEV_PARALLEL
, /* -parallel */
2403 DEV_VIRTCON
, /* -virtioconsole */
2404 DEV_DEBUGCON
, /* -debugcon */
2405 DEV_GDB
, /* -gdb, -s */
2406 DEV_SCLP
, /* s390 sclp */
2408 const char *cmdline
;
2410 QTAILQ_ENTRY(device_config
) next
;
2413 static QTAILQ_HEAD(, device_config
) device_configs
=
2414 QTAILQ_HEAD_INITIALIZER(device_configs
);
2416 static void add_device_config(int type
, const char *cmdline
)
2418 struct device_config
*conf
;
2420 conf
= g_malloc0(sizeof(*conf
));
2422 conf
->cmdline
= cmdline
;
2423 loc_save(&conf
->loc
);
2424 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2427 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2429 struct device_config
*conf
;
2432 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2433 if (conf
->type
!= type
)
2435 loc_push_restore(&conf
->loc
);
2436 rc
= func(conf
->cmdline
);
2437 loc_pop(&conf
->loc
);
2445 static int serial_parse(const char *devname
)
2447 static int index
= 0;
2450 if (strcmp(devname
, "none") == 0)
2452 if (index
== MAX_SERIAL_PORTS
) {
2453 error_report("too many serial ports");
2456 snprintf(label
, sizeof(label
), "serial%d", index
);
2457 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2458 if (!serial_hds
[index
]) {
2459 error_report("could not connect serial device"
2460 " to character backend '%s'", devname
);
2467 static int parallel_parse(const char *devname
)
2469 static int index
= 0;
2472 if (strcmp(devname
, "none") == 0)
2474 if (index
== MAX_PARALLEL_PORTS
) {
2475 error_report("too many parallel ports");
2478 snprintf(label
, sizeof(label
), "parallel%d", index
);
2479 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2480 if (!parallel_hds
[index
]) {
2481 error_report("could not connect parallel device"
2482 " to character backend '%s'", devname
);
2489 static int virtcon_parse(const char *devname
)
2491 QemuOptsList
*device
= qemu_find_opts("device");
2492 static int index
= 0;
2494 QemuOpts
*bus_opts
, *dev_opts
;
2496 if (strcmp(devname
, "none") == 0)
2498 if (index
== MAX_VIRTIO_CONSOLES
) {
2499 error_report("too many virtio consoles");
2503 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2504 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2506 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2507 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2509 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2510 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2511 if (!virtcon_hds
[index
]) {
2512 error_report("could not connect virtio console"
2513 " to character backend '%s'", devname
);
2516 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2522 static int sclp_parse(const char *devname
)
2524 QemuOptsList
*device
= qemu_find_opts("device");
2525 static int index
= 0;
2529 if (strcmp(devname
, "none") == 0) {
2532 if (index
== MAX_SCLP_CONSOLES
) {
2533 error_report("too many sclp consoles");
2537 assert(arch_type
== QEMU_ARCH_S390X
);
2539 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2540 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2542 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2543 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2544 if (!sclp_hds
[index
]) {
2545 error_report("could not connect sclp console"
2546 " to character backend '%s'", devname
);
2549 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2555 static int debugcon_parse(const char *devname
)
2559 if (!qemu_chr_new("debugcon", devname
)) {
2562 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2564 error_report("already have a debugcon device");
2567 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2568 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2572 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2574 const MachineClass
*mc1
= a
, *mc2
= b
;
2577 if (mc1
->family
== NULL
) {
2578 if (mc2
->family
== NULL
) {
2579 /* Compare standalone machine types against each other; they sort
2580 * in increasing order.
2582 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2583 object_class_get_name(OBJECT_CLASS(mc2
)));
2586 /* Standalone machine types sort after families. */
2590 if (mc2
->family
== NULL
) {
2591 /* Families sort before standalone machine types. */
2595 /* Families sort between each other alphabetically increasingly. */
2596 res
= strcmp(mc1
->family
, mc2
->family
);
2601 /* Within the same family, machine types sort in decreasing order. */
2602 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2603 object_class_get_name(OBJECT_CLASS(mc1
)));
2606 static MachineClass
*machine_parse(const char *name
)
2608 MachineClass
*mc
= NULL
;
2609 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2612 mc
= find_machine(name
);
2615 g_slist_free(machines
);
2618 if (name
&& !is_help_option(name
)) {
2619 error_report("unsupported machine type");
2620 error_printf("Use -machine help to list supported machines\n");
2622 printf("Supported machines are:\n");
2623 machines
= g_slist_sort(machines
, machine_class_cmp
);
2624 for (el
= machines
; el
; el
= el
->next
) {
2625 MachineClass
*mc
= el
->data
;
2627 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2629 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2630 mc
->is_default
? " (default)" : "");
2634 g_slist_free(machines
);
2635 exit(!name
|| !is_help_option(name
));
2638 void qemu_add_exit_notifier(Notifier
*notify
)
2640 notifier_list_add(&exit_notifiers
, notify
);
2643 void qemu_remove_exit_notifier(Notifier
*notify
)
2645 notifier_remove(notify
);
2648 static void qemu_run_exit_notifiers(void)
2650 notifier_list_notify(&exit_notifiers
, NULL
);
2653 static bool machine_init_done
;
2655 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2657 notifier_list_add(&machine_init_done_notifiers
, notify
);
2658 if (machine_init_done
) {
2659 notify
->notify(notify
, NULL
);
2663 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2665 notifier_remove(notify
);
2668 static void qemu_run_machine_init_done_notifiers(void)
2670 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2671 machine_init_done
= true;
2674 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2675 const char **poptarg
, int *poptind
)
2677 const QEMUOption
*popt
;
2678 int optind
= *poptind
;
2679 char *r
= argv
[optind
];
2682 loc_set_cmdline(argv
, optind
, 1);
2684 /* Treat --foo the same as -foo. */
2687 popt
= qemu_options
;
2690 error_report("invalid option");
2693 if (!strcmp(popt
->name
, r
+ 1))
2697 if (popt
->flags
& HAS_ARG
) {
2698 if (optind
>= argc
) {
2699 error_report("requires an argument");
2702 optarg
= argv
[optind
++];
2703 loc_set_cmdline(argv
, optind
- 2, 2);
2714 static MachineClass
*select_machine(void)
2716 MachineClass
*machine_class
= find_default_machine();
2721 loc_push_none(&loc
);
2723 opts
= qemu_get_machine_opts();
2724 qemu_opts_loc_restore(opts
);
2726 optarg
= qemu_opt_get(opts
, "type");
2728 machine_class
= machine_parse(optarg
);
2731 if (!machine_class
) {
2732 error_report("No machine specified, and there is no default");
2733 error_printf("Use -machine help to list supported machines\n");
2738 return machine_class
;
2741 static int machine_set_property(void *opaque
,
2742 const char *name
, const char *value
,
2745 Object
*obj
= OBJECT(opaque
);
2746 Error
*local_err
= NULL
;
2749 if (strcmp(name
, "type") == 0) {
2753 qom_name
= g_strdup(name
);
2754 for (p
= qom_name
; *p
; p
++) {
2760 object_property_parse(obj
, value
, qom_name
, &local_err
);
2764 error_report_err(local_err
);
2773 * Initial object creation happens before all other
2774 * QEMU data types are created. The majority of objects
2775 * can be created at this point. The rng-egd object
2776 * cannot be created here, as it depends on the chardev
2779 static bool object_create_initial(const char *type
)
2781 if (g_str_equal(type
, "rng-egd")) {
2786 * return false for concrete netfilters since
2787 * they depend on netdevs already existing
2789 if (g_str_equal(type
, "filter-buffer") ||
2790 g_str_equal(type
, "filter-dump") ||
2791 g_str_equal(type
, "filter-mirror") ||
2792 g_str_equal(type
, "filter-redirector") ||
2793 g_str_equal(type
, "colo-compare") ||
2794 g_str_equal(type
, "filter-rewriter") ||
2795 g_str_equal(type
, "filter-replay")) {
2799 /* Memory allocation by backends needs to be done
2800 * after configure_accelerator() (due to the tcg_enabled()
2801 * checks at memory_region_init_*()).
2803 * Also, allocation of large amounts of memory may delay
2804 * chardev initialization for too long, and trigger timeouts
2805 * on software that waits for a monitor socket to be created
2808 if (g_str_has_prefix(type
, "memory-backend-")) {
2817 * The remainder of object creation happens after the
2818 * creation of chardev, fsdev, net clients and device data types.
2820 static bool object_create_delayed(const char *type
)
2822 return !object_create_initial(type
);
2826 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2830 const char *mem_str
;
2831 const char *maxmem_str
, *slots_str
;
2832 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2833 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2836 loc_push_none(&loc
);
2837 qemu_opts_loc_restore(opts
);
2840 mem_str
= qemu_opt_get(opts
, "size");
2843 error_report("missing 'size' option value");
2847 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2849 /* Fix up legacy suffix-less format */
2850 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2851 uint64_t overflow_check
= sz
;
2854 if ((sz
>> 20) != overflow_check
) {
2855 error_report("too large 'size' option value");
2861 /* backward compatibility behaviour for case "-m 0" */
2863 sz
= default_ram_size
;
2866 sz
= QEMU_ALIGN_UP(sz
, 8192);
2868 if (ram_size
!= sz
) {
2869 error_report("ram size too large");
2873 /* store value for the future use */
2874 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2875 *maxram_size
= ram_size
;
2877 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2878 slots_str
= qemu_opt_get(opts
, "slots");
2879 if (maxmem_str
&& slots_str
) {
2882 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2883 slots
= qemu_opt_get_number(opts
, "slots", 0);
2884 if (sz
< ram_size
) {
2885 error_report("invalid value of -m option maxmem: "
2886 "maximum memory size (0x%" PRIx64
") must be at least "
2887 "the initial memory size (0x" RAM_ADDR_FMT
")",
2890 } else if (sz
> ram_size
) {
2892 error_report("invalid value of -m option: maxmem was "
2893 "specified, but no hotplug slots were specified");
2897 error_report("invalid value of -m option maxmem: "
2898 "memory slots were specified but maximum memory size "
2899 "(0x%" PRIx64
") is equal to the initial memory size "
2900 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2906 } else if ((!maxmem_str
&& slots_str
) ||
2907 (maxmem_str
&& !slots_str
)) {
2908 error_report("invalid -m option value: missing "
2909 "'%s' option", slots_str
? "maxmem" : "slots");
2916 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2920 g
= g_malloc0(sizeof(*g
));
2921 g
->driver
= qemu_opt_get(opts
, "driver");
2922 g
->property
= qemu_opt_get(opts
, "property");
2923 g
->value
= qemu_opt_get(opts
, "value");
2924 g
->user_provided
= true;
2925 g
->errp
= &error_fatal
;
2926 qdev_prop_register_global(g
);
2930 static int qemu_read_default_config_file(void)
2934 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2935 if (ret
< 0 && ret
!= -ENOENT
) {
2942 int main(int argc
, char **argv
, char **envp
)
2945 int snapshot
, linux_boot
;
2946 const char *initrd_filename
;
2947 const char *kernel_filename
, *kernel_cmdline
;
2948 const char *boot_order
= NULL
;
2949 const char *boot_once
= NULL
;
2951 int cyls
, heads
, secs
, translation
;
2952 QemuOpts
*opts
, *machine_opts
;
2953 QemuOpts
*hda_opts
= NULL
, *icount_opts
= NULL
, *accel_opts
= NULL
;
2954 QemuOptsList
*olist
;
2957 const char *loadvm
= NULL
;
2958 MachineClass
*machine_class
;
2959 const char *cpu_model
;
2960 const char *vga_model
= NULL
;
2961 const char *qtest_chrdev
= NULL
;
2962 const char *qtest_log
= NULL
;
2963 const char *pid_file
= NULL
;
2964 const char *incoming
= NULL
;
2965 bool defconfig
= true;
2966 bool userconfig
= true;
2967 bool nographic
= false;
2968 DisplayType display_type
= DT_DEFAULT
;
2969 int display_remote
= 0;
2970 const char *log_mask
= NULL
;
2971 const char *log_file
= NULL
;
2972 char *trace_file
= NULL
;
2973 ram_addr_t maxram_size
;
2974 uint64_t ram_slots
= 0;
2975 FILE *vmstate_dump_file
= NULL
;
2976 Error
*main_loop_err
= NULL
;
2978 bool list_data_dirs
= false;
2980 module_call_init(MODULE_INIT_TRACE
);
2982 qemu_init_cpu_list();
2983 qemu_init_cpu_loop();
2984 qemu_mutex_lock_iothread();
2986 atexit(qemu_run_exit_notifiers
);
2987 error_set_progname(argv
[0]);
2988 qemu_init_exec_dir(argv
[0]);
2990 module_call_init(MODULE_INIT_QOM
);
2991 module_call_init(MODULE_INIT_QAPI
);
2993 qemu_add_opts(&qemu_drive_opts
);
2994 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2995 qemu_add_drive_opts(&qemu_common_drive_opts
);
2996 qemu_add_drive_opts(&qemu_drive_opts
);
2997 qemu_add_drive_opts(&bdrv_runtime_opts
);
2998 qemu_add_opts(&qemu_chardev_opts
);
2999 qemu_add_opts(&qemu_device_opts
);
3000 qemu_add_opts(&qemu_netdev_opts
);
3001 qemu_add_opts(&qemu_net_opts
);
3002 qemu_add_opts(&qemu_rtc_opts
);
3003 qemu_add_opts(&qemu_global_opts
);
3004 qemu_add_opts(&qemu_mon_opts
);
3005 qemu_add_opts(&qemu_trace_opts
);
3006 qemu_add_opts(&qemu_option_rom_opts
);
3007 qemu_add_opts(&qemu_machine_opts
);
3008 qemu_add_opts(&qemu_accel_opts
);
3009 qemu_add_opts(&qemu_mem_opts
);
3010 qemu_add_opts(&qemu_smp_opts
);
3011 qemu_add_opts(&qemu_boot_opts
);
3012 qemu_add_opts(&qemu_sandbox_opts
);
3013 qemu_add_opts(&qemu_add_fd_opts
);
3014 qemu_add_opts(&qemu_object_opts
);
3015 qemu_add_opts(&qemu_tpmdev_opts
);
3016 qemu_add_opts(&qemu_realtime_opts
);
3017 qemu_add_opts(&qemu_msg_opts
);
3018 qemu_add_opts(&qemu_name_opts
);
3019 qemu_add_opts(&qemu_numa_opts
);
3020 qemu_add_opts(&qemu_icount_opts
);
3021 qemu_add_opts(&qemu_semihosting_config_opts
);
3022 qemu_add_opts(&qemu_fw_cfg_opts
);
3023 module_call_init(MODULE_INIT_OPTS
);
3027 if (qcrypto_init(&err
) < 0) {
3028 error_reportf_err(err
, "cannot initialize crypto: ");
3031 rtc_clock
= QEMU_CLOCK_HOST
;
3033 QLIST_INIT (&vm_change_state_head
);
3034 os_setup_early_signal_handling();
3038 cyls
= heads
= secs
= 0;
3039 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3043 bdrv_init_with_whitelist();
3047 /* first pass of option parsing */
3049 while (optind
< argc
) {
3050 if (argv
[optind
][0] != '-') {
3054 const QEMUOption
*popt
;
3056 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3057 switch (popt
->index
) {
3058 case QEMU_OPTION_nodefconfig
:
3061 case QEMU_OPTION_nouserconfig
:
3068 if (defconfig
&& userconfig
) {
3069 if (qemu_read_default_config_file() < 0) {
3074 /* second pass of option parsing */
3079 if (argv
[optind
][0] != '-') {
3080 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3082 const QEMUOption
*popt
;
3084 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3085 if (!(popt
->arch_mask
& arch_type
)) {
3086 error_report("Option not supported for this target");
3089 switch(popt
->index
) {
3090 case QEMU_OPTION_no_kvm_irqchip
: {
3091 olist
= qemu_find_opts("machine");
3092 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3095 case QEMU_OPTION_cpu
:
3096 /* hw initialization will check this */
3099 case QEMU_OPTION_hda
:
3103 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3105 snprintf(buf
, sizeof(buf
),
3106 "%s,cyls=%d,heads=%d,secs=%d%s",
3107 HD_OPTS
, cyls
, heads
, secs
,
3108 translation
== BIOS_ATA_TRANSLATION_LBA
?
3110 translation
== BIOS_ATA_TRANSLATION_NONE
?
3111 ",trans=none" : "");
3112 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3115 case QEMU_OPTION_hdb
:
3116 case QEMU_OPTION_hdc
:
3117 case QEMU_OPTION_hdd
:
3118 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3121 case QEMU_OPTION_drive
:
3122 if (drive_def(optarg
) == NULL
) {
3126 case QEMU_OPTION_set
:
3127 if (qemu_set_option(optarg
) != 0)
3130 case QEMU_OPTION_global
:
3131 if (qemu_global_option(optarg
) != 0)
3134 case QEMU_OPTION_mtdblock
:
3135 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3137 case QEMU_OPTION_sd
:
3138 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3140 case QEMU_OPTION_pflash
:
3141 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3143 case QEMU_OPTION_snapshot
:
3146 case QEMU_OPTION_hdachs
:
3150 cyls
= strtol(p
, (char **)&p
, 0);
3151 if (cyls
< 1 || cyls
> 16383)
3156 heads
= strtol(p
, (char **)&p
, 0);
3157 if (heads
< 1 || heads
> 16)
3162 secs
= strtol(p
, (char **)&p
, 0);
3163 if (secs
< 1 || secs
> 63)
3167 if (!strcmp(p
, "large")) {
3168 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3169 } else if (!strcmp(p
, "rechs")) {
3170 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3171 } else if (!strcmp(p
, "none")) {
3172 translation
= BIOS_ATA_TRANSLATION_NONE
;
3173 } else if (!strcmp(p
, "lba")) {
3174 translation
= BIOS_ATA_TRANSLATION_LBA
;
3175 } else if (!strcmp(p
, "auto")) {
3176 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3180 } else if (*p
!= '\0') {
3182 error_report("invalid physical CHS format");
3185 if (hda_opts
!= NULL
) {
3186 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3188 qemu_opt_set_number(hda_opts
, "heads", heads
,
3190 qemu_opt_set_number(hda_opts
, "secs", secs
,
3192 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3193 qemu_opt_set(hda_opts
, "trans", "large",
3195 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3196 qemu_opt_set(hda_opts
, "trans", "rechs",
3198 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3199 qemu_opt_set(hda_opts
, "trans", "lba",
3201 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3202 qemu_opt_set(hda_opts
, "trans", "none",
3208 case QEMU_OPTION_numa
:
3209 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3215 case QEMU_OPTION_display
:
3216 display_type
= select_display(optarg
);
3218 case QEMU_OPTION_nographic
:
3219 olist
= qemu_find_opts("machine");
3220 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3222 display_type
= DT_NONE
;
3224 case QEMU_OPTION_curses
:
3225 #ifdef CONFIG_CURSES
3226 display_type
= DT_CURSES
;
3228 error_report("curses support is disabled");
3232 case QEMU_OPTION_portrait
:
3233 graphic_rotate
= 90;
3235 case QEMU_OPTION_rotate
:
3236 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3237 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3238 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3239 error_report("only 90, 180, 270 deg rotation is available");
3243 case QEMU_OPTION_kernel
:
3244 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3247 case QEMU_OPTION_initrd
:
3248 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3251 case QEMU_OPTION_append
:
3252 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3255 case QEMU_OPTION_dtb
:
3256 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3259 case QEMU_OPTION_cdrom
:
3260 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3262 case QEMU_OPTION_boot
:
3263 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3269 case QEMU_OPTION_fda
:
3270 case QEMU_OPTION_fdb
:
3271 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3274 case QEMU_OPTION_no_fd_bootchk
:
3277 case QEMU_OPTION_netdev
:
3279 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3283 case QEMU_OPTION_net
:
3285 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3289 #ifdef CONFIG_LIBISCSI
3290 case QEMU_OPTION_iscsi
:
3291 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3299 case QEMU_OPTION_tftp
:
3300 error_report("The -tftp option is deprecated. "
3301 "Please use '-netdev user,tftp=...' instead.");
3302 legacy_tftp_prefix
= optarg
;
3304 case QEMU_OPTION_bootp
:
3305 error_report("The -bootp option is deprecated. "
3306 "Please use '-netdev user,bootfile=...' instead.");
3307 legacy_bootp_filename
= optarg
;
3309 case QEMU_OPTION_redir
:
3310 error_report("The -redir option is deprecated. "
3311 "Please use '-netdev user,hostfwd=...' instead.");
3312 if (net_slirp_redir(optarg
) < 0)
3316 case QEMU_OPTION_bt
:
3317 add_device_config(DEV_BT
, optarg
);
3319 case QEMU_OPTION_audio_help
:
3323 case QEMU_OPTION_soundhw
:
3324 select_soundhw (optarg
);
3329 case QEMU_OPTION_version
:
3334 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3341 case QEMU_OPTION_tpmdev
:
3342 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3347 case QEMU_OPTION_mempath
:
3350 case QEMU_OPTION_mem_prealloc
:
3359 case QEMU_OPTION_DFILTER
:
3360 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3363 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3365 case QEMU_OPTION_gdb
:
3366 add_device_config(DEV_GDB
, optarg
);
3369 if (is_help_option(optarg
)) {
3370 list_data_dirs
= true;
3371 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3372 data_dir
[data_dir_idx
++] = optarg
;
3375 case QEMU_OPTION_bios
:
3376 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3379 case QEMU_OPTION_singlestep
:
3386 keyboard_layout
= optarg
;
3388 case QEMU_OPTION_localtime
:
3391 case QEMU_OPTION_vga
:
3400 w
= strtol(p
, (char **)&p
, 10);
3403 error_report("invalid resolution or depth");
3409 h
= strtol(p
, (char **)&p
, 10);
3414 depth
= strtol(p
, (char **)&p
, 10);
3415 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3416 depth
!= 24 && depth
!= 32)
3418 } else if (*p
== '\0') {
3419 depth
= graphic_depth
;
3426 graphic_depth
= depth
;
3429 case QEMU_OPTION_echr
:
3432 term_escape_char
= strtol(optarg
, &r
, 0);
3434 printf("Bad argument to echr\n");
3437 case QEMU_OPTION_monitor
:
3438 default_monitor
= 0;
3439 if (strncmp(optarg
, "none", 4)) {
3440 monitor_parse(optarg
, "readline", false);
3443 case QEMU_OPTION_qmp
:
3444 monitor_parse(optarg
, "control", false);
3445 default_monitor
= 0;
3447 case QEMU_OPTION_qmp_pretty
:
3448 monitor_parse(optarg
, "control", true);
3449 default_monitor
= 0;
3451 case QEMU_OPTION_mon
:
3452 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3457 default_monitor
= 0;
3459 case QEMU_OPTION_chardev
:
3460 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3466 case QEMU_OPTION_fsdev
:
3467 olist
= qemu_find_opts("fsdev");
3469 error_report("fsdev support is disabled");
3472 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3477 case QEMU_OPTION_virtfs
: {
3480 const char *writeout
, *sock_fd
, *socket
;
3482 olist
= qemu_find_opts("virtfs");
3484 error_report("virtfs support is disabled");
3487 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3492 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3493 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3494 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3497 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3498 qemu_opt_get(opts
, "mount_tag"),
3501 error_report("duplicate fsdev id: %s",
3502 qemu_opt_get(opts
, "mount_tag"));
3506 writeout
= qemu_opt_get(opts
, "writeout");
3508 #ifdef CONFIG_SYNC_FILE_RANGE
3509 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3511 error_report("writeout=immediate not supported "
3512 "on this platform");
3516 qemu_opt_set(fsdev
, "fsdriver",
3517 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3518 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3520 qemu_opt_set(fsdev
, "security_model",
3521 qemu_opt_get(opts
, "security_model"),
3523 socket
= qemu_opt_get(opts
, "socket");
3525 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3527 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3529 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3532 qemu_opt_set_bool(fsdev
, "readonly",
3533 qemu_opt_get_bool(opts
, "readonly", 0),
3535 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3537 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3538 qemu_opt_set(device
, "fsdev",
3539 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3540 qemu_opt_set(device
, "mount_tag",
3541 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3544 case QEMU_OPTION_virtfs_synth
: {
3548 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3551 error_report("duplicate option: %s", "virtfs_synth");
3554 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3556 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3558 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3559 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3560 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3563 case QEMU_OPTION_serial
:
3564 add_device_config(DEV_SERIAL
, optarg
);
3566 if (strncmp(optarg
, "mon:", 4) == 0) {
3567 default_monitor
= 0;
3570 case QEMU_OPTION_watchdog
:
3572 error_report("only one watchdog option may be given");
3577 case QEMU_OPTION_watchdog_action
:
3578 if (select_watchdog_action(optarg
) == -1) {
3579 error_report("unknown -watchdog-action parameter");
3583 case QEMU_OPTION_virtiocon
:
3584 add_device_config(DEV_VIRTCON
, optarg
);
3585 default_virtcon
= 0;
3586 if (strncmp(optarg
, "mon:", 4) == 0) {
3587 default_monitor
= 0;
3590 case QEMU_OPTION_parallel
:
3591 add_device_config(DEV_PARALLEL
, optarg
);
3592 default_parallel
= 0;
3593 if (strncmp(optarg
, "mon:", 4) == 0) {
3594 default_monitor
= 0;
3597 case QEMU_OPTION_debugcon
:
3598 add_device_config(DEV_DEBUGCON
, optarg
);
3600 case QEMU_OPTION_loadvm
:
3603 case QEMU_OPTION_full_screen
:
3606 case QEMU_OPTION_no_frame
:
3609 case QEMU_OPTION_alt_grab
:
3612 case QEMU_OPTION_ctrl_grab
:
3615 case QEMU_OPTION_no_quit
:
3618 case QEMU_OPTION_sdl
:
3620 display_type
= DT_SDL
;
3623 error_report("SDL support is disabled");
3626 case QEMU_OPTION_pidfile
:
3629 case QEMU_OPTION_win2k_hack
:
3630 win2k_install_hack
= 1;
3632 case QEMU_OPTION_rtc_td_hack
: {
3633 static GlobalProperty slew_lost_ticks
= {
3634 .driver
= "mc146818rtc",
3635 .property
= "lost_tick_policy",
3639 qdev_prop_register_global(&slew_lost_ticks
);
3642 case QEMU_OPTION_acpitable
:
3643 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3648 acpi_table_add(opts
, &error_fatal
);
3650 case QEMU_OPTION_smbios
:
3651 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3656 smbios_entry_add(opts
, &error_fatal
);
3658 case QEMU_OPTION_fwcfg
:
3659 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3665 case QEMU_OPTION_enable_kvm
:
3666 olist
= qemu_find_opts("machine");
3667 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3669 case QEMU_OPTION_enable_hax
:
3670 olist
= qemu_find_opts("machine");
3671 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3674 case QEMU_OPTION_machine
:
3675 olist
= qemu_find_opts("machine");
3676 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3681 case QEMU_OPTION_no_kvm
:
3682 olist
= qemu_find_opts("machine");
3683 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3685 case QEMU_OPTION_no_kvm_pit
: {
3686 error_report("warning: ignoring deprecated option");
3689 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3690 static GlobalProperty kvm_pit_lost_tick_policy
= {
3691 .driver
= "kvm-pit",
3692 .property
= "lost_tick_policy",
3696 error_report("warning: deprecated, replaced by "
3697 "-global kvm-pit.lost_tick_policy=discard");
3698 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3701 case QEMU_OPTION_accel
:
3702 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3704 optarg
= qemu_opt_get(accel_opts
, "accel");
3706 olist
= qemu_find_opts("machine");
3707 if (strcmp("kvm", optarg
) == 0) {
3708 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3709 } else if (strcmp("xen", optarg
) == 0) {
3710 qemu_opts_parse_noisily(olist
, "accel=xen", false);
3711 } else if (strcmp("tcg", optarg
) == 0) {
3712 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3714 if (!is_help_option(optarg
)) {
3715 error_printf("Unknown accelerator: %s", optarg
);
3717 error_printf("Supported accelerators: kvm, xen, tcg\n");
3721 case QEMU_OPTION_usb
:
3722 olist
= qemu_find_opts("machine");
3723 qemu_opts_parse_noisily(olist
, "usb=on", false);
3725 case QEMU_OPTION_usbdevice
:
3726 olist
= qemu_find_opts("machine");
3727 qemu_opts_parse_noisily(olist
, "usb=on", false);
3728 add_device_config(DEV_USB
, optarg
);
3730 case QEMU_OPTION_device
:
3731 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3736 case QEMU_OPTION_smp
:
3737 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3742 case QEMU_OPTION_vnc
:
3743 vnc_parse(optarg
, &error_fatal
);
3745 case QEMU_OPTION_no_acpi
:
3748 case QEMU_OPTION_no_hpet
:
3751 case QEMU_OPTION_balloon
:
3752 if (balloon_parse(optarg
) < 0) {
3753 error_report("unknown -balloon argument %s", optarg
);
3757 case QEMU_OPTION_no_reboot
:
3760 case QEMU_OPTION_no_shutdown
:
3763 case QEMU_OPTION_show_cursor
:
3766 case QEMU_OPTION_uuid
:
3767 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3768 error_report("failed to parse UUID string: wrong format");
3771 qemu_uuid_set
= true;
3773 case QEMU_OPTION_option_rom
:
3774 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3775 error_report("too many option ROMs");
3778 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3783 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3784 option_rom
[nb_option_roms
].bootindex
=
3785 qemu_opt_get_number(opts
, "bootindex", -1);
3786 if (!option_rom
[nb_option_roms
].name
) {
3787 error_report("Option ROM file is not specified");
3792 case QEMU_OPTION_semihosting
:
3793 semihosting
.enabled
= true;
3794 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3796 case QEMU_OPTION_semihosting_config
:
3797 semihosting
.enabled
= true;
3798 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3801 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3803 const char *target
= qemu_opt_get(opts
, "target");
3804 if (target
!= NULL
) {
3805 if (strcmp("native", target
) == 0) {
3806 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3807 } else if (strcmp("gdb", target
) == 0) {
3808 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3809 } else if (strcmp("auto", target
) == 0) {
3810 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3812 error_report("unsupported semihosting-config %s",
3817 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3819 /* Set semihosting argument count and vector */
3820 qemu_opt_foreach(opts
, add_semihosting_arg
,
3821 &semihosting
, NULL
);
3823 error_report("unsupported semihosting-config %s", optarg
);
3827 case QEMU_OPTION_tdf
:
3828 error_report("warning: ignoring deprecated option");
3830 case QEMU_OPTION_name
:
3831 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3837 case QEMU_OPTION_prom_env
:
3838 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3839 error_report("too many prom variables");
3842 prom_envs
[nb_prom_envs
] = optarg
;
3845 case QEMU_OPTION_old_param
:
3848 case QEMU_OPTION_clock
:
3849 /* Clock options no longer exist. Keep this option for
3850 * backward compatibility.
3853 case QEMU_OPTION_startdate
:
3854 configure_rtc_date_offset(optarg
, 1);
3856 case QEMU_OPTION_rtc
:
3857 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3862 configure_rtc(opts
);
3864 case QEMU_OPTION_tb_size
:
3865 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3866 if (tcg_tb_size
< 0) {
3870 case QEMU_OPTION_icount
:
3871 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3877 case QEMU_OPTION_incoming
:
3879 runstate_set(RUN_STATE_INMIGRATE
);
3883 case QEMU_OPTION_only_migratable
:
3884 only_migratable
= 1;
3886 case QEMU_OPTION_nodefaults
:
3889 case QEMU_OPTION_xen_domid
:
3890 if (!(xen_available())) {
3891 error_report("Option not supported for this target");
3894 xen_domid
= atoi(optarg
);
3896 case QEMU_OPTION_xen_create
:
3897 if (!(xen_available())) {
3898 error_report("Option not supported for this target");
3901 xen_mode
= XEN_CREATE
;
3903 case QEMU_OPTION_xen_attach
:
3904 if (!(xen_available())) {
3905 error_report("Option not supported for this target");
3908 xen_mode
= XEN_ATTACH
;
3910 case QEMU_OPTION_trace
:
3912 trace_file
= trace_opt_parse(optarg
);
3914 case QEMU_OPTION_readconfig
:
3916 int ret
= qemu_read_config_file(optarg
);
3918 error_report("read config %s: %s", optarg
,
3924 case QEMU_OPTION_spice
:
3925 olist
= qemu_find_opts("spice");
3927 error_report("spice support is disabled");
3930 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3936 case QEMU_OPTION_writeconfig
:
3939 if (strcmp(optarg
, "-") == 0) {
3942 fp
= fopen(optarg
, "w");
3944 error_report("open %s: %s", optarg
,
3949 qemu_config_write(fp
);
3955 case QEMU_OPTION_qtest
:
3956 qtest_chrdev
= optarg
;
3958 case QEMU_OPTION_qtest_log
:
3961 case QEMU_OPTION_sandbox
:
3962 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
3968 case QEMU_OPTION_add_fd
:
3970 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3976 error_report("File descriptor passing is disabled on this "
3981 case QEMU_OPTION_object
:
3982 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
3988 case QEMU_OPTION_realtime
:
3989 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
3994 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
3996 case QEMU_OPTION_msg
:
3997 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4002 configure_msg(opts
);
4004 case QEMU_OPTION_dump_vmstate
:
4005 if (vmstate_dump_file
) {
4006 error_report("only one '-dump-vmstate' "
4007 "option may be given");
4010 vmstate_dump_file
= fopen(optarg
, "w");
4011 if (vmstate_dump_file
== NULL
) {
4012 error_report("open %s: %s", optarg
, strerror(errno
));
4017 os_parse_cmd_args(popt
->index
, optarg
);
4022 * Clear error location left behind by the loop.
4023 * Best done right after the loop. Do not insert code here!
4027 replay_configure(icount_opts
);
4029 qemu_tcg_configure(accel_opts
, &error_fatal
);
4031 machine_class
= select_machine();
4033 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4037 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4038 error_report("could not acquire pid file: %s", strerror(errno
));
4042 if (qemu_init_main_loop(&main_loop_err
)) {
4043 error_report_err(main_loop_err
);
4047 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4048 parse_sandbox
, NULL
, NULL
)) {
4052 if (qemu_opts_foreach(qemu_find_opts("name"),
4053 parse_name
, NULL
, NULL
)) {
4058 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4059 parse_add_fd
, NULL
, NULL
)) {
4063 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4064 cleanup_add_fd
, NULL
, NULL
)) {
4069 current_machine
= MACHINE(object_new(object_class_get_name(
4070 OBJECT_CLASS(machine_class
))));
4071 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4074 object_property_add_child(object_get_root(), "machine",
4075 OBJECT(current_machine
), &error_abort
);
4077 if (machine_class
->minimum_page_bits
) {
4078 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4079 /* This would be a board error: specifying a minimum smaller than
4080 * a target's compile-time fixed setting.
4082 g_assert_not_reached();
4086 cpu_exec_init_all();
4088 if (machine_class
->hw_version
) {
4089 qemu_set_hw_version(machine_class
->hw_version
);
4092 if (cpu_model
&& is_help_option(cpu_model
)) {
4093 list_cpus(stdout
, &fprintf
, cpu_model
);
4097 if (!trace_init_backends()) {
4100 trace_init_file(trace_file
);
4102 /* Open the logfile at this point and set the log mask if necessary.
4105 qemu_set_log_filename(log_file
, &error_fatal
);
4110 mask
= qemu_str_to_log_mask(log_mask
);
4112 qemu_print_log_usage(stdout
);
4120 /* If no data_dir is specified then try to find it relative to the
4122 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4123 data_dir
[data_dir_idx
] = os_find_datadir();
4124 if (data_dir
[data_dir_idx
] != NULL
) {
4128 /* If all else fails use the install path specified when building. */
4129 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4130 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4133 /* -L help lists the data directories and exits. */
4134 if (list_data_dirs
) {
4135 for (i
= 0; i
< data_dir_idx
; i
++) {
4136 printf("%s\n", data_dir
[i
]);
4141 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4143 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4144 if (max_cpus
> machine_class
->max_cpus
) {
4145 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4146 "supported by machine '%s' (%d)", max_cpus
,
4147 machine_class
->name
, machine_class
->max_cpus
);
4152 * Get the default machine options from the machine if it is not already
4153 * specified either by the configuration file or by the command line.
4155 if (machine_class
->default_machine_opts
) {
4156 qemu_opts_set_defaults(qemu_find_opts("machine"),
4157 machine_class
->default_machine_opts
, 0);
4160 qemu_opts_foreach(qemu_find_opts("device"),
4161 default_driver_check
, NULL
, NULL
);
4162 qemu_opts_foreach(qemu_find_opts("global"),
4163 default_driver_check
, NULL
, NULL
);
4165 if (!vga_model
&& !default_vga
) {
4166 vga_interface_type
= VGA_DEVICE
;
4168 if (!has_defaults
|| machine_class
->no_serial
) {
4171 if (!has_defaults
|| machine_class
->no_parallel
) {
4172 default_parallel
= 0;
4174 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4175 default_virtcon
= 0;
4177 if (!has_defaults
|| !machine_class
->use_sclp
) {
4180 if (!has_defaults
|| machine_class
->no_floppy
) {
4183 if (!has_defaults
|| machine_class
->no_cdrom
) {
4186 if (!has_defaults
|| machine_class
->no_sdcard
) {
4189 if (!has_defaults
) {
4190 default_monitor
= 0;
4195 if (is_daemonized()) {
4196 /* According to documentation and historically, -nographic redirects
4197 * serial port, parallel port and monitor to stdio, which does not work
4198 * with -daemonize. We can redirect these to null instead, but since
4199 * -nographic is legacy, let's just error out.
4200 * We disallow -nographic only if all other ports are not redirected
4201 * explicitly, to not break existing legacy setups which uses
4202 * -nographic _and_ redirects all ports explicitly - this is valid
4203 * usage, -nographic is just a no-op in this case.
4206 && (default_parallel
|| default_serial
4207 || default_monitor
|| default_virtcon
)) {
4208 error_report("-nographic cannot be used with -daemonize");
4211 #ifdef CONFIG_CURSES
4212 if (display_type
== DT_CURSES
) {
4213 error_report("curses display cannot be used with -daemonize");
4220 if (default_parallel
)
4221 add_device_config(DEV_PARALLEL
, "null");
4222 if (default_serial
&& default_monitor
) {
4223 add_device_config(DEV_SERIAL
, "mon:stdio");
4224 } else if (default_virtcon
&& default_monitor
) {
4225 add_device_config(DEV_VIRTCON
, "mon:stdio");
4226 } else if (default_sclp
&& default_monitor
) {
4227 add_device_config(DEV_SCLP
, "mon:stdio");
4230 add_device_config(DEV_SERIAL
, "stdio");
4231 if (default_virtcon
)
4232 add_device_config(DEV_VIRTCON
, "stdio");
4234 add_device_config(DEV_SCLP
, "stdio");
4236 if (default_monitor
)
4237 monitor_parse("stdio", "readline", false);
4241 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4242 if (default_parallel
)
4243 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4244 if (default_monitor
)
4245 monitor_parse("vc:80Cx24C", "readline", false);
4246 if (default_virtcon
)
4247 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4249 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4253 #if defined(CONFIG_VNC)
4254 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4258 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4259 #if defined(CONFIG_GTK)
4260 display_type
= DT_GTK
;
4261 #elif defined(CONFIG_SDL)
4262 display_type
= DT_SDL
;
4263 #elif defined(CONFIG_COCOA)
4264 display_type
= DT_COCOA
;
4265 #elif defined(CONFIG_VNC)
4266 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4268 display_type
= DT_NONE
;
4272 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4273 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4274 "for SDL, ignoring option");
4276 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4277 error_report("-no-quit is only valid for GTK and SDL, "
4281 if (display_type
== DT_GTK
) {
4282 early_gtk_display_init(request_opengl
);
4285 if (display_type
== DT_SDL
) {
4286 sdl_display_early_init(request_opengl
);
4289 qemu_console_early_init();
4291 if (request_opengl
== 1 && display_opengl
== 0) {
4292 #if defined(CONFIG_OPENGL)
4293 error_report("OpenGL is not supported by the display");
4295 error_report("OpenGL support is disabled");
4303 if (qemu_opts_foreach(qemu_find_opts("object"),
4304 user_creatable_add_opts_foreach
,
4305 object_create_initial
, NULL
)) {
4309 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4310 chardev_init_func
, NULL
, NULL
)) {
4314 #ifdef CONFIG_VIRTFS
4315 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4316 fsdev_init_func
, NULL
, NULL
)) {
4321 if (qemu_opts_foreach(qemu_find_opts("device"),
4322 device_help_func
, NULL
, NULL
)) {
4326 machine_opts
= qemu_get_machine_opts();
4327 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4329 object_unref(OBJECT(current_machine
));
4333 configure_accelerator(current_machine
);
4336 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4339 machine_opts
= qemu_get_machine_opts();
4340 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4341 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4342 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4343 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4345 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4347 boot_order
= qemu_opt_get(opts
, "order");
4349 validate_bootdevices(boot_order
, &error_fatal
);
4352 boot_once
= qemu_opt_get(opts
, "once");
4354 validate_bootdevices(boot_once
, &error_fatal
);
4357 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4358 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4362 boot_order
= machine_class
->default_boot_order
;
4365 if (!kernel_cmdline
) {
4366 kernel_cmdline
= "";
4367 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4370 linux_boot
= (kernel_filename
!= NULL
);
4372 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4373 error_report("-append only allowed with -kernel option");
4377 if (!linux_boot
&& initrd_filename
!= NULL
) {
4378 error_report("-initrd only allowed with -kernel option");
4382 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4383 /* fall back to the -kernel/-append */
4384 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4387 os_set_line_buffering();
4389 /* spice needs the timers to be initialized by this point */
4394 if (!tcg_enabled()) {
4395 error_report("-icount is not allowed with hardware virtualization");
4397 } else if (qemu_tcg_mttcg_enabled()) {
4398 error_report("-icount does not currently work with MTTCG");
4401 configure_icount(icount_opts
, &error_abort
);
4402 qemu_opts_del(icount_opts
);
4406 QemuOptsList
*net
= qemu_find_opts("net");
4407 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4409 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4415 if (net_init_clients() < 0) {
4419 if (qemu_opts_foreach(qemu_find_opts("object"),
4420 user_creatable_add_opts_foreach
,
4421 object_create_delayed
, NULL
)) {
4426 if (tpm_init() < 0) {
4431 /* init the bluetooth world */
4432 if (foreach_device_config(DEV_BT
, bt_parse
))
4435 if (!xen_enabled()) {
4436 /* On 32-bit hosts, QEMU is limited by virtual address space */
4437 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4438 error_report("at most 2047 MB RAM can be simulated");
4446 /* If the currently selected machine wishes to override the units-per-bus
4447 * property of its default HBA interface type, do so now. */
4448 if (machine_class
->units_per_default_bus
) {
4449 override_max_devs(machine_class
->block_default_type
,
4450 machine_class
->units_per_default_bus
);
4453 /* open the virtual block devices */
4454 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4455 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4458 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4459 &machine_class
->block_default_type
, NULL
)) {
4463 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4465 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4466 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4468 parse_numa_opts(machine_class
);
4470 if (qemu_opts_foreach(qemu_find_opts("mon"),
4471 mon_init_func
, NULL
, NULL
)) {
4475 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4477 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4479 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4481 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4484 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4487 /* If no default VGA is requested, the default is "none". */
4489 if (machine_class
->default_display
) {
4490 vga_model
= machine_class
->default_display
;
4491 } else if (vga_interface_available(VGA_CIRRUS
)) {
4492 vga_model
= "cirrus";
4493 } else if (vga_interface_available(VGA_STD
)) {
4498 select_vgahw(vga_model
);
4502 i
= select_watchdog(watchdog
);
4504 exit (i
== 1 ? 1 : 0);
4507 machine_register_compat_props(current_machine
);
4509 qemu_opts_foreach(qemu_find_opts("global"),
4510 global_init_func
, NULL
, NULL
);
4512 /* This checkpoint is required by replay to separate prior clock
4513 reading from the other reads, because timer polling functions query
4514 clock values from the log. */
4515 replay_checkpoint(CHECKPOINT_INIT
);
4516 qdev_machine_init();
4518 current_machine
->ram_size
= ram_size
;
4519 current_machine
->maxram_size
= maxram_size
;
4520 current_machine
->ram_slots
= ram_slots
;
4521 current_machine
->boot_order
= boot_order
;
4522 current_machine
->cpu_model
= cpu_model
;
4524 machine_class
->init(current_machine
);
4530 if (hax_enabled()) {
4534 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4535 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4539 /* init USB devices */
4540 if (machine_usb(current_machine
)) {
4541 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4545 /* Check if IGD GFX passthrough. */
4548 /* init generic devices */
4549 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4550 if (qemu_opts_foreach(qemu_find_opts("device"),
4551 device_init_func
, NULL
, NULL
)) {
4555 cpu_synchronize_all_post_init();
4557 numa_post_machine_init();
4559 rom_reset_order_override();
4562 * Create frontends for -drive if=scsi leftovers.
4563 * Normally, frontends for -drive get created by machine
4564 * initialization for onboard SCSI HBAs. However, we create a few
4565 * more ever since SCSI qdevification, but this is pretty much an
4566 * implementation accident, and deprecated.
4568 scsi_legacy_handle_cmdline();
4570 /* Did we create any drives that we failed to create a device for? */
4571 drive_check_orphaned();
4573 /* Don't warn about the default network setup that you get if
4574 * no command line -net or -netdev options are specified. There
4575 * are two cases that we would otherwise complain about:
4576 * (1) board doesn't support a NIC but the implicit "-net nic"
4578 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4579 * sets up a nic that isn't connected to anything.
4582 net_check_clients();
4587 qemu_boot_set(boot_once
, &error_fatal
);
4588 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4591 ds
= init_displaystate();
4593 /* init local displays */
4594 switch (display_type
) {
4596 curses_display_init(ds
, full_screen
);
4599 sdl_display_init(ds
, full_screen
, no_frame
);
4602 cocoa_display_init(ds
, full_screen
);
4605 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4611 /* must be after terminal init, SDL library changes signal handlers */
4612 os_setup_signal_handling();
4614 /* init remote displays */
4616 qemu_opts_foreach(qemu_find_opts("vnc"),
4617 vnc_init_func
, NULL
, NULL
);
4621 qemu_spice_display_init();
4624 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4628 qdev_machine_creation_done();
4630 /* TODO: once all bus devices are qdevified, this should be done
4631 * when bus is created by qdev.c */
4632 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4633 qemu_run_machine_init_done_notifiers();
4635 if (rom_check_and_register_reset() != 0) {
4636 error_report("rom check and register reset failed");
4642 /* This checkpoint is required by replay to separate prior clock
4643 reading from the other reads, because timer polling functions query
4644 clock values from the log. */
4645 replay_checkpoint(CHECKPOINT_RESET
);
4646 qemu_system_reset(VMRESET_SILENT
);
4647 register_global_state();
4648 if (replay_mode
!= REPLAY_MODE_NONE
) {
4649 replay_vmstate_init();
4650 } else if (loadvm
) {
4651 if (load_vmstate(loadvm
) < 0) {
4656 qdev_prop_check_globals();
4657 if (vmstate_dump_file
) {
4659 dump_vmstate_json_to_file(vmstate_dump_file
);
4664 Error
*local_err
= NULL
;
4665 qemu_start_incoming_migration(incoming
, &local_err
);
4667 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4670 } else if (autostart
) {
4677 replay_disable_events();
4678 iothread_stop_all();
4684 /* vhost-user must be cleaned up before chardevs. */