4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "qemu/osdep.h"
25 #include "qemu-version.h"
26 #include "qemu/cutils.h"
27 #include "qemu/help_option.h"
28 #include "qemu/uuid.h"
31 #include "sysemu/seccomp.h"
34 #if defined(CONFIG_VDE)
35 #include <libvdeplug.h>
39 #if defined(__APPLE__) || defined(main)
41 int qemu_main(int argc
, char **argv
, char **envp
);
42 int main(int argc
, char **argv
)
44 return qemu_main(argc
, argv
, NULL
);
47 #define main qemu_main
49 #endif /* CONFIG_SDL */
53 #define main qemu_main
54 #endif /* CONFIG_COCOA */
57 #include "qemu/error-report.h"
58 #include "qemu/sockets.h"
60 #include "hw/boards.h"
61 #include "sysemu/accel.h"
63 #include "hw/i386/pc.h"
64 #include "hw/isa/isa.h"
65 #include "hw/scsi/scsi.h"
67 #include "sysemu/watchdog.h"
68 #include "hw/smbios/smbios.h"
69 #include "hw/acpi/acpi.h"
70 #include "hw/xen/xen.h"
72 #include "hw/loader.h"
73 #include "monitor/qdev.h"
74 #include "sysemu/bt.h"
76 #include "net/slirp.h"
77 #include "monitor/monitor.h"
78 #include "ui/console.h"
80 #include "sysemu/sysemu.h"
81 #include "sysemu/numa.h"
82 #include "exec/gdbstub.h"
83 #include "qemu/timer.h"
84 #include "sysemu/char.h"
85 #include "qemu/bitmap.h"
87 #include "sysemu/blockdev.h"
88 #include "hw/block/block.h"
89 #include "migration/block.h"
90 #include "sysemu/tpm.h"
91 #include "sysemu/dma.h"
92 #include "audio/audio.h"
93 #include "migration/migration.h"
94 #include "sysemu/cpus.h"
95 #include "migration/colo.h"
96 #include "sysemu/kvm.h"
97 #include "sysemu/hax.h"
98 #include "qapi/qobject-input-visitor.h"
99 #include "qapi/qobject-input-visitor.h"
100 #include "qapi-visit.h"
101 #include "qapi/qmp/qjson.h"
102 #include "qemu/option.h"
103 #include "qemu/config-file.h"
104 #include "qemu-options.h"
105 #include "qmp-commands.h"
106 #include "qemu/main-loop.h"
108 #include "fsdev/qemu-fsdev.h"
110 #include "sysemu/qtest.h"
112 #include "disas/disas.h"
115 #include "slirp/libslirp.h"
117 #include "trace-root.h"
118 #include "trace/control.h"
119 #include "qemu/queue.h"
120 #include "sysemu/arch_init.h"
122 #include "ui/qemu-spice.h"
123 #include "qapi/string-input-visitor.h"
124 #include "qapi/opts-visitor.h"
125 #include "qom/object_interfaces.h"
126 #include "qapi-event.h"
127 #include "exec/semihost.h"
128 #include "crypto/init.h"
129 #include "sysemu/replay.h"
130 #include "qapi/qmp/qerror.h"
131 #include "sysemu/iothread.h"
133 #define MAX_VIRTIO_CONSOLES 1
134 #define MAX_SCLP_CONSOLES 1
136 static const char *data_dir
[16];
137 static int data_dir_idx
;
138 const char *bios_name
= NULL
;
139 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
140 int request_opengl
= -1;
142 const char* keyboard_layout
= NULL
;
144 const char *mem_path
= NULL
;
145 int mem_prealloc
= 0; /* force preallocation of physical target memory */
146 bool enable_mlock
= false;
148 NICInfo nd_table
[MAX_NICS
];
150 static int rtc_utc
= 1;
151 static int rtc_date_offset
= -1; /* -1 means no change */
152 QEMUClockType rtc_clock
;
153 int vga_interface_type
= VGA_NONE
;
154 static int full_screen
= 0;
155 static int no_frame
= 0;
157 static bool grab_on_hover
;
158 Chardev
*serial_hds
[MAX_SERIAL_PORTS
];
159 Chardev
*parallel_hds
[MAX_PARALLEL_PORTS
];
160 Chardev
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
161 Chardev
*sclp_hds
[MAX_SCLP_CONSOLES
];
162 int win2k_install_hack
= 0;
168 int acpi_enabled
= 1;
171 static int no_reboot
;
174 int graphic_rotate
= 0;
175 const char *watchdog
;
176 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
179 const char *qemu_name
;
182 unsigned int nb_prom_envs
= 0;
183 const char *prom_envs
[MAX_PROM_ENVS
];
186 uint8_t *boot_splash_filedata
;
187 size_t boot_splash_filedata_size
;
188 uint8_t qemu_extra_params_fw
[2];
189 int only_migratable
; /* turn it off unless user states otherwise */
191 int icount_align_option
;
193 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
194 * little-endian "wire format" described in the SMBIOS 2.6 specification.
199 static NotifierList exit_notifiers
=
200 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
202 static NotifierList machine_init_done_notifiers
=
203 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
207 enum xen_mode xen_mode
= XEN_EMULATE
;
209 static int has_defaults
= 1;
210 static int default_serial
= 1;
211 static int default_parallel
= 1;
212 static int default_virtcon
= 1;
213 static int default_sclp
= 1;
214 static int default_monitor
= 1;
215 static int default_floppy
= 1;
216 static int default_cdrom
= 1;
217 static int default_sdcard
= 1;
218 static int default_vga
= 1;
219 static int default_net
= 1;
225 { .driver
= "isa-serial", .flag
= &default_serial
},
226 { .driver
= "isa-parallel", .flag
= &default_parallel
},
227 { .driver
= "isa-fdc", .flag
= &default_floppy
},
228 { .driver
= "floppy", .flag
= &default_floppy
},
229 { .driver
= "ide-cd", .flag
= &default_cdrom
},
230 { .driver
= "ide-hd", .flag
= &default_cdrom
},
231 { .driver
= "ide-drive", .flag
= &default_cdrom
},
232 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
233 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
234 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
235 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
236 { .driver
= "VGA", .flag
= &default_vga
},
237 { .driver
= "isa-vga", .flag
= &default_vga
},
238 { .driver
= "cirrus-vga", .flag
= &default_vga
},
239 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
240 { .driver
= "vmware-svga", .flag
= &default_vga
},
241 { .driver
= "qxl-vga", .flag
= &default_vga
},
242 { .driver
= "virtio-vga", .flag
= &default_vga
},
245 static QemuOptsList qemu_rtc_opts
= {
247 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
251 .type
= QEMU_OPT_STRING
,
254 .type
= QEMU_OPT_STRING
,
257 .type
= QEMU_OPT_STRING
,
259 { /* end of list */ }
263 static QemuOptsList qemu_sandbox_opts
= {
265 .implied_opt_name
= "enable",
266 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
270 .type
= QEMU_OPT_BOOL
,
272 { /* end of list */ }
276 static QemuOptsList qemu_option_rom_opts
= {
277 .name
= "option-rom",
278 .implied_opt_name
= "romfile",
279 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
283 .type
= QEMU_OPT_NUMBER
,
286 .type
= QEMU_OPT_STRING
,
288 { /* end of list */ }
292 static QemuOptsList qemu_machine_opts
= {
294 .implied_opt_name
= "type",
296 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
299 * no elements => accept any
300 * sanity checking will happen later
301 * when setting machine properties
307 static QemuOptsList qemu_accel_opts
= {
309 .implied_opt_name
= "accel",
310 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
315 .type
= QEMU_OPT_STRING
,
316 .help
= "Select the type of accelerator",
320 .type
= QEMU_OPT_STRING
,
321 .help
= "Enable/disable multi-threaded TCG",
323 { /* end of list */ }
327 static QemuOptsList qemu_boot_opts
= {
329 .implied_opt_name
= "order",
331 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
335 .type
= QEMU_OPT_STRING
,
338 .type
= QEMU_OPT_STRING
,
341 .type
= QEMU_OPT_BOOL
,
344 .type
= QEMU_OPT_STRING
,
346 .name
= "splash-time",
347 .type
= QEMU_OPT_STRING
,
349 .name
= "reboot-timeout",
350 .type
= QEMU_OPT_STRING
,
353 .type
= QEMU_OPT_BOOL
,
359 static QemuOptsList qemu_add_fd_opts
= {
361 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
365 .type
= QEMU_OPT_NUMBER
,
366 .help
= "file descriptor of which a duplicate is added to fd set",
369 .type
= QEMU_OPT_NUMBER
,
370 .help
= "ID of the fd set to add fd to",
373 .type
= QEMU_OPT_STRING
,
374 .help
= "free-form string used to describe fd",
376 { /* end of list */ }
380 static QemuOptsList qemu_object_opts
= {
382 .implied_opt_name
= "qom-type",
383 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
389 static QemuOptsList qemu_tpmdev_opts
= {
391 .implied_opt_name
= "type",
392 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
394 /* options are defined in the TPM backends */
395 { /* end of list */ }
399 static QemuOptsList qemu_realtime_opts
= {
401 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
405 .type
= QEMU_OPT_BOOL
,
407 { /* end of list */ }
411 static QemuOptsList qemu_msg_opts
= {
413 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
417 .type
= QEMU_OPT_BOOL
,
419 { /* end of list */ }
423 static QemuOptsList qemu_name_opts
= {
425 .implied_opt_name
= "guest",
427 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
431 .type
= QEMU_OPT_STRING
,
432 .help
= "Sets the name of the guest.\n"
433 "This name will be displayed in the SDL window caption.\n"
434 "The name will also be used for the VNC server",
437 .type
= QEMU_OPT_STRING
,
438 .help
= "Sets the name of the QEMU process, as shown in top etc",
440 .name
= "debug-threads",
441 .type
= QEMU_OPT_BOOL
,
442 .help
= "When enabled, name the individual threads; defaults off.\n"
443 "NOTE: The thread names are for debugging and not a\n"
446 { /* End of list */ }
450 static QemuOptsList qemu_mem_opts
= {
452 .implied_opt_name
= "size",
453 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
458 .type
= QEMU_OPT_SIZE
,
462 .type
= QEMU_OPT_NUMBER
,
466 .type
= QEMU_OPT_SIZE
,
468 { /* end of list */ }
472 static QemuOptsList qemu_icount_opts
= {
474 .implied_opt_name
= "shift",
476 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
480 .type
= QEMU_OPT_STRING
,
483 .type
= QEMU_OPT_BOOL
,
486 .type
= QEMU_OPT_BOOL
,
489 .type
= QEMU_OPT_STRING
,
492 .type
= QEMU_OPT_STRING
,
494 .name
= "rrsnapshot",
495 .type
= QEMU_OPT_STRING
,
497 { /* end of list */ }
501 static QemuOptsList qemu_semihosting_config_opts
= {
502 .name
= "semihosting-config",
503 .implied_opt_name
= "enable",
504 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
508 .type
= QEMU_OPT_BOOL
,
511 .type
= QEMU_OPT_STRING
,
514 .type
= QEMU_OPT_STRING
,
516 { /* end of list */ }
520 static QemuOptsList qemu_fw_cfg_opts
= {
522 .implied_opt_name
= "name",
523 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
527 .type
= QEMU_OPT_STRING
,
528 .help
= "Sets the fw_cfg name of the blob to be inserted",
531 .type
= QEMU_OPT_STRING
,
532 .help
= "Sets the name of the file from which\n"
533 "the fw_cfg blob will be loaded",
536 .type
= QEMU_OPT_STRING
,
537 .help
= "Sets content of the blob to be inserted from a string",
539 { /* end of list */ }
544 * Get machine options
546 * Returns: machine options (never null).
548 QemuOpts
*qemu_get_machine_opts(void)
550 return qemu_find_opts_singleton("machine");
553 const char *qemu_get_vm_name(void)
558 static void res_free(void)
560 g_free(boot_splash_filedata
);
561 boot_splash_filedata
= NULL
;
564 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
566 const char *driver
= qemu_opt_get(opts
, "driver");
571 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
572 if (strcmp(default_list
[i
].driver
, driver
) != 0)
574 *(default_list
[i
].flag
) = 0;
579 /***********************************************************/
582 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
584 /* We use RUN_STATE__MAX but any invalid value will do */
585 static RunState vmstop_requested
= RUN_STATE__MAX
;
586 static QemuMutex vmstop_lock
;
591 } RunStateTransition
;
593 static const RunStateTransition runstate_transitions_def
[] = {
595 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
596 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
597 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
599 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
600 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
601 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
602 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
603 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
604 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
605 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
606 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
607 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
608 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
609 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
610 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
612 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
613 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
614 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
616 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
617 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
618 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
620 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
621 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
622 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
623 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
625 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
626 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
627 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
629 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
630 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
631 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
633 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
634 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
635 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
636 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
638 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
639 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
641 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
643 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
644 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
645 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
646 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
647 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
648 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
649 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
650 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
651 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
652 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
653 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
655 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
657 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
658 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
659 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
661 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
662 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
663 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
664 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
665 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
666 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
668 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
669 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
670 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
671 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
673 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
674 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
675 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
677 { RUN_STATE__MAX
, RUN_STATE__MAX
},
680 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
682 bool runstate_check(RunState state
)
684 return current_run_state
== state
;
687 bool runstate_store(char *str
, size_t size
)
689 const char *state
= RunState_lookup
[current_run_state
];
690 size_t len
= strlen(state
) + 1;
695 memcpy(str
, state
, len
);
699 static void runstate_init(void)
701 const RunStateTransition
*p
;
703 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
704 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
705 runstate_valid_transitions
[p
->from
][p
->to
] = true;
708 qemu_mutex_init(&vmstop_lock
);
711 /* This function will abort() on invalid state transitions */
712 void runstate_set(RunState new_state
)
714 assert(new_state
< RUN_STATE__MAX
);
716 if (current_run_state
== new_state
) {
720 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
721 error_report("invalid runstate transition: '%s' -> '%s'",
722 RunState_lookup
[current_run_state
],
723 RunState_lookup
[new_state
]);
726 trace_runstate_set(new_state
);
727 current_run_state
= new_state
;
730 int runstate_is_running(void)
732 return runstate_check(RUN_STATE_RUNNING
);
735 bool runstate_needs_reset(void)
737 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
738 runstate_check(RUN_STATE_SHUTDOWN
);
741 StatusInfo
*qmp_query_status(Error
**errp
)
743 StatusInfo
*info
= g_malloc0(sizeof(*info
));
745 info
->running
= runstate_is_running();
746 info
->singlestep
= singlestep
;
747 info
->status
= current_run_state
;
752 bool qemu_vmstop_requested(RunState
*r
)
754 qemu_mutex_lock(&vmstop_lock
);
755 *r
= vmstop_requested
;
756 vmstop_requested
= RUN_STATE__MAX
;
757 qemu_mutex_unlock(&vmstop_lock
);
758 return *r
< RUN_STATE__MAX
;
761 void qemu_system_vmstop_request_prepare(void)
763 qemu_mutex_lock(&vmstop_lock
);
766 void qemu_system_vmstop_request(RunState state
)
768 vmstop_requested
= state
;
769 qemu_mutex_unlock(&vmstop_lock
);
773 /***********************************************************/
774 /* real time host monotonic timer */
776 static time_t qemu_time(void)
778 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
781 /***********************************************************/
782 /* host time/date access */
783 void qemu_get_timedate(struct tm
*tm
, int offset
)
785 time_t ti
= qemu_time();
788 if (rtc_date_offset
== -1) {
792 localtime_r(&ti
, tm
);
794 ti
-= rtc_date_offset
;
799 int qemu_timedate_diff(struct tm
*tm
)
803 if (rtc_date_offset
== -1)
805 seconds
= mktimegm(tm
);
808 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
809 seconds
= mktime(&tmp
);
812 seconds
= mktimegm(tm
) + rtc_date_offset
;
814 return seconds
- qemu_time();
817 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
819 time_t rtc_start_date
;
822 if (!strcmp(startdate
, "now") && legacy
) {
823 rtc_date_offset
= -1;
825 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
833 } else if (sscanf(startdate
, "%d-%d-%d",
845 rtc_start_date
= mktimegm(&tm
);
846 if (rtc_start_date
== -1) {
848 error_report("invalid date format");
849 error_printf("valid formats: "
850 "'2006-06-17T16:01:21' or '2006-06-17'\n");
853 rtc_date_offset
= qemu_time() - rtc_start_date
;
857 static void configure_rtc(QemuOpts
*opts
)
861 value
= qemu_opt_get(opts
, "base");
863 if (!strcmp(value
, "utc")) {
865 } else if (!strcmp(value
, "localtime")) {
866 Error
*blocker
= NULL
;
868 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
869 "-rtc base=localtime");
870 replay_add_blocker(blocker
);
872 configure_rtc_date_offset(value
, 0);
875 value
= qemu_opt_get(opts
, "clock");
877 if (!strcmp(value
, "host")) {
878 rtc_clock
= QEMU_CLOCK_HOST
;
879 } else if (!strcmp(value
, "rt")) {
880 rtc_clock
= QEMU_CLOCK_REALTIME
;
881 } else if (!strcmp(value
, "vm")) {
882 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
884 error_report("invalid option value '%s'", value
);
888 value
= qemu_opt_get(opts
, "driftfix");
890 if (!strcmp(value
, "slew")) {
891 static GlobalProperty slew_lost_ticks
= {
892 .driver
= "mc146818rtc",
893 .property
= "lost_tick_policy",
897 qdev_prop_register_global(&slew_lost_ticks
);
898 } else if (!strcmp(value
, "none")) {
899 /* discard is default */
901 error_report("invalid option value '%s'", value
);
907 /***********************************************************/
908 /* Bluetooth support */
911 static struct HCIInfo
*hci_table
[MAX_NICS
];
913 struct HCIInfo
*qemu_next_hci(void)
915 if (cur_hci
== nb_hcis
)
918 return hci_table
[cur_hci
++];
921 static int bt_hci_parse(const char *str
)
926 if (nb_hcis
>= MAX_NICS
) {
927 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
940 bdaddr
.b
[5] = 0x56 + nb_hcis
;
941 hci
->bdaddr_set(hci
, bdaddr
.b
);
943 hci_table
[nb_hcis
++] = hci
;
948 static void bt_vhci_add(int vlan_id
)
950 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
953 error_report("warning: adding a VHCI to an empty scatternet %i",
956 bt_vhci_init(bt_new_hci(vlan
));
959 static struct bt_device_s
*bt_device_add(const char *opt
)
961 struct bt_scatternet_s
*vlan
;
963 char *endp
= strstr(opt
, ",vlan=");
964 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
967 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
970 vlan_id
= strtol(endp
+ 6, &endp
, 0);
972 error_report("unrecognised bluetooth vlan Id");
977 vlan
= qemu_find_bt_vlan(vlan_id
);
980 error_report("warning: adding a slave device to an empty scatternet %i",
983 if (!strcmp(devname
, "keyboard"))
984 return bt_keyboard_init(vlan
);
986 error_report("unsupported bluetooth device '%s'", devname
);
990 static int bt_parse(const char *opt
)
992 const char *endp
, *p
;
995 if (strstart(opt
, "hci", &endp
)) {
996 if (!*endp
|| *endp
== ',') {
998 if (!strstart(endp
, ",vlan=", 0))
1001 return bt_hci_parse(opt
);
1003 } else if (strstart(opt
, "vhci", &endp
)) {
1004 if (!*endp
|| *endp
== ',') {
1006 if (strstart(endp
, ",vlan=", &p
)) {
1007 vlan
= strtol(p
, (char **) &endp
, 0);
1009 error_report("bad scatternet '%s'", p
);
1013 error_report("bad parameter '%s'", endp
+ 1);
1022 } else if (strstart(opt
, "device:", &endp
))
1023 return !bt_device_add(endp
);
1025 error_report("bad bluetooth parameter '%s'", opt
);
1029 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1031 /* FIXME: change this to true for 1.3 */
1032 if (qemu_opt_get_bool(opts
, "enable", false)) {
1033 #ifdef CONFIG_SECCOMP
1034 if (seccomp_start() < 0) {
1035 error_report("failed to install seccomp syscall filter "
1040 error_report("seccomp support is disabled");
1048 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1050 const char *proc_name
;
1052 if (qemu_opt_get(opts
, "debug-threads")) {
1053 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1055 qemu_name
= qemu_opt_get(opts
, "guest");
1057 proc_name
= qemu_opt_get(opts
, "process");
1059 os_set_proc_name(proc_name
);
1065 bool defaults_enabled(void)
1067 return has_defaults
;
1071 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1073 int fd
, dupfd
, flags
;
1075 const char *fd_opaque
= NULL
;
1078 fd
= qemu_opt_get_number(opts
, "fd", -1);
1079 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1080 fd_opaque
= qemu_opt_get(opts
, "opaque");
1083 error_report("fd option is required and must be non-negative");
1087 if (fd
<= STDERR_FILENO
) {
1088 error_report("fd cannot be a standard I/O stream");
1093 * All fds inherited across exec() necessarily have FD_CLOEXEC
1094 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1096 flags
= fcntl(fd
, F_GETFD
);
1097 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1098 error_report("fd is not valid or already in use");
1103 error_report("set option is required and must be non-negative");
1107 #ifdef F_DUPFD_CLOEXEC
1108 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1112 qemu_set_cloexec(dupfd
);
1116 error_report("error duplicating fd: %s", strerror(errno
));
1120 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1121 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1128 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1132 fd
= qemu_opt_get_number(opts
, "fd", -1);
1139 /***********************************************************/
1140 /* QEMU Block devices */
1142 #define HD_OPTS "media=disk"
1143 #define CDROM_OPTS "media=cdrom"
1145 #define PFLASH_OPTS ""
1149 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1151 BlockInterfaceType
*block_default_type
= opaque
;
1153 return drive_new(opts
, *block_default_type
) == NULL
;
1156 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1158 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1159 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1164 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1165 int index
, const char *optstr
)
1170 if (!enable
|| drive_get_by_index(type
, index
)) {
1174 opts
= drive_add(type
, index
, NULL
, optstr
);
1176 drive_enable_snapshot(NULL
, opts
, NULL
);
1179 dinfo
= drive_new(opts
, type
);
1183 dinfo
->is_default
= true;
1187 static QemuOptsList qemu_smp_opts
= {
1189 .implied_opt_name
= "cpus",
1190 .merge_lists
= true,
1191 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1195 .type
= QEMU_OPT_NUMBER
,
1198 .type
= QEMU_OPT_NUMBER
,
1201 .type
= QEMU_OPT_NUMBER
,
1204 .type
= QEMU_OPT_NUMBER
,
1207 .type
= QEMU_OPT_NUMBER
,
1209 { /*End of list */ }
1213 static void smp_parse(QemuOpts
*opts
)
1216 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1217 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1218 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1219 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1221 /* compute missing values, prefer sockets over cores over threads */
1222 if (cpus
== 0 || sockets
== 0) {
1223 sockets
= sockets
> 0 ? sockets
: 1;
1224 cores
= cores
> 0 ? cores
: 1;
1225 threads
= threads
> 0 ? threads
: 1;
1227 cpus
= cores
* threads
* sockets
;
1229 } else if (cores
== 0) {
1230 threads
= threads
> 0 ? threads
: 1;
1231 cores
= cpus
/ (sockets
* threads
);
1232 cores
= cores
> 0 ? cores
: 1;
1233 } else if (threads
== 0) {
1234 threads
= cpus
/ (cores
* sockets
);
1235 threads
= threads
> 0 ? threads
: 1;
1236 } else if (sockets
* cores
* threads
< cpus
) {
1237 error_report("cpu topology: "
1238 "sockets (%u) * cores (%u) * threads (%u) < "
1240 sockets
, cores
, threads
, cpus
);
1244 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1246 if (max_cpus
< cpus
) {
1247 error_report("maxcpus must be equal to or greater than smp");
1251 if (sockets
* cores
* threads
> max_cpus
) {
1252 error_report("cpu topology: "
1253 "sockets (%u) * cores (%u) * threads (%u) > "
1255 sockets
, cores
, threads
, max_cpus
);
1261 smp_threads
= threads
;
1265 Error
*blocker
= NULL
;
1266 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1267 replay_add_blocker(blocker
);
1271 static void realtime_init(void)
1274 if (os_mlock() < 0) {
1275 error_report("locking memory failed");
1282 static void configure_msg(QemuOpts
*opts
)
1284 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1287 /***********************************************************/
1290 typedef struct SemihostingConfig
{
1292 SemihostingTarget target
;
1295 const char *cmdline
; /* concatenated argv */
1296 } SemihostingConfig
;
1298 static SemihostingConfig semihosting
;
1300 bool semihosting_enabled(void)
1302 return semihosting
.enabled
;
1305 SemihostingTarget
semihosting_get_target(void)
1307 return semihosting
.target
;
1310 const char *semihosting_get_arg(int i
)
1312 if (i
>= semihosting
.argc
) {
1315 return semihosting
.argv
[i
];
1318 int semihosting_get_argc(void)
1320 return semihosting
.argc
;
1323 const char *semihosting_get_cmdline(void)
1325 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1326 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1328 return semihosting
.cmdline
;
1331 static int add_semihosting_arg(void *opaque
,
1332 const char *name
, const char *val
,
1335 SemihostingConfig
*s
= opaque
;
1336 if (strcmp(name
, "arg") == 0) {
1338 /* one extra element as g_strjoinv() expects NULL-terminated array */
1339 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1340 s
->argv
[s
->argc
- 1] = val
;
1341 s
->argv
[s
->argc
] = NULL
;
1346 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1347 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1352 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1354 /* split -append and initialize argv[1..n] */
1355 cmd_token
= strtok(g_strdup(cmd
), " ");
1357 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1358 cmd_token
= strtok(NULL
, " ");
1362 /* Now we still need this for compatibility with XEN. */
1363 bool has_igd_gfx_passthru
;
1364 static void igd_gfx_passthru(void)
1366 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1369 /***********************************************************/
1372 static int usb_device_add(const char *devname
)
1374 USBDevice
*dev
= NULL
;
1375 #ifndef CONFIG_LINUX
1379 if (!machine_usb(current_machine
)) {
1383 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1384 dev
= usbdevice_create(devname
);
1388 /* the other ones */
1389 #ifndef CONFIG_LINUX
1390 /* only the linux version is qdev-ified, usb-bsd still needs this */
1391 if (strstart(devname
, "host:", &p
)) {
1392 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1402 static int usb_device_del(const char *devname
)
1407 if (strstart(devname
, "host:", &p
)) {
1411 if (!machine_usb(current_machine
)) {
1415 p
= strchr(devname
, '.');
1418 bus_num
= strtoul(devname
, NULL
, 0);
1419 addr
= strtoul(p
+ 1, NULL
, 0);
1421 return usb_device_delete_addr(bus_num
, addr
);
1424 static int usb_parse(const char *cmdline
)
1427 r
= usb_device_add(cmdline
);
1429 error_report("could not add USB device '%s'", cmdline
);
1434 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1436 const char *devname
= qdict_get_str(qdict
, "devname");
1437 if (usb_device_add(devname
) < 0) {
1438 error_report("could not add USB device '%s'", devname
);
1442 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1444 const char *devname
= qdict_get_str(qdict
, "devname");
1445 if (usb_device_del(devname
) < 0) {
1446 error_report("could not delete USB device '%s'", devname
);
1450 /***********************************************************/
1451 /* machine registration */
1453 MachineState
*current_machine
;
1455 static MachineClass
*find_machine(const char *name
)
1457 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1458 MachineClass
*mc
= NULL
;
1460 for (el
= machines
; el
; el
= el
->next
) {
1461 MachineClass
*temp
= el
->data
;
1463 if (!strcmp(temp
->name
, name
)) {
1468 !strcmp(temp
->alias
, name
)) {
1474 g_slist_free(machines
);
1478 MachineClass
*find_default_machine(void)
1480 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1481 MachineClass
*mc
= NULL
;
1483 for (el
= machines
; el
; el
= el
->next
) {
1484 MachineClass
*temp
= el
->data
;
1486 if (temp
->is_default
) {
1492 g_slist_free(machines
);
1496 MachineInfoList
*qmp_query_machines(Error
**errp
)
1498 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1499 MachineInfoList
*mach_list
= NULL
;
1501 for (el
= machines
; el
; el
= el
->next
) {
1502 MachineClass
*mc
= el
->data
;
1503 MachineInfoList
*entry
;
1506 info
= g_malloc0(sizeof(*info
));
1507 if (mc
->is_default
) {
1508 info
->has_is_default
= true;
1509 info
->is_default
= true;
1513 info
->has_alias
= true;
1514 info
->alias
= g_strdup(mc
->alias
);
1517 info
->name
= g_strdup(mc
->name
);
1518 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1519 info
->hotpluggable_cpus
= mc
->has_hotpluggable_cpus
;
1521 entry
= g_malloc0(sizeof(*entry
));
1522 entry
->value
= info
;
1523 entry
->next
= mach_list
;
1527 g_slist_free(machines
);
1531 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1533 ObjectProperty
*prop
;
1534 ObjectPropertyIterator iter
;
1536 if (!qemu_opt_has_help_opt(opts
)) {
1540 object_property_iter_init(&iter
, OBJECT(machine
));
1541 while ((prop
= object_property_iter_next(&iter
))) {
1546 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1547 prop
->name
, prop
->type
);
1548 if (prop
->description
) {
1549 error_printf(" (%s)\n", prop
->description
);
1558 /***********************************************************/
1559 /* main execution loop */
1561 struct vm_change_state_entry
{
1562 VMChangeStateHandler
*cb
;
1564 QLIST_ENTRY (vm_change_state_entry
) entries
;
1567 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1569 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1572 VMChangeStateEntry
*e
;
1574 e
= g_malloc0(sizeof (*e
));
1578 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1582 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1584 QLIST_REMOVE (e
, entries
);
1588 void vm_state_notify(int running
, RunState state
)
1590 VMChangeStateEntry
*e
, *next
;
1592 trace_vm_state_notify(running
, state
);
1594 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1595 e
->cb(e
->opaque
, running
, state
);
1599 static int reset_requested
;
1600 static int shutdown_requested
, shutdown_signal
= -1;
1601 static pid_t shutdown_pid
;
1602 static int powerdown_requested
;
1603 static int debug_requested
;
1604 static int suspend_requested
;
1605 static WakeupReason wakeup_reason
;
1606 static NotifierList powerdown_notifiers
=
1607 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1608 static NotifierList suspend_notifiers
=
1609 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1610 static NotifierList wakeup_notifiers
=
1611 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1612 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1614 int qemu_shutdown_requested_get(void)
1616 return shutdown_requested
;
1619 int qemu_reset_requested_get(void)
1621 return reset_requested
;
1624 static int qemu_shutdown_requested(void)
1626 return atomic_xchg(&shutdown_requested
, 0);
1629 static void qemu_kill_report(void)
1631 if (!qtest_driver() && shutdown_signal
!= -1) {
1632 if (shutdown_pid
== 0) {
1633 /* This happens for eg ^C at the terminal, so it's worth
1634 * avoiding printing an odd message in that case.
1636 error_report("terminating on signal %d", shutdown_signal
);
1638 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1640 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1641 shutdown_signal
, shutdown_pid
,
1642 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1643 g_free(shutdown_cmd
);
1645 shutdown_signal
= -1;
1649 static int qemu_reset_requested(void)
1651 int r
= reset_requested
;
1652 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1653 reset_requested
= 0;
1659 static int qemu_suspend_requested(void)
1661 int r
= suspend_requested
;
1662 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1663 suspend_requested
= 0;
1669 static WakeupReason
qemu_wakeup_requested(void)
1671 return wakeup_reason
;
1674 static int qemu_powerdown_requested(void)
1676 int r
= powerdown_requested
;
1677 powerdown_requested
= 0;
1681 static int qemu_debug_requested(void)
1683 int r
= debug_requested
;
1684 debug_requested
= 0;
1688 void qemu_system_reset(bool report
)
1692 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1694 cpu_synchronize_all_states();
1696 if (mc
&& mc
->reset
) {
1699 qemu_devices_reset();
1702 qapi_event_send_reset(&error_abort
);
1704 cpu_synchronize_all_post_reset();
1707 void qemu_system_guest_panicked(GuestPanicInformation
*info
)
1709 qemu_log_mask(LOG_GUEST_ERROR
, "Guest crashed\n");
1712 current_cpu
->crash_occurred
= true;
1714 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
,
1715 !!info
, info
, &error_abort
);
1716 vm_stop(RUN_STATE_GUEST_PANICKED
);
1718 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1719 !!info
, info
, &error_abort
);
1720 qemu_system_shutdown_request();
1724 if (info
->type
== GUEST_PANIC_INFORMATION_TYPE_HYPER_V
) {
1725 qemu_log_mask(LOG_GUEST_ERROR
, "HV crash parameters: (%#"PRIx64
1726 " %#"PRIx64
" %#"PRIx64
" %#"PRIx64
" %#"PRIx64
")\n",
1727 info
->u
.hyper_v
.arg1
,
1728 info
->u
.hyper_v
.arg2
,
1729 info
->u
.hyper_v
.arg3
,
1730 info
->u
.hyper_v
.arg4
,
1731 info
->u
.hyper_v
.arg5
);
1733 qapi_free_GuestPanicInformation(info
);
1737 void qemu_system_reset_request(void)
1740 shutdown_requested
= 1;
1742 reset_requested
= 1;
1745 qemu_notify_event();
1748 static void qemu_system_suspend(void)
1751 notifier_list_notify(&suspend_notifiers
, NULL
);
1752 runstate_set(RUN_STATE_SUSPENDED
);
1753 qapi_event_send_suspend(&error_abort
);
1756 void qemu_system_suspend_request(void)
1758 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1761 suspend_requested
= 1;
1763 qemu_notify_event();
1766 void qemu_register_suspend_notifier(Notifier
*notifier
)
1768 notifier_list_add(&suspend_notifiers
, notifier
);
1771 void qemu_system_wakeup_request(WakeupReason reason
)
1773 trace_system_wakeup_request(reason
);
1775 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1778 if (!(wakeup_reason_mask
& (1 << reason
))) {
1781 runstate_set(RUN_STATE_RUNNING
);
1782 wakeup_reason
= reason
;
1783 qemu_notify_event();
1786 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1789 wakeup_reason_mask
|= (1 << reason
);
1791 wakeup_reason_mask
&= ~(1 << reason
);
1795 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1797 notifier_list_add(&wakeup_notifiers
, notifier
);
1800 void qemu_system_killed(int signal
, pid_t pid
)
1802 shutdown_signal
= signal
;
1806 /* Cannot call qemu_system_shutdown_request directly because
1807 * we are in a signal handler.
1809 shutdown_requested
= 1;
1810 qemu_notify_event();
1813 void qemu_system_shutdown_request(void)
1815 trace_qemu_system_shutdown_request();
1816 replay_shutdown_request();
1817 shutdown_requested
= 1;
1818 qemu_notify_event();
1821 static void qemu_system_powerdown(void)
1823 qapi_event_send_powerdown(&error_abort
);
1824 notifier_list_notify(&powerdown_notifiers
, NULL
);
1827 void qemu_system_powerdown_request(void)
1829 trace_qemu_system_powerdown_request();
1830 powerdown_requested
= 1;
1831 qemu_notify_event();
1834 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1836 notifier_list_add(&powerdown_notifiers
, notifier
);
1839 void qemu_system_debug_request(void)
1841 debug_requested
= 1;
1842 qemu_notify_event();
1845 static bool main_loop_should_exit(void)
1848 if (qemu_debug_requested()) {
1849 vm_stop(RUN_STATE_DEBUG
);
1851 if (qemu_suspend_requested()) {
1852 qemu_system_suspend();
1854 if (qemu_shutdown_requested()) {
1856 qapi_event_send_shutdown(&error_abort
);
1858 vm_stop(RUN_STATE_SHUTDOWN
);
1863 if (qemu_reset_requested()) {
1865 qemu_system_reset(VMRESET_REPORT
);
1867 if (!runstate_check(RUN_STATE_RUNNING
) &&
1868 !runstate_check(RUN_STATE_INMIGRATE
)) {
1869 runstate_set(RUN_STATE_PRELAUNCH
);
1872 if (qemu_wakeup_requested()) {
1874 qemu_system_reset(VMRESET_SILENT
);
1875 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1876 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1878 qapi_event_send_wakeup(&error_abort
);
1880 if (qemu_powerdown_requested()) {
1881 qemu_system_powerdown();
1883 if (qemu_vmstop_requested(&r
)) {
1889 static void main_loop(void)
1893 #ifdef CONFIG_PROFILER
1897 nonblocking
= tcg_enabled() && last_io
> 0;
1898 #ifdef CONFIG_PROFILER
1899 ti
= profile_getclock();
1901 last_io
= main_loop_wait(nonblocking
);
1902 #ifdef CONFIG_PROFILER
1903 dev_time
+= profile_getclock() - ti
;
1905 } while (!main_loop_should_exit());
1908 static void version(void)
1910 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1911 QEMU_COPYRIGHT
"\n");
1914 static void help(int exitcode
)
1917 printf("usage: %s [options] [disk_image]\n\n"
1918 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1919 error_get_progname());
1921 #define QEMU_OPTIONS_GENERATE_HELP
1922 #include "qemu-options-wrapper.h"
1924 printf("\nDuring emulation, the following keys are useful:\n"
1925 "ctrl-alt-f toggle full screen\n"
1926 "ctrl-alt-n switch to virtual console 'n'\n"
1927 "ctrl-alt toggle mouse and keyboard grab\n"
1929 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1934 #define HAS_ARG 0x0001
1936 typedef struct QEMUOption
{
1943 static const QEMUOption qemu_options
[] = {
1944 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1945 #define QEMU_OPTIONS_GENERATE_OPTIONS
1946 #include "qemu-options-wrapper.h"
1950 typedef struct VGAInterfaceInfo
{
1951 const char *opt_name
; /* option name */
1952 const char *name
; /* human-readable name */
1953 /* Class names indicating that support is available.
1954 * If no class is specified, the interface is always available */
1955 const char *class_names
[2];
1958 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
1964 .name
= "standard VGA",
1965 .class_names
= { "VGA", "isa-vga" },
1968 .opt_name
= "cirrus",
1969 .name
= "Cirrus VGA",
1970 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
1973 .opt_name
= "vmware",
1974 .name
= "VMWare SVGA",
1975 .class_names
= { "vmware-svga" },
1978 .opt_name
= "virtio",
1979 .name
= "Virtio VGA",
1980 .class_names
= { "virtio-vga" },
1985 .class_names
= { "qxl-vga" },
1989 .name
= "TCX framebuffer",
1990 .class_names
= { "SUNW,tcx" },
1994 .name
= "CG3 framebuffer",
1995 .class_names
= { "cgthree" },
1998 .opt_name
= "xenfb",
2002 static bool vga_interface_available(VGAInterfaceType t
)
2004 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2006 assert(t
< VGA_TYPE_MAX
);
2007 return !ti
->class_names
[0] ||
2008 object_class_by_name(ti
->class_names
[0]) ||
2009 object_class_by_name(ti
->class_names
[1]);
2012 static void select_vgahw(const char *p
)
2017 assert(vga_interface_type
== VGA_NONE
);
2018 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2019 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2020 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2021 if (!vga_interface_available(t
)) {
2022 error_report("%s not available", ti
->name
);
2025 vga_interface_type
= t
;
2029 if (t
== VGA_TYPE_MAX
) {
2031 error_report("unknown vga type: %s", p
);
2035 const char *nextopt
;
2037 if (strstart(opts
, ",retrace=", &nextopt
)) {
2039 if (strstart(opts
, "dumb", &nextopt
))
2040 vga_retrace_method
= VGA_RETRACE_DUMB
;
2041 else if (strstart(opts
, "precise", &nextopt
))
2042 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2043 else goto invalid_vga
;
2044 } else goto invalid_vga
;
2049 typedef enum DisplayType
{
2058 static DisplayType
select_display(const char *p
)
2061 DisplayType display
= DT_DEFAULT
;
2063 if (strstart(p
, "sdl", &opts
)) {
2067 const char *nextopt
;
2069 if (strstart(opts
, ",frame=", &nextopt
)) {
2071 if (strstart(opts
, "on", &nextopt
)) {
2073 } else if (strstart(opts
, "off", &nextopt
)) {
2076 goto invalid_sdl_args
;
2078 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2080 if (strstart(opts
, "on", &nextopt
)) {
2082 } else if (strstart(opts
, "off", &nextopt
)) {
2085 goto invalid_sdl_args
;
2087 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2089 if (strstart(opts
, "on", &nextopt
)) {
2091 } else if (strstart(opts
, "off", &nextopt
)) {
2094 goto invalid_sdl_args
;
2096 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2098 if (strstart(opts
, "on", &nextopt
)) {
2100 } else if (strstart(opts
, "off", &nextopt
)) {
2103 goto invalid_sdl_args
;
2105 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2107 if (strstart(opts
, "on", &nextopt
)) {
2109 } else if (strstart(opts
, "off", &nextopt
)) {
2112 goto invalid_sdl_args
;
2116 error_report("invalid SDL option string");
2122 error_report("SDL support is disabled");
2125 } else if (strstart(p
, "vnc", &opts
)) {
2127 vnc_parse(opts
+ 1, &error_fatal
);
2129 error_report("VNC requires a display argument vnc=<display>");
2132 } else if (strstart(p
, "curses", &opts
)) {
2133 #ifdef CONFIG_CURSES
2134 display
= DT_CURSES
;
2136 error_report("curses support is disabled");
2139 } else if (strstart(p
, "gtk", &opts
)) {
2143 const char *nextopt
;
2145 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2147 if (strstart(opts
, "on", &nextopt
)) {
2148 grab_on_hover
= true;
2149 } else if (strstart(opts
, "off", &nextopt
)) {
2150 grab_on_hover
= false;
2152 goto invalid_gtk_args
;
2154 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2156 if (strstart(opts
, "on", &nextopt
)) {
2158 } else if (strstart(opts
, "off", &nextopt
)) {
2161 goto invalid_gtk_args
;
2165 error_report("invalid GTK option string");
2171 error_report("GTK support is disabled");
2174 } else if (strstart(p
, "none", &opts
)) {
2177 error_report("unknown display type");
2184 static int balloon_parse(const char *arg
)
2188 if (strcmp(arg
, "none") == 0) {
2192 if (!strncmp(arg
, "virtio", 6)) {
2193 if (arg
[6] == ',') {
2194 /* have params -> parse them */
2195 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2200 /* create empty opts */
2201 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2204 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2211 char *qemu_find_file(int type
, const char *name
)
2217 /* Try the name as a straight path first */
2218 if (access(name
, R_OK
) == 0) {
2219 trace_load_file(name
, name
);
2220 return g_strdup(name
);
2224 case QEMU_FILE_TYPE_BIOS
:
2227 case QEMU_FILE_TYPE_KEYMAP
:
2228 subdir
= "keymaps/";
2234 for (i
= 0; i
< data_dir_idx
; i
++) {
2235 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2236 if (access(buf
, R_OK
) == 0) {
2237 trace_load_file(name
, buf
);
2245 static inline bool nonempty_str(const char *str
)
2250 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2254 const char *name
, *file
, *str
;
2255 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2257 if (fw_cfg
== NULL
) {
2258 error_report("fw_cfg device not available");
2261 name
= qemu_opt_get(opts
, "name");
2262 file
= qemu_opt_get(opts
, "file");
2263 str
= qemu_opt_get(opts
, "string");
2265 /* we need name and either a file or the content string */
2266 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2267 error_report("invalid argument(s)");
2270 if (nonempty_str(file
) && nonempty_str(str
)) {
2271 error_report("file and string are mutually exclusive");
2274 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2275 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2278 if (strncmp(name
, "opt/", 4) != 0) {
2279 error_report("warning: externally provided fw_cfg item names "
2280 "should be prefixed with \"opt/\"");
2282 if (nonempty_str(str
)) {
2283 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2284 buf
= g_memdup(str
, size
);
2286 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2287 error_report("can't load %s", file
);
2291 /* For legacy, keep user files in a specific global order. */
2292 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2293 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2294 fw_cfg_reset_order_override(fw_cfg
);
2298 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2300 return qdev_device_help(opts
);
2303 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2308 dev
= qdev_device_add(opts
, &err
);
2310 error_report_err(err
);
2313 object_unref(OBJECT(dev
));
2317 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2319 Error
*local_err
= NULL
;
2321 qemu_chr_new_from_opts(opts
, &local_err
);
2323 error_report_err(local_err
);
2329 #ifdef CONFIG_VIRTFS
2330 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2332 return qemu_fsdev_add(opts
);
2336 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2339 const char *chardev
;
2343 mode
= qemu_opt_get(opts
, "mode");
2347 if (strcmp(mode
, "readline") == 0) {
2348 flags
= MONITOR_USE_READLINE
;
2349 } else if (strcmp(mode
, "control") == 0) {
2350 flags
= MONITOR_USE_CONTROL
;
2352 error_report("unknown monitor mode \"%s\"", mode
);
2356 if (qemu_opt_get_bool(opts
, "pretty", 0))
2357 flags
|= MONITOR_USE_PRETTY
;
2359 if (qemu_opt_get_bool(opts
, "default", 0)) {
2360 error_report("option 'default' does nothing and is deprecated");
2363 chardev
= qemu_opt_get(opts
, "chardev");
2364 chr
= qemu_chr_find(chardev
);
2366 error_report("chardev \"%s\" not found", chardev
);
2370 monitor_init(chr
, flags
);
2374 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2376 static int monitor_device_index
= 0;
2381 if (strstart(optarg
, "chardev:", &p
)) {
2382 snprintf(label
, sizeof(label
), "%s", p
);
2384 snprintf(label
, sizeof(label
), "compat_monitor%d",
2385 monitor_device_index
);
2386 opts
= qemu_chr_parse_compat(label
, optarg
);
2388 error_report("parse error: %s", optarg
);
2393 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2394 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2395 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2396 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2397 monitor_device_index
++;
2400 struct device_config
{
2402 DEV_USB
, /* -usbdevice */
2404 DEV_SERIAL
, /* -serial */
2405 DEV_PARALLEL
, /* -parallel */
2406 DEV_VIRTCON
, /* -virtioconsole */
2407 DEV_DEBUGCON
, /* -debugcon */
2408 DEV_GDB
, /* -gdb, -s */
2409 DEV_SCLP
, /* s390 sclp */
2411 const char *cmdline
;
2413 QTAILQ_ENTRY(device_config
) next
;
2416 static QTAILQ_HEAD(, device_config
) device_configs
=
2417 QTAILQ_HEAD_INITIALIZER(device_configs
);
2419 static void add_device_config(int type
, const char *cmdline
)
2421 struct device_config
*conf
;
2423 conf
= g_malloc0(sizeof(*conf
));
2425 conf
->cmdline
= cmdline
;
2426 loc_save(&conf
->loc
);
2427 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2430 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2432 struct device_config
*conf
;
2435 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2436 if (conf
->type
!= type
)
2438 loc_push_restore(&conf
->loc
);
2439 rc
= func(conf
->cmdline
);
2440 loc_pop(&conf
->loc
);
2448 static int serial_parse(const char *devname
)
2450 static int index
= 0;
2453 if (strcmp(devname
, "none") == 0)
2455 if (index
== MAX_SERIAL_PORTS
) {
2456 error_report("too many serial ports");
2459 snprintf(label
, sizeof(label
), "serial%d", index
);
2460 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2461 if (!serial_hds
[index
]) {
2462 error_report("could not connect serial device"
2463 " to character backend '%s'", devname
);
2470 static int parallel_parse(const char *devname
)
2472 static int index
= 0;
2475 if (strcmp(devname
, "none") == 0)
2477 if (index
== MAX_PARALLEL_PORTS
) {
2478 error_report("too many parallel ports");
2481 snprintf(label
, sizeof(label
), "parallel%d", index
);
2482 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2483 if (!parallel_hds
[index
]) {
2484 error_report("could not connect parallel device"
2485 " to character backend '%s'", devname
);
2492 static int virtcon_parse(const char *devname
)
2494 QemuOptsList
*device
= qemu_find_opts("device");
2495 static int index
= 0;
2497 QemuOpts
*bus_opts
, *dev_opts
;
2499 if (strcmp(devname
, "none") == 0)
2501 if (index
== MAX_VIRTIO_CONSOLES
) {
2502 error_report("too many virtio consoles");
2506 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2507 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2509 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2510 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2512 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2513 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2514 if (!virtcon_hds
[index
]) {
2515 error_report("could not connect virtio console"
2516 " to character backend '%s'", devname
);
2519 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2525 static int sclp_parse(const char *devname
)
2527 QemuOptsList
*device
= qemu_find_opts("device");
2528 static int index
= 0;
2532 if (strcmp(devname
, "none") == 0) {
2535 if (index
== MAX_SCLP_CONSOLES
) {
2536 error_report("too many sclp consoles");
2540 assert(arch_type
== QEMU_ARCH_S390X
);
2542 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2543 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2545 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2546 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2547 if (!sclp_hds
[index
]) {
2548 error_report("could not connect sclp console"
2549 " to character backend '%s'", devname
);
2552 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2558 static int debugcon_parse(const char *devname
)
2562 if (!qemu_chr_new("debugcon", devname
)) {
2565 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2567 error_report("already have a debugcon device");
2570 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2571 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2575 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2577 const MachineClass
*mc1
= a
, *mc2
= b
;
2580 if (mc1
->family
== NULL
) {
2581 if (mc2
->family
== NULL
) {
2582 /* Compare standalone machine types against each other; they sort
2583 * in increasing order.
2585 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2586 object_class_get_name(OBJECT_CLASS(mc2
)));
2589 /* Standalone machine types sort after families. */
2593 if (mc2
->family
== NULL
) {
2594 /* Families sort before standalone machine types. */
2598 /* Families sort between each other alphabetically increasingly. */
2599 res
= strcmp(mc1
->family
, mc2
->family
);
2604 /* Within the same family, machine types sort in decreasing order. */
2605 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2606 object_class_get_name(OBJECT_CLASS(mc1
)));
2609 static MachineClass
*machine_parse(const char *name
)
2611 MachineClass
*mc
= NULL
;
2612 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2615 mc
= find_machine(name
);
2618 g_slist_free(machines
);
2621 if (name
&& !is_help_option(name
)) {
2622 error_report("unsupported machine type");
2623 error_printf("Use -machine help to list supported machines\n");
2625 printf("Supported machines are:\n");
2626 machines
= g_slist_sort(machines
, machine_class_cmp
);
2627 for (el
= machines
; el
; el
= el
->next
) {
2628 MachineClass
*mc
= el
->data
;
2630 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2632 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2633 mc
->is_default
? " (default)" : "");
2637 g_slist_free(machines
);
2638 exit(!name
|| !is_help_option(name
));
2641 void qemu_add_exit_notifier(Notifier
*notify
)
2643 notifier_list_add(&exit_notifiers
, notify
);
2646 void qemu_remove_exit_notifier(Notifier
*notify
)
2648 notifier_remove(notify
);
2651 static void qemu_run_exit_notifiers(void)
2653 notifier_list_notify(&exit_notifiers
, NULL
);
2656 static bool machine_init_done
;
2658 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2660 notifier_list_add(&machine_init_done_notifiers
, notify
);
2661 if (machine_init_done
) {
2662 notify
->notify(notify
, NULL
);
2666 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2668 notifier_remove(notify
);
2671 static void qemu_run_machine_init_done_notifiers(void)
2673 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2674 machine_init_done
= true;
2677 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2678 const char **poptarg
, int *poptind
)
2680 const QEMUOption
*popt
;
2681 int optind
= *poptind
;
2682 char *r
= argv
[optind
];
2685 loc_set_cmdline(argv
, optind
, 1);
2687 /* Treat --foo the same as -foo. */
2690 popt
= qemu_options
;
2693 error_report("invalid option");
2696 if (!strcmp(popt
->name
, r
+ 1))
2700 if (popt
->flags
& HAS_ARG
) {
2701 if (optind
>= argc
) {
2702 error_report("requires an argument");
2705 optarg
= argv
[optind
++];
2706 loc_set_cmdline(argv
, optind
- 2, 2);
2717 static MachineClass
*select_machine(void)
2719 MachineClass
*machine_class
= find_default_machine();
2724 loc_push_none(&loc
);
2726 opts
= qemu_get_machine_opts();
2727 qemu_opts_loc_restore(opts
);
2729 optarg
= qemu_opt_get(opts
, "type");
2731 machine_class
= machine_parse(optarg
);
2734 if (!machine_class
) {
2735 error_report("No machine specified, and there is no default");
2736 error_printf("Use -machine help to list supported machines\n");
2741 return machine_class
;
2744 static int machine_set_property(void *opaque
,
2745 const char *name
, const char *value
,
2748 Object
*obj
= OBJECT(opaque
);
2749 Error
*local_err
= NULL
;
2752 if (strcmp(name
, "type") == 0) {
2756 qom_name
= g_strdup(name
);
2757 for (p
= qom_name
; *p
; p
++) {
2763 object_property_parse(obj
, value
, qom_name
, &local_err
);
2767 error_report_err(local_err
);
2776 * Initial object creation happens before all other
2777 * QEMU data types are created. The majority of objects
2778 * can be created at this point. The rng-egd object
2779 * cannot be created here, as it depends on the chardev
2782 static bool object_create_initial(const char *type
)
2784 if (g_str_equal(type
, "rng-egd")) {
2789 * return false for concrete netfilters since
2790 * they depend on netdevs already existing
2792 if (g_str_equal(type
, "filter-buffer") ||
2793 g_str_equal(type
, "filter-dump") ||
2794 g_str_equal(type
, "filter-mirror") ||
2795 g_str_equal(type
, "filter-redirector") ||
2796 g_str_equal(type
, "colo-compare") ||
2797 g_str_equal(type
, "filter-rewriter") ||
2798 g_str_equal(type
, "filter-replay")) {
2802 /* Memory allocation by backends needs to be done
2803 * after configure_accelerator() (due to the tcg_enabled()
2804 * checks at memory_region_init_*()).
2806 * Also, allocation of large amounts of memory may delay
2807 * chardev initialization for too long, and trigger timeouts
2808 * on software that waits for a monitor socket to be created
2811 if (g_str_has_prefix(type
, "memory-backend-")) {
2820 * The remainder of object creation happens after the
2821 * creation of chardev, fsdev, net clients and device data types.
2823 static bool object_create_delayed(const char *type
)
2825 return !object_create_initial(type
);
2829 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2833 const char *mem_str
;
2834 const char *maxmem_str
, *slots_str
;
2835 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2836 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2839 loc_push_none(&loc
);
2840 qemu_opts_loc_restore(opts
);
2843 mem_str
= qemu_opt_get(opts
, "size");
2846 error_report("missing 'size' option value");
2850 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2852 /* Fix up legacy suffix-less format */
2853 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2854 uint64_t overflow_check
= sz
;
2857 if ((sz
>> 20) != overflow_check
) {
2858 error_report("too large 'size' option value");
2864 /* backward compatibility behaviour for case "-m 0" */
2866 sz
= default_ram_size
;
2869 sz
= QEMU_ALIGN_UP(sz
, 8192);
2871 if (ram_size
!= sz
) {
2872 error_report("ram size too large");
2876 /* store value for the future use */
2877 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2878 *maxram_size
= ram_size
;
2880 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2881 slots_str
= qemu_opt_get(opts
, "slots");
2882 if (maxmem_str
&& slots_str
) {
2885 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2886 slots
= qemu_opt_get_number(opts
, "slots", 0);
2887 if (sz
< ram_size
) {
2888 error_report("invalid value of -m option maxmem: "
2889 "maximum memory size (0x%" PRIx64
") must be at least "
2890 "the initial memory size (0x" RAM_ADDR_FMT
")",
2893 } else if (sz
> ram_size
) {
2895 error_report("invalid value of -m option: maxmem was "
2896 "specified, but no hotplug slots were specified");
2900 error_report("invalid value of -m option maxmem: "
2901 "memory slots were specified but maximum memory size "
2902 "(0x%" PRIx64
") is equal to the initial memory size "
2903 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2909 } else if ((!maxmem_str
&& slots_str
) ||
2910 (maxmem_str
&& !slots_str
)) {
2911 error_report("invalid -m option value: missing "
2912 "'%s' option", slots_str
? "maxmem" : "slots");
2919 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2923 g
= g_malloc0(sizeof(*g
));
2924 g
->driver
= qemu_opt_get(opts
, "driver");
2925 g
->property
= qemu_opt_get(opts
, "property");
2926 g
->value
= qemu_opt_get(opts
, "value");
2927 g
->user_provided
= true;
2928 g
->errp
= &error_fatal
;
2929 qdev_prop_register_global(g
);
2933 static int qemu_read_default_config_file(void)
2937 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2938 if (ret
< 0 && ret
!= -ENOENT
) {
2945 int main(int argc
, char **argv
, char **envp
)
2948 int snapshot
, linux_boot
;
2949 const char *initrd_filename
;
2950 const char *kernel_filename
, *kernel_cmdline
;
2951 const char *boot_order
= NULL
;
2952 const char *boot_once
= NULL
;
2954 int cyls
, heads
, secs
, translation
;
2955 QemuOpts
*opts
, *machine_opts
;
2956 QemuOpts
*hda_opts
= NULL
, *icount_opts
= NULL
, *accel_opts
= NULL
;
2957 QemuOptsList
*olist
;
2960 const char *loadvm
= NULL
;
2961 MachineClass
*machine_class
;
2962 const char *cpu_model
;
2963 const char *vga_model
= NULL
;
2964 const char *qtest_chrdev
= NULL
;
2965 const char *qtest_log
= NULL
;
2966 const char *pid_file
= NULL
;
2967 const char *incoming
= NULL
;
2968 bool defconfig
= true;
2969 bool userconfig
= true;
2970 bool nographic
= false;
2971 DisplayType display_type
= DT_DEFAULT
;
2972 int display_remote
= 0;
2973 const char *log_mask
= NULL
;
2974 const char *log_file
= NULL
;
2975 char *trace_file
= NULL
;
2976 ram_addr_t maxram_size
;
2977 uint64_t ram_slots
= 0;
2978 FILE *vmstate_dump_file
= NULL
;
2979 Error
*main_loop_err
= NULL
;
2981 bool list_data_dirs
= false;
2982 typedef struct BlockdevOptions_queue
{
2983 BlockdevOptions
*bdo
;
2985 QSIMPLEQ_ENTRY(BlockdevOptions_queue
) entry
;
2986 } BlockdevOptions_queue
;
2987 QSIMPLEQ_HEAD(, BlockdevOptions_queue
) bdo_queue
2988 = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
2990 module_call_init(MODULE_INIT_TRACE
);
2992 qemu_init_cpu_list();
2993 qemu_init_cpu_loop();
2994 qemu_mutex_lock_iothread();
2996 atexit(qemu_run_exit_notifiers
);
2997 error_set_progname(argv
[0]);
2998 qemu_init_exec_dir(argv
[0]);
3000 module_call_init(MODULE_INIT_QOM
);
3001 monitor_init_qmp_commands();
3003 qemu_add_opts(&qemu_drive_opts
);
3004 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3005 qemu_add_drive_opts(&qemu_common_drive_opts
);
3006 qemu_add_drive_opts(&qemu_drive_opts
);
3007 qemu_add_drive_opts(&bdrv_runtime_opts
);
3008 qemu_add_opts(&qemu_chardev_opts
);
3009 qemu_add_opts(&qemu_device_opts
);
3010 qemu_add_opts(&qemu_netdev_opts
);
3011 qemu_add_opts(&qemu_net_opts
);
3012 qemu_add_opts(&qemu_rtc_opts
);
3013 qemu_add_opts(&qemu_global_opts
);
3014 qemu_add_opts(&qemu_mon_opts
);
3015 qemu_add_opts(&qemu_trace_opts
);
3016 qemu_add_opts(&qemu_option_rom_opts
);
3017 qemu_add_opts(&qemu_machine_opts
);
3018 qemu_add_opts(&qemu_accel_opts
);
3019 qemu_add_opts(&qemu_mem_opts
);
3020 qemu_add_opts(&qemu_smp_opts
);
3021 qemu_add_opts(&qemu_boot_opts
);
3022 qemu_add_opts(&qemu_sandbox_opts
);
3023 qemu_add_opts(&qemu_add_fd_opts
);
3024 qemu_add_opts(&qemu_object_opts
);
3025 qemu_add_opts(&qemu_tpmdev_opts
);
3026 qemu_add_opts(&qemu_realtime_opts
);
3027 qemu_add_opts(&qemu_msg_opts
);
3028 qemu_add_opts(&qemu_name_opts
);
3029 qemu_add_opts(&qemu_numa_opts
);
3030 qemu_add_opts(&qemu_icount_opts
);
3031 qemu_add_opts(&qemu_semihosting_config_opts
);
3032 qemu_add_opts(&qemu_fw_cfg_opts
);
3033 module_call_init(MODULE_INIT_OPTS
);
3037 if (qcrypto_init(&err
) < 0) {
3038 error_reportf_err(err
, "cannot initialize crypto: ");
3041 rtc_clock
= QEMU_CLOCK_HOST
;
3043 QLIST_INIT (&vm_change_state_head
);
3044 os_setup_early_signal_handling();
3048 cyls
= heads
= secs
= 0;
3049 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3053 bdrv_init_with_whitelist();
3057 /* first pass of option parsing */
3059 while (optind
< argc
) {
3060 if (argv
[optind
][0] != '-') {
3064 const QEMUOption
*popt
;
3066 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3067 switch (popt
->index
) {
3068 case QEMU_OPTION_nodefconfig
:
3071 case QEMU_OPTION_nouserconfig
:
3078 if (defconfig
&& userconfig
) {
3079 if (qemu_read_default_config_file() < 0) {
3084 /* second pass of option parsing */
3089 if (argv
[optind
][0] != '-') {
3090 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3092 const QEMUOption
*popt
;
3094 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3095 if (!(popt
->arch_mask
& arch_type
)) {
3096 error_report("Option not supported for this target");
3099 switch(popt
->index
) {
3100 case QEMU_OPTION_no_kvm_irqchip
: {
3101 olist
= qemu_find_opts("machine");
3102 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3105 case QEMU_OPTION_cpu
:
3106 /* hw initialization will check this */
3109 case QEMU_OPTION_hda
:
3113 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3115 snprintf(buf
, sizeof(buf
),
3116 "%s,cyls=%d,heads=%d,secs=%d%s",
3117 HD_OPTS
, cyls
, heads
, secs
,
3118 translation
== BIOS_ATA_TRANSLATION_LBA
?
3120 translation
== BIOS_ATA_TRANSLATION_NONE
?
3121 ",trans=none" : "");
3122 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3125 case QEMU_OPTION_hdb
:
3126 case QEMU_OPTION_hdc
:
3127 case QEMU_OPTION_hdd
:
3128 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3131 case QEMU_OPTION_blockdev
:
3134 BlockdevOptions_queue
*bdo
;
3136 v
= qobject_input_visitor_new_str(optarg
, "driver", &err
);
3138 error_report_err(err
);
3142 bdo
= g_new(BlockdevOptions_queue
, 1);
3143 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
3146 loc_save(&bdo
->loc
);
3147 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
3150 case QEMU_OPTION_drive
:
3151 if (drive_def(optarg
) == NULL
) {
3155 case QEMU_OPTION_set
:
3156 if (qemu_set_option(optarg
) != 0)
3159 case QEMU_OPTION_global
:
3160 if (qemu_global_option(optarg
) != 0)
3163 case QEMU_OPTION_mtdblock
:
3164 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3166 case QEMU_OPTION_sd
:
3167 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3169 case QEMU_OPTION_pflash
:
3170 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3172 case QEMU_OPTION_snapshot
:
3175 case QEMU_OPTION_hdachs
:
3179 cyls
= strtol(p
, (char **)&p
, 0);
3180 if (cyls
< 1 || cyls
> 16383)
3185 heads
= strtol(p
, (char **)&p
, 0);
3186 if (heads
< 1 || heads
> 16)
3191 secs
= strtol(p
, (char **)&p
, 0);
3192 if (secs
< 1 || secs
> 63)
3196 if (!strcmp(p
, "large")) {
3197 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3198 } else if (!strcmp(p
, "rechs")) {
3199 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3200 } else if (!strcmp(p
, "none")) {
3201 translation
= BIOS_ATA_TRANSLATION_NONE
;
3202 } else if (!strcmp(p
, "lba")) {
3203 translation
= BIOS_ATA_TRANSLATION_LBA
;
3204 } else if (!strcmp(p
, "auto")) {
3205 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3209 } else if (*p
!= '\0') {
3211 error_report("invalid physical CHS format");
3214 if (hda_opts
!= NULL
) {
3215 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3217 qemu_opt_set_number(hda_opts
, "heads", heads
,
3219 qemu_opt_set_number(hda_opts
, "secs", secs
,
3221 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3222 qemu_opt_set(hda_opts
, "trans", "large",
3224 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3225 qemu_opt_set(hda_opts
, "trans", "rechs",
3227 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3228 qemu_opt_set(hda_opts
, "trans", "lba",
3230 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3231 qemu_opt_set(hda_opts
, "trans", "none",
3237 case QEMU_OPTION_numa
:
3238 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3244 case QEMU_OPTION_display
:
3245 display_type
= select_display(optarg
);
3247 case QEMU_OPTION_nographic
:
3248 olist
= qemu_find_opts("machine");
3249 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3251 display_type
= DT_NONE
;
3253 case QEMU_OPTION_curses
:
3254 #ifdef CONFIG_CURSES
3255 display_type
= DT_CURSES
;
3257 error_report("curses support is disabled");
3261 case QEMU_OPTION_portrait
:
3262 graphic_rotate
= 90;
3264 case QEMU_OPTION_rotate
:
3265 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3266 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3267 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3268 error_report("only 90, 180, 270 deg rotation is available");
3272 case QEMU_OPTION_kernel
:
3273 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3276 case QEMU_OPTION_initrd
:
3277 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3280 case QEMU_OPTION_append
:
3281 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3284 case QEMU_OPTION_dtb
:
3285 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3288 case QEMU_OPTION_cdrom
:
3289 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3291 case QEMU_OPTION_boot
:
3292 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3298 case QEMU_OPTION_fda
:
3299 case QEMU_OPTION_fdb
:
3300 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3303 case QEMU_OPTION_no_fd_bootchk
:
3306 case QEMU_OPTION_netdev
:
3308 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3312 case QEMU_OPTION_net
:
3314 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3318 #ifdef CONFIG_LIBISCSI
3319 case QEMU_OPTION_iscsi
:
3320 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3328 case QEMU_OPTION_tftp
:
3329 error_report("The -tftp option is deprecated. "
3330 "Please use '-netdev user,tftp=...' instead.");
3331 legacy_tftp_prefix
= optarg
;
3333 case QEMU_OPTION_bootp
:
3334 error_report("The -bootp option is deprecated. "
3335 "Please use '-netdev user,bootfile=...' instead.");
3336 legacy_bootp_filename
= optarg
;
3338 case QEMU_OPTION_redir
:
3339 error_report("The -redir option is deprecated. "
3340 "Please use '-netdev user,hostfwd=...' instead.");
3341 if (net_slirp_redir(optarg
) < 0)
3345 case QEMU_OPTION_bt
:
3346 add_device_config(DEV_BT
, optarg
);
3348 case QEMU_OPTION_audio_help
:
3352 case QEMU_OPTION_soundhw
:
3353 select_soundhw (optarg
);
3358 case QEMU_OPTION_version
:
3363 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3370 case QEMU_OPTION_tpmdev
:
3371 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3376 case QEMU_OPTION_mempath
:
3379 case QEMU_OPTION_mem_prealloc
:
3388 case QEMU_OPTION_DFILTER
:
3389 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3392 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3394 case QEMU_OPTION_gdb
:
3395 add_device_config(DEV_GDB
, optarg
);
3398 if (is_help_option(optarg
)) {
3399 list_data_dirs
= true;
3400 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3401 data_dir
[data_dir_idx
++] = optarg
;
3404 case QEMU_OPTION_bios
:
3405 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3408 case QEMU_OPTION_singlestep
:
3415 keyboard_layout
= optarg
;
3417 case QEMU_OPTION_localtime
:
3420 case QEMU_OPTION_vga
:
3429 w
= strtol(p
, (char **)&p
, 10);
3432 error_report("invalid resolution or depth");
3438 h
= strtol(p
, (char **)&p
, 10);
3443 depth
= strtol(p
, (char **)&p
, 10);
3444 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3445 depth
!= 24 && depth
!= 32)
3447 } else if (*p
== '\0') {
3448 depth
= graphic_depth
;
3455 graphic_depth
= depth
;
3458 case QEMU_OPTION_echr
:
3461 term_escape_char
= strtol(optarg
, &r
, 0);
3463 printf("Bad argument to echr\n");
3466 case QEMU_OPTION_monitor
:
3467 default_monitor
= 0;
3468 if (strncmp(optarg
, "none", 4)) {
3469 monitor_parse(optarg
, "readline", false);
3472 case QEMU_OPTION_qmp
:
3473 monitor_parse(optarg
, "control", false);
3474 default_monitor
= 0;
3476 case QEMU_OPTION_qmp_pretty
:
3477 monitor_parse(optarg
, "control", true);
3478 default_monitor
= 0;
3480 case QEMU_OPTION_mon
:
3481 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3486 default_monitor
= 0;
3488 case QEMU_OPTION_chardev
:
3489 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3495 case QEMU_OPTION_fsdev
:
3496 olist
= qemu_find_opts("fsdev");
3498 error_report("fsdev support is disabled");
3501 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3506 case QEMU_OPTION_virtfs
: {
3509 const char *writeout
, *sock_fd
, *socket
;
3511 olist
= qemu_find_opts("virtfs");
3513 error_report("virtfs support is disabled");
3516 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3521 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3522 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3523 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3526 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3527 qemu_opt_get(opts
, "mount_tag"),
3530 error_report("duplicate fsdev id: %s",
3531 qemu_opt_get(opts
, "mount_tag"));
3535 writeout
= qemu_opt_get(opts
, "writeout");
3537 #ifdef CONFIG_SYNC_FILE_RANGE
3538 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3540 error_report("writeout=immediate not supported "
3541 "on this platform");
3545 qemu_opt_set(fsdev
, "fsdriver",
3546 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3547 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3549 qemu_opt_set(fsdev
, "security_model",
3550 qemu_opt_get(opts
, "security_model"),
3552 socket
= qemu_opt_get(opts
, "socket");
3554 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3556 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3558 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3561 qemu_opt_set_bool(fsdev
, "readonly",
3562 qemu_opt_get_bool(opts
, "readonly", 0),
3564 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3566 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3567 qemu_opt_set(device
, "fsdev",
3568 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3569 qemu_opt_set(device
, "mount_tag",
3570 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3573 case QEMU_OPTION_virtfs_synth
: {
3577 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3580 error_report("duplicate option: %s", "virtfs_synth");
3583 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3585 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3587 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3588 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3589 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3592 case QEMU_OPTION_serial
:
3593 add_device_config(DEV_SERIAL
, optarg
);
3595 if (strncmp(optarg
, "mon:", 4) == 0) {
3596 default_monitor
= 0;
3599 case QEMU_OPTION_watchdog
:
3601 error_report("only one watchdog option may be given");
3606 case QEMU_OPTION_watchdog_action
:
3607 if (select_watchdog_action(optarg
) == -1) {
3608 error_report("unknown -watchdog-action parameter");
3612 case QEMU_OPTION_virtiocon
:
3613 add_device_config(DEV_VIRTCON
, optarg
);
3614 default_virtcon
= 0;
3615 if (strncmp(optarg
, "mon:", 4) == 0) {
3616 default_monitor
= 0;
3619 case QEMU_OPTION_parallel
:
3620 add_device_config(DEV_PARALLEL
, optarg
);
3621 default_parallel
= 0;
3622 if (strncmp(optarg
, "mon:", 4) == 0) {
3623 default_monitor
= 0;
3626 case QEMU_OPTION_debugcon
:
3627 add_device_config(DEV_DEBUGCON
, optarg
);
3629 case QEMU_OPTION_loadvm
:
3632 case QEMU_OPTION_full_screen
:
3635 case QEMU_OPTION_no_frame
:
3638 case QEMU_OPTION_alt_grab
:
3641 case QEMU_OPTION_ctrl_grab
:
3644 case QEMU_OPTION_no_quit
:
3647 case QEMU_OPTION_sdl
:
3649 display_type
= DT_SDL
;
3652 error_report("SDL support is disabled");
3655 case QEMU_OPTION_pidfile
:
3658 case QEMU_OPTION_win2k_hack
:
3659 win2k_install_hack
= 1;
3661 case QEMU_OPTION_rtc_td_hack
: {
3662 static GlobalProperty slew_lost_ticks
= {
3663 .driver
= "mc146818rtc",
3664 .property
= "lost_tick_policy",
3668 qdev_prop_register_global(&slew_lost_ticks
);
3671 case QEMU_OPTION_acpitable
:
3672 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3677 acpi_table_add(opts
, &error_fatal
);
3679 case QEMU_OPTION_smbios
:
3680 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3685 smbios_entry_add(opts
, &error_fatal
);
3687 case QEMU_OPTION_fwcfg
:
3688 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3694 case QEMU_OPTION_enable_kvm
:
3695 olist
= qemu_find_opts("machine");
3696 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3698 case QEMU_OPTION_enable_hax
:
3699 olist
= qemu_find_opts("machine");
3700 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3703 case QEMU_OPTION_machine
:
3704 olist
= qemu_find_opts("machine");
3705 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3710 case QEMU_OPTION_no_kvm
:
3711 olist
= qemu_find_opts("machine");
3712 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3714 case QEMU_OPTION_no_kvm_pit
: {
3715 error_report("warning: ignoring deprecated option");
3718 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3719 static GlobalProperty kvm_pit_lost_tick_policy
= {
3720 .driver
= "kvm-pit",
3721 .property
= "lost_tick_policy",
3725 error_report("warning: deprecated, replaced by "
3726 "-global kvm-pit.lost_tick_policy=discard");
3727 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3730 case QEMU_OPTION_accel
:
3731 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3733 optarg
= qemu_opt_get(accel_opts
, "accel");
3735 olist
= qemu_find_opts("machine");
3736 if (strcmp("kvm", optarg
) == 0) {
3737 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3738 } else if (strcmp("xen", optarg
) == 0) {
3739 qemu_opts_parse_noisily(olist
, "accel=xen", false);
3740 } else if (strcmp("tcg", optarg
) == 0) {
3741 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3743 if (!is_help_option(optarg
)) {
3744 error_printf("Unknown accelerator: %s", optarg
);
3746 error_printf("Supported accelerators: kvm, xen, tcg\n");
3750 case QEMU_OPTION_usb
:
3751 olist
= qemu_find_opts("machine");
3752 qemu_opts_parse_noisily(olist
, "usb=on", false);
3754 case QEMU_OPTION_usbdevice
:
3755 olist
= qemu_find_opts("machine");
3756 qemu_opts_parse_noisily(olist
, "usb=on", false);
3757 add_device_config(DEV_USB
, optarg
);
3759 case QEMU_OPTION_device
:
3760 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3765 case QEMU_OPTION_smp
:
3766 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3771 case QEMU_OPTION_vnc
:
3772 vnc_parse(optarg
, &error_fatal
);
3774 case QEMU_OPTION_no_acpi
:
3777 case QEMU_OPTION_no_hpet
:
3780 case QEMU_OPTION_balloon
:
3781 if (balloon_parse(optarg
) < 0) {
3782 error_report("unknown -balloon argument %s", optarg
);
3786 case QEMU_OPTION_no_reboot
:
3789 case QEMU_OPTION_no_shutdown
:
3792 case QEMU_OPTION_show_cursor
:
3795 case QEMU_OPTION_uuid
:
3796 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3797 error_report("failed to parse UUID string: wrong format");
3800 qemu_uuid_set
= true;
3802 case QEMU_OPTION_option_rom
:
3803 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3804 error_report("too many option ROMs");
3807 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3812 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3813 option_rom
[nb_option_roms
].bootindex
=
3814 qemu_opt_get_number(opts
, "bootindex", -1);
3815 if (!option_rom
[nb_option_roms
].name
) {
3816 error_report("Option ROM file is not specified");
3821 case QEMU_OPTION_semihosting
:
3822 semihosting
.enabled
= true;
3823 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3825 case QEMU_OPTION_semihosting_config
:
3826 semihosting
.enabled
= true;
3827 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3830 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3832 const char *target
= qemu_opt_get(opts
, "target");
3833 if (target
!= NULL
) {
3834 if (strcmp("native", target
) == 0) {
3835 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3836 } else if (strcmp("gdb", target
) == 0) {
3837 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3838 } else if (strcmp("auto", target
) == 0) {
3839 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3841 error_report("unsupported semihosting-config %s",
3846 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3848 /* Set semihosting argument count and vector */
3849 qemu_opt_foreach(opts
, add_semihosting_arg
,
3850 &semihosting
, NULL
);
3852 error_report("unsupported semihosting-config %s", optarg
);
3856 case QEMU_OPTION_tdf
:
3857 error_report("warning: ignoring deprecated option");
3859 case QEMU_OPTION_name
:
3860 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3866 case QEMU_OPTION_prom_env
:
3867 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3868 error_report("too many prom variables");
3871 prom_envs
[nb_prom_envs
] = optarg
;
3874 case QEMU_OPTION_old_param
:
3877 case QEMU_OPTION_clock
:
3878 /* Clock options no longer exist. Keep this option for
3879 * backward compatibility.
3882 case QEMU_OPTION_startdate
:
3883 configure_rtc_date_offset(optarg
, 1);
3885 case QEMU_OPTION_rtc
:
3886 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3891 configure_rtc(opts
);
3893 case QEMU_OPTION_tb_size
:
3894 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3895 if (tcg_tb_size
< 0) {
3899 case QEMU_OPTION_icount
:
3900 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3906 case QEMU_OPTION_incoming
:
3908 runstate_set(RUN_STATE_INMIGRATE
);
3912 case QEMU_OPTION_only_migratable
:
3913 only_migratable
= 1;
3915 case QEMU_OPTION_nodefaults
:
3918 case QEMU_OPTION_xen_domid
:
3919 if (!(xen_available())) {
3920 error_report("Option not supported for this target");
3923 xen_domid
= atoi(optarg
);
3925 case QEMU_OPTION_xen_create
:
3926 if (!(xen_available())) {
3927 error_report("Option not supported for this target");
3930 xen_mode
= XEN_CREATE
;
3932 case QEMU_OPTION_xen_attach
:
3933 if (!(xen_available())) {
3934 error_report("Option not supported for this target");
3937 xen_mode
= XEN_ATTACH
;
3939 case QEMU_OPTION_trace
:
3941 trace_file
= trace_opt_parse(optarg
);
3943 case QEMU_OPTION_readconfig
:
3945 int ret
= qemu_read_config_file(optarg
);
3947 error_report("read config %s: %s", optarg
,
3953 case QEMU_OPTION_spice
:
3954 olist
= qemu_find_opts("spice");
3956 error_report("spice support is disabled");
3959 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3965 case QEMU_OPTION_writeconfig
:
3968 if (strcmp(optarg
, "-") == 0) {
3971 fp
= fopen(optarg
, "w");
3973 error_report("open %s: %s", optarg
,
3978 qemu_config_write(fp
);
3984 case QEMU_OPTION_qtest
:
3985 qtest_chrdev
= optarg
;
3987 case QEMU_OPTION_qtest_log
:
3990 case QEMU_OPTION_sandbox
:
3991 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
3997 case QEMU_OPTION_add_fd
:
3999 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4005 error_report("File descriptor passing is disabled on this "
4010 case QEMU_OPTION_object
:
4011 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
4017 case QEMU_OPTION_realtime
:
4018 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4023 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4025 case QEMU_OPTION_msg
:
4026 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4031 configure_msg(opts
);
4033 case QEMU_OPTION_dump_vmstate
:
4034 if (vmstate_dump_file
) {
4035 error_report("only one '-dump-vmstate' "
4036 "option may be given");
4039 vmstate_dump_file
= fopen(optarg
, "w");
4040 if (vmstate_dump_file
== NULL
) {
4041 error_report("open %s: %s", optarg
, strerror(errno
));
4046 os_parse_cmd_args(popt
->index
, optarg
);
4051 * Clear error location left behind by the loop.
4052 * Best done right after the loop. Do not insert code here!
4056 replay_configure(icount_opts
);
4058 machine_class
= select_machine();
4060 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4064 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4065 error_report("could not acquire pid file: %s", strerror(errno
));
4069 if (qemu_init_main_loop(&main_loop_err
)) {
4070 error_report_err(main_loop_err
);
4074 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4075 parse_sandbox
, NULL
, NULL
)) {
4079 if (qemu_opts_foreach(qemu_find_opts("name"),
4080 parse_name
, NULL
, NULL
)) {
4085 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4086 parse_add_fd
, NULL
, NULL
)) {
4090 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4091 cleanup_add_fd
, NULL
, NULL
)) {
4096 current_machine
= MACHINE(object_new(object_class_get_name(
4097 OBJECT_CLASS(machine_class
))));
4098 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4101 object_property_add_child(object_get_root(), "machine",
4102 OBJECT(current_machine
), &error_abort
);
4104 if (machine_class
->minimum_page_bits
) {
4105 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4106 /* This would be a board error: specifying a minimum smaller than
4107 * a target's compile-time fixed setting.
4109 g_assert_not_reached();
4113 cpu_exec_init_all();
4115 if (machine_class
->hw_version
) {
4116 qemu_set_hw_version(machine_class
->hw_version
);
4119 if (cpu_model
&& is_help_option(cpu_model
)) {
4120 list_cpus(stdout
, &fprintf
, cpu_model
);
4124 if (!trace_init_backends()) {
4127 trace_init_file(trace_file
);
4129 /* Open the logfile at this point and set the log mask if necessary.
4132 qemu_set_log_filename(log_file
, &error_fatal
);
4137 mask
= qemu_str_to_log_mask(log_mask
);
4139 qemu_print_log_usage(stdout
);
4147 /* If no data_dir is specified then try to find it relative to the
4149 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4150 data_dir
[data_dir_idx
] = os_find_datadir();
4151 if (data_dir
[data_dir_idx
] != NULL
) {
4155 /* If all else fails use the install path specified when building. */
4156 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4157 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4160 /* -L help lists the data directories and exits. */
4161 if (list_data_dirs
) {
4162 for (i
= 0; i
< data_dir_idx
; i
++) {
4163 printf("%s\n", data_dir
[i
]);
4168 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4170 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4171 if (max_cpus
> machine_class
->max_cpus
) {
4172 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4173 "supported by machine '%s' (%d)", max_cpus
,
4174 machine_class
->name
, machine_class
->max_cpus
);
4179 * Get the default machine options from the machine if it is not already
4180 * specified either by the configuration file or by the command line.
4182 if (machine_class
->default_machine_opts
) {
4183 qemu_opts_set_defaults(qemu_find_opts("machine"),
4184 machine_class
->default_machine_opts
, 0);
4187 qemu_opts_foreach(qemu_find_opts("device"),
4188 default_driver_check
, NULL
, NULL
);
4189 qemu_opts_foreach(qemu_find_opts("global"),
4190 default_driver_check
, NULL
, NULL
);
4192 if (!vga_model
&& !default_vga
) {
4193 vga_interface_type
= VGA_DEVICE
;
4195 if (!has_defaults
|| machine_class
->no_serial
) {
4198 if (!has_defaults
|| machine_class
->no_parallel
) {
4199 default_parallel
= 0;
4201 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4202 default_virtcon
= 0;
4204 if (!has_defaults
|| !machine_class
->use_sclp
) {
4207 if (!has_defaults
|| machine_class
->no_floppy
) {
4210 if (!has_defaults
|| machine_class
->no_cdrom
) {
4213 if (!has_defaults
|| machine_class
->no_sdcard
) {
4216 if (!has_defaults
) {
4217 default_monitor
= 0;
4222 if (is_daemonized()) {
4223 /* According to documentation and historically, -nographic redirects
4224 * serial port, parallel port and monitor to stdio, which does not work
4225 * with -daemonize. We can redirect these to null instead, but since
4226 * -nographic is legacy, let's just error out.
4227 * We disallow -nographic only if all other ports are not redirected
4228 * explicitly, to not break existing legacy setups which uses
4229 * -nographic _and_ redirects all ports explicitly - this is valid
4230 * usage, -nographic is just a no-op in this case.
4233 && (default_parallel
|| default_serial
4234 || default_monitor
|| default_virtcon
)) {
4235 error_report("-nographic cannot be used with -daemonize");
4238 #ifdef CONFIG_CURSES
4239 if (display_type
== DT_CURSES
) {
4240 error_report("curses display cannot be used with -daemonize");
4247 if (default_parallel
)
4248 add_device_config(DEV_PARALLEL
, "null");
4249 if (default_serial
&& default_monitor
) {
4250 add_device_config(DEV_SERIAL
, "mon:stdio");
4251 } else if (default_virtcon
&& default_monitor
) {
4252 add_device_config(DEV_VIRTCON
, "mon:stdio");
4253 } else if (default_sclp
&& default_monitor
) {
4254 add_device_config(DEV_SCLP
, "mon:stdio");
4257 add_device_config(DEV_SERIAL
, "stdio");
4258 if (default_virtcon
)
4259 add_device_config(DEV_VIRTCON
, "stdio");
4261 add_device_config(DEV_SCLP
, "stdio");
4263 if (default_monitor
)
4264 monitor_parse("stdio", "readline", false);
4268 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4269 if (default_parallel
)
4270 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4271 if (default_monitor
)
4272 monitor_parse("vc:80Cx24C", "readline", false);
4273 if (default_virtcon
)
4274 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4276 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4280 #if defined(CONFIG_VNC)
4281 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4285 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4286 #if defined(CONFIG_GTK)
4287 display_type
= DT_GTK
;
4288 #elif defined(CONFIG_SDL)
4289 display_type
= DT_SDL
;
4290 #elif defined(CONFIG_COCOA)
4291 display_type
= DT_COCOA
;
4292 #elif defined(CONFIG_VNC)
4293 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4295 display_type
= DT_NONE
;
4299 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4300 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4301 "for SDL, ignoring option");
4303 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4304 error_report("-no-quit is only valid for GTK and SDL, "
4308 if (display_type
== DT_GTK
) {
4309 early_gtk_display_init(request_opengl
);
4312 if (display_type
== DT_SDL
) {
4313 sdl_display_early_init(request_opengl
);
4316 qemu_console_early_init();
4318 if (request_opengl
== 1 && display_opengl
== 0) {
4319 #if defined(CONFIG_OPENGL)
4320 error_report("OpenGL is not supported by the display");
4322 error_report("OpenGL support is disabled");
4330 if (qemu_opts_foreach(qemu_find_opts("object"),
4331 user_creatable_add_opts_foreach
,
4332 object_create_initial
, NULL
)) {
4336 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4337 chardev_init_func
, NULL
, NULL
)) {
4341 #ifdef CONFIG_VIRTFS
4342 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4343 fsdev_init_func
, NULL
, NULL
)) {
4348 if (qemu_opts_foreach(qemu_find_opts("device"),
4349 device_help_func
, NULL
, NULL
)) {
4353 machine_opts
= qemu_get_machine_opts();
4354 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4356 object_unref(OBJECT(current_machine
));
4360 configure_accelerator(current_machine
);
4363 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4366 machine_opts
= qemu_get_machine_opts();
4367 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4368 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4369 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4370 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4372 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4374 boot_order
= qemu_opt_get(opts
, "order");
4376 validate_bootdevices(boot_order
, &error_fatal
);
4379 boot_once
= qemu_opt_get(opts
, "once");
4381 validate_bootdevices(boot_once
, &error_fatal
);
4384 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4385 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4389 boot_order
= machine_class
->default_boot_order
;
4392 if (!kernel_cmdline
) {
4393 kernel_cmdline
= "";
4394 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4397 linux_boot
= (kernel_filename
!= NULL
);
4399 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4400 error_report("-append only allowed with -kernel option");
4404 if (!linux_boot
&& initrd_filename
!= NULL
) {
4405 error_report("-initrd only allowed with -kernel option");
4409 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4410 /* fall back to the -kernel/-append */
4411 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4414 os_set_line_buffering();
4416 /* spice needs the timers to be initialized by this point */
4421 if (!tcg_enabled()) {
4422 error_report("-icount is not allowed with hardware virtualization");
4425 configure_icount(icount_opts
, &error_abort
);
4426 qemu_opts_del(icount_opts
);
4429 qemu_tcg_configure(accel_opts
, &error_fatal
);
4432 QemuOptsList
*net
= qemu_find_opts("net");
4433 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4435 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4441 if (net_init_clients() < 0) {
4445 if (qemu_opts_foreach(qemu_find_opts("object"),
4446 user_creatable_add_opts_foreach
,
4447 object_create_delayed
, NULL
)) {
4452 if (tpm_init() < 0) {
4457 /* init the bluetooth world */
4458 if (foreach_device_config(DEV_BT
, bt_parse
))
4461 if (!xen_enabled()) {
4462 /* On 32-bit hosts, QEMU is limited by virtual address space */
4463 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4464 error_report("at most 2047 MB RAM can be simulated");
4472 /* If the currently selected machine wishes to override the units-per-bus
4473 * property of its default HBA interface type, do so now. */
4474 if (machine_class
->units_per_default_bus
) {
4475 override_max_devs(machine_class
->block_default_type
,
4476 machine_class
->units_per_default_bus
);
4479 /* open the virtual block devices */
4480 while (!QSIMPLEQ_EMPTY(&bdo_queue
)) {
4481 BlockdevOptions_queue
*bdo
= QSIMPLEQ_FIRST(&bdo_queue
);
4483 QSIMPLEQ_REMOVE_HEAD(&bdo_queue
, entry
);
4484 loc_push_restore(&bdo
->loc
);
4485 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
4487 qapi_free_BlockdevOptions(bdo
->bdo
);
4490 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4491 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4494 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4495 &machine_class
->block_default_type
, NULL
)) {
4499 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4501 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4502 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4504 parse_numa_opts(machine_class
);
4506 if (qemu_opts_foreach(qemu_find_opts("mon"),
4507 mon_init_func
, NULL
, NULL
)) {
4511 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4513 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4515 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4517 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4520 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4523 /* If no default VGA is requested, the default is "none". */
4525 if (machine_class
->default_display
) {
4526 vga_model
= machine_class
->default_display
;
4527 } else if (vga_interface_available(VGA_CIRRUS
)) {
4528 vga_model
= "cirrus";
4529 } else if (vga_interface_available(VGA_STD
)) {
4534 select_vgahw(vga_model
);
4538 i
= select_watchdog(watchdog
);
4540 exit (i
== 1 ? 1 : 0);
4543 machine_register_compat_props(current_machine
);
4545 qemu_opts_foreach(qemu_find_opts("global"),
4546 global_init_func
, NULL
, NULL
);
4548 /* This checkpoint is required by replay to separate prior clock
4549 reading from the other reads, because timer polling functions query
4550 clock values from the log. */
4551 replay_checkpoint(CHECKPOINT_INIT
);
4552 qdev_machine_init();
4554 current_machine
->ram_size
= ram_size
;
4555 current_machine
->maxram_size
= maxram_size
;
4556 current_machine
->ram_slots
= ram_slots
;
4557 current_machine
->boot_order
= boot_order
;
4558 current_machine
->cpu_model
= cpu_model
;
4560 machine_class
->init(current_machine
);
4566 if (hax_enabled()) {
4570 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4571 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4575 /* init USB devices */
4576 if (machine_usb(current_machine
)) {
4577 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4581 /* Check if IGD GFX passthrough. */
4584 /* init generic devices */
4585 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4586 if (qemu_opts_foreach(qemu_find_opts("device"),
4587 device_init_func
, NULL
, NULL
)) {
4591 cpu_synchronize_all_post_init();
4593 numa_post_machine_init();
4595 rom_reset_order_override();
4598 * Create frontends for -drive if=scsi leftovers.
4599 * Normally, frontends for -drive get created by machine
4600 * initialization for onboard SCSI HBAs. However, we create a few
4601 * more ever since SCSI qdevification, but this is pretty much an
4602 * implementation accident, and deprecated.
4604 scsi_legacy_handle_cmdline();
4606 /* Did we create any drives that we failed to create a device for? */
4607 drive_check_orphaned();
4609 /* Don't warn about the default network setup that you get if
4610 * no command line -net or -netdev options are specified. There
4611 * are two cases that we would otherwise complain about:
4612 * (1) board doesn't support a NIC but the implicit "-net nic"
4614 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4615 * sets up a nic that isn't connected to anything.
4618 net_check_clients();
4623 qemu_boot_set(boot_once
, &error_fatal
);
4624 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4627 ds
= init_displaystate();
4629 /* init local displays */
4630 switch (display_type
) {
4632 curses_display_init(ds
, full_screen
);
4635 sdl_display_init(ds
, full_screen
, no_frame
);
4638 cocoa_display_init(ds
, full_screen
);
4641 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4647 /* must be after terminal init, SDL library changes signal handlers */
4648 os_setup_signal_handling();
4650 /* init remote displays */
4652 qemu_opts_foreach(qemu_find_opts("vnc"),
4653 vnc_init_func
, NULL
, NULL
);
4657 qemu_spice_display_init();
4660 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4664 qdev_machine_creation_done();
4666 /* TODO: once all bus devices are qdevified, this should be done
4667 * when bus is created by qdev.c */
4668 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4669 qemu_run_machine_init_done_notifiers();
4671 if (rom_check_and_register_reset() != 0) {
4672 error_report("rom check and register reset failed");
4678 /* This checkpoint is required by replay to separate prior clock
4679 reading from the other reads, because timer polling functions query
4680 clock values from the log. */
4681 replay_checkpoint(CHECKPOINT_RESET
);
4682 qemu_system_reset(VMRESET_SILENT
);
4683 register_global_state();
4684 if (replay_mode
!= REPLAY_MODE_NONE
) {
4685 replay_vmstate_init();
4686 } else if (loadvm
) {
4687 if (load_vmstate(loadvm
) < 0) {
4692 qdev_prop_check_globals();
4693 if (vmstate_dump_file
) {
4695 dump_vmstate_json_to_file(vmstate_dump_file
);
4700 Error
*local_err
= NULL
;
4701 qemu_start_incoming_migration(incoming
, &local_err
);
4703 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4706 } else if (autostart
) {
4713 replay_disable_events();
4714 iothread_stop_all();
4720 /* vhost-user must be cleaned up before chardevs. */