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
31 #include "config-host.h"
34 #include "sysemu/seccomp.h"
37 #if defined(CONFIG_VDE)
38 #include <libvdeplug.h>
42 #if defined(__APPLE__) || defined(main)
44 int qemu_main(int argc
, char **argv
);
45 int main(int argc
, char **argv
)
47 return qemu_main(argc
, argv
);
50 #define main qemu_main
52 #endif /* CONFIG_SDL */
56 #define main qemu_main
57 #endif /* CONFIG_COCOA */
61 #include "qemu/sockets.h"
63 #include "hw/boards.h"
65 #include "hw/pcmcia.h"
66 #include "hw/i386/pc.h"
67 #include "hw/isa/isa.h"
69 #include "sysemu/watchdog.h"
70 #include "hw/i386/smbios.h"
71 #include "hw/xen/xen.h"
73 #include "hw/loader.h"
74 #include "monitor/qdev.h"
75 #include "sysemu/bt.h"
77 #include "net/slirp.h"
78 #include "monitor/monitor.h"
79 #include "ui/console.h"
80 #include "sysemu/sysemu.h"
81 #include "exec/gdbstub.h"
82 #include "qemu/timer.h"
83 #include "sysemu/char.h"
84 #include "qemu/bitmap.h"
85 #include "sysemu/blockdev.h"
86 #include "hw/block/block.h"
87 #include "migration/block.h"
88 #include "sysemu/tpm.h"
89 #include "sysemu/dma.h"
90 #include "audio/audio.h"
91 #include "migration/migration.h"
92 #include "sysemu/kvm.h"
93 #include "qapi/qmp/qjson.h"
94 #include "qemu/option.h"
95 #include "qemu/config-file.h"
96 #include "qemu-options.h"
97 #include "qmp-commands.h"
98 #include "qemu/main-loop.h"
100 #include "fsdev/qemu-fsdev.h"
102 #include "sysemu/qtest.h"
104 #include "disas/disas.h"
107 #include "slirp/libslirp.h"
110 #include "trace/control.h"
111 #include "qemu/queue.h"
112 #include "sysemu/cpus.h"
113 #include "sysemu/arch_init.h"
114 #include "qemu/osdep.h"
116 #include "ui/qemu-spice.h"
117 #include "qapi/string-input-visitor.h"
118 #include "qapi/opts-visitor.h"
119 #include "qom/object_interfaces.h"
120 #include "qapi-event.h"
122 #define DEFAULT_RAM_SIZE 128
124 #define MAX_VIRTIO_CONSOLES 1
125 #define MAX_SCLP_CONSOLES 1
127 static const char *data_dir
[16];
128 static int data_dir_idx
;
129 const char *bios_name
= NULL
;
130 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
131 DisplayType display_type
= DT_DEFAULT
;
132 static int display_remote
;
133 const char* keyboard_layout
= NULL
;
135 const char *mem_path
= NULL
;
136 int mem_prealloc
= 0; /* force preallocation of physical target memory */
138 NICInfo nd_table
[MAX_NICS
];
140 static int rtc_utc
= 1;
141 static int rtc_date_offset
= -1; /* -1 means no change */
142 QEMUClockType rtc_clock
;
143 int vga_interface_type
= VGA_NONE
;
144 static int full_screen
= 0;
145 static int no_frame
= 0;
148 static bool grab_on_hover
;
150 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
151 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
152 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
153 CharDriverState
*sclp_hds
[MAX_SCLP_CONSOLES
];
154 int win2k_install_hack
= 0;
161 const char *vnc_display
;
163 int acpi_enabled
= 1;
166 static int no_reboot
;
169 int graphic_rotate
= 0;
170 const char *watchdog
;
171 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
173 int semihosting_enabled
= 0;
175 const char *qemu_name
;
178 unsigned int nb_prom_envs
= 0;
179 const char *prom_envs
[MAX_PROM_ENVS
];
181 static bool boot_strict
;
182 uint8_t *boot_splash_filedata
;
183 size_t boot_splash_filedata_size
;
184 uint8_t qemu_extra_params_fw
[2];
186 typedef struct FWBootEntry FWBootEntry
;
189 QTAILQ_ENTRY(FWBootEntry
) link
;
195 static QTAILQ_HEAD(, FWBootEntry
) fw_boot_order
=
196 QTAILQ_HEAD_INITIALIZER(fw_boot_order
);
200 NodeInfo numa_info
[MAX_NODES
];
202 uint8_t qemu_uuid
[16];
205 /* Trace unassigned memory or i/o accesses. */
206 bool trace_unassigned
;
208 static QEMUBootSetHandler
*boot_set_handler
;
209 static void *boot_set_opaque
;
211 static NotifierList exit_notifiers
=
212 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
214 static NotifierList machine_init_done_notifiers
=
215 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
217 static bool tcg_allowed
= true;
220 enum xen_mode xen_mode
= XEN_EMULATE
;
221 static int tcg_tb_size
;
223 static int has_defaults
= 1;
224 static int default_serial
= 1;
225 static int default_parallel
= 1;
226 static int default_virtcon
= 1;
227 static int default_sclp
= 1;
228 static int default_monitor
= 1;
229 static int default_floppy
= 1;
230 static int default_cdrom
= 1;
231 static int default_sdcard
= 1;
232 static int default_vga
= 1;
238 { .driver
= "isa-serial", .flag
= &default_serial
},
239 { .driver
= "isa-parallel", .flag
= &default_parallel
},
240 { .driver
= "isa-fdc", .flag
= &default_floppy
},
241 { .driver
= "ide-cd", .flag
= &default_cdrom
},
242 { .driver
= "ide-hd", .flag
= &default_cdrom
},
243 { .driver
= "ide-drive", .flag
= &default_cdrom
},
244 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
245 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
246 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
247 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
248 { .driver
= "VGA", .flag
= &default_vga
},
249 { .driver
= "isa-vga", .flag
= &default_vga
},
250 { .driver
= "cirrus-vga", .flag
= &default_vga
},
251 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
252 { .driver
= "vmware-svga", .flag
= &default_vga
},
253 { .driver
= "qxl-vga", .flag
= &default_vga
},
256 static QemuOptsList qemu_rtc_opts
= {
258 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
262 .type
= QEMU_OPT_STRING
,
265 .type
= QEMU_OPT_STRING
,
268 .type
= QEMU_OPT_STRING
,
270 { /* end of list */ }
274 static QemuOptsList qemu_sandbox_opts
= {
276 .implied_opt_name
= "enable",
277 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
281 .type
= QEMU_OPT_BOOL
,
283 { /* end of list */ }
287 static QemuOptsList qemu_trace_opts
= {
289 .implied_opt_name
= "trace",
290 .head
= QTAILQ_HEAD_INITIALIZER(qemu_trace_opts
.head
),
294 .type
= QEMU_OPT_STRING
,
297 .type
= QEMU_OPT_STRING
,
299 { /* end of list */ }
303 static QemuOptsList qemu_option_rom_opts
= {
304 .name
= "option-rom",
305 .implied_opt_name
= "romfile",
306 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
310 .type
= QEMU_OPT_NUMBER
,
313 .type
= QEMU_OPT_STRING
,
315 { /* end of list */ }
319 static QemuOptsList qemu_machine_opts
= {
321 .implied_opt_name
= "type",
323 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
327 .type
= QEMU_OPT_STRING
,
328 .help
= "emulated machine"
331 .type
= QEMU_OPT_STRING
,
332 .help
= "accelerator list",
334 .name
= "kernel_irqchip",
335 .type
= QEMU_OPT_BOOL
,
336 .help
= "use KVM in-kernel irqchip",
338 .name
= "kvm_shadow_mem",
339 .type
= QEMU_OPT_SIZE
,
340 .help
= "KVM shadow MMU size",
343 .type
= QEMU_OPT_STRING
,
344 .help
= "Linux kernel image file",
347 .type
= QEMU_OPT_STRING
,
348 .help
= "Linux initial ramdisk file",
351 .type
= QEMU_OPT_STRING
,
352 .help
= "Linux kernel command line",
355 .type
= QEMU_OPT_STRING
,
356 .help
= "Linux kernel device tree file",
359 .type
= QEMU_OPT_STRING
,
360 .help
= "Dump current dtb to a file and quit",
362 .name
= "phandle_start",
363 .type
= QEMU_OPT_NUMBER
,
364 .help
= "The first phandle ID we may generate dynamically",
366 .name
= "dt_compatible",
367 .type
= QEMU_OPT_STRING
,
368 .help
= "Overrides the \"compatible\" property of the dt root node",
370 .name
= "dump-guest-core",
371 .type
= QEMU_OPT_BOOL
,
372 .help
= "Include guest memory in a core dump",
375 .type
= QEMU_OPT_BOOL
,
376 .help
= "enable/disable memory merge support",
379 .type
= QEMU_OPT_BOOL
,
380 .help
= "Set on/off to enable/disable usb",
383 .type
= QEMU_OPT_STRING
,
384 .help
= "firmware image",
387 .type
= QEMU_OPT_STRING
,
388 .help
= "Specifies the KVM virtualization mode (HV, PR)",
390 .name
= PC_MACHINE_MAX_RAM_BELOW_4G
,
391 .type
= QEMU_OPT_SIZE
,
392 .help
= "maximum ram below the 4G boundary (32bit boundary)",
394 { /* End of list */ }
398 static QemuOptsList qemu_boot_opts
= {
400 .implied_opt_name
= "order",
402 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
406 .type
= QEMU_OPT_STRING
,
409 .type
= QEMU_OPT_STRING
,
412 .type
= QEMU_OPT_BOOL
,
415 .type
= QEMU_OPT_STRING
,
417 .name
= "splash-time",
418 .type
= QEMU_OPT_STRING
,
420 .name
= "reboot-timeout",
421 .type
= QEMU_OPT_STRING
,
424 .type
= QEMU_OPT_BOOL
,
430 static QemuOptsList qemu_add_fd_opts
= {
432 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
436 .type
= QEMU_OPT_NUMBER
,
437 .help
= "file descriptor of which a duplicate is added to fd set",
440 .type
= QEMU_OPT_NUMBER
,
441 .help
= "ID of the fd set to add fd to",
444 .type
= QEMU_OPT_STRING
,
445 .help
= "free-form string used to describe fd",
447 { /* end of list */ }
451 static QemuOptsList qemu_object_opts
= {
453 .implied_opt_name
= "qom-type",
454 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
460 static QemuOptsList qemu_tpmdev_opts
= {
462 .implied_opt_name
= "type",
463 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
465 /* options are defined in the TPM backends */
466 { /* end of list */ }
470 static QemuOptsList qemu_realtime_opts
= {
472 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
476 .type
= QEMU_OPT_BOOL
,
478 { /* end of list */ }
482 static QemuOptsList qemu_msg_opts
= {
484 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
488 .type
= QEMU_OPT_BOOL
,
490 { /* end of list */ }
494 static QemuOptsList qemu_name_opts
= {
496 .implied_opt_name
= "guest",
498 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
502 .type
= QEMU_OPT_STRING
,
503 .help
= "Sets the name of the guest.\n"
504 "This name will be displayed in the SDL window caption.\n"
505 "The name will also be used for the VNC server",
508 .type
= QEMU_OPT_STRING
,
509 .help
= "Sets the name of the QEMU process, as shown in top etc",
511 .name
= "debug-threads",
512 .type
= QEMU_OPT_BOOL
,
513 .help
= "When enabled, name the individual threads; defaults off.\n"
514 "NOTE: The thread names are for debugging and not a\n"
517 { /* End of list */ }
521 static QemuOptsList qemu_mem_opts
= {
523 .implied_opt_name
= "size",
524 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
529 .type
= QEMU_OPT_SIZE
,
533 .type
= QEMU_OPT_NUMBER
,
537 .type
= QEMU_OPT_SIZE
,
539 { /* end of list */ }
544 * Get machine options
546 * Returns: machine options (never null).
548 QemuOpts
*qemu_get_machine_opts(void)
550 return qemu_find_opts_singleton("machine");
553 const char *qemu_get_vm_name(void)
558 static void res_free(void)
560 if (boot_splash_filedata
!= NULL
) {
561 g_free(boot_splash_filedata
);
562 boot_splash_filedata
= NULL
;
566 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
568 const char *driver
= qemu_opt_get(opts
, "driver");
573 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
574 if (strcmp(default_list
[i
].driver
, driver
) != 0)
576 *(default_list
[i
].flag
) = 0;
581 /***********************************************************/
584 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
586 /* We use RUN_STATE_MAX but any invalid value will do */
587 static RunState vmstop_requested
= RUN_STATE_MAX
;
588 static QemuMutex vmstop_lock
;
593 } RunStateTransition
;
595 static const RunStateTransition runstate_transitions_def
[] = {
597 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
598 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
600 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
601 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
603 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
604 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
606 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
607 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
609 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
610 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
612 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
613 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
615 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
616 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
617 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
619 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
620 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
622 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
624 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
625 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
626 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
627 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
628 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
629 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
630 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
631 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
632 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
633 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
635 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
637 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
638 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
640 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
641 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
642 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
643 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
645 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
646 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
648 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
649 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
651 { RUN_STATE_MAX
, RUN_STATE_MAX
},
654 static bool runstate_valid_transitions
[RUN_STATE_MAX
][RUN_STATE_MAX
];
656 bool runstate_check(RunState state
)
658 return current_run_state
== state
;
661 static void runstate_init(void)
663 const RunStateTransition
*p
;
665 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
666 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE_MAX
; p
++) {
667 runstate_valid_transitions
[p
->from
][p
->to
] = true;
670 qemu_mutex_init(&vmstop_lock
);
673 /* This function will abort() on invalid state transitions */
674 void runstate_set(RunState new_state
)
676 assert(new_state
< RUN_STATE_MAX
);
678 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
679 fprintf(stderr
, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
680 RunState_lookup
[current_run_state
],
681 RunState_lookup
[new_state
]);
684 trace_runstate_set(new_state
);
685 current_run_state
= new_state
;
688 int runstate_is_running(void)
690 return runstate_check(RUN_STATE_RUNNING
);
693 bool runstate_needs_reset(void)
695 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
696 runstate_check(RUN_STATE_SHUTDOWN
);
699 StatusInfo
*qmp_query_status(Error
**errp
)
701 StatusInfo
*info
= g_malloc0(sizeof(*info
));
703 info
->running
= runstate_is_running();
704 info
->singlestep
= singlestep
;
705 info
->status
= current_run_state
;
710 static bool qemu_vmstop_requested(RunState
*r
)
712 qemu_mutex_lock(&vmstop_lock
);
713 *r
= vmstop_requested
;
714 vmstop_requested
= RUN_STATE_MAX
;
715 qemu_mutex_unlock(&vmstop_lock
);
716 return *r
< RUN_STATE_MAX
;
719 void qemu_system_vmstop_request_prepare(void)
721 qemu_mutex_lock(&vmstop_lock
);
724 void qemu_system_vmstop_request(RunState state
)
726 vmstop_requested
= state
;
727 qemu_mutex_unlock(&vmstop_lock
);
735 qemu_vmstop_requested(&requested
);
736 if (runstate_is_running() && requested
== RUN_STATE_MAX
) {
740 /* Ensure that a STOP/RESUME pair of events is emitted if a
741 * vmstop request was pending. The BLOCK_IO_ERROR event, for
742 * example, according to documentation is always followed by
745 if (runstate_is_running()) {
746 qapi_event_send_stop(&error_abort
);
749 runstate_set(RUN_STATE_RUNNING
);
750 vm_state_notify(1, RUN_STATE_RUNNING
);
754 qapi_event_send_resume(&error_abort
);
758 /***********************************************************/
759 /* real time host monotonic timer */
761 /***********************************************************/
762 /* host time/date access */
763 void qemu_get_timedate(struct tm
*tm
, int offset
)
769 if (rtc_date_offset
== -1) {
773 localtime_r(&ti
, tm
);
775 ti
-= rtc_date_offset
;
780 int qemu_timedate_diff(struct tm
*tm
)
784 if (rtc_date_offset
== -1)
786 seconds
= mktimegm(tm
);
789 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
790 seconds
= mktime(&tmp
);
793 seconds
= mktimegm(tm
) + rtc_date_offset
;
795 return seconds
- time(NULL
);
798 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
800 time_t rtc_start_date
;
803 if (!strcmp(startdate
, "now") && legacy
) {
804 rtc_date_offset
= -1;
806 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
814 } else if (sscanf(startdate
, "%d-%d-%d",
826 rtc_start_date
= mktimegm(&tm
);
827 if (rtc_start_date
== -1) {
829 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
830 "'2006-06-17T16:01:21' or '2006-06-17'\n");
833 rtc_date_offset
= time(NULL
) - rtc_start_date
;
837 static void configure_rtc(QemuOpts
*opts
)
841 value
= qemu_opt_get(opts
, "base");
843 if (!strcmp(value
, "utc")) {
845 } else if (!strcmp(value
, "localtime")) {
848 configure_rtc_date_offset(value
, 0);
851 value
= qemu_opt_get(opts
, "clock");
853 if (!strcmp(value
, "host")) {
854 rtc_clock
= QEMU_CLOCK_HOST
;
855 } else if (!strcmp(value
, "rt")) {
856 rtc_clock
= QEMU_CLOCK_REALTIME
;
857 } else if (!strcmp(value
, "vm")) {
858 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
860 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
864 value
= qemu_opt_get(opts
, "driftfix");
866 if (!strcmp(value
, "slew")) {
867 static GlobalProperty slew_lost_ticks
[] = {
869 .driver
= "mc146818rtc",
870 .property
= "lost_tick_policy",
873 { /* end of list */ }
876 qdev_prop_register_global_list(slew_lost_ticks
);
877 } else if (!strcmp(value
, "none")) {
878 /* discard is default */
880 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
886 /***********************************************************/
887 /* Bluetooth support */
890 static struct HCIInfo
*hci_table
[MAX_NICS
];
892 struct HCIInfo
*qemu_next_hci(void)
894 if (cur_hci
== nb_hcis
)
897 return hci_table
[cur_hci
++];
900 static int bt_hci_parse(const char *str
)
905 if (nb_hcis
>= MAX_NICS
) {
906 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
919 bdaddr
.b
[5] = 0x56 + nb_hcis
;
920 hci
->bdaddr_set(hci
, bdaddr
.b
);
922 hci_table
[nb_hcis
++] = hci
;
927 static void bt_vhci_add(int vlan_id
)
929 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
932 fprintf(stderr
, "qemu: warning: adding a VHCI to "
933 "an empty scatternet %i\n", vlan_id
);
935 bt_vhci_init(bt_new_hci(vlan
));
938 static struct bt_device_s
*bt_device_add(const char *opt
)
940 struct bt_scatternet_s
*vlan
;
942 char *endp
= strstr(opt
, ",vlan=");
943 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
946 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
949 vlan_id
= strtol(endp
+ 6, &endp
, 0);
951 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
956 vlan
= qemu_find_bt_vlan(vlan_id
);
959 fprintf(stderr
, "qemu: warning: adding a slave device to "
960 "an empty scatternet %i\n", vlan_id
);
962 if (!strcmp(devname
, "keyboard"))
963 return bt_keyboard_init(vlan
);
965 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
969 static int bt_parse(const char *opt
)
971 const char *endp
, *p
;
974 if (strstart(opt
, "hci", &endp
)) {
975 if (!*endp
|| *endp
== ',') {
977 if (!strstart(endp
, ",vlan=", 0))
980 return bt_hci_parse(opt
);
982 } else if (strstart(opt
, "vhci", &endp
)) {
983 if (!*endp
|| *endp
== ',') {
985 if (strstart(endp
, ",vlan=", &p
)) {
986 vlan
= strtol(p
, (char **) &endp
, 0);
988 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
992 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
1001 } else if (strstart(opt
, "device:", &endp
))
1002 return !bt_device_add(endp
);
1004 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
1008 static int parse_sandbox(QemuOpts
*opts
, void *opaque
)
1010 /* FIXME: change this to true for 1.3 */
1011 if (qemu_opt_get_bool(opts
, "enable", false)) {
1012 #ifdef CONFIG_SECCOMP
1013 if (seccomp_start() < 0) {
1014 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1015 "failed to install seccomp syscall filter in the kernel");
1019 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1020 "sandboxing request but seccomp is not compiled into this build");
1028 static int parse_name(QemuOpts
*opts
, void *opaque
)
1030 const char *proc_name
;
1032 if (qemu_opt_get(opts
, "debug-threads")) {
1033 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
1035 qemu_name
= qemu_opt_get(opts
, "guest");
1037 proc_name
= qemu_opt_get(opts
, "process");
1039 os_set_proc_name(proc_name
);
1045 bool usb_enabled(bool default_usb
)
1047 return qemu_opt_get_bool(qemu_get_machine_opts(), "usb",
1048 has_defaults
&& default_usb
);
1052 static int parse_add_fd(QemuOpts
*opts
, void *opaque
)
1054 int fd
, dupfd
, flags
;
1056 const char *fd_opaque
= NULL
;
1058 fd
= qemu_opt_get_number(opts
, "fd", -1);
1059 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1060 fd_opaque
= qemu_opt_get(opts
, "opaque");
1063 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1064 "fd option is required and must be non-negative");
1068 if (fd
<= STDERR_FILENO
) {
1069 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1070 "fd cannot be a standard I/O stream");
1075 * All fds inherited across exec() necessarily have FD_CLOEXEC
1076 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1078 flags
= fcntl(fd
, F_GETFD
);
1079 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1080 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1081 "fd is not valid or already in use");
1086 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1087 "set option is required and must be non-negative");
1091 #ifdef F_DUPFD_CLOEXEC
1092 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1096 qemu_set_cloexec(dupfd
);
1100 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1101 "Error duplicating fd: %s", strerror(errno
));
1105 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1106 monitor_fdset_add_fd(dupfd
, true, fdset_id
, fd_opaque
? true : false,
1112 static int cleanup_add_fd(QemuOpts
*opts
, void *opaque
)
1116 fd
= qemu_opt_get_number(opts
, "fd", -1);
1123 /***********************************************************/
1124 /* QEMU Block devices */
1126 #define HD_OPTS "media=disk"
1127 #define CDROM_OPTS "media=cdrom"
1129 #define PFLASH_OPTS ""
1133 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
1135 BlockInterfaceType
*block_default_type
= opaque
;
1137 return drive_new(opts
, *block_default_type
) == NULL
;
1140 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
1142 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
1143 qemu_opt_set(opts
, "snapshot", "on");
1148 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1149 int index
, const char *optstr
)
1153 if (!enable
|| drive_get_by_index(type
, index
)) {
1157 opts
= drive_add(type
, index
, NULL
, optstr
);
1159 drive_enable_snapshot(opts
, NULL
);
1161 if (!drive_new(opts
, type
)) {
1166 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
1168 boot_set_handler
= func
;
1169 boot_set_opaque
= opaque
;
1172 int qemu_boot_set(const char *boot_order
)
1174 if (!boot_set_handler
) {
1177 return boot_set_handler(boot_set_opaque
, boot_order
);
1180 static void validate_bootdevices(const char *devices
)
1182 /* We just do some generic consistency checks */
1186 for (p
= devices
; *p
!= '\0'; p
++) {
1187 /* Allowed boot devices are:
1188 * a-b: floppy disk drives
1189 * c-f: IDE disk drives
1190 * g-m: machine implementation dependent drives
1191 * n-p: network devices
1192 * It's up to each machine implementation to check if the given boot
1193 * devices match the actual hardware implementation and firmware
1196 if (*p
< 'a' || *p
> 'p') {
1197 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
1200 if (bitmap
& (1 << (*p
- 'a'))) {
1201 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
1204 bitmap
|= 1 << (*p
- 'a');
1208 static void restore_boot_order(void *opaque
)
1210 char *normal_boot_order
= opaque
;
1211 static int first
= 1;
1213 /* Restore boot order and remove ourselves after the first boot */
1219 qemu_boot_set(normal_boot_order
);
1221 qemu_unregister_reset(restore_boot_order
, normal_boot_order
);
1222 g_free(normal_boot_order
);
1225 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
1228 FWBootEntry
*node
, *i
;
1230 if (bootindex
< 0) {
1234 assert(dev
!= NULL
|| suffix
!= NULL
);
1236 node
= g_malloc0(sizeof(FWBootEntry
));
1237 node
->bootindex
= bootindex
;
1238 node
->suffix
= g_strdup(suffix
);
1241 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
1242 if (i
->bootindex
== bootindex
) {
1243 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
1245 } else if (i
->bootindex
< bootindex
) {
1248 QTAILQ_INSERT_BEFORE(i
, node
, link
);
1251 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
1254 DeviceState
*get_boot_device(uint32_t position
)
1256 uint32_t counter
= 0;
1257 FWBootEntry
*i
= NULL
;
1258 DeviceState
*res
= NULL
;
1260 if (!QTAILQ_EMPTY(&fw_boot_order
)) {
1261 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
1262 if (counter
== position
) {
1273 * This function returns null terminated string that consist of new line
1274 * separated device paths.
1276 * memory pointed by "size" is assigned total length of the array in bytes
1279 char *get_boot_devices_list(size_t *size
, bool ignore_suffixes
)
1285 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
1286 char *devpath
= NULL
, *bootpath
;
1290 devpath
= qdev_get_fw_dev_path(i
->dev
);
1294 if (i
->suffix
&& !ignore_suffixes
&& devpath
) {
1295 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
1297 bootpath
= g_malloc(bootpathlen
);
1298 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
1300 } else if (devpath
) {
1302 } else if (!ignore_suffixes
) {
1304 bootpath
= g_strdup(i
->suffix
);
1306 bootpath
= g_strdup("");
1310 list
[total
-1] = '\n';
1312 len
= strlen(bootpath
) + 1;
1313 list
= g_realloc(list
, total
+ len
);
1314 memcpy(&list
[total
], bootpath
, len
);
1321 if (boot_strict
&& *size
> 0) {
1322 list
[total
-1] = '\n';
1323 list
= g_realloc(list
, total
+ 5);
1324 memcpy(&list
[total
], "HALT", 5);
1330 static QemuOptsList qemu_smp_opts
= {
1332 .implied_opt_name
= "cpus",
1333 .merge_lists
= true,
1334 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1338 .type
= QEMU_OPT_NUMBER
,
1341 .type
= QEMU_OPT_NUMBER
,
1344 .type
= QEMU_OPT_NUMBER
,
1347 .type
= QEMU_OPT_NUMBER
,
1350 .type
= QEMU_OPT_NUMBER
,
1352 { /*End of list */ }
1356 static void smp_parse(QemuOpts
*opts
)
1360 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1361 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1362 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1363 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1365 /* compute missing values, prefer sockets over cores over threads */
1366 if (cpus
== 0 || sockets
== 0) {
1367 sockets
= sockets
> 0 ? sockets
: 1;
1368 cores
= cores
> 0 ? cores
: 1;
1369 threads
= threads
> 0 ? threads
: 1;
1371 cpus
= cores
* threads
* sockets
;
1375 threads
= threads
> 0 ? threads
: 1;
1376 cores
= cpus
/ (sockets
* threads
);
1378 threads
= cpus
/ (cores
* sockets
);
1382 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", 0);
1385 smp_cores
= cores
> 0 ? cores
: 1;
1386 smp_threads
= threads
> 0 ? threads
: 1;
1390 if (max_cpus
== 0) {
1391 max_cpus
= smp_cpus
;
1394 if (max_cpus
> MAX_CPUMASK_BITS
) {
1395 fprintf(stderr
, "Unsupported number of maxcpus\n");
1398 if (max_cpus
< smp_cpus
) {
1399 fprintf(stderr
, "maxcpus must be equal to or greater than smp\n");
1405 static void configure_realtime(QemuOpts
*opts
)
1409 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
1412 if (os_mlock() < 0) {
1413 fprintf(stderr
, "qemu: locking memory failed\n");
1420 static void configure_msg(QemuOpts
*opts
)
1422 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1425 /***********************************************************/
1428 static int usb_device_add(const char *devname
)
1430 USBDevice
*dev
= NULL
;
1431 #ifndef CONFIG_LINUX
1435 if (!usb_enabled(false)) {
1439 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1440 dev
= usbdevice_create(devname
);
1444 /* the other ones */
1445 #ifndef CONFIG_LINUX
1446 /* only the linux version is qdev-ified, usb-bsd still needs this */
1447 if (strstart(devname
, "host:", &p
)) {
1448 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1458 static int usb_device_del(const char *devname
)
1463 if (strstart(devname
, "host:", &p
)) {
1467 if (!usb_enabled(false)) {
1471 p
= strchr(devname
, '.');
1474 bus_num
= strtoul(devname
, NULL
, 0);
1475 addr
= strtoul(p
+ 1, NULL
, 0);
1477 return usb_device_delete_addr(bus_num
, addr
);
1480 static int usb_parse(const char *cmdline
)
1483 r
= usb_device_add(cmdline
);
1485 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
1490 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
1492 const char *devname
= qdict_get_str(qdict
, "devname");
1493 if (usb_device_add(devname
) < 0) {
1494 error_report("could not add USB device '%s'", devname
);
1498 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
1500 const char *devname
= qdict_get_str(qdict
, "devname");
1501 if (usb_device_del(devname
) < 0) {
1502 error_report("could not delete USB device '%s'", devname
);
1506 /***********************************************************/
1507 /* PCMCIA/Cardbus */
1509 static struct pcmcia_socket_entry_s
{
1510 PCMCIASocket
*socket
;
1511 struct pcmcia_socket_entry_s
*next
;
1512 } *pcmcia_sockets
= 0;
1514 void pcmcia_socket_register(PCMCIASocket
*socket
)
1516 struct pcmcia_socket_entry_s
*entry
;
1518 entry
= g_malloc(sizeof(struct pcmcia_socket_entry_s
));
1519 entry
->socket
= socket
;
1520 entry
->next
= pcmcia_sockets
;
1521 pcmcia_sockets
= entry
;
1524 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
1526 struct pcmcia_socket_entry_s
*entry
, **ptr
;
1528 ptr
= &pcmcia_sockets
;
1529 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
1530 if (entry
->socket
== socket
) {
1536 void pcmcia_info(Monitor
*mon
, const QDict
*qdict
)
1538 struct pcmcia_socket_entry_s
*iter
;
1540 if (!pcmcia_sockets
)
1541 monitor_printf(mon
, "No PCMCIA sockets\n");
1543 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1544 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1545 iter
->socket
->attached
? iter
->socket
->card_string
:
1549 /***********************************************************/
1550 /* machine registration */
1552 MachineState
*current_machine
;
1554 static void machine_class_init(ObjectClass
*oc
, void *data
)
1556 MachineClass
*mc
= MACHINE_CLASS(oc
);
1557 QEMUMachine
*qm
= data
;
1559 mc
->name
= qm
->name
;
1560 mc
->alias
= qm
->alias
;
1561 mc
->desc
= qm
->desc
;
1562 mc
->init
= qm
->init
;
1563 mc
->reset
= qm
->reset
;
1564 mc
->hot_add_cpu
= qm
->hot_add_cpu
;
1565 mc
->kvm_type
= qm
->kvm_type
;
1566 mc
->block_default_type
= qm
->block_default_type
;
1567 mc
->max_cpus
= qm
->max_cpus
;
1568 mc
->no_serial
= qm
->no_serial
;
1569 mc
->no_parallel
= qm
->no_parallel
;
1570 mc
->use_virtcon
= qm
->use_virtcon
;
1571 mc
->use_sclp
= qm
->use_sclp
;
1572 mc
->no_floppy
= qm
->no_floppy
;
1573 mc
->no_cdrom
= qm
->no_cdrom
;
1574 mc
->no_sdcard
= qm
->no_sdcard
;
1575 mc
->is_default
= qm
->is_default
;
1576 mc
->default_machine_opts
= qm
->default_machine_opts
;
1577 mc
->default_boot_order
= qm
->default_boot_order
;
1578 mc
->compat_props
= qm
->compat_props
;
1579 mc
->hw_version
= qm
->hw_version
;
1582 int qemu_register_machine(QEMUMachine
*m
)
1584 char *name
= g_strconcat(m
->name
, TYPE_MACHINE_SUFFIX
, NULL
);
1587 .parent
= TYPE_MACHINE
,
1588 .class_init
= machine_class_init
,
1589 .class_data
= (void *)m
,
1598 static MachineClass
*find_machine(const char *name
)
1600 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1601 MachineClass
*mc
= NULL
;
1603 for (el
= machines
; el
; el
= el
->next
) {
1604 MachineClass
*temp
= el
->data
;
1606 if (!strcmp(temp
->name
, name
)) {
1611 !strcmp(temp
->alias
, name
)) {
1617 g_slist_free(machines
);
1621 MachineClass
*find_default_machine(void)
1623 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1624 MachineClass
*mc
= NULL
;
1626 for (el
= machines
; el
; el
= el
->next
) {
1627 MachineClass
*temp
= el
->data
;
1629 if (temp
->is_default
) {
1635 g_slist_free(machines
);
1639 MachineInfoList
*qmp_query_machines(Error
**errp
)
1641 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1642 MachineInfoList
*mach_list
= NULL
;
1644 for (el
= machines
; el
; el
= el
->next
) {
1645 MachineClass
*mc
= el
->data
;
1646 MachineInfoList
*entry
;
1649 info
= g_malloc0(sizeof(*info
));
1650 if (mc
->is_default
) {
1651 info
->has_is_default
= true;
1652 info
->is_default
= true;
1656 info
->has_alias
= true;
1657 info
->alias
= g_strdup(mc
->alias
);
1660 info
->name
= g_strdup(mc
->name
);
1661 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1663 entry
= g_malloc0(sizeof(*entry
));
1664 entry
->value
= info
;
1665 entry
->next
= mach_list
;
1669 g_slist_free(machines
);
1673 /***********************************************************/
1674 /* main execution loop */
1676 struct vm_change_state_entry
{
1677 VMChangeStateHandler
*cb
;
1679 QLIST_ENTRY (vm_change_state_entry
) entries
;
1682 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1684 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1687 VMChangeStateEntry
*e
;
1689 e
= g_malloc0(sizeof (*e
));
1693 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1697 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1699 QLIST_REMOVE (e
, entries
);
1703 void vm_state_notify(int running
, RunState state
)
1705 VMChangeStateEntry
*e
;
1707 trace_vm_state_notify(running
, state
);
1709 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1710 e
->cb(e
->opaque
, running
, state
);
1714 /* reset/shutdown handler */
1716 typedef struct QEMUResetEntry
{
1717 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1718 QEMUResetHandler
*func
;
1722 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1723 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1724 static int reset_requested
;
1725 static int shutdown_requested
, shutdown_signal
= -1;
1726 static pid_t shutdown_pid
;
1727 static int powerdown_requested
;
1728 static int debug_requested
;
1729 static int suspend_requested
;
1730 static WakeupReason wakeup_reason
;
1731 static NotifierList powerdown_notifiers
=
1732 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1733 static NotifierList suspend_notifiers
=
1734 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1735 static NotifierList wakeup_notifiers
=
1736 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1737 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1739 int qemu_shutdown_requested_get(void)
1741 return shutdown_requested
;
1744 int qemu_reset_requested_get(void)
1746 return reset_requested
;
1749 static int qemu_shutdown_requested(void)
1751 int r
= shutdown_requested
;
1752 shutdown_requested
= 0;
1756 static void qemu_kill_report(void)
1758 if (!qtest_driver() && shutdown_signal
!= -1) {
1759 fprintf(stderr
, "qemu: terminating on signal %d", shutdown_signal
);
1760 if (shutdown_pid
== 0) {
1761 /* This happens for eg ^C at the terminal, so it's worth
1762 * avoiding printing an odd message in that case.
1764 fputc('\n', stderr
);
1766 fprintf(stderr
, " from pid " FMT_pid
"\n", shutdown_pid
);
1768 shutdown_signal
= -1;
1772 static int qemu_reset_requested(void)
1774 int r
= reset_requested
;
1775 reset_requested
= 0;
1779 static int qemu_suspend_requested(void)
1781 int r
= suspend_requested
;
1782 suspend_requested
= 0;
1786 static WakeupReason
qemu_wakeup_requested(void)
1788 return wakeup_reason
;
1791 static int qemu_powerdown_requested(void)
1793 int r
= powerdown_requested
;
1794 powerdown_requested
= 0;
1798 static int qemu_debug_requested(void)
1800 int r
= debug_requested
;
1801 debug_requested
= 0;
1805 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1807 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1810 re
->opaque
= opaque
;
1811 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1814 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1818 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1819 if (re
->func
== func
&& re
->opaque
== opaque
) {
1820 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1827 void qemu_devices_reset(void)
1829 QEMUResetEntry
*re
, *nre
;
1831 /* reset all devices */
1832 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1833 re
->func(re
->opaque
);
1837 void qemu_system_reset(bool report
)
1841 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1843 if (mc
&& mc
->reset
) {
1846 qemu_devices_reset();
1849 qapi_event_send_reset(&error_abort
);
1851 cpu_synchronize_all_post_reset();
1854 void qemu_system_reset_request(void)
1857 shutdown_requested
= 1;
1859 reset_requested
= 1;
1862 qemu_notify_event();
1865 static void qemu_system_suspend(void)
1868 notifier_list_notify(&suspend_notifiers
, NULL
);
1869 runstate_set(RUN_STATE_SUSPENDED
);
1870 qapi_event_send_suspend(&error_abort
);
1873 void qemu_system_suspend_request(void)
1875 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1878 suspend_requested
= 1;
1880 qemu_notify_event();
1883 void qemu_register_suspend_notifier(Notifier
*notifier
)
1885 notifier_list_add(&suspend_notifiers
, notifier
);
1888 void qemu_system_wakeup_request(WakeupReason reason
)
1890 trace_system_wakeup_request(reason
);
1892 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1895 if (!(wakeup_reason_mask
& (1 << reason
))) {
1898 runstate_set(RUN_STATE_RUNNING
);
1899 wakeup_reason
= reason
;
1900 qemu_notify_event();
1903 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1906 wakeup_reason_mask
|= (1 << reason
);
1908 wakeup_reason_mask
&= ~(1 << reason
);
1912 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1914 notifier_list_add(&wakeup_notifiers
, notifier
);
1917 void qemu_system_killed(int signal
, pid_t pid
)
1919 shutdown_signal
= signal
;
1922 qemu_system_shutdown_request();
1925 void qemu_system_shutdown_request(void)
1927 trace_qemu_system_shutdown_request();
1928 shutdown_requested
= 1;
1929 qemu_notify_event();
1932 static void qemu_system_powerdown(void)
1934 qapi_event_send_powerdown(&error_abort
);
1935 notifier_list_notify(&powerdown_notifiers
, NULL
);
1938 void qemu_system_powerdown_request(void)
1940 trace_qemu_system_powerdown_request();
1941 powerdown_requested
= 1;
1942 qemu_notify_event();
1945 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1947 notifier_list_add(&powerdown_notifiers
, notifier
);
1950 void qemu_system_debug_request(void)
1952 debug_requested
= 1;
1953 qemu_notify_event();
1956 static bool main_loop_should_exit(void)
1959 if (qemu_debug_requested()) {
1960 vm_stop(RUN_STATE_DEBUG
);
1962 if (qemu_suspend_requested()) {
1963 qemu_system_suspend();
1965 if (qemu_shutdown_requested()) {
1967 qapi_event_send_shutdown(&error_abort
);
1969 vm_stop(RUN_STATE_SHUTDOWN
);
1974 if (qemu_reset_requested()) {
1976 cpu_synchronize_all_states();
1977 qemu_system_reset(VMRESET_REPORT
);
1979 if (runstate_needs_reset()) {
1980 runstate_set(RUN_STATE_PAUSED
);
1983 if (qemu_wakeup_requested()) {
1985 cpu_synchronize_all_states();
1986 qemu_system_reset(VMRESET_SILENT
);
1987 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
1988 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
1990 qapi_event_send_wakeup(&error_abort
);
1992 if (qemu_powerdown_requested()) {
1993 qemu_system_powerdown();
1995 if (qemu_vmstop_requested(&r
)) {
2001 static void main_loop(void)
2005 #ifdef CONFIG_PROFILER
2009 nonblocking
= !kvm_enabled() && !xen_enabled() && last_io
> 0;
2010 #ifdef CONFIG_PROFILER
2011 ti
= profile_getclock();
2013 last_io
= main_loop_wait(nonblocking
);
2014 #ifdef CONFIG_PROFILER
2015 dev_time
+= profile_getclock() - ti
;
2017 } while (!main_loop_should_exit());
2020 static void version(void)
2022 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
2025 static void QEMU_NORETURN
help(int exitcode
)
2028 printf("usage: %s [options] [disk_image]\n\n"
2029 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
2030 error_get_progname());
2032 #define QEMU_OPTIONS_GENERATE_HELP
2033 #include "qemu-options-wrapper.h"
2035 printf("\nDuring emulation, the following keys are useful:\n"
2036 "ctrl-alt-f toggle full screen\n"
2037 "ctrl-alt-n switch to virtual console 'n'\n"
2038 "ctrl-alt toggle mouse and keyboard grab\n"
2040 "When using -nographic, press 'ctrl-a h' to get some help.\n");
2045 #define HAS_ARG 0x0001
2047 typedef struct QEMUOption
{
2054 static const QEMUOption qemu_options
[] = {
2055 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
2056 #define QEMU_OPTIONS_GENERATE_OPTIONS
2057 #include "qemu-options-wrapper.h"
2061 static bool vga_available(void)
2063 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
2066 static bool cirrus_vga_available(void)
2068 return object_class_by_name("cirrus-vga")
2069 || object_class_by_name("isa-cirrus-vga");
2072 static bool vmware_vga_available(void)
2074 return object_class_by_name("vmware-svga");
2077 static bool qxl_vga_available(void)
2079 return object_class_by_name("qxl-vga");
2082 static bool tcx_vga_available(void)
2084 return object_class_by_name("SUNW,tcx");
2087 static bool cg3_vga_available(void)
2089 return object_class_by_name("cgthree");
2092 static void select_vgahw (const char *p
)
2096 assert(vga_interface_type
== VGA_NONE
);
2097 if (strstart(p
, "std", &opts
)) {
2098 if (vga_available()) {
2099 vga_interface_type
= VGA_STD
;
2101 fprintf(stderr
, "Error: standard VGA not available\n");
2104 } else if (strstart(p
, "cirrus", &opts
)) {
2105 if (cirrus_vga_available()) {
2106 vga_interface_type
= VGA_CIRRUS
;
2108 fprintf(stderr
, "Error: Cirrus VGA not available\n");
2111 } else if (strstart(p
, "vmware", &opts
)) {
2112 if (vmware_vga_available()) {
2113 vga_interface_type
= VGA_VMWARE
;
2115 fprintf(stderr
, "Error: VMWare SVGA not available\n");
2118 } else if (strstart(p
, "xenfb", &opts
)) {
2119 vga_interface_type
= VGA_XENFB
;
2120 } else if (strstart(p
, "qxl", &opts
)) {
2121 if (qxl_vga_available()) {
2122 vga_interface_type
= VGA_QXL
;
2124 fprintf(stderr
, "Error: QXL VGA not available\n");
2127 } else if (strstart(p
, "tcx", &opts
)) {
2128 if (tcx_vga_available()) {
2129 vga_interface_type
= VGA_TCX
;
2131 fprintf(stderr
, "Error: TCX framebuffer not available\n");
2134 } else if (strstart(p
, "cg3", &opts
)) {
2135 if (cg3_vga_available()) {
2136 vga_interface_type
= VGA_CG3
;
2138 fprintf(stderr
, "Error: CG3 framebuffer not available\n");
2141 } else if (!strstart(p
, "none", &opts
)) {
2143 fprintf(stderr
, "Unknown vga type: %s\n", p
);
2147 const char *nextopt
;
2149 if (strstart(opts
, ",retrace=", &nextopt
)) {
2151 if (strstart(opts
, "dumb", &nextopt
))
2152 vga_retrace_method
= VGA_RETRACE_DUMB
;
2153 else if (strstart(opts
, "precise", &nextopt
))
2154 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2155 else goto invalid_vga
;
2156 } else goto invalid_vga
;
2161 static DisplayType
select_display(const char *p
)
2164 DisplayType display
= DT_DEFAULT
;
2166 if (strstart(p
, "sdl", &opts
)) {
2170 const char *nextopt
;
2172 if (strstart(opts
, ",frame=", &nextopt
)) {
2174 if (strstart(opts
, "on", &nextopt
)) {
2176 } else if (strstart(opts
, "off", &nextopt
)) {
2179 goto invalid_sdl_args
;
2181 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2183 if (strstart(opts
, "on", &nextopt
)) {
2185 } else if (strstart(opts
, "off", &nextopt
)) {
2188 goto invalid_sdl_args
;
2190 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2192 if (strstart(opts
, "on", &nextopt
)) {
2194 } else if (strstart(opts
, "off", &nextopt
)) {
2197 goto invalid_sdl_args
;
2199 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2201 if (strstart(opts
, "on", &nextopt
)) {
2203 } else if (strstart(opts
, "off", &nextopt
)) {
2206 goto invalid_sdl_args
;
2210 fprintf(stderr
, "Invalid SDL option string: %s\n", p
);
2216 fprintf(stderr
, "SDL support is disabled\n");
2219 } else if (strstart(p
, "vnc", &opts
)) {
2224 const char *nextopt
;
2226 if (strstart(opts
, "=", &nextopt
)) {
2227 vnc_display
= nextopt
;
2231 fprintf(stderr
, "VNC requires a display argument vnc=<display>\n");
2235 fprintf(stderr
, "VNC support is disabled\n");
2238 } else if (strstart(p
, "curses", &opts
)) {
2239 #ifdef CONFIG_CURSES
2240 display
= DT_CURSES
;
2242 fprintf(stderr
, "Curses support is disabled\n");
2245 } else if (strstart(p
, "gtk", &opts
)) {
2249 const char *nextopt
;
2251 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2253 if (strstart(opts
, "on", &nextopt
)) {
2254 grab_on_hover
= true;
2255 } else if (strstart(opts
, "off", &nextopt
)) {
2256 grab_on_hover
= false;
2258 goto invalid_gtk_args
;
2262 fprintf(stderr
, "Invalid GTK option string: %s\n", p
);
2268 fprintf(stderr
, "GTK support is disabled\n");
2271 } else if (strstart(p
, "none", &opts
)) {
2274 fprintf(stderr
, "Unknown display type: %s\n", p
);
2281 static int balloon_parse(const char *arg
)
2285 if (strcmp(arg
, "none") == 0) {
2289 if (!strncmp(arg
, "virtio", 6)) {
2290 if (arg
[6] == ',') {
2291 /* have params -> parse them */
2292 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
2296 /* create empty opts */
2297 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2300 qemu_opt_set(opts
, "driver", "virtio-balloon");
2307 #if defined(CONFIG_RUBY)
2308 /* Ruby interface for QEMU. See README.EXT for programming example. */
2312 static VALUE
qemu_open(int argc
, VALUE
*argv
, VALUE klass
)
2315 for (i
= 0; i
< argc
; i
++) {
2316 argv
[i
] = StringValue(argv
[i
]);
2317 fprintf(stderr
, "argv[%d] = %s\n", i
, StringValuePtr(argv
[i
]));
2319 //~ if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
2320 //~ mode = 0666; /* default value */
2322 return INT2FIX(argc
);
2325 void Init_qemu(void)
2327 printf("%s\n", __func__
);
2328 VALUE cQEMU
= rb_define_class("QEMU", rb_cObject
);
2329 rb_define_singleton_method(cQEMU
, "run", qemu_open
, -1);
2334 #endif /* CONFIG_RUBY */
2336 #if defined(CONFIG_DLL)
2337 BOOL APIENTRY
DllMain(HINSTANCE hModule
, DWORD ul_reason_for_call
, LPVOID data
)
2341 #endif /* CONFIG_DLL */
2343 char *qemu_find_file(int type
, const char *name
)
2349 /* Try the name as a straight path first */
2350 if (access(name
, R_OK
) == 0) {
2351 trace_load_file(name
, name
);
2352 return g_strdup(name
);
2356 case QEMU_FILE_TYPE_BIOS
:
2359 case QEMU_FILE_TYPE_KEYMAP
:
2360 subdir
= "keymaps/";
2366 for (i
= 0; i
< data_dir_idx
; i
++) {
2367 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2368 if (access(buf
, R_OK
) == 0) {
2369 trace_load_file(name
, buf
);
2377 static int device_help_func(QemuOpts
*opts
, void *opaque
)
2379 return qdev_device_help(opts
);
2382 static int device_init_func(QemuOpts
*opts
, void *opaque
)
2386 dev
= qdev_device_add(opts
);
2389 object_unref(OBJECT(dev
));
2393 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
2395 Error
*local_err
= NULL
;
2397 qemu_chr_new_from_opts(opts
, NULL
, &local_err
);
2399 error_report("%s", error_get_pretty(local_err
));
2400 error_free(local_err
);
2406 #ifdef CONFIG_VIRTFS
2407 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
2410 ret
= qemu_fsdev_add(opts
);
2416 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
2418 CharDriverState
*chr
;
2419 const char *chardev
;
2423 mode
= qemu_opt_get(opts
, "mode");
2427 if (strcmp(mode
, "readline") == 0) {
2428 flags
= MONITOR_USE_READLINE
;
2429 } else if (strcmp(mode
, "control") == 0) {
2430 flags
= MONITOR_USE_CONTROL
;
2432 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
2436 if (qemu_opt_get_bool(opts
, "pretty", 0))
2437 flags
|= MONITOR_USE_PRETTY
;
2439 if (qemu_opt_get_bool(opts
, "default", 0))
2440 flags
|= MONITOR_IS_DEFAULT
;
2442 chardev
= qemu_opt_get(opts
, "chardev");
2443 chr
= qemu_chr_find(chardev
);
2445 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
2449 qemu_chr_fe_claim_no_fail(chr
);
2450 monitor_init(chr
, flags
);
2454 static void monitor_parse(const char *optarg
, const char *mode
)
2456 static int monitor_device_index
= 0;
2462 if (strstart(optarg
, "chardev:", &p
)) {
2463 snprintf(label
, sizeof(label
), "%s", p
);
2465 snprintf(label
, sizeof(label
), "compat_monitor%d",
2466 monitor_device_index
);
2467 if (monitor_device_index
== 0) {
2470 opts
= qemu_chr_parse_compat(label
, optarg
);
2472 fprintf(stderr
, "parse error: %s\n", optarg
);
2477 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, NULL
);
2479 fprintf(stderr
, "duplicate chardev: %s\n", label
);
2482 qemu_opt_set(opts
, "mode", mode
);
2483 qemu_opt_set(opts
, "chardev", label
);
2485 qemu_opt_set(opts
, "default", "on");
2486 monitor_device_index
++;
2489 struct device_config
{
2491 DEV_USB
, /* -usbdevice */
2493 DEV_SERIAL
, /* -serial */
2494 DEV_PARALLEL
, /* -parallel */
2495 DEV_VIRTCON
, /* -virtioconsole */
2496 DEV_DEBUGCON
, /* -debugcon */
2497 DEV_GDB
, /* -gdb, -s */
2498 DEV_SCLP
, /* s390 sclp */
2500 const char *cmdline
;
2502 QTAILQ_ENTRY(device_config
) next
;
2505 static QTAILQ_HEAD(, device_config
) device_configs
=
2506 QTAILQ_HEAD_INITIALIZER(device_configs
);
2508 static void add_device_config(int type
, const char *cmdline
)
2510 struct device_config
*conf
;
2512 conf
= g_malloc0(sizeof(*conf
));
2514 conf
->cmdline
= cmdline
;
2515 loc_save(&conf
->loc
);
2516 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2519 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2521 struct device_config
*conf
;
2524 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2525 if (conf
->type
!= type
)
2527 loc_push_restore(&conf
->loc
);
2528 rc
= func(conf
->cmdline
);
2529 loc_pop(&conf
->loc
);
2536 static int serial_parse(const char *devname
)
2538 static int index
= 0;
2541 if (strcmp(devname
, "none") == 0)
2543 if (index
== MAX_SERIAL_PORTS
) {
2544 fprintf(stderr
, "qemu: too many serial ports\n");
2547 snprintf(label
, sizeof(label
), "serial%d", index
);
2548 serial_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2549 if (!serial_hds
[index
]) {
2550 fprintf(stderr
, "qemu: could not connect serial device"
2551 " to character backend '%s'\n", devname
);
2558 static int parallel_parse(const char *devname
)
2560 static int index
= 0;
2563 if (strcmp(devname
, "none") == 0)
2565 if (index
== MAX_PARALLEL_PORTS
) {
2566 fprintf(stderr
, "qemu: too many parallel ports\n");
2569 snprintf(label
, sizeof(label
), "parallel%d", index
);
2570 parallel_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2571 if (!parallel_hds
[index
]) {
2572 fprintf(stderr
, "qemu: could not connect parallel device"
2573 " to character backend '%s'\n", devname
);
2580 static int virtcon_parse(const char *devname
)
2582 QemuOptsList
*device
= qemu_find_opts("device");
2583 static int index
= 0;
2585 QemuOpts
*bus_opts
, *dev_opts
;
2587 if (strcmp(devname
, "none") == 0)
2589 if (index
== MAX_VIRTIO_CONSOLES
) {
2590 fprintf(stderr
, "qemu: too many virtio consoles\n");
2594 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2595 if (arch_type
== QEMU_ARCH_S390X
) {
2596 qemu_opt_set(bus_opts
, "driver", "virtio-serial-s390");
2598 qemu_opt_set(bus_opts
, "driver", "virtio-serial-pci");
2601 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2602 qemu_opt_set(dev_opts
, "driver", "virtconsole");
2604 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2605 virtcon_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2606 if (!virtcon_hds
[index
]) {
2607 fprintf(stderr
, "qemu: could not connect virtio console"
2608 " to character backend '%s'\n", devname
);
2611 qemu_opt_set(dev_opts
, "chardev", label
);
2617 static int sclp_parse(const char *devname
)
2619 QemuOptsList
*device
= qemu_find_opts("device");
2620 static int index
= 0;
2624 if (strcmp(devname
, "none") == 0) {
2627 if (index
== MAX_SCLP_CONSOLES
) {
2628 fprintf(stderr
, "qemu: too many sclp consoles\n");
2632 assert(arch_type
== QEMU_ARCH_S390X
);
2634 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2635 qemu_opt_set(dev_opts
, "driver", "sclpconsole");
2637 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2638 sclp_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2639 if (!sclp_hds
[index
]) {
2640 fprintf(stderr
, "qemu: could not connect sclp console"
2641 " to character backend '%s'\n", devname
);
2644 qemu_opt_set(dev_opts
, "chardev", label
);
2650 static int debugcon_parse(const char *devname
)
2654 if (!qemu_chr_new("debugcon", devname
, NULL
)) {
2657 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2659 fprintf(stderr
, "qemu: already have a debugcon device\n");
2662 qemu_opt_set(opts
, "driver", "isa-debugcon");
2663 qemu_opt_set(opts
, "chardev", "debugcon");
2667 static MachineClass
*machine_parse(const char *name
)
2669 MachineClass
*mc
= NULL
;
2670 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2673 mc
= find_machine(name
);
2678 if (name
&& !is_help_option(name
)) {
2679 error_report("Unsupported machine type");
2680 error_printf("Use -machine help to list supported machines!\n");
2682 printf("Supported machines are:\n");
2683 for (el
= machines
; el
; el
= el
->next
) {
2684 MachineClass
*mc
= el
->data
;
2686 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2688 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2689 mc
->is_default
? " (default)" : "");
2693 g_slist_free(machines
);
2694 exit(!name
|| !is_help_option(name
));
2697 static int tcg_init(MachineClass
*mc
)
2699 tcg_exec_init(tcg_tb_size
* 1024 * 1024);
2704 const char *opt_name
;
2706 int (*available
)(void);
2707 int (*init
)(MachineClass
*mc
);
2710 { "tcg", "tcg", tcg_available
, tcg_init
, &tcg_allowed
},
2711 { "xen", "Xen", xen_available
, xen_init
, &xen_allowed
},
2712 { "kvm", "KVM", kvm_available
, kvm_init
, &kvm_allowed
},
2713 { "qtest", "QTest", qtest_available
, qtest_init_accel
, &qtest_allowed
},
2716 static int configure_accelerator(MachineClass
*mc
)
2721 bool accel_initialised
= false;
2722 bool init_failed
= false;
2724 p
= qemu_opt_get(qemu_get_machine_opts(), "accel");
2726 /* Use the default "accelerator", tcg */
2730 while (!accel_initialised
&& *p
!= '\0') {
2734 p
= get_opt_name(buf
, sizeof (buf
), p
, ':');
2735 for (i
= 0; i
< ARRAY_SIZE(accel_list
); i
++) {
2736 if (strcmp(accel_list
[i
].opt_name
, buf
) == 0) {
2737 if (!accel_list
[i
].available()) {
2738 printf("%s not supported for this target\n",
2739 accel_list
[i
].name
);
2742 *(accel_list
[i
].allowed
) = true;
2743 ret
= accel_list
[i
].init(mc
);
2746 fprintf(stderr
, "failed to initialize %s: %s\n",
2749 *(accel_list
[i
].allowed
) = false;
2751 accel_initialised
= true;
2756 if (i
== ARRAY_SIZE(accel_list
)) {
2757 fprintf(stderr
, "\"%s\" accelerator does not exist.\n", buf
);
2761 if (!accel_initialised
) {
2763 fprintf(stderr
, "No accelerator found!\n");
2769 fprintf(stderr
, "Back to %s accelerator.\n", accel_list
[i
].name
);
2772 return !accel_initialised
;
2775 void qemu_add_exit_notifier(Notifier
*notify
)
2777 notifier_list_add(&exit_notifiers
, notify
);
2780 void qemu_remove_exit_notifier(Notifier
*notify
)
2782 notifier_remove(notify
);
2785 static void qemu_run_exit_notifiers(void)
2787 notifier_list_notify(&exit_notifiers
, NULL
);
2790 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2792 notifier_list_add(&machine_init_done_notifiers
, notify
);
2795 static void qemu_run_machine_init_done_notifiers(void)
2797 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2800 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2801 const char **poptarg
, int *poptind
)
2803 const QEMUOption
*popt
;
2804 int optind
= *poptind
;
2805 char *r
= argv
[optind
];
2808 loc_set_cmdline(argv
, optind
, 1);
2810 /* Treat --foo the same as -foo. */
2813 popt
= qemu_options
;
2816 error_report("invalid option");
2819 if (!strcmp(popt
->name
, r
+ 1))
2823 if (popt
->flags
& HAS_ARG
) {
2824 if (optind
>= argc
) {
2825 error_report("requires an argument");
2828 optarg
= argv
[optind
++];
2829 loc_set_cmdline(argv
, optind
- 2, 2);
2840 static gpointer
malloc_and_trace(gsize n_bytes
)
2842 void *ptr
= malloc(n_bytes
);
2843 trace_g_malloc(n_bytes
, ptr
);
2847 static gpointer
realloc_and_trace(gpointer mem
, gsize n_bytes
)
2849 void *ptr
= realloc(mem
, n_bytes
);
2850 trace_g_realloc(mem
, n_bytes
, ptr
);
2854 static void free_and_trace(gpointer mem
)
2860 static int object_set_property(const char *name
, const char *value
, void *opaque
)
2862 Object
*obj
= OBJECT(opaque
);
2863 StringInputVisitor
*siv
;
2864 Error
*local_err
= NULL
;
2866 if (strcmp(name
, "qom-type") == 0 || strcmp(name
, "id") == 0 ||
2867 strcmp(name
, "type") == 0) {
2871 siv
= string_input_visitor_new(value
);
2872 object_property_set(obj
, string_input_get_visitor(siv
), name
, &local_err
);
2873 string_input_visitor_cleanup(siv
);
2876 qerror_report_err(local_err
);
2877 error_free(local_err
);
2884 static int object_create(QemuOpts
*opts
, void *opaque
)
2893 ov
= opts_visitor_new(opts
);
2894 pdict
= qemu_opts_to_qdict(opts
, NULL
);
2896 visit_start_struct(opts_get_visitor(ov
), &dummy
, NULL
, NULL
, 0, &err
);
2901 qdict_del(pdict
, "qom-type");
2902 visit_type_str(opts_get_visitor(ov
), &type
, "qom-type", &err
);
2907 qdict_del(pdict
, "id");
2908 visit_type_str(opts_get_visitor(ov
), &id
, "id", &err
);
2913 object_add(type
, id
, pdict
, opts_get_visitor(ov
), &err
);
2917 visit_end_struct(opts_get_visitor(ov
), &err
);
2919 qmp_object_del(id
, NULL
);
2923 opts_visitor_cleanup(ov
);
2930 qerror_report_err(err
);
2936 int main(int argc
, char **argv
)
2939 int snapshot
, linux_boot
;
2940 const char *icount_option
= NULL
;
2941 const char *initrd_filename
;
2942 const char *kernel_filename
, *kernel_cmdline
;
2943 const char *boot_order
;
2945 int cyls
, heads
, secs
, translation
;
2946 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
;
2947 QemuOptsList
*olist
;
2950 const char *loadvm
= NULL
;
2951 MachineClass
*machine_class
;
2952 const char *cpu_model
;
2953 const char *vga_model
= NULL
;
2954 const char *qtest_chrdev
= NULL
;
2955 const char *qtest_log
= NULL
;
2956 const char *pid_file
= NULL
;
2957 const char *incoming
= NULL
;
2959 int show_vnc_port
= 0;
2961 bool defconfig
= true;
2962 bool userconfig
= true;
2963 const char *log_mask
= NULL
;
2964 const char *log_file
= NULL
;
2965 GMemVTable mem_trace
= {
2966 .malloc
= malloc_and_trace
,
2967 .realloc
= realloc_and_trace
,
2968 .free
= free_and_trace
,
2970 const char *trace_events
= NULL
;
2971 const char *trace_file
= NULL
;
2972 const ram_addr_t default_ram_size
= (ram_addr_t
)DEFAULT_RAM_SIZE
*
2974 ram_addr_t maxram_size
= default_ram_size
;
2975 uint64_t ram_slots
= 0;
2976 FILE *vmstate_dump_file
= NULL
;
2978 atexit(qemu_run_exit_notifiers
);
2979 error_set_progname(argv
[0]);
2980 qemu_init_exec_dir(argv
[0]);
2982 g_mem_set_vtable(&mem_trace
);
2984 module_call_init(MODULE_INIT_QOM
);
2986 qemu_add_opts(&qemu_drive_opts
);
2987 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2988 qemu_add_drive_opts(&qemu_common_drive_opts
);
2989 qemu_add_drive_opts(&qemu_drive_opts
);
2990 qemu_add_opts(&qemu_chardev_opts
);
2991 qemu_add_opts(&qemu_device_opts
);
2992 qemu_add_opts(&qemu_netdev_opts
);
2993 qemu_add_opts(&qemu_net_opts
);
2994 qemu_add_opts(&qemu_rtc_opts
);
2995 qemu_add_opts(&qemu_global_opts
);
2996 qemu_add_opts(&qemu_mon_opts
);
2997 qemu_add_opts(&qemu_trace_opts
);
2998 qemu_add_opts(&qemu_option_rom_opts
);
2999 qemu_add_opts(&qemu_machine_opts
);
3000 qemu_add_opts(&qemu_mem_opts
);
3001 qemu_add_opts(&qemu_smp_opts
);
3002 qemu_add_opts(&qemu_boot_opts
);
3003 qemu_add_opts(&qemu_sandbox_opts
);
3004 qemu_add_opts(&qemu_add_fd_opts
);
3005 qemu_add_opts(&qemu_object_opts
);
3006 qemu_add_opts(&qemu_tpmdev_opts
);
3007 qemu_add_opts(&qemu_realtime_opts
);
3008 qemu_add_opts(&qemu_msg_opts
);
3009 qemu_add_opts(&qemu_name_opts
);
3010 qemu_add_opts(&qemu_numa_opts
);
3014 rtc_clock
= QEMU_CLOCK_HOST
;
3016 QLIST_INIT (&vm_change_state_head
);
3017 os_setup_early_signal_handling();
3019 module_call_init(MODULE_INIT_MACHINE
);
3021 optarg
= strrchr(argv
[0], '/');
3023 machine_class
= find_machine(optarg
+ 1);
3025 if (!machine_class
) {
3026 machine_class
= find_default_machine();
3029 ram_size
= default_ram_size
;
3031 cyls
= heads
= secs
= 0;
3032 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3034 for (i
= 0; i
< MAX_NODES
; i
++) {
3035 numa_info
[i
].node_mem
= 0;
3036 numa_info
[i
].present
= false;
3037 bitmap_zero(numa_info
[i
].node_cpu
, MAX_CPUMASK_BITS
);
3041 max_numa_nodeid
= 0;
3044 bdrv_init_with_whitelist();
3048 /* first pass of option parsing */
3050 while (optind
< argc
) {
3051 if (argv
[optind
][0] != '-') {
3055 const QEMUOption
*popt
;
3057 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3058 switch (popt
->index
) {
3059 case QEMU_OPTION_nodefconfig
:
3062 case QEMU_OPTION_nouserconfig
:
3071 ret
= qemu_read_default_config_files(userconfig
);
3077 /* second pass of option parsing */
3082 if (argv
[optind
][0] != '-') {
3083 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3085 const QEMUOption
*popt
;
3087 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3088 if (!(popt
->arch_mask
& arch_type
)) {
3089 printf("Option %s not supported for this target\n", popt
->name
);
3092 switch(popt
->index
) {
3094 machine_class
= machine_parse(optarg
);
3096 case QEMU_OPTION_no_kvm_irqchip
: {
3097 olist
= qemu_find_opts("machine");
3098 qemu_opts_parse(olist
, "kernel_irqchip=off", 0);
3101 case QEMU_OPTION_cpu
:
3102 /* hw initialization will check this */
3105 case QEMU_OPTION_hda
:
3109 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3111 snprintf(buf
, sizeof(buf
),
3112 "%s,cyls=%d,heads=%d,secs=%d%s",
3113 HD_OPTS
, cyls
, heads
, secs
,
3114 translation
== BIOS_ATA_TRANSLATION_LBA
?
3116 translation
== BIOS_ATA_TRANSLATION_NONE
?
3117 ",trans=none" : "");
3118 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3121 case QEMU_OPTION_hdb
:
3122 case QEMU_OPTION_hdc
:
3123 case QEMU_OPTION_hdd
:
3124 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3127 case QEMU_OPTION_drive
:
3128 if (drive_def(optarg
) == NULL
) {
3132 case QEMU_OPTION_set
:
3133 if (qemu_set_option(optarg
) != 0)
3136 case QEMU_OPTION_global
:
3137 if (qemu_global_option(optarg
) != 0)
3140 case QEMU_OPTION_mtdblock
:
3141 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3143 case QEMU_OPTION_sd
:
3144 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3146 case QEMU_OPTION_pflash
:
3147 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3149 case QEMU_OPTION_snapshot
:
3152 case QEMU_OPTION_hdachs
:
3156 cyls
= strtol(p
, (char **)&p
, 0);
3157 if (cyls
< 1 || cyls
> 16383)
3162 heads
= strtol(p
, (char **)&p
, 0);
3163 if (heads
< 1 || heads
> 16)
3168 secs
= strtol(p
, (char **)&p
, 0);
3169 if (secs
< 1 || secs
> 63)
3173 if (!strcmp(p
, "large")) {
3174 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3175 } else if (!strcmp(p
, "rechs")) {
3176 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3177 } else if (!strcmp(p
, "none")) {
3178 translation
= BIOS_ATA_TRANSLATION_NONE
;
3179 } else if (!strcmp(p
, "lba")) {
3180 translation
= BIOS_ATA_TRANSLATION_LBA
;
3181 } else if (!strcmp(p
, "auto")) {
3182 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3186 } else if (*p
!= '\0') {
3188 fprintf(stderr
, "qemu: invalid physical CHS format\n");
3191 if (hda_opts
!= NULL
) {
3193 snprintf(num
, sizeof(num
), "%d", cyls
);
3194 qemu_opt_set(hda_opts
, "cyls", num
);
3195 snprintf(num
, sizeof(num
), "%d", heads
);
3196 qemu_opt_set(hda_opts
, "heads", num
);
3197 snprintf(num
, sizeof(num
), "%d", secs
);
3198 qemu_opt_set(hda_opts
, "secs", num
);
3199 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3200 qemu_opt_set(hda_opts
, "trans", "large");
3201 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3202 qemu_opt_set(hda_opts
, "trans", "rechs");
3203 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3204 qemu_opt_set(hda_opts
, "trans", "lba");
3205 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3206 qemu_opt_set(hda_opts
, "trans", "none");
3211 case QEMU_OPTION_numa
:
3212 opts
= qemu_opts_parse(qemu_find_opts("numa"), optarg
, 1);
3217 case QEMU_OPTION_display
:
3218 display_type
= select_display(optarg
);
3220 case QEMU_OPTION_nographic
:
3221 display_type
= DT_NOGRAPHIC
;
3223 case QEMU_OPTION_curses
:
3224 #ifdef CONFIG_CURSES
3225 display_type
= DT_CURSES
;
3227 fprintf(stderr
, "Curses support is disabled\n");
3231 case QEMU_OPTION_portrait
:
3232 graphic_rotate
= 90;
3234 case QEMU_OPTION_rotate
:
3235 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3236 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3237 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3239 "qemu: only 90, 180, 270 deg rotation is available\n");
3243 case QEMU_OPTION_kernel
:
3244 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
);
3246 case QEMU_OPTION_initrd
:
3247 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
);
3249 case QEMU_OPTION_append
:
3250 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
);
3252 case QEMU_OPTION_dtb
:
3253 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
);
3255 case QEMU_OPTION_cdrom
:
3256 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3258 case QEMU_OPTION_boot
:
3259 opts
= qemu_opts_parse(qemu_find_opts("boot-opts"), optarg
, 1);
3264 case QEMU_OPTION_fda
:
3265 case QEMU_OPTION_fdb
:
3266 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3269 case QEMU_OPTION_no_fd_bootchk
:
3272 case QEMU_OPTION_netdev
:
3273 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3277 case QEMU_OPTION_net
:
3278 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3282 #ifdef CONFIG_LIBISCSI
3283 case QEMU_OPTION_iscsi
:
3284 opts
= qemu_opts_parse(qemu_find_opts("iscsi"), optarg
, 0);
3291 case QEMU_OPTION_tftp
:
3292 legacy_tftp_prefix
= optarg
;
3294 case QEMU_OPTION_bootp
:
3295 legacy_bootp_filename
= optarg
;
3297 case QEMU_OPTION_redir
:
3298 if (net_slirp_redir(optarg
) < 0)
3302 case QEMU_OPTION_bt
:
3303 add_device_config(DEV_BT
, optarg
);
3305 case QEMU_OPTION_audio_help
:
3309 case QEMU_OPTION_soundhw
:
3310 select_soundhw (optarg
);
3315 case QEMU_OPTION_version
:
3319 case QEMU_OPTION_m
: {
3321 const char *mem_str
;
3322 const char *maxmem_str
, *slots_str
;
3324 opts
= qemu_opts_parse(qemu_find_opts("memory"),
3330 mem_str
= qemu_opt_get(opts
, "size");
3332 error_report("invalid -m option, missing 'size' option");
3336 error_report("missing 'size' option value");
3340 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
3342 /* Fix up legacy suffix-less format */
3343 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
3344 uint64_t overflow_check
= sz
;
3347 if ((sz
>> 20) != overflow_check
) {
3348 error_report("too large 'size' option value");
3353 /* backward compatibility behaviour for case "-m 0" */
3355 sz
= default_ram_size
;
3358 sz
= QEMU_ALIGN_UP(sz
, 8192);
3360 if (ram_size
!= sz
) {
3361 error_report("ram size too large");
3365 maxmem_str
= qemu_opt_get(opts
, "maxmem");
3366 slots_str
= qemu_opt_get(opts
, "slots");
3367 if (maxmem_str
&& slots_str
) {
3370 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
3371 if (sz
< ram_size
) {
3372 fprintf(stderr
, "qemu: invalid -m option value: maxmem "
3373 "(%" PRIu64
") <= initial memory ("
3374 RAM_ADDR_FMT
")\n", sz
, ram_size
);
3378 slots
= qemu_opt_get_number(opts
, "slots", 0);
3379 if ((sz
> ram_size
) && !slots
) {
3380 fprintf(stderr
, "qemu: invalid -m option value: maxmem "
3381 "(%" PRIu64
") more than initial memory ("
3382 RAM_ADDR_FMT
") but no hotplug slots where "
3383 "specified\n", sz
, ram_size
);
3387 if ((sz
<= ram_size
) && slots
) {
3388 fprintf(stderr
, "qemu: invalid -m option value: %"
3389 PRIu64
" hotplug slots where specified but "
3390 "maxmem (%" PRIu64
") <= initial memory ("
3391 RAM_ADDR_FMT
")\n", slots
, sz
, ram_size
);
3396 } else if ((!maxmem_str
&& slots_str
) ||
3397 (maxmem_str
&& !slots_str
)) {
3398 fprintf(stderr
, "qemu: invalid -m option value: missing "
3399 "'%s' option\n", slots_str
? "maxmem" : "slots");
3405 case QEMU_OPTION_tpmdev
:
3406 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3411 case QEMU_OPTION_mempath
:
3414 case QEMU_OPTION_mem_prealloc
:
3424 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3426 case QEMU_OPTION_gdb
:
3427 add_device_config(DEV_GDB
, optarg
);
3430 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3431 data_dir
[data_dir_idx
++] = optarg
;
3434 case QEMU_OPTION_bios
:
3435 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
);
3437 case QEMU_OPTION_singlestep
:
3444 keyboard_layout
= optarg
;
3446 case QEMU_OPTION_localtime
:
3449 case QEMU_OPTION_vga
:
3458 w
= strtol(p
, (char **)&p
, 10);
3461 fprintf(stderr
, "qemu: invalid resolution or depth\n");
3467 h
= strtol(p
, (char **)&p
, 10);
3472 depth
= strtol(p
, (char **)&p
, 10);
3473 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3474 depth
!= 24 && depth
!= 32)
3476 } else if (*p
== '\0') {
3477 depth
= graphic_depth
;
3484 graphic_depth
= depth
;
3487 case QEMU_OPTION_echr
:
3490 term_escape_char
= strtol(optarg
, &r
, 0);
3492 printf("Bad argument to echr\n");
3495 case QEMU_OPTION_monitor
:
3496 default_monitor
= 0;
3497 if (strncmp(optarg
, "none", 4)) {
3498 monitor_parse(optarg
, "readline");
3501 case QEMU_OPTION_qmp
:
3502 monitor_parse(optarg
, "control");
3503 default_monitor
= 0;
3505 case QEMU_OPTION_mon
:
3506 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
3510 default_monitor
= 0;
3512 case QEMU_OPTION_chardev
:
3513 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
3518 case QEMU_OPTION_fsdev
:
3519 olist
= qemu_find_opts("fsdev");
3521 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
3524 opts
= qemu_opts_parse(olist
, optarg
, 1);
3529 case QEMU_OPTION_virtfs
: {
3532 const char *writeout
, *sock_fd
, *socket
;
3534 olist
= qemu_find_opts("virtfs");
3536 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
3539 opts
= qemu_opts_parse(olist
, optarg
, 1);
3544 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3545 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3546 fprintf(stderr
, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
3549 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3550 qemu_opt_get(opts
, "mount_tag"),
3553 fprintf(stderr
, "duplicate fsdev id: %s\n",
3554 qemu_opt_get(opts
, "mount_tag"));
3558 writeout
= qemu_opt_get(opts
, "writeout");
3560 #ifdef CONFIG_SYNC_FILE_RANGE
3561 qemu_opt_set(fsdev
, "writeout", writeout
);
3563 fprintf(stderr
, "writeout=immediate not supported on "
3568 qemu_opt_set(fsdev
, "fsdriver", qemu_opt_get(opts
, "fsdriver"));
3569 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"));
3570 qemu_opt_set(fsdev
, "security_model",
3571 qemu_opt_get(opts
, "security_model"));
3572 socket
= qemu_opt_get(opts
, "socket");
3574 qemu_opt_set(fsdev
, "socket", socket
);
3576 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3578 qemu_opt_set(fsdev
, "sock_fd", sock_fd
);
3581 qemu_opt_set_bool(fsdev
, "readonly",
3582 qemu_opt_get_bool(opts
, "readonly", 0));
3583 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3585 qemu_opt_set(device
, "driver", "virtio-9p-pci");
3586 qemu_opt_set(device
, "fsdev",
3587 qemu_opt_get(opts
, "mount_tag"));
3588 qemu_opt_set(device
, "mount_tag",
3589 qemu_opt_get(opts
, "mount_tag"));
3592 case QEMU_OPTION_virtfs_synth
: {
3596 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3599 fprintf(stderr
, "duplicate option: %s\n", "virtfs_synth");
3602 qemu_opt_set(fsdev
, "fsdriver", "synth");
3604 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3606 qemu_opt_set(device
, "driver", "virtio-9p-pci");
3607 qemu_opt_set(device
, "fsdev", "v_synth");
3608 qemu_opt_set(device
, "mount_tag", "v_synth");
3611 case QEMU_OPTION_serial
:
3612 add_device_config(DEV_SERIAL
, optarg
);
3614 if (strncmp(optarg
, "mon:", 4) == 0) {
3615 default_monitor
= 0;
3618 case QEMU_OPTION_watchdog
:
3621 "qemu: only one watchdog option may be given\n");
3626 case QEMU_OPTION_watchdog_action
:
3627 if (select_watchdog_action(optarg
) == -1) {
3628 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
3632 case QEMU_OPTION_virtiocon
:
3633 add_device_config(DEV_VIRTCON
, optarg
);
3634 default_virtcon
= 0;
3635 if (strncmp(optarg
, "mon:", 4) == 0) {
3636 default_monitor
= 0;
3639 case QEMU_OPTION_parallel
:
3640 add_device_config(DEV_PARALLEL
, optarg
);
3641 default_parallel
= 0;
3642 if (strncmp(optarg
, "mon:", 4) == 0) {
3643 default_monitor
= 0;
3646 case QEMU_OPTION_debugcon
:
3647 add_device_config(DEV_DEBUGCON
, optarg
);
3649 case QEMU_OPTION_loadvm
:
3652 case QEMU_OPTION_full_screen
:
3655 case QEMU_OPTION_no_frame
:
3658 case QEMU_OPTION_alt_grab
:
3661 case QEMU_OPTION_ctrl_grab
:
3664 case QEMU_OPTION_no_quit
:
3667 case QEMU_OPTION_sdl
:
3669 display_type
= DT_SDL
;
3672 fprintf(stderr
, "SDL support is disabled\n");
3675 case QEMU_OPTION_pidfile
:
3678 case QEMU_OPTION_win2k_hack
:
3679 win2k_install_hack
= 1;
3681 case QEMU_OPTION_rtc_td_hack
: {
3682 static GlobalProperty slew_lost_ticks
[] = {
3684 .driver
= "mc146818rtc",
3685 .property
= "lost_tick_policy",
3688 { /* end of list */ }
3691 qdev_prop_register_global_list(slew_lost_ticks
);
3694 case QEMU_OPTION_acpitable
:
3695 opts
= qemu_opts_parse(qemu_find_opts("acpi"), optarg
, 1);
3699 do_acpitable_option(opts
);
3701 case QEMU_OPTION_smbios
:
3702 opts
= qemu_opts_parse(qemu_find_opts("smbios"), optarg
, 0);
3706 do_smbios_option(opts
);
3708 case QEMU_OPTION_enable_kvm
:
3709 olist
= qemu_find_opts("machine");
3710 qemu_opts_parse(olist
, "accel=kvm", 0);
3712 case QEMU_OPTION_machine
:
3713 olist
= qemu_find_opts("machine");
3714 opts
= qemu_opts_parse(olist
, optarg
, 1);
3718 optarg
= qemu_opt_get(opts
, "type");
3720 machine_class
= machine_parse(optarg
);
3723 case QEMU_OPTION_no_kvm
:
3724 olist
= qemu_find_opts("machine");
3725 qemu_opts_parse(olist
, "accel=tcg", 0);
3727 case QEMU_OPTION_no_kvm_pit
: {
3728 fprintf(stderr
, "Warning: KVM PIT can no longer be disabled "
3732 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3733 static GlobalProperty kvm_pit_lost_tick_policy
[] = {
3735 .driver
= "kvm-pit",
3736 .property
= "lost_tick_policy",
3739 { /* end of list */ }
3742 fprintf(stderr
, "Warning: option deprecated, use "
3743 "lost_tick_policy property of kvm-pit instead.\n");
3744 qdev_prop_register_global_list(kvm_pit_lost_tick_policy
);
3747 case QEMU_OPTION_usb
:
3748 olist
= qemu_find_opts("machine");
3749 qemu_opts_parse(olist
, "usb=on", 0);
3751 case QEMU_OPTION_usbdevice
:
3752 olist
= qemu_find_opts("machine");
3753 qemu_opts_parse(olist
, "usb=on", 0);
3754 add_device_config(DEV_USB
, optarg
);
3756 case QEMU_OPTION_device
:
3757 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
3761 case QEMU_OPTION_smp
:
3762 if (!qemu_opts_parse(qemu_find_opts("smp-opts"), optarg
, 1)) {
3766 case QEMU_OPTION_vnc
:
3769 vnc_display
= optarg
;
3771 fprintf(stderr
, "VNC support is disabled\n");
3775 case QEMU_OPTION_no_acpi
:
3778 case QEMU_OPTION_no_hpet
:
3781 case QEMU_OPTION_balloon
:
3782 if (balloon_parse(optarg
) < 0) {
3783 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
3787 case QEMU_OPTION_no_reboot
:
3790 case QEMU_OPTION_no_shutdown
:
3793 case QEMU_OPTION_show_cursor
:
3796 case QEMU_OPTION_uuid
:
3797 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
3798 fprintf(stderr
, "Fail to parse UUID string."
3799 " Wrong format.\n");
3802 qemu_uuid_set
= true;
3804 case QEMU_OPTION_option_rom
:
3805 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3806 fprintf(stderr
, "Too many option ROMs\n");
3809 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
3813 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3814 option_rom
[nb_option_roms
].bootindex
=
3815 qemu_opt_get_number(opts
, "bootindex", -1);
3816 if (!option_rom
[nb_option_roms
].name
) {
3817 fprintf(stderr
, "Option ROM file is not specified\n");
3822 case QEMU_OPTION_semihosting
:
3823 semihosting_enabled
= 1;
3825 case QEMU_OPTION_tdf
:
3826 fprintf(stderr
, "Warning: user space PIT time drift fix "
3827 "is no longer supported.\n");
3829 case QEMU_OPTION_name
:
3830 opts
= qemu_opts_parse(qemu_find_opts("name"), optarg
, 1);
3835 case QEMU_OPTION_prom_env
:
3836 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3837 fprintf(stderr
, "Too many prom variables\n");
3840 prom_envs
[nb_prom_envs
] = optarg
;
3843 case QEMU_OPTION_old_param
:
3846 case QEMU_OPTION_clock
:
3847 /* Clock options no longer exist. Keep this option for
3848 * backward compatibility.
3851 case QEMU_OPTION_startdate
:
3852 configure_rtc_date_offset(optarg
, 1);
3854 case QEMU_OPTION_rtc
:
3855 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
3859 configure_rtc(opts
);
3861 case QEMU_OPTION_tb_size
:
3862 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3863 if (tcg_tb_size
< 0) {
3867 case QEMU_OPTION_icount
:
3868 icount_option
= optarg
;
3870 case QEMU_OPTION_incoming
:
3872 runstate_set(RUN_STATE_INMIGRATE
);
3874 case QEMU_OPTION_nodefaults
:
3877 case QEMU_OPTION_xen_domid
:
3878 if (!(xen_available())) {
3879 printf("Option %s not supported for this target\n", popt
->name
);
3882 xen_domid
= atoi(optarg
);
3884 case QEMU_OPTION_xen_create
:
3885 if (!(xen_available())) {
3886 printf("Option %s not supported for this target\n", popt
->name
);
3889 xen_mode
= XEN_CREATE
;
3891 case QEMU_OPTION_xen_attach
:
3892 if (!(xen_available())) {
3893 printf("Option %s not supported for this target\n", popt
->name
);
3896 xen_mode
= XEN_ATTACH
;
3898 case QEMU_OPTION_trace
:
3900 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
3904 trace_events
= qemu_opt_get(opts
, "events");
3905 trace_file
= qemu_opt_get(opts
, "file");
3908 case QEMU_OPTION_trace_unassigned
:
3909 trace_unassigned
= true;
3911 case QEMU_OPTION_readconfig
:
3913 int ret
= qemu_read_config_file(optarg
);
3915 fprintf(stderr
, "read config %s: %s\n", optarg
,
3921 case QEMU_OPTION_spice
:
3922 olist
= qemu_find_opts("spice");
3924 fprintf(stderr
, "spice is not supported by this qemu build.\n");
3927 opts
= qemu_opts_parse(olist
, optarg
, 0);
3933 case QEMU_OPTION_writeconfig
:
3936 if (strcmp(optarg
, "-") == 0) {
3939 fp
= fopen(optarg
, "w");
3941 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
3945 qemu_config_write(fp
);
3951 case QEMU_OPTION_qtest
:
3952 qtest_chrdev
= optarg
;
3954 case QEMU_OPTION_qtest_log
:
3957 case QEMU_OPTION_sandbox
:
3958 opts
= qemu_opts_parse(qemu_find_opts("sandbox"), optarg
, 1);
3963 case QEMU_OPTION_add_fd
:
3965 opts
= qemu_opts_parse(qemu_find_opts("add-fd"), optarg
, 0);
3970 error_report("File descriptor passing is disabled on this "
3975 case QEMU_OPTION_object
:
3976 opts
= qemu_opts_parse(qemu_find_opts("object"), optarg
, 1);
3981 case QEMU_OPTION_realtime
:
3982 opts
= qemu_opts_parse(qemu_find_opts("realtime"), optarg
, 0);
3986 configure_realtime(opts
);
3988 case QEMU_OPTION_msg
:
3989 opts
= qemu_opts_parse(qemu_find_opts("msg"), optarg
, 0);
3993 configure_msg(opts
);
3995 case QEMU_OPTION_dump_vmstate
:
3996 vmstate_dump_file
= fopen(optarg
, "w");
3997 if (vmstate_dump_file
== NULL
) {
3998 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
4003 os_parse_cmd_args(popt
->index
, optarg
);
4011 if (qemu_init_main_loop()) {
4012 fprintf(stderr
, "qemu_init_main_loop failed\n");
4016 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox
, NULL
, 0)) {
4020 if (qemu_opts_foreach(qemu_find_opts("name"), parse_name
, NULL
, 1)) {
4025 if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd
, NULL
, 1)) {
4029 if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd
, NULL
, 1)) {
4034 if (machine_class
== NULL
) {
4035 fprintf(stderr
, "No machine specified, and there is no default.\n"
4036 "Use -machine help to list supported machines!\n");
4040 current_machine
= MACHINE(object_new(object_class_get_name(
4041 OBJECT_CLASS(machine_class
))));
4042 object_property_add_child(object_get_root(), "machine",
4043 OBJECT(current_machine
), &error_abort
);
4044 cpu_exec_init_all();
4046 if (machine_class
->hw_version
) {
4047 qemu_set_version(machine_class
->hw_version
);
4050 if (qemu_opts_foreach(qemu_find_opts("object"),
4051 object_create
, NULL
, 0) != 0) {
4055 /* Init CPU def lists, based on config
4056 * - Must be called after all the qemu_read_config_file() calls
4057 * - Must be called before list_cpus()
4058 * - Must be called before machine->init()
4062 if (cpu_model
&& is_help_option(cpu_model
)) {
4063 list_cpus(stdout
, &fprintf
, cpu_model
);
4067 /* Open the logfile at this point, if necessary. We can't open the logfile
4068 * when encountering either of the logging options (-d or -D) because the
4069 * other one may be encountered later on the command line, changing the
4070 * location or level of logging.
4075 qemu_set_log_filename(log_file
);
4078 mask
= qemu_str_to_log_mask(log_mask
);
4080 qemu_print_log_usage(stdout
);
4086 if (!is_daemonized()) {
4087 if (!trace_init_backends(trace_events
, trace_file
)) {
4092 /* If no data_dir is specified then try to find it relative to the
4094 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4095 data_dir
[data_dir_idx
] = os_find_datadir();
4096 if (data_dir
[data_dir_idx
] != NULL
) {
4100 /* If all else fails use the install path specified when building. */
4101 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4102 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4105 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4107 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4108 if (smp_cpus
> machine_class
->max_cpus
) {
4109 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
4110 "supported by machine `%s' (%d)\n", smp_cpus
,
4111 machine_class
->name
, machine_class
->max_cpus
);
4116 * Get the default machine options from the machine if it is not already
4117 * specified either by the configuration file or by the command line.
4119 if (machine_class
->default_machine_opts
) {
4120 qemu_opts_set_defaults(qemu_find_opts("machine"),
4121 machine_class
->default_machine_opts
, 0);
4124 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
4125 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
4127 if (!vga_model
&& !default_vga
) {
4128 vga_interface_type
= VGA_DEVICE
;
4130 if (!has_defaults
|| machine_class
->no_serial
) {
4133 if (!has_defaults
|| machine_class
->no_parallel
) {
4134 default_parallel
= 0;
4136 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4137 default_virtcon
= 0;
4139 if (!has_defaults
|| !machine_class
->use_sclp
) {
4142 if (!has_defaults
|| machine_class
->no_floppy
) {
4145 if (!has_defaults
|| machine_class
->no_cdrom
) {
4148 if (!has_defaults
|| machine_class
->no_sdcard
) {
4151 if (!has_defaults
) {
4152 default_monitor
= 0;
4157 if (is_daemonized()) {
4158 /* According to documentation and historically, -nographic redirects
4159 * serial port, parallel port and monitor to stdio, which does not work
4160 * with -daemonize. We can redirect these to null instead, but since
4161 * -nographic is legacy, let's just error out.
4162 * We disallow -nographic only if all other ports are not redirected
4163 * explicitly, to not break existing legacy setups which uses
4164 * -nographic _and_ redirects all ports explicitly - this is valid
4165 * usage, -nographic is just a no-op in this case.
4167 if (display_type
== DT_NOGRAPHIC
4168 && (default_parallel
|| default_serial
4169 || default_monitor
|| default_virtcon
)) {
4170 fprintf(stderr
, "-nographic can not be used with -daemonize\n");
4173 #ifdef CONFIG_CURSES
4174 if (display_type
== DT_CURSES
) {
4175 fprintf(stderr
, "curses display can not be used with -daemonize\n");
4181 if (display_type
== DT_NOGRAPHIC
) {
4182 if (default_parallel
)
4183 add_device_config(DEV_PARALLEL
, "null");
4184 if (default_serial
&& default_monitor
) {
4185 add_device_config(DEV_SERIAL
, "mon:stdio");
4186 } else if (default_virtcon
&& default_monitor
) {
4187 add_device_config(DEV_VIRTCON
, "mon:stdio");
4188 } else if (default_sclp
&& default_monitor
) {
4189 add_device_config(DEV_SCLP
, "mon:stdio");
4192 add_device_config(DEV_SERIAL
, "stdio");
4193 if (default_virtcon
)
4194 add_device_config(DEV_VIRTCON
, "stdio");
4196 add_device_config(DEV_SCLP
, "stdio");
4198 if (default_monitor
)
4199 monitor_parse("stdio", "readline");
4203 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4204 if (default_parallel
)
4205 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4206 if (default_monitor
)
4207 monitor_parse("vc:80Cx24C", "readline");
4208 if (default_virtcon
)
4209 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4211 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4215 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4216 #if defined(CONFIG_GTK)
4217 display_type
= DT_GTK
;
4218 #elif defined(CONFIG_SDL) || defined(CONFIG_COCOA)
4219 display_type
= DT_SDL
;
4220 #elif defined(CONFIG_VNC)
4221 vnc_display
= "localhost:0,to=99";
4224 display_type
= DT_NONE
;
4228 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4229 fprintf(stderr
, "-no-frame, -alt-grab and -ctrl-grab are only valid "
4230 "for SDL, ignoring option\n");
4232 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4233 fprintf(stderr
, "-no-quit is only valid for GTK and SDL, "
4234 "ignoring option\n");
4237 #if defined(CONFIG_GTK)
4238 if (display_type
== DT_GTK
) {
4239 early_gtk_display_init();
4245 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
4247 #ifdef CONFIG_VIRTFS
4248 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
4253 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4258 /* store value for the future use */
4259 qemu_opt_set_number(qemu_find_opts_singleton("memory"), "size", ram_size
);
4261 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0)
4266 machine_opts
= qemu_get_machine_opts();
4267 if (qemu_opt_foreach(machine_opts
, object_set_property
, current_machine
,
4269 object_unref(OBJECT(current_machine
));
4273 configure_accelerator(machine_class
);
4276 Error
*local_err
= NULL
;
4277 qtest_init(qtest_chrdev
, qtest_log
, &local_err
);
4279 error_report("%s", error_get_pretty(local_err
));
4280 error_free(local_err
);
4285 machine_opts
= qemu_get_machine_opts();
4286 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4287 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4288 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4289 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4291 boot_order
= machine_class
->default_boot_order
;
4292 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4294 char *normal_boot_order
;
4295 const char *order
, *once
;
4297 order
= qemu_opt_get(opts
, "order");
4299 validate_bootdevices(order
);
4303 once
= qemu_opt_get(opts
, "once");
4305 validate_bootdevices(once
);
4306 normal_boot_order
= g_strdup(boot_order
);
4308 qemu_register_reset(restore_boot_order
, normal_boot_order
);
4311 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4312 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4315 if (!kernel_cmdline
) {
4316 kernel_cmdline
= "";
4317 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4320 linux_boot
= (kernel_filename
!= NULL
);
4322 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4323 fprintf(stderr
, "-append only allowed with -kernel option\n");
4327 if (!linux_boot
&& initrd_filename
!= NULL
) {
4328 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
4332 if (!linux_boot
&& qemu_opt_get(machine_opts
, "dtb")) {
4333 fprintf(stderr
, "-dtb only allowed with -kernel option\n");
4337 os_set_line_buffering();
4339 qemu_init_cpu_loop();
4340 qemu_mutex_lock_iothread();
4343 /* spice needs the timers to be initialized by this point */
4347 if (icount_option
&& (kvm_enabled() || xen_enabled())) {
4348 fprintf(stderr
, "-icount is not allowed with kvm or xen\n");
4351 configure_icount(icount_option
);
4353 /* clean up network at qemu process termination */
4354 atexit(&net_cleanup
);
4356 if (net_init_clients() < 0) {
4361 if (tpm_init() < 0) {
4366 /* init the bluetooth world */
4367 if (foreach_device_config(DEV_BT
, bt_parse
))
4370 if (!xen_enabled()) {
4371 /* On 32-bit hosts, QEMU is limited by virtual address space */
4372 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4373 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
4381 /* open the virtual block devices */
4383 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
4384 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4385 &machine_class
->block_default_type
, 1) != 0) {
4389 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4391 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4392 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4394 if (qemu_opts_foreach(qemu_find_opts("numa"), numa_init_func
,
4401 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
4405 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4407 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4409 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4411 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4414 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4417 /* If no default VGA is requested, the default is "none". */
4419 if (cirrus_vga_available()) {
4420 vga_model
= "cirrus";
4421 } else if (vga_available()) {
4426 select_vgahw(vga_model
);
4430 i
= select_watchdog(watchdog
);
4432 exit (i
== 1 ? 1 : 0);
4435 if (machine_class
->compat_props
) {
4436 qdev_prop_register_global_list(machine_class
->compat_props
);
4440 qdev_machine_init();
4442 current_machine
->ram_size
= ram_size
;
4443 current_machine
->maxram_size
= maxram_size
;
4444 current_machine
->ram_slots
= ram_slots
;
4445 current_machine
->boot_order
= boot_order
;
4446 current_machine
->cpu_model
= cpu_model
;
4448 machine_class
->init(current_machine
);
4452 cpu_synchronize_all_post_init();
4456 /* init USB devices */
4457 if (usb_enabled(false)) {
4458 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4462 /* init generic devices */
4463 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
4466 net_check_clients();
4468 ds
= init_displaystate();
4470 /* init local displays */
4471 switch (display_type
) {
4473 (void)ds
; /* avoid warning if no display is configured */
4475 #if defined(CONFIG_CURSES)
4477 curses_display_init(ds
, full_screen
);
4480 #if defined(CONFIG_SDL)
4482 sdl_display_init(ds
, full_screen
, no_frame
);
4484 #elif defined(CONFIG_COCOA)
4486 cocoa_display_init(ds
, full_screen
);
4489 #if defined(CONFIG_GTK)
4491 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4498 /* must be after terminal init, SDL library changes signal handlers */
4499 os_setup_signal_handling();
4502 /* init remote displays */
4504 Error
*local_err
= NULL
;
4505 vnc_display_init(ds
);
4506 vnc_display_open(ds
, vnc_display
, &local_err
);
4507 if (local_err
!= NULL
) {
4508 error_report("Failed to start VNC server on `%s': %s",
4509 vnc_display
, error_get_pretty(local_err
));
4510 error_free(local_err
);
4514 if (show_vnc_port
) {
4515 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
4521 qemu_spice_display_init();
4525 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4529 qdev_machine_creation_done();
4531 if (rom_load_all() != 0) {
4532 fprintf(stderr
, "rom loading failed\n");
4536 /* TODO: once all bus devices are qdevified, this should be done
4537 * when bus is created by qdev.c */
4538 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4539 qemu_run_machine_init_done_notifiers();
4541 /* Done notifiers can load ROMs */
4544 qemu_system_reset(VMRESET_SILENT
);
4546 if (load_vmstate(loadvm
) < 0) {
4551 qdev_prop_check_global();
4552 if (vmstate_dump_file
) {
4554 dump_vmstate_json_to_file(vmstate_dump_file
);
4559 Error
*local_err
= NULL
;
4560 qemu_start_incoming_migration(incoming
, &local_err
);
4562 error_report("-incoming %s: %s", incoming
,
4563 error_get_pretty(local_err
));
4564 error_free(local_err
);
4567 } else if (autostart
) {
4573 if (is_daemonized()) {
4574 if (!trace_init_backends(trace_events
, trace_file
)) {