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)
40 #define SDL_MAIN_HANDLED
42 #if SDL_MAJOR_VERSION == 1
43 int qemu_main(int argc
, char **argv
);
44 int main(int argc
, char **argv
)
46 return qemu_main(argc
, argv
);
49 #define main qemu_main
50 #elif SDL_MAJOR_VERSION == 2
53 #error undefined SDL version
56 #endif /* CONFIG_SDL */
60 #define main qemu_main
61 #endif /* CONFIG_COCOA */
64 #include "qemu/error-report.h"
65 #include "qemu/sockets.h"
67 #include "hw/boards.h"
68 #include "sysemu/accel.h"
70 #include "hw/i386/pc.h"
71 #include "hw/isa/isa.h"
73 #include "sysemu/watchdog.h"
74 #include "hw/smbios/smbios.h"
75 #include "hw/xen/xen.h"
77 #include "hw/loader.h"
78 #include "monitor/qdev.h"
79 #include "sysemu/bt.h"
81 #include "net/slirp.h"
82 #include "monitor/monitor.h"
83 #include "ui/console.h"
85 #include "sysemu/sysemu.h"
86 #include "sysemu/numa.h"
87 #include "exec/gdbstub.h"
88 #include "qemu/timer.h"
89 #include "sysemu/char.h"
90 #include "qemu/bitmap.h"
92 #include "sysemu/blockdev.h"
93 #include "hw/block/block.h"
94 #include "migration/block.h"
95 #include "sysemu/tpm.h"
96 #include "sysemu/dma.h"
97 #include "audio/audio.h"
98 #include "migration/migration.h"
99 #include "sysemu/cpus.h"
100 #include "migration/colo.h"
101 #include "sysemu/kvm.h"
102 #include "sysemu/hax.h"
103 #include "qapi/qmp/qjson.h"
104 #include "qemu/option.h"
105 #include "qemu/config-file.h"
106 #include "qemu-options.h"
107 #include "qmp-commands.h"
108 #include "qemu/main-loop.h"
110 #include "fsdev/qemu-fsdev.h"
112 #include "sysemu/qtest.h"
114 #include "disas/disas.h"
117 #include "slirp/libslirp.h"
120 #include "trace/control.h"
121 #include "qemu/queue.h"
122 #include "sysemu/arch_init.h"
124 #include "ui/qemu-spice.h"
125 #include "qapi/string-input-visitor.h"
126 #include "qapi/opts-visitor.h"
127 #include "qom/object_interfaces.h"
128 #include "qapi-event.h"
129 #include "exec/semihost.h"
130 #include "crypto/init.h"
131 #include "sysemu/replay.h"
132 #include "qapi/qmp/qerror.h"
133 #include "sysemu/iothread.h"
135 #define MAX_VIRTIO_CONSOLES 1
136 #define MAX_SCLP_CONSOLES 1
138 static const char *data_dir
[16];
139 static int data_dir_idx
;
140 const char *bios_name
= NULL
;
141 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
142 int request_opengl
= -1;
144 const char* keyboard_layout
= NULL
;
146 const char *mem_path
= NULL
;
147 int mem_prealloc
= 0; /* force preallocation of physical target memory */
148 bool enable_mlock
= false;
150 NICInfo nd_table
[MAX_NICS
];
152 static int rtc_utc
= 1;
153 static int rtc_date_offset
= -1; /* -1 means no change */
154 QEMUClockType rtc_clock
;
155 int vga_interface_type
= VGA_NONE
;
156 static int full_screen
= 0;
157 static int no_frame
= 0;
159 static bool grab_on_hover
;
160 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
161 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
162 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
163 CharDriverState
*sclp_hds
[MAX_SCLP_CONSOLES
];
164 int win2k_install_hack
= 0;
170 int acpi_enabled
= 1;
173 static int no_reboot
;
176 int graphic_rotate
= 0;
177 const char *watchdog
;
178 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
181 const char *qemu_name
;
184 unsigned int nb_prom_envs
= 0;
185 const char *prom_envs
[MAX_PROM_ENVS
];
188 uint8_t *boot_splash_filedata
;
189 size_t boot_splash_filedata_size
;
190 uint8_t qemu_extra_params_fw
[2];
192 int icount_align_option
;
194 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
195 * little-endian "wire format" described in the SMBIOS 2.6 specification.
200 /* Trace unassigned memory or i/o accesses. */
201 bool trace_unassigned
;
203 static NotifierList exit_notifiers
=
204 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
206 static NotifierList machine_init_done_notifiers
=
207 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
211 enum xen_mode xen_mode
= XEN_EMULATE
;
213 static int has_defaults
= 1;
214 static int default_serial
= 1;
215 static int default_parallel
= 1;
216 static int default_virtcon
= 1;
217 static int default_sclp
= 1;
218 static int default_monitor
= 1;
219 static int default_floppy
= 1;
220 static int default_cdrom
= 1;
221 static int default_sdcard
= 1;
222 static int default_vga
= 1;
223 static int default_net
= 1;
229 { .driver
= "isa-serial", .flag
= &default_serial
},
230 { .driver
= "isa-parallel", .flag
= &default_parallel
},
231 { .driver
= "isa-fdc", .flag
= &default_floppy
},
232 { .driver
= "floppy", .flag
= &default_floppy
},
233 { .driver
= "ide-cd", .flag
= &default_cdrom
},
234 { .driver
= "ide-hd", .flag
= &default_cdrom
},
235 { .driver
= "ide-drive", .flag
= &default_cdrom
},
236 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
237 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
238 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
239 { .driver
= "VGA", .flag
= &default_vga
},
240 { .driver
= "isa-vga", .flag
= &default_vga
},
241 { .driver
= "cirrus-vga", .flag
= &default_vga
},
242 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
243 { .driver
= "vmware-svga", .flag
= &default_vga
},
244 { .driver
= "qxl-vga", .flag
= &default_vga
},
245 { .driver
= "virtio-vga", .flag
= &default_vga
},
248 static QemuOptsList qemu_rtc_opts
= {
250 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
254 .type
= QEMU_OPT_STRING
,
257 .type
= QEMU_OPT_STRING
,
260 .type
= QEMU_OPT_STRING
,
262 { /* end of list */ }
266 static QemuOptsList qemu_sandbox_opts
= {
268 .implied_opt_name
= "enable",
269 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
273 .type
= QEMU_OPT_BOOL
,
275 { /* end of list */ }
279 static QemuOptsList qemu_option_rom_opts
= {
280 .name
= "option-rom",
281 .implied_opt_name
= "romfile",
282 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
286 .type
= QEMU_OPT_NUMBER
,
289 .type
= QEMU_OPT_STRING
,
291 { /* end of list */ }
295 static QemuOptsList qemu_machine_opts
= {
297 .implied_opt_name
= "type",
299 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
302 * no elements => accept any
303 * sanity checking will happen later
304 * when setting machine properties
310 static QemuOptsList qemu_boot_opts
= {
312 .implied_opt_name
= "order",
314 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
318 .type
= QEMU_OPT_STRING
,
321 .type
= QEMU_OPT_STRING
,
324 .type
= QEMU_OPT_BOOL
,
327 .type
= QEMU_OPT_STRING
,
329 .name
= "splash-time",
330 .type
= QEMU_OPT_STRING
,
332 .name
= "reboot-timeout",
333 .type
= QEMU_OPT_STRING
,
336 .type
= QEMU_OPT_BOOL
,
342 static QemuOptsList qemu_add_fd_opts
= {
344 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
348 .type
= QEMU_OPT_NUMBER
,
349 .help
= "file descriptor of which a duplicate is added to fd set",
352 .type
= QEMU_OPT_NUMBER
,
353 .help
= "ID of the fd set to add fd to",
356 .type
= QEMU_OPT_STRING
,
357 .help
= "free-form string used to describe fd",
359 { /* end of list */ }
363 static QemuOptsList qemu_object_opts
= {
365 .implied_opt_name
= "qom-type",
366 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
372 static QemuOptsList qemu_tpmdev_opts
= {
374 .implied_opt_name
= "type",
375 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
377 /* options are defined in the TPM backends */
378 { /* end of list */ }
382 static QemuOptsList qemu_realtime_opts
= {
384 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
388 .type
= QEMU_OPT_BOOL
,
390 { /* end of list */ }
394 static QemuOptsList qemu_msg_opts
= {
396 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
400 .type
= QEMU_OPT_BOOL
,
402 { /* end of list */ }
406 static QemuOptsList qemu_name_opts
= {
408 .implied_opt_name
= "guest",
410 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
414 .type
= QEMU_OPT_STRING
,
415 .help
= "Sets the name of the guest.\n"
416 "This name will be displayed in the SDL window caption.\n"
417 "The name will also be used for the VNC server",
420 .type
= QEMU_OPT_STRING
,
421 .help
= "Sets the name of the QEMU process, as shown in top etc",
423 .name
= "debug-threads",
424 .type
= QEMU_OPT_BOOL
,
425 .help
= "When enabled, name the individual threads; defaults off.\n"
426 "NOTE: The thread names are for debugging and not a\n"
429 { /* End of list */ }
433 static QemuOptsList qemu_mem_opts
= {
435 .implied_opt_name
= "size",
436 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
441 .type
= QEMU_OPT_SIZE
,
445 .type
= QEMU_OPT_NUMBER
,
449 .type
= QEMU_OPT_SIZE
,
451 { /* end of list */ }
455 static QemuOptsList qemu_icount_opts
= {
457 .implied_opt_name
= "shift",
459 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
463 .type
= QEMU_OPT_STRING
,
466 .type
= QEMU_OPT_BOOL
,
469 .type
= QEMU_OPT_BOOL
,
472 .type
= QEMU_OPT_STRING
,
475 .type
= QEMU_OPT_STRING
,
477 { /* end of list */ }
481 static QemuOptsList qemu_semihosting_config_opts
= {
482 .name
= "semihosting-config",
483 .implied_opt_name
= "enable",
484 .head
= QTAILQ_HEAD_INITIALIZER(qemu_semihosting_config_opts
.head
),
488 .type
= QEMU_OPT_BOOL
,
491 .type
= QEMU_OPT_STRING
,
494 .type
= QEMU_OPT_STRING
,
496 { /* end of list */ }
500 static QemuOptsList qemu_fw_cfg_opts
= {
502 .implied_opt_name
= "name",
503 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
507 .type
= QEMU_OPT_STRING
,
508 .help
= "Sets the fw_cfg name of the blob to be inserted",
511 .type
= QEMU_OPT_STRING
,
512 .help
= "Sets the name of the file from which\n"
513 "the fw_cfg blob will be loaded",
516 .type
= QEMU_OPT_STRING
,
517 .help
= "Sets content of the blob to be inserted from a string",
519 { /* end of list */ }
523 #ifdef CONFIG_LIBISCSI
524 static QemuOptsList qemu_iscsi_opts
= {
526 .head
= QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts
.head
),
530 .type
= QEMU_OPT_STRING
,
531 .help
= "username for CHAP authentication to target",
534 .type
= QEMU_OPT_STRING
,
535 .help
= "password for CHAP authentication to target",
537 .name
= "password-secret",
538 .type
= QEMU_OPT_STRING
,
539 .help
= "ID of the secret providing password for CHAP "
540 "authentication to target",
542 .name
= "header-digest",
543 .type
= QEMU_OPT_STRING
,
544 .help
= "HeaderDigest setting. "
545 "{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
547 .name
= "initiator-name",
548 .type
= QEMU_OPT_STRING
,
549 .help
= "Initiator iqn name to use when connecting",
552 .type
= QEMU_OPT_NUMBER
,
553 .help
= "Request timeout in seconds (default 0 = no timeout)",
555 { /* end of list */ }
561 * Get machine options
563 * Returns: machine options (never null).
565 QemuOpts
*qemu_get_machine_opts(void)
567 return qemu_find_opts_singleton("machine");
570 const char *qemu_get_vm_name(void)
575 static void res_free(void)
577 g_free(boot_splash_filedata
);
578 boot_splash_filedata
= NULL
;
581 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
583 const char *driver
= qemu_opt_get(opts
, "driver");
588 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
589 if (strcmp(default_list
[i
].driver
, driver
) != 0)
591 *(default_list
[i
].flag
) = 0;
596 /***********************************************************/
599 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
601 /* We use RUN_STATE__MAX but any invalid value will do */
602 static RunState vmstop_requested
= RUN_STATE__MAX
;
603 static QemuMutex vmstop_lock
;
608 } RunStateTransition
;
610 static const RunStateTransition runstate_transitions_def
[] = {
612 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
613 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
614 { RUN_STATE_DEBUG
, RUN_STATE_PRELAUNCH
},
616 { RUN_STATE_INMIGRATE
, RUN_STATE_INTERNAL_ERROR
},
617 { RUN_STATE_INMIGRATE
, RUN_STATE_IO_ERROR
},
618 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
619 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
620 { RUN_STATE_INMIGRATE
, RUN_STATE_SHUTDOWN
},
621 { RUN_STATE_INMIGRATE
, RUN_STATE_SUSPENDED
},
622 { RUN_STATE_INMIGRATE
, RUN_STATE_WATCHDOG
},
623 { RUN_STATE_INMIGRATE
, RUN_STATE_GUEST_PANICKED
},
624 { RUN_STATE_INMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
625 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
626 { RUN_STATE_INMIGRATE
, RUN_STATE_POSTMIGRATE
},
627 { RUN_STATE_INMIGRATE
, RUN_STATE_COLO
},
629 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
630 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
631 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PRELAUNCH
},
633 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
634 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
635 { RUN_STATE_IO_ERROR
, RUN_STATE_PRELAUNCH
},
637 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
638 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
639 { RUN_STATE_PAUSED
, RUN_STATE_PRELAUNCH
},
640 { RUN_STATE_PAUSED
, RUN_STATE_COLO
},
642 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
643 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
644 { RUN_STATE_POSTMIGRATE
, RUN_STATE_PRELAUNCH
},
646 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
647 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
648 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
650 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
651 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
652 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_PRELAUNCH
},
653 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_COLO
},
655 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
656 { RUN_STATE_RESTORE_VM
, RUN_STATE_PRELAUNCH
},
658 { RUN_STATE_COLO
, RUN_STATE_RUNNING
},
660 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
661 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
662 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
663 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
664 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
665 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
666 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
667 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
668 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
669 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
670 { RUN_STATE_RUNNING
, RUN_STATE_COLO
},
672 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
674 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
675 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
676 { RUN_STATE_SHUTDOWN
, RUN_STATE_PRELAUNCH
},
678 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
679 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
680 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
681 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
682 { RUN_STATE_SUSPENDED
, RUN_STATE_PRELAUNCH
},
683 { RUN_STATE_SUSPENDED
, RUN_STATE_COLO
},
685 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
686 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
687 { RUN_STATE_WATCHDOG
, RUN_STATE_PRELAUNCH
},
688 { RUN_STATE_WATCHDOG
, RUN_STATE_COLO
},
690 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
691 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
692 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_PRELAUNCH
},
694 { RUN_STATE__MAX
, RUN_STATE__MAX
},
697 static bool runstate_valid_transitions
[RUN_STATE__MAX
][RUN_STATE__MAX
];
699 bool runstate_check(RunState state
)
701 return current_run_state
== state
;
704 bool runstate_store(char *str
, size_t size
)
706 const char *state
= RunState_lookup
[current_run_state
];
707 size_t len
= strlen(state
) + 1;
712 memcpy(str
, state
, len
);
716 static void runstate_init(void)
718 const RunStateTransition
*p
;
720 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
721 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE__MAX
; p
++) {
722 runstate_valid_transitions
[p
->from
][p
->to
] = true;
725 qemu_mutex_init(&vmstop_lock
);
728 /* This function will abort() on invalid state transitions */
729 void runstate_set(RunState new_state
)
731 assert(new_state
< RUN_STATE__MAX
);
733 if (current_run_state
== new_state
) {
737 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
738 error_report("invalid runstate transition: '%s' -> '%s'",
739 RunState_lookup
[current_run_state
],
740 RunState_lookup
[new_state
]);
743 trace_runstate_set(new_state
);
744 current_run_state
= new_state
;
747 int runstate_is_running(void)
749 return runstate_check(RUN_STATE_RUNNING
);
752 bool runstate_needs_reset(void)
754 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
755 runstate_check(RUN_STATE_SHUTDOWN
);
758 StatusInfo
*qmp_query_status(Error
**errp
)
760 StatusInfo
*info
= g_malloc0(sizeof(*info
));
762 info
->running
= runstate_is_running();
763 info
->singlestep
= singlestep
;
764 info
->status
= current_run_state
;
769 static bool qemu_vmstop_requested(RunState
*r
)
771 qemu_mutex_lock(&vmstop_lock
);
772 *r
= vmstop_requested
;
773 vmstop_requested
= RUN_STATE__MAX
;
774 qemu_mutex_unlock(&vmstop_lock
);
775 return *r
< RUN_STATE__MAX
;
778 void qemu_system_vmstop_request_prepare(void)
780 qemu_mutex_lock(&vmstop_lock
);
783 void qemu_system_vmstop_request(RunState state
)
785 vmstop_requested
= state
;
786 qemu_mutex_unlock(&vmstop_lock
);
794 qemu_vmstop_requested(&requested
);
795 if (runstate_is_running() && requested
== RUN_STATE__MAX
) {
799 /* Ensure that a STOP/RESUME pair of events is emitted if a
800 * vmstop request was pending. The BLOCK_IO_ERROR event, for
801 * example, according to documentation is always followed by
804 if (runstate_is_running()) {
805 qapi_event_send_stop(&error_abort
);
807 replay_enable_events();
809 runstate_set(RUN_STATE_RUNNING
);
810 vm_state_notify(1, RUN_STATE_RUNNING
);
814 qapi_event_send_resume(&error_abort
);
818 /***********************************************************/
819 /* real time host monotonic timer */
821 static time_t qemu_time(void)
823 return qemu_clock_get_ms(QEMU_CLOCK_HOST
) / 1000;
826 /***********************************************************/
827 /* host time/date access */
828 void qemu_get_timedate(struct tm
*tm
, int offset
)
830 time_t ti
= qemu_time();
833 if (rtc_date_offset
== -1) {
837 localtime_r(&ti
, tm
);
839 ti
-= rtc_date_offset
;
844 int qemu_timedate_diff(struct tm
*tm
)
848 if (rtc_date_offset
== -1)
850 seconds
= mktimegm(tm
);
853 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
854 seconds
= mktime(&tmp
);
857 seconds
= mktimegm(tm
) + rtc_date_offset
;
859 return seconds
- qemu_time();
862 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
864 time_t rtc_start_date
;
867 if (!strcmp(startdate
, "now") && legacy
) {
868 rtc_date_offset
= -1;
870 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
878 } else if (sscanf(startdate
, "%d-%d-%d",
890 rtc_start_date
= mktimegm(&tm
);
891 if (rtc_start_date
== -1) {
893 error_report("invalid date format");
894 error_printf("valid formats: "
895 "'2006-06-17T16:01:21' or '2006-06-17'\n");
898 rtc_date_offset
= qemu_time() - rtc_start_date
;
902 static void configure_rtc(QemuOpts
*opts
)
906 value
= qemu_opt_get(opts
, "base");
908 if (!strcmp(value
, "utc")) {
910 } else if (!strcmp(value
, "localtime")) {
911 Error
*blocker
= NULL
;
913 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
914 "-rtc base=localtime");
915 replay_add_blocker(blocker
);
917 configure_rtc_date_offset(value
, 0);
920 value
= qemu_opt_get(opts
, "clock");
922 if (!strcmp(value
, "host")) {
923 rtc_clock
= QEMU_CLOCK_HOST
;
924 } else if (!strcmp(value
, "rt")) {
925 rtc_clock
= QEMU_CLOCK_REALTIME
;
926 } else if (!strcmp(value
, "vm")) {
927 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
929 error_report("invalid option value '%s'", value
);
933 value
= qemu_opt_get(opts
, "driftfix");
935 if (!strcmp(value
, "slew")) {
936 static GlobalProperty slew_lost_ticks
= {
937 .driver
= "mc146818rtc",
938 .property
= "lost_tick_policy",
942 qdev_prop_register_global(&slew_lost_ticks
);
943 } else if (!strcmp(value
, "none")) {
944 /* discard is default */
946 error_report("invalid option value '%s'", value
);
952 /***********************************************************/
953 /* Bluetooth support */
956 static struct HCIInfo
*hci_table
[MAX_NICS
];
958 struct HCIInfo
*qemu_next_hci(void)
960 if (cur_hci
== nb_hcis
)
963 return hci_table
[cur_hci
++];
966 static int bt_hci_parse(const char *str
)
971 if (nb_hcis
>= MAX_NICS
) {
972 error_report("too many bluetooth HCIs (max %i)", MAX_NICS
);
985 bdaddr
.b
[5] = 0x56 + nb_hcis
;
986 hci
->bdaddr_set(hci
, bdaddr
.b
);
988 hci_table
[nb_hcis
++] = hci
;
993 static void bt_vhci_add(int vlan_id
)
995 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
998 error_report("warning: adding a VHCI to an empty scatternet %i",
1001 bt_vhci_init(bt_new_hci(vlan
));
1004 static struct bt_device_s
*bt_device_add(const char *opt
)
1006 struct bt_scatternet_s
*vlan
;
1008 char *endp
= strstr(opt
, ",vlan=");
1009 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
1012 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
1015 vlan_id
= strtol(endp
+ 6, &endp
, 0);
1017 error_report("unrecognised bluetooth vlan Id");
1022 vlan
= qemu_find_bt_vlan(vlan_id
);
1025 error_report("warning: adding a slave device to an empty scatternet %i",
1028 if (!strcmp(devname
, "keyboard"))
1029 return bt_keyboard_init(vlan
);
1031 error_report("unsupported bluetooth device '%s'", devname
);
1035 static int bt_parse(const char *opt
)
1037 const char *endp
, *p
;
1040 if (strstart(opt
, "hci", &endp
)) {
1041 if (!*endp
|| *endp
== ',') {
1043 if (!strstart(endp
, ",vlan=", 0))
1046 return bt_hci_parse(opt
);
1048 } else if (strstart(opt
, "vhci", &endp
)) {
1049 if (!*endp
|| *endp
== ',') {
1051 if (strstart(endp
, ",vlan=", &p
)) {
1052 vlan
= strtol(p
, (char **) &endp
, 0);
1054 error_report("bad scatternet '%s'", p
);
1058 error_report("bad parameter '%s'", endp
+ 1);
1067 } else if (strstart(opt
, "device:", &endp
))
1068 return !bt_device_add(endp
);
1070 error_report("bad bluetooth parameter '%s'", opt
);
1074 static int parse_sandbox(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1076 /* FIXME: change this to true for 1.3 */
1077 if (qemu_opt_get_bool(opts
, "enable", false)) {
1078 #ifdef CONFIG_SECCOMP
1079 if (seccomp_start() < 0) {
1080 error_report("failed to install seccomp syscall filter "
1085 error_report("seccomp support is disabled");
1093 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1095 const char *proc_name
;
1097 if (qemu_opt_get(opts
, "debug-threads")) {
1098 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1100 qemu_name
= qemu_opt_get(opts
, "guest");
1102 proc_name
= qemu_opt_get(opts
, "process");
1104 os_set_proc_name(proc_name
);
1110 bool defaults_enabled(void)
1112 return has_defaults
;
1116 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1118 int fd
, dupfd
, flags
;
1120 const char *fd_opaque
= NULL
;
1123 fd
= qemu_opt_get_number(opts
, "fd", -1);
1124 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1125 fd_opaque
= qemu_opt_get(opts
, "opaque");
1128 error_report("fd option is required and must be non-negative");
1132 if (fd
<= STDERR_FILENO
) {
1133 error_report("fd cannot be a standard I/O stream");
1138 * All fds inherited across exec() necessarily have FD_CLOEXEC
1139 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1141 flags
= fcntl(fd
, F_GETFD
);
1142 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1143 error_report("fd is not valid or already in use");
1148 error_report("set option is required and must be non-negative");
1152 #ifdef F_DUPFD_CLOEXEC
1153 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1157 qemu_set_cloexec(dupfd
);
1161 error_report("error duplicating fd: %s", strerror(errno
));
1165 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1166 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
1173 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1177 fd
= qemu_opt_get_number(opts
, "fd", -1);
1184 /***********************************************************/
1185 /* QEMU Block devices */
1187 #define HD_OPTS "media=disk"
1188 #define CDROM_OPTS "media=cdrom"
1190 #define PFLASH_OPTS ""
1194 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1196 BlockInterfaceType
*block_default_type
= opaque
;
1198 return drive_new(opts
, *block_default_type
) == NULL
;
1201 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1203 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
1204 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
1209 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1210 int index
, const char *optstr
)
1215 if (!enable
|| drive_get_by_index(type
, index
)) {
1219 opts
= drive_add(type
, index
, NULL
, optstr
);
1221 drive_enable_snapshot(NULL
, opts
, NULL
);
1224 dinfo
= drive_new(opts
, type
);
1228 dinfo
->is_default
= true;
1232 static QemuOptsList qemu_smp_opts
= {
1234 .implied_opt_name
= "cpus",
1235 .merge_lists
= true,
1236 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1240 .type
= QEMU_OPT_NUMBER
,
1243 .type
= QEMU_OPT_NUMBER
,
1246 .type
= QEMU_OPT_NUMBER
,
1249 .type
= QEMU_OPT_NUMBER
,
1252 .type
= QEMU_OPT_NUMBER
,
1254 { /*End of list */ }
1258 static void smp_parse(QemuOpts
*opts
)
1261 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1262 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1263 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1264 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1266 /* compute missing values, prefer sockets over cores over threads */
1267 if (cpus
== 0 || sockets
== 0) {
1268 sockets
= sockets
> 0 ? sockets
: 1;
1269 cores
= cores
> 0 ? cores
: 1;
1270 threads
= threads
> 0 ? threads
: 1;
1272 cpus
= cores
* threads
* sockets
;
1274 } else if (cores
== 0) {
1275 threads
= threads
> 0 ? threads
: 1;
1276 cores
= cpus
/ (sockets
* threads
);
1277 cores
= cores
> 0 ? cores
: 1;
1278 } else if (threads
== 0) {
1279 threads
= cpus
/ (cores
* sockets
);
1280 threads
= threads
> 0 ? threads
: 1;
1281 } else if (sockets
* cores
* threads
< cpus
) {
1282 error_report("cpu topology: "
1283 "sockets (%u) * cores (%u) * threads (%u) < "
1285 sockets
, cores
, threads
, cpus
);
1289 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", cpus
);
1291 if (max_cpus
< cpus
) {
1292 error_report("maxcpus must be equal to or greater than smp");
1296 if (sockets
* cores
* threads
> max_cpus
) {
1297 error_report("cpu topology: "
1298 "sockets (%u) * cores (%u) * threads (%u) > "
1300 sockets
, cores
, threads
, max_cpus
);
1306 smp_threads
= threads
;
1310 Error
*blocker
= NULL
;
1311 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
, "smp");
1312 replay_add_blocker(blocker
);
1316 static void realtime_init(void)
1319 if (os_mlock() < 0) {
1320 error_report("locking memory failed");
1327 static void configure_msg(QemuOpts
*opts
)
1329 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1332 /***********************************************************/
1335 typedef struct SemihostingConfig
{
1337 SemihostingTarget target
;
1340 const char *cmdline
; /* concatenated argv */
1341 } SemihostingConfig
;
1343 static SemihostingConfig semihosting
;
1345 bool semihosting_enabled(void)
1347 return semihosting
.enabled
;
1350 SemihostingTarget
semihosting_get_target(void)
1352 return semihosting
.target
;
1355 const char *semihosting_get_arg(int i
)
1357 if (i
>= semihosting
.argc
) {
1360 return semihosting
.argv
[i
];
1363 int semihosting_get_argc(void)
1365 return semihosting
.argc
;
1368 const char *semihosting_get_cmdline(void)
1370 if (semihosting
.cmdline
== NULL
&& semihosting
.argc
> 0) {
1371 semihosting
.cmdline
= g_strjoinv(" ", (gchar
**)semihosting
.argv
);
1373 return semihosting
.cmdline
;
1376 static int add_semihosting_arg(void *opaque
,
1377 const char *name
, const char *val
,
1380 SemihostingConfig
*s
= opaque
;
1381 if (strcmp(name
, "arg") == 0) {
1383 /* one extra element as g_strjoinv() expects NULL-terminated array */
1384 s
->argv
= g_realloc(s
->argv
, (s
->argc
+ 1) * sizeof(void *));
1385 s
->argv
[s
->argc
- 1] = val
;
1386 s
->argv
[s
->argc
] = NULL
;
1391 /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
1392 static inline void semihosting_arg_fallback(const char *file
, const char *cmd
)
1397 add_semihosting_arg(&semihosting
, "arg", file
, NULL
);
1399 /* split -append and initialize argv[1..n] */
1400 cmd_token
= strtok(g_strdup(cmd
), " ");
1402 add_semihosting_arg(&semihosting
, "arg", cmd_token
, NULL
);
1403 cmd_token
= strtok(NULL
, " ");
1407 /* Now we still need this for compatibility with XEN. */
1408 bool has_igd_gfx_passthru
;
1409 static void igd_gfx_passthru(void)
1411 has_igd_gfx_passthru
= current_machine
->igd_gfx_passthru
;
1414 /***********************************************************/
1417 static int usb_device_add(const char *devname
)
1419 USBDevice
*dev
= NULL
;
1420 #ifndef CONFIG_LINUX
1424 if (!machine_usb(current_machine
)) {
1428 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1429 dev
= usbdevice_create(devname
);
1433 /* the other ones */
1434 #ifndef CONFIG_LINUX
1435 /* only the linux version is qdev-ified, usb-bsd still needs this */
1436 if (strstart(devname
, "host:", &p
)) {
1437 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1447 static int usb_device_del(const char *devname
)
1452 if (strstart(devname
, "host:", &p
)) {
1456 if (!machine_usb(current_machine
)) {
1460 p
= strchr(devname
, '.');
1463 bus_num
= strtoul(devname
, NULL
, 0);
1464 addr
= strtoul(p
+ 1, NULL
, 0);
1466 return usb_device_delete_addr(bus_num
, addr
);
1469 static int usb_parse(const char *cmdline
)
1472 r
= usb_device_add(cmdline
);
1474 error_report("could not add USB device '%s'", cmdline
);
1479 void hmp_usb_add(Monitor
*mon
, const QDict
*qdict
)
1481 const char *devname
= qdict_get_str(qdict
, "devname");
1482 if (usb_device_add(devname
) < 0) {
1483 error_report("could not add USB device '%s'", devname
);
1487 void hmp_usb_del(Monitor
*mon
, const QDict
*qdict
)
1489 const char *devname
= qdict_get_str(qdict
, "devname");
1490 if (usb_device_del(devname
) < 0) {
1491 error_report("could not delete USB device '%s'", devname
);
1495 /***********************************************************/
1496 /* machine registration */
1498 MachineState
*current_machine
;
1500 static MachineClass
*find_machine(const char *name
)
1502 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1503 MachineClass
*mc
= NULL
;
1505 for (el
= machines
; el
; el
= el
->next
) {
1506 MachineClass
*temp
= el
->data
;
1508 if (!strcmp(temp
->name
, name
)) {
1513 !strcmp(temp
->alias
, name
)) {
1519 g_slist_free(machines
);
1523 MachineClass
*find_default_machine(void)
1525 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1526 MachineClass
*mc
= NULL
;
1528 for (el
= machines
; el
; el
= el
->next
) {
1529 MachineClass
*temp
= el
->data
;
1531 if (temp
->is_default
) {
1537 g_slist_free(machines
);
1541 MachineInfoList
*qmp_query_machines(Error
**errp
)
1543 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1544 MachineInfoList
*mach_list
= NULL
;
1546 for (el
= machines
; el
; el
= el
->next
) {
1547 MachineClass
*mc
= el
->data
;
1548 MachineInfoList
*entry
;
1551 info
= g_malloc0(sizeof(*info
));
1552 if (mc
->is_default
) {
1553 info
->has_is_default
= true;
1554 info
->is_default
= true;
1558 info
->has_alias
= true;
1559 info
->alias
= g_strdup(mc
->alias
);
1562 info
->name
= g_strdup(mc
->name
);
1563 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1564 info
->hotpluggable_cpus
= !!mc
->query_hotpluggable_cpus
;
1566 entry
= g_malloc0(sizeof(*entry
));
1567 entry
->value
= info
;
1568 entry
->next
= mach_list
;
1572 g_slist_free(machines
);
1576 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
1578 ObjectProperty
*prop
;
1579 ObjectPropertyIterator iter
;
1581 if (!qemu_opt_has_help_opt(opts
)) {
1585 object_property_iter_init(&iter
, OBJECT(machine
));
1586 while ((prop
= object_property_iter_next(&iter
))) {
1591 error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
1592 prop
->name
, prop
->type
);
1593 if (prop
->description
) {
1594 error_printf(" (%s)\n", prop
->description
);
1603 /***********************************************************/
1604 /* main execution loop */
1606 struct vm_change_state_entry
{
1607 VMChangeStateHandler
*cb
;
1609 QLIST_ENTRY (vm_change_state_entry
) entries
;
1612 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1614 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1617 VMChangeStateEntry
*e
;
1619 e
= g_malloc0(sizeof (*e
));
1623 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1627 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1629 QLIST_REMOVE (e
, entries
);
1633 void vm_state_notify(int running
, RunState state
)
1635 VMChangeStateEntry
*e
, *next
;
1637 trace_vm_state_notify(running
, state
);
1639 QLIST_FOREACH_SAFE(e
, &vm_change_state_head
, entries
, next
) {
1640 e
->cb(e
->opaque
, running
, state
);
1644 /* reset/shutdown handler */
1646 typedef struct QEMUResetEntry
{
1647 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1648 QEMUResetHandler
*func
;
1652 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1653 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1654 static int reset_requested
;
1655 static int shutdown_requested
, shutdown_signal
= -1;
1656 static pid_t shutdown_pid
;
1657 static int powerdown_requested
;
1658 static int debug_requested
;
1659 static int suspend_requested
;
1660 static WakeupReason wakeup_reason
;
1661 static NotifierList powerdown_notifiers
=
1662 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1663 static NotifierList suspend_notifiers
=
1664 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1665 static NotifierList wakeup_notifiers
=
1666 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1667 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1669 int qemu_shutdown_requested_get(void)
1671 return shutdown_requested
;
1674 int qemu_reset_requested_get(void)
1676 return reset_requested
;
1679 static int qemu_shutdown_requested(void)
1681 return atomic_xchg(&shutdown_requested
, 0);
1684 static void qemu_kill_report(void)
1686 if (!qtest_driver() && shutdown_signal
!= -1) {
1687 if (shutdown_pid
== 0) {
1688 /* This happens for eg ^C at the terminal, so it's worth
1689 * avoiding printing an odd message in that case.
1691 error_report("terminating on signal %d", shutdown_signal
);
1693 char *shutdown_cmd
= qemu_get_pid_name(shutdown_pid
);
1695 error_report("terminating on signal %d from pid " FMT_pid
" (%s)",
1696 shutdown_signal
, shutdown_pid
,
1697 shutdown_cmd
? shutdown_cmd
: "<unknown process>");
1698 g_free(shutdown_cmd
);
1700 shutdown_signal
= -1;
1704 static int qemu_reset_requested(void)
1706 int r
= reset_requested
;
1707 if (r
&& replay_checkpoint(CHECKPOINT_RESET_REQUESTED
)) {
1708 reset_requested
= 0;
1714 static int qemu_suspend_requested(void)
1716 int r
= suspend_requested
;
1717 if (r
&& replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED
)) {
1718 suspend_requested
= 0;
1724 static WakeupReason
qemu_wakeup_requested(void)
1726 return wakeup_reason
;
1729 static int qemu_powerdown_requested(void)
1731 int r
= powerdown_requested
;
1732 powerdown_requested
= 0;
1736 static int qemu_debug_requested(void)
1738 int r
= debug_requested
;
1739 debug_requested
= 0;
1743 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1745 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1748 re
->opaque
= opaque
;
1749 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1752 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1756 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1757 if (re
->func
== func
&& re
->opaque
== opaque
) {
1758 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1765 void qemu_devices_reset(void)
1767 QEMUResetEntry
*re
, *nre
;
1769 /* reset all devices */
1770 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1771 re
->func(re
->opaque
);
1775 void qemu_system_reset(bool report
)
1779 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1781 cpu_synchronize_all_states();
1783 if (mc
&& mc
->reset
) {
1786 qemu_devices_reset();
1789 qapi_event_send_reset(&error_abort
);
1791 cpu_synchronize_all_post_reset();
1794 void qemu_system_guest_panicked(void)
1797 current_cpu
->crash_occurred
= true;
1799 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE
, &error_abort
);
1800 vm_stop(RUN_STATE_GUEST_PANICKED
);
1802 qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF
,
1804 qemu_system_shutdown_request();
1808 void qemu_system_reset_request(void)
1811 shutdown_requested
= 1;
1813 reset_requested
= 1;
1816 qemu_notify_event();
1819 static void qemu_system_suspend(void)
1822 notifier_list_notify(&suspend_notifiers
, NULL
);
1823 runstate_set(RUN_STATE_SUSPENDED
);
1824 qapi_event_send_suspend(&error_abort
);
1827 void qemu_system_suspend_request(void)
1829 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1832 suspend_requested
= 1;
1834 qemu_notify_event();
1837 void qemu_register_suspend_notifier(Notifier
*notifier
)
1839 notifier_list_add(&suspend_notifiers
, notifier
);
1842 void qemu_system_wakeup_request(WakeupReason reason
)
1844 trace_system_wakeup_request(reason
);
1846 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1849 if (!(wakeup_reason_mask
& (1 << reason
))) {
1852 runstate_set(RUN_STATE_RUNNING
);
1853 wakeup_reason
= reason
;
1854 qemu_notify_event();
1857 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1860 wakeup_reason_mask
|= (1 << reason
);
1862 wakeup_reason_mask
&= ~(1 << reason
);
1866 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1868 notifier_list_add(&wakeup_notifiers
, notifier
);
1871 void qemu_system_killed(int signal
, pid_t pid
)
1873 shutdown_signal
= signal
;
1877 /* Cannot call qemu_system_shutdown_request directly because
1878 * we are in a signal handler.
1880 shutdown_requested
= 1;
1881 qemu_notify_event();
1884 void qemu_system_shutdown_request(void)
1886 trace_qemu_system_shutdown_request();
1887 replay_shutdown_request();
1888 shutdown_requested
= 1;
1889 qemu_notify_event();
1892 static void qemu_system_powerdown(void)
1894 qapi_event_send_powerdown(&error_abort
);
1895 notifier_list_notify(&powerdown_notifiers
, NULL
);
1898 void qemu_system_powerdown_request(void)
1900 trace_qemu_system_powerdown_request();
1901 powerdown_requested
= 1;
1902 qemu_notify_event();
1905 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1907 notifier_list_add(&powerdown_notifiers
, notifier
);
1910 void qemu_system_debug_request(void)
1912 debug_requested
= 1;
1913 qemu_notify_event();
1916 static bool main_loop_should_exit(void)
1919 if (qemu_debug_requested()) {
1920 vm_stop(RUN_STATE_DEBUG
);
1922 if (qemu_suspend_requested()) {
1923 qemu_system_suspend();
1925 if (qemu_shutdown_requested()) {
1927 qapi_event_send_shutdown(&error_abort
);
1929 vm_stop(RUN_STATE_SHUTDOWN
);
1934 if (qemu_reset_requested()) {
1936 qemu_system_reset(VMRESET_REPORT
);
1938 if (!runstate_check(RUN_STATE_RUNNING
) &&
1939 !runstate_check(RUN_STATE_INMIGRATE
)) {
1940 runstate_set(RUN_STATE_PRELAUNCH
);
1943 if (qemu_wakeup_requested()) {
1945 qemu_system_reset(VMRESET_SILENT
);
1946 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1947 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1949 qapi_event_send_wakeup(&error_abort
);
1951 if (qemu_powerdown_requested()) {
1952 qemu_system_powerdown();
1954 if (qemu_vmstop_requested(&r
)) {
1960 static void main_loop(void)
1964 #ifdef CONFIG_PROFILER
1968 nonblocking
= tcg_enabled() && last_io
> 0;
1969 #ifdef CONFIG_PROFILER
1970 ti
= profile_getclock();
1972 last_io
= main_loop_wait(nonblocking
);
1973 #ifdef CONFIG_PROFILER
1974 dev_time
+= profile_getclock() - ti
;
1976 } while (!main_loop_should_exit());
1979 static void version(void)
1981 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
"\n"
1982 QEMU_COPYRIGHT
"\n");
1985 static void QEMU_NORETURN
help(int exitcode
)
1988 printf("usage: %s [options] [disk_image]\n\n"
1989 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1990 error_get_progname());
1992 #define QEMU_OPTIONS_GENERATE_HELP
1993 #include "qemu-options-wrapper.h"
1995 printf("\nDuring emulation, the following keys are useful:\n"
1996 "ctrl-alt-f toggle full screen\n"
1997 "ctrl-alt-n switch to virtual console 'n'\n"
1998 "ctrl-alt toggle mouse and keyboard grab\n"
2000 "When using -nographic, press 'ctrl-a h' to get some help.\n");
2005 #define HAS_ARG 0x0001
2007 typedef struct QEMUOption
{
2014 static const QEMUOption qemu_options
[] = {
2015 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
2016 #define QEMU_OPTIONS_GENERATE_OPTIONS
2017 #include "qemu-options-wrapper.h"
2021 typedef struct VGAInterfaceInfo
{
2022 const char *opt_name
; /* option name */
2023 const char *name
; /* human-readable name */
2024 /* Class names indicating that support is available.
2025 * If no class is specified, the interface is always available */
2026 const char *class_names
[2];
2029 static VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
2035 .name
= "standard VGA",
2036 .class_names
= { "VGA", "isa-vga" },
2039 .opt_name
= "cirrus",
2040 .name
= "Cirrus VGA",
2041 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
2044 .opt_name
= "vmware",
2045 .name
= "VMWare SVGA",
2046 .class_names
= { "vmware-svga" },
2049 .opt_name
= "virtio",
2050 .name
= "Virtio VGA",
2051 .class_names
= { "virtio-vga" },
2056 .class_names
= { "qxl-vga" },
2060 .name
= "TCX framebuffer",
2061 .class_names
= { "SUNW,tcx" },
2065 .name
= "CG3 framebuffer",
2066 .class_names
= { "cgthree" },
2069 .opt_name
= "xenfb",
2073 static bool vga_interface_available(VGAInterfaceType t
)
2075 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2077 assert(t
< VGA_TYPE_MAX
);
2078 return !ti
->class_names
[0] ||
2079 object_class_by_name(ti
->class_names
[0]) ||
2080 object_class_by_name(ti
->class_names
[1]);
2083 static void select_vgahw(const char *p
)
2088 assert(vga_interface_type
== VGA_NONE
);
2089 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
2090 VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
2091 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
2092 if (!vga_interface_available(t
)) {
2093 error_report("%s not available", ti
->name
);
2096 vga_interface_type
= t
;
2100 if (t
== VGA_TYPE_MAX
) {
2102 error_report("unknown vga type: %s", p
);
2106 const char *nextopt
;
2108 if (strstart(opts
, ",retrace=", &nextopt
)) {
2110 if (strstart(opts
, "dumb", &nextopt
))
2111 vga_retrace_method
= VGA_RETRACE_DUMB
;
2112 else if (strstart(opts
, "precise", &nextopt
))
2113 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2114 else goto invalid_vga
;
2115 } else goto invalid_vga
;
2120 typedef enum DisplayType
{
2129 static DisplayType
select_display(const char *p
)
2132 DisplayType display
= DT_DEFAULT
;
2134 if (strstart(p
, "sdl", &opts
)) {
2138 const char *nextopt
;
2140 if (strstart(opts
, ",frame=", &nextopt
)) {
2142 if (strstart(opts
, "on", &nextopt
)) {
2144 } else if (strstart(opts
, "off", &nextopt
)) {
2147 goto invalid_sdl_args
;
2149 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2151 if (strstart(opts
, "on", &nextopt
)) {
2153 } else if (strstart(opts
, "off", &nextopt
)) {
2156 goto invalid_sdl_args
;
2158 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2160 if (strstart(opts
, "on", &nextopt
)) {
2162 } else if (strstart(opts
, "off", &nextopt
)) {
2165 goto invalid_sdl_args
;
2167 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2169 if (strstart(opts
, "on", &nextopt
)) {
2171 } else if (strstart(opts
, "off", &nextopt
)) {
2174 goto invalid_sdl_args
;
2176 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2178 if (strstart(opts
, "on", &nextopt
)) {
2180 } else if (strstart(opts
, "off", &nextopt
)) {
2183 goto invalid_sdl_args
;
2187 error_report("invalid SDL option string");
2193 error_report("SDL support is disabled");
2196 } else if (strstart(p
, "vnc", &opts
)) {
2198 vnc_parse(opts
+ 1, &error_fatal
);
2200 error_report("VNC requires a display argument vnc=<display>");
2203 } else if (strstart(p
, "curses", &opts
)) {
2204 #ifdef CONFIG_CURSES
2205 display
= DT_CURSES
;
2207 error_report("curses support is disabled");
2210 } else if (strstart(p
, "gtk", &opts
)) {
2214 const char *nextopt
;
2216 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2218 if (strstart(opts
, "on", &nextopt
)) {
2219 grab_on_hover
= true;
2220 } else if (strstart(opts
, "off", &nextopt
)) {
2221 grab_on_hover
= false;
2223 goto invalid_gtk_args
;
2225 } else if (strstart(opts
, ",gl=", &nextopt
)) {
2227 if (strstart(opts
, "on", &nextopt
)) {
2229 } else if (strstart(opts
, "off", &nextopt
)) {
2232 goto invalid_gtk_args
;
2236 error_report("invalid GTK option string");
2242 error_report("GTK support is disabled");
2245 } else if (strstart(p
, "none", &opts
)) {
2248 error_report("unknown display type");
2255 static int balloon_parse(const char *arg
)
2259 if (strcmp(arg
, "none") == 0) {
2263 if (!strncmp(arg
, "virtio", 6)) {
2264 if (arg
[6] == ',') {
2265 /* have params -> parse them */
2266 opts
= qemu_opts_parse_noisily(qemu_find_opts("device"), arg
+ 7,
2271 /* create empty opts */
2272 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2275 qemu_opt_set(opts
, "driver", "virtio-balloon", &error_abort
);
2282 #if defined(CONFIG_RUBY)
2283 /* Ruby interface for QEMU. See README.EXT for programming example. */
2287 static VALUE
qemu_open(int argc
, VALUE
*argv
, VALUE klass
)
2290 for (i
= 0; i
< argc
; i
++) {
2291 argv
[i
] = StringValue(argv
[i
]);
2292 fprintf(stderr
, "argv[%d] = %s\n", i
, StringValuePtr(argv
[i
]));
2294 //~ if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
2295 //~ mode = 0666; /* default value */
2297 return INT2FIX(argc
);
2300 void Init_qemu(void)
2302 printf("%s\n", __func__
);
2303 VALUE cQEMU
= rb_define_class("QEMU", rb_cObject
);
2304 rb_define_singleton_method(cQEMU
, "run", qemu_open
, -1);
2309 #endif /* CONFIG_RUBY */
2311 #if defined(CONFIG_DLL)
2312 BOOL APIENTRY
DllMain(HINSTANCE hModule
, DWORD ul_reason_for_call
, LPVOID data
)
2316 #endif /* CONFIG_DLL */
2318 char *qemu_find_file(int type
, const char *name
)
2324 /* Try the name as a straight path first */
2325 if (access(name
, R_OK
) == 0) {
2326 trace_load_file(name
, name
);
2327 return g_strdup(name
);
2331 case QEMU_FILE_TYPE_BIOS
:
2334 case QEMU_FILE_TYPE_KEYMAP
:
2335 subdir
= "keymaps/";
2341 for (i
= 0; i
< data_dir_idx
; i
++) {
2342 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2343 if (access(buf
, R_OK
) == 0) {
2344 trace_load_file(name
, buf
);
2352 static inline bool nonempty_str(const char *str
)
2357 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2361 const char *name
, *file
, *str
;
2362 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
2364 if (fw_cfg
== NULL
) {
2365 error_report("fw_cfg device not available");
2368 name
= qemu_opt_get(opts
, "name");
2369 file
= qemu_opt_get(opts
, "file");
2370 str
= qemu_opt_get(opts
, "string");
2372 /* we need name and either a file or the content string */
2373 if (!(nonempty_str(name
) && (nonempty_str(file
) || nonempty_str(str
)))) {
2374 error_report("invalid argument(s)");
2377 if (nonempty_str(file
) && nonempty_str(str
)) {
2378 error_report("file and string are mutually exclusive");
2381 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
2382 error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH
- 1);
2385 if (strncmp(name
, "opt/", 4) != 0) {
2386 error_report("warning: externally provided fw_cfg item names "
2387 "should be prefixed with \"opt/\"");
2389 if (nonempty_str(str
)) {
2390 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
2391 buf
= g_memdup(str
, size
);
2393 if (!g_file_get_contents(file
, &buf
, &size
, NULL
)) {
2394 error_report("can't load %s", file
);
2398 /* For legacy, keep user files in a specific global order. */
2399 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
2400 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
2401 fw_cfg_reset_order_override(fw_cfg
);
2405 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2407 return qdev_device_help(opts
);
2410 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2415 dev
= qdev_device_add(opts
, &err
);
2417 error_report_err(err
);
2420 object_unref(OBJECT(dev
));
2424 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2426 Error
*local_err
= NULL
;
2428 qemu_chr_new_from_opts(opts
, &local_err
);
2430 error_report_err(local_err
);
2436 #ifdef CONFIG_VIRTFS
2437 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2439 return qemu_fsdev_add(opts
);
2443 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2445 CharDriverState
*chr
;
2446 const char *chardev
;
2450 mode
= qemu_opt_get(opts
, "mode");
2454 if (strcmp(mode
, "readline") == 0) {
2455 flags
= MONITOR_USE_READLINE
;
2456 } else if (strcmp(mode
, "control") == 0) {
2457 flags
= MONITOR_USE_CONTROL
;
2459 error_report("unknown monitor mode \"%s\"", mode
);
2463 if (qemu_opt_get_bool(opts
, "pretty", 0))
2464 flags
|= MONITOR_USE_PRETTY
;
2466 if (qemu_opt_get_bool(opts
, "default", 0)) {
2467 error_report("option 'default' does nothing and is deprecated");
2470 chardev
= qemu_opt_get(opts
, "chardev");
2471 chr
= qemu_chr_find(chardev
);
2473 error_report("chardev \"%s\" not found", chardev
);
2477 monitor_init(chr
, flags
);
2481 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
2483 static int monitor_device_index
= 0;
2488 if (strstart(optarg
, "chardev:", &p
)) {
2489 snprintf(label
, sizeof(label
), "%s", p
);
2491 snprintf(label
, sizeof(label
), "compat_monitor%d",
2492 monitor_device_index
);
2493 opts
= qemu_chr_parse_compat(label
, optarg
);
2495 error_report("parse error: %s", optarg
);
2500 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
2501 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
2502 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
2503 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
2504 monitor_device_index
++;
2507 struct device_config
{
2509 DEV_USB
, /* -usbdevice */
2511 DEV_SERIAL
, /* -serial */
2512 DEV_PARALLEL
, /* -parallel */
2513 DEV_VIRTCON
, /* -virtioconsole */
2514 DEV_DEBUGCON
, /* -debugcon */
2515 DEV_GDB
, /* -gdb, -s */
2516 DEV_SCLP
, /* s390 sclp */
2518 const char *cmdline
;
2520 QTAILQ_ENTRY(device_config
) next
;
2523 static QTAILQ_HEAD(, device_config
) device_configs
=
2524 QTAILQ_HEAD_INITIALIZER(device_configs
);
2526 static void add_device_config(int type
, const char *cmdline
)
2528 struct device_config
*conf
;
2530 conf
= g_malloc0(sizeof(*conf
));
2532 conf
->cmdline
= cmdline
;
2533 loc_save(&conf
->loc
);
2534 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2537 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2539 struct device_config
*conf
;
2542 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2543 if (conf
->type
!= type
)
2545 loc_push_restore(&conf
->loc
);
2546 rc
= func(conf
->cmdline
);
2547 loc_pop(&conf
->loc
);
2555 static int serial_parse(const char *devname
)
2557 static int index
= 0;
2560 if (strcmp(devname
, "none") == 0)
2562 if (index
== MAX_SERIAL_PORTS
) {
2563 error_report("too many serial ports");
2566 snprintf(label
, sizeof(label
), "serial%d", index
);
2567 serial_hds
[index
] = qemu_chr_new(label
, devname
);
2568 if (!serial_hds
[index
]) {
2569 error_report("could not connect serial device"
2570 " to character backend '%s'", devname
);
2577 static int parallel_parse(const char *devname
)
2579 static int index
= 0;
2582 if (strcmp(devname
, "none") == 0)
2584 if (index
== MAX_PARALLEL_PORTS
) {
2585 error_report("too many parallel ports");
2588 snprintf(label
, sizeof(label
), "parallel%d", index
);
2589 parallel_hds
[index
] = qemu_chr_new(label
, devname
);
2590 if (!parallel_hds
[index
]) {
2591 error_report("could not connect parallel device"
2592 " to character backend '%s'", devname
);
2599 static int virtcon_parse(const char *devname
)
2601 QemuOptsList
*device
= qemu_find_opts("device");
2602 static int index
= 0;
2604 QemuOpts
*bus_opts
, *dev_opts
;
2606 if (strcmp(devname
, "none") == 0)
2608 if (index
== MAX_VIRTIO_CONSOLES
) {
2609 error_report("too many virtio consoles");
2613 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2614 qemu_opt_set(bus_opts
, "driver", "virtio-serial", &error_abort
);
2616 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2617 qemu_opt_set(dev_opts
, "driver", "virtconsole", &error_abort
);
2619 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2620 virtcon_hds
[index
] = qemu_chr_new(label
, devname
);
2621 if (!virtcon_hds
[index
]) {
2622 error_report("could not connect virtio console"
2623 " to character backend '%s'", devname
);
2626 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2632 static int sclp_parse(const char *devname
)
2634 QemuOptsList
*device
= qemu_find_opts("device");
2635 static int index
= 0;
2639 if (strcmp(devname
, "none") == 0) {
2642 if (index
== MAX_SCLP_CONSOLES
) {
2643 error_report("too many sclp consoles");
2647 assert(arch_type
== QEMU_ARCH_S390X
);
2649 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2650 qemu_opt_set(dev_opts
, "driver", "sclpconsole", &error_abort
);
2652 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2653 sclp_hds
[index
] = qemu_chr_new(label
, devname
);
2654 if (!sclp_hds
[index
]) {
2655 error_report("could not connect sclp console"
2656 " to character backend '%s'", devname
);
2659 qemu_opt_set(dev_opts
, "chardev", label
, &error_abort
);
2665 static int debugcon_parse(const char *devname
)
2669 if (!qemu_chr_new("debugcon", devname
)) {
2672 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2674 error_report("already have a debugcon device");
2677 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
2678 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
2682 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
2684 const MachineClass
*mc1
= a
, *mc2
= b
;
2687 if (mc1
->family
== NULL
) {
2688 if (mc2
->family
== NULL
) {
2689 /* Compare standalone machine types against each other; they sort
2690 * in increasing order.
2692 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
2693 object_class_get_name(OBJECT_CLASS(mc2
)));
2696 /* Standalone machine types sort after families. */
2700 if (mc2
->family
== NULL
) {
2701 /* Families sort before standalone machine types. */
2705 /* Families sort between each other alphabetically increasingly. */
2706 res
= strcmp(mc1
->family
, mc2
->family
);
2711 /* Within the same family, machine types sort in decreasing order. */
2712 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
2713 object_class_get_name(OBJECT_CLASS(mc1
)));
2716 static MachineClass
*machine_parse(const char *name
)
2718 MachineClass
*mc
= NULL
;
2719 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2722 mc
= find_machine(name
);
2725 g_slist_free(machines
);
2728 if (name
&& !is_help_option(name
)) {
2729 error_report("unsupported machine type");
2730 error_printf("Use -machine help to list supported machines\n");
2732 printf("Supported machines are:\n");
2733 machines
= g_slist_sort(machines
, machine_class_cmp
);
2734 for (el
= machines
; el
; el
= el
->next
) {
2735 MachineClass
*mc
= el
->data
;
2737 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2739 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2740 mc
->is_default
? " (default)" : "");
2744 g_slist_free(machines
);
2745 exit(!name
|| !is_help_option(name
));
2748 void qemu_add_exit_notifier(Notifier
*notify
)
2750 notifier_list_add(&exit_notifiers
, notify
);
2753 void qemu_remove_exit_notifier(Notifier
*notify
)
2755 notifier_remove(notify
);
2758 static void qemu_run_exit_notifiers(void)
2760 notifier_list_notify(&exit_notifiers
, NULL
);
2763 static bool machine_init_done
;
2765 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2767 notifier_list_add(&machine_init_done_notifiers
, notify
);
2768 if (machine_init_done
) {
2769 notify
->notify(notify
, NULL
);
2773 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
2775 notifier_remove(notify
);
2778 static void qemu_run_machine_init_done_notifiers(void)
2780 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2781 machine_init_done
= true;
2784 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2785 const char **poptarg
, int *poptind
)
2787 const QEMUOption
*popt
;
2788 int optind
= *poptind
;
2789 char *r
= argv
[optind
];
2792 loc_set_cmdline(argv
, optind
, 1);
2794 /* Treat --foo the same as -foo. */
2797 popt
= qemu_options
;
2800 error_report("invalid option");
2803 if (!strcmp(popt
->name
, r
+ 1))
2807 if (popt
->flags
& HAS_ARG
) {
2808 if (optind
>= argc
) {
2809 error_report("requires an argument");
2812 optarg
= argv
[optind
++];
2813 loc_set_cmdline(argv
, optind
- 2, 2);
2824 static MachineClass
*select_machine(void)
2826 MachineClass
*machine_class
= find_default_machine();
2831 loc_push_none(&loc
);
2833 opts
= qemu_get_machine_opts();
2834 qemu_opts_loc_restore(opts
);
2836 optarg
= qemu_opt_get(opts
, "type");
2838 machine_class
= machine_parse(optarg
);
2841 if (!machine_class
) {
2842 error_report("No machine specified, and there is no default");
2843 error_printf("Use -machine help to list supported machines\n");
2848 return machine_class
;
2851 static int machine_set_property(void *opaque
,
2852 const char *name
, const char *value
,
2855 Object
*obj
= OBJECT(opaque
);
2856 Error
*local_err
= NULL
;
2859 if (strcmp(name
, "type") == 0) {
2863 qom_name
= g_strdup(name
);
2864 for (p
= qom_name
; *p
; p
++) {
2870 object_property_parse(obj
, value
, qom_name
, &local_err
);
2874 error_report_err(local_err
);
2883 * Initial object creation happens before all other
2884 * QEMU data types are created. The majority of objects
2885 * can be created at this point. The rng-egd object
2886 * cannot be created here, as it depends on the chardev
2889 static bool object_create_initial(const char *type
)
2891 if (g_str_equal(type
, "rng-egd")) {
2896 * return false for concrete netfilters since
2897 * they depend on netdevs already existing
2899 if (g_str_equal(type
, "filter-buffer") ||
2900 g_str_equal(type
, "filter-dump") ||
2901 g_str_equal(type
, "filter-mirror") ||
2902 g_str_equal(type
, "filter-redirector") ||
2903 g_str_equal(type
, "colo-compare") ||
2904 g_str_equal(type
, "filter-rewriter") ||
2905 g_str_equal(type
, "filter-replay")) {
2909 /* Memory allocation by backends needs to be done
2910 * after configure_accelerator() (due to the tcg_enabled()
2911 * checks at memory_region_init_*()).
2913 * Also, allocation of large amounts of memory may delay
2914 * chardev initialization for too long, and trigger timeouts
2915 * on software that waits for a monitor socket to be created
2918 if (g_str_has_prefix(type
, "memory-backend-")) {
2927 * The remainder of object creation happens after the
2928 * creation of chardev, fsdev, net clients and device data types.
2930 static bool object_create_delayed(const char *type
)
2932 return !object_create_initial(type
);
2936 static void set_memory_options(uint64_t *ram_slots
, ram_addr_t
*maxram_size
,
2940 const char *mem_str
;
2941 const char *maxmem_str
, *slots_str
;
2942 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
2943 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2946 loc_push_none(&loc
);
2947 qemu_opts_loc_restore(opts
);
2950 mem_str
= qemu_opt_get(opts
, "size");
2953 error_report("missing 'size' option value");
2957 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2959 /* Fix up legacy suffix-less format */
2960 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2961 uint64_t overflow_check
= sz
;
2964 if ((sz
>> 20) != overflow_check
) {
2965 error_report("too large 'size' option value");
2971 /* backward compatibility behaviour for case "-m 0" */
2973 sz
= default_ram_size
;
2976 sz
= QEMU_ALIGN_UP(sz
, 8192);
2978 if (ram_size
!= sz
) {
2979 error_report("ram size too large");
2983 /* store value for the future use */
2984 qemu_opt_set_number(opts
, "size", ram_size
, &error_abort
);
2985 *maxram_size
= ram_size
;
2987 maxmem_str
= qemu_opt_get(opts
, "maxmem");
2988 slots_str
= qemu_opt_get(opts
, "slots");
2989 if (maxmem_str
&& slots_str
) {
2992 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2993 slots
= qemu_opt_get_number(opts
, "slots", 0);
2994 if (sz
< ram_size
) {
2995 error_report("invalid value of -m option maxmem: "
2996 "maximum memory size (0x%" PRIx64
") must be at least "
2997 "the initial memory size (0x" RAM_ADDR_FMT
")",
3000 } else if (sz
> ram_size
) {
3002 error_report("invalid value of -m option: maxmem was "
3003 "specified, but no hotplug slots were specified");
3007 error_report("invalid value of -m option maxmem: "
3008 "memory slots were specified but maximum memory size "
3009 "(0x%" PRIx64
") is equal to the initial memory size "
3010 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
3016 } else if ((!maxmem_str
&& slots_str
) ||
3017 (maxmem_str
&& !slots_str
)) {
3018 error_report("invalid -m option value: missing "
3019 "'%s' option", slots_str
? "maxmem" : "slots");
3026 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
3030 g
= g_malloc0(sizeof(*g
));
3031 g
->driver
= qemu_opt_get(opts
, "driver");
3032 g
->property
= qemu_opt_get(opts
, "property");
3033 g
->value
= qemu_opt_get(opts
, "value");
3034 g
->user_provided
= true;
3035 g
->errp
= &error_fatal
;
3036 qdev_prop_register_global(g
);
3040 int main(int argc
, char **argv
)
3043 int snapshot
, linux_boot
;
3044 const char *initrd_filename
;
3045 const char *kernel_filename
, *kernel_cmdline
;
3046 const char *boot_order
= NULL
;
3047 const char *boot_once
= NULL
;
3049 int cyls
, heads
, secs
, translation
;
3050 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
, *icount_opts
= NULL
;
3051 QemuOptsList
*olist
;
3054 const char *loadvm
= NULL
;
3055 MachineClass
*machine_class
;
3056 const char *cpu_model
;
3057 const char *vga_model
= NULL
;
3058 const char *qtest_chrdev
= NULL
;
3059 const char *qtest_log
= NULL
;
3060 const char *pid_file
= NULL
;
3061 const char *incoming
= NULL
;
3062 bool defconfig
= true;
3063 bool userconfig
= true;
3064 bool nographic
= false;
3065 DisplayType display_type
= DT_DEFAULT
;
3066 int display_remote
= 0;
3067 const char *log_mask
= NULL
;
3068 const char *log_file
= NULL
;
3069 char *trace_file
= NULL
;
3070 ram_addr_t maxram_size
;
3071 uint64_t ram_slots
= 0;
3072 FILE *vmstate_dump_file
= NULL
;
3073 Error
*main_loop_err
= NULL
;
3075 bool list_data_dirs
= false;
3077 module_call_init(MODULE_INIT_TRACE
);
3079 qemu_init_cpu_list();
3080 qemu_init_cpu_loop();
3081 qemu_mutex_lock_iothread();
3083 atexit(qemu_run_exit_notifiers
);
3084 error_set_progname(argv
[0]);
3085 qemu_init_exec_dir(argv
[0]);
3087 module_call_init(MODULE_INIT_QOM
);
3088 module_call_init(MODULE_INIT_QAPI
);
3090 qemu_add_opts(&qemu_drive_opts
);
3091 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3092 qemu_add_drive_opts(&qemu_common_drive_opts
);
3093 qemu_add_drive_opts(&qemu_drive_opts
);
3094 qemu_add_drive_opts(&bdrv_runtime_opts
);
3095 qemu_add_opts(&qemu_chardev_opts
);
3096 qemu_add_opts(&qemu_device_opts
);
3097 qemu_add_opts(&qemu_netdev_opts
);
3098 qemu_add_opts(&qemu_net_opts
);
3099 qemu_add_opts(&qemu_rtc_opts
);
3100 qemu_add_opts(&qemu_global_opts
);
3101 qemu_add_opts(&qemu_mon_opts
);
3102 qemu_add_opts(&qemu_trace_opts
);
3103 qemu_add_opts(&qemu_option_rom_opts
);
3104 qemu_add_opts(&qemu_machine_opts
);
3105 qemu_add_opts(&qemu_mem_opts
);
3106 qemu_add_opts(&qemu_smp_opts
);
3107 qemu_add_opts(&qemu_boot_opts
);
3108 qemu_add_opts(&qemu_sandbox_opts
);
3109 qemu_add_opts(&qemu_add_fd_opts
);
3110 qemu_add_opts(&qemu_object_opts
);
3111 qemu_add_opts(&qemu_tpmdev_opts
);
3112 qemu_add_opts(&qemu_realtime_opts
);
3113 qemu_add_opts(&qemu_msg_opts
);
3114 qemu_add_opts(&qemu_name_opts
);
3115 qemu_add_opts(&qemu_numa_opts
);
3116 qemu_add_opts(&qemu_icount_opts
);
3117 qemu_add_opts(&qemu_semihosting_config_opts
);
3118 qemu_add_opts(&qemu_fw_cfg_opts
);
3119 #ifdef CONFIG_LIBISCSI
3120 qemu_add_opts(&qemu_iscsi_opts
);
3122 module_call_init(MODULE_INIT_OPTS
);
3126 if (qcrypto_init(&err
) < 0) {
3127 error_reportf_err(err
, "cannot initialize crypto: ");
3130 rtc_clock
= QEMU_CLOCK_HOST
;
3132 QLIST_INIT (&vm_change_state_head
);
3133 os_setup_early_signal_handling();
3137 cyls
= heads
= secs
= 0;
3138 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3142 bdrv_init_with_whitelist();
3146 /* first pass of option parsing */
3148 while (optind
< argc
) {
3149 if (argv
[optind
][0] != '-') {
3153 const QEMUOption
*popt
;
3155 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3156 switch (popt
->index
) {
3157 case QEMU_OPTION_nodefconfig
:
3160 case QEMU_OPTION_nouserconfig
:
3169 ret
= qemu_read_default_config_files(userconfig
);
3175 /* second pass of option parsing */
3180 if (argv
[optind
][0] != '-') {
3181 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3183 const QEMUOption
*popt
;
3185 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3186 if (!(popt
->arch_mask
& arch_type
)) {
3187 error_report("Option not supported for this target");
3190 switch(popt
->index
) {
3191 case QEMU_OPTION_no_kvm_irqchip
: {
3192 olist
= qemu_find_opts("machine");
3193 qemu_opts_parse_noisily(olist
, "kernel_irqchip=off", false);
3196 case QEMU_OPTION_cpu
:
3197 /* hw initialization will check this */
3200 case QEMU_OPTION_hda
:
3204 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3206 snprintf(buf
, sizeof(buf
),
3207 "%s,cyls=%d,heads=%d,secs=%d%s",
3208 HD_OPTS
, cyls
, heads
, secs
,
3209 translation
== BIOS_ATA_TRANSLATION_LBA
?
3211 translation
== BIOS_ATA_TRANSLATION_NONE
?
3212 ",trans=none" : "");
3213 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3216 case QEMU_OPTION_hdb
:
3217 case QEMU_OPTION_hdc
:
3218 case QEMU_OPTION_hdd
:
3219 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3222 case QEMU_OPTION_drive
:
3223 if (drive_def(optarg
) == NULL
) {
3227 case QEMU_OPTION_set
:
3228 if (qemu_set_option(optarg
) != 0)
3231 case QEMU_OPTION_global
:
3232 if (qemu_global_option(optarg
) != 0)
3235 case QEMU_OPTION_mtdblock
:
3236 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3238 case QEMU_OPTION_sd
:
3239 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3241 case QEMU_OPTION_pflash
:
3242 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3244 case QEMU_OPTION_snapshot
:
3247 case QEMU_OPTION_hdachs
:
3251 cyls
= strtol(p
, (char **)&p
, 0);
3252 if (cyls
< 1 || cyls
> 16383)
3257 heads
= strtol(p
, (char **)&p
, 0);
3258 if (heads
< 1 || heads
> 16)
3263 secs
= strtol(p
, (char **)&p
, 0);
3264 if (secs
< 1 || secs
> 63)
3268 if (!strcmp(p
, "large")) {
3269 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3270 } else if (!strcmp(p
, "rechs")) {
3271 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3272 } else if (!strcmp(p
, "none")) {
3273 translation
= BIOS_ATA_TRANSLATION_NONE
;
3274 } else if (!strcmp(p
, "lba")) {
3275 translation
= BIOS_ATA_TRANSLATION_LBA
;
3276 } else if (!strcmp(p
, "auto")) {
3277 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3281 } else if (*p
!= '\0') {
3283 error_report("invalid physical CHS format");
3286 if (hda_opts
!= NULL
) {
3287 qemu_opt_set_number(hda_opts
, "cyls", cyls
,
3289 qemu_opt_set_number(hda_opts
, "heads", heads
,
3291 qemu_opt_set_number(hda_opts
, "secs", secs
,
3293 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3294 qemu_opt_set(hda_opts
, "trans", "large",
3296 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3297 qemu_opt_set(hda_opts
, "trans", "rechs",
3299 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3300 qemu_opt_set(hda_opts
, "trans", "lba",
3302 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3303 qemu_opt_set(hda_opts
, "trans", "none",
3309 case QEMU_OPTION_numa
:
3310 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
3316 case QEMU_OPTION_display
:
3317 display_type
= select_display(optarg
);
3319 case QEMU_OPTION_nographic
:
3320 olist
= qemu_find_opts("machine");
3321 qemu_opts_parse_noisily(olist
, "graphics=off", false);
3323 display_type
= DT_NONE
;
3325 case QEMU_OPTION_curses
:
3326 #ifdef CONFIG_CURSES
3327 display_type
= DT_CURSES
;
3329 error_report("curses support is disabled");
3333 case QEMU_OPTION_portrait
:
3334 graphic_rotate
= 90;
3336 case QEMU_OPTION_rotate
:
3337 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3338 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3339 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3340 error_report("only 90, 180, 270 deg rotation is available");
3344 case QEMU_OPTION_kernel
:
3345 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
,
3348 case QEMU_OPTION_initrd
:
3349 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
,
3352 case QEMU_OPTION_append
:
3353 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
,
3356 case QEMU_OPTION_dtb
:
3357 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
,
3360 case QEMU_OPTION_cdrom
:
3361 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3363 case QEMU_OPTION_boot
:
3364 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
3370 case QEMU_OPTION_fda
:
3371 case QEMU_OPTION_fdb
:
3372 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3375 case QEMU_OPTION_no_fd_bootchk
:
3378 case QEMU_OPTION_netdev
:
3380 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3384 case QEMU_OPTION_net
:
3386 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3390 #ifdef CONFIG_LIBISCSI
3391 case QEMU_OPTION_iscsi
:
3392 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
3400 case QEMU_OPTION_tftp
:
3401 error_report("The -tftp option is deprecated. "
3402 "Please use '-netdev user,tftp=...' instead.");
3403 legacy_tftp_prefix
= optarg
;
3405 case QEMU_OPTION_bootp
:
3406 error_report("The -bootp option is deprecated. "
3407 "Please use '-netdev user,bootfile=...' instead.");
3408 legacy_bootp_filename
= optarg
;
3410 case QEMU_OPTION_redir
:
3411 error_report("The -redir option is deprecated. "
3412 "Please use '-netdev user,hostfwd=...' instead.");
3413 if (net_slirp_redir(optarg
) < 0)
3417 case QEMU_OPTION_bt
:
3418 add_device_config(DEV_BT
, optarg
);
3420 case QEMU_OPTION_audio_help
:
3424 case QEMU_OPTION_soundhw
:
3425 select_soundhw (optarg
);
3430 case QEMU_OPTION_version
:
3435 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
3442 case QEMU_OPTION_tpmdev
:
3443 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3448 case QEMU_OPTION_mempath
:
3451 case QEMU_OPTION_mem_prealloc
:
3460 case QEMU_OPTION_DFILTER
:
3461 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
3464 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3466 case QEMU_OPTION_gdb
:
3467 add_device_config(DEV_GDB
, optarg
);
3470 if (is_help_option(optarg
)) {
3471 list_data_dirs
= true;
3472 } else if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3473 data_dir
[data_dir_idx
++] = optarg
;
3476 case QEMU_OPTION_bios
:
3477 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
,
3480 case QEMU_OPTION_singlestep
:
3487 keyboard_layout
= optarg
;
3489 case QEMU_OPTION_localtime
:
3492 case QEMU_OPTION_vga
:
3501 w
= strtol(p
, (char **)&p
, 10);
3504 error_report("invalid resolution or depth");
3510 h
= strtol(p
, (char **)&p
, 10);
3515 depth
= strtol(p
, (char **)&p
, 10);
3516 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3517 depth
!= 24 && depth
!= 32)
3519 } else if (*p
== '\0') {
3520 depth
= graphic_depth
;
3527 graphic_depth
= depth
;
3530 case QEMU_OPTION_echr
:
3533 term_escape_char
= strtol(optarg
, &r
, 0);
3535 printf("Bad argument to echr\n");
3538 case QEMU_OPTION_monitor
:
3539 default_monitor
= 0;
3540 if (strncmp(optarg
, "none", 4)) {
3541 monitor_parse(optarg
, "readline", false);
3544 case QEMU_OPTION_qmp
:
3545 monitor_parse(optarg
, "control", false);
3546 default_monitor
= 0;
3548 case QEMU_OPTION_qmp_pretty
:
3549 monitor_parse(optarg
, "control", true);
3550 default_monitor
= 0;
3552 case QEMU_OPTION_mon
:
3553 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3558 default_monitor
= 0;
3560 case QEMU_OPTION_chardev
:
3561 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3567 case QEMU_OPTION_fsdev
:
3568 olist
= qemu_find_opts("fsdev");
3570 error_report("fsdev support is disabled");
3573 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3578 case QEMU_OPTION_virtfs
: {
3581 const char *writeout
, *sock_fd
, *socket
;
3583 olist
= qemu_find_opts("virtfs");
3585 error_report("virtfs support is disabled");
3588 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3593 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3594 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3595 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3598 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3599 qemu_opt_get(opts
, "mount_tag"),
3602 error_report("duplicate fsdev id: %s",
3603 qemu_opt_get(opts
, "mount_tag"));
3607 writeout
= qemu_opt_get(opts
, "writeout");
3609 #ifdef CONFIG_SYNC_FILE_RANGE
3610 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3612 error_report("writeout=immediate not supported "
3613 "on this platform");
3617 qemu_opt_set(fsdev
, "fsdriver",
3618 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3619 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"),
3621 qemu_opt_set(fsdev
, "security_model",
3622 qemu_opt_get(opts
, "security_model"),
3624 socket
= qemu_opt_get(opts
, "socket");
3626 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3628 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3630 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3633 qemu_opt_set_bool(fsdev
, "readonly",
3634 qemu_opt_get_bool(opts
, "readonly", 0),
3636 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3638 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3639 qemu_opt_set(device
, "fsdev",
3640 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3641 qemu_opt_set(device
, "mount_tag",
3642 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3645 case QEMU_OPTION_virtfs_synth
: {
3649 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3652 error_report("duplicate option: %s", "virtfs_synth");
3655 qemu_opt_set(fsdev
, "fsdriver", "synth", &error_abort
);
3657 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3659 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3660 qemu_opt_set(device
, "fsdev", "v_synth", &error_abort
);
3661 qemu_opt_set(device
, "mount_tag", "v_synth", &error_abort
);
3664 case QEMU_OPTION_serial
:
3665 add_device_config(DEV_SERIAL
, optarg
);
3667 if (strncmp(optarg
, "mon:", 4) == 0) {
3668 default_monitor
= 0;
3671 case QEMU_OPTION_watchdog
:
3673 error_report("only one watchdog option may be given");
3678 case QEMU_OPTION_watchdog_action
:
3679 if (select_watchdog_action(optarg
) == -1) {
3680 error_report("unknown -watchdog-action parameter");
3684 case QEMU_OPTION_virtiocon
:
3685 add_device_config(DEV_VIRTCON
, optarg
);
3686 default_virtcon
= 0;
3687 if (strncmp(optarg
, "mon:", 4) == 0) {
3688 default_monitor
= 0;
3691 case QEMU_OPTION_parallel
:
3692 add_device_config(DEV_PARALLEL
, optarg
);
3693 default_parallel
= 0;
3694 if (strncmp(optarg
, "mon:", 4) == 0) {
3695 default_monitor
= 0;
3698 case QEMU_OPTION_debugcon
:
3699 add_device_config(DEV_DEBUGCON
, optarg
);
3701 case QEMU_OPTION_loadvm
:
3704 case QEMU_OPTION_full_screen
:
3707 case QEMU_OPTION_no_frame
:
3710 case QEMU_OPTION_alt_grab
:
3713 case QEMU_OPTION_ctrl_grab
:
3716 case QEMU_OPTION_no_quit
:
3719 case QEMU_OPTION_sdl
:
3721 display_type
= DT_SDL
;
3724 error_report("SDL support is disabled");
3727 case QEMU_OPTION_pidfile
:
3730 case QEMU_OPTION_win2k_hack
:
3731 win2k_install_hack
= 1;
3733 case QEMU_OPTION_rtc_td_hack
: {
3734 static GlobalProperty slew_lost_ticks
= {
3735 .driver
= "mc146818rtc",
3736 .property
= "lost_tick_policy",
3740 qdev_prop_register_global(&slew_lost_ticks
);
3743 case QEMU_OPTION_acpitable
:
3744 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3749 do_acpitable_option(opts
);
3751 case QEMU_OPTION_smbios
:
3752 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3757 do_smbios_option(opts
);
3759 case QEMU_OPTION_fwcfg
:
3760 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3766 case QEMU_OPTION_enable_kvm
:
3767 olist
= qemu_find_opts("machine");
3768 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3770 case QEMU_OPTION_enable_hax
:
3771 olist
= qemu_find_opts("machine");
3772 qemu_opts_parse_noisily(olist
, "accel=hax", false);
3775 case QEMU_OPTION_machine
:
3776 olist
= qemu_find_opts("machine");
3777 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3782 case QEMU_OPTION_no_kvm
:
3783 olist
= qemu_find_opts("machine");
3784 qemu_opts_parse_noisily(olist
, "accel=tcg", false);
3786 case QEMU_OPTION_no_kvm_pit
: {
3787 error_report("warning: ignoring deprecated option");
3790 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3791 static GlobalProperty kvm_pit_lost_tick_policy
= {
3792 .driver
= "kvm-pit",
3793 .property
= "lost_tick_policy",
3797 error_report("warning: deprecated, replaced by "
3798 "-global kvm-pit.lost_tick_policy=discard");
3799 qdev_prop_register_global(&kvm_pit_lost_tick_policy
);
3802 case QEMU_OPTION_usb
:
3803 olist
= qemu_find_opts("machine");
3804 qemu_opts_parse_noisily(olist
, "usb=on", false);
3806 case QEMU_OPTION_usbdevice
:
3807 olist
= qemu_find_opts("machine");
3808 qemu_opts_parse_noisily(olist
, "usb=on", false);
3809 add_device_config(DEV_USB
, optarg
);
3811 case QEMU_OPTION_device
:
3812 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3817 case QEMU_OPTION_smp
:
3818 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3823 case QEMU_OPTION_vnc
:
3824 vnc_parse(optarg
, &error_fatal
);
3826 case QEMU_OPTION_no_acpi
:
3829 case QEMU_OPTION_no_hpet
:
3832 case QEMU_OPTION_balloon
:
3833 if (balloon_parse(optarg
) < 0) {
3834 error_report("unknown -balloon argument %s", optarg
);
3838 case QEMU_OPTION_no_reboot
:
3841 case QEMU_OPTION_no_shutdown
:
3844 case QEMU_OPTION_show_cursor
:
3847 case QEMU_OPTION_uuid
:
3848 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3849 error_report("failed to parse UUID string: wrong format");
3852 qemu_uuid_set
= true;
3854 case QEMU_OPTION_option_rom
:
3855 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3856 error_report("too many option ROMs");
3859 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3864 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3865 option_rom
[nb_option_roms
].bootindex
=
3866 qemu_opt_get_number(opts
, "bootindex", -1);
3867 if (!option_rom
[nb_option_roms
].name
) {
3868 error_report("Option ROM file is not specified");
3873 case QEMU_OPTION_semihosting
:
3874 semihosting
.enabled
= true;
3875 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3877 case QEMU_OPTION_semihosting_config
:
3878 semihosting
.enabled
= true;
3879 opts
= qemu_opts_parse_noisily(qemu_find_opts("semihosting-config"),
3882 semihosting
.enabled
= qemu_opt_get_bool(opts
, "enable",
3884 const char *target
= qemu_opt_get(opts
, "target");
3885 if (target
!= NULL
) {
3886 if (strcmp("native", target
) == 0) {
3887 semihosting
.target
= SEMIHOSTING_TARGET_NATIVE
;
3888 } else if (strcmp("gdb", target
) == 0) {
3889 semihosting
.target
= SEMIHOSTING_TARGET_GDB
;
3890 } else if (strcmp("auto", target
) == 0) {
3891 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3893 error_report("unsupported semihosting-config %s",
3898 semihosting
.target
= SEMIHOSTING_TARGET_AUTO
;
3900 /* Set semihosting argument count and vector */
3901 qemu_opt_foreach(opts
, add_semihosting_arg
,
3902 &semihosting
, NULL
);
3904 error_report("unsupported semihosting-config %s", optarg
);
3908 case QEMU_OPTION_tdf
:
3909 error_report("warning: ignoring deprecated option");
3911 case QEMU_OPTION_name
:
3912 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3918 case QEMU_OPTION_prom_env
:
3919 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3920 error_report("too many prom variables");
3923 prom_envs
[nb_prom_envs
] = optarg
;
3926 case QEMU_OPTION_old_param
:
3929 case QEMU_OPTION_clock
:
3930 /* Clock options no longer exist. Keep this option for
3931 * backward compatibility.
3934 case QEMU_OPTION_startdate
:
3935 configure_rtc_date_offset(optarg
, 1);
3937 case QEMU_OPTION_rtc
:
3938 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3943 configure_rtc(opts
);
3945 case QEMU_OPTION_tb_size
:
3946 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3947 if (tcg_tb_size
< 0) {
3951 case QEMU_OPTION_icount
:
3952 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3958 case QEMU_OPTION_incoming
:
3960 runstate_set(RUN_STATE_INMIGRATE
);
3964 case QEMU_OPTION_nodefaults
:
3967 case QEMU_OPTION_xen_domid
:
3968 if (!(xen_available())) {
3969 error_report("Option not supported for this target");
3972 xen_domid
= atoi(optarg
);
3974 case QEMU_OPTION_xen_create
:
3975 if (!(xen_available())) {
3976 error_report("Option not supported for this target");
3979 xen_mode
= XEN_CREATE
;
3981 case QEMU_OPTION_xen_attach
:
3982 if (!(xen_available())) {
3983 error_report("Option not supported for this target");
3986 xen_mode
= XEN_ATTACH
;
3988 case QEMU_OPTION_trace
:
3990 trace_file
= trace_opt_parse(optarg
);
3992 case QEMU_OPTION_trace_unassigned
:
3993 trace_unassigned
= true;
3995 case QEMU_OPTION_readconfig
:
3997 int ret
= qemu_read_config_file(optarg
);
3999 error_report("read config %s: %s", optarg
,
4005 case QEMU_OPTION_spice
:
4006 olist
= qemu_find_opts("spice");
4008 error_report("spice support is disabled");
4011 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
4017 case QEMU_OPTION_writeconfig
:
4020 if (strcmp(optarg
, "-") == 0) {
4023 fp
= fopen(optarg
, "w");
4025 error_report("open %s: %s", optarg
,
4030 qemu_config_write(fp
);
4036 case QEMU_OPTION_qtest
:
4037 qtest_chrdev
= optarg
;
4039 case QEMU_OPTION_qtest_log
:
4042 case QEMU_OPTION_sandbox
:
4043 opts
= qemu_opts_parse_noisily(qemu_find_opts("sandbox"),
4049 case QEMU_OPTION_add_fd
:
4051 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
4057 error_report("File descriptor passing is disabled on this "
4062 case QEMU_OPTION_object
:
4063 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
4069 case QEMU_OPTION_realtime
:
4070 opts
= qemu_opts_parse_noisily(qemu_find_opts("realtime"),
4075 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
4077 case QEMU_OPTION_msg
:
4078 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
4083 configure_msg(opts
);
4085 case QEMU_OPTION_dump_vmstate
:
4086 if (vmstate_dump_file
) {
4087 error_report("only one '-dump-vmstate' "
4088 "option may be given");
4091 vmstate_dump_file
= fopen(optarg
, "w");
4092 if (vmstate_dump_file
== NULL
) {
4093 error_report("open %s: %s", optarg
, strerror(errno
));
4098 os_parse_cmd_args(popt
->index
, optarg
);
4103 * Clear error location left behind by the loop.
4104 * Best done right after the loop. Do not insert code here!
4108 replay_configure(icount_opts
);
4110 machine_class
= select_machine();
4112 set_memory_options(&ram_slots
, &maxram_size
, machine_class
);
4116 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4117 error_report("could not acquire pid file: %s", strerror(errno
));
4121 if (qemu_init_main_loop(&main_loop_err
)) {
4122 error_report_err(main_loop_err
);
4126 if (qemu_opts_foreach(qemu_find_opts("sandbox"),
4127 parse_sandbox
, NULL
, NULL
)) {
4131 if (qemu_opts_foreach(qemu_find_opts("name"),
4132 parse_name
, NULL
, NULL
)) {
4137 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4138 parse_add_fd
, NULL
, NULL
)) {
4142 if (qemu_opts_foreach(qemu_find_opts("add-fd"),
4143 cleanup_add_fd
, NULL
, NULL
)) {
4148 current_machine
= MACHINE(object_new(object_class_get_name(
4149 OBJECT_CLASS(machine_class
))));
4150 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
4153 object_property_add_child(object_get_root(), "machine",
4154 OBJECT(current_machine
), &error_abort
);
4156 if (machine_class
->minimum_page_bits
) {
4157 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
4158 /* This would be a board error: specifying a minimum smaller than
4159 * a target's compile-time fixed setting.
4161 g_assert_not_reached();
4165 cpu_exec_init_all();
4167 if (machine_class
->hw_version
) {
4168 qemu_set_hw_version(machine_class
->hw_version
);
4171 if (cpu_model
&& is_help_option(cpu_model
)) {
4172 list_cpus(stdout
, &fprintf
, cpu_model
);
4176 if (!trace_init_backends()) {
4179 trace_init_file(trace_file
);
4181 /* Open the logfile at this point and set the log mask if necessary.
4184 qemu_set_log_filename(log_file
, &error_fatal
);
4189 mask
= qemu_str_to_log_mask(log_mask
);
4191 qemu_print_log_usage(stdout
);
4199 /* If no data_dir is specified then try to find it relative to the
4201 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4202 data_dir
[data_dir_idx
] = os_find_datadir();
4203 if (data_dir
[data_dir_idx
] != NULL
) {
4207 /* If all else fails use the install path specified when building. */
4208 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4209 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4212 /* -L help lists the data directories and exits. */
4213 if (list_data_dirs
) {
4214 for (i
= 0; i
< data_dir_idx
; i
++) {
4215 printf("%s\n", data_dir
[i
]);
4220 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4222 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4223 if (max_cpus
> machine_class
->max_cpus
) {
4224 error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
4225 "supported by machine '%s' (%d)", max_cpus
,
4226 machine_class
->name
, machine_class
->max_cpus
);
4231 * Get the default machine options from the machine if it is not already
4232 * specified either by the configuration file or by the command line.
4234 if (machine_class
->default_machine_opts
) {
4235 qemu_opts_set_defaults(qemu_find_opts("machine"),
4236 machine_class
->default_machine_opts
, 0);
4239 qemu_opts_foreach(qemu_find_opts("device"),
4240 default_driver_check
, NULL
, NULL
);
4241 qemu_opts_foreach(qemu_find_opts("global"),
4242 default_driver_check
, NULL
, NULL
);
4244 if (!vga_model
&& !default_vga
) {
4245 vga_interface_type
= VGA_DEVICE
;
4247 if (!has_defaults
|| machine_class
->no_serial
) {
4250 if (!has_defaults
|| machine_class
->no_parallel
) {
4251 default_parallel
= 0;
4253 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4254 default_virtcon
= 0;
4256 if (!has_defaults
|| !machine_class
->use_sclp
) {
4259 if (!has_defaults
|| machine_class
->no_floppy
) {
4262 if (!has_defaults
|| machine_class
->no_cdrom
) {
4265 if (!has_defaults
|| machine_class
->no_sdcard
) {
4268 if (!has_defaults
) {
4269 default_monitor
= 0;
4274 if (is_daemonized()) {
4275 /* According to documentation and historically, -nographic redirects
4276 * serial port, parallel port and monitor to stdio, which does not work
4277 * with -daemonize. We can redirect these to null instead, but since
4278 * -nographic is legacy, let's just error out.
4279 * We disallow -nographic only if all other ports are not redirected
4280 * explicitly, to not break existing legacy setups which uses
4281 * -nographic _and_ redirects all ports explicitly - this is valid
4282 * usage, -nographic is just a no-op in this case.
4285 && (default_parallel
|| default_serial
4286 || default_monitor
|| default_virtcon
)) {
4287 error_report("-nographic cannot be used with -daemonize");
4290 #ifdef CONFIG_CURSES
4291 if (display_type
== DT_CURSES
) {
4292 error_report("curses display cannot be used with -daemonize");
4299 if (default_parallel
)
4300 add_device_config(DEV_PARALLEL
, "null");
4301 if (default_serial
&& default_monitor
) {
4302 add_device_config(DEV_SERIAL
, "mon:stdio");
4303 } else if (default_virtcon
&& default_monitor
) {
4304 add_device_config(DEV_VIRTCON
, "mon:stdio");
4305 } else if (default_sclp
&& default_monitor
) {
4306 add_device_config(DEV_SCLP
, "mon:stdio");
4309 add_device_config(DEV_SERIAL
, "stdio");
4310 if (default_virtcon
)
4311 add_device_config(DEV_VIRTCON
, "stdio");
4313 add_device_config(DEV_SCLP
, "stdio");
4315 if (default_monitor
)
4316 monitor_parse("stdio", "readline", false);
4320 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4321 if (default_parallel
)
4322 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4323 if (default_monitor
)
4324 monitor_parse("vc:80Cx24C", "readline", false);
4325 if (default_virtcon
)
4326 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4328 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4332 #if defined(CONFIG_VNC)
4333 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
4337 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4338 #if defined(CONFIG_GTK)
4339 display_type
= DT_GTK
;
4340 #elif defined(CONFIG_SDL)
4341 display_type
= DT_SDL
;
4342 #elif defined(CONFIG_COCOA)
4343 display_type
= DT_COCOA
;
4344 #elif defined(CONFIG_VNC)
4345 vnc_parse("localhost:0,to=99,id=default", &error_abort
);
4347 display_type
= DT_NONE
;
4351 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4352 error_report("-no-frame, -alt-grab and -ctrl-grab are only valid "
4353 "for SDL, ignoring option");
4355 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4356 error_report("-no-quit is only valid for GTK and SDL, "
4360 if (display_type
== DT_GTK
) {
4361 early_gtk_display_init(request_opengl
);
4364 if (display_type
== DT_SDL
) {
4365 sdl_display_early_init(request_opengl
);
4368 if (request_opengl
== 1 && display_opengl
== 0) {
4369 #if defined(CONFIG_OPENGL)
4370 error_report("OpenGL is not supported by the display");
4372 error_report("OpenGL support is disabled");
4380 if (qemu_opts_foreach(qemu_find_opts("object"),
4381 user_creatable_add_opts_foreach
,
4382 object_create_initial
, NULL
)) {
4386 if (qemu_opts_foreach(qemu_find_opts("chardev"),
4387 chardev_init_func
, NULL
, NULL
)) {
4391 #ifdef CONFIG_VIRTFS
4392 if (qemu_opts_foreach(qemu_find_opts("fsdev"),
4393 fsdev_init_func
, NULL
, NULL
)) {
4398 if (qemu_opts_foreach(qemu_find_opts("device"),
4399 device_help_func
, NULL
, NULL
)) {
4403 machine_opts
= qemu_get_machine_opts();
4404 if (qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
4406 object_unref(OBJECT(current_machine
));
4410 configure_accelerator(current_machine
);
4413 qtest_init(qtest_chrdev
, qtest_log
, &error_fatal
);
4416 machine_opts
= qemu_get_machine_opts();
4417 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4418 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4419 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4420 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4422 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4424 boot_order
= qemu_opt_get(opts
, "order");
4426 validate_bootdevices(boot_order
, &error_fatal
);
4429 boot_once
= qemu_opt_get(opts
, "once");
4431 validate_bootdevices(boot_once
, &error_fatal
);
4434 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4435 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4439 boot_order
= machine_class
->default_boot_order
;
4442 if (!kernel_cmdline
) {
4443 kernel_cmdline
= "";
4444 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4447 linux_boot
= (kernel_filename
!= NULL
);
4449 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4450 error_report("-append only allowed with -kernel option");
4454 if (!linux_boot
&& initrd_filename
!= NULL
) {
4455 error_report("-initrd only allowed with -kernel option");
4459 if (semihosting_enabled() && !semihosting_get_argc() && kernel_filename
) {
4460 /* fall back to the -kernel/-append */
4461 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
4464 os_set_line_buffering();
4466 /* spice needs the timers to be initialized by this point */
4471 if (!tcg_enabled()) {
4472 error_report("-icount is not allowed with hardware virtualization");
4475 configure_icount(icount_opts
, &error_abort
);
4476 qemu_opts_del(icount_opts
);
4480 QemuOptsList
*net
= qemu_find_opts("net");
4481 qemu_opts_set(net
, NULL
, "type", "nic", &error_abort
);
4483 qemu_opts_set(net
, NULL
, "type", "user", &error_abort
);
4489 if (net_init_clients() < 0) {
4493 if (qemu_opts_foreach(qemu_find_opts("object"),
4494 user_creatable_add_opts_foreach
,
4495 object_create_delayed
, NULL
)) {
4500 if (tpm_init() < 0) {
4505 /* init the bluetooth world */
4506 if (foreach_device_config(DEV_BT
, bt_parse
))
4509 if (!xen_enabled()) {
4510 /* On 32-bit hosts, QEMU is limited by virtual address space */
4511 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4512 error_report("at most 2047 MB RAM can be simulated");
4520 /* If the currently selected machine wishes to override the units-per-bus
4521 * property of its default HBA interface type, do so now. */
4522 if (machine_class
->units_per_default_bus
) {
4523 override_max_devs(machine_class
->block_default_type
,
4524 machine_class
->units_per_default_bus
);
4527 /* open the virtual block devices */
4528 if (snapshot
|| replay_mode
!= REPLAY_MODE_NONE
) {
4529 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
4532 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4533 &machine_class
->block_default_type
, NULL
)) {
4537 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4539 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4540 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4542 parse_numa_opts(machine_class
);
4544 if (qemu_opts_foreach(qemu_find_opts("mon"),
4545 mon_init_func
, NULL
, NULL
)) {
4549 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4551 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4553 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4555 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4558 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4561 /* If no default VGA is requested, the default is "none". */
4563 if (machine_class
->default_display
) {
4564 vga_model
= machine_class
->default_display
;
4565 } else if (vga_interface_available(VGA_CIRRUS
)) {
4566 vga_model
= "cirrus";
4567 } else if (vga_interface_available(VGA_STD
)) {
4572 select_vgahw(vga_model
);
4576 i
= select_watchdog(watchdog
);
4578 exit (i
== 1 ? 1 : 0);
4581 machine_register_compat_props(current_machine
);
4583 qemu_opts_foreach(qemu_find_opts("global"),
4584 global_init_func
, NULL
, NULL
);
4586 /* This checkpoint is required by replay to separate prior clock
4587 reading from the other reads, because timer polling functions query
4588 clock values from the log. */
4589 replay_checkpoint(CHECKPOINT_INIT
);
4590 qdev_machine_init();
4592 current_machine
->ram_size
= ram_size
;
4593 current_machine
->maxram_size
= maxram_size
;
4594 current_machine
->ram_slots
= ram_slots
;
4595 current_machine
->boot_order
= boot_order
;
4596 current_machine
->cpu_model
= cpu_model
;
4598 machine_class
->init(current_machine
);
4604 cpu_synchronize_all_post_init();
4606 numa_post_machine_init();
4608 if (hax_enabled()) {
4612 if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
4613 parse_fw_cfg
, fw_cfg_find(), NULL
) != 0) {
4617 /* init USB devices */
4618 if (machine_usb(current_machine
)) {
4619 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4623 /* Check if IGD GFX passthrough. */
4626 /* init generic devices */
4627 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
4628 if (qemu_opts_foreach(qemu_find_opts("device"),
4629 device_init_func
, NULL
, NULL
)) {
4632 rom_reset_order_override();
4634 /* Did we create any drives that we failed to create a device for? */
4635 drive_check_orphaned();
4637 /* Don't warn about the default network setup that you get if
4638 * no command line -net or -netdev options are specified. There
4639 * are two cases that we would otherwise complain about:
4640 * (1) board doesn't support a NIC but the implicit "-net nic"
4642 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
4643 * sets up a nic that isn't connected to anything.
4646 net_check_clients();
4651 qemu_boot_set(boot_once
, &error_fatal
);
4652 qemu_register_reset(restore_boot_order
, g_strdup(boot_order
));
4655 ds
= init_displaystate();
4657 /* init local displays */
4658 switch (display_type
) {
4660 curses_display_init(ds
, full_screen
);
4663 sdl_display_init(ds
, full_screen
, no_frame
);
4666 cocoa_display_init(ds
, full_screen
);
4669 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4675 /* must be after terminal init, SDL library changes signal handlers */
4676 os_setup_signal_handling();
4678 /* init remote displays */
4680 qemu_opts_foreach(qemu_find_opts("vnc"),
4681 vnc_init_func
, NULL
, NULL
);
4685 qemu_spice_display_init();
4688 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4692 qdev_machine_creation_done();
4694 /* TODO: once all bus devices are qdevified, this should be done
4695 * when bus is created by qdev.c */
4696 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4697 qemu_run_machine_init_done_notifiers();
4699 if (rom_check_and_register_reset() != 0) {
4700 error_report("rom check and register reset failed");
4706 /* This checkpoint is required by replay to separate prior clock
4707 reading from the other reads, because timer polling functions query
4708 clock values from the log. */
4709 replay_checkpoint(CHECKPOINT_RESET
);
4710 qemu_system_reset(VMRESET_SILENT
);
4711 register_global_state();
4713 if (load_vmstate(loadvm
) < 0) {
4718 qdev_prop_check_globals();
4719 if (vmstate_dump_file
) {
4721 dump_vmstate_json_to_file(vmstate_dump_file
);
4726 Error
*local_err
= NULL
;
4727 qemu_start_incoming_migration(incoming
, &local_err
);
4729 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
4732 } else if (autostart
) {
4739 replay_disable_events();
4740 iothread_stop_all();
4746 /* vhost-user must be cleaned up before chardevs. */