4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "qemu/osdep.h"
25 #include "qemu-version.h"
26 #include "qemu/cutils.h"
27 #include "qemu/help_option.h"
28 #include "qemu/uuid.h"
31 #include "sysemu/seccomp.h"
34 #if defined(CONFIG_VDE)
35 #include <libvdeplug.h>
39 #if defined(__APPLE__) || defined(main)
41 int qemu_main(int argc
, char **argv
, char **envp
);
42 int main(int argc
, char **argv
)
44 return qemu_main(argc
, argv
, NULL
);
47 #define main qemu_main
49 #endif /* CONFIG_SDL */
53 #define main qemu_main
54 #endif /* CONFIG_COCOA */
57 #include "qemu/error-report.h"
58 #include "qemu/sockets.h"
60 #include "hw/boards.h"
61 #include "sysemu/accel.h"
63 #include "hw/i386/pc.h"
64 #include "hw/isa/isa.h"
66 #include "sysemu/watchdog.h"
67 #include "hw/smbios/smbios.h"
68 #include "hw/acpi/acpi.h"
69 #include "hw/xen/xen.h"
71 #include "hw/loader.h"
72 #include "monitor/qdev.h"
73 #include "sysemu/bt.h"
75 #include "net/slirp.h"
76 #include "monitor/monitor.h"
77 #include "ui/console.h"
79 #include "sysemu/sysemu.h"
80 #include "sysemu/numa.h"
81 #include "exec/gdbstub.h"
82 #include "qemu/timer.h"
83 #include "sysemu/char.h"
84 #include "qemu/bitmap.h"
86 #include "sysemu/blockdev.h"
87 #include "hw/block/block.h"
88 #include "migration/block.h"
89 #include "sysemu/tpm.h"
90 #include "sysemu/dma.h"
91 #include "audio/audio.h"
92 #include "migration/migration.h"
93 #include "sysemu/cpus.h"
94 #include "migration/colo.h"
95 #include "sysemu/kvm.h"
96 #include "sysemu/hax.h"
97 #include "qapi/qmp/qjson.h"
98 #include "qemu/option.h"
99 #include "qemu/config-file.h"
100 #include "qemu-options.h"
101 #include "qmp-commands.h"
102 #include "qemu/main-loop.h"
104 #include "fsdev/qemu-fsdev.h"
106 #include "sysemu/qtest.h"
108 #include "disas/disas.h"
111 #include "slirp/libslirp.h"
114 #include "trace/control.h"
115 #include "qemu/queue.h"
116 #include "sysemu/arch_init.h"
118 #include "ui/qemu-spice.h"
119 #include "qapi/string-input-visitor.h"
120 #include "qapi/opts-visitor.h"
121 #include "qom/object_interfaces.h"
122 #include "qapi-event.h"
123 #include "exec/semihost.h"
124 #include "crypto/init.h"
125 #include "sysemu/replay.h"
126 #include "qapi/qmp/qerror.h"
127 #include "sysemu/iothread.h"
129 #define MAX_VIRTIO_CONSOLES 1
130 #define MAX_SCLP_CONSOLES 1
132 static const char *data_dir
[16];
133 static int data_dir_idx
;
134 const char *bios_name
= NULL
;
135 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
136 int request_opengl
= -1;
138 const char* keyboard_layout
= NULL
;
140 const char *mem_path
= NULL
;
141 int mem_prealloc
= 0; /* force preallocation of physical target memory */
142 bool enable_mlock
= false;
144 NICInfo nd_table
[MAX_NICS
];
146 static int rtc_utc
= 1;
147 static int rtc_date_offset
= -1; /* -1 means no change */
148 QEMUClockType rtc_clock
;
149 int vga_interface_type
= VGA_NONE
;
150 static int full_screen
= 0;
151 static int no_frame
= 0;
153 static bool grab_on_hover
;
154 Chardev
*serial_hds
[MAX_SERIAL_PORTS
];
155 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
156 Chardev
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
157 Chardev
*sclp_hds
[MAX_SCLP_CONSOLES
];
158 int win2k_install_hack
= 0;
164 int acpi_enabled
= 1;
167 static int no_reboot
;
170 int graphic_rotate
= 0;
171 const char *watchdog
;
172 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
175 const char *qemu_name
;
178 unsigned int nb_prom_envs
= 0;
179 const char *prom_envs
[MAX_PROM_ENVS
];
182 uint8_t *boot_splash_filedata
;
183 size_t boot_splash_filedata_size
;
184 uint8_t qemu_extra_params_fw
[2];
185 int only_migratable
; /* turn it off unless user states otherwise */
187 int icount_align_option
;
189 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
190 * little-endian "wire format" described in the SMBIOS 2.6 specification.
195 static NotifierList exit_notifiers
=
196 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
198 static NotifierList machine_init_done_notifiers
=
199 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
203 enum xen_mode xen_mode
= XEN_EMULATE
;
205 static int has_defaults
= 1;
206 static int default_serial
= 1;
207 static int default_parallel
= 1;
208 static int default_virtcon
= 1;
209 static int default_sclp
= 1;
210 static int default_monitor
= 1;
211 static int default_floppy
= 1;
212 static int default_cdrom
= 1;
213 static int default_sdcard
= 1;
214 static int default_vga
= 1;
215 static int default_net
= 1;
221 { .driver
= "isa-serial", .flag
= &default_serial
},
222 { .driver
= "isa-parallel", .flag
= &default_parallel
},
223 { .driver
= "isa-fdc", .flag
= &default_floppy
},
224 { .driver
= "floppy", .flag
= &default_floppy
},
225 { .driver
= "ide-cd", .flag
= &default_cdrom
},
226 { .driver
= "ide-hd", .flag
= &default_cdrom
},
227 { .driver
= "ide-drive", .flag
= &default_cdrom
},
228 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
229 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
230 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
231 { .driver
= "VGA", .flag
= &default_vga
},
232 { .driver
= "isa-vga", .flag
= &default_vga
},
233 { .driver
= "cirrus-vga", .flag
= &default_vga
},
234 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
235 { .driver
= "vmware-svga", .flag
= &default_vga
},
236 { .driver
= "qxl-vga", .flag
= &default_vga
},
237 { .driver
= "virtio-vga", .flag
= &default_vga
},
240 static QemuOptsList qemu_rtc_opts
= {
242 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
246 .type
= QEMU_OPT_STRING
,
249 .type
= QEMU_OPT_STRING
,
252 .type
= QEMU_OPT_STRING
,
254 { /* end of list */ }
258 static QemuOptsList qemu_sandbox_opts
= {
260 .implied_opt_name
= "enable",
261 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
265 .type
= QEMU_OPT_BOOL
,
267 { /* end of list */ }
271 static QemuOptsList qemu_option_rom_opts
= {
272 .name
= "option-rom",
273 .implied_opt_name
= "romfile",
274 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
278 .type
= QEMU_OPT_NUMBER
,
281 .type
= QEMU_OPT_STRING
,
283 { /* end of list */ }
287 static QemuOptsList qemu_machine_opts
= {
289 .implied_opt_name
= "type",
291 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
294 * no elements => accept any
295 * sanity checking will happen later
296 * when setting machine properties
302 static QemuOptsList qemu_boot_opts
= {
304 .implied_opt_name
= "order",
306 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
310 .type
= QEMU_OPT_STRING
,
313 .type
= QEMU_OPT_STRING
,
316 .type
= QEMU_OPT_BOOL
,
319 .type
= QEMU_OPT_STRING
,
321 .name
= "splash-time",
322 .type
= QEMU_OPT_STRING
,
324 .name
= "reboot-timeout",
325 .type
= QEMU_OPT_STRING
,
328 .type
= QEMU_OPT_BOOL
,
334 static QemuOptsList qemu_add_fd_opts
= {
336 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
340 .type
= QEMU_OPT_NUMBER
,
341 .help
= "file descriptor of which a duplicate is added to fd set",
344 .type
= QEMU_OPT_NUMBER
,
345 .help
= "ID of the fd set to add fd to",
348 .type
= QEMU_OPT_STRING
,
349 .help
= "free-form string used to describe fd",
351 { /* end of list */ }
355 static QemuOptsList qemu_object_opts
= {
357 .implied_opt_name
= "qom-type",
358 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
364 static QemuOptsList qemu_tpmdev_opts
= {
366 .implied_opt_name
= "type",
367 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
369 /* options are defined in the TPM backends */
370 { /* end of list */ }
374 static QemuOptsList qemu_realtime_opts
= {
376 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
380 .type
= QEMU_OPT_BOOL
,
382 { /* end of list */ }
386 static QemuOptsList qemu_msg_opts
= {
388 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
392 .type
= QEMU_OPT_BOOL
,
394 { /* end of list */ }
398 static QemuOptsList qemu_name_opts
= {
400 .implied_opt_name
= "guest",
402 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
406 .type
= QEMU_OPT_STRING
,
407 .help
= "Sets the name of the guest.\n"
408 "This name will be displayed in the SDL window caption.\n"
409 "The name will also be used for the VNC server",
412 .type
= QEMU_OPT_STRING
,
413 .help
= "Sets the name of the QEMU process, as shown in top etc",
415 .name
= "debug-threads",
416 .type
= QEMU_OPT_BOOL
,
417 .help
= "When enabled, name the individual threads; defaults off.\n"
418 "NOTE: The thread names are for debugging and not a\n"
421 { /* End of list */ }
425 static QemuOptsList qemu_mem_opts
= {
427 .implied_opt_name
= "size",
428 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
433 .type
= QEMU_OPT_SIZE
,
437 .type
= QEMU_OPT_NUMBER
,
441 .type
= QEMU_OPT_SIZE
,
443 { /* end of list */ }
447 static QemuOptsList qemu_icount_opts
= {
449 .implied_opt_name
= "shift",
451 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
455 .type
= QEMU_OPT_STRING
,
458 .type
= QEMU_OPT_BOOL
,
461 .type
= QEMU_OPT_BOOL
,
464 .type
= QEMU_OPT_STRING
,
467 .type
= QEMU_OPT_STRING
,
469 .name
= "rrsnapshot",
470 .type
= QEMU_OPT_STRING
,
472 { /* end of list */ }
476 static QemuOptsList qemu_semihosting_config_opts
= {
477 .name
= "semihosting-config",
478 .implied_opt_name
= "enable",
479 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
483 .type
= QEMU_OPT_BOOL
,
486 .type
= QEMU_OPT_STRING
,
489 .type
= QEMU_OPT_STRING
,
491 { /* end of list */ }
495 static QemuOptsList qemu_fw_cfg_opts
= {
497 .implied_opt_name
= "name",
498 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
502 .type
= QEMU_OPT_STRING
,
503 .help
= "Sets the fw_cfg name of the blob to be inserted",
506 .type
= QEMU_OPT_STRING
,
507 .help
= "Sets the name of the file from which\n"
508 "the fw_cfg blob will be loaded",
511 .type
= QEMU_OPT_STRING
,
512 .help
= "Sets content of the blob to be inserted from a string",
514 { /* end of list */ }
519 * Get machine options
521 * Returns: machine options (never null).
523 QemuOpts
*qemu_get_machine_opts(void)
525 return qemu_find_opts_singleton("machine");
528 const char *qemu_get_vm_name(void)
533 static void res_free(void)
535 g_free(boot_splash_filedata
);
536 boot_splash_filedata
= NULL
;
539 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
541 const char *driver
= qemu_opt_get(opts
, "driver");
546 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
547 if (strcmp(default_list
[i
].driver
, driver
) != 0)
549 *(default_list
[i
].flag
) = 0;
554 /***********************************************************/
557 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
559 /* We use RUN_STATE__MAX but any invalid value will do */
560 static RunState vmstop_requested
= RUN_STATE__MAX
;
561 static QemuMutex vmstop_lock
;
566 } RunStateTransition
;
568 static const RunStateTransition runstate_transitions_def
[] = {
570 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
571 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
572 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
574 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
575 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
576 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
577 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
578 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
579 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
580 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
581 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
582 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
583 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
584 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
585 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
587 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
588 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
589 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
591 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
592 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
593 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
595 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
596 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
597 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
598 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
600 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
601 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
602 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
604 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
605 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
606 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
608 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
609 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
610 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
611 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
613 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
614 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
616 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
618 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
619 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
620 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
621 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
622 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
623 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
624 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
625 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
626 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
627 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
628 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
630 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
632 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
633 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
634 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
636 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
637 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
638 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
639 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
640 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
641 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
643 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
644 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
645 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
646 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
648 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
649 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
650 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
652 { RUN_STATE__MAX
, RUN_STATE__MAX
},
655 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
657 bool runstate_check(RunState state
)
659 return current_run_state
== state
;
662 bool runstate_store(char *str
, size_t size
)
664 const char *state
= RunState_lookup
[current_run_state
];
665 size_t len
= strlen(state
) + 1;
670 memcpy(str
, state
, len
);
674 static void runstate_init(void)
676 const RunStateTransition
*p
;
678 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
679 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
680 runstate_valid_transitions
[p
->from
][p
->to
] = true;
683 qemu_mutex_init(&vmstop_lock
);
686 /* This function will abort() on invalid state transitions */
687 void runstate_set(RunState new_state
)
689 assert(new_state
< RUN_STATE__MAX
);
691 if (current_run_state
== new_state
) {
695 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
696 error_report("invalid runstate transition: '%s' -> '%s'",
697 RunState_lookup
[current_run_state
],
698 RunState_lookup
[new_state
]);
701 trace_runstate_set(new_state
);
702 current_run_state
= new_state
;
705 int runstate_is_running(void)
707 return runstate_check(RUN_STATE_RUNNING
);
710 bool runstate_needs_reset(void)
712 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
713 runstate_check(RUN_STATE_SHUTDOWN
);
716 StatusInfo
*qmp_query_status(Error
**errp
)
718 StatusInfo
*info
= g_malloc0(sizeof(*info
));
720 info
->running
= runstate_is_running();
721 info
->singlestep
= singlestep
;
722 info
->status
= current_run_state
;
727 static bool qemu_vmstop_requested(RunState
*r
)
729 qemu_mutex_lock(&vmstop_lock
);
730 *r
= vmstop_requested
;
731 vmstop_requested
= RUN_STATE__MAX
;
732 qemu_mutex_unlock(&vmstop_lock
);
733 return *r
< RUN_STATE__MAX
;
736 void qemu_system_vmstop_request_prepare(void)
738 qemu_mutex_lock(&vmstop_lock
);
741 void qemu_system_vmstop_request(RunState state
)
743 vmstop_requested
= state
;
744 qemu_mutex_unlock(&vmstop_lock
);
752 qemu_vmstop_requested(&requested
);
753 if (runstate_is_running() && requested
== RUN_STATE__MAX
) {
757 /* Ensure that a STOP/RESUME pair of events is emitted if a
758 * vmstop request was pending. The BLOCK_IO_ERROR event, for
759 * example, according to documentation is always followed by
762 if (runstate_is_running()) {
763 qapi_event_send_stop(&error_abort
);
765 replay_enable_events();
767 runstate_set(RUN_STATE_RUNNING
);
768 vm_state_notify(1, RUN_STATE_RUNNING
);
772 qapi_event_send_resume(&error_abort
);
776 /***********************************************************/
777 /* real time host monotonic timer */
779 static time_t qemu_time(void)
781 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
784 /***********************************************************/
785 /* host time/date access */
786 void qemu_get_timedate(struct tm
*tm
, int offset
)
788 time_t ti
= qemu_time();
791 if (rtc_date_offset
== -1) {
795 localtime_r(&ti
, tm
);
797 ti
-= rtc_date_offset
;
802 int qemu_timedate_diff(struct tm
*tm
)
806 if (rtc_date_offset
== -1)
808 seconds
= mktimegm(tm
);
811 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
812 seconds
= mktime(&tmp
);
815 seconds
= mktimegm(tm
) + rtc_date_offset
;
817 return seconds
- qemu_time();
820 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
822 time_t rtc_start_date
;
825 if (!strcmp(startdate
, "now") && legacy
) {
826 rtc_date_offset
= -1;
828 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
836 } else if (sscanf(startdate
, "%d-%d-%d",
848 rtc_start_date
= mktimegm(&tm
);
849 if (rtc_start_date
== -1) {
851 error_report("invalid date format");
852 error_printf("valid formats: "
853 "'2006-06-17T16:01:21' or '2006-06-17'\n");
856 rtc_date_offset
= qemu_time() - rtc_start_date
;
860 static void configure_rtc(QemuOpts
*opts
)
864 value
= qemu_opt_get(opts
, "base");
866 if (!strcmp(value
, "utc")) {
868 } else if (!strcmp(value
, "localtime")) {
869 Error
*blocker
= NULL
;
871 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
872 "-rtc base=localtime");
873 replay_add_blocker(blocker
);
875 configure_rtc_date_offset(value
, 0);
878 value
= qemu_opt_get(opts
, "clock");
880 if (!strcmp(value
, "host")) {
881 rtc_clock
= QEMU_CLOCK_HOST
;
882 } else if (!strcmp(value
, "rt")) {
883 rtc_clock
= QEMU_CLOCK_REALTIME
;
884 } else if (!strcmp(value
, "vm")) {
885 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
887 error_report("invalid option value '%s'", value
);
891 value
= qemu_opt_get(opts
, "driftfix");
893 if (!strcmp(value
, "slew")) {
894 static GlobalProperty slew_lost_ticks
= {
895 .driver
= "mc146818rtc",
896 .property
= "lost_tick_policy",
900 qdev_prop_register_global(&slew_lost_ticks
);
901 } else if (!strcmp(value
, "none")) {
902 /* discard is default */
904 error_report("invalid option value '%s'", value
);
910 /***********************************************************/
911 /* Bluetooth support */
914 static struct HCIInfo
*hci_table
[MAX_NICS
];
916 struct HCIInfo
*qemu_next_hci(void)
918 if (cur_hci
== nb_hcis
)
921 return hci_table
[cur_hci
++];
924 static int bt_hci_parse(const char *str
)
929 if (nb_hcis
>= MAX_NICS
) {
930 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
943 bdaddr
.b
[5] = 0x56 + nb_hcis
;
944 hci
->bdaddr_set(hci
, bdaddr
.b
);
946 hci_table
[nb_hcis
++] = hci
;
951 static void bt_vhci_add(int vlan_id
)
953 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
956 error_report("warning: adding a VHCI to an empty scatternet %i",
959 bt_vhci_init(bt_new_hci(vlan
));
962 static struct bt_device_s
*bt_device_add(const char *opt
)
964 struct bt_scatternet_s
*vlan
;
966 char *endp
= strstr(opt
, ",vlan=");
967 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
970 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
973 vlan_id
= strtol(endp
+ 6, &endp
, 0);
975 error_report("unrecognised bluetooth vlan Id");
980 vlan
= qemu_find_bt_vlan(vlan_id
);
983 error_report("warning: adding a slave device to an empty scatternet %i",
986 if (!strcmp(devname
, "keyboard"))
987 return bt_keyboard_init(vlan
);
989 error_report("unsupported bluetooth device '%s'", devname
);
993 static int bt_parse(const char *opt
)
995 const char *endp
, *p
;
998 if (strstart(opt
, "hci", &endp
)) {
999 if (!*endp
|| *endp
== ',') {
1001 if (!strstart(endp
, ",vlan=", 0))
1004 return bt_hci_parse(opt
);
1006 } else if (strstart(opt
, "vhci", &endp
)) {
1007 if (!*endp
|| *endp
== ',') {
1009 if (strstart(endp
, ",vlan=", &p
)) {
1010 vlan
= strtol(p
, (char **) &endp
, 0);
1012 error_report("bad scatternet '%s'", p
);
1016 error_report("bad parameter '%s'", endp
+ 1);
1025 } else if (strstart(opt
, "device:", &endp
))
1026 return !bt_device_add(endp
);
1028 error_report("bad bluetooth parameter '%s'", opt
);
1032 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1034 /* FIXME: change this to true for 1.3 */
1035 if (qemu_opt_get_bool(opts
, "enable", false)) {
1036 #ifdef CONFIG_SECCOMP
1037 if (seccomp_start() < 0) {
1038 error_report("failed to install seccomp syscall filter "
1043 error_report("seccomp support is disabled");
1051 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1053 const char *proc_name
;
1055 if (qemu_opt_get(opts
, "debug-threads")) {
1056 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1058 qemu_name
= qemu_opt_get(opts
, "guest");
1060 proc_name
= qemu_opt_get(opts
, "process");
1062 os_set_proc_name(proc_name
);
1068 bool defaults_enabled(void)
1070 return has_defaults
;
1074 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1076 int fd
, dupfd
, flags
;
1078 const char *fd_opaque
= NULL
;
1081 fd
= qemu_opt_get_number(opts
, "fd", -1);
1082 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1083 fd_opaque
= qemu_opt_get(opts
, "opaque");
1086 error_report("fd option is required and must be non-negative");
1090 if (fd
<= STDERR_FILENO
) {
1091 error_report("fd cannot be a standard I/O stream");
1096 * All fds inherited across exec() necessarily have FD_CLOEXEC
1097 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1099 flags
= fcntl(fd
, F_GETFD
);
1100 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1101 error_report("fd is not valid or already in use");
1106 error_report("set option is required and must be non-negative");
1110 #ifdef F_DUPFD_CLOEXEC
1111 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1115 qemu_set_cloexec(dupfd
);
1119 error_report("error duplicating fd: %s", strerror(errno
));
1123 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1124 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1131 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1135 fd
= qemu_opt_get_number(opts
, "fd", -1);
1142 /***********************************************************/
1143 /* QEMU Block devices */
1145 #define HD_OPTS "media=disk"
1146 #define CDROM_OPTS "media=cdrom"
1148 #define PFLASH_OPTS ""
1152 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1154 BlockInterfaceType
*block_default_type
= opaque
;
1156 return drive_new(opts
, *block_default_type
) == NULL
;
1159 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1161 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1162 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1167 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1168 int index
, const char *optstr
)
1173 if (!enable
|| drive_get_by_index(type
, index
)) {
1177 opts
= drive_add(type
, index
, NULL
, optstr
);
1179 drive_enable_snapshot(NULL
, opts
, NULL
);
1182 dinfo
= drive_new(opts
, type
);
1186 dinfo
->is_default
= true;
1190 static QemuOptsList qemu_smp_opts
= {
1192 .implied_opt_name
= "cpus",
1193 .merge_lists
= true,
1194 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1198 .type
= QEMU_OPT_NUMBER
,
1201 .type
= QEMU_OPT_NUMBER
,
1204 .type
= QEMU_OPT_NUMBER
,
1207 .type
= QEMU_OPT_NUMBER
,
1210 .type
= QEMU_OPT_NUMBER
,
1212 { /*End of list */ }
1216 static void smp_parse(QemuOpts
*opts
)
1219 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1220 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1221 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1222 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1224 /* compute missing values, prefer sockets over cores over threads */
1225 if (cpus
== 0 || sockets
== 0) {
1226 sockets
= sockets
> 0 ? sockets
: 1;
1227 cores
= cores
> 0 ? cores
: 1;
1228 threads
= threads
> 0 ? threads
: 1;
1230 cpus
= cores
* threads
* sockets
;
1232 } else if (cores
== 0) {
1233 threads
= threads
> 0 ? threads
: 1;
1234 cores
= cpus
/ (sockets
* threads
);
1235 cores
= cores
> 0 ? cores
: 1;
1236 } else if (threads
== 0) {
1237 threads
= cpus
/ (cores
* sockets
);
1238 threads
= threads
> 0 ? threads
: 1;
1239 } else if (sockets
* cores
* threads
< cpus
) {
1240 error_report("cpu topology: "
1241 "sockets (%u) * cores (%u) * threads (%u) < "
1243 sockets
, cores
, threads
, cpus
);
1247 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1249 if (max_cpus
< cpus
) {
1250 error_report("maxcpus must be equal to or greater than smp");
1254 if (sockets
* cores
* threads
> max_cpus
) {
1255 error_report("cpu topology: "
1256 "sockets (%u) * cores (%u) * threads (%u) > "
1258 sockets
, cores
, threads
, max_cpus
);
1264 smp_threads
= threads
;
1268 Error
*blocker
= NULL
;
1269 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1270 replay_add_blocker(blocker
);
1274 static void realtime_init(void)
1277 if (os_mlock() < 0) {
1278 error_report("locking memory failed");
1285 static void configure_msg(QemuOpts
*opts
)
1287 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1290 /***********************************************************/
1293 typedef struct SemihostingConfig
{
1295 SemihostingTarget target
;
1298 const char *cmdline
; /* concatenated argv */
1299 } SemihostingConfig
;
1301 static SemihostingConfig semihosting
;
1303 bool semihosting_enabled(void)
1305 return semihosting
.enabled
;
1308 SemihostingTarget
semihosting_get_target(void)
1310 return semihosting
.target
;
1313 const char *semihosting_get_arg(int i
)
1315 if (i
>= semihosting
.argc
) {
1318 return semihosting
.argv
[i
];
1321 int semihosting_get_argc(void)
1323 return semihosting
.argc
;
1326 const char *semihosting_get_cmdline(void)
1328 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1329 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1331 return semihosting
.cmdline
;
1334 static int add_semihosting_arg(void *opaque
,
1335 const char *name
, const char *val
,
1338 SemihostingConfig
*s
= opaque
;
1339 if (strcmp(name
, "arg") == 0) {
1341 /* one extra element as g_strjoinv() expects NULL-terminated array */
1342 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1343 s
->argv
[s
->argc
- 1] = val
;
1344 s
->argv
[s
->argc
] = NULL
;
1349 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1350 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1355 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1357 /* split -append and initialize argv[1..n] */
1358 cmd_token
= strtok(g_strdup(cmd
), " ");
1360 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1361 cmd_token
= strtok(NULL
, " ");
1365 /* Now we still need this for compatibility with XEN. */
1366 bool has_igd_gfx_passthru
;
1367 static void igd_gfx_passthru(void)
1369 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1372 /***********************************************************/
1375 static int usb_device_add(const char *devname
)
1377 USBDevice
*dev
= NULL
;
1378 #ifndef CONFIG_LINUX
1382 if (!machine_usb(current_machine
)) {
1386 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1387 dev
= usbdevice_create(devname
);
1391 /* the other ones */
1392 #ifndef CONFIG_LINUX
1393 /* only the linux version is qdev-ified, usb-bsd still needs this */
1394 if (strstart(devname
, "host:", &p
)) {
1395 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1405 static int usb_device_del(const char *devname
)
1410 if (strstart(devname
, "host:", &p
)) {
1414 if (!machine_usb(current_machine
)) {
1418 p
= strchr(devname
, '.');
1421 bus_num
= strtoul(devname
, NULL
, 0);
1422 addr
= strtoul(p
+ 1, NULL
, 0);
1424 return usb_device_delete_addr(bus_num
, addr
);
1427 static int usb_parse(const char *cmdline
)
1430 r
= usb_device_add(cmdline
);
1432 error_report("could not add USB device '%s'", cmdline
);
1437 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1439 const char *devname
= qdict_get_str(qdict
, "devname");
1440 if (usb_device_add(devname
) < 0) {
1441 error_report("could not add USB device '%s'", devname
);
1445 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1447 const char *devname
= qdict_get_str(qdict
, "devname");
1448 if (usb_device_del(devname
) < 0) {
1449 error_report("could not delete USB device '%s'", devname
);
1453 /***********************************************************/
1454 /* machine registration */
1456 MachineState
*current_machine
;
1458 static MachineClass
*find_machine(const char *name
)
1460 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1461 MachineClass
*mc
= NULL
;
1463 for (el
= machines
; el
; el
= el
->next
) {
1464 MachineClass
*temp
= el
->data
;
1466 if (!strcmp(temp
->name
, name
)) {
1471 !strcmp(temp
->alias
, name
)) {
1477 g_slist_free(machines
);
1481 MachineClass
*find_default_machine(void)
1483 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1484 MachineClass
*mc
= NULL
;
1486 for (el
= machines
; el
; el
= el
->next
) {
1487 MachineClass
*temp
= el
->data
;
1489 if (temp
->is_default
) {
1495 g_slist_free(machines
);
1499 MachineInfoList
*qmp_query_machines(Error
**errp
)
1501 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1502 MachineInfoList
*mach_list
= NULL
;
1504 for (el
= machines
; el
; el
= el
->next
) {
1505 MachineClass
*mc
= el
->data
;
1506 MachineInfoList
*entry
;
1509 info
= g_malloc0(sizeof(*info
));
1510 if (mc
->is_default
) {
1511 info
->has_is_default
= true;
1512 info
->is_default
= true;
1516 info
->has_alias
= true;
1517 info
->alias
= g_strdup(mc
->alias
);
1520 info
->name
= g_strdup(mc
->name
);
1521 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1522 info
->hotpluggable_cpus
= !!mc
->query_hotpluggable_cpus
;
1524 entry
= g_malloc0(sizeof(*entry
));
1525 entry
->value
= info
;
1526 entry
->next
= mach_list
;
1530 g_slist_free(machines
);
1534 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1536 ObjectProperty
*prop
;
1537 ObjectPropertyIterator iter
;
1539 if (!qemu_opt_has_help_opt(opts
)) {
1543 object_property_iter_init(&iter
, OBJECT(machine
));
1544 while ((prop
= object_property_iter_next(&iter
))) {
1549 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1550 prop
->name
, prop
->type
);
1551 if (prop
->description
) {
1552 error_printf(" (%s)\n", prop
->description
);
1561 /***********************************************************/
1562 /* main execution loop */
1564 struct vm_change_state_entry
{
1565 VMChangeStateHandler
*cb
;
1567 QLIST_ENTRY (vm_change_state_entry
) entries
;
1570 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1572 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1575 VMChangeStateEntry
*e
;
1577 e
= g_malloc0(sizeof (*e
));
1581 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1585 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1587 QLIST_REMOVE (e
, entries
);
1591 void vm_state_notify(int running
, RunState state
)
1593 VMChangeStateEntry
*e
, *next
;
1595 trace_vm_state_notify(running
, state
);
1597 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1598 e
->cb(e
->opaque
, running
, state
);
1602 static int reset_requested
;
1603 static int shutdown_requested
, shutdown_signal
= -1;
1604 static pid_t shutdown_pid
;
1605 static int powerdown_requested
;
1606 static int debug_requested
;
1607 static int suspend_requested
;
1608 static WakeupReason wakeup_reason
;
1609 static NotifierList powerdown_notifiers
=
1610 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1611 static NotifierList suspend_notifiers
=
1612 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1613 static NotifierList wakeup_notifiers
=
1614 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1615 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1617 int qemu_shutdown_requested_get(void)
1619 return shutdown_requested
;
1622 int qemu_reset_requested_get(void)
1624 return reset_requested
;
1627 static int qemu_shutdown_requested(void)
1629 return atomic_xchg(&shutdown_requested
, 0);
1632 static void qemu_kill_report(void)
1634 if (!qtest_driver() && shutdown_signal
!= -1) {
1635 if (shutdown_pid
== 0) {
1636 /* This happens for eg ^C at the terminal, so it's worth
1637 * avoiding printing an odd message in that case.
1639 error_report("terminating on signal %d", shutdown_signal
);
1641 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1643 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1644 shutdown_signal
, shutdown_pid
,
1645 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1646 g_free(shutdown_cmd
);
1648 shutdown_signal
= -1;
1652 static int qemu_reset_requested(void)
1654 int r
= reset_requested
;
1655 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1656 reset_requested
= 0;
1662 static int qemu_suspend_requested(void)
1664 int r
= suspend_requested
;
1665 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1666 suspend_requested
= 0;
1672 static WakeupReason
qemu_wakeup_requested(void)
1674 return wakeup_reason
;
1677 static int qemu_powerdown_requested(void)
1679 int r
= powerdown_requested
;
1680 powerdown_requested
= 0;
1684 static int qemu_debug_requested(void)
1686 int r
= debug_requested
;
1687 debug_requested
= 0;
1691 void qemu_system_reset(bool report
)
1695 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1697 cpu_synchronize_all_states();
1699 if (mc
&& mc
->reset
) {
1702 qemu_devices_reset();
1705 qapi_event_send_reset(&error_abort
);
1707 cpu_synchronize_all_post_reset();
1710 void qemu_system_guest_panicked(void)
1713 current_cpu
->crash_occurred
= true;
1715 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
, &error_abort
);
1716 vm_stop(RUN_STATE_GUEST_PANICKED
);
1718 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1720 qemu_system_shutdown_request();
1724 void qemu_system_reset_request(void)
1727 shutdown_requested
= 1;
1729 reset_requested
= 1;
1732 qemu_notify_event();
1735 static void qemu_system_suspend(void)
1738 notifier_list_notify(&suspend_notifiers
, NULL
);
1739 runstate_set(RUN_STATE_SUSPENDED
);
1740 qapi_event_send_suspend(&error_abort
);
1743 void qemu_system_suspend_request(void)
1745 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1748 suspend_requested
= 1;
1750 qemu_notify_event();
1753 void qemu_register_suspend_notifier(Notifier
*notifier
)
1755 notifier_list_add(&suspend_notifiers
, notifier
);
1758 void qemu_system_wakeup_request(WakeupReason reason
)
1760 trace_system_wakeup_request(reason
);
1762 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1765 if (!(wakeup_reason_mask
& (1 << reason
))) {
1768 runstate_set(RUN_STATE_RUNNING
);
1769 wakeup_reason
= reason
;
1770 qemu_notify_event();
1773 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1776 wakeup_reason_mask
|= (1 << reason
);
1778 wakeup_reason_mask
&= ~(1 << reason
);
1782 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1784 notifier_list_add(&wakeup_notifiers
, notifier
);
1787 void qemu_system_killed(int signal
, pid_t pid
)
1789 shutdown_signal
= signal
;
1793 /* Cannot call qemu_system_shutdown_request directly because
1794 * we are in a signal handler.
1796 shutdown_requested
= 1;
1797 qemu_notify_event();
1800 void qemu_system_shutdown_request(void)
1802 trace_qemu_system_shutdown_request();
1803 replay_shutdown_request();
1804 shutdown_requested
= 1;
1805 qemu_notify_event();
1808 static void qemu_system_powerdown(void)
1810 qapi_event_send_powerdown(&error_abort
);
1811 notifier_list_notify(&powerdown_notifiers
, NULL
);
1814 void qemu_system_powerdown_request(void)
1816 trace_qemu_system_powerdown_request();
1817 powerdown_requested
= 1;
1818 qemu_notify_event();
1821 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1823 notifier_list_add(&powerdown_notifiers
, notifier
);
1826 void qemu_system_debug_request(void)
1828 debug_requested
= 1;
1829 qemu_notify_event();
1832 static bool main_loop_should_exit(void)
1835 if (qemu_debug_requested()) {
1836 vm_stop(RUN_STATE_DEBUG
);
1838 if (qemu_suspend_requested()) {
1839 qemu_system_suspend();
1841 if (qemu_shutdown_requested()) {
1843 qapi_event_send_shutdown(&error_abort
);
1845 vm_stop(RUN_STATE_SHUTDOWN
);
1850 if (qemu_reset_requested()) {
1852 qemu_system_reset(VMRESET_REPORT
);
1854 if (!runstate_check(RUN_STATE_RUNNING
) &&
1855 !runstate_check(RUN_STATE_INMIGRATE
)) {
1856 runstate_set(RUN_STATE_PRELAUNCH
);
1859 if (qemu_wakeup_requested()) {
1861 qemu_system_reset(VMRESET_SILENT
);
1862 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1863 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1865 qapi_event_send_wakeup(&error_abort
);
1867 if (qemu_powerdown_requested()) {
1868 qemu_system_powerdown();
1870 if (qemu_vmstop_requested(&r
)) {
1876 static void main_loop(void)
1880 #ifdef CONFIG_PROFILER
1884 nonblocking
= tcg_enabled() && last_io
> 0;
1885 #ifdef CONFIG_PROFILER
1886 ti
= profile_getclock();
1888 last_io
= main_loop_wait(nonblocking
);
1889 #ifdef CONFIG_PROFILER
1890 dev_time
+= profile_getclock() - ti
;
1892 } while (!main_loop_should_exit());
1895 static void version(void)
1897 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1898 QEMU_COPYRIGHT
"\n");
1901 static void help(int exitcode
)
1904 printf("usage: %s [options] [disk_image]\n\n"
1905 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1906 error_get_progname());
1908 #define QEMU_OPTIONS_GENERATE_HELP
1909 #include "qemu-options-wrapper.h"
1911 printf("\nDuring emulation, the following keys are useful:\n"
1912 "ctrl-alt-f toggle full screen\n"
1913 "ctrl-alt-n switch to virtual console 'n'\n"
1914 "ctrl-alt toggle mouse and keyboard grab\n"
1916 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1921 #define HAS_ARG 0x0001
1923 typedef struct QEMUOption
{
1930 static const QEMUOption qemu_options
[] = {
1931 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1932 #define QEMU_OPTIONS_GENERATE_OPTIONS
1933 #include "qemu-options-wrapper.h"
1937 typedef struct VGAInterfaceInfo
{
1938 const char *opt_name
; /* option name */
1939 const char *name
; /* human-readable name */
1940 /* Class names indicating that support is available.
1941 * If no class is specified, the interface is always available */
1942 const char *class_names
[2];
1945 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1951 .name
= "standard VGA",
1952 .class_names
= { "VGA", "isa-vga" },
1955 .opt_name
= "cirrus",
1956 .name
= "Cirrus VGA",
1957 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1960 .opt_name
= "vmware",
1961 .name
= "VMWare SVGA",
1962 .class_names
= { "vmware-svga" },
1965 .opt_name
= "virtio",
1966 .name
= "Virtio VGA",
1967 .class_names
= { "virtio-vga" },
1972 .class_names
= { "qxl-vga" },
1976 .name
= "TCX framebuffer",
1977 .class_names
= { "SUNW,tcx" },
1981 .name
= "CG3 framebuffer",
1982 .class_names
= { "cgthree" },
1985 .opt_name
= "xenfb",
1989 static bool vga_interface_available(VGAInterfaceType t
)
1991 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
1993 assert(t
< VGA_TYPE_MAX
);
1994 return !ti
->class_names
[0] ||
1995 object_class_by_name(ti
->class_names
[0]) ||
1996 object_class_by_name(ti
->class_names
[1]);
1999 static void select_vgahw(const char *p
)
2004 assert(vga_interface_type
== VGA_NONE
);
2005 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2006 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2007 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2008 if (!vga_interface_available(t
)) {
2009 error_report("%s not available", ti
->name
);
2012 vga_interface_type
= t
;
2016 if (t
== VGA_TYPE_MAX
) {
2018 error_report("unknown vga type: %s", p
);
2022 const char *nextopt
;
2024 if (strstart(opts
, ",retrace=", &nextopt
)) {
2026 if (strstart(opts
, "dumb", &nextopt
))
2027 vga_retrace_method
= VGA_RETRACE_DUMB
;
2028 else if (strstart(opts
, "precise", &nextopt
))
2029 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2030 else goto invalid_vga
;
2031 } else goto invalid_vga
;
2036 typedef enum DisplayType
{
2045 static DisplayType
select_display(const char *p
)
2048 DisplayType display
= DT_DEFAULT
;
2050 if (strstart(p
, "sdl", &opts
)) {
2054 const char *nextopt
;
2056 if (strstart(opts
, ",frame=", &nextopt
)) {
2058 if (strstart(opts
, "on", &nextopt
)) {
2060 } else if (strstart(opts
, "off", &nextopt
)) {
2063 goto invalid_sdl_args
;
2065 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2067 if (strstart(opts
, "on", &nextopt
)) {
2069 } else if (strstart(opts
, "off", &nextopt
)) {
2072 goto invalid_sdl_args
;
2074 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2076 if (strstart(opts
, "on", &nextopt
)) {
2078 } else if (strstart(opts
, "off", &nextopt
)) {
2081 goto invalid_sdl_args
;
2083 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2085 if (strstart(opts
, "on", &nextopt
)) {
2087 } else if (strstart(opts
, "off", &nextopt
)) {
2090 goto invalid_sdl_args
;
2092 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2094 if (strstart(opts
, "on", &nextopt
)) {
2096 } else if (strstart(opts
, "off", &nextopt
)) {
2099 goto invalid_sdl_args
;
2103 error_report("invalid SDL option string");
2109 error_report("SDL support is disabled");
2112 } else if (strstart(p
, "vnc", &opts
)) {
2114 vnc_parse(opts
+ 1, &error_fatal
);
2116 error_report("VNC requires a display argument vnc=<display>");
2119 } else if (strstart(p
, "curses", &opts
)) {
2120 #ifdef CONFIG_CURSES
2121 display
= DT_CURSES
;
2123 error_report("curses support is disabled");
2126 } else if (strstart(p
, "gtk", &opts
)) {
2130 const char *nextopt
;
2132 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2134 if (strstart(opts
, "on", &nextopt
)) {
2135 grab_on_hover
= true;
2136 } else if (strstart(opts
, "off", &nextopt
)) {
2137 grab_on_hover
= false;
2139 goto invalid_gtk_args
;
2141 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2143 if (strstart(opts
, "on", &nextopt
)) {
2145 } else if (strstart(opts
, "off", &nextopt
)) {
2148 goto invalid_gtk_args
;
2152 error_report("invalid GTK option string");
2158 error_report("GTK support is disabled");
2161 } else if (strstart(p
, "none", &opts
)) {
2164 error_report("unknown display type");
2171 static int balloon_parse(const char *arg
)
2175 if (strcmp(arg
, "none") == 0) {
2179 if (!strncmp(arg
, "virtio", 6)) {
2180 if (arg
[6] == ',') {
2181 /* have params -> parse them */
2182 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2187 /* create empty opts */
2188 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2191 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2198 char *qemu_find_file(int type
, const char *name
)
2204 /* Try the name as a straight path first */
2205 if (access(name
, R_OK
) == 0) {
2206 trace_load_file(name
, name
);
2207 return g_strdup(name
);
2211 case QEMU_FILE_TYPE_BIOS
:
2214 case QEMU_FILE_TYPE_KEYMAP
:
2215 subdir
= "keymaps/";
2221 for (i
= 0; i
< data_dir_idx
; i
++) {
2222 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2223 if (access(buf
, R_OK
) == 0) {
2224 trace_load_file(name
, buf
);
2232 static inline bool nonempty_str(const char *str
)
2237 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2241 const char *name
, *file
, *str
;
2242 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2244 if (fw_cfg
== NULL
) {
2245 error_report("fw_cfg device not available");
2248 name
= qemu_opt_get(opts
, "name");
2249 file
= qemu_opt_get(opts
, "file");
2250 str
= qemu_opt_get(opts
, "string");
2252 /* we need name and either a file or the content string */
2253 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2254 error_report("invalid argument(s)");
2257 if (nonempty_str(file
) && nonempty_str(str
)) {
2258 error_report("file and string are mutually exclusive");
2261 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2262 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2265 if (strncmp(name
, "opt/", 4) != 0) {
2266 error_report("warning: externally provided fw_cfg item names "
2267 "should be prefixed with \"opt/\"");
2269 if (nonempty_str(str
)) {
2270 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2271 buf
= g_memdup(str
, size
);
2273 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2274 error_report("can't load %s", file
);
2278 /* For legacy, keep user files in a specific global order. */
2279 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2280 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2281 fw_cfg_reset_order_override(fw_cfg
);
2285 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2287 return qdev_device_help(opts
);
2290 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2295 dev
= qdev_device_add(opts
, &err
);
2297 error_report_err(err
);
2300 object_unref(OBJECT(dev
));
2304 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2306 Error
*local_err
= NULL
;
2308 qemu_chr_new_from_opts(opts
, &local_err
);
2310 error_report_err(local_err
);
2316 #ifdef CONFIG_VIRTFS
2317 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2319 return qemu_fsdev_add(opts
);
2323 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2326 const char *chardev
;
2330 mode
= qemu_opt_get(opts
, "mode");
2334 if (strcmp(mode
, "readline") == 0) {
2335 flags
= MONITOR_USE_READLINE
;
2336 } else if (strcmp(mode
, "control") == 0) {
2337 flags
= MONITOR_USE_CONTROL
;
2339 error_report("unknown monitor mode \"%s\"", mode
);
2343 if (qemu_opt_get_bool(opts
, "pretty", 0))
2344 flags
|= MONITOR_USE_PRETTY
;
2346 if (qemu_opt_get_bool(opts
, "default", 0)) {
2347 error_report("option 'default' does nothing and is deprecated");
2350 chardev
= qemu_opt_get(opts
, "chardev");
2351 chr
= qemu_chr_find(chardev
);
2353 error_report("chardev \"%s\" not found", chardev
);
2357 monitor_init(chr
, flags
);
2361 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2363 static int monitor_device_index
= 0;
2368 if (strstart(optarg
, "chardev:", &p
)) {
2369 snprintf(label
, sizeof(label
), "%s", p
);
2371 snprintf(label
, sizeof(label
), "compat_monitor%d",
2372 monitor_device_index
);
2373 opts
= qemu_chr_parse_compat(label
, optarg
);
2375 error_report("parse error: %s", optarg
);
2380 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2381 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2382 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2383 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2384 monitor_device_index
++;
2387 struct device_config
{
2389 DEV_USB
, /* -usbdevice */
2391 DEV_SERIAL
, /* -serial */
2392 DEV_PARALLEL
, /* -parallel */
2393 DEV_VIRTCON
, /* -virtioconsole */
2394 DEV_DEBUGCON
, /* -debugcon */
2395 DEV_GDB
, /* -gdb, -s */
2396 DEV_SCLP
, /* s390 sclp */
2398 const char *cmdline
;
2400 QTAILQ_ENTRY(device_config
) next
;
2403 static QTAILQ_HEAD(, device_config
) device_configs
=
2404 QTAILQ_HEAD_INITIALIZER(device_configs
);
2406 static void add_device_config(int type
, const char *cmdline
)
2408 struct device_config
*conf
;
2410 conf
= g_malloc0(sizeof(*conf
));
2412 conf
->cmdline
= cmdline
;
2413 loc_save(&conf
->loc
);
2414 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2417 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2419 struct device_config
*conf
;
2422 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2423 if (conf
->type
!= type
)
2425 loc_push_restore(&conf
->loc
);
2426 rc
= func(conf
->cmdline
);
2427 loc_pop(&conf
->loc
);
2435 static int serial_parse(const char *devname
)
2437 static int index
= 0;
2440 if (strcmp(devname
, "none") == 0)
2442 if (index
== MAX_SERIAL_PORTS
) {
2443 error_report("too many serial ports");
2446 snprintf(label
, sizeof(label
), "serial%d", index
);
2447 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2448 if (!serial_hds
[index
]) {
2449 error_report("could not connect serial device"
2450 " to character backend '%s'", devname
);
2457 static int parallel_parse(const char *devname
)
2459 static int index
= 0;
2462 if (strcmp(devname
, "none") == 0)
2464 if (index
== MAX_PARALLEL_PORTS
) {
2465 error_report("too many parallel ports");
2468 snprintf(label
, sizeof(label
), "parallel%d", index
);
2469 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2470 if (!parallel_hds
[index
]) {
2471 error_report("could not connect parallel device"
2472 " to character backend '%s'", devname
);
2479 static int virtcon_parse(const char *devname
)
2481 QemuOptsList
*device
= qemu_find_opts("device");
2482 static int index
= 0;
2484 QemuOpts
*bus_opts
, *dev_opts
;
2486 if (strcmp(devname
, "none") == 0)
2488 if (index
== MAX_VIRTIO_CONSOLES
) {
2489 error_report("too many virtio consoles");
2493 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2494 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2496 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2497 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2499 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2500 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2501 if (!virtcon_hds
[index
]) {
2502 error_report("could not connect virtio console"
2503 " to character backend '%s'", devname
);
2506 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2512 static int sclp_parse(const char *devname
)
2514 QemuOptsList
*device
= qemu_find_opts("device");
2515 static int index
= 0;
2519 if (strcmp(devname
, "none") == 0) {
2522 if (index
== MAX_SCLP_CONSOLES
) {
2523 error_report("too many sclp consoles");
2527 assert(arch_type
== QEMU_ARCH_S390X
);
2529 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2530 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2532 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2533 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2534 if (!sclp_hds
[index
]) {
2535 error_report("could not connect sclp console"
2536 " to character backend '%s'", devname
);
2539 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2545 static int debugcon_parse(const char *devname
)
2549 if (!qemu_chr_new("debugcon", devname
)) {
2552 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2554 error_report("already have a debugcon device");
2557 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2558 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2562 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2564 const MachineClass
*mc1
= a
, *mc2
= b
;
2567 if (mc1
->family
== NULL
) {
2568 if (mc2
->family
== NULL
) {
2569 /* Compare standalone machine types against each other; they sort
2570 * in increasing order.
2572 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2573 object_class_get_name(OBJECT_CLASS(mc2
)));
2576 /* Standalone machine types sort after families. */
2580 if (mc2
->family
== NULL
) {
2581 /* Families sort before standalone machine types. */
2585 /* Families sort between each other alphabetically increasingly. */
2586 res
= strcmp(mc1
->family
, mc2
->family
);
2591 /* Within the same family, machine types sort in decreasing order. */
2592 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2593 object_class_get_name(OBJECT_CLASS(mc1
)));
2596 static MachineClass
*machine_parse(const char *name
)
2598 MachineClass
*mc
= NULL
;
2599 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2602 mc
= find_machine(name
);
2605 g_slist_free(machines
);
2608 if (name
&& !is_help_option(name
)) {
2609 error_report("unsupported machine type");
2610 error_printf("Use -machine help to list supported machines\n");
2612 printf("Supported machines are:\n");
2613 machines
= g_slist_sort(machines
, machine_class_cmp
);
2614 for (el
= machines
; el
; el
= el
->next
) {
2615 MachineClass
*mc
= el
->data
;
2617 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2619 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2620 mc
->is_default
? " (default)" : "");
2624 g_slist_free(machines
);
2625 exit(!name
|| !is_help_option(name
));
2628 void qemu_add_exit_notifier(Notifier
*notify
)
2630 notifier_list_add(&exit_notifiers
, notify
);
2633 void qemu_remove_exit_notifier(Notifier
*notify
)
2635 notifier_remove(notify
);
2638 static void qemu_run_exit_notifiers(void)
2640 notifier_list_notify(&exit_notifiers
, NULL
);
2643 static bool machine_init_done
;
2645 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2647 notifier_list_add(&machine_init_done_notifiers
, notify
);
2648 if (machine_init_done
) {
2649 notify
->notify(notify
, NULL
);
2653 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2655 notifier_remove(notify
);
2658 static void qemu_run_machine_init_done_notifiers(void)
2660 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2661 machine_init_done
= true;
2664 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2665 const char **poptarg
, int *poptind
)
2667 const QEMUOption
*popt
;
2668 int optind
= *poptind
;
2669 char *r
= argv
[optind
];
2672 loc_set_cmdline(argv
, optind
, 1);
2674 /* Treat --foo the same as -foo. */
2677 popt
= qemu_options
;
2680 error_report("invalid option");
2683 if (!strcmp(popt
->name
, r
+ 1))
2687 if (popt
->flags
& HAS_ARG
) {
2688 if (optind
>= argc
) {
2689 error_report("requires an argument");
2692 optarg
= argv
[optind
++];
2693 loc_set_cmdline(argv
, optind
- 2, 2);
2704 static MachineClass
*select_machine(void)
2706 MachineClass
*machine_class
= find_default_machine();
2711 loc_push_none(&loc
);
2713 opts
= qemu_get_machine_opts();
2714 qemu_opts_loc_restore(opts
);
2716 optarg
= qemu_opt_get(opts
, "type");
2718 machine_class
= machine_parse(optarg
);
2721 if (!machine_class
) {
2722 error_report("No machine specified, and there is no default");
2723 error_printf("Use -machine help to list supported machines\n");
2728 return machine_class
;
2731 static int machine_set_property(void *opaque
,
2732 const char *name
, const char *value
,
2735 Object
*obj
= OBJECT(opaque
);
2736 Error
*local_err
= NULL
;
2739 if (strcmp(name
, "type") == 0) {
2743 qom_name
= g_strdup(name
);
2744 for (p
= qom_name
; *p
; p
++) {
2750 object_property_parse(obj
, value
, qom_name
, &local_err
);
2754 error_report_err(local_err
);
2763 * Initial object creation happens before all other
2764 * QEMU data types are created. The majority of objects
2765 * can be created at this point. The rng-egd object
2766 * cannot be created here, as it depends on the chardev
2769 static bool object_create_initial(const char *type
)
2771 if (g_str_equal(type
, "rng-egd")) {
2776 * return false for concrete netfilters since
2777 * they depend on netdevs already existing
2779 if (g_str_equal(type
, "filter-buffer") ||
2780 g_str_equal(type
, "filter-dump") ||
2781 g_str_equal(type
, "filter-mirror") ||
2782 g_str_equal(type
, "filter-redirector") ||
2783 g_str_equal(type
, "colo-compare") ||
2784 g_str_equal(type
, "filter-rewriter") ||
2785 g_str_equal(type
, "filter-replay")) {
2789 /* Memory allocation by backends needs to be done
2790 * after configure_accelerator() (due to the tcg_enabled()
2791 * checks at memory_region_init_*()).
2793 * Also, allocation of large amounts of memory may delay
2794 * chardev initialization for too long, and trigger timeouts
2795 * on software that waits for a monitor socket to be created
2798 if (g_str_has_prefix(type
, "memory-backend-")) {
2807 * The remainder of object creation happens after the
2808 * creation of chardev, fsdev, net clients and device data types.
2810 static bool object_create_delayed(const char *type
)
2812 return !object_create_initial(type
);
2816 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2820 const char *mem_str
;
2821 const char *maxmem_str
, *slots_str
;
2822 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2823 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2826 loc_push_none(&loc
);
2827 qemu_opts_loc_restore(opts
);
2830 mem_str
= qemu_opt_get(opts
, "size");
2833 error_report("missing 'size' option value");
2837 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2839 /* Fix up legacy suffix-less format */
2840 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2841 uint64_t overflow_check
= sz
;
2844 if ((sz
>> 20) != overflow_check
) {
2845 error_report("too large 'size' option value");
2851 /* backward compatibility behaviour for case "-m 0" */
2853 sz
= default_ram_size
;
2856 sz
= QEMU_ALIGN_UP(sz
, 8192);
2858 if (ram_size
!= sz
) {
2859 error_report("ram size too large");
2863 /* store value for the future use */
2864 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2865 *maxram_size
= ram_size
;
2867 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2868 slots_str
= qemu_opt_get(opts
, "slots");
2869 if (maxmem_str
&& slots_str
) {
2872 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2873 slots
= qemu_opt_get_number(opts
, "slots", 0);
2874 if (sz
< ram_size
) {
2875 error_report("invalid value of -m option maxmem: "
2876 "maximum memory size (0x%" PRIx64
") must be at least "
2877 "the initial memory size (0x" RAM_ADDR_FMT
")",
2880 } else if (sz
> ram_size
) {
2882 error_report("invalid value of -m option: maxmem was "
2883 "specified, but no hotplug slots were specified");
2887 error_report("invalid value of -m option maxmem: "
2888 "memory slots were specified but maximum memory size "
2889 "(0x%" PRIx64
") is equal to the initial memory size "
2890 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2896 } else if ((!maxmem_str
&& slots_str
) ||
2897 (maxmem_str
&& !slots_str
)) {
2898 error_report("invalid -m option value: missing "
2899 "'%s' option", slots_str
? "maxmem" : "slots");
2906 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2910 g
= g_malloc0(sizeof(*g
));
2911 g
->driver
= qemu_opt_get(opts
, "driver");
2912 g
->property
= qemu_opt_get(opts
, "property");
2913 g
->value
= qemu_opt_get(opts
, "value");
2914 g
->user_provided
= true;
2915 g
->errp
= &error_fatal
;
2916 qdev_prop_register_global(g
);
2920 static int qemu_read_default_config_file(void)
2924 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2925 if (ret
< 0 && ret
!= -ENOENT
) {
2932 int main(int argc
, char **argv
, char **envp
)
2935 int snapshot
, linux_boot
;
2936 const char *initrd_filename
;
2937 const char *kernel_filename
, *kernel_cmdline
;
2938 const char *boot_order
= NULL
;
2939 const char *boot_once
= NULL
;
2941 int cyls
, heads
, secs
, translation
;
2942 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
2943 QemuOptsList
*olist
;
2946 const char *loadvm
= NULL
;
2947 MachineClass
*machine_class
;
2948 const char *cpu_model
;
2949 const char *vga_model
= NULL
;
2950 const char *qtest_chrdev
= NULL
;
2951 const char *qtest_log
= NULL
;
2952 const char *pid_file
= NULL
;
2953 const char *incoming
= NULL
;
2954 bool defconfig
= true;
2955 bool userconfig
= true;
2956 bool nographic
= false;
2957 DisplayType display_type
= DT_DEFAULT
;
2958 int display_remote
= 0;
2959 const char *log_mask
= NULL
;
2960 const char *log_file
= NULL
;
2961 char *trace_file
= NULL
;
2962 ram_addr_t maxram_size
;
2963 uint64_t ram_slots
= 0;
2964 FILE *vmstate_dump_file
= NULL
;
2965 Error
*main_loop_err
= NULL
;
2967 bool list_data_dirs
= false;
2969 module_call_init(MODULE_INIT_TRACE
);
2971 qemu_init_cpu_list();
2972 qemu_init_cpu_loop();
2973 qemu_mutex_lock_iothread();
2975 atexit(qemu_run_exit_notifiers
);
2976 error_set_progname(argv
[0]);
2977 qemu_init_exec_dir(argv
[0]);
2979 module_call_init(MODULE_INIT_QOM
);
2980 module_call_init(MODULE_INIT_QAPI
);
2982 qemu_add_opts(&qemu_drive_opts
);
2983 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2984 qemu_add_drive_opts(&qemu_common_drive_opts
);
2985 qemu_add_drive_opts(&qemu_drive_opts
);
2986 qemu_add_drive_opts(&bdrv_runtime_opts
);
2987 qemu_add_opts(&qemu_chardev_opts
);
2988 qemu_add_opts(&qemu_device_opts
);
2989 qemu_add_opts(&qemu_netdev_opts
);
2990 qemu_add_opts(&qemu_net_opts
);
2991 qemu_add_opts(&qemu_rtc_opts
);
2992 qemu_add_opts(&qemu_global_opts
);
2993 qemu_add_opts(&qemu_mon_opts
);
2994 qemu_add_opts(&qemu_trace_opts
);
2995 qemu_add_opts(&qemu_option_rom_opts
);
2996 qemu_add_opts(&qemu_machine_opts
);
2997 qemu_add_opts(&qemu_mem_opts
);
2998 qemu_add_opts(&qemu_smp_opts
);
2999 qemu_add_opts(&qemu_boot_opts
);
3000 qemu_add_opts(&qemu_sandbox_opts
);
3001 qemu_add_opts(&qemu_add_fd_opts
);
3002 qemu_add_opts(&qemu_object_opts
);
3003 qemu_add_opts(&qemu_tpmdev_opts
);
3004 qemu_add_opts(&qemu_realtime_opts
);
3005 qemu_add_opts(&qemu_msg_opts
);
3006 qemu_add_opts(&qemu_name_opts
);
3007 qemu_add_opts(&qemu_numa_opts
);
3008 qemu_add_opts(&qemu_icount_opts
);
3009 qemu_add_opts(&qemu_semihosting_config_opts
);
3010 qemu_add_opts(&qemu_fw_cfg_opts
);
3011 module_call_init(MODULE_INIT_OPTS
);
3015 if (qcrypto_init(&err
) < 0) {
3016 error_reportf_err(err
, "cannot initialize crypto: ");
3019 rtc_clock
= QEMU_CLOCK_HOST
;
3021 QLIST_INIT (&vm_change_state_head
);
3022 os_setup_early_signal_handling();
3026 cyls
= heads
= secs
= 0;
3027 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3031 bdrv_init_with_whitelist();
3035 /* first pass of option parsing */
3037 while (optind
< argc
) {
3038 if (argv
[optind
][0] != '-') {
3042 const QEMUOption
*popt
;
3044 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3045 switch (popt
->index
) {
3046 case QEMU_OPTION_nodefconfig
:
3049 case QEMU_OPTION_nouserconfig
:
3056 if (defconfig
&& userconfig
) {
3057 if (qemu_read_default_config_file() < 0) {
3062 /* second pass of option parsing */
3067 if (argv
[optind
][0] != '-') {
3068 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3070 const QEMUOption
*popt
;
3072 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3073 if (!(popt
->arch_mask
& arch_type
)) {
3074 error_report("Option not supported for this target");
3077 switch(popt
->index
) {
3078 case QEMU_OPTION_no_kvm_irqchip
: {
3079 olist
= qemu_find_opts("machine");
3080 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3083 case QEMU_OPTION_cpu
:
3084 /* hw initialization will check this */
3087 case QEMU_OPTION_hda
:
3091 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3093 snprintf(buf
, sizeof(buf
),
3094 "%s,cyls=%d,heads=%d,secs=%d%s",
3095 HD_OPTS
, cyls
, heads
, secs
,
3096 translation
== BIOS_ATA_TRANSLATION_LBA
?
3098 translation
== BIOS_ATA_TRANSLATION_NONE
?
3099 ",trans=none" : "");
3100 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3103 case QEMU_OPTION_hdb
:
3104 case QEMU_OPTION_hdc
:
3105 case QEMU_OPTION_hdd
:
3106 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3109 case QEMU_OPTION_drive
:
3110 if (drive_def(optarg
) == NULL
) {
3114 case QEMU_OPTION_set
:
3115 if (qemu_set_option(optarg
) != 0)
3118 case QEMU_OPTION_global
:
3119 if (qemu_global_option(optarg
) != 0)
3122 case QEMU_OPTION_mtdblock
:
3123 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3125 case QEMU_OPTION_sd
:
3126 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3128 case QEMU_OPTION_pflash
:
3129 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3131 case QEMU_OPTION_snapshot
:
3134 case QEMU_OPTION_hdachs
:
3138 cyls
= strtol(p
, (char **)&p
, 0);
3139 if (cyls
< 1 || cyls
> 16383)
3144 heads
= strtol(p
, (char **)&p
, 0);
3145 if (heads
< 1 || heads
> 16)
3150 secs
= strtol(p
, (char **)&p
, 0);
3151 if (secs
< 1 || secs
> 63)
3155 if (!strcmp(p
, "large")) {
3156 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3157 } else if (!strcmp(p
, "rechs")) {
3158 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3159 } else if (!strcmp(p
, "none")) {
3160 translation
= BIOS_ATA_TRANSLATION_NONE
;
3161 } else if (!strcmp(p
, "lba")) {
3162 translation
= BIOS_ATA_TRANSLATION_LBA
;
3163 } else if (!strcmp(p
, "auto")) {
3164 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3168 } else if (*p
!= '\0') {
3170 error_report("invalid physical CHS format");
3173 if (hda_opts
!= NULL
) {
3174 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3176 qemu_opt_set_number(hda_opts
, "heads", heads
,
3178 qemu_opt_set_number(hda_opts
, "secs", secs
,
3180 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3181 qemu_opt_set(hda_opts
, "trans", "large",
3183 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3184 qemu_opt_set(hda_opts
, "trans", "rechs",
3186 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3187 qemu_opt_set(hda_opts
, "trans", "lba",
3189 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3190 qemu_opt_set(hda_opts
, "trans", "none",
3196 case QEMU_OPTION_numa
:
3197 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3203 case QEMU_OPTION_display
:
3204 display_type
= select_display(optarg
);
3206 case QEMU_OPTION_nographic
:
3207 olist
= qemu_find_opts("machine");
3208 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3210 display_type
= DT_NONE
;
3212 case QEMU_OPTION_curses
:
3213 #ifdef CONFIG_CURSES
3214 display_type
= DT_CURSES
;
3216 error_report("curses support is disabled");
3220 case QEMU_OPTION_portrait
:
3221 graphic_rotate
= 90;
3223 case QEMU_OPTION_rotate
:
3224 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3225 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3226 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3227 error_report("only 90, 180, 270 deg rotation is available");
3231 case QEMU_OPTION_kernel
:
3232 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3235 case QEMU_OPTION_initrd
:
3236 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3239 case QEMU_OPTION_append
:
3240 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3243 case QEMU_OPTION_dtb
:
3244 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3247 case QEMU_OPTION_cdrom
:
3248 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3250 case QEMU_OPTION_boot
:
3251 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3257 case QEMU_OPTION_fda
:
3258 case QEMU_OPTION_fdb
:
3259 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3262 case QEMU_OPTION_no_fd_bootchk
:
3265 case QEMU_OPTION_netdev
:
3267 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3271 case QEMU_OPTION_net
:
3273 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3277 #ifdef CONFIG_LIBISCSI
3278 case QEMU_OPTION_iscsi
:
3279 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3287 case QEMU_OPTION_tftp
:
3288 error_report("The -tftp option is deprecated. "
3289 "Please use '-netdev user,tftp=...' instead.");
3290 legacy_tftp_prefix
= optarg
;
3292 case QEMU_OPTION_bootp
:
3293 error_report("The -bootp option is deprecated. "
3294 "Please use '-netdev user,bootfile=...' instead.");
3295 legacy_bootp_filename
= optarg
;
3297 case QEMU_OPTION_redir
:
3298 error_report("The -redir option is deprecated. "
3299 "Please use '-netdev user,hostfwd=...' instead.");
3300 if (net_slirp_redir(optarg
) < 0)
3304 case QEMU_OPTION_bt
:
3305 add_device_config(DEV_BT
, optarg
);
3307 case QEMU_OPTION_audio_help
:
3311 case QEMU_OPTION_soundhw
:
3312 select_soundhw (optarg
);
3317 case QEMU_OPTION_version
:
3322 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3329 case QEMU_OPTION_tpmdev
:
3330 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3335 case QEMU_OPTION_mempath
:
3338 case QEMU_OPTION_mem_prealloc
:
3347 case QEMU_OPTION_DFILTER
:
3348 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3351 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3353 case QEMU_OPTION_gdb
:
3354 add_device_config(DEV_GDB
, optarg
);
3357 if (is_help_option(optarg
)) {
3358 list_data_dirs
= true;
3359 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3360 data_dir
[data_dir_idx
++] = optarg
;
3363 case QEMU_OPTION_bios
:
3364 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3367 case QEMU_OPTION_singlestep
:
3374 keyboard_layout
= optarg
;
3376 case QEMU_OPTION_localtime
:
3379 case QEMU_OPTION_vga
:
3388 w
= strtol(p
, (char **)&p
, 10);
3391 error_report("invalid resolution or depth");
3397 h
= strtol(p
, (char **)&p
, 10);
3402 depth
= strtol(p
, (char **)&p
, 10);
3403 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3404 depth
!= 24 && depth
!= 32)
3406 } else if (*p
== '\0') {
3407 depth
= graphic_depth
;
3414 graphic_depth
= depth
;
3417 case QEMU_OPTION_echr
:
3420 term_escape_char
= strtol(optarg
, &r
, 0);
3422 printf("Bad argument to echr\n");
3425 case QEMU_OPTION_monitor
:
3426 default_monitor
= 0;
3427 if (strncmp(optarg
, "none", 4)) {
3428 monitor_parse(optarg
, "readline", false);
3431 case QEMU_OPTION_qmp
:
3432 monitor_parse(optarg
, "control", false);
3433 default_monitor
= 0;
3435 case QEMU_OPTION_qmp_pretty
:
3436 monitor_parse(optarg
, "control", true);
3437 default_monitor
= 0;
3439 case QEMU_OPTION_mon
:
3440 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3445 default_monitor
= 0;
3447 case QEMU_OPTION_chardev
:
3448 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3454 case QEMU_OPTION_fsdev
:
3455 olist
= qemu_find_opts("fsdev");
3457 error_report("fsdev support is disabled");
3460 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3465 case QEMU_OPTION_virtfs
: {
3468 const char *writeout
, *sock_fd
, *socket
;
3470 olist
= qemu_find_opts("virtfs");
3472 error_report("virtfs support is disabled");
3475 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3480 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3481 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3482 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3485 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3486 qemu_opt_get(opts
, "mount_tag"),
3489 error_report("duplicate fsdev id: %s",
3490 qemu_opt_get(opts
, "mount_tag"));
3494 writeout
= qemu_opt_get(opts
, "writeout");
3496 #ifdef CONFIG_SYNC_FILE_RANGE
3497 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3499 error_report("writeout=immediate not supported "
3500 "on this platform");
3504 qemu_opt_set(fsdev
, "fsdriver",
3505 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3506 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3508 qemu_opt_set(fsdev
, "security_model",
3509 qemu_opt_get(opts
, "security_model"),
3511 socket
= qemu_opt_get(opts
, "socket");
3513 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3515 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3517 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3520 qemu_opt_set_bool(fsdev
, "readonly",
3521 qemu_opt_get_bool(opts
, "readonly", 0),
3523 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3525 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3526 qemu_opt_set(device
, "fsdev",
3527 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3528 qemu_opt_set(device
, "mount_tag",
3529 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3532 case QEMU_OPTION_virtfs_synth
: {
3536 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3539 error_report("duplicate option: %s", "virtfs_synth");
3542 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3544 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3546 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3547 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3548 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3551 case QEMU_OPTION_serial
:
3552 add_device_config(DEV_SERIAL
, optarg
);
3554 if (strncmp(optarg
, "mon:", 4) == 0) {
3555 default_monitor
= 0;
3558 case QEMU_OPTION_watchdog
:
3560 error_report("only one watchdog option may be given");
3565 case QEMU_OPTION_watchdog_action
:
3566 if (select_watchdog_action(optarg
) == -1) {
3567 error_report("unknown -watchdog-action parameter");
3571 case QEMU_OPTION_virtiocon
:
3572 add_device_config(DEV_VIRTCON
, optarg
);
3573 default_virtcon
= 0;
3574 if (strncmp(optarg
, "mon:", 4) == 0) {
3575 default_monitor
= 0;
3578 case QEMU_OPTION_parallel
:
3579 add_device_config(DEV_PARALLEL
, optarg
);
3580 default_parallel
= 0;
3581 if (strncmp(optarg
, "mon:", 4) == 0) {
3582 default_monitor
= 0;
3585 case QEMU_OPTION_debugcon
:
3586 add_device_config(DEV_DEBUGCON
, optarg
);
3588 case QEMU_OPTION_loadvm
:
3591 case QEMU_OPTION_full_screen
:
3594 case QEMU_OPTION_no_frame
:
3597 case QEMU_OPTION_alt_grab
:
3600 case QEMU_OPTION_ctrl_grab
:
3603 case QEMU_OPTION_no_quit
:
3606 case QEMU_OPTION_sdl
:
3608 display_type
= DT_SDL
;
3611 error_report("SDL support is disabled");
3614 case QEMU_OPTION_pidfile
:
3617 case QEMU_OPTION_win2k_hack
:
3618 win2k_install_hack
= 1;
3620 case QEMU_OPTION_rtc_td_hack
: {
3621 static GlobalProperty slew_lost_ticks
= {
3622 .driver
= "mc146818rtc",
3623 .property
= "lost_tick_policy",
3627 qdev_prop_register_global(&slew_lost_ticks
);
3630 case QEMU_OPTION_acpitable
:
3631 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3636 acpi_table_add(opts
, &error_fatal
);
3638 case QEMU_OPTION_smbios
:
3639 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3644 smbios_entry_add(opts
, &error_fatal
);
3646 case QEMU_OPTION_fwcfg
:
3647 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3653 case QEMU_OPTION_enable_kvm
:
3654 olist
= qemu_find_opts("machine");
3655 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3657 case QEMU_OPTION_enable_hax
:
3658 olist
= qemu_find_opts("machine");
3659 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3662 case QEMU_OPTION_machine
:
3663 olist
= qemu_find_opts("machine");
3664 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3669 case QEMU_OPTION_no_kvm
:
3670 olist
= qemu_find_opts("machine");
3671 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3673 case QEMU_OPTION_no_kvm_pit
: {
3674 error_report("warning: ignoring deprecated option");
3677 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3678 static GlobalProperty kvm_pit_lost_tick_policy
= {
3679 .driver
= "kvm-pit",
3680 .property
= "lost_tick_policy",
3684 error_report("warning: deprecated, replaced by "
3685 "-global kvm-pit.lost_tick_policy=discard");
3686 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3689 case QEMU_OPTION_usb
:
3690 olist
= qemu_find_opts("machine");
3691 qemu_opts_parse_noisily(olist
, "usb=on", false);
3693 case QEMU_OPTION_usbdevice
:
3694 olist
= qemu_find_opts("machine");
3695 qemu_opts_parse_noisily(olist
, "usb=on", false);
3696 add_device_config(DEV_USB
, optarg
);
3698 case QEMU_OPTION_device
:
3699 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3704 case QEMU_OPTION_smp
:
3705 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3710 case QEMU_OPTION_vnc
:
3711 vnc_parse(optarg
, &error_fatal
);
3713 case QEMU_OPTION_no_acpi
:
3716 case QEMU_OPTION_no_hpet
:
3719 case QEMU_OPTION_balloon
:
3720 if (balloon_parse(optarg
) < 0) {
3721 error_report("unknown -balloon argument %s", optarg
);
3725 case QEMU_OPTION_no_reboot
:
3728 case QEMU_OPTION_no_shutdown
:
3731 case QEMU_OPTION_show_cursor
:
3734 case QEMU_OPTION_uuid
:
3735 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3736 error_report("failed to parse UUID string: wrong format");
3739 qemu_uuid_set
= true;
3741 case QEMU_OPTION_option_rom
:
3742 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3743 error_report("too many option ROMs");
3746 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3751 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3752 option_rom
[nb_option_roms
].bootindex
=
3753 qemu_opt_get_number(opts
, "bootindex", -1);
3754 if (!option_rom
[nb_option_roms
].name
) {
3755 error_report("Option ROM file is not specified");
3760 case QEMU_OPTION_semihosting
:
3761 semihosting
.enabled
= true;
3762 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3764 case QEMU_OPTION_semihosting_config
:
3765 semihosting
.enabled
= true;
3766 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3769 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3771 const char *target
= qemu_opt_get(opts
, "target");
3772 if (target
!= NULL
) {
3773 if (strcmp("native", target
) == 0) {
3774 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3775 } else if (strcmp("gdb", target
) == 0) {
3776 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3777 } else if (strcmp("auto", target
) == 0) {
3778 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3780 error_report("unsupported semihosting-config %s",
3785 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3787 /* Set semihosting argument count and vector */
3788 qemu_opt_foreach(opts
, add_semihosting_arg
,
3789 &semihosting
, NULL
);
3791 error_report("unsupported semihosting-config %s", optarg
);
3795 case QEMU_OPTION_tdf
:
3796 error_report("warning: ignoring deprecated option");
3798 case QEMU_OPTION_name
:
3799 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3805 case QEMU_OPTION_prom_env
:
3806 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3807 error_report("too many prom variables");
3810 prom_envs
[nb_prom_envs
] = optarg
;
3813 case QEMU_OPTION_old_param
:
3816 case QEMU_OPTION_clock
:
3817 /* Clock options no longer exist. Keep this option for
3818 * backward compatibility.
3821 case QEMU_OPTION_startdate
:
3822 configure_rtc_date_offset(optarg
, 1);
3824 case QEMU_OPTION_rtc
:
3825 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3830 configure_rtc(opts
);
3832 case QEMU_OPTION_tb_size
:
3833 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3834 if (tcg_tb_size
< 0) {
3838 case QEMU_OPTION_icount
:
3839 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3845 case QEMU_OPTION_incoming
:
3847 runstate_set(RUN_STATE_INMIGRATE
);
3851 case QEMU_OPTION_only_migratable
:
3852 only_migratable
= 1;
3854 case QEMU_OPTION_nodefaults
:
3857 case QEMU_OPTION_xen_domid
:
3858 if (!(xen_available())) {
3859 error_report("Option not supported for this target");
3862 xen_domid
= atoi(optarg
);
3864 case QEMU_OPTION_xen_create
:
3865 if (!(xen_available())) {
3866 error_report("Option not supported for this target");
3869 xen_mode
= XEN_CREATE
;
3871 case QEMU_OPTION_xen_attach
:
3872 if (!(xen_available())) {
3873 error_report("Option not supported for this target");
3876 xen_mode
= XEN_ATTACH
;
3878 case QEMU_OPTION_trace
:
3880 trace_file
= trace_opt_parse(optarg
);
3882 case QEMU_OPTION_readconfig
:
3884 int ret
= qemu_read_config_file(optarg
);
3886 error_report("read config %s: %s", optarg
,
3892 case QEMU_OPTION_spice
:
3893 olist
= qemu_find_opts("spice");
3895 error_report("spice support is disabled");
3898 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3904 case QEMU_OPTION_writeconfig
:
3907 if (strcmp(optarg
, "-") == 0) {
3910 fp
= fopen(optarg
, "w");
3912 error_report("open %s: %s", optarg
,
3917 qemu_config_write(fp
);
3923 case QEMU_OPTION_qtest
:
3924 qtest_chrdev
= optarg
;
3926 case QEMU_OPTION_qtest_log
:
3929 case QEMU_OPTION_sandbox
:
3930 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
3936 case QEMU_OPTION_add_fd
:
3938 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3944 error_report("File descriptor passing is disabled on this "
3949 case QEMU_OPTION_object
:
3950 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
3956 case QEMU_OPTION_realtime
:
3957 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
3962 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
3964 case QEMU_OPTION_msg
:
3965 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3970 configure_msg(opts
);
3972 case QEMU_OPTION_dump_vmstate
:
3973 if (vmstate_dump_file
) {
3974 error_report("only one '-dump-vmstate' "
3975 "option may be given");
3978 vmstate_dump_file
= fopen(optarg
, "w");
3979 if (vmstate_dump_file
== NULL
) {
3980 error_report("open %s: %s", optarg
, strerror(errno
));
3985 os_parse_cmd_args(popt
->index
, optarg
);
3990 * Clear error location left behind by the loop.
3991 * Best done right after the loop. Do not insert code here!
3995 replay_configure(icount_opts
);
3997 machine_class
= select_machine();
3999 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4003 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4004 error_report("could not acquire pid file: %s", strerror(errno
));
4008 if (qemu_init_main_loop(&main_loop_err
)) {
4009 error_report_err(main_loop_err
);
4013 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4014 parse_sandbox
, NULL
, NULL
)) {
4018 if (qemu_opts_foreach(qemu_find_opts("name"),
4019 parse_name
, NULL
, NULL
)) {
4024 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4025 parse_add_fd
, NULL
, NULL
)) {
4029 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4030 cleanup_add_fd
, NULL
, NULL
)) {
4035 current_machine
= MACHINE(object_new(object_class_get_name(
4036 OBJECT_CLASS(machine_class
))));
4037 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4040 object_property_add_child(object_get_root(), "machine",
4041 OBJECT(current_machine
), &error_abort
);
4043 if (machine_class
->minimum_page_bits
) {
4044 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4045 /* This would be a board error: specifying a minimum smaller than
4046 * a target's compile-time fixed setting.
4048 g_assert_not_reached();
4052 cpu_exec_init_all();
4054 if (machine_class
->hw_version
) {
4055 qemu_set_hw_version(machine_class
->hw_version
);
4058 if (cpu_model
&& is_help_option(cpu_model
)) {
4059 list_cpus(stdout
, &fprintf
, cpu_model
);
4063 if (!trace_init_backends()) {
4066 trace_init_file(trace_file
);
4068 /* Open the logfile at this point and set the log mask if necessary.
4071 qemu_set_log_filename(log_file
, &error_fatal
);
4076 mask
= qemu_str_to_log_mask(log_mask
);
4078 qemu_print_log_usage(stdout
);
4086 /* If no data_dir is specified then try to find it relative to the
4088 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4089 data_dir
[data_dir_idx
] = os_find_datadir();
4090 if (data_dir
[data_dir_idx
] != NULL
) {
4094 /* If all else fails use the install path specified when building. */
4095 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4096 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4099 /* -L help lists the data directories and exits. */
4100 if (list_data_dirs
) {
4101 for (i
= 0; i
< data_dir_idx
; i
++) {
4102 printf("%s\n", data_dir
[i
]);
4107 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4109 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4110 if (max_cpus
> machine_class
->max_cpus
) {
4111 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4112 "supported by machine '%s' (%d)", max_cpus
,
4113 machine_class
->name
, machine_class
->max_cpus
);
4118 * Get the default machine options from the machine if it is not already
4119 * specified either by the configuration file or by the command line.
4121 if (machine_class
->default_machine_opts
) {
4122 qemu_opts_set_defaults(qemu_find_opts("machine"),
4123 machine_class
->default_machine_opts
, 0);
4126 qemu_opts_foreach(qemu_find_opts("device"),
4127 default_driver_check
, NULL
, NULL
);
4128 qemu_opts_foreach(qemu_find_opts("global"),
4129 default_driver_check
, NULL
, NULL
);
4131 if (!vga_model
&& !default_vga
) {
4132 vga_interface_type
= VGA_DEVICE
;
4134 if (!has_defaults
|| machine_class
->no_serial
) {
4137 if (!has_defaults
|| machine_class
->no_parallel
) {
4138 default_parallel
= 0;
4140 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4141 default_virtcon
= 0;
4143 if (!has_defaults
|| !machine_class
->use_sclp
) {
4146 if (!has_defaults
|| machine_class
->no_floppy
) {
4149 if (!has_defaults
|| machine_class
->no_cdrom
) {
4152 if (!has_defaults
|| machine_class
->no_sdcard
) {
4155 if (!has_defaults
) {
4156 default_monitor
= 0;
4161 if (is_daemonized()) {
4162 /* According to documentation and historically, -nographic redirects
4163 * serial port, parallel port and monitor to stdio, which does not work
4164 * with -daemonize. We can redirect these to null instead, but since
4165 * -nographic is legacy, let's just error out.
4166 * We disallow -nographic only if all other ports are not redirected
4167 * explicitly, to not break existing legacy setups which uses
4168 * -nographic _and_ redirects all ports explicitly - this is valid
4169 * usage, -nographic is just a no-op in this case.
4172 && (default_parallel
|| default_serial
4173 || default_monitor
|| default_virtcon
)) {
4174 error_report("-nographic cannot be used with -daemonize");
4177 #ifdef CONFIG_CURSES
4178 if (display_type
== DT_CURSES
) {
4179 error_report("curses display cannot be used with -daemonize");
4186 if (default_parallel
)
4187 add_device_config(DEV_PARALLEL
, "null");
4188 if (default_serial
&& default_monitor
) {
4189 add_device_config(DEV_SERIAL
, "mon:stdio");
4190 } else if (default_virtcon
&& default_monitor
) {
4191 add_device_config(DEV_VIRTCON
, "mon:stdio");
4192 } else if (default_sclp
&& default_monitor
) {
4193 add_device_config(DEV_SCLP
, "mon:stdio");
4196 add_device_config(DEV_SERIAL
, "stdio");
4197 if (default_virtcon
)
4198 add_device_config(DEV_VIRTCON
, "stdio");
4200 add_device_config(DEV_SCLP
, "stdio");
4202 if (default_monitor
)
4203 monitor_parse("stdio", "readline", false);
4207 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4208 if (default_parallel
)
4209 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4210 if (default_monitor
)
4211 monitor_parse("vc:80Cx24C", "readline", false);
4212 if (default_virtcon
)
4213 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4215 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4219 #if defined(CONFIG_VNC)
4220 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4224 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4225 #if defined(CONFIG_GTK)
4226 display_type
= DT_GTK
;
4227 #elif defined(CONFIG_SDL)
4228 display_type
= DT_SDL
;
4229 #elif defined(CONFIG_COCOA)
4230 display_type
= DT_COCOA
;
4231 #elif defined(CONFIG_VNC)
4232 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4234 display_type
= DT_NONE
;
4238 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4239 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4240 "for SDL, ignoring option");
4242 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4243 error_report("-no-quit is only valid for GTK and SDL, "
4247 if (display_type
== DT_GTK
) {
4248 early_gtk_display_init(request_opengl
);
4251 if (display_type
== DT_SDL
) {
4252 sdl_display_early_init(request_opengl
);
4255 qemu_console_early_init();
4257 if (request_opengl
== 1 && display_opengl
== 0) {
4258 #if defined(CONFIG_OPENGL)
4259 error_report("OpenGL is not supported by the display");
4261 error_report("OpenGL support is disabled");
4269 if (qemu_opts_foreach(qemu_find_opts("object"),
4270 user_creatable_add_opts_foreach
,
4271 object_create_initial
, NULL
)) {
4275 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4276 chardev_init_func
, NULL
, NULL
)) {
4280 #ifdef CONFIG_VIRTFS
4281 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4282 fsdev_init_func
, NULL
, NULL
)) {
4287 if (qemu_opts_foreach(qemu_find_opts("device"),
4288 device_help_func
, NULL
, NULL
)) {
4292 machine_opts
= qemu_get_machine_opts();
4293 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4295 object_unref(OBJECT(current_machine
));
4299 configure_accelerator(current_machine
);
4302 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4305 machine_opts
= qemu_get_machine_opts();
4306 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4307 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4308 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4309 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4311 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4313 boot_order
= qemu_opt_get(opts
, "order");
4315 validate_bootdevices(boot_order
, &error_fatal
);
4318 boot_once
= qemu_opt_get(opts
, "once");
4320 validate_bootdevices(boot_once
, &error_fatal
);
4323 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4324 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4328 boot_order
= machine_class
->default_boot_order
;
4331 if (!kernel_cmdline
) {
4332 kernel_cmdline
= "";
4333 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4336 linux_boot
= (kernel_filename
!= NULL
);
4338 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4339 error_report("-append only allowed with -kernel option");
4343 if (!linux_boot
&& initrd_filename
!= NULL
) {
4344 error_report("-initrd only allowed with -kernel option");
4348 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4349 /* fall back to the -kernel/-append */
4350 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4353 os_set_line_buffering();
4355 /* spice needs the timers to be initialized by this point */
4360 if (!tcg_enabled()) {
4361 error_report("-icount is not allowed with hardware virtualization");
4364 configure_icount(icount_opts
, &error_abort
);
4365 qemu_opts_del(icount_opts
);
4369 QemuOptsList
*net
= qemu_find_opts("net");
4370 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4372 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4378 if (net_init_clients() < 0) {
4382 if (qemu_opts_foreach(qemu_find_opts("object"),
4383 user_creatable_add_opts_foreach
,
4384 object_create_delayed
, NULL
)) {
4389 if (tpm_init() < 0) {
4394 /* init the bluetooth world */
4395 if (foreach_device_config(DEV_BT
, bt_parse
))
4398 if (!xen_enabled()) {
4399 /* On 32-bit hosts, QEMU is limited by virtual address space */
4400 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4401 error_report("at most 2047 MB RAM can be simulated");
4409 /* If the currently selected machine wishes to override the units-per-bus
4410 * property of its default HBA interface type, do so now. */
4411 if (machine_class
->units_per_default_bus
) {
4412 override_max_devs(machine_class
->block_default_type
,
4413 machine_class
->units_per_default_bus
);
4416 /* open the virtual block devices */
4417 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4418 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4421 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4422 &machine_class
->block_default_type
, NULL
)) {
4426 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4428 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4429 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4431 parse_numa_opts(machine_class
);
4433 if (qemu_opts_foreach(qemu_find_opts("mon"),
4434 mon_init_func
, NULL
, NULL
)) {
4438 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4440 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4442 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4444 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4447 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4450 /* If no default VGA is requested, the default is "none". */
4452 if (machine_class
->default_display
) {
4453 vga_model
= machine_class
->default_display
;
4454 } else if (vga_interface_available(VGA_CIRRUS
)) {
4455 vga_model
= "cirrus";
4456 } else if (vga_interface_available(VGA_STD
)) {
4461 select_vgahw(vga_model
);
4465 i
= select_watchdog(watchdog
);
4467 exit (i
== 1 ? 1 : 0);
4470 machine_register_compat_props(current_machine
);
4472 qemu_opts_foreach(qemu_find_opts("global"),
4473 global_init_func
, NULL
, NULL
);
4475 /* This checkpoint is required by replay to separate prior clock
4476 reading from the other reads, because timer polling functions query
4477 clock values from the log. */
4478 replay_checkpoint(CHECKPOINT_INIT
);
4479 qdev_machine_init();
4481 current_machine
->ram_size
= ram_size
;
4482 current_machine
->maxram_size
= maxram_size
;
4483 current_machine
->ram_slots
= ram_slots
;
4484 current_machine
->boot_order
= boot_order
;
4485 current_machine
->cpu_model
= cpu_model
;
4487 machine_class
->init(current_machine
);
4493 cpu_synchronize_all_post_init();
4495 if (hax_enabled()) {
4499 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4500 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4504 /* init USB devices */
4505 if (machine_usb(current_machine
)) {
4506 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4510 /* Check if IGD GFX passthrough. */
4513 /* init generic devices */
4514 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4515 if (qemu_opts_foreach(qemu_find_opts("device"),
4516 device_init_func
, NULL
, NULL
)) {
4520 numa_post_machine_init();
4522 rom_reset_order_override();
4524 /* Did we create any drives that we failed to create a device for? */
4525 drive_check_orphaned();
4527 /* Don't warn about the default network setup that you get if
4528 * no command line -net or -netdev options are specified. There
4529 * are two cases that we would otherwise complain about:
4530 * (1) board doesn't support a NIC but the implicit "-net nic"
4532 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4533 * sets up a nic that isn't connected to anything.
4536 net_check_clients();
4541 qemu_boot_set(boot_once
, &error_fatal
);
4542 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4545 ds
= init_displaystate();
4547 /* init local displays */
4548 switch (display_type
) {
4550 curses_display_init(ds
, full_screen
);
4553 sdl_display_init(ds
, full_screen
, no_frame
);
4556 cocoa_display_init(ds
, full_screen
);
4559 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4565 /* must be after terminal init, SDL library changes signal handlers */
4566 os_setup_signal_handling();
4568 /* init remote displays */
4570 qemu_opts_foreach(qemu_find_opts("vnc"),
4571 vnc_init_func
, NULL
, NULL
);
4575 qemu_spice_display_init();
4578 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4582 qdev_machine_creation_done();
4584 /* TODO: once all bus devices are qdevified, this should be done
4585 * when bus is created by qdev.c */
4586 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4587 qemu_run_machine_init_done_notifiers();
4589 if (rom_check_and_register_reset() != 0) {
4590 error_report("rom check and register reset failed");
4596 /* This checkpoint is required by replay to separate prior clock
4597 reading from the other reads, because timer polling functions query
4598 clock values from the log. */
4599 replay_checkpoint(CHECKPOINT_RESET
);
4600 qemu_system_reset(VMRESET_SILENT
);
4601 register_global_state();
4602 if (replay_mode
!= REPLAY_MODE_NONE
) {
4603 replay_vmstate_init();
4604 } else if (loadvm
) {
4605 if (load_vmstate(loadvm
) < 0) {
4610 qdev_prop_check_globals();
4611 if (vmstate_dump_file
) {
4613 dump_vmstate_json_to_file(vmstate_dump_file
);
4618 Error
*local_err
= NULL
;
4619 qemu_start_incoming_migration(incoming
, &local_err
);
4621 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4624 } else if (autostart
) {
4631 replay_disable_events();
4632 iothread_stop_all();
4638 /* vhost-user must be cleaned up before chardevs. */